rimecms 1.4.2 → 1.4.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.
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
const rendered = $derived.by(() => {
|
|
21
21
|
if (!row) return null;
|
|
22
22
|
const { fields, path } = getFieldListAtPath(
|
|
23
|
-
withBlockTypes(row.path, form.values),
|
|
23
|
+
withBlockTypes(row.path, form.values, form.config.fields),
|
|
24
24
|
form.config.fields
|
|
25
25
|
);
|
|
26
26
|
return { fields: fields.filter((field) => field.type !== 'blocks'), path };
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
// svelte-ignore state_referenced_locally
|
|
28
28
|
let groupOpen = $state(readStored(key) === 'true');
|
|
29
29
|
|
|
30
|
-
const field = $derived(form.useField(path));
|
|
30
|
+
const field = $derived(form.useField(path, config));
|
|
31
31
|
|
|
32
32
|
function handleClick() {
|
|
33
33
|
groupOpen = !groupOpen;
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
<FieldsPreview
|
|
74
74
|
preview={config.get.preview}
|
|
75
75
|
fields={previewFields}
|
|
76
|
-
getField={(field) => form.useField(basePath + field.name)}
|
|
76
|
+
getField={(field) => form.useField(basePath + field.name, field)}
|
|
77
77
|
/>
|
|
78
78
|
</FieldsPreviewTrigger>
|
|
79
79
|
{:else}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FieldBuilder } from '../../core/fields/builders/index.js';
|
|
1
2
|
import type { GenericBlock } from '../../core/prototype/types.js';
|
|
2
3
|
import type { FormErrors } from '../types.js';
|
|
3
4
|
import type { Dic } from '../../util/types.js';
|
|
@@ -40,13 +41,15 @@ export declare const blockPath: (at: BlockAt) => string;
|
|
|
40
41
|
export declare const shiftListPath: (list: string, removed: BlockAt) => string;
|
|
41
42
|
/**
|
|
42
43
|
* The path with each block index carrying its type, read off the document: what
|
|
43
|
-
* `getFieldAtPath` wants.
|
|
44
|
+
* `getFieldAtPath` wants. Only an index in a list of blocks takes a type; a tree row keeps its
|
|
45
|
+
* bare index, even when it holds a field named `type`.
|
|
44
46
|
*
|
|
45
47
|
* ```
|
|
46
|
-
* withBlockTypes('sections.0.items.1', doc) // 'sections.0:grid.items.1:paragraph'
|
|
48
|
+
* withBlockTypes('sections.0.items.1', doc, fields) // 'sections.0:grid.items.1:paragraph'
|
|
49
|
+
* withBlockTypes('links.0.label', doc, fields) // 'links.0.label'
|
|
47
50
|
* ```
|
|
48
51
|
*/
|
|
49
|
-
export declare const withBlockTypes: (path: string, doc: Dic) => string;
|
|
52
|
+
export declare const withBlockTypes: (path: string, doc: Dic, fields: FieldBuilder[]) => string;
|
|
50
53
|
/**
|
|
51
54
|
* Every `path` and `position` under a list, rewritten from the list's own path: the block's, and
|
|
52
55
|
* those of the lists nested in it.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getFieldAtPath } from '../../core/fields/util.js';
|
|
1
2
|
import { getValueAtPath, isObjectLiteral, setValueAtPath } from '../../util/object.js';
|
|
2
3
|
import { isWithin, normalizeFieldPath } from '../../util/string.js';
|
|
3
4
|
import { isTempId, tempId } from '../../util/random.js';
|
|
@@ -36,20 +37,22 @@ export const shiftListPath = (list, removed) => {
|
|
|
36
37
|
};
|
|
37
38
|
/**
|
|
38
39
|
* The path with each block index carrying its type, read off the document: what
|
|
39
|
-
* `getFieldAtPath` wants.
|
|
40
|
+
* `getFieldAtPath` wants. Only an index in a list of blocks takes a type; a tree row keeps its
|
|
41
|
+
* bare index, even when it holds a field named `type`.
|
|
40
42
|
*
|
|
41
43
|
* ```
|
|
42
|
-
* withBlockTypes('sections.0.items.1', doc) // 'sections.0:grid.items.1:paragraph'
|
|
44
|
+
* withBlockTypes('sections.0.items.1', doc, fields) // 'sections.0:grid.items.1:paragraph'
|
|
45
|
+
* withBlockTypes('links.0.label', doc, fields) // 'links.0.label'
|
|
43
46
|
* ```
|
|
44
47
|
*/
|
|
45
|
-
export const withBlockTypes = (path, doc) => {
|
|
48
|
+
export const withBlockTypes = (path, doc, fields) => {
|
|
46
49
|
const parts = normalizeFieldPath(path).split('.');
|
|
47
50
|
const typed = [];
|
|
48
51
|
for (let i = 0; i < parts.length; i++) {
|
|
49
52
|
const part = parts[i];
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
52
|
-
const item = getValueAtPath(
|
|
53
|
+
const isBlockIndex = /^\d+$/.test(part) && getFieldAtPath(typed.join('.'), fields)?.type === 'blocks';
|
|
54
|
+
if (isBlockIndex) {
|
|
55
|
+
const item = getValueAtPath(parts.slice(0, i + 1).join('.'), doc);
|
|
53
56
|
const type = item && isObjectLiteral(item) && typeof item.type === 'string' ? item.type : '';
|
|
54
57
|
typed.push(type ? `${part}:${type}` : part);
|
|
55
58
|
}
|
|
@@ -166,7 +166,8 @@ function createDocumentFormState({ initial, config, readOnly, key, onNestedDocum
|
|
|
166
166
|
},
|
|
167
167
|
/** The `BlocksBuilder` a list path names, read through the document for the block types. */
|
|
168
168
|
builder(list) {
|
|
169
|
-
const
|
|
169
|
+
const typed = withBlockTypes(list, doc, documentConfig.fields);
|
|
170
|
+
const field = getFieldAtPath(typed, documentConfig.fields);
|
|
170
171
|
return field && field.type === 'blocks' ? field : undefined;
|
|
171
172
|
},
|
|
172
173
|
/** Whether the list's block set has this type. */
|
|
@@ -278,11 +279,13 @@ function createDocumentFormState({ initial, config, readOnly, key, onNestedDocum
|
|
|
278
279
|
};
|
|
279
280
|
/**
|
|
280
281
|
* The field at `path`, read and written through the form. `config` is the field's builder;
|
|
281
|
-
* without it, the builder is looked up in the document's fields by `path
|
|
282
|
+
* without it, the builder is looked up in the document's fields by `path`, the block types read
|
|
283
|
+
* off the document: `sections.0.title` -> `sections.0:hero.title`.
|
|
282
284
|
*/
|
|
283
285
|
function useField(path, config) {
|
|
284
286
|
if (!config) {
|
|
285
|
-
const
|
|
287
|
+
const typed = withBlockTypes(path, doc, documentConfig.fields);
|
|
288
|
+
const resolved = getFieldAtPath(typed, documentConfig.fields);
|
|
286
289
|
if (!resolved)
|
|
287
290
|
throw new Error(`can't find config for field : ${path}`);
|
|
288
291
|
config = resolved;
|