@manifest-editor/creator-api 2.1.1-next.0.96fdf30 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +131 -100
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +131 -100
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { Entities, Vault } from "@iiif/helpers/vault";
|
|
2
2
|
import { resources } from "@manifest-editor/editor-api";
|
|
3
|
-
import * as _iiif_presentation_329 from "@iiif/presentation-3";
|
|
4
3
|
import { Annotation, DescriptiveProperties, LinkingProperties, NavPlaceExtension, Reference, SpecificResource, StructuralProperties, TechnicalProperties } from "@iiif/presentation-3";
|
|
5
4
|
import { ReactNode } from "react";
|
|
6
5
|
import { SupportedSelector } from "@iiif/helpers";
|
|
7
|
-
|
|
8
6
|
//#region src/ReferencedResource.d.ts
|
|
9
7
|
declare class ReferencedResource {
|
|
10
8
|
vault: Vault;
|
|
@@ -17,56 +15,56 @@ declare class ReferencedResource {
|
|
|
17
15
|
id: string;
|
|
18
16
|
};
|
|
19
17
|
specificResource(): {
|
|
20
|
-
created?: string
|
|
21
|
-
generated?: string
|
|
22
|
-
modified?: string
|
|
23
|
-
creator?:
|
|
24
|
-
generator?:
|
|
25
|
-
audience?: (
|
|
26
|
-
accessibility?: string | string[]
|
|
27
|
-
motivation?: (
|
|
28
|
-
rights?: string | string[]
|
|
29
|
-
canonical?: string
|
|
30
|
-
via?: string | string[]
|
|
31
|
-
role?: string
|
|
32
|
-
id?: string
|
|
18
|
+
created?: string;
|
|
19
|
+
generated?: string;
|
|
20
|
+
modified?: string;
|
|
21
|
+
creator?: import("@iiif/presentation-3").Creator;
|
|
22
|
+
generator?: import("@iiif/presentation-3").Creator;
|
|
23
|
+
audience?: import("@iiif/presentation-3").Audience | import("@iiif/presentation-3").Audience[];
|
|
24
|
+
accessibility?: string | string[];
|
|
25
|
+
motivation?: import("@iiif/presentation-3").AnyMotivation | import("@iiif/presentation-3").AnyMotivation[];
|
|
26
|
+
rights?: string | string[];
|
|
27
|
+
canonical?: string;
|
|
28
|
+
via?: string | string[];
|
|
29
|
+
role?: string;
|
|
30
|
+
id?: string;
|
|
33
31
|
type: "SpecificResource";
|
|
34
|
-
state?: (
|
|
35
|
-
purpose?: (
|
|
32
|
+
state?: import("@iiif/presentation-3").State | import("@iiif/presentation-3").State[];
|
|
33
|
+
purpose?: import("@iiif/presentation-3").AnyMotivation | import("@iiif/presentation-3").AnyMotivation[];
|
|
36
34
|
source?: any;
|
|
37
|
-
selector?: (
|
|
38
|
-
styleClass?: string
|
|
39
|
-
renderedVia?: (
|
|
40
|
-
scope?:
|
|
35
|
+
selector?: import("@iiif/presentation-3").Selector | import("@iiif/presentation-3").Selector[];
|
|
36
|
+
styleClass?: string;
|
|
37
|
+
renderedVia?: import("@iiif/presentation-3").Agent | import("@iiif/presentation-3").Agent[];
|
|
38
|
+
scope?: import("@iiif/presentation-3").LinkedResource;
|
|
41
39
|
};
|
|
42
40
|
optionalSpecificResource(): {
|
|
43
41
|
type: string;
|
|
44
42
|
id: string;
|
|
45
43
|
} | {
|
|
44
|
+
created?: string;
|
|
45
|
+
generated?: string;
|
|
46
|
+
modified?: string;
|
|
47
|
+
creator?: import("@iiif/presentation-3").Creator;
|
|
48
|
+
generator?: import("@iiif/presentation-3").Creator;
|
|
49
|
+
audience?: import("@iiif/presentation-3").Audience | import("@iiif/presentation-3").Audience[];
|
|
50
|
+
accessibility?: string | string[];
|
|
51
|
+
motivation?: import("@iiif/presentation-3").AnyMotivation | import("@iiif/presentation-3").AnyMotivation[];
|
|
52
|
+
rights?: string | string[];
|
|
53
|
+
canonical?: string;
|
|
54
|
+
via?: string | string[];
|
|
55
|
+
role?: string;
|
|
56
|
+
id?: string;
|
|
57
|
+
type: "SpecificResource";
|
|
58
|
+
state?: import("@iiif/presentation-3").State | import("@iiif/presentation-3").State[];
|
|
59
|
+
purpose?: import("@iiif/presentation-3").AnyMotivation | import("@iiif/presentation-3").AnyMotivation[];
|
|
60
|
+
selector?: import("@iiif/presentation-3").Selector | import("@iiif/presentation-3").Selector[];
|
|
61
|
+
styleClass?: string;
|
|
62
|
+
renderedVia?: import("@iiif/presentation-3").Agent | import("@iiif/presentation-3").Agent[];
|
|
63
|
+
scope?: import("@iiif/presentation-3").LinkedResource;
|
|
46
64
|
source: {
|
|
47
65
|
id: any;
|
|
48
66
|
type: any;
|
|
49
67
|
};
|
|
50
|
-
created?: string | undefined;
|
|
51
|
-
generated?: string | undefined;
|
|
52
|
-
modified?: string | undefined;
|
|
53
|
-
creator?: _iiif_presentation_329.Creator | undefined;
|
|
54
|
-
generator?: _iiif_presentation_329.Creator | undefined;
|
|
55
|
-
audience?: (_iiif_presentation_329.Audience | _iiif_presentation_329.Audience[]) | undefined;
|
|
56
|
-
accessibility?: string | string[] | undefined;
|
|
57
|
-
motivation?: (_iiif_presentation_329.AnyMotivation | _iiif_presentation_329.AnyMotivation[]) | undefined;
|
|
58
|
-
rights?: string | string[] | undefined;
|
|
59
|
-
canonical?: string | undefined;
|
|
60
|
-
via?: string | string[] | undefined;
|
|
61
|
-
role?: string | undefined;
|
|
62
|
-
id?: string | undefined;
|
|
63
|
-
type: "SpecificResource";
|
|
64
|
-
state?: (_iiif_presentation_329.State | _iiif_presentation_329.State[]) | undefined;
|
|
65
|
-
purpose?: (_iiif_presentation_329.AnyMotivation | _iiif_presentation_329.AnyMotivation[]) | undefined;
|
|
66
|
-
selector?: (_iiif_presentation_329.Selector | _iiif_presentation_329.Selector[]) | undefined;
|
|
67
|
-
styleClass?: string | undefined;
|
|
68
|
-
renderedVia?: (_iiif_presentation_329.Agent | _iiif_presentation_329.Agent[]) | undefined;
|
|
69
|
-
scope?: _iiif_presentation_329.LinkedResource;
|
|
70
68
|
};
|
|
71
69
|
get(): any;
|
|
72
70
|
}
|
|
@@ -84,27 +82,27 @@ declare class CreatorResource {
|
|
|
84
82
|
constructor(inputData: any, vault: Vault);
|
|
85
83
|
get(): any;
|
|
86
84
|
getSpecificResource(): {
|
|
87
|
-
created?: string
|
|
88
|
-
generated?: string
|
|
89
|
-
modified?: string
|
|
90
|
-
creator?:
|
|
91
|
-
generator?:
|
|
92
|
-
audience?: (
|
|
93
|
-
accessibility?: string | string[]
|
|
94
|
-
motivation?: (
|
|
95
|
-
rights?: string | string[]
|
|
96
|
-
canonical?: string
|
|
97
|
-
via?: string | string[]
|
|
98
|
-
role?: string
|
|
99
|
-
id?: string
|
|
85
|
+
created?: string;
|
|
86
|
+
generated?: string;
|
|
87
|
+
modified?: string;
|
|
88
|
+
creator?: import("@iiif/presentation-3").Creator;
|
|
89
|
+
generator?: import("@iiif/presentation-3").Creator;
|
|
90
|
+
audience?: import("@iiif/presentation-3").Audience | import("@iiif/presentation-3").Audience[];
|
|
91
|
+
accessibility?: string | string[];
|
|
92
|
+
motivation?: import("@iiif/presentation-3").AnyMotivation | import("@iiif/presentation-3").AnyMotivation[];
|
|
93
|
+
rights?: string | string[];
|
|
94
|
+
canonical?: string;
|
|
95
|
+
via?: string | string[];
|
|
96
|
+
role?: string;
|
|
97
|
+
id?: string;
|
|
100
98
|
type: "SpecificResource";
|
|
101
|
-
state?: (
|
|
102
|
-
purpose?: (
|
|
99
|
+
state?: import("@iiif/presentation-3").State | import("@iiif/presentation-3").State[];
|
|
100
|
+
purpose?: import("@iiif/presentation-3").AnyMotivation | import("@iiif/presentation-3").AnyMotivation[];
|
|
103
101
|
source?: any;
|
|
104
|
-
selector?: (
|
|
105
|
-
styleClass?: string
|
|
106
|
-
renderedVia?: (
|
|
107
|
-
scope?:
|
|
102
|
+
selector?: import("@iiif/presentation-3").Selector | import("@iiif/presentation-3").Selector[];
|
|
103
|
+
styleClass?: string;
|
|
104
|
+
renderedVia?: import("@iiif/presentation-3").Agent | import("@iiif/presentation-3").Agent[];
|
|
105
|
+
scope?: import("@iiif/presentation-3").LinkedResource;
|
|
108
106
|
} | {
|
|
109
107
|
type: string;
|
|
110
108
|
source: {
|
|
@@ -113,27 +111,27 @@ declare class CreatorResource {
|
|
|
113
111
|
};
|
|
114
112
|
};
|
|
115
113
|
ref(): {
|
|
116
|
-
created?: string
|
|
117
|
-
generated?: string
|
|
118
|
-
modified?: string
|
|
119
|
-
creator?:
|
|
120
|
-
generator?:
|
|
121
|
-
audience?: (
|
|
122
|
-
accessibility?: string | string[]
|
|
123
|
-
motivation?: (
|
|
124
|
-
rights?: string | string[]
|
|
125
|
-
canonical?: string
|
|
126
|
-
via?: string | string[]
|
|
127
|
-
role?: string
|
|
128
|
-
id?: string
|
|
114
|
+
created?: string;
|
|
115
|
+
generated?: string;
|
|
116
|
+
modified?: string;
|
|
117
|
+
creator?: import("@iiif/presentation-3").Creator;
|
|
118
|
+
generator?: import("@iiif/presentation-3").Creator;
|
|
119
|
+
audience?: import("@iiif/presentation-3").Audience | import("@iiif/presentation-3").Audience[];
|
|
120
|
+
accessibility?: string | string[];
|
|
121
|
+
motivation?: import("@iiif/presentation-3").AnyMotivation | import("@iiif/presentation-3").AnyMotivation[];
|
|
122
|
+
rights?: string | string[];
|
|
123
|
+
canonical?: string;
|
|
124
|
+
via?: string | string[];
|
|
125
|
+
role?: string;
|
|
126
|
+
id?: string;
|
|
129
127
|
type: "SpecificResource";
|
|
130
|
-
state?: (
|
|
131
|
-
purpose?: (
|
|
128
|
+
state?: import("@iiif/presentation-3").State | import("@iiif/presentation-3").State[];
|
|
129
|
+
purpose?: import("@iiif/presentation-3").AnyMotivation | import("@iiif/presentation-3").AnyMotivation[];
|
|
132
130
|
source?: any;
|
|
133
|
-
selector?: (
|
|
134
|
-
styleClass?: string
|
|
135
|
-
renderedVia?: (
|
|
136
|
-
scope?:
|
|
131
|
+
selector?: import("@iiif/presentation-3").Selector | import("@iiif/presentation-3").Selector[];
|
|
132
|
+
styleClass?: string;
|
|
133
|
+
renderedVia?: import("@iiif/presentation-3").Agent | import("@iiif/presentation-3").Agent[];
|
|
134
|
+
scope?: import("@iiif/presentation-3").LinkedResource;
|
|
137
135
|
} | {
|
|
138
136
|
id: any;
|
|
139
137
|
type: any;
|
|
@@ -150,13 +148,15 @@ declare class CreatorInstance implements CreatorFunctionContext {
|
|
|
150
148
|
previewVault: Vault;
|
|
151
149
|
configs: CreatorDefinition[];
|
|
152
150
|
options: CreatorOptions;
|
|
151
|
+
config: Record<string, unknown>;
|
|
152
|
+
creatorConfig: CreatorConfig;
|
|
153
153
|
target: CreatorOptions["target"];
|
|
154
154
|
selector: SupportedSelector | undefined | null;
|
|
155
155
|
serialisedSelector: {
|
|
156
156
|
type: string;
|
|
157
157
|
value: string;
|
|
158
158
|
} | null;
|
|
159
|
-
constructor(vault: Vault, options: CreatorOptions, createConfigs: CreatorDefinition[], previewVault: Vault);
|
|
159
|
+
constructor(vault: Vault, options: CreatorOptions, createConfigs: CreatorDefinition[], previewVault: Vault, configKey: string, creatorConfig?: CreatorConfig);
|
|
160
160
|
getPreviewVault(): Vault;
|
|
161
161
|
setSelector(selector: SupportedSelector): void;
|
|
162
162
|
getSerialisedSelector(): {
|
|
@@ -176,7 +176,7 @@ declare class CreatorInstance implements CreatorFunctionContext {
|
|
|
176
176
|
}
|
|
177
177
|
//#endregion
|
|
178
178
|
//#region src/creator-register.d.ts
|
|
179
|
-
declare function defineCreator<const Payload
|
|
179
|
+
declare function defineCreator<const Payload = any, const ID = Readonly<string>, const ResourceType extends AllAvailableParentTypes = never, const AdditionalResourceTypes extends Array<AllAvailableParentTypes> = [], const AllResourceTypes = [ResourceType, ...AdditionalResourceTypes], const SupportsParentTypes extends Array<AllAvailableParentTypes> = AllParentTypes, const SupportsParentFields extends Array<AllProperties> = [], const CreateReturnType = any>(options: SpecificCreatorDefinition<Payload, ID, ResourceType, AdditionalResourceTypes, AllResourceTypes, SupportsParentTypes, SupportsParentFields, CreateReturnType>): SpecificCreatorDefinition<Payload, ID, ResourceType, AdditionalResourceTypes, AllResourceTypes, SupportsParentTypes, SupportsParentFields, CreateReturnType>;
|
|
180
180
|
declare function withInitialData<T extends CreatorDefinition>(creator: T, data: Record<string, any>, overrides?: Record<string, any>): T;
|
|
181
181
|
declare function withCustomRender<T extends CreatorDefinition>(creator: T, render: (ctx: CreatorContext<any>, originalRender: (ctx: CreatorContext<any>) => React.ReactNode) => React.ReactNode): T;
|
|
182
182
|
declare namespace IIIFManifestEditor {
|
|
@@ -195,13 +195,14 @@ type ExtractCreatorGenerics<T extends CreatorDefinition> = T extends SpecificCre
|
|
|
195
195
|
type CreatorSupportsParentTypes<T, Type extends AllAvailableParentTypes> = T extends CreatorDefinition ? ExtractCreatorGenerics<T>["SupportsParentTypes"] extends never ? false : HelperInArray<Type, ExtractCreatorGenerics<T>["SupportsParentTypes"]> : false;
|
|
196
196
|
type CreatorSupportsParentFields<T, Field extends AllProperties> = T extends CreatorDefinition ? ExtractCreatorGenerics<T>["SupportsParentFields"] extends never ? false : HelperInArray<Field, ExtractCreatorGenerics<T>["SupportsParentFields"]> : false;
|
|
197
197
|
type CreatorSupportsParent<T, Type extends AllAvailableParentTypes, Field extends AllProperties> = T extends CreatorDefinition ? CreatorSupportsParentTypes<T, Type> extends true ? CreatorSupportsParentFields<T, Field> extends true ? true : false : false : false;
|
|
198
|
-
type HelperInArray<ToFind, Array
|
|
199
|
-
type CreatorDefinitionFilterByParent<Type extends AllAvailableParentTypes, Field extends AllProperties = AllProperties, CD extends IIIFManifestEditor.CreatorDefinitions = IIIFManifestEditor.CreatorDefinitions> = { [K in keyof CD]: CreatorSupportsParent<CD[K], Type, Field> extends true ? CD[K] : never }[keyof CD];
|
|
198
|
+
type HelperInArray<ToFind, Array extends readonly any[]> = Array extends readonly [infer Head, ...infer Tail] ? Head extends ToFind ? true : HelperInArray<ToFind, Tail> : false;
|
|
199
|
+
type CreatorDefinitionFilterByParent<Type extends AllAvailableParentTypes, Field extends AllProperties = AllProperties, CD extends IIIFManifestEditor.CreatorDefinitions = IIIFManifestEditor.CreatorDefinitions> = { [K in keyof CD]: CreatorSupportsParent<CD[K], Type, Field> extends true ? CD[K] : never; }[keyof CD];
|
|
200
200
|
//#endregion
|
|
201
201
|
//#region src/types.d.ts
|
|
202
202
|
interface CreatorContext<T = any> {
|
|
203
203
|
vault: Vault;
|
|
204
204
|
options: CreatorOptions;
|
|
205
|
+
config?: Record<string, unknown>;
|
|
205
206
|
validate: (payload: T) => Promise<boolean> | boolean;
|
|
206
207
|
runCreate: (payload: T) => void;
|
|
207
208
|
}
|
|
@@ -209,6 +210,7 @@ type ResolvedCreatorReturn<T extends CreatorDefinition> = Awaited<ExtractCreator
|
|
|
209
210
|
interface CreatorFunctionContext {
|
|
210
211
|
vault: Vault;
|
|
211
212
|
options: CreatorOptions;
|
|
213
|
+
config: Record<string, unknown>;
|
|
212
214
|
ref(idOrRef: string | Reference): ReferencedResource;
|
|
213
215
|
embed(data: any): CreatorResource;
|
|
214
216
|
create(definition: string, payload: any, options?: Partial<CreatorOptions>): Promise<CreatorResource | CreatorResource[]>;
|
|
@@ -232,24 +234,51 @@ interface CreatorOptions {
|
|
|
232
234
|
initialData?: any;
|
|
233
235
|
rootId?: string;
|
|
234
236
|
}
|
|
237
|
+
type CreatorConfig = Record<string, Record<string, unknown>>;
|
|
238
|
+
type CreatorConfigField = {
|
|
239
|
+
id: string;
|
|
240
|
+
type: "checkbox";
|
|
241
|
+
label: string;
|
|
242
|
+
summary?: string;
|
|
243
|
+
defaultValue?: boolean;
|
|
244
|
+
};
|
|
245
|
+
interface CreatorConfiguration {
|
|
246
|
+
fields: CreatorConfigField[];
|
|
247
|
+
}
|
|
248
|
+
interface CreatorResourceProbeHelpers {
|
|
249
|
+
json(url: string): Promise<any>;
|
|
250
|
+
text(url: string): Promise<string>;
|
|
251
|
+
head(url: string): Promise<Response>;
|
|
252
|
+
contentType(url: string): Promise<string>;
|
|
253
|
+
}
|
|
254
|
+
type CreatorResourceProbeResult = boolean | {
|
|
255
|
+
initialData?: Record<string, any>;
|
|
256
|
+
label?: string;
|
|
257
|
+
};
|
|
235
258
|
type AllAvailableParentTypes = keyof typeof resources.supported;
|
|
236
259
|
type GetSupportedResourceFields<Resource extends AllAvailableParentTypes> = {} & (typeof resources.supported)[Resource]["allowed"][number];
|
|
237
260
|
type AllProperties = ({} & keyof LinkingProperties) | ({} & keyof StructuralProperties<any>) | ({} & keyof TechnicalProperties) | ({} & keyof DescriptiveProperties) | ({} & keyof Annotation) | ({} & keyof NavPlaceExtension);
|
|
238
261
|
type AllParentTypes = ["Collection", "Manifest", "Canvas", "Annotation", "AnnotationPage", "Range", "AnnotationCollection", "ContentResource", "Agent"];
|
|
239
|
-
interface SpecificCreatorDefinition<Payload
|
|
240
|
-
readonly id: ID
|
|
262
|
+
interface SpecificCreatorDefinition<Payload = any, ID = Readonly<string>, ResourceType extends AllAvailableParentTypes = never, AdditionalResourceTypes extends Array<AllAvailableParentTypes> = [], AllResourceTypes = [ResourceType, ...AdditionalResourceTypes], SupportsParentTypes extends Array<AllAvailableParentTypes> = AllParentTypes, SupportsParentFields extends Array<AllProperties> = [], CreateReturnType = any | Promise<any> | any[] | Promise<any[]>> {
|
|
263
|
+
readonly id: ID;
|
|
241
264
|
label: string;
|
|
242
265
|
summary?: string;
|
|
243
266
|
icon?: any;
|
|
244
267
|
dependencies?: string[];
|
|
245
268
|
tags?: string[];
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
269
|
+
configuration?: CreatorConfiguration;
|
|
270
|
+
readonly configKey?: string;
|
|
271
|
+
create: (payload: Payload, ctx: CreatorInstance) => CreateReturnType;
|
|
272
|
+
validate?: (payload: Payload, vault: Vault) => void | Promise<void>;
|
|
273
|
+
supportsResource?: (value: string, helpers: CreatorResourceProbeHelpers, ctx: {
|
|
274
|
+
vault: Vault;
|
|
275
|
+
resource: CreatableResource;
|
|
276
|
+
}) => CreatorResourceProbeResult | Promise<CreatorResourceProbeResult>;
|
|
277
|
+
render?: (ctx: CreatorContext<Payload>) => ReactNode;
|
|
278
|
+
renderCanvas?: (ctx: CreatorContext<Payload>) => ReactNode | null;
|
|
279
|
+
renderModal?: (ctx: CreatorContext<Payload>) => ReactNode;
|
|
280
|
+
resourceType: ResourceType;
|
|
281
|
+
additionalTypes?: AdditionalResourceTypes;
|
|
253
282
|
actionButton?: string;
|
|
254
283
|
resourceFields: string[];
|
|
255
284
|
embeddedResources?: string[];
|
|
@@ -258,8 +287,8 @@ interface SpecificCreatorDefinition<Payload$1 = any, ID$1 = Readonly<string>, Re
|
|
|
258
287
|
hiddenModal?: boolean;
|
|
259
288
|
supports: {
|
|
260
289
|
initialData?: boolean;
|
|
261
|
-
parentTypes?: SupportsParentTypes
|
|
262
|
-
parentFields?: SupportsParentFields
|
|
290
|
+
parentTypes?: SupportsParentTypes;
|
|
291
|
+
parentFields?: SupportsParentFields;
|
|
263
292
|
parentFieldMap?: Record<string, string[]>;
|
|
264
293
|
custom?: (parent: CreatorParent, vault: Vault) => boolean;
|
|
265
294
|
disallowPainting?: boolean;
|
|
@@ -267,7 +296,7 @@ interface SpecificCreatorDefinition<Payload$1 = any, ID$1 = Readonly<string>, Re
|
|
|
267
296
|
};
|
|
268
297
|
sideEffects?: Array<CreatorSideEffect>;
|
|
269
298
|
}
|
|
270
|
-
type CreatorDefinition<Payload
|
|
299
|
+
type CreatorDefinition<Payload = any> = SpecificCreatorDefinition<Payload, any, any, any, any, any, any>;
|
|
271
300
|
interface CreatorSideEffect {
|
|
272
301
|
run?: (result: any, ctx: {
|
|
273
302
|
options: CreatorOptions;
|
|
@@ -296,22 +325,24 @@ declare class Creator {
|
|
|
296
325
|
configs: CreatorDefinition[];
|
|
297
326
|
vault: Vault;
|
|
298
327
|
previewVault: Vault;
|
|
299
|
-
|
|
328
|
+
creatorConfig: CreatorConfig;
|
|
329
|
+
constructor(vault: Vault, configs: CreatorDefinition[], previewVault?: Vault, creatorConfig?: CreatorConfig);
|
|
300
330
|
matchBasedOnResource(resource: CreatableResource): CreatorDefinition[];
|
|
301
331
|
create(definition: string, payload: any, options?: Partial<CreatorOptions>): Promise<Reference | Reference[]>;
|
|
302
332
|
}
|
|
303
333
|
//#endregion
|
|
304
334
|
//#region src/utils.d.ts
|
|
335
|
+
declare function getCreatorConfigKey(definition: CreatorDefinition): string;
|
|
305
336
|
declare function resolveType(type: string): keyof Entities;
|
|
306
337
|
declare function getEmptyType(type: string): any;
|
|
307
338
|
declare function randomId(): string;
|
|
308
339
|
declare function matchBasedOnResource(resource: CreatableResource, list: CreatorDefinition[], options: {
|
|
309
340
|
vault: Vault;
|
|
310
341
|
}): CreatorDefinition[];
|
|
311
|
-
declare function creatorHelper<const ResourceType
|
|
342
|
+
declare function creatorHelper<const ResourceType extends AllAvailableParentTypes, const Parent extends {
|
|
312
343
|
id: string;
|
|
313
|
-
type: ResourceType
|
|
314
|
-
}, const ResourceField extends GetSupportedResourceFields<ResourceType
|
|
344
|
+
type: ResourceType;
|
|
345
|
+
}, const ResourceField extends GetSupportedResourceFields<ResourceType>, const CID extends CreatorDefinitionFilterByParent<ResourceType, ResourceField>["id"], Payload = GetCreatorPayload<IIIFManifestEditor.CreatorDefinitions[CID]>, Return = ResolvedCreatorReturn<IIIFManifestEditor.CreatorDefinitions[CID]>>(ctx: CreatorFunctionContext, parent: Parent | ResourceType, property: ResourceField, definition: CID): (payload: Payload, options?: Partial<CreatorOptions>) => Promise<Return>;
|
|
315
346
|
//#endregion
|
|
316
|
-
export { AllAvailableParentTypes, AllParentTypes, AllProperties, CreatableResource, Creator, CreatorContext, CreatorDefinition, CreatorDefinitionFilterByParent, CreatorFunctionContext, CreatorOptions, CreatorResource, CreatorSideEffect, ExtractCreatorGenerics, GetCreatorPayload, GetSupportedResourceFields, IIIFManifestEditor, ResolvedCreatorReturn, SpecificCreatorDefinition, creatorHelper, defineCreator, getEmptyType, matchBasedOnResource, randomId, resolveType, withCustomRender, withInitialData };
|
|
347
|
+
export { AllAvailableParentTypes, AllParentTypes, AllProperties, CreatableResource, Creator, CreatorConfig, CreatorConfigField, CreatorConfiguration, CreatorContext, CreatorDefinition, CreatorDefinitionFilterByParent, CreatorFunctionContext, CreatorOptions, CreatorResource, CreatorResourceProbeHelpers, CreatorResourceProbeResult, CreatorSideEffect, ExtractCreatorGenerics, GetCreatorPayload, GetSupportedResourceFields, IIIFManifestEditor, ResolvedCreatorReturn, SpecificCreatorDefinition, creatorHelper, defineCreator, getCreatorConfigKey, getEmptyType, matchBasedOnResource, randomId, resolveType, withCustomRender, withInitialData };
|
|
317
348
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/ReferencedResource.ts","../src/CreatorResource.ts","../src/CreatorInstance.ts","../src/creator-register.ts","../src/types.ts","../src/Creator.ts","../src/utils.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/ReferencedResource.ts","../src/CreatorResource.ts","../src/CreatorInstance.ts","../src/creator-register.ts","../src/types.ts","../src/Creator.ts","../src/utils.ts"],"mappings":";;;;;;cAIa;EACX,OAAO;EACP,UAAU,YAAY;EACtB,WAAW;EACX,UAAU;EACV,YAAY,WAAW,YAAY,kBAAkB,OAAO;EAa5D;;;;EAIA;;;;;;;;;;;;;;;;;;;;;;;EAIA;;;;;;;;;;;;;;;;;;;;;;;;;MAKQ;MACA;;;EASR;;;;cCtCW;EACX;EACA;EACA;EACA;EACA,YAAY;EACZ,UAAU;EACV,OAAO;EACP,mBAAmB;EAEnB,YAAY,gBAAgB,OAAO;EAkInC;EAIA;;;;;;;;;;;;;;;;;;;;;;;;;;MAcuD;;;EAPvD;;;;;;;;;;;;;;;;;;;;;;;;IAOuD;;EAIvD,6BAAyB;EAIzB,2BAA2B;EAS3B;EAwE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gCAChB,cACA,sBAEF,UAAU,kBAAkB,mBAAmB,mBAAmB,OAClE,SAAS,sBAAsB,mBAAmB,mBAAmB,OAErE,KAAK,wBACL,QAAQ,SAAS,cACjB,UAAU,eACV,YAAY,OACV,SAAS,SAAS,UAAU,QAAQ,oBAAoB,QAAQ"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Vault as e}from"@iiif/helpers/vault";import{addMappings as t,batchActions as n,entityActions as r,importEntities as i}from"@iiif/helpers/vault/actions";import{annotationResponseToSelector as a,seraliseSupportedSelector as o}from"react-iiif-vault";import{HAS_PART as s,PART_OF as c,emptyAgent as l,emptyAnnotation as u,emptyAnnotationPage as d,emptyCanvas as f,emptyCollection as p,emptyManifest as m,emptyRange as h,emptyService as g,isSpecificResource as _,toRef as v}from"@iiif/parser";import{references as y}from"@manifest-editor/editor-api";function b(e){"@babel/helpers - typeof";return b=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},b(e)}function x(e,t){if(b(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(b(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function S(e){var t=x(e,`string`);return b(t)==`symbol`?t:t+``}function C(e,t,n){return(t=S(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var w=class{constructor(e,t){C(this,`vault`,void 0),C(this,`original`,void 0),C(this,`reference`,void 0),C(this,`resource`,void 0),this.vault=t,this.original=e,this.reference=_(e)?e.source:e,this.resource=_(e)?e:{type:`SpecificResource`,source:this.reference}}ref(){return this.reference}specificResource(){return this.resource}optionalSpecificResource(){return _(this.original)?{...this.original,source:{id:this.original.source?.id,type:this.original.source?.type}}:this.original}get(){return this.vault.get(this.resource)}};function T(e){switch(e){case`Image`:case`Video`:case`Sound`:case`Dataset`:case`Text`:case`TextualBody`:case`Composite`:case`List`:case`Choice`:case`Independents`:case`Audience`:return`ContentResource`;case`ImageService1`:case`ImageService2`:case`ImageService3`:return`Service`}return e}const E={Annotation:u,AnnotationPage:d,Canvas:f,Collection:p,Manifest:m,Range:h,ResourceProvider:l,Service:g};function D(e){return E[T(e)]||{}}function O(){return`${Math.random().toString(36).substring(2)}-${Date.now().toString(36)}`}function k(e,t,n){let r=[];if(t.length===0)return[];let i=v(e.parent),a=e.property,o=e.filter;for(let s of t)if(!(o&&(!s.tags||!s.tags.includes(o)))&&i&&a){if(s.supports.parentTypes&&!s.supports.parentTypes.includes(i.type)||s.supports.parentFields&&!s.supports.parentFields.includes(a))continue;if(s.supports.parentFieldMap){let e=s.supports.parentFieldMap[i.type];if(!e||!e.includes(a))continue}if(s.supports.disallowPainting&&e.isPainting||s.supports.onlyPainting&&!e.isPainting||s.supports.custom&&!s.supports.custom({property:a,resource:i,atIndex:e.index},n.vault))continue;let t=Object.keys(e.initialData||{}).filter(e=>e!==`skipEditingOnCreate`);if(!s.supports.initialData&&t.length!==0||s.resourceType!==e.type&&!(s.additionalTypes||[]).includes(e.type))continue;r.push(s)}return r}function A(e,t,n,r){return(i,a={})=>(typeof t!=`string`&&(a.parent={property:n,resource:t,atIndex:a?.parent?.atIndex}),e.create(r,i,a))}var j=class e{constructor(t,n){C(this,`resource`,void 0),C(this,`warnings`,[]),C(this,`errors`,[]),C(this,`partOf`,void 0),C(this,`references`,[]),C(this,`embedded`,[]),C(this,`vault`,void 0),C(this,`specificResource`,void 0),this.vault=n;let r={...t};if(r.type===`SpecificResource`){let e=r.source;this.specificResource={...r,source:{id:e.id,type:T(e.type)}},r=e}let i=Object.keys(r),a=D(r.type);for(let t of i)if(!(y.inlineProperties.includes(t)||!y.all.includes(t))){if(r.type===`Range`&&t===`items`){let e=[];for(let i of r[t]){if(i instanceof w){this.references.push(i),e.push(i);continue}let a=new w(i,n);e.push(a),r[t]=a}r[t]=e;continue}if(r.type===`Manifest`&&t===`start`){let e=r[t];if(e instanceof w){this.references.push(e);continue}r[t]=new w(e,n);continue}if(r.type===`Annotation`&&t===`target`){let e=r[t];if(e instanceof w){this.references.push(e);continue}typeof e==`string`&&(e={id:e,type:`Canvas`}),r[t]=new w(e,n);continue}if(!y.single.includes(t)&&(y.externalProperties.includes(t)||y.internalProperties.includes(t))){let i=r[t]||[],a=Array.isArray(i)?i:[i],o=[];for(let t of a){if(t instanceof w){this.references.push(t),o.push(t);continue}if(t instanceof e){this.embedded.push(t),o.push(t);continue}if(this.vault.get(t,{skipSelfReturn:!0})){let e=T(t.type),r=new w({id:t.id,type:e},n);this.references.push(r),o.push(r)}else{let r=new e(t,n);this.embedded.push(r),o.push(r)}}r[t]=o}}this.resource={...a,...r}}get(){return this.resource}getSpecificResource(){let e=this.ref();return _(e)?e:{type:`SpecificResource`,source:e}}ref(){return this.specificResource?this.specificResource:{id:this.resource.id,type:T(this.resource.type)}}getAllReferencedResources(){return this.references}getAllEmbeddedResources(){let e=[];for(let t of this.embedded)e.push(...t.getAllEmbeddedResources());return e.push(...this.embedded),e}getVaultResource(){let t=this.resource,n=Object.keys(t),r={};for(let i of n){if(y.inlineProperties.includes(i)||!y.all.includes(i)){r[i]=t[i];continue}if(y.single.includes(i)){let e=t[i];e instanceof w?t.type===`Manifest`&&i===`start`||t.type===`Annotation`&&i===`target`?r[i]=e.specificResource():r[i]=e.optionalSpecificResource():r[i]=t[i];continue}if(t[i]){r[i]=[];for(let n of t[i]||[]){if(t.type===`Range`&&i===`items`){n instanceof w&&(n.ref().type===`Canvas`?r[i].push(n.specificResource()):r[i].push(n.ref())),n instanceof e&&(n.ref().type===`Canvas`?r[i].push(n.getSpecificResource()):r[i].push(n.ref()));continue}n instanceof w&&r[i].push(n.optionalSpecificResource()),n instanceof e&&r[i].push(n.ref())}}}return this.partOf&&(r[s]=r[s]||[],r[s].push(this.partOf)),r}setPartOf(e){let t=this.ref();this.partOf={id:t.id,type:T(t.type),[c]:e}}},M=class{constructor(e,t,n,r){C(this,`vault`,void 0),C(this,`previewVault`,void 0),C(this,`configs`,void 0),C(this,`options`,void 0),C(this,`target`,void 0),C(this,`selector`,void 0),C(this,`serialisedSelector`,null),this.vault=e,this.previewVault=r,this.options=t,this.configs=n,this.target=this.options.target||this.options.parent?.resource;let i=this.options.initialData?.selector;this.selector=i?a(i):null,this.options.initialData?.getSerialisedSelector&&(this.serialisedSelector=this.options.initialData.getSerialisedSelector())}getPreviewVault(){return this.previewVault}setSelector(e){this.selector=e}getSerialisedSelector(){if(this.serialisedSelector)return this.serialisedSelector;let e=this.selector;if(e){let t=o(e,this.options.initialData?.on);if(t)return t}return null}getTarget(){let e=this.target,t=this.getSerialisedSelector();return t?{type:`SpecificResource`,source:e,selector:t}:e}getParent(){return this.options.parent?.resource}getParentResource(){let e=this.getParent();if(e)return{type:`SpecificResource`,source:e}}generateId(e,t){return t&&t instanceof w&&(t=t.ref()),this.options.rootId&&(t={id:this.options.rootId,type:`none`}),`${(t||this.options.parent?.resource)?.id}/${e}/${O()}`}ref(e){let t=``,n=``;return typeof e==`string`?t=e:(t=e.id,n=e.type),n=this.vault.getState().iiif.mapping[t]||n||`unknown`,new w({id:t,type:n},this.vault)}embed(e){return new j(e,this.vault)}async create(e,t,n){let r=this.configs.find(t=>t.id===e);if(!r)throw Error(`Creator config ${e} not found`);return await new N(this.vault,r,t,this.configs,this.previewVault,n).run()}},N=class{constructor(e,t,n,r,i,a){C(this,`resource`,null),C(this,`payload`,void 0),C(this,`vault`,void 0),C(this,`previewVault`,void 0),C(this,`definition`,void 0),C(this,`options`,void 0),C(this,`configs`,void 0),this.vault=e,this.previewVault=i,this.definition=t,this.payload=n,this.configs=this.filterCreateConfigs(r),this.options={targetType:a?.targetType||t.resourceType,...a||{}}}filterCreateConfigs(e){let t={};for(let n of e)t[n.id]=n;return Object.values(t)}async run(){let e=new M(this.vault,this.options,this.configs,this.previewVault),t=await this.definition.create(this.payload,e);if(Array.isArray(t)){let e=[];for(let n of t)n instanceof j?e.push(n):e.push(new j(n,this.vault));return this.resource=e,this.resource}return t instanceof j?this.resource=t:this.resource=new j(t,this.vault),this.resource}getActions(){if(!this.resource)return[];let e=Array.isArray(this.resource)?this.resource:[this.resource],n=[],r={},a={};for(let o of e){this.options.parent&&o.setPartOf(this.options.parent.resource.id);let e=[...o.getAllEmbeddedResources(),o];for(let t of e){let e=t.getVaultResource();if(!e.type||!e.id)continue;let n=T(e.type);r[n]=r[n]?r[n]:{},r[n][e.id]=e,a[e.id]=n}n.push(i({entities:r})),n.push(t({mapping:a}))}return n}commit(e=[]){if(!this.resource)throw Error(`Creator has not been run`);let t=this.getActions();return this.vault.dispatch(n({actions:[...t,...e]})),Array.isArray(this.resource)?this.resource.map(e=>e.ref()):this.resource.ref()}},P=class{constructor(t,n,r){C(this,`configs`,void 0),C(this,`vault`,void 0),C(this,`previewVault`,void 0),this.configs=n||[],this.vault=t,this.previewVault=r||new e}matchBasedOnResource(e){return k(e,this.configs||[],{vault:this.vault})}async create(e,t,n){let i=this.configs.find(t=>t.id===e);if(!i)throw Error(`Creator config ${e} not found`);if(n?.parent){if(i.supports.parentTypes&&!i.supports.parentTypes.includes(n.parent.resource.type))throw Error(`Definition ${e} does not support parent type ${n.parent.resource.type}`);if(i.supports.parentFields&&!i.supports.parentFields.includes(n.parent.property))throw Error(`Definition ${e} does not support parent field ${n.parent.property}`);if(i.supports.parentFieldMap){let t=i.supports.parentFieldMap[n.parent.resource.type];if(!t||!t.includes(n.parent.property))throw Error(`Definition ${e} does not support parent ${n.parent.property} / ${n.parent.property}`)}if(i.supports.custom&&!i.supports.custom(n.parent,this.vault))throw Error(`Definition does not support resource`)}let a=new N(this.vault,i,t,this.configs,this.previewVault,n),o=await a.run(),s=Array.isArray(o)?o:[o],c=[];for(let e of s)n?.parent&&(n.parent.property===`start`||n.parent.property===`target`?c.push(r.modifyEntityField({id:n.parent.resource.id,type:n.parent.resource.type,value:e.ref(),key:n.parent.property})):c.push(r.addReference({id:n.parent.resource.id,type:n.parent.resource.type,reference:e.ref(),key:n.parent.property,index:n.parent.atIndex})));let l=a.commit(c);if(n?.parent&&i.sideEffects){for(let e of i.sideEffects)if(e.run){let t=Array.isArray(l)?l:[l];for(let r of t)await e.run(r,{vault:this.vault,options:n})}}return l}};function F(e){return e}function I(e,t,n={}){let r=e.render?r=>{let i={...r,options:{...r.options||{},initialData:{...t||{},...r.options?.initialData||{},...n||{}}}};return e.render?.(i)}:void 0;return{...e,render:r}}function L(e,t){let n=n=>t(n,e.render);return{...e,render:n}}export{P as Creator,j as CreatorResource,A as creatorHelper,F as defineCreator,D as getEmptyType,k as matchBasedOnResource,O as randomId,T as resolveType,L as withCustomRender,I as withInitialData};
|
|
1
|
+
import{Vault as e}from"@iiif/helpers/vault";import{addMappings as t,batchActions as n,entityActions as r,importEntities as i}from"@iiif/helpers/vault/actions";import{annotationResponseToSelector as a,seraliseSupportedSelector as o}from"react-iiif-vault";import{HAS_PART as s,PART_OF as c,emptyAgent as l,emptyAnnotation as u,emptyAnnotationPage as d,emptyCanvas as f,emptyCollection as p,emptyManifest as m,emptyRange as h,emptyService as g,isSpecificResource as _,toRef as v}from"@iiif/parser";import{references as y}from"@manifest-editor/editor-api";function b(e){"@babel/helpers - typeof";return b=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},b(e)}function x(e,t){if(b(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(b(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function S(e){var t=x(e,`string`);return b(t)==`symbol`?t:t+``}function C(e,t,n){return(t=S(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var w=class{constructor(e,t){C(this,`vault`,void 0),C(this,`original`,void 0),C(this,`reference`,void 0),C(this,`resource`,void 0),this.vault=t,this.original=e,this.reference=_(e)?e.source:e,this.resource=_(e)?e:{type:`SpecificResource`,source:this.reference}}ref(){return this.reference}specificResource(){return this.resource}optionalSpecificResource(){return _(this.original)?{...this.original,source:{id:this.original.source?.id,type:this.original.source?.type}}:this.original}get(){return this.vault.get(this.resource)}};function T(e){return e.configKey??e.id}function E(e){switch(e){case`Image`:case`Video`:case`Sound`:case`Dataset`:case`Text`:case`TextualBody`:case`Composite`:case`List`:case`Choice`:case`Independents`:case`Audience`:return`ContentResource`;case`ImageService1`:case`ImageService2`:case`ImageService3`:return`Service`}return e}const D={Annotation:u,AnnotationPage:d,Canvas:f,Collection:p,Manifest:m,Range:h,ResourceProvider:l,Service:g};function O(e){let t=E(e);return D[t]||{}}function k(){return`${Math.random().toString(36).substring(2)}-${Date.now().toString(36)}`}function A(e,t,n){let r=[];if(t.length===0)return[];let i=v(e.parent),a=e.property,o=e.filter;for(let s of t)if(!(o&&(!s.tags||!s.tags.includes(o)))&&i&&a){if(s.supports.parentTypes&&!s.supports.parentTypes.includes(i.type)||s.supports.parentFields&&!s.supports.parentFields.includes(a))continue;if(s.supports.parentFieldMap){let e=s.supports.parentFieldMap[i.type];if(!e||!e.includes(a))continue}if(s.supports.disallowPainting&&e.isPainting||s.supports.onlyPainting&&!e.isPainting||s.supports.custom&&!s.supports.custom({property:a,resource:i,atIndex:e.index},n.vault))continue;let t=Object.keys(e.initialData||{}).filter(e=>e!==`skipEditingOnCreate`);if(!s.supports.initialData&&t.length!==0||s.resourceType!==e.type&&!(s.additionalTypes||[]).includes(e.type))continue;r.push(s)}return r}function j(e,t,n,r){return(i,a={})=>(typeof t!=`string`&&(a.parent={property:n,resource:t,atIndex:a?.parent?.atIndex}),e.create(r,i,a))}var M=class e{constructor(t,n){C(this,`resource`,void 0),C(this,`warnings`,[]),C(this,`errors`,[]),C(this,`partOf`,void 0),C(this,`references`,[]),C(this,`embedded`,[]),C(this,`vault`,void 0),C(this,`specificResource`,void 0),this.vault=n;let r={...t};if(r.type===`SpecificResource`){let e=r.source;this.specificResource={...r,source:{id:e.id,type:E(e.type)}},r=e}let i=Object.keys(r),a=O(r.type);for(let t of i)if(!(y.inlineProperties.includes(t)||!y.all.includes(t))){if(r.type===`Range`&&t===`items`){let e=[];for(let i of r[t]){if(i instanceof w){this.references.push(i),e.push(i);continue}let a=new w(i,n);e.push(a),r[t]=a}r[t]=e;continue}if(r.type===`Manifest`&&t===`start`){let e=r[t];if(e instanceof w){this.references.push(e);continue}let i=new w(e,n);r[t]=i;continue}if(r.type===`Annotation`&&t===`target`){let e=r[t];if(e instanceof w){this.references.push(e);continue}typeof e==`string`&&(e={id:e,type:`Canvas`});let i=new w(e,n);r[t]=i;continue}if(!y.single.includes(t)&&(y.externalProperties.includes(t)||y.internalProperties.includes(t))){let i=r[t]||[],a=Array.isArray(i)?i:[i],o=[];for(let t of a){if(t instanceof w){this.references.push(t),o.push(t);continue}if(t instanceof e){this.embedded.push(t),o.push(t);continue}if(_(t)){let r=new e(t,n);this.embedded.push(r),o.push(r);continue}if(this.vault.get(t,{skipSelfReturn:!0})){let e=E(t.type),r=new w({id:t.id,type:e},n);this.references.push(r),o.push(r)}else{let r=new e(t,n);this.embedded.push(r),o.push(r)}}r[t]=o}}this.resource={...a,...r}}get(){return this.resource}getSpecificResource(){let e=this.ref();return _(e)?e:{type:`SpecificResource`,source:e}}ref(){return this.specificResource?this.specificResource:{id:this.resource.id,type:E(this.resource.type)}}getAllReferencedResources(){return this.references}getAllEmbeddedResources(){let e=[];for(let t of this.embedded)e.push(...t.getAllEmbeddedResources());return e.push(...this.embedded),e}getVaultResource(){let t=this.resource,n=Object.keys(t),r={};for(let i of n){if(y.inlineProperties.includes(i)||!y.all.includes(i)){r[i]=t[i];continue}if(y.single.includes(i)){let e=t[i];r[i]=e instanceof w?t.type===`Manifest`&&i===`start`||t.type===`Annotation`&&i===`target`?e.specificResource():e.optionalSpecificResource():t[i];continue}if(t[i]){r[i]=[];for(let n of t[i]||[]){if(t.type===`Range`&&i===`items`){n instanceof w&&(n.ref().type===`Canvas`?r[i].push(n.specificResource()):r[i].push(n.ref())),n instanceof e&&(n.ref().type===`Canvas`?r[i].push(n.getSpecificResource()):r[i].push(n.ref()));continue}n instanceof w&&r[i].push(n.optionalSpecificResource()),n instanceof e&&r[i].push(n.ref())}}}return this.partOf&&(r[s]=r[s]||[],r[s].push(this.partOf)),r}setPartOf(e){let t=this.ref();this.partOf={id:t.id,type:E(t.type),[c]:e}}},N=class{constructor(e,t,n,r,i,o={}){C(this,`vault`,void 0),C(this,`previewVault`,void 0),C(this,`configs`,void 0),C(this,`options`,void 0),C(this,`config`,void 0),C(this,`creatorConfig`,void 0),C(this,`target`,void 0),C(this,`selector`,void 0),C(this,`serialisedSelector`,null),this.vault=e,this.previewVault=r,this.options=t,this.configs=n,this.creatorConfig=o,this.config=o[i]||{},this.target=this.options.target||this.options.parent?.resource;let s=this.options.initialData?.selector;this.selector=s?a(s):null,this.options.initialData?.getSerialisedSelector&&(this.serialisedSelector=this.options.initialData.getSerialisedSelector())}getPreviewVault(){return this.previewVault}setSelector(e){this.selector=e}getSerialisedSelector(){if(this.serialisedSelector)return this.serialisedSelector;let e=this.selector;if(e){let t=o(e,this.options.initialData?.on);if(t)return t}return null}getTarget(){let e=this.target,t=this.getSerialisedSelector();return t?{type:`SpecificResource`,source:e,selector:t}:e}getParent(){return this.options.parent?.resource}getParentResource(){let e=this.getParent();if(e)return{type:`SpecificResource`,source:e}}generateId(e,t){return t&&t instanceof w&&(t=t.ref()),this.options.rootId&&(t={id:this.options.rootId,type:`none`}),`${(t||this.options.parent?.resource)?.id}/${e}/${k()}`}ref(e){let t=``,n=``;return typeof e==`string`?t=e:(t=e.id,n=e.type),n=this.vault.getState().iiif.mapping[t]||n||`unknown`,new w({id:t,type:n},this.vault)}embed(e){return new M(e,this.vault)}async create(e,t,n){let r=this.configs.find(t=>t.id===e);if(!r)throw Error(`Creator config ${e} not found`);return await new P(this.vault,r,t,this.configs,this.previewVault,n,this.creatorConfig).run()}},P=class{constructor(e,t,n,r,i,a,o){C(this,`resource`,null),C(this,`payload`,void 0),C(this,`vault`,void 0),C(this,`previewVault`,void 0),C(this,`definition`,void 0),C(this,`options`,void 0),C(this,`configs`,void 0),C(this,`creatorConfig`,void 0),this.vault=e,this.previewVault=i,this.definition=t,this.payload=n,this.configs=this.filterCreateConfigs(r),this.creatorConfig=o||{},this.options={targetType:a?.targetType||t.resourceType,...a||{}}}filterCreateConfigs(e){let t={};for(let n of e)t[n.id]=n;return Object.values(t)}async run(){let e=new N(this.vault,this.options,this.configs,this.previewVault,T(this.definition),this.creatorConfig),t=await this.definition.create(this.payload,e);if(Array.isArray(t)){let e=[];for(let n of t)n instanceof M?e.push(n):e.push(new M(n,this.vault));return this.resource=e,this.resource}return this.resource=t instanceof M?t:new M(t,this.vault),this.resource}getActions(){if(!this.resource)return[];let e=Array.isArray(this.resource)?this.resource:[this.resource],n=[],r={},a={};for(let o of e){this.options.parent&&o.setPartOf(this.options.parent.resource.id);let e=[...o.getAllEmbeddedResources(),o];for(let t of e){let e=t.getVaultResource();if(!e.type||!e.id)continue;let n=E(e.type);r[n]=r[n]?r[n]:{},r[n][e.id]=e,a[e.id]=n}n.push(i({entities:r})),n.push(t({mapping:a}))}return n}commit(e=[]){if(!this.resource)throw Error(`Creator has not been run`);let t=this.getActions();return this.vault.dispatch(n({actions:[...t,...e]})),Array.isArray(this.resource)?this.resource.map(e=>e.ref()):this.resource.ref()}},F=class{constructor(t,n,r,i){C(this,`configs`,void 0),C(this,`vault`,void 0),C(this,`previewVault`,void 0),C(this,`creatorConfig`,void 0),this.configs=n||[],this.vault=t,this.previewVault=r||new e,this.creatorConfig=i||{}}matchBasedOnResource(e){return A(e,this.configs||[],{vault:this.vault})}async create(e,t,n){let i=this.configs.find(t=>t.id===e);if(!i)throw Error(`Creator config ${e} not found`);if(n?.parent){if(i.supports.parentTypes&&!i.supports.parentTypes.includes(n.parent.resource.type))throw Error(`Definition ${e} does not support parent type ${n.parent.resource.type}`);if(i.supports.parentFields&&!i.supports.parentFields.includes(n.parent.property))throw Error(`Definition ${e} does not support parent field ${n.parent.property}`);if(i.supports.parentFieldMap){let t=i.supports.parentFieldMap[n.parent.resource.type];if(!t||!t.includes(n.parent.property))throw Error(`Definition ${e} does not support parent ${n.parent.property} / ${n.parent.property}`)}if(i.supports.custom&&!i.supports.custom(n.parent,this.vault))throw Error(`Definition does not support resource`)}let a=new P(this.vault,i,t,this.configs,this.previewVault,n,this.creatorConfig),o=await a.run(),s=Array.isArray(o)?o:[o],c=[];for(let e of s)n?.parent&&(n.parent.property===`start`||n.parent.property===`target`?c.push(r.modifyEntityField({id:n.parent.resource.id,type:n.parent.resource.type,value:e.ref(),key:n.parent.property})):c.push(r.addReference({id:n.parent.resource.id,type:n.parent.resource.type,reference:e.ref(),key:n.parent.property,index:n.parent.atIndex})));let l=a.commit(c);if(n?.parent&&i.sideEffects){for(let e of i.sideEffects)if(e.run){let t=Array.isArray(l)?l:[l];for(let r of t)await e.run(r,{vault:this.vault,options:n})}}return l}};function I(e){return e}function L(e,t,n={}){let r=e.render?r=>{let i={...r,options:{...r.options||{},initialData:{...t||{},...r.options?.initialData||{},...n||{}}}};return e.render?.(i)}:void 0;return{...e,render:r}}function R(e,t){let n=n=>t(n,e.render);return{...e,render:n}}export{F as Creator,M as CreatorResource,j as creatorHelper,I as defineCreator,T as getCreatorConfigKey,O as getEmptyType,A as matchBasedOnResource,k as randomId,E as resolveType,R as withCustomRender,L as withInitialData};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|