@derweili/payload-visual-editing 0.0.0-stage → 0.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +142 -2
  4. package/dist/client/VisualEditingAdmin.d.ts +9 -0
  5. package/dist/client/VisualEditingAdmin.d.ts.map +1 -0
  6. package/dist/client/VisualEditingAdmin.js +109 -0
  7. package/dist/client/VisualEditingAdmin.js.map +1 -0
  8. package/dist/client/dom-adapter.d.ts +61 -0
  9. package/dist/client/dom-adapter.d.ts.map +1 -0
  10. package/dist/client/dom-adapter.js +177 -0
  11. package/dist/client/dom-adapter.js.map +1 -0
  12. package/dist/client/focus.d.ts +36 -0
  13. package/dist/client/focus.d.ts.map +1 -0
  14. package/dist/client/focus.js +61 -0
  15. package/dist/client/focus.js.map +1 -0
  16. package/dist/client/index.d.ts +6 -0
  17. package/dist/client/index.d.ts.map +1 -0
  18. package/dist/client/index.js +7 -0
  19. package/dist/client/index.js.map +1 -0
  20. package/dist/client/keep-in-view.d.ts +6 -0
  21. package/dist/client/keep-in-view.d.ts.map +1 -0
  22. package/dist/client/keep-in-view.js +78 -0
  23. package/dist/client/keep-in-view.js.map +1 -0
  24. package/dist/client/resolve-focus.d.ts +56 -0
  25. package/dist/client/resolve-focus.d.ts.map +1 -0
  26. package/dist/client/resolve-focus.js +138 -0
  27. package/dist/client/resolve-focus.js.map +1 -0
  28. package/dist/server/encode-document.d.ts +23 -0
  29. package/dist/server/encode-document.d.ts.map +1 -0
  30. package/dist/server/encode-document.js +147 -0
  31. package/dist/server/encode-document.js.map +1 -0
  32. package/dist/server/hooks.d.ts +17 -0
  33. package/dist/server/hooks.d.ts.map +1 -0
  34. package/dist/server/hooks.js +79 -0
  35. package/dist/server/hooks.js.map +1 -0
  36. package/dist/server/index.d.ts +10 -0
  37. package/dist/server/index.d.ts.map +1 -0
  38. package/dist/server/index.js +10 -0
  39. package/dist/server/index.js.map +1 -0
  40. package/dist/server/options.d.ts +58 -0
  41. package/dist/server/options.d.ts.map +1 -0
  42. package/dist/server/options.js +18 -0
  43. package/dist/server/options.js.map +1 -0
  44. package/dist/server/path-matcher.d.ts +8 -0
  45. package/dist/server/path-matcher.d.ts.map +1 -0
  46. package/dist/server/path-matcher.js +32 -0
  47. package/dist/server/path-matcher.js.map +1 -0
  48. package/dist/server/plugin.d.ts +13 -0
  49. package/dist/server/plugin.d.ts.map +1 -0
  50. package/dist/server/plugin.js +102 -0
  51. package/dist/server/plugin.js.map +1 -0
  52. package/package.json +74 -3
