rimecms 1.1.1 → 1.1.3
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/read.server.js +4 -4
- package/dist/adapter-sqlite/table.server.d.ts +3 -6
- package/dist/adapter-sqlite/table.server.js +3 -6
- package/dist/adapter-sqlite/transform.server.d.ts +1 -1
- package/dist/adapter-sqlite/transform.server.js +3 -2
- package/dist/adapter-sqlite/write.server.d.ts +13 -15
- package/dist/adapter-sqlite/write.server.js +15 -17
- package/dist/core/adapter.d.ts +19 -33
- package/dist/core/adapter.js +0 -12
- package/dist/core/auth/augment.js +2 -1
- package/dist/core/auth/hooks/augment-fields-password.server.d.ts +2 -2
- package/dist/core/auth/hooks/augment-fields-password.server.js +2 -2
- package/dist/core/auth/tables.d.ts +2 -5
- package/dist/core/auth/tables.js +3 -7
- package/dist/core/auth/validate-config.d.ts +3 -8
- package/dist/core/auth/validate-config.js +4 -10
- package/dist/core/config/types.d.ts +6 -6
- package/dist/core/config/validate.server.js +11 -0
- package/dist/core/fields/builders/boolean-builder.d.ts +2 -2
- package/dist/core/fields/builders/boolean-builder.js +4 -1
- package/dist/core/fields/builders/select-builder.d.ts +3 -3
- package/dist/core/fields/builders/select-builder.js +4 -2
- package/dist/core/fields/complete.d.ts +18 -0
- package/dist/core/fields/complete.js +32 -0
- package/dist/core/fields/empty.d.ts +14 -0
- package/dist/core/fields/empty.js +13 -0
- package/dist/core/fields/initial.d.ts +32 -0
- package/dist/core/fields/initial.js +47 -0
- package/dist/core/fields/util.d.ts +0 -16
- package/dist/core/fields/util.js +0 -29
- 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/build-document.server.d.ts +4 -10
- package/dist/core/pipeline/build-document.server.js +8 -17
- package/dist/core/pipeline/hooks/data-config-map.server.d.ts +1 -1
- package/dist/core/pipeline/hooks/data-config-map.server.js +1 -1
- package/dist/core/pipeline/hooks/process-document-fields.server.d.ts +3 -2
- package/dist/core/pipeline/hooks/process-document-fields.server.js +3 -16
- package/dist/core/pipeline/hooks/set-default-values.server.d.ts +15 -4
- package/dist/core/pipeline/hooks/set-default-values.server.js +50 -25
- package/dist/core/pipeline/hooks/validate-fields.server.js +1 -1
- package/dist/core/pipeline/run.server.js +1 -2
- package/dist/core/prototype/area/api.server.d.ts +4 -6
- package/dist/core/prototype/area/api.server.js +4 -6
- package/dist/core/prototype/area/definition.server.js +23 -9
- package/dist/core/prototype/area/hooks.server.js +1 -1
- package/dist/core/prototype/collection/api.server.d.ts +5 -6
- package/dist/core/prototype/collection/api.server.js +5 -6
- package/dist/core/prototype/collection/definition.js +3 -8
- package/dist/core/prototype/collection/hooks/merge-with-initial.server.d.ts +15 -0
- package/dist/core/prototype/collection/hooks/merge-with-initial.server.js +20 -0
- package/dist/core/prototype/collection/hooks.server.js +5 -5
- package/dist/core/prototype/collection/nested/module.js +1 -1
- package/dist/core/prototype/collection/nested/module.server.js +1 -1
- package/dist/core/prototype/collection/operations/duplicate.js +4 -8
- package/dist/core/prototype/collection/upload/directories/derive.js +2 -2
- package/dist/core/prototype/collection/upload/hooks/handle-path-creation.server.js +2 -2
- package/dist/core/prototype/define.d.ts +2 -2
- package/dist/core/prototype/define.js +4 -4
- package/dist/core/prototype/initial.d.ts +23 -0
- package/dist/core/prototype/initial.js +19 -0
- package/dist/core/prototype/shared/versions/augment.d.ts +2 -4
- package/dist/core/prototype/shared/versions/augment.js +4 -6
- package/dist/core/prototype/shared/versions/configure.server.js +3 -3
- package/dist/core/prototype/shared/versions/hooks/fallback-data-from-original.d.ts +14 -2
- package/dist/core/prototype/shared/versions/hooks/fallback-data-from-original.js +28 -22
- package/dist/core/prototype/shared/versions/hooks/handle-new-version.server.js +3 -4
- package/dist/core/prototype/shared/versions/{blank.d.ts → initial.d.ts} +2 -4
- package/dist/core/prototype/shared/versions/{blank.js → initial.js} +2 -4
- package/dist/core/prototype/when.d.ts +2 -6
- package/dist/core/prototype/when.js +2 -6
- package/dist/fields/blocks/component/AddBlockButton.svelte +2 -2
- package/dist/fields/blocks/component/focus/BlocksFocus.svelte +16 -10
- package/dist/fields/blocks/component/focus/Inspector.svelte +27 -3
- package/dist/fields/blocks/component/focus/LayersList.svelte +4 -1
- package/dist/fields/blocks/component/focus/Renders.svelte +55 -11
- 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 +6 -4
- package/dist/fields/blocks/component/focus/focus.svelte.js +34 -8
- package/dist/fields/blocks/defaults.d.ts +22 -0
- package/dist/fields/blocks/defaults.js +23 -0
- package/dist/fields/blocks/index.d.ts +42 -5
- package/dist/fields/blocks/index.js +37 -1
- package/dist/fields/combobox/index.d.ts +2 -2
- package/dist/fields/combobox/index.js +2 -1
- package/dist/fields/date/index.d.ts +2 -2
- package/dist/fields/date/index.js +2 -1
- package/dist/fields/email/index.d.ts +2 -2
- package/dist/fields/email/index.js +2 -1
- package/dist/fields/group/index.d.ts +1 -0
- package/dist/fields/link/index.d.ts +3 -2
- package/dist/fields/link/index.js +2 -1
- package/dist/fields/number/index.d.ts +3 -2
- package/dist/fields/number/index.js +2 -1
- package/dist/fields/relation/component/RelationInline.svelte +1 -2
- package/dist/fields/relation/component/default/Default.svelte +1 -1
- package/dist/fields/relation/component/upload/Create.svelte +1 -1
- package/dist/fields/relation/index.d.ts +2 -2
- package/dist/fields/relation/index.js +2 -1
- package/dist/fields/rich-text/index.d.ts +2 -2
- package/dist/fields/rich-text/index.js +2 -1
- package/dist/fields/slug/index.d.ts +3 -2
- package/dist/fields/slug/index.js +2 -1
- package/dist/fields/text/index.d.ts +3 -2
- package/dist/fields/text/index.js +2 -1
- package/dist/fields/textarea/index.d.ts +3 -2
- package/dist/fields/textarea/index.js +2 -1
- package/dist/fields/time/index.d.ts +2 -2
- package/dist/fields/time/index.js +2 -1
- package/dist/fields/toggle/index.d.ts +3 -2
- package/dist/fields/toggle/index.js +2 -2
- package/dist/fields/tree/component/AddItemButton.svelte +3 -4
- package/dist/fields/tree/component/AddItemButton.svelte.d.ts +1 -1
- package/dist/fields/tree/defaults.d.ts +21 -0
- package/dist/fields/tree/defaults.js +18 -0
- package/dist/fields/tree/index.d.ts +17 -3
- package/dist/fields/tree/index.js +27 -0
- package/dist/fields/types.d.ts +14 -0
- package/dist/panel/components/ui/button/button.svelte +2 -3
- package/dist/panel/context/blocks-ops.d.ts +0 -1
- package/dist/panel/context/blocks-ops.js +1 -2
- package/dist/panel/pages/collection-document/load.server.js +1 -1
- 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/util/object.d.ts +2 -2
- package/dist/util/object.js +3 -3
- package/dist/util/random.d.ts +2 -0
- package/dist/util/random.js +2 -0
- package/package.json +1 -1
- package/dist/core/fields/blank.d.ts +0 -21
- package/dist/core/fields/blank.js +0 -37
- package/dist/core/prototype/blank.d.ts +0 -26
- package/dist/core/prototype/blank.js +0 -22
- package/dist/core/prototype/collection/hooks/merge-with-blank.server.d.ts +0 -9
- package/dist/core/prototype/collection/hooks/merge-with-blank.server.js +0 -14
- package/dist/fields/blocks/component/focus/StagePlaceholder.svelte +0 -66
- package/dist/fields/blocks/component/focus/StagePlaceholder.svelte.d.ts +0 -3
|
@@ -21,7 +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
|
|
24
|
+
import StageAdd from './StageAdd.svelte';
|
|
25
25
|
|
|
26
26
|
const { form }: { form: DocumentFormContext } = $props();
|
|
27
27
|
|
|
@@ -54,6 +54,13 @@
|
|
|
54
54
|
count === 1 ? t__('fields.blocks_count', '1') : t__('fields.blocks_count|m|p', String(count))
|
|
55
55
|
);
|
|
56
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
|
+
|
|
57
64
|
let confirmRemove = $state(false);
|
|
58
65
|
|
|
59
66
|
/**
|
|
@@ -293,7 +300,7 @@
|
|
|
293
300
|
keys: '/',
|
|
294
301
|
hidden: true,
|
|
295
302
|
when: () => free() && editing,
|
|
296
|
-
run: focus.pick
|
|
303
|
+
run: () => focus.pick()
|
|
297
304
|
},
|
|
298
305
|
{
|
|
299
306
|
id: 'blocks.back',
|
|
@@ -409,14 +416,14 @@
|
|
|
409
416
|
<div class="rz-blocks-focus__body">
|
|
410
417
|
<!--
|
|
411
418
|
The stage: the open list, or the narrowed block alone with what it holds. A click beside the
|
|
412
|
-
blocks selects the root; the blocks stop their own clicks.
|
|
419
|
+
blocks selects the root; the blocks and their lists stop their own clicks.
|
|
413
420
|
-->
|
|
414
421
|
<section class="rz-blocks-focus__renders" role="presentation" onclick={focus.selectRoot}>
|
|
415
422
|
{#key focus.path}
|
|
416
423
|
<Renders {form} list={stageList} only={focus.narrowedRow?.index} onRemove={requestRemove} />
|
|
417
424
|
{/key}
|
|
418
|
-
{#if
|
|
419
|
-
<
|
|
425
|
+
{#if showAdd && homeList}
|
|
426
|
+
<StageAdd list={homeList} />
|
|
420
427
|
{/if}
|
|
421
428
|
</section>
|
|
422
429
|
|
|
@@ -438,8 +445,8 @@
|
|
|
438
445
|
|
|
439
446
|
<BlockPicker
|
|
440
447
|
bind:open={() => focus.picking, (open) => (focus.picking = open)}
|
|
441
|
-
types={
|
|
442
|
-
onpick={(block) => focus.
|
|
448
|
+
types={focus.pickTypes()}
|
|
449
|
+
onpick={(block) => focus.insertPicked(block.name)}
|
|
443
450
|
/>
|
|
444
451
|
|
|
445
452
|
<Dialog.Root bind:open={confirmRemove}>
|
|
@@ -576,14 +583,13 @@
|
|
|
576
583
|
}
|
|
577
584
|
|
|
578
585
|
.rz-blocks-focus__renders > :global(.rz-renders),
|
|
579
|
-
.rz-blocks-focus__renders > :global(.rz-stage-
|
|
586
|
+
.rz-blocks-focus__renders > :global(.rz-stage-add) {
|
|
580
587
|
max-width: var(--rz-document-width, 60rem);
|
|
581
588
|
margin-inline: auto;
|
|
582
589
|
}
|
|
583
590
|
|
|
584
591
|
/* Under the blocks, one gap further down. */
|
|
585
|
-
.rz-blocks-focus__renders > :global(.rz-stage-
|
|
586
|
-
display: block;
|
|
592
|
+
.rz-blocks-focus__renders > :global(.rz-stage-add) {
|
|
587
593
|
margin-top: var(--rz-size-3);
|
|
588
594
|
}
|
|
589
595
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { Button } from '../../../../panel/components/ui/button/index.js';
|
|
6
6
|
import { withBlockTypes } from '../../../../panel/context/blocks-ops.js';
|
|
7
7
|
import type { DocumentFormContext } from '../../../../panel/context/documentForm.svelte.js';
|
|
8
|
-
import { Focus, ToyBrick } from '@lucide/svelte';
|
|
8
|
+
import { Focus, Plus, ToyBrick } from '@lucide/svelte';
|
|
9
9
|
import { getBlocksFocusContext } from './focus.svelte.js';
|
|
10
10
|
|
|
11
11
|
type Props = { form: DocumentFormContext };
|
|
@@ -34,7 +34,10 @@
|
|
|
34
34
|
|
|
35
35
|
{#if row && rendered}
|
|
36
36
|
{@const Icon = row.config?.icon ?? ToyBrick}
|
|
37
|
-
<!--
|
|
37
|
+
<!--
|
|
38
|
+
The selected block: its head, its fields, then how many blocks each of its lists holds, and a
|
|
39
|
+
button that adds one.
|
|
40
|
+
-->
|
|
38
41
|
<article class="rz-inspector" data-block-path={row.path}>
|
|
39
42
|
<header class="rz-inspector__header">
|
|
40
43
|
<span class="rz-inspector__icon"><Icon size={14} /></span>
|
|
@@ -63,6 +66,17 @@
|
|
|
63
66
|
<li class="rz-inspector__list">
|
|
64
67
|
<span>{child.label}</span>
|
|
65
68
|
<span class="rz-inspector__count">{countOf(child.list)}</span>
|
|
69
|
+
{#if !focus.locked}
|
|
70
|
+
<Button
|
|
71
|
+
class="rz-inspector__add"
|
|
72
|
+
variant="secondary"
|
|
73
|
+
title={t__('fields.add_block')}
|
|
74
|
+
aria-label={t__('fields.add_block')}
|
|
75
|
+
onclick={() => focus.pick(child.list)}
|
|
76
|
+
>
|
|
77
|
+
<Plus size={14} />
|
|
78
|
+
</Button>
|
|
79
|
+
{/if}
|
|
66
80
|
</li>
|
|
67
81
|
{/each}
|
|
68
82
|
</ul>
|
|
@@ -101,6 +115,10 @@
|
|
|
101
115
|
h3 {
|
|
102
116
|
font-variation-settings: 'wght' 500;
|
|
103
117
|
font-weight: 500;
|
|
118
|
+
overflow: hidden;
|
|
119
|
+
display: -webkit-box;
|
|
120
|
+
-webkit-box-orient: vertical;
|
|
121
|
+
-webkit-line-clamp: 1;
|
|
104
122
|
font-size: var(--rz-text-md);
|
|
105
123
|
white-space: nowrap;
|
|
106
124
|
}
|
|
@@ -150,11 +168,17 @@
|
|
|
150
168
|
|
|
151
169
|
.rz-inspector__list {
|
|
152
170
|
display: flex;
|
|
153
|
-
|
|
171
|
+
align-items: center;
|
|
154
172
|
gap: var(--rz-size-2);
|
|
173
|
+
|
|
174
|
+
:global(.rz-inspector__add) {
|
|
175
|
+
flex-shrink: 0;
|
|
176
|
+
}
|
|
155
177
|
}
|
|
156
178
|
|
|
179
|
+
/* On the right, then the button. */
|
|
157
180
|
.rz-inspector__count {
|
|
181
|
+
margin-left: auto;
|
|
158
182
|
color: var(--rz-fg-subtle);
|
|
159
183
|
}
|
|
160
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,9 +1,10 @@
|
|
|
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';
|
|
@@ -12,9 +13,17 @@
|
|
|
12
13
|
/**
|
|
13
14
|
* `only` narrows the list to the block at that index, focus on one block: it does not move
|
|
14
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.
|
|
15
17
|
*/
|
|
16
|
-
type Props = {
|
|
17
|
-
|
|
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();
|
|
18
27
|
|
|
19
28
|
const focus = getBlocksFocusContext()!;
|
|
20
29
|
const rows = $derived(
|
|
@@ -32,6 +41,23 @@
|
|
|
32
41
|
focus.inspect();
|
|
33
42
|
}
|
|
34
43
|
|
|
44
|
+
/**
|
|
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.
|
|
47
|
+
*/
|
|
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) {
|
|
57
|
+
event.stopPropagation();
|
|
58
|
+
focus.pick(list);
|
|
59
|
+
}
|
|
60
|
+
|
|
35
61
|
/** The one block the controls act on: selected alone, and the form open to changes. */
|
|
36
62
|
const controlled = (rowPath: string) =>
|
|
37
63
|
!focus.locked && focus.selection.length === 1 && focus.selection[0] === rowPath;
|
|
@@ -99,17 +125,22 @@
|
|
|
99
125
|
One list of blocks, one wrapper per block. A block's nested lists are the `nested` snippet its
|
|
100
126
|
render puts where they go; a block without a render is a row with them under it.
|
|
101
127
|
-->
|
|
102
|
-
<div
|
|
128
|
+
<div
|
|
129
|
+
class="rz-renders {className ?? ''}"
|
|
130
|
+
data-list={list}
|
|
131
|
+
data-empty={rows.length ? undefined : ''}
|
|
132
|
+
use:sortableList
|
|
133
|
+
>
|
|
103
134
|
{#each rows as row (row.block.id)}
|
|
104
135
|
{@const config = row.config}
|
|
105
136
|
{@const Render = config?.render}
|
|
106
|
-
{#snippet nested(name?: string)}
|
|
137
|
+
{#snippet nested(name?: string, options?: { class?: string })}
|
|
107
138
|
{#each row.children.filter((child) => !name || child.builder.name === name) as child (child.builder.name)}
|
|
108
139
|
<!-- All of them at once, and more than one: each under its name. -->
|
|
109
140
|
{#if !name && row.children.length > 1}
|
|
110
141
|
<p class="rz-renders__list-label">{child.label}</p>
|
|
111
142
|
{/if}
|
|
112
|
-
<Renders {form} list={child.list} {onRemove} />
|
|
143
|
+
<Renders {form} list={child.list} holder={row.path} class={options?.class} {onRemove} />
|
|
113
144
|
{/each}
|
|
114
145
|
{/snippet}
|
|
115
146
|
<div
|
|
@@ -127,7 +158,7 @@
|
|
|
127
158
|
}
|
|
128
159
|
}}
|
|
129
160
|
>
|
|
130
|
-
{#if controlled(row.path) && !focus.isNarrowedBlock(row.path)}
|
|
161
|
+
{#if controlled(row.path) && !focus.isNarrowedBlock(row.path) && config?.controls !== false}
|
|
131
162
|
<!-- Above it: move, duplicate, remove. A click on the block already opens its fields. -->
|
|
132
163
|
<div class="rz-renders__toolbar">
|
|
133
164
|
<button
|
|
@@ -200,6 +231,19 @@
|
|
|
200
231
|
<p class="rz-renders__empty">{t__('fields.no_blocks_yet')}</p>
|
|
201
232
|
{/if}
|
|
202
233
|
{/each}
|
|
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>
|
|
246
|
+
{/if}
|
|
203
247
|
</div>
|
|
204
248
|
|
|
205
249
|
<style>/* A level: its fill, a hairline, and its shadow when it has one. raised has none, float does. */
|
|
@@ -223,8 +267,9 @@
|
|
|
223
267
|
min-height: var(--rz-size-8);
|
|
224
268
|
}
|
|
225
269
|
|
|
226
|
-
/* An empty nested list: somewhere to drop a type. */
|
|
270
|
+
/* An empty nested list: somewhere to drop a type, its `+` inside. */
|
|
227
271
|
.rz-renders[data-empty]:not([data-list='']) {
|
|
272
|
+
padding: var(--rz-size-2);
|
|
228
273
|
border: 1px dashed var(--rz-border-strong);
|
|
229
274
|
border-radius: var(--rz-radius-md);
|
|
230
275
|
}
|
|
@@ -232,7 +277,6 @@
|
|
|
232
277
|
/* A block under the pointer: a dashed frame, on the innermost block only. */
|
|
233
278
|
.rz-renders__item {
|
|
234
279
|
position: relative;
|
|
235
|
-
border-radius: var(--rz-radius-md);
|
|
236
280
|
outline: 1px dashed transparent;
|
|
237
281
|
outline-offset: 3px;
|
|
238
282
|
cursor: pointer;
|
|
@@ -249,7 +293,7 @@
|
|
|
249
293
|
|
|
250
294
|
/* The selected block: an accent frame around it. */
|
|
251
295
|
.rz-renders__item[data-selected] {
|
|
252
|
-
outline:
|
|
296
|
+
outline: 1px solid oklch(from var(--rz-accent) l c h / 0.6);
|
|
253
297
|
outline-offset: 3px;
|
|
254
298
|
}
|
|
255
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>
|
|
@@ -55,8 +55,9 @@ 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
|
-
|
|
58
|
+
pick: (list?: string) => void;
|
|
59
|
+
pickTypes: () => import("../../index.js").BlockBuilder[];
|
|
60
|
+
insertPicked: (type: string) => string | null;
|
|
60
61
|
/** The block the stage is narrowed to, when the path ends on one. */
|
|
61
62
|
readonly narrowedRow: LayerRow | null;
|
|
62
63
|
/** Nothing selected: the root node, and the whole list on the stage. */
|
|
@@ -110,8 +111,9 @@ export declare const getBlocksFocusContext: () => {
|
|
|
110
111
|
/** Turns the panel to the selected block's fields, and opens it where it is a sheet. */
|
|
111
112
|
inspect(): void;
|
|
112
113
|
picking: boolean;
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
pick: (list?: string) => void;
|
|
115
|
+
pickTypes: () => import("../../index.js").BlockBuilder[];
|
|
116
|
+
insertPicked: (type: string) => string | null;
|
|
115
117
|
/** The block the stage is narrowed to, when the path ends on one. */
|
|
116
118
|
readonly narrowedRow: LayerRow | null;
|
|
117
119
|
/** Nothing selected: the root node, and the whole list on the stage. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { pushState, replaceState } from '$app/navigation';
|
|
2
2
|
import { page } from '$app/state';
|
|
3
|
-
import {
|
|
3
|
+
import { initialValues } from '../../../../core/fields/initial.js';
|
|
4
4
|
import { blockPath, parseBlockPath, shiftListPath } from '../../../../panel/context/blocks-ops.js';
|
|
5
5
|
import { capitalize } from '../../../../util/string.js';
|
|
6
6
|
import { getContext, setContext } from 'svelte';
|
|
@@ -39,6 +39,8 @@ export function setBlocksFocusContext(form) {
|
|
|
39
39
|
let inspected = $state(0);
|
|
40
40
|
/** The picker of types to add is open. */
|
|
41
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);
|
|
42
44
|
/** The folded rows, by block id: a fold stays on its block when the block moves. */
|
|
43
45
|
const collapsed = new SvelteSet();
|
|
44
46
|
/** The entries focus pushed, up to the one on screen. */
|
|
@@ -305,11 +307,37 @@ export function setBlocksFocusContext(form) {
|
|
|
305
307
|
const config = builderOf(at.list)?.get.blocks.find((candidate) => candidate.name === type)?.get;
|
|
306
308
|
if (!config)
|
|
307
309
|
return null;
|
|
308
|
-
const
|
|
309
|
-
const id = form.blocks.insert(at, empty);
|
|
310
|
+
const id = form.blocks.insert(at, { ...initialValues(config.fields), type });
|
|
310
311
|
select(blockPath(at));
|
|
311
312
|
return id;
|
|
312
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());
|
|
313
341
|
function duplicateSelection() {
|
|
314
342
|
const current = movableAt();
|
|
315
343
|
if (locked || !current)
|
|
@@ -431,11 +459,9 @@ export function setBlocksFocusContext(form) {
|
|
|
431
459
|
set picking(value) {
|
|
432
460
|
picking = value;
|
|
433
461
|
},
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
picking = true;
|
|
438
|
-
},
|
|
462
|
+
pick,
|
|
463
|
+
pickTypes,
|
|
464
|
+
insertPicked,
|
|
439
465
|
/** The block the stage is narrowed to, when the path ends on one. */
|
|
440
466
|
get narrowedRow() {
|
|
441
467
|
return narrowed ? (rootRows()[0] ?? null) : null;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Dic } from '../../util/types.js';
|
|
2
|
+
import type { BlockBuilder } from './index.js';
|
|
3
|
+
/** A block in a default: its `type`, and the values it starts with. */
|
|
4
|
+
export type BlockDefault = {
|
|
5
|
+
type: string;
|
|
6
|
+
} & Dic;
|
|
7
|
+
/**
|
|
8
|
+
* A default list of blocks as a document holds it: each block with a fresh temporary id and the
|
|
9
|
+
* initial values of its type's other fields, the values it names winning. A new copy on each call.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* completeBlocks('sections', [grid, paragraph], [{ type: 'grid', items: [{ type: 'paragraph' }] }]);
|
|
13
|
+
* // [{
|
|
14
|
+
* // id: 'temp-3f9a…', type: 'grid', path: null, position: null, title: null,
|
|
15
|
+
* // items: [{ id: 'temp-8c1d…', type: 'paragraph', path: null, position: null, text: null }]
|
|
16
|
+
* // }]
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* `path` and `position` stay `null`: the server reads them from where the block sits, the panel
|
|
20
|
+
* from its index. A block without a real id is added on save.
|
|
21
|
+
*/
|
|
22
|
+
export declare const completeBlocks: (field: string, blocks: BlockBuilder[], value: BlockDefault[]) => Dic[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { completeItem } from '../../core/fields/complete.js';
|
|
2
|
+
/**
|
|
3
|
+
* A default list of blocks as a document holds it: each block with a fresh temporary id and the
|
|
4
|
+
* initial values of its type's other fields, the values it names winning. A new copy on each call.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* completeBlocks('sections', [grid, paragraph], [{ type: 'grid', items: [{ type: 'paragraph' }] }]);
|
|
8
|
+
* // [{
|
|
9
|
+
* // id: 'temp-3f9a…', type: 'grid', path: null, position: null, title: null,
|
|
10
|
+
* // items: [{ id: 'temp-8c1d…', type: 'paragraph', path: null, position: null, text: null }]
|
|
11
|
+
* // }]
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* `path` and `position` stay `null`: the server reads them from where the block sits, the panel
|
|
15
|
+
* from its index. A block without a real id is added on save.
|
|
16
|
+
*/
|
|
17
|
+
export const completeBlocks = (field, blocks, value) => value.map((given) => {
|
|
18
|
+
const block = blocks.find((candidate) => candidate.name === given?.type);
|
|
19
|
+
if (!block) {
|
|
20
|
+
throw new Error(`${field}.defaultValue(): "${given?.type}" is not a block of ${field}`);
|
|
21
|
+
}
|
|
22
|
+
return { ...completeItem(block.get.fields, given), type: block.name };
|
|
23
|
+
});
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { FieldBuilder, FieldNode, ValueNode } from '../../core/fields/builders/field-builder.js';
|
|
2
|
-
import { FormFieldBuilder } from '../../core/fields/builders/form-field-builder.js';
|
|
2
|
+
import { FormFieldBuilder, type FormFieldUse } from '../../core/fields/builders/form-field-builder.js';
|
|
3
|
+
import type { CompletesDefault } from '../../core/fields/complete.js';
|
|
3
4
|
import type { WithoutBuilders } from '../../core/fields/types.js';
|
|
4
5
|
import type { GenericBlock } from '../../core/prototype/types.js';
|
|
5
|
-
import type { Field, FormField } from '../types.js';
|
|
6
|
+
import type { DefaultOptions, DefaultValueFn, Field, FormField } from '../types.js';
|
|
6
7
|
import type { DocumentFormContext } from '../../panel/context/documentForm.svelte.js';
|
|
7
8
|
import type { Dic } from '../../util/types.js';
|
|
8
9
|
import type { IconProps } from '@lucide/svelte';
|
|
9
10
|
import type { Component, Snippet } from 'svelte';
|
|
11
|
+
import { type BlockDefault } from './defaults.js';
|
|
10
12
|
export declare const blocks: (name: string, blocks: BlockBuilder[]) => BlocksBuilder;
|
|
11
13
|
export declare const block: (name: string) => BlockBuilder;
|
|
12
14
|
export declare class BlocksBuilder extends FormFieldBuilder<BlocksField> {
|
|
@@ -22,6 +24,20 @@ export declare class BlocksBuilder extends FormFieldBuilder<BlocksField> {
|
|
|
22
24
|
* `summary`: one row, `3 blocks · Edit`, with the blocks edited in focus mode.
|
|
23
25
|
*/
|
|
24
26
|
layout(layout: 'default' | 'summary'): this;
|
|
27
|
+
/**
|
|
28
|
+
* The blocks a new document starts with, and a block inserted in the panel when the list sits
|
|
29
|
+
* inside it. Each names its `type` and the values it starts with; the rest comes from its
|
|
30
|
+
* fields.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* blocks('sections', [paragraph, grid]).defaultValue([
|
|
34
|
+
* { type: 'grid', title: 'Gallery', items: [{ type: 'paragraph' }] }
|
|
35
|
+
* ]);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
defaultValue(value: BlockDefault[] | DefaultValueFn<BlockDefault[]>, options?: DefaultOptions): this;
|
|
39
|
+
/** The default completed as a document holds it — see `completeBlocks`. */
|
|
40
|
+
get use(): FormFieldUse<BlocksField> & CompletesDefault<BlockDefault>;
|
|
25
41
|
localized(): this;
|
|
26
42
|
compile(): any;
|
|
27
43
|
protected generateType(): string;
|
|
@@ -61,10 +77,16 @@ export declare class BlockBuilder {
|
|
|
61
77
|
* The component drawn for the block on the stage of focus mode.
|
|
62
78
|
* It gets the block value, its path, its fields and the form, so it can show the value,
|
|
63
79
|
* resolve its relations with `populate` and mount panel fields with `RenderFields`.
|
|
80
|
+
*
|
|
81
|
+
* `controls: false` drops the bar above the selected block, for a small one like a button.
|
|
82
|
+
* Keys, ⌘K and the layers still move, duplicate and remove it.
|
|
64
83
|
* @example
|
|
65
84
|
* block('hero').fields(text('title'), richText('text')).render(HeroRender)
|
|
85
|
+
* block('button').render(ButtonRender, { controls: false })
|
|
66
86
|
*/
|
|
67
|
-
render(component: Component<BlockRenderProps
|
|
87
|
+
render(component: Component<BlockRenderProps>, options?: {
|
|
88
|
+
controls?: boolean;
|
|
89
|
+
}): this;
|
|
68
90
|
description(description: string): this;
|
|
69
91
|
label(label: string): this;
|
|
70
92
|
fields(...fields: FieldBuilder<Field>[]): this;
|
|
@@ -76,6 +98,8 @@ export declare class BlockBuilder {
|
|
|
76
98
|
thumbnail?: Component;
|
|
77
99
|
renderTitle?: BlocksFieldBlockRenderTitle;
|
|
78
100
|
render?: Component<BlockRenderProps>;
|
|
101
|
+
/** `false`: no bar above the block when it is selected on the stage. */
|
|
102
|
+
controls?: boolean;
|
|
79
103
|
fields: FieldBuilder<Field>[];
|
|
80
104
|
};
|
|
81
105
|
get name(): string;
|
|
@@ -102,8 +126,19 @@ export type BlockRenderProps = {
|
|
|
102
126
|
/** The block's field builders, for `RenderFields`. */
|
|
103
127
|
fields: FieldBuilder<Field>[];
|
|
104
128
|
form: DocumentFormContext;
|
|
105
|
-
/**
|
|
106
|
-
|
|
129
|
+
/**
|
|
130
|
+
* The block's nested lists, each block in its own selectable wrapper, `.rz-renders`, and a `+`
|
|
131
|
+
* after them, `.rz-renders__add`. `children('items')` draws one list; `class` names its wrapper,
|
|
132
|
+
* for the render to lay it out.
|
|
133
|
+
* @example
|
|
134
|
+
* {@render children?.('items', { class: 'cards' })}
|
|
135
|
+
*
|
|
136
|
+
* :global(.cards) { display: flex; gap: 1rem; }
|
|
137
|
+
* :global(.cards > .rz-renders__add) { align-self: center; }
|
|
138
|
+
*/
|
|
139
|
+
children?: Snippet<[name?: string, options?: {
|
|
140
|
+
class?: string;
|
|
141
|
+
}]>;
|
|
107
142
|
};
|
|
108
143
|
export type BlocksFieldBlock = {
|
|
109
144
|
name: string;
|
|
@@ -113,6 +148,8 @@ export type BlocksFieldBlock = {
|
|
|
113
148
|
thumbnail?: Component;
|
|
114
149
|
renderTitle?: BlocksFieldBlockRenderTitle;
|
|
115
150
|
render?: Component<BlockRenderProps>;
|
|
151
|
+
/** `false`: no bar above the block when it is selected on the stage. */
|
|
152
|
+
controls?: boolean;
|
|
116
153
|
fields: FieldBuilder<Field>[];
|
|
117
154
|
};
|
|
118
155
|
export type BlocksFieldRaw = FormField & {
|
|
@@ -5,6 +5,7 @@ import { number } from '../number/index.js';
|
|
|
5
5
|
import { text } from '../text/index.js';
|
|
6
6
|
import Blocks from './component/Blocks.svelte';
|
|
7
7
|
import Cell from './component/Cell.svelte';
|
|
8
|
+
import { completeBlocks } from './defaults.js';
|
|
8
9
|
export const blocks = (name, blocks) => new BlocksBuilder(name, blocks);
|
|
9
10
|
export const block = (name) => new BlockBuilder(name);
|
|
10
11
|
export class BlocksBuilder extends FormFieldBuilder {
|
|
@@ -30,6 +31,35 @@ export class BlocksBuilder extends FormFieldBuilder {
|
|
|
30
31
|
this.field.layout = layout;
|
|
31
32
|
return this;
|
|
32
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* The blocks a new document starts with, and a block inserted in the panel when the list sits
|
|
36
|
+
* inside it. Each names its `type` and the values it starts with; the rest comes from its
|
|
37
|
+
* fields.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* blocks('sections', [paragraph, grid]).defaultValue([
|
|
41
|
+
* { type: 'grid', title: 'Gallery', items: [{ type: 'paragraph' }] }
|
|
42
|
+
* ]);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
defaultValue(value, options) {
|
|
46
|
+
this.field.defaultValue = value;
|
|
47
|
+
this.field.defaultFill = options?.fill;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/** The default completed as a document holds it — see `completeBlocks`. */
|
|
51
|
+
get use() {
|
|
52
|
+
const use = super.use;
|
|
53
|
+
const completeDefault = (value) => completeBlocks(this.name, this.field.blocks, value);
|
|
54
|
+
return {
|
|
55
|
+
...use,
|
|
56
|
+
completeDefault,
|
|
57
|
+
defaultValue: (context = {}) => {
|
|
58
|
+
const value = use.defaultValue(context);
|
|
59
|
+
return Array.isArray(value) ? completeDefault(value) : [];
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
33
63
|
localized() {
|
|
34
64
|
if (this.field.blocks.length === 0) {
|
|
35
65
|
throw new Error('localized() must be called after blocks assignment');
|
|
@@ -165,11 +195,17 @@ export class BlockBuilder {
|
|
|
165
195
|
* The component drawn for the block on the stage of focus mode.
|
|
166
196
|
* It gets the block value, its path, its fields and the form, so it can show the value,
|
|
167
197
|
* resolve its relations with `populate` and mount panel fields with `RenderFields`.
|
|
198
|
+
*
|
|
199
|
+
* `controls: false` drops the bar above the selected block, for a small one like a button.
|
|
200
|
+
* Keys, ⌘K and the layers still move, duplicate and remove it.
|
|
168
201
|
* @example
|
|
169
202
|
* block('hero').fields(text('title'), richText('text')).render(HeroRender)
|
|
203
|
+
* block('button').render(ButtonRender, { controls: false })
|
|
170
204
|
*/
|
|
171
|
-
render(component) {
|
|
205
|
+
render(component, options = {}) {
|
|
172
206
|
this.block.render = component;
|
|
207
|
+
if (options.controls === false)
|
|
208
|
+
this.block.controls = false;
|
|
173
209
|
return this;
|
|
174
210
|
}
|
|
175
211
|
description(description) {
|