-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
201 additions
and
51 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
manifest-editor/src/_creators/Manifest/ManifestBrowserCreator/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { CreatorDefinition } from "@/creator-api"; | ||
import textFormatIcon from "@/icons/TextFormatIcon.svg"; | ||
import React from "react"; | ||
import ManifestBrowserCreatorForm from "@/_creators/Manifest/ManifestBrowserCreator/manifest-browser-form.lazy"; | ||
import { createFromManifestBrowserOutput } from "@/_creators/Manifest/ManifestBrowserCreator/manifest-browser-creator"; | ||
|
||
export const manifestBrowserCreator: CreatorDefinition = { | ||
id: "@manifest-editor/manifest-browser-creator", | ||
create: createFromManifestBrowserOutput, | ||
label: "IIIF Browser", | ||
summary: "Find a resource within a IIIF Collection", | ||
icon: <img src={textFormatIcon} alt="" />, | ||
render(ctx: any) { | ||
return <ManifestBrowserCreatorForm {...ctx} />; | ||
}, | ||
resourceType: "Manifest", | ||
resourceFields: ["id", "label"], | ||
additionalTypes: ["Collection"], | ||
supports: { | ||
parentTypes: ["Collection"], | ||
parentFieldMap: { | ||
Collection: ["items"], | ||
}, | ||
}, | ||
sideEffects: [], | ||
staticFields: {}, | ||
}; |
55 changes: 55 additions & 0 deletions
55
manifest-editor/src/_creators/Manifest/ManifestBrowserCreator/manifest-browser-creator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { CreatorFunctionContext } from "@/creator-api"; | ||
import { ContentState, normaliseContentState, parseContentState } from "@iiif/vault-helpers"; | ||
import { lazy } from "react"; | ||
import invariant from "tiny-invariant"; | ||
|
||
interface ManifestBrowserCreatorPayload { | ||
// This is the output (JSON) from the IIIF Browser. | ||
// We could have gone with "IIIF Content State" here and may do in the future, but this | ||
// will simplify parsing and importing resources. | ||
output: string | ContentState | ContentState[]; | ||
} | ||
|
||
export async function createFromManifestBrowserOutput( | ||
data: ManifestBrowserCreatorPayload, | ||
ctx: CreatorFunctionContext | ||
) { | ||
const targetType = ctx.options.targetType as "Manifest" | "Collection"; | ||
|
||
// For now.. | ||
if (Array.isArray(data.output)) { | ||
throw new Error("Multiple items not yet supported"); | ||
} | ||
|
||
const contentState = normaliseContentState( | ||
typeof data.output === "string" ? parseContentState(data.output) : data.output | ||
); | ||
|
||
const target = contentState.target[0]; | ||
const previewVault = ctx.getPreviewVault(); | ||
|
||
if (targetType === "Manifest") { | ||
const manifestId = target.source.id; | ||
invariant(manifestId, "Could not find Manifest ID"); | ||
const manifest = await previewVault.get(manifestId); | ||
return ctx.embed({ | ||
id: target.source.id, | ||
type: "Manifest", | ||
label: manifest.label, | ||
}); | ||
} | ||
|
||
if (targetType === "Collection") { | ||
const collectionId = target.source.id; | ||
invariant(collectionId, "Could not find Manifest ID"); | ||
const collection = await previewVault.get(collectionId); | ||
return ctx.embed({ | ||
id: target.source.id, | ||
type: "Collection", | ||
label: collection.label, | ||
}); | ||
} | ||
|
||
throw new Error("Not yet supported."); | ||
} | ||
export const ManifestBrowserCreatorForm = lazy(() => import("./manifest-browser-form.lazy")); |
38 changes: 38 additions & 0 deletions
38
manifest-editor/src/_creators/Manifest/ManifestBrowserCreator/manifest-browser-form.lazy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { CreatorContext } from "@/creator-api"; | ||
import { | ||
HOMEPAGE_COLLECTION, | ||
PreviewVaultBoundary, | ||
usePreviewHistory, | ||
usePreviewVault, | ||
} from "@/shell/PreviewVault/PreviewVault"; | ||
import { IIIFExplorer } from "@/components/widgets/IIIFExplorer/IIIFExplorer"; | ||
|
||
export default function ManifestBrowserCreatorForm(props: CreatorContext) { | ||
const vault = usePreviewVault(); | ||
const { addHistory, clearHistory } = usePreviewHistory(); | ||
|
||
return ( | ||
<> | ||
<PreviewVaultBoundary> | ||
<IIIFExplorer | ||
window={false} | ||
hideHeader={true} | ||
outputTypes={["Manifest", "Collection"]} | ||
vault={vault} | ||
output={{ type: "content-state" }} | ||
homepageCollection={HOMEPAGE_COLLECTION} | ||
clearHomepageCollection={clearHistory} | ||
onHistory={addHistory} | ||
outputTargets={[ | ||
{ | ||
type: "callback", | ||
label: "Select", | ||
cb: (resource) => props.runCreate({ output: resource }), | ||
}, | ||
]} | ||
allowRemoveEntry | ||
/> | ||
</PreviewVaultBoundary> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters