rimecms 1.1.2 → 1.1.4
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/adapter-sqlite/relations.server.d.ts +4 -4
- package/dist/core/adapter.d.ts +4 -4
- package/dist/core/fields/types.d.ts +34 -3
- package/dist/core/fields/types.test-d.d.ts +1 -0
- package/dist/core/fields/types.test-d.js +37 -0
- package/dist/core/i18n/en/fields.d.ts +1 -1
- package/dist/core/i18n/en/fields.js +1 -1
- package/dist/core/i18n/fr/fields.d.ts +1 -1
- package/dist/core/i18n/fr/fields.js +1 -1
- package/dist/core/pipeline/hooks/set-default-values.server.d.ts +1 -1
- package/dist/core/pipeline/hooks/set-default-values.server.js +25 -30
- package/dist/core/pipeline/persist/relations/diff.server.d.ts +4 -4
- package/dist/core/pipeline/persist/relations/extract.server.js +27 -45
- package/dist/core/prototype/area/api.server.d.ts +7 -1
- package/dist/core/prototype/area/api.server.js +3 -0
- package/dist/core/prototype/area/operations/update.d.ts +2 -1
- package/dist/core/prototype/collection/api.server.d.ts +16 -3
- package/dist/core/prototype/collection/api.server.js +6 -0
- package/dist/core/prototype/collection/operations/create.d.ts +2 -1
- package/dist/core/prototype/collection/operations/delete.js +6 -4
- package/dist/core/prototype/collection/operations/duplicate.js +2 -4
- package/dist/core/prototype/collection/operations/update-by-id.d.ts +2 -1
- package/dist/core/prototype/collection/thumbnail/hooks/set-document-thumbnail.server.js +9 -15
- package/dist/core/prototype/collection/upload/disk/delete.server.js +1 -1
- package/dist/core/prototype/shared/title/hooks/set-document-title.server.js +2 -2
- package/dist/core/prototype/shared/versions/hooks/handle-new-version.server.js +17 -1
- package/dist/fields/blocks/component/focus/BlocksFocus.svelte +21 -4
- package/dist/fields/blocks/component/focus/Inspector.svelte +12 -28
- package/dist/fields/blocks/component/focus/LayersList.svelte +4 -1
- package/dist/fields/blocks/component/focus/Renders.svelte +44 -28
- package/dist/fields/blocks/component/focus/Renders.svelte.d.ts +3 -0
- package/dist/fields/blocks/component/focus/StageAdd.svelte +42 -0
- package/dist/fields/blocks/component/focus/StageAdd.svelte.d.ts +6 -0
- package/dist/fields/blocks/component/focus/focus.svelte.d.ts +7 -13
- package/dist/fields/blocks/component/focus/focus.svelte.js +38 -33
- package/dist/fields/blocks/index.d.ts +26 -5
- package/dist/fields/blocks/index.js +8 -2
- package/dist/fields/relation/component/Relation.svelte +16 -3
- package/dist/fields/relation/component/Relation.svelte.d.ts +2 -1
- package/dist/fields/relation/component/RelationInline.svelte +6 -9
- package/dist/fields/relation/fetch.d.ts +12 -0
- package/dist/fields/relation/fetch.js +27 -0
- package/dist/fields/relation/index.d.ts +16 -7
- package/dist/fields/relation/index.js +20 -4
- package/dist/fields/relation/module.server.js +15 -18
- package/dist/fields/relation/populate.js +4 -21
- package/dist/fields/relation/relation.d.ts +38 -0
- package/dist/fields/relation/relation.js +55 -0
- package/dist/fields/relation/relation.test-d.d.ts +1 -0
- package/dist/fields/relation/relation.test-d.js +10 -0
- package/dist/fields/relation/value.d.ts +2 -2
- package/dist/fields/rich-text/component/Cell.svelte +2 -2
- package/dist/fields/rich-text/json.d.ts +4 -9
- package/dist/fields/rich-text/json.js +8 -6
- package/dist/fields/types.d.ts +4 -1
- package/dist/live/Consumer.svelte +3 -3
- package/dist/live/Consumer.svelte.d.ts +2 -2
- package/dist/panel/components/sections/collection/grid/grid-item/GridItem.svelte +7 -1
- package/dist/panel/components/ui/button/button.svelte +2 -3
- package/dist/panel/context/documentForm.svelte.js +2 -2
- package/dist/panel/style/index.css +4 -3
- package/dist/panel/style/palette.css +3 -3
- package/dist/panel/style/scheme.css +1 -0
- package/dist/public.d.ts +3 -3
- package/dist/public.js +3 -3
- package/dist/types.d.ts +1 -1
- package/dist/util/types.d.ts +1 -1
- package/dist/util/types.js +1 -1
- package/package.json +1 -1
- package/dist/fields/blocks/component/focus/StagePlaceholder.svelte +0 -86
- package/dist/fields/blocks/component/focus/StagePlaceholder.svelte.d.ts +0 -8
- package/dist/fields/relation/util.d.ts +0 -57
- package/dist/fields/relation/util.js +0 -86
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RimeError } from '../../../../errors/index.js';
|
|
2
|
+
import { buildConfigMap } from '../../../../pipeline/config-map/index.js';
|
|
2
3
|
import { Hooks } from '../../../../pipeline/define-hook.js';
|
|
3
4
|
import { copyLocales } from '../../../../locale/copy.server.js';
|
|
4
5
|
import { moveEditLock } from '../../metas/lock.server.js';
|
|
@@ -6,7 +7,9 @@ import { fileForDocument } from '../../../collection/upload/util/converter.serve
|
|
|
6
7
|
import { VERSIONS_STATUS } from '../constant.js';
|
|
7
8
|
import { withVersionsSuffix } from '../naming.js';
|
|
8
9
|
import { VersionOperations } from '../strategy.js';
|
|
9
|
-
import {
|
|
10
|
+
import { RelationFieldBuilder } from '../../../../../fields/relation/index.js';
|
|
11
|
+
import { Relation } from '../../../../../fields/relation/relation.js';
|
|
12
|
+
import { getValueAtPath, isObjectLiteral, omit, recursiveRemoveKeys, setValueAtPath } from '../../../../../util/object.js';
|
|
10
13
|
import { retireAutoSaves } from '../retire-auto-saves.server.js';
|
|
11
14
|
import { fallbackDataFromOriginal } from './fallback-data-from-original.js';
|
|
12
15
|
/**
|
|
@@ -185,9 +188,22 @@ async function prepareDataForNewVersion(args) {
|
|
|
185
188
|
if (!data.status) {
|
|
186
189
|
data.status = VERSIONS_STATUS.DRAFT;
|
|
187
190
|
}
|
|
191
|
+
// A relation sent back as documents, read at depth 1, keeps what it points to: the strip
|
|
192
|
+
// below takes every `id`, a document's own included.
|
|
193
|
+
for (const [path, field] of Object.entries(buildConfigMap(data, config.fields))) {
|
|
194
|
+
if (!(field instanceof RelationFieldBuilder))
|
|
195
|
+
continue;
|
|
196
|
+
const value = getValueAtPath(path, data);
|
|
197
|
+
if (!Array.isArray(value))
|
|
198
|
+
continue;
|
|
199
|
+
const refs = value.map((entry) => isDocument(entry) ? { relationTo: field.get.relationTo, documentId: entry.id } : entry);
|
|
200
|
+
data = setValueAtPath(path, data, refs);
|
|
201
|
+
}
|
|
188
202
|
// Remove ownerId and id props from data this force new relation/blocks creations
|
|
189
203
|
data = recursiveRemoveKeys('ownerId', 'id').from(data);
|
|
190
204
|
data.ownerId = originalDoc.id;
|
|
191
205
|
delete data.id;
|
|
192
206
|
return data;
|
|
193
207
|
}
|
|
208
|
+
/** An object with its own `id` that is not a ref: a document, as a read at depth 1 hands it back. */
|
|
209
|
+
const isDocument = (entry) => isObjectLiteral(entry) && !Relation.isRef(entry) && typeof entry.id === 'string';
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
import Palette from './Palette.svelte';
|
|
22
22
|
import Inspector from './Inspector.svelte';
|
|
23
23
|
import Renders from './Renders.svelte';
|
|
24
|
+
import StageAdd from './StageAdd.svelte';
|
|
24
25
|
|
|
25
26
|
const { form }: { form: DocumentFormContext } = $props();
|
|
26
27
|
|
|
@@ -53,6 +54,13 @@
|
|
|
53
54
|
count === 1 ? t__('fields.blocks_count', '1') : t__('fields.blocks_count|m|p', String(count))
|
|
54
55
|
);
|
|
55
56
|
|
|
57
|
+
/**
|
|
58
|
+
* "Add a block or type /" under the stage, while the home list has blocks. Empty, the open list
|
|
59
|
+
* has its message, and a nested one its `+`.
|
|
60
|
+
*/
|
|
61
|
+
const homeList = $derived(focus.homeList());
|
|
62
|
+
const showAdd = $derived(!focus.locked && !!homeList && form.blocks.list(homeList).length > 0);
|
|
63
|
+
|
|
56
64
|
let confirmRemove = $state(false);
|
|
57
65
|
|
|
58
66
|
/**
|
|
@@ -292,7 +300,7 @@
|
|
|
292
300
|
keys: '/',
|
|
293
301
|
hidden: true,
|
|
294
302
|
when: () => free() && editing,
|
|
295
|
-
run: focus.pick
|
|
303
|
+
run: () => focus.pick()
|
|
296
304
|
},
|
|
297
305
|
{
|
|
298
306
|
id: 'blocks.back',
|
|
@@ -414,6 +422,9 @@
|
|
|
414
422
|
{#key focus.path}
|
|
415
423
|
<Renders {form} list={stageList} only={focus.narrowedRow?.index} onRemove={requestRemove} />
|
|
416
424
|
{/key}
|
|
425
|
+
{#if showAdd && homeList}
|
|
426
|
+
<StageAdd list={homeList} />
|
|
427
|
+
{/if}
|
|
417
428
|
</section>
|
|
418
429
|
|
|
419
430
|
{#if narrow}
|
|
@@ -434,8 +445,8 @@
|
|
|
434
445
|
|
|
435
446
|
<BlockPicker
|
|
436
447
|
bind:open={() => focus.picking, (open) => (focus.picking = open)}
|
|
437
|
-
types={
|
|
438
|
-
onpick={(block) => focus.
|
|
448
|
+
types={focus.pickTypes()}
|
|
449
|
+
onpick={(block) => focus.insertPicked(block.name)}
|
|
439
450
|
/>
|
|
440
451
|
|
|
441
452
|
<Dialog.Root bind:open={confirmRemove}>
|
|
@@ -571,11 +582,17 @@
|
|
|
571
582
|
min-height: 0;
|
|
572
583
|
}
|
|
573
584
|
|
|
574
|
-
.rz-blocks-focus__renders > :global(.rz-renders)
|
|
585
|
+
.rz-blocks-focus__renders > :global(.rz-renders),
|
|
586
|
+
.rz-blocks-focus__renders > :global(.rz-stage-add) {
|
|
575
587
|
max-width: var(--rz-document-width, 60rem);
|
|
576
588
|
margin-inline: auto;
|
|
577
589
|
}
|
|
578
590
|
|
|
591
|
+
/* Under the blocks, one gap further down. */
|
|
592
|
+
.rz-blocks-focus__renders > :global(.rz-stage-add) {
|
|
593
|
+
margin-top: var(--rz-size-3);
|
|
594
|
+
}
|
|
595
|
+
|
|
579
596
|
.rz-blocks-focus__panel,
|
|
580
597
|
.rz-blocks-focus__renders {
|
|
581
598
|
min-width: 0;
|
|
@@ -30,12 +30,6 @@
|
|
|
30
30
|
? t__('fields.blocks_count', '1')
|
|
31
31
|
: t__('fields.blocks_count|m|p', String(count));
|
|
32
32
|
};
|
|
33
|
-
|
|
34
|
-
/** Opens the picker on the list: the block picked goes at its end. */
|
|
35
|
-
function addTo(list: string) {
|
|
36
|
-
focus.selectList(list);
|
|
37
|
-
focus.pick();
|
|
38
|
-
}
|
|
39
33
|
</script>
|
|
40
34
|
|
|
41
35
|
{#if row && rendered}
|
|
@@ -73,15 +67,15 @@
|
|
|
73
67
|
<span>{child.label}</span>
|
|
74
68
|
<span class="rz-inspector__count">{countOf(child.list)}</span>
|
|
75
69
|
{#if !focus.locked}
|
|
76
|
-
<
|
|
77
|
-
type="button"
|
|
70
|
+
<Button
|
|
78
71
|
class="rz-inspector__add"
|
|
72
|
+
variant="secondary"
|
|
79
73
|
title={t__('fields.add_block')}
|
|
80
74
|
aria-label={t__('fields.add_block')}
|
|
81
|
-
onclick={() =>
|
|
75
|
+
onclick={() => focus.pick(child.list)}
|
|
82
76
|
>
|
|
83
77
|
<Plus size={14} />
|
|
84
|
-
</
|
|
78
|
+
</Button>
|
|
85
79
|
{/if}
|
|
86
80
|
</li>
|
|
87
81
|
{/each}
|
|
@@ -121,6 +115,10 @@
|
|
|
121
115
|
h3 {
|
|
122
116
|
font-variation-settings: 'wght' 500;
|
|
123
117
|
font-weight: 500;
|
|
118
|
+
overflow: hidden;
|
|
119
|
+
display: -webkit-box;
|
|
120
|
+
-webkit-box-orient: vertical;
|
|
121
|
+
-webkit-line-clamp: 1;
|
|
124
122
|
font-size: var(--rz-text-md);
|
|
125
123
|
white-space: nowrap;
|
|
126
124
|
}
|
|
@@ -172,6 +170,10 @@
|
|
|
172
170
|
display: flex;
|
|
173
171
|
align-items: center;
|
|
174
172
|
gap: var(--rz-size-2);
|
|
173
|
+
|
|
174
|
+
:global(.rz-inspector__add) {
|
|
175
|
+
flex-shrink: 0;
|
|
176
|
+
}
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
/* On the right, then the button. */
|
|
@@ -179,22 +181,4 @@
|
|
|
179
181
|
margin-left: auto;
|
|
180
182
|
color: var(--rz-fg-subtle);
|
|
181
183
|
}
|
|
182
|
-
|
|
183
|
-
.rz-inspector__add {
|
|
184
|
-
display: grid;
|
|
185
|
-
place-items: center;
|
|
186
|
-
width: var(--rz-size-6);
|
|
187
|
-
height: var(--rz-size-6);
|
|
188
|
-
flex-shrink: 0;
|
|
189
|
-
border-radius: var(--rz-radius-sm);
|
|
190
|
-
color: var(--rz-fg-subtle);
|
|
191
|
-
&:hover {
|
|
192
|
-
color: var(--rz-fg);
|
|
193
|
-
background-color: var(--rz-bg-hover);
|
|
194
|
-
}
|
|
195
|
-
&:focus-visible {
|
|
196
|
-
outline: 2px solid var(--rz-accent-border);
|
|
197
|
-
outline-offset: 2px;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
184
|
</style>
|
|
@@ -155,8 +155,10 @@
|
|
|
155
155
|
/* A focused input: an accent edge and a soft halo. */
|
|
156
156
|
|
|
157
157
|
/* An input with an error. */
|
|
158
|
-
.
|
|
158
|
+
/* One column as wide as the panel: a long title ends in an ellipsis instead of widening it. */
|
|
159
|
+
.rz-layers__list {
|
|
159
160
|
display: grid;
|
|
161
|
+
grid-template-columns: minmax(0, 1fr);
|
|
160
162
|
gap: 1px;
|
|
161
163
|
min-height: var(--rz-size-2);
|
|
162
164
|
}
|
|
@@ -280,6 +282,7 @@
|
|
|
280
282
|
|
|
281
283
|
.rz-layers__title {
|
|
282
284
|
flex: 1;
|
|
285
|
+
min-width: 0;
|
|
283
286
|
overflow: hidden;
|
|
284
287
|
text-overflow: ellipsis;
|
|
285
288
|
white-space: nowrap;
|
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { t__ } from '../../../../core/i18n/index.js';
|
|
3
|
+
import { Button } from '../../../../panel/components/ui/button/index.js';
|
|
4
|
+
import { parseBlockPath, shiftListPath } from '../../../../panel/context/blocks-ops.js';
|
|
3
5
|
import type { DocumentFormContext } from '../../../../panel/context/documentForm.svelte.js';
|
|
4
|
-
import { shiftListPath } from '../../../../panel/context/blocks-ops.js';
|
|
5
6
|
import { useSortable } from '../../../../panel/util/Sortable.js';
|
|
6
|
-
import { ArrowDown, ArrowUp, CopyPlus, Focus, Trash2 } from '@lucide/svelte';
|
|
7
|
+
import { ArrowDown, ArrowUp, CopyPlus, Focus, Plus, Trash2 } from '@lucide/svelte';
|
|
7
8
|
import type Sortable from 'sortablejs';
|
|
8
9
|
import DefaultRender from './DefaultRender.svelte';
|
|
9
10
|
import { getBlocksFocusContext } from './focus.svelte.js';
|
|
10
11
|
import Renders from './Renders.svelte';
|
|
11
|
-
import StagePlaceholder from './StagePlaceholder.svelte';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* `only` narrows the list to the block at that index, focus on one block: it does not move
|
|
15
15
|
* then, its own lists do. `onRemove` asks first when the block holds blocks of its own.
|
|
16
|
+
* `holder` is the block a nested list belongs to, and `class` what its render names it.
|
|
16
17
|
*/
|
|
17
|
-
type Props = {
|
|
18
|
-
|
|
18
|
+
type Props = {
|
|
19
|
+
form: DocumentFormContext;
|
|
20
|
+
list: string;
|
|
21
|
+
only?: number;
|
|
22
|
+
holder?: string;
|
|
23
|
+
class?: string;
|
|
24
|
+
onRemove: () => void;
|
|
25
|
+
};
|
|
26
|
+
const { form, list, only, holder, class: className, onRemove }: Props = $props();
|
|
19
27
|
|
|
20
28
|
const focus = getBlocksFocusContext()!;
|
|
21
29
|
const rows = $derived(
|
|
@@ -34,22 +42,22 @@
|
|
|
34
42
|
}
|
|
35
43
|
|
|
36
44
|
/**
|
|
37
|
-
*
|
|
38
|
-
* block
|
|
45
|
+
* The `+` at the end of a nested list. An empty list always has it; one with blocks while its
|
|
46
|
+
* block, or one of its own blocks, is selected.
|
|
39
47
|
*/
|
|
40
|
-
|
|
48
|
+
const showAdd = $derived(
|
|
49
|
+
!!holder &&
|
|
50
|
+
!focus.locked &&
|
|
51
|
+
(!rows.length ||
|
|
52
|
+
focus.selection.some((path) => path === holder || parseBlockPath(path).list === list))
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
/** Opens the picker on this list; the block picked goes at its end. */
|
|
56
|
+
function add(event: MouseEvent) {
|
|
41
57
|
event.stopPropagation();
|
|
42
|
-
focus.
|
|
58
|
+
focus.pick(list);
|
|
43
59
|
}
|
|
44
60
|
|
|
45
|
-
/**
|
|
46
|
-
* "Type / to add a block" at the end of the list the next block goes to, so one on the stage.
|
|
47
|
-
* An empty open list has its own message instead.
|
|
48
|
-
*/
|
|
49
|
-
const placeholder = $derived(
|
|
50
|
-
!focus.locked && list === focus.insertList() && (rows.length > 0 || list !== focus.path)
|
|
51
|
-
);
|
|
52
|
-
|
|
53
61
|
/** The one block the controls act on: selected alone, and the form open to changes. */
|
|
54
62
|
const controlled = (rowPath: string) =>
|
|
55
63
|
!focus.locked && focus.selection.length === 1 && focus.selection[0] === rowPath;
|
|
@@ -118,23 +126,21 @@
|
|
|
118
126
|
render puts where they go; a block without a render is a row with them under it.
|
|
119
127
|
-->
|
|
120
128
|
<div
|
|
121
|
-
class="rz-renders"
|
|
129
|
+
class="rz-renders {className ?? ''}"
|
|
122
130
|
data-list={list}
|
|
123
131
|
data-empty={rows.length ? undefined : ''}
|
|
124
|
-
role="presentation"
|
|
125
|
-
onclick={selectList}
|
|
126
132
|
use:sortableList
|
|
127
133
|
>
|
|
128
134
|
{#each rows as row (row.block.id)}
|
|
129
135
|
{@const config = row.config}
|
|
130
136
|
{@const Render = config?.render}
|
|
131
|
-
{#snippet nested(name?: string)}
|
|
137
|
+
{#snippet nested(name?: string, options?: { class?: string })}
|
|
132
138
|
{#each row.children.filter((child) => !name || child.builder.name === name) as child (child.builder.name)}
|
|
133
139
|
<!-- All of them at once, and more than one: each under its name. -->
|
|
134
140
|
{#if !name && row.children.length > 1}
|
|
135
141
|
<p class="rz-renders__list-label">{child.label}</p>
|
|
136
142
|
{/if}
|
|
137
|
-
<Renders {form} list={child.list} {onRemove} />
|
|
143
|
+
<Renders {form} list={child.list} holder={row.path} class={options?.class} {onRemove} />
|
|
138
144
|
{/each}
|
|
139
145
|
{/snippet}
|
|
140
146
|
<div
|
|
@@ -152,7 +158,7 @@
|
|
|
152
158
|
}
|
|
153
159
|
}}
|
|
154
160
|
>
|
|
155
|
-
{#if controlled(row.path) && !focus.isNarrowedBlock(row.path)}
|
|
161
|
+
{#if controlled(row.path) && !focus.isNarrowedBlock(row.path) && config?.controls !== false}
|
|
156
162
|
<!-- Above it: move, duplicate, remove. A click on the block already opens its fields. -->
|
|
157
163
|
<div class="rz-renders__toolbar">
|
|
158
164
|
<button
|
|
@@ -225,8 +231,18 @@
|
|
|
225
231
|
<p class="rz-renders__empty">{t__('fields.no_blocks_yet')}</p>
|
|
226
232
|
{/if}
|
|
227
233
|
{/each}
|
|
228
|
-
{#if
|
|
229
|
-
|
|
234
|
+
{#if showAdd}
|
|
235
|
+
<!-- After the blocks, in the list's own layout: the render styles `.rz-renders__add`. -->
|
|
236
|
+
<Button
|
|
237
|
+
class="rz-renders__add"
|
|
238
|
+
variant="secondary"
|
|
239
|
+
size="icon-sm"
|
|
240
|
+
title={t__('fields.add_block')}
|
|
241
|
+
aria-label={t__('fields.add_block')}
|
|
242
|
+
onclick={add}
|
|
243
|
+
>
|
|
244
|
+
<Plus size={14} />
|
|
245
|
+
</Button>
|
|
230
246
|
{/if}
|
|
231
247
|
</div>
|
|
232
248
|
|
|
@@ -251,8 +267,9 @@
|
|
|
251
267
|
min-height: var(--rz-size-8);
|
|
252
268
|
}
|
|
253
269
|
|
|
254
|
-
/* An empty nested list: somewhere to drop a type. */
|
|
270
|
+
/* An empty nested list: somewhere to drop a type, its `+` inside. */
|
|
255
271
|
.rz-renders[data-empty]:not([data-list='']) {
|
|
272
|
+
padding: var(--rz-size-2);
|
|
256
273
|
border: 1px dashed var(--rz-border-strong);
|
|
257
274
|
border-radius: var(--rz-radius-md);
|
|
258
275
|
}
|
|
@@ -260,7 +277,6 @@
|
|
|
260
277
|
/* A block under the pointer: a dashed frame, on the innermost block only. */
|
|
261
278
|
.rz-renders__item {
|
|
262
279
|
position: relative;
|
|
263
|
-
border-radius: var(--rz-radius-md);
|
|
264
280
|
outline: 1px dashed transparent;
|
|
265
281
|
outline-offset: 3px;
|
|
266
282
|
cursor: pointer;
|
|
@@ -277,7 +293,7 @@
|
|
|
277
293
|
|
|
278
294
|
/* The selected block: an accent frame around it. */
|
|
279
295
|
.rz-renders__item[data-selected] {
|
|
280
|
-
outline:
|
|
296
|
+
outline: 1px solid oklch(from var(--rz-accent) l c h / 0.6);
|
|
281
297
|
outline-offset: 3px;
|
|
282
298
|
}
|
|
283
299
|
|
|
@@ -3,11 +3,14 @@ import Renders from './Renders.svelte';
|
|
|
3
3
|
/**
|
|
4
4
|
* `only` narrows the list to the block at that index, focus on one block: it does not move
|
|
5
5
|
* then, its own lists do. `onRemove` asks first when the block holds blocks of its own.
|
|
6
|
+
* `holder` is the block a nested list belongs to, and `class` what its render names it.
|
|
6
7
|
*/
|
|
7
8
|
type Props = {
|
|
8
9
|
form: DocumentFormContext;
|
|
9
10
|
list: string;
|
|
10
11
|
only?: number;
|
|
12
|
+
holder?: string;
|
|
13
|
+
class?: string;
|
|
11
14
|
onRemove: () => void;
|
|
12
15
|
};
|
|
13
16
|
declare const Renders: import("svelte").Component<Props, {}, "">;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { t__ } from '../../../../core/i18n/index.js';
|
|
3
|
+
import { Button } from '../../../../panel/components/ui/button/index.js';
|
|
4
|
+
import Kbd from '../../../../panel/components/ui/kbd/Kbd.svelte';
|
|
5
|
+
import { Plus } from '@lucide/svelte';
|
|
6
|
+
import { getBlocksFocusContext } from './focus.svelte.js';
|
|
7
|
+
|
|
8
|
+
type Props = { list: string };
|
|
9
|
+
const { list }: Props = $props();
|
|
10
|
+
|
|
11
|
+
const focus = getBlocksFocusContext()!;
|
|
12
|
+
|
|
13
|
+
/** "Add a block or type $1", cut around the key. */
|
|
14
|
+
const KEY = '\u0000';
|
|
15
|
+
const [before, after] = $derived(t__('fields.add_block_or_type', KEY).split(KEY));
|
|
16
|
+
|
|
17
|
+
/** Adds at the end of the list, as its `+` does. */
|
|
18
|
+
function add(event: MouseEvent) {
|
|
19
|
+
event.stopPropagation();
|
|
20
|
+
focus.pick(list);
|
|
21
|
+
}
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<!-- Under the blocks: a button that adds one, and the key that does too. -->
|
|
25
|
+
<div class="rz-stage-add">
|
|
26
|
+
<Button variant="ghost" icon={Plus} onclick={add}>
|
|
27
|
+
{before}<Kbd keys="/" />{after}
|
|
28
|
+
</Button>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<style>
|
|
32
|
+
/* Quiet until hovered. */
|
|
33
|
+
.rz-stage-add {
|
|
34
|
+
--rz-button-ghost-fg: var(--rz-fg-subtle);
|
|
35
|
+
:global(.rz-button--ghost:hover) {
|
|
36
|
+
color: var(--rz-fg);
|
|
37
|
+
}
|
|
38
|
+
:global(.rz-kbd) {
|
|
39
|
+
margin-inline: var(--rz-size-0-5);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
</style>
|
|
@@ -37,7 +37,7 @@ export type LayerRow = {
|
|
|
37
37
|
* `?focus=` in the address reopens it.
|
|
38
38
|
*
|
|
39
39
|
* The stage shows the open list, or the one block the path ends on and the lists it holds. The
|
|
40
|
-
* selection is a block,
|
|
40
|
+
* selection is a block, or nothing, which is the root node of the layers.
|
|
41
41
|
*
|
|
42
42
|
* A focus opened from the field rides in `page.state`, one history entry per `open`, so Escape
|
|
43
43
|
* and the back button go up the same levels. One opened by the address has no history entry of
|
|
@@ -55,18 +55,15 @@ export declare function setBlocksFocusContext(form: DocumentFormContext): {
|
|
|
55
55
|
/** Turns the panel to the selected block's fields, and opens it where it is a sheet. */
|
|
56
56
|
inspect(): void;
|
|
57
57
|
picking: boolean;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*/
|
|
62
|
-
pick(): void;
|
|
58
|
+
pick: (list?: string) => void;
|
|
59
|
+
pickTypes: () => import("../../index.js").BlockBuilder[];
|
|
60
|
+
insertPicked: (type: string) => string | null;
|
|
63
61
|
/** The block the stage is narrowed to, when the path ends on one. */
|
|
64
62
|
readonly narrowedRow: LayerRow | null;
|
|
65
63
|
/** Nothing selected: the root node, and the whole list on the stage. */
|
|
66
64
|
readonly rootSelected: boolean;
|
|
67
65
|
rootLabel: () => string;
|
|
68
66
|
selectRoot: () => void;
|
|
69
|
-
selectList: (list: string) => void;
|
|
70
67
|
breadcrumb: () => Crumb[];
|
|
71
68
|
isSelected: (rowPath: string) => boolean;
|
|
72
69
|
isNarrowedBlock: (rowPath: string) => boolean;
|
|
@@ -114,18 +111,15 @@ export declare const getBlocksFocusContext: () => {
|
|
|
114
111
|
/** Turns the panel to the selected block's fields, and opens it where it is a sheet. */
|
|
115
112
|
inspect(): void;
|
|
116
113
|
picking: boolean;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*/
|
|
121
|
-
pick(): void;
|
|
114
|
+
pick: (list?: string) => void;
|
|
115
|
+
pickTypes: () => import("../../index.js").BlockBuilder[];
|
|
116
|
+
insertPicked: (type: string) => string | null;
|
|
122
117
|
/** The block the stage is narrowed to, when the path ends on one. */
|
|
123
118
|
readonly narrowedRow: LayerRow | null;
|
|
124
119
|
/** Nothing selected: the root node, and the whole list on the stage. */
|
|
125
120
|
readonly rootSelected: boolean;
|
|
126
121
|
rootLabel: () => string;
|
|
127
122
|
selectRoot: () => void;
|
|
128
|
-
selectList: (list: string) => void;
|
|
129
123
|
breadcrumb: () => Crumb[];
|
|
130
124
|
isSelected: (rowPath: string) => boolean;
|
|
131
125
|
isNarrowedBlock: (rowPath: string) => boolean;
|
|
@@ -19,7 +19,7 @@ const endsOnBlock = (target) => /\.\d+$/.test(target);
|
|
|
19
19
|
* `?focus=` in the address reopens it.
|
|
20
20
|
*
|
|
21
21
|
* The stage shows the open list, or the one block the path ends on and the lists it holds. The
|
|
22
|
-
* selection is a block,
|
|
22
|
+
* selection is a block, or nothing, which is the root node of the layers.
|
|
23
23
|
*
|
|
24
24
|
* A focus opened from the field rides in `page.state`, one history entry per `open`, so Escape
|
|
25
25
|
* and the back button go up the same levels. One opened by the address has no history entry of
|
|
@@ -33,14 +33,14 @@ export function setBlocksFocusContext(form) {
|
|
|
33
33
|
/** Narrowed by the address, the block is selected and its fields show. */
|
|
34
34
|
const narrowedFromUrl = !!initial && endsOnBlock(initial);
|
|
35
35
|
let selection = $state(narrowedFromUrl ? [initial] : []);
|
|
36
|
-
/** A list inside the stage, `sections.1.items`, selected while no block is. */
|
|
37
|
-
let selectedList = $state(null);
|
|
38
36
|
/** The panel's tab: the tree of blocks, the selected block's fields, the types to add. */
|
|
39
37
|
let tab = $state(narrowedFromUrl ? 'inspector' : 'layers');
|
|
40
38
|
/** Counts the asks to show a block's fields, so a closed panel knows to open. */
|
|
41
39
|
let inspected = $state(0);
|
|
42
40
|
/** The picker of types to add is open. */
|
|
43
41
|
let picking = $state(false);
|
|
42
|
+
/** The list a `+` opened the picker on. Without one, the picker adds where the next insert goes. */
|
|
43
|
+
let pickList = $state(null);
|
|
44
44
|
/** The folded rows, by block id: a fold stays on its block when the block moves. */
|
|
45
45
|
const collapsed = new SvelteSet();
|
|
46
46
|
/** The entries focus pushed, up to the one on screen. */
|
|
@@ -49,7 +49,6 @@ export function setBlocksFocusContext(form) {
|
|
|
49
49
|
if (path)
|
|
50
50
|
return;
|
|
51
51
|
selection = [];
|
|
52
|
-
selectedList = null;
|
|
53
52
|
collapsed.clear();
|
|
54
53
|
// Closed back onto the entry the address opened: the address drops its focus too.
|
|
55
54
|
if (page.url.searchParams.has(FOCUS_PARAM))
|
|
@@ -71,7 +70,6 @@ export function setBlocksFocusContext(form) {
|
|
|
71
70
|
* `sections.1`: that block selected, its fields in the panel.
|
|
72
71
|
*/
|
|
73
72
|
function open(target, selected) {
|
|
74
|
-
selectedList = null;
|
|
75
73
|
if (endsOnBlock(target)) {
|
|
76
74
|
selection = [target];
|
|
77
75
|
tab = 'inspector';
|
|
@@ -258,7 +256,6 @@ export function setBlocksFocusContext(form) {
|
|
|
258
256
|
/* ----------------------------------------------------------- selection */
|
|
259
257
|
const currentAt = () => (selection[0] ? parseBlockPath(selection[0]) : null);
|
|
260
258
|
function select(rowPath, options = {}) {
|
|
261
|
-
selectedList = null;
|
|
262
259
|
if (options.extend && selection.length) {
|
|
263
260
|
selection = selection.includes(rowPath)
|
|
264
261
|
? selection.filter((item) => item !== rowPath)
|
|
@@ -283,20 +280,7 @@ export function setBlocksFocusContext(form) {
|
|
|
283
280
|
}
|
|
284
281
|
const selectRoot = () => {
|
|
285
282
|
selection = [];
|
|
286
|
-
selectedList = null;
|
|
287
283
|
};
|
|
288
|
-
/** A list the blocks of the stage hold: `sections.1.items` under `sections`. */
|
|
289
|
-
const isNestedList = (list) => !!path && list.startsWith(`${path}.`) && list !== homeList() && !!builderOf(list);
|
|
290
|
-
/**
|
|
291
|
-
* Selects a list: the next block goes at its end. The home list, or a list outside the stage,
|
|
292
|
-
* selects the root.
|
|
293
|
-
*/
|
|
294
|
-
function selectList(list) {
|
|
295
|
-
selection = [];
|
|
296
|
-
selectedList = isNestedList(list) ? list : null;
|
|
297
|
-
}
|
|
298
|
-
/** The selected list, while no block is selected and the stage still holds it. */
|
|
299
|
-
const listSelected = () => !selection.length && selectedList && isNestedList(selectedList) ? selectedList : null;
|
|
300
284
|
/* ---------------------------------------------------------- operations */
|
|
301
285
|
/** The narrowed block itself: it stays where it is, and what is added goes inside it. */
|
|
302
286
|
const isNarrowedBlock = (rowPath) => !!narrowed && rowPath === path;
|
|
@@ -305,14 +289,14 @@ export function setBlocksFocusContext(form) {
|
|
|
305
289
|
const current = currentAt();
|
|
306
290
|
return current && !isNarrowedBlock(blockPath(current)) ? current : null;
|
|
307
291
|
}
|
|
308
|
-
/** The list the next insert goes to: the selected block's,
|
|
309
|
-
const insertList = () => movableAt()?.list ??
|
|
310
|
-
/** Where the palette inserts: after the selected block, else at the end of the list. */
|
|
292
|
+
/** The list the next insert goes to: the selected block's, else the home list. */
|
|
293
|
+
const insertList = () => movableAt()?.list ?? homeList();
|
|
294
|
+
/** Where the palette inserts: after the selected block, else at the end of the home list. */
|
|
311
295
|
function insertionPoint() {
|
|
312
296
|
const current = movableAt();
|
|
313
297
|
if (current)
|
|
314
298
|
return { list: current.list, index: current.index + 1 };
|
|
315
|
-
const list =
|
|
299
|
+
const list = homeList();
|
|
316
300
|
if (!list)
|
|
317
301
|
return null;
|
|
318
302
|
return { list, index: form.blocks.list(list).length };
|
|
@@ -327,6 +311,33 @@ export function setBlocksFocusContext(form) {
|
|
|
327
311
|
select(blockPath(at));
|
|
328
312
|
return id;
|
|
329
313
|
}
|
|
314
|
+
/** Where the picker adds: the end of the list a `+` opened it on, else the next insert's place. */
|
|
315
|
+
function pickPoint() {
|
|
316
|
+
if (!pickList)
|
|
317
|
+
return insertionPoint();
|
|
318
|
+
return { list: pickList, index: form.blocks.list(pickList).length };
|
|
319
|
+
}
|
|
320
|
+
/** The types the picker offers. */
|
|
321
|
+
function pickTypes() {
|
|
322
|
+
const at = pickPoint();
|
|
323
|
+
return at ? (builderOf(at.list)?.get.blocks ?? []) : [];
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Opens the picker of types to add, on `list` or where the next insert goes. A list that takes
|
|
327
|
+
* one type gets it at once.
|
|
328
|
+
*/
|
|
329
|
+
function pick(list) {
|
|
330
|
+
if (locked)
|
|
331
|
+
return;
|
|
332
|
+
pickList = list ?? null;
|
|
333
|
+
const types = pickTypes();
|
|
334
|
+
if (types.length === 1)
|
|
335
|
+
insertPicked(types[0].name);
|
|
336
|
+
else
|
|
337
|
+
picking = true;
|
|
338
|
+
}
|
|
339
|
+
/** Adds the type picked where the picker was opened. */
|
|
340
|
+
const insertPicked = (type) => insertType(type, pickPoint());
|
|
330
341
|
function duplicateSelection() {
|
|
331
342
|
const current = movableAt();
|
|
332
343
|
if (locked || !current)
|
|
@@ -448,25 +459,19 @@ export function setBlocksFocusContext(form) {
|
|
|
448
459
|
set picking(value) {
|
|
449
460
|
picking = value;
|
|
450
461
|
},
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
*/
|
|
455
|
-
pick() {
|
|
456
|
-
if (!locked)
|
|
457
|
-
picking = true;
|
|
458
|
-
},
|
|
462
|
+
pick,
|
|
463
|
+
pickTypes,
|
|
464
|
+
insertPicked,
|
|
459
465
|
/** The block the stage is narrowed to, when the path ends on one. */
|
|
460
466
|
get narrowedRow() {
|
|
461
467
|
return narrowed ? (rootRows()[0] ?? null) : null;
|
|
462
468
|
},
|
|
463
469
|
/** Nothing selected: the root node, and the whole list on the stage. */
|
|
464
470
|
get rootSelected() {
|
|
465
|
-
return selection.length === 0
|
|
471
|
+
return selection.length === 0;
|
|
466
472
|
},
|
|
467
473
|
rootLabel,
|
|
468
474
|
selectRoot,
|
|
469
|
-
selectList,
|
|
470
475
|
breadcrumb,
|
|
471
476
|
isSelected: (rowPath) => selection.includes(rowPath),
|
|
472
477
|
isNarrowedBlock,
|