@derweili/payload-visual-editing-overlay 0.1.0 → 0.1.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @derweili/payload-visual-editing-overlay
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#10](https://github.com/derweili/payload-visual-editing/pull/10) [`53bd748`](https://github.com/derweili/payload-visual-editing/commit/53bd7486fe30d9c009d65a876ef6230e49084202) Thanks [@derweili](https://github.com/derweili)! - Overlay: new `textColor` option for the edit button's text, next to `color` (outline and button background). The default highlight is now the docs' brand green `#168b49` with white text, instead of blue. The admin's field highlight uses the same green.
8
+
9
+ - Updated dependencies []:
10
+ - @derweili/payload-visual-editing-core@0.1.2
11
+
12
+ ## 0.1.1
13
+
14
+ ### Patch Changes
15
+
16
+ - [#6](https://github.com/derweili/payload-visual-editing/pull/6) [`5bdb1f5`](https://github.com/derweili/payload-visual-editing/commit/5bdb1f56012fec706d7e00cc84f55292072e5b46) Thanks [@derweili](https://github.com/derweili)! - Published from GitHub Actions with npm Trusted Publishing: every release now carries a provenance attestation that links the tarball to its source commit and build.
17
+
18
+ - Updated dependencies [[`5bdb1f5`](https://github.com/derweili/payload-visual-editing/commit/5bdb1f56012fec706d7e00cc84f55292072e5b46)]:
19
+ - @derweili/payload-visual-editing-core@0.1.1
20
+
3
21
  ## 0.1.0
4
22
 
5
23
  First release.
package/README.md CHANGED
@@ -45,7 +45,8 @@ through `postMessage`.
45
45
  | Option | Default | |
46
46
  | --- | --- | --- |
47
47
  | `label` | `"Edit"` | Text of the button |
48
- | `color` | a blue | Outline and button colour |
48
+ | `color` | `"#168b49"` (green) | Highlight colour: the outline and the button's background |
49
+ | `textColor` | `"#fff"` | Text colour of the button |
49
50
  | `adminRoute` | `"/admin"` | Payload's `routes.admin` |
50
51
  | `serverURL` | the page's origin | Origin of the admin, when it runs on another domain |
51
52
  | `openIn` | `"new-tab"` | Outside the Live Preview: `"same-tab"` navigates instead |
@@ -4,5 +4,5 @@ export type VisualEditingProps = Omit<OverlayOptions, 'root'>;
4
4
  * Mount in Draft Mode only, e.g. in the root layout:
5
5
  * `{draft && <VisualEditing label="Bearbeiten" />}`. Renders nothing itself.
6
6
  */
7
- export declare function VisualEditing({ adminRoute, serverURL, openIn, handshakeTimeout, label, color }: VisualEditingProps): null;
7
+ export declare function VisualEditing({ adminRoute, serverURL, openIn, handshakeTimeout, label, color, textColor }: VisualEditingProps): null;
8
8
  //# sourceMappingURL=VisualEditing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"VisualEditing.d.ts","sourceRoot":"","sources":["../../src/react/VisualEditing.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAE1E,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAA;AAE7D;;;GAGG;AACH,wBAAgB,aAAa,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,kBAAkB,GAAG,IAAI,CAMzH"}
1
+ {"version":3,"file":"VisualEditing.d.ts","sourceRoot":"","sources":["../../src/react/VisualEditing.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAE1E,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAA;AAE7D;;;GAGG;AACH,wBAAgB,aAAa,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,kBAAkB,GAAG,IAAI,CAMpI"}
@@ -4,7 +4,7 @@ import { createOverlay } from "../vanilla/overlay.js";
4
4
  /**
5
5
  * Mount in Draft Mode only, e.g. in the root layout:
6
6
  * `{draft && <VisualEditing label="Bearbeiten" />}`. Renders nothing itself.
7
- */ export function VisualEditing({ adminRoute, serverURL, openIn, handshakeTimeout, label, color }) {
7
+ */ export function VisualEditing({ adminRoute, serverURL, openIn, handshakeTimeout, label, color, textColor }) {
8
8
  useEffect(()=>{
9
9
  const overlay = createOverlay({
10
10
  adminRoute,
@@ -12,7 +12,8 @@ import { createOverlay } from "../vanilla/overlay.js";
12
12
  openIn,
13
13
  handshakeTimeout,
14
14
  label,
15
- color
15
+ color,
16
+ textColor
16
17
  });
17
18
  return ()=>overlay.destroy();
18
19
  }, [
@@ -21,7 +22,8 @@ import { createOverlay } from "../vanilla/overlay.js";
21
22
  openIn,
22
23
  handshakeTimeout,
23
24
  label,
24
- color
25
+ color,
26
+ textColor
25
27
  ]);
26
28
  return null;
27
29
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/react/VisualEditing.tsx"],"sourcesContent":["'use client'\n\nimport { useEffect } from 'react'\n\nimport { createOverlay, type OverlayOptions } from '../vanilla/overlay.ts'\n\nexport type VisualEditingProps = Omit<OverlayOptions, 'root'>\n\n/**\n * Mount in Draft Mode only, e.g. in the root layout:\n * `{draft && <VisualEditing label=\"Bearbeiten\" />}`. Renders nothing itself.\n */\nexport function VisualEditing({ adminRoute, serverURL, openIn, handshakeTimeout, label, color }: VisualEditingProps): null {\n useEffect(() => {\n const overlay = createOverlay({ adminRoute, serverURL, openIn, handshakeTimeout, label, color })\n return () => overlay.destroy()\n }, [adminRoute, serverURL, openIn, handshakeTimeout, label, color])\n return null\n}\n"],"names":["useEffect","createOverlay","VisualEditing","adminRoute","serverURL","openIn","handshakeTimeout","label","color","overlay","destroy"],"mappings":"AAAA;AAEA,SAASA,SAAS,QAAQ,QAAO;AAEjC,SAASC,aAAa,QAA6B,wBAAuB;AAI1E;;;CAGC,GACD,OAAO,SAASC,cAAc,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAEC,KAAK,EAAsB;IACjHR,UAAU;QACR,MAAMS,UAAUR,cAAc;YAAEE;YAAYC;YAAWC;YAAQC;YAAkBC;YAAOC;QAAM;QAC9F,OAAO,IAAMC,QAAQC,OAAO;IAC9B,GAAG;QAACP;QAAYC;QAAWC;QAAQC;QAAkBC;QAAOC;KAAM;IAClE,OAAO;AACT"}
1
+ {"version":3,"sources":["../../src/react/VisualEditing.tsx"],"sourcesContent":["'use client'\n\nimport { useEffect } from 'react'\n\nimport { createOverlay, type OverlayOptions } from '../vanilla/overlay.ts'\n\nexport type VisualEditingProps = Omit<OverlayOptions, 'root'>\n\n/**\n * Mount in Draft Mode only, e.g. in the root layout:\n * `{draft && <VisualEditing label=\"Bearbeiten\" />}`. Renders nothing itself.\n */\nexport function VisualEditing({ adminRoute, serverURL, openIn, handshakeTimeout, label, color, textColor }: VisualEditingProps): null {\n useEffect(() => {\n const overlay = createOverlay({ adminRoute, serverURL, openIn, handshakeTimeout, label, color, textColor })\n return () => overlay.destroy()\n }, [adminRoute, serverURL, openIn, handshakeTimeout, label, color, textColor])\n return null\n}\n"],"names":["useEffect","createOverlay","VisualEditing","adminRoute","serverURL","openIn","handshakeTimeout","label","color","textColor","overlay","destroy"],"mappings":"AAAA;AAEA,SAASA,SAAS,QAAQ,QAAO;AAEjC,SAASC,aAAa,QAA6B,wBAAuB;AAI1E;;;CAGC,GACD,OAAO,SAASC,cAAc,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAEC,KAAK,EAAEC,SAAS,EAAsB;IAC5HT,UAAU;QACR,MAAMU,UAAUT,cAAc;YAAEE;YAAYC;YAAWC;YAAQC;YAAkBC;YAAOC;YAAOC;QAAU;QACzG,OAAO,IAAMC,QAAQC,OAAO;IAC9B,GAAG;QAACR;QAAYC;QAAWC;QAAQC;QAAkBC;QAAOC;QAAOC;KAAU;IAC7E,OAAO;AACT"}
@@ -1,5 +1,8 @@
1
1
  import { type SourceRef } from '@derweili/payload-visual-editing-core';
2
2
  export declare const OVERLAY_ATTR = "data-pve-overlay";
3
+ /** The brand green of the docs; white text on it has a 4.6:1 contrast (WCAG AA). */
4
+ export declare const DEFAULT_COLOR = "#168b49";
5
+ export declare const DEFAULT_TEXT_COLOR = "#fff";
3
6
  export interface OverlayOptions {
4
7
  /** Where to look for editable content. Default: `document.body`. */
5
8
  root?: Element;
@@ -13,8 +16,10 @@ export interface OverlayOptions {
13
16
  handshakeTimeout?: number;
14
17
  /** Text of the edit button. Default: "Edit". */
15
18
  label?: string;
16
- /** Outline and button colour. Default: a blue that reads on light and dark pages. */
19
+ /** Highlight colour: the outline and the button's background. Default: "#168b49" (green). */
17
20
  color?: string;
21
+ /** Text colour of the button. Default: "#fff". */
22
+ textColor?: string;
18
23
  }
19
24
  export interface Overlay {
20
25
  /** Scans the page again; normally the MutationObserver does this. */
@@ -1 +1 @@
1
- {"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../../src/vanilla/overlay.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,uCAAuC,CAAA;AAI9C,eAAO,MAAM,YAAY,qBAAqB,CAAA;AAE9C,MAAM,WAAW,cAAc;IAC7B,oEAAoE;IACpE,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,wEAAwE;IACxE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,mGAAmG;IACnG,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,6FAA6F;IAC7F,MAAM,CAAC,EAAE,SAAS,GAAG,UAAU,CAAA;IAC/B,+FAA+F;IAC/F,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,qFAAqF;IACrF,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,OAAO;IACtB,qEAAqE;IACrE,MAAM,IAAI,IAAI,CAAA;IACd,mEAAmE;IACnE,IAAI,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,OAAO,IAAI,IAAI,CAAA;CAChB;AASD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAyMnE"}
1
+ {"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../../src/vanilla/overlay.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,uCAAuC,CAAA;AAI9C,eAAO,MAAM,YAAY,qBAAqB,CAAA;AAC9C,oFAAoF;AACpF,eAAO,MAAM,aAAa,YAAY,CAAA;AACtC,eAAO,MAAM,kBAAkB,SAAS,CAAA;AAExC,MAAM,WAAW,cAAc;IAC7B,oEAAoE;IACpE,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,wEAAwE;IACxE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,mGAAmG;IACnG,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,6FAA6F;IAC7F,MAAM,CAAC,EAAE,SAAS,GAAG,UAAU,CAAA;IAC/B,+FAA+F;IAC/F,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,6FAA6F;IAC7F,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,OAAO;IACtB,qEAAqE;IACrE,MAAM,IAAI,IAAI,CAAA;IACd,mEAAmE;IACnE,IAAI,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,OAAO,IAAI,IAAI,CAAA;CAChB;AASD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CA8MnE"}
@@ -1,6 +1,8 @@
1
1
  import { buildAdminUrl, createFocusMessage, createReadyMessage, isReadyMessage } from '@derweili/payload-visual-editing-core';
2
2
  import { findTarget, scanTargets } from "./scan.js";
3
3
  export const OVERLAY_ATTR = 'data-pve-overlay';
4
+ /** The brand green of the docs; white text on it has a 4.6:1 contrast (WCAG AA). */ export const DEFAULT_COLOR = '#168b49';
5
+ export const DEFAULT_TEXT_COLOR = '#fff';
4
6
  const RESCAN_DELAY = 100;
5
7
  /** Time to move the pointer from the content to the edit button before the button hides. */ const HIDE_DELAY = 400;
6
8
  /** Gap between the outline and the content, and between the button and the viewport edge. */ const PAD = 4;
@@ -22,13 +24,18 @@ const RADIUS = '3px';
22
24
  const layer = document.createElement('div');
23
25
  layer.setAttribute(OVERLAY_ATTR, '');
24
26
  layer.style.cssText = 'position:fixed;inset:0;pointer-events:none;z-index:2147483647;';
25
- const color = options.color ?? '#2563eb';
27
+ const color = options.color ?? DEFAULT_COLOR;
28
+ const textColor = options.textColor ?? DEFAULT_TEXT_COLOR;
26
29
  const outline = document.createElement('div');
27
- outline.style.cssText = `position:fixed;display:none;box-sizing:border-box;border:2px solid ${color};border-radius:${RADIUS};`;
30
+ outline.style.cssText = `position:fixed;display:none;box-sizing:border-box;border:2px solid;border-radius:${RADIUS};`;
31
+ outline.style.borderColor = color;
28
32
  const button = document.createElement('button');
29
33
  button.type = 'button';
30
34
  button.textContent = options.label ?? 'Edit';
31
- button.style.cssText = `position:fixed;display:none;pointer-events:auto;margin:0;padding:2px 8px;border:0;` + `background:${color};color:#fff;font:600 12px/1.5 system-ui,sans-serif;cursor:pointer;`;
35
+ button.style.cssText = `position:fixed;display:none;pointer-events:auto;margin:0;padding:2px 8px;border:0;` + `font:600 12px/1.5 system-ui,sans-serif;cursor:pointer;`;
36
+ // Set apart from cssText: a colour value can't add other declarations
37
+ button.style.background = color;
38
+ button.style.color = textColor;
32
39
  // appendChild, not append: in apps with Cloudflare's worker types, `Element.append` is HTMLRewriter's
33
40
  layer.appendChild(outline);
34
41
  layer.appendChild(button);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/vanilla/overlay.ts"],"sourcesContent":["import {\n buildAdminUrl,\n createFocusMessage,\n createReadyMessage,\n isReadyMessage,\n type SourceRef,\n} from '@derweili/payload-visual-editing-core'\n\nimport { findTarget, scanTargets, type Targets } from './scan.ts'\n\nexport const OVERLAY_ATTR = 'data-pve-overlay'\n\nexport interface OverlayOptions {\n /** Where to look for editable content. Default: `document.body`. */\n root?: Element\n /** Payload's admin route (`config.routes.admin`). Default: \"/admin\". */\n adminRoute?: string\n /** Origin of the Payload admin, e.g. \"https://cms.example.com\". Default: the page's own origin. */\n serverURL?: string\n /** Outside the Live Preview iframe: open the admin in a new tab (default) or in this tab. */\n openIn?: 'new-tab' | 'same-tab'\n /** Inside the iframe: how long to wait for the admin's `pve:ready` before opening the link. */\n handshakeTimeout?: number\n /** Text of the edit button. Default: \"Edit\". */\n label?: string\n /** Outline and button colour. Default: a blue that reads on light and dark pages. */\n color?: string\n}\n\nexport interface Overlay {\n /** Scans the page again; normally the MutationObserver does this. */\n rescan(): void\n /** Opens the editor for a ref, like a click on the edit button. */\n edit(ref: SourceRef): Promise<void>\n destroy(): void\n}\n\nconst RESCAN_DELAY = 100\n/** Time to move the pointer from the content to the edit button before the button hides. */\nconst HIDE_DELAY = 400\n/** Gap between the outline and the content, and between the button and the viewport edge. */\nconst PAD = 4\nconst RADIUS = '3px'\n\n/**\n * Outlines editable content on hover and shows an edit button.\n * - Standalone: the button opens the admin's deep link.\n * - Inside the admin's Live Preview iframe: it sends `pve:focus` to the parent. Without a\n * `pve:ready` from the admin within `handshakeTimeout`, it falls back to the deep link.\n * Alt/Option-click on editable content does the same as the button.\n */\nexport function createOverlay(options: OverlayOptions = {}): Overlay {\n const document = options.root?.ownerDocument ?? globalThis.document\n const window = document.defaultView!\n const root = options.root ?? document.body\n const adminOrigin = new URL(options.serverURL ?? window.location.origin).origin\n const handshakeTimeout = options.handshakeTimeout ?? 500\n const inIframe = window.parent !== window\n\n // --- UI: one fixed layer that never takes pointer events except on the button\n const layer = document.createElement('div')\n layer.setAttribute(OVERLAY_ATTR, '')\n layer.style.cssText = 'position:fixed;inset:0;pointer-events:none;z-index:2147483647;'\n const color = options.color ?? '#2563eb'\n const outline = document.createElement('div')\n outline.style.cssText = `position:fixed;display:none;box-sizing:border-box;border:2px solid ${color};border-radius:${RADIUS};`\n const button = document.createElement('button')\n button.type = 'button'\n button.textContent = options.label ?? 'Edit'\n button.style.cssText =\n `position:fixed;display:none;pointer-events:auto;margin:0;padding:2px 8px;border:0;` +\n `background:${color};color:#fff;font:600 12px/1.5 system-ui,sans-serif;cursor:pointer;`\n // appendChild, not append: in apps with Cloudflare's worker types, `Element.append` is HTMLRewriter's\n layer.appendChild(outline)\n layer.appendChild(button)\n document.body.appendChild(layer)\n\n // --- State\n let targets: Targets = new Map()\n let current: { element: Element; ref: SourceRef } | null = null\n let rescanTimer: ReturnType<typeof setTimeout> | undefined\n let hideTimer: ReturnType<typeof setTimeout> | undefined\n let frame = 0\n\n const place = () => {\n frame = 0\n if (!current) return\n const rect = current.element.getBoundingClientRect()\n const box = {\n top: rect.top - PAD,\n left: rect.left - PAD,\n right: rect.right + PAD,\n bottom: rect.bottom + PAD,\n }\n Object.assign(outline.style, {\n display: 'block',\n top: `${box.top}px`,\n left: `${box.left}px`,\n width: `${box.right - box.left}px`,\n height: `${box.bottom - box.top}px`,\n })\n // Visible before measuring: a hidden button measures 0 × 0\n button.style.display = 'block'\n const { offsetWidth: width, offsetHeight: height } = button\n const viewportWidth = document.documentElement.clientWidth || window.innerWidth\n // Flush on the outline's top-right corner, so the pointer reaches it without leaving the\n // outline; inside the outline's top edge when there is no room above. Always in the viewport.\n const top = box.top >= height ? box.top - height : box.top\n const left = Math.min(Math.max(PAD, box.right - width), Math.max(PAD, viewportWidth - width - PAD))\n // Seamless joint: no rounding where the button meets the outline\n const above = top < box.top\n const onCorner = left === box.right - width\n Object.assign(button.style, {\n top: `${top}px`,\n left: `${left}px`,\n borderRadius: above ? `${RADIUS} ${RADIUS} 0 0` : `0 0 0 ${RADIUS}`,\n })\n outline.style.borderTopRightRadius = onCorner ? '0' : RADIUS\n }\n const schedulePlace = () => {\n if (current && !frame) frame = window.requestAnimationFrame(place)\n }\n\n const show = (target: { element: Element; ref: SourceRef } | null) => {\n clearTimeout(hideTimer)\n hideTimer = undefined\n current = target\n if (!target) {\n outline.style.display = 'none'\n button.style.display = 'none'\n return\n }\n place()\n }\n\n const rescan = () => {\n rescanTimer = undefined\n targets = scanTargets(root, layer)\n if (current && !targets.has(current.element)) show(null)\n }\n\n // --- Opening the editor\n let ready = false\n const readyWaiters = new Set<(ready: boolean) => void>()\n\n const onMessage = (event: MessageEvent) => {\n if (event.source !== window.parent || event.origin !== adminOrigin) return\n if (!isReadyMessage(event.data)) return\n ready = true\n for (const resolve of readyWaiters) resolve(true)\n readyWaiters.clear()\n }\n\n const ping = () => window.parent.postMessage(createReadyMessage(), adminOrigin)\n\n const waitForReady = () =>\n new Promise<boolean>((resolve) => {\n if (ready) return resolve(true)\n readyWaiters.add(resolve)\n setTimeout(() => {\n readyWaiters.delete(resolve)\n resolve(ready)\n }, handshakeTimeout)\n ping()\n })\n\n const openLink = (ref: SourceRef) => {\n const url = buildAdminUrl(ref, { adminRoute: options.adminRoute, serverURL: adminOrigin })\n // In the iframe the fallback always opens a tab: navigating the iframe would show the admin in it\n if (inIframe || options.openIn !== 'same-tab') window.open(url, '_blank', 'noopener')\n else window.location.assign(url)\n }\n\n const edit = async (ref: SourceRef) => {\n if (inIframe && (await waitForReady())) {\n window.parent.postMessage(createFocusMessage(ref), adminOrigin)\n return\n }\n openLink(ref)\n }\n\n // --- Events\n const onPointerOver = (event: Event) => {\n const node = event.target as Node | null\n if (node && layer.contains(node)) {\n // On the edit button: keep the current target\n clearTimeout(hideTimer)\n hideTimer = undefined\n return\n }\n const target = findTarget(node, targets)\n if (target) {\n if (target.element !== current?.element) show(target)\n else clearTimeout(hideTimer)\n return\n }\n // Off editable content: hide a moment later, so the pointer can still reach the button\n if (current) {\n clearTimeout(hideTimer)\n hideTimer = setTimeout(() => show(null), HIDE_DELAY)\n }\n }\n\n const onButtonClick = (event: Event) => {\n event.preventDefault()\n event.stopPropagation()\n if (current) void edit(current.ref)\n }\n\n const onClick = (event: MouseEvent) => {\n if (!event.altKey) return\n const target = findTarget(event.target as Node | null, targets)\n if (!target) return\n // Alt-click on a link would otherwise download it\n event.preventDefault()\n event.stopPropagation()\n void edit(target.ref)\n }\n\n const observer = new window.MutationObserver((mutations) => {\n if (mutations.every((mutation) => layer.contains(mutation.target))) return\n rescanTimer ??= setTimeout(rescan, RESCAN_DELAY)\n })\n\n document.addEventListener('pointerover', onPointerOver)\n document.addEventListener('click', onClick, true)\n button.addEventListener('click', onButtonClick)\n window.addEventListener('scroll', schedulePlace, { capture: true, passive: true })\n window.addEventListener('resize', schedulePlace)\n window.addEventListener('message', onMessage)\n observer.observe(root, { subtree: true, childList: true, characterData: true, attributes: true })\n rescan()\n if (inIframe) ping()\n\n return {\n rescan,\n edit,\n destroy() {\n observer.disconnect()\n clearTimeout(rescanTimer)\n clearTimeout(hideTimer)\n if (frame) window.cancelAnimationFrame(frame)\n document.removeEventListener('pointerover', onPointerOver)\n document.removeEventListener('click', onClick, true)\n window.removeEventListener('scroll', schedulePlace, { capture: true })\n window.removeEventListener('resize', schedulePlace)\n window.removeEventListener('message', onMessage)\n for (const resolve of readyWaiters) resolve(false)\n readyWaiters.clear()\n layer.remove()\n },\n }\n}\n"],"names":["buildAdminUrl","createFocusMessage","createReadyMessage","isReadyMessage","findTarget","scanTargets","OVERLAY_ATTR","RESCAN_DELAY","HIDE_DELAY","PAD","RADIUS","createOverlay","options","document","root","ownerDocument","globalThis","window","defaultView","body","adminOrigin","URL","serverURL","location","origin","handshakeTimeout","inIframe","parent","layer","createElement","setAttribute","style","cssText","color","outline","button","type","textContent","label","appendChild","targets","Map","current","rescanTimer","hideTimer","frame","place","rect","element","getBoundingClientRect","box","top","left","right","bottom","Object","assign","display","width","height","offsetWidth","offsetHeight","viewportWidth","documentElement","clientWidth","innerWidth","Math","min","max","above","onCorner","borderRadius","borderTopRightRadius","schedulePlace","requestAnimationFrame","show","target","clearTimeout","undefined","rescan","has","ready","readyWaiters","Set","onMessage","event","source","data","resolve","clear","ping","postMessage","waitForReady","Promise","add","setTimeout","delete","openLink","ref","url","adminRoute","openIn","open","edit","onPointerOver","node","contains","onButtonClick","preventDefault","stopPropagation","onClick","altKey","observer","MutationObserver","mutations","every","mutation","addEventListener","capture","passive","observe","subtree","childList","characterData","attributes","destroy","disconnect","cancelAnimationFrame","removeEventListener","remove"],"mappings":"AAAA,SACEA,aAAa,EACbC,kBAAkB,EAClBC,kBAAkB,EAClBC,cAAc,QAET,wCAAuC;AAE9C,SAASC,UAAU,EAAEC,WAAW,QAAsB,YAAW;AAEjE,OAAO,MAAMC,eAAe,mBAAkB;AA2B9C,MAAMC,eAAe;AACrB,0FAA0F,GAC1F,MAAMC,aAAa;AACnB,2FAA2F,GAC3F,MAAMC,MAAM;AACZ,MAAMC,SAAS;AAEf;;;;;;CAMC,GACD,OAAO,SAASC,cAAcC,UAA0B,CAAC,CAAC;IACxD,MAAMC,WAAWD,QAAQE,IAAI,EAAEC,iBAAiBC,WAAWH,QAAQ;IACnE,MAAMI,SAASJ,SAASK,WAAW;IACnC,MAAMJ,OAAOF,QAAQE,IAAI,IAAID,SAASM,IAAI;IAC1C,MAAMC,cAAc,IAAIC,IAAIT,QAAQU,SAAS,IAAIL,OAAOM,QAAQ,CAACC,MAAM,EAAEA,MAAM;IAC/E,MAAMC,mBAAmBb,QAAQa,gBAAgB,IAAI;IACrD,MAAMC,WAAWT,OAAOU,MAAM,KAAKV;IAEnC,+EAA+E;IAC/E,MAAMW,QAAQf,SAASgB,aAAa,CAAC;IACrCD,MAAME,YAAY,CAACxB,cAAc;IACjCsB,MAAMG,KAAK,CAACC,OAAO,GAAG;IACtB,MAAMC,QAAQrB,QAAQqB,KAAK,IAAI;IAC/B,MAAMC,UAAUrB,SAASgB,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5B,OAAO8G,oBAAoB,CAAClF;YACvChC,SAASmH,mBAAmB,CAAC,eAAexB;YAC5C3F,SAASmH,mBAAmB,CAAC,SAASlB,SAAS;YAC/C7F,OAAO+G,mBAAmB,CAAC,UAAUvD,eAAe;gBAAE6C,SAAS;YAAK;YACpErG,OAAO+G,mBAAmB,CAAC,UAAUvD;YACrCxD,OAAO+G,mBAAmB,CAAC,WAAW5C;YACtC,KAAK,MAAMI,WAAWN,aAAcM,QAAQ;YAC5CN,aAAaO,KAAK;YAClB7D,MAAMqG,MAAM;QACd;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/vanilla/overlay.ts"],"sourcesContent":["import {\n buildAdminUrl,\n createFocusMessage,\n createReadyMessage,\n isReadyMessage,\n type SourceRef,\n} from '@derweili/payload-visual-editing-core'\n\nimport { findTarget, scanTargets, type Targets } from './scan.ts'\n\nexport const OVERLAY_ATTR = 'data-pve-overlay'\n/** The brand green of the docs; white text on it has a 4.6:1 contrast (WCAG AA). */\nexport const DEFAULT_COLOR = '#168b49'\nexport const DEFAULT_TEXT_COLOR = '#fff'\n\nexport interface OverlayOptions {\n /** Where to look for editable content. Default: `document.body`. */\n root?: Element\n /** Payload's admin route (`config.routes.admin`). Default: \"/admin\". */\n adminRoute?: string\n /** Origin of the Payload admin, e.g. \"https://cms.example.com\". Default: the page's own origin. */\n serverURL?: string\n /** Outside the Live Preview iframe: open the admin in a new tab (default) or in this tab. */\n openIn?: 'new-tab' | 'same-tab'\n /** Inside the iframe: how long to wait for the admin's `pve:ready` before opening the link. */\n handshakeTimeout?: number\n /** Text of the edit button. Default: \"Edit\". */\n label?: string\n /** Highlight colour: the outline and the button's background. Default: \"#168b49\" (green). */\n color?: string\n /** Text colour of the button. Default: \"#fff\". */\n textColor?: string\n}\n\nexport interface Overlay {\n /** Scans the page again; normally the MutationObserver does this. */\n rescan(): void\n /** Opens the editor for a ref, like a click on the edit button. */\n edit(ref: SourceRef): Promise<void>\n destroy(): void\n}\n\nconst RESCAN_DELAY = 100\n/** Time to move the pointer from the content to the edit button before the button hides. */\nconst HIDE_DELAY = 400\n/** Gap between the outline and the content, and between the button and the viewport edge. */\nconst PAD = 4\nconst RADIUS = '3px'\n\n/**\n * Outlines editable content on hover and shows an edit button.\n * - Standalone: the button opens the admin's deep link.\n * - Inside the admin's Live Preview iframe: it sends `pve:focus` to the parent. Without a\n * `pve:ready` from the admin within `handshakeTimeout`, it falls back to the deep link.\n * Alt/Option-click on editable content does the same as the button.\n */\nexport function createOverlay(options: OverlayOptions = {}): Overlay {\n const document = options.root?.ownerDocument ?? globalThis.document\n const window = document.defaultView!\n const root = options.root ?? document.body\n const adminOrigin = new URL(options.serverURL ?? window.location.origin).origin\n const handshakeTimeout = options.handshakeTimeout ?? 500\n const inIframe = window.parent !== window\n\n // --- UI: one fixed layer that never takes pointer events except on the button\n const layer = document.createElement('div')\n layer.setAttribute(OVERLAY_ATTR, '')\n layer.style.cssText = 'position:fixed;inset:0;pointer-events:none;z-index:2147483647;'\n const color = options.color ?? DEFAULT_COLOR\n const textColor = options.textColor ?? DEFAULT_TEXT_COLOR\n const outline = document.createElement('div')\n outline.style.cssText = `position:fixed;display:none;box-sizing:border-box;border:2px solid;border-radius:${RADIUS};`\n outline.style.borderColor = color\n const button = document.createElement('button')\n button.type = 'button'\n button.textContent = options.label ?? 'Edit'\n button.style.cssText =\n `position:fixed;display:none;pointer-events:auto;margin:0;padding:2px 8px;border:0;` +\n `font:600 12px/1.5 system-ui,sans-serif;cursor:pointer;`\n // Set apart from cssText: a colour value can't add other declarations\n button.style.background = color\n button.style.color = textColor\n // appendChild, not append: in apps with Cloudflare's worker types, `Element.append` is HTMLRewriter's\n layer.appendChild(outline)\n layer.appendChild(button)\n document.body.appendChild(layer)\n\n // --- State\n let targets: Targets = new Map()\n let current: { element: Element; ref: SourceRef } | null = null\n let rescanTimer: ReturnType<typeof setTimeout> | undefined\n let hideTimer: ReturnType<typeof setTimeout> | undefined\n let frame = 0\n\n const place = () => {\n frame = 0\n if (!current) return\n const rect = current.element.getBoundingClientRect()\n const box = {\n top: rect.top - PAD,\n left: rect.left - PAD,\n right: rect.right + PAD,\n bottom: rect.bottom + PAD,\n }\n Object.assign(outline.style, {\n display: 'block',\n top: `${box.top}px`,\n left: `${box.left}px`,\n width: `${box.right - box.left}px`,\n height: `${box.bottom - box.top}px`,\n })\n // Visible before measuring: a hidden button measures 0 × 0\n button.style.display = 'block'\n const { offsetWidth: width, offsetHeight: height } = button\n const viewportWidth = document.documentElement.clientWidth || window.innerWidth\n // Flush on the outline's top-right corner, so the pointer reaches it without leaving the\n // outline; inside the outline's top edge when there is no room above. Always in the viewport.\n const top = box.top >= height ? box.top - height : box.top\n const left = Math.min(Math.max(PAD, box.right - width), Math.max(PAD, viewportWidth - width - PAD))\n // Seamless joint: no rounding where the button meets the outline\n const above = top < box.top\n const onCorner = left === box.right - width\n Object.assign(button.style, {\n top: `${top}px`,\n left: `${left}px`,\n borderRadius: above ? `${RADIUS} ${RADIUS} 0 0` : `0 0 0 ${RADIUS}`,\n })\n outline.style.borderTopRightRadius = onCorner ? '0' : RADIUS\n }\n const schedulePlace = () => {\n if (current && !frame) frame = window.requestAnimationFrame(place)\n }\n\n const show = (target: { element: Element; ref: SourceRef } | null) => {\n clearTimeout(hideTimer)\n hideTimer = undefined\n current = target\n if (!target) {\n outline.style.display = 'none'\n button.style.display = 'none'\n return\n }\n place()\n }\n\n const rescan = () => {\n rescanTimer = undefined\n targets = scanTargets(root, layer)\n if (current && !targets.has(current.element)) show(null)\n }\n\n // --- Opening the editor\n let ready = false\n const readyWaiters = new Set<(ready: boolean) => void>()\n\n const onMessage = (event: MessageEvent) => {\n if (event.source !== window.parent || event.origin !== adminOrigin) return\n if (!isReadyMessage(event.data)) return\n ready = true\n for (const resolve of readyWaiters) resolve(true)\n readyWaiters.clear()\n }\n\n const ping = () => window.parent.postMessage(createReadyMessage(), adminOrigin)\n\n const waitForReady = () =>\n new Promise<boolean>((resolve) => {\n if (ready) return resolve(true)\n readyWaiters.add(resolve)\n setTimeout(() => {\n readyWaiters.delete(resolve)\n resolve(ready)\n }, handshakeTimeout)\n ping()\n })\n\n const openLink = (ref: SourceRef) => {\n const url = buildAdminUrl(ref, { adminRoute: options.adminRoute, serverURL: adminOrigin })\n // In the iframe the fallback always opens a tab: navigating the iframe would show the admin in it\n if (inIframe || options.openIn !== 'same-tab') window.open(url, '_blank', 'noopener')\n else window.location.assign(url)\n }\n\n const edit = async (ref: SourceRef) => {\n if (inIframe && (await waitForReady())) {\n window.parent.postMessage(createFocusMessage(ref), adminOrigin)\n return\n }\n openLink(ref)\n }\n\n // --- Events\n const onPointerOver = (event: Event) => {\n const node = event.target as Node | null\n if (node && layer.contains(node)) {\n // On the edit button: keep the current target\n clearTimeout(hideTimer)\n hideTimer = undefined\n return\n }\n const target = findTarget(node, targets)\n if (target) {\n if (target.element !== current?.element) show(target)\n else clearTimeout(hideTimer)\n return\n }\n // Off editable content: hide a moment later, so the pointer can still reach the button\n if (current) {\n clearTimeout(hideTimer)\n hideTimer = setTimeout(() => show(null), HIDE_DELAY)\n }\n }\n\n const onButtonClick = (event: Event) => {\n event.preventDefault()\n event.stopPropagation()\n if (current) void edit(current.ref)\n }\n\n const onClick = (event: MouseEvent) => {\n if (!event.altKey) return\n const target = findTarget(event.target as Node | null, targets)\n if (!target) return\n // Alt-click on a link would otherwise download it\n event.preventDefault()\n event.stopPropagation()\n void edit(target.ref)\n }\n\n const observer = new window.MutationObserver((mutations) => {\n if (mutations.every((mutation) => layer.contains(mutation.target))) return\n rescanTimer ??= setTimeout(rescan, RESCAN_DELAY)\n })\n\n document.addEventListener('pointerover', onPointerOver)\n document.addEventListener('click', onClick, true)\n button.addEventListener('click', onButtonClick)\n window.addEventListener('scroll', schedulePlace, { capture: true, passive: true })\n window.addEventListener('resize', schedulePlace)\n window.addEventListener('message', onMessage)\n observer.observe(root, { subtree: true, childList: true, characterData: true, attributes: true })\n rescan()\n if (inIframe) ping()\n\n return {\n rescan,\n edit,\n destroy() {\n observer.disconnect()\n clearTimeout(rescanTimer)\n clearTimeout(hideTimer)\n if (frame) window.cancelAnimationFrame(frame)\n document.removeEventListener('pointerover', onPointerOver)\n document.removeEventListener('click', onClick, true)\n window.removeEventListener('scroll', schedulePlace, { capture: true })\n window.removeEventListener('resize', schedulePlace)\n window.removeEventListener('message', onMessage)\n for (const resolve of readyWaiters) resolve(false)\n readyWaiters.clear()\n layer.remove()\n },\n }\n}\n"],"names":["buildAdminUrl","createFocusMessage","createReadyMessage","isReadyMessage","findTarget","scanTargets","OVERLAY_ATTR","DEFAULT_COLOR","DEFAULT_TEXT_COLOR","RESCAN_DELAY","HIDE_DELAY","PAD","RADIUS","createOverlay","options","document","root","ownerDocument","globalThis","window","defaultView","body","adminOrigin","URL","serverURL","location","origin","handshakeTimeout","inIframe","parent","layer","createElement","setAttribute","style","cssText","color","textColor","outline","borderColor","button","type","textContent","label","background","appendChild","targets","Map","current","rescanTimer","hideTimer","frame","place","rect","element","getBoundingClientRect","box","top","left","right","bottom","Object","assign","display","width","height","offsetWidth","offsetHeight","viewportWidth","documentElement","clientWidth","innerWidth","Math","min","max","above","onCorner","borderRadius","borderTopRightRadius","schedulePlace","requestAnimationFrame","show","target","clearTimeout","undefined","rescan","has","ready","readyWaiters","Set","onMessage","event","source","data","resolve","clear","ping","postMessage","waitForReady","Promise","add","setTimeout","delete","openLink","ref","url","adminRoute","openIn","open","edit","onPointerOver","node","contains","onButtonClick","preventDefault","stopPropagation","onClick","altKey","observer","MutationObserver","mutations","every","mutation","addEventListener","capture","passive","observe","subtree","childList","characterData","attributes","destroy","disconnect","cancelAnimationFrame","removeEventListener","remove"],"mappings":"AAAA,SACEA,aAAa,EACbC,kBAAkB,EAClBC,kBAAkB,EAClBC,cAAc,QAET,wCAAuC;AAE9C,SAASC,UAAU,EAAEC,WAAW,QAAsB,YAAW;AAEjE,OAAO,MAAMC,eAAe,mBAAkB;AAC9C,kFAAkF,GAClF,OAAO,MAAMC,gBAAgB,U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G,MAAM;QACd;IACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@derweili/payload-visual-editing-overlay",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Frontend overlay for Payload visual editing: outlines, edit buttons, links back to the admin",
5
5
  "keywords": [
6
6
  "payload",
@@ -43,7 +43,7 @@
43
43
  "LICENSE"
44
44
  ],
45
45
  "dependencies": {
46
- "@derweili/payload-visual-editing-core": "0.1.0"
46
+ "@derweili/payload-visual-editing-core": "0.1.2"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "react": "^18.0.0 || ^19.0.0"