@focus-reactive/payload-plugin-visual-editing 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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:
@@ -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
 
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;AAC5E,SAASC,mBAAmB,QAAQ,8BAA8B;AAClE,SACEC,yBAAyB,EACzBC,0BAA0B,QACrB,oCAAoC;AAC3C,SAASC,yBAAyB,QAAQ,oCAAoC;AAC9E,SAASC,iBAAiB,QAAQ,4BAA4B;AAC9D,SAASC,oBAAoB,QAAQ,+BAA+B;AAEpE,SACEP,oBAAoB,EACpBQ,MAAM,EACNC,SAAS,EACTC,MAAM,EACNC,KAAK,QAEA,qBAAqB;AAE5B,MAAMC,uBAAuB;IAC3B;IACA;IACA;IACA;CACD;AAED,MAAMC,wBACJ;AAYF,OAAO,MAAMC,sBACX,CAACC,eAA0C,CAAC,CAAC,GAC7C,CAACC;QACC,MAAMC,WAAW,IAAIC,IAAI;eAAIN;eAA0BG,aAAaI,eAAe,IAAI,EAAE;SAAE;QAC3F,MAAMC,cAAc,IAAIF,IAAIH,aAAaK,WAAW;QACpD,MAAMC,gBAAgBN,aAAaM,aAAa,IAAI;QACpD,MAAMC,gBAAgBP,aAAaO,aAAa,IAAItB;QAEpD,MAAMuB,cAAcjB,kBAAkB;YACpCkB,mBAAmBT,aAAaS,iBAAiB;QACnD;QACA,MAAMC,kBAAkBtB;QACxB,MAAMuB,YAAYxB,oBAAoBmB;QACtC,MAAMM,iBAAiB1B,yBAAyB;YAAEsB;YAAaD;YAAeD;QAAc;QAC5F,MAAMO,mBAAmBxB;QACzB,MAAMyB,kBAAkBxB,0BAA0B;YAChDkB;YACAD;YACAD;QACF;QACA,MAAMS,aAAavB;QAEnB,OAAO;YACL,GAAGS,MAAM;YACTe,aAAaf,OAAOe,WAAW,EAAEC,IAAI,CAACC;gBACpC,IAAIhB,SAASiB,GAAG,CAACD,WAAWE,IAAI,GAAG,OAAOF;gBAC1C,OAAO;oBACL,GAAGA,UAAU;oBACbG,OAAO;wBACL,GAAGH,WAAWG,KAAK;wBACnBX,iBAAiB;+BAAKQ,WAAWG,KAAK,EAAEX,mBAAmB,EAAE;4BAAGA;yBAAgB;wBAChFY,cAAc;+BAAKJ,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,oCAAoC;AAC3C,SAASC,yBAAyB,QAAQ,oCAAoC;AAC9E,SAASC,iBAAiB,QAAQ,4BAA4B;AAC9D,SAASC,oBAAoB,QAAQ,+BAA+B;AAEpE,SACEP,oBAAoB,EACpBQ,MAAM,EACNC,SAAS,EACTC,MAAM,EACNC,KAAK,QAEA,qBAAqB;AAQ5B,MAAMC,uBAAuB;IAC3B;IACA;IACA;IACA;CACD;AAED,MAAMC,wBACJ;AAeF,OAAO,MAAMC,sBACX,CAACC,eAA0C,CAAC,CAAC,GAC7C,CAACC;QACC,MAAMC,WAAW,IAAIC,IAAI;eAAIN;eAA0BG,aAAaI,eAAe,IAAI,EAAE;SAAE;QAC3F,MAAMC,cAAc,IAAIF,IAAIH,aAAaK,WAAW;QACpD,MAAMC,gBAAgBN,aAAaM,aAAa,IAAI;QACpD,MAAMC,gBAAgBP,aAAaO,aAAa,IAAItB;QACpD,MAAMuB,aAAaR,aAAaQ,UAAU,IAAI;QAE9C,MAAMC,cAAclB,kBAAkB;YACpCmB,mBAAmBV,aAAaU,iBAAiB;QACnD;QACA,MAAMC,kBAAkBvB;QACxB,MAAMwB,YAAYzB,oBAAoBmB,eAAeE;QACrD,MAAMK,iBAAiB3B,yBAAyB;YAC9CuB;YACAF;YACAD;YACAE;QACF;QACA,MAAMM,mBAAmBzB;QACzB,MAAM0B,kBAAkBzB,0BAA0B;YAChDmB;YACAF;YACAD;YACAE;QACF;QACA,MAAMQ,aAAaxB;QAEnB,OAAO;YACL,GAAGS,MAAM;YACTgB,aAAahB,OAAOgB,WAAW,EAAEC,IAAI,CAACC;gBACpC,IAAIjB,SAASkB,GAAG,CAACD,WAAWE,IAAI,GAAG,OAAOF;gBAC1C,OAAO;oBACL,GAAGA,UAAU;oBACbG,OAAO;wBACL,GAAGH,WAAWG,KAAK;wBACnBX,iBAAiB;+BAAKQ,WAAWG,KAAK,EAAEX,mBAAmB,EAAE;4BAAGA;yBAAgB;wBAChFY,cAAc;+BAAKJ,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,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.0",
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>",