rimecms 1.1.0 → 1.1.2
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/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 +2 -13
- package/dist/fields/blocks/component/focus/Inspector.svelte +43 -3
- package/dist/fields/blocks/component/focus/Renders.svelte +29 -1
- package/dist/fields/blocks/component/focus/StagePlaceholder.svelte +24 -4
- package/dist/fields/blocks/component/focus/StagePlaceholder.svelte.d.ts +6 -1
- package/dist/fields/blocks/component/focus/focus.svelte.d.ts +11 -3
- package/dist/fields/blocks/component/focus/focus.svelte.js +31 -10
- package/dist/fields/blocks/defaults.d.ts +22 -0
- package/dist/fields/blocks/defaults.js +23 -0
- package/dist/fields/blocks/index.d.ts +18 -2
- package/dist/fields/blocks/index.js +33 -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/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/relation/util.d.ts +9 -21
- package/dist/fields/relation/util.js +11 -28
- 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/live/context.svelte.js +7 -3
- package/dist/panel/components/ui/command/command-dialog.svelte +2 -8
- package/dist/panel/components/ui/command/command-dialog.svelte.d.ts +1 -1
- 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/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 +2 -2
- 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/panel/components/ui/tooltip/index.d.ts +0 -7
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import DefaultRender from './DefaultRender.svelte';
|
|
9
9
|
import { getBlocksFocusContext } from './focus.svelte.js';
|
|
10
10
|
import Renders from './Renders.svelte';
|
|
11
|
+
import StagePlaceholder from './StagePlaceholder.svelte';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* `only` narrows the list to the block at that index, focus on one block: it does not move
|
|
@@ -32,6 +33,23 @@
|
|
|
32
33
|
focus.inspect();
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
/**
|
|
37
|
+
* A click beside the blocks selects the list, so the next block goes at its end. A click on a
|
|
38
|
+
* block stops at the block.
|
|
39
|
+
*/
|
|
40
|
+
function selectList(event: MouseEvent) {
|
|
41
|
+
event.stopPropagation();
|
|
42
|
+
focus.selectList(list);
|
|
43
|
+
}
|
|
44
|
+
|
|
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
|
+
|
|
35
53
|
/** The one block the controls act on: selected alone, and the form open to changes. */
|
|
36
54
|
const controlled = (rowPath: string) =>
|
|
37
55
|
!focus.locked && focus.selection.length === 1 && focus.selection[0] === rowPath;
|
|
@@ -99,7 +117,14 @@
|
|
|
99
117
|
One list of blocks, one wrapper per block. A block's nested lists are the `nested` snippet its
|
|
100
118
|
render puts where they go; a block without a render is a row with them under it.
|
|
101
119
|
-->
|
|
102
|
-
<div
|
|
120
|
+
<div
|
|
121
|
+
class="rz-renders"
|
|
122
|
+
data-list={list}
|
|
123
|
+
data-empty={rows.length ? undefined : ''}
|
|
124
|
+
role="presentation"
|
|
125
|
+
onclick={selectList}
|
|
126
|
+
use:sortableList
|
|
127
|
+
>
|
|
103
128
|
{#each rows as row (row.block.id)}
|
|
104
129
|
{@const config = row.config}
|
|
105
130
|
{@const Render = config?.render}
|
|
@@ -200,6 +225,9 @@
|
|
|
200
225
|
<p class="rz-renders__empty">{t__('fields.no_blocks_yet')}</p>
|
|
201
226
|
{/if}
|
|
202
227
|
{/each}
|
|
228
|
+
{#if placeholder}
|
|
229
|
+
<StagePlaceholder {list} compact={list !== focus.path} />
|
|
230
|
+
{/if}
|
|
203
231
|
</div>
|
|
204
232
|
|
|
205
233
|
<style>/* A level: its fill, a hairline, and its shadow when it has one. raised has none, float does. */
|
|
@@ -3,22 +3,31 @@
|
|
|
3
3
|
import Kbd from '../../../../panel/components/ui/kbd/Kbd.svelte';
|
|
4
4
|
import { getBlocksFocusContext } from './focus.svelte.js';
|
|
5
5
|
|
|
6
|
+
/** `compact` inside a block's render, where the list may be a narrow column. */
|
|
7
|
+
type Props = { list: string; compact?: boolean };
|
|
8
|
+
const { list, compact = false }: Props = $props();
|
|
9
|
+
|
|
6
10
|
const focus = getBlocksFocusContext()!;
|
|
7
11
|
|
|
8
12
|
/** "Type $1 to add a block", cut around the key. */
|
|
9
13
|
const KEY = '\u0000';
|
|
10
14
|
const [before, after] = $derived(t__('fields.type_to_add_block', KEY).split(KEY));
|
|
11
15
|
|
|
12
|
-
/** Adds at the end of the
|
|
16
|
+
/** Adds at the end of the list: the list selected, then the picker, as `/` opens. */
|
|
13
17
|
function add(event: MouseEvent) {
|
|
14
18
|
event.stopPropagation();
|
|
15
|
-
focus.
|
|
19
|
+
focus.selectList(list);
|
|
16
20
|
focus.pick();
|
|
17
21
|
}
|
|
18
22
|
</script>
|
|
19
23
|
|
|
20
24
|
<!-- Under the blocks: the key that adds one, and a click that does the same. -->
|
|
21
|
-
<button
|
|
25
|
+
<button
|
|
26
|
+
type="button"
|
|
27
|
+
class="rz-stage-placeholder"
|
|
28
|
+
class:rz-stage-placeholder--compact={compact}
|
|
29
|
+
onclick={add}
|
|
30
|
+
>
|
|
22
31
|
{before}<Kbd keys="/" />{after}
|
|
23
32
|
</button>
|
|
24
33
|
|
|
@@ -37,8 +46,10 @@
|
|
|
37
46
|
/* A focused input: an accent edge and a soft halo. */
|
|
38
47
|
|
|
39
48
|
/* An input with an error. */
|
|
40
|
-
.
|
|
49
|
+
/* A row of its own, across every column of the list. */
|
|
50
|
+
.rz-stage-placeholder {
|
|
41
51
|
display: block;
|
|
52
|
+
grid-column: 1 / -1;
|
|
42
53
|
width: 100%;
|
|
43
54
|
padding: var(--rz-size-1) var(--rz-size-1-5);
|
|
44
55
|
border-radius: var(--rz-radius-lg);
|
|
@@ -63,4 +74,13 @@
|
|
|
63
74
|
vertical-align: text-bottom;
|
|
64
75
|
}
|
|
65
76
|
}
|
|
77
|
+
|
|
78
|
+
.rz-stage-placeholder--compact {
|
|
79
|
+
padding: var(--rz-size-2) var(--rz-size-3);
|
|
80
|
+
font-size: var(--rz-text-sm);
|
|
81
|
+
|
|
82
|
+
:global(.rz-kbd) {
|
|
83
|
+
font-size: var(--rz-text-xs);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
66
86
|
</style>
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/** `compact` inside a block's render, where the list may be a narrow column. */
|
|
2
|
+
type Props = {
|
|
3
|
+
list: string;
|
|
4
|
+
compact?: boolean;
|
|
5
|
+
};
|
|
6
|
+
declare const StagePlaceholder: import("svelte").Component<Props, {}, "">;
|
|
2
7
|
type StagePlaceholder = ReturnType<typeof StagePlaceholder>;
|
|
3
8
|
export default StagePlaceholder;
|
|
@@ -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, or nothing, which is the root node of the layers.
|
|
40
|
+
* selection is a block, a list inside the stage, 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,7 +55,10 @@ 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
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Opens the picker of types to add. The one picked goes after the selected block, or at the
|
|
60
|
+
* end of the selected list.
|
|
61
|
+
*/
|
|
59
62
|
pick(): void;
|
|
60
63
|
/** The block the stage is narrowed to, when the path ends on one. */
|
|
61
64
|
readonly narrowedRow: LayerRow | null;
|
|
@@ -63,6 +66,7 @@ export declare function setBlocksFocusContext(form: DocumentFormContext): {
|
|
|
63
66
|
readonly rootSelected: boolean;
|
|
64
67
|
rootLabel: () => string;
|
|
65
68
|
selectRoot: () => void;
|
|
69
|
+
selectList: (list: string) => void;
|
|
66
70
|
breadcrumb: () => Crumb[];
|
|
67
71
|
isSelected: (rowPath: string) => boolean;
|
|
68
72
|
isNarrowedBlock: (rowPath: string) => boolean;
|
|
@@ -110,7 +114,10 @@ export declare const getBlocksFocusContext: () => {
|
|
|
110
114
|
/** Turns the panel to the selected block's fields, and opens it where it is a sheet. */
|
|
111
115
|
inspect(): void;
|
|
112
116
|
picking: boolean;
|
|
113
|
-
/**
|
|
117
|
+
/**
|
|
118
|
+
* Opens the picker of types to add. The one picked goes after the selected block, or at the
|
|
119
|
+
* end of the selected list.
|
|
120
|
+
*/
|
|
114
121
|
pick(): void;
|
|
115
122
|
/** The block the stage is narrowed to, when the path ends on one. */
|
|
116
123
|
readonly narrowedRow: LayerRow | null;
|
|
@@ -118,6 +125,7 @@ export declare const getBlocksFocusContext: () => {
|
|
|
118
125
|
readonly rootSelected: boolean;
|
|
119
126
|
rootLabel: () => string;
|
|
120
127
|
selectRoot: () => void;
|
|
128
|
+
selectList: (list: string) => void;
|
|
121
129
|
breadcrumb: () => Crumb[];
|
|
122
130
|
isSelected: (rowPath: string) => boolean;
|
|
123
131
|
isNarrowedBlock: (rowPath: string) => boolean;
|
|
@@ -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';
|
|
@@ -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, or nothing, which is the root node of the layers.
|
|
22
|
+
* selection is a block, a list inside the stage, 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,6 +33,8 @@ 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);
|
|
36
38
|
/** The panel's tab: the tree of blocks, the selected block's fields, the types to add. */
|
|
37
39
|
let tab = $state(narrowedFromUrl ? 'inspector' : 'layers');
|
|
38
40
|
/** Counts the asks to show a block's fields, so a closed panel knows to open. */
|
|
@@ -47,6 +49,7 @@ export function setBlocksFocusContext(form) {
|
|
|
47
49
|
if (path)
|
|
48
50
|
return;
|
|
49
51
|
selection = [];
|
|
52
|
+
selectedList = null;
|
|
50
53
|
collapsed.clear();
|
|
51
54
|
// Closed back onto the entry the address opened: the address drops its focus too.
|
|
52
55
|
if (page.url.searchParams.has(FOCUS_PARAM))
|
|
@@ -68,6 +71,7 @@ export function setBlocksFocusContext(form) {
|
|
|
68
71
|
* `sections.1`: that block selected, its fields in the panel.
|
|
69
72
|
*/
|
|
70
73
|
function open(target, selected) {
|
|
74
|
+
selectedList = null;
|
|
71
75
|
if (endsOnBlock(target)) {
|
|
72
76
|
selection = [target];
|
|
73
77
|
tab = 'inspector';
|
|
@@ -254,6 +258,7 @@ export function setBlocksFocusContext(form) {
|
|
|
254
258
|
/* ----------------------------------------------------------- selection */
|
|
255
259
|
const currentAt = () => (selection[0] ? parseBlockPath(selection[0]) : null);
|
|
256
260
|
function select(rowPath, options = {}) {
|
|
261
|
+
selectedList = null;
|
|
257
262
|
if (options.extend && selection.length) {
|
|
258
263
|
selection = selection.includes(rowPath)
|
|
259
264
|
? selection.filter((item) => item !== rowPath)
|
|
@@ -278,7 +283,20 @@ export function setBlocksFocusContext(form) {
|
|
|
278
283
|
}
|
|
279
284
|
const selectRoot = () => {
|
|
280
285
|
selection = [];
|
|
286
|
+
selectedList = null;
|
|
281
287
|
};
|
|
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;
|
|
282
300
|
/* ---------------------------------------------------------- operations */
|
|
283
301
|
/** The narrowed block itself: it stays where it is, and what is added goes inside it. */
|
|
284
302
|
const isNarrowedBlock = (rowPath) => !!narrowed && rowPath === path;
|
|
@@ -287,14 +305,14 @@ export function setBlocksFocusContext(form) {
|
|
|
287
305
|
const current = currentAt();
|
|
288
306
|
return current && !isNarrowedBlock(blockPath(current)) ? current : null;
|
|
289
307
|
}
|
|
290
|
-
/** The list the next insert goes to: the selected block's,
|
|
291
|
-
const insertList = () => movableAt()?.list ?? homeList();
|
|
292
|
-
/** Where the palette inserts: after the selected block, else at the end of the
|
|
308
|
+
/** The list the next insert goes to: the selected block's, the selected list, the home list. */
|
|
309
|
+
const insertList = () => movableAt()?.list ?? listSelected() ?? homeList();
|
|
310
|
+
/** Where the palette inserts: after the selected block, else at the end of the list. */
|
|
293
311
|
function insertionPoint() {
|
|
294
312
|
const current = movableAt();
|
|
295
313
|
if (current)
|
|
296
314
|
return { list: current.list, index: current.index + 1 };
|
|
297
|
-
const list = homeList();
|
|
315
|
+
const list = listSelected() ?? homeList();
|
|
298
316
|
if (!list)
|
|
299
317
|
return null;
|
|
300
318
|
return { list, index: form.blocks.list(list).length };
|
|
@@ -305,8 +323,7 @@ export function setBlocksFocusContext(form) {
|
|
|
305
323
|
const config = builderOf(at.list)?.get.blocks.find((candidate) => candidate.name === type)?.get;
|
|
306
324
|
if (!config)
|
|
307
325
|
return null;
|
|
308
|
-
const
|
|
309
|
-
const id = form.blocks.insert(at, empty);
|
|
326
|
+
const id = form.blocks.insert(at, { ...initialValues(config.fields), type });
|
|
310
327
|
select(blockPath(at));
|
|
311
328
|
return id;
|
|
312
329
|
}
|
|
@@ -431,7 +448,10 @@ export function setBlocksFocusContext(form) {
|
|
|
431
448
|
set picking(value) {
|
|
432
449
|
picking = value;
|
|
433
450
|
},
|
|
434
|
-
/**
|
|
451
|
+
/**
|
|
452
|
+
* Opens the picker of types to add. The one picked goes after the selected block, or at the
|
|
453
|
+
* end of the selected list.
|
|
454
|
+
*/
|
|
435
455
|
pick() {
|
|
436
456
|
if (!locked)
|
|
437
457
|
picking = true;
|
|
@@ -442,10 +462,11 @@ export function setBlocksFocusContext(form) {
|
|
|
442
462
|
},
|
|
443
463
|
/** Nothing selected: the root node, and the whole list on the stage. */
|
|
444
464
|
get rootSelected() {
|
|
445
|
-
return selection.length === 0;
|
|
465
|
+
return selection.length === 0 && !listSelected();
|
|
446
466
|
},
|
|
447
467
|
rootLabel,
|
|
448
468
|
selectRoot,
|
|
469
|
+
selectList,
|
|
449
470
|
breadcrumb,
|
|
450
471
|
isSelected: (rowPath) => selection.includes(rowPath),
|
|
451
472
|
isNarrowedBlock,
|
|
@@ -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;
|
|
@@ -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');
|
|
@@ -77,7 +107,9 @@ export class BlocksBuilder extends FormFieldBuilder {
|
|
|
77
107
|
.map((block) => {
|
|
78
108
|
const blockTypeName = `Block${toPascalCase(block.name)}`;
|
|
79
109
|
blockNames.push(blockTypeName);
|
|
80
|
-
|
|
110
|
+
// `type` is written above as the block's name, so its hidden field stays out.
|
|
111
|
+
const fields = block.get.fields.filter((f) => f.name !== 'type');
|
|
112
|
+
const fieldsType = joinMemberTypes(fields.map((f) => f.use.generateType()));
|
|
81
113
|
return dedent `
|
|
82
114
|
//@shared:start ${blockTypeName}
|
|
83
115
|
export type ${blockTypeName} = {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { DefaultValueFn, FormField, OptionWithIcon } from '../types.js';
|
|
1
|
+
import type { DefaultOptions, DefaultValueFn, FormField, OptionWithIcon } from '../types.js';
|
|
2
2
|
import { PickOneFieldBuilder } from '../../core/fields/builders/select-builder.js';
|
|
3
3
|
export declare class ComboBoxFieldBuilder extends PickOneFieldBuilder<ComboBoxField> {
|
|
4
4
|
get component(): import("svelte").Component<import("./component/props.js").ComboBoxProps, {}, "">;
|
|
5
5
|
options(...options: OptionWithIcon[] | string[]): this;
|
|
6
|
-
defaultValue(value: string | DefaultValueFn<string
|
|
6
|
+
defaultValue(value: string | DefaultValueFn<string>, options?: DefaultOptions): this;
|
|
7
7
|
protected generateType(): string;
|
|
8
8
|
}
|
|
9
9
|
export declare const combobox: (name: string) => ComboBoxFieldBuilder;
|
|
@@ -7,8 +7,9 @@ export class ComboBoxFieldBuilder extends PickOneFieldBuilder {
|
|
|
7
7
|
options(...options) {
|
|
8
8
|
return super.options(...options);
|
|
9
9
|
}
|
|
10
|
-
defaultValue(value) {
|
|
10
|
+
defaultValue(value, options) {
|
|
11
11
|
this.field.defaultValue = value;
|
|
12
|
+
this.field.defaultFill = options?.fill;
|
|
12
13
|
return this;
|
|
13
14
|
}
|
|
14
15
|
generateType() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DataType } from '../../core/fields/builders/form-field-builder.js';
|
|
2
2
|
import { FormFieldBuilder } from '../../core/fields/builders/form-field-builder.js';
|
|
3
|
-
import type { DefaultValueFn, FormField } from '../types.js';
|
|
3
|
+
import type { DefaultOptions, DefaultValueFn, FormField } from '../types.js';
|
|
4
4
|
export declare const date: (name: string) => DateFieldBuilder;
|
|
5
5
|
export declare class DateFieldBuilder extends FormFieldBuilder<DateField> {
|
|
6
6
|
constructor(name: string);
|
|
@@ -13,7 +13,7 @@ export declare class DateFieldBuilder extends FormFieldBuilder<DateField> {
|
|
|
13
13
|
get cell(): import("svelte").Component<{
|
|
14
14
|
value: Date | undefined;
|
|
15
15
|
}, {}, "">;
|
|
16
|
-
defaultValue(value: Date | DefaultValueFn<Date
|
|
16
|
+
defaultValue(value: Date | DefaultValueFn<Date>, options?: DefaultOptions): this;
|
|
17
17
|
isTitle(): this;
|
|
18
18
|
protected generateType(): string;
|
|
19
19
|
}
|
|
@@ -22,8 +22,9 @@ export class DateFieldBuilder extends FormFieldBuilder {
|
|
|
22
22
|
get cell() {
|
|
23
23
|
return Cell;
|
|
24
24
|
}
|
|
25
|
-
defaultValue(value) {
|
|
25
|
+
defaultValue(value, options) {
|
|
26
26
|
this.field.defaultValue = value;
|
|
27
|
+
this.field.defaultFill = options?.fill;
|
|
27
28
|
return this;
|
|
28
29
|
}
|
|
29
30
|
isTitle() {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { DataType } from '../../core/fields/builders/form-field-builder.js';
|
|
2
2
|
import { FormFieldBuilder } from '../../core/fields/builders/form-field-builder.js';
|
|
3
|
-
import type { DefaultValueFn, FormField } from '../types.js';
|
|
3
|
+
import type { DefaultOptions, DefaultValueFn, FormField } from '../types.js';
|
|
4
4
|
export declare class EmailFieldBuilder extends FormFieldBuilder<EmailField> {
|
|
5
5
|
constructor(name: string);
|
|
6
6
|
get dataType(): DataType;
|
|
7
7
|
get component(): import("svelte").Component<import("./component/props").EmailFieldProps, {}, "">;
|
|
8
8
|
layout(layout: 'compact' | 'default'): this;
|
|
9
9
|
unique(bool?: boolean): this;
|
|
10
|
-
defaultValue(value: string | DefaultValueFn<string
|
|
10
|
+
defaultValue(value: string | DefaultValueFn<string>, options?: DefaultOptions): this;
|
|
11
11
|
isTitle(): this;
|
|
12
12
|
protected generateType(): string;
|
|
13
13
|
}
|
|
@@ -24,8 +24,9 @@ export class EmailFieldBuilder extends FormFieldBuilder {
|
|
|
24
24
|
this.field.unique = typeof bool === 'boolean' ? bool : true;
|
|
25
25
|
return this;
|
|
26
26
|
}
|
|
27
|
-
defaultValue(value) {
|
|
27
|
+
defaultValue(value, options) {
|
|
28
28
|
this.field.defaultValue = value;
|
|
29
|
+
this.field.defaultFill = options?.fill;
|
|
29
30
|
return this;
|
|
30
31
|
}
|
|
31
32
|
isTitle() {
|
|
@@ -61,6 +61,7 @@ export declare class GroupFieldBuilder extends FormFieldBuilder<GroupField> {
|
|
|
61
61
|
onChange?: import("../types.js").FieldHookClient[];
|
|
62
62
|
};
|
|
63
63
|
defaultValue?: import("../types.js").DefaultValueFn<any> | unknown;
|
|
64
|
+
defaultFill?: import("../types.js").DefaultFill;
|
|
64
65
|
isEmpty: (value: unknown) => boolean;
|
|
65
66
|
root?: boolean;
|
|
66
67
|
index?: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DataType } from '../../core/fields/builders/form-field-builder.js';
|
|
2
2
|
import { FormFieldBuilder } from '../../core/fields/builders/form-field-builder.js';
|
|
3
|
-
import type { DefaultValueFn, FormField } from '../types.js';
|
|
3
|
+
import type { DefaultOptions, DefaultValueFn, FormField } from '../types.js';
|
|
4
4
|
import type { Link, LinkType } from './types.js';
|
|
5
5
|
export declare class LinkFieldBuilder extends FormFieldBuilder<LinkField> {
|
|
6
6
|
constructor(name: string);
|
|
@@ -9,7 +9,7 @@ export declare class LinkFieldBuilder extends FormFieldBuilder<LinkField> {
|
|
|
9
9
|
value: Link | null;
|
|
10
10
|
}, {}, "">;
|
|
11
11
|
layout(str: 'compact' | 'default'): this;
|
|
12
|
-
defaultValue(value: Link | DefaultValueFn<Link
|
|
12
|
+
defaultValue(value: Link | DefaultValueFn<Link>, options?: DefaultOptions): this;
|
|
13
13
|
get dataType(): DataType;
|
|
14
14
|
types(...values: LinkType[]): this;
|
|
15
15
|
static readonly sanitize: (link: unknown) => Link | undefined;
|
|
@@ -52,6 +52,7 @@ export declare class LinkFieldBuilder extends FormFieldBuilder<LinkField> {
|
|
|
52
52
|
target: "_self" | "_blank";
|
|
53
53
|
url?: string | undefined;
|
|
54
54
|
} | undefined;
|
|
55
|
+
defaultFill?: import("../types.js").DefaultFill | undefined;
|
|
55
56
|
isEmpty: (value: unknown) => boolean;
|
|
56
57
|
root?: boolean | undefined;
|
|
57
58
|
index?: boolean | undefined;
|
|
@@ -26,8 +26,9 @@ export class LinkFieldBuilder extends FormFieldBuilder {
|
|
|
26
26
|
this.field.layout = str;
|
|
27
27
|
return this;
|
|
28
28
|
}
|
|
29
|
-
defaultValue(value) {
|
|
29
|
+
defaultValue(value, options) {
|
|
30
30
|
this.field.defaultValue = value;
|
|
31
|
+
this.field.defaultFill = options?.fill;
|
|
31
32
|
return this;
|
|
32
33
|
}
|
|
33
34
|
get dataType() {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { DataType } from '../../core/fields/builders/form-field-builder.js';
|
|
2
2
|
import { FormFieldBuilder } from '../../core/fields/builders/form-field-builder.js';
|
|
3
|
-
import type { DefaultValueFn, FieldValidationFunc, FormField } from '../types.js';
|
|
3
|
+
import type { DefaultOptions, DefaultValueFn, FieldValidationFunc, FormField } from '../types.js';
|
|
4
4
|
export declare const number: (name: string) => NumberFieldBuilder;
|
|
5
5
|
export declare class NumberFieldBuilder extends FormFieldBuilder<NumberField> {
|
|
6
6
|
constructor(name: string);
|
|
7
7
|
get component(): import("svelte").Component<import("./component/props").NumberFieldProps, {}, "">;
|
|
8
|
-
defaultValue(value: number | DefaultValueFn<number
|
|
8
|
+
defaultValue(value: number | DefaultValueFn<number>, options?: DefaultOptions): this;
|
|
9
9
|
min(value: number): this;
|
|
10
10
|
max(value: number): this;
|
|
11
11
|
get dataType(): DataType;
|
|
@@ -43,6 +43,7 @@ export declare class NumberFieldBuilder extends FormFieldBuilder<NumberField> {
|
|
|
43
43
|
onChange?: import("../types.js").FieldHookClient[] | undefined;
|
|
44
44
|
} | undefined;
|
|
45
45
|
defaultValue?: number | DefaultValueFn<number> | undefined;
|
|
46
|
+
defaultFill?: import("../types.js").DefaultFill | undefined;
|
|
46
47
|
isEmpty: (value: unknown) => boolean;
|
|
47
48
|
root?: boolean | undefined;
|
|
48
49
|
index?: boolean | undefined;
|
|
@@ -22,8 +22,9 @@ export class NumberFieldBuilder extends FormFieldBuilder {
|
|
|
22
22
|
get component() {
|
|
23
23
|
return Number;
|
|
24
24
|
}
|
|
25
|
-
defaultValue(value) {
|
|
25
|
+
defaultValue(value, options) {
|
|
26
26
|
this.field.defaultValue = value;
|
|
27
|
+
this.field.defaultFill = options?.fill;
|
|
27
28
|
return this;
|
|
28
29
|
}
|
|
29
30
|
min(value) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DataType } from '../../core/fields/builders/form-field-builder.js';
|
|
2
2
|
import { FormFieldBuilder } from '../../core/fields/builders/form-field-builder.js';
|
|
3
3
|
import type { CollectionSlug, GenericDoc } from '../../core/prototype/types.js';
|
|
4
|
-
import type { DefaultValueFn, FormField } from '../types.js';
|
|
4
|
+
import type { DefaultOptions, DefaultValueFn, FormField } from '../types.js';
|
|
5
5
|
import type { RegisterCollection } from '../../index.js';
|
|
6
6
|
import type { WithOptional } from '../../util/types.js';
|
|
7
7
|
export declare class RelationFieldBuilder<Doc extends GenericDoc = GenericDoc> extends FormFieldBuilder<RelationField<Doc>> {
|
|
@@ -22,7 +22,7 @@ export declare class RelationFieldBuilder<Doc extends GenericDoc = GenericDoc> e
|
|
|
22
22
|
query(query: string | QueryResolver<Doc>): this;
|
|
23
23
|
to<Slug extends CollectionSlug>(slug: Slug): RelationFieldBuilder<RegisterCollection[Slug]>;
|
|
24
24
|
many(): this;
|
|
25
|
-
defaultValue(value: string | string[] | DefaultValueFn<string | string[]
|
|
25
|
+
defaultValue(value: string | string[] | DefaultValueFn<string | string[]>, options?: DefaultOptions): this;
|
|
26
26
|
/** Documentation only — relation fields are diverted into relationFieldsMap/junction
|
|
27
27
|
* tables before reaching the adapter's generic column renderer (see root.server.ts). */
|
|
28
28
|
get dataType(): DataType;
|