@derweili/payload-visual-editing-overlay 0.0.0-stage → 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # @derweili/payload-visual-editing-overlay
2
+
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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.
8
+
9
+ - Updated dependencies [[`5bdb1f5`](https://github.com/derweili/payload-visual-editing/commit/5bdb1f56012fec706d7e00cc84f55292072e5b46)]:
10
+ - @derweili/payload-visual-editing-core@0.1.1
11
+
12
+ ## 0.1.0
13
+
14
+ First release.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Julian Weiland
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,145 @@
1
- # Temporary Holding Version
1
+ # @derweili/payload-visual-editing-overlay
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The frontend part of Payload visual editing. Everything in a page that comes from Payload gets a
4
+ hover outline and an "Edit" button. The button opens the field in the admin, or focuses it next to
5
+ the page in the Live Preview.
6
+
7
+ Needs [`@derweili/payload-visual-editing`](../payload-visual-editing) in the Payload config.
8
+ Overview: [README](../../README.md).
9
+
10
+ | Entry | For |
11
+ | --- | --- |
12
+ | `/react` | `<VisualEditing />` (a client component), plus `fieldAttrs` and `stegaClean` |
13
+ | `/vanilla` | Framework-agnostic: `createOverlay()`, `fieldAttrs`, `stegaClean`, `stegaSplitParts`, `sourceOf`, `fieldSourceOf`. Safe in server components (no `'use client'`) |
14
+
15
+ ## Setup (Next.js)
16
+
17
+ 1. Read drafts with source maps (see the plugin README), only in Draft Mode:
18
+
19
+ ```ts
20
+ const { isEnabled: draft } = await draftMode()
21
+ const page = await payload.findByID({
22
+ collection: 'pages',
23
+ id,
24
+ draft,
25
+ context: draft ? { encodeSourceMaps: true } : {},
26
+ })
27
+ ```
28
+
29
+ 2. Mount the overlay in Draft Mode, e.g. in the root layout:
30
+
31
+ ```tsx
32
+ import { VisualEditing } from '@derweili/payload-visual-editing-overlay/react'
33
+
34
+ {draft && <VisualEditing label="Edit" />}
35
+ ```
36
+
37
+ 3. Render text as usual. The encoded characters are invisible and the overlay finds them. Clean
38
+ every string that feeds logic rather than display (see "stegaClean pitfalls" below).
39
+
40
+ The admin's Live Preview needs nothing extra: inside its iframe the overlay talks to the admin
41
+ through `postMessage`.
42
+
43
+ ### `<VisualEditing />` / `createOverlay()` options
44
+
45
+ | Option | Default | |
46
+ | --- | --- | --- |
47
+ | `label` | `"Edit"` | Text of the button |
48
+ | `color` | a blue | Outline and button colour |
49
+ | `adminRoute` | `"/admin"` | Payload's `routes.admin` |
50
+ | `serverURL` | the page's origin | Origin of the admin, when it runs on another domain |
51
+ | `openIn` | `"new-tab"` | Outside the Live Preview: `"same-tab"` navigates instead |
52
+ | `handshakeTimeout` | `500` | In the Live Preview: ms to wait for the admin before opening a new tab |
53
+ | `root` (vanilla only) | `document.body` | Where to look for editable content |
54
+
55
+ `createOverlay()` returns `{ rescan(), edit(ref), destroy() }`. A MutationObserver rescans on its
56
+ own when the page changes.
57
+
58
+ Holding Alt while clicking editable content also opens it, without the button.
59
+
60
+ ## stegaClean pitfalls
61
+
62
+ Encoded strings look normal but aren't equal to their visible text: `"Home" !== "Home\u200b…"`. Use
63
+ `stegaClean(value)` (works on strings, arrays and objects) wherever a string is used for more than
64
+ display:
65
+
66
+ - **Comparisons and lookups:** `===`, `switch`, `includes`, map keys, sorting, `localeCompare`.
67
+ - **URLs and identifiers:** slugs, `href`, `id`/`className`, `key`. Better: exclude these fields in
68
+ the plugin (`slug` and `url` are excluded by default).
69
+ - **Metadata:** `<title>`, `generateMetadata`, Open Graph, JSON-LD. Hidden characters there end up
70
+ in search results and shares.
71
+ - **Form values:** `<option value>`, hidden inputs, anything submitted back.
72
+ - **Parsing and measuring:** `JSON.parse`, `Number()`, `new Date()`, `length`, truncation.
73
+ - **`split` and `trim`:** the hidden ref sits at the end of the string, so after `split('\n')` only
74
+ the last part keeps it, and `trim()` can damage it (U+FEFF counts as whitespace). Use
75
+ `stegaSplitParts(text, /\n{2,}/, (part) => part.trim())`: it splits the visible text and gives
76
+ every part the ref.
77
+
78
+ Text fields that only feed logic belong in the plugin's `exclude`, so they arrive clean.
79
+
80
+ ## Images, numbers and other values without text
81
+
82
+ Text needs nothing from the frontend: the source travels inside the string as invisible characters.
83
+ Images, numbers, selects, dates, relationships and URL-like text can't carry those characters. For
84
+ them the plugin attaches a **source tag** when it encodes a document, and the frontend renders it as
85
+ `data-` attributes with `fieldAttrs()`.
86
+
87
+ ### 1. Fetch with encoding on (Draft Mode only)
88
+
89
+ ```ts
90
+ const doc = await payload.findByID({
91
+ collection: 'pages',
92
+ id,
93
+ depth: 1,
94
+ draft: true,
95
+ context: { encodeSourceMaps: true },
96
+ })
97
+ ```
98
+
99
+ ### 2. Render the attributes
100
+
101
+ In a **server component** that receives the Payload document:
102
+
103
+ ```tsx
104
+ import { fieldAttrs, fieldSourceOf, sourceOf } from '@derweili/payload-visual-editing-overlay/vanilla'
105
+
106
+ <img {...fieldAttrs(sourceOf(doc.image))} src={doc.image.url} alt={doc.image.alt} />
107
+ <span {...fieldAttrs(fieldSourceOf(doc, 'year'))}>{doc.year}</span>
108
+ ```
109
+
110
+ - `sourceOf(value)`: populated uploads and relationships. They are objects, so the tag sits on the
111
+ value itself (each item of a `hasMany` field is tagged).
112
+ - `fieldSourceOf(parent, 'name')`: numbers, selects, dates, … Primitives can't hold a tag, so it
113
+ sits on the object that contains them.
114
+ - `fieldAttrs(null)` returns `{}`: outside Draft Mode the same code renders nothing extra.
115
+
116
+ ### 3. Client components: pass the source as a prop
117
+
118
+ Tags are stored under symbol keys and don't survive React's serialization to client components. Read
119
+ them on the server, in your mapping code, and pass the plain `SourceLocation`
120
+ (`{ collection | global, id?, path, locale? }`) on:
121
+
122
+ ```ts
123
+ // server: mapping code
124
+ const toImage = (media: Media) => ({ url: media.url, alt: media.alt, source: sourceOf(media) })
125
+ ```
126
+
127
+ ```tsx
128
+ // any component, client or server
129
+ <img {...fieldAttrs(image.source)} src={image.url} alt={image.alt} />
130
+ ```
131
+
132
+ Doing it once in a shared mapper and image component covers every image of a site.
133
+
134
+ ### 4. Mount the overlay
135
+
136
+ `<VisualEditing />` (from `/react`) in Draft Mode, as for text.
137
+
138
+ ### Where tags survive, and where not
139
+
140
+ | Survives | Lost |
141
+ | --- | --- |
142
+ | object spread (`{ ...doc }`), `Object.assign` | `JSON.stringify`, `structuredClone` |
143
+ | passing objects around on the server | props sent to client components |
144
+ | | caches that serialize (e.g. `unstable_cache`): don't cache Draft Mode reads |
145
+ | | copying fields one by one (`{ url: media.url }`): read `sourceOf(media)` there |
@@ -0,0 +1,8 @@
1
+ import { type OverlayOptions } from '../vanilla/overlay.ts';
2
+ export type VisualEditingProps = Omit<OverlayOptions, 'root'>;
3
+ /**
4
+ * Mount in Draft Mode only, e.g. in the root layout:
5
+ * `{draft && <VisualEditing label="Bearbeiten" />}`. Renders nothing itself.
6
+ */
7
+ export declare function VisualEditing({ adminRoute, serverURL, openIn, handshakeTimeout, label, color }: VisualEditingProps): null;
8
+ //# sourceMappingURL=VisualEditing.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,29 @@
1
+ 'use client';
2
+ import { useEffect } from 'react';
3
+ import { createOverlay } from "../vanilla/overlay.js";
4
+ /**
5
+ * Mount in Draft Mode only, e.g. in the root layout:
6
+ * `{draft && <VisualEditing label="Bearbeiten" />}`. Renders nothing itself.
7
+ */ export function VisualEditing({ adminRoute, serverURL, openIn, handshakeTimeout, label, color }) {
8
+ useEffect(()=>{
9
+ const overlay = createOverlay({
10
+ adminRoute,
11
+ serverURL,
12
+ openIn,
13
+ handshakeTimeout,
14
+ label,
15
+ color
16
+ });
17
+ return ()=>overlay.destroy();
18
+ }, [
19
+ adminRoute,
20
+ serverURL,
21
+ openIn,
22
+ handshakeTimeout,
23
+ label,
24
+ color
25
+ ]);
26
+ return null;
27
+ }
28
+
29
+ //# sourceMappingURL=VisualEditing.js.map
@@ -0,0 +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"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * React entry: <VisualEditing />. A client module: server components import `stegaClean` and
3
+ * `fieldAttrs` from `./vanilla` instead (functions from a 'use client' module aren't callable there).
4
+ */
5
+ export { VisualEditing, type VisualEditingProps } from './VisualEditing.tsx';
6
+ export { fieldAttrs, stegaClean } from '../vanilla/index.ts';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC5E,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,8 @@
1
+ 'use client';
2
+ /**
3
+ * React entry: <VisualEditing />. A client module: server components import `stegaClean` and
4
+ * `fieldAttrs` from `./vanilla` instead (functions from a 'use client' module aren't callable there).
5
+ */ export { VisualEditing } from "./VisualEditing.jsx";
6
+ export { fieldAttrs, stegaClean } from "../vanilla/index.js";
7
+
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/react/index.ts"],"sourcesContent":["'use client'\n/**\n * React entry: <VisualEditing />. A client module: server components import `stegaClean` and\n * `fieldAttrs` from `./vanilla` instead (functions from a 'use client' module aren't callable there).\n */\nexport { VisualEditing, type VisualEditingProps } from './VisualEditing.tsx'\nexport { fieldAttrs, stegaClean } from '../vanilla/index.ts'\n"],"names":["VisualEditing","fieldAttrs","stegaClean"],"mappings":"AAAA;AACA;;;CAGC,GACD,SAASA,aAAa,QAAiC,sBAAqB;AAC5E,SAASC,UAAU,EAAEC,UAAU,QAAQ,sBAAqB"}
@@ -0,0 +1,20 @@
1
+ import { type SourceLocation, type SourceRef } from '@derweili/payload-visual-editing-core';
2
+ /**
3
+ * Marks an element that can't carry stega text (image, number, link target) as editable.
4
+ * Namespaced so they can't clash with other libraries' `data-*` attributes.
5
+ */
6
+ export declare const DOC_ATTR = "data-pve-doc";
7
+ export declare const PATH_ATTR = "data-pve-path";
8
+ export declare const LOCALE_ATTR = "data-pve-locale";
9
+ export type FieldAttrs = Partial<Record<typeof DOC_ATTR | typeof PATH_ATTR | typeof LOCALE_ATTR, string>>;
10
+ /**
11
+ * Attributes to spread onto an element: `<img {...fieldAttrs(source)} />`.
12
+ * Returns `{}` without a source, so callers pass one only in Draft Mode:
13
+ * `fieldAttrs(draft ? { collection: 'projects', id, path: 'cover' } : null)`.
14
+ *
15
+ * `data-pve-doc` is `collections/<slug>/<id>` or `globals/<slug>`, as in the admin URL.
16
+ */
17
+ export declare function fieldAttrs(source: SourceLocation | null | undefined): FieldAttrs;
18
+ /** Reads the attributes back into a ref; null when the element isn't (validly) marked. */
19
+ export declare function readFieldAttrs(element: Element): SourceRef | null;
20
+ //# sourceMappingURL=attributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/vanilla/attributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,uCAAuC,CAAA;AAEtG;;;GAGG;AACH,eAAO,MAAM,QAAQ,iBAAiB,CAAA;AACtC,eAAO,MAAM,SAAS,kBAAkB,CAAA;AACxC,eAAO,MAAM,WAAW,oBAAoB,CAAA;AAE5C,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,QAAQ,GAAG,OAAO,SAAS,GAAG,OAAO,WAAW,EAAE,MAAM,CAAC,CAAC,CAAA;AAEzG;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,GAAG,UAAU,CAWhF;AAED,0FAA0F;AAC1F,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAejE"}
@@ -0,0 +1,54 @@
1
+ import { encodeRef } from '@derweili/payload-visual-editing-core';
2
+ /**
3
+ * Marks an element that can't carry stega text (image, number, link target) as editable.
4
+ * Namespaced so they can't clash with other libraries' `data-*` attributes.
5
+ */ export const DOC_ATTR = 'data-pve-doc';
6
+ export const PATH_ATTR = 'data-pve-path';
7
+ export const LOCALE_ATTR = 'data-pve-locale';
8
+ /**
9
+ * Attributes to spread onto an element: `<img {...fieldAttrs(source)} />`.
10
+ * Returns `{}` without a source, so callers pass one only in Draft Mode:
11
+ * `fieldAttrs(draft ? { collection: 'projects', id, path: 'cover' } : null)`.
12
+ *
13
+ * `data-pve-doc` is `collections/<slug>/<id>` or `globals/<slug>`, as in the admin URL.
14
+ */ export function fieldAttrs(source) {
15
+ if (!source) return {};
16
+ const doc = 'global' in source && source.global ? `globals/${source.global}` : `collections/${source.collection}/${source.id}`;
17
+ return {
18
+ [DOC_ATTR]: doc,
19
+ [PATH_ATTR]: source.path,
20
+ ...source.locale ? {
21
+ [LOCALE_ATTR]: source.locale
22
+ } : {}
23
+ };
24
+ }
25
+ /** Reads the attributes back into a ref; null when the element isn't (validly) marked. */ export function readFieldAttrs(element) {
26
+ const doc = element.getAttribute(DOC_ATTR);
27
+ const path = element.getAttribute(PATH_ATTR);
28
+ if (!doc || path === null) return null;
29
+ const locale = element.getAttribute(LOCALE_ATTR) || undefined;
30
+ const [kind, slug, ...rest] = doc.split('/');
31
+ if (kind === 'globals' && slug && rest.length === 0) {
32
+ return encodeRef({
33
+ global: slug,
34
+ path,
35
+ ...locale ? {
36
+ locale
37
+ } : {}
38
+ });
39
+ }
40
+ if (kind === 'collections' && slug && rest.length === 1 && rest[0]) {
41
+ // Ids come back as strings; numeric ids are fine in admin URLs either way
42
+ return encodeRef({
43
+ collection: slug,
44
+ id: rest[0],
45
+ path,
46
+ ...locale ? {
47
+ locale
48
+ } : {}
49
+ });
50
+ }
51
+ return null;
52
+ }
53
+
54
+ //# sourceMappingURL=attributes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/vanilla/attributes.ts"],"sourcesContent":["import { encodeRef, type SourceLocation, type SourceRef } from '@derweili/payload-visual-editing-core'\n\n/**\n * Marks an element that can't carry stega text (image, number, link target) as editable.\n * Namespaced so they can't clash with other libraries' `data-*` attributes.\n */\nexport const DOC_ATTR = 'data-pve-doc'\nexport const PATH_ATTR = 'data-pve-path'\nexport const LOCALE_ATTR = 'data-pve-locale'\n\nexport type FieldAttrs = Partial<Record<typeof DOC_ATTR | typeof PATH_ATTR | typeof LOCALE_ATTR, string>>\n\n/**\n * Attributes to spread onto an element: `<img {...fieldAttrs(source)} />`.\n * Returns `{}` without a source, so callers pass one only in Draft Mode:\n * `fieldAttrs(draft ? { collection: 'projects', id, path: 'cover' } : null)`.\n *\n * `data-pve-doc` is `collections/<slug>/<id>` or `globals/<slug>`, as in the admin URL.\n */\nexport function fieldAttrs(source: SourceLocation | null | undefined): FieldAttrs {\n if (!source) return {}\n const doc =\n 'global' in source && source.global\n ? `globals/${source.global}`\n : `collections/${source.collection}/${source.id}`\n return {\n [DOC_ATTR]: doc,\n [PATH_ATTR]: source.path,\n ...(source.locale ? { [LOCALE_ATTR]: source.locale } : {}),\n }\n}\n\n/** Reads the attributes back into a ref; null when the element isn't (validly) marked. */\nexport function readFieldAttrs(element: Element): SourceRef | null {\n const doc = element.getAttribute(DOC_ATTR)\n const path = element.getAttribute(PATH_ATTR)\n if (!doc || path === null) return null\n const locale = element.getAttribute(LOCALE_ATTR) || undefined\n\n const [kind, slug, ...rest] = doc.split('/')\n if (kind === 'globals' && slug && rest.length === 0) {\n return encodeRef({ global: slug, path, ...(locale ? { locale } : {}) })\n }\n if (kind === 'collections' && slug && rest.length === 1 && rest[0]) {\n // Ids come back as strings; numeric ids are fine in admin URLs either way\n return encodeRef({ collection: slug, id: rest[0], path, ...(locale ? { locale } : {}) })\n }\n return null\n}\n"],"names":["encodeRef","DOC_ATTR","PATH_ATTR","LOCALE_ATTR","fieldAttrs","source","doc","global","collection","id","path","locale","readFieldAttrs","element","getAttribute","undefined","kind","slug","rest","split","length"],"mappings":"AAAA,SAASA,SAAS,QAA6C,wCAAuC;AAEtG;;;CAGC,GACD,OAAO,MAAMC,WAAW,eAAc;AACtC,OAAO,MAAMC,YAAY,gBAAe;AACxC,OAAO,MAAMC,cAAc,kBAAiB;AAI5C;;;;;;CAMC,GACD,OAAO,SAASC,WAAWC,MAAyC;IAClE,IAAI,CAACA,QAAQ,OAAO,CAAC;IACrB,MAAMC,MACJ,YAAYD,UAAUA,OAAOE,MAAM,GAC/B,CAAC,QAAQ,EAAEF,OAAOE,MAAM,EAAE,GAC1B,CAAC,YAAY,EAAEF,OAAOG,UAAU,CAAC,CAAC,EAAEH,OAAOI,EAAE,EAAE;IACrD,OAAO;QACL,CAACR,SAAS,EAAEK;QACZ,CAACJ,UAAU,EAAEG,OAAOK,IAAI;QACxB,GAAIL,OAAOM,MAAM,GAAG;YAAE,CAACR,YAAY,EAAEE,OAAOM,MAAM;QAAC,IAAI,CAAC,CAAC;IAC3D;AACF;AAEA,wFAAwF,GACxF,OAAO,SAASC,eAAeC,OAAgB;IAC7C,MAAMP,MAAMO,QAAQC,YAAY,CAACb;IACjC,MAAMS,OAAOG,QAAQC,YAAY,CAACZ;IAClC,IAAI,CAACI,OAAOI,SAAS,MAAM,OAAO;IAClC,MAAMC,SAASE,QAAQC,YAAY,CAACX,gBAAgBY;IAEpD,MAAM,CAACC,MAAMC,MAAM,GAAGC,KAAK,GAAGZ,IAAIa,KAAK,CAAC;IACxC,IAAIH,SAAS,aAAaC,QAAQC,KAAKE,MAAM,KAAK,GAAG;QACnD,OAAOpB,UAAU;YAAEO,QAAQU;YAAMP;YAAM,GAAIC,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;QAAE;IACvE;IACA,IAAIK,SAAS,iBAAiBC,QAAQC,KAAKE,MAAM,KAAK,KAAKF,IAAI,CAAC,EAAE,EAAE;QAClE,0EAA0E;QAC1E,OAAOlB,UAAU;YAAEQ,YAAYS;YAAMR,IAAIS,IAAI,CAAC,EAAE;YAAER;YAAM,GAAIC,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;QAAE;IACxF;IACA,OAAO;AACT"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Framework-agnostic overlay: DOM scan, outlines, edit button, links back to the admin.
3
+ * Safe to import in server code (no 'use client'): `stegaClean` and `fieldAttrs` come from here.
4
+ */
5
+ export { fieldSourceOf, sourceOf, stegaClean, stegaSplitParts, type SourceLocation, } from '@derweili/payload-visual-editing-core';
6
+ export { DOC_ATTR, LOCALE_ATTR, PATH_ATTR, fieldAttrs, readFieldAttrs, type FieldAttrs } from './attributes.ts';
7
+ export { OVERLAY_ATTR, createOverlay, type Overlay, type OverlayOptions } from './overlay.ts';
8
+ export { findTarget, scanTargets, type Targets } from './scan.ts';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vanilla/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,aAAa,EACb,QAAQ,EACR,UAAU,EACV,eAAe,EACf,KAAK,cAAc,GACpB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC/G,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7F,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAA"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Framework-agnostic overlay: DOM scan, outlines, edit button, links back to the admin.
3
+ * Safe to import in server code (no 'use client'): `stegaClean` and `fieldAttrs` come from here.
4
+ */ export { fieldSourceOf, sourceOf, stegaClean, stegaSplitParts } from '@derweili/payload-visual-editing-core';
5
+ export { DOC_ATTR, LOCALE_ATTR, PATH_ATTR, fieldAttrs, readFieldAttrs } from "./attributes.js";
6
+ export { OVERLAY_ATTR, createOverlay } from "./overlay.js";
7
+ export { findTarget, scanTargets } from "./scan.js";
8
+
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/vanilla/index.ts"],"sourcesContent":["/**\n * Framework-agnostic overlay: DOM scan, outlines, edit button, links back to the admin.\n * Safe to import in server code (no 'use client'): `stegaClean` and `fieldAttrs` come from here.\n */\nexport {\n fieldSourceOf,\n sourceOf,\n stegaClean,\n stegaSplitParts,\n type SourceLocation,\n} from '@derweili/payload-visual-editing-core'\nexport { DOC_ATTR, LOCALE_ATTR, PATH_ATTR, fieldAttrs, readFieldAttrs, type FieldAttrs } from './attributes.ts'\nexport { OVERLAY_ATTR, createOverlay, type Overlay, type OverlayOptions } from './overlay.ts'\nexport { findTarget, scanTargets, type Targets } from './scan.ts'\n"],"names":["fieldSourceOf","sourceOf","stegaClean","stegaSplitParts","DOC_ATTR","LOCALE_ATTR","PATH_ATTR","fieldAttrs","readFieldAttrs","OVERLAY_ATTR","createOverlay","findTarget","scanTargets"],"mappings":"AAAA;;;CAGC,GACD,SACEA,aAAa,EACbC,QAAQ,EACRC,UAAU,EACVC,eAAe,QAEV,wCAAuC;AAC9C,SAASC,QAAQ,EAAEC,WAAW,EAAEC,SAAS,EAAEC,UAAU,EAAEC,cAAc,QAAyB,kBAAiB;AAC/G,SAASC,YAAY,EAAEC,aAAa,QAA2C,eAAc;AAC7F,SAASC,UAAU,EAAEC,WAAW,QAAsB,YAAW"}
@@ -0,0 +1,34 @@
1
+ import { type SourceRef } from '@derweili/payload-visual-editing-core';
2
+ export declare const OVERLAY_ATTR = "data-pve-overlay";
3
+ export interface OverlayOptions {
4
+ /** Where to look for editable content. Default: `document.body`. */
5
+ root?: Element;
6
+ /** Payload's admin route (`config.routes.admin`). Default: "/admin". */
7
+ adminRoute?: string;
8
+ /** Origin of the Payload admin, e.g. "https://cms.example.com". Default: the page's own origin. */
9
+ serverURL?: string;
10
+ /** Outside the Live Preview iframe: open the admin in a new tab (default) or in this tab. */
11
+ openIn?: 'new-tab' | 'same-tab';
12
+ /** Inside the iframe: how long to wait for the admin's `pve:ready` before opening the link. */
13
+ handshakeTimeout?: number;
14
+ /** Text of the edit button. Default: "Edit". */
15
+ label?: string;
16
+ /** Outline and button colour. Default: a blue that reads on light and dark pages. */
17
+ color?: string;
18
+ }
19
+ export interface Overlay {
20
+ /** Scans the page again; normally the MutationObserver does this. */
21
+ rescan(): void;
22
+ /** Opens the editor for a ref, like a click on the edit button. */
23
+ edit(ref: SourceRef): Promise<void>;
24
+ destroy(): void;
25
+ }
26
+ /**
27
+ * Outlines editable content on hover and shows an edit button.
28
+ * - Standalone: the button opens the admin's deep link.
29
+ * - Inside the admin's Live Preview iframe: it sends `pve:focus` to the parent. Without a
30
+ * `pve:ready` from the admin within `handshakeTimeout`, it falls back to the deep link.
31
+ * Alt/Option-click on editable content does the same as the button.
32
+ */
33
+ export declare function createOverlay(options?: OverlayOptions): Overlay;
34
+ //# sourceMappingURL=overlay.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,210 @@
1
+ import { buildAdminUrl, createFocusMessage, createReadyMessage, isReadyMessage } from '@derweili/payload-visual-editing-core';
2
+ import { findTarget, scanTargets } from "./scan.js";
3
+ export const OVERLAY_ATTR = 'data-pve-overlay';
4
+ const RESCAN_DELAY = 100;
5
+ /** Time to move the pointer from the content to the edit button before the button hides. */ const HIDE_DELAY = 400;
6
+ /** Gap between the outline and the content, and between the button and the viewport edge. */ const PAD = 4;
7
+ const RADIUS = '3px';
8
+ /**
9
+ * Outlines editable content on hover and shows an edit button.
10
+ * - Standalone: the button opens the admin's deep link.
11
+ * - Inside the admin's Live Preview iframe: it sends `pve:focus` to the parent. Without a
12
+ * `pve:ready` from the admin within `handshakeTimeout`, it falls back to the deep link.
13
+ * Alt/Option-click on editable content does the same as the button.
14
+ */ export function createOverlay(options = {}) {
15
+ const document = options.root?.ownerDocument ?? globalThis.document;
16
+ const window = document.defaultView;
17
+ const root = options.root ?? document.body;
18
+ const adminOrigin = new URL(options.serverURL ?? window.location.origin).origin;
19
+ const handshakeTimeout = options.handshakeTimeout ?? 500;
20
+ const inIframe = window.parent !== window;
21
+ // --- UI: one fixed layer that never takes pointer events except on the button
22
+ const layer = document.createElement('div');
23
+ layer.setAttribute(OVERLAY_ATTR, '');
24
+ layer.style.cssText = 'position:fixed;inset:0;pointer-events:none;z-index:2147483647;';
25
+ const color = options.color ?? '#2563eb';
26
+ const outline = document.createElement('div');
27
+ outline.style.cssText = `position:fixed;display:none;box-sizing:border-box;border:2px solid ${color};border-radius:${RADIUS};`;
28
+ const button = document.createElement('button');
29
+ button.type = 'button';
30
+ 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;`;
32
+ // appendChild, not append: in apps with Cloudflare's worker types, `Element.append` is HTMLRewriter's
33
+ layer.appendChild(outline);
34
+ layer.appendChild(button);
35
+ document.body.appendChild(layer);
36
+ // --- State
37
+ let targets = new Map();
38
+ let current = null;
39
+ let rescanTimer;
40
+ let hideTimer;
41
+ let frame = 0;
42
+ const place = ()=>{
43
+ frame = 0;
44
+ if (!current) return;
45
+ const rect = current.element.getBoundingClientRect();
46
+ const box = {
47
+ top: rect.top - PAD,
48
+ left: rect.left - PAD,
49
+ right: rect.right + PAD,
50
+ bottom: rect.bottom + PAD
51
+ };
52
+ Object.assign(outline.style, {
53
+ display: 'block',
54
+ top: `${box.top}px`,
55
+ left: `${box.left}px`,
56
+ width: `${box.right - box.left}px`,
57
+ height: `${box.bottom - box.top}px`
58
+ });
59
+ // Visible before measuring: a hidden button measures 0 × 0
60
+ button.style.display = 'block';
61
+ const { offsetWidth: width, offsetHeight: height } = button;
62
+ const viewportWidth = document.documentElement.clientWidth || window.innerWidth;
63
+ // Flush on the outline's top-right corner, so the pointer reaches it without leaving the
64
+ // outline; inside the outline's top edge when there is no room above. Always in the viewport.
65
+ const top = box.top >= height ? box.top - height : box.top;
66
+ const left = Math.min(Math.max(PAD, box.right - width), Math.max(PAD, viewportWidth - width - PAD));
67
+ // Seamless joint: no rounding where the button meets the outline
68
+ const above = top < box.top;
69
+ const onCorner = left === box.right - width;
70
+ Object.assign(button.style, {
71
+ top: `${top}px`,
72
+ left: `${left}px`,
73
+ borderRadius: above ? `${RADIUS} ${RADIUS} 0 0` : `0 0 0 ${RADIUS}`
74
+ });
75
+ outline.style.borderTopRightRadius = onCorner ? '0' : RADIUS;
76
+ };
77
+ const schedulePlace = ()=>{
78
+ if (current && !frame) frame = window.requestAnimationFrame(place);
79
+ };
80
+ const show = (target)=>{
81
+ clearTimeout(hideTimer);
82
+ hideTimer = undefined;
83
+ current = target;
84
+ if (!target) {
85
+ outline.style.display = 'none';
86
+ button.style.display = 'none';
87
+ return;
88
+ }
89
+ place();
90
+ };
91
+ const rescan = ()=>{
92
+ rescanTimer = undefined;
93
+ targets = scanTargets(root, layer);
94
+ if (current && !targets.has(current.element)) show(null);
95
+ };
96
+ // --- Opening the editor
97
+ let ready = false;
98
+ const readyWaiters = new Set();
99
+ const onMessage = (event)=>{
100
+ if (event.source !== window.parent || event.origin !== adminOrigin) return;
101
+ if (!isReadyMessage(event.data)) return;
102
+ ready = true;
103
+ for (const resolve of readyWaiters)resolve(true);
104
+ readyWaiters.clear();
105
+ };
106
+ const ping = ()=>window.parent.postMessage(createReadyMessage(), adminOrigin);
107
+ const waitForReady = ()=>new Promise((resolve)=>{
108
+ if (ready) return resolve(true);
109
+ readyWaiters.add(resolve);
110
+ setTimeout(()=>{
111
+ readyWaiters.delete(resolve);
112
+ resolve(ready);
113
+ }, handshakeTimeout);
114
+ ping();
115
+ });
116
+ const openLink = (ref)=>{
117
+ const url = buildAdminUrl(ref, {
118
+ adminRoute: options.adminRoute,
119
+ serverURL: adminOrigin
120
+ });
121
+ // In the iframe the fallback always opens a tab: navigating the iframe would show the admin in it
122
+ if (inIframe || options.openIn !== 'same-tab') window.open(url, '_blank', 'noopener');
123
+ else window.location.assign(url);
124
+ };
125
+ const edit = async (ref)=>{
126
+ if (inIframe && await waitForReady()) {
127
+ window.parent.postMessage(createFocusMessage(ref), adminOrigin);
128
+ return;
129
+ }
130
+ openLink(ref);
131
+ };
132
+ // --- Events
133
+ const onPointerOver = (event)=>{
134
+ const node = event.target;
135
+ if (node && layer.contains(node)) {
136
+ // On the edit button: keep the current target
137
+ clearTimeout(hideTimer);
138
+ hideTimer = undefined;
139
+ return;
140
+ }
141
+ const target = findTarget(node, targets);
142
+ if (target) {
143
+ if (target.element !== current?.element) show(target);
144
+ else clearTimeout(hideTimer);
145
+ return;
146
+ }
147
+ // Off editable content: hide a moment later, so the pointer can still reach the button
148
+ if (current) {
149
+ clearTimeout(hideTimer);
150
+ hideTimer = setTimeout(()=>show(null), HIDE_DELAY);
151
+ }
152
+ };
153
+ const onButtonClick = (event)=>{
154
+ event.preventDefault();
155
+ event.stopPropagation();
156
+ if (current) void edit(current.ref);
157
+ };
158
+ const onClick = (event)=>{
159
+ if (!event.altKey) return;
160
+ const target = findTarget(event.target, targets);
161
+ if (!target) return;
162
+ // Alt-click on a link would otherwise download it
163
+ event.preventDefault();
164
+ event.stopPropagation();
165
+ void edit(target.ref);
166
+ };
167
+ const observer = new window.MutationObserver((mutations)=>{
168
+ if (mutations.every((mutation)=>layer.contains(mutation.target))) return;
169
+ rescanTimer ??= setTimeout(rescan, RESCAN_DELAY);
170
+ });
171
+ document.addEventListener('pointerover', onPointerOver);
172
+ document.addEventListener('click', onClick, true);
173
+ button.addEventListener('click', onButtonClick);
174
+ window.addEventListener('scroll', schedulePlace, {
175
+ capture: true,
176
+ passive: true
177
+ });
178
+ window.addEventListener('resize', schedulePlace);
179
+ window.addEventListener('message', onMessage);
180
+ observer.observe(root, {
181
+ subtree: true,
182
+ childList: true,
183
+ characterData: true,
184
+ attributes: true
185
+ });
186
+ rescan();
187
+ if (inIframe) ping();
188
+ return {
189
+ rescan,
190
+ edit,
191
+ destroy () {
192
+ observer.disconnect();
193
+ clearTimeout(rescanTimer);
194
+ clearTimeout(hideTimer);
195
+ if (frame) window.cancelAnimationFrame(frame);
196
+ document.removeEventListener('pointerover', onPointerOver);
197
+ document.removeEventListener('click', onClick, true);
198
+ window.removeEventListener('scroll', schedulePlace, {
199
+ capture: true
200
+ });
201
+ window.removeEventListener('resize', schedulePlace);
202
+ window.removeEventListener('message', onMessage);
203
+ for (const resolve of readyWaiters)resolve(false);
204
+ readyWaiters.clear();
205
+ layer.remove();
206
+ }
207
+ };
208
+ }
209
+
210
+ //# sourceMappingURL=overlay.js.map
@@ -0,0 +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,aAAa,CAAC;IACvCK,QAAQH,KAAK,CAACC,OAAO,GAAG,CAAC,mEAAmE,EAAEC,MAA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ASmH,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"}
@@ -0,0 +1,15 @@
1
+ import { type SourceRef } from '@derweili/payload-visual-editing-core';
2
+ export type Targets = Map<Element, SourceRef>;
3
+ /**
4
+ * Finds every editable element below `root`:
5
+ * - the parent element of each text node that carries a ref (the first ref wins per element)
6
+ * - every element marked with `fieldAttrs()` (these win over text refs on the same element)
7
+ * Elements inside `ignore` (the overlay's own UI) are skipped.
8
+ */
9
+ export declare function scanTargets(root: Element, ignore?: Element | null): Targets;
10
+ /** The innermost editable element at or above `node`, or null. */
11
+ export declare function findTarget(node: Node | null, targets: Targets): {
12
+ element: Element;
13
+ ref: SourceRef;
14
+ } | null;
15
+ //# sourceMappingURL=scan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/vanilla/scan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,SAAS,EAAE,MAAM,uCAAuC,CAAA;AAI7F,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;AAE7C;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,GAAG,OAAO,CAsB3E;AAED,kEAAkE;AAClE,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,OAAO,EAAE,OAAO,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,SAAS,CAAA;CAAE,GAAG,IAAI,CAO3G"}
@@ -0,0 +1,46 @@
1
+ import { hasStega, stegaDecode } from '@derweili/payload-visual-editing-core';
2
+ import { DOC_ATTR, readFieldAttrs } from "./attributes.js";
3
+ /**
4
+ * Finds every editable element below `root`:
5
+ * - the parent element of each text node that carries a ref (the first ref wins per element)
6
+ * - every element marked with `fieldAttrs()` (these win over text refs on the same element)
7
+ * Elements inside `ignore` (the overlay's own UI) are skipped.
8
+ */ export function scanTargets(root, ignore) {
9
+ const targets = new Map();
10
+ const document = root.ownerDocument;
11
+ const walker = document.createTreeWalker(root, 0x4 /* NodeFilter.SHOW_TEXT */ );
12
+ for(let node = walker.nextNode(); node; node = walker.nextNode()){
13
+ const text = node.nodeValue;
14
+ const element = node.parentElement;
15
+ if (!text || !element || targets.has(element) || !hasStega(text)) continue;
16
+ if (ignore?.contains(element)) continue;
17
+ if (element.closest('script, style, noscript, template')) continue;
18
+ const ref = stegaDecode(text);
19
+ if (ref) targets.set(element, ref);
20
+ }
21
+ const marked = [
22
+ ...root.matches(`[${DOC_ATTR}]`) ? [
23
+ root
24
+ ] : [],
25
+ ...root.querySelectorAll(`[${DOC_ATTR}]`)
26
+ ];
27
+ for (const element of marked){
28
+ if (ignore?.contains(element)) continue;
29
+ const ref = readFieldAttrs(element);
30
+ if (ref) targets.set(element, ref);
31
+ }
32
+ return targets;
33
+ }
34
+ /** The innermost editable element at or above `node`, or null. */ export function findTarget(node, targets) {
35
+ for(let current = node; current; current = current.parentNode){
36
+ if (current.nodeType !== 1) continue;
37
+ const ref = targets.get(current);
38
+ if (ref) return {
39
+ element: current,
40
+ ref
41
+ };
42
+ }
43
+ return null;
44
+ }
45
+
46
+ //# sourceMappingURL=scan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/vanilla/scan.ts"],"sourcesContent":["import { hasStega, stegaDecode, type SourceRef } from '@derweili/payload-visual-editing-core'\n\nimport { DOC_ATTR, readFieldAttrs } from './attributes.ts'\n\nexport type Targets = Map<Element, SourceRef>\n\n/**\n * Finds every editable element below `root`:\n * - the parent element of each text node that carries a ref (the first ref wins per element)\n * - every element marked with `fieldAttrs()` (these win over text refs on the same element)\n * Elements inside `ignore` (the overlay's own UI) are skipped.\n */\nexport function scanTargets(root: Element, ignore?: Element | null): Targets {\n const targets: Targets = new Map()\n const document = root.ownerDocument\n\n const walker = document.createTreeWalker(root, 0x4 /* NodeFilter.SHOW_TEXT */)\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n const text = node.nodeValue\n const element = node.parentElement\n if (!text || !element || targets.has(element) || !hasStega(text)) continue\n if (ignore?.contains(element)) continue\n if (element.closest('script, style, noscript, template')) continue\n const ref = stegaDecode(text)\n if (ref) targets.set(element, ref)\n }\n\n const marked = [...(root.matches(`[${DOC_ATTR}]`) ? [root] : []), ...root.querySelectorAll(`[${DOC_ATTR}]`)]\n for (const element of marked) {\n if (ignore?.contains(element)) continue\n const ref = readFieldAttrs(element)\n if (ref) targets.set(element, ref)\n }\n return targets\n}\n\n/** The innermost editable element at or above `node`, or null. */\nexport function findTarget(node: Node | null, targets: Targets): { element: Element; ref: SourceRef } | null {\n for (let current: Node | null = node; current; current = current.parentNode) {\n if (current.nodeType !== 1) continue\n const ref = targets.get(current as Element)\n if (ref) return { element: current as Element, ref }\n }\n return null\n}\n"],"names":["hasStega","stegaDecode","DOC_ATTR","readFieldAttrs","scanTargets","root","ignore","targets","Map","document","ownerDocument","walker","createTreeWalker","node","nextNode","text","nodeValue","element","parentElement","has","contains","closest","ref","set","marked","matches","querySelectorAll","findTarget","current","parentNode","nodeType","get"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,WAAW,QAAwB,wCAAuC;AAE7F,SAASC,QAAQ,EAAEC,cAAc,QAAQ,kBAAiB;AAI1D;;;;;CAKC,GACD,OAAO,SAASC,YAAYC,IAAa,EAAEC,MAAuB;IAChE,MAAMC,UAAmB,IAAIC;IAC7B,MAAMC,WAAWJ,KAAKK,aAAa;IAEnC,MAAMC,SAASF,SAASG,gBAAgB,CAACP,MAAM,IAAI,wBAAwB;IAC3E,IAAK,IAAIQ,OAAOF,OAAOG,QAAQ,IAAID,MAAMA,OAAOF,OAAOG,QAAQ,GAAI;QACjE,MAAMC,OAAOF,KAAKG,SAAS;QAC3B,MAAMC,UAAUJ,KAAKK,aAAa;QAClC,IAAI,CAACH,QAAQ,CAACE,WAAWV,QAAQY,GAAG,CAACF,YAAY,CAACjB,SAASe,OAAO;QAClE,IAAIT,QAAQc,SAASH,UAAU;QAC/B,IAAIA,QAAQI,OAAO,CAAC,sCAAsC;QAC1D,MAAMC,MAAMrB,YAAYc;QACxB,IAAIO,KAAKf,QAAQgB,GAAG,CAACN,SAASK;IAChC;IAEA,MAAME,SAAS;WAAKnB,KAAKoB,OAAO,CAAC,CAAC,CAAC,EAAEvB,SAAS,CAAC,CAAC,IAAI;YAACG;SAAK,GAAG,EAAE;WAAMA,KAAKqB,gBAAgB,CAAC,CAAC,CAAC,EAAExB,SAAS,CAAC,CAAC;KAAE;IAC5G,KAAK,MAAMe,WAAWO,OAAQ;QAC5B,IAAIlB,QAAQc,SAASH,UAAU;QAC/B,MAAMK,MAAMnB,eAAec;QAC3B,IAAIK,KAAKf,QAAQgB,GAAG,CAACN,SAASK;IAChC;IACA,OAAOf;AACT;AAEA,gEAAgE,GAChE,OAAO,SAASoB,WAAWd,IAAiB,EAAEN,OAAgB;IAC5D,IAAK,IAAIqB,UAAuBf,MAAMe,SAASA,UAAUA,QAAQC,UAAU,CAAE;QAC3E,IAAID,QAAQE,QAAQ,KAAK,GAAG;QAC5B,MAAMR,MAAMf,QAAQwB,GAAG,CAACH;QACxB,IAAIN,KAAK,OAAO;YAAEL,SAASW;YAAoBN;QAAI;IACrD;IACA,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,73 @@
1
1
  {
2
2
  "name": "@derweili/payload-visual-editing-overlay",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Frontend overlay for Payload visual editing: outlines, edit buttons, links back to the admin",
5
+ "keywords": [
6
+ "payload",
7
+ "payloadcms",
8
+ "visual-editing",
9
+ "overlay",
10
+ "react",
11
+ "live-preview"
12
+ ],
13
+ "license": "MIT",
14
+ "author": "Julian Weiland",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/derweili/payload-visual-editing.git",
18
+ "directory": "packages/visual-editing-overlay"
19
+ },
20
+ "homepage": "https://github.com/derweili/payload-visual-editing/tree/main/packages/visual-editing-overlay#readme",
21
+ "bugs": "https://github.com/derweili/payload-visual-editing/issues",
22
+ "type": "module",
23
+ "sideEffects": false,
24
+ "exports": {
25
+ "./vanilla": {
26
+ "types": "./dist/vanilla/index.d.ts",
27
+ "import": "./dist/vanilla/index.js",
28
+ "default": "./dist/vanilla/index.js"
29
+ },
30
+ "./react": {
31
+ "types": "./dist/react/index.d.ts",
32
+ "import": "./dist/react/index.js",
33
+ "default": "./dist/react/index.js"
34
+ }
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "README.md",
42
+ "CHANGELOG.md",
43
+ "LICENSE"
44
+ ],
45
+ "dependencies": {
46
+ "@derweili/payload-visual-editing-core": "0.1.1"
47
+ },
48
+ "peerDependencies": {
49
+ "react": "^18.0.0 || ^19.0.0"
50
+ },
51
+ "peerDependenciesMeta": {
52
+ "react": {
53
+ "optional": true
54
+ }
55
+ },
56
+ "devDependencies": {
57
+ "@swc/cli": "0.7.10",
58
+ "@swc/core": "1.15.11",
59
+ "@types/react": "19.2.14",
60
+ "@types/react-dom": "19.2.3",
61
+ "jsdom": "28.0.0",
62
+ "react": "19.2.9",
63
+ "react-dom": "19.2.9",
64
+ "typescript": "5.7.3",
65
+ "vite": "7.3.8",
66
+ "vitest": "4.0.18"
67
+ },
68
+ "scripts": {
69
+ "build": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths --delete-dir-on-start && tsc -p tsconfig.build.json",
70
+ "test": "vitest run",
71
+ "typecheck": "tsc --noEmit"
72
+ }
6
73
  }