@payload-onpage/react 0.2.1 → 0.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/dist/OnPageClient.d.ts.map +1 -1
- package/dist/OnPageClient.js +9 -5
- package/dist/OnPageClient.js.map +1 -1
- package/dist/annotations.d.ts +1 -1
- package/dist/annotations.d.ts.map +1 -1
- package/dist/context.d.ts +19 -5
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +31 -7
- package/dist/context.js.map +1 -1
- package/dist/dom.d.ts +16 -12
- package/dist/dom.d.ts.map +1 -1
- package/dist/dom.js +16 -16
- package/dist/dom.js.map +1 -1
- package/dist/editor/FieldHost.d.ts.map +1 -1
- package/dist/editor/FieldHost.js +18 -11
- package/dist/editor/FieldHost.js.map +1 -1
- package/dist/editor/OnPageEditor.d.ts +15 -8
- package/dist/editor/OnPageEditor.d.ts.map +1 -1
- package/dist/editor/OnPageEditor.js +73 -103
- package/dist/editor/OnPageEditor.js.map +1 -1
- package/dist/editor/editTarget.d.ts +28 -0
- package/dist/editor/editTarget.d.ts.map +1 -0
- package/dist/editor/editTarget.js +20 -0
- package/dist/editor/editTarget.js.map +1 -0
- package/dist/editor/useClientDocs.d.ts +4 -0
- package/dist/editor/useClientDocs.d.ts.map +1 -0
- package/dist/editor/useClientDocs.js +16 -0
- package/dist/editor/useClientDocs.js.map +1 -0
- package/dist/editor/useEditorSession.d.ts +13 -0
- package/dist/editor/useEditorSession.d.ts.map +1 -0
- package/dist/editor/useEditorSession.js +30 -0
- package/dist/editor/useEditorSession.js.map +1 -0
- package/dist/editor/useFlash.d.ts +4 -0
- package/dist/editor/useFlash.d.ts.map +1 -0
- package/dist/editor/useFlash.js +16 -0
- package/dist/editor/useFlash.js.map +1 -0
- package/dist/editor/useGhosts.d.ts +5 -7
- package/dist/editor/useGhosts.d.ts.map +1 -1
- package/dist/editor/useGhosts.js.map +1 -1
- package/dist/editor/usePageEvents.d.ts.map +1 -1
- package/dist/editor/usePageEvents.js +16 -16
- package/dist/editor/usePageEvents.js.map +1 -1
- package/dist/editor-kit.d.ts +10 -6
- package/dist/editor-kit.d.ts.map +1 -1
- package/dist/editor-kit.js +8 -5
- package/dist/editor-kit.js.map +1 -1
- package/dist/editors/CheckboxEditor.d.ts +6 -1
- package/dist/editors/CheckboxEditor.d.ts.map +1 -1
- package/dist/editors/CheckboxEditor.js +6 -3
- package/dist/editors/CheckboxEditor.js.map +1 -1
- package/dist/editors/ColorEditor.d.ts +3 -1
- package/dist/editors/ColorEditor.d.ts.map +1 -1
- package/dist/editors/ColorEditor.js +9 -15
- package/dist/editors/ColorEditor.js.map +1 -1
- package/dist/editors/DateEditor.d.ts +3 -1
- package/dist/editors/DateEditor.d.ts.map +1 -1
- package/dist/editors/DateEditor.js +10 -12
- package/dist/editors/DateEditor.js.map +1 -1
- package/dist/editors/InlineText.d.ts +2 -2
- package/dist/editors/InlineText.d.ts.map +1 -1
- package/dist/editors/InlineText.js +2 -3
- package/dist/editors/InlineText.js.map +1 -1
- package/dist/editors/NumberEditor.d.ts +3 -1
- package/dist/editors/NumberEditor.d.ts.map +1 -1
- package/dist/editors/NumberEditor.js +9 -17
- package/dist/editors/NumberEditor.js.map +1 -1
- package/dist/editors/RelationshipEditor.d.ts +7 -1
- package/dist/editors/RelationshipEditor.d.ts.map +1 -1
- package/dist/editors/RelationshipEditor.js +10 -18
- package/dist/editors/RelationshipEditor.js.map +1 -1
- package/dist/editors/SelectEditor.d.ts +4 -1
- package/dist/editors/SelectEditor.d.ts.map +1 -1
- package/dist/editors/SelectEditor.js +8 -13
- package/dist/editors/SelectEditor.js.map +1 -1
- package/dist/editors/UploadEditor.d.ts +7 -1
- package/dist/editors/UploadEditor.d.ts.map +1 -1
- package/dist/editors/UploadEditor.js +5 -5
- package/dist/editors/UploadEditor.js.map +1 -1
- package/dist/editors/index.d.ts +0 -1
- package/dist/editors/index.d.ts.map +1 -1
- package/dist/editors/index.js +56 -16
- package/dist/editors/index.js.map +1 -1
- package/dist/editors/kit.d.ts +39 -0
- package/dist/editors/kit.d.ts.map +1 -0
- package/dist/editors/kit.js +44 -0
- package/dist/editors/kit.js.map +1 -0
- package/dist/editors/useDebouncedSearch.d.ts +10 -6
- package/dist/editors/useDebouncedSearch.d.ts.map +1 -1
- package/dist/editors/useDebouncedSearch.js +11 -7
- package/dist/editors/useDebouncedSearch.js.map +1 -1
- package/dist/geometry.d.ts +49 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +48 -0
- package/dist/geometry.js.map +1 -0
- package/dist/hub.d.ts +4 -4
- package/dist/hub.d.ts.map +1 -1
- package/dist/hub.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +4 -2
- package/dist/layout.js.map +1 -1
- package/dist/locators.d.ts +0 -2
- package/dist/locators.d.ts.map +1 -1
- package/dist/locators.js +10 -16
- package/dist/locators.js.map +1 -1
- package/dist/messages.d.ts +15 -2
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +5 -0
- package/dist/messages.js.map +1 -1
- package/dist/registry.d.ts +21 -2
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +31 -6
- package/dist/registry.js.map +1 -1
- package/dist/rowOps.d.ts +20 -0
- package/dist/rowOps.d.ts.map +1 -0
- package/dist/rowOps.js +48 -0
- package/dist/rowOps.js.map +1 -0
- package/dist/sanitize.d.ts +2 -0
- package/dist/sanitize.d.ts.map +1 -1
- package/dist/sanitize.js +3 -0
- package/dist/sanitize.js.map +1 -1
- package/dist/settings.d.ts +10 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +30 -0
- package/dist/settings.js.map +1 -0
- package/dist/styles.d.ts +0 -4
- package/dist/styles.d.ts.map +1 -1
- package/dist/styles.js +2 -1
- package/dist/styles.js.map +1 -1
- package/dist/targets.d.ts +1 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/types.d.ts +71 -46
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/BlockPicker.d.ts.map +1 -1
- package/dist/ui/BlockPicker.js +6 -5
- package/dist/ui/BlockPicker.js.map +1 -1
- package/dist/ui/Dialog.d.ts +0 -5
- package/dist/ui/Dialog.d.ts.map +1 -1
- package/dist/ui/Dialog.js +10 -6
- package/dist/ui/Dialog.js.map +1 -1
- package/dist/ui/Dock.d.ts +1 -6
- package/dist/ui/Dock.d.ts.map +1 -1
- package/dist/ui/Dock.js +46 -28
- package/dist/ui/Dock.js.map +1 -1
- package/dist/ui/Overlay.d.ts.map +1 -1
- package/dist/ui/Overlay.js +39 -37
- package/dist/ui/Overlay.js.map +1 -1
- package/dist/ui/PreviewToolbar.d.ts +3 -3
- package/dist/ui/PreviewToolbar.d.ts.map +1 -1
- package/dist/ui/PreviewToolbar.js +4 -6
- package/dist/ui/PreviewToolbar.js.map +1 -1
- package/dist/ui/SettingsPanel.d.ts +0 -9
- package/dist/ui/SettingsPanel.d.ts.map +1 -1
- package/dist/ui/SettingsPanel.js +36 -41
- package/dist/ui/SettingsPanel.js.map +1 -1
- package/dist/ui/ToolbarButton.d.ts +12 -0
- package/dist/ui/ToolbarButton.d.ts.map +1 -0
- package/dist/ui/ToolbarButton.js +7 -0
- package/dist/ui/ToolbarButton.js.map +1 -0
- package/dist/useEvent.d.ts +1 -1
- package/dist/useEvent.d.ts.map +1 -1
- package/dist/useEvent.js +3 -1
- package/dist/useEvent.js.map +1 -1
- package/dist/useIsClient.d.ts +5 -0
- package/dist/useIsClient.d.ts.map +1 -0
- package/dist/useIsClient.js +8 -0
- package/dist/useIsClient.js.map +1 -0
- package/package.json +2 -2
- package/src/OnPageClient.tsx +9 -5
- package/src/annotations.ts +1 -1
- package/src/context.tsx +53 -10
- package/src/dom.ts +17 -18
- package/src/editor/FieldHost.tsx +26 -11
- package/src/editor/OnPageEditor.tsx +103 -160
- package/src/editor/editTarget.ts +41 -0
- package/src/editor/useClientDocs.ts +19 -0
- package/src/editor/useEditorSession.ts +36 -0
- package/src/editor/useFlash.ts +18 -0
- package/src/editor/useGhosts.ts +5 -7
- package/src/editor/usePageEvents.ts +13 -14
- package/src/editor-kit.ts +10 -6
- package/src/editors/CheckboxEditor.tsx +11 -12
- package/src/editors/ColorEditor.tsx +15 -35
- package/src/editors/DateEditor.tsx +18 -37
- package/src/editors/InlineText.tsx +4 -5
- package/src/editors/NumberEditor.tsx +15 -36
- package/src/editors/RelationshipEditor.tsx +18 -36
- package/src/editors/SelectEditor.tsx +14 -22
- package/src/editors/UploadEditor.tsx +6 -6
- package/src/editors/index.ts +56 -16
- package/src/editors/kit.tsx +97 -0
- package/src/editors/useDebouncedSearch.ts +18 -10
- package/src/geometry.ts +62 -0
- package/src/hub.ts +5 -5
- package/src/index.ts +5 -2
- package/src/layout.ts +5 -2
- package/src/locators.ts +11 -14
- package/src/messages.ts +26 -5
- package/src/registry.ts +42 -8
- package/src/rowOps.ts +64 -0
- package/src/sanitize.ts +6 -0
- package/src/settings.ts +49 -0
- package/src/styles.ts +2 -1
- package/src/targets.ts +1 -1
- package/src/types.ts +78 -45
- package/src/ui/BlockPicker.tsx +6 -7
- package/src/ui/Dialog.tsx +9 -5
- package/src/ui/Dock.tsx +67 -50
- package/src/ui/Overlay.tsx +75 -102
- package/src/ui/PreviewToolbar.tsx +7 -15
- package/src/ui/SettingsPanel.tsx +84 -81
- package/src/ui/ToolbarButton.tsx +36 -0
- package/src/useEvent.ts +4 -2
- package/src/useIsClient.ts +15 -0
|
@@ -7,33 +7,37 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
7
7
|
* through the DataSource; the Renderer shows them (server refresh by default,
|
|
8
8
|
* instant for documents rendered with <OnPageClient>).
|
|
9
9
|
*/
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from 'react';
|
|
10
|
+
import { refKey, } from '@payload-onpage/core';
|
|
11
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
13
12
|
import { createPortal } from 'react-dom';
|
|
14
|
-
import {
|
|
13
|
+
import { OnPageProvider, useSessionSnapshot } from "../context.js";
|
|
15
14
|
import { UI } from "../dom.js";
|
|
16
15
|
import { defaultEditors } from "../editors/index.js";
|
|
17
16
|
import { hub } from "../hub.js";
|
|
18
17
|
import { notifyLayout } from "../layout.js";
|
|
19
18
|
import { annotations, composite, stega } from "../locators.js";
|
|
20
19
|
import { createTranslate } from "../messages.js";
|
|
21
|
-
import { mergeEditors
|
|
20
|
+
import { mergeEditors } from "../registry.js";
|
|
22
21
|
import { clientState } from "../renderers.js";
|
|
23
|
-
import { injectStyles } from "../styles.js";
|
|
24
22
|
import { useTargets } from "../targets.js";
|
|
25
23
|
import { BlockPicker } from "../ui/BlockPicker.js";
|
|
26
24
|
import { Dock } from "../ui/Dock.js";
|
|
27
25
|
import { Overlay } from "../ui/Overlay.js";
|
|
28
26
|
import { SettingsPanel } from "../ui/SettingsPanel.js";
|
|
27
|
+
import { useEditorStyles, useIsClient } from "../useIsClient.js";
|
|
28
|
+
import { useEvent } from "../useEvent.js";
|
|
29
|
+
import { resolveEditTarget } from "./editTarget.js";
|
|
29
30
|
import { FieldHost } from "./FieldHost.js";
|
|
30
31
|
import { Ghosts } from "./Ghosts.js";
|
|
31
|
-
import {
|
|
32
|
+
import { useClientDocs } from "./useClientDocs.js";
|
|
33
|
+
import { useEditorSession } from "./useEditorSession.js";
|
|
34
|
+
import { useFlash } from "./useFlash.js";
|
|
32
35
|
import { useGhosts } from "./useGhosts.js";
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
import { usePageEvents } from "./usePageEvents.js";
|
|
37
|
+
/** How long a re-rendered page gets to land (and the locator to rescan) before ghosts are retired. */
|
|
38
|
+
const SETTLE_MS = 250;
|
|
35
39
|
export function OnPageEditor(props) {
|
|
36
|
-
const { dataSource, locale,
|
|
40
|
+
const { dataSource, locale, links, media } = props;
|
|
37
41
|
const renderer = useMemo(() => props.renderer ?? clientState(), [props.renderer]);
|
|
38
42
|
const locator = useMemo(() => props.locator ?? composite(annotations(), stega()), [props.locator]);
|
|
39
43
|
const editors = useMemo(() => mergeEditors(defaultEditors, props.editors), [props.editors]);
|
|
@@ -44,15 +48,31 @@ export function OnPageEditor(props) {
|
|
|
44
48
|
const [editing, setEditing] = useState(null);
|
|
45
49
|
const [selected, setSelected] = useState(null);
|
|
46
50
|
const [renders, setRenders] = useState(0);
|
|
47
|
-
const [flash,
|
|
48
|
-
const [clientDocs,
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
+
const [flash, notify] = useFlash();
|
|
52
|
+
const [clientDocs, registerClientDoc] = useClientDocs();
|
|
53
|
+
const isLive = useCallback((key) => renderer.live || clientDocs.has(key), [renderer, clientDocs]);
|
|
54
|
+
// Refresh mode saves quickly (the page only updates after a save); client mode uses the collection's interval.
|
|
55
|
+
const session = useEditorSession({
|
|
56
|
+
dataSource,
|
|
57
|
+
locale,
|
|
58
|
+
autosaveDelay: props.autosaveDelay ?? (renderer.live ? undefined : 250),
|
|
59
|
+
onSaved: (ref, seq) => void rerender([ref], seq),
|
|
60
|
+
});
|
|
61
|
+
const snap = useSessionSnapshot(session);
|
|
51
62
|
const targets = useTargets(locator, root);
|
|
52
63
|
const { ghosts, add: addGhostEntry, rendered: ghostsRendered } = useGhosts(session ? snap : null);
|
|
53
|
-
|
|
64
|
+
// Pending "retire ghosts" timers, cleared on unmount.
|
|
65
|
+
const ghostTimers = useRef(new Set());
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
const timers = ghostTimers.current;
|
|
68
|
+
return () => {
|
|
69
|
+
for (const id of timers)
|
|
70
|
+
clearTimeout(id);
|
|
71
|
+
timers.clear();
|
|
72
|
+
};
|
|
73
|
+
}, []);
|
|
54
74
|
/** Re-render documents that aren't client-rendered, then retire their ghosts. */
|
|
55
|
-
const rerender =
|
|
75
|
+
const rerender = useEvent(async (refs, seq) => {
|
|
56
76
|
const stale = refs.filter((r) => !isLive(refKey(r)));
|
|
57
77
|
if (!stale.length)
|
|
58
78
|
return;
|
|
@@ -65,38 +85,14 @@ export function OnPageEditor(props) {
|
|
|
65
85
|
}
|
|
66
86
|
finally {
|
|
67
87
|
setRenders((n) => n - 1);
|
|
68
|
-
|
|
69
|
-
|
|
88
|
+
const id = setTimeout(() => {
|
|
89
|
+
ghostTimers.current.delete(id);
|
|
70
90
|
for (const r of stale)
|
|
71
91
|
ghostsRendered(refKey(r), seq ?? Number.MAX_SAFE_INTEGER);
|
|
72
|
-
},
|
|
92
|
+
}, SETTLE_MS);
|
|
93
|
+
ghostTimers.current.add(id);
|
|
73
94
|
}
|
|
74
|
-
}
|
|
75
|
-
const handleSaved = useEvent((ref, seq) => void rerender([ref], seq));
|
|
76
|
-
// One session per data source and locale; disposed (after flushing) when they change or on unmount.
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
// Refresh mode saves quickly (the page only updates after a save); client mode uses the collection's interval.
|
|
79
|
-
const delay = autosaveDelay ?? (renderer.live ? undefined : 250);
|
|
80
|
-
const s = new EditorSession({
|
|
81
|
-
dataSource,
|
|
82
|
-
locale,
|
|
83
|
-
autosaveDelay: delay,
|
|
84
|
-
onSaved: (ref, seq) => handleSaved(ref, seq),
|
|
85
|
-
});
|
|
86
|
-
// The session is an external resource with a lifecycle; it lives in state so StrictMode's
|
|
87
|
-
// mount/unmount/mount gets a fresh one each time.
|
|
88
|
-
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
89
|
-
setSession(s);
|
|
90
|
-
return () => {
|
|
91
|
-
void s.flush().finally(() => s.dispose());
|
|
92
|
-
};
|
|
93
|
-
}, [dataSource, locale, autosaveDelay, renderer.live, handleSaved]);
|
|
94
|
-
useEffect(() => {
|
|
95
|
-
if (!flash)
|
|
96
|
-
return;
|
|
97
|
-
const id = setTimeout(() => setFlash(null), 4000);
|
|
98
|
-
return () => clearTimeout(id);
|
|
99
|
-
}, [flash]);
|
|
95
|
+
});
|
|
100
96
|
// Documents on this page: everything the locator found, plus client-mode documents.
|
|
101
97
|
const docKeys = useMemo(() => {
|
|
102
98
|
const keys = new Set(clientDocs);
|
|
@@ -109,103 +105,77 @@ export function OnPageEditor(props) {
|
|
|
109
105
|
return;
|
|
110
106
|
const seen = new Set();
|
|
111
107
|
for (const target of targets.all) {
|
|
112
|
-
const
|
|
113
|
-
if (seen.has(
|
|
108
|
+
const key = refKey(target.ref);
|
|
109
|
+
if (seen.has(key))
|
|
114
110
|
continue;
|
|
115
|
-
seen.add(
|
|
111
|
+
seen.add(key);
|
|
116
112
|
void session.open(target.ref);
|
|
117
113
|
}
|
|
118
114
|
}, [targets, session]);
|
|
119
115
|
useEffect(() => notifyLayout(), [snap, targets]);
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const next = new Set(s);
|
|
125
|
-
next.delete(key);
|
|
126
|
-
return next;
|
|
127
|
-
});
|
|
128
|
-
}, []);
|
|
129
|
-
const addGhost = useCallback((g) => addGhostEntry(g, session?.get(g.key)?.save.seq ?? 0), [addGhostEntry, session]);
|
|
130
|
-
const edit = useCallback((key, path, opts = {}) => {
|
|
131
|
-
const state = session?.get(key);
|
|
132
|
-
if (!state?.schema || !state.doc) {
|
|
133
|
-
if (state?.status === 'error')
|
|
134
|
-
notify('notify.cantEdit', { message: state.error ?? '' }, true);
|
|
135
|
-
else
|
|
136
|
-
notify('notify.loading');
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
if (!isEditablePath(state.schema, path))
|
|
140
|
-
return false;
|
|
141
|
-
const hit = fieldAtPath(state.schema.fields, state.doc, path);
|
|
142
|
-
if (!hit)
|
|
143
|
-
return false;
|
|
144
|
-
const editor = resolveEditor(editors, hit.field, opts.kind === 'field' ? undefined : opts.kind);
|
|
145
|
-
if (!editor)
|
|
146
|
-
return false;
|
|
147
|
-
setEditing({
|
|
148
|
-
key,
|
|
149
|
-
path,
|
|
150
|
-
editor,
|
|
116
|
+
const addGhost = useEvent((g) => addGhostEntry(g, session?.get(g.key)?.save.seq ?? 0));
|
|
117
|
+
// Stable: reads the latest state when called, so the API doesn't change on every rescan.
|
|
118
|
+
const edit = useEvent((key, path, opts = {}) => {
|
|
119
|
+
const target = resolveEditTarget(session?.get(key), editors, key, path, {
|
|
151
120
|
point: opts.point,
|
|
121
|
+
kind: opts.kind,
|
|
152
122
|
el: opts.anchor ?? targets.find(key, path)?.el,
|
|
153
123
|
});
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
124
|
+
switch (target.kind) {
|
|
125
|
+
case 'not-ready':
|
|
126
|
+
if (target.state?.status === 'error')
|
|
127
|
+
notify(t('notify.cantEdit', { message: target.state.error ?? '' }), true);
|
|
128
|
+
else
|
|
129
|
+
notify(t('notify.loading'));
|
|
130
|
+
return true;
|
|
131
|
+
case 'none':
|
|
132
|
+
return false;
|
|
133
|
+
case 'edit':
|
|
134
|
+
setEditing(target.editing);
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
const api = useMemo(() => session && {
|
|
157
139
|
session,
|
|
158
|
-
snap,
|
|
159
140
|
renderer,
|
|
160
141
|
media,
|
|
161
142
|
editors,
|
|
162
|
-
targets,
|
|
163
143
|
links,
|
|
164
144
|
t,
|
|
165
|
-
panel,
|
|
166
145
|
setPanel,
|
|
167
|
-
editing,
|
|
168
146
|
setEditing,
|
|
169
|
-
selected,
|
|
170
147
|
setSelected,
|
|
171
|
-
docKeys,
|
|
172
148
|
isLive,
|
|
173
149
|
registerClientDoc,
|
|
174
|
-
rendering: renders > 0,
|
|
175
150
|
edit,
|
|
176
151
|
rerender: (refs) => rerender(refs),
|
|
177
152
|
notify,
|
|
178
153
|
addGhost,
|
|
179
154
|
}, [
|
|
180
155
|
session,
|
|
181
|
-
snap,
|
|
182
156
|
renderer,
|
|
183
157
|
media,
|
|
184
158
|
editors,
|
|
185
|
-
targets,
|
|
186
159
|
links,
|
|
187
160
|
t,
|
|
188
|
-
panel,
|
|
189
|
-
editing,
|
|
190
|
-
selected,
|
|
191
|
-
docKeys,
|
|
192
161
|
isLive,
|
|
193
162
|
registerClientDoc,
|
|
194
|
-
renders,
|
|
195
163
|
edit,
|
|
196
164
|
rerender,
|
|
197
165
|
notify,
|
|
198
166
|
addGhost,
|
|
199
167
|
]);
|
|
168
|
+
const state = useMemo(() => ({ snap, targets, panel, editing, selected, docKeys, rendering: renders > 0, flash }), [snap, targets, panel, editing, selected, docKeys, renders, flash]);
|
|
169
|
+
// Components outside the editor's tree (client-mode documents) reach it through the hub.
|
|
200
170
|
useEffect(() => {
|
|
201
|
-
hub.set(
|
|
202
|
-
}, [
|
|
171
|
+
hub.set(api);
|
|
172
|
+
}, [api]);
|
|
203
173
|
useEffect(() => () => hub.set(null), []);
|
|
204
|
-
|
|
205
|
-
usePageEvents(
|
|
206
|
-
const mounted =
|
|
207
|
-
if (!mounted || !
|
|
174
|
+
useEditorStyles();
|
|
175
|
+
usePageEvents(api && { ...api, ...state }, root);
|
|
176
|
+
const mounted = useIsClient();
|
|
177
|
+
if (!mounted || !api)
|
|
208
178
|
return null;
|
|
209
|
-
return (_jsxs(
|
|
179
|
+
return (_jsxs(OnPageProvider, { api: api, state: state, children: [createPortal(_jsxs("div", { className: "po-doc-layer", [UI]: '', children: [_jsx(Ghosts, { ghosts: ghosts }), _jsx(FieldHost, { mode: "inline" })] }), document.body), createPortal(_jsxs("div", { className: "po-layer", [UI]: '', children: [_jsx(Overlay, {}), _jsx(SettingsPanel, {}), _jsx(BlockPicker, {}), _jsx(FieldHost, { mode: "popover" }), _jsx(Dock, {})] }), document.body)] }));
|
|
210
180
|
}
|
|
211
181
|
//# sourceMappingURL=OnPageEditor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OnPageEditor.js","sourceRoot":"","sources":["../../src/editor/OnPageEditor.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;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IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAA;IAEjC,OAAO,CACL,MAAC,cAAc,IAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,aACnC,YAAY,CACX,eAAK,SAAS,EAAC,cAAc,EAAO,CAAC,EAAE,CAAC,EAAE,EAAE,aAC1C,KAAC,MAAM,IAAC,MAAM,EAAE,MAAM,GAAI,EAC1B,KAAC,SAAS,IAAC,IAAI,EAAC,QAAQ,GAAG,IACvB,EACN,QAAQ,CAAC,IAAI,CACd,EACA,YAAY,CACX,eAAK,SAAS,EAAC,UAAU,EAAO,CAAC,EAAE,CAAC,EAAE,EAAE,aACtC,KAAC,OAAO,KAAG,EACX,KAAC,aAAa,KAAG,EACjB,KAAC,WAAW,KAAG,EACf,KAAC,SAAS,IAAC,IAAI,EAAC,SAAS,GAAG,EAC5B,KAAC,IAAI,KAAG,IACJ,EACN,QAAQ,CAAC,IAAI,CACd,IACc,CAClB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What clicking or pressing Enter on a field opens: a pure function of the
|
|
3
|
+
* document's state, the editor registry and what was clicked.
|
|
4
|
+
*/
|
|
5
|
+
import { type DocumentState, type RefKey, type TargetKind } from '@payload-onpage/core';
|
|
6
|
+
import type { EditingState, EditorRegistry } from '../types.ts';
|
|
7
|
+
export type EditTarget =
|
|
8
|
+
/** The document isn't loaded (yet, or it failed). */
|
|
9
|
+
{
|
|
10
|
+
kind: 'not-ready';
|
|
11
|
+
state: DocumentState | undefined;
|
|
12
|
+
}
|
|
13
|
+
/** Nothing here is edited in place. */
|
|
14
|
+
| {
|
|
15
|
+
kind: 'none';
|
|
16
|
+
} | {
|
|
17
|
+
kind: 'edit';
|
|
18
|
+
editing: EditingState;
|
|
19
|
+
};
|
|
20
|
+
export declare function resolveEditTarget(state: DocumentState | undefined, editors: EditorRegistry, key: RefKey, path: string, opts: {
|
|
21
|
+
point?: {
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
} | undefined;
|
|
25
|
+
kind?: TargetKind | undefined;
|
|
26
|
+
el?: Element | undefined;
|
|
27
|
+
}): EditTarget;
|
|
28
|
+
//# sourceMappingURL=editTarget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editTarget.d.ts","sourceRoot":"","sources":["../../src/editor/editTarget.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,UAAU,EAChB,MAAM,sBAAsB,CAAA;AAE7B,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE/D,MAAM,MAAM,UAAU;AACpB,qDAAqD;AACnD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,aAAa,GAAG,SAAS,CAAA;CAAE;AACzD,uCAAuC;GACrC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,CAAA;AAE3C,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,aAAa,GAAG,SAAS,EAChC,OAAO,EAAE,cAAc,EACvB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;IACJ,KAAK,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAA;IAC5C,IAAI,CAAC,EAAE,UAAU,GAAG,SAAS,CAAA;IAC7B,EAAE,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CACzB,GACA,UAAU,CAQZ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What clicking or pressing Enter on a field opens: a pure function of the
|
|
3
|
+
* document's state, the editor registry and what was clicked.
|
|
4
|
+
*/
|
|
5
|
+
import { fieldAtPath, isEditablePath, isReady, } from '@payload-onpage/core';
|
|
6
|
+
import { resolveEditor } from "../registry.js";
|
|
7
|
+
export function resolveEditTarget(state, editors, key, path, opts) {
|
|
8
|
+
if (!isReady(state))
|
|
9
|
+
return { kind: 'not-ready', state };
|
|
10
|
+
if (!isEditablePath(state.schema, path))
|
|
11
|
+
return { kind: 'none' };
|
|
12
|
+
const hit = fieldAtPath(state.schema.fields, state.doc, path);
|
|
13
|
+
if (!hit)
|
|
14
|
+
return { kind: 'none' };
|
|
15
|
+
const editor = resolveEditor(editors, hit.field, opts.kind === 'field' ? undefined : opts.kind);
|
|
16
|
+
if (!editor)
|
|
17
|
+
return { kind: 'none' };
|
|
18
|
+
return { kind: 'edit', editing: { key, path, editor, point: opts.point, el: opts.el } };
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=editTarget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editTarget.js","sourceRoot":"","sources":["../../src/editor/editTarget.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,WAAW,EACX,cAAc,EACd,OAAO,GAIR,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAU9C,MAAM,UAAU,iBAAiB,CAC/B,KAAgC,EAChC,OAAuB,EACvB,GAAW,EACX,IAAY,EACZ,IAIC;IAED,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAA;IACxD,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;IAChE,MAAM,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAC7D,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;IACjC,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC/F,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;IACpC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAA;AACzF,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RefKey } from '@payload-onpage/core';
|
|
2
|
+
/** Documents rendered from editor state on this page (client mode), and how they register. */
|
|
3
|
+
export declare function useClientDocs(): [ReadonlySet<RefKey>, (key: RefKey) => () => void];
|
|
4
|
+
//# sourceMappingURL=useClientDocs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useClientDocs.d.ts","sourceRoot":"","sources":["../../src/editor/useClientDocs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAGlD,8FAA8F;AAC9F,wBAAgB,aAAa,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,IAAI,CAAC,CAYlF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useState } from 'react';
|
|
3
|
+
/** Documents rendered from editor state on this page (client mode), and how they register. */
|
|
4
|
+
export function useClientDocs() {
|
|
5
|
+
const [docs, setDocs] = useState(() => new Set());
|
|
6
|
+
const register = useCallback((key) => {
|
|
7
|
+
setDocs((s) => new Set(s).add(key));
|
|
8
|
+
return () => setDocs((s) => {
|
|
9
|
+
const next = new Set(s);
|
|
10
|
+
next.delete(key);
|
|
11
|
+
return next;
|
|
12
|
+
});
|
|
13
|
+
}, []);
|
|
14
|
+
return [docs, register];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=useClientDocs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useClientDocs.js","sourceRoot":"","sources":["../../src/editor/useClientDocs.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAGZ,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE7C,8FAA8F;AAC9F,MAAM,UAAU,aAAa;IAC3B,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAsB,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,CAAA;IACtE,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,GAAW,EAAE,EAAE;QAC3C,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;QACnC,OAAO,GAAG,EAAE,CACV,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YACZ,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAA;YACvB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;YAChB,OAAO,IAAI,CAAA;QACb,CAAC,CAAC,CAAA;IACN,CAAC,EAAE,EAAE,CAAC,CAAA;IACN,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EditorSession, type DataSource, type DocRef } from '@payload-onpage/core';
|
|
2
|
+
/**
|
|
3
|
+
* One editor session per data source and locale, disposed (after flushing its
|
|
4
|
+
* saves) when they change or on unmount. It lives in state, so StrictMode's
|
|
5
|
+
* mount/unmount/mount gets a fresh one each time.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useEditorSession(opts: {
|
|
8
|
+
dataSource: DataSource;
|
|
9
|
+
locale: string | undefined;
|
|
10
|
+
autosaveDelay: number | undefined;
|
|
11
|
+
onSaved: (ref: DocRef, seq: number) => void;
|
|
12
|
+
}): EditorSession | null;
|
|
13
|
+
//# sourceMappingURL=useEditorSession.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEditorSession.d.ts","sourceRoot":"","sources":["../../src/editor/useEditorSession.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAIlF;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,aAAa,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;CAC5C,GAAG,aAAa,GAAG,IAAI,CAmBvB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { EditorSession } from '@payload-onpage/core';
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { useEvent } from "../useEvent.js";
|
|
5
|
+
/**
|
|
6
|
+
* One editor session per data source and locale, disposed (after flushing its
|
|
7
|
+
* saves) when they change or on unmount. It lives in state, so StrictMode's
|
|
8
|
+
* mount/unmount/mount gets a fresh one each time.
|
|
9
|
+
*/
|
|
10
|
+
export function useEditorSession(opts) {
|
|
11
|
+
const { dataSource, locale, autosaveDelay } = opts;
|
|
12
|
+
const onSaved = useEvent(opts.onSaved);
|
|
13
|
+
const [session, setSession] = useState(null);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const s = new EditorSession({
|
|
16
|
+
dataSource,
|
|
17
|
+
locale,
|
|
18
|
+
autosaveDelay,
|
|
19
|
+
onSaved: (ref, seq) => onSaved(ref, seq),
|
|
20
|
+
});
|
|
21
|
+
// The session is an external resource with a lifecycle (see above).
|
|
22
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
23
|
+
setSession(s);
|
|
24
|
+
return () => {
|
|
25
|
+
void s.flush().finally(() => s.dispose());
|
|
26
|
+
};
|
|
27
|
+
}, [dataSource, locale, autosaveDelay, onSaved]);
|
|
28
|
+
return session;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=useEditorSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEditorSession.js","sourceRoot":"","sources":["../../src/editor/useEditorSession.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,aAAa,EAAgC,MAAM,sBAAsB,CAAA;AAClF,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAKhC;IACC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,CAAA;IAClD,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACtC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAuB,IAAI,CAAC,CAAA;IAClE,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,GAAG,IAAI,aAAa,CAAC;YAC1B,UAAU;YACV,MAAM;YACN,aAAa;YACb,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;SACzC,CAAC,CAAA;QACF,oEAAoE;QACpE,2DAA2D;QAC3D,UAAU,CAAC,CAAC,CAAC,CAAA;QACb,OAAO,GAAG,EAAE;YACV,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAA;QAC3C,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC,CAAA;IAChD,OAAO,OAAO,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFlash.d.ts","sourceRoot":"","sources":["../../src/editor/useFlash.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAIxC,6DAA6D;AAC7D,wBAAgB,QAAQ,IAAI,CAAC,KAAK,GAAG,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC,CAShF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
const SHOWN_FOR = 4000;
|
|
4
|
+
/** The dock's short message, cleared after a few seconds. */
|
|
5
|
+
export function useFlash() {
|
|
6
|
+
const [flash, setFlash] = useState(null);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (!flash)
|
|
9
|
+
return;
|
|
10
|
+
const id = setTimeout(() => setFlash(null), SHOWN_FOR);
|
|
11
|
+
return () => clearTimeout(id);
|
|
12
|
+
}, [flash]);
|
|
13
|
+
const notify = useCallback((text, bad) => setFlash({ text, bad }), []);
|
|
14
|
+
return [flash, notify];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=useFlash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFlash.js","sourceRoot":"","sources":["../../src/editor/useFlash.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAGxD,MAAM,SAAS,GAAG,IAAI,CAAA;AAEtB,6DAA6D;AAC7D,MAAM,UAAU,QAAQ;IACtB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAA;IACtD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,KAAK;YAAE,OAAM;QAClB,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,CAAA;QACtD,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAA;IAC/B,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IACX,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,IAAY,EAAE,GAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;IACxF,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;AACxB,CAAC"}
|
|
@@ -4,14 +4,12 @@
|
|
|
4
4
|
* records the document's save sequence when it was made; the render after a
|
|
5
5
|
* later save retires it. Failed saves and a TTL retire ghosts too.
|
|
6
6
|
*/
|
|
7
|
-
import type { SessionSnapshot } from '@payload-onpage/core';
|
|
8
|
-
|
|
7
|
+
import type { SessionSnapshot, RefKey } from '@payload-onpage/core';
|
|
8
|
+
import type { GhostInput } from '../types.ts';
|
|
9
|
+
export interface Ghost extends GhostInput {
|
|
9
10
|
id: string;
|
|
10
|
-
key:
|
|
11
|
+
key: RefKey;
|
|
11
12
|
path: string;
|
|
12
|
-
html: string;
|
|
13
|
-
className?: string;
|
|
14
|
-
style?: Partial<CSSStyleDeclaration>;
|
|
15
13
|
/** Save sequence of the document when the ghost was made. */
|
|
16
14
|
afterSeq: number;
|
|
17
15
|
until: number;
|
|
@@ -19,6 +17,6 @@ export interface Ghost {
|
|
|
19
17
|
export declare function useGhosts(snap: SessionSnapshot | null): {
|
|
20
18
|
ghosts: Ghost[];
|
|
21
19
|
add: (g: Omit<Ghost, "id" | "until" | "afterSeq">, afterSeq: number) => void;
|
|
22
|
-
rendered: (key:
|
|
20
|
+
rendered: (key: RefKey, seq: number) => void;
|
|
23
21
|
};
|
|
24
22
|
//# sourceMappingURL=useGhosts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGhosts.d.ts","sourceRoot":"","sources":["../../src/editor/useGhosts.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"useGhosts.d.ts","sourceRoot":"","sources":["../../src/editor/useGhosts.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG7C,MAAM,WAAW,KAAM,SAAQ,UAAU;IACvC,EAAE,EAAE,MAAM,CAAA;IACV,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;CACd;AAID,wBAAgB,SAAS,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI;;aAGxB,IAAI,CAAC,KAAK,EAAE,IAAI,GAAG,OAAO,GAAG,UAAU,CAAC,YAAY,MAAM;oBASnD,MAAM,OAAO,MAAM;EA0BvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGhosts.js","sourceRoot":"","sources":["../../src/editor/useGhosts.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"useGhosts.js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
|
|
|
1
|
-
{"version":3,"file":"usePageEvents.d.ts","sourceRoot":"","sources":["../../src/editor/usePageEvents.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePageEvents.d.ts","sourceRoot":"","sources":["../../src/editor/usePageEvents.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIrD,wBAAgB,aAAa,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,UAAU,GAAG,IAAI,GAAG,IAAI,CA4IjG"}
|
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
* - a warning before leaving with unsaved changes
|
|
8
8
|
*/
|
|
9
9
|
import { useEvent } from "../useEvent.js";
|
|
10
|
-
import {
|
|
10
|
+
import { refKey, resolveRow, isReady } from '@payload-onpage/core';
|
|
11
|
+
import { rowOps } from "../rowOps.js";
|
|
11
12
|
import { useEffect } from 'react';
|
|
12
|
-
import { isOurs, isTyping } from "../dom.js";
|
|
13
|
+
import { DOM_ATTR, isOurs, isTyping } from "../dom.js";
|
|
13
14
|
import { isFieldTarget, isRowTarget, targetsAt } from "../targets.js";
|
|
14
|
-
const FOCUSABLE_FLAG =
|
|
15
|
+
const FOCUSABLE_FLAG = DOM_ATTR.focusable;
|
|
15
16
|
export function usePageEvents(ctx, root) {
|
|
16
17
|
const onClick = useEvent((e) => {
|
|
17
18
|
if (!ctx || e.altKey || e.button !== 0)
|
|
@@ -42,26 +43,25 @@ export function usePageEvents(ctx, root) {
|
|
|
42
43
|
e.preventDefault(); // don't navigate away from the editor by accident
|
|
43
44
|
}
|
|
44
45
|
});
|
|
46
|
+
/** ⌥↑/⌥↓ move the selected row, ⌥⌫ deletes it. True when the key was ours (even if the row can't move). */
|
|
45
47
|
const moveSelected = (dir) => {
|
|
46
48
|
if (!ctx?.selected)
|
|
47
49
|
return false;
|
|
48
50
|
const { key, path } = ctx.selected;
|
|
49
51
|
const state = ctx.snap.docs[key];
|
|
50
|
-
const info = state
|
|
52
|
+
const info = isReady(state) ? resolveRow(state.schema, state.doc, path) : null;
|
|
51
53
|
if (!info)
|
|
52
54
|
return false;
|
|
55
|
+
const ops = rowOps(ctx.session, key, info);
|
|
53
56
|
if (dir === 'delete') {
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
if (ops.remove())
|
|
58
|
+
ctx.setSelected(null);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const next = ops.move(dir);
|
|
62
|
+
if (next)
|
|
63
|
+
ctx.setSelected(next);
|
|
59
64
|
}
|
|
60
|
-
const to = info.index + dir;
|
|
61
|
-
if (to < 0 || to >= info.length)
|
|
62
|
-
return true;
|
|
63
|
-
ctx.session.apply(key, (d) => updateArray(d, info.listPath, (a) => moveItem(a, info.index, to)));
|
|
64
|
-
ctx.setSelected({ key, path: `${info.listPath}.${to}` });
|
|
65
65
|
return true;
|
|
66
66
|
};
|
|
67
67
|
const onKey = useEvent((e) => {
|
|
@@ -122,7 +122,7 @@ export function usePageEvents(ctx, root) {
|
|
|
122
122
|
e.preventDefault();
|
|
123
123
|
});
|
|
124
124
|
useEffect(() => {
|
|
125
|
-
document.documentElement.setAttribute(
|
|
125
|
+
document.documentElement.setAttribute(DOM_ATTR.editing, '');
|
|
126
126
|
const click = (e) => onClick(e);
|
|
127
127
|
const key = (e) => onKey(e);
|
|
128
128
|
const focus = (e) => onFocus(e);
|
|
@@ -132,7 +132,7 @@ export function usePageEvents(ctx, root) {
|
|
|
132
132
|
document.addEventListener('focusin', focus);
|
|
133
133
|
window.addEventListener('beforeunload', unload);
|
|
134
134
|
return () => {
|
|
135
|
-
document.documentElement.removeAttribute(
|
|
135
|
+
document.documentElement.removeAttribute(DOM_ATTR.editing);
|
|
136
136
|
document.removeEventListener('click', click, true);
|
|
137
137
|
document.removeEventListener('keydown', key);
|
|
138
138
|
document.removeEventListener('focusin', focus);
|