@@ -0,0 +1,17 @@
1
+ import type { CollectionAfterReadHook, CollectionBeforeOperationHook, CollectionBeforeValidateHook, GlobalAfterReadHook, GlobalBeforeOperationHook, GlobalBeforeValidateHook, PayloadRequest } from 'payload';
2
+ import { type ResolvedSourceMapOptions } from './options.ts';
3
+ /** True when this request asked for source maps (Local API context or an allowed REST request). */
4
+ export declare const shouldEncode: (req: PayloadRequest) => boolean;
5
+ export declare function createHooks(options: ResolvedSourceMapOptions): {
6
+ collection: {
7
+ beforeOperation: CollectionBeforeOperationHook;
8
+ beforeValidate: CollectionBeforeValidateHook;
9
+ afterRead: CollectionAfterReadHook;
10
+ };
11
+ global: {
12
+ beforeOperation: GlobalBeforeOperationHook;
13
+ beforeValidate: GlobalBeforeValidateHook;
14
+ afterRead: GlobalAfterReadHook;
15
+ };
16
+ };
17
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/server/hooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,uBAAuB,EACvB,6BAA6B,EAC7B,4BAA4B,EAG5B,mBAAmB,EACnB,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,EACf,MAAM,SAAS,CAAA;AAGhB,OAAO,EAA0C,KAAK,wBAAwB,EAAE,MAAM,cAAc,CAAA;AAGpG,mGAAmG;AACnG,eAAO,MAAM,YAAY,QAAS,cAAc,KAAG,OAAqD,CAAA;AAexG,wBAAgB,WAAW,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;;EA6D5D"}
@@ -0,0 +1,79 @@
1
+ import { stegaClean } from '@derweili/payload-visual-editing-core';
2
+ import { encodeDocument } from "./encode-document.js";
3
+ import { ENCODE_CONTEXT_KEY, ENCODE_QUERY_PARAM } from "./options.js";
4
+ import { createPathMatcher } from "./path-matcher.js";
5
+ /** True when this request asked for source maps (Local API context or an allowed REST request). */ export const shouldEncode = (req)=>req.context?.[ENCODE_CONTEXT_KEY] === true;
6
+ /**
7
+ * REST: moves `?encodeSourceMaps=true` into `req.context` for GET reads, if `canEncode`
8
+ * allows it. Populated relationships share the request, so they see the flag too.
9
+ */ async function applyQueryFlag(req, operation, options) {
10
+ // Only plain REST reads. A write (PATCH, POST, …) reads the document again on the same request,
11
+ // which would otherwise encode the response of the write.
12
+ if (operation !== 'read' || req.method !== 'GET') return;
13
+ if (req.query?.[ENCODE_QUERY_PARAM] !== 'true') return;
14
+ if (!await options.canEncode({
15
+ req
16
+ })) return;
17
+ req.context[ENCODE_CONTEXT_KEY] = true;
18
+ }
19
+ export function createHooks(options) {
20
+ const isIncluded = options.include ? createPathMatcher(options.include) : ()=>true;
21
+ const isExcluded = createPathMatcher(options.exclude);
22
+ const shouldEncodePath = (path)=>isIncluded(path) && !isExcluded(path);
23
+ const encode = (req, fields, data, target)=>{
24
+ const localization = req.payload.config.localization;
25
+ encodeDocument({
26
+ fields,
27
+ data,
28
+ target,
29
+ locale: req.locale ?? undefined,
30
+ locales: localization ? localization.localeCodes : null,
31
+ skip: options.skip,
32
+ shouldEncodePath,
33
+ // Generic lookup: an app's generated types narrow `blocks` to its own block slugs
34
+ resolveBlock: (slug)=>req.payload.blocks[slug]
35
+ });
36
+ };
37
+ const collectionBeforeOperation = async ({ args, operation, req })=>{
38
+ await applyQueryFlag(req, operation, options);
39
+ return args;
40
+ };
41
+ const globalBeforeOperation = async ({ args, operation, req })=>{
42
+ await applyQueryFlag(req, operation, options);
43
+ return args;
44
+ };
45
+ const collectionAfterRead = ({ collection, doc, req })=>{
46
+ if (!shouldEncode(req) || !doc) return doc;
47
+ encode(req, collection.flattenedFields, doc, {
48
+ collection: collection.slug,
49
+ id: doc.id
50
+ });
51
+ return doc;
52
+ };
53
+ const globalAfterRead = ({ doc, global, req })=>{
54
+ if (!shouldEncode(req) || !doc) return doc;
55
+ encode(req, global.flattenedFields, doc, {
56
+ global: global.slug
57
+ });
58
+ return doc;
59
+ };
60
+ /**
61
+ * Encoded text must never be saved: e.g. an editor copies text from the preview into the admin,
62
+ * or a hook writes back a document it read with the flag on.
63
+ */ const collectionBeforeValidate = ({ data })=>data ? stegaClean(data) : data;
64
+ const globalBeforeValidate = ({ data })=>data ? stegaClean(data) : data;
65
+ return {
66
+ collection: {
67
+ beforeOperation: collectionBeforeOperation,
68
+ beforeValidate: collectionBeforeValidate,
69
+ afterRead: collectionAfterRead
70
+ },
71
+ global: {
72
+ beforeOperation: globalBeforeOperation,
73
+ beforeValidate: globalBeforeValidate,
74
+ afterRead: globalAfterRead
75
+ }
76
+ };
77
+ }
78
+
79
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/server/hooks.ts"],"sourcesContent":["import { stegaClean } from '@derweili/payload-visual-editing-core'\nimport type {\n CollectionAfterReadHook,\n CollectionBeforeOperationHook,\n CollectionBeforeValidateHook,\n FlattenedBlock,\n FlattenedField,\n GlobalAfterReadHook,\n GlobalBeforeOperationHook,\n GlobalBeforeValidateHook,\n PayloadRequest,\n} from 'payload'\n\nimport { encodeDocument, type EncodeTarget } from './encode-document.ts'\nimport { ENCODE_CONTEXT_KEY, ENCODE_QUERY_PARAM, type ResolvedSourceMapOptions } from './options.ts'\nimport { createPathMatcher } from './path-matcher.ts'\n\n/** True when this request asked for source maps (Local API context or an allowed REST request). */\nexport const shouldEncode = (req: PayloadRequest): boolean => req.context?.[ENCODE_CONTEXT_KEY] === true\n\n/**\n * REST: moves `?encodeSourceMaps=true` into `req.context` for GET reads, if `canEncode`\n * allows it. Populated relationships share the request, so they see the flag too.\n */\nasync function applyQueryFlag(req: PayloadRequest, operation: string, options: ResolvedSourceMapOptions) {\n // Only plain REST reads. A write (PATCH, POST, …) reads the document again on the same request,\n // which would otherwise encode the response of the write.\n if (operation !== 'read' || req.method !== 'GET') return\n if (req.query?.[ENCODE_QUERY_PARAM] !== 'true') return\n if (!(await options.canEncode({ req }))) return\n req.context[ENCODE_CONTEXT_KEY] = true\n}\n\nexport function createHooks(options: ResolvedSourceMapOptions) {\n const isIncluded = options.include ? createPathMatcher(options.include) : () => true\n const isExcluded = createPathMatcher(options.exclude)\n const shouldEncodePath = (path: string) => isIncluded(path) && !isExcluded(path)\n\n const encode = (req: PayloadRequest, fields: FlattenedField[], data: Record<string, unknown>, target: EncodeTarget) => {\n const localization = req.payload.config.localization\n encodeDocument({\n fields,\n data,\n target,\n locale: req.locale ?? undefined,\n locales: localization ? localization.localeCodes : null,\n skip: options.skip,\n shouldEncodePath,\n // Generic lookup: an app's generated types narrow `blocks` to its own block slugs\n resolveBlock: (slug) => (req.payload.blocks as Record<string, FlattenedBlock | undefined>)[slug],\n })\n }\n\n const collectionBeforeOperation: CollectionBeforeOperationHook = async ({ args, operation, req }) => {\n await applyQueryFlag(req, operation, options)\n return args\n }\n\n const globalBeforeOperation: GlobalBeforeOperationHook = async ({ args, operation, req }) => {\n await applyQueryFlag(req, operation, options)\n return args\n }\n\n const collectionAfterRead: CollectionAfterReadHook = ({ collection, doc, req }) => {\n if (!shouldEncode(req) || !doc) return doc\n encode(req, collection.flattenedFields, doc, { collection: collection.slug, id: doc.id })\n return doc\n }\n\n const globalAfterRead: GlobalAfterReadHook = ({ doc, global, req }) => {\n if (!shouldEncode(req) || !doc) return doc\n encode(req, global.flattenedFields, doc, { global: global.slug })\n return doc\n }\n\n /**\n * Encoded text must never be saved: e.g. an editor copies text from the preview into the admin,\n * or a hook writes back a document it read with the flag on.\n */\n const collectionBeforeValidate: CollectionBeforeValidateHook = ({ data }) => (data ? stegaClean(data) : data)\n const globalBeforeValidate: GlobalBeforeValidateHook = ({ data }) => (data ? stegaClean(data) : data)\n\n return {\n collection: {\n beforeOperation: collectionBeforeOperation,\n beforeValidate: collectionBeforeValidate,\n afterRead: collectionAfterRead,\n },\n global: {\n beforeOperation: globalBeforeOperation,\n beforeValidate: globalBeforeValidate,\n afterRead: globalAfterRead,\n },\n }\n}\n"],"names":["stegaClean","encodeDocument","ENCODE_CONTEXT_KEY","ENCODE_QUERY_PARAM","createPathMatcher","shouldEncode","req","context","applyQueryFlag","operation","options","method","query","canEncode","createHooks","isIncluded","include","isExcluded","exclude","shouldEncodePath","path","encode","fields","data","target","localization","payload","config","locale","undefined","locales","localeCodes","skip","resolveBlock","slug","blocks","collectionBeforeOperation","args","globalBeforeOperation","collectionAfterRead","collection","doc","flattenedFields","id","globalAfterRead","global","collectionBeforeValidate","globalBeforeValidate","beforeOperation","beforeValidate","afterRead"],"mappings":"AAAA,SAASA,UAAU,QAAQ,wCAAuC;AAalE,SAASC,cAAc,QAA2B,uBAAsB;AACxE,SAASC,kBAAkB,EAAEC,kBAAkB,QAAuC,eAAc;AACpG,SAASC,iBAAiB,QAAQ,oBAAmB;AAErD,iGAAiG,GACjG,OAAO,MAAMC,eAAe,CAACC,MAAiCA,IAAIC,OAAO,EAAE,CAACL,mBAAmB,KAAK,KAAI;AAExG;;;CAGC,GACD,eAAeM,eAAeF,GAAmB,EAAEG,SAAiB,EAAEC,OAAiC;IACrG,gGAAgG;IAChG,0DAA0D;IAC1D,IAAID,cAAc,UAAUH,IAAIK,MAAM,KAAK,OAAO;IAClD,IAAIL,IAAIM,KAAK,EAAE,CAACT,mBAAmB,KAAK,QAAQ;IAChD,IAAI,CAAE,MAAMO,QAAQG,SAAS,CAAC;QAAEP;IAAI,IAAK;IACzCA,IAAIC,OAAO,CAACL,mBAAmB,GAAG;AACpC;AAEA,OAAO,SAASY,YAAYJ,OAAiC;IAC3D,MAAMK,aAAaL,QAAQM,OAAO,GAAGZ,kBAAkBM,QAAQM,OAAO,IAAI,IAAM;IAChF,MAAMC,aAAab,kBAAkBM,QAAQQ,OAAO;IACpD,MAAMC,mBAAmB,CAACC,OAAiBL,WAAWK,SAAS,CAACH,WAAWG;IAE3E,MAAMC,SAAS,CAACf,KAAqBgB,QAA0BC,MAA+BC;QAC5F,MAAMC,eAAenB,IAAIoB,OAAO,CAACC,MAAM,CAACF,YAAY;QACpDxB,eAAe;YACbqB;YACAC;YACAC;YACAI,QAAQtB,IAAIsB,MAAM,IAAIC;YACtBC,SAASL,eAAeA,aAAaM,WAAW,GAAG;YACnDC,MAAMtB,QAAQsB,IAAI;YAClBb;YACA,kFAAkF;YAClFc,cAAc,CAACC,OAAS,AAAC5B,IAAIoB,OAAO,CAACS,MAAM,AAA+C,CAACD,KAAK;QAClG;IACF;IAEA,MAAME,4BAA2D,OAAO,EAAEC,IAAI,EAAE5B,SAAS,EAAEH,GAAG,EAAE;QAC9F,MAAME,eAAeF,KAAKG,WAAWC;QACrC,OAAO2B;IACT;IAEA,MAAMC,wBAAmD,OAAO,EAAED,IAAI,EAAE5B,SAAS,EAAEH,GAAG,EAAE;QACtF,MAAME,eAAeF,KAAKG,WAAWC;QACrC,OAAO2B;IACT;IAEA,MAAME,sBAA+C,CAAC,EAAEC,UAAU,EAAEC,GAAG,EAAEnC,GAAG,EAAE;QAC5E,IAAI,CAACD,aAAaC,QAAQ,CAACmC,KAAK,OAAOA;QACvCpB,OAAOf,KAAKkC,WAAWE,eAAe,EAAED,KAAK;YAAED,YAAYA,WAAWN,IAAI;YAAES,IAAIF,IAAIE,EAAE;QAAC;QACvF,OAAOF;IACT;IAEA,MAAMG,kBAAuC,CAAC,EAAEH,GAAG,EAAEI,MAAM,EAAEvC,GAAG,EAAE;QAChE,IAAI,CAACD,aAAaC,QAAQ,CAACmC,KAAK,OAAOA;QACvCpB,OAAOf,KAAKuC,OAAOH,eAAe,EAAED,KAAK;YAAEI,QAAQA,OAAOX,IAAI;QAAC;QAC/D,OAAOO;IACT;IAEA;;;GAGC,GACD,MAAMK,2BAAyD,CAAC,EAAEvB,IAAI,EAAE,GAAMA,OAAOvB,WAAWuB,QAAQA;IACxG,MAAMwB,uBAAiD,CAAC,EAAExB,IAAI,EAAE,GAAMA,OAAOvB,WAAWuB,QAAQA;IAEhG,OAAO;QACLiB,YAAY;YACVQ,iBAAiBZ;YACjBa,gBAAgBH;YAChBI,WAAWX;QACb;QACAM,QAAQ;YACNG,iBAAiBV;YACjBW,gBAAgBF;YAChBG,WAAWN;QACb;IACF;AACF"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Server entry: Payload config plugin.
3
+ * Must stay free of Node-only APIs (fs, path, child_process): runs on Cloudflare Workers.
4
+ */
5
+ export { ADMIN_COMPONENT, visualEditingPlugin } from './plugin.ts';
6
+ export { DEFAULT_EXCLUDE, ENCODE_CONTEXT_KEY, ENCODE_QUERY_PARAM, type SourceMapOptions, type VisualEditingPluginOptions, } from './options.ts';
7
+ export { encodeDocument, type EncodeDocumentArgs, type EncodeTarget } from './encode-document.ts';
8
+ export { createPathMatcher } from './path-matcher.ts';
9
+ export { stegaClean } from '@derweili/payload-visual-editing-core';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAClE,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,KAAK,0BAA0B,GAChC,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,cAAc,EAAE,KAAK,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACjG,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Server entry: Payload config plugin.
3
+ * Must stay free of Node-only APIs (fs, path, child_process): runs on Cloudflare Workers.
4
+ */ export { ADMIN_COMPONENT, visualEditingPlugin } from "./plugin.js";
5
+ export { DEFAULT_EXCLUDE, ENCODE_CONTEXT_KEY, ENCODE_QUERY_PARAM } from "./options.js";
6
+ export { encodeDocument } from "./encode-document.js";
7
+ export { createPathMatcher } from "./path-matcher.js";
8
+ export { stegaClean } from '@derweili/payload-visual-editing-core';
9
+
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/server/index.ts"],"sourcesContent":["/**\n * Server entry: Payload config plugin.\n * Must stay free of Node-only APIs (fs, path, child_process): runs on Cloudflare Workers.\n */\nexport { ADMIN_COMPONENT, visualEditingPlugin } from './plugin.ts'\nexport {\n DEFAULT_EXCLUDE,\n ENCODE_CONTEXT_KEY,\n ENCODE_QUERY_PARAM,\n type SourceMapOptions,\n type VisualEditingPluginOptions,\n} from './options.ts'\nexport { encodeDocument, type EncodeDocumentArgs, type EncodeTarget } from './encode-document.ts'\nexport { createPathMatcher } from './path-matcher.ts'\nexport { stegaClean } from '@derweili/payload-visual-editing-core'\n"],"names":["ADMIN_COMPONENT","visualEditingPlugin","DEFAULT_EXCLUDE","ENCODE_CONTEXT_KEY","ENCODE_QUERY_PARAM","encodeDocument","createPathMatcher","stegaClean"],"mappings":"AAAA;;;CAGC,GACD,SAASA,eAAe,EAAEC,mBAAmB,QAAQ,cAAa;AAClE,SACEC,eAAe,EACfC,kBAAkB,EAClBC,kBAAkB,QAGb,eAAc;AACrB,SAASC,cAAc,QAAoD,uBAAsB;AACjG,SAASC,iBAAiB,QAAQ,oBAAmB;AACrD,SAASC,UAAU,QAAQ,wCAAuC"}
@@ -0,0 +1,58 @@
1
+ import type { PayloadRequest } from 'payload';
2
+ /** `req.context` key that switches encoding on (Local API: `context: { encodeSourceMaps: true }`). */
3
+ export declare const ENCODE_CONTEXT_KEY = "encodeSourceMaps";
4
+ /** REST query parameter that switches encoding on (`?encodeSourceMaps=true`), subject to `canEncode`. */
5
+ export declare const ENCODE_QUERY_PARAM = "encodeSourceMaps";
6
+ export interface SourceMapOptions {
7
+ /** Default: true. false removes the encoding hooks entirely. */
8
+ enabled?: boolean;
9
+ /**
10
+ * Who may switch encoding on with the REST query parameter.
11
+ * Default: logged-in users only. The Local API context flag is trusted (server code).
12
+ */
13
+ canEncode?: (args: {
14
+ req: PayloadRequest;
15
+ }) => boolean | Promise<boolean>;
16
+ /**
17
+ * How URL- or date-like strings are treated. "auto" (default) leaves them unencoded: dates as
18
+ * in @vercel/stega, URLs only without whitespace (see `looksLikeUrlOrDate` in core).
19
+ * false encodes every string that isn't excluded; true encodes nothing.
20
+ */
21
+ skip?: 'auto' | boolean;
22
+ /**
23
+ * Only encode fields whose path matches one of these patterns. Default: every field.
24
+ * Patterns match the data path without array indices (`team.links.label`):
25
+ * `*` is one segment, `**` any number of segments, and a pattern without a dot matches a
26
+ * field name at any depth.
27
+ */
28
+ include?: string[];
29
+ /** Never encode fields matching these patterns (same syntax). Replaces the defaults. */
30
+ exclude?: string[];
31
+ }
32
+ export interface VisualEditingPluginOptions {
33
+ /** Turns the whole plugin off without removing it from the config. Default: true. */
34
+ enabled?: boolean;
35
+ /** Collections whose documents get source maps and field focusing. Default: none. */
36
+ collections?: string[];
37
+ /** Globals that get source maps and field focusing. Default: none. */
38
+ globals?: string[];
39
+ sourceMaps?: SourceMapOptions;
40
+ /**
41
+ * Adds the admin component that focuses a field from `?field=` or a click in the Live Preview
42
+ * to the edit views of these collections and globals. Default: true. Run
43
+ * `payload generate:importmap` after adding the plugin.
44
+ */
45
+ focusFields?: boolean;
46
+ }
47
+ /** Text fields that usually feed logic rather than display. Fields named `id` are never encoded. */
48
+ export declare const DEFAULT_EXCLUDE: string[];
49
+ export interface ResolvedSourceMapOptions {
50
+ enabled: boolean;
51
+ canEncode: NonNullable<SourceMapOptions['canEncode']>;
52
+ skip: 'auto' | boolean;
53
+ include: string[] | null;
54
+ exclude: string[];
55
+ }
56
+ export declare const defaultCanEncode: ResolvedSourceMapOptions['canEncode'];
57
+ export declare function resolveSourceMapOptions(options?: SourceMapOptions): ResolvedSourceMapOptions;
58
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/server/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,sGAAsG;AACtG,eAAO,MAAM,kBAAkB,qBAAqB,CAAA;AACpD,yGAAyG;AACzG,eAAO,MAAM,kBAAkB,qBAAqB,CAAA;AAEpD,MAAM,WAAW,gBAAgB;IAC/B,gEAAgE;IAChE,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,cAAc,CAAA;KAAE,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACzE;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACvB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,wFAAwF;IACxF,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACnB;AAED,MAAM,WAAW,0BAA0B;IACzC,qFAAqF;IACrF,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,qFAAqF;IACrF,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,UAAU,CAAC,EAAE,gBAAgB,CAAA;IAC7B;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,oGAAoG;AACpG,eAAO,MAAM,eAAe,UAAkB,CAAA;AAE9C,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,WAAW,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAA;IACrD,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IACtB,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;IACxB,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,eAAO,MAAM,gBAAgB,EAAE,wBAAwB,CAAC,WAAW,CAAkC,CAAA;AAErG,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,gBAAqB,GAAG,wBAAwB,CAQhG"}
@@ -0,0 +1,18 @@
1
+ /** `req.context` key that switches encoding on (Local API: `context: { encodeSourceMaps: true }`). */ export const ENCODE_CONTEXT_KEY = 'encodeSourceMaps';
2
+ /** REST query parameter that switches encoding on (`?encodeSourceMaps=true`), subject to `canEncode`. */ export const ENCODE_QUERY_PARAM = 'encodeSourceMaps';
3
+ /** Text fields that usually feed logic rather than display. Fields named `id` are never encoded. */ export const DEFAULT_EXCLUDE = [
4
+ 'slug',
5
+ 'url'
6
+ ];
7
+ export const defaultCanEncode = ({ req })=>Boolean(req.user);
8
+ export function resolveSourceMapOptions(options = {}) {
9
+ return {
10
+ enabled: options.enabled ?? true,
11
+ canEncode: options.canEncode ?? defaultCanEncode,
12
+ skip: options.skip ?? 'auto',
13
+ include: options.include ?? null,
14
+ exclude: options.exclude ?? DEFAULT_EXCLUDE
15
+ };
16
+ }
17
+
18
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/server/options.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\n/** `req.context` key that switches encoding on (Local API: `context: { encodeSourceMaps: true }`). */\nexport const ENCODE_CONTEXT_KEY = 'encodeSourceMaps'\n/** REST query parameter that switches encoding on (`?encodeSourceMaps=true`), subject to `canEncode`. */\nexport const ENCODE_QUERY_PARAM = 'encodeSourceMaps'\n\nexport interface SourceMapOptions {\n /** Default: true. false removes the encoding hooks entirely. */\n enabled?: boolean\n /**\n * Who may switch encoding on with the REST query parameter.\n * Default: logged-in users only. The Local API context flag is trusted (server code).\n */\n canEncode?: (args: { req: PayloadRequest }) => boolean | Promise<boolean>\n /**\n * How URL- or date-like strings are treated. \"auto\" (default) leaves them unencoded: dates as\n * in @vercel/stega, URLs only without whitespace (see `looksLikeUrlOrDate` in core).\n * false encodes every string that isn't excluded; true encodes nothing.\n */\n skip?: 'auto' | boolean\n /**\n * Only encode fields whose path matches one of these patterns. Default: every field.\n * Patterns match the data path without array indices (`team.links.label`):\n * `*` is one segment, `**` any number of segments, and a pattern without a dot matches a\n * field name at any depth.\n */\n include?: string[]\n /** Never encode fields matching these patterns (same syntax). Replaces the defaults. */\n exclude?: string[]\n}\n\nexport interface VisualEditingPluginOptions {\n /** Turns the whole plugin off without removing it from the config. Default: true. */\n enabled?: boolean\n /** Collections whose documents get source maps and field focusing. Default: none. */\n collections?: string[]\n /** Globals that get source maps and field focusing. Default: none. */\n globals?: string[]\n sourceMaps?: SourceMapOptions\n /**\n * Adds the admin component that focuses a field from `?field=` or a click in the Live Preview\n * to the edit views of these collections and globals. Default: true. Run\n * `payload generate:importmap` after adding the plugin.\n */\n focusFields?: boolean\n}\n\n/** Text fields that usually feed logic rather than display. Fields named `id` are never encoded. */\nexport const DEFAULT_EXCLUDE = ['slug', 'url']\n\nexport interface ResolvedSourceMapOptions {\n enabled: boolean\n canEncode: NonNullable<SourceMapOptions['canEncode']>\n skip: 'auto' | boolean\n include: string[] | null\n exclude: string[]\n}\n\nexport const defaultCanEncode: ResolvedSourceMapOptions['canEncode'] = ({ req }) => Boolean(req.user)\n\nexport function resolveSourceMapOptions(options: SourceMapOptions = {}): ResolvedSourceMapOptions {\n return {\n enabled: options.enabled ?? true,\n canEncode: options.canEncode ?? defaultCanEncode,\n skip: options.skip ?? 'auto',\n include: options.include ?? null,\n exclude: options.exclude ?? DEFAULT_EXCLUDE,\n }\n}\n"],"names":["ENCODE_CONTEXT_KEY","ENCODE_QUERY_PARAM","DEFAULT_EXCLUDE","defaultCanEncode","req","Boolean","user","resolveSourceMapOptions","options","enabled","canEncode","skip","include","exclude"],"mappings":"AAEA,oGAAoG,GACpG,OAAO,MAAMA,qBAAqB,mBAAkB;AACpD,uGAAuG,GACvG,OAAO,MAAMC,qBAAqB,mBAAkB;AA2CpD,kGAAkG,GAClG,OAAO,MAAMC,kBAAkB;IAAC;IAAQ;CAAM,CAAA;AAU9C,OAAO,MAAMC,mBAA0D,CAAC,EAAEC,GAAG,EAAE,GAAKC,QAAQD,IAAIE,IAAI,EAAC;AAErG,OAAO,SAASC,wBAAwBC,UAA4B,CAAC,CAAC;IACpE,OAAO;QACLC,SAASD,QAAQC,OAAO,IAAI;QAC5BC,WAAWF,QAAQE,SAAS,IAAIP;QAChCQ,MAAMH,QAAQG,IAAI,IAAI;QACtBC,SAASJ,QAAQI,OAAO,IAAI;QAC5BC,SAASL,QAAQK,OAAO,IAAIX;IAC9B;AACF"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Compiles include/exclude patterns into one test on data paths.
3
+ * Patterns match the path without array indices: `team.2.links.0.label` → `team.links.label`.
4
+ * - `*` matches one segment (or part of one: `meta*`), `**` any number of segments (also none)
5
+ * - a pattern without a dot matches a field name at any depth (`slug` ≙ `**.slug`)
6
+ */
7
+ export declare function createPathMatcher(patterns: readonly string[]): (path: string) => boolean;
8
+ //# sourceMappingURL=path-matcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-matcher.d.ts","sourceRoot":"","sources":["../../src/server/path-matcher.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAQxF"}
@@ -0,0 +1,32 @@
1
+ import { stripIndices } from '@derweili/payload-visual-editing-core';
2
+ /**
3
+ * Compiles include/exclude patterns into one test on data paths.
4
+ * Patterns match the path without array indices: `team.2.links.0.label` → `team.links.label`.
5
+ * - `*` matches one segment (or part of one: `meta*`), `**` any number of segments (also none)
6
+ * - a pattern without a dot matches a field name at any depth (`slug` ≙ `**.slug`)
7
+ */ export function createPathMatcher(patterns) {
8
+ const compiled = patterns.map((pattern)=>(pattern.includes('.') ? pattern : `**.${pattern}`).split('.').map(compileSegment));
9
+ return (path)=>{
10
+ const segments = stripIndices(path).split('.');
11
+ return compiled.some((pattern)=>matches(pattern, 0, segments, 0));
12
+ };
13
+ }
14
+ function compileSegment(segment) {
15
+ if (segment === '**') return '**';
16
+ const escaped = segment.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
17
+ return new RegExp(`^${escaped}$`);
18
+ }
19
+ function matches(pattern, p, path, s) {
20
+ if (p === pattern.length) return s === path.length;
21
+ const segment = pattern[p];
22
+ if (segment === '**') {
23
+ // Zero or more segments
24
+ for(let next = s; next <= path.length; next++){
25
+ if (matches(pattern, p + 1, path, next)) return true;
26
+ }
27
+ return false;
28
+ }
29
+ return s < path.length && segment.test(path[s]) && matches(pattern, p + 1, path, s + 1);
30
+ }
31
+
32
+ //# sourceMappingURL=path-matcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/server/path-matcher.ts"],"sourcesContent":["import { stripIndices } from '@derweili/payload-visual-editing-core'\n\n/**\n * Compiles include/exclude patterns into one test on data paths.\n * Patterns match the path without array indices: `team.2.links.0.label` → `team.links.label`.\n * - `*` matches one segment (or part of one: `meta*`), `**` any number of segments (also none)\n * - a pattern without a dot matches a field name at any depth (`slug` ≙ `**.slug`)\n */\nexport function createPathMatcher(patterns: readonly string[]): (path: string) => boolean {\n const compiled = patterns.map((pattern) =>\n (pattern.includes('.') ? pattern : `**.${pattern}`).split('.').map(compileSegment),\n )\n return (path) => {\n const segments = stripIndices(path).split('.')\n return compiled.some((pattern) => matches(pattern, 0, segments, 0))\n }\n}\n\ntype Segment = '**' | RegExp\n\nfunction compileSegment(segment: string): Segment {\n if (segment === '**') return '**'\n const escaped = segment.replace(/[.+?^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\*/g, '.*')\n return new RegExp(`^${escaped}$`)\n}\n\nfunction matches(pattern: Segment[], p: number, path: string[], s: number): boolean {\n if (p === pattern.length) return s === path.length\n const segment = pattern[p]!\n if (segment === '**') {\n // Zero or more segments\n for (let next = s; next <= path.length; next++) {\n if (matches(pattern, p + 1, path, next)) return true\n }\n return false\n }\n return s < path.length && segment.test(path[s]!) && matches(pattern, p + 1, path, s + 1)\n}\n"],"names":["stripIndices","createPathMatcher","patterns","compiled","map","pattern","includes","split","compileSegment","path","segments","some","matches","segment","escaped","replace","RegExp","p","s","length","next","test"],"mappings":"AAAA,SAASA,YAAY,QAAQ,wCAAuC;AAEpE;;;;;CAKC,GACD,OAAO,SAASC,kBAAkBC,QAA2B;IAC3D,MAAMC,WAAWD,SAASE,GAAG,CAAC,CAACC,UAC7B,AAACA,CAAAA,QAAQC,QAAQ,CAAC,OAAOD,UAAU,CAAC,GAAG,EAAEA,SAAS,AAAD,EAAGE,KAAK,CAAC,KAAKH,GAAG,CAACI;IAErE,OAAO,CAACC;QACN,MAAMC,WAAWV,aAAaS,MAAMF,KAAK,CAAC;QAC1C,OAAOJ,SAASQ,IAAI,CAAC,CAACN,UAAYO,QAAQP,SAAS,GAAGK,UAAU;IAClE;AACF;AAIA,SAASF,eAAeK,OAAe;IACrC,IAAIA,YAAY,MAAM,OAAO;IAC7B,MAAMC,UAAUD,QAAQE,OAAO,CAAC,sBAAsB,QAAQA,OAAO,CAAC,OAAO;IAC7E,OAAO,IAAIC,OAAO,CAAC,CAAC,EAAEF,QAAQ,CAAC,CAAC;AAClC;AAEA,SAASF,QAAQP,OAAkB,EAAEY,CAAS,EAAER,IAAc,EAAES,CAAS;IACvE,IAAID,MAAMZ,QAAQc,MAAM,EAAE,OAAOD,MAAMT,KAAKU,MAAM;IAClD,MAAMN,UAAUR,OAAO,CAACY,EAAE;IAC1B,IAAIJ,YAAY,MAAM;QACpB,wBAAwB;QACxB,IAAK,IAAIO,OAAOF,GAAGE,QAAQX,KAAKU,MAAM,EAAEC,OAAQ;YAC9C,IAAIR,QAAQP,SAASY,IAAI,GAAGR,MAAMW,OAAO,OAAO;QAClD;QACA,OAAO;IACT;IACA,OAAOF,IAAIT,KAAKU,MAAM,IAAIN,QAAQQ,IAAI,CAACZ,IAAI,CAACS,EAAE,KAAMN,QAAQP,SAASY,IAAI,GAAGR,MAAMS,IAAI;AACxF"}
@@ -0,0 +1,13 @@
1
+ import type { Plugin } from 'payload';
2
+ import { type VisualEditingPluginOptions } from './options.ts';
3
+ /** Import map path of the admin component that focuses fields (src/client/VisualEditingAdmin.tsx). */
4
+ export declare const ADMIN_COMPONENT = "@derweili/payload-visual-editing/client#VisualEditingAdmin";
5
+ /**
6
+ * Payload plugin for visual editing (ADR 0001):
7
+ * - stega source maps on text, textarea and Lexical fields of the configured collections and
8
+ * globals, switched on per request (M1)
9
+ * - an admin component in their edit views that focuses the field from `?field=` or from a click
10
+ * in the Live Preview (M3)
11
+ */
12
+ export declare const visualEditingPlugin: (options?: VisualEditingPluginOptions) => Plugin;
13
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/server/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA0C,MAAM,EAAE,MAAM,SAAS,CAAA;AAG7E,OAAO,EAA2B,KAAK,0BAA0B,EAAE,MAAM,cAAc,CAAA;AAEvF,sGAAsG;AACtG,eAAO,MAAM,eAAe,+DAA+D,CAAA;AAiB3F;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,aACpB,0BAA0B,KAAQ,MAgE3C,CAAA"}
@@ -0,0 +1,102 @@
1
+ import { createHooks } from "./hooks.js";
2
+ import { resolveSourceMapOptions } from "./options.js";
3
+ /** Import map path of the admin component that focuses fields (src/client/VisualEditingAdmin.tsx). */ export const ADMIN_COMPONENT = '@derweili/payload-visual-editing/client#VisualEditingAdmin';
4
+ /** Adds the plugin's hooks: before the entity's own beforeValidate, after its own afterRead. */ function withHooks(own, hooks) {
5
+ const current = own ?? {};
6
+ return {
7
+ ...current,
8
+ beforeOperation: [
9
+ ...current.beforeOperation ?? [],
10
+ hooks.beforeOperation
11
+ ],
12
+ beforeValidate: [
13
+ hooks.beforeValidate,
14
+ ...current.beforeValidate ?? []
15
+ ],
16
+ // Last, so the encoding sees the document other hooks produced
17
+ afterRead: [
18
+ ...current.afterRead ?? [],
19
+ hooks.afterRead
20
+ ]
21
+ };
22
+ }
23
+ /**
24
+ * Payload plugin for visual editing (ADR 0001):
25
+ * - stega source maps on text, textarea and Lexical fields of the configured collections and
26
+ * globals, switched on per request (M1)
27
+ * - an admin component in their edit views that focuses the field from `?field=` or from a click
28
+ * in the Live Preview (M3)
29
+ */ export const visualEditingPlugin = (options = {})=>(config)=>{
30
+ if (options.enabled === false) return config;
31
+ const sourceMaps = resolveSourceMapOptions(options.sourceMaps);
32
+ const focusFields = options.focusFields !== false;
33
+ if (!sourceMaps.enabled && !focusFields) return config;
34
+ const collections = new Set(options.collections ?? []);
35
+ const globals = new Set(options.globals ?? []);
36
+ assertKnownSlugs('collections', collections, (config.collections ?? []).map((c)=>c.slug));
37
+ assertKnownSlugs('globals', globals, (config.globals ?? []).map((g)=>g.slug));
38
+ const hooks = sourceMaps.enabled ? createHooks(sourceMaps) : null;
39
+ return {
40
+ ...config,
41
+ collections: (config.collections ?? []).map((collection)=>{
42
+ if (!collections.has(collection.slug)) return collection;
43
+ const admin = collection.admin ?? {};
44
+ return {
45
+ ...collection,
46
+ ...hooks ? {
47
+ hooks: withHooks(collection.hooks, hooks.collection)
48
+ } : {},
49
+ ...focusFields ? {
50
+ admin: {
51
+ ...admin,
52
+ components: {
53
+ ...admin.components,
54
+ edit: {
55
+ ...admin.components?.edit,
56
+ beforeDocumentControls: [
57
+ ...admin.components?.edit?.beforeDocumentControls ?? [],
58
+ ADMIN_COMPONENT
59
+ ]
60
+ }
61
+ }
62
+ }
63
+ } : {}
64
+ };
65
+ }),
66
+ globals: (config.globals ?? []).map((global)=>{
67
+ if (!globals.has(global.slug)) return global;
68
+ const admin = global.admin ?? {};
69
+ return {
70
+ ...global,
71
+ ...hooks ? {
72
+ hooks: withHooks(global.hooks, hooks.global)
73
+ } : {},
74
+ ...focusFields ? {
75
+ admin: {
76
+ ...admin,
77
+ components: {
78
+ ...admin.components,
79
+ elements: {
80
+ ...admin.components?.elements,
81
+ beforeDocumentControls: [
82
+ ...admin.components?.elements?.beforeDocumentControls ?? [],
83
+ ADMIN_COMPONENT
84
+ ]
85
+ }
86
+ }
87
+ }
88
+ } : {}
89
+ };
90
+ })
91
+ };
92
+ };
93
+ function assertKnownSlugs(kind, wanted, known) {
94
+ const unknown = [
95
+ ...wanted
96
+ ].filter((slug)=>!known.includes(slug));
97
+ if (unknown.length > 0) {
98
+ throw new Error(`visualEditingPlugin: unknown ${kind}: ${unknown.join(', ')}`);
99
+ }
100
+ }
101
+
102
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/server/plugin.ts"],"sourcesContent":["import type { CollectionConfig, Config, GlobalConfig, Plugin } from 'payload'\n\nimport { createHooks } from './hooks.ts'\nimport { resolveSourceMapOptions, type VisualEditingPluginOptions } from './options.ts'\n\n/** Import map path of the admin component that focuses fields (src/client/VisualEditingAdmin.tsx). */\nexport const ADMIN_COMPONENT = '@derweili/payload-visual-editing/client#VisualEditingAdmin'\n\ntype Hooks = ReturnType<typeof createHooks>\ntype EntityHooks = NonNullable<CollectionConfig['hooks']> | NonNullable<GlobalConfig['hooks']>\n\n/** Adds the plugin's hooks: before the entity's own beforeValidate, after its own afterRead. */\nfunction withHooks<T extends EntityHooks>(own: T | undefined, hooks: Hooks['collection'] | Hooks['global']): T {\n const current = (own ?? {}) as Record<string, unknown[] | undefined>\n return {\n ...current,\n beforeOperation: [...(current.beforeOperation ?? []), hooks.beforeOperation],\n beforeValidate: [hooks.beforeValidate, ...(current.beforeValidate ?? [])],\n // Last, so the encoding sees the document other hooks produced\n afterRead: [...(current.afterRead ?? []), hooks.afterRead],\n } as T\n}\n\n/**\n * Payload plugin for visual editing (ADR 0001):\n * - stega source maps on text, textarea and Lexical fields of the configured collections and\n * globals, switched on per request (M1)\n * - an admin component in their edit views that focuses the field from `?field=` or from a click\n * in the Live Preview (M3)\n */\nexport const visualEditingPlugin =\n (options: VisualEditingPluginOptions = {}): Plugin =>\n (config: Config): Config => {\n if (options.enabled === false) return config\n const sourceMaps = resolveSourceMapOptions(options.sourceMaps)\n const focusFields = options.focusFields !== false\n if (!sourceMaps.enabled && !focusFields) return config\n\n const collections = new Set(options.collections ?? [])\n const globals = new Set(options.globals ?? [])\n assertKnownSlugs('collections', collections, (config.collections ?? []).map((c) => c.slug))\n assertKnownSlugs('globals', globals, (config.globals ?? []).map((g) => g.slug))\n\n const hooks = sourceMaps.enabled ? createHooks(sourceMaps) : null\n\n return {\n ...config,\n collections: (config.collections ?? []).map((collection) => {\n if (!collections.has(collection.slug)) return collection\n const admin = collection.admin ?? {}\n return {\n ...collection,\n ...(hooks ? { hooks: withHooks(collection.hooks, hooks.collection) } : {}),\n ...(focusFields\n ? {\n admin: {\n ...admin,\n components: {\n ...admin.components,\n edit: {\n ...admin.components?.edit,\n beforeDocumentControls: [...(admin.components?.edit?.beforeDocumentControls ?? []), ADMIN_COMPONENT],\n },\n },\n },\n }\n : {}),\n }\n }),\n globals: (config.globals ?? []).map((global) => {\n if (!globals.has(global.slug)) return global\n const admin = global.admin ?? {}\n return {\n ...global,\n ...(hooks ? { hooks: withHooks(global.hooks, hooks.global) } : {}),\n ...(focusFields\n ? {\n admin: {\n ...admin,\n components: {\n ...admin.components,\n elements: {\n ...admin.components?.elements,\n beforeDocumentControls: [\n ...(admin.components?.elements?.beforeDocumentControls ?? []),\n ADMIN_COMPONENT,\n ],\n },\n },\n },\n }\n : {}),\n }\n }),\n }\n }\n\nfunction assertKnownSlugs(kind: string, wanted: Set<string>, known: string[]) {\n const unknown = [...wanted].filter((slug) => !known.includes(slug))\n if (unknown.length > 0) {\n throw new Error(`visualEditingPlugin: unknown ${kind}: ${unknown.join(', ')}`)\n }\n}\n"],"names":["createHooks","resolveSourceMapOptions","ADMIN_COMPONENT","withHooks","own","hooks","current","beforeOperation","beforeValidate","afterRead","visualEditingPlugin","options","config","enabled","sourceMaps","focusFields","collections","Set","globals","assertKnownSlugs","map","c","slug","g","collection","has","admin","components","edit","beforeDocumentControls","global","elements","kind","wanted","known","unknown","filter","includes","length","Error","join"],"mappings":"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"}
package/package.json CHANGED
@@ -1,6 +1,77 @@
1
1
  {
2
2
  "name": "@derweili/payload-visual-editing",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Visual editing for Payload 3: stega source maps and click-to-focus in the admin",
5
+ "keywords": [
6
+ "payload",
7
+ "payloadcms",
8
+ "payload-plugin",
9
+ "visual-editing",
10
+ "live-preview",
11
+ "nextjs",
12
+ "cms"
13
+ ],
14
+ "license": "MIT",
15
+ "author": "Julian Weiland",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/derweili/payload-visual-editing.git",
19
+ "directory": "packages/payload-visual-editing"
20
+ },
21
+ "homepage": "https://github.com/derweili/payload-visual-editing/tree/main/packages/payload-visual-editing#readme",
22
+ "bugs": "https://github.com/derweili/payload-visual-editing/issues",
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "exports": {
26
+ "./server": {
27
+ "types": "./dist/server/index.d.ts",
28
+ "import": "./dist/server/index.js",
29
+ "default": "./dist/server/index.js"
30
+ },
31
+ "./client": {
32
+ "types": "./dist/client/index.d.ts",
33
+ "import": "./dist/client/index.js",
34
+ "default": "./dist/client/index.js"
35
+ }
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "README.md",
43
+ "CHANGELOG.md",
44
+ "LICENSE"
45
+ ],
46
+ "dependencies": {
47
+ "@derweili/payload-visual-editing-core": "0.1.0"
48
+ },
49
+ "peerDependencies": {
50
+ "@payloadcms/ui": "^3.94.1",
51
+ "next": "^15.4.0 || ^16.0.0",
52
+ "payload": "^3.94.1",
53
+ "react": "^19.0.0"
54
+ },
55
+ "devDependencies": {
56
+ "@payloadcms/db-d1-sqlite": "3.94.1",
57
+ "@payloadcms/richtext-lexical": "3.94.1",
58
+ "@payloadcms/ui": "3.94.1",
59
+ "@swc/cli": "0.7.10",
60
+ "@swc/core": "1.15.11",
61
+ "@types/react": "19.2.14",
62
+ "@types/react-dom": "19.2.3",
63
+ "miniflare": "5.20261123.1-beta",
64
+ "next": "16.4.6",
65
+ "payload": "3.94.1",
66
+ "react": "19.2.9",
67
+ "react-dom": "19.2.9",
68
+ "typescript": "5.7.3",
69
+ "vite": "7.3.8",
70
+ "vitest": "4.0.18"
71
+ },
72
+ "scripts": {
73
+ "build": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths --delete-dir-on-start && tsc -p tsconfig.build.json",
74
+ "test": "vitest run",
75
+ "typecheck": "tsc --noEmit"
76
+ }
6
77
  }