@thebes/cadmea 1.5.0 → 1.6.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.
@@ -1,16 +1,16 @@
1
1
  import { createComponent, escape, ssr, ssrAttribute } from "solid-js/web";
2
2
  import { createMutation, createQuery, useQueryClient } from "@tanstack/solid-query";
3
- import { For, Index, Show, Suspense, createEffect, createSignal, lazy, onCleanup } from "solid-js";
3
+ import { For, Index, Show, Suspense, createEffect, createSignal, lazy, onCleanup, onMount } from "solid-js";
4
4
  import { createForm } from "@tanstack/solid-form";
5
- import { validateDocument } from "@thebes/cadmus/cms";
5
+ import { VISUAL_EDIT_MESSAGE, validateDocument } from "@thebes/cadmus/cms";
6
6
  import { Link, useBlocker } from "@tanstack/solid-router";
7
7
  import { createSolidTable, flexRender, getCoreRowModel } from "@tanstack/solid-table";
8
8
  //#region src/CollectionEdit.tsx
9
- var _tmpl$$4 = ["<p class=\"text-sm text-error\" role=\"alert\">", "</p>"], _tmpl$2$3 = "<span class=\"loading loading-spinner loading-sm\"></span>", _tmpl$3$1 = [
9
+ var _tmpl$$5 = ["<p class=\"text-sm text-error\" role=\"alert\">", "</p>"], _tmpl$2$3 = "<span class=\"loading loading-spinner loading-sm\"></span>", _tmpl$3$2 = [
10
10
  "<button type=\"button\" class=\"btn flex-1\"",
11
11
  ">",
12
12
  "</button>"
13
- ], _tmpl$4$1 = [
13
+ ], _tmpl$4$2 = [
14
14
  "<button type=\"button\" class=\"btn btn-primary flex-1\"",
15
15
  ">",
16
16
  "</button>"
@@ -216,7 +216,7 @@ function CollectionEdit(props) {
216
216
  return props.error;
217
217
  },
218
218
  get children() {
219
- return ssr(_tmpl$$4, escape(props.error));
219
+ return ssr(_tmpl$$5, escape(props.error));
220
220
  }
221
221
  })), escape(createComponent(For, {
222
222
  each: fieldGroups,
@@ -255,7 +255,7 @@ function CollectionEdit(props) {
255
255
  return props.capabilities?.canUpdate !== false;
256
256
  },
257
257
  get children() {
258
- return ssr(_tmpl$4$1, ssrAttribute("disabled", props.saving, true), escape(createComponent(Show, {
258
+ return ssr(_tmpl$4$2, ssrAttribute("disabled", props.saving, true), escape(createComponent(Show, {
259
259
  get when() {
260
260
  return props.saving;
261
261
  },
@@ -271,7 +271,7 @@ function CollectionEdit(props) {
271
271
  },
272
272
  get children() {
273
273
  return [
274
- ssr(_tmpl$3$1, ssrAttribute("disabled", props.draftActions?.saving, true), escape(createComponent(Show, {
274
+ ssr(_tmpl$3$2, ssrAttribute("disabled", props.draftActions?.saving, true), escape(createComponent(Show, {
275
275
  get when() {
276
276
  return props.draftActions?.saving;
277
277
  },
@@ -282,7 +282,7 @@ function CollectionEdit(props) {
282
282
  return ssr(_tmpl$2$3);
283
283
  }
284
284
  }))),
285
- ssr(_tmpl$4$1, ssrAttribute("disabled", !props.draftActions?.canPublish || props.draftActions?.publishing, true), escape(createComponent(Show, {
285
+ ssr(_tmpl$4$2, ssrAttribute("disabled", !props.draftActions?.canPublish || props.draftActions?.publishing, true), escape(createComponent(Show, {
286
286
  get when() {
287
287
  return props.draftActions?.publishing;
288
288
  },
@@ -636,7 +636,7 @@ function formatDateValue(value) {
636
636
  }
637
637
  //#endregion
638
638
  //#region src/tanstack-start/create.tsx
639
- var _tmpl$$3 = [
639
+ var _tmpl$$4 = [
640
640
  "<div class=\"flex flex-col gap-4\"><h1 class=\"text-xl font-semibold\">",
641
641
  "</h1>",
642
642
  "</div>"
@@ -658,7 +658,7 @@ function createCollectionCreatePage(options) {
658
658
  },
659
659
  onError: (e) => setError(e.message)
660
660
  }));
661
- return ssr(_tmpl$$3, escape(options.label ?? `New ${options.collection.slug}`), escape(createComponent(CollectionEdit, {
661
+ return ssr(_tmpl$$4, escape(options.label ?? `New ${options.collection.slug}`), escape(createComponent(CollectionEdit, {
662
662
  get config() {
663
663
  return options.collection;
664
664
  },
@@ -679,13 +679,44 @@ function createCollectionCreatePage(options) {
679
679
  };
680
680
  }
681
681
  //#endregion
682
+ //#region src/VisualEditingPane.tsx
683
+ var _tmpl$$3 = ["<iframe", "></iframe>"];
684
+ function originOf(url) {
685
+ try {
686
+ return new URL(url).origin;
687
+ } catch {
688
+ return;
689
+ }
690
+ }
691
+ function VisualEditingPane(props) {
692
+ onMount(() => {
693
+ const expected = props.allowedOrigin ?? originOf(props.src);
694
+ const handler = (event) => {
695
+ if (expected && event.origin !== expected) return;
696
+ const data = event.data;
697
+ if (data?.type === VISUAL_EDIT_MESSAGE && data.ref) props.onEdit?.(data.ref);
698
+ };
699
+ window.addEventListener("message", handler);
700
+ onCleanup(() => window.removeEventListener("message", handler));
701
+ });
702
+ createEffect(() => {
703
+ props.previewValues;
704
+ props.previewTarget;
705
+ });
706
+ return ssr(_tmpl$$3, ssrAttribute("src", escape(props.src, true), false) + ssrAttribute("title", escape(props.title ?? "Preview", true), false) + ssrAttribute("class", escape(props.class ?? "h-full w-full border-0", true), false));
707
+ }
708
+ //#endregion
682
709
  //#region src/tanstack-start/edit.tsx
683
710
  var _tmpl$$2 = ["<button type=\"button\" class=\"btn btn-error btn-outline btn-sm self-start\">", "</button>"], _tmpl$2$2 = [
684
711
  "<div class=\"flex flex-col gap-4\"><h1 class=\"text-xl font-semibold\">",
685
712
  "</h1>",
686
713
  "",
687
714
  "</div>"
688
- ];
715
+ ], _tmpl$3$1 = [
716
+ "<div class=\"grid grid-cols-1 gap-4 lg:grid-cols-2\">",
717
+ "",
718
+ "</div>"
719
+ ], _tmpl$4$1 = ["<div class=\"lg:sticky lg:top-4 lg:h-[calc(100vh-2rem)]\">", "</div>"];
689
720
  /**
690
721
  * Builds an edit-page component for a collection — fetch, update, and
691
722
  * delete, all wired together, plus a router-level unsaved-changes guard
@@ -699,6 +730,7 @@ function createCollectionEditPage(options) {
699
730
  const [error, setError] = createSignal();
700
731
  const [dirty, setDirty] = createSignal(false);
701
732
  const [latestDraftId, setLatestDraftId] = createSignal();
733
+ const [previewValues, setPreviewValues] = createSignal({});
702
734
  useBlocker({
703
735
  shouldBlockFn: () => dirty(),
704
736
  enableBeforeUnload: () => dirty()
@@ -755,7 +787,7 @@ function createCollectionEditPage(options) {
755
787
  },
756
788
  onError: (e) => setError(e.message)
757
789
  }));
758
- return ssr(_tmpl$2$2, escape(options.label ?? `Edit ${options.collection.slug}`), escape(createComponent(Show, {
790
+ const EditorPane = () => ssr(_tmpl$2$2, escape(options.label ?? `Edit ${options.collection.slug}`), escape(createComponent(Show, {
759
791
  get when() {
760
792
  return row.data;
761
793
  },
@@ -784,6 +816,7 @@ function createCollectionEditPage(options) {
784
816
  return options.fieldWidgets;
785
817
  },
786
818
  onDirtyChange: setDirty,
819
+ onValuesChange: setPreviewValues,
787
820
  get capabilities() {
788
821
  return options.capabilities?.();
789
822
  },
@@ -799,7 +832,8 @@ function createCollectionEditPage(options) {
799
832
  canPreview: latestDraftId() !== void 0,
800
833
  saveDraftLabel: options.draftActions.saveDraftLabel,
801
834
  publishLabel: options.draftActions.publishLabel,
802
- previewLabel: options.draftActions.previewLabel
835
+ previewLabel: options.draftActions.previewLabel,
836
+ autosave: options.draftActions.autosave
803
837
  };
804
838
  }
805
839
  });
@@ -812,6 +846,40 @@ function createCollectionEditPage(options) {
812
846
  return ssr(_tmpl$$2, escape(options.deleteLabel ?? `Delete ${options.collection.slug}`));
813
847
  }
814
848
  })));
849
+ return createComponent(Show, {
850
+ get when() {
851
+ return options.preview;
852
+ },
853
+ get fallback() {
854
+ return createComponent(EditorPane, {});
855
+ },
856
+ get children() {
857
+ return ssr(_tmpl$3$1, escape(createComponent(EditorPane, {})), escape(createComponent(Show, {
858
+ get when() {
859
+ return options.preview?.url();
860
+ },
861
+ children: (url) => ssr(_tmpl$4$1, escape(createComponent(VisualEditingPane, {
862
+ get src() {
863
+ return url();
864
+ },
865
+ get allowedOrigin() {
866
+ return options.preview?.allowedOrigin?.();
867
+ },
868
+ get previewValues() {
869
+ return previewValues();
870
+ },
871
+ get previewTarget() {
872
+ return {
873
+ collection: options.collection.slug,
874
+ id: Number(row.data?.id)
875
+ };
876
+ },
877
+ "class": "border-base-300 rounded-box h-full w-full border",
878
+ title: "Live preview"
879
+ })))
880
+ })));
881
+ }
882
+ });
815
883
  };
816
884
  }
817
885
  //#endregion