@focus-reactive/payload-plugin-visual-editing 1.0.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 +264 -0
- package/dist/admin/VisualEditingBridgeProvider.d.ts +4 -0
- package/dist/admin/VisualEditingBridgeProvider.js +144 -0
- package/dist/admin/VisualEditingBridgeProvider.js.map +1 -0
- package/dist/admin/expandAndFocus.d.ts +6 -0
- package/dist/admin/expandAndFocus.js +356 -0
- package/dist/admin/expandAndFocus.js.map +1 -0
- package/dist/admin/index.d.ts +1 -0
- package/dist/admin/index.js +3 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/parseFieldPath.d.ts +4 -0
- package/dist/admin/parseFieldPath.js +25 -0
- package/dist/admin/parseFieldPath.js.map +1 -0
- package/dist/admin/resolveContainerChain.d.ts +30 -0
- package/dist/admin/resolveContainerChain.js +171 -0
- package/dist/admin/resolveContainerChain.js.map +1 -0
- package/dist/client/VisualEditingOverlay.d.ts +4 -0
- package/dist/client/VisualEditingOverlay.js +30 -0
- package/dist/client/VisualEditingOverlay.js.map +1 -0
- package/dist/client/VisualEditingProvider.d.ts +23 -0
- package/dist/client/VisualEditingProvider.js +68 -0
- package/dist/client/VisualEditingProvider.js.map +1 -0
- package/dist/client/VisualEditingToggle.d.ts +1 -0
- package/dist/client/VisualEditingToggle.js +163 -0
- package/dist/client/VisualEditingToggle.js.map +1 -0
- package/dist/client/buildAdminEditUrl.d.ts +7 -0
- package/dist/client/buildAdminEditUrl.js +9 -0
- package/dist/client/buildAdminEditUrl.js.map +1 -0
- package/dist/client/index.d.ts +11 -0
- package/dist/client/index.js +13 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/overlay/constants.d.ts +9 -0
- package/dist/client/overlay/constants.js +49 -0
- package/dist/client/overlay/constants.js.map +1 -0
- package/dist/client/overlay/createOverlay.d.ts +11 -0
- package/dist/client/overlay/createOverlay.js +80 -0
- package/dist/client/overlay/createOverlay.js.map +1 -0
- package/dist/client/overlay/editBadge.d.ts +21 -0
- package/dist/client/overlay/editBadge.js +99 -0
- package/dist/client/overlay/editBadge.js.map +1 -0
- package/dist/client/overlay/hoverController.d.ts +14 -0
- package/dist/client/overlay/hoverController.js +137 -0
- package/dist/client/overlay/hoverController.js.map +1 -0
- package/dist/client/overlay/markerExtractor.d.ts +8 -0
- package/dist/client/overlay/markerExtractor.js +47 -0
- package/dist/client/overlay/markerExtractor.js.map +1 -0
- package/dist/client/overlay/mutationPipeline.d.ts +10 -0
- package/dist/client/overlay/mutationPipeline.js +78 -0
- package/dist/client/overlay/mutationPipeline.js.map +1 -0
- package/dist/client/overlay/stegaBookkeeper.d.ts +11 -0
- package/dist/client/overlay/stegaBookkeeper.js +36 -0
- package/dist/client/overlay/stegaBookkeeper.js.map +1 -0
- package/dist/client/overlay/stegaScanner.d.ts +11 -0
- package/dist/client/overlay/stegaScanner.js +54 -0
- package/dist/client/overlay/stegaScanner.js.map +1 -0
- package/dist/client/overlay/targetRegistry.d.ts +34 -0
- package/dist/client/overlay/targetRegistry.js +70 -0
- package/dist/client/overlay/targetRegistry.js.map +1 -0
- package/dist/client/overlay/targetSelector.d.ts +2 -0
- package/dist/client/overlay/targetSelector.js +67 -0
- package/dist/client/overlay/targetSelector.js.map +1 -0
- package/dist/client/overlayClickHandler.d.ts +7 -0
- package/dist/client/overlayClickHandler.js +24 -0
- package/dist/client/overlayClickHandler.js.map +1 -0
- package/dist/client/useVisualEditingOverlay.d.ts +4 -0
- package/dist/client/useVisualEditingOverlay.js +21 -0
- package/dist/client/useVisualEditingOverlay.js.map +1 -0
- package/dist/client/withVisualEditingPath.d.ts +9 -0
- package/dist/client/withVisualEditingPath.js +17 -0
- package/dist/client/withVisualEditingPath.js.map +1 -0
- package/dist/constants.d.ts +16 -0
- package/dist/constants.js +15 -0
- package/dist/constants.js.map +1 -0
- package/dist/excludeValues.d.ts +6 -0
- package/dist/excludeValues.js +24 -0
- package/dist/excludeValues.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/afterOperationHook.d.ts +10 -0
- package/dist/internal/afterOperationHook.js +28 -0
- package/dist/internal/afterOperationHook.js.map +1 -0
- package/dist/internal/afterReadHook.d.ts +2 -0
- package/dist/internal/afterReadHook.js +16 -0
- package/dist/internal/afterReadHook.js.map +1 -0
- package/dist/internal/beforeOperationHook.d.ts +4 -0
- package/dist/internal/beforeOperationHook.js +16 -0
- package/dist/internal/beforeOperationHook.js.map +1 -0
- package/dist/internal/buildFieldSchema.d.ts +3 -0
- package/dist/internal/buildFieldSchema.js +67 -0
- package/dist/internal/buildFieldSchema.js.map +1 -0
- package/dist/internal/encodeStega.d.ts +7 -0
- package/dist/internal/encodeStega.js +171 -0
- package/dist/internal/encodeStega.js.map +1 -0
- package/dist/internal/enrichWithPathMeta.d.ts +4 -0
- package/dist/internal/enrichWithPathMeta.js +76 -0
- package/dist/internal/enrichWithPathMeta.js.map +1 -0
- package/dist/internal/filterEditableFields.d.ts +2 -0
- package/dist/internal/filterEditableFields.js +88 -0
- package/dist/internal/filterEditableFields.js.map +1 -0
- package/dist/internal/gate.d.ts +2 -0
- package/dist/internal/gate.js +15 -0
- package/dist/internal/gate.js.map +1 -0
- package/dist/internal/globalAfterReadHook.d.ts +10 -0
- package/dist/internal/globalAfterReadHook.js +19 -0
- package/dist/internal/globalAfterReadHook.js.map +1 -0
- package/dist/internal/markTerminalUploads.d.ts +13 -0
- package/dist/internal/markTerminalUploads.js +79 -0
- package/dist/internal/markTerminalUploads.js.map +1 -0
- package/dist/internal/schemaCache.d.ts +10 -0
- package/dist/internal/schemaCache.js +29 -0
- package/dist/internal/schemaCache.js.map +1 -0
- package/dist/internal/shared.d.ts +32 -0
- package/dist/internal/shared.js +55 -0
- package/dist/internal/shared.js.map +1 -0
- package/dist/internal/stripStegaHook.d.ts +2 -0
- package/dist/internal/stripStegaHook.js +29 -0
- package/dist/internal/stripStegaHook.js.map +1 -0
- package/package.json +105 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { BuildAdminEditUrl } from "../buildAdminEditUrl.js";
|
|
2
|
+
import type { Marker } from "./markerExtractor.js";
|
|
3
|
+
export type TargetConfig = {
|
|
4
|
+
/** The marker path currently bound to this target. Used by callers to detect path changes
|
|
5
|
+
* on the same DOM element (the React-reuses-the-node-with-new-content case). */
|
|
6
|
+
path: string;
|
|
7
|
+
href: string;
|
|
8
|
+
clickHandler: (event: MouseEvent) => void;
|
|
9
|
+
originalOutline: string;
|
|
10
|
+
/** Whether the badge owns outline paint/restore for this target. True in hover mode,
|
|
11
|
+
* false in 'always' mode where the registry already painted the outline. */
|
|
12
|
+
paintOutline: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type TargetRegistryCtx = {
|
|
15
|
+
buildAdminEditUrl: BuildAdminEditUrl;
|
|
16
|
+
adminOrigin: string;
|
|
17
|
+
adminBasePath: string;
|
|
18
|
+
locale?: string;
|
|
19
|
+
/** 'always' paints outlines on every registered target; 'hover' leaves painting to the badge. */
|
|
20
|
+
mode: "always" | "hover";
|
|
21
|
+
};
|
|
22
|
+
export interface TargetRegistry {
|
|
23
|
+
/** Register or replace the config bound to `target`. Re-registration keeps the outline snapshot
|
|
24
|
+
* but produces a fresh href + click handler so a re-rendered element with a new marker path
|
|
25
|
+
* does not retain stale click targets. */
|
|
26
|
+
upsert(target: HTMLElement, marker: Marker, ctx: TargetRegistryCtx): TargetConfig;
|
|
27
|
+
get(target: HTMLElement): TargetConfig | undefined;
|
|
28
|
+
has(target: HTMLElement): boolean;
|
|
29
|
+
/** Remove the config, restore original outline, and drop the `data-ve-target` attribute. */
|
|
30
|
+
remove(target: HTMLElement): void;
|
|
31
|
+
/** Remove every still-tracked target (used on overlay teardown). */
|
|
32
|
+
disposeAll(): void;
|
|
33
|
+
}
|
|
34
|
+
export declare function createTargetRegistry(): TargetRegistry;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { spreadVeIdentity } from "../../internal/shared.js";
|
|
2
|
+
import { buildOverlayClickHandler } from "../overlayClickHandler.js";
|
|
3
|
+
import { DATA_VE_TARGET_ATTR, OUTLINE_STYLE } from "./constants.js";
|
|
4
|
+
export function createTargetRegistry() {
|
|
5
|
+
const configs = new Map();
|
|
6
|
+
const buildBindings = (marker, ctx)=>{
|
|
7
|
+
const href = ctx.buildAdminEditUrl({
|
|
8
|
+
...spreadVeIdentity(marker),
|
|
9
|
+
locale: ctx.locale,
|
|
10
|
+
adminBasePath: ctx.adminBasePath
|
|
11
|
+
});
|
|
12
|
+
const clickHandler = buildOverlayClickHandler({
|
|
13
|
+
...spreadVeIdentity(marker),
|
|
14
|
+
href,
|
|
15
|
+
adminOrigin: ctx.adminOrigin,
|
|
16
|
+
locale: ctx.locale
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
href,
|
|
20
|
+
clickHandler
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
const clearTarget = (target, originalOutline)=>{
|
|
24
|
+
target.style.outline = originalOutline;
|
|
25
|
+
target.removeAttribute(DATA_VE_TARGET_ATTR);
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
upsert (target, marker, ctx) {
|
|
29
|
+
const existing = configs.get(target);
|
|
30
|
+
const { href, clickHandler } = buildBindings(marker, ctx);
|
|
31
|
+
// Always re-write the target attr — `marker.path` may have changed for the same element.
|
|
32
|
+
target.setAttribute(DATA_VE_TARGET_ATTR, marker.path);
|
|
33
|
+
const originalOutline = existing?.originalOutline ?? target.style.outline;
|
|
34
|
+
// 'always' mode paints the outline at registration so every editable shows it persistently.
|
|
35
|
+
// First registration only — re-upserts (marker path change) leave the painted outline intact.
|
|
36
|
+
if (ctx.mode === "always" && !existing) {
|
|
37
|
+
target.style.outline = OUTLINE_STYLE;
|
|
38
|
+
}
|
|
39
|
+
const next = {
|
|
40
|
+
path: marker.path,
|
|
41
|
+
href,
|
|
42
|
+
clickHandler,
|
|
43
|
+
originalOutline,
|
|
44
|
+
paintOutline: ctx.mode === "hover"
|
|
45
|
+
};
|
|
46
|
+
configs.set(target, next);
|
|
47
|
+
return next;
|
|
48
|
+
},
|
|
49
|
+
get (target) {
|
|
50
|
+
return configs.get(target);
|
|
51
|
+
},
|
|
52
|
+
has (target) {
|
|
53
|
+
return configs.has(target);
|
|
54
|
+
},
|
|
55
|
+
remove (target) {
|
|
56
|
+
const config = configs.get(target);
|
|
57
|
+
if (!config) return;
|
|
58
|
+
clearTarget(target, config.originalOutline);
|
|
59
|
+
configs.delete(target);
|
|
60
|
+
},
|
|
61
|
+
disposeAll () {
|
|
62
|
+
for (const [target, config] of configs){
|
|
63
|
+
clearTarget(target, config.originalOutline);
|
|
64
|
+
}
|
|
65
|
+
configs.clear();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=targetRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/overlay/targetRegistry.ts"],"sourcesContent":["import type { BuildAdminEditUrl } from \"../buildAdminEditUrl.js\";\nimport type { Marker } from \"./markerExtractor.js\";\n\nimport { spreadVeIdentity } from \"../../internal/shared.js\";\nimport { buildOverlayClickHandler } from \"../overlayClickHandler.js\";\nimport { DATA_VE_TARGET_ATTR, OUTLINE_STYLE } from \"./constants.js\";\n\nexport type TargetConfig = {\n /** The marker path currently bound to this target. Used by callers to detect path changes\n * on the same DOM element (the React-reuses-the-node-with-new-content case). */\n path: string;\n href: string;\n clickHandler: (event: MouseEvent) => void;\n originalOutline: string;\n /** Whether the badge owns outline paint/restore for this target. True in hover mode,\n * false in 'always' mode where the registry already painted the outline. */\n paintOutline: boolean;\n};\n\nexport type TargetRegistryCtx = {\n buildAdminEditUrl: BuildAdminEditUrl;\n adminOrigin: string;\n adminBasePath: string;\n locale?: string;\n /** 'always' paints outlines on every registered target; 'hover' leaves painting to the badge. */\n mode: \"always\" | \"hover\";\n};\n\nexport interface TargetRegistry {\n /** Register or replace the config bound to `target`. Re-registration keeps the outline snapshot\n * but produces a fresh href + click handler so a re-rendered element with a new marker path\n * does not retain stale click targets. */\n upsert(target: HTMLElement, marker: Marker, ctx: TargetRegistryCtx): TargetConfig;\n get(target: HTMLElement): TargetConfig | undefined;\n has(target: HTMLElement): boolean;\n /** Remove the config, restore original outline, and drop the `data-ve-target` attribute. */\n remove(target: HTMLElement): void;\n /** Remove every still-tracked target (used on overlay teardown). */\n disposeAll(): void;\n}\n\nexport function createTargetRegistry(): TargetRegistry {\n const configs = new Map<HTMLElement, TargetConfig>();\n\n const buildBindings = (marker: Marker, ctx: TargetRegistryCtx) => {\n const href = ctx.buildAdminEditUrl({\n ...spreadVeIdentity(marker),\n locale: ctx.locale,\n adminBasePath: ctx.adminBasePath,\n });\n const clickHandler = buildOverlayClickHandler({\n ...spreadVeIdentity(marker),\n href,\n adminOrigin: ctx.adminOrigin,\n locale: ctx.locale,\n });\n return { href, clickHandler };\n };\n\n const clearTarget = (target: HTMLElement, originalOutline: string) => {\n target.style.outline = originalOutline;\n target.removeAttribute(DATA_VE_TARGET_ATTR);\n };\n\n return {\n upsert(target, marker, ctx) {\n const existing = configs.get(target);\n const { href, clickHandler } = buildBindings(marker, ctx);\n // Always re-write the target attr — `marker.path` may have changed for the same element.\n target.setAttribute(DATA_VE_TARGET_ATTR, marker.path);\n const originalOutline = existing?.originalOutline ?? target.style.outline;\n // 'always' mode paints the outline at registration so every editable shows it persistently.\n // First registration only — re-upserts (marker path change) leave the painted outline intact.\n if (ctx.mode === \"always\" && !existing) {\n target.style.outline = OUTLINE_STYLE;\n }\n const next: TargetConfig = {\n path: marker.path,\n href,\n clickHandler,\n originalOutline,\n paintOutline: ctx.mode === \"hover\",\n };\n configs.set(target, next);\n return next;\n },\n get(target) {\n return configs.get(target);\n },\n has(target) {\n return configs.has(target);\n },\n remove(target) {\n const config = configs.get(target);\n if (!config) return;\n clearTarget(target, config.originalOutline);\n configs.delete(target);\n },\n disposeAll() {\n for (const [target, config] of configs) {\n clearTarget(target, config.originalOutline);\n }\n configs.clear();\n },\n };\n}\n"],"names":["spreadVeIdentity","buildOverlayClickHandler","DATA_VE_TARGET_ATTR","OUTLINE_STYLE","createTargetRegistry","configs","Map","buildBindings","marker","ctx","href","buildAdminEditUrl","locale","adminBasePath","clickHandler","adminOrigin","clearTarget","target","originalOutline","style","outline","removeAttribute","upsert","existing","get","setAttribute","path","mode","next","paintOutline","set","has","remove","config","delete","disposeAll","clear"],"mappings":"AAGA,SAASA,gBAAgB,QAAQ,2BAA2B;AAC5D,SAASC,wBAAwB,QAAQ,4BAA4B;AACrE,SAASC,mBAAmB,EAAEC,aAAa,QAAQ,iBAAiB;AAoCpE,OAAO,SAASC;IACd,MAAMC,UAAU,IAAIC;IAEpB,MAAMC,gBAAgB,CAACC,QAAgBC;QACrC,MAAMC,OAAOD,IAAIE,iBAAiB,CAAC;YACjC,GAAGX,iBAAiBQ,OAAO;YAC3BI,QAAQH,IAAIG,MAAM;YAClBC,eAAeJ,IAAII,aAAa;QAClC;QACA,MAAMC,eAAeb,yBAAyB;YAC5C,GAAGD,iBAAiBQ,OAAO;YAC3BE;YACAK,aAAaN,IAAIM,WAAW;YAC5BH,QAAQH,IAAIG,MAAM;QACpB;QACA,OAAO;YAAEF;YAAMI;QAAa;IAC9B;IAEA,MAAME,cAAc,CAACC,QAAqBC;QACxCD,OAAOE,KAAK,CAACC,OAAO,GAAGF;QACvBD,OAAOI,eAAe,CAACnB;IACzB;IAEA,OAAO;QACLoB,QAAOL,MAAM,EAAET,MAAM,EAAEC,GAAG;YACxB,MAAMc,WAAWlB,QAAQmB,GAAG,CAACP;YAC7B,MAAM,EAAEP,IAAI,EAAEI,YAAY,EAAE,GAAGP,cAAcC,QAAQC;YACrD,yFAAyF;YACzFQ,OAAOQ,YAAY,CAACvB,qBAAqBM,OAAOkB,IAAI;YACpD,MAAMR,kBAAkBK,UAAUL,mBAAmBD,OAAOE,KAAK,CAACC,OAAO;YACzE,4FAA4F;YAC5F,8FAA8F;YAC9F,IAAIX,IAAIkB,IAAI,KAAK,YAAY,CAACJ,UAAU;gBACtCN,OAAOE,KAAK,CAACC,OAAO,GAAGjB;YACzB;YACA,MAAMyB,OAAqB;gBACzBF,MAAMlB,OAAOkB,IAAI;gBACjBhB;gBACAI;gBACAI;gBACAW,cAAcpB,IAAIkB,IAAI,KAAK;YAC7B;YACAtB,QAAQyB,GAAG,CAACb,QAAQW;YACpB,OAAOA;QACT;QACAJ,KAAIP,MAAM;YACR,OAAOZ,QAAQmB,GAAG,CAACP;QACrB;QACAc,KAAId,MAAM;YACR,OAAOZ,QAAQ0B,GAAG,CAACd;QACrB;QACAe,QAAOf,MAAM;YACX,MAAMgB,SAAS5B,QAAQmB,GAAG,CAACP;YAC3B,IAAI,CAACgB,QAAQ;YACbjB,YAAYC,QAAQgB,OAAOf,eAAe;YAC1Cb,QAAQ6B,MAAM,CAACjB;QACjB;QACAkB;YACE,KAAK,MAAM,CAAClB,QAAQgB,OAAO,IAAI5B,QAAS;gBACtCW,YAAYC,QAAQgB,OAAOf,eAAe;YAC5C;YACAb,QAAQ+B,KAAK;QACf;IACF;AACF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { DATA_VE_TARGET_ATTR } from "./constants.js";
|
|
2
|
+
// Shared ancestor walk used by all three target-selection helpers below.
|
|
3
|
+
// Walks up from `start` calling `select` on each element; returns the first
|
|
4
|
+
// non-null result. When `boundary` is provided, stops ascending once the
|
|
5
|
+
// current element is no longer contained by (or equal to) the boundary.
|
|
6
|
+
function walkAncestors(start, select, boundary) {
|
|
7
|
+
let cur = start;
|
|
8
|
+
while(cur){
|
|
9
|
+
if (boundary && !boundary.contains(cur)) return null;
|
|
10
|
+
const hit = select(cur);
|
|
11
|
+
if (hit) return hit;
|
|
12
|
+
cur = cur.parentElement;
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
export function findTargetAncestor(el) {
|
|
17
|
+
return walkAncestors(el, (cur)=>cur instanceof HTMLElement && cur.hasAttribute(DATA_VE_TARGET_ATTR) ? cur : null);
|
|
18
|
+
}
|
|
19
|
+
function findButtonOrAnchor(start, boundary) {
|
|
20
|
+
return walkAncestors(start, (cur)=>cur.tagName === "A" || cur.tagName === "BUTTON" ? cur : null, boundary);
|
|
21
|
+
}
|
|
22
|
+
function lowestCommonAncestor(nodes) {
|
|
23
|
+
if (nodes.length === 0) return null;
|
|
24
|
+
const firstParent = nodes[0].parentElement;
|
|
25
|
+
if (nodes.length === 1 || !firstParent) return firstParent;
|
|
26
|
+
const otherSets = nodes.slice(1).map((n)=>{
|
|
27
|
+
const set = new Set();
|
|
28
|
+
for(let p = n.parentElement; p; p = p.parentElement)set.add(p);
|
|
29
|
+
return set;
|
|
30
|
+
});
|
|
31
|
+
for(let p = firstParent; p; p = p.parentElement){
|
|
32
|
+
if (otherSets.every((s)=>s.has(p))) return p;
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
// If the stega text lives inside a <label> whose associated form control is a
|
|
37
|
+
// *sibling* (the common floating-label pattern: `<div><input/><label/></div>`),
|
|
38
|
+
// the raw LCA is just the <label>. Hovering the input then never triggers
|
|
39
|
+
// mouseenter on the label (events don't bubble across siblings). Climb to the
|
|
40
|
+
// nearest ancestor that contains both so the whole field becomes the hover zone.
|
|
41
|
+
function expandLabelToFormFieldContainer(lca, boundary) {
|
|
42
|
+
if (lca.tagName !== "LABEL") return null;
|
|
43
|
+
const label = lca;
|
|
44
|
+
let control = null;
|
|
45
|
+
// oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors
|
|
46
|
+
if (label.htmlFor) control = label.ownerDocument.getElementById(label.htmlFor);
|
|
47
|
+
if (!control) control = label.querySelector("input, textarea, select");
|
|
48
|
+
if (!control || label.contains(control)) return null;
|
|
49
|
+
const controlAncestors = new Set();
|
|
50
|
+
for(let p = control; p && boundary.contains(p); p = p.parentElement){
|
|
51
|
+
controlAncestors.add(p);
|
|
52
|
+
}
|
|
53
|
+
for(let p = label.parentElement; p && boundary.contains(p); p = p.parentElement){
|
|
54
|
+
if (controlAncestors.has(p)) return p;
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
export function pickTargetForGroup(nodes, boundary) {
|
|
59
|
+
const buttonOrAnchor = findButtonOrAnchor(nodes[0]?.parentElement ?? null, boundary);
|
|
60
|
+
const inside = buttonOrAnchor && nodes.every((n)=>buttonOrAnchor.contains(n));
|
|
61
|
+
if (inside) return buttonOrAnchor;
|
|
62
|
+
const lca = lowestCommonAncestor(nodes);
|
|
63
|
+
if (!lca) return null;
|
|
64
|
+
return expandLabelToFormFieldContainer(lca, boundary) ?? lca;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=targetSelector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/overlay/targetSelector.ts"],"sourcesContent":["import { DATA_VE_TARGET_ATTR } from \"./constants.js\";\n\n// Shared ancestor walk used by all three target-selection helpers below.\n// Walks up from `start` calling `select` on each element; returns the first\n// non-null result. When `boundary` is provided, stops ascending once the\n// current element is no longer contained by (or equal to) the boundary.\nfunction walkAncestors<T>(\n start: Element | null,\n select: (el: Element) => T | null,\n boundary?: Element\n): T | null {\n let cur: Element | null = start;\n while (cur) {\n if (boundary && !boundary.contains(cur)) return null;\n const hit = select(cur);\n if (hit) return hit;\n cur = cur.parentElement;\n }\n return null;\n}\n\nexport function findTargetAncestor(el: Element | null): HTMLElement | null {\n return walkAncestors(el, (cur) =>\n cur instanceof HTMLElement && cur.hasAttribute(DATA_VE_TARGET_ATTR) ? cur : null\n );\n}\n\nfunction findButtonOrAnchor(start: Element | null, boundary: Element): Element | null {\n return walkAncestors(\n start,\n (cur) => (cur.tagName === \"A\" || cur.tagName === \"BUTTON\" ? cur : null),\n boundary\n );\n}\n\nfunction lowestCommonAncestor(nodes: readonly Node[]): Element | null {\n if (nodes.length === 0) return null;\n const firstParent = nodes[0]!.parentElement;\n if (nodes.length === 1 || !firstParent) return firstParent;\n const otherSets = nodes.slice(1).map((n) => {\n const set = new Set<Element>();\n for (let p: Element | null = n.parentElement; p; p = p.parentElement) set.add(p);\n return set;\n });\n for (let p: Element | null = firstParent; p; p = p.parentElement) {\n if (otherSets.every((s) => s.has(p!))) return p;\n }\n return null;\n}\n\n// If the stega text lives inside a <label> whose associated form control is a\n// *sibling* (the common floating-label pattern: `<div><input/><label/></div>`),\n// the raw LCA is just the <label>. Hovering the input then never triggers\n// mouseenter on the label (events don't bubble across siblings). Climb to the\n// nearest ancestor that contains both so the whole field becomes the hover zone.\nfunction expandLabelToFormFieldContainer(lca: Element, boundary: Element): Element | null {\n if (lca.tagName !== \"LABEL\") return null;\n const label = lca as HTMLLabelElement;\n let control: Element | null = null;\n // oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors\n if (label.htmlFor) control = label.ownerDocument.getElementById(label.htmlFor);\n if (!control) control = label.querySelector(\"input, textarea, select\");\n if (!control || label.contains(control)) return null;\n\n const controlAncestors = new Set<Element>();\n for (let p: Element | null = control; p && boundary.contains(p); p = p.parentElement) {\n controlAncestors.add(p);\n }\n for (\n let p: Element | null = label.parentElement;\n p && boundary.contains(p);\n p = p.parentElement\n ) {\n if (controlAncestors.has(p)) return p;\n }\n return null;\n}\n\nexport function pickTargetForGroup(nodes: readonly Text[], boundary: Element): Element | null {\n const buttonOrAnchor = findButtonOrAnchor(nodes[0]?.parentElement ?? null, boundary);\n const inside = buttonOrAnchor && nodes.every((n) => buttonOrAnchor.contains(n));\n if (inside) return buttonOrAnchor;\n\n const lca = lowestCommonAncestor(nodes);\n if (!lca) return null;\n\n return expandLabelToFormFieldContainer(lca, boundary) ?? lca;\n}\n"],"names":["DATA_VE_TARGET_ATTR","walkAncestors","start","select","boundary","cur","contains","hit","parentElement","findTargetAncestor","el","HTMLElement","hasAttribute","findButtonOrAnchor","tagName","lowestCommonAncestor","nodes","length","firstParent","otherSets","slice","map","n","set","Set","p","add","every","s","has","expandLabelToFormFieldContainer","lca","label","control","htmlFor","ownerDocument","getElementById","querySelector","controlAncestors","pickTargetForGroup","buttonOrAnchor","inside"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,iBAAiB;AAErD,yEAAyE;AACzE,4EAA4E;AAC5E,yEAAyE;AACzE,wEAAwE;AACxE,SAASC,cACPC,KAAqB,EACrBC,MAAiC,EACjCC,QAAkB;IAElB,IAAIC,MAAsBH;IAC1B,MAAOG,IAAK;QACV,IAAID,YAAY,CAACA,SAASE,QAAQ,CAACD,MAAM,OAAO;QAChD,MAAME,MAAMJ,OAAOE;QACnB,IAAIE,KAAK,OAAOA;QAChBF,MAAMA,IAAIG,aAAa;IACzB;IACA,OAAO;AACT;AAEA,OAAO,SAASC,mBAAmBC,EAAkB;IACnD,OAAOT,cAAcS,IAAI,CAACL,MACxBA,eAAeM,eAAeN,IAAIO,YAAY,CAACZ,uBAAuBK,MAAM;AAEhF;AAEA,SAASQ,mBAAmBX,KAAqB,EAAEE,QAAiB;IAClE,OAAOH,cACLC,OACA,CAACG,MAASA,IAAIS,OAAO,KAAK,OAAOT,IAAIS,OAAO,KAAK,WAAWT,MAAM,MAClED;AAEJ;AAEA,SAASW,qBAAqBC,KAAsB;IAClD,IAAIA,MAAMC,MAAM,KAAK,GAAG,OAAO;IAC/B,MAAMC,cAAcF,KAAK,CAAC,EAAE,CAAER,aAAa;IAC3C,IAAIQ,MAAMC,MAAM,KAAK,KAAK,CAACC,aAAa,OAAOA;IAC/C,MAAMC,YAAYH,MAAMI,KAAK,CAAC,GAAGC,GAAG,CAAC,CAACC;QACpC,MAAMC,MAAM,IAAIC;QAChB,IAAK,IAAIC,IAAoBH,EAAEd,aAAa,EAAEiB,GAAGA,IAAIA,EAAEjB,aAAa,CAAEe,IAAIG,GAAG,CAACD;QAC9E,OAAOF;IACT;IACA,IAAK,IAAIE,IAAoBP,aAAaO,GAAGA,IAAIA,EAAEjB,aAAa,CAAE;QAChE,IAAIW,UAAUQ,KAAK,CAAC,CAACC,IAAMA,EAAEC,GAAG,CAACJ,KAAM,OAAOA;IAChD;IACA,OAAO;AACT;AAEA,8EAA8E;AAC9E,gFAAgF;AAChF,0EAA0E;AAC1E,8EAA8E;AAC9E,iFAAiF;AACjF,SAASK,gCAAgCC,GAAY,EAAE3B,QAAiB;IACtE,IAAI2B,IAAIjB,OAAO,KAAK,SAAS,OAAO;IACpC,MAAMkB,QAAQD;IACd,IAAIE,UAA0B;IAC9B,6GAA6G;IAC7G,IAAID,MAAME,OAAO,EAAED,UAAUD,MAAMG,aAAa,CAACC,cAAc,CAACJ,MAAME,OAAO;IAC7E,IAAI,CAACD,SAASA,UAAUD,MAAMK,aAAa,CAAC;IAC5C,IAAI,CAACJ,WAAWD,MAAM1B,QAAQ,CAAC2B,UAAU,OAAO;IAEhD,MAAMK,mBAAmB,IAAId;IAC7B,IAAK,IAAIC,IAAoBQ,SAASR,KAAKrB,SAASE,QAAQ,CAACmB,IAAIA,IAAIA,EAAEjB,aAAa,CAAE;QACpF8B,iBAAiBZ,GAAG,CAACD;IACvB;IACA,IACE,IAAIA,IAAoBO,MAAMxB,aAAa,EAC3CiB,KAAKrB,SAASE,QAAQ,CAACmB,IACvBA,IAAIA,EAAEjB,aAAa,CACnB;QACA,IAAI8B,iBAAiBT,GAAG,CAACJ,IAAI,OAAOA;IACtC;IACA,OAAO;AACT;AAEA,OAAO,SAASc,mBAAmBvB,KAAsB,EAAEZ,QAAiB;IAC1E,MAAMoC,iBAAiB3B,mBAAmBG,KAAK,CAAC,EAAE,EAAER,iBAAiB,MAAMJ;IAC3E,MAAMqC,SAASD,kBAAkBxB,MAAMW,KAAK,CAAC,CAACL,IAAMkB,eAAelC,QAAQ,CAACgB;IAC5E,IAAImB,QAAQ,OAAOD;IAEnB,MAAMT,MAAMhB,qBAAqBC;IACjC,IAAI,CAACe,KAAK,OAAO;IAEjB,OAAOD,gCAAgCC,KAAK3B,aAAa2B;AAC3D"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { VeIdentity } from "../internal/shared.js";
|
|
2
|
+
export type OverlayClickContext = VeIdentity & {
|
|
3
|
+
href: string;
|
|
4
|
+
adminOrigin: string;
|
|
5
|
+
locale?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const buildOverlayClickHandler: (ctx: OverlayClickContext, win?: Window) => (event: MouseEvent) => void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { VE_MESSAGE_TYPE } from "../constants.js";
|
|
2
|
+
import { spreadVeIdentity } from "../internal/shared.js";
|
|
3
|
+
export const buildOverlayClickHandler = (ctx, win = window)=>(event)=>{
|
|
4
|
+
event.preventDefault?.();
|
|
5
|
+
const message = {
|
|
6
|
+
type: VE_MESSAGE_TYPE,
|
|
7
|
+
...spreadVeIdentity(ctx),
|
|
8
|
+
...ctx.locale !== undefined && {
|
|
9
|
+
locale: ctx.locale
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
if (win.parent && win.parent !== win) {
|
|
13
|
+
win.parent.postMessage(message, ctx.adminOrigin || "*");
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const opener = win.opener;
|
|
17
|
+
if (opener && !opener.closed) {
|
|
18
|
+
opener.postMessage(message, ctx.adminOrigin || "*");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
win.open(ctx.href, "_blank");
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=overlayClickHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/overlayClickHandler.ts"],"sourcesContent":["import type { VeIdentity } from \"../internal/shared.js\";\n\nimport { VE_MESSAGE_TYPE } from \"../constants.js\";\nimport type { VeOpenFieldMessage } from \"../constants.js\";\nimport { spreadVeIdentity } from \"../internal/shared.js\";\n\nexport type OverlayClickContext = VeIdentity & {\n href: string;\n adminOrigin: string;\n locale?: string;\n};\n\nexport const buildOverlayClickHandler =\n (ctx: OverlayClickContext, win: Window = window) =>\n (event: MouseEvent) => {\n event.preventDefault?.();\n\n const message: VeOpenFieldMessage = {\n type: VE_MESSAGE_TYPE,\n ...spreadVeIdentity(ctx),\n ...(ctx.locale !== undefined && { locale: ctx.locale }),\n };\n\n if (win.parent && win.parent !== win) {\n win.parent.postMessage(message, ctx.adminOrigin || \"*\");\n return;\n }\n\n const opener = win.opener as Window | null;\n if (opener && !opener.closed) {\n opener.postMessage(message, ctx.adminOrigin || \"*\");\n return;\n }\n\n win.open(ctx.href, \"_blank\");\n };\n"],"names":["VE_MESSAGE_TYPE","spreadVeIdentity","buildOverlayClickHandler","ctx","win","window","event","preventDefault","message","type","locale","undefined","parent","postMessage","adminOrigin","opener","closed","open","href"],"mappings":"AAEA,SAASA,eAAe,QAAQ,kBAAkB;AAElD,SAASC,gBAAgB,QAAQ,wBAAwB;AAQzD,OAAO,MAAMC,2BACX,CAACC,KAA0BC,MAAcC,MAAM,GAC/C,CAACC;QACCA,MAAMC,cAAc;QAEpB,MAAMC,UAA8B;YAClCC,MAAMT;YACN,GAAGC,iBAAiBE,IAAI;YACxB,GAAIA,IAAIO,MAAM,KAAKC,aAAa;gBAAED,QAAQP,IAAIO,MAAM;YAAC,CAAC;QACxD;QAEA,IAAIN,IAAIQ,MAAM,IAAIR,IAAIQ,MAAM,KAAKR,KAAK;YACpCA,IAAIQ,MAAM,CAACC,WAAW,CAACL,SAASL,IAAIW,WAAW,IAAI;YACnD;QACF;QAEA,MAAMC,SAASX,IAAIW,MAAM;QACzB,IAAIA,UAAU,CAACA,OAAOC,MAAM,EAAE;YAC5BD,OAAOF,WAAW,CAACL,SAASL,IAAIW,WAAW,IAAI;YAC/C;QACF;QAEAV,IAAIa,IAAI,CAACd,IAAIe,IAAI,EAAE;IACrB,EAAE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { createOverlay } from "./overlay/createOverlay.js";
|
|
4
|
+
export function useVisualEditingOverlay(enabled, rootRef, ctx) {
|
|
5
|
+
const ctxRef = useRef(ctx);
|
|
6
|
+
ctxRef.current = ctx;
|
|
7
|
+
// Include mode in deps so the overlay tears down and rebuilds when the user flips between
|
|
8
|
+
// 'always' and 'hover' — otherwise existing targets keep their old paint state.
|
|
9
|
+
useEffect(()=>{
|
|
10
|
+
if (!enabled) return;
|
|
11
|
+
const root = rootRef.current;
|
|
12
|
+
if (!root) return;
|
|
13
|
+
return createOverlay(root, ()=>ctxRef.current);
|
|
14
|
+
}, [
|
|
15
|
+
enabled,
|
|
16
|
+
ctx.mode,
|
|
17
|
+
rootRef
|
|
18
|
+
]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=useVisualEditingOverlay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/useVisualEditingOverlay.ts"],"sourcesContent":["\"use client\";\n\nimport type { RefObject } from \"react\";\n\nimport type { OverlayCtx } from \"./overlay/createOverlay.js\";\n\nimport { useEffect, useRef } from \"react\";\n\nimport { createOverlay } from \"./overlay/createOverlay.js\";\n\nexport type { OverlayCtx };\n\nexport function useVisualEditingOverlay(\n enabled: boolean,\n rootRef: RefObject<HTMLElement | null>,\n ctx: OverlayCtx\n): void {\n const ctxRef = useRef(ctx);\n ctxRef.current = ctx;\n // Include mode in deps so the overlay tears down and rebuilds when the user flips between\n // 'always' and 'hover' — otherwise existing targets keep their old paint state.\n useEffect(() => {\n if (!enabled) return;\n const root = rootRef.current;\n if (!root) return;\n return createOverlay(root, () => ctxRef.current);\n }, [enabled, ctx.mode, rootRef]);\n}\n"],"names":["useEffect","useRef","createOverlay","useVisualEditingOverlay","enabled","rootRef","ctx","ctxRef","current","root","mode"],"mappings":"AAAA;AAMA,SAASA,SAAS,EAAEC,MAAM,QAAQ,QAAQ;AAE1C,SAASC,aAAa,QAAQ,6BAA6B;AAI3D,OAAO,SAASC,wBACdC,OAAgB,EAChBC,OAAsC,EACtCC,GAAe;IAEf,MAAMC,SAASN,OAAOK;IACtBC,OAAOC,OAAO,GAAGF;IACjB,0FAA0F;IAC1F,gFAAgF;IAChFN,UAAU;QACR,IAAI,CAACI,SAAS;QACd,MAAMK,OAAOJ,QAAQG,OAAO;QAC5B,IAAI,CAACC,MAAM;QACX,OAAOP,cAAcO,MAAM,IAAMF,OAAOC,OAAO;IACjD,GAAG;QAACJ;QAASE,IAAII,IAAI;QAAEL;KAAQ;AACjC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DATA_VE_COLLECTION_ATTR, DATA_VE_DOC_ID_ATTR, DATA_VE_KIND_ATTR, DATA_VE_PATH_ATTR } from "../constants.js";
|
|
2
|
+
type Attrs = Partial<{
|
|
3
|
+
[DATA_VE_PATH_ATTR]: string;
|
|
4
|
+
[DATA_VE_DOC_ID_ATTR]: string;
|
|
5
|
+
[DATA_VE_COLLECTION_ATTR]: string;
|
|
6
|
+
[DATA_VE_KIND_ATTR]: string;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const withVisualEditingPath: (value: unknown) => Attrs;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DATA_VE_COLLECTION_ATTR, DATA_VE_DOC_ID_ATTR, DATA_VE_KIND_ATTR, DATA_VE_PATH_ATTR } from "../constants.js";
|
|
2
|
+
import { isMetaInfo } from "../internal/shared.js";
|
|
3
|
+
export const withVisualEditingPath = (value)=>{
|
|
4
|
+
const hasMeta = !!value && typeof value === "object" && "_meta" in value;
|
|
5
|
+
if (!(hasMeta && isMetaInfo(value._meta))) return {};
|
|
6
|
+
const meta = value._meta;
|
|
7
|
+
return {
|
|
8
|
+
[DATA_VE_PATH_ATTR]: meta.path,
|
|
9
|
+
[DATA_VE_COLLECTION_ATTR]: meta.collectionSlug,
|
|
10
|
+
[DATA_VE_KIND_ATTR]: meta.kind,
|
|
11
|
+
...meta.docId !== undefined && {
|
|
12
|
+
[DATA_VE_DOC_ID_ATTR]: meta.docId
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=withVisualEditingPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/withVisualEditingPath.ts"],"sourcesContent":["import {\n DATA_VE_COLLECTION_ATTR,\n DATA_VE_DOC_ID_ATTR,\n DATA_VE_KIND_ATTR,\n DATA_VE_PATH_ATTR,\n} from \"../constants.js\";\nimport { isMetaInfo } from \"../internal/shared.js\";\n\ntype Attrs = Partial<{\n [DATA_VE_PATH_ATTR]: string;\n [DATA_VE_DOC_ID_ATTR]: string;\n [DATA_VE_COLLECTION_ATTR]: string;\n [DATA_VE_KIND_ATTR]: string;\n}>;\n\nexport const withVisualEditingPath = (value: unknown): Attrs => {\n const hasMeta = !!value && typeof value === \"object\" && \"_meta\" in value;\n if (!(hasMeta && isMetaInfo(value._meta))) return {};\n\n const meta = value._meta;\n return {\n [DATA_VE_PATH_ATTR]: meta.path,\n [DATA_VE_COLLECTION_ATTR]: meta.collectionSlug,\n [DATA_VE_KIND_ATTR]: meta.kind,\n ...(meta.docId !== undefined && { [DATA_VE_DOC_ID_ATTR]: meta.docId }),\n };\n};\n"],"names":["DATA_VE_COLLECTION_ATTR","DATA_VE_DOC_ID_ATTR","DATA_VE_KIND_ATTR","DATA_VE_PATH_ATTR","isMetaInfo","withVisualEditingPath","value","hasMeta","_meta","meta","path","collectionSlug","kind","docId","undefined"],"mappings":"AAAA,SACEA,uBAAuB,EACvBC,mBAAmB,EACnBC,iBAAiB,EACjBC,iBAAiB,QACZ,kBAAkB;AACzB,SAASC,UAAU,QAAQ,wBAAwB;AASnD,OAAO,MAAMC,wBAAwB,CAACC;IACpC,MAAMC,UAAU,CAAC,CAACD,SAAS,OAAOA,UAAU,YAAY,WAAWA;IACnE,IAAI,CAAEC,CAAAA,WAAWH,WAAWE,MAAME,KAAK,CAAA,GAAI,OAAO,CAAC;IAEnD,MAAMC,OAAOH,MAAME,KAAK;IACxB,OAAO;QACL,CAACL,kBAAkB,EAAEM,KAAKC,IAAI;QAC9B,CAACV,wBAAwB,EAAES,KAAKE,cAAc;QAC9C,CAACT,kBAAkB,EAAEO,KAAKG,IAAI;QAC9B,GAAIH,KAAKI,KAAK,KAAKC,aAAa;YAAE,CAACb,oBAAoB,EAAEQ,KAAKI,KAAK;QAAC,CAAC;IACvE;AACF,EAAE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const DATA_VE_PATH_ATTR = "data-ve-path";
|
|
2
|
+
export declare const DATA_VE_DOC_ID_ATTR = "data-ve-doc-id";
|
|
3
|
+
export declare const DATA_VE_COLLECTION_ATTR = "data-ve-collection";
|
|
4
|
+
export declare const DATA_VE_KIND_ATTR = "data-ve-kind";
|
|
5
|
+
export declare const STORAGE_KEY = "visual-editing";
|
|
6
|
+
export type VisualEditingMode = "off" | "always" | "hover";
|
|
7
|
+
export declare const VISUAL_EDITING_MODES: readonly VisualEditingMode[];
|
|
8
|
+
export declare const VE_MESSAGE_TYPE = "ve:open-field";
|
|
9
|
+
export type VeOpenFieldMessage = {
|
|
10
|
+
type: typeof VE_MESSAGE_TYPE;
|
|
11
|
+
path: string;
|
|
12
|
+
docId?: string;
|
|
13
|
+
collectionSlug: string;
|
|
14
|
+
kind: "collection" | "global";
|
|
15
|
+
locale?: string;
|
|
16
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// For elements that can't carry inline stega — e.g. rich-text wrappers where the
|
|
2
|
+
// renderer owns the text nodes. Overlay reads it as a fallback path marker.
|
|
3
|
+
export const DATA_VE_PATH_ATTR = "data-ve-path";
|
|
4
|
+
export const DATA_VE_DOC_ID_ATTR = "data-ve-doc-id";
|
|
5
|
+
export const DATA_VE_COLLECTION_ATTR = "data-ve-collection";
|
|
6
|
+
export const DATA_VE_KIND_ATTR = "data-ve-kind";
|
|
7
|
+
export const STORAGE_KEY = "visual-editing";
|
|
8
|
+
export const VISUAL_EDITING_MODES = [
|
|
9
|
+
"off",
|
|
10
|
+
"always",
|
|
11
|
+
"hover"
|
|
12
|
+
];
|
|
13
|
+
export const VE_MESSAGE_TYPE = "ve:open-field";
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts"],"sourcesContent":["// For elements that can't carry inline stega — e.g. rich-text wrappers where the\n// renderer owns the text nodes. Overlay reads it as a fallback path marker.\nexport const DATA_VE_PATH_ATTR = \"data-ve-path\";\nexport const DATA_VE_DOC_ID_ATTR = \"data-ve-doc-id\";\nexport const DATA_VE_COLLECTION_ATTR = \"data-ve-collection\";\nexport const DATA_VE_KIND_ATTR = \"data-ve-kind\";\n\nexport const STORAGE_KEY = \"visual-editing\";\n\n// Off: overlay not mounted. Always: outlines painted on every editable target.\n// Hover: outline + edit badge only on the element under the cursor.\nexport type VisualEditingMode = \"off\" | \"always\" | \"hover\";\n\nexport const VISUAL_EDITING_MODES: readonly VisualEditingMode[] = [\"off\", \"always\", \"hover\"];\n\nexport const VE_MESSAGE_TYPE = \"ve:open-field\";\n\nexport type VeOpenFieldMessage = {\n type: typeof VE_MESSAGE_TYPE;\n path: string;\n docId?: string;\n collectionSlug: string;\n kind: \"collection\" | \"global\";\n locale?: string;\n};\n"],"names":["DATA_VE_PATH_ATTR","DATA_VE_DOC_ID_ATTR","DATA_VE_COLLECTION_ATTR","DATA_VE_KIND_ATTR","STORAGE_KEY","VISUAL_EDITING_MODES","VE_MESSAGE_TYPE"],"mappings":"AAAA,iFAAiF;AACjF,4EAA4E;AAC5E,OAAO,MAAMA,oBAAoB,eAAe;AAChD,OAAO,MAAMC,sBAAsB,iBAAiB;AACpD,OAAO,MAAMC,0BAA0B,qBAAqB;AAC5D,OAAO,MAAMC,oBAAoB,eAAe;AAEhD,OAAO,MAAMC,cAAc,iBAAiB;AAM5C,OAAO,MAAMC,uBAAqD;IAAC;IAAO;IAAU;CAAQ,CAAC;AAE7F,OAAO,MAAMC,kBAAkB,gBAAgB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type ValueExcludePredicate = (value: string) => boolean;
|
|
2
|
+
export declare const isUrl: ValueExcludePredicate;
|
|
3
|
+
export declare const isSlug: ValueExcludePredicate;
|
|
4
|
+
export declare const isHash: ValueExcludePredicate;
|
|
5
|
+
export declare const isIsoDate: ValueExcludePredicate;
|
|
6
|
+
export declare const defaultExcludeValues: readonly ValueExcludePredicate[];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// URL-like: absolute URLs with any scheme (`https://`, `mailto:`, `tel:`, `data:`, `file://`),
|
|
2
|
+
// protocol-relative (`//cdn`), or root-relative (`/path`). Encoding stega into URLs corrupts
|
|
3
|
+
// them when the string lands in an `href` — the zero-width chars percent-encode into garbage.
|
|
4
|
+
export const isUrl = (value)=>/^(?:[a-z][a-z0-9+.-]*:|\/\/|\/)/i.test(value);
|
|
5
|
+
// Multi-word hyphen-joined lowercase identifiers (`hello-world`, `e-commerce`). Requires at
|
|
6
|
+
// least one hyphen so plain single words (`hello`, `world`) still get stega. Intentionally broad
|
|
7
|
+
// — matches `state-of-the-art` too; users who want those editable can override via the
|
|
8
|
+
// excludeValues config.
|
|
9
|
+
export const isSlug = (value)=>/^[a-z0-9]+(-[a-z0-9]+)+$/.test(value);
|
|
10
|
+
// Hash-prefixed fragment URLs (`#`, `#demo`, `#section-1`). The `(?!\d+$)` carves out
|
|
11
|
+
// `#<number>` ranking text (`#1`, `#42`) so it stays editable. `#1a` or `#1 seed` still
|
|
12
|
+
// match — the rule is "hash followed by a purely numeric tail is NOT a fragment."
|
|
13
|
+
export const isHash = (value)=>/^#(?!\d+$)/.test(value);
|
|
14
|
+
// Strict ISO 8601 timestamps. Matches `YYYY-MM-DD` and the full `YYYY-MM-DDThh:mm:ss(.fff)?(Z|+hh:mm)?`
|
|
15
|
+
// shape. Does not match `YYYY` or `YYYY-MM` — those are too easily confused with regular content.
|
|
16
|
+
export const isIsoDate = (value)=>/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?)?$/.test(value);
|
|
17
|
+
export const defaultExcludeValues = [
|
|
18
|
+
isUrl,
|
|
19
|
+
isSlug,
|
|
20
|
+
isHash,
|
|
21
|
+
isIsoDate
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=excludeValues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/excludeValues.ts"],"sourcesContent":["export type ValueExcludePredicate = (value: string) => boolean;\n\n// URL-like: absolute URLs with any scheme (`https://`, `mailto:`, `tel:`, `data:`, `file://`),\n// protocol-relative (`//cdn`), or root-relative (`/path`). Encoding stega into URLs corrupts\n// them when the string lands in an `href` — the zero-width chars percent-encode into garbage.\nexport const isUrl: ValueExcludePredicate = (value) =>\n /^(?:[a-z][a-z0-9+.-]*:|\\/\\/|\\/)/i.test(value);\n\n// Multi-word hyphen-joined lowercase identifiers (`hello-world`, `e-commerce`). Requires at\n// least one hyphen so plain single words (`hello`, `world`) still get stega. Intentionally broad\n// — matches `state-of-the-art` too; users who want those editable can override via the\n// excludeValues config.\nexport const isSlug: ValueExcludePredicate = (value) => /^[a-z0-9]+(-[a-z0-9]+)+$/.test(value);\n\n// Hash-prefixed fragment URLs (`#`, `#demo`, `#section-1`). The `(?!\\d+$)` carves out\n// `#<number>` ranking text (`#1`, `#42`) so it stays editable. `#1a` or `#1 seed` still\n// match — the rule is \"hash followed by a purely numeric tail is NOT a fragment.\"\nexport const isHash: ValueExcludePredicate = (value) => /^#(?!\\d+$)/.test(value);\n\n// Strict ISO 8601 timestamps. Matches `YYYY-MM-DD` and the full `YYYY-MM-DDThh:mm:ss(.fff)?(Z|+hh:mm)?`\n// shape. Does not match `YYYY` or `YYYY-MM` — those are too easily confused with regular content.\nexport const isIsoDate: ValueExcludePredicate = (value) =>\n /^\\d{4}-\\d{2}-\\d{2}(?:T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:?\\d{2})?)?$/.test(value);\n\nexport const defaultExcludeValues: readonly ValueExcludePredicate[] = [\n isUrl,\n isSlug,\n isHash,\n isIsoDate,\n];\n"],"names":["isUrl","value","test","isSlug","isHash","isIsoDate","defaultExcludeValues"],"mappings":"AAEA,+FAA+F;AAC/F,6FAA6F;AAC7F,8FAA8F;AAC9F,OAAO,MAAMA,QAA+B,CAACC,QAC3C,mCAAmCC,IAAI,CAACD,OAAO;AAEjD,4FAA4F;AAC5F,iGAAiG;AACjG,uFAAuF;AACvF,wBAAwB;AACxB,OAAO,MAAME,SAAgC,CAACF,QAAU,2BAA2BC,IAAI,CAACD,OAAO;AAE/F,sFAAsF;AACtF,wFAAwF;AACxF,kFAAkF;AAClF,OAAO,MAAMG,SAAgC,CAACH,QAAU,aAAaC,IAAI,CAACD,OAAO;AAEjF,wGAAwG;AACxG,kGAAkG;AAClG,OAAO,MAAMI,YAAmC,CAACJ,QAC/C,8EAA8EC,IAAI,CAACD,OAAO;AAE5F,OAAO,MAAMK,uBAAyD;IACpEN;IACAG;IACAC;IACAC;CACD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Plugin } from "payload";
|
|
2
|
+
import type { ValueExcludePredicate } from "./excludeValues.js";
|
|
3
|
+
export { defaultExcludeValues, isHash, isIsoDate, isSlug, isUrl, type ValueExcludePredicate, } from "./excludeValues.js";
|
|
4
|
+
export type VisualEditingPluginConfig = {
|
|
5
|
+
skipCollections?: string[];
|
|
6
|
+
skipGlobals?: string[];
|
|
7
|
+
excludeFieldNames?: string[];
|
|
8
|
+
/** Value-shape predicates; any matching value is left un-stega'd. Replaces defaults when set.
|
|
9
|
+
* Omit to use `defaultExcludeValues` (URL / slug / hash / ISO-date). */
|
|
10
|
+
excludeValues?: ValueExcludePredicate[];
|
|
11
|
+
adminBasePath?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const visualEditingPlugin: (pluginConfig?: VisualEditingPluginConfig) => Plugin;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { defaultExcludeValues } from "./excludeValues.js";
|
|
2
|
+
import { createAfterOperationHook } from "./internal/afterOperationHook.js";
|
|
3
|
+
import { createAfterReadHook } from "./internal/afterReadHook.js";
|
|
4
|
+
import { createBeforeOperationHook, createGlobalBeforeReadHook } from "./internal/beforeOperationHook.js";
|
|
5
|
+
import { createGlobalAfterReadHook } from "./internal/globalAfterReadHook.js";
|
|
6
|
+
import { createSchemaCache } from "./internal/schemaCache.js";
|
|
7
|
+
import { createStripStegaHook } from "./internal/stripStegaHook.js";
|
|
8
|
+
export { defaultExcludeValues, isHash, isIsoDate, isSlug, isUrl } from "./excludeValues.js";
|
|
9
|
+
const INTERNAL_COLLECTIONS = [
|
|
10
|
+
"payload-preferences",
|
|
11
|
+
"payload-migrations",
|
|
12
|
+
"payload-locked-documents",
|
|
13
|
+
"payload-jobs"
|
|
14
|
+
];
|
|
15
|
+
const BRIDGE_COMPONENT_PATH = "@focus-reactive/payload-plugin-visual-editing/admin#VisualEditingBridgeProvider";
|
|
16
|
+
export const visualEditingPlugin = (pluginConfig = {})=>(config)=>{
|
|
17
|
+
const skipCols = new Set([
|
|
18
|
+
...INTERNAL_COLLECTIONS,
|
|
19
|
+
...pluginConfig.skipCollections ?? []
|
|
20
|
+
]);
|
|
21
|
+
const skipGlobals = new Set(pluginConfig.skipGlobals);
|
|
22
|
+
const adminBasePath = pluginConfig.adminBasePath ?? "/admin";
|
|
23
|
+
const excludeValues = pluginConfig.excludeValues ?? defaultExcludeValues;
|
|
24
|
+
const schemaCache = createSchemaCache({
|
|
25
|
+
excludeFieldNames: pluginConfig.excludeFieldNames
|
|
26
|
+
});
|
|
27
|
+
const beforeOperation = createBeforeOperationHook();
|
|
28
|
+
const afterRead = createAfterReadHook(adminBasePath);
|
|
29
|
+
const afterOperation = createAfterOperationHook({
|
|
30
|
+
schemaCache,
|
|
31
|
+
excludeValues,
|
|
32
|
+
adminBasePath
|
|
33
|
+
});
|
|
34
|
+
const globalBeforeRead = createGlobalBeforeReadHook();
|
|
35
|
+
const globalAfterRead = createGlobalAfterReadHook({
|
|
36
|
+
schemaCache,
|
|
37
|
+
excludeValues,
|
|
38
|
+
adminBasePath
|
|
39
|
+
});
|
|
40
|
+
const stripStega = createStripStegaHook();
|
|
41
|
+
return {
|
|
42
|
+
...config,
|
|
43
|
+
collections: config.collections?.map((collection)=>{
|
|
44
|
+
if (skipCols.has(collection.slug)) return collection;
|
|
45
|
+
return {
|
|
46
|
+
...collection,
|
|
47
|
+
hooks: {
|
|
48
|
+
...collection.hooks,
|
|
49
|
+
beforeOperation: [
|
|
50
|
+
...collection.hooks?.beforeOperation ?? [],
|
|
51
|
+
beforeOperation
|
|
52
|
+
],
|
|
53
|
+
beforeChange: [
|
|
54
|
+
...collection.hooks?.beforeChange ?? [],
|
|
55
|
+
stripStega
|
|
56
|
+
],
|
|
57
|
+
afterRead: [
|
|
58
|
+
...collection.hooks?.afterRead ?? [],
|
|
59
|
+
afterRead
|
|
60
|
+
],
|
|
61
|
+
afterOperation: [
|
|
62
|
+
...collection.hooks?.afterOperation ?? [],
|
|
63
|
+
afterOperation
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}),
|
|
68
|
+
globals: config.globals?.map((global)=>{
|
|
69
|
+
if (skipGlobals.has(global.slug)) return global;
|
|
70
|
+
return {
|
|
71
|
+
...global,
|
|
72
|
+
hooks: {
|
|
73
|
+
...global.hooks,
|
|
74
|
+
beforeRead: [
|
|
75
|
+
...global.hooks?.beforeRead ?? [],
|
|
76
|
+
globalBeforeRead
|
|
77
|
+
],
|
|
78
|
+
beforeChange: [
|
|
79
|
+
...global.hooks?.beforeChange ?? [],
|
|
80
|
+
stripStega
|
|
81
|
+
],
|
|
82
|
+
afterRead: [
|
|
83
|
+
...global.hooks?.afterRead ?? [],
|
|
84
|
+
globalAfterRead
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}),
|
|
89
|
+
admin: {
|
|
90
|
+
...config.admin,
|
|
91
|
+
components: {
|
|
92
|
+
...config.admin?.components,
|
|
93
|
+
providers: [
|
|
94
|
+
...config.admin?.components?.providers ?? [],
|
|
95
|
+
{
|
|
96
|
+
path: BRIDGE_COMPONENT_PATH,
|
|
97
|
+
clientProps: {
|
|
98
|
+
adminBasePath
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CollectionAfterOperationHook } from "payload";
|
|
2
|
+
import type { ValueExcludePredicate } from "../excludeValues.js";
|
|
3
|
+
import type { SchemaCache } from "./schemaCache.js";
|
|
4
|
+
type Args = {
|
|
5
|
+
schemaCache: SchemaCache;
|
|
6
|
+
excludeValues: readonly ValueExcludePredicate[];
|
|
7
|
+
adminBasePath: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const createAfterOperationHook: ({ schemaCache, excludeValues, adminBasePath, }: Args) => CollectionAfterOperationHook;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { encodeStega } from "./encodeStega.js";
|
|
2
|
+
import { shouldEnrich } from "./gate.js";
|
|
3
|
+
// Payload fires afterOperation exactly once per outermost operation.
|
|
4
|
+
// Population uses lower-level reads that trigger afterRead (enrich only)
|
|
5
|
+
// but not afterOperation — so we get the fully-populated tree here
|
|
6
|
+
// and encode it in a single pass with no risk of double-encoding.
|
|
7
|
+
const ENCODING_OPERATIONS = new Set([
|
|
8
|
+
"find",
|
|
9
|
+
"findByID",
|
|
10
|
+
"findVersions",
|
|
11
|
+
"findVersionByID"
|
|
12
|
+
]);
|
|
13
|
+
export const createAfterOperationHook = ({ schemaCache, excludeValues, adminBasePath })=>{
|
|
14
|
+
return ({ operation, result, req })=>{
|
|
15
|
+
if (!ENCODING_OPERATIONS.has(operation)) return result;
|
|
16
|
+
if (!shouldEnrich(req, adminBasePath)) return result;
|
|
17
|
+
const resolve = (slug)=>schemaCache.get(slug, req.payload);
|
|
18
|
+
if (operation === "find" || operation === "findVersions") {
|
|
19
|
+
if (Array.isArray(result.docs)) {
|
|
20
|
+
result.docs = result.docs.map((doc)=>encodeStega(doc, resolve, excludeValues));
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
return encodeStega(result, resolve, excludeValues);
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=afterOperationHook.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { enrichWithPathMeta } from "./enrichWithPathMeta.js";
|
|
2
|
+
import { shouldEnrich } from "./gate.js";
|
|
3
|
+
export const createAfterReadHook = (adminBasePath)=>{
|
|
4
|
+
return ({ doc, collection, req })=>{
|
|
5
|
+
if (!shouldEnrich(req, adminBasePath)) return doc;
|
|
6
|
+
if (!doc || typeof doc !== "object") return doc;
|
|
7
|
+
const docId = typeof doc.id === "string" || typeof doc.id === "number" ? String(doc.id) : undefined;
|
|
8
|
+
return enrichWithPathMeta(doc, {
|
|
9
|
+
docId,
|
|
10
|
+
collectionSlug: collection.slug,
|
|
11
|
+
kind: "collection"
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=afterReadHook.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CollectionBeforeOperationHook, GlobalBeforeReadHook } from "payload";
|
|
2
|
+
export declare const DRAFT_CONTEXT_KEY = "__visualEditingDraft";
|
|
3
|
+
export declare const createBeforeOperationHook: () => CollectionBeforeOperationHook;
|
|
4
|
+
export declare const createGlobalBeforeReadHook: () => GlobalBeforeReadHook;
|