@goodfellow-cms/admin 0.7.0 → 0.9.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/plugin.js CHANGED
@@ -1,5 +1,13 @@
1
- import { r as createChannel, t as PLUGIN_READY_MESSAGE } from "./plugin-protocol-DkvBDqsF.js";
1
+ import { _ as mediaUrl, a as showMediaInPreview, n as PLUGIN_READY_MESSAGE, r as createMediaPreviews, s as createChannel, t as installCustomFonts } from "./custom-font-faces-DJ2AF2oN.js";
2
+ import { MEDIA_DIR } from "@goodfellow-cms/core";
2
3
  //#region src/plugin.ts
4
+ /**
5
+ * A plugin's admin frame: runs the plugin's admin module, sandboxed away from
6
+ * the admin panel's own page, and answers for it. Builds bundle each plugin's
7
+ * admin module with this into a page of its own (`pluginFrameEntry()` in
8
+ * `@goodfellow-cms/core`), whose Content Security Policy reaches only the
9
+ * addresses the plugin declared.
10
+ */
3
11
  /** Shows the admin panel's light or dark choice, as the admin panel's stylesheet reads it. */
4
12
  function applyTheme(choice) {
5
13
  const root = document.documentElement;
@@ -34,6 +42,28 @@ function adminApi(channel, init) {
34
42
  }
35
43
  };
36
44
  }
45
+ /**
46
+ * Shows the site's media in an editor's frame as Puck's frame does: `/media/…`
47
+ * addresses from the site's folder, from memory for uploads the live site
48
+ * doesn't have yet (which the page sends, or reads from the repository when
49
+ * an image doesn't load), or from the storage a plugin keeps them in. Text
50
+ * edited in place keeps its addresses, since editors read its HTML back into
51
+ * content.
52
+ */
53
+ function showEditorMedia(channel, init) {
54
+ let storage = init.mediaStorage;
55
+ const previews = createMediaPreviews({ readBytes: async (path) => {
56
+ if (!path.startsWith(`${MEDIA_DIR}/`)) return void 0;
57
+ return await channel.call("media.bytes", mediaUrl(path)) ?? void 0;
58
+ } }, init.siteUrl, () => storage);
59
+ channel.handle("media.remember", (file) => {
60
+ if (typeof file?.url === "string" && file.bytes instanceof Uint8Array) previews.remember(file.url, file.bytes);
61
+ });
62
+ channel.handle("media.storage", (given) => {
63
+ storage = given ?? void 0;
64
+ });
65
+ return showMediaInPreview(document, previews, { keep: "[contenteditable]:not([contenteditable=\"false\"])" });
66
+ }
37
67
  /** Opens an editor plugin's editor in the frame, giving the admin panel's page what it can do. */
38
68
  async function openEditor(admin, channel, init, element, api) {
39
69
  const open = init.editor;
@@ -54,11 +84,21 @@ async function openEditor(admin, channel, init, element, api) {
54
84
  }),
55
85
  sharePreview: (root) => channel.call("editor.sharePreview", { root }),
56
86
  draw: (block) => channel.call("editor.draw", { block }),
57
- styles: () => channel.call("editor.styles")
87
+ fields: (block) => channel.call("editor.fields", { block }),
88
+ styles: async () => {
89
+ const styles = await channel.call("editor.styles");
90
+ installCustomFonts(document, styles.customFonts ?? [], async (url) => await channel.call("media.bytes", url) ?? void 0);
91
+ return styles;
92
+ },
93
+ showsMedia: true
58
94
  };
59
95
  document.documentElement.classList.add("gfa-plugin-editor");
96
+ const stopShowingMedia = showEditorMedia(channel, init);
60
97
  const controls = await admin.editor.mount(element, session, api) ?? {};
61
- window.addEventListener("pagehide", () => controls.destroy?.());
98
+ window.addEventListener("pagehide", () => {
99
+ controls.destroy?.();
100
+ stopShowingMedia();
101
+ });
62
102
  return {
63
103
  opened: {
64
104
  set: typeof controls.set === "function",