@velocity-astro/cms-admin 0.1.0-beta.6 → 0.1.0-beta.8
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/app-dist/assets/{RichTextEditor-BiKJJtkz.js → RichTextEditor-D-0hJngm.js} +1 -1
- package/app-dist/assets/index-C2SsRclY.js +80 -0
- package/app-dist/assets/index-D8x7A_Xo.css +2 -0
- package/app-dist/index.html +5 -3
- package/dist/app/AdminLayout.d.ts.map +1 -1
- package/dist/app/AdminLayout.js +97 -54
- package/dist/app/AdminLayout.js.map +1 -1
- package/dist/app/paths.d.ts +2 -0
- package/dist/app/paths.d.ts.map +1 -1
- package/dist/app/paths.js +2 -0
- package/dist/app/paths.js.map +1 -1
- package/dist/client/queries.d.ts +2 -0
- package/dist/client/queries.d.ts.map +1 -1
- package/dist/client/queries.js +42 -7
- package/dist/client/queries.js.map +1 -1
- package/dist/fields/BlocksControl.d.ts +6 -0
- package/dist/fields/BlocksControl.d.ts.map +1 -1
- package/dist/fields/BlocksControl.js +303 -89
- package/dist/fields/BlocksControl.js.map +1 -1
- package/dist/fields/SiteImagePicker.d.ts +22 -0
- package/dist/fields/SiteImagePicker.d.ts.map +1 -0
- package/dist/fields/SiteImagePicker.js +42 -0
- package/dist/fields/SiteImagePicker.js.map +1 -0
- package/dist/fields/block-icons.d.ts.map +1 -1
- package/dist/fields/block-icons.js +3 -1
- package/dist/fields/block-icons.js.map +1 -1
- package/dist/fields/carry.d.ts +19 -0
- package/dist/fields/carry.d.ts.map +1 -0
- package/dist/fields/carry.js +61 -0
- package/dist/fields/carry.js.map +1 -0
- package/dist/fields/controls.d.ts.map +1 -1
- package/dist/fields/controls.js +82 -58
- package/dist/fields/controls.js.map +1 -1
- package/dist/fields/field-control.d.ts +80 -0
- package/dist/fields/field-control.d.ts.map +1 -1
- package/dist/fields/field-control.js.map +1 -1
- package/dist/fields/page-focus.d.ts +32 -3
- package/dist/fields/page-focus.d.ts.map +1 -1
- package/dist/fields/page-focus.js +55 -1
- package/dist/fields/page-focus.js.map +1 -1
- package/dist/lib/open-site.d.ts +6 -0
- package/dist/lib/open-site.d.ts.map +1 -0
- package/dist/lib/open-site.js +8 -0
- package/dist/lib/open-site.js.map +1 -0
- package/dist/lib/rich-from-html.d.ts +9 -0
- package/dist/lib/rich-from-html.d.ts.map +1 -0
- package/dist/lib/rich-from-html.js +129 -0
- package/dist/lib/rich-from-html.js.map +1 -0
- package/dist/lib/sittings.d.ts +16 -0
- package/dist/lib/sittings.d.ts.map +1 -0
- package/dist/lib/sittings.js +29 -0
- package/dist/lib/sittings.js.map +1 -0
- package/dist/lib/use-command-key.d.ts +16 -0
- package/dist/lib/use-command-key.d.ts.map +1 -0
- package/dist/lib/use-command-key.js +30 -0
- package/dist/lib/use-command-key.js.map +1 -0
- package/dist/lib/use-history.d.ts +24 -0
- package/dist/lib/use-history.d.ts.map +1 -0
- package/dist/lib/use-history.js +48 -0
- package/dist/lib/use-history.js.map +1 -0
- package/dist/lib/use-narrow.d.ts +5 -0
- package/dist/lib/use-narrow.d.ts.map +1 -0
- package/dist/lib/use-narrow.js +19 -0
- package/dist/lib/use-narrow.js.map +1 -0
- package/dist/lib/use-save-key.d.ts +15 -0
- package/dist/lib/use-save-key.d.ts.map +1 -0
- package/dist/lib/use-save-key.js +27 -0
- package/dist/lib/use-save-key.js.map +1 -0
- package/dist/lib/use-undo-keys.d.ts +14 -0
- package/dist/lib/use-undo-keys.d.ts.map +1 -0
- package/dist/lib/use-undo-keys.js +46 -0
- package/dist/lib/use-undo-keys.js.map +1 -0
- package/dist/messages/en.d.ts +72 -2
- package/dist/messages/en.d.ts.map +1 -1
- package/dist/messages/en.js +72 -2
- package/dist/messages/en.js.map +1 -1
- package/dist/page-bridge/preview-bridge.d.ts +3 -3
- package/dist/page-bridge/preview-bridge.d.ts.map +1 -1
- package/dist/page-bridge/preview-bridge.js +1145 -33
- package/dist/page-bridge/preview-bridge.js.map +1 -1
- package/dist/screens/Contact/ContactScreen.js +1 -1
- package/dist/screens/Contact/ContactScreen.js.map +1 -1
- package/dist/screens/Contacts/ContactsScreen.js +2 -2
- package/dist/screens/Contacts/ContactsScreen.js.map +1 -1
- package/dist/screens/Contacts/StagesDialog.d.ts.map +1 -1
- package/dist/screens/Contacts/StagesDialog.js +4 -1
- package/dist/screens/Contacts/StagesDialog.js.map +1 -1
- package/dist/screens/ContentList/ContentListScreen.d.ts.map +1 -1
- package/dist/screens/ContentList/ContentListScreen.js +11 -4
- package/dist/screens/ContentList/ContentListScreen.js.map +1 -1
- package/dist/screens/ContentList/EntryPeek.d.ts +13 -0
- package/dist/screens/ContentList/EntryPeek.d.ts.map +1 -0
- package/dist/screens/ContentList/EntryPeek.js +32 -0
- package/dist/screens/ContentList/EntryPeek.js.map +1 -0
- package/dist/screens/ContentType/ContentTypeScreen.js +1 -1
- package/dist/screens/ContentType/ContentTypeScreen.js.map +1 -1
- package/dist/screens/Deals/DealsScreen.js +27 -3
- package/dist/screens/Deals/DealsScreen.js.map +1 -1
- package/dist/screens/EntryEditor/EntryEditorScreen.d.ts.map +1 -1
- package/dist/screens/EntryEditor/EntryEditorScreen.js +5 -3
- package/dist/screens/EntryEditor/EntryEditorScreen.js.map +1 -1
- package/dist/screens/EntryEditor/EntryForm.d.ts +2 -0
- package/dist/screens/EntryEditor/EntryForm.d.ts.map +1 -1
- package/dist/screens/EntryEditor/EntryForm.js +165 -19
- package/dist/screens/EntryEditor/EntryForm.js.map +1 -1
- package/dist/screens/EntryEditor/HistoryDialog.d.ts +2 -1
- package/dist/screens/EntryEditor/HistoryDialog.d.ts.map +1 -1
- package/dist/screens/EntryEditor/HistoryDialog.js +24 -5
- package/dist/screens/EntryEditor/HistoryDialog.js.map +1 -1
- package/dist/screens/EntryEditor/PagePane.d.ts +12 -2
- package/dist/screens/EntryEditor/PagePane.d.ts.map +1 -1
- package/dist/screens/EntryEditor/PagePane.js +54 -19
- package/dist/screens/EntryEditor/PagePane.js.map +1 -1
- package/dist/screens/EntryEditor/SectionOutline.d.ts +11 -0
- package/dist/screens/EntryEditor/SectionOutline.d.ts.map +1 -0
- package/dist/screens/EntryEditor/SectionOutline.js +46 -0
- package/dist/screens/EntryEditor/SectionOutline.js.map +1 -0
- package/dist/screens/EntryEditor/ThemeCard.d.ts +32 -0
- package/dist/screens/EntryEditor/ThemeCard.d.ts.map +1 -0
- package/dist/screens/EntryEditor/ThemeCard.js +67 -0
- package/dist/screens/EntryEditor/ThemeCard.js.map +1 -0
- package/dist/screens/Home/HomeScreen.d.ts +1 -1
- package/dist/screens/Home/HomeScreen.d.ts.map +1 -1
- package/dist/screens/Home/HomeScreen.js +54 -16
- package/dist/screens/Home/HomeScreen.js.map +1 -1
- package/dist/testing/admin-client-contract.d.ts.map +1 -1
- package/dist/testing/admin-client-contract.js +6 -0
- package/dist/testing/admin-client-contract.js.map +1 -1
- package/package.json +5 -5
- package/app-dist/assets/index-BgVjqwy6.js +0 -80
- package/app-dist/assets/index-BvWFILf6.css +0 -2
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { liveFields } from '@velocity-astro/cms-core';
|
|
3
|
-
import { ConfirmDialog, OptionPicker, SectionList, Text } from '@velocity-astro/cms-ui';
|
|
3
|
+
import { Button, ConfirmDialog, Dialog, OptionPicker, SectionList, Text } from '@velocity-astro/cms-ui';
|
|
4
4
|
import { Copy, Eye, EyeOff, Trash2 } from 'lucide-react';
|
|
5
5
|
import { useEffect, useRef, useState } from 'react';
|
|
6
6
|
import { localized, withValue } from '../lib/content.js';
|
|
7
7
|
import { useLast } from '../lib/use-closing.js';
|
|
8
8
|
import { useLocale, useMessages } from '../messages/messages-context.js';
|
|
9
9
|
import { blockIcon } from './block-icons.js';
|
|
10
|
+
import { carriedSection } from './carry.js';
|
|
10
11
|
import { FieldGrid } from './FieldGrid.js';
|
|
11
12
|
import { useControlFor } from './FieldSummary.js';
|
|
12
|
-
import { usePageFocus } from './page-focus.js';
|
|
13
|
+
import { PageFocusInside, usePageFocus } from './page-focus.js';
|
|
14
|
+
import { SiteImagePicker } from './SiteImagePicker.js';
|
|
13
15
|
const isSection = (value) => typeof value === 'object' && value !== null && typeof value.id === 'string' && typeof value.block === 'string';
|
|
14
16
|
/**
|
|
15
17
|
* A few of a section's own words: the first line of text it holds, in the order of its fields.
|
|
16
|
-
* `isWords` leaves out the fields that hold a choice or a
|
|
18
|
+
* `isWords` leaves out the fields that hold a choice, a figure or a picture's name, which say nothing about it.
|
|
17
19
|
*/
|
|
18
20
|
function summaryOf(block, section, isWords) {
|
|
19
21
|
for (const field of liveFields(block.fields)) {
|
|
@@ -23,109 +25,221 @@ function summaryOf(block, section, isWords) {
|
|
|
23
25
|
}
|
|
24
26
|
return undefined;
|
|
25
27
|
}
|
|
28
|
+
const blocksOf = (field) => (Array.isArray(field.options['blocks']) ? field.options['blocks'] : []);
|
|
29
|
+
const maxOf = (field) => (typeof field.options['max'] === 'number' ? field.options['max'] : undefined);
|
|
30
|
+
const isFull = (list) => list.max !== undefined && list.sections.length >= list.max;
|
|
31
|
+
const withData = (list, id, data) => list.to(list.sections.map((existing) => (existing.id === id ? { ...existing, data: data } : existing)));
|
|
32
|
+
/** A list and every list inside its sections, outermost first. */
|
|
33
|
+
function gather(list, controlFor) {
|
|
34
|
+
const inner = list.sections.flatMap((section, index) => {
|
|
35
|
+
const block = blockOf(list.blocks, section);
|
|
36
|
+
if (!block || block.retiredAt !== undefined)
|
|
37
|
+
return [];
|
|
38
|
+
return liveFields(block.fields).flatMap((field) => (controlFor(field.type)?.sections?.(field, section.data[field.id], controlFor) ?? []).flatMap((found) => {
|
|
39
|
+
const place = found.place === '' ? field.key : `${field.key}.${found.place}`;
|
|
40
|
+
return gather({
|
|
41
|
+
key: `${section.id}:${place}`,
|
|
42
|
+
group: blocksOf(found.field).filter((block) => block.retiredAt === undefined).map((block) => block.key).sort().join('|'),
|
|
43
|
+
blocks: blocksOf(found.field),
|
|
44
|
+
sections: found.sections.filter(isSection),
|
|
45
|
+
max: maxOf(found.field),
|
|
46
|
+
path: `${list.path}.${index}.${place}`,
|
|
47
|
+
inside: [...list.inside, section.id],
|
|
48
|
+
to: (next) => withData(list, section.id, withValue(section.data, field.id, found.put(next))),
|
|
49
|
+
}, controlFor);
|
|
50
|
+
}));
|
|
51
|
+
});
|
|
52
|
+
return [list, ...inner];
|
|
53
|
+
}
|
|
54
|
+
function locate(lists, id) {
|
|
55
|
+
for (const list of lists) {
|
|
56
|
+
const at = list.sections.findIndex((section) => section.id === id);
|
|
57
|
+
const section = list.sections[at];
|
|
58
|
+
if (section)
|
|
59
|
+
return { list, at, section };
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
/** A copy of a section with an id of its own, and one for every section inside it. */
|
|
64
|
+
export function copyOf(value) {
|
|
65
|
+
if (Array.isArray(value))
|
|
66
|
+
return value.map((item) => copyOf(item));
|
|
67
|
+
if (typeof value !== 'object' || value === null)
|
|
68
|
+
return value;
|
|
69
|
+
const copied = Object.fromEntries(Object.entries(value).map(([key, inner]) => [key, copyOf(inner)]));
|
|
70
|
+
return (isSection(value) ? { ...copied, id: crypto.randomUUID() } : copied);
|
|
71
|
+
}
|
|
72
|
+
/** The places of one kind (words, pictures, links) a section holds, by the keys the page knows its fields by. */
|
|
73
|
+
function placesIn(list, section, ask, controlFor) {
|
|
74
|
+
const block = blockOf(list.blocks, section);
|
|
75
|
+
if (!block || block.retiredAt !== undefined)
|
|
76
|
+
return [];
|
|
77
|
+
return liveFields(block.fields).flatMap((inner) => {
|
|
78
|
+
const control = controlFor(inner.type);
|
|
79
|
+
return ((control && ask(control, inner, section.data[inner.id])) ?? []).map((found) => ({
|
|
80
|
+
...found,
|
|
81
|
+
place: found.place === '' ? inner.key : `${inner.key}.${found.place}`,
|
|
82
|
+
put: (held) => withValue(section.data, inner.id, found.put(held)),
|
|
83
|
+
}));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
26
86
|
/**
|
|
27
87
|
* The sections of a page. Each is one of the blocks the field allows and opens to that block's
|
|
28
88
|
* own fields, drawn by their own controls. What a section looks like on the site is the
|
|
29
89
|
* template's business: here it is only data.
|
|
90
|
+
*
|
|
91
|
+
* A block may hold sections of its own (the columns of a row). In the form those are drawn by
|
|
92
|
+
* the control of the field that holds them, which is this one again. To the page, the field that
|
|
93
|
+
* holds the whole page answers for every section in it, however deep.
|
|
30
94
|
*/
|
|
31
95
|
export function BlocksControl({ field, label, help, value, onChange, path, problem, problems }) {
|
|
32
96
|
const messages = useMessages();
|
|
33
97
|
const locale = useLocale();
|
|
34
|
-
const blocks =
|
|
98
|
+
const blocks = blocksOf(field);
|
|
35
99
|
const sections = Array.isArray(value) ? value.filter(isSection) : [];
|
|
36
|
-
const max =
|
|
100
|
+
const max = maxOf(field);
|
|
37
101
|
const [openIds, setOpenIds] = useState([]);
|
|
38
102
|
const [isPicking, setPicking] = useState(false);
|
|
39
|
-
// Where the section being picked goes: a place among
|
|
40
|
-
const [
|
|
103
|
+
// Where the section being picked goes: the list, and a place among its sections or the end.
|
|
104
|
+
const [pick, setPick] = useState({ key: '', at: null });
|
|
41
105
|
const [removingId, setRemovingId] = useState(null);
|
|
106
|
+
// The picture being changed from the page: its section and its place in it.
|
|
107
|
+
const [picturing, setPicturing] = useState(null);
|
|
108
|
+
// The link being changed from the page, the same way.
|
|
109
|
+
const [linking, setLinking] = useState(null);
|
|
42
110
|
// The field last pressed on the page, until the person turns to something else in the form.
|
|
43
111
|
const [pointed, setPointed] = useState(null);
|
|
44
112
|
const controlFor = useControlFor();
|
|
45
113
|
const focus = usePageFocus();
|
|
46
114
|
const pressed = focus?.pressed;
|
|
115
|
+
const opened = focus?.opened;
|
|
47
116
|
const change = (next) => onChange(next.length === 0 ? undefined : next);
|
|
117
|
+
const listsOf = (all) => gather({ key: '', group: '', blocks, sections: all, max, path, inside: [], to: (next) => next }, controlFor);
|
|
118
|
+
const lists = listsOf(sections);
|
|
119
|
+
const own = lists[0];
|
|
120
|
+
const wordsOf = (list, section) => placesIn(list, section, (control, inner, held) => control.words?.(inner, held, controlFor), controlFor);
|
|
121
|
+
const picturesOf = (list, section) => placesIn(list, section, (control, inner, held) => control.pictures?.(inner, held, controlFor), controlFor);
|
|
122
|
+
const linksOf = (list, section) => placesIn(list, section, (control, inner, held) => control.links?.(inner, held, controlFor), controlFor);
|
|
123
|
+
const itemsOf = (list, section) => placesIn(list, section, (control, inner, held) => control.lists?.(inner, held, controlFor), controlFor);
|
|
124
|
+
const swatchesOf = (list, section) => placesIn(list, section, (control, inner, held) => control.swatches?.(inner, held, controlFor), controlFor);
|
|
125
|
+
// What the handlers below work from: what the form holds now, whenever the page speaks.
|
|
126
|
+
const held = useRef({ sections, lists, listsOf, change, wordsOf, itemsOf, swatchesOf });
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
held.current = { sections, lists, listsOf, change, wordsOf, itemsOf, swatchesOf };
|
|
129
|
+
});
|
|
48
130
|
const open = (id) => {
|
|
49
131
|
setOpenIds((ids) => (ids.includes(id) ? ids : [...ids, id]));
|
|
50
132
|
focus?.open(id);
|
|
51
133
|
};
|
|
134
|
+
// A section opens with every section it is inside.
|
|
135
|
+
const reveal = (id) => {
|
|
136
|
+
const wanted = [...(locate(held.current.lists, id)?.list.inside ?? []), id];
|
|
137
|
+
setOpenIds((ids) => (wanted.every((one) => ids.includes(one)) ? ids : [...new Set([...ids, ...wanted])]));
|
|
138
|
+
};
|
|
52
139
|
// A section pressed on the page beside the form opens here.
|
|
53
140
|
useEffect(() => {
|
|
54
141
|
if (!pressed)
|
|
55
142
|
return;
|
|
56
|
-
|
|
143
|
+
reveal(pressed.id);
|
|
57
144
|
// A field inside a list is pointed at by the list it is in.
|
|
58
145
|
const [key] = pressed.field?.split('.') ?? [];
|
|
59
146
|
setPointed(key === undefined ? null : { section: pressed.id, key, at: pressed.at });
|
|
60
147
|
}, [pressed]);
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
put: (words) => withValue(section.data, inner.id, put(words)),
|
|
69
|
-
})));
|
|
70
|
-
};
|
|
71
|
-
const typable = Object.fromEntries(sections.map((section) => [section.id, wordsOf(section).map(({ place }) => place)]));
|
|
148
|
+
// So does one opened from somewhere else: a section added inside another from the page.
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (opened !== undefined)
|
|
151
|
+
reveal(opened);
|
|
152
|
+
}, [opened]);
|
|
153
|
+
const isInside = focus?.isInside === true;
|
|
154
|
+
const typable = isInside ? {} : Object.fromEntries(lists.flatMap((list) => list.sections.map((section) => [section.id, wordsOf(list, section).map(({ place }) => place)])));
|
|
72
155
|
const typableSaid = JSON.stringify(typable);
|
|
73
156
|
const setTypable = focus?.setTypable;
|
|
74
157
|
useEffect(() => setTypable?.(JSON.parse(typableSaid)), [setTypable, typableSaid]);
|
|
75
158
|
// Words typed on the page go into the form as they are typed. Several may arrive before the
|
|
76
159
|
// form is drawn again, so each builds on the one before.
|
|
77
|
-
const held = useRef({ sections, wordsOf, change });
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
held.current = { sections, wordsOf, change };
|
|
80
|
-
});
|
|
81
160
|
const onTyped = focus?.onTyped;
|
|
82
|
-
useEffect(() => onTyped?.((id,
|
|
161
|
+
useEffect(() => onTyped?.((id, place, words) => {
|
|
83
162
|
const now = held.current;
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
if (!
|
|
163
|
+
const found = locate(now.lists, id);
|
|
164
|
+
const at = found && now.wordsOf(found.list, found.section).find((candidate) => candidate.place === place);
|
|
165
|
+
if (!found || !at)
|
|
87
166
|
return;
|
|
88
|
-
const next =
|
|
89
|
-
held.current = { ...now, sections: next };
|
|
167
|
+
const next = withData(found.list, id, at.put(words));
|
|
168
|
+
held.current = { ...now, sections: next, lists: now.listsOf(next) };
|
|
90
169
|
now.change(next);
|
|
91
170
|
}), [onTyped]);
|
|
92
171
|
const nameOf = (block) => (block ? localized(block.label, locale) : messages.editor.sectionUnknown);
|
|
93
172
|
// What the page may offer on each section it shows. Hidden and retired sections are not on the page.
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
173
|
+
const offered = isInside
|
|
174
|
+
? undefined
|
|
175
|
+
: {
|
|
176
|
+
labels: {
|
|
177
|
+
up: messages.editor.pageMoveUp,
|
|
178
|
+
down: messages.editor.pageMoveDown,
|
|
179
|
+
duplicate: messages.editor.pageDuplicate,
|
|
180
|
+
remove: messages.editor.pageRemove,
|
|
181
|
+
add: messages.editor.pageAdd,
|
|
182
|
+
reorder: messages.editor.pageReorder,
|
|
183
|
+
done: messages.editor.pageReorderDone,
|
|
184
|
+
addBefore: messages.editor.pageAddBefore,
|
|
185
|
+
addAfter: messages.editor.pageAddAfter,
|
|
186
|
+
picture: messages.editor.pagePicture,
|
|
187
|
+
link: messages.editor.pageLink,
|
|
188
|
+
bold: messages.editor.richText.bold,
|
|
189
|
+
italic: messages.editor.richText.italic,
|
|
190
|
+
textLink: messages.editor.richText.link,
|
|
191
|
+
itemUp: messages.editor.pageItemUp,
|
|
192
|
+
itemDown: messages.editor.pageItemDown,
|
|
193
|
+
itemDuplicate: messages.editor.pageItemDuplicate,
|
|
194
|
+
itemRemove: messages.editor.pageItemRemove,
|
|
195
|
+
},
|
|
196
|
+
sections: Object.fromEntries(lists.flatMap((list) => list.sections.map((section, at) => [
|
|
197
|
+
section.id,
|
|
198
|
+
{
|
|
199
|
+
name: nameOf(blockOf(list.blocks, section)),
|
|
200
|
+
up: at > 0,
|
|
201
|
+
down: at < list.sections.length - 1,
|
|
202
|
+
copy: !isFull(list),
|
|
203
|
+
add: !isFull(list),
|
|
204
|
+
pictures: picturesOf(list, section).map(({ place }) => place),
|
|
205
|
+
links: linksOf(list, section).map(({ place }) => place),
|
|
206
|
+
lists: itemsOf(list, section).map((found) => ({ field: found.place, count: found.items.length, full: found.isFull })),
|
|
207
|
+
swatches: swatchesOf(list, section).map((found) => ({ field: found.place, name: localized(found.field.label, locale), ...(found.chosen !== undefined && { chosen: found.chosen }), choices: found.choices.map((choice) => ({ value: choice.value, name: choice.name(locale), colour: choice.colour })) })),
|
|
208
|
+
list: list.key,
|
|
209
|
+
group: list.group,
|
|
210
|
+
},
|
|
211
|
+
]))),
|
|
212
|
+
slots: Object.fromEntries(lists.slice(1).map((list) => [list.key, { group: list.group, empty: list.sections.length === 0, full: isFull(list) }])),
|
|
213
|
+
};
|
|
107
214
|
const offeredSaid = JSON.stringify(offered);
|
|
108
215
|
const setTools = focus?.setTools;
|
|
109
|
-
useEffect(() =>
|
|
216
|
+
useEffect(() => {
|
|
217
|
+
if (offeredSaid !== undefined)
|
|
218
|
+
setTools?.(JSON.parse(offeredSaid));
|
|
219
|
+
}, [setTools, offeredSaid]);
|
|
110
220
|
const remove = (id) => {
|
|
111
|
-
|
|
221
|
+
const found = locate(lists, id);
|
|
222
|
+
if (found)
|
|
223
|
+
change(found.list.to(found.list.sections.filter((section) => section.id !== id)));
|
|
112
224
|
setOpenIds((ids) => ids.filter((candidate) => candidate !== id));
|
|
113
225
|
};
|
|
114
226
|
const act = (id, action) => {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
if (!section)
|
|
227
|
+
const found = locate(held.current.lists, id);
|
|
228
|
+
if (!found)
|
|
118
229
|
return;
|
|
230
|
+
const { list, at, section } = found;
|
|
119
231
|
if (action === 'duplicate') {
|
|
120
|
-
|
|
121
|
-
|
|
232
|
+
if (isFull(list))
|
|
233
|
+
return;
|
|
234
|
+
const copy = copyOf(section);
|
|
235
|
+
change(list.to([...list.sections.slice(0, at + 1), copy, ...list.sections.slice(at + 1)]));
|
|
122
236
|
open(copy.id);
|
|
123
237
|
}
|
|
124
238
|
else if (action === 'hide') {
|
|
125
|
-
change(sections.map((existing) => (existing.id === id ? { ...existing, hidden: true } : existing)));
|
|
239
|
+
change(list.to(list.sections.map((existing) => (existing.id === id ? { ...existing, hidden: true } : existing))));
|
|
126
240
|
}
|
|
127
241
|
else if (action === 'show') {
|
|
128
|
-
change(sections.map((existing) => (existing.id === id ? { id: existing.id, block: existing.block, data: existing.data } : existing)));
|
|
242
|
+
change(list.to(list.sections.map((existing) => (existing.id === id ? { id: existing.id, block: existing.block, data: existing.data } : existing))));
|
|
129
243
|
}
|
|
130
244
|
else if (action === 'remove') {
|
|
131
245
|
// An empty section is removed at once: there is nothing to lose.
|
|
@@ -135,61 +249,146 @@ export function BlocksControl({ field, label, help, value, onChange, path, probl
|
|
|
135
249
|
setRemovingId(id);
|
|
136
250
|
}
|
|
137
251
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const next = [...sections];
|
|
252
|
+
const moveIn = (list, from, to) => {
|
|
253
|
+
const next = [...list.sections];
|
|
141
254
|
const [moved] = next.splice(from, 1);
|
|
142
255
|
if (moved)
|
|
143
256
|
next.splice(to, 0, moved);
|
|
144
|
-
change(next);
|
|
257
|
+
change(list.to(next));
|
|
145
258
|
};
|
|
146
|
-
const acting = useRef({
|
|
259
|
+
const acting = useRef({ act, moveIn });
|
|
147
260
|
useEffect(() => {
|
|
148
|
-
acting.current = {
|
|
261
|
+
acting.current = { act, moveIn };
|
|
149
262
|
});
|
|
263
|
+
// A button pressed on a section on the page does what the same button does here.
|
|
150
264
|
const onActed = focus?.onActed;
|
|
151
265
|
const show = focus?.open;
|
|
152
266
|
useEffect(() => onActed?.((id, action) => {
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
if (at < 0)
|
|
267
|
+
const found = locate(held.current.lists, id);
|
|
268
|
+
if (!found)
|
|
156
269
|
return;
|
|
270
|
+
const { list, at } = found;
|
|
157
271
|
if (action === 'up' || action === 'down') {
|
|
158
272
|
const to = action === 'up' ? at - 1 : at + 1;
|
|
159
|
-
if (to < 0 || to >=
|
|
273
|
+
if (to < 0 || to >= list.sections.length)
|
|
160
274
|
return;
|
|
161
|
-
|
|
275
|
+
acting.current.moveIn(list, at, to);
|
|
162
276
|
// The page is drawn again with the section in its new place, and brings it into view.
|
|
163
277
|
show?.(id);
|
|
164
278
|
}
|
|
165
279
|
else if (action === 'addBefore' || action === 'addAfter') {
|
|
166
|
-
if (
|
|
280
|
+
if (isFull(list))
|
|
167
281
|
return;
|
|
168
|
-
|
|
282
|
+
setPick({ key: list.key, at: action === 'addBefore' ? at : at + 1 });
|
|
169
283
|
setPicking(true);
|
|
170
284
|
}
|
|
171
|
-
else
|
|
172
|
-
|
|
285
|
+
else {
|
|
286
|
+
acting.current.act(id, action);
|
|
173
287
|
}
|
|
174
288
|
}), [onActed, show]);
|
|
175
|
-
//
|
|
176
|
-
const
|
|
177
|
-
useEffect(() =>
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
289
|
+
// The button of an empty place inside a section offers what can be added there.
|
|
290
|
+
const onSlotted = focus?.onSlotted;
|
|
291
|
+
useEffect(() => onSlotted?.((id, place) => {
|
|
292
|
+
const list = held.current.lists.find((candidate) => candidate.key === `${id}:${place}`);
|
|
293
|
+
if (!list || isFull(list))
|
|
294
|
+
return;
|
|
295
|
+
setPick({ key: list.key, at: null });
|
|
296
|
+
setPicking(true);
|
|
297
|
+
}), [onSlotted]);
|
|
298
|
+
// A swatch pressed on a section's bar chooses what the same swatch chooses in the form.
|
|
299
|
+
const onSwatched = focus?.onSwatched;
|
|
300
|
+
useEffect(() => onSwatched?.((id, place, chosen) => {
|
|
301
|
+
const now = held.current;
|
|
302
|
+
const found = locate(now.lists, id);
|
|
303
|
+
const swatch = found && now.swatchesOf(found.list, found.section).find((candidate) => candidate.place === place);
|
|
304
|
+
// Only a choice the field has, whatever the page said.
|
|
305
|
+
if (!found || !swatch || swatch.chosen === chosen || !swatch.choices.some((choice) => choice.value === chosen))
|
|
182
306
|
return;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
307
|
+
now.change(withData(found.list, id, swatch.put(chosen)));
|
|
308
|
+
}), [onSwatched]);
|
|
309
|
+
// The button on a picture of the page opens the window that picture is chosen in.
|
|
310
|
+
const onPictured = focus?.onPictured;
|
|
311
|
+
useEffect(() => onPictured?.((id, place) => setPicturing({ section: id, place })), [onPictured]);
|
|
312
|
+
const pictureAt = useLast(picturing);
|
|
313
|
+
const pictureIn = pictureAt ? locate(lists, pictureAt.section) : undefined;
|
|
314
|
+
const picture = pictureIn && picturesOf(pictureIn.list, pictureIn.section).find((candidate) => candidate.place === pictureAt?.place);
|
|
315
|
+
// A button on an item of a list on the page does what the list's own row does in the form.
|
|
316
|
+
const onItemActed = focus?.onItemActed;
|
|
317
|
+
useEffect(() => onItemActed?.((id, place, at, action) => {
|
|
318
|
+
const now = held.current;
|
|
319
|
+
const found = locate(now.lists, id);
|
|
320
|
+
const list = found && now.itemsOf(found.list, found.section).find((candidate) => candidate.place === place);
|
|
321
|
+
const item = list?.items[at];
|
|
322
|
+
if (!found || !list || at < 0 || at >= list.items.length)
|
|
186
323
|
return;
|
|
187
|
-
|
|
324
|
+
const next = [...list.items];
|
|
325
|
+
if (action === 'remove') {
|
|
326
|
+
next.splice(at, 1);
|
|
327
|
+
}
|
|
328
|
+
else if (action === 'duplicate') {
|
|
329
|
+
if (list.isFull)
|
|
330
|
+
return;
|
|
331
|
+
next.splice(at + 1, 0, copyOf(item));
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
const to = action === 'up' ? at - 1 : at + 1;
|
|
335
|
+
if (to < 0 || to >= next.length)
|
|
336
|
+
return;
|
|
337
|
+
next.splice(at, 1);
|
|
338
|
+
next.splice(to, 0, item);
|
|
339
|
+
}
|
|
340
|
+
now.change(withData(found.list, id, list.put(next)));
|
|
341
|
+
}), [onItemActed]);
|
|
342
|
+
// The button on a link of the page opens a window that holds the link's own field.
|
|
343
|
+
const onLinked = focus?.onLinked;
|
|
344
|
+
useEffect(() => onLinked?.((id, place) => setLinking({ section: id, place })), [onLinked]);
|
|
345
|
+
const linkAt = useLast(linking);
|
|
346
|
+
const linkIn = linkAt ? locate(lists, linkAt.section) : undefined;
|
|
347
|
+
const link = linkIn && linksOf(linkIn.list, linkIn.section).find((candidate) => candidate.place === linkAt?.place);
|
|
348
|
+
// A section dragged on the page lands where the form would put it: among the sections it was
|
|
349
|
+
// with, or in another place that takes the same blocks.
|
|
350
|
+
const onDragged = focus?.onDragged;
|
|
351
|
+
useEffect(() => onDragged?.((id, beforeId, into) => {
|
|
352
|
+
const now = held.current;
|
|
353
|
+
const found = locate(now.lists, id);
|
|
354
|
+
if (!found)
|
|
355
|
+
return;
|
|
356
|
+
const from = found.list;
|
|
357
|
+
if (into === undefined || into === from.key) {
|
|
358
|
+
const before = beforeId === null ? from.sections.length : from.sections.findIndex((section) => section.id === beforeId);
|
|
359
|
+
if (before < 0)
|
|
360
|
+
return;
|
|
361
|
+
// Taking it out first moves everything after it one place up.
|
|
362
|
+
const to = before > found.at ? before - 1 : before;
|
|
363
|
+
if (to === found.at)
|
|
364
|
+
return;
|
|
365
|
+
acting.current.moveIn(from, found.at, to);
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
const target = now.lists.find((candidate) => candidate.key === into);
|
|
369
|
+
// Only into a place that holds the same blocks, has room, and is not inside the section itself.
|
|
370
|
+
if (!target || target.group !== from.group || isFull(target) || target.inside.includes(id))
|
|
371
|
+
return;
|
|
372
|
+
const without = from.to(from.sections.filter((section) => section.id !== id));
|
|
373
|
+
const there = now.listsOf(without).find((candidate) => candidate.key === into);
|
|
374
|
+
if (!there)
|
|
375
|
+
return;
|
|
376
|
+
const before = beforeId === null ? there.sections.length : there.sections.findIndex((section) => section.id === beforeId);
|
|
377
|
+
if (before < 0)
|
|
378
|
+
return;
|
|
379
|
+
// The same block there may go by other ids: the section is held as that place holds it.
|
|
380
|
+
const carried = carriedSection(from.blocks, there.blocks, found.section, controlFor);
|
|
381
|
+
if (!carried)
|
|
382
|
+
return;
|
|
383
|
+
now.change(there.to([...there.sections.slice(0, before), carried, ...there.sections.slice(before)]));
|
|
384
|
+
}
|
|
188
385
|
show?.(id);
|
|
189
386
|
}), [onDragged, show]);
|
|
190
|
-
// The picker offers what the
|
|
387
|
+
// The picker offers what the place being added to takes.
|
|
388
|
+
const picking = lists.find((list) => list.key === pick.key) ?? own;
|
|
389
|
+
// It offers what the template describes today, under the names it files them by.
|
|
191
390
|
const byGroup = new Map();
|
|
192
|
-
for (const block of blocks) {
|
|
391
|
+
for (const block of picking?.blocks ?? []) {
|
|
193
392
|
if (block.retiredAt !== undefined)
|
|
194
393
|
continue;
|
|
195
394
|
const name = block.group ?? messages.editor.sectionOtherGroup;
|
|
@@ -204,23 +403,27 @@ export function BlocksControl({ field, label, help, value, onChange, path, probl
|
|
|
204
403
|
byGroup.set(name, options);
|
|
205
404
|
}
|
|
206
405
|
const groups = [...byGroup].map(([name, options]) => ({ id: name, label: name, options }));
|
|
207
|
-
const
|
|
406
|
+
const removingIn = removingId === null ? undefined : locate(lists, removingId);
|
|
407
|
+
const removingName = useLast(removingIn ? nameOf(blockOf(removingIn.list.blocks, removingIn.section)) : null);
|
|
208
408
|
return (_jsxs(_Fragment, { children: [_jsx(SectionList, { label: label, ...(help !== undefined && { description: help }), ...(problem !== undefined && { errorMessage: problem }), emptyText: messages.editor.sectionsEmpty, addLabel: messages.editor.sectionAdd, onAdd: () => {
|
|
209
|
-
|
|
409
|
+
setPick({ key: '', at: null });
|
|
210
410
|
setPicking(true);
|
|
211
|
-
}, isFull: isFull, openIds: openIds, revealId: pressed?.id, onOpenChange: (id, isOpen) => {
|
|
411
|
+
}, isFull: own !== undefined && isFull(own), openIds: openIds, revealId: pressed?.id, onOpenChange: (id, isOpen) => {
|
|
212
412
|
setPointed(null);
|
|
213
413
|
if (isOpen)
|
|
214
414
|
open(id);
|
|
215
415
|
else
|
|
216
416
|
setOpenIds((ids) => ids.filter((candidate) => candidate !== id));
|
|
217
|
-
}, onMove:
|
|
417
|
+
}, onMove: (from, to) => {
|
|
418
|
+
if (own)
|
|
419
|
+
moveIn(own, from, to);
|
|
420
|
+
}, onAction: act, moveUpLabel: (position) => messages.editor.sectionMoveUp(nameOf(blockOf(blocks, sections[position - 1])), position), moveDownLabel: (position) => messages.editor.sectionMoveDown(nameOf(blockOf(blocks, sections[position - 1])), position), moreLabel: (position) => messages.editor.sectionMore(nameOf(blockOf(blocks, sections[position - 1])), position), dragLabel: (position) => messages.editor.sectionDrag(nameOf(blockOf(blocks, sections[position - 1])), position), items: sections.map((section, index) => {
|
|
218
421
|
const block = blockOf(blocks, section);
|
|
219
422
|
const isRetired = block === undefined || block.retiredAt !== undefined;
|
|
220
423
|
const inner = block ? liveFields(block.fields) : [];
|
|
221
424
|
const prefix = `${path}.${index}.`;
|
|
222
425
|
const found = [...problems.keys()].filter((key) => key.startsWith(prefix)).length;
|
|
223
|
-
const summary = block ? summaryOf(block, section, (inner) => controlFor(inner.type)?.width !== 'compact') : undefined;
|
|
426
|
+
const summary = block ? summaryOf(block, section, (inner) => controlFor(inner.type)?.width !== 'compact' && controlFor(inner.type)?.pictures === undefined) : undefined;
|
|
224
427
|
const hidden = section.hidden === true;
|
|
225
428
|
return {
|
|
226
429
|
id: section.id,
|
|
@@ -240,17 +443,28 @@ export function BlocksControl({ field, label, help, value, onChange, path, probl
|
|
|
240
443
|
]),
|
|
241
444
|
{ id: 'remove', label: messages.editor.sectionRemove, icon: Trash2, tone: 'danger' },
|
|
242
445
|
],
|
|
243
|
-
content: isRetired ? (_jsx(Text, { size: "sm", tone: "muted", children: messages.editor.sectionRetiredNote })) : inner.length === 0 ? (_jsx(Text, { size: "sm", tone: "muted", children: messages.editor.sectionNoFields })) : (_jsx(FieldGrid, { fields: inner, values: section.data, onChange: (child, next) => change(sections.map((existing) => (existing.id === section.id ? { ...existing, data: withValue(existing.data, child.id, next) } : existing))), pathOf: (child) => `${prefix}${child.key}`, problems: problems, spotlight: pointed?.section === section.id ? pointed : {} })),
|
|
446
|
+
content: isRetired ? (_jsx(Text, { size: "sm", tone: "muted", children: messages.editor.sectionRetiredNote })) : inner.length === 0 ? (_jsx(Text, { size: "sm", tone: "muted", children: messages.editor.sectionNoFields })) : (_jsx(PageFocusInside, { children: _jsx(FieldGrid, { fields: inner, values: section.data, onChange: (child, next) => change(sections.map((existing) => (existing.id === section.id ? { ...existing, data: withValue(existing.data, child.id, next) } : existing))), pathOf: (child) => `${prefix}${child.key}`, problems: problems, spotlight: pointed?.section === section.id ? pointed : {} }) })),
|
|
244
447
|
};
|
|
245
448
|
}) }), _jsx(OptionPicker, { isOpen: isPicking, onOpenChange: setPicking, title: messages.editor.sectionPickerTitle, closeLabel: messages.editor.close, emptyText: messages.editor.sectionPickerEmpty, groups: groups, onChoose: (blockId) => {
|
|
246
449
|
const added = { id: crypto.randomUUID(), block: blockId, data: {} };
|
|
247
|
-
|
|
248
|
-
|
|
450
|
+
if (!picking)
|
|
451
|
+
return;
|
|
452
|
+
const at = pick.at ?? picking.sections.length;
|
|
453
|
+
change(picking.to([...picking.sections.slice(0, at), added, ...picking.sections.slice(at)]));
|
|
249
454
|
open(added.id);
|
|
250
|
-
} }), _jsx(
|
|
455
|
+
} }), pictureIn && picture && (_jsx(SiteImagePicker, { label: messages.editor.pagePicture, value: picture.name, onChange: (name) => change(withData(pictureIn.list, pictureIn.section.id, picture.put(name))), window: {
|
|
456
|
+
isOpen: picturing !== null,
|
|
457
|
+
onOpenChange: (isOpen) => {
|
|
458
|
+
if (!isOpen)
|
|
459
|
+
setPicturing(null);
|
|
460
|
+
},
|
|
461
|
+
} })), linkIn && link && (_jsx(Dialog, { isOpen: linking !== null, onOpenChange: (isOpen) => {
|
|
462
|
+
if (!isOpen)
|
|
463
|
+
setLinking(null);
|
|
464
|
+
}, title: messages.editor.pageLink, closeLabel: messages.editor.close, footer: _jsx(Button, { variant: "primary", onPress: () => setLinking(null), children: messages.editor.pageLinkDone }), children: _jsx(FieldGrid, { fields: [link.field], values: { [link.field.id]: link.link }, onChange: (_field, next) => change(withData(linkIn.list, linkIn.section.id, link.put(next))), pathOf: () => `${linkIn.list.path}.${linkIn.at}.${link.place}`, problems: problems, perRow: 1 }) })), _jsx(ConfirmDialog, { isOpen: removingId !== null, onOpenChange: (isOpen) => {
|
|
251
465
|
if (!isOpen)
|
|
252
466
|
setRemovingId(null);
|
|
253
|
-
}, title: messages.editor.sectionRemoveTitle(
|
|
467
|
+
}, title: messages.editor.sectionRemoveTitle(removingName ?? messages.editor.sectionUnknown), confirmLabel: messages.editor.sectionRemoveConfirm, cancelLabel: messages.editor.cancel, tone: "danger", onConfirm: () => {
|
|
254
468
|
if (removingId !== null)
|
|
255
469
|
remove(removingId);
|
|
256
470
|
setRemovingId(null);
|