@focus-reactive/payload-plugin-visual-editing 1.0.0 → 1.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/README.md CHANGED
@@ -35,12 +35,13 @@ export default buildConfig({
35
35
  skipGlobals: [], // global slugs to exclude
36
36
  excludeFieldNames: ['tenant'], // extra field names to strip (merged with '_status', 'folder', 'slug')
37
37
  adminBasePath: '/admin', // Payload admin base path (default '/admin')
38
+ enrichment: 'explicit', // which reads get stega (default 'auto') — see "Enrichment modes"
38
39
  }),
39
40
  ],
40
41
  })
41
42
  ```
42
43
 
43
- This adds enrichment hooks to every non-skipped collection and global, registers the `VisualEditingBridgeProvider` admin component, and adds a `beforeChange` hook that strips stega from writes so markers can never be persisted to the database.
44
+ This adds enrichment hooks to every non-skipped collection and global, registers the `VisualEditingBridgeProvider` admin component, and adds a `beforeChange` hook that strips intact stega markers from writes.
44
45
 
45
46
  ### 2. Enable drafts on editable collections
46
47
 
@@ -131,6 +132,8 @@ export default async function Page({ params }: { params: Promise<{ slug: string
131
132
  }
132
133
  ```
133
134
 
135
+ With `enrichment: 'explicit'`, also pass `context: { visualEditing: draft }` — see [Enrichment modes](#enrichment-modes).
136
+
134
137
  ### 6. Wrap the frontend layout
135
138
 
136
139
  Mount the provider (gated on draft mode), the toggle, and the overlay:
@@ -174,7 +177,7 @@ bunx payload generate:importmap
174
177
 
175
178
  ### Using it
176
179
 
177
- Open a document in the admin, open the **Live Preview** side panel (it loads the frontend in draft mode), then flip the floating toggle to **Always** or **Hover**. Editable text shows an outline and an **Edit** badge; clicking it focuses that field in the admin form. To leave draft mode when viewing the frontend directly, hit `/next/exit-preview`.
180
+ Open a document in the admin, open the **Live Preview** side panel (it loads the frontend in draft mode), then flip the floating toggle to **Always** or **Hover**. Editable text shows an outline and an **Edit** badge; clicking it focuses that field in the admin form. A plain click anywhere on a highlighted element opens its field too; a modifier-click or a text selection keeps the page's normal behavior. To leave draft mode when viewing the frontend directly, hit `/next/exit-preview`.
178
181
 
179
182
  ## Editable richText and upload fields
180
183
 
@@ -225,15 +228,37 @@ Clicking the Edit badge on an upload opens the media document's admin page (not
225
228
 
226
229
  **Uploads require `depth ≥ 1`** so Payload returns the populated media document alongside its `_meta`. At `depth: 0` the value is a bare id string and no overlay is drawn.
227
230
 
231
+ ## Enrichment modes
232
+
233
+ The `enrichment` option decides which reads get stega.
234
+
235
+ - **`'auto'`** (default) — every Local API read with `draft: true` outside the admin base path is enriched. The plugin can't tell a preview render from any other server code that reads drafts, so plugins, jobs, hooks and scripts receive stega too.
236
+ - **`'explicit'`** — only reads that pass `context: { visualEditing: true }` are enriched. Everything else gets clean data.
237
+
238
+ ```ts
239
+ const { isEnabled: draft } = await draftMode()
240
+
241
+ await payload.find({
242
+ collection: 'pages',
243
+ draft,
244
+ context: { visualEditing: draft },
245
+ where: { slug: { equals: slug } },
246
+ })
247
+ ```
248
+
249
+ In either mode `context.visualEditing` wins when set: `true` always enriches, `false` never does. Server code that reads drafts for its own processing should pass `context: { visualEditing: false }` under `'auto'`. The plugin augments Payload's `RequestContext`, so the key is type-checked.
250
+
251
+ > **Why it matters.** The `beforeChange` strip only removes intact markers. If server code receives stega, transforms the text (an LLM translation, truncation, concatenation) and writes it back, fragments of a damaged marker survive the strip and end up in the database. Use `'explicit'` whenever server code reads drafts and writes derived content.
252
+
228
253
  ## How it works
229
254
 
230
255
  ### Server pipeline
231
256
 
232
257
  1. `beforeOperation` stamps `req.context` with the draft flag.
233
- 2. `afterRead` (gated to draft reads served to the frontend Local API — admin-panel reads, identified by their admin pathname, and REST reads are skipped) walks the returned document, attaches `_meta.path` markers to leaf-ish objects, and for rich-text / primitive-terminal types sets `_meta.terminal = true` so outer collection walks don't clobber them.
258
+ 2. `afterRead` (gated by the [enrichment mode](#enrichment-modes) — under `'auto'`, draft reads served to the frontend Local API; admin-panel reads, identified by their admin pathname, and REST reads are skipped) walks the returned document, attaches `_meta.path` markers to leaf-ish objects, and for rich-text / primitive-terminal types sets `_meta.terminal = true` so outer collection walks don't clobber them.
234
259
  3. `afterOperation` uses the collection's schema to embed Vercel stega into text fields, carrying the field path all the way through SSR into the client DOM.
235
260
  4. Before stega is embedded, a small pre-pass walks each enriched doc's schema against its data. Populated `upload:<slug>` values are flipped to `_meta.terminal = true` so their identity is preserved for wrapper-attr consumption on the client (`<img {...withVisualEditingPath(upload)} />`), without embedding zero-width stega into `alt` or `filename`.
236
- 5. `beforeChange` strips stega from every write as a safety net, so markers can never be persisted even if a read is ever mis-classified.
261
+ 5. `beforeChange` strips intact stega markers from every write as a safety net. Markers damaged by a text transformation are not recognized — keep stega away from such code with the [enrichment mode](#enrichment-modes).
237
262
 
238
263
  The schema cache (per slug, memoized) resolves relationship targets lazily so you don't pay for unused collections.
239
264
 
@@ -249,6 +274,7 @@ The schema cache (per slug, memoized) resolves relationship targets lazily so yo
249
274
  | `skipGlobals` | `string[]` | `[]` | Exclude these global slugs from enrichment. |
250
275
  | `excludeFieldNames` | `string[]` | `[]` | Extra field names to strip from the serialized schema. Always merged with `_status`, `folder`, `slug`. |
251
276
  | `adminBasePath` | `string` | `/admin` | Payload admin base path. Used to exclude admin reads from enrichment and by the bridge for URL parsing and admin-tab navigation. |
277
+ | `enrichment` | `'auto' \| 'explicit'` | `'auto'` | Which reads get stega: any frontend draft read, or only reads passing `context: { visualEditing: true }`. See [Enrichment modes](#enrichment-modes). |
252
278
 
253
279
  The `VisualEditing.Provider` (client) also accepts `framedOnly` (restrict the overlay to the CMS preview iframe) and `adminBasePath` (must match the server option).
254
280
 
@@ -7,7 +7,10 @@ import { createMutationPipeline } from "./mutationPipeline.js";
7
7
  import { createStegaBookkeeper } from "./stegaBookkeeper.js";
8
8
  import { collectAttrMatches, collectTextMatches } from "./stegaScanner.js";
9
9
  import { createTargetRegistry } from "./targetRegistry.js";
10
- import { pickTargetForGroup } from "./targetSelector.js";
10
+ import { findTargetAncestor, pickTargetForGroup } from "./targetSelector.js";
11
+ const isPlainPrimaryClick = (event)=>event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
12
+ const hasTextSelection = ()=>document.getSelection()?.isCollapsed === false;
13
+ const isRepeatedClick = (event)=>event.detail > 1;
11
14
  // Wires every overlay submodule and returns a dispose that tears them down in reverse order.
12
15
  // `getCtx` is a getter so the callsite (the hook) can stabilize its useEffect dependency array
13
16
  // on just `[enabled]` while still seeing fresh ctx when a target is registered.
@@ -68,7 +71,23 @@ export function createOverlay(main, getCtx) {
68
71
  },
69
72
  onTextReset: (node)=>bookkeeper.forgetText(node)
70
73
  });
74
+ const openFieldOnTargetClick = (event)=>{
75
+ if (!isPlainPrimaryClick(event)) return;
76
+ const target = findTargetAncestor(event.target instanceof Element ? event.target : null);
77
+ const config = target ? registry.get(target) : undefined;
78
+ if (!config) return;
79
+ if (isRepeatedClick(event)) {
80
+ event.preventDefault();
81
+ event.stopPropagation();
82
+ return;
83
+ }
84
+ if (hasTextSelection()) return;
85
+ event.stopPropagation();
86
+ config.clickHandler(event);
87
+ };
88
+ main.addEventListener("click", openFieldOnTargetClick, true);
71
89
  return ()=>{
90
+ main.removeEventListener("click", openFieldOnTargetClick, true);
72
91
  pipeline.dispose();
73
92
  hover.dispose();
74
93
  registry.disposeAll();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/overlay/createOverlay.ts"],"sourcesContent":["import type { BuildAdminEditUrl } from \"../buildAdminEditUrl.js\";\nimport type { Marker } from \"./markerExtractor.js\";\nimport type { TextMatch } from \"./stegaScanner.js\";\n\nimport { DATA_VE_PATH_ATTR } from \"../../constants.js\";\nimport { LABEL_CLASS } from \"./constants.js\";\nimport { createEditBadge } from \"./editBadge.js\";\nimport { createHoverController } from \"./hoverController.js\";\nimport { groupNodesByPath, readMarkerFromAttrs } from \"./markerExtractor.js\";\nimport { createMutationPipeline } from \"./mutationPipeline.js\";\nimport { createStegaBookkeeper } from \"./stegaBookkeeper.js\";\nimport { collectAttrMatches, collectTextMatches } from \"./stegaScanner.js\";\nimport { createTargetRegistry } from \"./targetRegistry.js\";\nimport { pickTargetForGroup } from \"./targetSelector.js\";\n\nexport type OverlayCtx = {\n buildAdminEditUrl: BuildAdminEditUrl;\n adminOrigin: string;\n adminBasePath: string;\n locale?: string;\n /** 'always' paints outlines on every editable target; 'hover' paints only the hovered one.\n * 'off' is handled by not mounting the overlay at all, so it never reaches this module. */\n mode: \"always\" | \"hover\";\n};\n\n// Wires every overlay submodule and returns a dispose that tears them down in reverse order.\n// `getCtx` is a getter so the callsite (the hook) can stabilize its useEffect dependency array\n// on just `[enabled]` while still seeing fresh ctx when a target is registered.\nexport function createOverlay(main: HTMLElement, getCtx: () => OverlayCtx): () => void {\n // Fast Refresh may skip the cleanup from a previous effect run — purge any leftover labels.\n // Outline and target attrs are owned by the registry now (disposal restores them), so leftover\n // attrs only exist if a crash skipped cleanup entirely; rare enough to not warrant a scan.\n for (const leftover of Array.from(document.querySelectorAll<HTMLElement>(`.${LABEL_CLASS}`))) {\n leftover.remove();\n }\n\n const bookkeeper = createStegaBookkeeper();\n const registry = createTargetRegistry();\n const badge = createEditBadge();\n const hover = createHoverController(badge, registry);\n\n const applyOverlay = (target: HTMLElement, marker: Marker): boolean => {\n const existing = registry.get(target);\n if (existing && existing.path === marker.path) return false;\n registry.upsert(target, marker, getCtx());\n if (existing) {\n hover.refresh(target);\n } else {\n hover.attach(target);\n }\n return true;\n };\n\n const scan = (root: Element) => {\n if (!root.isConnected) return;\n // Our own `appendChild(label)` triggers childList mutations the observer will forward\n // back here. The label has no stega and no wrapper — short-circuit to avoid TreeWalker work.\n if (root.classList?.contains(LABEL_CLASS)) return;\n\n const newMatches: TextMatch[] = [];\n for (const match of collectTextMatches(root)) {\n if (bookkeeper.recordText(match.textNode)) newMatches.push(match);\n }\n\n for (const match of collectAttrMatches(root)) {\n bookkeeper.recordAttr(match.el, match.attr, match.value);\n }\n\n for (const { nodes, ctx: marker } of groupNodesByPath(newMatches)) {\n const target = pickTargetForGroup(nodes, main);\n if (!(target instanceof HTMLElement)) continue;\n applyOverlay(target, marker);\n }\n\n // Rich text and other renderers that own their own text nodes carry the path on a wrapper\n // attr instead of inline stega.\n const wrappers: HTMLElement[] = [];\n if (root.matches(`[${DATA_VE_PATH_ATTR}]`)) wrappers.push(root as HTMLElement);\n wrappers.push(...Array.from(root.querySelectorAll<HTMLElement>(`[${DATA_VE_PATH_ATTR}]`)));\n\n for (const target of wrappers) {\n const marker = readMarkerFromAttrs(target);\n if (!marker) continue;\n applyOverlay(target, marker);\n }\n };\n\n scan(main);\n\n const pipeline = createMutationPipeline(main, {\n onRoots: (roots) => {\n for (const root of roots) scan(root);\n },\n onTextReset: (node) => bookkeeper.forgetText(node),\n });\n\n return () => {\n pipeline.dispose();\n hover.dispose();\n registry.disposeAll();\n badge.dispose();\n bookkeeper.restoreAll();\n };\n}\n"],"names":["DATA_VE_PATH_ATTR","LABEL_CLASS","createEditBadge","createHoverController","groupNodesByPath","readMarkerFromAttrs","createMutationPipeline","createStegaBookkeeper","collectAttrMatches","collectTextMatches","createTargetRegistry","pickTargetForGroup","createOverlay","main","getCtx","leftover","Array","from","document","querySelectorAll","remove","bookkeeper","registry","badge","hover","applyOverlay","target","marker","existing","get","path","upsert","refresh","attach","scan","root","isConnected","classList","contains","newMatches","match","recordText","textNode","push","recordAttr","el","attr","value","nodes","ctx","HTMLElement","wrappers","matches","pipeline","onRoots","roots","onTextReset","node","forgetText","dispose","disposeAll","restoreAll"],"mappings":"AAIA,SAASA,iBAAiB,QAAQ,qBAAqB;AACvD,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,eAAe,QAAQ,iBAAiB;AACjD,SAASC,qBAAqB,QAAQ,uBAAuB;AAC7D,SAASC,gBAAgB,EAAEC,mBAAmB,QAAQ,uBAAuB;AAC7E,SAASC,sBAAsB,QAAQ,wBAAwB;AAC/D,SAASC,qBAAqB,QAAQ,uBAAuB;AAC7D,SAASC,kBAAkB,EAAEC,kBAAkB,QAAQ,oBAAo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BAAiBmC,YAAa;YACjE,MAAMb,SAASf,mBAAmBqC,OAAOnC;YACzC,IAAI,CAAEa,CAAAA,kBAAkBwB,WAAU,GAAI;YACtCzB,aAAaC,QAAQC;QACvB;QAEA,0FAA0F;QAC1F,gCAAgC;QAChC,MAAMwB,WAA0B,EAAE;QAClC,IAAIhB,KAAKiB,OAAO,CAAC,CAAC,CAAC,EAAEpD,kBAAkB,CAAC,CAAC,GAAGmD,SAASR,IAAI,CAACR;QAC1DgB,SAASR,IAAI,IAAI3B,MAAMC,IAAI,CAACkB,KAAKhB,gBAAgB,CAAc,CAAC,CAAC,EAAEnB,kBAAkB,CAAC,CAAC;QAEvF,KAAK,MAAM0B,UAAUyB,SAAU;YAC7B,MAAMxB,SAAStB,oBAAoBqB;YACnC,IAAI,CAACC,QAAQ;YACbF,aAAaC,QAAQC;QACvB;IACF;IAEAO,KAAKrB;IAEL,MAAMwC,WAAW/C,uBAAuBO,MAAM;QAC5CyC,SAAS,CAACC;YACR,KAAK,MAAMpB,QAAQoB,MAAOrB,KAAKC;QACjC;QACAqB,aAAa,CAACC,OAASpC,WAAWqC,UAAU,CAACD;IAC/C;IAEA,OAAO;QACLJ,SAASM,OAAO;QAChBnC,MAAMmC,OAAO;QACbrC,SAASsC,UAAU;QACnBrC,MAAMoC,OAAO;QACbtC,WAAWwC,UAAU;IACvB;AACF"}
1
+ {"version":3,"sources":["../../../src/client/overlay/createOverlay.ts"],"sourcesContent":["import type { BuildAdminEditUrl } from \"../buildAdminEditUrl.js\";\nimport type { Marker } from \"./markerExtractor.js\";\nimport type { TextMatch } from \"./stegaScanner.js\";\n\nimport { DATA_VE_PATH_ATTR } from \"../../constants.js\";\nimport { LABEL_CLASS } from \"./constants.js\";\nimport { createEditBadge } from \"./editBadge.js\";\nimport { createHoverController } from \"./hoverController.js\";\nimport { groupNodesByPath, readMarkerFromAttrs } from \"./markerExtractor.js\";\nimport { createMutationPipeline } from \"./mutationPipeline.js\";\nimport { createStegaBookkeeper } from \"./stegaBookkeeper.js\";\nimport { collectAttrMatches, collectTextMatches } from \"./stegaScanner.js\";\nimport { createTargetRegistry } from \"./targetRegistry.js\";\nimport { findTargetAncestor, pickTargetForGroup } from \"./targetSelector.js\";\n\nexport type OverlayCtx = {\n buildAdminEditUrl: BuildAdminEditUrl;\n adminOrigin: string;\n adminBasePath: string;\n locale?: string;\n /** 'always' paints outlines on every editable target; 'hover' paints only the hovered one.\n * 'off' is handled by not mounting the overlay at all, so it never reaches this module. */\n mode: \"always\" | \"hover\";\n};\n\nconst isPlainPrimaryClick = (event: MouseEvent) =>\n event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;\n\nconst hasTextSelection = () => document.getSelection()?.isCollapsed === false;\n\nconst isRepeatedClick = (event: MouseEvent) => event.detail > 1;\n\n// Wires every overlay submodule and returns a dispose that tears them down in reverse order.\n// `getCtx` is a getter so the callsite (the hook) can stabilize its useEffect dependency array\n// on just `[enabled]` while still seeing fresh ctx when a target is registered.\nexport function createOverlay(main: HTMLElement, getCtx: () => OverlayCtx): () => void {\n // Fast Refresh may skip the cleanup from a previous effect run — purge any leftover labels.\n // Outline and target attrs are owned by the registry now (disposal restores them), so leftover\n // attrs only exist if a crash skipped cleanup entirely; rare enough to not warrant a scan.\n for (const leftover of Array.from(document.querySelectorAll<HTMLElement>(`.${LABEL_CLASS}`))) {\n leftover.remove();\n }\n\n const bookkeeper = createStegaBookkeeper();\n const registry = createTargetRegistry();\n const badge = createEditBadge();\n const hover = createHoverController(badge, registry);\n\n const applyOverlay = (target: HTMLElement, marker: Marker): boolean => {\n const existing = registry.get(target);\n if (existing && existing.path === marker.path) return false;\n registry.upsert(target, marker, getCtx());\n if (existing) {\n hover.refresh(target);\n } else {\n hover.attach(target);\n }\n return true;\n };\n\n const scan = (root: Element) => {\n if (!root.isConnected) return;\n // Our own `appendChild(label)` triggers childList mutations the observer will forward\n // back here. The label has no stega and no wrapper — short-circuit to avoid TreeWalker work.\n if (root.classList?.contains(LABEL_CLASS)) return;\n\n const newMatches: TextMatch[] = [];\n for (const match of collectTextMatches(root)) {\n if (bookkeeper.recordText(match.textNode)) newMatches.push(match);\n }\n\n for (const match of collectAttrMatches(root)) {\n bookkeeper.recordAttr(match.el, match.attr, match.value);\n }\n\n for (const { nodes, ctx: marker } of groupNodesByPath(newMatches)) {\n const target = pickTargetForGroup(nodes, main);\n if (!(target instanceof HTMLElement)) continue;\n applyOverlay(target, marker);\n }\n\n // Rich text and other renderers that own their own text nodes carry the path on a wrapper\n // attr instead of inline stega.\n const wrappers: HTMLElement[] = [];\n if (root.matches(`[${DATA_VE_PATH_ATTR}]`)) wrappers.push(root as HTMLElement);\n wrappers.push(...Array.from(root.querySelectorAll<HTMLElement>(`[${DATA_VE_PATH_ATTR}]`)));\n\n for (const target of wrappers) {\n const marker = readMarkerFromAttrs(target);\n if (!marker) continue;\n applyOverlay(target, marker);\n }\n };\n\n scan(main);\n\n const pipeline = createMutationPipeline(main, {\n onRoots: (roots) => {\n for (const root of roots) scan(root);\n },\n onTextReset: (node) => bookkeeper.forgetText(node),\n });\n\n const openFieldOnTargetClick = (event: MouseEvent) => {\n if (!isPlainPrimaryClick(event)) return;\n const target = findTargetAncestor(event.target instanceof Element ? event.target : null);\n const config = target ? registry.get(target) : undefined;\n if (!config) return;\n if (isRepeatedClick(event)) {\n event.preventDefault();\n event.stopPropagation();\n return;\n }\n if (hasTextSelection()) return;\n event.stopPropagation();\n config.clickHandler(event);\n };\n main.addEventListener(\"click\", openFieldOnTargetClick, true);\n\n return () => {\n main.removeEventListener(\"click\", openFieldOnTargetClick, true);\n pipeline.dispose();\n hover.dispose();\n registry.disposeAll();\n badge.dispose();\n bookkeeper.restoreAll();\n };\n}\n"],"names":["DATA_VE_PATH_ATTR","LABEL_CLASS","createEditBadge","createHoverController","groupNodesByPath","readMarkerFromAttrs","createMutationPipeline","createStegaBookkeeper","collectAttrMatches","collectTextMatches","createTargetRegistry","findTargetAncestor","pickTargetForGroup","isPlainPrimaryClick","event","button","metaKey","ctrlKey","shiftKey","altKey","hasTextSelection","document","getSelection","isCollapsed","isRepeatedClick","detail","createOverlay","main","getCtx","leftover","Array","from","querySelectorAll","remove","bookkeeper","registry","badge","hover","applyOverlay","target","marker","existing","get","path","upsert","refresh","attach","scan","root","isConnected","classList","contains","newMatches","match","recordText","textNode","push","recordAttr","el","attr","value","nodes","ctx","HTMLElement","wrappers","matches","pipeline","onRoots","roots","onTextReset","node","forgetText","openFieldOnTargetClick","Element","config","undefined","preventDefault","stopPropagation","clickHandler","addEventListener","removeEventListener","dispose","disposeAll","restoreAll"],"mappings":"AAIA,SAASA,iBAAiB,QAAQ,qBAAqB;AACvD,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,eAAe,QAAQ,iBAAiB;AACjD,SAASC,qBAAqB,QAAQ,uBAAuB;AAC7D,SAASC,gBAAgB,EAAEC,mBAAmB,QAAQ,uBAAuB;AAC7E,SAASC,sBAAsB,QAAQ,wBAAwB;AAC/D,SAASC,qBAAqB,QAAQ,uBAAuB;AAC7D,SAASC,kBAAkB,EAAEC,kBAAkB,QAAQ,oBAAoB;AAC3E,SAASC,oBAAoB,QAAQ,sBAAsB;AAC3D,SAASC,kBAAkB,EAAEC,kBAAkB,QAAQ,sBAAsB;AAY7E,MAAMC,sBAAsB,CAACC,QAC3BA,MAAMC,MAAM,KAAK,KAAK,CAACD,MAAME,OAAO,IAAI,CAACF,MAAMG,OAAO,IAAI,CAACH,MAAMI,QAAQ,IAAI,CAACJ,MAAMK,MAAM;AAE5F,MAAMC,mBAAmB,IAAMC,SAASC,YAAY,IAAIC,gBAAgB;AAExE,MAAMC,kBAAkB,CAACV,QAAsBA,MAAMW,MAAM,GAAG;AAE9D,6FAA6F;AAC7F,+FAA+F;AAC/F,gFAAgF;AAChF,OAAO,SAASC,cAAcC,IAAiB,EAAEC,MAAwB;IACvE,4FAA4F;IAC5F,+FAA+F;IAC/F,2FAA2F;IAC3F,KAAK,MAAMC,YAAYC,M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C,EAAEjE,kBAAkB,CAAC,CAAC,GAAGgE,SAASR,IAAI,CAACR;QAC1DgB,SAASR,IAAI,IAAI1B,MAAMC,IAAI,CAACiB,KAAKhB,gBAAgB,CAAc,CAAC,CAAC,EAAEhC,kBAAkB,CAAC,CAAC;QAEvF,KAAK,MAAMuC,UAAUyB,SAAU;YAC7B,MAAMxB,SAASnC,oBAAoBkC;YACnC,IAAI,CAACC,QAAQ;YACbF,aAAaC,QAAQC;QACvB;IACF;IAEAO,KAAKpB;IAEL,MAAMuC,WAAW5D,uBAAuBqB,MAAM;QAC5CwC,SAAS,CAACC;YACR,KAAK,MAAMpB,QAAQoB,MAAOrB,KAAKC;QACjC;QACAqB,aAAa,CAACC,OAASpC,WAAWqC,UAAU,CAACD;IAC/C;IAEA,MAAME,yBAAyB,CAAC1D;QAC9B,IAAI,CAACD,oBAAoBC,QAAQ;QACjC,MAAMyB,SAAS5B,mBAAmBG,MAAMyB,MAAM,YAAYkC,UAAU3D,MAAMyB,MAAM,GAAG;QACnF,MAAMmC,SAASnC,SAASJ,SAASO,GAAG,CAACH,UAAUoC;QAC/C,IAAI,CAACD,QAAQ;QACb,IAAIlD,gBAAgBV,QAAQ;YAC1BA,MAAM8D,cAAc;YACpB9D,MAAM+D,eAAe;YACrB;QACF;QACA,IAAIzD,oBAAoB;QACxBN,MAAM+D,eAAe;QACrBH,OAAOI,YAAY,CAAChE;IACtB;IACAa,KAAKoD,gBAAgB,CAAC,SAASP,wBAAwB;IAEvD,OAAO;QACL7C,KAAKqD,mBAAmB,CAAC,SAASR,wBAAwB;QAC1DN,SAASe,OAAO;QAChB5C,MAAM4C,OAAO;QACb9C,SAAS+C,UAAU;QACnB9C,MAAM6C,OAAO;QACb/C,WAAWiD,UAAU;IACvB;AACF"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import type { Plugin } from "payload";
2
2
  import type { ValueExcludePredicate } from "./excludeValues.js";
3
+ import type { Enrichment } from "./internal/gate.js";
3
4
  export { defaultExcludeValues, isHash, isIsoDate, isSlug, isUrl, type ValueExcludePredicate, } from "./excludeValues.js";
5
+ declare module "payload" {
6
+ interface RequestContext {
7
+ visualEditing?: boolean;
8
+ }
9
+ }
4
10
  export type VisualEditingPluginConfig = {
5
11
  skipCollections?: string[];
6
12
  skipGlobals?: string[];
@@ -9,5 +15,8 @@ export type VisualEditingPluginConfig = {
9
15
  * Omit to use `defaultExcludeValues` (URL / slug / hash / ISO-date). */
10
16
  excludeValues?: ValueExcludePredicate[];
11
17
  adminBasePath?: string;
18
+ /** `'auto'` (default) enriches any Local API draft read outside the admin.
19
+ * `'explicit'` enriches only reads that pass `context: { visualEditing: true }`. */
20
+ enrichment?: Enrichment;
12
21
  };
13
22
  export declare const visualEditingPlugin: (pluginConfig?: VisualEditingPluginConfig) => Plugin;
package/dist/index.js CHANGED
@@ -21,21 +21,24 @@ export const visualEditingPlugin = (pluginConfig = {})=>(config)=>{
21
21
  const skipGlobals = new Set(pluginConfig.skipGlobals);
22
22
  const adminBasePath = pluginConfig.adminBasePath ?? "/admin";
23
23
  const excludeValues = pluginConfig.excludeValues ?? defaultExcludeValues;
24
+ const enrichment = pluginConfig.enrichment ?? "auto";
24
25
  const schemaCache = createSchemaCache({
25
26
  excludeFieldNames: pluginConfig.excludeFieldNames
26
27
  });
27
28
  const beforeOperation = createBeforeOperationHook();
28
- const afterRead = createAfterReadHook(adminBasePath);
29
+ const afterRead = createAfterReadHook(adminBasePath, enrichment);
29
30
  const afterOperation = createAfterOperationHook({
30
31
  schemaCache,
31
32
  excludeValues,
32
- adminBasePath
33
+ adminBasePath,
34
+ enrichment
33
35
  });
34
36
  const globalBeforeRead = createGlobalBeforeReadHook();
35
37
  const globalAfterRead = createGlobalAfterReadHook({
36
38
  schemaCache,
37
39
  excludeValues,
38
- adminBasePath
40
+ adminBasePath,
41
+ enrichment
39
42
  });
40
43
  const stripStega = createStripStegaHook();
41
44
  return {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin } from \"payload\";\n\nimport type { ValueExcludePredicate } from \"./excludeValues.js\";\n\nimport { defaultExcludeValues } from \"./excludeValues.js\";\nimport { createAfterOperationHook } from \"./internal/afterOperationHook.js\";\nimport { createAfterReadHook } from \"./internal/afterReadHook.js\";\nimport {\n createBeforeOperationHook,\n createGlobalBeforeReadHook,\n} from \"./internal/beforeOperationHook.js\";\nimport { createGlobalAfterReadHook } from \"./internal/globalAfterReadHook.js\";\nimport { createSchemaCache } from \"./internal/schemaCache.js\";\nimport { createStripStegaHook } from \"./internal/stripStegaHook.js\";\n\nexport {\n defaultExcludeValues,\n isHash,\n isIsoDate,\n isSlug,\n isUrl,\n type ValueExcludePredicate,\n} from \"./excludeValues.js\";\n\nconst INTERNAL_COLLECTIONS = [\n \"payload-preferences\",\n \"payload-migrations\",\n \"payload-locked-documents\",\n \"payload-jobs\",\n];\n\nconst BRIDGE_COMPONENT_PATH =\n \"@focus-reactive/payload-plugin-visual-editing/admin#VisualEditingBridgeProvider\";\n\nexport type VisualEditingPluginConfig = {\n skipCollections?: string[];\n skipGlobals?: string[];\n excludeFieldNames?: string[];\n /** Value-shape predicates; any matching value is left un-stega'd. Replaces defaults when set.\n * Omit to use `defaultExcludeValues` (URL / slug / hash / ISO-date). */\n excludeValues?: ValueExcludePredicate[];\n adminBasePath?: string;\n};\n\nexport const visualEditingPlugin =\n (pluginConfig: VisualEditingPluginConfig = {}): Plugin =>\n (config) => {\n const skipCols = new Set([...INTERNAL_COLLECTIONS, ...(pluginConfig.skipCollections ?? [])]);\n const skipGlobals = new Set(pluginConfig.skipGlobals);\n const adminBasePath = pluginConfig.adminBasePath ?? \"/admin\";\n const excludeValues = pluginConfig.excludeValues ?? defaultExcludeValues;\n\n const schemaCache = createSchemaCache({\n excludeFieldNames: pluginConfig.excludeFieldNames,\n });\n const beforeOperation = createBeforeOperationHook();\n const afterRead = createAfterReadHook(adminBasePath);\n const afterOperation = createAfterOperationHook({ schemaCache, excludeValues, adminBasePath });\n const globalBeforeRead = createGlobalBeforeReadHook();\n const globalAfterRead = createGlobalAfterReadHook({\n schemaCache,\n excludeValues,\n adminBasePath,\n });\n const stripStega = createStripStegaHook();\n\n return {\n ...config,\n collections: config.collections?.map((collection) => {\n if (skipCols.has(collection.slug)) return collection;\n return {\n ...collection,\n hooks: {\n ...collection.hooks,\n beforeOperation: [...(collection.hooks?.beforeOperation ?? []), beforeOperation],\n beforeChange: [...(collection.hooks?.beforeChange ?? []), stripStega],\n afterRead: [...(collection.hooks?.afterRead ?? []), afterRead],\n afterOperation: [...(collection.hooks?.afterOperation ?? []), afterOperation],\n },\n };\n }),\n globals: config.globals?.map((global) => {\n if (skipGlobals.has(global.slug)) return global;\n return {\n ...global,\n hooks: {\n ...global.hooks,\n beforeRead: [...(global.hooks?.beforeRead ?? []), globalBeforeRead],\n beforeChange: [...(global.hooks?.beforeChange ?? []), stripStega],\n afterRead: [...(global.hooks?.afterRead ?? []), globalAfterRead],\n },\n };\n }),\n admin: {\n ...config.admin,\n components: {\n ...config.admin?.components,\n providers: [\n ...(config.admin?.components?.providers ?? []),\n {\n path: BRIDGE_COMPONENT_PATH,\n clientProps: { adminBasePath },\n },\n ],\n },\n },\n };\n };\n"],"names":["defaultExcludeValues","createAfterOperationHook","createAfterReadHook","createBeforeOperationHook","createGlobalBeforeReadHook","createGlobalAfterReadHook","createSchemaCache","createStripStegaHook","isHash","isIsoDate","isSlug","isUrl","INTERNAL_COLLECTIONS","BRIDGE_COMPONENT_PATH","visualEditingPlugin","pluginConfig","config","skipCols","Set","skipCollections","skipGlobals","adminBasePath","excludeValues","schemaCache","excludeFieldNames","beforeOperation","afterRead","afterOperation","globalBeforeRead","globalAfterRead","stripStega","collections","map","collection","has","slug","hooks","beforeChange","globals","global","beforeRead","admin","components","providers","path","clientProps"],"mappings":"AAIA,SAASA,oBAAoB,QAAQ,qBAAqB;AAC1D,SAASC,wBAAwB,QAAQ,mCAAmC;AAC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,WAAWG,KAAK,EAAEC,gBAAgB,EAAE;4BAAGP;yBAAW;wBACrEJ,WAAW;+BAAKO,WAAWG,KAAK,EAAEV,aAAa,EAAE;4BAAGA;yBAAU;wBAC9DC,gBAAgB;+BAAKM,WAAWG,KAAK,EAAET,kBAAkB,EAAE;4BAAGA;yBAAe;oBAC/E;gBACF;YACF;YACAW,SAAStB,OAAOsB,OAAO,EAAEN,IAAI,CAACO;gBAC5B,IAAInB,YAAYc,GAAG,CAACK,OAAOJ,IAAI,GAAG,OAAOI;gBACzC,OAAO;oBACL,GAAGA,MAAM;oBACTH,OAAO;wBACL,GAAGG,OAAOH,KAAK;wBACfI,YAAY;+BAAKD,OAAOH,KAAK,EAAEI,cAAc,EAAE;4BAAGZ;yBAAiB;wBACnES,cAAc;+BAAKE,OAAOH,KAAK,EAAEC,gBAAgB,EAAE;4BAAGP;yBAAW;wBACjEJ,WAAW;+BAAKa,OAAOH,KAAK,EAAEV,aAAa,EAAE;4BAAGG;yBAAgB;oBAClE;gBACF;YACF;YACAY,OAAO;gBACL,GAAGzB,OAAOyB,KAAK;gBACfC,YAAY;oBACV,GAAG1B,OAAOyB,KAAK,EAAEC,UAAU;oBAC3BC,WAAW;2BACL3B,OAAOyB,KAAK,EAAEC,YAAYC,aAAa,EAAE;wBAC7C;4BACEC,MAAM/B;4BACNgC,aAAa;gCAAExB;4BAAc;wBAC/B;qBACD;gBACH;YACF;QACF;IACF,EAAE"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin } from \"payload\";\n\nimport type { ValueExcludePredicate } from \"./excludeValues.js\";\nimport type { Enrichment } from \"./internal/gate.js\";\n\nimport { defaultExcludeValues } from \"./excludeValues.js\";\nimport { createAfterOperationHook } from \"./internal/afterOperationHook.js\";\nimport { createAfterReadHook } from \"./internal/afterReadHook.js\";\nimport {\n createBeforeOperationHook,\n createGlobalBeforeReadHook,\n} from \"./internal/beforeOperationHook.js\";\nimport { createGlobalAfterReadHook } from \"./internal/globalAfterReadHook.js\";\nimport { createSchemaCache } from \"./internal/schemaCache.js\";\nimport { createStripStegaHook } from \"./internal/stripStegaHook.js\";\n\nexport {\n defaultExcludeValues,\n isHash,\n isIsoDate,\n isSlug,\n isUrl,\n type ValueExcludePredicate,\n} from \"./excludeValues.js\";\n\ndeclare module \"payload\" {\n interface RequestContext {\n visualEditing?: boolean;\n }\n}\n\nconst INTERNAL_COLLECTIONS = [\n \"payload-preferences\",\n \"payload-migrations\",\n \"payload-locked-documents\",\n \"payload-jobs\",\n];\n\nconst BRIDGE_COMPONENT_PATH =\n \"@focus-reactive/payload-plugin-visual-editing/admin#VisualEditingBridgeProvider\";\n\nexport type VisualEditingPluginConfig = {\n skipCollections?: string[];\n skipGlobals?: string[];\n excludeFieldNames?: string[];\n /** Value-shape predicates; any matching value is left un-stega'd. Replaces defaults when set.\n * Omit to use `defaultExcludeValues` (URL / slug / hash / ISO-date). */\n excludeValues?: ValueExcludePredicate[];\n adminBasePath?: string;\n /** `'auto'` (default) enriches any Local API draft read outside the admin.\n * `'explicit'` enriches only reads that pass `context: { visualEditing: true }`. */\n enrichment?: Enrichment;\n};\n\nexport const visualEditingPlugin =\n (pluginConfig: VisualEditingPluginConfig = {}): Plugin =>\n (config) => {\n const skipCols = new Set([...INTERNAL_COLLECTIONS, ...(pluginConfig.skipCollections ?? [])]);\n const skipGlobals = new Set(pluginConfig.skipGlobals);\n const adminBasePath = pluginConfig.adminBasePath ?? \"/admin\";\n const excludeValues = pluginConfig.excludeValues ?? defaultExcludeValues;\n const enrichment = pluginConfig.enrichment ?? \"auto\";\n\n const schemaCache = createSchemaCache({\n excludeFieldNames: pluginConfig.excludeFieldNames,\n });\n const beforeOperation = createBeforeOperationHook();\n const afterRead = createAfterReadHook(adminBasePath, enrichment);\n const afterOperation = createAfterOperationHook({\n schemaCache,\n excludeValues,\n adminBasePath,\n enrichment,\n });\n const globalBeforeRead = createGlobalBeforeReadHook();\n const globalAfterRead = createGlobalAfterReadHook({\n schemaCache,\n excludeValues,\n adminBasePath,\n enrichment,\n });\n const stripStega = createStripStegaHook();\n\n return {\n ...config,\n collections: config.collections?.map((collection) => {\n if (skipCols.has(collection.slug)) return collection;\n return {\n ...collection,\n hooks: {\n ...collection.hooks,\n beforeOperation: [...(collection.hooks?.beforeOperation ?? []), beforeOperation],\n beforeChange: [...(collection.hooks?.beforeChange ?? []), stripStega],\n afterRead: [...(collection.hooks?.afterRead ?? []), afterRead],\n afterOperation: [...(collection.hooks?.afterOperation ?? []), afterOperation],\n },\n };\n }),\n globals: config.globals?.map((global) => {\n if (skipGlobals.has(global.slug)) return global;\n return {\n ...global,\n hooks: {\n ...global.hooks,\n beforeRead: [...(global.hooks?.beforeRead ?? []), globalBeforeRead],\n beforeChange: [...(global.hooks?.beforeChange ?? []), stripStega],\n afterRead: [...(global.hooks?.afterRead ?? []), globalAfterRead],\n },\n };\n }),\n admin: {\n ...config.admin,\n components: {\n ...config.admin?.components,\n providers: [\n ...(config.admin?.components?.providers ?? []),\n {\n path: BRIDGE_COMPONENT_PATH,\n clientProps: { adminBasePath },\n },\n ],\n },\n },\n };\n };\n"],"names":["defaultExcludeValues","createAfterOperationHook","createAfterReadHook","createBeforeOperationHook","createGlobalBeforeReadHook","createGlobalAfterReadHook","createSchemaCache","createStripStegaHook","isHash","isIsoDate","isSlug","isUrl","INTERNAL_COLLECTIONS","BRIDGE_COMPONENT_PATH","visualEditingPlugin","pluginConfig","config","skipCols","Set","skipCollections","skipGlobals","adminBasePath","excludeValues","enrichment","schemaCache","excludeFieldNames","beforeOperation","afterRead","afterOperation","globalBeforeRead","globalAfterRead","stripStega","collections","map","collection","has","slug","hooks","beforeChange","globals","global","beforeRead","admin","components","providers","path","clientProps"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,qBAAqB;AAC1D,SAASC,wBAAwB,QAAQ,mCAAmC;AAC5E,SAASC,mBAAmB,QAAQ,8BAA8B;AAClE,SACEC,yBAAyB,EACzBC,0BAA0B,QACrB,oCAAo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,gBAAgB,EAAE;4BAAGP;yBAAW;wBACrEJ,WAAW;+BAAKO,WAAWG,KAAK,EAAEV,aAAa,EAAE;4BAAGA;yBAAU;wBAC9DC,gBAAgB;+BAAKM,WAAWG,KAAK,EAAET,kBAAkB,EAAE;4BAAGA;yBAAe;oBAC/E;gBACF;YACF;YACAW,SAASvB,OAAOuB,OAAO,EAAEN,IAAI,CAACO;gBAC5B,IAAIpB,YAAYe,GAAG,CAACK,OAAOJ,IAAI,GAAG,OAAOI;gBACzC,OAAO;oBACL,GAAGA,MAAM;oBACTH,OAAO;wBACL,GAAGG,OAAOH,KAAK;wBACfI,YAAY;+BAAKD,OAAOH,KAAK,EAAEI,cAAc,EAAE;4BAAGZ;yBAAiB;wBACnES,cAAc;+BAAKE,OAAOH,KAAK,EAAEC,gBAAgB,EAAE;4BAAGP;yBAAW;wBACjEJ,WAAW;+BAAKa,OAAOH,KAAK,EAAEV,aAAa,EAAE;4BAAGG;yBAAgB;oBAClE;gBACF;YACF;YACAY,OAAO;gBACL,GAAG1B,OAAO0B,KAAK;gBACfC,YAAY;oBACV,GAAG3B,OAAO0B,KAAK,EAAEC,UAAU;oBAC3BC,WAAW;2BACL5B,OAAO0B,KAAK,EAAEC,YAAYC,aAAa,EAAE;wBAC7C;4BACEC,MAAMhC;4BACNiC,aAAa;gCAAEzB;4BAAc;wBAC/B;qBACD;gBACH;YACF;QACF;IACF,EAAE"}
@@ -1,10 +1,12 @@
1
1
  import type { CollectionAfterOperationHook } from "payload";
2
2
  import type { ValueExcludePredicate } from "../excludeValues.js";
3
3
  import type { SchemaCache } from "./schemaCache.js";
4
+ import type { Enrichment } from "./gate.js";
4
5
  type Args = {
5
6
  schemaCache: SchemaCache;
6
7
  excludeValues: readonly ValueExcludePredicate[];
7
8
  adminBasePath: string;
9
+ enrichment?: Enrichment;
8
10
  };
9
- export declare const createAfterOperationHook: ({ schemaCache, excludeValues, adminBasePath, }: Args) => CollectionAfterOperationHook;
11
+ export declare const createAfterOperationHook: ({ schemaCache, excludeValues, adminBasePath, enrichment, }: Args) => CollectionAfterOperationHook;
10
12
  export {};
@@ -10,10 +10,10 @@ const ENCODING_OPERATIONS = new Set([
10
10
  "findVersions",
11
11
  "findVersionByID"
12
12
  ]);
13
- export const createAfterOperationHook = ({ schemaCache, excludeValues, adminBasePath })=>{
13
+ export const createAfterOperationHook = ({ schemaCache, excludeValues, adminBasePath, enrichment })=>{
14
14
  return ({ operation, result, req })=>{
15
15
  if (!ENCODING_OPERATIONS.has(operation)) return result;
16
- if (!shouldEnrich(req, adminBasePath)) return result;
16
+ if (!shouldEnrich(req, adminBasePath, enrichment)) return result;
17
17
  const resolve = (slug)=>schemaCache.get(slug, req.payload);
18
18
  if (operation === "find" || operation === "findVersions") {
19
19
  if (Array.isArray(result.docs)) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/internal/afterOperationHook.ts"],"sourcesContent":["import type { CollectionAfterOperationHook, CollectionSlug } from \"payload\";\nimport type { ValueExcludePredicate } from \"../excludeValues.js\";\nimport type { SchemaCache } from \"./schemaCache.js\";\n\nimport { encodeStega } from \"./encodeStega.js\";\nimport { shouldEnrich } from \"./gate.js\";\n\ntype Args = {\n schemaCache: SchemaCache;\n excludeValues: readonly ValueExcludePredicate[];\n adminBasePath: string;\n};\n\n// Payload fires afterOperation exactly once per outermost operation.\n// Population uses lower-level reads that trigger afterRead (enrich only)\n// but not afterOperation — so we get the fully-populated tree here\n// and encode it in a single pass with no risk of double-encoding.\nconst ENCODING_OPERATIONS = new Set([\"find\", \"findByID\", \"findVersions\", \"findVersionByID\"]);\n\nexport const createAfterOperationHook = ({\n schemaCache,\n excludeValues,\n adminBasePath,\n}: Args): CollectionAfterOperationHook => {\n return ({ operation, result, req }) => {\n if (!ENCODING_OPERATIONS.has(operation)) return result;\n if (!shouldEnrich(req, adminBasePath)) return result;\n\n const resolve = (slug: CollectionSlug) => schemaCache.get(slug, req.payload);\n\n if (operation === \"find\" || operation === \"findVersions\") {\n if (Array.isArray(result.docs)) {\n result.docs = result.docs.map((doc) => encodeStega(doc, resolve, excludeValues));\n }\n return result;\n }\n\n return encodeStega(result, resolve, excludeValues);\n };\n};\n"],"names":["encodeStega","shouldEnrich","ENCODING_OPERATIONS","Set","createAfterOperationHook","schemaCache","excludeValues","adminBasePath","operation","result","req","has","resolve","slug","get","payload","Array","isArray","docs","map","doc"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAmB;AAC/C,SAASC,YAAY,QAAQ,YAAY;AAQzC,qEAAqE;AACrE,yEAAyE;AACzE,mEAAmE;AACnE,kEAAkE;AAClE,MAAMC,sBAAsB,IAAIC,IAAI;IAAC;IAAQ;IAAY;IAAgB;CAAkB;AAE3F,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,WAAW,EACXC,aAAa,EACbC,aAAa,EACR;IACL,OAAO,CAAC,EAAEC,SAAS,EAAEC,MAAM,EAAEC,GAAG,EAAE;QAChC,IAAI,CAACR,oBAAoBS,GAAG,CAACH,YAAY,OAAOC;QAChD,IAAI,CAACR,aAAaS,KAAKH,gBAAgB,OAAOE;QAE9C,MAAMG,UAAU,CAACC,OAAyBR,YAAYS,GAAG,CAACD,MAAMH,IAAIK,OAAO;QAE3E,IAAIP,cAAc,UAAUA,cAAc,gBAAgB;YACxD,IAAIQ,MAAMC,OAAO,CAACR,OAAOS,IAAI,GAAG;gBAC9BT,OAAOS,IAAI,GAAGT,OAAOS,IAAI,CAACC,GAAG,CAAC,CAACC,MAAQpB,YAAYoB,KAAKR,SAASN;YACnE;YACA,OAAOG;QACT;QAEA,OAAOT,YAAYS,QAAQG,SAASN;IACtC;AACF,EAAE"}
1
+ {"version":3,"sources":["../../src/internal/afterOperationHook.ts"],"sourcesContent":["import type { CollectionAfterOperationHook, CollectionSlug } from \"payload\";\nimport type { ValueExcludePredicate } from \"../excludeValues.js\";\nimport type { SchemaCache } from \"./schemaCache.js\";\nimport type { Enrichment } from \"./gate.js\";\n\nimport { encodeStega } from \"./encodeStega.js\";\nimport { shouldEnrich } from \"./gate.js\";\n\ntype Args = {\n schemaCache: SchemaCache;\n excludeValues: readonly ValueExcludePredicate[];\n adminBasePath: string;\n enrichment?: Enrichment;\n};\n\n// Payload fires afterOperation exactly once per outermost operation.\n// Population uses lower-level reads that trigger afterRead (enrich only)\n// but not afterOperation — so we get the fully-populated tree here\n// and encode it in a single pass with no risk of double-encoding.\nconst ENCODING_OPERATIONS = new Set([\"find\", \"findByID\", \"findVersions\", \"findVersionByID\"]);\n\nexport const createAfterOperationHook = ({\n schemaCache,\n excludeValues,\n adminBasePath,\n enrichment,\n}: Args): CollectionAfterOperationHook => {\n return ({ operation, result, req }) => {\n if (!ENCODING_OPERATIONS.has(operation)) return result;\n if (!shouldEnrich(req, adminBasePath, enrichment)) return result;\n\n const resolve = (slug: CollectionSlug) => schemaCache.get(slug, req.payload);\n\n if (operation === \"find\" || operation === \"findVersions\") {\n if (Array.isArray(result.docs)) {\n result.docs = result.docs.map((doc) => encodeStega(doc, resolve, excludeValues));\n }\n return result;\n }\n\n return encodeStega(result, resolve, excludeValues);\n };\n};\n"],"names":["encodeStega","shouldEnrich","ENCODING_OPERATIONS","Set","createAfterOperationHook","schemaCache","excludeValues","adminBasePath","enrichment","operation","result","req","has","resolve","slug","get","payload","Array","isArray","docs","map","doc"],"mappings":"AAKA,SAASA,WAAW,QAAQ,mBAAmB;AAC/C,SAASC,YAAY,QAAQ,YAAY;AASzC,qEAAqE;AACrE,yEAAyE;AACzE,mEAAmE;AACnE,kEAAkE;AAClE,MAAMC,sBAAsB,IAAIC,IAAI;IAAC;IAAQ;IAAY;IAAgB;CAAkB;AAE3F,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,WAAW,EACXC,aAAa,EACbC,aAAa,EACbC,UAAU,EACL;IACL,OAAO,CAAC,EAAEC,SAAS,EAAEC,MAAM,EAAEC,GAAG,EAAE;QAChC,IAAI,CAACT,oBAAoBU,GAAG,CAACH,YAAY,OAAOC;QAChD,IAAI,CAACT,aAAaU,KAAKJ,eAAeC,aAAa,OAAOE;QAE1D,MAAMG,UAAU,CAACC,OAAyBT,YAAYU,GAAG,CAACD,MAAMH,IAAIK,OAAO;QAE3E,IAAIP,cAAc,UAAUA,cAAc,gBAAgB;YACxD,IAAIQ,MAAMC,OAAO,CAACR,OAAOS,IAAI,GAAG;gBAC9BT,OAAOS,IAAI,GAAGT,OAAOS,IAAI,CAACC,GAAG,CAAC,CAACC,MAAQrB,YAAYqB,KAAKR,SAASP;YACnE;YACA,OAAOI;QACT;QAEA,OAAOV,YAAYU,QAAQG,SAASP;IACtC;AACF,EAAE"}
@@ -1,2 +1,3 @@
1
1
  import type { CollectionAfterReadHook } from "payload";
2
- export declare const createAfterReadHook: (adminBasePath: string) => CollectionAfterReadHook;
2
+ import type { Enrichment } from "./gate.js";
3
+ export declare const createAfterReadHook: (adminBasePath: string, enrichment?: Enrichment) => CollectionAfterReadHook;
@@ -1,8 +1,8 @@
1
1
  import { enrichWithPathMeta } from "./enrichWithPathMeta.js";
2
2
  import { shouldEnrich } from "./gate.js";
3
- export const createAfterReadHook = (adminBasePath)=>{
3
+ export const createAfterReadHook = (adminBasePath, enrichment)=>{
4
4
  return ({ doc, collection, req })=>{
5
- if (!shouldEnrich(req, adminBasePath)) return doc;
5
+ if (!shouldEnrich(req, adminBasePath, enrichment)) return doc;
6
6
  if (!doc || typeof doc !== "object") return doc;
7
7
  const docId = typeof doc.id === "string" || typeof doc.id === "number" ? String(doc.id) : undefined;
8
8
  return enrichWithPathMeta(doc, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/internal/afterReadHook.ts"],"sourcesContent":["import type { CollectionAfterReadHook } from \"payload\";\n\nimport { enrichWithPathMeta } from \"./enrichWithPathMeta.js\";\nimport { shouldEnrich } from \"./gate.js\";\n\nexport const createAfterReadHook = (adminBasePath: string): CollectionAfterReadHook => {\n return ({ doc, collection, req }) => {\n if (!shouldEnrich(req, adminBasePath)) return doc;\n if (!doc || typeof doc !== \"object\") return doc;\n\n const docId =\n typeof doc.id === \"string\" || typeof doc.id === \"number\" ? String(doc.id) : undefined;\n return enrichWithPathMeta(doc, {\n docId,\n collectionSlug: collection.slug,\n kind: \"collection\",\n });\n };\n};\n"],"names":["enrichWithPathMeta","shouldEnrich","createAfterReadHook","adminBasePath","doc","collection","req","docId","id","String","undefined","collectionSlug","slug","kind"],"mappings":"AAEA,SAASA,kBAAkB,QAAQ,0BAA0B;AAC7D,SAASC,YAAY,QAAQ,YAAY;AAEzC,OAAO,MAAMC,sBAAsB,CAACC;IAClC,OAAO,CAAC,EAAEC,GAAG,EAAEC,UAAU,EAAEC,GAAG,EAAE;QAC9B,IAAI,CAACL,aAAaK,KAAKH,gBAAgB,OAAOC;QAC9C,IAAI,CAACA,OAAO,OAAOA,QAAQ,UAAU,OAAOA;QAE5C,MAAMG,QACJ,OAAOH,IAAII,EAAE,KAAK,YAAY,OAAOJ,IAAII,EAAE,KAAK,WAAWC,OAAOL,IAAII,EAAE,IAAIE;QAC9E,OAAOV,mBAAmBI,KAAK;YAC7BG;YACAI,gBAAgBN,WAAWO,IAAI;YAC/BC,MAAM;QACR;IACF;AACF,EAAE"}
1
+ {"version":3,"sources":["../../src/internal/afterReadHook.ts"],"sourcesContent":["import type { CollectionAfterReadHook } from \"payload\";\nimport type { Enrichment } from \"./gate.js\";\n\nimport { enrichWithPathMeta } from \"./enrichWithPathMeta.js\";\nimport { shouldEnrich } from \"./gate.js\";\n\nexport const createAfterReadHook = (\n adminBasePath: string,\n enrichment?: Enrichment\n): CollectionAfterReadHook => {\n return ({ doc, collection, req }) => {\n if (!shouldEnrich(req, adminBasePath, enrichment)) return doc;\n if (!doc || typeof doc !== \"object\") return doc;\n\n const docId =\n typeof doc.id === \"string\" || typeof doc.id === \"number\" ? String(doc.id) : undefined;\n return enrichWithPathMeta(doc, {\n docId,\n collectionSlug: collection.slug,\n kind: \"collection\",\n });\n };\n};\n"],"names":["enrichWithPathMeta","shouldEnrich","createAfterReadHook","adminBasePath","enrichment","doc","collection","req","docId","id","String","undefined","collectionSlug","slug","kind"],"mappings":"AAGA,SAASA,kBAAkB,QAAQ,0BAA0B;AAC7D,SAASC,YAAY,QAAQ,YAAY;AAEzC,OAAO,MAAMC,sBAAsB,CACjCC,eACAC;IAEA,OAAO,CAAC,EAAEC,GAAG,EAAEC,UAAU,EAAEC,GAAG,EAAE;QAC9B,IAAI,CAACN,aAAaM,KAAKJ,eAAeC,aAAa,OAAOC;QAC1D,IAAI,CAACA,OAAO,OAAOA,QAAQ,UAAU,OAAOA;QAE5C,MAAMG,QACJ,OAAOH,IAAII,EAAE,KAAK,YAAY,OAAOJ,IAAII,EAAE,KAAK,WAAWC,OAAOL,IAAII,EAAE,IAAIE;QAC9E,OAAOX,mBAAmBK,KAAK;YAC7BG;YACAI,gBAAgBN,WAAWO,IAAI;YAC/BC,MAAM;QACR;IACF;AACF,EAAE"}
@@ -1,2 +1,3 @@
1
1
  import type { PayloadRequest } from "payload";
2
- export declare const shouldEnrich: (req: PayloadRequest, adminBasePath: string) => boolean;
2
+ export type Enrichment = "auto" | "explicit";
3
+ export declare const shouldEnrich: (req: PayloadRequest, adminBasePath: string, enrichment?: Enrichment) => boolean;
@@ -1,8 +1,9 @@
1
1
  import { DRAFT_CONTEXT_KEY } from "./beforeOperationHook.js";
2
- export const shouldEnrich = (req, adminBasePath)=>{
2
+ export const shouldEnrich = (req, adminBasePath, enrichment = "auto")=>{
3
3
  const context = req.context;
4
4
  const override = context?.visualEditing;
5
5
  if (typeof override === "boolean") return override;
6
+ if (enrichment === "explicit") return false;
6
7
  if (context?.[DRAFT_CONTEXT_KEY] !== true) return false;
7
8
  if (req.payloadAPI !== "local") return false;
8
9
  // The admin edit view also reads via Local API + draft:true; only its pathname
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/internal/gate.ts"],"sourcesContent":["import type { PayloadRequest } from \"payload\";\n\nimport { DRAFT_CONTEXT_KEY } from \"./beforeOperationHook.js\";\n\nexport const shouldEnrich = (req: PayloadRequest, adminBasePath: string): boolean => {\n const context = req.context;\n\n const override = context?.visualEditing;\n if (typeof override === \"boolean\") return override;\n\n if (context?.[DRAFT_CONTEXT_KEY] !== true) return false;\n if (req.payloadAPI !== \"local\") return false;\n\n // The admin edit view also reads via Local API + draft:true; only its pathname\n // (under the admin base path) sets it apart from a frontend RSC render. Skip it\n // so stega doesn't leak into form inputs (and persist on save).\n if ((req.pathname ?? \"\").startsWith(adminBasePath)) return false;\n\n return true;\n};\n"],"names":["DRAFT_CONTEXT_KEY","shouldEnrich","req","adminBasePath","context","override","visualEditing","payloadAPI","pathname","startsWith"],"mappings":"AAEA,SAASA,iBAAiB,QAAQ,2BAA2B;AAE7D,OAAO,MAAMC,eAAe,CAACC,KAAqBC;IAChD,MAAMC,UAAUF,IAAIE,OAAO;IAE3B,MAAMC,WAAWD,SAASE;IAC1B,IAAI,OAAOD,aAAa,WAAW,OAAOA;IAE1C,IAAID,SAAS,CAACJ,kBAAkB,KAAK,MAAM,OAAO;IAClD,IAAIE,IAAIK,UAAU,KAAK,SAAS,OAAO;IAEvC,+EAA+E;IAC/E,gFAAgF;IAChF,gEAAgE;IAChE,IAAI,AAACL,CAAAA,IAAIM,QAAQ,IAAI,EAAC,EAAGC,UAAU,CAACN,gBAAgB,OAAO;IAE3D,OAAO;AACT,EAAE"}
1
+ {"version":3,"sources":["../../src/internal/gate.ts"],"sourcesContent":["import type { PayloadRequest } from \"payload\";\n\nimport { DRAFT_CONTEXT_KEY } from \"./beforeOperationHook.js\";\n\nexport type Enrichment = \"auto\" | \"explicit\";\n\nexport const shouldEnrich = (\n req: PayloadRequest,\n adminBasePath: string,\n enrichment: Enrichment = \"auto\"\n): boolean => {\n const context = req.context;\n\n const override = context?.visualEditing;\n if (typeof override === \"boolean\") return override;\n\n if (enrichment === \"explicit\") return false;\n\n if (context?.[DRAFT_CONTEXT_KEY] !== true) return false;\n if (req.payloadAPI !== \"local\") return false;\n\n // The admin edit view also reads via Local API + draft:true; only its pathname\n // (under the admin base path) sets it apart from a frontend RSC render. Skip it\n // so stega doesn't leak into form inputs (and persist on save).\n if ((req.pathname ?? \"\").startsWith(adminBasePath)) return false;\n\n return true;\n};\n"],"names":["DRAFT_CONTEXT_KEY","shouldEnrich","req","adminBasePath","enrichment","context","override","visualEditing","payloadAPI","pathname","startsWith"],"mappings":"AAEA,SAASA,iBAAiB,QAAQ,2BAA2B;AAI7D,OAAO,MAAMC,eAAe,CAC1BC,KACAC,eACAC,aAAyB,MAAM;IAE/B,MAAMC,UAAUH,IAAIG,OAAO;IAE3B,MAAMC,WAAWD,SAASE;IAC1B,IAAI,OAAOD,aAAa,WAAW,OAAOA;IAE1C,IAAIF,eAAe,YAAY,OAAO;IAEtC,IAAIC,SAAS,CAACL,kBAAkB,KAAK,MAAM,OAAO;IAClD,IAAIE,IAAIM,UAAU,KAAK,SAAS,OAAO;IAEvC,+EAA+E;IAC/E,gFAAgF;IAChF,gEAAgE;IAChE,IAAI,AAACN,CAAAA,IAAIO,QAAQ,IAAI,EAAC,EAAGC,UAAU,CAACP,gBAAgB,OAAO;IAE3D,OAAO;AACT,EAAE"}
@@ -1,10 +1,12 @@
1
1
  import type { GlobalAfterReadHook } from "payload";
2
2
  import type { ValueExcludePredicate } from "../excludeValues.js";
3
3
  import type { SchemaCache } from "./schemaCache.js";
4
+ import type { Enrichment } from "./gate.js";
4
5
  type Args = {
5
6
  schemaCache: SchemaCache;
6
7
  excludeValues: readonly ValueExcludePredicate[];
7
8
  adminBasePath: string;
9
+ enrichment?: Enrichment;
8
10
  };
9
- export declare const createGlobalAfterReadHook: ({ schemaCache, excludeValues, adminBasePath, }: Args) => GlobalAfterReadHook;
11
+ export declare const createGlobalAfterReadHook: ({ schemaCache, excludeValues, adminBasePath, enrichment, }: Args) => GlobalAfterReadHook;
10
12
  export {};
@@ -4,9 +4,9 @@ import { shouldEnrich } from "./gate.js";
4
4
  // Globals: no afterOperation hook exists, so enrichment + encoding happen here.
5
5
  // Populated collection sub-docs (if any) already carry their own `_meta` from their own afterRead;
6
6
  // `enrichWithPathMeta` preserves those.
7
- export const createGlobalAfterReadHook = ({ schemaCache, excludeValues, adminBasePath })=>{
7
+ export const createGlobalAfterReadHook = ({ schemaCache, excludeValues, adminBasePath, enrichment })=>{
8
8
  return ({ doc, global, req })=>{
9
- if (!shouldEnrich(req, adminBasePath)) return doc;
9
+ if (!shouldEnrich(req, adminBasePath, enrichment)) return doc;
10
10
  if (!doc || typeof doc !== "object") return doc;
11
11
  const enriched = enrichWithPathMeta(doc, {
12
12
  collectionSlug: global.slug,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/internal/globalAfterReadHook.ts"],"sourcesContent":["import type { GlobalAfterReadHook } from \"payload\";\nimport type { ValueExcludePredicate } from \"../excludeValues.js\";\nimport type { SchemaCache } from \"./schemaCache.js\";\n\nimport { encodeStega } from \"./encodeStega.js\";\nimport { enrichWithPathMeta } from \"./enrichWithPathMeta.js\";\nimport { shouldEnrich } from \"./gate.js\";\n\ntype Args = {\n schemaCache: SchemaCache;\n excludeValues: readonly ValueExcludePredicate[];\n adminBasePath: string;\n};\n\n// Globals: no afterOperation hook exists, so enrichment + encoding happen here.\n// Populated collection sub-docs (if any) already carry their own `_meta` from their own afterRead;\n// `enrichWithPathMeta` preserves those.\nexport const createGlobalAfterReadHook = ({\n schemaCache,\n excludeValues,\n adminBasePath,\n}: Args): GlobalAfterReadHook => {\n return ({ doc, global, req }) => {\n if (!shouldEnrich(req, adminBasePath)) return doc;\n if (!doc || typeof doc !== \"object\") return doc;\n\n const enriched = enrichWithPathMeta(doc, {\n collectionSlug: global.slug,\n kind: \"global\",\n });\n return encodeStega(enriched, (slug) => schemaCache.get(slug, req.payload), excludeValues);\n };\n};\n"],"names":["encodeStega","enrichWithPathMeta","shouldEnrich","createGlobalAfterReadHook","schemaCache","excludeValues","adminBasePath","doc","global","req","enriched","collectionSlug","slug","kind","get","payload"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAmB;AAC/C,SAASC,kBAAkB,QAAQ,0BAA0B;AAC7D,SAASC,YAAY,QAAQ,YAAY;AAQzC,gFAAgF;AAChF,mGAAmG;AACnG,wCAAwC;AACxC,OAAO,MAAMC,4BAA4B,CAAC,EACxCC,WAAW,EACXC,aAAa,EACbC,aAAa,EACR;IACL,OAAO,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,GAAG,EAAE;QAC1B,IAAI,CAACP,aAAaO,KAAKH,gBAAgB,OAAOC;QAC9C,IAAI,CAACA,OAAO,OAAOA,QAAQ,UAAU,OAAOA;QAE5C,MAAMG,WAAWT,mBAAmBM,KAAK;YACvCI,gBAAgBH,OAAOI,IAAI;YAC3BC,MAAM;QACR;QACA,OAAOb,YAAYU,UAAU,CAACE,OAASR,YAAYU,GAAG,CAACF,MAAMH,IAAIM,OAAO,GAAGV;IAC7E;AACF,EAAE"}
1
+ {"version":3,"sources":["../../src/internal/globalAfterReadHook.ts"],"sourcesContent":["import type { GlobalAfterReadHook } from \"payload\";\nimport type { ValueExcludePredicate } from \"../excludeValues.js\";\nimport type { SchemaCache } from \"./schemaCache.js\";\nimport type { Enrichment } from \"./gate.js\";\n\nimport { encodeStega } from \"./encodeStega.js\";\nimport { enrichWithPathMeta } from \"./enrichWithPathMeta.js\";\nimport { shouldEnrich } from \"./gate.js\";\n\ntype Args = {\n schemaCache: SchemaCache;\n excludeValues: readonly ValueExcludePredicate[];\n adminBasePath: string;\n enrichment?: Enrichment;\n};\n\n// Globals: no afterOperation hook exists, so enrichment + encoding happen here.\n// Populated collection sub-docs (if any) already carry their own `_meta` from their own afterRead;\n// `enrichWithPathMeta` preserves those.\nexport const createGlobalAfterReadHook = ({\n schemaCache,\n excludeValues,\n adminBasePath,\n enrichment,\n}: Args): GlobalAfterReadHook => {\n return ({ doc, global, req }) => {\n if (!shouldEnrich(req, adminBasePath, enrichment)) return doc;\n if (!doc || typeof doc !== \"object\") return doc;\n\n const enriched = enrichWithPathMeta(doc, {\n collectionSlug: global.slug,\n kind: \"global\",\n });\n return encodeStega(enriched, (slug) => schemaCache.get(slug, req.payload), excludeValues);\n };\n};\n"],"names":["encodeStega","enrichWithPathMeta","shouldEnrich","createGlobalAfterReadHook","schemaCache","excludeValues","adminBasePath","enrichment","doc","global","req","enriched","collectionSlug","slug","kind","get","payload"],"mappings":"AAKA,SAASA,WAAW,QAAQ,mBAAmB;AAC/C,SAASC,kBAAkB,QAAQ,0BAA0B;AAC7D,SAASC,YAAY,QAAQ,YAAY;AASzC,gFAAgF;AAChF,mGAAmG;AACnG,wCAAwC;AACxC,OAAO,MAAMC,4BAA4B,CAAC,EACxCC,WAAW,EACXC,aAAa,EACbC,aAAa,EACbC,UAAU,EACL;IACL,OAAO,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,GAAG,EAAE;QAC1B,IAAI,CAACR,aAAaQ,KAAKJ,eAAeC,aAAa,OAAOC;QAC1D,IAAI,CAACA,OAAO,OAAOA,QAAQ,UAAU,OAAOA;QAE5C,MAAMG,WAAWV,mBAAmBO,KAAK;YACvCI,gBAAgBH,OAAOI,IAAI;YAC3BC,MAAM;QACR;QACA,OAAOd,YAAYW,UAAU,CAACE,OAAST,YAAYW,GAAG,CAACF,MAAMH,IAAIM,OAAO,GAAGX;IAC7E;AACF,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@focus-reactive/payload-plugin-visual-editing",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Visual editing for Payload CMS — click-to-edit overlays on your frontend via Vercel stega and a postMessage bridge back to the admin.",
5
5
  "license": "MIT",
6
6
  "author": "FocusReactive <ship@focusreactive.com>",