@manifest-editor/shell 2.2.0 → 2.2.1-cdn.1.2412bf12
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 +47 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -57
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,o)=>(o=n==null?{}:e(i(n)),s(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));let l=require("@manifest-editor/components"),u=require("react");u=c(u,1);let d=require("react/jsx-runtime"),f=require("zustand"),p=require("localforage");p=c(p,1);let m=require("react-iiif-vault"),h=require("@iiif/parser"),g=require("styled-components");g=c(g,1);let _=require("immer"),v=require("@manifest-editor/editor-api"),y=require("@react-stately/toast"),b=require("@iiif/helpers"),x=require("@iiif/helpers/vault");x=c(x,1);let S=require("@manifest-editor/creator-api"),C=require("react-error-boundary"),w=require("@iiif/helpers/vault/actions"),T=require("@iiif/helpers/vault/utility"),E=require("mitt");E=c(E,1);let D=require("tiny-use-debounce"),O=require("react-transition-group"),ee=require("shallowequal");ee=c(ee,1);let k=require("@atlas-viewer/iiif-image-api"),A=require("@manifest-editor/client-vault");var j=process.env.NODE_ENV===`production`,M=`Invariant failed`;function N(e,t){if(!e){if(j)throw Error(M);var n=typeof t==`function`?t():t,r=n?`${M}: ${n}`:M;throw Error(r)}}const P={previews:[],behaviorPresets:[`auto-advance`,`no-auto-advance`,`repeat`,`no-repeat`,`unordered`,`individuals`,`continuous`,`paged`,`non-paged`,`facing-pages`,`multi-part`,`together`,`sequence`,`thumbnail-nav`,`no-nav`,`hidden`],defaultPreview:null,editorConfig:{},newTemplates:null,i18n:{advancedLanguageMode:!1,availableLanguages:[`en`,`cy`,`nl`,`fr`],defaultLanguage:`en`},editorFeatureFlags:{enableMultiImageCanvases:!0,enableMultiMediaCanvases:!0,annotationPopups:!1,rememberCanvasId:!0,manifestGridOptions:!1,rememberLeftPanelId:!1},uploadBackends:[],plugins:{apps:{}},export:{baseIdentifier:null,version:3},creators:{}};function F(e,t){if(!e&&!t)return;let n={...e||{}};for(let[e,r]of Object.entries(t||{}))n[e]={...n[e]||{},...r||{}};return n}function te(e,t){if(!e&&!t)return;let n={...e?.apps||{}};for(let[e,r]of Object.entries(t?.apps||{})){let t=n[e]||{};n[e]={...t,...r,settings:{...t.settings||{},...r.settings||{}}}}return{apps:n}}function ne(e,t){if(!e&&!t)return;let n={...e||{}};for(let[e,r]of Object.entries(t||{}))n[e]={...n[e]||{},...r||{}};return n}function I(...e){let t={};for(let n of e)n&&(t={...t,...n,editorConfig:F(t.editorConfig,n.editorConfig),editorFeatureFlags:t.editorFeatureFlags||n.editorFeatureFlags?{...t.editorFeatureFlags||{},...n.editorFeatureFlags||{}}:void 0,i18n:t.i18n||n.i18n?{...t.i18n||{},...n.i18n||{}}:void 0,export:t.export||n.export?{...t.export||{},...n.export||{}}:void 0,creators:ne(t.creators,n.creators),plugins:te(t.plugins,n.plugins)});return t}function re(...e){return I(P,...e)}const L=(0,u.createContext)(P),R=(0,u.createContext)(()=>{});function z(){return(0,u.useContext)(L)}function ie(){return(0,u.useContext)(R)}function ae({children:e,config:t,saveConfig:n}){let[r,i]=(0,u.useState)(null),a=(0,u.useMemo)(()=>re(t,r),[t,r]),o=(0,u.useCallback)(e=>{i(t=>I(t,e)),n&&n(e)},[n]);return(0,d.jsx)(R.Provider,{value:o,children:(0,d.jsx)(L.Provider,{value:a,children:e})})}const oe=`@manifest-editor/canvas-progress`,se=`status`,ce=new Set([`queued`,`pending`,`done`]);function le(e){return typeof e==`string`?e:e?.id||null}function ue(e){return typeof e==`string`&&ce.has(e)?e:`none`}function de(e){return typeof e==`string`&&ce.has(e)}function fe(e,t){let n=le(t);return n?ue(e.getResourceMeta(n,oe)?.[se]):`none`}function pe(e,t){let n=le(t);return n?ue(e?.iiif?.meta?.[n]?.[oe]?.[se]):`none`}function me(e,t,n){let r=le(t);if(!r)return`none`;let i=de(n)?n:void 0;return e.setMetaValue([r,oe,se],i),i||`none`}function he(e,t){return me(e,t,`none`)}function ge(e,t,n){let r={};for(let i of t){let t=le(i);t&&(r[t]=me(e,i,n))}return r}function _e(e,t){return ge(e,t,`none`)}function ve(e){return{getStatus(t){return fe(e,t)},setStatus(t,n){return me(e,t,n)},clearStatus(t){return he(e,t)},setStatuses(t,n){return ge(e,t,n)},clearStatuses(t){return _e(e,t)}}}function ye(e,t=new Set){function n(e){let n=le(e);n&&t.add(n)}function r(e){for(let t of e)n(t)}return{trackedResourceIds:t,getStatus(t){return e.getStatus(t)},setStatus(t,r){return n(t),e.setStatus(t,r)},clearStatus(t){return n(t),e.clearStatus(t)},setStatuses(t,n){return r(t),e.setStatuses(t,n)},clearStatuses(t){return r(t),e.clearStatuses(t)},clearTrackedStatuses(){e.clearStatuses(Array.from(t).map(e=>({id:e,type:`Canvas`}))),t.clear()}}}function be(e){let t=le(e);return(0,m.useVaultSelector)(e=>t?pe(e,t):`none`,[t])}function xe(e){let t=(0,m.useVault)(),n=le(e),r=(0,u.useMemo)(()=>ve(t),[t]);return(0,u.useMemo)(()=>({setStatus(e){return r.setStatus(n,e)},clearStatus(){return r.clearStatus(n)},getStatus(){return r.getStatus(n)}}),[r,n])}const Se={queued:{label:`Queued`,stripClass:`bg-zinc-400/80`,badgeClass:`bg-zinc-500`,dimOverlay:!0},pending:{label:`In progress`,stripClass:`bg-amber-400/90 animate-pulse`,badgeClass:`bg-amber-500`},done:{label:`Done`,stripClass:`bg-me-primary-500`,badgeClass:`bg-me-primary-500`}};function Ce({className:e}){return(0,d.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,d.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,d.jsx)(`path`,{d:`M12 7v5l2.5 2.5`})]})}function we({className:e}){return(0,d.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,children:[(0,d.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`,stroke:`currentColor`,strokeWidth:`2.5`,strokeOpacity:`0.3`}),(0,d.jsx)(`path`,{d:`M12 3a9 9 0 0 1 9 9`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`})]})}function Te({className:e}){return(0,d.jsx)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,d.jsx)(`path`,{d:`M5 12l4 4 8-8`})})}function Ee({resource:e,status:t,className:n}){return t?(0,d.jsx)(Oe,{status:t,className:n}):(0,d.jsx)(De,{resource:e,className:n})}function De({resource:e,className:t}){let n=be(e);return(0,d.jsx)(Oe,{status:n,className:t})}function Oe({status:e,className:t}){if(e===`none`)return null;let n=Se[e];return(0,d.jsxs)(d.Fragment,{children:[n.dimOverlay&&(0,d.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0 z-10 bg-white/40`}),(0,d.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-x-0 top-0 z-10 h-[3px] rounded-t-sm ${n.stripClass} ${t||``}`}),(0,d.jsxs)(`div`,{className:`pointer-events-none absolute right-1.5 top-1.5 z-10 flex h-[18px] w-[18px] items-center justify-center rounded-full ${n.badgeClass} shadow-md ring-2 ring-white/70`,title:n.label,children:[(0,d.jsx)(`span`,{className:`sr-only`,children:n.label}),e===`queued`&&(0,d.jsx)(Ce,{className:`h-2.5 w-2.5 text-white`}),e===`pending`&&(0,d.jsx)(we,{className:`h-2.5 w-2.5 animate-spin text-white`}),e===`done`&&(0,d.jsx)(Te,{className:`h-2.5 w-2.5 text-white`})]})]})}function ke(e,t){return`${e}::${t.type}::${t.id}`}function Ae(e=[],t=[]){let n=[],r=new Set;for(let e=t.length-1;e>=0;--e){let i=t[e];i&&!r.has(i.id)&&(r.add(i.id),n.unshift(i))}return[...e.filter(e=>!r.has(e.id)),...n]}function je(e){return[...e].sort((e,t)=>{let n=(e.section||``).localeCompare(t.section||``);if(n!==0)return n;let r=(e.order||0)-(t.order||0);if(r!==0)return r;let i=e.label.localeCompare(t.label);return i===0?e.id.localeCompare(t.id):i})}function Me(e){return e instanceof Error?{message:e.message,stack:e.stack,detail:e}:{message:typeof e==`string`?e:`Background action failed`,detail:e}}function Ne(e){return e&&typeof e==`object`&&typeof e.message==`string`?{message:e.message,stack:typeof e.stack==`string`?e.stack:void 0,detail:e.detail}:Me(e)}function Pe(e,t){return!e.resourceTypes?.length||e.resourceTypes.includes(t.type)}function Fe({definitions:e,instances:t,systemContext:n,targets:r,onSupportsError:i}){let a=je(e),o=[];for(let e of r){let r=[];for(let o of a){if(!Pe(o,e))continue;let a=ke(o.id,e),s={...n,definition:o,target:e,instanceKey:a,instance:t[a]};try{if(o.supports&&!o.supports(s))continue}catch(e){i?.(o,e);continue}r.push({definition:o,target:e,instanceKey:a,instance:t[a],context:s})}r.length&&o.push({id:`${e.scope}:${e.type}:${e.id}`,label:e.label,target:e,actions:r})}return o}let Ie=0;function Le(e){return Ie+=1,`${e}-${Date.now()}-${Ie}`}function Re(e,t,n,r=Date.now()){return{id:Le(`event`),createdAt:r,type:e,message:t,data:n}}function B(e,t,n,r,i=Date.now()){return{...e,events:[...e.events,Re(t,n,r,i)]}}function ze(e){return e.filter(e=>String(e.type)!==`progress`)}function Be(e){return{...e,logs:[...e.logs],events:ze(e.events),progress:e.progress?{...e.progress}:void 0}}function Ve(e,t,n){if(!Ge(n.status))return e;let r=e[t]||[],i=Be(n),a=r.findIndex(e=>e.runId===n.runId),o=a>=0?r.map((e,t)=>t===a?i:e):[...r,i];return{...e,[t]:o}}function V(e,t,n){let r=e.instances[t];if(!r)return{instances:e.instances,histories:e.histories};let i=n(r);return{instances:{...e.instances,[t]:i},histories:Ve(e.histories,t,i)}}function He(e){return Number.isFinite(e)?Math.min(100,Math.max(0,e)):0}function Ue(e){let t=e,n=typeof t.current==`number`&&Number.isFinite(t.current)?t.current:void 0,r=typeof t.total==`number`&&Number.isFinite(t.total)?t.total:void 0;return{percent:He(typeof t.percent==`number`&&Number.isFinite(t.percent)?t.percent:typeof n==`number`&&typeof r==`number`&&r>0?n/r*100:0),current:n,total:r,label:t.label}}function We(e){return e===`preparing`||e===`running`}function Ge(e){return e===`complete`||e===`error`||e===`cancelled`}function Ke(e){return e===`queued`||e===`running`||e===`complete`||e===`skipped`||e===`error`||e===`cancelled`}function qe(e){return!e||e===`queued`||e===`running`}function Je(e){return e===`complete`||e===`skipped`||e===`error`||e===`cancelled`}function Ye(e){if(e!==void 0)try{return JSON.parse(JSON.stringify(e))}catch{return}}function Xe(e){return e&&{message:e.message,stack:e.stack,detail:Ye(e.detail)}}function Ze(e){return{...e,error:Xe(e.error)||null,result:Ye(e.result),logs:e.logs.map(e=>({...e,data:Ye(e.data)})),events:ze(e.events).map(e=>({...e,data:Ye(e.data)})),progress:e.progress?{...e.progress}:void 0}}function Qe(e){return{...e,status:it(e.status),input:Ye(e.input),result:Ye(e.result),error:Xe(e.error)||null}}function $e(e){return{version:1,data:Ye(e.data),tasks:e.tasks.map(Qe)}}function et(e){return{version:1,savedAt:Date.now(),instances:Object.fromEntries(Object.entries(e.instances).map(([e,t])=>[e,Ze(t)])),histories:Object.fromEntries(Object.entries(e.histories).map(([e,t])=>[e,t.map(Ze)])),plans:Object.fromEntries(Object.entries(e.plans).map(([e,t])=>[e,$e(t)]))}}function tt(){return{version:1,savedAt:Date.now(),instances:{},histories:{},plans:{}}}function nt(e,t){return{version:1,savedAt:t.savedAt,instances:{...e.instances,...t.instances},histories:{...e.histories,...t.histories},plans:{...e.plans,...t.plans}}}function rt(e){return!Object.keys(e.instances).length&&!Object.keys(e.histories).length&&!Object.keys(e.plans).length}function it(e){return Ke(e)?e:`queued`}function at(e,t){let n=Date.now(),r=typeof e.id==`string`&&e.id?e.id:`task-${t+1}`;return{...e,id:r,label:typeof e.label==`string`&&e.label?e.label:r,status:it(e.status),error:e.error?Ne(e.error):null,createdAt:typeof e.createdAt==`number`?e.createdAt:n}}function ot(e){return!e||e.version!==1||!Array.isArray(e.tasks)?null:{version:1,data:e.data,tasks:e.tasks.map(at)}}function st(e){return{...e,tasks:e.tasks.map(e=>e.status===`running`?{...e,status:`queued`,statusText:`Queued after reload`,startedAt:void 0}:e)}}function ct(e,t=Date.now()){return{...e,tasks:e.tasks.map(e=>qe(e.status)?{...e,status:`cancelled`,statusText:`Cancelled`,error:null,completedAt:t}:e)}}function lt(e){return{...e,error:e.error?Ne(e.error):null,logs:Array.isArray(e.logs)?e.logs:[],events:ze(Array.isArray(e.events)?e.events:[]),resultsAvailable:e.resultsAvailable===!0}}function ut(e){return!e||e.version!==1?tt():{version:1,savedAt:typeof e.savedAt==`number`?e.savedAt:Date.now(),instances:e.instances||{},histories:e.histories||{},plans:e.plans||{}}}function dt(e,t,n){let r=e,i=t;if(We(e.status)){if(e.cancelRequestedAt){let t=Date.now();i=i&&ct(i,t),r=B({...e,status:`cancelled`,statusText:`Cancelled`,completedAt:t,cancelledAt:t},`status`,`Cancelled`,{status:`cancelled`},t)}else if(n.resumable&&i)i=st(i),r=B({...e,status:`running`,statusText:`Resuming`,completedAt:void 0,cancelledAt:void 0},`status`,`Resuming`,{status:`running`});else{let t=Date.now();r=B({...e,status:`cancelled`,statusText:`Interrupted by page reload`,completedAt:t,cancelledAt:t},`status`,`Interrupted by page reload`,{status:`cancelled`},t)}}return{instance:r,plan:i}}function ft(e,t){let n=ut(e),r=new Map(t.map(e=>[e.id,e])),i={},a={},o={},s=tt();for(let[e,t]of Object.entries(n.histories)){let n=(Array.isArray(t)?t:[]).map(lt),i=n.filter(e=>r.has(e.actionId)),o=n.filter(e=>!r.has(e.actionId));i.length&&(a[e]=i),o.length&&(s.histories[e]=o)}for(let[e,t]of Object.entries(n.instances)){let c=lt(t),l=ot(n.plans[e]),u=r.get(c.actionId);if(!u){s.instances[e]=Ze(c),l&&(s.plans[e]=$e(l));continue}let d=dt(c,l,u);i[e]=d.instance,a=Ve(a,e,d.instance),d.plan&&(o[e]=d.plan)}return{instances:i,histories:a,plans:o,deferred:s}}function pt(e,t){let n=e.tasks.length;if(!n)return;let r=e.tasks.filter(e=>Je(e.status)).length;return Ue({current:r,total:n,label:t})}function mt(e){return e&&typeof e==`object`&&`taskStatus`in e&&(e.taskStatus===`complete`||e.taskStatus===`skipped`)?{taskStatus:e.taskStatus,result:e.result,statusText:e.statusText}:{taskStatus:`complete`,result:e}}function ht(e,t){for(let n of t.tasks)!n.target||n.target.type!==`Canvas`||(n.status===`running`?e.setStatus(n.target,`pending`):n.status===`queued`&&e.setStatus(n.target,`queued`))}function gt(e,t,n){let{store:r,context:i}=e,{instanceKey:a}=i;function o(){return r.getState().plans[a]}function s(){return o()?.tasks||[]}function c(e=[`queued`,`running`]){let t=new Set(e);return s().filter(e=>t.has(it(e.status)))}function l(e,t,n=!1){r.getState().updateActionTask(a,e,t,n)}async function u(e,i={}){let u=c(i.statuses||[`queued`,`running`]),d=s().length,f=u.length,p=i.yieldEveryMs===!1?!1:i.yieldEveryMs??16,m=0;for(let[c,h]of u.entries()){if(t.aborted||_t(m,p)&&(await vt(),m=Date.now(),t.aborted))throw Error(`Background action cancelled.`);let u=s().find(e=>e.id===h.id)||h,g=s().findIndex(e=>e.id===u.id),_=i.progressLabel?.(u,g,d)||u.label||`Task ${g+1}/${d}`;u.target?.type===`Canvas`&&n.setStatus(u.target,`pending`),l(u.id,{status:`running`,statusText:_,error:null,startedAt:Date.now(),completedAt:void 0},!0),r.getState().setActionStatus(a,`running`,_),r.getState().setActionProgress(a,{current:s().filter(e=>Je(e.status)).length,total:d,label:_});try{let r=await e(u,{index:g,total:d,pendingIndex:c,pendingTotal:f});if(t.aborted)throw Error(`Background action cancelled.`);let i=mt(r);l(u.id,{status:i.taskStatus,statusText:i.statusText||(i.taskStatus===`skipped`?`Skipped`:`Complete`),result:i.result,error:null,completedAt:Date.now()},!0),u.target?.type===`Canvas`&&n.setStatus(u.target,`done`)}catch(e){if(t.aborted||Ct(e))throw l(u.id,{status:`cancelled`,statusText:`Cancelled`,error:null,completedAt:Date.now()},!0),e;let n=Me(e);l(u.id,{status:`error`,statusText:n.message,error:n,completedAt:Date.now()},!0),r.getState().appendActionLog(a,`Task failed: ${u.label}`,`warn`,{taskId:u.id,error:n.message})}finally{let e=o();e&&r.getState().setActionProgress(a,{current:e.tasks.filter(e=>Je(e.status)).length,total:d,label:_})}}return s()}return{getAll:s,getPending:()=>c(),update:l,runEach:u}}function _t(e,t){return t!==!1&&(!e||Date.now()-e>=t)}function vt(){return new Promise(e=>{setTimeout(e,0)})}function yt(e=[]){let t=null,n=null,r=null,i=tt();return(0,f.createStore)((a,o)=>{function s(e,t){let n=Ae([],t),r=ft(i,n);return i=r.deferred,{definitions:n,instances:{...e.instances,...r.instances},histories:{...e.histories,...r.histories},plans:{...e.plans,...r.plans},controllers:Object.fromEntries(Object.entries(e.controllers).filter(([t,n])=>n&&e.instances[t]?.status&&We(e.instances[t].status)))}}async function c(){if(r&&(clearTimeout(r),r=null),!t||!n||!o().hasHydrated)return;let e=nt(i,et(o()));if(rt(e)){await t.clear(n);return}await t.save(n,e)}function l(e=!1){if(!(!t||!n||!o().hasHydrated)){if(e){c();return}r&&clearTimeout(r),r=setTimeout(()=>{c()},300)}}return{definitions:Ae([],e),instances:{},histories:{},plans:{},controllers:{},hasHydrated:!0,setDefinitions(e){a(t=>s(t,e)),l()},setPersistence(e,r){t=e,n=e&&r?r:null,a({hasHydrated:!t})},hydrate(e){let t=ft(ut(e),o().definitions);i=t.deferred,a({instances:t.instances,histories:t.histories,plans:t.plans,controllers:{},hasHydrated:!0}),l(!0)},persist(e=!1){l(e)},flushPersistence:c,registerAction(e){return a(t=>s(t,Ae(t.definitions,[e]))),l(),()=>o().unregisterAction(e.id)},unregisterAction(e){a(t=>{let n={};for(let[r,i]of Object.entries(t.instances))i.actionId!==e&&(n[r]=i);let r={};for(let[n,i]of Object.entries(t.histories)){let t=i.filter(t=>t.actionId!==e);t.length&&(r[n]=t)}let i={...t.plans},a={...t.controllers};for(let[n,r]of Object.entries(t.instances))r.actionId===e&&(a[n]?.abort(),delete a[n],delete i[n]);return{definitions:t.definitions.filter(t=>t.id!==e),instances:n,histories:r,plans:i,controllers:a}}),l(!0)},resetAction(e){a(t=>{t.controllers[e]?.abort();let n={...t.instances},r={...t.histories},i={...t.plans},a={...t.controllers};return delete n[e],delete r[e],delete i[e],delete a[e],{instances:n,histories:r,plans:i,controllers:a}}),l(!0)},startAction(e,t,n,r){let i=Date.now();a(a=>{let o={...a.plans};return delete o[e],{instances:{...a.instances,[e]:{id:e,runId:Le(`run`),actionId:t.id,target:n,label:t.label,status:`preparing`,statusText:`Preparing`,error:null,result:void 0,resultsAvailable:!1,logs:[],events:[Re(`started`,`Preparing`,{status:`preparing`},i)],progress:void 0,startedAt:i,completedAt:void 0,cancelRequestedAt:void 0,cancelledAt:void 0}},plans:o,controllers:r?{...a.controllers,[e]:r}:a.controllers}}),l(!0)},resumeAction(e,t){let n=Date.now();a(r=>({...V(r,e,e=>B({...e,status:`running`,statusText:`Resuming`,completedAt:void 0,cancelledAt:void 0},`status`,`Resuming`,{status:`running`},n)),controllers:{...r.controllers,[e]:t}})),l(!0)},cancelAction(e){let t=o().controllers[e],n=o().instances[e];if(!n||!We(n.status))return;let r=Date.now();a(t=>{let n=V(t,e,e=>B(B({...e,status:`cancelled`,statusText:`Cancelled`,completedAt:r,cancelledAt:r,cancelRequestedAt:e.cancelRequestedAt||r},`cancel-requested`,`Cancelling`,void 0,r),`status`,`Cancelled`,{status:`cancelled`},r)),i=t.plans[e];return{...n,plans:i?{...t.plans,[e]:ct(i,r)}:t.plans,controllers:Object.fromEntries(Object.entries(t.controllers).filter(([t])=>t!==e))}}),l(!0),t?.abort()},setActionLabel(e,t){let n=Date.now();a(r=>({...V(r,e,e=>B({...e,label:t},`label`,t,{label:t},n))})),l()},setActionStatus(e,t,n){let r=Date.now(),i=Ge(t)?r:void 0;a(a=>({...V(a,e,e=>B({...e,status:t,statusText:n,completedAt:i,cancelledAt:t===`cancelled`?r:void 0},`status`,n||t,{status:t},r)),controllers:We(t)?a.controllers:Object.fromEntries(Object.entries(a.controllers).filter(([t])=>t!==e))})),l(Ge(t))},setActionError(e,t,n){let r=Date.now(),i=Me(t);a(t=>({...V(t,e,e=>B({...e,status:`error`,statusText:n,error:i,completedAt:r,cancelledAt:void 0},`error`,n||i.message,i,r)),controllers:Object.fromEntries(Object.entries(t.controllers).filter(([t])=>t!==e))})),l(!0)},appendActionLog(e,t,n=`info`,r){let i=Date.now(),o={id:Le(`log`),createdAt:i,level:n,message:t,data:r};a(a=>({...V(a,e,e=>B({...e,logs:[...e.logs,o]},`log`,t,{level:n,data:r},i))})),l()},setActionProgress(e,t){let n=t?Ue(t):void 0;a(t=>({...V(t,e,e=>({...e,progress:n}))}))},setResult(e,t){let n=Date.now();a(r=>({...V(r,e,e=>B({...e,result:t},`result`,`Result recorded`,void 0,n))})),l(!0)},setResultsAvailable(e,t){let n=Date.now();a(r=>({...V(r,e,e=>B({...e,resultsAvailable:t},`results-available`,t?`Results available`:`Results hidden`,{available:t},n))})),l(!0)},setActionPlan(e,t){let n=ot(t);n&&(a(t=>({...V(t,e,e=>({...e,progress:pt(n,`Queued`)})),plans:{...t.plans,[e]:n}})),l(!0))},updateActionTask(e,t,n,r=!1){a(r=>{let i=r.plans[e];if(!i)return r;let a=i.tasks.map(e=>e.id===t?at({...e,...n,status:n.status?it(n.status):e.status,error:n.error?Ne(n.error):n.error===null?null:e.error},0):e),o={...i,tasks:a};return{...V(r,e,e=>({...e,progress:pt(o,n.statusText||n.label)})),plans:{...r.plans,[e]:o}}}),l(r)}}})}function bt(e,t,n){let{store:r,context:i}=e,{instanceKey:a}=i,o=gt(e,t,n);return{...i,canvasProgress:n,instance:r.getState().instances[a],plan:r.getState().plans[a],tasks:o,signal:t,prepareData:e.prepareData,setActionLabel(e){r.getState().setActionLabel(a,e)},setActionStatus(e,t){r.getState().setActionStatus(a,e,t)},setActionError(e,t){r.getState().setActionError(a,e,t)},appendActionLog(e,t,n){r.getState().appendActionLog(a,e,t,n)},setActionProgress(e){r.getState().setActionProgress(a,e)},setResult(e){r.getState().setResult(a,e)},setResultsAvailable(e){r.getState().setResultsAvailable(a,e)}}}function xt(e){return!!e&&typeof e==`object`&&e.version===1&&Array.isArray(e.tasks)}async function St(e){let{store:t,context:n}=e,{definition:r,instanceKey:i,target:a}=n,o=t.getState().instances[i],s=t.getState().controllers[i];if((o?.status===`preparing`||o?.status===`running`)&&(!e.resume||s))return o;let c=new AbortController,l=c.signal,u=ye(n.canvasProgress),d=()=>c.abort();e.signal&&(e.signal.aborted?c.abort():e.signal.addEventListener(`abort`,d,{once:!0})),e.resume&&o&&We(o.status)?t.getState().resumeAction(i,c):t.getState().startAction(i,r,a,c);let f=()=>{let e=t.getState().instances[i];e&&!Ge(e.status)&&t.getState().setActionStatus(i,`cancelled`,`Cancelled`)};try{if(!e.resume&&r.prepare){let n=await r.prepare(bt(e,l,u));if(l.aborted)return f(),t.getState().instances[i];if(n===!1)return t.getState().setActionStatus(i,`idle`),t.getState().instances[i];xt(n)&&t.getState().setActionPlan(i,n)}if(l.aborted)return f(),t.getState().instances[i];let n=t.getState().plans[i];n&&ht(u,n),t.getState().setActionStatus(i,`running`,e.resume?`Resuming`:`Running`);let a=await r.run(bt(e,l,u));if(l.aborted)return f(),t.getState().instances[i];let o=t.getState().instances[i];a!==void 0&&o&&!Ge(o.status)&&t.getState().setResult(i,a),o=t.getState().instances[i],o&&We(o.status)&&((a!==void 0||o?.resultsAvailable)&&t.getState().setResultsAvailable(i,!0),t.getState().setActionStatus(i,`complete`,`Complete`))}catch(e){l.aborted||Ct(e)?f():t.getState().setActionError(i,e,`Error`)}finally{u.clearTrackedStatuses(),e.signal?.removeEventListener(`abort`,d),await t.getState().flushPersistence()}return t.getState().instances[i]}function Ct(e){return e instanceof Error&&(e.name===`AbortError`||e.message.toLowerCase().includes(`aborted`))}function wt(e){return JSON.stringify([e.appId,e.instanceId,e.rootResource.type,e.rootResource.id])}let Tt;function Et(){if(typeof window>`u`)return null;let e=p.default.createInstance({name:`manifest-editor-background-actions-v1`,storeName:`background-actions`});return{async load(t){return e.getItem(wt(t))},async save(t,n){await e.setItem(wt(t),n)},async clear(t){await e.removeItem(wt(t))}}}function Dt(){return Tt===void 0&&(Tt=Et()),Tt}const Ot=(0,u.createContext)(null);function kt({children:e,persistence:t,persistenceKey:n}){let r=U(),i=Hn(),a=(0,u.useMemo)(()=>yt(),[]),o=r.layout.backgroundActions||[],s=(0,u.useMemo)(()=>t===!1?null:t||Dt(),[t]),c=(0,u.useMemo)(()=>n||null,[n]);return(0,u.useEffect)(()=>{a.getState().setDefinitions(o)},[a,o]),(0,u.useEffect)(()=>{let e=c||{appId:i.appId,instanceId:i.instanceId,rootResource:{id:`global`,type:`Manifest`}},t=!1;return a.getState().setPersistence(s,e),s?(s.load(e).then(e=>{t||a.getState().hydrate(e)}).catch(e=>{console.warn(`[manifest-editor/background-actions] Failed to load persisted actions`,e),t||a.getState().hydrate(null)}),()=>{t=!0,a.getState().flushPersistence()}):(a.getState().hydrate(null),()=>void 0)},[i.appId,i.instanceId,s,c?.appId,c?.instanceId,c?.rootResource.id,c?.rootResource.type,a]),(0,u.useEffect)(()=>{let e=()=>{a.getState().flushPersistence()};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[a]),(0,u.createElement)(Ot.Provider,{value:a},e)}function At(){let e=(0,u.useContext)(Ot);if(!e)throw Error(`useBackgroundActionsStore must be used within a BackgroundActionsProvider`);return e}function H(e=e=>e){return(0,f.useStore)(At(),e)}function jt(e){return H(t=>t.instances[e])}function Mt(e){return H(t=>t.histories[e]||[])}async function Nt(e){let t;try{await fetch(e).then(e=>e.json().catch(e=>{console.error(`'${e}' happened!`)})).then(e=>{t={...e}})}catch(e){console.log(e)}return t}function Pt(e,t,n){return`create_${e}_${t}_${(0,h.toRef)(n)?.type||`unknown`}`}function Ft(e,t,n=`text/json`){let r=e instanceof Blob?e:new Blob([e],{type:n}),i=document.createElement(`a`);i.download=t,i.href=window.URL.createObjectURL(r);let a=new MouseEvent(`click`,{view:window,bubbles:!0,cancelable:!0});i.dispatchEvent(a),i.remove()}async function It(e){return navigator.clipboard.writeText(typeof e==`string`?e:JSON.stringify(e,null,2))}function Lt(){return`${Math.random().toString(36).substr(2)}-${Date.now().toString(36)}`}function Rt(e,t){let{default:n,config:r,preset:i,...a}=e,o={metadata:n,layout:{leftPanels:[],rightPanels:[],centerPanels:[],...a},config:r,preset:i},s=t?t(o):o;return{...s,preset:zt(void 0,s.preset)}}function zt(e,t){if(!e&&!t)return;let n=e?.templateFilter&&t?.templateFilter?n=>e.templateFilter(n)&&t.templateFilter(n):t?.templateFilter||e?.templateFilter,r=t?.templateStrategy===`replace`?t.templates||[]:[...e?.templates||[],...t?.templates||[]],i=e?.preview||t?.preview?{...e?.preview||{},...t?.preview||{},actions:[...e?.preview?.actions||[],...t?.preview?.actions||[]]}:void 0;return{...e||{},...t||{},templateFilter:n,templates:n?r.filter(n):r,preview:i}}function Bt(e,t,n){return{...e,metadata:t,config:I(e.config||{},n.config||{}),preset:zt(e.preset,n.preset),layout:{...e.layout,leftPanels:[...(e.layout.leftPanels||[]).filter(e=>!n?.leftPanelIds||n.leftPanelIds.includes(e.id)),...n?.leftPanels||[]],annotations:[...n?.annotations||[],...e.layout.annotations||[]],canvasEditors:[...n?.canvasEditors||[],...e.layout.canvasEditors||[]],creators:[...n?.creators||[],...e.layout.creators||[]],background:[...e.layout?.background||[],...n?.background||[]],backgroundActions:Ae(e.layout?.backgroundActions||[],n?.backgroundActions||[]),editors:[...n?.editors||[],...e.layout.editors||[]],rightPanels:[...e.layout.rightPanels||[],...n?.rightPanels||[]],centerPanels:[...e.layout.centerPanels||[],...n?.centerPanels||[]],modals:[...e.layout.modals||[],...n?.modalPanels||[]]}}}const Vt=[`leftPanels`,`centerPanels`,`rightPanels`,`modalPanels`,`annotations`,`canvasEditors`,`editors`,`creators`,`background`,`backgroundActions`],Ht={plugins:[],enabled:[],disabled:[],globalApps:{},apps:{}};function Ut(){return Ht}function Wt(e=[]){return Array.from(new Set(e.filter(Boolean)))}function Gt(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Kt(e={}){return{...e,enabled:Wt(e.enabled||[]),disabled:Wt(e.disabled||[]),settings:e.settings?{...e.settings}:void 0}}function qt(e){let t={};for(let[n,r]of Object.entries(e?.apps||{}))t[n]=Kt(r);return t}function Jt(e={},t){return{...e,enabled:Wt([...(e.enabled||[]).filter(e=>e!==t),t]),disabled:(e.disabled||[]).filter(e=>e!==t)}}function Yt(e={},t){return{...e,enabled:(e.enabled||[]).filter(e=>e!==t),disabled:Wt([...(e.disabled||[]).filter(e=>e!==t),t])}}function Xt(e={},t){return{...e,enabled:(e.enabled||[]).filter(e=>e!==t),disabled:(e.disabled||[]).filter(e=>e!==t)}}function Zt(e={},t={}){let n=e.enabled||[],r=t.enabled||[],i=e.disabled||[],a=t.disabled||[];return n.length===r.length&&n.every((e,t)=>e===r[t])&&i.length===a.length&&i.every((e,t)=>e===a[t])&&JSON.stringify(e.settings||{})===JSON.stringify(t.settings||{})}function Qt(e,t){let{default:n,config:r,settings:i,...a}=e,o={metadata:n,extension:{...a,config:r},settings:i};return t?t(o):o}function $t(e){return{metadata:e.default,extension:{},settings:e.settings,load:e.load,loadStatus:`idle`}}function en(e){return!!e&&`metadata`in e&&`extension`in e}function tn(e){return!!e&&`load`in e&&`default`in e}function nn(e){return en(e)?e:tn(e)?$t(e):Qt(e)}function rn(e=[]){return e.map(nn)}function an(e,t){let n=new Map(e.map(e=>[e.metadata.id,e]));return t.map(e=>{let t=n.get(e.metadata.id);return t?t.loadStatus===`loaded`&&e.load?{...t,metadata:e.metadata,load:e.load}:t.loadStatus===`loading`&&e.load?{...e,loadStatus:`loading`}:t.loadStatus===`error`&&e.load?{...e,loadStatus:`error`,loadError:t.loadError}:e:e})}function on(e,t,n){let r=e.metadata.supports;if(!r)return!0;if(r.apps?.length){let e=new Set([n,t?.metadata.id].filter(Boolean));if(!r.apps.some(t=>e.has(t)))return!1}if(r.projectTypes?.length){let e=t?.metadata.projectType;if(!e||!r.projectTypes.includes(e))return!1}return!0}function sn(e,t,n){let r=e.metadata.supports;if(!r)return null;if(r.apps?.length){let e=new Set([n,t?.metadata.id].filter(Boolean));if(!r.apps.some(t=>e.has(t)))return`This plugin does not support the current app.`}if(r.projectTypes?.length){let e=t?.metadata.projectType;if(!e||!r.projectTypes.includes(e))return`This plugin does not support the current project type.`}return null}function cn(e,t,n){let r=n?t.apps[n]:void 0,i=n?t.globalApps[n]:void 0,a=e.metadata.id;return r?.disabled?.includes(a)?!1:r?.enabled?.includes(a)?!0:i?.disabled?.includes(a)?!1:i?.enabled?.includes(a)?!0:t.disabled.includes(a)?!1:t.enabled.includes(a)?!0:e.metadata.defaultEnabled===!0}function ln(e,t,n){let r=n?t.apps[n]:void 0,i=n?t.globalApps[n]:void 0,a=e.metadata.id;return r?.disabled?.includes(a)||r?.enabled?.includes(a)?`workspace`:i?.disabled?.includes(a)||i?.enabled?.includes(a)?`global`:t.disabled.includes(a)||t.enabled.includes(a)?`provider`:`default`}function un(e,t,n){let r=[],i=new Set,a=new Set,o=new Set(e.plugins.filter(r=>on(r,t,n)&&cn(r,e,n)).map(e=>e.metadata.id)),s=new Map(e.plugins.map(e=>[e.metadata.id,e])),c=new Set;function l(e){let u=e.metadata.id;if(i.has(u))return!0;if(a.has(u))return!1;if(c.has(u))return yn(`Plugin "${u}" was not enabled because its dependency graph contains a cycle.`),a.add(u),!1;c.add(u);for(let r of e.metadata.dependencies||[]){let e=s.get(r);if(!e||!o.has(r))return yn(`Plugin "${u}" was not enabled because dependency "${r}" is not enabled.`),c.delete(u),a.add(u),!1;if(!on(e,t,n))return yn(`Plugin "${u}" was not enabled because dependency "${r}" is not compatible.`),c.delete(u),a.add(u),!1;if(!l(e))return c.delete(u),a.add(u),!1}return c.delete(u),r.push(e),i.add(u),!0}for(let r of e.plugins)on(r,t,n)&&cn(r,e,n)&&l(r);return r}function dn(e,t){let n=e?.settings?.[t];return Gt(n)?n:{}}function fn(e={},t,n){return{...e,settings:{...e.settings||{},[t]:n}}}function pn(e={},t){let n={...e.settings||{}};return delete n[t],{...e,settings:n}}function mn(e){return{...e?.settings?.defaults||{}}}function hn(e,t,n){let r=e.plugins.find(e=>e.metadata.id===t),i=n?e.globalApps[n]:void 0,a=n?e.apps[n]:void 0;return{...mn(r),...dn(i,t),...dn(a,t)}}function gn(e,t){return{getSettings(n){return hn(e,n,t)}}}function _n(e,t,n,r,i){let a=new Map(t.plugins.map(e=>[e.metadata.id,e])),o=[],s=[],c=new Set,l=e;function u(e){let t=e.metadata.id;if(!o.includes(t)){if(c.has(t)){s.push(`${t} has a circular dependency`);return}c.add(t);for(let t of e.metadata.dependencies||[]){let e=a.get(t);if(!e){s.push(`${t} is not available`);continue}if(!on(e,r,i)){s.push(`${e.metadata.label} is not compatible`);continue}u(e)}c.delete(t),l=Jt(l,t),o.push(t)}}return u(n),s.length?{config:e,enabledIds:[],blocked:s}:{config:l,enabledIds:o,blocked:s}}function vn(e,t){return t===`modalPanels`?e.layout.modals||[]:e.layout[t]||[]}function yn(e){globalThis.process?.env?.NODE_ENV!==`production`&&console.warn(`[manifest-editor/plugin] ${e}`)}function bn(e,t,n,r){if(!r?.length)return;let i=[];for(let a of r){if(n.has(a.id)){yn(`Plugin "${e.metadata.id}" contribution "${a.id}" for "${t}" was skipped because that id already exists.`);continue}n.add(a.id),i.push(a)}return i.length?i:void 0}function xn(e,t){let n=t.extension,r={config:n.config,preset:n.preset,disableSideEffects:n.disableSideEffects};for(let i of Vt){let a=bn(t,i,new Set(vn(e,i).map(e=>e.id)),n[i]);a&&(r[i]=a)}return r}function Sn(e,t,n){if(!t.length)return e;let r=e,i=new Set;for(let a of t){if(!on(a,e,n))continue;let t=(a.metadata.dependencies||[]).filter(e=>!i.has(e));if(t.length){yn(`Plugin "${a.metadata.id}" was not applied because dependencies are missing or later in the plugin order: ${t.join(`, `)}`);continue}let o=xn(r,a);r=Bt(r,r.metadata,o),i.add(a.metadata.id)}let a=new Set(e.layout.leftPanels.map(e=>e.id)),o=r.layout.leftPanels.filter(e=>e.divide),s=r.layout.leftPanels.filter(e=>!e.divide),c=!1,l=s.map(e=>!c&&!a.has(e.id)?(c=!0,{...e,separator:!0}):e);return{...r,config:I(e.config||{},...t.filter(e=>i.has(e.metadata.id)).map(e=>e.extension.config||{}),r.config||{}),layout:{...r.layout,leftPanels:[...l,...o],backgroundActions:Ae([],r.layout.backgroundActions||[])}}}function Cn({plugins:e=[],enabled:t=[],disabled:n=[],globalPluginConfig:r}={}){let i=(e=[])=>Array.from(new Set(e.filter(Boolean)));return(0,f.createStore)(a=>({plugins:e,enabled:i(t),disabled:i(n),globalApps:qt(r),apps:{},setProviderState(e){a(t=>({...t,plugins:an(t.plugins,e.plugins||[]),enabled:i(e.enabled||[]),disabled:i(e.disabled||[]),globalApps:qt(e.globalPluginConfig)}))},setPluginLoading(e){a(t=>({...t,plugins:t.plugins.map(t=>t.metadata.id===e?{...t,loadStatus:`loading`,loadError:void 0}:t)}))},setPluginLoaded(e,t){a(n=>({...n,plugins:n.plugins.map(n=>n.metadata.id===e?{...t,metadata:{...n.metadata,...t.metadata},settings:t.settings||n.settings,load:n.load,loadStatus:`loaded`,loadError:void 0}:n)}))},setPluginLoadError(e,t){a(n=>({...n,plugins:n.plugins.map(n=>n.metadata.id===e?{...n,loadStatus:`error`,loadError:t}:n)}))},setAppConfig(e,t){let n=Kt(t);a(t=>Zt(t.apps[e],n)?t:{...t,apps:{...t.apps,[e]:n}})},setGlobalConfig(e){a(t=>({...t,globalApps:qt(e)}))},setGlobalAppConfig(e,t){let n=Kt(t);a(t=>Zt(t.globalApps[e],n)?t:{...t,globalApps:{...t.globalApps,[e]:n}})},enable(e,t,n=`workspace`){a(r=>({...r,plugins:r.plugins.map(e=>e.metadata.id===t&&e.loadStatus===`error`?{...e,loadStatus:`idle`,loadError:void 0}:e),...n===`global`?{globalApps:{...r.globalApps,[e]:Jt(r.globalApps[e],t)}}:{apps:{...r.apps,[e]:Jt(r.apps[e],t)}}}))},disable(e,t,n=`workspace`){a(r=>({...r,...n===`global`?{globalApps:{...r.globalApps,[e]:Yt(r.globalApps[e],t)}}:{apps:{...r.apps,[e]:Yt(r.apps[e],t)}}}))}}))}const wn=(0,u.createContext)(null),Tn=(0,u.createContext)({});function En({plugins:e,enabled:t,disabled:n,globalPluginConfig:r,saveGlobalPluginConfig:i,children:a}){let o=(0,u.useMemo)(()=>rn(e),[e]),s=(0,u.useMemo)(()=>Cn({plugins:o,enabled:t,disabled:n,globalPluginConfig:r}),[]);(0,u.useEffect)(()=>{s.getState().setProviderState({plugins:o,enabled:t,disabled:n,globalPluginConfig:r})},[s,o,t,n,r]);let c=(0,u.useMemo)(()=>({globalPluginConfig:r,saveGlobalPluginConfig:i}),[r,i]);return(0,u.createElement)(Tn.Provider,{value:c},(0,u.createElement)(wn.Provider,{value:s},a))}function Dn(){return(0,u.useContext)(wn)}function On(){let e=Dn();if(!e)throw Error(`usePluginStoreApi must be used within <PluginProvider />`);return e}function kn(e){let t=Dn();return t?(0,f.useStore)(t,e):e(Ut())}function An(){return kn(e=>({plugins:e.plugins,enabled:e.enabled,disabled:e.disabled,globalApps:e.globalApps,apps:e.apps}))}function jn(e){let t=(0,u.useContext)(Bn),n=(0,u.useContext)(zn),r=An(),i=e||t?.appId;return(0,u.useMemo)(()=>un(r,n,i),[r,n,i])}function Mn(){let e=Dn();return(0,u.useMemo)(()=>e?{enable(t,n,r){e.getState().enable(t,n,r||`workspace`)},disable(t,n,r){e.getState().disable(t,n,r||`workspace`)},setAppConfig(t,n){e.getState().setAppConfig(t,n)},setGlobalAppConfig(t,n){e.getState().setGlobalAppConfig(t,n)}}:{enable(){},disable(){},setAppConfig(){},setGlobalAppConfig(){}},[e])}function Nn(e){let t=(0,u.useContext)(Bn),n=An(),r=e||t?.appId;return(0,u.useMemo)(()=>gn(n,r),[n,r])}function Pn(e,t){let n=(0,u.useContext)(Bn),r=An(),i=t||n?.appId;return(0,u.useMemo)(()=>hn(r,e,i),[r,e,i])}function Fn(e,t){let n=(0,u.useContext)(Bn),r=Dn(),i=An(),a=z(),o=ie(),{saveGlobalPluginConfig:s}=(0,u.useContext)(Tn),c=t||n?.appId||``,l=i.plugins.find(t=>t.metadata.id===e)||null,d=c?i.globalApps[c]:void 0,f=c?i.apps[c]:void 0,p=(0,u.useMemo)(()=>mn(l||void 0),[l]),m=(0,u.useMemo)(()=>dn(d,e),[d,e]),h=(0,u.useMemo)(()=>dn(f,e),[f,e]),g=(0,u.useMemo)(()=>hn(i,e,c),[i,e,c]),_=(0,u.useCallback)(e=>{c&&(r?.getState().setAppConfig(c,e),o({plugins:{...a.plugins||{},apps:{...a.plugins?.apps||{},[c]:e}}}))},[a.plugins,c,o,r]),v=(0,u.useCallback)(t=>{_(fn(f||{},e,t))},[_,e,f]),y=(0,u.useCallback)(()=>{_(pn(f||{},e))},[_,e,f]),b=(0,u.useCallback)(async e=>{if(!c||!s)return;let t=i.globalApps[c]||{},n={apps:{...i.globalApps,[c]:e}};r?.getState().setGlobalAppConfig(c,e);try{await s(n)}catch(e){throw r?.getState().setGlobalAppConfig(c,t),e}},[c,s,i.globalApps,r]),x=(0,u.useCallback)(async t=>{await b(fn(d||{},e,t))},[d,b,e]),S=(0,u.useCallback)(async()=>{await b(pn(d||{},e))},[d,b,e]);return{plugin:l,appId:c,defaults:p,global:m,workspace:h,effective:g,canSaveGlobal:!!s,setWorkspaceSettings:v,resetWorkspaceSettings:y,setGlobalSettings:x,resetGlobalSettings:S}}function In(e,t){let n=An(),r=Dn(),i=(0,u.useMemo)(()=>un(n,e,t),[n,e,t]);return(0,u.useEffect)(()=>{if(r)for(let e of i)!e.load||e.loadStatus===`loading`||e.loadStatus===`loaded`||e.loadStatus===`error`||(r.getState().setPluginLoading(e.metadata.id),e.load().then(t=>{r.getState().setPluginLoaded(e.metadata.id,nn(t))}).catch(t=>{r.getState().setPluginLoadError(e.metadata.id,Ln(t))}))},[r,i]),(0,u.useMemo)(()=>Sn(e,i.filter(e=>!e.load||e.loadStatus===`loaded`),t),[e,i,t])}function Ln(e){return e instanceof Error?e.message:typeof e==`string`?e:`Plugin failed to load.`}function Rn({config:e}){let t=(0,u.useContext)(Bn),n=Dn(),r=t?.appId,i=r?e?.plugins?.apps?.[r]:void 0;return(0,u.useEffect)(()=>{!n||!r||n.getState().setAppConfig(r,i||{})},[n,r,i]),null}const zn=(0,u.createContext)(null),Bn=(0,u.createContext)(null),Vn=(0,u.createContext)({state:null,setState:()=>{}});function Hn(){let e=(0,u.useContext)(Bn);return N(e,`Hook useAppInstance must be used inside <AppProvider />`),e}function U(){let e=(0,u.useContext)(zn);return N(e,`Hook useApp must be used inside <AppProvider />`),e}function Un(){return(0,u.useContext)(Vn)}function Wn(e,t){return e.find(e=>e.id===t)||null}function Gn(){let e=U(),{state:t,setState:n}=Un(),r=e.preset?.templates||[],i=typeof t?.presetTemplateId==`string`?t.presetTemplateId:null;return{templates:r,selectedTemplateId:i,selectedTemplate:(0,u.useMemo)(()=>Wn(r,i),[i,r]),setSelectedTemplateId:(0,u.useCallback)(e=>n({presetTemplateId:e}),[n])}}function Kn(e){let[t,n,r]=(0,l.useLocalStorage)(`app-state/${e.appId}/${e.instanceId}`,e.initialState||{}),i=(0,u.useCallback)(e=>{let t=r.current?JSON.parse(r.current||`{}`):{},i=(typeof e==`function`?e(t):e)||{};n({...t,...i})},[]);(0,u.useEffect)(()=>{e.args&&i(e.args)},[e.appId]);let a=(0,u.useMemo)(()=>({state:t||{},setState:i}),[i,t]);return(0,d.jsx)(Vn.Provider,{value:a,children:e.children})}function qn({instanceId:e,appId:t,args:n,definition:r,children:i,initialState:a}){let o=(0,u.useMemo)(()=>({instanceId:e,appId:t,args:n}),[e,t,n]),s=(0,u.useMemo)(()=>a||{},[e]),c=In(r,t);return(0,d.jsx)(ae,{config:c.config||{},children:(0,d.jsx)(zn.Provider,{value:c,children:(0,d.jsx)(Bn.Provider,{value:o,children:(0,d.jsx)(Kn,{instanceId:o.instanceId,appId:o.appId,args:o.args,initialState:s,children:i})})})})}const Jn=(0,u.createContext)(null);function Yn(){let e=(0,u.useContext)(Jn);return N(e,`Hook useApps must be used inside <MultiAppProvider />`),e}function Xn(e,t=!1){let[n,r]=(0,l.useOptionalLocalStorage)(`SelectedApplication`,e||{id:`splash`},!t);return[n,r]}function Zn({apps:e,initialApp:t,saveCurrentApp:n=!0,instanceId:r,children:i,config:a={}}){let{defaultApp:o=`splash`,collectionApp:s=`collection-editor`,manifestApp:c=`manifest-editor`}=a,[l,f]=Xn(t,n),p=e=>{e===`Manifest`&&f({id:c}),e===`Collection`&&f({id:s})},m=(0,u.useMemo)(()=>({currentApp:l||{id:o},initialApp:t||{id:o},apps:e,changeApp:f,changeProjectType:p}),[t,e,l]),h=e[m.currentApp.id];return!l||!h?null:(0,d.jsx)(qn,{appId:l.id,definition:h,instanceId:l.id+r,args:l.args,children:(0,d.jsx)(Jn.Provider,{value:m,children:i})})}const Qn=g.default.div`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,o)=>(o=n==null?{}:e(i(n)),s(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));let l=require("@manifest-editor/components"),u=require("react");u=c(u,1);let d=require("react/jsx-runtime"),f=require("zustand"),p=require("localforage");p=c(p,1);let m=require("react-iiif-vault"),h=require("@iiif/parser"),g=require("styled-components");g=c(g,1);let _=require("immer"),v=require("@manifest-editor/editor-api"),y=require("@react-stately/toast"),b=require("@iiif/helpers"),x=require("@iiif/helpers/vault");x=c(x,1);let S=require("@manifest-editor/creator-api"),C=require("react-error-boundary"),w=require("@iiif/helpers/vault/actions"),T=require("@iiif/helpers/vault/utility"),E=require("mitt");E=c(E,1);let D=require("tiny-use-debounce"),O=require("react-transition-group"),ee=require("shallowequal");ee=c(ee,1);let k=require("@atlas-viewer/iiif-image-api"),A=require("@manifest-editor/client-vault");var j=process.env.NODE_ENV===`production`,M=`Invariant failed`;function N(e,t){if(!e){if(j)throw Error(M);var n=typeof t==`function`?t():t,r=n?`${M}: ${n}`:M;throw Error(r)}}const P={previews:[],behaviorPresets:[`auto-advance`,`no-auto-advance`,`repeat`,`no-repeat`,`unordered`,`individuals`,`continuous`,`paged`,`non-paged`,`facing-pages`,`multi-part`,`together`,`sequence`,`thumbnail-nav`,`no-nav`,`hidden`],defaultPreview:null,editorConfig:{},newTemplates:null,i18n:{advancedLanguageMode:!1,availableLanguages:[`en`,`cy`,`nl`,`fr`],defaultLanguage:`en`},editorFeatureFlags:{enableMultiImageCanvases:!0,enableMultiMediaCanvases:!0,annotationPopups:!1,rememberCanvasId:!0,manifestGridOptions:!1,rememberLeftPanelId:!1},uploadBackends:[],plugins:{apps:{}},export:{baseIdentifier:null,version:3},creators:{"iiif-image-services":{compact:`with-dimensions`,includeSizes:!1,includeTiles:!1}}};function F(e,t){if(!e&&!t)return;let n={...e||{}};for(let[e,r]of Object.entries(t||{}))n[e]={...n[e]||{},...r||{}};return n}function te(e,t){if(!e&&!t)return;let n={...e?.apps||{}};for(let[e,r]of Object.entries(t?.apps||{})){let t=n[e]||{};n[e]={...t,...r,settings:{...t.settings||{},...r.settings||{}}}}return{apps:n}}function ne(e,t){if(!e&&!t)return;let n={...e||{}};for(let[e,r]of Object.entries(t||{}))n[e]={...n[e]||{},...r||{}};return n}function I(...e){let t={};for(let n of e)n&&(t={...t,...n,editorConfig:F(t.editorConfig,n.editorConfig),editorFeatureFlags:t.editorFeatureFlags||n.editorFeatureFlags?{...t.editorFeatureFlags||{},...n.editorFeatureFlags||{}}:void 0,i18n:t.i18n||n.i18n?{...t.i18n||{},...n.i18n||{}}:void 0,export:t.export||n.export?{...t.export||{},...n.export||{}}:void 0,creators:ne(t.creators,n.creators),plugins:te(t.plugins,n.plugins)});return t}function re(...e){return I(P,...e)}const L=(0,u.createContext)(P),R=(0,u.createContext)(()=>{});function z(){return(0,u.useContext)(L)}function ie(){return(0,u.useContext)(R)}function ae({children:e,config:t,saveConfig:n}){let[r,i]=(0,u.useState)(null),a=(0,u.useMemo)(()=>re(t,r),[t,r]),o=(0,u.useCallback)(e=>{i(t=>I(t,e)),n&&n(e)},[n]);return(0,d.jsx)(R.Provider,{value:o,children:(0,d.jsx)(L.Provider,{value:a,children:e})})}const oe=`@manifest-editor/canvas-progress`,se=`status`,ce=new Set([`queued`,`pending`,`done`]);function le(e){return typeof e==`string`?e:e?.id||null}function ue(e){return typeof e==`string`&&ce.has(e)?e:`none`}function de(e){return typeof e==`string`&&ce.has(e)}function fe(e,t){let n=le(t);return n?ue(e.getResourceMeta(n,oe)?.[se]):`none`}function pe(e,t){let n=le(t);return n?ue(e?.iiif?.meta?.[n]?.[oe]?.[se]):`none`}function me(e,t,n){let r=le(t);if(!r)return`none`;let i=de(n)?n:void 0;return e.setMetaValue([r,oe,se],i),i||`none`}function he(e,t){return me(e,t,`none`)}function ge(e,t,n){let r={};for(let i of t){let t=le(i);t&&(r[t]=me(e,i,n))}return r}function _e(e,t){return ge(e,t,`none`)}function ve(e){return{getStatus(t){return fe(e,t)},setStatus(t,n){return me(e,t,n)},clearStatus(t){return he(e,t)},setStatuses(t,n){return ge(e,t,n)},clearStatuses(t){return _e(e,t)}}}function ye(e,t=new Set){function n(e){let n=le(e);n&&t.add(n)}function r(e){for(let t of e)n(t)}return{trackedResourceIds:t,getStatus(t){return e.getStatus(t)},setStatus(t,r){return n(t),e.setStatus(t,r)},clearStatus(t){return n(t),e.clearStatus(t)},setStatuses(t,n){return r(t),e.setStatuses(t,n)},clearStatuses(t){return r(t),e.clearStatuses(t)},clearTrackedStatuses(){e.clearStatuses(Array.from(t).map(e=>({id:e,type:`Canvas`}))),t.clear()}}}function be(e){let t=le(e);return(0,m.useVaultSelector)(e=>t?pe(e,t):`none`,[t])}function xe(e){let t=(0,m.useVault)(),n=le(e),r=(0,u.useMemo)(()=>ve(t),[t]);return(0,u.useMemo)(()=>({setStatus(e){return r.setStatus(n,e)},clearStatus(){return r.clearStatus(n)},getStatus(){return r.getStatus(n)}}),[r,n])}const Se={queued:{label:`Queued`,stripClass:`bg-zinc-400/80`,badgeClass:`bg-zinc-500`,dimOverlay:!0},pending:{label:`In progress`,stripClass:`bg-amber-400/90 animate-pulse`,badgeClass:`bg-amber-500`},done:{label:`Done`,stripClass:`bg-me-primary-500`,badgeClass:`bg-me-primary-500`}};function Ce({className:e}){return(0,d.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,d.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,d.jsx)(`path`,{d:`M12 7v5l2.5 2.5`})]})}function we({className:e}){return(0,d.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,children:[(0,d.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`,stroke:`currentColor`,strokeWidth:`2.5`,strokeOpacity:`0.3`}),(0,d.jsx)(`path`,{d:`M12 3a9 9 0 0 1 9 9`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`})]})}function Te({className:e}){return(0,d.jsx)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,d.jsx)(`path`,{d:`M5 12l4 4 8-8`})})}function Ee({resource:e,status:t,className:n}){return t?(0,d.jsx)(Oe,{status:t,className:n}):(0,d.jsx)(De,{resource:e,className:n})}function De({resource:e,className:t}){let n=be(e);return(0,d.jsx)(Oe,{status:n,className:t})}function Oe({status:e,className:t}){if(e===`none`)return null;let n=Se[e];return(0,d.jsxs)(d.Fragment,{children:[n.dimOverlay&&(0,d.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0 z-10 bg-white/40`}),(0,d.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-x-0 top-0 z-10 h-[3px] rounded-t-sm ${n.stripClass} ${t||``}`}),(0,d.jsxs)(`div`,{className:`pointer-events-none absolute right-1.5 top-1.5 z-10 flex h-[18px] w-[18px] items-center justify-center rounded-full ${n.badgeClass} shadow-md ring-2 ring-white/70`,title:n.label,children:[(0,d.jsx)(`span`,{className:`sr-only`,children:n.label}),e===`queued`&&(0,d.jsx)(Ce,{className:`h-2.5 w-2.5 text-white`}),e===`pending`&&(0,d.jsx)(we,{className:`h-2.5 w-2.5 animate-spin text-white`}),e===`done`&&(0,d.jsx)(Te,{className:`h-2.5 w-2.5 text-white`})]})]})}function ke(e,t){return`${e}::${t.type}::${t.id}`}function Ae(e=[],t=[]){let n=[],r=new Set;for(let e=t.length-1;e>=0;--e){let i=t[e];i&&!r.has(i.id)&&(r.add(i.id),n.unshift(i))}return[...e.filter(e=>!r.has(e.id)),...n]}function je(e){return[...e].sort((e,t)=>{let n=(e.section||``).localeCompare(t.section||``);if(n!==0)return n;let r=(e.order||0)-(t.order||0);if(r!==0)return r;let i=e.label.localeCompare(t.label);return i===0?e.id.localeCompare(t.id):i})}function Me(e){return e instanceof Error?{message:e.message,stack:e.stack,detail:e}:{message:typeof e==`string`?e:`Background action failed`,detail:e}}function Ne(e){return e&&typeof e==`object`&&typeof e.message==`string`?{message:e.message,stack:typeof e.stack==`string`?e.stack:void 0,detail:e.detail}:Me(e)}function Pe(e,t){return!e.resourceTypes?.length||e.resourceTypes.includes(t.type)}function Fe({definitions:e,instances:t,systemContext:n,targets:r,onSupportsError:i}){let a=je(e),o=[];for(let e of r){let r=[];for(let o of a){if(!Pe(o,e))continue;let a=ke(o.id,e),s={...n,definition:o,target:e,instanceKey:a,instance:t[a]};try{if(o.supports&&!o.supports(s))continue}catch(e){i?.(o,e);continue}r.push({definition:o,target:e,instanceKey:a,instance:t[a],context:s})}r.length&&o.push({id:`${e.scope}:${e.type}:${e.id}`,label:e.label,target:e,actions:r})}return o}let Ie=0;function Le(e){return Ie+=1,`${e}-${Date.now()}-${Ie}`}function Re(e,t,n,r=Date.now()){return{id:Le(`event`),createdAt:r,type:e,message:t,data:n}}function B(e,t,n,r,i=Date.now()){return{...e,events:[...e.events,Re(t,n,r,i)]}}function ze(e){return e.filter(e=>String(e.type)!==`progress`)}function Be(e){return{...e,logs:[...e.logs],events:ze(e.events),progress:e.progress?{...e.progress}:void 0}}function Ve(e,t,n){if(!Ge(n.status))return e;let r=e[t]||[],i=Be(n),a=r.findIndex(e=>e.runId===n.runId),o=a>=0?r.map((e,t)=>t===a?i:e):[...r,i];return{...e,[t]:o}}function V(e,t,n){let r=e.instances[t];if(!r)return{instances:e.instances,histories:e.histories};let i=n(r);return{instances:{...e.instances,[t]:i},histories:Ve(e.histories,t,i)}}function He(e){return Number.isFinite(e)?Math.min(100,Math.max(0,e)):0}function Ue(e){let t=e,n=typeof t.current==`number`&&Number.isFinite(t.current)?t.current:void 0,r=typeof t.total==`number`&&Number.isFinite(t.total)?t.total:void 0;return{percent:He(typeof t.percent==`number`&&Number.isFinite(t.percent)?t.percent:typeof n==`number`&&typeof r==`number`&&r>0?n/r*100:0),current:n,total:r,label:t.label}}function We(e){return e===`preparing`||e===`running`}function Ge(e){return e===`complete`||e===`error`||e===`cancelled`}function Ke(e){return e===`queued`||e===`running`||e===`complete`||e===`skipped`||e===`error`||e===`cancelled`}function qe(e){return!e||e===`queued`||e===`running`}function Je(e){return e===`complete`||e===`skipped`||e===`error`||e===`cancelled`}function Ye(e){if(e!==void 0)try{return JSON.parse(JSON.stringify(e))}catch{return}}function Xe(e){return e&&{message:e.message,stack:e.stack,detail:Ye(e.detail)}}function Ze(e){return{...e,error:Xe(e.error)||null,result:Ye(e.result),logs:e.logs.map(e=>({...e,data:Ye(e.data)})),events:ze(e.events).map(e=>({...e,data:Ye(e.data)})),progress:e.progress?{...e.progress}:void 0}}function Qe(e){return{...e,status:it(e.status),input:Ye(e.input),result:Ye(e.result),error:Xe(e.error)||null}}function $e(e){return{version:1,data:Ye(e.data),tasks:e.tasks.map(Qe)}}function et(e){return{version:1,savedAt:Date.now(),instances:Object.fromEntries(Object.entries(e.instances).map(([e,t])=>[e,Ze(t)])),histories:Object.fromEntries(Object.entries(e.histories).map(([e,t])=>[e,t.map(Ze)])),plans:Object.fromEntries(Object.entries(e.plans).map(([e,t])=>[e,$e(t)]))}}function tt(){return{version:1,savedAt:Date.now(),instances:{},histories:{},plans:{}}}function nt(e,t){return{version:1,savedAt:t.savedAt,instances:{...e.instances,...t.instances},histories:{...e.histories,...t.histories},plans:{...e.plans,...t.plans}}}function rt(e){return!Object.keys(e.instances).length&&!Object.keys(e.histories).length&&!Object.keys(e.plans).length}function it(e){return Ke(e)?e:`queued`}function at(e,t){let n=Date.now(),r=typeof e.id==`string`&&e.id?e.id:`task-${t+1}`;return{...e,id:r,label:typeof e.label==`string`&&e.label?e.label:r,status:it(e.status),error:e.error?Ne(e.error):null,createdAt:typeof e.createdAt==`number`?e.createdAt:n}}function ot(e){return!e||e.version!==1||!Array.isArray(e.tasks)?null:{version:1,data:e.data,tasks:e.tasks.map(at)}}function st(e){return{...e,tasks:e.tasks.map(e=>e.status===`running`?{...e,status:`queued`,statusText:`Queued after reload`,startedAt:void 0}:e)}}function ct(e,t=Date.now()){return{...e,tasks:e.tasks.map(e=>qe(e.status)?{...e,status:`cancelled`,statusText:`Cancelled`,error:null,completedAt:t}:e)}}function lt(e){return{...e,error:e.error?Ne(e.error):null,logs:Array.isArray(e.logs)?e.logs:[],events:ze(Array.isArray(e.events)?e.events:[]),resultsAvailable:e.resultsAvailable===!0}}function ut(e){return!e||e.version!==1?tt():{version:1,savedAt:typeof e.savedAt==`number`?e.savedAt:Date.now(),instances:e.instances||{},histories:e.histories||{},plans:e.plans||{}}}function dt(e,t,n){let r=e,i=t;if(We(e.status)){if(e.cancelRequestedAt){let t=Date.now();i=i&&ct(i,t),r=B({...e,status:`cancelled`,statusText:`Cancelled`,completedAt:t,cancelledAt:t},`status`,`Cancelled`,{status:`cancelled`},t)}else if(n.resumable&&i)i=st(i),r=B({...e,status:`running`,statusText:`Resuming`,completedAt:void 0,cancelledAt:void 0},`status`,`Resuming`,{status:`running`});else{let t=Date.now();r=B({...e,status:`cancelled`,statusText:`Interrupted by page reload`,completedAt:t,cancelledAt:t},`status`,`Interrupted by page reload`,{status:`cancelled`},t)}}return{instance:r,plan:i}}function ft(e,t){let n=ut(e),r=new Map(t.map(e=>[e.id,e])),i={},a={},o={},s=tt();for(let[e,t]of Object.entries(n.histories)){let n=(Array.isArray(t)?t:[]).map(lt),i=n.filter(e=>r.has(e.actionId)),o=n.filter(e=>!r.has(e.actionId));i.length&&(a[e]=i),o.length&&(s.histories[e]=o)}for(let[e,t]of Object.entries(n.instances)){let c=lt(t),l=ot(n.plans[e]),u=r.get(c.actionId);if(!u){s.instances[e]=Ze(c),l&&(s.plans[e]=$e(l));continue}let d=dt(c,l,u);i[e]=d.instance,a=Ve(a,e,d.instance),d.plan&&(o[e]=d.plan)}return{instances:i,histories:a,plans:o,deferred:s}}function pt(e,t){let n=e.tasks.length;if(!n)return;let r=e.tasks.filter(e=>Je(e.status)).length;return Ue({current:r,total:n,label:t})}function mt(e){return e&&typeof e==`object`&&`taskStatus`in e&&(e.taskStatus===`complete`||e.taskStatus===`skipped`)?{taskStatus:e.taskStatus,result:e.result,statusText:e.statusText}:{taskStatus:`complete`,result:e}}function ht(e,t){for(let n of t.tasks)!n.target||n.target.type!==`Canvas`||(n.status===`running`?e.setStatus(n.target,`pending`):n.status===`queued`&&e.setStatus(n.target,`queued`))}function gt(e,t,n){let{store:r,context:i}=e,{instanceKey:a}=i;function o(){return r.getState().plans[a]}function s(){return o()?.tasks||[]}function c(e=[`queued`,`running`]){let t=new Set(e);return s().filter(e=>t.has(it(e.status)))}function l(e,t,n=!1){r.getState().updateActionTask(a,e,t,n)}async function u(e,i={}){let u=c(i.statuses||[`queued`,`running`]),d=s().length,f=u.length,p=i.yieldEveryMs===!1?!1:i.yieldEveryMs??16,m=0;for(let[c,h]of u.entries()){if(t.aborted||_t(m,p)&&(await vt(),m=Date.now(),t.aborted))throw Error(`Background action cancelled.`);let u=s().find(e=>e.id===h.id)||h,g=s().findIndex(e=>e.id===u.id),_=i.progressLabel?.(u,g,d)||u.label||`Task ${g+1}/${d}`;u.target?.type===`Canvas`&&n.setStatus(u.target,`pending`),l(u.id,{status:`running`,statusText:_,error:null,startedAt:Date.now(),completedAt:void 0},!0),r.getState().setActionStatus(a,`running`,_),r.getState().setActionProgress(a,{current:s().filter(e=>Je(e.status)).length,total:d,label:_});try{let r=await e(u,{index:g,total:d,pendingIndex:c,pendingTotal:f});if(t.aborted)throw Error(`Background action cancelled.`);let i=mt(r);l(u.id,{status:i.taskStatus,statusText:i.statusText||(i.taskStatus===`skipped`?`Skipped`:`Complete`),result:i.result,error:null,completedAt:Date.now()},!0),u.target?.type===`Canvas`&&n.setStatus(u.target,`done`)}catch(e){if(t.aborted||Ct(e))throw l(u.id,{status:`cancelled`,statusText:`Cancelled`,error:null,completedAt:Date.now()},!0),e;let n=Me(e);l(u.id,{status:`error`,statusText:n.message,error:n,completedAt:Date.now()},!0),r.getState().appendActionLog(a,`Task failed: ${u.label}`,`warn`,{taskId:u.id,error:n.message})}finally{let e=o();e&&r.getState().setActionProgress(a,{current:e.tasks.filter(e=>Je(e.status)).length,total:d,label:_})}}return s()}return{getAll:s,getPending:()=>c(),update:l,runEach:u}}function _t(e,t){return t!==!1&&(!e||Date.now()-e>=t)}function vt(){return new Promise(e=>{setTimeout(e,0)})}function yt(e=[]){let t=null,n=null,r=null,i=tt();return(0,f.createStore)((a,o)=>{function s(e,t){let n=Ae([],t),r=ft(i,n);return i=r.deferred,{definitions:n,instances:{...e.instances,...r.instances},histories:{...e.histories,...r.histories},plans:{...e.plans,...r.plans},controllers:Object.fromEntries(Object.entries(e.controllers).filter(([t,n])=>n&&e.instances[t]?.status&&We(e.instances[t].status)))}}async function c(){if(r&&(clearTimeout(r),r=null),!t||!n||!o().hasHydrated)return;let e=nt(i,et(o()));if(rt(e)){await t.clear(n);return}await t.save(n,e)}function l(e=!1){if(!(!t||!n||!o().hasHydrated)){if(e){c();return}r&&clearTimeout(r),r=setTimeout(()=>{c()},300)}}return{definitions:Ae([],e),instances:{},histories:{},plans:{},controllers:{},hasHydrated:!0,setDefinitions(e){a(t=>s(t,e)),l()},setPersistence(e,r){t=e,n=e&&r?r:null,a({hasHydrated:!t})},hydrate(e){let t=ft(ut(e),o().definitions);i=t.deferred,a({instances:t.instances,histories:t.histories,plans:t.plans,controllers:{},hasHydrated:!0}),l(!0)},persist(e=!1){l(e)},flushPersistence:c,registerAction(e){return a(t=>s(t,Ae(t.definitions,[e]))),l(),()=>o().unregisterAction(e.id)},unregisterAction(e){a(t=>{let n={};for(let[r,i]of Object.entries(t.instances))i.actionId!==e&&(n[r]=i);let r={};for(let[n,i]of Object.entries(t.histories)){let t=i.filter(t=>t.actionId!==e);t.length&&(r[n]=t)}let i={...t.plans},a={...t.controllers};for(let[n,r]of Object.entries(t.instances))r.actionId===e&&(a[n]?.abort(),delete a[n],delete i[n]);return{definitions:t.definitions.filter(t=>t.id!==e),instances:n,histories:r,plans:i,controllers:a}}),l(!0)},resetAction(e){a(t=>{t.controllers[e]?.abort();let n={...t.instances},r={...t.histories},i={...t.plans},a={...t.controllers};return delete n[e],delete r[e],delete i[e],delete a[e],{instances:n,histories:r,plans:i,controllers:a}}),l(!0)},startAction(e,t,n,r){let i=Date.now();a(a=>{let o={...a.plans};return delete o[e],{instances:{...a.instances,[e]:{id:e,runId:Le(`run`),actionId:t.id,target:n,label:t.label,status:`preparing`,statusText:`Preparing`,error:null,result:void 0,resultsAvailable:!1,logs:[],events:[Re(`started`,`Preparing`,{status:`preparing`},i)],progress:void 0,startedAt:i,completedAt:void 0,cancelRequestedAt:void 0,cancelledAt:void 0}},plans:o,controllers:r?{...a.controllers,[e]:r}:a.controllers}}),l(!0)},resumeAction(e,t){let n=Date.now();a(r=>({...V(r,e,e=>B({...e,status:`running`,statusText:`Resuming`,completedAt:void 0,cancelledAt:void 0},`status`,`Resuming`,{status:`running`},n)),controllers:{...r.controllers,[e]:t}})),l(!0)},cancelAction(e){let t=o().controllers[e],n=o().instances[e];if(!n||!We(n.status))return;let r=Date.now();a(t=>{let n=V(t,e,e=>B(B({...e,status:`cancelled`,statusText:`Cancelled`,completedAt:r,cancelledAt:r,cancelRequestedAt:e.cancelRequestedAt||r},`cancel-requested`,`Cancelling`,void 0,r),`status`,`Cancelled`,{status:`cancelled`},r)),i=t.plans[e];return{...n,plans:i?{...t.plans,[e]:ct(i,r)}:t.plans,controllers:Object.fromEntries(Object.entries(t.controllers).filter(([t])=>t!==e))}}),l(!0),t?.abort()},setActionLabel(e,t){let n=Date.now();a(r=>({...V(r,e,e=>B({...e,label:t},`label`,t,{label:t},n))})),l()},setActionStatus(e,t,n){let r=Date.now(),i=Ge(t)?r:void 0;a(a=>({...V(a,e,e=>B({...e,status:t,statusText:n,completedAt:i,cancelledAt:t===`cancelled`?r:void 0},`status`,n||t,{status:t},r)),controllers:We(t)?a.controllers:Object.fromEntries(Object.entries(a.controllers).filter(([t])=>t!==e))})),l(Ge(t))},setActionError(e,t,n){let r=Date.now(),i=Me(t);a(t=>({...V(t,e,e=>B({...e,status:`error`,statusText:n,error:i,completedAt:r,cancelledAt:void 0},`error`,n||i.message,i,r)),controllers:Object.fromEntries(Object.entries(t.controllers).filter(([t])=>t!==e))})),l(!0)},appendActionLog(e,t,n=`info`,r){let i=Date.now(),o={id:Le(`log`),createdAt:i,level:n,message:t,data:r};a(a=>({...V(a,e,e=>B({...e,logs:[...e.logs,o]},`log`,t,{level:n,data:r},i))})),l()},setActionProgress(e,t){let n=t?Ue(t):void 0;a(t=>({...V(t,e,e=>({...e,progress:n}))}))},setResult(e,t){let n=Date.now();a(r=>({...V(r,e,e=>B({...e,result:t},`result`,`Result recorded`,void 0,n))})),l(!0)},setResultsAvailable(e,t){let n=Date.now();a(r=>({...V(r,e,e=>B({...e,resultsAvailable:t},`results-available`,t?`Results available`:`Results hidden`,{available:t},n))})),l(!0)},setActionPlan(e,t){let n=ot(t);n&&(a(t=>({...V(t,e,e=>({...e,progress:pt(n,`Queued`)})),plans:{...t.plans,[e]:n}})),l(!0))},updateActionTask(e,t,n,r=!1){a(r=>{let i=r.plans[e];if(!i)return r;let a=i.tasks.map(e=>e.id===t?at({...e,...n,status:n.status?it(n.status):e.status,error:n.error?Ne(n.error):n.error===null?null:e.error},0):e),o={...i,tasks:a};return{...V(r,e,e=>({...e,progress:pt(o,n.statusText||n.label)})),plans:{...r.plans,[e]:o}}}),l(r)}}})}function bt(e,t,n){let{store:r,context:i}=e,{instanceKey:a}=i,o=gt(e,t,n);return{...i,canvasProgress:n,instance:r.getState().instances[a],plan:r.getState().plans[a],tasks:o,signal:t,prepareData:e.prepareData,setActionLabel(e){r.getState().setActionLabel(a,e)},setActionStatus(e,t){r.getState().setActionStatus(a,e,t)},setActionError(e,t){r.getState().setActionError(a,e,t)},appendActionLog(e,t,n){r.getState().appendActionLog(a,e,t,n)},setActionProgress(e){r.getState().setActionProgress(a,e)},setResult(e){r.getState().setResult(a,e)},setResultsAvailable(e){r.getState().setResultsAvailable(a,e)}}}function xt(e){return!!e&&typeof e==`object`&&e.version===1&&Array.isArray(e.tasks)}async function St(e){let{store:t,context:n}=e,{definition:r,instanceKey:i,target:a}=n,o=t.getState().instances[i],s=t.getState().controllers[i];if((o?.status===`preparing`||o?.status===`running`)&&(!e.resume||s))return o;let c=new AbortController,l=c.signal,u=ye(n.canvasProgress),d=()=>c.abort();e.signal&&(e.signal.aborted?c.abort():e.signal.addEventListener(`abort`,d,{once:!0})),e.resume&&o&&We(o.status)?t.getState().resumeAction(i,c):t.getState().startAction(i,r,a,c);let f=()=>{let e=t.getState().instances[i];e&&!Ge(e.status)&&t.getState().setActionStatus(i,`cancelled`,`Cancelled`)};try{if(!e.resume&&r.prepare){let n=await r.prepare(bt(e,l,u));if(l.aborted)return f(),t.getState().instances[i];if(n===!1)return t.getState().setActionStatus(i,`idle`),t.getState().instances[i];xt(n)&&t.getState().setActionPlan(i,n)}if(l.aborted)return f(),t.getState().instances[i];let n=t.getState().plans[i];n&&ht(u,n),t.getState().setActionStatus(i,`running`,e.resume?`Resuming`:`Running`);let a=await r.run(bt(e,l,u));if(l.aborted)return f(),t.getState().instances[i];let o=t.getState().instances[i];a!==void 0&&o&&!Ge(o.status)&&t.getState().setResult(i,a),o=t.getState().instances[i],o&&We(o.status)&&((a!==void 0||o?.resultsAvailable)&&t.getState().setResultsAvailable(i,!0),t.getState().setActionStatus(i,`complete`,`Complete`))}catch(e){l.aborted||Ct(e)?f():t.getState().setActionError(i,e,`Error`)}finally{u.clearTrackedStatuses(),e.signal?.removeEventListener(`abort`,d),await t.getState().flushPersistence()}return t.getState().instances[i]}function Ct(e){return e instanceof Error&&(e.name===`AbortError`||e.message.toLowerCase().includes(`aborted`))}function wt(e){return JSON.stringify([e.appId,e.instanceId,e.rootResource.type,e.rootResource.id])}let Tt;function Et(){if(typeof window>`u`)return null;let e=p.default.createInstance({name:`manifest-editor-background-actions-v1`,storeName:`background-actions`});return{async load(t){return e.getItem(wt(t))},async save(t,n){await e.setItem(wt(t),n)},async clear(t){await e.removeItem(wt(t))}}}function Dt(){return Tt===void 0&&(Tt=Et()),Tt}const Ot=(0,u.createContext)(null);function kt({children:e,persistence:t,persistenceKey:n}){let r=U(),i=Hn(),a=(0,u.useMemo)(()=>yt(),[]),o=r.layout.backgroundActions||[],s=(0,u.useMemo)(()=>t===!1?null:t||Dt(),[t]),c=(0,u.useMemo)(()=>n||null,[n]);return(0,u.useEffect)(()=>{a.getState().setDefinitions(o)},[a,o]),(0,u.useEffect)(()=>{let e=c||{appId:i.appId,instanceId:i.instanceId,rootResource:{id:`global`,type:`Manifest`}},t=!1;return a.getState().setPersistence(s,e),s?(s.load(e).then(e=>{t||a.getState().hydrate(e)}).catch(e=>{console.warn(`[manifest-editor/background-actions] Failed to load persisted actions`,e),t||a.getState().hydrate(null)}),()=>{t=!0,a.getState().flushPersistence()}):(a.getState().hydrate(null),()=>void 0)},[i.appId,i.instanceId,s,c?.appId,c?.instanceId,c?.rootResource.id,c?.rootResource.type,a]),(0,u.useEffect)(()=>{let e=()=>{a.getState().flushPersistence()};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[a]),(0,u.createElement)(Ot.Provider,{value:a},e)}function At(){let e=(0,u.useContext)(Ot);if(!e)throw Error(`useBackgroundActionsStore must be used within a BackgroundActionsProvider`);return e}function H(e=e=>e){return(0,f.useStore)(At(),e)}function jt(e){return H(t=>t.instances[e])}function Mt(e){return H(t=>t.histories[e]||[])}async function Nt(e){let t;try{await fetch(e).then(e=>e.json().catch(e=>{console.error(`'${e}' happened!`)})).then(e=>{t={...e}})}catch(e){console.log(e)}return t}function Pt(e,t,n){return`create_${e}_${t}_${(0,h.toRef)(n)?.type||`unknown`}`}function Ft(e,t,n=`text/json`){let r=e instanceof Blob?e:new Blob([e],{type:n}),i=document.createElement(`a`);i.download=t,i.href=window.URL.createObjectURL(r);let a=new MouseEvent(`click`,{view:window,bubbles:!0,cancelable:!0});i.dispatchEvent(a),i.remove()}async function It(e){return navigator.clipboard.writeText(typeof e==`string`?e:JSON.stringify(e,null,2))}function Lt(){return`${Math.random().toString(36).substr(2)}-${Date.now().toString(36)}`}function Rt(e,t){let{default:n,config:r,preset:i,...a}=e,o={metadata:n,layout:{leftPanels:[],rightPanels:[],centerPanels:[],...a},config:r,preset:i},s=t?t(o):o;return{...s,preset:zt(void 0,s.preset)}}function zt(e,t){if(!e&&!t)return;let n=e?.templateFilter&&t?.templateFilter?n=>e.templateFilter(n)&&t.templateFilter(n):t?.templateFilter||e?.templateFilter,r=t?.templateStrategy===`replace`?t.templates||[]:[...e?.templates||[],...t?.templates||[]],i=e?.preview||t?.preview?{...e?.preview||{},...t?.preview||{},actions:[...e?.preview?.actions||[],...t?.preview?.actions||[]]}:void 0;return{...e||{},...t||{},templateFilter:n,templates:n?r.filter(n):r,preview:i}}function Bt(e,t,n){return{...e,metadata:t,config:I(e.config||{},n.config||{}),preset:zt(e.preset,n.preset),layout:{...e.layout,leftPanels:[...(e.layout.leftPanels||[]).filter(e=>!n?.leftPanelIds||n.leftPanelIds.includes(e.id)),...n?.leftPanels||[]],annotations:[...n?.annotations||[],...e.layout.annotations||[]],canvasEditors:[...n?.canvasEditors||[],...e.layout.canvasEditors||[]],creators:[...n?.creators||[],...e.layout.creators||[]],background:[...e.layout?.background||[],...n?.background||[]],backgroundActions:Ae(e.layout?.backgroundActions||[],n?.backgroundActions||[]),editors:[...n?.editors||[],...e.layout.editors||[]],rightPanels:[...e.layout.rightPanels||[],...n?.rightPanels||[]],centerPanels:[...e.layout.centerPanels||[],...n?.centerPanels||[]],modals:[...e.layout.modals||[],...n?.modalPanels||[]]}}}const Vt=[`leftPanels`,`centerPanels`,`rightPanels`,`modalPanels`,`annotations`,`canvasEditors`,`editors`,`creators`,`background`,`backgroundActions`],Ht={plugins:[],enabled:[],disabled:[],globalApps:{},apps:{}};function Ut(){return Ht}function Wt(e=[]){return Array.from(new Set(e.filter(Boolean)))}function Gt(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Kt(e={}){return{...e,enabled:Wt(e.enabled||[]),disabled:Wt(e.disabled||[]),settings:e.settings?{...e.settings}:void 0}}function qt(e){let t={};for(let[n,r]of Object.entries(e?.apps||{}))t[n]=Kt(r);return t}function Jt(e={},t){return{...e,enabled:Wt([...(e.enabled||[]).filter(e=>e!==t),t]),disabled:(e.disabled||[]).filter(e=>e!==t)}}function Yt(e={},t){return{...e,enabled:(e.enabled||[]).filter(e=>e!==t),disabled:Wt([...(e.disabled||[]).filter(e=>e!==t),t])}}function Xt(e={},t){return{...e,enabled:(e.enabled||[]).filter(e=>e!==t),disabled:(e.disabled||[]).filter(e=>e!==t)}}function Zt(e={},t={}){let n=e.enabled||[],r=t.enabled||[],i=e.disabled||[],a=t.disabled||[];return n.length===r.length&&n.every((e,t)=>e===r[t])&&i.length===a.length&&i.every((e,t)=>e===a[t])&&JSON.stringify(e.settings||{})===JSON.stringify(t.settings||{})}function Qt(e,t){let{default:n,config:r,settings:i,...a}=e,o={metadata:n,extension:{...a,config:r},settings:i};return t?t(o):o}function $t(e){return{metadata:e.default,extension:{},settings:e.settings,load:e.load,loadStatus:`idle`}}function en(e){return!!e&&`metadata`in e&&`extension`in e}function tn(e){return!!e&&`load`in e&&`default`in e}function nn(e){return en(e)?e:tn(e)?$t(e):Qt(e)}function rn(e=[]){return e.map(nn)}function an(e,t){let n=new Map(e.map(e=>[e.metadata.id,e]));return t.map(e=>{let t=n.get(e.metadata.id);return t?t.loadStatus===`loaded`&&e.load?{...t,metadata:e.metadata,load:e.load}:t.loadStatus===`loading`&&e.load?{...e,loadStatus:`loading`}:t.loadStatus===`error`&&e.load?{...e,loadStatus:`error`,loadError:t.loadError}:e:e})}function on(e,t,n){let r=e.metadata.supports;if(!r)return!0;if(r.apps?.length){let e=new Set([n,t?.metadata.id].filter(Boolean));if(!r.apps.some(t=>e.has(t)))return!1}if(r.projectTypes?.length){let e=t?.metadata.projectType;if(!e||!r.projectTypes.includes(e))return!1}return!0}function sn(e,t,n){let r=e.metadata.supports;if(!r)return null;if(r.apps?.length){let e=new Set([n,t?.metadata.id].filter(Boolean));if(!r.apps.some(t=>e.has(t)))return`This plugin does not support the current app.`}if(r.projectTypes?.length){let e=t?.metadata.projectType;if(!e||!r.projectTypes.includes(e))return`This plugin does not support the current project type.`}return null}function cn(e,t,n){let r=n?t.apps[n]:void 0,i=n?t.globalApps[n]:void 0,a=e.metadata.id;return r?.disabled?.includes(a)?!1:r?.enabled?.includes(a)?!0:i?.disabled?.includes(a)?!1:i?.enabled?.includes(a)?!0:t.disabled.includes(a)?!1:t.enabled.includes(a)?!0:e.metadata.defaultEnabled===!0}function ln(e,t,n){let r=n?t.apps[n]:void 0,i=n?t.globalApps[n]:void 0,a=e.metadata.id;return r?.disabled?.includes(a)||r?.enabled?.includes(a)?`workspace`:i?.disabled?.includes(a)||i?.enabled?.includes(a)?`global`:t.disabled.includes(a)||t.enabled.includes(a)?`provider`:`default`}function un(e,t,n){let r=[],i=new Set,a=new Set,o=new Set(e.plugins.filter(r=>on(r,t,n)&&cn(r,e,n)).map(e=>e.metadata.id)),s=new Map(e.plugins.map(e=>[e.metadata.id,e])),c=new Set;function l(e){let u=e.metadata.id;if(i.has(u))return!0;if(a.has(u))return!1;if(c.has(u))return yn(`Plugin "${u}" was not enabled because its dependency graph contains a cycle.`),a.add(u),!1;c.add(u);for(let r of e.metadata.dependencies||[]){let e=s.get(r);if(!e||!o.has(r))return yn(`Plugin "${u}" was not enabled because dependency "${r}" is not enabled.`),c.delete(u),a.add(u),!1;if(!on(e,t,n))return yn(`Plugin "${u}" was not enabled because dependency "${r}" is not compatible.`),c.delete(u),a.add(u),!1;if(!l(e))return c.delete(u),a.add(u),!1}return c.delete(u),r.push(e),i.add(u),!0}for(let r of e.plugins)on(r,t,n)&&cn(r,e,n)&&l(r);return r}function dn(e,t){let n=e?.settings?.[t];return Gt(n)?n:{}}function fn(e={},t,n){return{...e,settings:{...e.settings||{},[t]:n}}}function pn(e={},t){let n={...e.settings||{}};return delete n[t],{...e,settings:n}}function mn(e){return{...e?.settings?.defaults||{}}}function hn(e,t,n){let r=e.plugins.find(e=>e.metadata.id===t),i=n?e.globalApps[n]:void 0,a=n?e.apps[n]:void 0;return{...mn(r),...dn(i,t),...dn(a,t)}}function gn(e,t){return{getSettings(n){return hn(e,n,t)}}}function _n(e,t,n,r,i){let a=new Map(t.plugins.map(e=>[e.metadata.id,e])),o=[],s=[],c=new Set,l=e;function u(e){let t=e.metadata.id;if(!o.includes(t)){if(c.has(t)){s.push(`${t} has a circular dependency`);return}c.add(t);for(let t of e.metadata.dependencies||[]){let e=a.get(t);if(!e){s.push(`${t} is not available`);continue}if(!on(e,r,i)){s.push(`${e.metadata.label} is not compatible`);continue}u(e)}c.delete(t),l=Jt(l,t),o.push(t)}}return u(n),s.length?{config:e,enabledIds:[],blocked:s}:{config:l,enabledIds:o,blocked:s}}function vn(e,t){return t===`modalPanels`?e.layout.modals||[]:e.layout[t]||[]}function yn(e){globalThis.process?.env?.NODE_ENV!==`production`&&console.warn(`[manifest-editor/plugin] ${e}`)}function bn(e,t,n,r){if(!r?.length)return;let i=[];for(let a of r){if(n.has(a.id)){yn(`Plugin "${e.metadata.id}" contribution "${a.id}" for "${t}" was skipped because that id already exists.`);continue}n.add(a.id),i.push(a)}return i.length?i:void 0}function xn(e,t){let n=t.extension,r={config:n.config,preset:n.preset,disableSideEffects:n.disableSideEffects};for(let i of Vt){let a=bn(t,i,new Set(vn(e,i).map(e=>e.id)),n[i]);a&&(r[i]=a)}return r}function Sn(e,t,n){if(!t.length)return e;let r=e,i=new Set;for(let a of t){if(!on(a,e,n))continue;let t=(a.metadata.dependencies||[]).filter(e=>!i.has(e));if(t.length){yn(`Plugin "${a.metadata.id}" was not applied because dependencies are missing or later in the plugin order: ${t.join(`, `)}`);continue}let o=xn(r,a);r=Bt(r,r.metadata,o),i.add(a.metadata.id)}let a=new Set(e.layout.leftPanels.map(e=>e.id)),o=r.layout.leftPanels.filter(e=>e.divide),s=r.layout.leftPanels.filter(e=>!e.divide),c=!1,l=s.map(e=>!c&&!a.has(e.id)?(c=!0,{...e,separator:!0}):e);return{...r,config:I(e.config||{},...t.filter(e=>i.has(e.metadata.id)).map(e=>e.extension.config||{}),r.config||{}),layout:{...r.layout,leftPanels:[...l,...o],backgroundActions:Ae([],r.layout.backgroundActions||[])}}}function Cn({plugins:e=[],enabled:t=[],disabled:n=[],globalPluginConfig:r}={}){let i=(e=[])=>Array.from(new Set(e.filter(Boolean)));return(0,f.createStore)(a=>({plugins:e,enabled:i(t),disabled:i(n),globalApps:qt(r),apps:{},setProviderState(e){a(t=>({...t,plugins:an(t.plugins,e.plugins||[]),enabled:i(e.enabled||[]),disabled:i(e.disabled||[]),globalApps:qt(e.globalPluginConfig)}))},setPluginLoading(e){a(t=>({...t,plugins:t.plugins.map(t=>t.metadata.id===e?{...t,loadStatus:`loading`,loadError:void 0}:t)}))},setPluginLoaded(e,t){a(n=>({...n,plugins:n.plugins.map(n=>n.metadata.id===e?{...t,metadata:{...n.metadata,...t.metadata},settings:t.settings||n.settings,load:n.load,loadStatus:`loaded`,loadError:void 0}:n)}))},setPluginLoadError(e,t){a(n=>({...n,plugins:n.plugins.map(n=>n.metadata.id===e?{...n,loadStatus:`error`,loadError:t}:n)}))},setAppConfig(e,t){let n=Kt(t);a(t=>Zt(t.apps[e],n)?t:{...t,apps:{...t.apps,[e]:n}})},setGlobalConfig(e){a(t=>({...t,globalApps:qt(e)}))},setGlobalAppConfig(e,t){let n=Kt(t);a(t=>Zt(t.globalApps[e],n)?t:{...t,globalApps:{...t.globalApps,[e]:n}})},enable(e,t,n=`workspace`){a(r=>({...r,plugins:r.plugins.map(e=>e.metadata.id===t&&e.loadStatus===`error`?{...e,loadStatus:`idle`,loadError:void 0}:e),...n===`global`?{globalApps:{...r.globalApps,[e]:Jt(r.globalApps[e],t)}}:{apps:{...r.apps,[e]:Jt(r.apps[e],t)}}}))},disable(e,t,n=`workspace`){a(r=>({...r,...n===`global`?{globalApps:{...r.globalApps,[e]:Yt(r.globalApps[e],t)}}:{apps:{...r.apps,[e]:Yt(r.apps[e],t)}}}))}}))}const wn=(0,u.createContext)(null),Tn=(0,u.createContext)({});function En({plugins:e,enabled:t,disabled:n,globalPluginConfig:r,saveGlobalPluginConfig:i,children:a}){let o=(0,u.useMemo)(()=>rn(e),[e]),s=(0,u.useMemo)(()=>Cn({plugins:o,enabled:t,disabled:n,globalPluginConfig:r}),[]);(0,u.useEffect)(()=>{s.getState().setProviderState({plugins:o,enabled:t,disabled:n,globalPluginConfig:r})},[s,o,t,n,r]);let c=(0,u.useMemo)(()=>({globalPluginConfig:r,saveGlobalPluginConfig:i}),[r,i]);return(0,u.createElement)(Tn.Provider,{value:c},(0,u.createElement)(wn.Provider,{value:s},a))}function Dn(){return(0,u.useContext)(wn)}function On(){let e=Dn();if(!e)throw Error(`usePluginStoreApi must be used within <PluginProvider />`);return e}function kn(e){let t=Dn();return t?(0,f.useStore)(t,e):e(Ut())}function An(){return kn(e=>({plugins:e.plugins,enabled:e.enabled,disabled:e.disabled,globalApps:e.globalApps,apps:e.apps}))}function jn(e){let t=(0,u.useContext)(Bn),n=(0,u.useContext)(zn),r=An(),i=e||t?.appId;return(0,u.useMemo)(()=>un(r,n,i),[r,n,i])}function Mn(){let e=Dn();return(0,u.useMemo)(()=>e?{enable(t,n,r){e.getState().enable(t,n,r||`workspace`)},disable(t,n,r){e.getState().disable(t,n,r||`workspace`)},setAppConfig(t,n){e.getState().setAppConfig(t,n)},setGlobalAppConfig(t,n){e.getState().setGlobalAppConfig(t,n)}}:{enable(){},disable(){},setAppConfig(){},setGlobalAppConfig(){}},[e])}function Nn(e){let t=(0,u.useContext)(Bn),n=An(),r=e||t?.appId;return(0,u.useMemo)(()=>gn(n,r),[n,r])}function Pn(e,t){let n=(0,u.useContext)(Bn),r=An(),i=t||n?.appId;return(0,u.useMemo)(()=>hn(r,e,i),[r,e,i])}function Fn(e,t){let n=(0,u.useContext)(Bn),r=Dn(),i=An(),a=z(),o=ie(),{saveGlobalPluginConfig:s}=(0,u.useContext)(Tn),c=t||n?.appId||``,l=i.plugins.find(t=>t.metadata.id===e)||null,d=c?i.globalApps[c]:void 0,f=c?i.apps[c]:void 0,p=(0,u.useMemo)(()=>mn(l||void 0),[l]),m=(0,u.useMemo)(()=>dn(d,e),[d,e]),h=(0,u.useMemo)(()=>dn(f,e),[f,e]),g=(0,u.useMemo)(()=>hn(i,e,c),[i,e,c]),_=(0,u.useCallback)(e=>{c&&(r?.getState().setAppConfig(c,e),o({plugins:{...a.plugins||{},apps:{...a.plugins?.apps||{},[c]:e}}}))},[a.plugins,c,o,r]),v=(0,u.useCallback)(t=>{_(fn(f||{},e,t))},[_,e,f]),y=(0,u.useCallback)(()=>{_(pn(f||{},e))},[_,e,f]),b=(0,u.useCallback)(async e=>{if(!c||!s)return;let t=i.globalApps[c]||{},n={apps:{...i.globalApps,[c]:e}};r?.getState().setGlobalAppConfig(c,e);try{await s(n)}catch(e){throw r?.getState().setGlobalAppConfig(c,t),e}},[c,s,i.globalApps,r]),x=(0,u.useCallback)(async t=>{await b(fn(d||{},e,t))},[d,b,e]),S=(0,u.useCallback)(async()=>{await b(pn(d||{},e))},[d,b,e]);return{plugin:l,appId:c,defaults:p,global:m,workspace:h,effective:g,canSaveGlobal:!!s,setWorkspaceSettings:v,resetWorkspaceSettings:y,setGlobalSettings:x,resetGlobalSettings:S}}function In(e,t){let n=An(),r=Dn(),i=(0,u.useMemo)(()=>un(n,e,t),[n,e,t]);return(0,u.useEffect)(()=>{if(r)for(let e of i)!e.load||e.loadStatus===`loading`||e.loadStatus===`loaded`||e.loadStatus===`error`||(r.getState().setPluginLoading(e.metadata.id),e.load().then(t=>{r.getState().setPluginLoaded(e.metadata.id,nn(t))}).catch(t=>{r.getState().setPluginLoadError(e.metadata.id,Ln(t))}))},[r,i]),(0,u.useMemo)(()=>Sn(e,i.filter(e=>!e.load||e.loadStatus===`loaded`),t),[e,i,t])}function Ln(e){return e instanceof Error?e.message:typeof e==`string`?e:`Plugin failed to load.`}function Rn({config:e}){let t=(0,u.useContext)(Bn),n=Dn(),r=t?.appId,i=r?e?.plugins?.apps?.[r]:void 0;return(0,u.useEffect)(()=>{!n||!r||n.getState().setAppConfig(r,i||{})},[n,r,i]),null}const zn=(0,u.createContext)(null),Bn=(0,u.createContext)(null),Vn=(0,u.createContext)({state:null,setState:()=>{}});function Hn(){let e=(0,u.useContext)(Bn);return N(e,`Hook useAppInstance must be used inside <AppProvider />`),e}function U(){let e=(0,u.useContext)(zn);return N(e,`Hook useApp must be used inside <AppProvider />`),e}function Un(){return(0,u.useContext)(Vn)}function Wn(e,t){return e.find(e=>e.id===t)||null}function Gn(){let e=U(),{state:t,setState:n}=Un(),r=e.preset?.templates||[],i=typeof t?.presetTemplateId==`string`?t.presetTemplateId:null;return{templates:r,selectedTemplateId:i,selectedTemplate:(0,u.useMemo)(()=>Wn(r,i),[i,r]),setSelectedTemplateId:(0,u.useCallback)(e=>n({presetTemplateId:e}),[n])}}function Kn(e){let[t,n,r]=(0,l.useLocalStorage)(`app-state/${e.appId}/${e.instanceId}`,e.initialState||{}),i=(0,u.useCallback)(e=>{let t=r.current?JSON.parse(r.current||`{}`):{},i=(typeof e==`function`?e(t):e)||{};n({...t,...i})},[]);(0,u.useEffect)(()=>{e.args&&i(e.args)},[e.appId]);let a=(0,u.useMemo)(()=>({state:t||{},setState:i}),[i,t]);return(0,d.jsx)(Vn.Provider,{value:a,children:e.children})}function qn({instanceId:e,appId:t,args:n,definition:r,children:i,initialState:a}){let o=(0,u.useMemo)(()=>({instanceId:e,appId:t,args:n}),[e,t,n]),s=(0,u.useMemo)(()=>a||{},[e]),c=In(r,t);return(0,d.jsx)(ae,{config:c.config||{},children:(0,d.jsx)(zn.Provider,{value:c,children:(0,d.jsx)(Bn.Provider,{value:o,children:(0,d.jsx)(Kn,{instanceId:o.instanceId,appId:o.appId,args:o.args,initialState:s,children:i})})})})}const Jn=(0,u.createContext)(null);function Yn(){let e=(0,u.useContext)(Jn);return N(e,`Hook useApps must be used inside <MultiAppProvider />`),e}function Xn(e,t=!1){let[n,r]=(0,l.useOptionalLocalStorage)(`SelectedApplication`,e||{id:`splash`},!t);return[n,r]}function Zn({apps:e,initialApp:t,saveCurrentApp:n=!0,instanceId:r,children:i,config:a={}}){let{defaultApp:o=`splash`,collectionApp:s=`collection-editor`,manifestApp:c=`manifest-editor`}=a,[l,f]=Xn(t,n),p=e=>{e===`Manifest`&&f({id:c}),e===`Collection`&&f({id:s})},m=(0,u.useMemo)(()=>({currentApp:l||{id:o},initialApp:t||{id:o},apps:e,changeApp:f,changeProjectType:p}),[t,e,l]),h=e[m.currentApp.id];return!l||!h?null:(0,d.jsx)(qn,{appId:l.id,definition:h,instanceId:l.id+r,args:l.args,children:(0,d.jsx)(Jn.Provider,{value:m,children:i})})}const Qn=g.default.div`
|
|
2
2
|
display: flex;
|
|
3
3
|
align-items: center;
|
|
4
4
|
height: 3em;
|
|
@@ -441,13 +441,13 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
441
441
|
> * {
|
|
442
442
|
min-width: 0;
|
|
443
443
|
}
|
|
444
|
-
`;function mo({panel:e,state:t,actions:n,isLeft:r,pinActions:i=n,transition:a,close:o,available:s=[],style:c,noHeader:l,isModal:f}){let p=(0,u.useContext)(m.ReactVaultContext)||null,[h,g]=(0,u.useState)(!1),_=Un(),v=pi(),{tabs:y,pinnable:b,hideHeader:x}=e?.options||{},S=(0,u.useMemo)(()=>(s||[]).filter(e=>!e.requiresState),[s]),{itemProps:w,isOpen:T,setIsOpen:E}=ir(S.length),[D,O]=(0,u.useState)(``),ee=(0,u.useRef)(void 0);(0,u.useEffect)(()=>g(!1),[_.state.canvasId,e?.id]),(0,u.useEffect)(()=>O(``),[e]),(0,u.useEffect)(()=>(ee.current=O,()=>{ee.current=void 0}),[]);let k=(0,u.useCallback)(e=>{ee.current&&ee.current(e)},[]),A=(0,u.useCallback)(r=>{let i=e?t.stack.length?n.popStack:e.backAction?()=>e&&e.backAction&&e.backAction(t,{...v,current:n},_):null:null;r&&(!i||r.metaKey)&&S.length?(r.preventDefault(),E(!0)):i?.()},[n,_,v,e,E,t,S.length]),j=r=>{n.change({id:r.id,state:r.defaultState,stacked:!!(t.stack.length||e?.backAction)})};if(!e||!t.current)return null;let M=e.backAction||t.stack.length?(0,d.jsx)(lo,{"aria-label":`Back`,onClick:A,children:(0,d.jsx)($a,{"aria-hidden":`true`})}):null,N=(0,d.jsx)(lo,{"aria-label":`Close panel`,onClick:o||n.close,children:(0,d.jsx)(tr,{"aria-hidden":`true`})});return(0,d.jsx)(ao.Provider,{value:k,children:(0,d.jsxs)(so,{"data-modal":f,"data-state":a,"data-flipped":r,style:c,"data-header":!l,children:[l?null:(0,d.jsxs)(co,{"data-tabs":!!y,"data-error":h,children:[(0,d.jsxs)(Ja,{style:{display:`flex`,height:`100%`},children:[e.renderBackAction?e.renderBackAction({backAction:A,fallback:M}):M,S.length?(0,d.jsxs)(Xa,{$open:T,role:`menu`,style:{left:`0.5em`},children:[(0,d.jsx)(Za,{children:`All panels`}),(0,d.jsx)(Qa,{}),S.map((t,n)=>(0,d.jsx)(Ya,{...w[n],onClick:()=>j(t),$active:e.id===t.id,children:t.label},n))]}):null]}),D?(0,d.jsx)(fo,{as:r?`h1`:`h2`,children:D}):x?(0,d.jsx)(uo,{}):(0,d.jsx)(fo,{as:r?`h1`:`h2`,children:e.label}),b?t.pinned?(0,d.jsx)(lo,{"aria-label":`Unpin panel`,onClick:i.unpin,children:(0,d.jsx)(eo,{"aria-hidden":`true`,fill:`orange`})}):(0,d.jsx)(lo,{"aria-label":`Pin panel`,onClick:()=>i.pin({id:e.id,state:t.state}),children:(0,d.jsx)(eo,{"aria-hidden":`true`,fill:`#ddd`})}):null,e.renderCloseAction?e.renderCloseAction({closeAction:o||n.close,fallback:N}):N]}),(0,d.jsx)(po,{className:`OverrideScrollbar`,children:(0,d.jsx)(C.ErrorBoundary,{onError:()=>g(!0),FallbackComponent:io,resetKeys:[_.state.canvasId,e?.id],onReset:()=>g(!1),children:ro(e.render(t.state||e.defaultState||{},{...v,current:n,vault:p,transition:a,isModal:f},_))})})]})})}function ho(e=`vault://homepage-collection.json`){let t=new x.Vault,n=window.localStorage.getItem(`preview-vault-collection`),r=!1;if(n)try{let i=JSON.parse(n);if(i.id&&i.id===e){t.dispatch((0,w.requestResource)({id:i.id}));let e=(0,T.actionListFromResource)(i.id,i);t.dispatch((0,w.batchActions)({actions:e})),r=!0}}catch{}if(!r){let n=(0,T.actionListFromResource)(e,{"@context":`http://iiif.io/api/presentation/3/context.json`,id:e,type:`Collection`,label:{en:[`Recent items`]},items:[]});t.dispatch((0,w.requestResource)({id:e})),t.dispatch((0,w.batchActions)({actions:n}))}return t.on(`after:@iiif/REMOVE_REFERENCE`,n=>{n.action.payload.id===e&&window.localStorage.setItem(`preview-vault-collection`,JSON.stringify(t.toPresentation3({id:e,type:`Collection`})))}),{vault:t,unsubscribe:()=>{},addHistory:(n,r)=>{let i=t.getState();if(n&&r&&(r===`Collection`||r===`Manifest`)){let a=i.iiif.entities.Collection[e];if(a){let i=a.items.findIndex(e=>e.id===n);i===-1?t.dispatch((0,w.addReference)({id:e,type:`Collection`,reference:{id:n,type:r},key:`items`,index:0})):t.dispatch((0,w.reorderEntityField)({id:e,type:`Collection`,key:`items`,startIndex:i,endIndex:0})),window.localStorage.setItem(`preview-vault-collection`,JSON.stringify(t.toPresentation3({id:e,type:`Collection`})))}}},clearHistory:()=>{t.dispatch((0,w.modifyEntityField)({id:e,type:`Collection`,key:`items`,value:[]})),window.localStorage.setItem(`preview-vault-collection`,JSON.stringify(t.toPresentation3({id:e,type:`Collection`})))}}}function go(){return(0,u.useContext)(_o)}const _o=(0,u.createContext)(new x.Vault),vo=(0,u.createContext)({addHistory:(e,t)=>{},clearHistory:()=>{}}),yo=`manifest-editor://homepage-collection.json`;function bo(){return(0,u.useContext)(vo)}function xo(e){let{vault:t,unsubscribe:n,addHistory:r,clearHistory:i}=(0,u.useMemo)(()=>ho(yo),[]);return(0,u.useEffect)(()=>n,[]),(0,d.jsx)(vo.Provider,{value:{addHistory:r,clearHistory:i},children:(0,d.jsx)(_o.Provider,{value:t,children:e.children})})}function So({children:e}){let t=go();return(0,d.jsx)(m.VaultProvider,{vault:t,children:e})}function Co(e,t,n,r,i){let a=(0,m.useVault)(),o=U(),{create:s,edit:c}=ui(),l=(0,u.useMemo)(()=>(0,S.matchBasedOnResource)({type:n,parent:e,index:0,property:t},o.layout.creators||[],{vault:a}),[e,t,o.layout.creators,n,a]),d=e&&l.length!==0,f=(0,u.useCallback)((a,o)=>{if(e)return s({type:n,parent:(0,h.toRef)(e),property:t,index:a,target:r,initialData:o,...i||{}})},[s,e,t,n,i,r]),p=(0,u.useCallback)((a,o,c)=>{if(e)return s({type:n,filter:a,parent:(0,h.toRef)(e),property:t,index:o,target:r,initialData:c,...i||{}})},[s,e,t,n,i,r]);return[d,{create:f,edit:(0,u.useCallback)((n,r)=>{c(n,e?{parent:(0,h.toRef)(e),property:t,index:r}:void 0)},[c,e,t]),createFiltered:p,creator:(0,u.useCallback)((a,o)=>{if(e)return s({type:n,initialCreator:a,parent:(0,h.toRef)(e),property:t,target:r,initialData:o,...i||{}})},[n,t,e,r,s,i]),buttonProps:(0,u.useMemo)(()=>({"data-action-id":Pt(n,t,e)}),[n,t,e])}]}function wo(){let e=(0,m.useVault)(),t=go(),n=U(),r=z();return(0,u.useMemo)(()=>new S.Creator(e,n.layout.creators||[],t,r.creators),[n.layout.creators,r.creators,t,e])}async function To(e){let t=await e.create(),n=Array.isArray(t)?t[0]:t;return n?(e.onCreate?.(),e.close?.(),e.edit?.(n),!0):!1}const Eo=(0,u.createContext)({});function Do(e){return(0,u.useContext)(Eo)[e]||{}}function Oo(e){let t=(0,u.useContext)(Eo),n=(0,u.useMemo)(()=>({...t,[e.id]:e.data}),[t,e.id,e.data]);return(0,d.jsx)(Eo.Provider,{value:n,children:e.children})}const ko=(0,u.memo)(function(e){let t=(0,m.useVault)(),{edit:n,modal:r}=ui(),[i,a]=(0,u.useState)(!1),[o,s]=(0,u.useState)(null),c=wo(),f=z(),p=(0,u.useRef)(!1),g=e.resource.initialData?.selector;Ka(g);let _=Do(e.creator.id),v={targetType:e.resource.type,parent:e.resource.parent?{property:e.resource.property,atIndex:e.resource.index,resource:e.resource.parent}:void 0,target:e.resource.target,initialData:{..._,...e.resource.initialData||{},...e.initialData||{}}},y=async t=>{if(!(i||p.current)){a(!0),p.current=!0;try{await To({create:()=>c.create(e.creator.id,t,v),onCreate:e.onCreate,close:e.skipEditingOnCreate?void 0:()=>{r.popStack(),r.close()},edit:e.skipEditingOnCreate||e.resource.initialData?.skipEditingOnCreate?void 0:t=>n(t,{parent:(0,h.toRef)(e.resource.parent),property:e.resource.property,index:e.resource.index})})}catch(e){s(e?.message||`Unknown error`)}finally{a(!1),p.current=!1}}},b=async()=>!0;if((0,u.useEffect)(()=>{e.resource.initialData?.showEmptyForm||!e.creator.render&&!i&&y({})},[e.creator]),o)return(0,d.jsx)(`div`,{className:`flex flex-col items-center p-4`,children:(0,d.jsx)(l.ErrorMessage,{children:o})});let x=(0,d.jsx)(`div`,{className:`flex flex-col items-center py-8`,children:(0,d.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,d.jsx)(l.Spinner,{}),` `,(0,d.jsx)(`span`,{children:`Loading`})]})});return i?x:e.creator.render?(0,d.jsx)(d.Fragment,{children:(0,d.jsx)(u.Suspense,{fallback:x,children:e.creator.render({vault:t,runCreate:y,validate:b,options:v,config:f.creators?.[(0,S.getCreatorConfigKey)(e.creator)]||{}})})}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(l.EmptyState,{children:`No options available`}),(0,d.jsx)(l.ActionButton,{primary:!0,onPress:()=>y({}),children:e.creator.actionButton||`Create`})]})});function Ao(e){let t=U(),n=(0,m.useVault)(),[r,i]=(0,u.useState)(e.resource.initialCreator||``),[a,o]=(0,u.useState)(),[s,c]=(0,u.useState)(``),[f,p]=(0,u.useState)(!1),[h,g]=(0,u.useState)(``),[_,v]=(0,u.useState)(null),y=(0,u.useRef)(null),b=oo(),x=(0,u.useMemo)(()=>(0,S.matchBasedOnResource)(e.resource,t.layout.creators||[],{vault:n}),[e.resource,t.layout.creators,n]),C=x.some(e=>e.supportsResource);(0,u.useEffect)(()=>{x.length===1&&!r&&!C&&i(x[0].id)},[C,r,x]),(0,u.useEffect)(()=>{C&&!r&&y.current?.focus()},[C,r]);let w=x.find(e=>e.id===r);if((0,u.useEffect)(()=>{w&&b?.(w.label)}),x.length===0)return(0,d.jsx)(l.EmptyState,{children:`Not currently supported`});let T=(e,t)=>{o(t||Po(s)),i(e.id)},E=async t=>{t.preventDefault();let r=s.trim();if(!r||f)return;p(!0),g(``),v(null);let i=Fo(),a=await Promise.all(x.map(async t=>{if(!t.supportsResource)return null;try{let a=await t.supportsResource(r,i,{vault:n,resource:e.resource});return a?{creator:t,initialData:No(r,a).initialData}:null}catch(e){return{creator:t,error:e?.message||`Could not check this link`}}})),o=a.filter(jo),c=a.filter(Mo);if(p(!1),o.length===1){T(o[0].creator,o[0].initialData);return}if(o.length>1){v(o),g(`Multiple creators can use this link. Choose one below.`);return}g(c[0]?.error||`No creator recognised this link. Choose one below.`)},D=(0,d.jsx)(l.ModalBackSlot,{children:(0,d.jsx)(l.IconButton,{root:document.getElementById(`headlessui-portal-root`)||void 0,label:`Back to Add content options`,className:`group`,placement:`right`,onPress:()=>{i(``),o(void 0)},children:(0,d.jsx)(l.GridIcon,{className:`text-2xl opacity-50 group-hover:opacity-70`})})});if(w)return w.hiddenModal?(0,d.jsxs)(d.Fragment,{children:[D,(0,d.jsx)(ko,{creator:w,resource:e.resource,initialData:a})]}):(0,d.jsxs)(`div`,{children:[D,(0,d.jsx)(`div`,{className:`p-2 py-6`,children:(0,d.jsx)(ko,{creator:w,resource:e.resource,initialData:a})})]});let O=_?.length?_.map(e=>e.creator):x,ee=new Map(_?.map(e=>[e.creator.id,e.initialData]));return(0,d.jsxs)(d.Fragment,{children:[C?(0,d.jsxs)(`form`,{className:`p-4 pb-0`,onSubmit:E,children:[(0,d.jsx)(`label`,{className:`block text-sm font-medium text-gray-700`,htmlFor:`creator-resource-link`,children:`Paste a link`}),(0,d.jsxs)(`div`,{className:`mt-1 flex gap-2`,children:[(0,d.jsx)(`input`,{ref:y,id:`creator-resource-link`,className:`min-w-0 flex-1 rounded border border-gray-300 px-3 py-2 text-sm`,value:s,onChange:e=>{c(e.currentTarget.value),g(``),v(null)},placeholder:`https://example.org/resource`,type:`url`}),(0,d.jsx)(l.ActionButton,{primary:!0,type:`submit`,isDisabled:!s.trim()||f,children:f?`Checking`:`Use link`})]}),h?(0,d.jsx)(`div`,{className:`mt-2 text-sm text-gray-600`,role:`status`,children:h}):null]}):null,(0,d.jsx)(l.CreatorGrid,{label:`Select a type`,items:O.map(e=>({id:e.id,title:e.label,description:e.summary||``,icon:e.icon,onClick:()=>T(e,ee.get(e.id))}))})]})}function jo(e){return!!e&&!(`error`in e)}function Mo(e){return!!e&&`error`in e}function No(e,t){return typeof t==`object`?t:{initialData:Po(e)}}function Po(e){let t=e.trim();return t?{url:t,youtubeUrl:t}:void 0}function Fo(){let e=new Map,t=new Map,n=new Map,r=t=>(e.has(t)||e.set(t,fetch(t).then(e=>{if(!e.ok)throw Error(`Could not load ${t}`);return e.text()})),e.get(t)),i=e=>(n.has(e)||n.set(e,fetch(e,{method:`HEAD`}).then(t=>{if(!t.ok)throw Error(`Could not check ${e}`);return t})),n.get(e));return{text:r,head:i,json(e){return t.has(e)||t.set(e,r(e).then(e=>JSON.parse(e))),t.get(e)},async contentType(e){return(await i(e)).headers.get(`content-type`)||``}}}const Io={id:`@manifest-editor/creator`,label:`Add content`,options:{hideHeader:!0,tabs:!1},render(e){return(0,d.jsx)(Ao,{resource:e})}},Lo={color:{main:`#B84C74`,mainHover:`#4a89ff`,logoPink:`#E94581`,white:`white`,grey:`grey`,black:`black`,lightgrey:`#F8F9FA`,mediumgrey:`#dddddd`,danger:`#a90e21`,warning:`#e38627`,lightdanger:`#ffeaea`,lightsuccess:`#c5e8c5`,success:`#6ccd55`,greyOverlay:`rgba(0, 0, 0, 0.2)`,highlight:`#faeed7`},iiifColor:{manifest:`rgba(0, 0, 0, 0.2)`,canvas:`rgba(255, 222, 219, 0.8)`,service:`rgba(13, 110, 253, 0.8)`,annotation:`rgba(247, 226, 173, 0.8)`,contentResource:`rgba(207, 247, 255, 0.8)`,ranges:`rgba(144, 213, 157, 0.8)`},padding:{xs:`0.25rem`,small:`0.5rem`,medium:`1rem`,large:`2rem`},device:{mobile:`375px`,tablet:`768px`,laptop:`992px`,desktop:`1200px`},shadows:{standard:`rgba(0, 0, 0, 0.1) 0px 1px 3px 0px, rgba(0, 0, 0, 0.05) 0px 5px 15px 0px`,bottom:`rgba(0, 0, 0, 0.1) 0px 4px 2px -2px`}};function Ro(e){let{}=e,t=(0,m.useVault)(),n=U(),r=(0,u.useMemo)(()=>(0,S.matchBasedOnResource)(e.resource,n.layout.creators||[],{vault:t}),[e.resource,n.layout.creators,t]);return r.length===0?(0,d.jsx)(`div`,{children:`No supported creators found`}):(0,d.jsx)(`div`,{children:(0,d.jsxs)(l.Tabs,{className:`w-full flex-1 overflow-hidden flex flex-col`,children:[(0,d.jsx)(l.TabList,{className:`flex-1 overflow-hidden w-full flex text-sm whitespace-nowrap`,items:r,children:e=>(0,d.jsx)(l.Tab,{id:e.id,children:e.label})}),r.map(t=>(0,d.jsx)(l.TabPanel,{id:t.id,className:`p-2`,children:(0,d.jsx)(g.ThemeProvider,{theme:Lo,children:(0,d.jsx)(ko,{creator:t,resource:e.resource,onCreate:e.onCreate,skipEditingOnCreate:!0})})},t.id))]})})}function zo({fallback:e,backAction:t}){let n=Xr(),{back:r}=Jr();return n.length?(0,d.jsx)(lo,{"aria-label":`Back`,onClick:r,children:(0,d.jsx)($a,{"aria-hidden":`true`})}):e}function Bo({closeAction:e,fallback:t}){let n=Xr();return Yr()||n.length?(0,d.jsx)(lo,{"aria-label":`Close panel`,onClick:()=>{e()},children:(0,d.jsx)(tr,{"aria-hidden":`true`})}):t}function Vo(e,t,n,r){let i=t.filter(t=>t.resourceType===e.resource.source.type);if(i.length===0)return null;for(let t of i){let i=[],a={},o=e.property===`partOf`,s=(t.editors||[]).filter(t=>{if(o&&t.id!==`@manifest-editor/part-of-reference`||r.hideTabs&&r.hideTabs.includes(t.id)||r.onlyTabs&&!r.onlyTabs.includes(t.id))return!1;if(t.supports.sortKey){if(i.includes(t.supports.sortKey))return!1;t.supports.sortFallback&&(a[t.supports.sortKey]=t)}return n.edit&&!t.supports.edit||t.supports.custom&&t.supports.custom(e,n.vault)===!1?!1:(t.supports.sortKey&&i.push(t.supports.sortKey),!0)}),c=Object.keys(a);for(let e of c)!i.includes(e)&&a[e]&&!s.includes(a[e])&&s.push(a[e]);if(s.length)return{...t,editors:s}}return null}function Ho({currentTab:e=void 0}){let t=Yr(),n=(0,u.useContext)(m.ResourceReactContext),r=U(),i=W(),a=(0,m.useVault)(),{change:o}=ui(),s=oo(),{editorConfig:c}=z(),f=t?.resource.source?.id,p=t?.resource.source?.type,h=f!==i.id;f&&h&&i.type===`Collection`&&p===`Collection`&&(p=`EmbeddedCollection`);let g=(p?c[p]:c.All)||{},_=(0,u.useMemo)(()=>{let e={...n},r=t?.resource.source.id,i=t?.resource.source.type,a={Collection:`collection`,Manifest:`manifest`,Range:`range`,Canvas:`canvas`,Annotation:`annotation`,AnnotationPage:`annotationPage`};return i&&a[i]&&(e[a[i]]=r),e},[t,n]);function v(e){return t?(0,d.jsx)(m.ResourceReactContext.Provider,{value:_,children:e}):e}let y=(0,u.useMemo)(()=>{if(!t)return null;let e=r.layout.editors||[],n=(r.layout.resources||[]).map(t=>typeof t==`string`?{id:`@default/`+t,label:t,resourceType:t,auto:!0,editors:e.filter(e=>e.supports.resourceTypes.includes(t))}:t);return Vo(t,n,{edit:!0,vault:a},g)},[t,r]);(0,u.useEffect)(()=>{s(y?.label||``)},[y]),(0,u.useEffect)(()=>{let t=y?.editors.map(e=>e.id)||[];t.find(t=>t===e)||o(`@manifest-editor/editor`,{currentTab:t[0]})},[y?.editors,e,o]);let b=(0,u.useMemo)(()=>(y?.editors||[]).map(e=>({id:e.id,label:e.label,renderComponent:()=>e.component(g)})),[y?.editors,g]);if(!t||!y)return null;if(g.singleTab){let e=(y?.editors||[]).find(e=>e.id===g.singleTab);if(e)return v((0,d.jsx)(`div`,{className:`w-full`,children:e.component(g)},t.resource.source?.id))}return v((0,d.jsx)(l.SidebarTabs,{isNested:h,rootResource:i,menuId:t.resource.source.id,menu:b,selectedKey:e,onSelectionChange:e=>{o(`@manifest-editor/editor`,{currentTab:e})}},t.resource.source?.id))}const Uo={id:`@manifest-editor/editor`,label:`Editor`,options:{hideHeader:!0,tabs:!0,minWidth:400},renderBackAction:({backAction:e,fallback:t})=>(0,d.jsx)(zo,{backAction:e,fallback:t}),renderCloseAction:({closeAction:e,fallback:t})=>(0,d.jsx)(Bo,{closeAction:e,fallback:t}),render({currentTab:e}){return(0,d.jsx)(Ho,{currentTab:e})}};function Wo(e){let[t,n]=(0,u.useState)(!1),r=(0,u.useRef)(null),i=(0,u.useRef)(0);function a(t){i.current--,!(t&&i.current!==0)&&(r.current&&(clearTimeout(r.current),r.current=0),r.current=setTimeout(()=>{n(!1)},e))}function o(){i.current++,r.current&&clearTimeout(r.current),n(!0)}return(0,u.useMemo)(()=>[t,{set:o,clear:a}],[t])}function Go(e){return e?typeof e==`string`?{src:e,alt:``}:e:null}function Ko(e){return e?typeof e==`string`?e:e.name:null}function qo(e){let t=e.extension,n=t.leftPanels?.[0]||t.centerPanels?.[0]||t.rightPanels?.[0]||t.modalPanels?.[0];return n?{id:n.id,label:n.label||`Open plugin`,modal:t.modalPanels?.some(e=>e.id===n.id)||!1}:null}function Jo(e){return e instanceof Error?e.message:`Plugin configuration could not be saved.`}function Yo(e){return(0,d.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,...e,children:[(0,d.jsx)(`path`,{d:`M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z`}),(0,d.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]})}function Xo(e){return(0,d.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,...e,children:[(0,d.jsx)(`path`,{d:`M7 7h10v10`}),(0,d.jsx)(`path`,{d:`M7 17 17 7`})]})}function Zo(){let e=U(),{appId:t}=Hn(),n=z(),r=ie(),i=An(),a=Mn(),o=ui(),{saveGlobalPluginConfig:s}=(0,u.useContext)(Tn),[c,f]=(0,u.useState)(!1),[p,m]=(0,u.useState)(``),[h,g]=(0,u.useState)(null),[_,v]=(0,u.useState)(null),[y,b]=(0,u.useState)(null),x=(0,u.useMemo)(()=>new Set(un(i,e,t).map(e=>e.metadata.id)),[i,e,t]),S=(0,u.useMemo)(()=>{let n=p.trim().toLowerCase();return i.plugins.filter(r=>{let i=on(r,e,t);return!c&&!i?!1:!n||[r.metadata.label,r.metadata.id,r.metadata.description,Ko(r.metadata.author),...r.metadata.tags||[]].filter(Boolean).join(` `).toLowerCase().includes(n)})},[e,t,i.plugins,p,c]),C=h&&i.plugins.find(e=>e.metadata.id===h)||null;if(!i.plugins.length)return null;function w(e){a.setAppConfig(t,e),r({plugins:{...n.plugins||{},apps:{...n.plugins?.apps||{},[t]:e}}})}async function T(e){if(!s){b(`Global plugin settings are not available in this host.`);return}let n=i.globalApps[t]||{},r={apps:{...i.globalApps,[t]:e}};a.setGlobalAppConfig(t,e);try{await s(r)}catch(e){a.setGlobalAppConfig(t,n),b(Jo(e))}}async function E(n,r,a){b(null),v(`${a}:${n.metadata.id}`);let o=a===`global`?i.globalApps[t]||{}:i.apps[t]||{},s=r?_n(o,i,n,e,t):{config:Yt(o,n.metadata.id),blocked:[]};if(s.blocked.length){v(null),b(`Cannot enable ${n.metadata.label}: ${s.blocked.join(`, `)}.`);return}a===`global`?await T(s.config):w(s.config),v(null)}function D(e){let t=qo(e);if(t){if(t.modal){o.modal.open({id:t.id});return}o.open(t.id)}}return(0,d.jsxs)(`section`,{className:`flex flex-col gap-3 border-t border-gray-200 pt-4 mt-4`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,d.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,d.jsx)(`h3`,{className:`font-semibold text-sm text-gray-900`,children:`Plugins`})}),(0,d.jsx)(`button`,{type:`button`,className:`rounded border border-gray-200 bg-white px-2 py-1 text-xs text-gray-500 hover:text-gray-700 hover:border-gray-300 transition-colors`,onClick:()=>f(e=>!e),children:c?`Compatible only`:`Show all`})]}),(0,d.jsx)(`input`,{"aria-label":`Search plugins`,className:`rounded border border-gray-200 px-2.5 py-1.5 text-xs focus:border-me-primary-500 focus:ring-2 focus:ring-me-primary-500/20 focus:outline-none`,type:`search`,placeholder:`Search plugins…`,value:p,onChange:e=>m(e.currentTarget.value)}),y?(0,d.jsx)(`div`,{className:`rounded border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700`,children:y}):null,(0,d.jsx)(`div`,{className:`flex flex-col gap-2`,children:S.map(n=>{let r=cn(n,i,t),a=x.has(n.metadata.id),o=r&&n.loadStatus===`loading`,s=r&&n.loadStatus===`error`?n.loadError:null,c=Go(n.metadata.image),u=r&&!a&&!o&&!s,f=on(n,e,t),p=sn(n,e,t),m=qo(n),h=!!n.settings,v=_===`workspace:${n.metadata.id}`;return(0,d.jsxs)(`article`,{className:`flex gap-2.5 rounded-lg border bg-white p-3 text-sm transition-colors ${a?`border-gray-200`:`border-gray-100 bg-gray-50`} ${f?``:`bg-gray-100`}`,children:[c?(0,d.jsx)(`img`,{className:`h-9 w-9 rounded object-cover flex-none mt-0.5`,src:c.src,alt:c.alt||n.metadata.label}):(0,d.jsx)(`div`,{className:`h-9 w-9 rounded flex items-center justify-center flex-none mt-0.5 text-lg ${a?`bg-me-primary-50 text-me-primary-500`:`bg-gray-100 text-gray-600`}`,children:(0,d.jsx)(Yo,{className:`w-4 h-4`})}),(0,d.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1`,children:[(0,d.jsxs)(`div`,{className:`flex items-start justify-between gap-1`,children:[(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 min-w-0`,children:[(0,d.jsx)(`span`,{className:`font-medium text-gray-900 text-xs`,children:n.metadata.label}),n.metadata.official?(0,d.jsxs)(`span`,{className:`rounded-full text-me-primary-500 px-1.5 py-0 text-[9px] font-bold inline-flex items-center gap-1`,children:[(0,d.jsx)(l.CheckIcon,{className:`w-3 h-3`}),` Verified`]}):null,n.metadata.version?(0,d.jsx)(`span`,{className:`text-[10px] text-gray-600`,children:n.metadata.version}):null]}),(0,d.jsxs)(`div`,{className:`flex items-center gap-1 flex-none`,children:[h?(0,d.jsx)(`button`,{type:`button`,title:`Configure plugin`,"aria-label":`Configure ${n.metadata.label}`,className:`rounded p-1 text-gray-600 hover:text-gray-700 hover:bg-gray-100 transition-colors`,onClick:()=>g(n.metadata.id),children:(0,d.jsx)(Yo,{className:`w-3.5 h-3.5`})}):null,a&&m?(0,d.jsx)(`button`,{type:`button`,title:`Open ${m.label}`,"aria-label":`Open ${m.label}`,className:`rounded p-1 text-me-primary-500 hover:bg-me-primary-50 transition-colors`,onClick:()=>D(n),children:(0,d.jsx)(Xo,{className:`w-3.5 h-3.5`})}):null,(0,d.jsx)(`button`,{type:`button`,disabled:!f||v,onClick:()=>E(n,!r,`workspace`),className:`relative inline-flex h-5 w-9 flex-none items-center rounded-full transition-colors disabled:opacity-40 focus:outline-none focus:ring-2 focus:ring-me-primary-500/30 ${r?`bg-me-primary-500`:`bg-gray-200`}`,title:r?`Disable plugin`:`Enable plugin`,"aria-label":`${r?`Disable`:`Enable`} ${n.metadata.label}`,children:(0,d.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white shadow transition-transform ${r?`translate-x-4`:`translate-x-0.5`}`})})]})]}),n.metadata.description?(0,d.jsx)(`p`,{className:`text-xs text-gray-500 leading-relaxed`,children:n.metadata.description}):null,o?(0,d.jsx)(`span`,{className:`text-xs text-gray-500`,children:`Loading plugin…`}):null,s?(0,d.jsx)(`span`,{className:`text-xs text-red-600`,children:s}):null,u?(0,d.jsx)(`span`,{className:`text-xs text-amber-600`,children:`Waiting for required dependencies`}):null,!f&&p?(0,d.jsx)(`span`,{className:`text-xs text-gray-600`,children:p}):null]})]},n.metadata.id)})}),S.length?null:(0,d.jsx)(`div`,{className:`rounded-lg border border-gray-100 bg-gray-50 p-4 text-center text-xs text-gray-500`,children:`No plugins found.`}),C?(0,d.jsx)(l.Modal,{title:`Configure ${C.metadata.label}`,onClose:()=>g(null),width:`560px`,children:(0,d.jsx)(Qo,{plugin:C,onClose:()=>g(null),canSaveGlobal:!!s})}):null]})}function Qo({plugin:e,onClose:t,canSaveGlobal:n}){let r=Fn(e.metadata.id),[i,a]=(0,u.useState)(`workspace`),[o,s]=(0,u.useState)({}),[c,l]=(0,u.useState)(!1),[f,p]=(0,u.useState)(!1),[m,h]=(0,u.useState)(null),g=i===`global`?r.global:r.workspace;(0,u.useEffect)(()=>{s({...g}),h(null),p(!1)},[e.metadata.id,i]);async function _(){let t=e.settings?.validate?.(o);if(t){h(t);return}l(!0),h(null);try{i===`global`?await r.setGlobalSettings(o):r.setWorkspaceSettings(o),p(!0),setTimeout(()=>p(!1),2e3)}catch(e){h(Jo(e))}finally{l(!1)}}async function v(){l(!0),h(null);try{i===`global`?await r.resetGlobalSettings():r.resetWorkspaceSettings(),s({})}catch(e){h(Jo(e))}finally{l(!1)}}let y=n&&r.canSaveGlobal;return(0,d.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[y?(0,d.jsxs)(`div`,{className:`flex items-center gap-1 px-5 pt-4 pb-3 border-b border-gray-100`,children:[(0,d.jsx)(`span`,{className:`text-xs text-gray-500 mr-2`,children:`Scope:`}),(0,d.jsx)(`button`,{type:`button`,className:`rounded-full px-3 py-1 text-xs font-medium transition-colors ${i===`workspace`?`bg-me-primary-500 text-white`:`bg-gray-100 text-gray-600 hover:bg-gray-200`}`,onClick:()=>a(`workspace`),children:`This workspace`}),(0,d.jsx)(`button`,{type:`button`,className:`rounded-full px-3 py-1 text-xs font-medium transition-colors ${i===`global`?`bg-me-primary-500 text-white`:`bg-gray-100 text-gray-600 hover:bg-gray-200`}`,onClick:()=>a(`global`),children:`All workspaces`})]}):null,m?(0,d.jsx)(`div`,{className:`mx-5 mt-4 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700`,children:m}):null,(0,d.jsx)(`div`,{className:`flex-1 overflow-y-auto p-5`,children:(0,d.jsx)(`div`,{className:`flex flex-col gap-3`,children:e.settings?.render?e.settings.render({plugin:e,appId:r.appId,scope:i,value:o,defaults:r.defaults,effective:r.effective,onChange:s}):e.settings?.fields?.length?e.settings.fields.map(e=>(0,d.jsx)($o,{field:e,draft:o,setDraft:s},e.id)):(0,d.jsx)(`div`,{className:`rounded-lg border border-gray-100 bg-gray-50 p-4 text-center text-sm text-gray-500`,children:`This plugin has no configurable settings.`})})}),(0,d.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-gray-100 px-5 py-4`,children:[(0,d.jsx)(`button`,{type:`button`,className:`text-xs text-gray-600 hover:text-gray-700 transition-colors disabled:opacity-40`,disabled:c,onClick:v,children:`Reset to defaults`}),(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[f?(0,d.jsx)(`span`,{className:`text-xs text-green-600`,children:`✓ Saved`}):null,(0,d.jsx)(`button`,{type:`button`,className:`rounded-lg bg-me-primary-500 px-4 py-2 text-sm font-medium text-white hover:bg-me-primary-600 disabled:opacity-50 transition-colors`,disabled:c,onClick:_,children:c?`Saving…`:`Save ${i}`})]})]})]})}function $o({field:e,draft:t,setDraft:n}){let r=t[e.id],i=`plugin-setting-${e.id}`;function a(r){n({...t,[e.id]:r})}let o=(0,d.jsx)(`label`,{className:`text-sm font-medium text-gray-900`,htmlFor:i,children:e.label}),s=`rounded-lg border border-gray-200 bg-white px-3 py-2 text-sm focus:border-me-primary-500 focus:ring-2 focus:ring-me-primary-500/20 focus:outline-none`;return e.type===`boolean`?(0,d.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-gray-100 bg-white px-4 py-3`,children:[(0,d.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[o,e.description?(0,d.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.description}):null]}),(0,d.jsx)(`input`,{id:i,type:`checkbox`,checked:r===!0,onChange:e=>a(e.currentTarget.checked),className:`h-4 w-4 rounded border-gray-300 text-me-primary-500 focus:ring-me-primary-500`})]}):e.type===`textarea`?(0,d.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-gray-100 bg-white px-4 py-3`,children:[o,e.description?(0,d.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.description}):null,(0,d.jsx)(`textarea`,{id:i,className:`${s} min-h-24 resize-y`,value:typeof r==`string`?r:``,placeholder:e.placeholder,onChange:e=>a(e.currentTarget.value)})]}):e.type===`select`?(0,d.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-gray-100 bg-white px-4 py-3`,children:[o,e.description?(0,d.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.description}):null,(0,d.jsxs)(`select`,{id:i,className:s,value:r===void 0?``:String(r),onChange:t=>{let n=e.options?.find(e=>String(e.value)===t.currentTarget.value);a(n?n.value:t.currentTarget.value)},children:[(0,d.jsx)(`option`,{value:``,children:`Default`}),(e.options||[]).map(e=>(0,d.jsx)(`option`,{value:String(e.value),children:e.label},String(e.value)))]})]}):(0,d.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-gray-100 bg-white px-4 py-3`,children:[o,e.description?(0,d.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.description}):null,(0,d.jsx)(`input`,{id:i,className:s,type:e.type===`number`?`number`:`text`,value:typeof r==`string`||typeof r==`number`?r:``,placeholder:e.placeholder,onChange:t=>{a(e.type===`number`?Number(t.currentTarget.value):t.currentTarget.value)}})]})}function es(){let e=Cr(),t=W(),n=z(),r=ie(),[i,a]=Wo(2e3);function o(e){e.preventDefault();let t=new FormData(e.target),i={defaultPreview:t.get(`defaultPreview`),i18n:{...n.i18n||{},advancedLanguageMode:t.get(`advancedLanguageMode`)===`on`,availableLanguages:(t.get(`availableLanguages`)||``).split(`,`).map(e=>e.trim()),defaultLanguage:t.get(`defaultLanguage`)},export:{...n.export||{},version:t.get(`isVersion2`)===`on`?2:3,baseIdentifier:t.get(`base`)||null},plugins:n.plugins,editorFeatureFlags:{...n.editorFeatureFlags||{},rememberCanvasId:t.get(`rememberCanvasId`)===`on`,rememberLeftPanelId:t.get(`rememberLeftPanelId`)===`on`,annotationPopups:t.get(`annotationPopups`)===`on`,manifestGridOptions:t.get(`manifestGridOptions`)===`on`,enableMultiImageCanvases:t.get(`enableMultiImageCanvases`)===`on`,enableMultiMediaCanvases:t.get(`enableMultiMediaCanvases`)===`on`}};r(i),a.set(),a.clear()}return(0,d.jsxs)(l.Sidebar,{children:[(0,d.jsx)(l.SidebarHeader,{title:`Workspace configuration`}),i?(0,d.jsx)(`div`,{className:`bg-me-primary-500 text-white p-3 text-sm`,children:`Changes saved`}):null,(0,d.jsx)(l.SidebarContent,{className:`p-4`,children:(0,d.jsxs)(l.Form.Form,{onSubmit:o,className:`flex flex-col gap-3`,children:[(0,d.jsxs)(l.Form.InputContainer,{children:[(0,d.jsx)(l.Form.Label,{htmlFor:`defaultLanguage`,children:`Default Language`}),(0,d.jsx)(l.Form.Input,{type:`text`,name:`defaultLanguage`,id:`defaultLanguage`,defaultValue:n.i18n?.defaultLanguage||``})]}),(0,d.jsxs)(l.Form.InputContainer,{children:[(0,d.jsx)(l.Form.Label,{htmlFor:`availableLanguages`,children:`Available Languages`}),(0,d.jsx)(l.Form.Input,{type:`text`,name:`availableLanguages`,id:`availableLanguages`,defaultValue:(n.i18n?.availableLanguages||[]).join(`, `)})]}),(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,className:`my-3`,children:[(0,d.jsx)(l.Form.Input,{type:`checkbox`,name:`advancedLanguageMode`,id:`advancedLanguageMode`,defaultChecked:n.i18n?.advancedLanguageMode||!1}),(0,d.jsx)(l.Form.Label,{htmlFor:`advancedLanguageMode`,children:`Advanced Language Mode`})]}),(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,className:`my-3`,children:[(0,d.jsx)(l.Form.Input,{type:`checkbox`,name:`textGranularityEnabled`,id:`textGranularityEnabled`,defaultChecked:n.i18n?.textGranularityEnabled||!1}),(0,d.jsx)(l.Form.Label,{htmlFor:`textGranularityEnabled`,children:`Enable text granularity`})]}),(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,className:`my-3`,children:[(0,d.jsx)(l.Form.Input,{type:`checkbox`,name:`rememberCanvasId`,id:`rememberCanvasId`,defaultChecked:n.editorFeatureFlags?.rememberCanvasId||!1}),(0,d.jsx)(l.Form.Label,{htmlFor:`rememberCanvasId`,children:`Remember Canvas ID`})]}),(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,className:`my-3`,children:[(0,d.jsx)(l.Form.Input,{type:`checkbox`,name:`rememberLeftPanelId`,id:`rememberLeftPanelId`,defaultChecked:n.editorFeatureFlags?.rememberLeftPanelId||!1}),(0,d.jsx)(l.Form.Label,{htmlFor:`rememberLeftPanelId`,children:`Remember Left panel`})]}),(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,className:`my-3`,children:[(0,d.jsx)(l.Form.Input,{type:`checkbox`,name:`manifestGridOptions`,id:`manifestGridOptions`,defaultChecked:n.editorFeatureFlags?.manifestGridOptions||!1}),(0,d.jsx)(l.Form.Label,{htmlFor:`manifestGridOptions`,children:`Manifest Grid Options`})]}),(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,className:`my-3`,children:[(0,d.jsx)(l.Form.Input,{type:`checkbox`,name:`isVersion2`,id:`isVersion2`,defaultChecked:n.export?.version===2}),(0,d.jsxs)(l.Form.Label,{htmlFor:`isVersion2`,children:[`Export Presentation 2 `,t.type,`s`]})]}),(0,d.jsxs)(l.Form.InputContainer,{children:[(0,d.jsx)(l.Form.Label,{htmlFor:`defaultPreview`,children:`Default preview`}),(0,d.jsx)(`div`,{children:e.configs.map((e,t)=>e.type===`iiif-preview-service`?null:(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,children:[(0,d.jsx)(l.Form.Input,{type:`radio`,id:e.id,name:`defaultPreview`,value:e.id,defaultChecked:n.defaultPreview?n.defaultPreview===e.id:t===0}),(0,d.jsx)(`label`,{htmlFor:e.id,children:e.label})]},e.id))})]}),t.type===`Manifest`?(0,d.jsx)(`a`,{className:`text-sm text-me-primary-500 hover:underline hover:text-me-primary-600`,href:window.location.pathname.includes(`/exhibition`)?window.location.pathname.replace(`/exhibition`,``)||`/`:`${window.location.pathname}/exhibition`,children:window.location.pathname.includes(`/exhibition`)?`Return to Manifest Editor`:`Go to Exhibition Editor`}):null,(0,d.jsx)(Zo,{}),(0,d.jsx)(`div`,{className:`mt-5`,children:(0,d.jsx)(l.ActionButton,{type:`submit`,children:`Save changes`})})]})})]})}function ts(e){let t=new Map;for(let n of e){if(!n.configuration?.fields.length)continue;let e=(0,S.getCreatorConfigKey)(n);(!t.has(e)||n.id===e)&&t.set(e,n)}return Array.from(t.values())}function ns(){let e=U(),t=z(),n=ie(),r=(0,u.useMemo)(()=>ts(e.layout.creators||[]),[e.layout.creators]);function i(e,t){let r=(0,S.getCreatorConfigKey)(e),i=new FormData(t),a={};for(let t of e.configuration?.fields||[])t.type===`checkbox`&&(a[t.id]=i.get(t.id)===`on`);n({creators:{[r]:a}})}return r.length?(0,d.jsx)(`div`,{className:`flex max-w-3xl flex-col gap-6`,children:r.map(e=>(0,d.jsxs)(l.Form.Form,{className:`flex flex-col gap-3 border-b border-gray-100 pb-5 last:border-b-0`,onChange:t=>i(e,t.currentTarget),children:[(0,d.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,d.jsx)(`h3`,{className:`text-base font-semibold text-gray-900`,children:e.label}),e.summary?(0,d.jsx)(`p`,{className:`text-sm text-gray-500`,children:e.summary}):null]}),e.configuration?.fields.map(n=>{let r=(0,S.getCreatorConfigKey)(e),i=t.creators?.[r]?.[n.id],a=`${r}-${n.id}`;return n.type===`checkbox`?(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,className:`my-1 items-start`,children:[(0,d.jsx)(l.Form.Input,{type:`checkbox`,name:n.id,id:a,defaultChecked:typeof i==`boolean`?i:n.defaultValue||!1}),(0,d.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,d.jsx)(l.Form.Label,{htmlFor:a,children:n.label}),n.summary?(0,d.jsx)(`p`,{className:`text-sm text-gray-500`,children:n.summary}):null]})]},n.id):null})]},(0,S.getCreatorConfigKey)(e)))}):(0,d.jsx)(l.EmptyState,{children:`No creator settings available`})}function rs(){return(0,f.createStore)((e,t)=>({specificMenus:{},resourceMenus:{},hookMenuItem(t){let n=Lt(),r=t.resource?.id||``,i=t.resource?.type;return i?r?(e(e=>({specificMenus:{...e.specificMenus,[r]:{...e.specificMenus[r]||{},menus:{...e.specificMenus[r]?.menus||{},[n]:{sectionTitle:t.sectionTitle,items:t.items}}}}})),()=>{e(e=>({specificMenus:{...e.specificMenus,[r]:{...e.specificMenus[r]||{},menus:{...e.specificMenus[r]?.menus||{},[n]:void 0}}}}))}):(e(e=>({resourceMenus:{...e.resourceMenus,[i]:{...e.resourceMenus[i]||{},menus:{...e.resourceMenus[i]?.menus||{},[n]:{sectionTitle:t.sectionTitle,items:t.items}}}}})),()=>{e(e=>({resourceMenus:{...e.resourceMenus,[i]:{...e.resourceMenus[i]||{},menus:{...e.resourceMenus[i]?.menus||{},[n]:void 0}}}}))}):()=>{}}}))}const is=(0,u.createContext)(null);function as({children:e}){let t=(0,u.useMemo)(()=>rs(),[]);return(0,d.jsx)(is.Provider,{value:t,children:e})}function os(){let e=(0,u.useContext)(is);if(!e)throw Error(`useContextMenuStore must be used within a ContextMenuProvider`);return e}function ss(e){let t=os(),n=(0,f.useStore)(t,e=>e.resourceMenus),r=(0,f.useStore)(t,e=>e.specificMenus);return(0,u.useMemo)(()=>{let t=r[e.id||``]?.menus||{},i=n[e.type]?.menus||{},a=Object.values(t).flat(),o=[...Object.values(i).flat(),...a].filter(e=>e!==void 0),s=[],c=[];for(let e of o){let t=[];for(let n of e.items||[])n.id&&s.includes(n.id)||(s.push(n.id),t.push(n));t.length&&c.push({...e,items:t})}return cs(c)},[r,n,e.id,e.type])}function cs(e){let t={},n=[];e.forEach(e=>{if(!e)return;let r=e.sectionTitle;if(!r){n.push(...e.items||[]);return}t[r]||(t[r]=[]),t[r].push(...e.items)});let r=Object.entries(t).map(([e,t])=>({sectionTitle:e,items:t}));return n.length&&r.push({items:n}),r}function ls(e,t=[]){let n=os(),r=(0,f.useStore)(n,e=>e.hookMenuItem);(0,u.useEffect)(()=>r(e),[r,e.resource?.id,e.resource?.type,...t])}var us={CenterPanelContainer:`_CenterPanelContainer_1sbe6_1`,CenterPanelHeader:`_CenterPanelHeader_1sbe6_16`,CenterPanelClose:`_CenterPanelClose_1sbe6_23`,CenterPanelTitle:`_CenterPanelTitle_1sbe6_28`};function ds(e){return(0,d.jsxs)(`div`,{className:us.CenterPanelContainer,children:[e.title||e.close?(0,d.jsxs)(`div`,{className:us.CenterPanelHeader,children:[e.title?(0,d.jsx)(`h2`,{className:us.CenterPanelTitle,children:e.title}):null,e.close?(0,d.jsx)(K,{className:us.CenterPanelClose,onClick:e.close,children:(0,d.jsx)(tr,{})}):null]}):null,e.children]})}const fs=g.default.div`
|
|
444
|
+
`;function mo({panel:e,state:t,actions:n,isLeft:r,pinActions:i=n,transition:a,close:o,available:s=[],style:c,noHeader:l,isModal:f}){let p=(0,u.useContext)(m.ReactVaultContext)||null,[h,g]=(0,u.useState)(!1),_=Un(),v=pi(),{tabs:y,pinnable:b,hideHeader:x}=e?.options||{},S=(0,u.useMemo)(()=>(s||[]).filter(e=>!e.requiresState),[s]),{itemProps:w,isOpen:T,setIsOpen:E}=ir(S.length),[D,O]=(0,u.useState)(``),ee=(0,u.useRef)(void 0);(0,u.useEffect)(()=>g(!1),[_.state.canvasId,e?.id]),(0,u.useEffect)(()=>O(``),[e]),(0,u.useEffect)(()=>(ee.current=O,()=>{ee.current=void 0}),[]);let k=(0,u.useCallback)(e=>{ee.current&&ee.current(e)},[]),A=(0,u.useCallback)(r=>{let i=e?t.stack.length?n.popStack:e.backAction?()=>e&&e.backAction&&e.backAction(t,{...v,current:n},_):null:null;r&&(!i||r.metaKey)&&S.length?(r.preventDefault(),E(!0)):i?.()},[n,_,v,e,E,t,S.length]),j=r=>{n.change({id:r.id,state:r.defaultState,stacked:!!(t.stack.length||e?.backAction)})};if(!e||!t.current)return null;let M=e.backAction||t.stack.length?(0,d.jsx)(lo,{"aria-label":`Back`,onClick:A,children:(0,d.jsx)($a,{"aria-hidden":`true`})}):null,N=(0,d.jsx)(lo,{"aria-label":`Close panel`,onClick:o||n.close,children:(0,d.jsx)(tr,{"aria-hidden":`true`})});return(0,d.jsx)(ao.Provider,{value:k,children:(0,d.jsxs)(so,{"data-modal":f,"data-state":a,"data-flipped":r,style:c,"data-header":!l,children:[l?null:(0,d.jsxs)(co,{"data-tabs":!!y,"data-error":h,children:[(0,d.jsxs)(Ja,{style:{display:`flex`,height:`100%`},children:[e.renderBackAction?e.renderBackAction({backAction:A,fallback:M}):M,S.length?(0,d.jsxs)(Xa,{$open:T,role:`menu`,style:{left:`0.5em`},children:[(0,d.jsx)(Za,{children:`All panels`}),(0,d.jsx)(Qa,{}),S.map((t,n)=>(0,d.jsx)(Ya,{...w[n],onClick:()=>j(t),$active:e.id===t.id,children:t.label},n))]}):null]}),D?(0,d.jsx)(fo,{as:r?`h1`:`h2`,children:D}):x?(0,d.jsx)(uo,{}):(0,d.jsx)(fo,{as:r?`h1`:`h2`,children:e.label}),b?t.pinned?(0,d.jsx)(lo,{"aria-label":`Unpin panel`,onClick:i.unpin,children:(0,d.jsx)(eo,{"aria-hidden":`true`,fill:`orange`})}):(0,d.jsx)(lo,{"aria-label":`Pin panel`,onClick:()=>i.pin({id:e.id,state:t.state}),children:(0,d.jsx)(eo,{"aria-hidden":`true`,fill:`#ddd`})}):null,e.renderCloseAction?e.renderCloseAction({closeAction:o||n.close,fallback:N}):N]}),(0,d.jsx)(po,{className:`OverrideScrollbar`,children:(0,d.jsx)(C.ErrorBoundary,{onError:()=>g(!0),FallbackComponent:io,resetKeys:[_.state.canvasId,e?.id],onReset:()=>g(!1),children:ro(e.render(t.state||e.defaultState||{},{...v,current:n,vault:p,transition:a,isModal:f},_))})})]})})}function ho(e=`vault://homepage-collection.json`){let t=new x.Vault,n=window.localStorage.getItem(`preview-vault-collection`),r=!1;if(n)try{let i=JSON.parse(n);if(i.id&&i.id===e){t.dispatch((0,w.requestResource)({id:i.id}));let e=(0,T.actionListFromResource)(i.id,i);t.dispatch((0,w.batchActions)({actions:e})),r=!0}}catch{}if(!r){let n=(0,T.actionListFromResource)(e,{"@context":`http://iiif.io/api/presentation/3/context.json`,id:e,type:`Collection`,label:{en:[`Recent items`]},items:[]});t.dispatch((0,w.requestResource)({id:e})),t.dispatch((0,w.batchActions)({actions:n}))}return t.on(`after:@iiif/REMOVE_REFERENCE`,n=>{n.action.payload.id===e&&window.localStorage.setItem(`preview-vault-collection`,JSON.stringify(t.toPresentation3({id:e,type:`Collection`})))}),{vault:t,unsubscribe:()=>{},addHistory:(n,r)=>{let i=t.getState();if(n&&r&&(r===`Collection`||r===`Manifest`)){let a=i.iiif.entities.Collection[e];if(a){let i=a.items.findIndex(e=>e.id===n);i===-1?t.dispatch((0,w.addReference)({id:e,type:`Collection`,reference:{id:n,type:r},key:`items`,index:0})):t.dispatch((0,w.reorderEntityField)({id:e,type:`Collection`,key:`items`,startIndex:i,endIndex:0})),window.localStorage.setItem(`preview-vault-collection`,JSON.stringify(t.toPresentation3({id:e,type:`Collection`})))}}},clearHistory:()=>{t.dispatch((0,w.modifyEntityField)({id:e,type:`Collection`,key:`items`,value:[]})),window.localStorage.setItem(`preview-vault-collection`,JSON.stringify(t.toPresentation3({id:e,type:`Collection`})))}}}function go(){return(0,u.useContext)(_o)}const _o=(0,u.createContext)(new x.Vault),vo=(0,u.createContext)({addHistory:(e,t)=>{},clearHistory:()=>{}}),yo=`manifest-editor://homepage-collection.json`;function bo(){return(0,u.useContext)(vo)}function xo(e){let{vault:t,unsubscribe:n,addHistory:r,clearHistory:i}=(0,u.useMemo)(()=>ho(yo),[]);return(0,u.useEffect)(()=>n,[]),(0,d.jsx)(vo.Provider,{value:{addHistory:r,clearHistory:i},children:(0,d.jsx)(_o.Provider,{value:t,children:e.children})})}function So({children:e}){let t=go();return(0,d.jsx)(m.VaultProvider,{vault:t,children:e})}function Co(e,t,n,r,i){let a=(0,m.useVault)(),o=U(),{create:s,edit:c}=ui(),l=(0,u.useMemo)(()=>(0,S.matchBasedOnResource)({type:n,parent:e,index:0,property:t},o.layout.creators||[],{vault:a}),[e,t,o.layout.creators,n,a]),d=e&&l.length!==0,f=(0,u.useCallback)((a,o)=>{if(e)return s({type:n,parent:(0,h.toRef)(e),property:t,index:a,target:r,initialData:o,...i||{}})},[s,e,t,n,i,r]),p=(0,u.useCallback)((a,o,c)=>{if(e)return s({type:n,filter:a,parent:(0,h.toRef)(e),property:t,index:o,target:r,initialData:c,...i||{}})},[s,e,t,n,i,r]);return[d,{create:f,edit:(0,u.useCallback)((n,r)=>{c(n,e?{parent:(0,h.toRef)(e),property:t,index:r}:void 0)},[c,e,t]),createFiltered:p,creator:(0,u.useCallback)((a,o)=>{if(e)return s({type:n,initialCreator:a,parent:(0,h.toRef)(e),property:t,target:r,initialData:o,...i||{}})},[n,t,e,r,s,i]),buttonProps:(0,u.useMemo)(()=>({"data-action-id":Pt(n,t,e)}),[n,t,e])}]}function wo(){let e=(0,m.useVault)(),t=go(),n=U(),r=z();return(0,u.useMemo)(()=>new S.Creator(e,n.layout.creators||[],t,r.creators),[n.layout.creators,r.creators,t,e])}async function To(e){let t=await e.create(),n=Array.isArray(t)?t[0]:t;return n?(e.onCreate?.(),e.close?.(),e.edit?.(n),!0):!1}const Eo=(0,u.createContext)({});function Do(e){return(0,u.useContext)(Eo)[e]||{}}function Oo(e){let t=(0,u.useContext)(Eo),n=(0,u.useMemo)(()=>({...t,[e.id]:e.data}),[t,e.id,e.data]);return(0,d.jsx)(Eo.Provider,{value:n,children:e.children})}const ko=(0,u.memo)(function(e){let t=(0,m.useVault)(),{edit:n,modal:r}=ui(),[i,a]=(0,u.useState)(!1),[o,s]=(0,u.useState)(null),c=wo(),f=z(),p=(0,u.useRef)(!1),g=e.resource.initialData?.selector;Ka(g);let _=Do(e.creator.id),v={targetType:e.resource.type,parent:e.resource.parent?{property:e.resource.property,atIndex:e.resource.index,resource:e.resource.parent}:void 0,target:e.resource.target,initialData:{..._,...e.resource.initialData||{},...e.initialData||{}}},y=async t=>{if(!(i||p.current)){a(!0),p.current=!0;try{await To({create:()=>c.create(e.creator.id,t,v),onCreate:e.onCreate,close:e.skipEditingOnCreate?void 0:()=>{r.popStack(),r.close()},edit:e.skipEditingOnCreate||e.resource.initialData?.skipEditingOnCreate?void 0:t=>n(t,{parent:(0,h.toRef)(e.resource.parent),property:e.resource.property,index:e.resource.index})})}catch(e){s(e?.message||`Unknown error`)}finally{a(!1),p.current=!1}}},b=async()=>!0;if((0,u.useEffect)(()=>{e.resource.initialData?.showEmptyForm||!e.creator.render&&!i&&y({})},[e.creator]),o)return(0,d.jsx)(`div`,{className:`flex flex-col items-center p-4`,children:(0,d.jsx)(l.ErrorMessage,{children:o})});let x=(0,d.jsx)(`div`,{className:`flex flex-col items-center py-8`,children:(0,d.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,d.jsx)(l.Spinner,{}),` `,(0,d.jsx)(`span`,{children:`Loading`})]})});return i?x:e.creator.render?(0,d.jsx)(d.Fragment,{children:(0,d.jsx)(u.Suspense,{fallback:x,children:e.creator.render({vault:t,runCreate:y,validate:b,options:v,config:f.creators?.[(0,S.getCreatorConfigKey)(e.creator)]||{}})})}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(l.EmptyState,{children:`No options available`}),(0,d.jsx)(l.ActionButton,{primary:!0,onPress:()=>y({}),children:e.creator.actionButton||`Create`})]})});function Ao(e){let t=U(),n=(0,m.useVault)(),[r,i]=(0,u.useState)(e.resource.initialCreator||``),[a,o]=(0,u.useState)(),[s,c]=(0,u.useState)(``),[f,p]=(0,u.useState)(!1),[h,g]=(0,u.useState)(``),[_,v]=(0,u.useState)(null),y=(0,u.useRef)(null),b=oo(),x=(0,u.useMemo)(()=>(0,S.matchBasedOnResource)(e.resource,t.layout.creators||[],{vault:n}),[e.resource,t.layout.creators,n]),C=x.some(e=>e.supportsResource);(0,u.useEffect)(()=>{x.length===1&&!r&&!C&&i(x[0].id)},[C,r,x]),(0,u.useEffect)(()=>{C&&!r&&y.current?.focus()},[C,r]);let w=x.find(e=>e.id===r);if((0,u.useEffect)(()=>{w&&b?.(w.label)}),x.length===0)return(0,d.jsx)(l.EmptyState,{children:`Not currently supported`});let T=(e,t)=>{o(t||Po(s)),i(e.id)},E=async t=>{t.preventDefault();let r=s.trim();if(!r||f)return;p(!0),g(``),v(null);let i=Fo(),a=await Promise.all(x.map(async t=>{if(!t.supportsResource)return null;try{let a=await t.supportsResource(r,i,{vault:n,resource:e.resource});return a?{creator:t,initialData:No(r,a).initialData}:null}catch(e){return{creator:t,error:e?.message||`Could not check this link`}}})),o=a.filter(jo),c=a.filter(Mo);if(p(!1),o.length===1){T(o[0].creator,o[0].initialData);return}if(o.length>1){v(o),g(`Multiple creators can use this link. Choose one below.`);return}g(c[0]?.error||`No creator recognised this link. Choose one below.`)},D=(0,d.jsx)(l.ModalBackSlot,{children:(0,d.jsx)(l.IconButton,{root:document.getElementById(`headlessui-portal-root`)||void 0,label:`Back to Add content options`,className:`group`,placement:`right`,onPress:()=>{i(``),o(void 0)},children:(0,d.jsx)(l.GridIcon,{className:`text-2xl opacity-50 group-hover:opacity-70`})})});if(w)return w.hiddenModal?(0,d.jsxs)(d.Fragment,{children:[D,(0,d.jsx)(ko,{creator:w,resource:e.resource,initialData:a})]}):(0,d.jsxs)(`div`,{children:[D,(0,d.jsx)(`div`,{className:`p-2 py-6`,children:(0,d.jsx)(ko,{creator:w,resource:e.resource,initialData:a})})]});let O=_?.length?_.map(e=>e.creator):x,ee=new Map(_?.map(e=>[e.creator.id,e.initialData]));return(0,d.jsxs)(d.Fragment,{children:[C?(0,d.jsxs)(`form`,{className:`p-4 pb-0`,onSubmit:E,children:[(0,d.jsx)(`label`,{className:`block text-sm font-medium text-gray-700`,htmlFor:`creator-resource-link`,children:`Paste a link`}),(0,d.jsxs)(`div`,{className:`mt-1 flex gap-2`,children:[(0,d.jsx)(`input`,{ref:y,id:`creator-resource-link`,className:`min-w-0 flex-1 rounded border border-gray-300 px-3 py-2 text-sm`,value:s,onChange:e=>{c(e.currentTarget.value),g(``),v(null)},placeholder:`https://example.org/resource`,type:`url`}),(0,d.jsx)(l.ActionButton,{primary:!0,type:`submit`,isDisabled:!s.trim()||f,children:f?`Checking`:`Use link`})]}),h?(0,d.jsx)(`div`,{className:`mt-2 text-sm text-gray-600`,role:`status`,children:h}):null]}):null,(0,d.jsx)(l.CreatorGrid,{label:`Select a type`,items:O.map(e=>({id:e.id,title:e.label,description:e.summary||``,icon:e.icon,onClick:()=>T(e,ee.get(e.id))}))})]})}function jo(e){return!!e&&!(`error`in e)}function Mo(e){return!!e&&`error`in e}function No(e,t){return typeof t==`object`?t:{initialData:Po(e)}}function Po(e){let t=e.trim();return t?{url:t,youtubeUrl:t}:void 0}function Fo(){let e=new Map,t=new Map,n=new Map,r=t=>(e.has(t)||e.set(t,fetch(t).then(e=>{if(!e.ok)throw Error(`Could not load ${t}`);return e.text()})),e.get(t)),i=e=>(n.has(e)||n.set(e,fetch(e,{method:`HEAD`}).then(t=>{if(!t.ok)throw Error(`Could not check ${e}`);return t})),n.get(e));return{text:r,head:i,json(e){return t.has(e)||t.set(e,r(e).then(e=>JSON.parse(e))),t.get(e)},async contentType(e){return(await i(e)).headers.get(`content-type`)||``}}}const Io={id:`@manifest-editor/creator`,label:`Add content`,options:{hideHeader:!0,tabs:!1},render(e){return(0,d.jsx)(Ao,{resource:e})}},Lo={color:{main:`#B84C74`,mainHover:`#4a89ff`,logoPink:`#E94581`,white:`white`,grey:`grey`,black:`black`,lightgrey:`#F8F9FA`,mediumgrey:`#dddddd`,danger:`#a90e21`,warning:`#e38627`,lightdanger:`#ffeaea`,lightsuccess:`#c5e8c5`,success:`#6ccd55`,greyOverlay:`rgba(0, 0, 0, 0.2)`,highlight:`#faeed7`},iiifColor:{manifest:`rgba(0, 0, 0, 0.2)`,canvas:`rgba(255, 222, 219, 0.8)`,service:`rgba(13, 110, 253, 0.8)`,annotation:`rgba(247, 226, 173, 0.8)`,contentResource:`rgba(207, 247, 255, 0.8)`,ranges:`rgba(144, 213, 157, 0.8)`},padding:{xs:`0.25rem`,small:`0.5rem`,medium:`1rem`,large:`2rem`},device:{mobile:`375px`,tablet:`768px`,laptop:`992px`,desktop:`1200px`},shadows:{standard:`rgba(0, 0, 0, 0.1) 0px 1px 3px 0px, rgba(0, 0, 0, 0.05) 0px 5px 15px 0px`,bottom:`rgba(0, 0, 0, 0.1) 0px 4px 2px -2px`}};function Ro(e){let{}=e,t=(0,m.useVault)(),n=U(),r=(0,u.useMemo)(()=>(0,S.matchBasedOnResource)(e.resource,n.layout.creators||[],{vault:t}),[e.resource,n.layout.creators,t]);return r.length===0?(0,d.jsx)(`div`,{children:`No supported creators found`}):(0,d.jsx)(`div`,{children:(0,d.jsxs)(l.Tabs,{className:`w-full flex-1 overflow-hidden flex flex-col`,children:[(0,d.jsx)(l.TabList,{className:`flex-1 overflow-hidden w-full flex text-sm whitespace-nowrap`,items:r,children:e=>(0,d.jsx)(l.Tab,{id:e.id,children:e.label})}),r.map(t=>(0,d.jsx)(l.TabPanel,{id:t.id,className:`p-2`,children:(0,d.jsx)(g.ThemeProvider,{theme:Lo,children:(0,d.jsx)(ko,{creator:t,resource:e.resource,onCreate:e.onCreate,skipEditingOnCreate:!0})})},t.id))]})})}function zo({fallback:e,backAction:t}){let n=Xr(),{back:r}=Jr();return n.length?(0,d.jsx)(lo,{"aria-label":`Back`,onClick:r,children:(0,d.jsx)($a,{"aria-hidden":`true`})}):e}function Bo({closeAction:e,fallback:t}){let n=Xr();return Yr()||n.length?(0,d.jsx)(lo,{"aria-label":`Close panel`,onClick:()=>{e()},children:(0,d.jsx)(tr,{"aria-hidden":`true`})}):t}function Vo(e,t,n,r){let i=t.filter(t=>t.resourceType===e.resource.source.type);if(i.length===0)return null;for(let t of i){let i=[],a={},o=e.property===`partOf`,s=(t.editors||[]).filter(t=>{if(o&&t.id!==`@manifest-editor/part-of-reference`||r.hideTabs&&r.hideTabs.includes(t.id)||r.onlyTabs&&!r.onlyTabs.includes(t.id))return!1;if(t.supports.sortKey){if(i.includes(t.supports.sortKey))return!1;t.supports.sortFallback&&(a[t.supports.sortKey]=t)}return n.edit&&!t.supports.edit||t.supports.custom&&t.supports.custom(e,n.vault)===!1?!1:(t.supports.sortKey&&i.push(t.supports.sortKey),!0)}),c=Object.keys(a);for(let e of c)!i.includes(e)&&a[e]&&!s.includes(a[e])&&s.push(a[e]);if(s.length)return{...t,editors:s}}return null}function Ho({currentTab:e=void 0}){let t=Yr(),n=(0,u.useContext)(m.ResourceReactContext),r=U(),i=W(),a=(0,m.useVault)(),{change:o}=ui(),s=oo(),{editorConfig:c}=z(),f=t?.resource.source?.id,p=t?.resource.source?.type,h=f!==i.id;f&&h&&i.type===`Collection`&&p===`Collection`&&(p=`EmbeddedCollection`);let g=(p?c[p]:c.All)||{},_=(0,u.useMemo)(()=>{let e={...n},r=t?.resource.source.id,i=t?.resource.source.type,a={Collection:`collection`,Manifest:`manifest`,Range:`range`,Canvas:`canvas`,Annotation:`annotation`,AnnotationPage:`annotationPage`};return i&&a[i]&&(e[a[i]]=r),e},[t,n]);function v(e){return t?(0,d.jsx)(m.ResourceReactContext.Provider,{value:_,children:e}):e}let y=(0,u.useMemo)(()=>{if(!t)return null;let e=r.layout.editors||[],n=(r.layout.resources||[]).map(t=>typeof t==`string`?{id:`@default/`+t,label:t,resourceType:t,auto:!0,editors:e.filter(e=>e.supports.resourceTypes.includes(t))}:t);return Vo(t,n,{edit:!0,vault:a},g)},[t,r]);(0,u.useEffect)(()=>{s(y?.label||``)},[y]),(0,u.useEffect)(()=>{let t=y?.editors.map(e=>e.id)||[];t.find(t=>t===e)||o(`@manifest-editor/editor`,{currentTab:t[0]})},[y?.editors,e,o]);let b=(0,u.useMemo)(()=>(y?.editors||[]).map(e=>({id:e.id,label:e.label,renderComponent:()=>e.component(g)})),[y?.editors,g]);if(!t||!y)return null;if(g.singleTab){let e=(y?.editors||[]).find(e=>e.id===g.singleTab);if(e)return v((0,d.jsx)(`div`,{className:`w-full`,children:e.component(g)},t.resource.source?.id))}return v((0,d.jsx)(l.SidebarTabs,{isNested:h,rootResource:i,menuId:t.resource.source.id,menu:b,selectedKey:e,onSelectionChange:e=>{o(`@manifest-editor/editor`,{currentTab:e})}},t.resource.source?.id))}const Uo={id:`@manifest-editor/editor`,label:`Editor`,options:{hideHeader:!0,tabs:!0,minWidth:400},renderBackAction:({backAction:e,fallback:t})=>(0,d.jsx)(zo,{backAction:e,fallback:t}),renderCloseAction:({closeAction:e,fallback:t})=>(0,d.jsx)(Bo,{closeAction:e,fallback:t}),render({currentTab:e}){return(0,d.jsx)(Ho,{currentTab:e})}};function Wo(e){let[t,n]=(0,u.useState)(!1),r=(0,u.useRef)(null),i=(0,u.useRef)(0);function a(t){i.current--,!(t&&i.current!==0)&&(r.current&&(clearTimeout(r.current),r.current=0),r.current=setTimeout(()=>{n(!1)},e))}function o(){i.current++,r.current&&clearTimeout(r.current),n(!0)}return(0,u.useMemo)(()=>[t,{set:o,clear:a}],[t])}function Go(e){return e?typeof e==`string`?{src:e,alt:``}:e:null}function Ko(e){return e?typeof e==`string`?e:e.name:null}function qo(e){let t=e.extension,n=t.leftPanels?.[0]||t.centerPanels?.[0]||t.rightPanels?.[0]||t.modalPanels?.[0];return n?{id:n.id,label:n.label||`Open plugin`,modal:t.modalPanels?.some(e=>e.id===n.id)||!1}:null}function Jo(e){return e instanceof Error?e.message:`Plugin configuration could not be saved.`}function Yo(e){return(0,d.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,...e,children:[(0,d.jsx)(`path`,{d:`M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z`}),(0,d.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]})}function Xo(e){return(0,d.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,...e,children:[(0,d.jsx)(`path`,{d:`M7 7h10v10`}),(0,d.jsx)(`path`,{d:`M7 17 17 7`})]})}function Zo(){let e=U(),{appId:t}=Hn(),n=z(),r=ie(),i=An(),a=Mn(),o=ui(),{saveGlobalPluginConfig:s}=(0,u.useContext)(Tn),[c,f]=(0,u.useState)(!1),[p,m]=(0,u.useState)(``),[h,g]=(0,u.useState)(null),[_,v]=(0,u.useState)(null),[y,b]=(0,u.useState)(null),x=(0,u.useMemo)(()=>new Set(un(i,e,t).map(e=>e.metadata.id)),[i,e,t]),S=(0,u.useMemo)(()=>{let n=p.trim().toLowerCase();return i.plugins.filter(r=>{let i=on(r,e,t);return!c&&!i?!1:!n||[r.metadata.label,r.metadata.id,r.metadata.description,Ko(r.metadata.author),...r.metadata.tags||[]].filter(Boolean).join(` `).toLowerCase().includes(n)})},[e,t,i.plugins,p,c]),C=h&&i.plugins.find(e=>e.metadata.id===h)||null;if(!i.plugins.length)return null;function w(e){a.setAppConfig(t,e),r({plugins:{...n.plugins||{},apps:{...n.plugins?.apps||{},[t]:e}}})}async function T(e){if(!s){b(`Global plugin settings are not available in this host.`);return}let n=i.globalApps[t]||{},r={apps:{...i.globalApps,[t]:e}};a.setGlobalAppConfig(t,e);try{await s(r)}catch(e){a.setGlobalAppConfig(t,n),b(Jo(e))}}async function E(n,r,a){b(null),v(`${a}:${n.metadata.id}`);let o=a===`global`?i.globalApps[t]||{}:i.apps[t]||{},s=r?_n(o,i,n,e,t):{config:Yt(o,n.metadata.id),blocked:[]};if(s.blocked.length){v(null),b(`Cannot enable ${n.metadata.label}: ${s.blocked.join(`, `)}.`);return}a===`global`?await T(s.config):w(s.config),v(null)}function D(e){let t=qo(e);if(t){if(t.modal){o.modal.open({id:t.id});return}o.open(t.id)}}return(0,d.jsxs)(`section`,{className:`flex flex-col gap-3 border-t border-gray-200 pt-4 mt-4`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,d.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,d.jsx)(`h3`,{className:`font-semibold text-sm text-gray-900`,children:`Plugins`})}),(0,d.jsx)(`button`,{type:`button`,className:`rounded border border-gray-200 bg-white px-2 py-1 text-xs text-gray-500 hover:text-gray-700 hover:border-gray-300 transition-colors`,onClick:()=>f(e=>!e),children:c?`Compatible only`:`Show all`})]}),(0,d.jsx)(`input`,{"aria-label":`Search plugins`,className:`rounded border border-gray-200 px-2.5 py-1.5 text-xs focus:border-me-primary-500 focus:ring-2 focus:ring-me-primary-500/20 focus:outline-none`,type:`search`,placeholder:`Search plugins…`,value:p,onChange:e=>m(e.currentTarget.value)}),y?(0,d.jsx)(`div`,{className:`rounded border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700`,children:y}):null,(0,d.jsx)(`div`,{className:`flex flex-col gap-2`,children:S.map(n=>{let r=cn(n,i,t),a=x.has(n.metadata.id),o=r&&n.loadStatus===`loading`,s=r&&n.loadStatus===`error`?n.loadError:null,c=Go(n.metadata.image),u=r&&!a&&!o&&!s,f=on(n,e,t),p=sn(n,e,t),m=qo(n),h=!!n.settings,v=_===`workspace:${n.metadata.id}`;return(0,d.jsxs)(`article`,{className:`flex gap-2.5 rounded-lg border bg-white p-3 text-sm transition-colors ${a?`border-gray-200`:`border-gray-100 bg-gray-50`} ${f?``:`bg-gray-100`}`,children:[c?(0,d.jsx)(`img`,{className:`h-9 w-9 rounded object-cover flex-none mt-0.5`,src:c.src,alt:c.alt||n.metadata.label}):(0,d.jsx)(`div`,{className:`h-9 w-9 rounded flex items-center justify-center flex-none mt-0.5 text-lg ${a?`bg-me-primary-50 text-me-primary-500`:`bg-gray-100 text-gray-600`}`,children:(0,d.jsx)(Yo,{className:`w-4 h-4`})}),(0,d.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1`,children:[(0,d.jsxs)(`div`,{className:`flex items-start justify-between gap-1`,children:[(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 min-w-0`,children:[(0,d.jsx)(`span`,{className:`font-medium text-gray-900 text-xs`,children:n.metadata.label}),n.metadata.official?(0,d.jsxs)(`span`,{className:`rounded-full text-me-primary-500 px-1.5 py-0 text-[9px] font-bold inline-flex items-center gap-1`,children:[(0,d.jsx)(l.CheckIcon,{className:`w-3 h-3`}),` Verified`]}):null,n.metadata.version?(0,d.jsx)(`span`,{className:`text-[10px] text-gray-600`,children:n.metadata.version}):null]}),(0,d.jsxs)(`div`,{className:`flex items-center gap-1 flex-none`,children:[h?(0,d.jsx)(`button`,{type:`button`,title:`Configure plugin`,"aria-label":`Configure ${n.metadata.label}`,className:`rounded p-1 text-gray-600 hover:text-gray-700 hover:bg-gray-100 transition-colors`,onClick:()=>g(n.metadata.id),children:(0,d.jsx)(Yo,{className:`w-3.5 h-3.5`})}):null,a&&m?(0,d.jsx)(`button`,{type:`button`,title:`Open ${m.label}`,"aria-label":`Open ${m.label}`,className:`rounded p-1 text-me-primary-500 hover:bg-me-primary-50 transition-colors`,onClick:()=>D(n),children:(0,d.jsx)(Xo,{className:`w-3.5 h-3.5`})}):null,(0,d.jsx)(`button`,{type:`button`,disabled:!f||v,onClick:()=>E(n,!r,`workspace`),className:`relative inline-flex h-5 w-9 flex-none items-center rounded-full transition-colors disabled:opacity-40 focus:outline-none focus:ring-2 focus:ring-me-primary-500/30 ${r?`bg-me-primary-500`:`bg-gray-200`}`,title:r?`Disable plugin`:`Enable plugin`,"aria-label":`${r?`Disable`:`Enable`} ${n.metadata.label}`,children:(0,d.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 transform rounded-full bg-white shadow transition-transform ${r?`translate-x-4`:`translate-x-0.5`}`})})]})]}),n.metadata.description?(0,d.jsx)(`p`,{className:`text-xs text-gray-500 leading-relaxed`,children:n.metadata.description}):null,o?(0,d.jsx)(`span`,{className:`text-xs text-gray-500`,children:`Loading plugin…`}):null,s?(0,d.jsx)(`span`,{className:`text-xs text-red-600`,children:s}):null,u?(0,d.jsx)(`span`,{className:`text-xs text-amber-600`,children:`Waiting for required dependencies`}):null,!f&&p?(0,d.jsx)(`span`,{className:`text-xs text-gray-600`,children:p}):null]})]},n.metadata.id)})}),S.length?null:(0,d.jsx)(`div`,{className:`rounded-lg border border-gray-100 bg-gray-50 p-4 text-center text-xs text-gray-500`,children:`No plugins found.`}),C?(0,d.jsx)(l.Modal,{title:`Configure ${C.metadata.label}`,onClose:()=>g(null),width:`560px`,children:(0,d.jsx)(Qo,{plugin:C,onClose:()=>g(null),canSaveGlobal:!!s})}):null]})}function Qo({plugin:e,onClose:t,canSaveGlobal:n}){let r=Fn(e.metadata.id),[i,a]=(0,u.useState)(`workspace`),[o,s]=(0,u.useState)({}),[c,l]=(0,u.useState)(!1),[f,p]=(0,u.useState)(!1),[m,h]=(0,u.useState)(null),g=i===`global`?r.global:r.workspace;(0,u.useEffect)(()=>{s({...g}),h(null),p(!1)},[e.metadata.id,i]);async function _(){let t=e.settings?.validate?.(o);if(t){h(t);return}l(!0),h(null);try{i===`global`?await r.setGlobalSettings(o):r.setWorkspaceSettings(o),p(!0),setTimeout(()=>p(!1),2e3)}catch(e){h(Jo(e))}finally{l(!1)}}async function v(){l(!0),h(null);try{i===`global`?await r.resetGlobalSettings():r.resetWorkspaceSettings(),s({})}catch(e){h(Jo(e))}finally{l(!1)}}let y=n&&r.canSaveGlobal;return(0,d.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[y?(0,d.jsxs)(`div`,{className:`flex items-center gap-1 px-5 pt-4 pb-3 border-b border-gray-100`,children:[(0,d.jsx)(`span`,{className:`text-xs text-gray-500 mr-2`,children:`Scope:`}),(0,d.jsx)(`button`,{type:`button`,className:`rounded-full px-3 py-1 text-xs font-medium transition-colors ${i===`workspace`?`bg-me-primary-500 text-white`:`bg-gray-100 text-gray-600 hover:bg-gray-200`}`,onClick:()=>a(`workspace`),children:`This workspace`}),(0,d.jsx)(`button`,{type:`button`,className:`rounded-full px-3 py-1 text-xs font-medium transition-colors ${i===`global`?`bg-me-primary-500 text-white`:`bg-gray-100 text-gray-600 hover:bg-gray-200`}`,onClick:()=>a(`global`),children:`All workspaces`})]}):null,m?(0,d.jsx)(`div`,{className:`mx-5 mt-4 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700`,children:m}):null,(0,d.jsx)(`div`,{className:`flex-1 overflow-y-auto p-5`,children:(0,d.jsx)(`div`,{className:`flex flex-col gap-3`,children:e.settings?.render?e.settings.render({plugin:e,appId:r.appId,scope:i,value:o,defaults:r.defaults,effective:r.effective,onChange:s}):e.settings?.fields?.length?e.settings.fields.map(e=>(0,d.jsx)($o,{field:e,draft:o,setDraft:s},e.id)):(0,d.jsx)(`div`,{className:`rounded-lg border border-gray-100 bg-gray-50 p-4 text-center text-sm text-gray-500`,children:`This plugin has no configurable settings.`})})}),(0,d.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-gray-100 px-5 py-4`,children:[(0,d.jsx)(`button`,{type:`button`,className:`text-xs text-gray-600 hover:text-gray-700 transition-colors disabled:opacity-40`,disabled:c,onClick:v,children:`Reset to defaults`}),(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[f?(0,d.jsx)(`span`,{className:`text-xs text-green-600`,children:`✓ Saved`}):null,(0,d.jsx)(`button`,{type:`button`,className:`rounded-lg bg-me-primary-500 px-4 py-2 text-sm font-medium text-white hover:bg-me-primary-600 disabled:opacity-50 transition-colors`,disabled:c,onClick:_,children:c?`Saving…`:`Save ${i}`})]})]})]})}function $o({field:e,draft:t,setDraft:n}){let r=t[e.id],i=`plugin-setting-${e.id}`;function a(r){n({...t,[e.id]:r})}let o=(0,d.jsx)(`label`,{className:`text-sm font-medium text-gray-900`,htmlFor:i,children:e.label}),s=`rounded-lg border border-gray-200 bg-white px-3 py-2 text-sm focus:border-me-primary-500 focus:ring-2 focus:ring-me-primary-500/20 focus:outline-none`;return e.type===`boolean`?(0,d.jsxs)(`div`,{className:`flex items-center justify-between rounded-lg border border-gray-100 bg-white px-4 py-3`,children:[(0,d.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[o,e.description?(0,d.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.description}):null]}),(0,d.jsx)(`input`,{id:i,type:`checkbox`,checked:r===!0,onChange:e=>a(e.currentTarget.checked),className:`h-4 w-4 rounded border-gray-300 text-me-primary-500 focus:ring-me-primary-500`})]}):e.type===`textarea`?(0,d.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-gray-100 bg-white px-4 py-3`,children:[o,e.description?(0,d.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.description}):null,(0,d.jsx)(`textarea`,{id:i,className:`${s} min-h-24 resize-y`,value:typeof r==`string`?r:``,placeholder:e.placeholder,onChange:e=>a(e.currentTarget.value)})]}):e.type===`select`?(0,d.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-gray-100 bg-white px-4 py-3`,children:[o,e.description?(0,d.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.description}):null,(0,d.jsxs)(`select`,{id:i,className:s,value:r===void 0?``:String(r),onChange:t=>{let n=e.options?.find(e=>String(e.value)===t.currentTarget.value);a(n?n.value:t.currentTarget.value)},children:[(0,d.jsx)(`option`,{value:``,children:`Default`}),(e.options||[]).map(e=>(0,d.jsx)(`option`,{value:String(e.value),children:e.label},String(e.value)))]})]}):(0,d.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-gray-100 bg-white px-4 py-3`,children:[o,e.description?(0,d.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.description}):null,(0,d.jsx)(`input`,{id:i,className:s,type:e.type===`number`?`number`:`text`,value:typeof r==`string`||typeof r==`number`?r:``,placeholder:e.placeholder,onChange:t=>{a(e.type===`number`?Number(t.currentTarget.value):t.currentTarget.value)}})]})}function es(){let e=z(),t=ie(),n=e.creators[`iiif-image-services`]||{};return(0,d.jsxs)(l.Form.Form,{className:`flex max-w-3xl flex-col gap-4`,onChange:e=>{let n=new FormData(e.currentTarget);t({creators:{"iiif-image-services":{compact:n.get(`compact`)===`compact`?`compact`:`with-dimensions`,includeSizes:n.get(`includeSizes`)===`on`,includeTiles:n.get(`includeTiles`)===`on`}}})},onSubmit:e=>e.preventDefault(),children:[(0,d.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900`,children:`IIIF Options`}),(0,d.jsxs)(`fieldset`,{className:`flex flex-col gap-4`,children:[(0,d.jsx)(`legend`,{className:`mb-3 text-base font-semibold`,children:`Image services`}),(0,d.jsxs)(l.Form.InputContainer,{children:[(0,d.jsx)(l.Form.Label,{htmlFor:`compactImageServices`,children:`Compact services`}),(0,d.jsxs)(`select`,{id:`compactImageServices`,name:`compact`,className:`rounded border border-gray-300 p-2`,defaultValue:n.compact===`compact`?`compact`:`with-dimensions`,children:[(0,d.jsx)(`option`,{value:`with-dimensions`,children:`id, type, profile, width, height (default)`}),(0,d.jsx)(`option`,{value:`compact`,children:`id, type, profile (compact)`})]})]}),(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,children:[(0,d.jsx)(l.Form.Input,{id:`includeSizes`,name:`includeSizes`,type:`checkbox`,defaultChecked:n.includeSizes===!0}),(0,d.jsx)(l.Form.Label,{htmlFor:`includeSizes`,children:`Include sizes`})]}),(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,children:[(0,d.jsx)(l.Form.Input,{id:`includeTiles`,name:`includeTiles`,type:`checkbox`,defaultChecked:n.includeTiles===!0}),(0,d.jsx)(l.Form.Label,{htmlFor:`includeTiles`,children:`Include tiles`})]}),(0,d.jsx)(`p`,{className:`text-sm text-gray-500`,children:`Applies to newly added images. Thumbnails always include available sizes and tiles.`})]})]})}function ts(){let e=Cr(),t=W(),n=z(),r=ie(),[i,a]=Wo(2e3);function o(e){e.preventDefault();let t=new FormData(e.target),i={defaultPreview:t.get(`defaultPreview`),i18n:{...n.i18n||{},advancedLanguageMode:t.get(`advancedLanguageMode`)===`on`,availableLanguages:(t.get(`availableLanguages`)||``).split(`,`).map(e=>e.trim()),defaultLanguage:t.get(`defaultLanguage`)},export:{...n.export||{},version:t.get(`isVersion2`)===`on`?2:3,baseIdentifier:t.get(`base`)||null},plugins:n.plugins,editorFeatureFlags:{...n.editorFeatureFlags||{},rememberCanvasId:t.get(`rememberCanvasId`)===`on`,rememberLeftPanelId:t.get(`rememberLeftPanelId`)===`on`,annotationPopups:t.get(`annotationPopups`)===`on`,manifestGridOptions:t.get(`manifestGridOptions`)===`on`,enableMultiImageCanvases:t.get(`enableMultiImageCanvases`)===`on`,enableMultiMediaCanvases:t.get(`enableMultiMediaCanvases`)===`on`}};r(i),a.set(),a.clear()}return(0,d.jsxs)(l.Sidebar,{children:[(0,d.jsx)(l.SidebarHeader,{title:`Workspace configuration`}),i?(0,d.jsx)(`div`,{className:`bg-me-primary-500 text-white p-3 text-sm`,children:`Changes saved`}):null,(0,d.jsxs)(l.SidebarContent,{className:`p-4`,children:[(0,d.jsx)(es,{}),(0,d.jsxs)(l.Form.Form,{onSubmit:o,className:`flex flex-col gap-3`,children:[(0,d.jsxs)(l.Form.InputContainer,{children:[(0,d.jsx)(l.Form.Label,{htmlFor:`defaultLanguage`,children:`Default Language`}),(0,d.jsx)(l.Form.Input,{type:`text`,name:`defaultLanguage`,id:`defaultLanguage`,defaultValue:n.i18n?.defaultLanguage||``})]}),(0,d.jsxs)(l.Form.InputContainer,{children:[(0,d.jsx)(l.Form.Label,{htmlFor:`availableLanguages`,children:`Available Languages`}),(0,d.jsx)(l.Form.Input,{type:`text`,name:`availableLanguages`,id:`availableLanguages`,defaultValue:(n.i18n?.availableLanguages||[]).join(`, `)})]}),(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,className:`my-3`,children:[(0,d.jsx)(l.Form.Input,{type:`checkbox`,name:`advancedLanguageMode`,id:`advancedLanguageMode`,defaultChecked:n.i18n?.advancedLanguageMode||!1}),(0,d.jsx)(l.Form.Label,{htmlFor:`advancedLanguageMode`,children:`Advanced Language Mode`})]}),(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,className:`my-3`,children:[(0,d.jsx)(l.Form.Input,{type:`checkbox`,name:`textGranularityEnabled`,id:`textGranularityEnabled`,defaultChecked:n.i18n?.textGranularityEnabled||!1}),(0,d.jsx)(l.Form.Label,{htmlFor:`textGranularityEnabled`,children:`Enable text granularity`})]}),(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,className:`my-3`,children:[(0,d.jsx)(l.Form.Input,{type:`checkbox`,name:`rememberCanvasId`,id:`rememberCanvasId`,defaultChecked:n.editorFeatureFlags?.rememberCanvasId||!1}),(0,d.jsx)(l.Form.Label,{htmlFor:`rememberCanvasId`,children:`Remember Canvas ID`})]}),(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,className:`my-3`,children:[(0,d.jsx)(l.Form.Input,{type:`checkbox`,name:`rememberLeftPanelId`,id:`rememberLeftPanelId`,defaultChecked:n.editorFeatureFlags?.rememberLeftPanelId||!1}),(0,d.jsx)(l.Form.Label,{htmlFor:`rememberLeftPanelId`,children:`Remember Left panel`})]}),(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,className:`my-3`,children:[(0,d.jsx)(l.Form.Input,{type:`checkbox`,name:`manifestGridOptions`,id:`manifestGridOptions`,defaultChecked:n.editorFeatureFlags?.manifestGridOptions||!1}),(0,d.jsx)(l.Form.Label,{htmlFor:`manifestGridOptions`,children:`Manifest Grid Options`})]}),(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,className:`my-3`,children:[(0,d.jsx)(l.Form.Input,{type:`checkbox`,name:`isVersion2`,id:`isVersion2`,defaultChecked:n.export?.version===2}),(0,d.jsxs)(l.Form.Label,{htmlFor:`isVersion2`,children:[`Export Presentation 2 `,t.type,`s`]})]}),(0,d.jsxs)(l.Form.InputContainer,{children:[(0,d.jsx)(l.Form.Label,{htmlFor:`defaultPreview`,children:`Default preview`}),(0,d.jsx)(`div`,{children:e.configs.map((e,t)=>e.type===`iiif-preview-service`?null:(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,children:[(0,d.jsx)(l.Form.Input,{type:`radio`,id:e.id,name:`defaultPreview`,value:e.id,defaultChecked:n.defaultPreview?n.defaultPreview===e.id:t===0}),(0,d.jsx)(`label`,{htmlFor:e.id,children:e.label})]},e.id))})]}),t.type===`Manifest`?(0,d.jsx)(`a`,{className:`text-sm text-me-primary-500 hover:underline hover:text-me-primary-600`,href:window.location.pathname.includes(`/exhibition`)?window.location.pathname.replace(`/exhibition`,``)||`/`:`${window.location.pathname}/exhibition`,children:window.location.pathname.includes(`/exhibition`)?`Return to Manifest Editor`:`Go to Exhibition Editor`}):null,(0,d.jsx)(Zo,{}),(0,d.jsx)(`div`,{className:`mt-5`,children:(0,d.jsx)(l.ActionButton,{type:`submit`,children:`Save changes`})})]})]})]})}function ns(e){let t=new Map;for(let n of e){if(!n.configuration?.fields.length)continue;let e=(0,S.getCreatorConfigKey)(n);(!t.has(e)||n.id===e)&&t.set(e,n)}return Array.from(t.values())}function rs(){let e=U(),t=z(),n=ie(),r=(0,u.useMemo)(()=>ns(e.layout.creators||[]),[e.layout.creators]);function i(e,t){let r=(0,S.getCreatorConfigKey)(e),i=new FormData(t),a={};for(let t of e.configuration?.fields||[])t.type===`checkbox`&&(a[t.id]=i.get(t.id)===`on`);n({creators:{[r]:a}})}return r.length?(0,d.jsx)(`div`,{className:`flex max-w-3xl flex-col gap-6`,children:r.map(e=>(0,d.jsxs)(l.Form.Form,{className:`flex flex-col gap-3 border-b border-gray-100 pb-5 last:border-b-0`,onChange:t=>i(e,t.currentTarget),children:[(0,d.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,d.jsx)(`h3`,{className:`text-base font-semibold text-gray-900`,children:e.label}),e.summary?(0,d.jsx)(`p`,{className:`text-sm text-gray-500`,children:e.summary}):null]}),e.configuration?.fields.map(n=>{let r=(0,S.getCreatorConfigKey)(e),i=t.creators?.[r]?.[n.id],a=`${r}-${n.id}`;return n.type===`checkbox`?(0,d.jsxs)(l.Form.InputContainer,{horizontal:!0,className:`my-1 items-start`,children:[(0,d.jsx)(l.Form.Input,{type:`checkbox`,name:n.id,id:a,defaultChecked:typeof i==`boolean`?i:n.defaultValue||!1}),(0,d.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,d.jsx)(l.Form.Label,{htmlFor:a,children:n.label}),n.summary?(0,d.jsx)(`p`,{className:`text-sm text-gray-500`,children:n.summary}):null]})]},n.id):null})]},(0,S.getCreatorConfigKey)(e)))}):(0,d.jsx)(l.EmptyState,{children:`No creator settings available`})}function is(){return(0,f.createStore)((e,t)=>({specificMenus:{},resourceMenus:{},hookMenuItem(t){let n=Lt(),r=t.resource?.id||``,i=t.resource?.type;return i?r?(e(e=>({specificMenus:{...e.specificMenus,[r]:{...e.specificMenus[r]||{},menus:{...e.specificMenus[r]?.menus||{},[n]:{sectionTitle:t.sectionTitle,items:t.items}}}}})),()=>{e(e=>({specificMenus:{...e.specificMenus,[r]:{...e.specificMenus[r]||{},menus:{...e.specificMenus[r]?.menus||{},[n]:void 0}}}}))}):(e(e=>({resourceMenus:{...e.resourceMenus,[i]:{...e.resourceMenus[i]||{},menus:{...e.resourceMenus[i]?.menus||{},[n]:{sectionTitle:t.sectionTitle,items:t.items}}}}})),()=>{e(e=>({resourceMenus:{...e.resourceMenus,[i]:{...e.resourceMenus[i]||{},menus:{...e.resourceMenus[i]?.menus||{},[n]:void 0}}}}))}):()=>{}}}))}const as=(0,u.createContext)(null);function os({children:e}){let t=(0,u.useMemo)(()=>is(),[]);return(0,d.jsx)(as.Provider,{value:t,children:e})}function ss(){let e=(0,u.useContext)(as);if(!e)throw Error(`useContextMenuStore must be used within a ContextMenuProvider`);return e}function cs(e){let t=ss(),n=(0,f.useStore)(t,e=>e.resourceMenus),r=(0,f.useStore)(t,e=>e.specificMenus);return(0,u.useMemo)(()=>{let t=r[e.id||``]?.menus||{},i=n[e.type]?.menus||{},a=Object.values(t).flat(),o=[...Object.values(i).flat(),...a].filter(e=>e!==void 0),s=[],c=[];for(let e of o){let t=[];for(let n of e.items||[])n.id&&s.includes(n.id)||(s.push(n.id),t.push(n));t.length&&c.push({...e,items:t})}return ls(c)},[r,n,e.id,e.type])}function ls(e){let t={},n=[];e.forEach(e=>{if(!e)return;let r=e.sectionTitle;if(!r){n.push(...e.items||[]);return}t[r]||(t[r]=[]),t[r].push(...e.items)});let r=Object.entries(t).map(([e,t])=>({sectionTitle:e,items:t}));return n.length&&r.push({items:n}),r}function us(e,t=[]){let n=ss(),r=(0,f.useStore)(n,e=>e.hookMenuItem);(0,u.useEffect)(()=>r(e),[r,e.resource?.id,e.resource?.type,...t])}var ds={CenterPanelContainer:`_CenterPanelContainer_1sbe6_1`,CenterPanelHeader:`_CenterPanelHeader_1sbe6_16`,CenterPanelClose:`_CenterPanelClose_1sbe6_23`,CenterPanelTitle:`_CenterPanelTitle_1sbe6_28`};function fs(e){return(0,d.jsxs)(`div`,{className:ds.CenterPanelContainer,children:[e.title||e.close?(0,d.jsxs)(`div`,{className:ds.CenterPanelHeader,children:[e.title?(0,d.jsx)(`h2`,{className:ds.CenterPanelTitle,children:e.title}):null,e.close?(0,d.jsx)(K,{className:ds.CenterPanelClose,onClick:e.close,children:(0,d.jsx)(tr,{})}):null]}):null,e.children]})}const ps=g.default.div`
|
|
445
445
|
flex: 1;
|
|
446
446
|
display: flex;
|
|
447
447
|
width: 100%;
|
|
448
448
|
flex-direction: column;
|
|
449
449
|
position: relative;
|
|
450
|
-
`,
|
|
450
|
+
`,ms=g.default.div`
|
|
451
451
|
background: #fff;
|
|
452
452
|
position: relative;
|
|
453
453
|
border-bottom: 1px solid #d0d0d0;
|
|
@@ -465,11 +465,11 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
465
465
|
//flex-direction: column;
|
|
466
466
|
//justify-content: center;
|
|
467
467
|
}
|
|
468
|
-
`,
|
|
468
|
+
`,hs=g.default.p`
|
|
469
469
|
font-size: 0.9em;
|
|
470
470
|
color: #777;
|
|
471
471
|
font-weight: 400;
|
|
472
|
-
`,
|
|
472
|
+
`,gs=g.default.button`
|
|
473
473
|
color: inherit;
|
|
474
474
|
text-rendering: geometricPrecision;
|
|
475
475
|
border: none;
|
|
@@ -511,7 +511,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
511
511
|
margin-top: 0.5em;
|
|
512
512
|
}
|
|
513
513
|
}
|
|
514
|
-
`,
|
|
514
|
+
`,_s=g.default.div`
|
|
515
515
|
font-size: 1.4em;
|
|
516
516
|
padding-right: 0.3em;
|
|
517
517
|
display: flex;
|
|
@@ -520,7 +520,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
520
520
|
[data-large="true"] & {
|
|
521
521
|
font-size: 2em;
|
|
522
522
|
}
|
|
523
|
-
`,
|
|
523
|
+
`,vs=g.default.div`
|
|
524
524
|
width: 2em;
|
|
525
525
|
align-items: center;
|
|
526
526
|
//padding-top: 0.5em;
|
|
@@ -533,11 +533,11 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
533
533
|
fill: #999;
|
|
534
534
|
color: #999;
|
|
535
535
|
}
|
|
536
|
-
`,
|
|
536
|
+
`,ys=g.default.div`
|
|
537
537
|
min-height: 0;
|
|
538
538
|
overflow: visible;
|
|
539
539
|
display: flex;
|
|
540
|
-
`,
|
|
540
|
+
`,bs=g.default.div`
|
|
541
541
|
min-height: 0;
|
|
542
542
|
overflow: visible;
|
|
543
543
|
flex: 1;
|
|
@@ -550,7 +550,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
550
550
|
&[data-max-height="true"] {
|
|
551
551
|
overflow-y: auto;
|
|
552
552
|
}
|
|
553
|
-
`,
|
|
553
|
+
`,xs=g.default.section`
|
|
554
554
|
display: grid;
|
|
555
555
|
grid-template-rows: 0fr;
|
|
556
556
|
overflow: hidden;
|
|
@@ -578,7 +578,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
578
578
|
&[data-scrolled="true"] {
|
|
579
579
|
box-shadow: inset 0px 2px 0px 0 rgba(0, 0, 0, 0.1);
|
|
580
580
|
}
|
|
581
|
-
`,
|
|
581
|
+
`,Ss=g.default.div`
|
|
582
582
|
position: sticky;
|
|
583
583
|
display: flex;
|
|
584
584
|
top: 0;
|
|
@@ -614,7 +614,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
614
614
|
right: 0.5em;
|
|
615
615
|
}
|
|
616
616
|
}
|
|
617
|
-
`,
|
|
617
|
+
`,Cs=(()=>void 0);let ws=0;function Ts(){return(0,u.useMemo)(()=>ws++,[])}function Es(e,t=!1){let[n,r]=(0,u.useState)([]),i=(0,u.useRef)(-1),a=t=>{let r=document.activeElement,i=n.findIndex(e=>e.current?.button?.current===r);if(i!==-1)switch(t.code){case`Home`:n[0]&&n[0].current?.focus();break;case`End`:{let t=e-1;n[t]&&n[t].current?.focus();break}case`ArrowDown`:if(i!==e-1){let e=i+1;n[e]&&n[e].current?.focus()}break;case`ArrowUp`:if(i!==0){let e=i-1;n[e]&&n[e].current?.focus()}break;case`ArrowLeft`:{let e=n[i];e&&e.current&&e.current.close();break}case`ArrowRight`:{let e=n[i];e&&e.current&&e.current.open();break}}},o=(e,r)=>{if(t&&r&&e!==i.current){i.current=e;for(let t=0;t<n.length;t++){let r=n[t];t!==e&&r.current?.close()}}};return(0,u.useEffect)(()=>{r(t=>Array(e).fill(0).map((e,n)=>t[n]||(0,u.createRef)()))},[e]),{open:e=>{let t=n[e];t&&t.current&&t.current.open()},close:e=>{let t=n[e];t&&t.current&&t.current.close()},toggle:e=>{let t=n[e];t&&t.current&&t.current.toggle()},focus:e=>{let t=n[e];t&&t.current&&t.current.focus()},openAll:()=>{for(let e=0;e<n.length;e++)n[e].current?.open()},closeAll:()=>{for(let e=0;e<n.length;e++)n[e].current?.close()},onKeyDown:a,getItemProps:e=>({ref:n[e],onChange:t=>o(e,t)})}}const Ds=(0,u.forwardRef)(function(e,t){let n=(0,u.useRef)(null),r=(0,u.useRef)(null),i=Ts(),[a,o]=(0,u.useState)(e.initialOpen||!1),s=e.onChange||Cs,c=()=>{s(!a),o(e=>!e)},l=e.maxHeight,[f,p]=(0,u.useState)(!1);return(0,u.useImperativeHandle)(t,()=>({open(){s(!0),o(!0)},close(){s(!1),o(!1)},toggle(){c()},focus(){r.current&&r.current.focus()},button:r})),(0,d.jsxs)(ms,{"data-large":e.large,"data-open":a,children:[(0,d.jsxs)(Ss,{"data-open":a,children:[e.icon?(0,d.jsx)(vs,{onClick:c,children:e.icon}):null,(0,d.jsxs)(gs,{ref:r,onClick:c,"aria-expanded":a,"aria-controls":`accordion-${i}`,children:[e.label,e.description?(0,d.jsx)(hs,{children:e.description}):null]}),(0,d.jsx)(_s,{onClick:c,children:(0,d.jsx)(nr,{width:`1em`,height:`1em`,rotate:a?0:180})})]}),(0,d.jsx)(xs,{"aria-labelledby":`accordion-${i}`,"aria-hidden":!a,"data-overflow":!!e.overflow,"data-has-icon":!!e.icon,onScroll:e=>{e.target.scrollTop>0?p(!0):p(!1)},ref:n,$initial:!a,"data-scrolled":f,hidden:!a,children:(0,d.jsx)(ys,{children:(0,d.jsx)(bs,{"data-max-height":!!l,"data-full":e.fullWidth,style:{maxHeight:l||void 0},children:e.children})})})]})});function Os(e){let{getItemProps:t,onKeyDown:n}=Es(e.items.length,e.singleMode);return(0,d.jsx)(ps,{onKeyDown:n,children:e.items.map((n,r)=>(0,d.jsx)(Ds,{overflow:e.overflow,maxHeight:e.maxHeight,...n,...t(r),children:n.children},r))})}function ks(){return(0,d.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,height:`48`,viewBox:`0 -960 960 960`,width:`48`,children:(0,d.jsx)(`path`,{d:`M220-160q-24 0-42-18t-18-42v-143h60v143h520v-143h60v143q0 24-18 42t-42 18H220Zm260-153L287-506l43-43 120 120v-371h60v371l120-120 43 43-193 193Z`})})}const As=g.default.div`
|
|
618
618
|
padding: 0.3em;
|
|
619
619
|
|
|
620
620
|
display: flex;
|
|
@@ -636,12 +636,12 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
636
636
|
position: sticky;
|
|
637
637
|
bottom: 0;
|
|
638
638
|
}
|
|
639
|
-
`;function
|
|
639
|
+
`;function js(e){let t=(0,m.useManifest)(),n=(0,m.useVault)(),r=ui(),i=(0,u.useMemo)(()=>JSON.stringify(n.toPresentation3(t),null,2),[t,n]),a=(0,u.useMemo)(()=>JSON.stringify(n.toPresentation2(t),null,2),[t,n]);return(0,d.jsx)(fs,{title:`Export manifest`,close:r.centerPanel.popStack,children:(0,d.jsx)(`div`,{style:{flex:1,overflowY:`auto`},children:(0,d.jsx)(Os,{items:[{label:`Presentation 3`,description:`Download this version by clicking the "Download" button.`,maxHeight:400,large:!0,initialOpen:!0,overflow:!0,icon:(0,d.jsx)(K,{onClick:()=>Ft(i,`manifest.json`),children:(0,d.jsx)(ks,{})}),children:(0,d.jsxs)(`div`,{style:{maxWidth:`100%`},children:[(0,d.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`},children:JSON.stringify(n.toPresentation3(t),null,2)}),(0,d.jsxs)(As,{"data-sticky":`true`,children:[(0,d.jsx)(K,{onClick:()=>It(i),children:`Copy to clipboard`}),(0,d.jsx)(K,{onClick:()=>Ft(i,`manifest.json`),children:`Download`})]})]})},{label:`Presentation 2`,description:`Download this version by clicking the "Download" button.`,maxHeight:400,large:!0,icon:(0,d.jsx)(K,{onClick:()=>Ft(a,`manifest.json`),children:(0,d.jsx)(ks,{})}),children:(0,d.jsxs)(`div`,{style:{maxWidth:`100%`},children:[(0,d.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`},children:JSON.stringify(n.toPresentation2(t),null,2)}),(0,d.jsxs)(As,{"data-sticky":`true`,children:[(0,d.jsx)(K,{onClick:()=>It(a),children:`Copy to clipboard`}),(0,d.jsx)(K,{onClick:()=>Ft(a,`manifest.json`),children:`Download`})]})]})}]})})})}function Ms({key:e,initialValue:t,requestId:n,getInitialValue:r}){let[i,a]=(0,m.useCurrentAnnotationMetadata)({requestId:n}),[o,s]=(0,u.useState)(r&&r(i)||i[e]||t);return[o,(0,u.useCallback)(t=>{a({[e]:t}),s(t)},[])]}const Ns=(0,E.default)(),Ps=(0,u.createContext)(Ns);function Fs({children:e,emitter:t}){return(0,d.jsx)(Ps.Provider,{value:t,children:e})}function Is(){return(0,u.useContext)(Ps)}function Ls(e,t,n=[]){let r=(0,u.useContext)(Ps);(0,u.useEffect)(()=>{let n=e=>{t(e)};return r.on(e,n),()=>{r.off(e,n)}},[r,e,...n])}function Rs(e,t=[]){let n=t.length?t:Array(e.length).fill(!1);if(typeof window>`u`)return n;let r=e.map(e=>window.matchMedia(e)),i=()=>r.map(e=>e.matches),[a,o]=(0,u.useState)(i);return(0,u.useLayoutEffect)(()=>{let e=()=>o(i);return r.forEach(t=>t.addListener(e)),()=>r.forEach(t=>t.removeListener(e))},[]),a}function zs(e,t,n,r=!0){let i=(0,D.useDebounce)(t,n);(0,u.useEffect)(()=>typeof window>`u`?()=>void 0:(window.addEventListener(`beforeunload`,t,!1),()=>{t(),window.removeEventListener(`beforeunload`,t)}),[t]),(0,u.useEffect)(()=>{if(e&&r)return e.subscribe(i,!0)},[i,e,r])}function Bs(){let e=(0,m.useAtlasStore)(),t=(0,f.useStore)(e,e=>e.switchTool),n=(0,f.useStore)(e,e=>e.polygonState.currentTool),r=(0,f.useStore)(e,e=>e.polygonState.selectedStamp),i=(0,f.useStore)(e,e=>e.polygonState.showBoundingBox);return(0,u.useMemo)(()=>({currentTool:n,selectedStamp:r,draw:{active:n===`pencil`,enable:t.draw},polygon:{active:n===`pen`,enable:t.pen},line:{active:n===`line`,enable:t.line},lineBox:{active:n===`lineBox`,enable:t.lineBox},square:{active:n===`box`,enable:t.box},triangle:{active:r?.id===`triangle`,enable:t.triangle},hexagon:{active:r?.id===`hexagon`,enable:t.hexagon},circle:{active:r?.id===`circle`,enable:t.circle},remove:{active:i,enable:t.remove}}),[i,r,n,t])}const Vs=g.default.div`
|
|
640
640
|
position: relative;
|
|
641
641
|
width: 1px;
|
|
642
642
|
background: rgba(0, 0, 0, 0.2);
|
|
643
643
|
z-index: 50;
|
|
644
|
-
`,
|
|
644
|
+
`,Hs=(0,g.default)(wr)`
|
|
645
645
|
transition:
|
|
646
646
|
opacity 300ms,
|
|
647
647
|
transform 300ms;
|
|
@@ -653,7 +653,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
653
653
|
&:focus {
|
|
654
654
|
outline: 2px solid salmon;
|
|
655
655
|
}
|
|
656
|
-
`;(0,g.default)(
|
|
656
|
+
`;(0,g.default)(Hs)`
|
|
657
657
|
background: #fff;
|
|
658
658
|
width: 30px;
|
|
659
659
|
height: 30px;
|
|
@@ -667,7 +667,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
667
667
|
svg {
|
|
668
668
|
fill: #9999;
|
|
669
669
|
}
|
|
670
|
-
`;const
|
|
670
|
+
`;const Us=(0,g.default)(Hs)`
|
|
671
671
|
position: relative;
|
|
672
672
|
display: flex;
|
|
673
673
|
opacity: 1;
|
|
@@ -694,7 +694,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
694
694
|
svg {
|
|
695
695
|
font-size: 1.5em;
|
|
696
696
|
}
|
|
697
|
-
`,
|
|
697
|
+
`,Ws=g.default.div`
|
|
698
698
|
background: rgba(0, 0, 0, 0);
|
|
699
699
|
position: absolute;
|
|
700
700
|
width: 16px;
|
|
@@ -717,12 +717,12 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
717
717
|
&:hover {
|
|
718
718
|
transform: scaleX(100%);
|
|
719
719
|
background: rgba(0, 0, 0, 0.1);
|
|
720
|
-
${
|
|
720
|
+
${Hs} {
|
|
721
721
|
transform: scaleX(100%);
|
|
722
722
|
opacity: 1;
|
|
723
723
|
}
|
|
724
724
|
}
|
|
725
|
-
`,
|
|
725
|
+
`,Gs=g.default.div`
|
|
726
726
|
background: rgba(0, 0, 0, 0);
|
|
727
727
|
position: absolute;
|
|
728
728
|
pointer-events: none;
|
|
@@ -731,7 +731,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
731
731
|
top: 0;
|
|
732
732
|
bottom: 0;
|
|
733
733
|
z-index: 51; // This will always be quite high.
|
|
734
|
-
`,
|
|
734
|
+
`,Ks=(0,u.forwardRef)(function({dir:e,open:t,actions:n,reset:r},i){let[a,o]=(0,u.useState)(!0),s=`mt-[calc(50vh+8px)]`,c=e===`left`?`${s} ml-[13px]`:`${s} ml-[3px]`;return(0,d.jsxs)(Vs,{onClick:()=>n.open(),children:[(0,d.jsx)(Gs,{$open:t,$dir:e,className:`group`,children:t?null:(0,d.jsxs)(l.Tooltip,{placement:e===`left`?`right`:`left`,children:[(0,d.jsx)(l.TooltipTrigger,{"aria-label":`Open ${e} panel`,as:Us,$dir:e,onClick:e=>n.open(),children:(0,d.jsx)(nr,{"aria-hidden":`true`,className:`text-2xl`,rotate:e===`right`?90:270})}),(0,d.jsx)(l.DefaultTooltipContent,{children:`Open`})]})}),(0,d.jsxs)(l.Tooltip,{placement:e===`left`?`right`:`left`,children:[(0,d.jsx)(l.TooltipTrigger,{asChild:!0,children:(0,d.jsx)(`div`,{children:(0,d.jsxs)(Ws,{ref:i,$open:t,$dir:e,className:`group`,children:[t?(0,d.jsxs)(l.Tooltip,{placement:e===`left`?`right`:`left`,children:[(0,d.jsx)(l.TooltipTrigger,{"aria-label":`Close ${e} panel`,as:l.IconHandle,onPress:()=>n.close(),children:(0,d.jsx)(`div`,{onMouseOut:()=>{o(!0)},onMouseOver:()=>{o(!1)},children:(0,d.jsx)(tr,{"aria-hidden":`true`})})}),(0,d.jsx)(l.DefaultTooltipContent,{children:`Close`})]}):null,r&&t?(0,d.jsxs)(l.Tooltip,{placement:e===`left`?`right`:`left`,children:[(0,d.jsx)(l.TooltipTrigger,{"aria-label":`Reset ${e} panel size`,as:l.IconHandle,onPress:()=>r(),children:(0,d.jsx)(`div`,{onMouseOut:()=>{o(!0)},onMouseOver:()=>{o(!1)},children:(0,d.jsx)(l.ResetIcon,{"aria-hidden":`true`})})}),(0,d.jsx)(l.DefaultTooltipContent,{children:`Reset`})]}):null,t?(0,d.jsxs)(l.Tooltip,{placement:e===`left`?`right`:`left`,children:[(0,d.jsx)(l.TooltipTrigger,{asChild:!0,children:(0,d.jsx)(`div`,{onMouseOut:()=>{o(!0)},onMouseOver:()=>{o(!1)},children:(0,d.jsx)(l.ResizeHandle,{"aria-label":`Resize panel`})})}),(0,d.jsx)(l.DefaultTooltipContent,{children:`Resize panel`})]}):null]})})}),a&&(0,d.jsx)(l.DefaultTooltipContent,{className:c,children:`Resize panel`})]})]})});function qs(e){return(0,d.jsx)(`svg`,{width:`1em`,height:`1em`,viewBox:`0 0 42 42`,xmlns:`http://www.w3.org/2000/svg`,stroke:`currentColor`,...e,children:(0,d.jsxs)(`g`,{transform:`translate(2 2)`,strokeWidth:5,fill:`none`,fillRule:`evenodd`,children:[(0,d.jsx)(`circle`,{strokeOpacity:.5,cx:18,cy:18,r:18}),(0,d.jsx)(`path`,{d:`M36 18c0-9.94-8.06-18-18-18`,children:(0,d.jsx)(`animateTransform`,{attributeName:`transform`,type:`rotate`,from:`0 18 18`,to:`360 18 18`,dur:`1s`,repeatCount:`indefinite`})})]})})}var Js={ghostLoadingBlock:`_ghostLoadingBlock_1i1t4_1`,"ghost-loading":`_ghost-loading_1i1t4_1`,ghostLoading:`_ghost-loading_1i1t4_1`,ghostBlockList:`_ghostBlockList_1i1t4_28`};function Ys(){return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`div`,{"data-header":`true`,className:Js.ghostLoadingBlock}),(0,d.jsxs)(`div`,{className:Js.ghostBlockList,children:[(0,d.jsx)(`div`,{className:Js.ghostLoadingBlock}),(0,d.jsx)(`div`,{className:Js.ghostLoadingBlock}),(0,d.jsx)(`div`,{className:Js.ghostLoadingBlock}),(0,d.jsx)(`div`,{className:Js.ghostLoadingBlock})]})]})}function Xs(e,t,n,r=[]){(0,u.useLayoutEffect)(()=>{let r=e.current;if(r)return r.addEventListener(t,n),()=>{r.removeEventListener(t,n)}},[t,...r])}function Zs(e,t,n,r){return Math.sqrt(Math.abs(n-e)**2+Math.abs(r-t)**2)}function Qs(e,t,n,r){return n||(r?r/e:t)}function $s(e,t={}){let n=(0,u.useRef)(null),r=(0,u.useRef)(null),i=(0,u.useRef)(null),a=(0,u.useRef)(null),o=(0,u.useRef)(.5),[s,c]=(0,u.useState)(!1),d=(0,u.useRef)(!1),f=(0,u.useRef)(0),p=(0,u.useRef)({x:0,y:0}),[{widthA:m,widthB:h},g]=(0,l.useLocalStorage)(`resize-layout/${e}`,{widthA:`auto`,widthB:`${no({initial:t.widthA,fallback:320,options:{minWidth:t.minWidthPx,maxWidth:t.maxWidthPx}})}px`}),{loading:_=!1}=t;return Xs(a,`mousedown`,e=>{p.current.x=e.pageX,p.current.y=e.pageY,f.current&&(clearTimeout(f.current),f.current=0),f.current=setTimeout(()=>{c(!0),d.current=!0},350)},[_]),Xs({current:typeof window<`u`?window:void 0},`mouseup`,()=>{let e=n.current;if(e&&d.current){let{x:n,width:r}=e.getBoundingClientRect(),i=t.marginLeft||0,a=Qs(r,.8,t.maxWidthPct,t.maxWidthPx)*r,s=Qs(r,.2,t.minWidthPct,t.minWidthPx)*r;if(t.left){let e=o.current*r-i;g({widthA:`${(1-o.current)*r-i}`,widthB:`${e>a?a:e<s?s:e}px`})}else{let e=1-o.current*r-i;g({widthA:`${e>a?a:e<s?s:e}px`,widthB:`${o.current*r-i}px`})}c(!1),d.current=!1,t.onDragEnd&&t.onDragEnd()}clearTimeout(f.current),f.current=0},[_]),Xs(n,`mousemove`,e=>{if(!d.current&&f.current&&Zs(p.current.x,p.current.y,e.pageX,e.pageY)>20&&(c(!0),d.current=!0,clearTimeout(f.current),f.current=0),d.current&&r.current){let i=n.current;if(i){let{x:n,width:a}=i.getBoundingClientRect(),s=t.marginLeft||0,c=t.left||!1,l=Qs(a,.8,t.maxWidthPct,t.maxWidthPx),u=Qs(a,.2,t.minWidthPct,t.minWidthPx);o.current=(a+n-e.pageX-5)/a,c&&(o.current=1-o.current),o.current=o.current<u?u:o.current,o.current=o.current>l?l:o.current,r.current.style.width=`${o.current*a-s}px`}}},[s,_]),{refs:{container:n,resizer:a,resizableDiv:r,otherDiv:i},setWidths:g,isDragging:s,widthA:m,widthB:h}}const q=`.manifest-editor.exhibition-focused &`,J=`[data-exhibition-theme="dark"] ${q}`,Y={pink:`#b84c74`,pinkHover:`#9f3f64`,lightApp:`#f4f1ec`,lightStage:`#dfdbd4`,lightPanel:`#fff`,lightPanelSoft:`#f8f6f3`,lightBorder:`#dcd5ce`,lightPanelBorder:`#ddd5ce`,lightText:`#25211f`,lightMuted:`#6a625c`,darkApp:`#18161d`,darkStage:`#0e0d12`,darkPanel:`#28222d`,darkPanelSoft:`#2f2934`,darkPanelHeader:`#25222b`,darkHover:`#312c34`,darkSelected:`#3a3440`,darkText:`#f6f1f4`,darkMuted:`#c8c0c6`,darkSubtle:`#999088`,darkLabel:`#d9d1da`,darkWarning:`#4a2636`,darkWarningBorder:`#7a3f59`,darkBorder:`rgba(246, 241, 244, 0.16)`,darkBorderSoft:`rgba(246, 241, 244, 0.14)`},ec=g.default.div`
|
|
735
735
|
display: flex;
|
|
736
736
|
flex: 1 1 0;
|
|
737
737
|
min-height: 0;
|
|
@@ -745,7 +745,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
745
745
|
${J} {
|
|
746
746
|
background: ${Y.darkApp};
|
|
747
747
|
}
|
|
748
|
-
`,
|
|
748
|
+
`,tc=g.default.div`
|
|
749
749
|
flex: 1 1 0;
|
|
750
750
|
min-width: 0;
|
|
751
751
|
min-height: 0;
|
|
@@ -861,12 +861,12 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
861
861
|
background: ${Y.darkHover} !important;
|
|
862
862
|
color: #fff !important;
|
|
863
863
|
}
|
|
864
|
-
`,
|
|
864
|
+
`,nc=g.default.div`
|
|
865
865
|
display: flex;
|
|
866
866
|
flex: 1;
|
|
867
867
|
justify-content: center;
|
|
868
868
|
align-items: center;
|
|
869
|
-
`,
|
|
869
|
+
`,rc=g.default.div`
|
|
870
870
|
position: absolute;
|
|
871
871
|
top: 3rem;
|
|
872
872
|
z-index: 40;
|
|
@@ -896,7 +896,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
896
896
|
`:g.css`
|
|
897
897
|
right: 1rem;
|
|
898
898
|
`}
|
|
899
|
-
`,
|
|
899
|
+
`,ic=g.default.button`
|
|
900
900
|
width: 2.35rem;
|
|
901
901
|
height: 2.35rem;
|
|
902
902
|
border: 0;
|
|
@@ -956,16 +956,16 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
956
956
|
width: 2.75rem;
|
|
957
957
|
height: 2.75rem;
|
|
958
958
|
}
|
|
959
|
-
`,
|
|
959
|
+
`,ac=g.default.div`
|
|
960
960
|
display: flex;
|
|
961
961
|
flex-direction: column;
|
|
962
962
|
gap: 0.25rem;
|
|
963
|
-
`,
|
|
963
|
+
`,oc=g.default.div`
|
|
964
964
|
width: 100%;
|
|
965
965
|
height: 1px;
|
|
966
966
|
margin: 0.25rem 0;
|
|
967
967
|
background: rgba(15, 23, 42, 0.14);
|
|
968
|
-
`,
|
|
968
|
+
`,sc=g.default.aside`
|
|
969
969
|
position: absolute;
|
|
970
970
|
top: 3rem;
|
|
971
971
|
bottom: 1rem;
|
|
@@ -1250,13 +1250,13 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
1250
1250
|
min-width: 0;
|
|
1251
1251
|
transform: translateY(${e=>e.$open?`0`:`0.75rem`});
|
|
1252
1252
|
}
|
|
1253
|
-
`,
|
|
1253
|
+
`,cc=g.default.div`
|
|
1254
1254
|
display: flex;
|
|
1255
1255
|
flex: 1;
|
|
1256
1256
|
min-width: 0;
|
|
1257
1257
|
height: 100%;
|
|
1258
1258
|
overflow: hidden;
|
|
1259
|
-
`,
|
|
1259
|
+
`,lc=g.default.div`
|
|
1260
1260
|
display: flex;
|
|
1261
1261
|
flex-direction: column;
|
|
1262
1262
|
flex: 1;
|
|
@@ -1265,16 +1265,16 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
1265
1265
|
max-width: 100%;
|
|
1266
1266
|
min-width: 0;
|
|
1267
1267
|
overflow: hidden;
|
|
1268
|
-
`,
|
|
1268
|
+
`,uc=g.default.header`
|
|
1269
1269
|
//box-shadow: 0 3px 2px 0 rgba(0, 0, 0, 0.04), 0 1px 0 0 rgba(0, 0, 0, 0.17);
|
|
1270
1270
|
z-index: 200;
|
|
1271
|
-
`,uc=g.default.div`
|
|
1272
|
-
background: #fff;
|
|
1273
1271
|
`,dc=g.default.div`
|
|
1272
|
+
background: #fff;
|
|
1273
|
+
`,fc=g.default.div`
|
|
1274
1274
|
display: flex;
|
|
1275
1275
|
flex: 1 1 0;
|
|
1276
1276
|
min-height: 0;
|
|
1277
|
-
`,
|
|
1277
|
+
`,pc=g.default.div`
|
|
1278
1278
|
background: #fff;
|
|
1279
1279
|
display: flex;
|
|
1280
1280
|
flex-direction: column;
|
|
@@ -1293,7 +1293,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
1293
1293
|
`;case`unmounted`:case`exited`:return g.css`
|
|
1294
1294
|
max-width: 0;
|
|
1295
1295
|
`}}}
|
|
1296
|
-
`,
|
|
1296
|
+
`,mc=g.default.div`
|
|
1297
1297
|
flex: 1 1 0;
|
|
1298
1298
|
background: #e3e7f0;
|
|
1299
1299
|
// background: #efefef;
|
|
@@ -1312,7 +1312,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
1312
1312
|
> * {
|
|
1313
1313
|
min-width: 0;
|
|
1314
1314
|
}
|
|
1315
|
-
`,
|
|
1315
|
+
`,hc=g.default.div`
|
|
1316
1316
|
background: #fff;
|
|
1317
1317
|
display: flex;
|
|
1318
1318
|
flex-direction: column;
|
|
@@ -1328,7 +1328,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
1328
1328
|
`;case`unmounted`:case`exited`:return g.css`
|
|
1329
1329
|
max-width: 0;
|
|
1330
1330
|
`}}}
|
|
1331
|
-
`,
|
|
1331
|
+
`,gc=g.default.div`
|
|
1332
1332
|
display: flex;
|
|
1333
1333
|
flex: 1;
|
|
1334
1334
|
height: 100%;
|
|
@@ -1409,17 +1409,17 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
1409
1409
|
flex: 1;
|
|
1410
1410
|
min-width: 0;
|
|
1411
1411
|
overflow: hidden;
|
|
1412
|
-
`;function
|
|
1412
|
+
`;function _c(e,t,n){return e.filter(e=>{if(!e.supports)return!0;try{return e.supports(t)}catch(t){return n?.(e,t),!1}})}function vc(e,t){return t?e.some(e=>e.id===t)?t:e[0]?.id||null:null}function Q(e){return e.map(e=>e.id).join(`,`)}function yc(e){let t=e?.resource;return t?.source?.type||t?.type||null}const bc=(0,u.memo)(function(e){let t=U(),n=Un(),r=W(),i=pi(),{vault:a}=(0,u.useContext)(m.ReactVaultContext),o=a||void 0,s=(0,m.useVaultSelector)(e=>e.iiif),{loading:c,state:f,leftPanels:p,centerPanels:h,rightPanels:g,modals:_=[],actions:v}=i,y=e.isLoading||!1,b=(0,u.useMemo)(()=>({rootResource:r,vault:o,app:t,layoutState:f,appState:n}),[r,o,t,f,n,s]),x=(0,u.useMemo)(()=>_c(p,b,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}).filter(e=>!e.focusedMode?.hide),[p,b]),S=(0,u.useMemo)(()=>_c(h,b,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[h,b]),w=(0,u.useMemo)(()=>_c(g,b,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}).filter(e=>!e.focusedMode?.hide),[g,b]),T=(0,u.useMemo)(()=>_c(_,b,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[_,b]),E=(0,u.useMemo)(()=>x.filter(e=>e.modal),[x]),D=(0,u.useMemo)(()=>x.filter(e=>!e.modal),[x]),O=(0,u.useMemo)(()=>[...T,...E],[T,E]),k=(0,u.useMemo)(()=>({...i,leftPanels:x,centerPanels:S,rightPanels:w,modals:O}),[i,x,S,w,O]),A=D.find(e=>e.id===f.leftPanel.current),j=w.find(e=>e.id===f.rightPanel.current),M=S.find(e=>e.id===f.centerPanel.current),N=O.find(e=>e.id===f.modal.current),P=f.modal.open&&E.some(e=>e.id===f.modal.current)?f.modal.current:f.leftPanel.current,F=f.pinnedRightPanel.pinned?w.find(e=>e.id===f.pinnedRightPanel.current):void 0,te=j&&(F?.id!==j.id||!(0,ee.default)(f.pinnedRightPanel.state,f.rightPanel.state)),ne=(0,u.useMemo)(()=>({rootResource:r,vault:o,app:t,layoutState:f,appState:n,actions:v}),[r,o,t,f,n,v]),I=e=>{e.focusedMode?.onSelect?.(ne)},re=!A||A.focusedMode?.closeOnMainPanelClick!==!1,[L]=Rs([`(max-width: 1020px)`]),R=(0,u.useMemo)(()=>(i.background||[]).map((e,t)=>(0,d.jsx)(u.Fragment,{children:e.render()},t)),[i.background]);(0,u.useLayoutEffect)(()=>{w.length&&v.rightPanel.change({id:w[0].id}),D.length&&v.leftPanel.change({id:D[0].id}),S.length&&v.centerPanel.change({id:S[0].id}),v.leftPanel.close(),v.rightPanel.close()},[]),(0,u.useLayoutEffect)(()=>{if(M&&M.onMount)return M.onMount(f.centerPanel.state||M.defaultState||{},{...k,current:v.centerPanel,vault:o},n)},[f.centerPanel.current,M?.id]),(0,u.useLayoutEffect)(()=>{L&&f.leftPanel.open&&f.rightPanel.open&&v.rightPanel.close()},[L,f.leftPanel.open,f.rightPanel.open]),(0,u.useLayoutEffect)(()=>{if(!f.leftPanel.open||!f.leftPanel.current)return;let e=x.find(e=>e.id===f.leftPanel.current);e?.focusedMode?.onSelect&&I(e)},[f.leftPanel.open,f.leftPanel.current,Q(x)]),(0,u.useLayoutEffect)(()=>{if(f.leftPanel.current&&!A){let e=vc(D,f.leftPanel.current);e?v.leftPanel.change({id:e}):v.leftPanel.close()}if(f.centerPanel.current&&!M){let e=vc(S,f.centerPanel.current);e?v.centerPanel.change({id:e}):v.centerPanel.close()}if(f.rightPanel.current&&!j){let e=vc(w,f.rightPanel.current);e?v.rightPanel.change({id:e}):v.rightPanel.close()}if(f.modal.current&&!N){let e=vc(O,f.modal.current);e?v.modal.change({id:e}):v.modal.close()}},[f.leftPanel.current,f.centerPanel.current,f.rightPanel.current,f.modal.current,A?.id,M?.id,j?.id,N?.id,Q(D),Q(S),Q(w),Q(O)]),Ls(`layout.edit`,e=>{yc(e)===`Canvas`&&!f.rightPanel.open||(w.find(e=>e.id===`@manifest-editor/editor`)?v.rightPanel.open({id:`@manifest-editor/editor`,stacked:!0}):j&&v.rightPanel.open())},[Q(w),j?.id,f.rightPanel.open]);let z=`4.5rem`,ie=`${no({options:A?.options,fallback:340})}px`,ae=`${no({options:j?.options,fallback:420})}px`,oe={"--manifest-editor-layout-left-sidebar-small":z,"--manifest-editor-layout-left-sidebar-large":f.leftPanel.open?`calc(${z} + ${ie})`:z,"--manifest-editor-layout-right-sidebar-small":z,"--manifest-editor-layout-right-sidebar-large":f.rightPanel.open?`calc(${z} + ${ae})`:z};return(0,u.useLayoutEffect)(()=>{if(typeof document>`u`)return;let e=document.documentElement,t=Object.keys(oe).map(t=>[t,e.style.getPropertyValue(t)]);for(let[t,n]of Object.entries(oe))e.style.setProperty(t,n);return()=>{for(let[n,r]of t)r?e.style.setProperty(n,r):e.style.removeProperty(n)}},[ie,ae,f.leftPanel.open,f.rightPanel.open]),c?null:(0,d.jsx)(ci.Provider,{value:`focused`,children:(0,d.jsxs)(lc,{id:e.htmlId||`manifest-editor-container`,className:`manifest-editor ${e.className||``}`,"data-layout-mode":`focused`,style:oe,children:[e.hideHeader?null:(0,d.jsxs)(uc,{children:[e.header||null,e.menu?(0,d.jsx)(`menu`,{children:e.menu}):null]}),(0,d.jsxs)(ec,{children:[(0,d.jsx)(tc,{onClick:()=>{re&&v.leftPanel.close()},children:(0,d.jsxs)(gc,{$menu:e.centerPanelMenuPosition||`top`,children:[e.centerPanelMenu?(0,d.jsx)(X,{$open:f.centerPanel.open,$position:e.centerPanelMenuPosition||`top`,children:e.centerPanelMenu}):null,(0,d.jsx)(Z,{children:(0,d.jsx)(C.ErrorBoundary,{resetKeys:[M?.id],FallbackComponent:io,children:y?(0,d.jsx)(nc,{children:(0,d.jsx)(qs,{stroke:`rgba(0,0,0,.3)`,fontSize:`2em`})}):f.centerPanel.open&&M?ro(M.render(f.centerPanel.state||M.defaultState||{},{...k,current:v.centerPanel,vault:o},n)):null})})]})}),!S.length&&!x.length?null:(0,d.jsxs)(rc,{$side:`left`,"aria-label":`Main and left panels`,children:[S.length?(0,d.jsx)(ac,{"aria-label":`Main panels`,children:S.filter(e=>!e.focusedMode?.hide).map(e=>(0,d.jsxs)(l.Tooltip,{placement:`right`,children:[(0,d.jsx)(l.TooltipTrigger,{asChild:!0,children:(0,d.jsx)(ic,{type:`button`,"aria-label":e.label,"data-selected":f.centerPanel.current===e.id,onClick:()=>{v.centerPanel.open({id:e.id}),v.leftPanel.close(),v.rightPanel.close(),I(e)},children:e.icon||e.label.slice(0,1)})}),(0,d.jsx)(l.DefaultTooltipContent,{children:e.label})]},e.id))}):null,S.length&&x.length?(0,d.jsx)(oc,{}):null,x.length?(0,d.jsx)(ac,{"aria-label":`Left panels`,children:x.map(e=>(0,d.jsxs)(l.Tooltip,{placement:`right`,children:[(0,d.jsx)(l.TooltipTrigger,{asChild:!0,children:(0,d.jsx)(ic,{type:`button`,"aria-label":e.label,"data-selected":P===e.id,onClick:()=>{if(e.modal){L&&v.rightPanel.close(),f.modal.open&&f.modal.current===e.id?v.modal.close():(v.modal.open({id:e.id,state:e.defaultState}),I(e));return}L&&v.rightPanel.close(),f.leftPanel.current===e.id?v.leftPanel.toggle():v.leftPanel.open({id:e.id})},children:e.icon||e.label.slice(0,1)})}),(0,d.jsx)(l.DefaultTooltipContent,{children:e.label})]},e.id))}):null]}),((e,t,n)=>{if(!t.length)return null;let r=e===`left`?v.leftPanel:v.rightPanel;return(0,d.jsx)(rc,{$side:e,"aria-label":`${e} panels`,children:t.map(t=>(0,d.jsxs)(l.Tooltip,{placement:e===`left`?`right`:`left`,children:[(0,d.jsx)(l.TooltipTrigger,{asChild:!0,children:(0,d.jsx)(ic,{type:`button`,"aria-label":t.label,"data-selected":n===t.id,onClick:()=>{L&&(e===`left`?v.rightPanel.close():v.leftPanel.close()),n===t.id?r.toggle():r.open({id:t.id})},children:t.icon||t.label.slice(0,1)})}),(0,d.jsx)(l.DefaultTooltipContent,{children:t.label})]},t.id))})})(`right`,w,f.rightPanel.current),D.length>0?(0,d.jsx)(sc,{$side:`left`,$open:f.leftPanel.open,style:{width:ie,minWidth:A?.options?.minWidth,maxWidth:A?.options?.maxWidth},children:(0,d.jsx)(cc,{children:y?(0,d.jsx)(Z,{children:(0,d.jsx)(Ys,{})}):(0,d.jsxs)(d.Fragment,{children:[e.leftPanelMenu?(0,d.jsx)(X,{$open:f.leftPanel.open,$position:e.leftPanelMenuPosition||`bottom`,children:e.leftPanelMenu}):null,(0,d.jsx)(Z,{children:A?(0,d.jsx)(mo,{isLeft:!0,panel:A,state:f.leftPanel,actions:v.leftPanel}):null})]})})}):null,w.length>0?(0,d.jsx)(sc,{$side:`right`,$open:f.rightPanel.open,style:{width:ae,minWidth:j?.options?.minWidth,maxWidth:j?.options?.maxWidth},children:(0,d.jsx)(cc,{children:y?(0,d.jsx)(Z,{children:(0,d.jsx)(Ys,{})}):(0,d.jsxs)(d.Fragment,{children:[e.rightPanelMenu?(0,d.jsx)(X,{$open:f.rightPanel.open,$position:e.rightPanelMenuPosition||`bottom`,children:e.rightPanelMenu}):null,(0,d.jsxs)(Z,{children:[te?(0,d.jsx)(mo,{panel:j,state:f.rightPanel,actions:v.rightPanel,pinActions:v.pinnedRightPanel,available:w}):null,F?(0,d.jsx)(mo,{panel:F,state:f.pinnedRightPanel,actions:v.pinnedRightPanel,close:v.rightPanel.close}):null]})]})})}):null]}),(0,d.jsx)(dc,{children:e.footer||null}),(0,d.jsx)(`div`,{className:`hidden`,children:R}),(0,d.jsx)(ea,{}),(0,d.jsx)(ta,{}),(0,d.jsx)(d.Fragment,{children:N?(0,d.jsx)(l.Modal,{title:N.label,open:f.modal.open,onClose:()=>v.modal.close(),children:N.modal?(0,d.jsx)(`div`,{className:`h-[70vh] min-h-[60vh] max-h-full flex w-full`,children:(0,d.jsx)(mo,{isLeft:!0,isModal:!0,noHeader:!0,panel:N,state:f.modal,actions:v.modal})}):ro(N.render(f.modal.state||N.defaultState||{},{...k,current:v.modal,vault:o,isModal:!0},n))}):null}),(0,d.jsx)(Da,{})]})})}),xc=g.default.div`
|
|
1413
1413
|
position: relative;
|
|
1414
1414
|
display: flex;
|
|
1415
1415
|
flex: 1;
|
|
1416
1416
|
overflow: hidden;
|
|
1417
1417
|
flex-direction: column;
|
|
1418
|
-
`,
|
|
1418
|
+
`,Sc=g.default.div`
|
|
1419
1419
|
flex: 1;
|
|
1420
1420
|
position: relative;
|
|
1421
1421
|
z-index: 7;
|
|
1422
|
-
`,
|
|
1422
|
+
`,Cc=g.default.div`
|
|
1423
1423
|
display: flex;
|
|
1424
1424
|
gap: 0.5rem;
|
|
1425
1425
|
width: 100%;
|
|
@@ -1428,7 +1428,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
1428
1428
|
padding: 0.5rem;
|
|
1429
1429
|
min-height: 4rem;
|
|
1430
1430
|
z-index: 9;
|
|
1431
|
-
`,
|
|
1431
|
+
`,wc=g.default.button`
|
|
1432
1432
|
flex: 1;
|
|
1433
1433
|
min-width: 0;
|
|
1434
1434
|
padding: 0.75rem 1rem;
|
|
@@ -1439,11 +1439,11 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
1439
1439
|
overflow: hidden;
|
|
1440
1440
|
text-overflow: ellipsis;
|
|
1441
1441
|
white-space: nowrap;
|
|
1442
|
-
`,
|
|
1442
|
+
`,Tc=g.default.div`
|
|
1443
1443
|
display: flex;
|
|
1444
1444
|
flex: 1;
|
|
1445
1445
|
min-width: 0;
|
|
1446
|
-
`,
|
|
1446
|
+
`,Ec=g.default.button`
|
|
1447
1447
|
display: flex;
|
|
1448
1448
|
align-items: center;
|
|
1449
1449
|
justify-content: center;
|
|
@@ -1463,7 +1463,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
1463
1463
|
flex: 0 0 auto;
|
|
1464
1464
|
font-size: 1.25em;
|
|
1465
1465
|
}
|
|
1466
|
-
`,
|
|
1466
|
+
`,Dc=g.default.div`
|
|
1467
1467
|
background: #fff;
|
|
1468
1468
|
display: flex;
|
|
1469
1469
|
position: absolute;
|
|
@@ -1494,7 +1494,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
1494
1494
|
padding-right: 0.5em;
|
|
1495
1495
|
font-size: 1.1em;
|
|
1496
1496
|
}
|
|
1497
|
-
`,
|
|
1497
|
+
`,Oc=g.default.div`
|
|
1498
1498
|
display: flex;
|
|
1499
1499
|
flex-direction: column;
|
|
1500
1500
|
position: absolute;
|
|
@@ -1510,7 +1510,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
1510
1510
|
${e=>e.$open&&g.css`
|
|
1511
1511
|
transform: translateX(0);
|
|
1512
1512
|
`}
|
|
1513
|
-
`,
|
|
1513
|
+
`,kc=g.default.button`
|
|
1514
1514
|
border: 0;
|
|
1515
1515
|
background: rgba(0, 0, 0, 0.4);
|
|
1516
1516
|
pointer-events: none;
|
|
@@ -1527,6 +1527,6 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
1527
1527
|
pointer-events: visible;
|
|
1528
1528
|
opacity: 1;
|
|
1529
1529
|
`}
|
|
1530
|
-
`,kc=(0,u.memo)(function(e){if(e.layoutMode===`focused`)return(0,d.jsx)(yc,{...e});let t=U(),n=Un(),r=W(),i=pi(),{vault:a}=(0,u.useContext)(m.ReactVaultContext),o=a||void 0,s=(0,m.useVaultSelector)(e=>e.iiif),c=(0,u.useRef)(null),f=(0,u.useRef)(null),{loading:p,state:h,leftPanels:g,centerPanels:_,rightPanels:v,modals:y=[],actions:b}=i,x=(0,u.useMemo)(()=>({rootResource:r,vault:o,app:t,layoutState:h,appState:n}),[r,o,t,h,n,s]),S=(0,u.useMemo)(()=>gc(g,x,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[g,x]),w=(0,u.useMemo)(()=>gc(_,x,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[_,x]),T=(0,u.useMemo)(()=>gc(v,x,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[v,x]),E=(0,u.useMemo)(()=>gc(y,x,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[y,x]),D=(0,u.useMemo)(()=>S.filter(e=>e.modal),[S]),k=(0,u.useMemo)(()=>S.filter(e=>!e.modal),[S]),A=(0,u.useMemo)(()=>[...E,...D],[E,D]),j=(0,u.useMemo)(()=>({...i,leftPanels:S,centerPanels:w,rightPanels:T,modals:A}),[i,S,w,T,A]),M=k.find(e=>e.id===h.leftPanel.current),N=T.find(e=>e.id===h.rightPanel.current),P=w.find(e=>e.id===h.centerPanel.current),F=A.find(e=>e.id===h.modal.current),te=h.modal.open&&D.some(e=>e.id===h.modal.current)?h.modal.current:h.leftPanel.current,ne=h.pinnedRightPanel.pinned?T.find(e=>e.id===h.pinnedRightPanel.current):void 0,[I]=Ls([`(max-width: 1020px)`]),re=e.isLoading||!1,L=(0,u.useMemo)(()=>(i.background||[]).map((e,t)=>(0,d.jsx)(u.Fragment,{children:e.render()},t)),[i.background]),R=Qs(`left-panel/${M?.id}`,{left:!0,marginLeft:60,minWidthPx:M?.options?.minWidth||200,maxWidthPx:M?.options?.maxWidth||720,loading:p}),z=Qs(`right-panel/${N?.id}`,{left:!1,minWidthPx:N?.options?.minWidth||320,maxWidthPx:N?.options?.maxWidth||720,loading:p}),ie=N&&(ne?.id!==N.id||!(0,ee.default)(h.pinnedRightPanel.state,h.rightPanel.state)),ae=R.widthB===`auto`?void 0:()=>R.setWidths({widthA:`auto`,widthB:no({options:M?.options,fallback:320})}),oe=z.widthB===`auto`?void 0:()=>z.setWidths({widthA:`auto`,widthB:no({options:N?.options,fallback:320})});if((0,u.useLayoutEffect)(()=>{I&&h.leftPanel.open&&h.rightPanel.open&&(b.leftPanel.close(),b.rightPanel.close())},[I]),(0,u.useLayoutEffect)(()=>{if(P&&P.onMount)return P.onMount(h.centerPanel.state||P.defaultState||{},{...j,current:b.centerPanel,vault:o},n)},[h.centerPanel.current,P?.id]),(0,u.useLayoutEffect)(()=>{if(h.leftPanel.current&&!M){let e=_c(k,h.leftPanel.current);e?b.leftPanel.change({id:e}):b.leftPanel.close()}if(h.centerPanel.current&&!P){let e=_c(w,h.centerPanel.current);e?b.centerPanel.change({id:e}):b.centerPanel.close()}if(h.rightPanel.current&&!N){let e=_c(T,h.rightPanel.current);e?b.rightPanel.change({id:e}):b.rightPanel.close()}if(h.modal.current&&!F){let e=_c(A,h.modal.current);e?b.modal.change({id:e}):b.modal.close()}},[h.leftPanel.current,h.centerPanel.current,h.rightPanel.current,h.modal.current,M?.id,P?.id,N?.id,F?.id,Q(k),Q(w),Q(T),Q(A)]),(0,u.useLayoutEffect)(()=>{T.length&&b.rightPanel.change({id:T[0].id}),k.length&&b.leftPanel.change({id:k[0].id}),w.length&&b.centerPanel.change({id:w[0].id})},[]),p)return null;let se=t=>(0,d.jsx)(hc,{$menu:e.leftPanelMenuPosition||`bottom`,ref:R.refs.resizableDiv,className:[`manifest-editor`,t?`transition transition-${t}`:``].join(` `),style:{width:h.leftPanel.open||t!==`exited`?R.widthB:void 0,minWidth:M?.options?.minWidth},children:re?(0,d.jsx)(Z,{children:(0,d.jsx)(Js,{})}):(0,d.jsxs)(d.Fragment,{children:[e.leftPanelMenu?(0,d.jsx)(X,{$open:h.leftPanel.open&&t!==`exited`,$position:e.leftPanelMenuPosition||`bottom`,children:e.leftPanelMenu}):null,(0,d.jsx)(Z,{children:h.leftPanel.open||t!==`exited`?(0,d.jsx)(d.Fragment,{children:M?(0,d.jsx)(mo,{isLeft:!0,noHeader:!0,transition:t,panel:M,state:h.leftPanel,actions:b.leftPanel}):null}):null})]})}),ce=()=>F?(0,d.jsx)(l.Modal,{title:F.label,open:h.modal.open,onClose:()=>b.modal.close(),children:F.modal?(0,d.jsx)(`div`,{className:`h-[70vh] min-h-[60vh] max-h-full flex w-full`,children:(0,d.jsx)(mo,{isLeft:!0,isModal:!0,noHeader:!0,panel:F,state:h.modal,actions:b.modal})}):ro(F.render(h.modal.state||F.defaultState||{},{...j,current:b.modal,vault:o,isModal:!0},n))}):null,le=()=>(0,d.jsxs)(hc,{$menu:e.centerPanelMenuPosition||`top`,children:[e.centerPanelMenu?(0,d.jsx)(X,{$open:h.centerPanel.open,$position:e.centerPanelMenuPosition||`top`,children:e.centerPanelMenu}):null,(0,d.jsx)(Z,{children:(0,d.jsx)(C.ErrorBoundary,{resetKeys:[P?.id],FallbackComponent:io,children:re?(0,d.jsx)(`div`,{style:{display:`flex`,flex:1,justifyContent:`center`,alignItems:`center`},children:(0,d.jsx)(Ks,{stroke:`rgba(0,0,0,.3)`,fontSize:`2em`})}):h.centerPanel.open&&P?ro(P.render(h.centerPanel.state||P.defaultState||{},{...j,current:b.centerPanel,vault:o},n)):null})})]}),ue=t=>(0,d.jsx)(hc,{$menu:e.rightPanelMenuPosition||`bottom`,ref:z.refs.resizableDiv,className:t?`transition transition-${t}`:``,style:{width:h.rightPanel.open||t!==`exited`?z.widthB:void 0,minWidth:N?.options?.minWidth},children:re?(0,d.jsx)(Z,{children:(0,d.jsx)(Js,{})}):(0,d.jsxs)(d.Fragment,{children:[e.rightPanelMenu?(0,d.jsx)(X,{$open:h.rightPanel.open,$position:e.rightPanelMenuPosition||`bottom`,children:e.rightPanelMenu}):null,(0,d.jsx)(Z,{children:h.rightPanel.open||t!==`exited`?(0,d.jsxs)(d.Fragment,{children:[ie?(0,d.jsx)(mo,{panel:N,state:h.rightPanel,actions:b.rightPanel,pinActions:b.pinnedRightPanel,available:T}):null,ne?(0,d.jsx)(mo,{panel:ne,state:h.pinnedRightPanel,actions:b.pinnedRightPanel,close:b.rightPanel.close}):null]}):null})]})});return I?(0,d.jsxs)(cc,{children:[e.hideHeader?null:(0,d.jsxs)(lc,{children:[e.header||null,e.menu?(0,d.jsx)(`menu`,{children:e.menu}):null]}),(0,d.jsx)(dc,{children:(0,d.jsxs)(bc,{children:[(0,d.jsxs)(Sc,{children:[k.length>0?(0,d.jsx)(Cc,{type:`button`,"aria-expanded":h.leftPanel.open,onClick:()=>{b.rightPanel.close(),b.leftPanel.toggle()},children:M?.label}):null,T.length>0?(0,d.jsx)(wc,{children:(0,d.jsxs)(Tc,{type:`button`,"aria-expanded":h.rightPanel.open,onClick:()=>{b.leftPanel.close(),b.rightPanel.toggle()},children:[(0,d.jsx)(nr,{"aria-hidden":`true`,rotate:90}),N?.label]})}):null]}),(0,d.jsx)(xc,{children:le()}),T.length>0?(0,d.jsx)(Ec,{$open:h.rightPanel.open,children:ue()}):null,k.length>0?(0,d.jsxs)(Dc,{$open:h.leftPanel.open,children:[(0,d.jsx)(`nav`,{"aria-label":`Left panel tabs`,className:`flex flex-none overflow-x-auto border-b border-gray-300`,children:k.map(e=>(0,d.jsxs)(`button`,{type:`button`,"aria-pressed":h.leftPanel.current===e.id,className:`flex flex-1 shrink-0 items-center justify-center gap-1.5 border-0 border-b-[3px] p-3 text-gray-700 [&>svg]:shrink-0 [&>svg]:text-xl ${h.leftPanel.current===e.id?`border-b-[#b83265] bg-[#f9e8ef]`:`border-b-transparent bg-white`}`,onClick:()=>{b.rightPanel.close(),b.leftPanel.open({id:e.id,state:e.defaultState})},children:[e.icon,e.label]},e.id))}),se()]}):null,S.length>0||T.length>0?(0,d.jsx)(Oc,{type:`button`,"aria-label":`Close panels`,$open:h.leftPanel.open||h.rightPanel.open,onClick:()=>{b.leftPanel.close(),b.rightPanel.close()}}):null]})}),(0,d.jsx)(`div`,{className:`hidden`,children:L}),(0,d.jsx)(ea,{}),(0,d.jsx)(ta,{}),(0,d.jsx)(d.Fragment,{children:ce()}),(0,d.jsx)(Da,{})]}):(0,d.jsxs)(cc,{id:e.htmlId||`manifest-editor-container`,className:`manifest-editor ${e.className||``}`,children:[e.hideHeader?null:(0,d.jsxs)(lc,{children:[e.header||null,e.menu?(0,d.jsx)(`menu`,{children:e.menu}):null]}),(0,d.jsxs)(dc,{ref:e=>{R.refs.container.current=e,z.refs.container.current=e},children:[S.length>0?(0,d.jsx)(l.PanelSideMenu,{current:te,items:S.map(e=>({id:e.id,label:e.label,icon:e.icon,divide:e.divide,separator:e.separator,onClick:()=>{if(e.modal){h.modal.open&&h.modal.current===e.id?b.modal.close():b.modal.open({id:e.id,state:e.defaultState});return}h.leftPanel.current===e.id?b.leftPanel.toggle():b.leftPanel.change({id:e.id})}})),open:h.leftPanel.open}):null,k.length>0?(0,d.jsx)(O.Transition,{nodeRef:c,in:h.leftPanel.open,timeout:400,unmountOnExit:!1,children:e=>(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(fc,{ref:c,$width:R.widthB,$state:e,$motion:!0,children:se(e)}),(0,d.jsx)(Gs,{ref:R.refs.resizer,reset:ae,dir:`left`,transition:e,open:h.leftPanel.open||e!==`exited`,actions:b.leftPanel})]})}):null,(0,d.jsx)(pc,{children:le()}),T.length>0?(0,d.jsx)(O.Transition,{nodeRef:f,in:h.rightPanel.open,timeout:400,unmountOnExit:!1,children:e=>(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(Gs,{ref:z.refs.resizer,dir:`right`,reset:oe,open:h.rightPanel.open,actions:b.rightPanel}),(0,d.jsx)(mc,{ref:f,$width:z.widthB,$state:e,$motion:!0,children:ue(e)})]})}):null]}),(0,d.jsx)(uc,{children:e.footer||null}),(0,d.jsx)(`div`,{className:`hidden`,children:L}),(0,d.jsx)(ea,{}),(0,d.jsx)(ta,{}),(0,d.jsx)(d.Fragment,{children:ce()}),(0,d.jsx)(Da,{})]})});function Ac(e,t){function n(){t({type:`popStack`,panel:e,payload:void 0})}function r(n){t({type:`change`,panel:e,payload:n})}function i(n){t({type:`open`,panel:e,payload:n})}function a(){t({type:`close`,panel:e,payload:void 0})}function o(){t({type:`toggle`,panel:e,payload:void 0})}function s(){t({type:`minimise`,panel:e,payload:void 0})}function c(n){t({type:`maximise`,panel:e,payload:n})}function l(n){t({type:`setCustomWidth`,panel:e,payload:n})}function d(){t({type:`resetSize`,panel:e,payload:void 0})}function f(n){t({type:`pin`,panel:e,payload:n})}function p(){t({type:`unpin`,panel:e,payload:void 0})}return(0,u.useMemo)(()=>({popStack:n,change:r,open:i,close:a,toggle:o,minimise:s,maximise:c,setCustomWidth:l,resetSize:d,pin:f,unpin:p}),[])}function jc(e,t){if(t.payload&&t.payload.stacked){if(e.current){let n=e.stack[e.stack.length-1];if(n&&n.id===e.current)return;t.payload.unique&&(e.stack=e.stack.filter(t=>t.id!==e.current)),e.stack.push({id:e.current,state:e.state?{...(0,_.original)(e.state)}:{}})}}else e.stack=[]}function Mc(e,t){switch(t.type){case`popStack`:if(e.stack.length){let t=e.stack[e.stack.length-1];t&&(e.current=t.id,e.state=t.state),e.stack=e.stack.slice(0,-1)}break;case`change`:t.payload.id!==e.current&&jc(e,t),e.state=t.payload.state,e.current=t.payload.id;break;case`close`:e.open=!1;break;case`open`:e.open=!0,t.payload&&(t.payload.id!==e.current&&jc(e,t),e.state=t.payload.state,e.current=t.payload.id);break;case`toggle`:e.open=!e.open;break;case`maximise`:e.minimised=!1,t.payload&&(e.state=t.payload.state,e.current=t.payload.id);break;case`minimise`:e.minimised=!0;break;case`setCustomWidth`:e.customWidth=t.payload;break;case`resetSize`:e.customWidth=void 0}if(to(e))switch(t.type){case`pin`:e.pinned=!0,e.state=t.payload.state,e.current=t.payload.id;break;case`unpin`:e.pinned=!1,e.state=void 0}}const Nc=(0,_.produce)((e,t)=>{switch(t.panel){case`centerPanel`:Mc(e.centerPanel,t);break;case`leftPanel`:Mc(e.leftPanel,t);break;case`rightPanel`:Mc(e.rightPanel,t);break;case`modal`:Mc(e.modal,t);break;case`pinnedRightPanel`:Mc(e.pinnedRightPanel,t)}});function Pc(){return{customWidth:void 0,minimised:!1,open:!0,current:null,state:null,stack:[]}}function Fc(){return{leftPanel:Pc(),centerPanel:Pc(),rightPanel:Pc(),modal:Pc(),pinnedRightPanel:{...Pc(),pinnable:!0,pinned:!1}}}function Ic({className:e,variant:t=`light`}){let n=(0,m.useManifest)(),r=(0,m.useVault)(),{edit:i}=ui(),a=Yr(),o=Xr(),s=n?.items||[],c=n?.viewingDirection===`right-to-left`||n?.viewingDirection===`bottom-to-top`,l=n?.viewingDirection===`top-to-bottom`||n?.viewingDirection===`bottom-to-top`,f=Lc(a)||o.map(Lc).find(Boolean)||s[0]?.id||``,p=Math.max(0,s.findIndex(e=>e.id===f)),h=s[p]?.id||``,g=p+1,_=(0,u.useMemo)(()=>s.map((e,t)=>{let n=r.get({id:e.id,type:`Canvas`});return{id:e.id,pageNumber:t+1,labelText:(0,b.getValue)(n?.label)||`Page ${t+1}`}}),[s,r]),v=e=>{let t=s.findIndex(t=>t.id===e),r=s[t];!r||!n||i({id:r.id,type:`Canvas`},{parent:{id:n.id,type:`Manifest`},property:`items`,index:t},{forceOpen:!1})};if(!n||s.length<2)return(0,d.jsx)(`div`,{});let y=s[p-1],x=s[p+1],S=t===`dark`;return(0,d.jsxs)(`nav`,{"aria-label":`Manifest pagination`,className:Vc(`inline-flex shrink-0 items-center gap-1 rounded-full border px-1.5 py-1`,`focus-within:ring-2 focus-within:ring-me-primary-500/40`,c&&`flex-row-reverse`,S?`border-white/20 bg-white/10 text-white`:`border-me-gray-300 bg-white text-me-gray-900`,e),children:[(0,d.jsx)(Rc,{ariaLabel:`Previous canvas`,disabled:!y,onClick:()=>y&&v(y.id),dark:S,children:(0,d.jsx)(zc,{reverse:c,vertical:l})}),(0,d.jsxs)(`label`,{htmlFor:`manifest-pagination-page-select`,"aria-label":`Page ${g} of ${s.length}`,className:Vc(`relative inline-flex min-h-8 cursor-pointer select-none items-center gap-0.5`,`whitespace-nowrap rounded-full border px-2.5 text-xs font-semibold leading-none`,`focus-within:outline-none focus-within:ring-2 focus-within:ring-me-primary-500/40`,S?`border-white/20 bg-white/10 text-white hover:bg-white/15`:`border-me-gray-300 bg-me-gray-100 text-me-gray-900 hover:bg-me-primary-50`),children:[(0,d.jsxs)(`span`,{children:[g,` / `,s.length]}),(0,d.jsx)(Bc,{className:Vc(`shrink-0 text-base`,S?`text-white/60`:`text-me-gray-500`)}),(0,d.jsx)(`select`,{id:`manifest-pagination-page-select`,"aria-label":`Jump to canvas`,value:h,onChange:e=>v(e.target.value),className:`absolute inset-0 cursor-pointer appearance-none border-0 bg-white opacity-0`,children:_.map(e=>(0,d.jsxs)(`option`,{value:e.id,children:[`Page `,e.pageNumber,` - `,e.labelText]},e.id))})]}),(0,d.jsx)(Rc,{ariaLabel:`Next canvas`,disabled:!x,onClick:()=>x&&v(x.id),dark:S,children:(0,d.jsx)(zc,{reverse:!c,vertical:l})})]})}function Lc(e){let t=e?.resource?.source;return t?.type===`Canvas`?t.id:null}function Rc({ariaLabel:e,children:t,dark:n,disabled:r,onClick:i}){return(0,d.jsx)(`button`,{type:`button`,"aria-label":e,disabled:r,onClick:i,className:Vc(`inline-flex h-8 w-8 items-center justify-center rounded-full border-0 bg-transparent p-0`,`text-lg transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-me-primary-500/50`,n?`text-white hover:bg-white/15 disabled:text-white/40 disabled:hover:bg-transparent`:`text-me-gray-900 hover:bg-me-primary-50 disabled:text-me-gray-500 disabled:hover:bg-transparent`,`disabled:cursor-not-allowed`),children:t})}function zc({reverse:e,vertical:t}){return(0,d.jsx)(e?l.ArrowRightIcon:l.BackIcon,{"aria-hidden":!0,className:Vc(`block`,t&&`rotate-90`)})}function Bc(e){return(0,d.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,"aria-hidden":!0,...e,children:(0,d.jsx)(`path`,{fill:`currentColor`,d:`m7 10l5 5l5-5z`})})}function Vc(...e){return e.filter(Boolean).join(` `)}const Hc=new WeakMap;function Uc(e,t){let n={port:t,lastActionId:`@genesis`},r=Wc(e);function i(e){t.postMessage(typeof e==`string`?e:JSON.stringify(e))}function a(){i({_id:Lt(),_type:`init-response`,_lastActionId:n.lastActionId,data:e.getState()})}function o(e){i({_id:e,_type:`vault-action-rejection`,_lastActionId:n.lastActionId,action:e})}function s(e){let t=Kc(e.data);if(t){if(t._type===`init-request`){a();return}t._type===`vault-action`&&o(t._id)}}return r.targets.add(n),t.addEventListener(`message`,s),t.start(),()=>{t.removeEventListener(`message`,s),r.targets.delete(n),r.targets.size===0&&e.dispatch===r.patchedDispatch&&(e.dispatch=r.originalDispatch,Hc.delete(e)),t.close()}}function Wc(e){let t=Hc.get(e);if(t)return t;let n=e.dispatch.bind(e),r=new Set,i=(e=>{let t=n(e);for(let t of r)Gc(t,e);return t}),a={originalDispatch:n,patchedDispatch:i,targets:r};return e.dispatch=i,Hc.set(e,a),a}function Gc(e,t){let n={_id:Lt(),_type:`vault-action`,_lastActionId:e.lastActionId,action:t};e.lastActionId=n._id,e.port.postMessage(JSON.stringify(n))}function Kc(e){try{if(typeof e==`string`)return JSON.parse(e);if(typeof e==`object`&&e)return e}catch{return null}return null}const qc=(0,u.createContext)(null);function Jc({children:e}){let t=(0,m.useVault)(),n=(0,u.useRef)(null),r=(0,u.useRef)(null),i=(0,u.useRef)(null),a=(0,u.useRef)(!1),[o,s]=(0,u.useState)(!0),c=(0,u.useCallback)(()=>{if(!n.current||n.current.closed||!r.current)return;i.current?.();let e=new MessageChannel;i.current=Uc(t,e.port1),n.current.postMessage({_type:`manifest-editor:iframe-preview:connect`,resource:r.current.resource,canvasId:r.current.canvasId||null,annotationId:r.current.annotationId||void 0},new URL(r.current.url).origin,[e.port2]),a.current=!0},[t]);(0,u.useEffect)(()=>{let e=e=>{!r.current||e.source!==n.current||e.origin===new URL(r.current.url).origin&&e.data?._type===`manifest-editor:iframe-preview:ready`&&c()},t=window.setInterval(()=>{n.current?.closed&&(i.current?.(),i.current=null,a.current=!1,n.current=null,s(!0))},1e3);return window.addEventListener(`message`,e),()=>{window.removeEventListener(`message`,e),window.clearInterval(t),i.current?.()}},[c]);let l=(0,u.useCallback)(e=>{r.current=e;let t=n.current;if(t&&!t.closed){t.focus();return}i.current?.(),i.current=null,a.current=!1,n.current=window.open(e.url,e.name||`manifest-editor-preview`,e.features||`popup,width=1200,height=900`),s(!n.current)},[]),f=(0,u.useCallback)(e=>{let t=r.current;r.current=e;let o=n.current;if(!(!o||o.closed)){if(t&&(t.url!==e.url||t.reloadKey!==e.reloadKey)){i.current?.(),i.current=null,a.current=!1,o.location.href=e.url;return}a.current&&o.postMessage({_type:`manifest-editor:iframe-preview:selection`,resource:e.resource,canvasId:e.canvasId||null,annotationId:e.annotationId||void 0},new URL(e.url).origin)}},[]),p=(0,u.useCallback)(()=>{n.current&&!n.current.closed&&n.current.focus()},[]);return(0,d.jsx)(qc.Provider,{value:{open:l,update:f,focus:p,isClosed:o},children:e})}function Yc(){let e=(0,u.useContext)(qc);return N(e,`usePreviewWindow() can only be called from inside <PreviewWindowProvider />`),e}var Xc=class extends u.Component{constructor(...e){super(...e),G(this,`state`,{hasError:!1})}static getDerivedStateFromError(e){return console.error(e),{hasError:!0}}componentDidCatch(e,t){console.error(`Uncaught error:`,e,t)}render(){return this.state.hasError?(0,d.jsx)(`h1`,{children:`Sorry.. there was an error`}):this.props.children}};function Zc(e,t){return typeof e==`string`?{id:e,state:t}:e}const Qc=(0,u.memo)(function(e){let t=U(),n=Fs(),r=t.layout,[i,a]=(0,u.useReducer)(Nc,void 0,Fc),o={centerPanel:Ac(`centerPanel`,a),leftPanel:Ac(`leftPanel`,a),rightPanel:Ac(`rightPanel`,a),pinnedRightPanel:Ac(`pinnedRightPanel`,a),modal:Ac(`modal`,a),editingStack:Jr()};function s(e){let t=r.rightPanels.find(t=>t.id===e);if(t)return[t,o.rightPanel,o.pinnedRightPanel];let n=r.centerPanels.find(t=>t.id===e);if(n)return[n,o.centerPanel];let i=r.leftPanels.find(t=>t.id===e);if(i)return i.modal?[i,o.modal]:[i,o.leftPanel];N(!1,`Was not able to find panel with id "${e}"`)}function c(e,t){let{id:r,state:i,stacked:a}=Zc(e,t),[o,c,l]=s(r);if(l&&o.options?.openPinned)l.pin({id:r,state:{...o.defaultState||{},...i||{}}});else{let e={id:r,state:{...o.defaultState||{},...i||{}},stacked:a};n.emit(`layout.open`,e),c.open(e)}}function l(e,t){let{id:r,state:i}=Zc(e,t),[a,o]=s(r),c={id:r,state:{...a.defaultState||{},...i||{}},stacked:!0};n.emit(`layout.open`,c),o.open(c)}function f(e,t){let{id:r,state:i,stacked:a}=Zc(e,t),[o,c]=s(r),l={id:r,state:{...o.defaultState||{},...i||{}},stacked:a};n.emit(`layout.change`,l),c.change(l)}function p(e,t){let{id:r}=Zc(e,t),[,i]=s(r);n.emit(`layout.close`,{id:r}),i.close()}function m(e,t){let{id:r}=Zc(e,t),[,i]=s(r);n.emit(`layout.toggle`,{id:r}),i.toggle()}function g(e,t={},{reset:i,property:a,stacked:s,forceOpen:c,selectedTab:l}={}){let u={resource:(0,h.isSpecificResource)(e)?e:{type:`SpecificResource`,source:e},...t};n.emit(`layout.edit`,u),o.editingStack.edit(u,i),r.rightPanels.find(e=>e.id===`@manifest-editor/editor`)&&(c?o.rightPanel.open({id:`@manifest-editor/editor`,stacked:s!==!1,state:{property:a,currentTab:l},unique:!0}):o.rightPanel.change({id:`@manifest-editor/editor`,stacked:s!==!1,state:{property:a,currentTab:l},unique:!0}))}async function _(e){o.editingStack.create(e,{}),n.emit(`layout.create`,e),r.modals?.find(e=>e.id===`@manifest-editor/creator`)?o.modal.open({id:`@manifest-editor/creator`,stacked:!0,unique:!0,state:e}):r.rightPanels.find(e=>e.id===`@manifest-editor/creator`)&&o.rightPanel.open({id:`@manifest-editor/creator`,stacked:!0,unique:!0,state:e})}let v={open:c,change:f,close:p,toggle:m,stack:l,edit:g,create:_};return(0,d.jsx)(oi.Provider,{value:(0,u.useMemo)(()=>({...o,...v}),[r]),children:(0,d.jsx)(si.Provider,{value:i,children:e.children})})}),$c=[{id:`universal-viewer`,config:{url:`https://universalviewer.dev/#?iiifManifestId={manifestId}`},type:`external-manifest-preview`,label:`Universal viewer`},{id:`mirador-3`,type:`external-manifest-preview`,label:`Mirador 3`,config:{url:`https://tomcrane.github.io/scratch/mirador3/?iiif-content={manifestId}`}},{id:`annona`,type:`external-manifest-preview`,label:`Annona`,config:{url:`https://ncsu-libraries.github.io/annona/tools/#/display?url={manifestId}&viewtype=iiif-storyboard&settings=%7B%22fullpage%22%3Atrue%7D`}},{id:`iiif-preview`,config:{url:`https://iiif-preview.digirati.services/store`},type:`iiif-preview-service`,label:`IIIF Preview`}],el=new k.ImageServiceLoader({approximateServices:!0,verificationsRequired:8,enableFetching:!0});function tl({config:e,saveConfig:t,children:n,theme:r,previews:i,resource:a,editing:o,backgroundActionPersistence:s}){let c=Hn(),l=z(),f=(0,u.useMemo)(()=>{let t=e?.previews||(l.previews?.length?l.previews:$c);return re(l,{previews:t},e)},[l,e]),p=(0,u.useMemo)(()=>({appId:c.appId,instanceId:c.instanceId,rootResource:{id:a.id,type:a.type}}),[c.appId,c.instanceId,a.id,a.type]);return(0,d.jsx)(Xc,{children:(0,d.jsx)(m.ImageServiceLoaderContext.Provider,{value:el,children:(0,d.jsx)(lr,{resource:a,children:(0,d.jsx)(xo,{children:(0,d.jsx)(g.ThemeProvider,{theme:r||Lo,children:(0,d.jsxs)(ae,{config:f,saveConfig:t,children:[(0,d.jsx)(Rn,{config:f}),(0,d.jsx)(ii,{children:(0,d.jsx)(Qc,{children:(0,d.jsx)(kt,{persistence:s,persistenceKey:p,children:(0,d.jsx)(as,{children:(0,d.jsx)(Gi,{children:(0,d.jsx)(xr,{previews:i||[],configs:f.previews,children:(0,d.jsx)(Jc,{children:(0,d.jsx)(m.AtlasStoreProvider,{children:n})})})})})})})})]})})})})})})}const nl=new Set([`Collection`,`Manifest`,`Canvas`,`Range`,`AnnotationPage`,`Annotation`,`ContentResource`,`Agent`]),rl={satisfied:0,missing:0,invalid:0,disallowed:0,"not-applicable":0},il=new Set([`label`,`summary`,`language`,`navDate`,`provider`,`requiredStatement`,`rights`,`thumbnail`]);function al(e){return e?Array.isArray(e)?e.filter(Boolean):e.split(`.`).filter(Boolean):[]}function ol(e,t){let n=al(e),r=al(t);return n.length===r.length&&n.every((e,t)=>e===r[t])}function sl(e,t){let n=e;for(let e of al(t)){if(n==null)return;n=n[e]}return n}function cl(e,t,n){let r=al(t);if(!r.length)return n;let i=Array.isArray(e)?[...e]:{...e||{}},a=i;return r.forEach((e,t)=>{if(t===r.length-1){a[e]=n;return}let i=a[e];a[e]=Array.isArray(i)?[...i]:{...i||{}},a=a[e]}),i}function $(e){if(e==null)return!1;if(typeof e==`string`)return e.trim().length>0;if(typeof e==`number`||typeof e==`boolean`)return!0;if(Array.isArray(e))return e.some(e=>$(e));if(typeof e!=`object`)return!1;let t=Object.entries(e);return t.length?!t.every(([,e])=>typeof e==`string`||Array.isArray(e)&&e.every(e=>typeof e==`string`))||t.some(([,e])=>$(e)):!1}function ll(e){return Array.isArray(e)?e.map(ll):e&&typeof e==`object`?Object.keys(e).sort().reduce((t,n)=>(t[n]=ll(e[n]),t),{}):e}function ul(e,t){return JSON.stringify(ll(e))===JSON.stringify(ll(t))}function dl(e,t,n,r){let i=al(n);for(let n of e||[])for(let e of n.terminology?.properties||[])if(!(e.entityType&&e.entityType!==t)&&ol(e.path,i))return e.label;return r||zl(i)}function fl(e,t,n){let r=al(n),i=[],a,o,s=!1,c=!1;if(!t||!nl.has(t.type))return{entityType:t?.type,path:r,label:dl(e,t?.type,r),disallowed:!1,required:!1,rules:i};for(let n of e||[])for(let e of n.rules||[])!(`entityType`in e)||!(`path`in e)||e.entityType===t.type&&ol(e.path,r)&&(i.push(e),e.type===`disallow-property`&&(s=!0),e.type===`require-non-empty`&&(c=!0),e.type===`fixed-value`&&!o&&(a=e.value,o=e,c=!0));return{entityType:t.type,path:r,label:dl(e,t.type,r),disallowed:s,required:c,fixedValue:a,fixedValueRule:o,rules:i}}function pl(e,t,n){let r=e||[],i=ml(t,n),a=[];for(let e of r)for(let[n,r]of(e.rules||[]).entries())a.push(...hl(e,r,n,i,t));return{specifications:r,results:a,counts:wl(a)}}function ml(e,t){let n=[],r=new Set;function i(t){let a=El(t);if(!a)return;if(a.type===`SpecificResource`){i(t?.source);return}let o=Tl(e,t)||Tl(e,a);if(!o||!o.type)return;let s=`${o.type}:${o.id||JSON.stringify(a)}`;if(!r.has(s)){r.add(s),nl.has(o.type)&&n.push({ref:{id:o.id,type:o.type},resource:o});for(let e of Dl(o))i(e)}}return i(t),n}function hl(e,t,n,r,i){switch(t.type){case`disallow-property`:case`require-non-empty`:case`fixed-value`:return gl(e,t,n,r);case`iiif:canvas-with-image-service`:return[_l(e,t,n,r,i)];case`iiif:thumbnail-from-body-service`:return vl(e,t,n,r,i);case`iiif:valid-rights`:return yl(e,t,n,r);case`iiif:required-statement`:return bl(e,t,n,r);case`iiif:metadata-template`:return xl(e,t,n,r);default:return[]}}function gl(e,t,n,r){let i=r.filter(e=>e.ref.type===t.entityType),a=dl(e?[e]:[],t.entityType,t.path);return i.length?i.map(({ref:r,resource:i})=>{let o=sl(i,t.path),s=$(o);if(t.type===`disallow-property`)return Sl(e,t,n,{target:r,path:t.path,status:s?`disallowed`:`satisfied`,displayLabel:a,actual:o,message:s?`${a} is present but is not allowed.`:`${a} is not present.`,editorTarget:Cl(r,t.path)});if(t.type===`require-non-empty`)return Sl(e,t,n,{target:r,path:t.path,status:s?`satisfied`:`missing`,displayLabel:a,actual:o,message:s?`${a} has a value.`:`${a} must be filled in.`,editorTarget:Cl(r,t.path)});let c=ul(o,t.value);return Sl(e,t,n,{target:r,path:t.path,status:c?`satisfied`:s?`invalid`:`missing`,displayLabel:a,expected:t.value,actual:o,message:c?`${a} matches the required value.`:s?`${a} does not match the required value.`:`${a} must use the required value.`,editorTarget:Cl(r,t.path)})}):[Sl(e,t,n,{status:`not-applicable`,displayLabel:a,message:`No ${t.entityType} resources were found for ${a}.`,path:t.path})]}function _l(e,t,n,r,i){let a=r.filter(e=>e.ref.type===`Canvas`),o=Ol(t),s=a.find(({resource:e})=>kl(Al(e,i),o));return Sl(e,t,n,{target:s?.ref,status:s?`satisfied`:`missing`,displayLabel:t.label||`Canvas image service`,expected:o,message:s?`A canvas contains the required image service.`:o.length?`A canvas must contain one of the required image services: ${o.join(`, `)}.`:`A canvas must contain a painting body with an image service.`,editorTarget:s?Cl(s.ref,[`items`]):void 0})}function vl(e,t,n,r,i){let a=t.entityType||`Canvas`,o=r.filter(e=>e.ref.type===a);return o.length?o.map(({ref:o,resource:s})=>{let c=a===`Manifest`?r.filter(e=>e.ref.type===`Canvas`).flatMap(e=>Al(e.resource,i)):Al(s,i),l=jl(s,c,i),u=$(s.thumbnail);return Sl(e,t,n,{target:o,path:[`thumbnail`],status:l?`satisfied`:c.length?u?`invalid`:t.requireThumbnail===!1?`not-applicable`:`missing`:`not-applicable`,displayLabel:dl([e],o.type,[`thumbnail`],`Thumbnail`),expected:c,actual:s.thumbnail,message:l?`Thumbnail uses the same image service as the painting content.`:c.length?u?`Thumbnail does not use the same image service as the painting content.`:`Thumbnail must be created from the painting image service.`:`No painting image service was found to compare against.`,editorTarget:Cl(o,[`thumbnail`])})}):[Sl(e,t,n,{status:`not-applicable`,displayLabel:`Thumbnail`,message:`No ${a} resources were found for thumbnail checks.`})]}function yl(e,t,n,r){let i=t.entityType||`Manifest`,a=r.filter(e=>e.ref.type===i),o=t.allowed||[];return a.map(({ref:r,resource:i})=>{let a=i.rights,s=$(a),c=typeof a==`string`&&o.map(Fl).includes(Fl(a));return Sl(e,t,n,{target:r,path:[`rights`],status:c?`satisfied`:!s&&t.required!==!1?`missing`:`invalid`,displayLabel:dl([e],r.type,[`rights`],`Rights`),expected:o,actual:a,message:c?`Rights uses an allowed URI.`:!s&&t.required!==!1?`Rights must use an allowed URI.`:`Rights is not one of the allowed URIs.`,editorTarget:Cl(r,[`rights`])})})}function bl(e,t,n,r){let i=t.entityType||`Manifest`;return r.filter(e=>e.ref.type===i).map(({ref:r,resource:i})=>{let a=i.requiredStatement,o=t.label?Il(a?.label,t.label):$(a?.label),s=t.value||t.valueRequired!==!1,c=t.value?Il(a?.value,t.value):!s||$(a?.value),l=$(a);return Sl(e,t,n,{target:r,path:[`requiredStatement`],status:o&&c?`satisfied`:l?`invalid`:`missing`,displayLabel:dl([e],r.type,[`requiredStatement`],`Required statement`),expected:t.value||t.label,actual:a,message:o&&c?`Required statement is complete.`:l?`Required statement does not match the specification.`:`Required statement must be filled in.`,editorTarget:Cl(r,[`requiredStatement`])})})}function xl(e,t,n,r){let i=t.entityType||`Manifest`,a=r.filter(e=>e.ref.type===i),o=[];for(let{ref:r,resource:i}of a){let a=Array.isArray(i.metadata)?i.metadata:[];t.items.forEach((i,s)=>{let c=a.find(e=>Il(e?.label,i.label)),l=i.value?Il(c?.value,i.value):!i.valueRequired||$(c?.value),u=c&&l?`satisfied`:c&&i.value?`invalid`:`missing`,d=Rl(i.label);o.push(Sl(e,t,n,{idSuffix:`metadata-${s}`,target:r,path:[`metadata`],status:u,displayLabel:d||`Metadata`,expected:i.value||i.label,actual:c,message:c&&l?`${d||`Metadata`} is present.`:c?`${d||`Metadata`} needs a value.`:`${d||`Metadata`} metadata must be added.`,editorTarget:Cl(r,[`metadata`])}))})}return o}function Sl(e,t,n,r){let i=t.id||`${t.type}-${n}`,a=r.idSuffix?`-${r.idSuffix}`:``;return{id:`${e.id}-${i}-${r.target?.type||`root`}-${r.target?.id||`none`}${a}`,specificationId:e.id,specificationLabel:e.label,ruleId:i,ruleType:t.type,ruleLabel:t.label||r.displayLabel,ruleIndex:n,target:r.target,path:r.path,status:r.status,displayLabel:r.displayLabel,message:t.message||r.message,expected:r.expected,actual:r.actual,editorTarget:r.editorTarget}}function Cl(e,t){let n=t[0];return{resource:e,propertyPath:t,selectedTab:n===`metadata`?`@manifest-editor/metadata`:n&&il.has(n)?`@manifest-editor/descriptive-properties`:void 0}}function wl(e){let t={...rl};for(let n of e)t[n.status]+=1;return t}function Tl(e,t){let n=El(t);if(!n)return t;try{return e.get(n,{skipSelfReturn:!1})||t}catch{try{return e.get(n)||t}catch{return t}}}function El(e){return!e||typeof e!=`object`?null:e.type===`SpecificResource`?{id:e.id||e.source?.id||``,type:`SpecificResource`}:typeof e.id==`string`&&typeof e.type==`string`?{id:e.id,type:e.type}:null}function Dl(e){if(!e||typeof e!=`object`)return[];let t=[];for(let n of[`items`,`structures`,`annotations`,`thumbnail`,`provider`,`homepage`,`rendering`,`seeAlso`,`body`,`target`,`source`]){let r=e[n];Array.isArray(r)?t.push(...r):r&&t.push(r)}return t}function Ol(e){return[...e.serviceIds||[],...e.serviceId?[e.serviceId]:[]].filter(Boolean)}function kl(e,t){let n=new Set(e.filter(Boolean));return t.length?t.some(e=>n.has(e)):n.size>0}function Al(e,t){let n=Pl(t,e?.items),r=[];for(let e of n){let n=Pl(t,e?.items);for(let e of n)if((Array.isArray(e?.motivation)?e.motivation:[e?.motivation]).includes(`painting`))for(let n of Ml(e?.body,t))r.push(...Nl(n))}return Array.from(new Set(r))}function jl(e,t,n){let r=Pl(n,e?.thumbnail);if(!r.length||!t.length)return!1;for(let e of r){let n=Nl(e),r=typeof e?.id==`string`?e.id:``;if(n.some(e=>t.includes(e))||t.some(e=>r.startsWith(e)))return!0}return!1}function Ml(e,t){let n=Tl(t,e);return n?Array.isArray(n)?n.flatMap(e=>Ml(e,t)):n.type===`SpecificResource`?Ml(n.source,t):n.type===`Choice`?n.items?.flatMap(e=>Ml(e,t))||[]:[n]:[]}function Nl(e){let t=e?.service||e?.services,n=Array.isArray(t)?t:t?[t]:[],r=[];for(let e of n){let t=typeof e==`string`?e:e?.id||e?.[`@id`];typeof t==`string`&&t&&r.push(t)}return Array.from(new Set(r))}function Pl(e,t){if(!t)return[];let n=Array.isArray(t)?t:[t];try{let t=e.get(n);if(Array.isArray(t))return t.filter(Boolean)}catch{}return n.map(t=>Tl(e,t)).filter(Boolean)}function Fl(e){return e.replace(/^https:/,`http:`).replace(/\/?$/,`/`)}function Il(e,t){return typeof t==`string`?Ll(e).some(e=>e===t):ul(e,t)}function Ll(e){return e?typeof e==`string`?[e.trim()].filter(Boolean):Array.isArray(e)?e.flatMap(Ll):typeof e==`object`?Object.values(e).flatMap(Ll):[]:[]}function Rl(e){return typeof e==`string`?e:Ll(e)[0]||``}function zl(e){return(e[e.length-1]||`Property`).replace(/([A-Z])/g,` $1`).replace(/[-_]/g,` `).replace(/^./,e=>e.toUpperCase())}const Bl=(0,u.createContext)([]);function Vl({children:e,specifications:t}){let n=(0,u.useMemo)(()=>t||[],[t]);return(0,d.jsx)(Bl.Provider,{value:n,children:e})}function Hl(){return(0,u.useContext)(Bl)}function Ul(e){let t=W(),n=Hl(),r=e||t;return(0,m.useVaultSelector)((e,t)=>pl(n,t,r),[n,r.id,r.type])}function Wl(){let e=Hl();return(0,u.useMemo)(()=>({getLabel(t,n,r){return dl(e,t,n,r)}}),[e])}function Gl(e,t){let n=Hl();return(0,u.useMemo)(()=>fl(n,e,t),[n,e?.id,e?.type,JSON.stringify(t)])}const Kl={},ql=(0,u.createContext)(`global`);function Jl(){return(0,u.useContext)(ql)}function Yl(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}function Xl(e){let t=Jl(),[,n]=(0,u.useReducer)(e=>e+1,0),r=(0,u.useMemo)(()=>(Kl[t]||(Kl[t]={}),Kl[t][e]||(Kl[t][e]={name:e,emitter:(0,E.default)(),status:`idle`,promise:Promise.resolve(),abort:new AbortController,reject:()=>void 0,resolve:()=>void 0}),Kl[t][e]),[t,e]);return Zl(r,`abort`,n),Zl(r,`error`,n),Zl(r,`complete`,n),Zl(r,`running`,n),r}function Zl(e,t,n){let r=(0,u.useCallback)(()=>n(e),[n]);(0,u.useEffect)(()=>{let n=e.emitter;return n.on(t,r),()=>n.off(t,r)},[t,r,e.emitter])}const Ql=()=>void 0;function $l(e,t){let n=Xl(e);return Zl(n,`complete`,t||Ql),[e=>{n.status===`running`&&(n.abort.abort(),n.emitter.emit(`abort`)),n.error&&(n.error=``);let t=Yl();t.promise.then(()=>n.emitter.emit(`complete`)).catch(()=>n.emitter.emit(`error`)),n.status=`running`,n.request=e,n.promise=t.promise,n.resolve=t.resolve,n.reject=t.reject,n.emitter.emit(`running`)},n]}function eu(e,t){let n=Xl(e);return Zl(n,`running`,t),[e=>{n.status===`running`&&(n.response=e,n.status=`complete`,n.resolve())},n,(e,t)=>{n.status===`running`&&(n.error=t||e,n.status=`error`,n.reject(e))}]}function tu({children:e}){return(0,d.jsx)(ql.Provider,{value:(0,u.useMemo)(()=>`id-${Date.now()}`,[]),children:e})}function nu(e){return!1}function ru({as:e,reference:t,onReference:n,onLink:r,onAnalysis:i,onDropReference:a,onDropLink:o,onDropAnalysis:s,onPasteReference:c,onPasteLink:l,onPasteAnalysis:f,...p}){let m=e||`div`,h=a||n,g=c||n,_=l||r,v=f||i,y=(0,u.useMemo)(()=>t,[t?.id,t?.type]),b=(0,u.useCallback)(function(e){e.defaultPrevented||(e.preventDefault(),e.clipboardData&&y&&y.id&&y.type&&e.clipboardData.setData(`application/json+vault`,JSON.stringify({id:y.id,type:y.type})))},[y]),x=(0,u.useCallback)(async function(e){if(!e.defaultPrevented&&(e.preventDefault(),e.clipboardData)){if(p.onLoading&&p.onLoading(),g){let t=e.clipboardData.getData(`application/json+vault`);if(t)try{let e=JSON.parse(t);e&&e.id&&e.type&&g(e)}catch{}}if(_||v){let t=e.clipboardData.getData(`text`);if(t.startsWith(`http`)){let e=t.split(`
|
|
1531
|
-
`);for(let t of e){if(v)try{let e=await
|
|
1530
|
+
`,Ac=(0,u.memo)(function(e){if(e.layoutMode===`focused`)return(0,d.jsx)(bc,{...e});let t=U(),n=Un(),r=W(),i=pi(),{vault:a}=(0,u.useContext)(m.ReactVaultContext),o=a||void 0,s=(0,m.useVaultSelector)(e=>e.iiif),c=(0,u.useRef)(null),f=(0,u.useRef)(null),{loading:p,state:h,leftPanels:g,centerPanels:_,rightPanels:v,modals:y=[],actions:b}=i,x=(0,u.useMemo)(()=>({rootResource:r,vault:o,app:t,layoutState:h,appState:n}),[r,o,t,h,n,s]),S=(0,u.useMemo)(()=>_c(g,x,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[g,x]),w=(0,u.useMemo)(()=>_c(_,x,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[_,x]),T=(0,u.useMemo)(()=>_c(v,x,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[v,x]),E=(0,u.useMemo)(()=>_c(y,x,(e,t)=>{console.error(`Layout panel "${e.id}" failed support check`,t)}),[y,x]),D=(0,u.useMemo)(()=>S.filter(e=>e.modal),[S]),k=(0,u.useMemo)(()=>S.filter(e=>!e.modal),[S]),A=(0,u.useMemo)(()=>[...E,...D],[E,D]),j=(0,u.useMemo)(()=>({...i,leftPanels:S,centerPanels:w,rightPanels:T,modals:A}),[i,S,w,T,A]),M=k.find(e=>e.id===h.leftPanel.current),N=T.find(e=>e.id===h.rightPanel.current),P=w.find(e=>e.id===h.centerPanel.current),F=A.find(e=>e.id===h.modal.current),te=h.modal.open&&D.some(e=>e.id===h.modal.current)?h.modal.current:h.leftPanel.current,ne=h.pinnedRightPanel.pinned?T.find(e=>e.id===h.pinnedRightPanel.current):void 0,[I]=Rs([`(max-width: 1020px)`]),re=e.isLoading||!1,L=(0,u.useMemo)(()=>(i.background||[]).map((e,t)=>(0,d.jsx)(u.Fragment,{children:e.render()},t)),[i.background]),R=$s(`left-panel/${M?.id}`,{left:!0,marginLeft:60,minWidthPx:M?.options?.minWidth||200,maxWidthPx:M?.options?.maxWidth||720,loading:p}),z=$s(`right-panel/${N?.id}`,{left:!1,minWidthPx:N?.options?.minWidth||320,maxWidthPx:N?.options?.maxWidth||720,loading:p}),ie=N&&(ne?.id!==N.id||!(0,ee.default)(h.pinnedRightPanel.state,h.rightPanel.state)),ae=R.widthB===`auto`?void 0:()=>R.setWidths({widthA:`auto`,widthB:no({options:M?.options,fallback:320})}),oe=z.widthB===`auto`?void 0:()=>z.setWidths({widthA:`auto`,widthB:no({options:N?.options,fallback:320})});if((0,u.useLayoutEffect)(()=>{I&&h.leftPanel.open&&h.rightPanel.open&&(b.leftPanel.close(),b.rightPanel.close())},[I]),(0,u.useLayoutEffect)(()=>{if(P&&P.onMount)return P.onMount(h.centerPanel.state||P.defaultState||{},{...j,current:b.centerPanel,vault:o},n)},[h.centerPanel.current,P?.id]),(0,u.useLayoutEffect)(()=>{if(h.leftPanel.current&&!M){let e=vc(k,h.leftPanel.current);e?b.leftPanel.change({id:e}):b.leftPanel.close()}if(h.centerPanel.current&&!P){let e=vc(w,h.centerPanel.current);e?b.centerPanel.change({id:e}):b.centerPanel.close()}if(h.rightPanel.current&&!N){let e=vc(T,h.rightPanel.current);e?b.rightPanel.change({id:e}):b.rightPanel.close()}if(h.modal.current&&!F){let e=vc(A,h.modal.current);e?b.modal.change({id:e}):b.modal.close()}},[h.leftPanel.current,h.centerPanel.current,h.rightPanel.current,h.modal.current,M?.id,P?.id,N?.id,F?.id,Q(k),Q(w),Q(T),Q(A)]),(0,u.useLayoutEffect)(()=>{T.length&&b.rightPanel.change({id:T[0].id}),k.length&&b.leftPanel.change({id:k[0].id}),w.length&&b.centerPanel.change({id:w[0].id})},[]),p)return null;let se=t=>(0,d.jsx)(gc,{$menu:e.leftPanelMenuPosition||`bottom`,ref:R.refs.resizableDiv,className:[`manifest-editor`,t?`transition transition-${t}`:``].join(` `),style:{width:h.leftPanel.open||t!==`exited`?R.widthB:void 0,minWidth:M?.options?.minWidth},children:re?(0,d.jsx)(Z,{children:(0,d.jsx)(Ys,{})}):(0,d.jsxs)(d.Fragment,{children:[e.leftPanelMenu?(0,d.jsx)(X,{$open:h.leftPanel.open&&t!==`exited`,$position:e.leftPanelMenuPosition||`bottom`,children:e.leftPanelMenu}):null,(0,d.jsx)(Z,{children:h.leftPanel.open||t!==`exited`?(0,d.jsx)(d.Fragment,{children:M?(0,d.jsx)(mo,{isLeft:!0,noHeader:!0,transition:t,panel:M,state:h.leftPanel,actions:b.leftPanel}):null}):null})]})}),ce=()=>F?(0,d.jsx)(l.Modal,{title:F.label,open:h.modal.open,onClose:()=>b.modal.close(),children:F.modal?(0,d.jsx)(`div`,{className:`h-[70vh] min-h-[60vh] max-h-full flex w-full`,children:(0,d.jsx)(mo,{isLeft:!0,isModal:!0,noHeader:!0,panel:F,state:h.modal,actions:b.modal})}):ro(F.render(h.modal.state||F.defaultState||{},{...j,current:b.modal,vault:o,isModal:!0},n))}):null,le=()=>(0,d.jsxs)(gc,{$menu:e.centerPanelMenuPosition||`top`,children:[e.centerPanelMenu?(0,d.jsx)(X,{$open:h.centerPanel.open,$position:e.centerPanelMenuPosition||`top`,children:e.centerPanelMenu}):null,(0,d.jsx)(Z,{children:(0,d.jsx)(C.ErrorBoundary,{resetKeys:[P?.id],FallbackComponent:io,children:re?(0,d.jsx)(`div`,{style:{display:`flex`,flex:1,justifyContent:`center`,alignItems:`center`},children:(0,d.jsx)(qs,{stroke:`rgba(0,0,0,.3)`,fontSize:`2em`})}):h.centerPanel.open&&P?ro(P.render(h.centerPanel.state||P.defaultState||{},{...j,current:b.centerPanel,vault:o},n)):null})})]}),ue=t=>(0,d.jsx)(gc,{$menu:e.rightPanelMenuPosition||`bottom`,ref:z.refs.resizableDiv,className:t?`transition transition-${t}`:``,style:{width:h.rightPanel.open||t!==`exited`?z.widthB:void 0,minWidth:N?.options?.minWidth},children:re?(0,d.jsx)(Z,{children:(0,d.jsx)(Ys,{})}):(0,d.jsxs)(d.Fragment,{children:[e.rightPanelMenu?(0,d.jsx)(X,{$open:h.rightPanel.open,$position:e.rightPanelMenuPosition||`bottom`,children:e.rightPanelMenu}):null,(0,d.jsx)(Z,{children:h.rightPanel.open||t!==`exited`?(0,d.jsxs)(d.Fragment,{children:[ie?(0,d.jsx)(mo,{panel:N,state:h.rightPanel,actions:b.rightPanel,pinActions:b.pinnedRightPanel,available:T}):null,ne?(0,d.jsx)(mo,{panel:ne,state:h.pinnedRightPanel,actions:b.pinnedRightPanel,close:b.rightPanel.close}):null]}):null})]})});return I?(0,d.jsxs)(lc,{children:[e.hideHeader?null:(0,d.jsxs)(uc,{children:[e.header||null,e.menu?(0,d.jsx)(`menu`,{children:e.menu}):null]}),(0,d.jsx)(fc,{children:(0,d.jsxs)(xc,{children:[(0,d.jsxs)(Cc,{children:[k.length>0?(0,d.jsx)(wc,{type:`button`,"aria-expanded":h.leftPanel.open,onClick:()=>{b.rightPanel.close(),b.leftPanel.toggle()},children:M?.label}):null,T.length>0?(0,d.jsx)(Tc,{children:(0,d.jsxs)(Ec,{type:`button`,"aria-expanded":h.rightPanel.open,onClick:()=>{b.leftPanel.close(),b.rightPanel.toggle()},children:[(0,d.jsx)(nr,{"aria-hidden":`true`,rotate:90}),N?.label]})}):null]}),(0,d.jsx)(Sc,{children:le()}),T.length>0?(0,d.jsx)(Dc,{$open:h.rightPanel.open,children:ue()}):null,k.length>0?(0,d.jsxs)(Oc,{$open:h.leftPanel.open,children:[(0,d.jsx)(`nav`,{"aria-label":`Left panel tabs`,className:`flex flex-none overflow-x-auto border-b border-gray-300`,children:k.map(e=>(0,d.jsxs)(`button`,{type:`button`,"aria-pressed":h.leftPanel.current===e.id,className:`flex flex-1 shrink-0 items-center justify-center gap-1.5 border-0 border-b-[3px] p-3 text-gray-700 [&>svg]:shrink-0 [&>svg]:text-xl ${h.leftPanel.current===e.id?`border-b-[#b83265] bg-[#f9e8ef]`:`border-b-transparent bg-white`}`,onClick:()=>{b.rightPanel.close(),b.leftPanel.open({id:e.id,state:e.defaultState})},children:[e.icon,e.label]},e.id))}),se()]}):null,S.length>0||T.length>0?(0,d.jsx)(kc,{type:`button`,"aria-label":`Close panels`,$open:h.leftPanel.open||h.rightPanel.open,onClick:()=>{b.leftPanel.close(),b.rightPanel.close()}}):null]})}),(0,d.jsx)(`div`,{className:`hidden`,children:L}),(0,d.jsx)(ea,{}),(0,d.jsx)(ta,{}),(0,d.jsx)(d.Fragment,{children:ce()}),(0,d.jsx)(Da,{})]}):(0,d.jsxs)(lc,{id:e.htmlId||`manifest-editor-container`,className:`manifest-editor ${e.className||``}`,children:[e.hideHeader?null:(0,d.jsxs)(uc,{children:[e.header||null,e.menu?(0,d.jsx)(`menu`,{children:e.menu}):null]}),(0,d.jsxs)(fc,{ref:e=>{R.refs.container.current=e,z.refs.container.current=e},children:[S.length>0?(0,d.jsx)(l.PanelSideMenu,{current:te,items:S.map(e=>({id:e.id,label:e.label,icon:e.icon,divide:e.divide,separator:e.separator,onClick:()=>{if(e.modal){h.modal.open&&h.modal.current===e.id?b.modal.close():b.modal.open({id:e.id,state:e.defaultState});return}h.leftPanel.current===e.id?b.leftPanel.toggle():b.leftPanel.change({id:e.id})}})),open:h.leftPanel.open}):null,k.length>0?(0,d.jsx)(O.Transition,{nodeRef:c,in:h.leftPanel.open,timeout:400,unmountOnExit:!1,children:e=>(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(pc,{ref:c,$width:R.widthB,$state:e,$motion:!0,children:se(e)}),(0,d.jsx)(Ks,{ref:R.refs.resizer,reset:ae,dir:`left`,transition:e,open:h.leftPanel.open||e!==`exited`,actions:b.leftPanel})]})}):null,(0,d.jsx)(mc,{children:le()}),T.length>0?(0,d.jsx)(O.Transition,{nodeRef:f,in:h.rightPanel.open,timeout:400,unmountOnExit:!1,children:e=>(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(Ks,{ref:z.refs.resizer,dir:`right`,reset:oe,open:h.rightPanel.open,actions:b.rightPanel}),(0,d.jsx)(hc,{ref:f,$width:z.widthB,$state:e,$motion:!0,children:ue(e)})]})}):null]}),(0,d.jsx)(dc,{children:e.footer||null}),(0,d.jsx)(`div`,{className:`hidden`,children:L}),(0,d.jsx)(ea,{}),(0,d.jsx)(ta,{}),(0,d.jsx)(d.Fragment,{children:ce()}),(0,d.jsx)(Da,{})]})});function jc(e,t){function n(){t({type:`popStack`,panel:e,payload:void 0})}function r(n){t({type:`change`,panel:e,payload:n})}function i(n){t({type:`open`,panel:e,payload:n})}function a(){t({type:`close`,panel:e,payload:void 0})}function o(){t({type:`toggle`,panel:e,payload:void 0})}function s(){t({type:`minimise`,panel:e,payload:void 0})}function c(n){t({type:`maximise`,panel:e,payload:n})}function l(n){t({type:`setCustomWidth`,panel:e,payload:n})}function d(){t({type:`resetSize`,panel:e,payload:void 0})}function f(n){t({type:`pin`,panel:e,payload:n})}function p(){t({type:`unpin`,panel:e,payload:void 0})}return(0,u.useMemo)(()=>({popStack:n,change:r,open:i,close:a,toggle:o,minimise:s,maximise:c,setCustomWidth:l,resetSize:d,pin:f,unpin:p}),[])}function Mc(e,t){if(t.payload&&t.payload.stacked){if(e.current){let n=e.stack[e.stack.length-1];if(n&&n.id===e.current)return;t.payload.unique&&(e.stack=e.stack.filter(t=>t.id!==e.current)),e.stack.push({id:e.current,state:e.state?{...(0,_.original)(e.state)}:{}})}}else e.stack=[]}function Nc(e,t){switch(t.type){case`popStack`:if(e.stack.length){let t=e.stack[e.stack.length-1];t&&(e.current=t.id,e.state=t.state),e.stack=e.stack.slice(0,-1)}break;case`change`:t.payload.id!==e.current&&Mc(e,t),e.state=t.payload.state,e.current=t.payload.id;break;case`close`:e.open=!1;break;case`open`:e.open=!0,t.payload&&(t.payload.id!==e.current&&Mc(e,t),e.state=t.payload.state,e.current=t.payload.id);break;case`toggle`:e.open=!e.open;break;case`maximise`:e.minimised=!1,t.payload&&(e.state=t.payload.state,e.current=t.payload.id);break;case`minimise`:e.minimised=!0;break;case`setCustomWidth`:e.customWidth=t.payload;break;case`resetSize`:e.customWidth=void 0}if(to(e))switch(t.type){case`pin`:e.pinned=!0,e.state=t.payload.state,e.current=t.payload.id;break;case`unpin`:e.pinned=!1,e.state=void 0}}const Pc=(0,_.produce)((e,t)=>{switch(t.panel){case`centerPanel`:Nc(e.centerPanel,t);break;case`leftPanel`:Nc(e.leftPanel,t);break;case`rightPanel`:Nc(e.rightPanel,t);break;case`modal`:Nc(e.modal,t);break;case`pinnedRightPanel`:Nc(e.pinnedRightPanel,t)}});function Fc(){return{customWidth:void 0,minimised:!1,open:!0,current:null,state:null,stack:[]}}function Ic(){return{leftPanel:Fc(),centerPanel:Fc(),rightPanel:Fc(),modal:Fc(),pinnedRightPanel:{...Fc(),pinnable:!0,pinned:!1}}}function Lc({className:e,variant:t=`light`}){let n=(0,m.useManifest)(),r=(0,m.useVault)(),{edit:i}=ui(),a=Yr(),o=Xr(),s=n?.items||[],c=n?.viewingDirection===`right-to-left`||n?.viewingDirection===`bottom-to-top`,l=n?.viewingDirection===`top-to-bottom`||n?.viewingDirection===`bottom-to-top`,f=Rc(a)||o.map(Rc).find(Boolean)||s[0]?.id||``,p=Math.max(0,s.findIndex(e=>e.id===f)),h=s[p]?.id||``,g=p+1,_=(0,u.useMemo)(()=>s.map((e,t)=>{let n=r.get({id:e.id,type:`Canvas`});return{id:e.id,pageNumber:t+1,labelText:(0,b.getValue)(n?.label)||`Page ${t+1}`}}),[s,r]),v=e=>{let t=s.findIndex(t=>t.id===e),r=s[t];!r||!n||i({id:r.id,type:`Canvas`},{parent:{id:n.id,type:`Manifest`},property:`items`,index:t},{forceOpen:!1})};if(!n||s.length<2)return(0,d.jsx)(`div`,{});let y=s[p-1],x=s[p+1],S=t===`dark`;return(0,d.jsxs)(`nav`,{"aria-label":`Manifest pagination`,className:Hc(`inline-flex shrink-0 items-center gap-1 rounded-full border px-1.5 py-1`,`focus-within:ring-2 focus-within:ring-me-primary-500/40`,c&&`flex-row-reverse`,S?`border-white/20 bg-white/10 text-white`:`border-me-gray-300 bg-white text-me-gray-900`,e),children:[(0,d.jsx)(zc,{ariaLabel:`Previous canvas`,disabled:!y,onClick:()=>y&&v(y.id),dark:S,children:(0,d.jsx)(Bc,{reverse:c,vertical:l})}),(0,d.jsxs)(`label`,{htmlFor:`manifest-pagination-page-select`,"aria-label":`Page ${g} of ${s.length}`,className:Hc(`relative inline-flex min-h-8 cursor-pointer select-none items-center gap-0.5`,`whitespace-nowrap rounded-full border px-2.5 text-xs font-semibold leading-none`,`focus-within:outline-none focus-within:ring-2 focus-within:ring-me-primary-500/40`,S?`border-white/20 bg-white/10 text-white hover:bg-white/15`:`border-me-gray-300 bg-me-gray-100 text-me-gray-900 hover:bg-me-primary-50`),children:[(0,d.jsxs)(`span`,{children:[g,` / `,s.length]}),(0,d.jsx)(Vc,{className:Hc(`shrink-0 text-base`,S?`text-white/60`:`text-me-gray-500`)}),(0,d.jsx)(`select`,{id:`manifest-pagination-page-select`,"aria-label":`Jump to canvas`,value:h,onChange:e=>v(e.target.value),className:`absolute inset-0 cursor-pointer appearance-none border-0 bg-white opacity-0`,children:_.map(e=>(0,d.jsxs)(`option`,{value:e.id,children:[`Page `,e.pageNumber,` - `,e.labelText]},e.id))})]}),(0,d.jsx)(zc,{ariaLabel:`Next canvas`,disabled:!x,onClick:()=>x&&v(x.id),dark:S,children:(0,d.jsx)(Bc,{reverse:!c,vertical:l})})]})}function Rc(e){let t=e?.resource?.source;return t?.type===`Canvas`?t.id:null}function zc({ariaLabel:e,children:t,dark:n,disabled:r,onClick:i}){return(0,d.jsx)(`button`,{type:`button`,"aria-label":e,disabled:r,onClick:i,className:Hc(`inline-flex h-8 w-8 items-center justify-center rounded-full border-0 bg-transparent p-0`,`text-lg transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-me-primary-500/50`,n?`text-white hover:bg-white/15 disabled:text-white/40 disabled:hover:bg-transparent`:`text-me-gray-900 hover:bg-me-primary-50 disabled:text-me-gray-500 disabled:hover:bg-transparent`,`disabled:cursor-not-allowed`),children:t})}function Bc({reverse:e,vertical:t}){return(0,d.jsx)(e?l.ArrowRightIcon:l.BackIcon,{"aria-hidden":!0,className:Hc(`block`,t&&`rotate-90`)})}function Vc(e){return(0,d.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,viewBox:`0 0 24 24`,"aria-hidden":!0,...e,children:(0,d.jsx)(`path`,{fill:`currentColor`,d:`m7 10l5 5l5-5z`})})}function Hc(...e){return e.filter(Boolean).join(` `)}const Uc=new WeakMap;function Wc(e,t){let n={port:t,lastActionId:`@genesis`},r=Gc(e);function i(e){t.postMessage(typeof e==`string`?e:JSON.stringify(e))}function a(){i({_id:Lt(),_type:`init-response`,_lastActionId:n.lastActionId,data:e.getState()})}function o(e){i({_id:e,_type:`vault-action-rejection`,_lastActionId:n.lastActionId,action:e})}function s(e){let t=qc(e.data);if(t){if(t._type===`init-request`){a();return}t._type===`vault-action`&&o(t._id)}}return r.targets.add(n),t.addEventListener(`message`,s),t.start(),()=>{t.removeEventListener(`message`,s),r.targets.delete(n),r.targets.size===0&&e.dispatch===r.patchedDispatch&&(e.dispatch=r.originalDispatch,Uc.delete(e)),t.close()}}function Gc(e){let t=Uc.get(e);if(t)return t;let n=e.dispatch.bind(e),r=new Set,i=(e=>{let t=n(e);for(let t of r)Kc(t,e);return t}),a={originalDispatch:n,patchedDispatch:i,targets:r};return e.dispatch=i,Uc.set(e,a),a}function Kc(e,t){let n={_id:Lt(),_type:`vault-action`,_lastActionId:e.lastActionId,action:t};e.lastActionId=n._id,e.port.postMessage(JSON.stringify(n))}function qc(e){try{if(typeof e==`string`)return JSON.parse(e);if(typeof e==`object`&&e)return e}catch{return null}return null}const Jc=(0,u.createContext)(null);function Yc({children:e}){let t=(0,m.useVault)(),n=(0,u.useRef)(null),r=(0,u.useRef)(null),i=(0,u.useRef)(null),a=(0,u.useRef)(!1),[o,s]=(0,u.useState)(!0),c=(0,u.useCallback)(()=>{if(!n.current||n.current.closed||!r.current)return;i.current?.();let e=new MessageChannel;i.current=Wc(t,e.port1),n.current.postMessage({_type:`manifest-editor:iframe-preview:connect`,resource:r.current.resource,canvasId:r.current.canvasId||null,annotationId:r.current.annotationId||void 0},new URL(r.current.url).origin,[e.port2]),a.current=!0},[t]);(0,u.useEffect)(()=>{let e=e=>{!r.current||e.source!==n.current||e.origin===new URL(r.current.url).origin&&e.data?._type===`manifest-editor:iframe-preview:ready`&&c()},t=window.setInterval(()=>{n.current?.closed&&(i.current?.(),i.current=null,a.current=!1,n.current=null,s(!0))},1e3);return window.addEventListener(`message`,e),()=>{window.removeEventListener(`message`,e),window.clearInterval(t),i.current?.()}},[c]);let l=(0,u.useCallback)(e=>{r.current=e;let t=n.current;if(t&&!t.closed){t.focus();return}i.current?.(),i.current=null,a.current=!1,n.current=window.open(e.url,e.name||`manifest-editor-preview`,e.features||`popup,width=1200,height=900`),s(!n.current)},[]),f=(0,u.useCallback)(e=>{let t=r.current;r.current=e;let o=n.current;if(!(!o||o.closed)){if(t&&(t.url!==e.url||t.reloadKey!==e.reloadKey)){i.current?.(),i.current=null,a.current=!1,o.location.href=e.url;return}a.current&&o.postMessage({_type:`manifest-editor:iframe-preview:selection`,resource:e.resource,canvasId:e.canvasId||null,annotationId:e.annotationId||void 0},new URL(e.url).origin)}},[]),p=(0,u.useCallback)(()=>{n.current&&!n.current.closed&&n.current.focus()},[]);return(0,d.jsx)(Jc.Provider,{value:{open:l,update:f,focus:p,isClosed:o},children:e})}function Xc(){let e=(0,u.useContext)(Jc);return N(e,`usePreviewWindow() can only be called from inside <PreviewWindowProvider />`),e}var Zc=class extends u.Component{constructor(...e){super(...e),G(this,`state`,{hasError:!1})}static getDerivedStateFromError(e){return console.error(e),{hasError:!0}}componentDidCatch(e,t){console.error(`Uncaught error:`,e,t)}render(){return this.state.hasError?(0,d.jsx)(`h1`,{children:`Sorry.. there was an error`}):this.props.children}};function Qc(e,t){return typeof e==`string`?{id:e,state:t}:e}const $c=(0,u.memo)(function(e){let t=U(),n=Is(),r=t.layout,[i,a]=(0,u.useReducer)(Pc,void 0,Ic),o={centerPanel:jc(`centerPanel`,a),leftPanel:jc(`leftPanel`,a),rightPanel:jc(`rightPanel`,a),pinnedRightPanel:jc(`pinnedRightPanel`,a),modal:jc(`modal`,a),editingStack:Jr()};function s(e){let t=r.rightPanels.find(t=>t.id===e);if(t)return[t,o.rightPanel,o.pinnedRightPanel];let n=r.centerPanels.find(t=>t.id===e);if(n)return[n,o.centerPanel];let i=r.leftPanels.find(t=>t.id===e);if(i)return i.modal?[i,o.modal]:[i,o.leftPanel];N(!1,`Was not able to find panel with id "${e}"`)}function c(e,t){let{id:r,state:i,stacked:a}=Qc(e,t),[o,c,l]=s(r);if(l&&o.options?.openPinned)l.pin({id:r,state:{...o.defaultState||{},...i||{}}});else{let e={id:r,state:{...o.defaultState||{},...i||{}},stacked:a};n.emit(`layout.open`,e),c.open(e)}}function l(e,t){let{id:r,state:i}=Qc(e,t),[a,o]=s(r),c={id:r,state:{...a.defaultState||{},...i||{}},stacked:!0};n.emit(`layout.open`,c),o.open(c)}function f(e,t){let{id:r,state:i,stacked:a}=Qc(e,t),[o,c]=s(r),l={id:r,state:{...o.defaultState||{},...i||{}},stacked:a};n.emit(`layout.change`,l),c.change(l)}function p(e,t){let{id:r}=Qc(e,t),[,i]=s(r);n.emit(`layout.close`,{id:r}),i.close()}function m(e,t){let{id:r}=Qc(e,t),[,i]=s(r);n.emit(`layout.toggle`,{id:r}),i.toggle()}function g(e,t={},{reset:i,property:a,stacked:s,forceOpen:c,selectedTab:l}={}){let u={resource:(0,h.isSpecificResource)(e)?e:{type:`SpecificResource`,source:e},...t};n.emit(`layout.edit`,u),o.editingStack.edit(u,i),r.rightPanels.find(e=>e.id===`@manifest-editor/editor`)&&(c?o.rightPanel.open({id:`@manifest-editor/editor`,stacked:s!==!1,state:{property:a,currentTab:l},unique:!0}):o.rightPanel.change({id:`@manifest-editor/editor`,stacked:s!==!1,state:{property:a,currentTab:l},unique:!0}))}async function _(e){o.editingStack.create(e,{}),n.emit(`layout.create`,e),r.modals?.find(e=>e.id===`@manifest-editor/creator`)?o.modal.open({id:`@manifest-editor/creator`,stacked:!0,unique:!0,state:e}):r.rightPanels.find(e=>e.id===`@manifest-editor/creator`)&&o.rightPanel.open({id:`@manifest-editor/creator`,stacked:!0,unique:!0,state:e})}let v={open:c,change:f,close:p,toggle:m,stack:l,edit:g,create:_};return(0,d.jsx)(oi.Provider,{value:(0,u.useMemo)(()=>({...o,...v}),[r]),children:(0,d.jsx)(si.Provider,{value:i,children:e.children})})}),el=[{id:`universal-viewer`,config:{url:`https://universalviewer.dev/#?iiifManifestId={manifestId}`},type:`external-manifest-preview`,label:`Universal viewer`},{id:`mirador-3`,type:`external-manifest-preview`,label:`Mirador 3`,config:{url:`https://tomcrane.github.io/scratch/mirador3/?iiif-content={manifestId}`}},{id:`annona`,type:`external-manifest-preview`,label:`Annona`,config:{url:`https://ncsu-libraries.github.io/annona/tools/#/display?url={manifestId}&viewtype=iiif-storyboard&settings=%7B%22fullpage%22%3Atrue%7D`}},{id:`iiif-preview`,config:{url:`https://iiif-preview.digirati.services/store`},type:`iiif-preview-service`,label:`IIIF Preview`}],tl=new k.ImageServiceLoader({approximateServices:!0,verificationsRequired:8,enableFetching:!0});function nl({config:e,saveConfig:t,children:n,theme:r,previews:i,resource:a,editing:o,backgroundActionPersistence:s}){let c=Hn(),l=z(),f=(0,u.useMemo)(()=>{let t=e?.previews||(l.previews?.length?l.previews:el);return re(l,{previews:t},e)},[l,e]),p=(0,u.useMemo)(()=>({appId:c.appId,instanceId:c.instanceId,rootResource:{id:a.id,type:a.type}}),[c.appId,c.instanceId,a.id,a.type]);return(0,d.jsx)(Zc,{children:(0,d.jsx)(m.ImageServiceLoaderContext.Provider,{value:tl,children:(0,d.jsx)(lr,{resource:a,children:(0,d.jsx)(xo,{children:(0,d.jsx)(g.ThemeProvider,{theme:r||Lo,children:(0,d.jsxs)(ae,{config:f,saveConfig:t,children:[(0,d.jsx)(Rn,{config:f}),(0,d.jsx)(ii,{children:(0,d.jsx)($c,{children:(0,d.jsx)(kt,{persistence:s,persistenceKey:p,children:(0,d.jsx)(os,{children:(0,d.jsx)(Gi,{children:(0,d.jsx)(xr,{previews:i||[],configs:f.previews,children:(0,d.jsx)(Yc,{children:(0,d.jsx)(m.AtlasStoreProvider,{children:n})})})})})})})})]})})})})})})}const rl=new Set([`Collection`,`Manifest`,`Canvas`,`Range`,`AnnotationPage`,`Annotation`,`ContentResource`,`Agent`]),il={satisfied:0,missing:0,invalid:0,disallowed:0,"not-applicable":0},al=new Set([`label`,`summary`,`language`,`navDate`,`provider`,`requiredStatement`,`rights`,`thumbnail`]);function ol(e){return e?Array.isArray(e)?e.filter(Boolean):e.split(`.`).filter(Boolean):[]}function sl(e,t){let n=ol(e),r=ol(t);return n.length===r.length&&n.every((e,t)=>e===r[t])}function cl(e,t){let n=e;for(let e of ol(t)){if(n==null)return;n=n[e]}return n}function ll(e,t,n){let r=ol(t);if(!r.length)return n;let i=Array.isArray(e)?[...e]:{...e||{}},a=i;return r.forEach((e,t)=>{if(t===r.length-1){a[e]=n;return}let i=a[e];a[e]=Array.isArray(i)?[...i]:{...i||{}},a=a[e]}),i}function $(e){if(e==null)return!1;if(typeof e==`string`)return e.trim().length>0;if(typeof e==`number`||typeof e==`boolean`)return!0;if(Array.isArray(e))return e.some(e=>$(e));if(typeof e!=`object`)return!1;let t=Object.entries(e);return t.length?!t.every(([,e])=>typeof e==`string`||Array.isArray(e)&&e.every(e=>typeof e==`string`))||t.some(([,e])=>$(e)):!1}function ul(e){return Array.isArray(e)?e.map(ul):e&&typeof e==`object`?Object.keys(e).sort().reduce((t,n)=>(t[n]=ul(e[n]),t),{}):e}function dl(e,t){return JSON.stringify(ul(e))===JSON.stringify(ul(t))}function fl(e,t,n,r){let i=ol(n);for(let n of e||[])for(let e of n.terminology?.properties||[])if(!(e.entityType&&e.entityType!==t)&&sl(e.path,i))return e.label;return r||Bl(i)}function pl(e,t,n){let r=ol(n),i=[],a,o,s=!1,c=!1;if(!t||!rl.has(t.type))return{entityType:t?.type,path:r,label:fl(e,t?.type,r),disallowed:!1,required:!1,rules:i};for(let n of e||[])for(let e of n.rules||[])!(`entityType`in e)||!(`path`in e)||e.entityType===t.type&&sl(e.path,r)&&(i.push(e),e.type===`disallow-property`&&(s=!0),e.type===`require-non-empty`&&(c=!0),e.type===`fixed-value`&&!o&&(a=e.value,o=e,c=!0));return{entityType:t.type,path:r,label:fl(e,t.type,r),disallowed:s,required:c,fixedValue:a,fixedValueRule:o,rules:i}}function ml(e,t,n){let r=e||[],i=hl(t,n),a=[];for(let e of r)for(let[n,r]of(e.rules||[]).entries())a.push(...gl(e,r,n,i,t));return{specifications:r,results:a,counts:Tl(a)}}function hl(e,t){let n=[],r=new Set;function i(t){let a=Dl(t);if(!a)return;if(a.type===`SpecificResource`){i(t?.source);return}let o=El(e,t)||El(e,a);if(!o||!o.type)return;let s=`${o.type}:${o.id||JSON.stringify(a)}`;if(!r.has(s)){r.add(s),rl.has(o.type)&&n.push({ref:{id:o.id,type:o.type},resource:o});for(let e of Ol(o))i(e)}}return i(t),n}function gl(e,t,n,r,i){switch(t.type){case`disallow-property`:case`require-non-empty`:case`fixed-value`:return _l(e,t,n,r);case`iiif:canvas-with-image-service`:return[vl(e,t,n,r,i)];case`iiif:thumbnail-from-body-service`:return yl(e,t,n,r,i);case`iiif:valid-rights`:return bl(e,t,n,r);case`iiif:required-statement`:return xl(e,t,n,r);case`iiif:metadata-template`:return Sl(e,t,n,r);default:return[]}}function _l(e,t,n,r){let i=r.filter(e=>e.ref.type===t.entityType),a=fl(e?[e]:[],t.entityType,t.path);return i.length?i.map(({ref:r,resource:i})=>{let o=cl(i,t.path),s=$(o);if(t.type===`disallow-property`)return Cl(e,t,n,{target:r,path:t.path,status:s?`disallowed`:`satisfied`,displayLabel:a,actual:o,message:s?`${a} is present but is not allowed.`:`${a} is not present.`,editorTarget:wl(r,t.path)});if(t.type===`require-non-empty`)return Cl(e,t,n,{target:r,path:t.path,status:s?`satisfied`:`missing`,displayLabel:a,actual:o,message:s?`${a} has a value.`:`${a} must be filled in.`,editorTarget:wl(r,t.path)});let c=dl(o,t.value);return Cl(e,t,n,{target:r,path:t.path,status:c?`satisfied`:s?`invalid`:`missing`,displayLabel:a,expected:t.value,actual:o,message:c?`${a} matches the required value.`:s?`${a} does not match the required value.`:`${a} must use the required value.`,editorTarget:wl(r,t.path)})}):[Cl(e,t,n,{status:`not-applicable`,displayLabel:a,message:`No ${t.entityType} resources were found for ${a}.`,path:t.path})]}function vl(e,t,n,r,i){let a=r.filter(e=>e.ref.type===`Canvas`),o=kl(t),s=a.find(({resource:e})=>Al(jl(e,i),o));return Cl(e,t,n,{target:s?.ref,status:s?`satisfied`:`missing`,displayLabel:t.label||`Canvas image service`,expected:o,message:s?`A canvas contains the required image service.`:o.length?`A canvas must contain one of the required image services: ${o.join(`, `)}.`:`A canvas must contain a painting body with an image service.`,editorTarget:s?wl(s.ref,[`items`]):void 0})}function yl(e,t,n,r,i){let a=t.entityType||`Canvas`,o=r.filter(e=>e.ref.type===a);return o.length?o.map(({ref:o,resource:s})=>{let c=a===`Manifest`?r.filter(e=>e.ref.type===`Canvas`).flatMap(e=>jl(e.resource,i)):jl(s,i),l=Ml(s,c,i),u=$(s.thumbnail);return Cl(e,t,n,{target:o,path:[`thumbnail`],status:l?`satisfied`:c.length?u?`invalid`:t.requireThumbnail===!1?`not-applicable`:`missing`:`not-applicable`,displayLabel:fl([e],o.type,[`thumbnail`],`Thumbnail`),expected:c,actual:s.thumbnail,message:l?`Thumbnail uses the same image service as the painting content.`:c.length?u?`Thumbnail does not use the same image service as the painting content.`:`Thumbnail must be created from the painting image service.`:`No painting image service was found to compare against.`,editorTarget:wl(o,[`thumbnail`])})}):[Cl(e,t,n,{status:`not-applicable`,displayLabel:`Thumbnail`,message:`No ${a} resources were found for thumbnail checks.`})]}function bl(e,t,n,r){let i=t.entityType||`Manifest`,a=r.filter(e=>e.ref.type===i),o=t.allowed||[];return a.map(({ref:r,resource:i})=>{let a=i.rights,s=$(a),c=typeof a==`string`&&o.map(Il).includes(Il(a));return Cl(e,t,n,{target:r,path:[`rights`],status:c?`satisfied`:!s&&t.required!==!1?`missing`:`invalid`,displayLabel:fl([e],r.type,[`rights`],`Rights`),expected:o,actual:a,message:c?`Rights uses an allowed URI.`:!s&&t.required!==!1?`Rights must use an allowed URI.`:`Rights is not one of the allowed URIs.`,editorTarget:wl(r,[`rights`])})})}function xl(e,t,n,r){let i=t.entityType||`Manifest`;return r.filter(e=>e.ref.type===i).map(({ref:r,resource:i})=>{let a=i.requiredStatement,o=t.label?Ll(a?.label,t.label):$(a?.label),s=t.value||t.valueRequired!==!1,c=t.value?Ll(a?.value,t.value):!s||$(a?.value),l=$(a);return Cl(e,t,n,{target:r,path:[`requiredStatement`],status:o&&c?`satisfied`:l?`invalid`:`missing`,displayLabel:fl([e],r.type,[`requiredStatement`],`Required statement`),expected:t.value||t.label,actual:a,message:o&&c?`Required statement is complete.`:l?`Required statement does not match the specification.`:`Required statement must be filled in.`,editorTarget:wl(r,[`requiredStatement`])})})}function Sl(e,t,n,r){let i=t.entityType||`Manifest`,a=r.filter(e=>e.ref.type===i),o=[];for(let{ref:r,resource:i}of a){let a=Array.isArray(i.metadata)?i.metadata:[];t.items.forEach((i,s)=>{let c=a.find(e=>Ll(e?.label,i.label)),l=i.value?Ll(c?.value,i.value):!i.valueRequired||$(c?.value),u=c&&l?`satisfied`:c&&i.value?`invalid`:`missing`,d=zl(i.label);o.push(Cl(e,t,n,{idSuffix:`metadata-${s}`,target:r,path:[`metadata`],status:u,displayLabel:d||`Metadata`,expected:i.value||i.label,actual:c,message:c&&l?`${d||`Metadata`} is present.`:c?`${d||`Metadata`} needs a value.`:`${d||`Metadata`} metadata must be added.`,editorTarget:wl(r,[`metadata`])}))})}return o}function Cl(e,t,n,r){let i=t.id||`${t.type}-${n}`,a=r.idSuffix?`-${r.idSuffix}`:``;return{id:`${e.id}-${i}-${r.target?.type||`root`}-${r.target?.id||`none`}${a}`,specificationId:e.id,specificationLabel:e.label,ruleId:i,ruleType:t.type,ruleLabel:t.label||r.displayLabel,ruleIndex:n,target:r.target,path:r.path,status:r.status,displayLabel:r.displayLabel,message:t.message||r.message,expected:r.expected,actual:r.actual,editorTarget:r.editorTarget}}function wl(e,t){let n=t[0];return{resource:e,propertyPath:t,selectedTab:n===`metadata`?`@manifest-editor/metadata`:n&&al.has(n)?`@manifest-editor/descriptive-properties`:void 0}}function Tl(e){let t={...il};for(let n of e)t[n.status]+=1;return t}function El(e,t){let n=Dl(t);if(!n)return t;try{return e.get(n,{skipSelfReturn:!1})||t}catch{try{return e.get(n)||t}catch{return t}}}function Dl(e){return!e||typeof e!=`object`?null:e.type===`SpecificResource`?{id:e.id||e.source?.id||``,type:`SpecificResource`}:typeof e.id==`string`&&typeof e.type==`string`?{id:e.id,type:e.type}:null}function Ol(e){if(!e||typeof e!=`object`)return[];let t=[];for(let n of[`items`,`structures`,`annotations`,`thumbnail`,`provider`,`homepage`,`rendering`,`seeAlso`,`body`,`target`,`source`]){let r=e[n];Array.isArray(r)?t.push(...r):r&&t.push(r)}return t}function kl(e){return[...e.serviceIds||[],...e.serviceId?[e.serviceId]:[]].filter(Boolean)}function Al(e,t){let n=new Set(e.filter(Boolean));return t.length?t.some(e=>n.has(e)):n.size>0}function jl(e,t){let n=Fl(t,e?.items),r=[];for(let e of n){let n=Fl(t,e?.items);for(let e of n)if((Array.isArray(e?.motivation)?e.motivation:[e?.motivation]).includes(`painting`))for(let n of Nl(e?.body,t))r.push(...Pl(n))}return Array.from(new Set(r))}function Ml(e,t,n){let r=Fl(n,e?.thumbnail);if(!r.length||!t.length)return!1;for(let e of r){let n=Pl(e),r=typeof e?.id==`string`?e.id:``;if(n.some(e=>t.includes(e))||t.some(e=>r.startsWith(e)))return!0}return!1}function Nl(e,t){let n=El(t,e);return n?Array.isArray(n)?n.flatMap(e=>Nl(e,t)):n.type===`SpecificResource`?Nl(n.source,t):n.type===`Choice`?n.items?.flatMap(e=>Nl(e,t))||[]:[n]:[]}function Pl(e){let t=e?.service||e?.services,n=Array.isArray(t)?t:t?[t]:[],r=[];for(let e of n){let t=typeof e==`string`?e:e?.id||e?.[`@id`];typeof t==`string`&&t&&r.push(t)}return Array.from(new Set(r))}function Fl(e,t){if(!t)return[];let n=Array.isArray(t)?t:[t];try{let t=e.get(n);if(Array.isArray(t))return t.filter(Boolean)}catch{}return n.map(t=>El(e,t)).filter(Boolean)}function Il(e){return e.replace(/^https:/,`http:`).replace(/\/?$/,`/`)}function Ll(e,t){return typeof t==`string`?Rl(e).some(e=>e===t):dl(e,t)}function Rl(e){return e?typeof e==`string`?[e.trim()].filter(Boolean):Array.isArray(e)?e.flatMap(Rl):typeof e==`object`?Object.values(e).flatMap(Rl):[]:[]}function zl(e){return typeof e==`string`?e:Rl(e)[0]||``}function Bl(e){return(e[e.length-1]||`Property`).replace(/([A-Z])/g,` $1`).replace(/[-_]/g,` `).replace(/^./,e=>e.toUpperCase())}const Vl=(0,u.createContext)([]);function Hl({children:e,specifications:t}){let n=(0,u.useMemo)(()=>t||[],[t]);return(0,d.jsx)(Vl.Provider,{value:n,children:e})}function Ul(){return(0,u.useContext)(Vl)}function Wl(e){let t=W(),n=Ul(),r=e||t;return(0,m.useVaultSelector)((e,t)=>ml(n,t,r),[n,r.id,r.type])}function Gl(){let e=Ul();return(0,u.useMemo)(()=>({getLabel(t,n,r){return fl(e,t,n,r)}}),[e])}function Kl(e,t){let n=Ul();return(0,u.useMemo)(()=>pl(n,e,t),[n,e?.id,e?.type,JSON.stringify(t)])}const ql={},Jl=(0,u.createContext)(`global`);function Yl(){return(0,u.useContext)(Jl)}function Xl(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}function Zl(e){let t=Yl(),[,n]=(0,u.useReducer)(e=>e+1,0),r=(0,u.useMemo)(()=>(ql[t]||(ql[t]={}),ql[t][e]||(ql[t][e]={name:e,emitter:(0,E.default)(),status:`idle`,promise:Promise.resolve(),abort:new AbortController,reject:()=>void 0,resolve:()=>void 0}),ql[t][e]),[t,e]);return Ql(r,`abort`,n),Ql(r,`error`,n),Ql(r,`complete`,n),Ql(r,`running`,n),r}function Ql(e,t,n){let r=(0,u.useCallback)(()=>n(e),[n]);(0,u.useEffect)(()=>{let n=e.emitter;return n.on(t,r),()=>n.off(t,r)},[t,r,e.emitter])}const $l=()=>void 0;function eu(e,t){let n=Zl(e);return Ql(n,`complete`,t||$l),[e=>{n.status===`running`&&(n.abort.abort(),n.emitter.emit(`abort`)),n.error&&(n.error=``);let t=Xl();t.promise.then(()=>n.emitter.emit(`complete`)).catch(()=>n.emitter.emit(`error`)),n.status=`running`,n.request=e,n.promise=t.promise,n.resolve=t.resolve,n.reject=t.reject,n.emitter.emit(`running`)},n]}function tu(e,t){let n=Zl(e);return Ql(n,`running`,t),[e=>{n.status===`running`&&(n.response=e,n.status=`complete`,n.resolve())},n,(e,t)=>{n.status===`running`&&(n.error=t||e,n.status=`error`,n.reject(e))}]}function nu({children:e}){return(0,d.jsx)(Jl.Provider,{value:(0,u.useMemo)(()=>`id-${Date.now()}`,[]),children:e})}function ru(e){return!1}function iu({as:e,reference:t,onReference:n,onLink:r,onAnalysis:i,onDropReference:a,onDropLink:o,onDropAnalysis:s,onPasteReference:c,onPasteLink:l,onPasteAnalysis:f,...p}){let m=e||`div`,h=a||n,g=c||n,_=l||r,v=f||i,y=(0,u.useMemo)(()=>t,[t?.id,t?.type]),b=(0,u.useCallback)(function(e){e.defaultPrevented||(e.preventDefault(),e.clipboardData&&y&&y.id&&y.type&&e.clipboardData.setData(`application/json+vault`,JSON.stringify({id:y.id,type:y.type})))},[y]),x=(0,u.useCallback)(async function(e){if(!e.defaultPrevented&&(e.preventDefault(),e.clipboardData)){if(p.onLoading&&p.onLoading(),g){let t=e.clipboardData.getData(`application/json+vault`);if(t)try{let e=JSON.parse(t);e&&e.id&&e.type&&g(e)}catch{}}if(_||v){let t=e.clipboardData.getData(`text`);if(t.startsWith(`http`)){let e=t.split(`
|
|
1531
|
+
`);for(let t of e){if(v)try{let e=await ru(t);if(e){v(e);continue}}catch{}_&&_(t)}}}p.onComplete&&p.onComplete()}},[]),S=(0,u.useCallback)(function(e){e.defaultPrevented||(e.preventDefault(),e.dataTransfer&&p.draggable&&(e.dataTransfer.effectAllowed=`all`,y&&y.id&&y.type&&e.dataTransfer.setData(`application/json+vault`,JSON.stringify({id:y.id,type:y.type}))))},[]),C=(0,u.useCallback)(async function(e){if(e.preventDefault(),e.dataTransfer){if(h){let t=e.dataTransfer.getData(`application/json+vault`);if(t)try{let n=JSON.parse(t);n&&n.id&&n.type&&h(n,e)}catch{return}}let t=e.dataTransfer.getData(`application/json`);if(t){JSON.parse(t);return}if(e.dataTransfer.getData(`text/plain`))return}},[]),w=(0,u.useCallback)(e=>{e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`)},[]);return(0,d.jsx)(m,{onCopy:b,onPaste:x,onDrop:C,onDragOver:w,onDragStart:S,tabIndex:-1,...p})}exports.AppHeader=Oa,exports.AppMenuProvider=Ma,exports.AppProvider=qn,exports.AppReactContext=Bn,exports.AppResourceInstanceProvider=cr,exports.AppResourceProvider=lr,exports.AppStateReactContext=Vn,exports.AtlasStoreProvider=m.AtlasStoreProvider,exports.AtlasStoreReactContext=m.AtlasStoreReactContext,exports.BackgroundActionToasts=ta,exports.BackgroundActionsMenu=ha,exports.BackgroundActionsMount=ea,exports.BackgroundActionsProvider=kt,exports.BackgroundActionsReactContext=Ot,exports.BaseAnnotationCreator=Ro,exports.BaseEditor=Ho,exports.BaseEditorBackButton=zo,exports.BaseEditorCloseButton=Bo,exports.ButtonChange=Or,exports.ButtonContainer=Er,exports.ButtonEmpty=Fr,exports.ButtonMain=Dr,exports.CANVAS_PROGRESS_META_NAMESPACE=oe,exports.CANVAS_PROGRESS_STATUS_META_KEY=se,exports.ConfigEditor=ts,exports.ConfigProvider=ae,exports.ConfigReactContext=L,exports.ContextMenuProvider=os,exports.ContextMenuReactContext=as,exports.CreatorInitialData=Oo,exports.CreatorSettings=rs,exports.EditingStack=ii,exports.EditingStackContext=Kr,exports.EventEmitterProvider=Fs,exports.ExportPanel=js,exports.FLAG_TAG=gi,exports.HOMEPAGE_COLLECTION=yo,exports.HandleContainer=Vs,exports.HandleControls=Ks,exports.IIIFOptions=es,exports.InlineEditingStack=ai,exports.Layout=Ac,exports.LayoutActionsReactContext=oi,exports.LayoutModeReactContext=ci,exports.LayoutStateReactContext=si,exports.ManifestEditorCanvasProgressOverlay=Ee,exports.ManifestEditorTagBadge=zi,exports.ManifestEditorTagIcon=Ri,exports.ManifestEditorTagOverlay=Bi,exports.ManifestPaginationNavigation=Lc,exports.MenuContainer=kr,exports.MenuItem=Ar,exports.MenuItemClose=Pr,exports.MenuItemLabel=Nr,exports.MenuItemStatus=Mr,Object.defineProperty(exports,"MessagePortClientVault",{enumerable:!0,get:function(){return A.MessagePortClientVault}}),exports.ModularPanel=mo,exports.ModularPanelHeader=co,exports.ModulePanelButton=lo,exports.MultiAppProvider=Zn,exports.PanelError=io,exports.PluginConfigBridge=Rn,exports.PluginGlobalConfigReactContext=Tn,exports.PluginManager=Zo,exports.PluginProvider=En,exports.PluginReactContext=wn,exports.PresetOnboarding=Da,exports.PresetOnboardingButton=Ta,exports.PresetPreviewButton=Ea,exports.PreviewButton=Lr,exports.PreviewProvider=xr,exports.PreviewVaultBoundary=So,exports.PreviewVaultContext=xo,exports.PreviewWindowProvider=Yc,exports.PrimeAppReactContext=zn,exports.ReactEmitterContext=Ps,exports.ResourceEditingProvider=Hr,exports.ResourceEditingReactContext=Rr,exports.SaveConfigReactContext=R,exports.ShellProvider=nl,exports.SpecificationProvider=Hl,exports.TAGS_META_KEY=hi,exports.TAGS_META_NAMESPACE=mi,exports.TaskBridge=nu,exports.ToastProvider=Gi,exports.UniversalCopyTarget=iu,exports.addResourceTag=ki,exports.analyse=Ra,exports.analyseJson=Ba,exports.applyPlugins=Sn,exports.baseCreator=Io,exports.baseEditor=Uo,exports.clearCanvasProgressStatus=he,exports.clearCanvasProgressStatuses=_e,exports.collectSpecificationResources=hl,exports.copyToClipboard=It,exports.createActionIdentity=Pt,exports.createBackgroundActionsStore=yt,exports.createDownload=Ft,exports.createIframeVaultBridge=Wc,exports.createLocalForageBackgroundActionPersistence=Et,exports.createManifestEditorCanvasProgressApi=ve,exports.createManifestEditorTagsApi=Fi,exports.createPluginRuntimeApi=gn,exports.createPluginStore=Cn,exports.createPreviewVault=ho,exports.createTrackingCanvasProgressApi=ye,exports.detectMedia=La,exports.disablePluginInConfig=Yt,exports.editBasedOnResource=Vo,exports.enablePluginAndDependenciesInConfig=_n,exports.enablePluginInConfig=Jt,exports.evaluateSpecifications=ml,exports.extendApp=Bt,exports.filterSupportedPanels=_c,exports.getAvailableBackgroundActionGroups=Fe,exports.getBackgroundActionInstanceKey=ke,exports.getCanvasProgressStatus=fe,exports.getCanvasProgressStatusFromState=pe,exports.getDefaultLayoutState=Ic,exports.getDefaultPanelState=Fc,exports.getEffectivePluginSettings=hn,exports.getEmptyPluginState=Ut,exports.getEnabledPluginsForApp=un,exports.getFormat=Ua,exports.getImageDimensions=Wa,exports.getManifestNomalized=Nt,exports.getPluginCompatibilityReason=sn,exports.getPluginDefaultSettings=mn,exports.getPluginSelectionSource=ln,exports.getPluginSettingsFromConfig=dn,exports.getPresetOnboardingDismissalKey=Ca,exports.getPropertyPolicy=pl,exports.getResourceTag=Ai,exports.getResourceTagGroups=Mi,exports.getResourceTags=Ei,exports.getResourceTagsFromState=Di,exports.getSelectedPresetTemplate=Wn,exports.getSupportedPanelFallback=vc,exports.getTerminologyLabel=fl,exports.getValueAtPath=cl,exports.hasMeaningfulValue=$,exports.hasPreviewOption=Ir,exports.hasResourceTag=Ni,exports.isLazyPlugin=tn,exports.isMappedPlugin=en,exports.isPinnableState=to,exports.isPluginCompatible=on,exports.isPluginSelected=cn,exports.layoutReducer=Pc,exports.mapApp=Rt,exports.mapLazyPlugin=$t,exports.mapPlugin=Qt,exports.mergeBackgroundActionDefinitions=Ae,exports.mergeConfig=re,exports.mergePartialConfig=I,exports.mergePresetConfig=zt,exports.mergeProviderPlugins=an,exports.normaliseBackgroundActionError=Me,exports.normaliseJsonValue=ul,exports.normalisePlugin=nn,exports.normalisePluginAppConfig=Kt,exports.normalisePluginAppsConfig=qt,exports.normalisePlugins=rn,exports.normaliseSpecificationPath=ol,exports.panelIds=Q,exports.panelSizing=no,exports.pluginAppConfigEquals=Zt,exports.polygonToBoundingBox=Pa,exports.randomId=Lt,exports.removeResourceTag=ji,exports.renderHelper=ro,exports.resetPluginInConfig=Xt,exports.resetPluginSettingsInConfig=pn,exports.runBackgroundAction=St,exports.setCanvasProgressStatus=me,exports.setCanvasProgressStatuses=ge,exports.setPluginSettingsInConfig=fn,exports.setResourceTags=Oi,exports.setValueAtPath=ll,exports.sortBackgroundActionDefinitions=je,exports.specificationJsonEquals=dl,exports.specificationPathEquals=sl,exports.toggleResourceTag=Pi,exports.useAnnotationCreatorState=Ms,exports.useAnnotationPageEditor=ti,exports.useApp=U,exports.useAppInstance=Hn,exports.useAppMenu=Aa,exports.useAppMenuItem=ja,exports.useAppResource=W,exports.useAppResourceInstance=sr,exports.useAppState=Un,exports.useApps=Yn,exports.useAtlasStore=Na,exports.useAvailableBackgroundActions=$i,exports.useAvailableLayouts=fi,exports.useBackgroundActionHistory=Mt,exports.useBackgroundActionInstance=jt,exports.useBackgroundActionsStore=H,exports.useBackgroundActionsStoreApi=At,exports.useCanvasProgressActions=xe,exports.useCanvasProgressStatus=be,exports.useCollectionEditor=$r,exports.useConfig=z,exports.useCreatingResource=Zr,exports.useCreator=Co,exports.useCustomContextMenu=us,exports.useDecayState=Wo,exports.useEditingContext=zr,exports.useEditingResource=Yr,exports.useEditingResourceStack=Xr,exports.useEditingStack=Jr,exports.useEditor=ni,exports.useEmitter=Is,exports.useEnabledPlugins=jn,exports.useEvent=Ls,exports.useGenericEditor=ei,exports.useHighlightedImageResource=Ga,exports.useHoverHighlightImageResource=qa,exports.useInitialData=Do,exports.useInlineCreator=wo,exports.useLayoutActions=ui,exports.useLayoutMode=di,exports.useLayoutProvider=pi,exports.useLayoutState=li,exports.useLocalStorage=l.useLocalStorage,exports.useManifestEditor=Qr,exports.useMatchMedia=Rs,exports.useOpenPresetOnboarding=wa,exports.useOptionalLocalStorage=l.useOptionalLocalStorage,exports.useOptionalPluginStoreApi=Dn,exports.useOptionalResource=Vr,exports.usePanelActions=jc,exports.usePluginActions=Mn,exports.usePluginConfigApi=Fn,exports.usePluginRuntimeApi=Nn,exports.usePluginSettings=Pn,exports.usePluginStoreApi=On,exports.usePlugins=An,exports.usePresetTemplateSelection=Gn,exports.usePreviewContext=Cr,exports.usePreviewHistory=bo,exports.usePreviewVault=go,exports.usePreviewWindow=Xc,exports.usePreviews=Sr,exports.useResolvedPluginApp=In,exports.useResource=Br,exports.useResourceContextMenuItems=cs,exports.useResourceTagActions=Li,exports.useResourceTags=Ii,exports.useSaveConfig=ie,exports.useSaveVault=zs,exports.useSetCustomTitle=oo,exports.useSpecificationPropertyPolicy=Kl,exports.useSpecificationReport=Wl,exports.useSpecificationTerminology=Gl,exports.useSpecifications=Ul,exports.useSvgTools=Bs,exports.useTask=Zl,exports.useTaskDispatch=eu,exports.useTaskEvent=Ql,exports.useTaskRunner=tu,exports.useTemporaryHighlight=Ka,exports.useToasts=Ki;
|
|
1532
1532
|
//# sourceMappingURL=index.cjs.map
|