@focus-reactive/payload-plugin-visual-editing 1.2.0 → 1.3.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 +265 -31
- package/dist/admin/InstantPreviewBroadcaster.js +44 -3
- package/dist/admin/InstantPreviewBroadcaster.js.map +1 -1
- package/dist/admin/PreviewPageBridge.d.ts +1 -0
- package/dist/admin/PreviewPageBridge.js +50 -0
- package/dist/admin/PreviewPageBridge.js.map +1 -0
- package/dist/admin/VisualEditingBridgeProvider.js +60 -35
- package/dist/admin/VisualEditingBridgeProvider.js.map +1 -1
- package/dist/admin/expandAndFocus.d.ts +1 -0
- package/dist/admin/expandAndFocus.js +122 -99
- package/dist/admin/expandAndFocus.js.map +1 -1
- package/dist/admin/index.d.ts +1 -0
- package/dist/admin/index.js +1 -0
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/instantPreview/previewGrants.d.ts +14 -0
- package/dist/admin/instantPreview/previewGrants.js +62 -0
- package/dist/admin/instantPreview/previewGrants.js.map +1 -0
- package/dist/admin/instantPreview/usePreviewPage.d.ts +2 -1
- package/dist/admin/instantPreview/usePreviewPage.js +12 -3
- package/dist/admin/instantPreview/usePreviewPage.js.map +1 -1
- package/dist/admin/openField/openForms.d.ts +7 -0
- package/dist/admin/openField/openForms.js +40 -0
- package/dist/admin/openField/openForms.js.map +1 -1
- package/dist/admin/previewPages.d.ts +7 -0
- package/dist/admin/previewPages.js +13 -0
- package/dist/admin/previewPages.js.map +1 -0
- package/dist/client/createOverlay.js +3 -0
- package/dist/client/createOverlay.js.map +1 -1
- package/dist/client/index.d.ts +6 -6
- package/dist/client/index.js +5 -5
- package/dist/client/index.js.map +1 -1
- package/dist/client/instantPreview/instantPreview.js +1 -1
- package/dist/client/instantPreview/instantPreview.js.map +1 -1
- package/dist/client/instantPreview/liveFields.d.ts +2 -1
- package/dist/client/instantPreview/liveFields.js +32 -5
- package/dist/client/instantPreview/liveFields.js.map +1 -1
- package/dist/client/instantPreview/liveRichTextOf.d.ts +3 -0
- package/dist/client/instantPreview/liveRichTextOf.js +3 -0
- package/dist/client/instantPreview/liveRichTextOf.js.map +1 -1
- package/dist/client/instantPreview/unsavedRender/baseValues.d.ts +12 -0
- package/dist/client/instantPreview/unsavedRender/baseValues.js +130 -0
- package/dist/client/instantPreview/unsavedRender/baseValues.js.map +1 -0
- package/dist/client/instantPreview/unsavedRender/liveRichText.d.ts +29 -0
- package/dist/client/instantPreview/unsavedRender/liveRichText.js +117 -0
- package/dist/client/instantPreview/unsavedRender/liveRichText.js.map +1 -0
- package/dist/client/instantPreview/unsavedRender/optimisticValue.d.ts +6 -0
- package/dist/client/instantPreview/unsavedRender/optimisticValue.js +20 -0
- package/dist/client/instantPreview/unsavedRender/optimisticValue.js.map +1 -0
- package/dist/client/instantPreview/unsavedRender/renderSources.d.ts +26 -0
- package/dist/client/instantPreview/unsavedRender/renderSources.js +77 -0
- package/dist/client/instantPreview/unsavedRender/renderSources.js.map +1 -0
- package/dist/client/instantPreview/unsavedRender/unsavedRender.d.ts +6 -1
- package/dist/client/instantPreview/unsavedRender/unsavedRender.js +116 -17
- package/dist/client/instantPreview/unsavedRender/unsavedRender.js.map +1 -1
- package/dist/client/instantPreview/unsavedRender/valueSource.d.ts +17 -0
- package/dist/client/instantPreview/unsavedRender/valueSource.js +38 -0
- package/dist/client/instantPreview/unsavedRender/valueSource.js.map +1 -0
- package/dist/client/overlay/constants.d.ts +1 -2
- package/dist/client/overlay/constants.js +1 -7
- package/dist/client/overlay/constants.js.map +1 -1
- package/dist/client/overlay/fieldTracker.d.ts +2 -0
- package/dist/client/overlay/fieldTracker.js +140 -42
- package/dist/client/overlay/fieldTracker.js.map +1 -1
- package/dist/client/overlay/hoverController.js +3 -3
- package/dist/client/overlay/hoverController.js.map +1 -1
- package/dist/client/overlay/markerCleaner.d.ts +5 -0
- package/dist/client/overlay/markerCleaner.js +94 -0
- package/dist/client/overlay/markerCleaner.js.map +1 -0
- package/dist/client/overlay/markerExtractor.js +1 -1
- package/dist/client/overlay/markerExtractor.js.map +1 -1
- package/dist/client/overlay/mutationPipeline.d.ts +3 -0
- package/dist/client/overlay/mutationPipeline.js +15 -9
- package/dist/client/overlay/mutationPipeline.js.map +1 -1
- package/dist/client/overlay/pageNodes.d.ts +3 -0
- package/dist/client/overlay/pageNodes.js +34 -0
- package/dist/client/overlay/pageNodes.js.map +1 -0
- package/dist/client/overlayClickHandler.js +3 -2
- package/dist/client/overlayClickHandler.js.map +1 -1
- package/dist/client/overlayScope.d.ts +14 -0
- package/dist/client/overlayScope.js +23 -0
- package/dist/client/overlayScope.js.map +1 -0
- package/dist/client/previewGrant.d.ts +5 -0
- package/dist/client/previewGrant.js +34 -0
- package/dist/client/previewGrant.js.map +1 -0
- package/dist/client/react/LiveRichText.d.ts +17 -0
- package/dist/client/react/LiveRichText.js +32 -0
- package/dist/client/react/LiveRichText.js.map +1 -0
- package/dist/client/react/UnsavedRenderBoundary.js.map +1 -0
- package/dist/client/react/VisualEditingOverlay.js +60 -0
- package/dist/client/react/VisualEditingOverlay.js.map +1 -0
- package/dist/client/react/VisualEditingProvider.d.ts +21 -0
- package/dist/client/react/VisualEditingProvider.js +83 -0
- package/dist/client/react/VisualEditingProvider.js.map +1 -0
- package/dist/client/react/VisualEditingToggle.d.ts +1 -0
- package/dist/client/react/VisualEditingToggle.js +32 -0
- package/dist/client/react/VisualEditingToggle.js.map +1 -0
- package/dist/client/react/overlayContext.d.ts +2 -0
- package/dist/client/react/overlayContext.js +4 -0
- package/dist/client/react/overlayContext.js.map +1 -0
- package/dist/client/react/useIsomorphicLayoutEffect.js.map +1 -0
- package/dist/client/react/useUnsavedRender.d.ts +16 -0
- package/dist/client/react/useUnsavedRender.js +89 -0
- package/dist/client/react/useUnsavedRender.js.map +1 -0
- package/dist/client/saveEvents.d.ts +3 -0
- package/dist/client/saveEvents.js +27 -0
- package/dist/client/saveEvents.js.map +1 -0
- package/dist/client/session.d.ts +40 -0
- package/dist/client/session.js +100 -0
- package/dist/client/session.js.map +1 -0
- package/dist/client/sessionOverlay.d.ts +9 -0
- package/dist/client/sessionOverlay.js +74 -0
- package/dist/client/sessionOverlay.js.map +1 -0
- package/dist/client/toggle.d.ts +7 -0
- package/dist/client/toggle.js +158 -0
- package/dist/client/toggle.js.map +1 -0
- package/dist/client/withVisualEditingPath.d.ts +2 -0
- package/dist/client/withVisualEditingPath.js +5 -6
- package/dist/client/withVisualEditingPath.js.map +1 -1
- package/dist/dom/index.d.ts +6 -0
- package/dist/dom/index.js +7 -0
- package/dist/dom/index.js.map +1 -0
- package/dist/dom/liveRichTextElements.d.ts +8 -0
- package/dist/dom/liveRichTextElements.js +69 -0
- package/dist/dom/liveRichTextElements.js.map +1 -0
- package/dist/dom/mountVisualEditing.d.ts +16 -0
- package/dist/dom/mountVisualEditing.js +52 -0
- package/dist/dom/mountVisualEditing.js.map +1 -0
- package/dist/excludeValues.d.ts +0 -4
- package/dist/excludeValues.js +4 -4
- package/dist/excludeValues.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/readUnsavedRichText.d.ts +16 -2
- package/dist/readUnsavedRichText.js +26 -7
- package/dist/readUnsavedRichText.js.map +1 -1
- package/dist/server/endpoints.d.ts +16 -0
- package/dist/server/endpoints.js +136 -0
- package/dist/server/endpoints.js.map +1 -0
- package/dist/server/markRead.js +3 -3
- package/dist/server/markRead.js.map +1 -1
- package/dist/server/markedReads.d.ts +1 -1
- package/dist/server/markedReads.js +4 -2
- package/dist/server/markedReads.js.map +1 -1
- package/dist/server/previewGrant.d.ts +9 -0
- package/dist/server/previewGrant.js +31 -0
- package/dist/server/previewGrant.js.map +1 -0
- package/dist/server/unsavedRichText/hooks.js +24 -9
- package/dist/server/unsavedRichText/hooks.js.map +1 -1
- package/dist/server/unsavedRichText/placeUnsavedState.js +1 -1
- package/dist/server/unsavedRichText/placeUnsavedState.js.map +1 -1
- package/dist/server/unsavedRichText/postedEditorState.js +3 -31
- package/dist/server/unsavedRichText/postedEditorState.js.map +1 -1
- package/dist/server/unsavedRichText/postedRequest.d.ts +2 -1
- package/dist/server/unsavedRichText/postedRequest.js +14 -4
- package/dist/server/unsavedRichText/postedRequest.js.map +1 -1
- package/dist/server/unsavedRichText/readAsUser.d.ts +7 -2
- package/dist/server/unsavedRichText/readAsUser.js +47 -16
- package/dist/server/unsavedRichText/readAsUser.js.map +1 -1
- package/dist/server/unsavedRichText/readContext.d.ts +6 -0
- package/dist/server/unsavedRichText/readContext.js +5 -0
- package/dist/server/unsavedRichText/readContext.js.map +1 -1
- package/dist/server/unsavedRichText/savedReferences.d.ts +5 -0
- package/dist/server/unsavedRichText/savedReferences.js +61 -0
- package/dist/server/unsavedRichText/savedReferences.js.map +1 -0
- package/dist/server/withDocumentControls.d.ts +10 -0
- package/dist/server/{withInstantPreview.js → withDocumentControls.js} +17 -7
- package/dist/server/withDocumentControls.js.map +1 -0
- package/dist/shared/buildAdminEditUrl.d.ts +1 -0
- package/dist/shared/buildAdminEditUrl.js +5 -1
- package/dist/shared/buildAdminEditUrl.js.map +1 -1
- package/dist/shared/protocol.d.ts +18 -0
- package/dist/shared/protocol.js +6 -0
- package/dist/shared/protocol.js.map +1 -1
- package/dist/shared/richText/editorStateTree.d.ts +2 -0
- package/dist/shared/richText/editorStateTree.js +34 -0
- package/dist/shared/richText/editorStateTree.js.map +1 -0
- package/dist/{server → shared}/richText/markTextLeaves.js +5 -5
- package/dist/shared/richText/markTextLeaves.js.map +1 -0
- package/dist/shared/richText/nodeKey.d.ts +3 -2
- package/dist/shared/richText/nodeKey.js +15 -6
- package/dist/shared/richText/nodeKey.js.map +1 -1
- package/dist/shared/richText/references.d.ts +16 -0
- package/dist/shared/richText/references.js +85 -0
- package/dist/shared/richText/references.js.map +1 -0
- package/dist/{server/unsavedRichText → shared/richText}/relatedIds.d.ts +1 -1
- package/dist/{server/unsavedRichText → shared/richText}/relatedIds.js +4 -4
- package/dist/shared/richText/relatedIds.js.map +1 -0
- package/dist/shared/richText/savedNodeFields.d.ts +3 -0
- package/dist/{server/unsavedRichText → shared/richText}/savedNodeFields.js +4 -4
- package/dist/shared/richText/savedNodeFields.js.map +1 -0
- package/dist/shared/shared.d.ts +14 -3
- package/dist/shared/shared.js +46 -1
- package/dist/shared/shared.js.map +1 -1
- package/dist/shared/stegaText.d.ts +2 -1
- package/dist/shared/stegaText.js +3 -1
- package/dist/shared/stegaText.js.map +1 -1
- package/package.json +26 -4
- package/dist/client/VisualEditingOverlay.js +0 -39
- package/dist/client/VisualEditingOverlay.js.map +0 -1
- package/dist/client/VisualEditingProvider.d.ts +0 -25
- package/dist/client/VisualEditingProvider.js +0 -68
- package/dist/client/VisualEditingProvider.js.map +0 -1
- package/dist/client/VisualEditingToggle.d.ts +0 -1
- package/dist/client/VisualEditingToggle.js +0 -153
- package/dist/client/VisualEditingToggle.js.map +0 -1
- package/dist/client/instantPreview/LiveRichText.d.ts +0 -16
- package/dist/client/instantPreview/LiveRichText.js +0 -18
- package/dist/client/instantPreview/LiveRichText.js.map +0 -1
- package/dist/client/instantPreview/unsavedRender/UnsavedRenderBoundary.js.map +0 -1
- package/dist/client/instantPreview/unsavedRender/useUnsavedRender.d.ts +0 -10
- package/dist/client/instantPreview/unsavedRender/useUnsavedRender.js +0 -118
- package/dist/client/instantPreview/unsavedRender/useUnsavedRender.js.map +0 -1
- package/dist/client/overlayContext.d.ts +0 -3
- package/dist/client/overlayContext.js +0 -5
- package/dist/client/overlayContext.js.map +0 -1
- package/dist/client/useIsomorphicLayoutEffect.js.map +0 -1
- package/dist/client/useVisualEditingOverlay.d.ts +0 -4
- package/dist/client/useVisualEditingOverlay.js +0 -33
- package/dist/client/useVisualEditingOverlay.js.map +0 -1
- package/dist/server/richText/markTextLeaves.js.map +0 -1
- package/dist/server/unsavedRichText/relatedIds.js.map +0 -1
- package/dist/server/unsavedRichText/savedNodeFields.d.ts +0 -2
- package/dist/server/unsavedRichText/savedNodeFields.js.map +0 -1
- package/dist/server/withInstantPreview.d.ts +0 -9
- package/dist/server/withInstantPreview.js.map +0 -1
- /package/dist/client/{instantPreview/unsavedRender → react}/UnsavedRenderBoundary.d.ts +0 -0
- /package/dist/client/{instantPreview/unsavedRender → react}/UnsavedRenderBoundary.js +0 -0
- /package/dist/client/{VisualEditingOverlay.d.ts → react/VisualEditingOverlay.d.ts} +0 -0
- /package/dist/client/{useIsomorphicLayoutEffect.d.ts → react/useIsomorphicLayoutEffect.d.ts} +0 -0
- /package/dist/client/{useIsomorphicLayoutEffect.js → react/useIsomorphicLayoutEffect.js} +0 -0
- /package/dist/{server → shared}/richText/markTextLeaves.d.ts +0 -0
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
4
|
-
import { createPortal } from "react-dom";
|
|
5
|
-
import { VISUAL_EDITING_MODES } from "./visualEditingMode.js";
|
|
6
|
-
import { useVisualEditing } from "./VisualEditingProvider.js";
|
|
7
|
-
const STYLE_ID = "ve-toggle-styles";
|
|
8
|
-
const SCOPED_STYLES = `
|
|
9
|
-
[data-ve-toggle-root] {
|
|
10
|
-
transition: opacity 140ms ease, transform 140ms ease;
|
|
11
|
-
}
|
|
12
|
-
body[data-ve-hovering='true'] [data-ve-toggle-root] {
|
|
13
|
-
opacity: 0;
|
|
14
|
-
transform: translateY(8px);
|
|
15
|
-
pointer-events: none;
|
|
16
|
-
}
|
|
17
|
-
[data-ve-toggle-btn][data-ve-active="false"]:hover {
|
|
18
|
-
background: rgba(255, 255, 255, 0.06);
|
|
19
|
-
color: rgba(255, 255, 255, 0.92);
|
|
20
|
-
}
|
|
21
|
-
[data-ve-toggle-btn]:focus-visible {
|
|
22
|
-
outline: 2px solid #34d399;
|
|
23
|
-
outline-offset: 2px;
|
|
24
|
-
}
|
|
25
|
-
`;
|
|
26
|
-
const MODE_LABELS = {
|
|
27
|
-
off: "Off",
|
|
28
|
-
always: "Always",
|
|
29
|
-
hover: "Hover"
|
|
30
|
-
};
|
|
31
|
-
const MODE_DESCRIPTIONS = {
|
|
32
|
-
off: "Disable visual editing",
|
|
33
|
-
always: "Always show edit outlines",
|
|
34
|
-
hover: "Show edit outline on hover only"
|
|
35
|
-
};
|
|
36
|
-
const CONTAINER_STYLE = {
|
|
37
|
-
position: "fixed",
|
|
38
|
-
right: "20px",
|
|
39
|
-
bottom: "20px",
|
|
40
|
-
zIndex: 2147483646,
|
|
41
|
-
display: "inline-flex",
|
|
42
|
-
alignItems: "center",
|
|
43
|
-
gap: "2px",
|
|
44
|
-
padding: "4px",
|
|
45
|
-
background: "rgba(18, 18, 18, 0.92)",
|
|
46
|
-
backdropFilter: "blur(12px) saturate(140%)",
|
|
47
|
-
WebkitBackdropFilter: "blur(12px) saturate(140%)",
|
|
48
|
-
border: "1px solid rgba(255, 255, 255, 0.08)",
|
|
49
|
-
borderRadius: "10px",
|
|
50
|
-
boxShadow: "0 12px 32px -8px rgba(0, 0, 0, 0.4), 0 4px 12px -2px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.05)",
|
|
51
|
-
fontFamily: 'system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
|
|
52
|
-
pointerEvents: "auto"
|
|
53
|
-
};
|
|
54
|
-
const BRAND_STYLE = {
|
|
55
|
-
display: "inline-flex",
|
|
56
|
-
alignItems: "center",
|
|
57
|
-
justifyContent: "center",
|
|
58
|
-
width: "26px",
|
|
59
|
-
height: "26px",
|
|
60
|
-
color: "rgba(52, 211, 153, 0.85)",
|
|
61
|
-
pointerEvents: "none"
|
|
62
|
-
};
|
|
63
|
-
const BUTTON_BASE = {
|
|
64
|
-
appearance: "none",
|
|
65
|
-
border: 0,
|
|
66
|
-
margin: 0,
|
|
67
|
-
padding: "6px 11px",
|
|
68
|
-
fontSize: "11px",
|
|
69
|
-
fontFamily: "inherit",
|
|
70
|
-
fontWeight: 600,
|
|
71
|
-
letterSpacing: "0.06em",
|
|
72
|
-
textTransform: "uppercase",
|
|
73
|
-
borderRadius: "6px",
|
|
74
|
-
cursor: "pointer",
|
|
75
|
-
background: "transparent",
|
|
76
|
-
color: "rgba(255, 255, 255, 0.55)",
|
|
77
|
-
transition: "background-color 160ms ease, color 160ms ease",
|
|
78
|
-
lineHeight: 1,
|
|
79
|
-
WebkitTapHighlightColor: "transparent"
|
|
80
|
-
};
|
|
81
|
-
const ACTIVE_BUTTON = {
|
|
82
|
-
background: "#34d399",
|
|
83
|
-
color: "#022c22",
|
|
84
|
-
boxShadow: "0 1px 2px rgba(0, 0, 0, 0.24)"
|
|
85
|
-
};
|
|
86
|
-
function ensureStylesInjected() {
|
|
87
|
-
// oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors
|
|
88
|
-
if (document.getElementById(STYLE_ID)) return;
|
|
89
|
-
const style = document.createElement("style");
|
|
90
|
-
style.id = STYLE_ID;
|
|
91
|
-
style.textContent = SCOPED_STYLES;
|
|
92
|
-
document.head.append(style);
|
|
93
|
-
}
|
|
94
|
-
export function VisualEditingToggle() {
|
|
95
|
-
const { available, mode, setMode } = useVisualEditing();
|
|
96
|
-
const [mounted, setMounted] = useState(false);
|
|
97
|
-
useEffect(()=>{
|
|
98
|
-
setMounted(true);
|
|
99
|
-
ensureStylesInjected();
|
|
100
|
-
}, []);
|
|
101
|
-
if (!mounted || !available) return null;
|
|
102
|
-
const control = /*#__PURE__*/ _jsxs("div", {
|
|
103
|
-
role: "radiogroup",
|
|
104
|
-
"aria-label": "Visual editing mode",
|
|
105
|
-
"data-ve-toggle-root": "",
|
|
106
|
-
style: CONTAINER_STYLE,
|
|
107
|
-
children: [
|
|
108
|
-
/*#__PURE__*/ _jsx("span", {
|
|
109
|
-
"aria-hidden": "true",
|
|
110
|
-
style: BRAND_STYLE,
|
|
111
|
-
children: /*#__PURE__*/ _jsxs("svg", {
|
|
112
|
-
width: "14",
|
|
113
|
-
height: "14",
|
|
114
|
-
viewBox: "0 0 16 16",
|
|
115
|
-
fill: "none",
|
|
116
|
-
stroke: "currentColor",
|
|
117
|
-
strokeWidth: "1.6",
|
|
118
|
-
strokeLinecap: "round",
|
|
119
|
-
strokeLinejoin: "round",
|
|
120
|
-
children: [
|
|
121
|
-
/*#__PURE__*/ _jsx("path", {
|
|
122
|
-
d: "M11.2 2.2l2.6 2.6-8.5 8.5L1.5 14l.7-3.8z"
|
|
123
|
-
}),
|
|
124
|
-
/*#__PURE__*/ _jsx("path", {
|
|
125
|
-
d: "M10 3.4l2.6 2.6"
|
|
126
|
-
})
|
|
127
|
-
]
|
|
128
|
-
})
|
|
129
|
-
}),
|
|
130
|
-
VISUAL_EDITING_MODES.map((m)=>{
|
|
131
|
-
const active = m === mode;
|
|
132
|
-
return /*#__PURE__*/ _jsx("button", {
|
|
133
|
-
type: "button",
|
|
134
|
-
role: "radio",
|
|
135
|
-
"aria-checked": active,
|
|
136
|
-
"aria-label": MODE_DESCRIPTIONS[m],
|
|
137
|
-
title: MODE_DESCRIPTIONS[m],
|
|
138
|
-
"data-ve-toggle-btn": "",
|
|
139
|
-
"data-ve-active": String(active),
|
|
140
|
-
onClick: ()=>setMode(m),
|
|
141
|
-
style: active ? {
|
|
142
|
-
...BUTTON_BASE,
|
|
143
|
-
...ACTIVE_BUTTON
|
|
144
|
-
} : BUTTON_BASE,
|
|
145
|
-
children: MODE_LABELS[m]
|
|
146
|
-
}, m);
|
|
147
|
-
})
|
|
148
|
-
]
|
|
149
|
-
});
|
|
150
|
-
return /*#__PURE__*/ createPortal(control, document.body);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
//# sourceMappingURL=VisualEditingToggle.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/client/VisualEditingToggle.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\n\nimport type { VisualEditingMode } from \"./visualEditingMode.js\";\n\nimport { VISUAL_EDITING_MODES } from \"./visualEditingMode.js\";\nimport { useVisualEditing } from \"./VisualEditingProvider.js\";\n\nconst STYLE_ID = \"ve-toggle-styles\";\n\nconst SCOPED_STYLES = `\n[data-ve-toggle-root] {\n\ttransition: opacity 140ms ease, transform 140ms ease;\n}\nbody[data-ve-hovering='true'] [data-ve-toggle-root] {\n\topacity: 0;\n\ttransform: translateY(8px);\n\tpointer-events: none;\n}\n[data-ve-toggle-btn][data-ve-active=\"false\"]:hover {\n\tbackground: rgba(255, 255, 255, 0.06);\n\tcolor: rgba(255, 255, 255, 0.92);\n}\n[data-ve-toggle-btn]:focus-visible {\n\toutline: 2px solid #34d399;\n\toutline-offset: 2px;\n}\n`;\n\nconst MODE_LABELS: Record<VisualEditingMode, string> = {\n off: \"Off\",\n always: \"Always\",\n hover: \"Hover\",\n};\n\nconst MODE_DESCRIPTIONS: Record<VisualEditingMode, string> = {\n off: \"Disable visual editing\",\n always: \"Always show edit outlines\",\n hover: \"Show edit outline on hover only\",\n};\n\nconst CONTAINER_STYLE: React.CSSProperties = {\n position: \"fixed\",\n right: \"20px\",\n bottom: \"20px\",\n zIndex: 2147483646,\n display: \"inline-flex\",\n alignItems: \"center\",\n gap: \"2px\",\n padding: \"4px\",\n background: \"rgba(18, 18, 18, 0.92)\",\n backdropFilter: \"blur(12px) saturate(140%)\",\n WebkitBackdropFilter: \"blur(12px) saturate(140%)\",\n border: \"1px solid rgba(255, 255, 255, 0.08)\",\n borderRadius: \"10px\",\n boxShadow:\n \"0 12px 32px -8px rgba(0, 0, 0, 0.4), 0 4px 12px -2px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.05)\",\n fontFamily: 'system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif',\n pointerEvents: \"auto\",\n};\n\nconst BRAND_STYLE: React.CSSProperties = {\n display: \"inline-flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n width: \"26px\",\n height: \"26px\",\n color: \"rgba(52, 211, 153, 0.85)\",\n pointerEvents: \"none\",\n};\n\nconst BUTTON_BASE: React.CSSProperties = {\n appearance: \"none\",\n border: 0,\n margin: 0,\n padding: \"6px 11px\",\n fontSize: \"11px\",\n fontFamily: \"inherit\",\n fontWeight: 600,\n letterSpacing: \"0.06em\",\n textTransform: \"uppercase\",\n borderRadius: \"6px\",\n cursor: \"pointer\",\n background: \"transparent\",\n color: \"rgba(255, 255, 255, 0.55)\",\n transition: \"background-color 160ms ease, color 160ms ease\",\n lineHeight: 1,\n WebkitTapHighlightColor: \"transparent\",\n};\n\nconst ACTIVE_BUTTON: React.CSSProperties = {\n background: \"#34d399\",\n color: \"#022c22\",\n boxShadow: \"0 1px 2px rgba(0, 0, 0, 0.24)\",\n};\n\nfunction ensureStylesInjected(): void {\n // oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors\n if (document.getElementById(STYLE_ID)) return;\n const style = document.createElement(\"style\");\n style.id = STYLE_ID;\n style.textContent = SCOPED_STYLES;\n document.head.append(style);\n}\n\nexport function VisualEditingToggle(): React.ReactElement | null {\n const { available, mode, setMode } = useVisualEditing();\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => {\n setMounted(true);\n ensureStylesInjected();\n }, []);\n\n if (!mounted || !available) return null;\n\n const control = (\n <div\n role=\"radiogroup\"\n aria-label=\"Visual editing mode\"\n data-ve-toggle-root=\"\"\n style={CONTAINER_STYLE}\n >\n <span aria-hidden=\"true\" style={BRAND_STYLE}>\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.6\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M11.2 2.2l2.6 2.6-8.5 8.5L1.5 14l.7-3.8z\" />\n <path d=\"M10 3.4l2.6 2.6\" />\n </svg>\n </span>\n {VISUAL_EDITING_MODES.map((m) => {\n const active = m === mode;\n return (\n <button\n key={m}\n type=\"button\"\n role=\"radio\"\n aria-checked={active}\n aria-label={MODE_DESCRIPTIONS[m]}\n title={MODE_DESCRIPTIONS[m]}\n data-ve-toggle-btn=\"\"\n data-ve-active={String(active)}\n onClick={() => setMode(m)}\n style={active ? { ...BUTTON_BASE, ...ACTIVE_BUTTON } : BUTTON_BASE}\n >\n {MODE_LABELS[m]}\n </button>\n );\n })}\n </div>\n );\n\n return createPortal(control, document.body);\n}\n"],"names":["useEffect","useState","createPortal","VISUAL_EDITING_MODES","useVisualEditing","STYLE_ID","SCOPED_STYLES","MODE_LABELS","off","always","hover","MODE_DESCRIPTIONS","CONTAINER_STYLE","position","right","bottom","zIndex","display","alignItems","gap","padding","background","backdropFilter","WebkitBackdropFilter","border","borderRadius","boxShadow","fontFamily","pointerEvents","BRAND_STYLE","justifyContent","width","height","color","BUTTON_BASE","appearance","margin","fontSize","fontWeight","letterSpacing","textTransform","cursor","transition","lineHeight","WebkitTapHighlightColor","ACTIVE_BUTTON","ensureStylesInjected","document","getElementById","style","createElement","id","textContent","head","append","VisualEditingToggle","available","mode","setMode","mounted","setMounted","control","div","role","aria-label","data-ve-toggle-root","span","aria-hidden","svg","viewBox","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","path","d","map","m","active","button","type","aria-checked","title","data-ve-toggle-btn","data-ve-active","String","onClick","body"],"mappings":"AAAA;;AAEA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAC5C,SAASC,YAAY,QAAQ,YAAY;AAIzC,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,gBAAgB,QAAQ,6BAA6B;AAE9D,MAAMC,WAAW;AAEjB,MAAMC,gBAAgB,CAAC;;;;;;;;;;;;;;;;;AAiBvB,CAAC;AAED,MAAMC,cAAiD;IACrDC,KAAK;IACLC,QAAQ;IACRC,OAAO;AACT;AAEA,MAAMC,oBAAuD;IAC3DH,KAAK;IACLC,QAAQ;IACRC,OAAO;AACT;AAEA,MAAME,kBAAuC;IAC3CC,UAAU;IACVC,OAAO;IACPC,QAAQ;IACRC,QAAQ;IACRC,SAAS;IACTC,YAAY;IACZC,KAAK;IACLC,SAAS;IACTC,YAAY;IACZC,gBAAgB;IAChBC,sBAAsB;IACtBC,QAAQ;IACRC,cAAc;IACdC,WACE;IACFC,YAAY;IACZC,eAAe;AACjB;AAEA,MAAMC,cAAmC;IACvCZ,SAAS;IACTC,YAAY;IACZY,gBAAgB;IAChBC,OAAO;IACPC,QAAQ;IACRC,OAAO;IACPL,eAAe;AACjB;AAEA,MAAMM,cAAmC;IACvCC,YAAY;IACZX,QAAQ;IACRY,QAAQ;IACRhB,SAAS;IACTiB,UAAU;IACVV,YAAY;IACZW,YAAY;IACZC,eAAe;IACfC,eAAe;IACff,cAAc;IACdgB,QAAQ;IACRpB,YAAY;IACZY,OAAO;IACPS,YAAY;IACZC,YAAY;IACZC,yBAAyB;AAC3B;AAEA,MAAMC,gBAAqC;IACzCxB,YAAY;IACZY,OAAO;IACPP,WAAW;AACb;AAEA,SAASoB;IACP,6GAA6G;IAC7G,IAAIC,SAASC,cAAc,CAAC3C,WAAW;IACvC,MAAM4C,QAAQF,SAASG,aAAa,CAAC;IACrCD,MAAME,EAAE,GAAG9C;IACX4C,MAAMG,WAAW,GAAG9C;IACpByC,SAASM,IAAI,CAACC,MAAM,CAACL;AACvB;AAEA,OAAO,SAASM;IACd,MAAM,EAAEC,SAAS,EAAEC,IAAI,EAAEC,OAAO,EAAE,GAAGtD;IACrC,MAAM,CAACuD,SAASC,WAAW,GAAG3D,SAAS;IAEvCD,UAAU;QACR4D,WAAW;QACXd;IACF,GAAG,EAAE;IAEL,IAAI,CAACa,WAAW,CAACH,WAAW,OAAO;IAEnC,MAAMK,wBACJ,MAACC;QACCC,MAAK;QACLC,cAAW;QACXC,uBAAoB;QACpBhB,OAAOrC;;0BAEP,KAACsD;gBAAKC,eAAY;gBAAOlB,OAAOpB;0BAC9B,cAAA,MAACuC;oBACCrC,OAAM;oBACNC,QAAO;oBACPqC,SAAQ;oBACRC,MAAK;oBACLC,QAAO;oBACPC,aAAY;oBACZC,eAAc;oBACdC,gBAAe;;sCAEf,KAACC;4BAAKC,GAAE;;sCACR,KAACD;4BAAKC,GAAE;;;;;YAGXzE,qBAAqB0E,GAAG,CAAC,CAACC;gBACzB,MAAMC,SAASD,MAAMrB;gBACrB,qBACE,KAACuB;oBAECC,MAAK;oBACLlB,MAAK;oBACLmB,gBAAcH;oBACdf,cAAYrD,iBAAiB,CAACmE,EAAE;oBAChCK,OAAOxE,iBAAiB,CAACmE,EAAE;oBAC3BM,sBAAmB;oBACnBC,kBAAgBC,OAAOP;oBACvBQ,SAAS,IAAM7B,QAAQoB;oBACvB7B,OAAO8B,SAAS;wBAAE,GAAG7C,WAAW;wBAAE,GAAGW,aAAa;oBAAC,IAAIX;8BAEtD3B,WAAW,CAACuE,EAAE;mBAXVA;YAcX;;;IAIJ,qBAAO5E,aAAa2D,SAASd,SAASyC,IAAI;AAC5C"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from "react";
|
|
2
|
-
import type { LiveRichTextIdentity } from "./liveRichTextOf.js";
|
|
3
|
-
import type { LiveRichTextAction, LiveRichTextRender } from "./unsavedRender/useUnsavedRender.js";
|
|
4
|
-
type RenderedByAction = {
|
|
5
|
-
action: LiveRichTextAction;
|
|
6
|
-
render?: never;
|
|
7
|
-
};
|
|
8
|
-
type RenderedByCall = {
|
|
9
|
-
action?: never;
|
|
10
|
-
render: LiveRichTextRender;
|
|
11
|
-
};
|
|
12
|
-
export type LiveRichTextProps = LiveRichTextIdentity & (RenderedByAction | RenderedByCall) & {
|
|
13
|
-
children: ReactNode;
|
|
14
|
-
};
|
|
15
|
-
export declare function LiveRichText({ action, children, field, render, shape, }: LiveRichTextProps): ReactNode;
|
|
16
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { UnsavedRenderBoundary } from "./unsavedRender/UnsavedRenderBoundary.js";
|
|
4
|
-
import { useUnsavedRender } from "./unsavedRender/useUnsavedRender.js";
|
|
5
|
-
export function LiveRichText({ action, children, field, render, shape }) {
|
|
6
|
-
const renderUnsaved = render ?? ((request)=>action(request));
|
|
7
|
-
const { dropUnsavedRender, shown } = useUnsavedRender(field, {
|
|
8
|
-
node: children,
|
|
9
|
-
shape
|
|
10
|
-
}, renderUnsaved);
|
|
11
|
-
return /*#__PURE__*/ _jsx(UnsavedRenderBoundary, {
|
|
12
|
-
fallback: children,
|
|
13
|
-
onError: dropUnsavedRender,
|
|
14
|
-
children: shown
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
//# sourceMappingURL=LiveRichText.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/instantPreview/LiveRichText.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ReactNode } from \"react\";\n\nimport type { LiveRichTextIdentity } from \"./liveRichTextOf.js\";\nimport type { LiveRichTextAction, LiveRichTextRender } from \"./unsavedRender/useUnsavedRender.js\";\n\nimport { UnsavedRenderBoundary } from \"./unsavedRender/UnsavedRenderBoundary.js\";\nimport { useUnsavedRender } from \"./unsavedRender/useUnsavedRender.js\";\n\ntype RenderedByAction = { action: LiveRichTextAction; render?: never };\n\ntype RenderedByCall = { action?: never; render: LiveRichTextRender };\n\nexport type LiveRichTextProps = LiveRichTextIdentity &\n (RenderedByAction | RenderedByCall) & { children: ReactNode };\n\nexport function LiveRichText({\n action,\n children,\n field,\n render,\n shape,\n}: LiveRichTextProps): ReactNode {\n const renderUnsaved: LiveRichTextRender = render ?? ((request) => action(request));\n const { dropUnsavedRender, shown } = useUnsavedRender(\n field,\n { node: children, shape },\n renderUnsaved\n );\n\n return (\n <UnsavedRenderBoundary fallback={children} onError={dropUnsavedRender}>\n {shown}\n </UnsavedRenderBoundary>\n );\n}\n"],"names":["UnsavedRenderBoundary","useUnsavedRender","LiveRichText","action","children","field","render","shape","renderUnsaved","request","dropUnsavedRender","shown","node","fallback","onError"],"mappings":"AAAA;;AAOA,SAASA,qBAAqB,QAAQ,2CAA2C;AACjF,SAASC,gBAAgB,QAAQ,sCAAsC;AASvE,OAAO,SAASC,aAAa,EAC3BC,MAAM,EACNC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,KAAK,EACa;IAClB,MAAMC,gBAAoCF,UAAW,CAAA,CAACG,UAAYN,OAAOM,QAAO;IAChF,MAAM,EAAEC,iBAAiB,EAAEC,KAAK,EAAE,GAAGV,iBACnCI,OACA;QAAEO,MAAMR;QAAUG;IAAM,GACxBC;IAGF,qBACE,KAACR;QAAsBa,UAAUT;QAAUU,SAASJ;kBACjDC;;AAGP"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/client/instantPreview/unsavedRender/UnsavedRenderBoundary.tsx"],"sourcesContent":["\"use client\";\n\nimport type { ReactNode } from \"react\";\n\nimport { Component } from \"react\";\n\ntype Props = {\n children: ReactNode;\n fallback: ReactNode;\n onError: () => void;\n};\n\ntype State = { children: ReactNode; hasFailed: boolean };\n\nexport class UnsavedRenderBoundary extends Component<Props, State> {\n override state: State = { children: null, hasFailed: false };\n\n static getDerivedStateFromProps({ children }: Props, state: State): Partial<State> | null {\n return children === state.children ? null : { children, hasFailed: false };\n }\n\n static getDerivedStateFromError(): Partial<State> {\n return { hasFailed: true };\n }\n\n override componentDidCatch(): void {\n this.props.onError();\n }\n\n override render(): ReactNode {\n const { children, fallback } = this.props;\n return this.state.hasFailed ? fallback : children;\n }\n}\n"],"names":["Component","UnsavedRenderBoundary","state","children","hasFailed","getDerivedStateFromProps","getDerivedStateFromError","componentDidCatch","props","onError","render","fallback"],"mappings":"AAAA;AAIA,SAASA,SAAS,QAAQ,QAAQ;AAUlC,OAAO,MAAMC,8BAA8BD;IAChCE,QAAe;QAAEC,UAAU;QAAMC,WAAW;IAAM,EAAE;IAE7D,OAAOC,yBAAyB,EAAEF,QAAQ,EAAS,EAAED,KAAY,EAAyB;QACxF,OAAOC,aAAaD,MAAMC,QAAQ,GAAG,OAAO;YAAEA;YAAUC,WAAW;QAAM;IAC3E;IAEA,OAAOE,2BAA2C;QAChD,OAAO;YAAEF,WAAW;QAAK;IAC3B;IAESG,oBAA0B;QACjC,IAAI,CAACC,KAAK,CAACC,OAAO;IACpB;IAESC,SAAoB;QAC3B,MAAM,EAAEP,QAAQ,EAAEQ,QAAQ,EAAE,GAAG,IAAI,CAACH,KAAK;QACzC,OAAO,IAAI,CAACN,KAAK,CAACE,SAAS,GAAGO,WAAWR;IAC3C;AACF"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from "react";
|
|
2
|
-
import type { LiveRichTextField, LiveRichTextRequest } from "../../../shared/protocol.js";
|
|
3
|
-
import type { RenderOfShape } from "./unsavedRender.js";
|
|
4
|
-
export type LiveRichTextRender = (request: LiveRichTextRequest, signal: AbortSignal) => Promise<ReactNode>;
|
|
5
|
-
export type LiveRichTextAction = (request: LiveRichTextRequest) => Promise<ReactNode>;
|
|
6
|
-
export type UnsavedRenderOfField = {
|
|
7
|
-
dropUnsavedRender: () => void;
|
|
8
|
-
shown: ReactNode;
|
|
9
|
-
};
|
|
10
|
-
export declare function useUnsavedRender(field: LiveRichTextField, saved: RenderOfShape<ReactNode>, render: LiveRichTextRender): UnsavedRenderOfField;
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { startTransition, useContext, useEffect, useRef, useState } from "react";
|
|
2
|
-
import { keyedFieldAddressOf, veDocumentOf } from "../../../shared/veDocument.js";
|
|
3
|
-
import { listenToAdmin } from "../adminChannel.js";
|
|
4
|
-
import { adminOriginOf } from "../../adminWindow.js";
|
|
5
|
-
import { readRichTextStructure } from "../liveMessages.js";
|
|
6
|
-
import { OverlayLocaleContext, SavedRichTextShapesContext } from "../../overlayContext.js";
|
|
7
|
-
import { useIsomorphicLayoutEffect } from "../../useIsomorphicLayoutEffect.js";
|
|
8
|
-
import { useVisualEditing } from "../../VisualEditingProvider.js";
|
|
9
|
-
import { announceLiveRichText } from "./announcer.js";
|
|
10
|
-
import { createUnsavedRender, heldSavedOf, inPlaceOfSaved, NOTHING_TOLD } from "./unsavedRender.js";
|
|
11
|
-
export function useUnsavedRender(field, saved, render) {
|
|
12
|
-
const { adminOrigin, available, instantPreview } = useVisualEditing();
|
|
13
|
-
const pageLocale = useContext(OverlayLocaleContext);
|
|
14
|
-
const savedShapes = useContext(SavedRichTextShapesContext);
|
|
15
|
-
const fieldAddress = keyedFieldAddressOf(field);
|
|
16
|
-
const renderKey = JSON.stringify([
|
|
17
|
-
fieldAddress,
|
|
18
|
-
pageLocale ?? null
|
|
19
|
-
]);
|
|
20
|
-
const savedShape = saved.shape;
|
|
21
|
-
const isLive = available && instantPreview;
|
|
22
|
-
const [shown, setShown] = useState({
|
|
23
|
-
renderKey,
|
|
24
|
-
state: NOTHING_TOLD
|
|
25
|
-
});
|
|
26
|
-
const [heldSaved, setHeldSaved] = useState(saved);
|
|
27
|
-
const unsavedRender = useRef(null);
|
|
28
|
-
const shownOfThisField = shown.renderKey === renderKey ? shown.state : NOTHING_TOLD;
|
|
29
|
-
const latest = useRef({
|
|
30
|
-
adminOrigin,
|
|
31
|
-
field,
|
|
32
|
-
pageLocale,
|
|
33
|
-
render,
|
|
34
|
-
savedShape,
|
|
35
|
-
shownOfThisField
|
|
36
|
-
});
|
|
37
|
-
useIsomorphicLayoutEffect(()=>{
|
|
38
|
-
latest.current = {
|
|
39
|
-
adminOrigin,
|
|
40
|
-
field,
|
|
41
|
-
pageLocale,
|
|
42
|
-
render,
|
|
43
|
-
savedShape,
|
|
44
|
-
shownOfThisField
|
|
45
|
-
};
|
|
46
|
-
unsavedRender.current?.committed(shownOfThisField, savedShape);
|
|
47
|
-
});
|
|
48
|
-
useIsomorphicLayoutEffect(()=>{
|
|
49
|
-
if (isLive) return savedShapes?.name(fieldAddress, savedShape);
|
|
50
|
-
}, [
|
|
51
|
-
fieldAddress,
|
|
52
|
-
isLive,
|
|
53
|
-
savedShape,
|
|
54
|
-
savedShapes
|
|
55
|
-
]);
|
|
56
|
-
useEffect(()=>{
|
|
57
|
-
if (!isLive) return;
|
|
58
|
-
const fieldRender = createUnsavedRender({
|
|
59
|
-
onChange: (change, isRender)=>{
|
|
60
|
-
const show = ()=>setShown((current)=>({
|
|
61
|
-
renderKey,
|
|
62
|
-
state: {
|
|
63
|
-
...current.renderKey === renderKey ? current.state : NOTHING_TOLD,
|
|
64
|
-
...change
|
|
65
|
-
}
|
|
66
|
-
}));
|
|
67
|
-
if (isRender) startTransition(show);
|
|
68
|
-
else show();
|
|
69
|
-
},
|
|
70
|
-
render: ({ locale, state }, signal)=>latest.current.render({
|
|
71
|
-
field: latest.current.field,
|
|
72
|
-
locale,
|
|
73
|
-
state
|
|
74
|
-
}, signal),
|
|
75
|
-
savedShape: latest.current.savedShape,
|
|
76
|
-
shown: latest.current.shownOfThisField
|
|
77
|
-
});
|
|
78
|
-
unsavedRender.current = fieldRender;
|
|
79
|
-
const adminPage = ()=>({
|
|
80
|
-
adminOrigin: adminOriginOf(latest.current.adminOrigin),
|
|
81
|
-
locale: latest.current.pageLocale
|
|
82
|
-
});
|
|
83
|
-
const stopListening = listenToAdmin({
|
|
84
|
-
adminPage,
|
|
85
|
-
announce: ()=>{
|
|
86
|
-
const announced = latest.current.field;
|
|
87
|
-
announceLiveRichText({
|
|
88
|
-
document: veDocumentOf(announced),
|
|
89
|
-
key: announced.key
|
|
90
|
-
}, adminPage());
|
|
91
|
-
},
|
|
92
|
-
onMessage: fieldRender.tell,
|
|
93
|
-
read: (data)=>{
|
|
94
|
-
const structure = readRichTextStructure(data);
|
|
95
|
-
const isOfThisField = structure && keyedFieldAddressOf(structure) === fieldAddress;
|
|
96
|
-
return isOfThisField ? structure : null;
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
return ()=>{
|
|
100
|
-
unsavedRender.current = null;
|
|
101
|
-
fieldRender.stop();
|
|
102
|
-
stopListening();
|
|
103
|
-
};
|
|
104
|
-
}, [
|
|
105
|
-
fieldAddress,
|
|
106
|
-
isLive,
|
|
107
|
-
renderKey
|
|
108
|
-
]);
|
|
109
|
-
const shownState = isLive ? shownOfThisField : NOTHING_TOLD;
|
|
110
|
-
const held = heldSavedOf(heldSaved, saved, shownState.editorShape);
|
|
111
|
-
if (held !== heldSaved) setHeldSaved(held);
|
|
112
|
-
return {
|
|
113
|
-
dropUnsavedRender: ()=>unsavedRender.current?.dropUnsaved(),
|
|
114
|
-
shown: inPlaceOfSaved(shownState, saved, held)
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
//# sourceMappingURL=useUnsavedRender.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/client/instantPreview/unsavedRender/useUnsavedRender.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\n\nimport { startTransition, useContext, useEffect, useRef, useState } from \"react\";\n\nimport type { LiveRichTextField, LiveRichTextRequest } from \"../../../shared/protocol.js\";\nimport type { RenderOfShape, UnsavedRender, UnsavedRenderState } from \"./unsavedRender.js\";\n\nimport { keyedFieldAddressOf, veDocumentOf } from \"../../../shared/veDocument.js\";\nimport { listenToAdmin } from \"../adminChannel.js\";\nimport { adminOriginOf } from \"../../adminWindow.js\";\nimport { readRichTextStructure } from \"../liveMessages.js\";\nimport { OverlayLocaleContext, SavedRichTextShapesContext } from \"../../overlayContext.js\";\nimport { useIsomorphicLayoutEffect } from \"../../useIsomorphicLayoutEffect.js\";\nimport { useVisualEditing } from \"../../VisualEditingProvider.js\";\nimport { announceLiveRichText } from \"./announcer.js\";\nimport { createUnsavedRender, heldSavedOf, inPlaceOfSaved, NOTHING_TOLD } from \"./unsavedRender.js\";\n\nexport type LiveRichTextRender = (\n request: LiveRichTextRequest,\n signal: AbortSignal\n) => Promise<ReactNode>;\n\nexport type LiveRichTextAction = (request: LiveRichTextRequest) => Promise<ReactNode>;\n\nexport type UnsavedRenderOfField = {\n dropUnsavedRender: () => void;\n shown: ReactNode;\n};\n\ntype Shown = { renderKey: string; state: UnsavedRenderState<ReactNode> };\n\nexport function useUnsavedRender(\n field: LiveRichTextField,\n saved: RenderOfShape<ReactNode>,\n render: LiveRichTextRender\n): UnsavedRenderOfField {\n const { adminOrigin, available, instantPreview } = useVisualEditing();\n const pageLocale = useContext(OverlayLocaleContext);\n const savedShapes = useContext(SavedRichTextShapesContext);\n const fieldAddress = keyedFieldAddressOf(field);\n const renderKey = JSON.stringify([fieldAddress, pageLocale ?? null]);\n const savedShape = saved.shape;\n const isLive = available && instantPreview;\n const [shown, setShown] = useState<Shown>({ renderKey, state: NOTHING_TOLD });\n const [heldSaved, setHeldSaved] = useState(saved);\n const unsavedRender = useRef<UnsavedRender<ReactNode> | null>(null);\n const shownOfThisField = shown.renderKey === renderKey ? shown.state : NOTHING_TOLD;\n const latest = useRef({ adminOrigin, field, pageLocale, render, savedShape, shownOfThisField });\n\n useIsomorphicLayoutEffect(() => {\n latest.current = { adminOrigin, field, pageLocale, render, savedShape, shownOfThisField };\n unsavedRender.current?.committed(shownOfThisField, savedShape);\n });\n\n useIsomorphicLayoutEffect(() => {\n if (isLive) return savedShapes?.name(fieldAddress, savedShape);\n }, [fieldAddress, isLive, savedShape, savedShapes]);\n\n useEffect(() => {\n if (!isLive) return;\n const fieldRender = createUnsavedRender<ReactNode>({\n onChange: (change, isRender) => {\n const show = () =>\n setShown((current) => ({\n renderKey,\n state: {\n ...(current.renderKey === renderKey ? current.state : NOTHING_TOLD),\n ...change,\n },\n }));\n if (isRender) startTransition(show);\n else show();\n },\n render: ({ locale, state }, signal) =>\n latest.current.render({ field: latest.current.field, locale, state }, signal),\n savedShape: latest.current.savedShape,\n shown: latest.current.shownOfThisField,\n });\n unsavedRender.current = fieldRender;\n\n const adminPage = () => ({\n adminOrigin: adminOriginOf(latest.current.adminOrigin),\n locale: latest.current.pageLocale,\n });\n\n const stopListening = listenToAdmin({\n adminPage,\n announce: () => {\n const announced = latest.current.field;\n announceLiveRichText(\n { document: veDocumentOf(announced), key: announced.key },\n adminPage()\n );\n },\n onMessage: fieldRender.tell,\n read: (data: unknown) => {\n const structure = readRichTextStructure(data);\n const isOfThisField = structure && keyedFieldAddressOf(structure) === fieldAddress;\n return isOfThisField ? structure : null;\n },\n });\n\n return () => {\n unsavedRender.current = null;\n fieldRender.stop();\n stopListening();\n };\n }, [fieldAddress, isLive, renderKey]);\n\n const shownState = isLive ? shownOfThisField : NOTHING_TOLD;\n const held = heldSavedOf(heldSaved, saved, shownState.editorShape);\n if (held !== heldSaved) setHeldSaved(held);\n\n return {\n dropUnsavedRender: () => unsavedRender.current?.dropUnsaved(),\n shown: inPlaceOfSaved(shownState, saved, held),\n };\n}\n"],"names":["startTransition","useContext","useEffect","useRef","useState","keyedFieldAddressOf","veDocumentOf","listenToAdmin","adminOriginOf","readRichTextStructure","OverlayLocaleContext","SavedRichTextShapesContext","useIsomorphicLayoutEffect","useVisualEditing","announceLiveRichText","createUnsavedRender","heldSavedOf","inPlaceOfSaved","NOTHING_TOLD","useUnsavedRender","field","saved","render","adminOrigin","available","instantPreview","pageLocale","savedShapes","fieldAddress","renderKey","JSON","stringify","savedShape","shape","isLive","shown","setShown","state","heldSaved","setHeldSaved","unsavedRender","shownOfThisField","latest","current","committed","name","fieldRender","onChange","change","isRender","show","locale","signal","adminPage","stopListening","announce","announced","document","key","onMessage","tell","read","data","structure","isOfThisField","stop","shownState","held","editorShape","dropUnsavedRender","dropUnsaved"],"mappings":"AAEA,SAASA,eAAe,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAKjF,SAASC,mBAAmB,EAAEC,YAAY,QAAQ,gCAAgC;AAClF,SAASC,aAAa,QAAQ,qBAAqB;AACnD,SAASC,aAAa,QAAQ,uBAAuB;AACrD,SAASC,qBAAqB,QAAQ,qBAAqB;AAC3D,SAASC,oBAAoB,EAAEC,0BAA0B,QAAQ,0BAA0B;AAC3F,SAASC,yBAAyB,QAAQ,qCAAqC;AAC/E,SAASC,gBAAgB,QAAQ,iCAAiC;AAClE,SAASC,oBAAoB,QAAQ,iBAAiB;AACtD,SAASC,mBAAmB,EAAEC,WAAW,EAAEC,cAAc,EAAEC,YAAY,QAAQ,qBAAqB;AAgBpG,OAAO,SAASC,iBACdC,KAAwB,EACxBC,KAA+B,EAC/BC,MAA0B;IAE1B,MAAM,EAAEC,WAAW,EAAEC,SAAS,EAAEC,cAAc,EAAE,GAAGZ;IACnD,MAAMa,aAAazB,WAAWS;IAC9B,MAAMiB,cAAc1B,WAAWU;IAC/B,MAAMiB,eAAevB,oBAAoBe;IACzC,MAAMS,YAAYC,KAAKC,SAAS,CAAC;QAACH;QAAcF,cAAc;KAAK;IACnE,MAAMM,aAAaX,MAAMY,KAAK;IAC9B,MAAMC,SAASV,aAAaC;IAC5B,MAAM,CAACU,OAAOC,SAAS,GAAGhC,SAAgB;QAAEyB;QAAWQ,OAAOnB;IAAa;IAC3E,MAAM,CAACoB,WAAWC,aAAa,GAAGnC,SAASiB;IAC3C,MAAMmB,gBAAgBrC,OAAwC;IAC9D,MAAMsC,mBAAmBN,MAAMN,SAAS,KAAKA,YAAYM,MAAME,KAAK,GAAGnB;IACvE,MAAMwB,SAASvC,OAAO;QAAEoB;QAAaH;QAAOM;QAAYJ;QAAQU;QAAYS;IAAiB;IAE7F7B,0BAA0B;QACxB8B,OAAOC,OAAO,GAAG;YAAEpB;YAAaH;YAAOM;YAAYJ;YAAQU;YAAYS;QAAiB;QACxFD,cAAcG,OAAO,EAAEC,UAAUH,kBAAkBT;IACrD;IAEApB,0BAA0B;QACxB,IAAIsB,QAAQ,OAAOP,aAAakB,KAAKjB,cAAcI;IACrD,GAAG;QAACJ;QAAcM;QAAQF;QAAYL;KAAY;IAElDzB,UAAU;QACR,IAAI,CAACgC,QAAQ;QACb,MAAMY,cAAc/B,oBAA+B;YACjDgC,UAAU,CAACC,QAAQC;gBACjB,MAAMC,OAAO,IACXd,SAAS,CAACO,UAAa,CAAA;4BACrBd;4BACAQ,OAAO;gCACL,GAAIM,QAAQd,SAAS,KAAKA,YAAYc,QAAQN,KAAK,GAAGnB,YAAY;gCAClE,GAAG8B,MAAM;4BACX;wBACF,CAAA;gBACF,IAAIC,UAAUjD,gBAAgBkD;qBACzBA;YACP;YACA5B,QAAQ,CAAC,EAAE6B,MAAM,EAAEd,KAAK,EAAE,EAAEe,SAC1BV,OAAOC,OAAO,CAACrB,MAAM,CAAC;oBAAEF,OAAOsB,OAAOC,OAAO,CAACvB,KAAK;oBAAE+B;oBAAQd;gBAAM,GAAGe;YACxEpB,YAAYU,OAAOC,OAAO,CAACX,UAAU;YACrCG,OAAOO,OAAOC,OAAO,CAACF,gBAAgB;QACxC;QACAD,cAAcG,OAAO,GAAGG;QAExB,MAAMO,YAAY,IAAO,CAAA;gBACvB9B,aAAaf,cAAckC,OAAOC,OAAO,CAACpB,WAAW;gBACrD4B,QAAQT,OAAOC,OAAO,CAACjB,UAAU;YACnC,CAAA;QAEA,MAAM4B,gBAAgB/C,cAAc;YAClC8C;YACAE,UAAU;gBACR,MAAMC,YAAYd,OAAOC,OAAO,CAACvB,KAAK;gBACtCN,qBACE;oBAAE2C,UAAUnD,aAAakD;oBAAYE,KAAKF,UAAUE,GAAG;gBAAC,GACxDL;YAEJ;YACAM,WAAWb,YAAYc,IAAI;YAC3BC,MAAM,CAACC;gBACL,MAAMC,YAAYtD,sBAAsBqD;gBACxC,MAAME,gBAAgBD,aAAa1D,oBAAoB0D,eAAenC;gBACtE,OAAOoC,gBAAgBD,YAAY;YACrC;QACF;QAEA,OAAO;YACLvB,cAAcG,OAAO,GAAG;YACxBG,YAAYmB,IAAI;YAChBX;QACF;IACF,GAAG;QAAC1B;QAAcM;QAAQL;KAAU;IAEpC,MAAMqC,aAAahC,SAASO,mBAAmBvB;IAC/C,MAAMiD,OAAOnD,YAAYsB,WAAWjB,OAAO6C,WAAWE,WAAW;IACjE,IAAID,SAAS7B,WAAWC,aAAa4B;IAErC,OAAO;QACLE,mBAAmB,IAAM7B,cAAcG,OAAO,EAAE2B;QAChDnC,OAAOlB,eAAeiD,YAAY7C,OAAO8C;IAC3C;AACF"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { SavedRichTextShapes } from "./instantPreview/unsavedRender/savedShapes.js";
|
|
2
|
-
export declare const OverlayLocaleContext: import("react").Context<string | undefined>;
|
|
3
|
-
export declare const SavedRichTextShapesContext: import("react").Context<SavedRichTextShapes | null>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/client/overlayContext.ts"],"sourcesContent":["import { createContext } from \"react\";\n\nimport type { SavedRichTextShapes } from \"./instantPreview/unsavedRender/savedShapes.js\";\n\nexport const OverlayLocaleContext = createContext<string | undefined>(undefined);\n\nexport const SavedRichTextShapesContext = createContext<SavedRichTextShapes | null>(null);\n"],"names":["createContext","OverlayLocaleContext","undefined","SavedRichTextShapesContext"],"mappings":"AAAA,SAASA,aAAa,QAAQ,QAAQ;AAItC,OAAO,MAAMC,uBAAuBD,cAAkCE,WAAW;AAEjF,OAAO,MAAMC,6BAA6BH,cAA0C,MAAM"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/client/useIsomorphicLayoutEffect.ts"],"sourcesContent":["import { useEffect, useLayoutEffect } from \"react\";\n\nexport const useIsomorphicLayoutEffect =\n typeof window === \"undefined\" ? useEffect : useLayoutEffect;\n"],"names":["useEffect","useLayoutEffect","useIsomorphicLayoutEffect","window"],"mappings":"AAAA,SAASA,SAAS,EAAEC,eAAe,QAAQ,QAAQ;AAEnD,OAAO,MAAMC,4BACX,OAAOC,WAAW,cAAcH,YAAYC,gBAAgB"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useEffect, useRef } from "react";
|
|
3
|
-
import { createOverlay } from "./createOverlay.js";
|
|
4
|
-
import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.js";
|
|
5
|
-
export function useVisualEditingOverlay(active, rootRef, ctx) {
|
|
6
|
-
const ctxRef = useRef(ctx);
|
|
7
|
-
const overlayRef = useRef(null);
|
|
8
|
-
useIsomorphicLayoutEffect(()=>{
|
|
9
|
-
ctxRef.current = ctx;
|
|
10
|
-
});
|
|
11
|
-
useEffect(()=>{
|
|
12
|
-
if (!active) return;
|
|
13
|
-
const root = rootRef.current;
|
|
14
|
-
if (!root) return;
|
|
15
|
-
const overlay = createOverlay(root, ()=>ctxRef.current);
|
|
16
|
-
overlayRef.current = overlay;
|
|
17
|
-
return ()=>{
|
|
18
|
-
overlayRef.current = null;
|
|
19
|
-
overlay.dispose();
|
|
20
|
-
};
|
|
21
|
-
}, [
|
|
22
|
-
active,
|
|
23
|
-
ctx.instantPreview,
|
|
24
|
-
rootRef
|
|
25
|
-
]);
|
|
26
|
-
useEffect(()=>{
|
|
27
|
-
overlayRef.current?.applyMode();
|
|
28
|
-
}, [
|
|
29
|
-
ctx.mode
|
|
30
|
-
]);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
//# sourceMappingURL=useVisualEditingOverlay.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/client/useVisualEditingOverlay.ts"],"sourcesContent":["\"use client\";\n\nimport type { RefObject } from \"react\";\n\nimport type { Overlay, OverlayCtx } from \"./createOverlay.js\";\n\nimport { useEffect, useRef } from \"react\";\n\nimport { createOverlay } from \"./createOverlay.js\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect.js\";\n\nexport type { OverlayCtx };\n\nexport function useVisualEditingOverlay(\n active: boolean,\n rootRef: RefObject<HTMLElement | null>,\n ctx: OverlayCtx\n): void {\n const ctxRef = useRef(ctx);\n const overlayRef = useRef<Overlay | null>(null);\n\n useIsomorphicLayoutEffect(() => {\n ctxRef.current = ctx;\n });\n\n useEffect(() => {\n if (!active) return;\n const root = rootRef.current;\n if (!root) return;\n const overlay = createOverlay(root, () => ctxRef.current);\n overlayRef.current = overlay;\n return () => {\n overlayRef.current = null;\n overlay.dispose();\n };\n }, [active, ctx.instantPreview, rootRef]);\n\n useEffect(() => {\n overlayRef.current?.applyMode();\n }, [ctx.mode]);\n}\n"],"names":["useEffect","useRef","createOverlay","useIsomorphicLayoutEffect","useVisualEditingOverlay","active","rootRef","ctx","ctxRef","overlayRef","current","root","overlay","dispose","instantPreview","applyMode","mode"],"mappings":"AAAA;AAMA,SAASA,SAAS,EAAEC,MAAM,QAAQ,QAAQ;AAE1C,SAASC,aAAa,QAAQ,qBAAqB;AACnD,SAASC,yBAAyB,QAAQ,iCAAiC;AAI3E,OAAO,SAASC,wBACdC,MAAe,EACfC,OAAsC,EACtCC,GAAe;IAEf,MAAMC,SAASP,OAAOM;IACtB,MAAME,aAAaR,OAAuB;IAE1CE,0BAA0B;QACxBK,OAAOE,OAAO,GAAGH;IACnB;IAEAP,UAAU;QACR,IAAI,CAACK,QAAQ;QACb,MAAMM,OAAOL,QAAQI,OAAO;QAC5B,IAAI,CAACC,MAAM;QACX,MAAMC,UAAUV,cAAcS,MAAM,IAAMH,OAAOE,OAAO;QACxDD,WAAWC,OAAO,GAAGE;QACrB,OAAO;YACLH,WAAWC,OAAO,GAAG;YACrBE,QAAQC,OAAO;QACjB;IACF,GAAG;QAACR;QAAQE,IAAIO,cAAc;QAAER;KAAQ;IAExCN,UAAU;QACRS,WAAWC,OAAO,EAAEK;IACtB,GAAG;QAACR,IAAIS,IAAI;KAAC;AACf"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/richText/markTextLeaves.ts"],"sourcesContent":["import { withMarker } from \"../../shared/stegaText.js\";\nimport { toRichTextNodeMarker } from \"../../shared/richText/nodeKey.js\";\nimport { shapeOf } from \"../../shared/richText/shapeOf.js\";\nimport { addressOf, forEachTextLeaf } from \"../../shared/richText/textLeaves.js\";\nimport { rootOf } from \"../../shared/richText/editorNodes.js\";\n\nexport const markTextLeaves = (editorState: unknown, fieldAddress: string): void => {\n const root = rootOf(editorState);\n const shape = shapeOf(editorState, fieldAddress);\n if (!root || shape === null) return;\n forEachTextLeaf(root, (leaf, indexes) => {\n if (leaf.text === \"\") return;\n leaf.text = withMarker(leaf.text, toRichTextNodeMarker(addressOf(indexes), shape));\n });\n};\n"],"names":["withMarker","toRichTextNodeMarker","shapeOf","addressOf","forEachTextLeaf","rootOf","markTextLeaves","editorState","fieldAddress","root","shape","leaf","indexes","text"],"mappings":"AAAA,SAASA,UAAU,QAAQ,4BAA4B;AACvD,SAASC,oBAAoB,QAAQ,mCAAmC;AACxE,SAASC,OAAO,QAAQ,mCAAmC;AAC3D,SAASC,SAAS,EAAEC,eAAe,QAAQ,sCAAsC;AACjF,SAASC,MAAM,QAAQ,uCAAuC;AAE9D,OAAO,MAAMC,iBAAiB,CAACC,aAAsBC;IACnD,MAAMC,OAAOJ,OAAOE;IACpB,MAAMG,QAAQR,QAAQK,aAAaC;IACnC,IAAI,CAACC,QAAQC,UAAU,MAAM;IAC7BN,gBAAgBK,MAAM,CAACE,MAAMC;QAC3B,IAAID,KAAKE,IAAI,KAAK,IAAI;QACtBF,KAAKE,IAAI,GAAGb,WAAWW,KAAKE,IAAI,EAAEZ,qBAAqBE,UAAUS,UAAUF;IAC7E;AACF,EAAE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/unsavedRichText/relatedIds.ts"],"sourcesContent":["import type { VeEditorState } from \"../../shared/protocol.js\";\nimport type { EditorNode } from \"../../shared/richText/editorNodes.js\";\n\nimport { LINK_NODE_TYPES, RELATED_VALUE_NODE_TYPES } from \"../../shared/richText/nodeTypes.js\";\nimport { mapEditorNodes } from \"../../shared/richText/editorNodes.js\";\nimport type { PlainObject } from \"../../shared/plainObject.js\";\n\nimport { idOf } from \"../../shared/veDocument.js\";\nimport { isPlainObject } from \"../../shared/plainObject.js\";\n\nconst withValueAsId = (holder: PlainObject): PlainObject =>\n isPlainObject(holder.value) ? { ...holder, value: idOf(holder.value.id) } : holder;\n\nconst withLinkedDocumentAsId = (node: EditorNode): EditorNode => {\n const { fields } = node;\n if (!isPlainObject(fields) || !isPlainObject(fields.doc)) return node;\n return { ...node, fields: { ...fields, doc: withValueAsId(fields.doc) } };\n};\n\nconst withRelatedAsIds = (node: EditorNode): EditorNode => {\n if (RELATED_VALUE_NODE_TYPES.has(node.type)) return withValueAsId(node);\n if (LINK_NODE_TYPES.has(node.type)) return withLinkedDocumentAsId(node);\n return node;\n};\n\nexport const withRelatedDocumentsAsIds = (state: VeEditorState): VeEditorState =>\n isPlainObject(state.root)\n ? { ...state, root: mapEditorNodes(state.root, withRelatedAsIds) }\n : state;\n"],"names":["LINK_NODE_TYPES","RELATED_VALUE_NODE_TYPES","mapEditorNodes","idOf","isPlainObject","withValueAsId","holder","value","id","withLinkedDocumentAsId","node","fields","doc","withRelatedAsIds","has","type","withRelatedDocumentsAsIds","state","root"],"mappings":"AAGA,SAASA,eAAe,EAAEC,wBAAwB,QAAQ,qCAAqC;AAC/F,SAASC,cAAc,QAAQ,uCAAuC;AAGtE,SAASC,IAAI,QAAQ,6BAA6B;AAClD,SAASC,aAAa,QAAQ,8BAA8B;AAE5D,MAAMC,gBAAgB,CAACC,SACrBF,cAAcE,OAAOC,KAAK,IAAI;QAAE,GAAGD,MAAM;QAAEC,OAAOJ,KAAKG,OAAOC,KAAK,CAACC,EAAE;IAAE,IAAIF;AAE9E,MAAMG,yBAAyB,CAACC;IAC9B,MAAM,EAAEC,MAAM,EAAE,GAAGD;IACnB,IAAI,CAACN,cAAcO,WAAW,CAACP,cAAcO,OAAOC,GAAG,GAAG,OAAOF;IACjE,OAAO;QAAE,GAAGA,IAAI;QAAEC,QAAQ;YAAE,GAAGA,MAAM;YAAEC,KAAKP,cAAcM,OAAOC,GAAG;QAAE;IAAE;AAC1E;AAEA,MAAMC,mBAAmB,CAACH;IACxB,IAAIT,yBAAyBa,GAAG,CAACJ,KAAKK,IAAI,GAAG,OAAOV,cAAcK;IAClE,IAAIV,gBAAgBc,GAAG,CAACJ,KAAKK,IAAI,GAAG,OAAON,uBAAuBC;IAClE,OAAOA;AACT;AAEA,OAAO,MAAMM,4BAA4B,CAACC,QACxCb,cAAca,MAAMC,IAAI,IACpB;QAAE,GAAGD,KAAK;QAAEC,MAAMhB,eAAee,MAAMC,IAAI,EAAEL;IAAkB,IAC/DI,MAAM"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/unsavedRichText/savedNodeFields.ts"],"sourcesContent":["import type { VeEditorState } from \"../../shared/protocol.js\";\nimport type { EditorNode } from \"../../shared/richText/editorNodes.js\";\nimport type { PlainObject } from \"../../shared/plainObject.js\";\n\nimport { LINK_NODE_TYPES, UPLOAD_NODE_TYPE } from \"../../shared/richText/nodeTypes.js\";\nimport { forEachEditorNode, mapEditorNodes, rootOf } from \"../../shared/richText/editorNodes.js\";\nimport { isPlainObject } from \"../../shared/plainObject.js\";\n\nconst TARGET_FIELDS_OF_A_LINK = [\"doc\", \"linkType\", \"newTab\", \"url\"];\n\ntype SavedFields = Map<string, PlainObject>;\n\nconst savedKeyOf = ({ id, type }: EditorNode): string | null =>\n typeof id === \"string\" && typeof type === \"string\" ? JSON.stringify([type, id]) : null;\n\nconst targetOf = (fields: unknown): PlainObject =>\n isPlainObject(fields)\n ? Object.fromEntries(\n TARGET_FIELDS_OF_A_LINK.filter((name) => Object.hasOwn(fields, name)).map((name) => [\n name,\n fields[name],\n ])\n )\n : {};\n\nconst fieldsOf = (node: EditorNode, saved: SavedFields): PlainObject | null | undefined => {\n const key = savedKeyOf(node);\n const savedFields = key === null ? undefined : saved.get(key);\n if (node.type === UPLOAD_NODE_TYPE) return savedFields ?? null;\n if (LINK_NODE_TYPES.has(node.type)) return { ...savedFields, ...targetOf(node.fields) };\n return undefined;\n};\n\nconst withSavedFields = (node: EditorNode, saved: SavedFields): EditorNode => {\n const fields = fieldsOf(node, saved);\n return fields === undefined ? node : { ...node, fields };\n};\n\nexport const withSavedNodeFieldsOf = (state: VeEditorState, stored: unknown): VeEditorState => {\n const saved: SavedFields = new Map();\n forEachEditorNode(rootOf(stored), (node) => {\n const key = savedKeyOf(node);\n if (key !== null && isPlainObject(node.fields)) saved.set(key, node.fields);\n });\n return { ...state, root: mapEditorNodes(state.root, (node) => withSavedFields(node, saved)) };\n};\n"],"names":["LINK_NODE_TYPES","UPLOAD_NODE_TYPE","forEachEditorNode","mapEditorNodes","rootOf","isPlainObject","TARGET_FIELDS_OF_A_LINK","savedKeyOf","id","type","JSON","stringify","targetOf","fields","Object","fromEntries","filter","name","hasOwn","map","fieldsOf","node","saved","key","savedFields","undefined","get","has","withSavedFields","withSavedNodeFieldsOf","state","stored","Map","set","root"],"mappings":"AAIA,SAASA,eAAe,EAAEC,gBAAgB,QAAQ,qCAAqC;AACvF,SAASC,iBAAiB,EAAEC,cAAc,EAAEC,MAAM,QAAQ,uCAAuC;AACjG,SAASC,aAAa,QAAQ,8BAA8B;AAE5D,MAAMC,0BAA0B;IAAC;IAAO;IAAY;IAAU;CAAM;AAIpE,MAAMC,aAAa,CAAC,EAAEC,EAAE,EAAEC,IAAI,EAAc,GAC1C,OAAOD,OAAO,YAAY,OAAOC,SAAS,WAAWC,KAAKC,SAAS,CAAC;QAACF;QAAMD;KAAG,IAAI;AAEpF,MAAMI,WAAW,CAACC,SAChBR,cAAcQ,UACVC,OAAOC,WAAW,CAChBT,wBAAwBU,MAAM,CAAC,CAACC,OAASH,OAAOI,MAAM,CAACL,QAAQI,OAAOE,GAAG,CAAC,CAACF,OAAS;YAClFA;YACAJ,MAAM,CAACI,KAAK;SACb,KAEH,CAAC;AAEP,MAAMG,WAAW,CAACC,MAAkBC;IAClC,MAAMC,MAAMhB,WAAWc;IACvB,MAAMG,cAAcD,QAAQ,OAAOE,YAAYH,MAAMI,GAAG,CAACH;IACzD,IAAIF,KAAKZ,IAAI,KAAKR,kBAAkB,OAAOuB,eAAe;IAC1D,IAAIxB,gBAAgB2B,GAAG,CAACN,KAAKZ,IAAI,GAAG,OAAO;QAAE,GAAGe,WAAW;QAAE,GAAGZ,SAASS,KAAKR,MAAM,CAAC;IAAC;IACtF,OAAOY;AACT;AAEA,MAAMG,kBAAkB,CAACP,MAAkBC;IACzC,MAAMT,SAASO,SAASC,MAAMC;IAC9B,OAAOT,WAAWY,YAAYJ,OAAO;QAAE,GAAGA,IAAI;QAAER;IAAO;AACzD;AAEA,OAAO,MAAMgB,wBAAwB,CAACC,OAAsBC;IAC1D,MAAMT,QAAqB,IAAIU;IAC/B9B,kBAAkBE,OAAO2B,SAAS,CAACV;QACjC,MAAME,MAAMhB,WAAWc;QACvB,IAAIE,QAAQ,QAAQlB,cAAcgB,KAAKR,MAAM,GAAGS,MAAMW,GAAG,CAACV,KAAKF,KAAKR,MAAM;IAC5E;IACA,OAAO;QAAE,GAAGiB,KAAK;QAAEI,MAAM/B,eAAe2B,MAAMI,IAAI,EAAE,CAACb,OAASO,gBAAgBP,MAAMC;IAAQ;AAC9F,EAAE"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig, Config, GlobalConfig } from "payload";
|
|
2
|
-
type RootLivePreview = NonNullable<Config["admin"]>["livePreview"];
|
|
3
|
-
export type InstantPreviewOptions = {
|
|
4
|
-
rootLivePreview: RootLivePreview;
|
|
5
|
-
excludeFieldNames: string[];
|
|
6
|
-
};
|
|
7
|
-
export declare const withInstantPreviewCollection: (collection: CollectionConfig, options: InstantPreviewOptions) => CollectionConfig;
|
|
8
|
-
export declare const withInstantPreviewGlobal: (global: GlobalConfig, options: InstantPreviewOptions) => GlobalConfig;
|
|
9
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/server/withInstantPreview.ts"],"sourcesContent":["import type { CollectionConfig, Config, CustomComponent, GlobalConfig } from \"payload\";\n\nimport { PACKAGE_NAME } from \"../shared/packageName.js\";\n\nconst INSTANT_PREVIEW_COMPONENT_PATH = `${PACKAGE_NAME}/admin#InstantPreviewBroadcaster`;\nconst OPEN_FORM_ANNOUNCER_PATH = `${PACKAGE_NAME}/admin#OpenFormAnnouncer`;\n\ntype RootLivePreview = NonNullable<Config[\"admin\"]>[\"livePreview\"];\n\nexport type InstantPreviewOptions = {\n rootLivePreview: RootLivePreview;\n excludeFieldNames: string[];\n};\n\ntype SlotName = \"edit\" | \"elements\";\n\ntype ControlsSlot = { beforeDocumentControls?: CustomComponent[] };\n\ntype PreviewableEntity = {\n admin?: { components?: Partial<Record<SlotName, ControlsSlot>>; livePreview?: unknown };\n slug: string;\n};\n\nconst hasLivePreview = (\n { admin, slug }: PreviewableEntity,\n slugsPreviewedByRoot: readonly string[] | undefined\n): boolean => Boolean(admin?.livePreview) || Boolean(slugsPreviewedByRoot?.includes(slug));\n\nconst instantPreviewControlsOf = (\n entity: PreviewableEntity,\n slugsPreviewedByRoot: readonly string[] | undefined,\n { excludeFieldNames }: InstantPreviewOptions\n): CustomComponent[] => [\n { path: OPEN_FORM_ANNOUNCER_PATH },\n ...(hasLivePreview(entity, slugsPreviewedByRoot)\n ? [{ clientProps: { excludeFieldNames }, path: INSTANT_PREVIEW_COMPONENT_PATH }]\n : []),\n];\n\nconst withInstantPreviewIn = <Entity extends PreviewableEntity>(\n entity: Entity,\n slotName: SlotName,\n slugsPreviewedByRoot: readonly string[] | undefined,\n options: InstantPreviewOptions\n): Entity => {\n const components = entity.admin?.components;\n const slot = components?.[slotName];\n return {\n ...entity,\n admin: {\n ...entity.admin,\n components: {\n ...components,\n [slotName]: {\n ...slot,\n beforeDocumentControls: [\n ...(slot?.beforeDocumentControls ?? []),\n ...instantPreviewControlsOf(entity, slugsPreviewedByRoot, options),\n ],\n },\n },\n },\n };\n};\n\nexport const withInstantPreviewCollection = (\n collection: CollectionConfig,\n options: InstantPreviewOptions\n): CollectionConfig =>\n withInstantPreviewIn(collection, \"edit\", options.rootLivePreview?.collections, options);\n\nexport const withInstantPreviewGlobal = (\n global: GlobalConfig,\n options: InstantPreviewOptions\n): GlobalConfig =>\n withInstantPreviewIn(global, \"elements\", options.rootLivePreview?.globals, options);\n"],"names":["PACKAGE_NAME","INSTANT_PREVIEW_COMPONENT_PATH","OPEN_FORM_ANNOUNCER_PATH","hasLivePreview","admin","slug","slugsPreviewedByRoot","Boolean","livePreview","includes","instantPreviewControlsOf","entity","excludeFieldNames","path","clientProps","withInstantPreviewIn","slotName","options","components","slot","beforeDocumentControls","withInstantPreviewCollection","collection","rootLivePreview","collections","withInstantPreviewGlobal","global","globals"],"mappings":"AAEA,SAASA,YAAY,QAAQ,2BAA2B;AAExD,MAAMC,iCAAiC,CAAC,EAAED,aAAa,gCAAgC,CAAC;AACxF,MAAME,2BAA2B,CAAC,EAAEF,aAAa,wBAAwB,CAAC;AAkB1E,MAAMG,iBAAiB,CACrB,EAAEC,KAAK,EAAEC,IAAI,EAAqB,EAClCC,uBACYC,QAAQH,OAAOI,gBAAgBD,QAAQD,sBAAsBG,SAASJ;AAEpF,MAAMK,2BAA2B,CAC/BC,QACAL,sBACA,EAAEM,iBAAiB,EAAyB,GACtB;QACtB;YAAEC,MAAMX;QAAyB;WAC7BC,eAAeQ,QAAQL,wBACvB;YAAC;gBAAEQ,aAAa;oBAAEF;gBAAkB;gBAAGC,MAAMZ;YAA+B;SAAE,GAC9E,EAAE;KACP;AAED,MAAMc,uBAAuB,CAC3BJ,QACAK,UACAV,sBACAW;IAEA,MAAMC,aAAaP,OAAOP,KAAK,EAAEc;IACjC,MAAMC,OAAOD,YAAY,CAACF,SAAS;IACnC,OAAO;QACL,GAAGL,MAAM;QACTP,OAAO;YACL,GAAGO,OAAOP,KAAK;YACfc,YAAY;gBACV,GAAGA,UAAU;gBACb,CAACF,SAAS,EAAE;oBACV,GAAGG,IAAI;oBACPC,wBAAwB;2BAClBD,MAAMC,0BAA0B,EAAE;2BACnCV,yBAAyBC,QAAQL,sBAAsBW;qBAC3D;gBACH;YACF;QACF;IACF;AACF;AAEA,OAAO,MAAMI,+BAA+B,CAC1CC,YACAL,UAEAF,qBAAqBO,YAAY,QAAQL,QAAQM,eAAe,EAAEC,aAAaP,SAAS;AAE1F,OAAO,MAAMQ,2BAA2B,CACtCC,QACAT,UAEAF,qBAAqBW,QAAQ,YAAYT,QAAQM,eAAe,EAAEI,SAASV,SAAS"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/client/{useIsomorphicLayoutEffect.d.ts → react/useIsomorphicLayoutEffect.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|