@manifest-editor/manifest-preset 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.
@@ -0,0 +1,425 @@
1
+ // src/left-panels/canvas-listing.tsx
2
+ import {
3
+ CreateCanvasIcon,
4
+ IIIFBrowserIcon,
5
+ Sidebar,
6
+ SidebarContent,
7
+ SidebarHeader,
8
+ ThumbnailGridContainer,
9
+ useFastList
10
+ } from "@manifest-editor/components";
11
+ import {
12
+ CanvasGrid,
13
+ CanvasList,
14
+ InputContainer,
15
+ createAppActions,
16
+ useInStack,
17
+ useToggleList
18
+ } from "@manifest-editor/editors";
19
+ import {
20
+ useCreator,
21
+ useLayoutActions,
22
+ useManifestEditor
23
+ } from "@manifest-editor/shell";
24
+ import { useEffect, useLayoutEffect } from "react";
25
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
26
+ var CanvasListingIcon = ({
27
+ title,
28
+ titleId,
29
+ ...props
30
+ }) => /* @__PURE__ */ jsxs(
31
+ "svg",
32
+ {
33
+ xmlns: "http://www.w3.org/2000/svg",
34
+ viewBox: "0 0 24 24",
35
+ width: "1em",
36
+ height: "1em",
37
+ "aria-labelledby": titleId,
38
+ ...props,
39
+ children: [
40
+ title ? /* @__PURE__ */ jsx("title", { id: titleId, children: title }) : null,
41
+ /* @__PURE__ */ jsxs("g", { fill: "none", children: [
42
+ /* @__PURE__ */ jsx("path", { d: "M0 0h24v24H0V0z" }),
43
+ /* @__PURE__ */ jsx("path", { d: "M0 0h24v24H0V0z", opacity: ".87" })
44
+ ] }),
45
+ /* @__PURE__ */ jsx(
46
+ "path",
47
+ {
48
+ d: "M3 13h2v-2H3v2zm0 4h2v-2H3v2zm0-8h2V7H3v2zm4 4h14v-2H7v2zm0 4h14v-2H7v2zM7 7v2h14V7H7zm-4 6h2v-2H3v2zm0 4h2v-2H3v2zm0-8h2V7H3v2zm4 4h14v-2H7v2zm0 4h14v-2H7v2zM7 7v2h14V7H7z",
49
+ fill: "currentColor"
50
+ }
51
+ )
52
+ ]
53
+ }
54
+ );
55
+ var canvasListing = {
56
+ id: "canvas-listing",
57
+ label: "Canvases",
58
+ icon: /* @__PURE__ */ jsx(CanvasListingIcon, {}),
59
+ render: (state, ctx, app) => {
60
+ return /* @__PURE__ */ jsx(
61
+ CanvasListing,
62
+ {
63
+ gridView: state.gridView || false,
64
+ onChangeGridView: (gridView) => ctx.actions.change("canvas-listing", { gridView })
65
+ }
66
+ );
67
+ }
68
+ };
69
+ function CanvasListing({
70
+ gridView,
71
+ onChangeGridView
72
+ }) {
73
+ const { open } = useLayoutActions();
74
+ const { structural, technical } = useManifestEditor();
75
+ const [toggled, toggle] = useToggleList();
76
+ const canvas = useInStack("Canvas");
77
+ const { items } = structural;
78
+ const manifestId = technical.id.get();
79
+ const manifest = { id: manifestId, type: "Manifest" };
80
+ const [canCreateCanvas, canvasActions] = useCreator(
81
+ manifest,
82
+ "items",
83
+ "Canvas"
84
+ );
85
+ const canvases = useFastList(items.get(), 24);
86
+ useEffect(() => {
87
+ if (canvas?.resource.source.id) {
88
+ return;
89
+ }
90
+ if (items.get().length) {
91
+ open({ id: "current-canvas" });
92
+ canvasActions.edit(items.get()[0]);
93
+ }
94
+ }, []);
95
+ useLayoutEffect(() => {
96
+ const selected = document.querySelector('[data-canvas-selected="true"]');
97
+ if (selected) {
98
+ selected.scrollIntoView({ block: "center" });
99
+ }
100
+ }, [canvases, gridView]);
101
+ return /* @__PURE__ */ jsxs(Sidebar, { children: [
102
+ /* @__PURE__ */ jsx(
103
+ SidebarHeader,
104
+ {
105
+ title: "Canvases",
106
+ actions: [
107
+ {
108
+ icon: /* @__PURE__ */ jsx(Fragment, { children: gridView ? /* @__PURE__ */ jsx(CanvasListingIcon, { width: 24, height: 24 }) : /* @__PURE__ */ jsx(CanvasThumbnailsIcon, {}) }),
109
+ title: gridView ? "List view" : "Grid view",
110
+ onClick: () => {
111
+ onChangeGridView(!gridView);
112
+ }
113
+ },
114
+ {
115
+ icon: /* @__PURE__ */ jsx(ListEditIcon, {}),
116
+ title: "Edit canvases",
117
+ toggled: toggled.items,
118
+ onClick: () => toggle("items")
119
+ },
120
+ {
121
+ icon: /* @__PURE__ */ jsx(IIIFBrowserIcon, { className: "text-2xl" }),
122
+ title: "IIIF Browser",
123
+ onClick: () => canvasActions.creator("@manifest-editor/iiif-browser-creator"),
124
+ disabled: !canCreateCanvas
125
+ },
126
+ {
127
+ icon: /* @__PURE__ */ jsx(CreateCanvasIcon, {}),
128
+ title: "Add new canvas",
129
+ onClick: () => canvasActions.create(),
130
+ disabled: !canCreateCanvas
131
+ }
132
+ ]
133
+ }
134
+ ),
135
+ gridView ? /* @__PURE__ */ jsx(CanvasGridView, { isEditing: toggled.items }) : /* @__PURE__ */ jsx(CanvasListView, { isEditing: toggled.items })
136
+ ] });
137
+ }
138
+ function useEditCanvasItems() {
139
+ const { edit, open } = useLayoutActions();
140
+ const canvas = useInStack("Canvas");
141
+ const { technical, structural } = useManifestEditor();
142
+ const { items } = structural;
143
+ const manifestId = technical.id.get();
144
+ const manifest = { id: manifestId, type: "Manifest" };
145
+ const canvases = useFastList(items.get(), 24);
146
+ const [canCreateCanvas, canvasActions] = useCreator(
147
+ manifest,
148
+ "items",
149
+ "Canvas"
150
+ );
151
+ return {
152
+ canvas,
153
+ canvases,
154
+ items,
155
+ canvasActions,
156
+ open,
157
+ edit,
158
+ canCreateCanvas
159
+ };
160
+ }
161
+ function CanvasGridView({ isEditing }) {
162
+ const { canvas, items, canvases, canvasActions, open } = useEditCanvasItems();
163
+ return /* @__PURE__ */ jsx(SidebarContent, { children: /* @__PURE__ */ jsx(ThumbnailGridContainer, { children: /* @__PURE__ */ jsx(
164
+ CanvasGrid,
165
+ {
166
+ id: items.focusId(),
167
+ list: items.get() || [],
168
+ inlineHandle: false,
169
+ activeId: canvas?.resource.source.id,
170
+ reorder: isEditing ? (t) => items.reorder(t.startIndex, t.endIndex) : void 0,
171
+ onSelect: (item, idx) => {
172
+ open({ id: "current-canvas" });
173
+ canvasActions.edit(item, idx);
174
+ },
175
+ createActions: createAppActions(items)
176
+ }
177
+ ) }) });
178
+ }
179
+ function CanvasListView({ isEditing }) {
180
+ const { canvas, items, canvasActions, open } = useEditCanvasItems();
181
+ return /* @__PURE__ */ jsx(SidebarContent, { className: "p-3", children: /* @__PURE__ */ jsx(InputContainer, { $wide: true, children: /* @__PURE__ */ jsx(
182
+ CanvasList,
183
+ {
184
+ id: items.focusId(),
185
+ list: items.get() || [],
186
+ inlineHandle: false,
187
+ activeId: canvas?.resource.source.id,
188
+ reorder: isEditing ? (t) => items.reorder(t.startIndex, t.endIndex) : void 0,
189
+ onSelect: (item, idx) => {
190
+ open({ id: "current-canvas" });
191
+ canvasActions.edit(item, idx);
192
+ },
193
+ createActions: createAppActions(items)
194
+ }
195
+ ) }) });
196
+ }
197
+ function ListEditIcon() {
198
+ return /* @__PURE__ */ jsxs(
199
+ "svg",
200
+ {
201
+ xmlns: "http://www.w3.org/2000/svg",
202
+ height: "24",
203
+ viewBox: "0 0 24 24",
204
+ width: "24",
205
+ children: [
206
+ /* @__PURE__ */ jsx("path", { d: "M0 0h24v24H0V0z", fill: "none" }),
207
+ /* @__PURE__ */ jsx("path", { d: "M14.06 9.02l.92.92L5.92 19H5v-.92l9.06-9.06M17.66 3c-.25 0-.51.1-.7.29l-1.83 1.83 3.75 3.75 1.83-1.83c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.2-.2-.45-.29-.71-.29zm-3.6 3.19L3 17.25V21h3.75L17.81 9.94l-3.75-3.75z" })
208
+ ]
209
+ }
210
+ );
211
+ }
212
+ function CanvasThumbnailsIcon() {
213
+ return /* @__PURE__ */ jsxs(
214
+ "svg",
215
+ {
216
+ xmlns: "http://www.w3.org/2000/svg",
217
+ height: "24",
218
+ viewBox: "0 0 24 24",
219
+ width: "24",
220
+ children: [
221
+ /* @__PURE__ */ jsx("path", { d: "M0 0h24v24H0V0z", fill: "none" }),
222
+ /* @__PURE__ */ jsx(
223
+ "path",
224
+ {
225
+ d: "M20 2H4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zM8 20H4v-4h4v4zm0-6H4v-4h4v4zm0-6H4V4h4v4zm6 12h-4v-4h4v4zm0-6h-4v-4h4v4zm0-6h-4V4h4v4zm6 12h-4v-4h4v4zm0-6h-4v-4h4v4zm0-6h-4V4h4v4z",
226
+ fill: "currentColor"
227
+ }
228
+ )
229
+ ]
230
+ }
231
+ );
232
+ }
233
+
234
+ // src/left-panels/manifest.tsx
235
+ import {
236
+ Sidebar as Sidebar2,
237
+ SidebarContent as SidebarContent2,
238
+ SidebarHeader as SidebarHeader2
239
+ } from "@manifest-editor/components";
240
+ import {
241
+ useLayoutActions as useLayoutActions2,
242
+ useManifestEditor as useManifestEditor2
243
+ } from "@manifest-editor/shell";
244
+ import { useEffect as useEffect2, useRef } from "react";
245
+ import { LocaleString, ManifestMetadata } from "react-iiif-vault";
246
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
247
+ function ManifestIcon({
248
+ title,
249
+ titleId,
250
+ ...props
251
+ }) {
252
+ return /* @__PURE__ */ jsxs2(
253
+ "svg",
254
+ {
255
+ xmlns: "http://www.w3.org/2000/svg",
256
+ width: "1em",
257
+ height: "1em",
258
+ "aria-labelledby": titleId,
259
+ ...props,
260
+ children: [
261
+ title ? /* @__PURE__ */ jsx2("title", { id: titleId, children: title }) : null,
262
+ /* @__PURE__ */ jsx2("path", { d: "M0 0h24v24H0V0z", fill: "none" }),
263
+ /* @__PURE__ */ jsx2(
264
+ "path",
265
+ {
266
+ d: "M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8z",
267
+ fill: "currentColor"
268
+ }
269
+ )
270
+ ]
271
+ }
272
+ );
273
+ }
274
+ var manifestPanel = {
275
+ id: "left-panel-manifest",
276
+ label: "Manifest summary",
277
+ icon: /* @__PURE__ */ jsx2(ManifestIcon, {}),
278
+ render: (state, ctx, app) => {
279
+ return /* @__PURE__ */ jsxs2(Sidebar2, { children: [
280
+ /* @__PURE__ */ jsx2(SidebarHeader2, { title: "Manifest summary" }),
281
+ /* @__PURE__ */ jsx2(SidebarContent2, { className: "p-4", children: /* @__PURE__ */ jsx2(ManifestPanel, {}) })
282
+ ] });
283
+ }
284
+ };
285
+ function ManifestPanel() {
286
+ const { edit, open } = useLayoutActions2();
287
+ const { descriptive, technical } = useManifestEditor2();
288
+ const manifestId = technical.id.get();
289
+ const manifest = { id: manifestId, type: "Manifest" };
290
+ const isInitial = useRef(true);
291
+ const label = descriptive.label.get();
292
+ const summary = descriptive.summary.get();
293
+ const requiredStatement = descriptive.requiredStatement.get();
294
+ const metadata = descriptive.metadata.get();
295
+ useEffect2(() => {
296
+ edit(manifest);
297
+ open({ id: "overview" });
298
+ isInitial.current = false;
299
+ }, []);
300
+ return /* @__PURE__ */ jsxs2(Fragment2, { children: [
301
+ label ? /* @__PURE__ */ jsx2(
302
+ LocaleString,
303
+ {
304
+ as: "h2",
305
+ className: "text-lg font-semibold mb-2 [&>a]:underline [&>a]:hover:text-slate-400",
306
+ children: label
307
+ }
308
+ ) : null,
309
+ summary ? /* @__PURE__ */ jsx2(
310
+ LocaleString,
311
+ {
312
+ enableDangerouslySetInnerHTML: true,
313
+ as: "p",
314
+ className: "text-sm text-slate-800 block [&>a]:underline [&>a]:hover:text-slate-400 mb-2",
315
+ children: summary
316
+ }
317
+ ) : null,
318
+ /* @__PURE__ */ jsx2("hr", {}),
319
+ requiredStatement ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
320
+ /* @__PURE__ */ jsxs2("div", { className: "py-2 text-black", children: [
321
+ /* @__PURE__ */ jsx2(
322
+ LocaleString,
323
+ {
324
+ as: "h4",
325
+ className: "font-bold text-black w-full text-sm font-semibold mb-0 [&>a]:underline [&>a]:hover:text-slate-400",
326
+ children: requiredStatement.label
327
+ }
328
+ ),
329
+ /* @__PURE__ */ jsx2(
330
+ LocaleString,
331
+ {
332
+ enableDangerouslySetInnerHTML: true,
333
+ className: "text-sm [&>a]:underline [&>a]:hover:text-slate-400",
334
+ children: requiredStatement.value
335
+ }
336
+ )
337
+ ] }),
338
+ /* @__PURE__ */ jsx2("hr", {})
339
+ ] }) : null,
340
+ metadata && metadata.length === 0 ? /* @__PURE__ */ jsx2("div", { className: "py-2 text-gray-400", children: "You can add some descriptive metadata for this manifest using the editing panel on the right" }) : null,
341
+ /* @__PURE__ */ jsx2(
342
+ ManifestMetadata,
343
+ {
344
+ allowHtml: true,
345
+ classes: {
346
+ container: "w-full",
347
+ row: "border-b border-gray-200 flex flex-col flex-wrap py-2",
348
+ label: "font-bold text-black w-full text-sm font-semibold mb-1",
349
+ value: "text-sm text-black block [&>span>a]:underline [&>span>a]:hover:text-slate-400",
350
+ empty: "text-gray-400"
351
+ }
352
+ }
353
+ )
354
+ ] });
355
+ }
356
+
357
+ // src/center-panels/manifest-overview.tsx
358
+ import {
359
+ CanvasThumbnailGridItem as CanvasThumbnailGridItem2,
360
+ ManifestOverviewEmptyState,
361
+ ThumbnailGridContainer as ThumbnailGridContainer2,
362
+ useFastList as useFastList2
363
+ } from "@manifest-editor/components";
364
+ import {
365
+ useCreator as useCreator2,
366
+ useLayoutActions as useLayoutActions3,
367
+ useManifestEditor as useManifestEditor3
368
+ } from "@manifest-editor/shell";
369
+ import { jsx as jsx3 } from "react/jsx-runtime";
370
+ var manifestOverview = {
371
+ id: "overview",
372
+ label: "Overview",
373
+ icon: "",
374
+ render: () => /* @__PURE__ */ jsx3(ManifestOverviewCenterPanel, {})
375
+ };
376
+ function ManifestOverviewCenterPanel() {
377
+ const { edit, open } = useLayoutActions3();
378
+ const { structural, technical } = useManifestEditor3();
379
+ const { items } = structural;
380
+ const manifestId = technical.id.get();
381
+ const manifest = { id: manifestId, type: "Manifest" };
382
+ const [canCreateCanvas, canvasActions] = useCreator2(
383
+ manifest,
384
+ "items",
385
+ "Canvas"
386
+ );
387
+ const canvases = useFastList2(items.get(), 24);
388
+ if (!canvases || canvases.length === 0) {
389
+ return /* @__PURE__ */ jsx3("div", { children: /* @__PURE__ */ jsx3(
390
+ ManifestOverviewEmptyState,
391
+ {
392
+ onCreate: canvasActions.create,
393
+ canCreate: canCreateCanvas
394
+ }
395
+ ) });
396
+ }
397
+ return /* @__PURE__ */ jsx3(ThumbnailGridContainer2, { wide: true, children: canvases.map((item) => /* @__PURE__ */ jsx3(
398
+ CanvasThumbnailGridItem2,
399
+ {
400
+ id: item.id,
401
+ onClick: () => {
402
+ open({ id: "current-canvas" });
403
+ open({ id: "canvas-listing", state: { gridView: true } });
404
+ canvasActions.edit(item);
405
+ }
406
+ },
407
+ item.id
408
+ )) });
409
+ }
410
+
411
+ export {
412
+ CanvasListingIcon,
413
+ canvasListing,
414
+ CanvasListing,
415
+ useEditCanvasItems,
416
+ CanvasGridView,
417
+ CanvasListView,
418
+ ListEditIcon,
419
+ CanvasThumbnailsIcon,
420
+ ManifestIcon,
421
+ manifestPanel,
422
+ ManifestPanel,
423
+ manifestOverview,
424
+ ManifestOverviewCenterPanel
425
+ };