@manifest-editor/creator-api 1.2.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -26,7 +26,11 @@ var __publicField = (obj, key, value) => {
26
26
  var src_exports = {};
27
27
  __export(src_exports, {
28
28
  Creator: () => Creator,
29
- CreatorResource: () => CreatorResource
29
+ CreatorResource: () => CreatorResource,
30
+ getEmptyType: () => getEmptyType,
31
+ matchBasedOnResource: () => matchBasedOnResource,
32
+ randomId: () => randomId,
33
+ resolveType: () => resolveType
30
34
  });
31
35
  module.exports = __toCommonJS(src_exports);
32
36
 
@@ -112,6 +116,64 @@ function getEmptyType(type) {
112
116
  function randomId() {
113
117
  return `${Math.random().toString(36).substr(2)}-${Date.now().toString(36)}`;
114
118
  }
119
+ function matchBasedOnResource(resource, list, options) {
120
+ const supported = [];
121
+ if (list.length === 0) {
122
+ return [];
123
+ }
124
+ const parent = (0, import_parser2.toRef)(resource.parent);
125
+ const property = resource.property;
126
+ const filter = resource.filter;
127
+ for (const def of list) {
128
+ if (filter) {
129
+ if (!def.tags)
130
+ continue;
131
+ if (!def.tags.includes(filter)) {
132
+ continue;
133
+ }
134
+ }
135
+ if (parent && property) {
136
+ if (def.supports.parentTypes) {
137
+ if (!def.supports.parentTypes.includes(parent.type)) {
138
+ continue;
139
+ }
140
+ }
141
+ if (def.supports.parentFields) {
142
+ if (!def.supports.parentFields.includes(property)) {
143
+ continue;
144
+ }
145
+ }
146
+ if (def.supports.parentFieldMap) {
147
+ const type = def.supports.parentFieldMap[parent.type];
148
+ if (!type || !type.includes(property)) {
149
+ continue;
150
+ }
151
+ }
152
+ if (def.supports.disallowPainting && resource.isPainting) {
153
+ continue;
154
+ }
155
+ if (def.supports.custom) {
156
+ const isValid = def.supports.custom(
157
+ { property, resource: parent, atIndex: resource.index },
158
+ options.vault
159
+ );
160
+ if (!isValid) {
161
+ continue;
162
+ }
163
+ }
164
+ if (!def.supports.initialData && Object.keys(resource.initialData || {}).length !== 0) {
165
+ continue;
166
+ }
167
+ if (def.resourceType !== resource.type) {
168
+ if (!(def.additionalTypes || []).includes(resource.type)) {
169
+ continue;
170
+ }
171
+ }
172
+ supported.push(def);
173
+ }
174
+ }
175
+ return supported;
176
+ }
115
177
 
116
178
  // src/CreatorResource.ts
117
179
  var import_parser3 = require("@iiif/parser");
@@ -486,6 +548,13 @@ var Creator = class {
486
548
  this.vault = vault;
487
549
  this.previewVault = previewVault || new import_vault.Vault();
488
550
  }
551
+ matchBasedOnResource(resource) {
552
+ return matchBasedOnResource(
553
+ resource,
554
+ this.configs || [],
555
+ { vault: this.vault }
556
+ );
557
+ }
489
558
  async create(definition, payload, options) {
490
559
  const foundDefinition = this.configs.find((t) => t.id === definition);
491
560
  if (!foundDefinition) {
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _iiif_presentation_3 from '@iiif/presentation-3';
2
2
  import { Reference, SpecificResource } from '@iiif/presentation-3';
3
- import { Vault } from '@iiif/helpers/vault';
3
+ import { Vault, Entities } from '@iiif/helpers/vault';
4
4
  import { ReactNode } from 'react';
5
5
 
6
6
  declare class ReferencedResource {
@@ -19,22 +19,22 @@ declare class ReferencedResource {
19
19
  modified?: string | undefined;
20
20
  creator?: _iiif_presentation_3.Creator | undefined;
21
21
  generator?: _iiif_presentation_3.Creator | undefined;
22
- audience?: _iiif_presentation_3.Audience | _iiif_presentation_3.Audience[] | undefined;
22
+ audience?: (_iiif_presentation_3.Audience | _iiif_presentation_3.Audience[]) | undefined;
23
23
  accessibility?: string | string[] | undefined;
24
- motivation?: _iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[] | undefined;
24
+ motivation?: (_iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[]) | undefined;
25
25
  rights?: string | string[] | undefined;
26
26
  canonical?: string | undefined;
27
27
  via?: string | string[] | undefined;
28
28
  role?: string | undefined;
29
29
  id?: string | undefined;
30
30
  type: "SpecificResource";
31
- state?: _iiif_presentation_3.State | _iiif_presentation_3.State[] | undefined;
32
- purpose?: _iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[] | undefined;
31
+ state?: (_iiif_presentation_3.State | _iiif_presentation_3.State[]) | undefined;
32
+ purpose?: (_iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[]) | undefined;
33
33
  source?: any;
34
- selector?: _iiif_presentation_3.Selector | _iiif_presentation_3.Selector[] | undefined;
34
+ selector?: (_iiif_presentation_3.Selector | _iiif_presentation_3.Selector[]) | undefined;
35
35
  styleClass?: string | undefined;
36
- renderedVia?: _iiif_presentation_3.Agent | _iiif_presentation_3.Agent[] | undefined;
37
- scope?: any;
36
+ renderedVia?: (_iiif_presentation_3.Agent | _iiif_presentation_3.Agent[]) | undefined;
37
+ scope?: _iiif_presentation_3.LinkedResource;
38
38
  };
39
39
  optionalSpecificResource(): {
40
40
  type: string;
@@ -49,21 +49,21 @@ declare class ReferencedResource {
49
49
  modified?: string | undefined;
50
50
  creator?: _iiif_presentation_3.Creator | undefined;
51
51
  generator?: _iiif_presentation_3.Creator | undefined;
52
- audience?: _iiif_presentation_3.Audience | _iiif_presentation_3.Audience[] | undefined;
52
+ audience?: (_iiif_presentation_3.Audience | _iiif_presentation_3.Audience[]) | undefined;
53
53
  accessibility?: string | string[] | undefined;
54
- motivation?: _iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[] | undefined;
54
+ motivation?: (_iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[]) | undefined;
55
55
  rights?: string | string[] | undefined;
56
56
  canonical?: string | undefined;
57
57
  via?: string | string[] | undefined;
58
58
  role?: string | undefined;
59
59
  id?: string | undefined;
60
60
  type: "SpecificResource";
61
- state?: _iiif_presentation_3.State | _iiif_presentation_3.State[] | undefined;
62
- purpose?: _iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[] | undefined;
63
- selector?: _iiif_presentation_3.Selector | _iiif_presentation_3.Selector[] | undefined;
61
+ state?: (_iiif_presentation_3.State | _iiif_presentation_3.State[]) | undefined;
62
+ purpose?: (_iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[]) | undefined;
63
+ selector?: (_iiif_presentation_3.Selector | _iiif_presentation_3.Selector[]) | undefined;
64
64
  styleClass?: string | undefined;
65
- renderedVia?: _iiif_presentation_3.Agent | _iiif_presentation_3.Agent[] | undefined;
66
- scope?: any;
65
+ renderedVia?: (_iiif_presentation_3.Agent | _iiif_presentation_3.Agent[]) | undefined;
66
+ scope?: _iiif_presentation_3.LinkedResource;
67
67
  };
68
68
  get(): any;
69
69
  }
@@ -85,22 +85,22 @@ declare class CreatorResource {
85
85
  modified?: string | undefined;
86
86
  creator?: _iiif_presentation_3.Creator | undefined;
87
87
  generator?: _iiif_presentation_3.Creator | undefined;
88
- audience?: _iiif_presentation_3.Audience | _iiif_presentation_3.Audience[] | undefined;
88
+ audience?: (_iiif_presentation_3.Audience | _iiif_presentation_3.Audience[]) | undefined;
89
89
  accessibility?: string | string[] | undefined;
90
- motivation?: _iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[] | undefined;
90
+ motivation?: (_iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[]) | undefined;
91
91
  rights?: string | string[] | undefined;
92
92
  canonical?: string | undefined;
93
93
  via?: string | string[] | undefined;
94
94
  role?: string | undefined;
95
95
  id?: string | undefined;
96
96
  type: "SpecificResource";
97
- state?: _iiif_presentation_3.State | _iiif_presentation_3.State[] | undefined;
98
- purpose?: _iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[] | undefined;
97
+ state?: (_iiif_presentation_3.State | _iiif_presentation_3.State[]) | undefined;
98
+ purpose?: (_iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[]) | undefined;
99
99
  source?: any;
100
- selector?: _iiif_presentation_3.Selector | _iiif_presentation_3.Selector[] | undefined;
100
+ selector?: (_iiif_presentation_3.Selector | _iiif_presentation_3.Selector[]) | undefined;
101
101
  styleClass?: string | undefined;
102
- renderedVia?: _iiif_presentation_3.Agent | _iiif_presentation_3.Agent[] | undefined;
103
- scope?: any;
102
+ renderedVia?: (_iiif_presentation_3.Agent | _iiif_presentation_3.Agent[]) | undefined;
103
+ scope?: _iiif_presentation_3.LinkedResource;
104
104
  } | {
105
105
  id: any;
106
106
  type: any;
@@ -138,12 +138,14 @@ interface CreatorFunctionContext {
138
138
  ref(idOrRef: string | Reference): ReferencedResource;
139
139
  embed(data: any): CreatorResource;
140
140
  create(definition: string, payload: any, options?: Partial<CreatorOptions>): Promise<CreatorResource>;
141
+ create<Definition extends CreatorDefinition = any>(definition: Definition["id"], payload: GetCreatorPayload<Definition>, options?: Partial<CreatorOptions>): Promise<CreatorResource>;
141
142
  generateId(type: string, parent?: Reference | ReferencedResource): string;
142
143
  getParent(): Reference | undefined;
143
144
  getTarget(): SpecificResource | Reference | undefined;
144
145
  getParentResource(): SpecificResource | undefined;
145
146
  getPreviewVault(): Vault;
146
147
  }
148
+ type GetCreatorPayload<T extends CreatorDefinition> = T extends CreatorDefinition<infer Payload> ? Payload : never;
147
149
  interface CreatorParent {
148
150
  resource: Reference;
149
151
  property: string;
@@ -155,23 +157,25 @@ interface CreatorOptions {
155
157
  parent?: CreatorParent;
156
158
  initialData?: any;
157
159
  }
158
- interface CreatorDefinition {
160
+ interface CreatorDefinition<Payload = any> {
159
161
  id: string;
160
162
  label: string;
161
163
  summary?: string;
162
164
  icon?: any;
163
165
  dependencies?: string[];
164
- create: (payload: any, ctx: CreatorInstance) => any | Promise<any>;
165
- validate?: (payload: any, vault: Vault) => void | Promise<void>;
166
- render?: (ctx: CreatorContext) => ReactNode;
167
- renderCanvas?: (ctx: CreatorContext) => ReactNode | null;
168
- renderModal?: (ctx: CreatorContext) => ReactNode;
166
+ tags?: string[];
167
+ create: (payload: Payload, ctx: CreatorInstance) => any | Promise<any>;
168
+ validate?: (payload: Payload, vault: Vault) => void | Promise<void>;
169
+ render?: (ctx: CreatorContext<Payload>) => ReactNode;
170
+ renderCanvas?: (ctx: CreatorContext<Payload>) => ReactNode | null;
171
+ renderModal?: (ctx: CreatorContext<Payload>) => ReactNode;
169
172
  resourceType: string;
170
173
  additionalTypes?: string[];
171
174
  resourceFields: string[];
172
175
  embeddedResources?: string[];
173
176
  staticFields?: Record<string, any>;
174
177
  allowModal?: boolean;
178
+ hiddenModal?: boolean;
175
179
  supports: {
176
180
  initialData?: boolean;
177
181
  parentTypes?: string[];
@@ -192,13 +196,33 @@ interface CreatorSideEffect {
192
196
  replaceSiblings?: boolean;
193
197
  canvasInteraction?: boolean;
194
198
  }
199
+ interface CreatableResource {
200
+ type: string;
201
+ parent?: Reference;
202
+ property?: string;
203
+ index?: number;
204
+ onlyReference?: boolean;
205
+ target?: Reference;
206
+ initialData?: any;
207
+ isPainting?: boolean;
208
+ filter?: string;
209
+ initialCreator?: string;
210
+ }
195
211
 
196
212
  declare class Creator {
197
213
  configs: CreatorDefinition[];
198
214
  vault: Vault;
199
215
  previewVault: Vault;
200
216
  constructor(vault: Vault, configs: CreatorDefinition[], previewVault?: Vault);
217
+ matchBasedOnResource(resource: CreatableResource): CreatorDefinition<any>[];
201
218
  create(definition: string, payload: any, options?: Partial<CreatorOptions>): Promise<Reference>;
202
219
  }
203
220
 
204
- export { Creator, type CreatorContext, type CreatorDefinition, type CreatorFunctionContext, type CreatorOptions, CreatorResource, type CreatorSideEffect };
221
+ declare function resolveType(type: string): keyof Entities;
222
+ declare function getEmptyType(type: string): any;
223
+ declare function randomId(): string;
224
+ declare function matchBasedOnResource(resource: CreatableResource, list: CreatorDefinition[], options: {
225
+ vault: Vault;
226
+ }): CreatorDefinition[];
227
+
228
+ export { type CreatableResource, Creator, type CreatorContext, type CreatorDefinition, type CreatorFunctionContext, type CreatorOptions, CreatorResource, type CreatorSideEffect, type GetCreatorPayload, getEmptyType, matchBasedOnResource, randomId, resolveType };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _iiif_presentation_3 from '@iiif/presentation-3';
2
2
  import { Reference, SpecificResource } from '@iiif/presentation-3';
3
- import { Vault } from '@iiif/helpers/vault';
3
+ import { Vault, Entities } from '@iiif/helpers/vault';
4
4
  import { ReactNode } from 'react';
5
5
 
6
6
  declare class ReferencedResource {
@@ -19,22 +19,22 @@ declare class ReferencedResource {
19
19
  modified?: string | undefined;
20
20
  creator?: _iiif_presentation_3.Creator | undefined;
21
21
  generator?: _iiif_presentation_3.Creator | undefined;
22
- audience?: _iiif_presentation_3.Audience | _iiif_presentation_3.Audience[] | undefined;
22
+ audience?: (_iiif_presentation_3.Audience | _iiif_presentation_3.Audience[]) | undefined;
23
23
  accessibility?: string | string[] | undefined;
24
- motivation?: _iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[] | undefined;
24
+ motivation?: (_iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[]) | undefined;
25
25
  rights?: string | string[] | undefined;
26
26
  canonical?: string | undefined;
27
27
  via?: string | string[] | undefined;
28
28
  role?: string | undefined;
29
29
  id?: string | undefined;
30
30
  type: "SpecificResource";
31
- state?: _iiif_presentation_3.State | _iiif_presentation_3.State[] | undefined;
32
- purpose?: _iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[] | undefined;
31
+ state?: (_iiif_presentation_3.State | _iiif_presentation_3.State[]) | undefined;
32
+ purpose?: (_iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[]) | undefined;
33
33
  source?: any;
34
- selector?: _iiif_presentation_3.Selector | _iiif_presentation_3.Selector[] | undefined;
34
+ selector?: (_iiif_presentation_3.Selector | _iiif_presentation_3.Selector[]) | undefined;
35
35
  styleClass?: string | undefined;
36
- renderedVia?: _iiif_presentation_3.Agent | _iiif_presentation_3.Agent[] | undefined;
37
- scope?: any;
36
+ renderedVia?: (_iiif_presentation_3.Agent | _iiif_presentation_3.Agent[]) | undefined;
37
+ scope?: _iiif_presentation_3.LinkedResource;
38
38
  };
39
39
  optionalSpecificResource(): {
40
40
  type: string;
@@ -49,21 +49,21 @@ declare class ReferencedResource {
49
49
  modified?: string | undefined;
50
50
  creator?: _iiif_presentation_3.Creator | undefined;
51
51
  generator?: _iiif_presentation_3.Creator | undefined;
52
- audience?: _iiif_presentation_3.Audience | _iiif_presentation_3.Audience[] | undefined;
52
+ audience?: (_iiif_presentation_3.Audience | _iiif_presentation_3.Audience[]) | undefined;
53
53
  accessibility?: string | string[] | undefined;
54
- motivation?: _iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[] | undefined;
54
+ motivation?: (_iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[]) | undefined;
55
55
  rights?: string | string[] | undefined;
56
56
  canonical?: string | undefined;
57
57
  via?: string | string[] | undefined;
58
58
  role?: string | undefined;
59
59
  id?: string | undefined;
60
60
  type: "SpecificResource";
61
- state?: _iiif_presentation_3.State | _iiif_presentation_3.State[] | undefined;
62
- purpose?: _iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[] | undefined;
63
- selector?: _iiif_presentation_3.Selector | _iiif_presentation_3.Selector[] | undefined;
61
+ state?: (_iiif_presentation_3.State | _iiif_presentation_3.State[]) | undefined;
62
+ purpose?: (_iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[]) | undefined;
63
+ selector?: (_iiif_presentation_3.Selector | _iiif_presentation_3.Selector[]) | undefined;
64
64
  styleClass?: string | undefined;
65
- renderedVia?: _iiif_presentation_3.Agent | _iiif_presentation_3.Agent[] | undefined;
66
- scope?: any;
65
+ renderedVia?: (_iiif_presentation_3.Agent | _iiif_presentation_3.Agent[]) | undefined;
66
+ scope?: _iiif_presentation_3.LinkedResource;
67
67
  };
68
68
  get(): any;
69
69
  }
@@ -85,22 +85,22 @@ declare class CreatorResource {
85
85
  modified?: string | undefined;
86
86
  creator?: _iiif_presentation_3.Creator | undefined;
87
87
  generator?: _iiif_presentation_3.Creator | undefined;
88
- audience?: _iiif_presentation_3.Audience | _iiif_presentation_3.Audience[] | undefined;
88
+ audience?: (_iiif_presentation_3.Audience | _iiif_presentation_3.Audience[]) | undefined;
89
89
  accessibility?: string | string[] | undefined;
90
- motivation?: _iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[] | undefined;
90
+ motivation?: (_iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[]) | undefined;
91
91
  rights?: string | string[] | undefined;
92
92
  canonical?: string | undefined;
93
93
  via?: string | string[] | undefined;
94
94
  role?: string | undefined;
95
95
  id?: string | undefined;
96
96
  type: "SpecificResource";
97
- state?: _iiif_presentation_3.State | _iiif_presentation_3.State[] | undefined;
98
- purpose?: _iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[] | undefined;
97
+ state?: (_iiif_presentation_3.State | _iiif_presentation_3.State[]) | undefined;
98
+ purpose?: (_iiif_presentation_3.AnyMotivation | _iiif_presentation_3.AnyMotivation[]) | undefined;
99
99
  source?: any;
100
- selector?: _iiif_presentation_3.Selector | _iiif_presentation_3.Selector[] | undefined;
100
+ selector?: (_iiif_presentation_3.Selector | _iiif_presentation_3.Selector[]) | undefined;
101
101
  styleClass?: string | undefined;
102
- renderedVia?: _iiif_presentation_3.Agent | _iiif_presentation_3.Agent[] | undefined;
103
- scope?: any;
102
+ renderedVia?: (_iiif_presentation_3.Agent | _iiif_presentation_3.Agent[]) | undefined;
103
+ scope?: _iiif_presentation_3.LinkedResource;
104
104
  } | {
105
105
  id: any;
106
106
  type: any;
@@ -138,12 +138,14 @@ interface CreatorFunctionContext {
138
138
  ref(idOrRef: string | Reference): ReferencedResource;
139
139
  embed(data: any): CreatorResource;
140
140
  create(definition: string, payload: any, options?: Partial<CreatorOptions>): Promise<CreatorResource>;
141
+ create<Definition extends CreatorDefinition = any>(definition: Definition["id"], payload: GetCreatorPayload<Definition>, options?: Partial<CreatorOptions>): Promise<CreatorResource>;
141
142
  generateId(type: string, parent?: Reference | ReferencedResource): string;
142
143
  getParent(): Reference | undefined;
143
144
  getTarget(): SpecificResource | Reference | undefined;
144
145
  getParentResource(): SpecificResource | undefined;
145
146
  getPreviewVault(): Vault;
146
147
  }
148
+ type GetCreatorPayload<T extends CreatorDefinition> = T extends CreatorDefinition<infer Payload> ? Payload : never;
147
149
  interface CreatorParent {
148
150
  resource: Reference;
149
151
  property: string;
@@ -155,23 +157,25 @@ interface CreatorOptions {
155
157
  parent?: CreatorParent;
156
158
  initialData?: any;
157
159
  }
158
- interface CreatorDefinition {
160
+ interface CreatorDefinition<Payload = any> {
159
161
  id: string;
160
162
  label: string;
161
163
  summary?: string;
162
164
  icon?: any;
163
165
  dependencies?: string[];
164
- create: (payload: any, ctx: CreatorInstance) => any | Promise<any>;
165
- validate?: (payload: any, vault: Vault) => void | Promise<void>;
166
- render?: (ctx: CreatorContext) => ReactNode;
167
- renderCanvas?: (ctx: CreatorContext) => ReactNode | null;
168
- renderModal?: (ctx: CreatorContext) => ReactNode;
166
+ tags?: string[];
167
+ create: (payload: Payload, ctx: CreatorInstance) => any | Promise<any>;
168
+ validate?: (payload: Payload, vault: Vault) => void | Promise<void>;
169
+ render?: (ctx: CreatorContext<Payload>) => ReactNode;
170
+ renderCanvas?: (ctx: CreatorContext<Payload>) => ReactNode | null;
171
+ renderModal?: (ctx: CreatorContext<Payload>) => ReactNode;
169
172
  resourceType: string;
170
173
  additionalTypes?: string[];
171
174
  resourceFields: string[];
172
175
  embeddedResources?: string[];
173
176
  staticFields?: Record<string, any>;
174
177
  allowModal?: boolean;
178
+ hiddenModal?: boolean;
175
179
  supports: {
176
180
  initialData?: boolean;
177
181
  parentTypes?: string[];
@@ -192,13 +196,33 @@ interface CreatorSideEffect {
192
196
  replaceSiblings?: boolean;
193
197
  canvasInteraction?: boolean;
194
198
  }
199
+ interface CreatableResource {
200
+ type: string;
201
+ parent?: Reference;
202
+ property?: string;
203
+ index?: number;
204
+ onlyReference?: boolean;
205
+ target?: Reference;
206
+ initialData?: any;
207
+ isPainting?: boolean;
208
+ filter?: string;
209
+ initialCreator?: string;
210
+ }
195
211
 
196
212
  declare class Creator {
197
213
  configs: CreatorDefinition[];
198
214
  vault: Vault;
199
215
  previewVault: Vault;
200
216
  constructor(vault: Vault, configs: CreatorDefinition[], previewVault?: Vault);
217
+ matchBasedOnResource(resource: CreatableResource): CreatorDefinition<any>[];
201
218
  create(definition: string, payload: any, options?: Partial<CreatorOptions>): Promise<Reference>;
202
219
  }
203
220
 
204
- export { Creator, type CreatorContext, type CreatorDefinition, type CreatorFunctionContext, type CreatorOptions, CreatorResource, type CreatorSideEffect };
221
+ declare function resolveType(type: string): keyof Entities;
222
+ declare function getEmptyType(type: string): any;
223
+ declare function randomId(): string;
224
+ declare function matchBasedOnResource(resource: CreatableResource, list: CreatorDefinition[], options: {
225
+ vault: Vault;
226
+ }): CreatorDefinition[];
227
+
228
+ export { type CreatableResource, Creator, type CreatorContext, type CreatorDefinition, type CreatorFunctionContext, type CreatorOptions, CreatorResource, type CreatorSideEffect, type GetCreatorPayload, getEmptyType, matchBasedOnResource, randomId, resolveType };
package/dist/index.js CHANGED
@@ -57,7 +57,8 @@ import {
57
57
  emptyCollection,
58
58
  emptyManifest,
59
59
  emptyRange,
60
- emptyService
60
+ emptyService,
61
+ toRef
61
62
  } from "@iiif/parser";
62
63
  function resolveType(type) {
63
64
  switch (type) {
@@ -96,6 +97,64 @@ function getEmptyType(type) {
96
97
  function randomId() {
97
98
  return `${Math.random().toString(36).substr(2)}-${Date.now().toString(36)}`;
98
99
  }
100
+ function matchBasedOnResource(resource, list, options) {
101
+ const supported = [];
102
+ if (list.length === 0) {
103
+ return [];
104
+ }
105
+ const parent = toRef(resource.parent);
106
+ const property = resource.property;
107
+ const filter = resource.filter;
108
+ for (const def of list) {
109
+ if (filter) {
110
+ if (!def.tags)
111
+ continue;
112
+ if (!def.tags.includes(filter)) {
113
+ continue;
114
+ }
115
+ }
116
+ if (parent && property) {
117
+ if (def.supports.parentTypes) {
118
+ if (!def.supports.parentTypes.includes(parent.type)) {
119
+ continue;
120
+ }
121
+ }
122
+ if (def.supports.parentFields) {
123
+ if (!def.supports.parentFields.includes(property)) {
124
+ continue;
125
+ }
126
+ }
127
+ if (def.supports.parentFieldMap) {
128
+ const type = def.supports.parentFieldMap[parent.type];
129
+ if (!type || !type.includes(property)) {
130
+ continue;
131
+ }
132
+ }
133
+ if (def.supports.disallowPainting && resource.isPainting) {
134
+ continue;
135
+ }
136
+ if (def.supports.custom) {
137
+ const isValid = def.supports.custom(
138
+ { property, resource: parent, atIndex: resource.index },
139
+ options.vault
140
+ );
141
+ if (!isValid) {
142
+ continue;
143
+ }
144
+ }
145
+ if (!def.supports.initialData && Object.keys(resource.initialData || {}).length !== 0) {
146
+ continue;
147
+ }
148
+ if (def.resourceType !== resource.type) {
149
+ if (!(def.additionalTypes || []).includes(resource.type)) {
150
+ continue;
151
+ }
152
+ }
153
+ supported.push(def);
154
+ }
155
+ }
156
+ return supported;
157
+ }
99
158
 
100
159
  // src/CreatorResource.ts
101
160
  import { HAS_PART, PART_OF } from "@iiif/parser";
@@ -470,6 +529,13 @@ var Creator = class {
470
529
  this.vault = vault;
471
530
  this.previewVault = previewVault || new Vault();
472
531
  }
532
+ matchBasedOnResource(resource) {
533
+ return matchBasedOnResource(
534
+ resource,
535
+ this.configs || [],
536
+ { vault: this.vault }
537
+ );
538
+ }
473
539
  async create(definition, payload, options) {
474
540
  const foundDefinition = this.configs.find((t) => t.id === definition);
475
541
  if (!foundDefinition) {
@@ -541,5 +607,9 @@ var Creator = class {
541
607
  };
542
608
  export {
543
609
  Creator,
544
- CreatorResource
610
+ CreatorResource,
611
+ getEmptyType,
612
+ matchBasedOnResource,
613
+ randomId,
614
+ resolveType
545
615
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manifest-editor/creator-api",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "type": "module",
5
5
  "bugs": "https://github.com/digirati-co-uk/iiif-manifest-editor/issues",
6
6
  "repository": {
@@ -42,16 +42,16 @@
42
42
  "prepack": "tsup src/index.ts"
43
43
  },
44
44
  "dependencies": {
45
- "@iiif/helpers": "^1.2.12",
46
- "@iiif/parser": "^2.1.2",
45
+ "@iiif/helpers": "^1.3.1",
46
+ "@iiif/parser": "^2.1.7",
47
47
  "@iiif/presentation-3": "^2.2.3",
48
48
  "@iiif/presentation-3-normalized": "^0.9.7",
49
- "@manifest-editor/editor-api": "1.1.0",
50
- "polygon-editor": "^0.0.4",
49
+ "@manifest-editor/editor-api": "1.3.1",
50
+ "polygon-editor": "^0.0.6",
51
51
  "react-iiif-vault": "^1.2.1"
52
52
  },
53
53
  "devDependencies": {
54
- "@repo/eslint-config": "0.0.0",
54
+ "@repo/eslint-config": "workspace:*",
55
55
  "@types/react": "^18.3.3",
56
56
  "tiny-invariant": "^1.3.3",
57
57
  "tsup": "^8.0.2"
@@ -59,5 +59,5 @@
59
59
  "publishConfig": {
60
60
  "access": "public"
61
61
  },
62
- "gitHead": "d1de1d181a41f39cd2f01839348fa2da187331cb"
62
+ "gitHead": "920fe405869996394c204c6eae70f446aab78986"
63
63
  }