rimecms 1.1.3 → 1.1.5
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 +2 -0
- package/dist/core/i18n/en/fields.js +2 -0
- package/dist/core/i18n/fr/fields.d.ts +2 -0
- package/dist/core/i18n/fr/fields.js +2 -0
- 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/index.d.ts +2 -2
- package/dist/fields/blocks/index.js +1 -1
- 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 -8
- package/dist/fields/relation/component/upload/Upload.svelte +236 -46
- 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/component/RichText.svelte +3 -9
- package/dist/fields/rich-text/component/bubble-menu/bubble-menu.css +0 -1
- package/dist/fields/rich-text/component/props.d.ts +0 -1
- package/dist/fields/rich-text/core/build-editor-config.d.ts +0 -1
- package/dist/fields/rich-text/core/features/resource/index.js +6 -1
- package/dist/fields/rich-text/core/features/resource/resource-extension.d.ts +0 -8
- package/dist/fields/rich-text/core/features/resource/resource-extension.js +0 -10
- package/dist/fields/rich-text/json.d.ts +4 -9
- package/dist/fields/rich-text/json.js +8 -6
- package/dist/fields/tabs/component/Tabs.svelte +1 -9
- 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/context/documentForm.svelte.js +2 -2
- 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/relation/util.d.ts +0 -57
- package/dist/fields/relation/util.js +0 -86
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getRequestEvent } from '$app/server';
|
|
2
2
|
import { env } from '$env/dynamic/public';
|
|
3
3
|
import { PARAMS } from '../../core/constants.js';
|
|
4
|
+
import { Relation } from './relation.js';
|
|
4
5
|
import { trycatchFetch } from '../../util/function.js';
|
|
5
6
|
import { toKebabCase } from '../../util/string.js';
|
|
6
7
|
/** Real implementation — resolved server-side via `$rime/fields/relation` (see relation/index.ts,
|
|
@@ -24,24 +25,20 @@ export const ensureRelationExists = async (value, { config }) => {
|
|
|
24
25
|
const { doc } = await response.json();
|
|
25
26
|
return doc;
|
|
26
27
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const doc = await retrieveRelation(value);
|
|
42
|
-
if (doc) {
|
|
43
|
-
output.push(doc.id);
|
|
44
|
-
}
|
|
28
|
+
// One value outside an array is a list of one.
|
|
29
|
+
const entries = Array.isArray(value) ? value : value ? [value] : [];
|
|
30
|
+
for (const entry of entries) {
|
|
31
|
+
// A bare id, a ref, or a document read at depth 1 and sent back. A `null` element — what
|
|
32
|
+
// `[undefined]` becomes over JSON — names nothing, like an unknown id.
|
|
33
|
+
const documentId = typeof entry === 'string'
|
|
34
|
+
? entry
|
|
35
|
+
: Relation.isRef(entry)
|
|
36
|
+
? entry.documentId
|
|
37
|
+
: entry?.id;
|
|
38
|
+
if (!documentId)
|
|
39
|
+
continue;
|
|
40
|
+
if (await retrieveRelation(documentId))
|
|
41
|
+
output.push(entry);
|
|
45
42
|
}
|
|
46
43
|
return output;
|
|
47
44
|
};
|
|
@@ -1,27 +1,10 @@
|
|
|
1
|
-
import { API_PREFIX } from '../../core/routes/constants.js';
|
|
2
1
|
import { isObjectLiteral } from '../../util/object.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
/** One request per document for the page's life. */
|
|
6
|
-
function fetchDoc(slug, id) {
|
|
7
|
-
const key = `${slug}/${id}`;
|
|
8
|
-
if (!cache.has(key)) {
|
|
9
|
-
const url = `${API_PREFIX}/${toKebabCase(slug)}/${id}?depth=1`;
|
|
10
|
-
cache.set(key, fetch(url)
|
|
11
|
-
.then((response) => response.json())
|
|
12
|
-
.then((response) => response?.doc ?? null)
|
|
13
|
-
.catch((error) => {
|
|
14
|
-
console.error(error);
|
|
15
|
-
return null;
|
|
16
|
-
}));
|
|
17
|
-
}
|
|
18
|
-
return cache.get(key);
|
|
19
|
-
}
|
|
2
|
+
import { clearFetchedDocs, fetchDoc } from './fetch.js';
|
|
3
|
+
import { Relation } from './relation.js';
|
|
20
4
|
const isLink = (value) => 'value' in value &&
|
|
21
5
|
'target' in value &&
|
|
22
6
|
'type' in value &&
|
|
23
7
|
!['url', 'email', 'tel', 'anchor'].includes(value.type);
|
|
24
|
-
const isRelation = (value) => 'documentId' in value && 'relationTo' in value;
|
|
25
8
|
/**
|
|
26
9
|
* Relations and resource links resolved at depth 1, the shape the API answers with.
|
|
27
10
|
* A resolved document is returned as is; a relation that cannot be fetched stays a reference.
|
|
@@ -38,7 +21,7 @@ export async function populate(value) {
|
|
|
38
21
|
const doc = await fetchDoc(value.type, value.value);
|
|
39
22
|
return doc?.url ? { ...value, url: doc.url } : value;
|
|
40
23
|
}
|
|
41
|
-
if (
|
|
24
|
+
if (Relation.isRef(value)) {
|
|
42
25
|
if ('livePreview' in value)
|
|
43
26
|
return value.livePreview;
|
|
44
27
|
return ((await fetchDoc(value.relationTo, value.documentId)) ?? value);
|
|
@@ -46,4 +29,4 @@ export async function populate(value) {
|
|
|
46
29
|
const entries = await Promise.all(Object.entries(value).map(async ([key, item]) => [key, await populate(item)]));
|
|
47
30
|
return Object.fromEntries(entries);
|
|
48
31
|
}
|
|
49
|
-
populate.clear =
|
|
32
|
+
populate.clear = clearFetchedDocs;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { RelationRef, RelationValue } from '../types.js';
|
|
2
|
+
type Resolution<T> = {
|
|
3
|
+
/** The first document, or `null`. A promise when it has to be fetched. */
|
|
4
|
+
first(): T | null | Promise<T | null>;
|
|
5
|
+
/** Every document. A promise when some have to be fetched. */
|
|
6
|
+
all(): T[] | Promise<T[]>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The documents a relation value holds. A document is kept as it is, a ref carrying a live preview
|
|
10
|
+
* gives that preview, and any other ref is fetched from the API. Anything else, a bare id
|
|
11
|
+
* included, names no document and gives nothing.
|
|
12
|
+
*
|
|
13
|
+
* `first()` and `all()` answer the documents themselves when nothing has to be fetched, and a
|
|
14
|
+
* promise otherwise; `await` and `{#await}` take either. A ref that cannot be fetched is left out.
|
|
15
|
+
* During server rendering a ref is not fetched: its promise stays pending, and the browser fetches
|
|
16
|
+
* it once the page hydrates.
|
|
17
|
+
*
|
|
18
|
+
* ```svelte
|
|
19
|
+
* {#await Relation.resolve(block.image).first() then image}
|
|
20
|
+
* {#if image}<img src={image.sizes.md} alt={image.alt} />{/if}
|
|
21
|
+
* {/await}
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare function resolve<T>(value: RelationValue<T> | T | RelationRef | null | undefined | false): Resolution<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Reads relation field values.
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* await Relation.resolve(page.author).first(); // UsersDoc | null
|
|
30
|
+
* await Relation.resolve(block.images).all(); // MediasDoc[]
|
|
31
|
+
* Relation.isRef(entry); // true for { relationTo, documentId }, false for a document
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare const Relation: {
|
|
35
|
+
resolve: typeof resolve;
|
|
36
|
+
isRef: (value: unknown) => value is RelationRef;
|
|
37
|
+
};
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { isObjectLiteral } from '../../util/object.js';
|
|
2
|
+
import { fetchDoc } from './fetch.js';
|
|
3
|
+
/** `{ relationTo, documentId }`, whatever else it carries: a ref, not a document. */
|
|
4
|
+
const isRef = (value) => isObjectLiteral(value) &&
|
|
5
|
+
typeof value.relationTo === 'string' &&
|
|
6
|
+
typeof value.documentId === 'string';
|
|
7
|
+
/** Any other object with an `id`: a document, as a read at depth 1 or more hands it back. */
|
|
8
|
+
const isDocument = (value) => isObjectLiteral(value) && !isRef(value) && typeof value.id === 'string';
|
|
9
|
+
/** What a live-edit form puts on a ref: the document as it is being edited. */
|
|
10
|
+
const livePreviewOf = (ref) => ref.livePreview;
|
|
11
|
+
/**
|
|
12
|
+
* The documents a relation value holds. A document is kept as it is, a ref carrying a live preview
|
|
13
|
+
* gives that preview, and any other ref is fetched from the API. Anything else, a bare id
|
|
14
|
+
* included, names no document and gives nothing.
|
|
15
|
+
*
|
|
16
|
+
* `first()` and `all()` answer the documents themselves when nothing has to be fetched, and a
|
|
17
|
+
* promise otherwise; `await` and `{#await}` take either. A ref that cannot be fetched is left out.
|
|
18
|
+
* During server rendering a ref is not fetched: its promise stays pending, and the browser fetches
|
|
19
|
+
* it once the page hydrates.
|
|
20
|
+
*
|
|
21
|
+
* ```svelte
|
|
22
|
+
* {#await Relation.resolve(block.image).first() then image}
|
|
23
|
+
* {#if image}<img src={image.sizes.md} alt={image.alt} />{/if}
|
|
24
|
+
* {/await}
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
function resolve(value) {
|
|
28
|
+
const entries = (Array.isArray(value) ? value : [value]).filter((entry) => isRef(entry) || isDocument(entry));
|
|
29
|
+
const toFetch = (entry) => isRef(entry) && !livePreviewOf(entry);
|
|
30
|
+
const all = () => {
|
|
31
|
+
const read = (entry) => (isRef(entry) ? livePreviewOf(entry) : entry);
|
|
32
|
+
if (!entries.some(toFetch))
|
|
33
|
+
return entries.map(read);
|
|
34
|
+
if (typeof window === 'undefined')
|
|
35
|
+
return new Promise(() => { });
|
|
36
|
+
return Promise.all(entries.map((entry) => toFetch(entry)
|
|
37
|
+
? fetchDoc(entry.relationTo, entry.documentId)
|
|
38
|
+
: read(entry))).then((docs) => docs.filter((doc) => !!doc));
|
|
39
|
+
};
|
|
40
|
+
const first = () => {
|
|
41
|
+
const docs = all();
|
|
42
|
+
return docs instanceof Promise ? docs.then((list) => list[0] ?? null) : (docs[0] ?? null);
|
|
43
|
+
};
|
|
44
|
+
return { first, all };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Reads relation field values.
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* await Relation.resolve(page.author).first(); // UsersDoc | null
|
|
51
|
+
* await Relation.resolve(block.images).all(); // MediasDoc[]
|
|
52
|
+
* Relation.isRef(entry); // true for { relationTo, documentId }, false for a document
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export const Relation = { resolve, isRef };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { describe, expectTypeOf, it } from 'vitest';
|
|
2
|
+
import { Relation } from './relation.js';
|
|
3
|
+
const m1 = { id: 'm1', _type: 'medias' };
|
|
4
|
+
describe('Relation.resolve types', () => {
|
|
5
|
+
it('reads the document type off the value', () => {
|
|
6
|
+
expectTypeOf(Relation.resolve({}).first()).toEqualTypeOf();
|
|
7
|
+
expectTypeOf(Relation.resolve([m1]).all()).toEqualTypeOf();
|
|
8
|
+
expectTypeOf(Relation.resolve(m1).first()).toEqualTypeOf();
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GenericDoc } from '../../core/prototype/types.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { RelationRow } from './index.js';
|
|
3
3
|
/** A related document as the field holds it before it is written: its id, and its row if any. */
|
|
4
4
|
export type RelationItem = {
|
|
5
5
|
documentId: string;
|
|
@@ -22,4 +22,4 @@ export declare function toRelationValue(items: RelationItem[], args: {
|
|
|
22
22
|
path: string;
|
|
23
23
|
locale?: string;
|
|
24
24
|
live?: boolean;
|
|
25
|
-
}): Omit<
|
|
25
|
+
}): Omit<RelationRow, 'ownerId'>[];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { RichText } from '../json.js';
|
|
3
3
|
|
|
4
4
|
let { value }: { value: string } = $props();
|
|
5
5
|
|
|
6
|
-
let textValue: string = $derived(
|
|
6
|
+
let textValue: string = $derived(RichText.toText(value));
|
|
7
7
|
</script>
|
|
8
8
|
|
|
9
9
|
{#if textValue && textValue.length > 10}
|
|
@@ -7,16 +7,12 @@
|
|
|
7
7
|
import type { RichTextFieldProps } from './props.js';
|
|
8
8
|
import './styles/field.css';
|
|
9
9
|
|
|
10
|
-
const { path, config, form,
|
|
10
|
+
const { path, config, form, class: className }: RichTextFieldProps = $props();
|
|
11
11
|
|
|
12
12
|
const field = $derived(form.useField<JSONContent>(path, config));
|
|
13
13
|
</script>
|
|
14
14
|
|
|
15
|
-
<fieldset
|
|
16
|
-
class:rz-field-rich-text--standalone={standAlone}
|
|
17
|
-
class="rz-field-rich-text {config.get.className || ''}"
|
|
18
|
-
use:fieldset={field}
|
|
19
|
-
>
|
|
15
|
+
<fieldset class="rz-field-rich-text {config.get.className || ''}" use:fieldset={field}>
|
|
20
16
|
<Field.Label {config} for={path || config.name} />
|
|
21
17
|
|
|
22
18
|
<Field.Error error={field.error} />
|
|
@@ -31,9 +27,7 @@
|
|
|
31
27
|
onUpdate={(json) => (field.value = json)}
|
|
32
28
|
/>
|
|
33
29
|
|
|
34
|
-
{
|
|
35
|
-
<Field.Hint {config} />
|
|
36
|
-
{/if}
|
|
30
|
+
<Field.Hint {config} />
|
|
37
31
|
</fieldset>
|
|
38
32
|
|
|
39
33
|
<style>
|
|
@@ -12,7 +12,12 @@ export const ResourceFeature = (args) => {
|
|
|
12
12
|
icon: Images,
|
|
13
13
|
isActive: ({ editor }) => editor.isActive('rich-text-resource-' + slug),
|
|
14
14
|
suggestion: {
|
|
15
|
-
|
|
15
|
+
// This feature's own node: each `resource()` is a node type of its own.
|
|
16
|
+
command: ({ editor }) => editor
|
|
17
|
+
.chain()
|
|
18
|
+
.focus()
|
|
19
|
+
.insertContent({ type: 'rich-text-resource-' + slug, attrs: { _fresh: true } })
|
|
20
|
+
.run()
|
|
16
21
|
}
|
|
17
22
|
}
|
|
18
23
|
]
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import type { PrototypeSlug } from '../../../../../core/prototype/types.js';
|
|
2
|
-
import type { Dic } from '../../../../../util/types.js';
|
|
3
2
|
import { Node } from '@tiptap/core';
|
|
4
|
-
declare module '@tiptap/core' {
|
|
5
|
-
interface Commands<ReturnType> {
|
|
6
|
-
resource: {
|
|
7
|
-
insertResource: (attributes?: Dic) => ReturnType;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
3
|
export interface ResourceFeatureExtensionOptions {
|
|
12
4
|
label?: string;
|
|
13
5
|
source: `${PrototypeSlug}${string}`;
|
|
@@ -15,16 +15,6 @@ export const Resource = Node.create({
|
|
|
15
15
|
// A node just inserted opens its dialog; one read from stored content does not.
|
|
16
16
|
{ _fresh: { default: false } });
|
|
17
17
|
},
|
|
18
|
-
addCommands() {
|
|
19
|
-
return {
|
|
20
|
-
insertResource: (attributes = {}) => ({ commands }) => {
|
|
21
|
-
return commands.insertContent({
|
|
22
|
-
type: this.name,
|
|
23
|
-
attrs: { _fresh: true, ...attributes }
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
18
|
parseHTML() {
|
|
29
19
|
return [{ tag: this.name }];
|
|
30
20
|
},
|
|
@@ -7,12 +7,7 @@ import type { JSONContent } from '@tiptap/core';
|
|
|
7
7
|
* isJSONContent('Just a string') // false
|
|
8
8
|
*/
|
|
9
9
|
export declare const isJSONContent: (value: any) => value is JSONContent;
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @example
|
|
15
|
-
* // Returns "Hello world"
|
|
16
|
-
* richTextJSONToText('{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Hello world"}]}]}');
|
|
17
|
-
*/
|
|
18
|
-
export declare const richTextJSONToText: (value: string | JSONContent | undefined) => string;
|
|
10
|
+
/** Reads rich text field values. */
|
|
11
|
+
export declare const RichText: {
|
|
12
|
+
toText: (value: string | JSONContent | undefined) => string;
|
|
13
|
+
};
|
|
@@ -9,14 +9,14 @@ export const isJSONContent = (value) => {
|
|
|
9
9
|
return typeof value === 'object' && value !== null && 'content' in value;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
* Extracts text content from a TipTap/ProseMirror JSON structure.
|
|
12
|
+
* The text of a rich text value, its nodes' text joined by spaces.
|
|
14
13
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* RichText.toText({ type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Hello' }] }] });
|
|
16
|
+
* // 'Hello'
|
|
17
|
+
* ```
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
const toText = (value) => {
|
|
20
20
|
if (!value)
|
|
21
21
|
return '';
|
|
22
22
|
let textValue;
|
|
@@ -42,3 +42,5 @@ export const richTextJSONToText = (value) => {
|
|
|
42
42
|
}
|
|
43
43
|
return textValue;
|
|
44
44
|
};
|
|
45
|
+
/** Reads rich text field values. */
|
|
46
|
+
export const RichText = { toText };
|
|
@@ -86,12 +86,7 @@
|
|
|
86
86
|
<!-- If the first and only field is a rich text field, render it directly -->
|
|
87
87
|
{#if tab.get.fields.length === 1 && tab.get.fields[0].type === 'richText'}
|
|
88
88
|
{@const firstField = tab.get.fields[0] as RichTextFieldBuilder}
|
|
89
|
-
<RichText
|
|
90
|
-
standAlone={true}
|
|
91
|
-
path="{prependPath}{tab.name}.{firstField.name}"
|
|
92
|
-
config={firstField}
|
|
93
|
-
{form}
|
|
94
|
-
/>
|
|
89
|
+
<RichText path="{prependPath}{tab.name}.{firstField.name}" config={firstField} {form} />
|
|
95
90
|
{:else}
|
|
96
91
|
<!-- Otherwise, render the fields -->
|
|
97
92
|
<RenderFields fields={tab.get.fields} path="{prependPath}{tab.name}" {form} />
|
|
@@ -104,9 +99,6 @@
|
|
|
104
99
|
|
|
105
100
|
<style>
|
|
106
101
|
.rz-tabs__bar {
|
|
107
|
-
position: sticky;
|
|
108
|
-
top: var(--rz-tabs-list-top, var(--rz-size-11));
|
|
109
|
-
z-index: 40;
|
|
110
102
|
margin-inline: calc(-1 * var(--rz-fields-padding));
|
|
111
103
|
padding: var(--rz-size-2) var(--rz-fields-padding);
|
|
112
104
|
}
|
package/dist/fields/types.d.ts
CHANGED
|
@@ -130,7 +130,10 @@ export type RelationRef = {
|
|
|
130
130
|
relationTo: string;
|
|
131
131
|
documentId: string;
|
|
132
132
|
};
|
|
133
|
-
|
|
133
|
+
/** A relation as a read answers it: the documents at depth 1 or more, refs at depth 0. */
|
|
134
|
+
export type RelationValue<T> = T[] | RelationRef[];
|
|
135
|
+
/** What a write takes for a relation: what a read answers, or bare ids. */
|
|
136
|
+
export type RelationInput<T> = RelationValue<T> | string[] | string;
|
|
134
137
|
export type BaseUseFieldReturn = {
|
|
135
138
|
path: string;
|
|
136
139
|
value: any;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<script lang="ts" generics="T">
|
|
2
2
|
import { getLiveContext } from './context.svelte.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { WithRelationResolved } from '../core/fields/types.js';
|
|
4
4
|
import type { Snippet } from 'svelte';
|
|
5
5
|
|
|
6
6
|
let { child, data } = $props<{
|
|
7
|
-
child: Snippet<[doc:
|
|
7
|
+
child: Snippet<[doc: WithRelationResolved<T>]>;
|
|
8
8
|
data: { doc: T };
|
|
9
9
|
}>();
|
|
10
10
|
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
const doc = $derived(live.doc || data.doc) as
|
|
19
|
+
const doc = $derived(live.doc || data.doc) as WithRelationResolved<T>;
|
|
20
20
|
</script>
|
|
21
21
|
|
|
22
22
|
{@render child(doc)}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WithRelationResolved } from '../core/fields/types.js';
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
declare function $$render<T>(): {
|
|
4
4
|
props: {
|
|
5
|
-
child: Snippet<[doc:
|
|
5
|
+
child: Snippet<[doc: WithRelationResolved<T>]>;
|
|
6
6
|
data: {
|
|
7
7
|
doc: T;
|
|
8
8
|
};
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { PARAMS } from '../../../../../../core/constants.js';
|
|
5
5
|
import { UPLOAD_PATH } from '../../../../../../core/prototype/collection/upload/constant.js';
|
|
6
6
|
import { isUploadConfig } from '../../../../../../core/prototype/collection/upload/util/config';
|
|
7
|
+
import { getMimeTypeFromExtension } from '../../../../../../core/prototype/collection/upload/util/mime';
|
|
7
8
|
import type { GenericDoc } from '../../../../../../core/prototype/types';
|
|
8
9
|
import { panelPath } from '../../../../../../core/routes/util';
|
|
9
10
|
import { getLocaleContext } from '../../../../../context/locale.svelte.js';
|
|
@@ -29,7 +30,12 @@
|
|
|
29
30
|
const isUploadCollection = $derived(isUploadConfig(config));
|
|
30
31
|
const hasDraft = $derived(!!(config.versions && config.versions.draft));
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
// A file's own type, else the one its thumbnail's extension names: a page shows its image.
|
|
34
|
+
const mimeType = $derived.by(() => {
|
|
35
|
+
if (typeof doc.mimeType === 'string') return doc.mimeType;
|
|
36
|
+
const url = typeof doc._thumbnail === 'string' ? doc._thumbnail : '';
|
|
37
|
+
return getMimeTypeFromExtension(url.split('.').pop() || '') || '';
|
|
38
|
+
});
|
|
33
39
|
const isImage = $derived(!!doc._thumbnail && mimeType.startsWith('image/'));
|
|
34
40
|
// A photo fills its frame; a png, a gif or an svg may be a logo, so it shows whole.
|
|
35
41
|
const contain = $derived(/^image\/(png|gif|svg)/.test(mimeType));
|
|
@@ -7,7 +7,7 @@ import { getFieldAtPath } from '../../core/fields/util.js';
|
|
|
7
7
|
import { buildConfigMap } from '../../core/pipeline/config-map/index.js';
|
|
8
8
|
import { AUTO_SAVE_DELAY_MS, VERSIONS_STATUS } from '../../core/prototype/shared/versions/constant.js';
|
|
9
9
|
import { apiUrl, panelUrl } from '../../core/routes/util.js';
|
|
10
|
-
import { isJSONContent,
|
|
10
|
+
import { isJSONContent, RichText } from '../../fields/rich-text/json.js';
|
|
11
11
|
import { isObjectLiteral, omit } from '../../util/object.js';
|
|
12
12
|
import { normalizeFieldPath } from '../../util/string.js';
|
|
13
13
|
import { randomId } from '../../util/random.js';
|
|
@@ -82,7 +82,7 @@ function createDocumentFormState({ initial, config, readOnly, key, onNestedDocum
|
|
|
82
82
|
function computeTitleFromValue(value) {
|
|
83
83
|
// Handle rich text value
|
|
84
84
|
if (isJSONContent(value)) {
|
|
85
|
-
return
|
|
85
|
+
return RichText.toText(value);
|
|
86
86
|
}
|
|
87
87
|
if (typeof value === 'string') {
|
|
88
88
|
return value;
|
package/dist/public.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { getI18nContext, setI18nContext } from './core/i18n/context.js';
|
|
2
2
|
import { createI18n } from './core/i18n/index.js';
|
|
3
3
|
import { openSse } from './core/plugins/sse/index.js';
|
|
4
|
-
import {
|
|
4
|
+
import { Relation } from './fields/relation/relation.js';
|
|
5
5
|
import RenderRichText from './fields/rich-text/core/render-rich-text.svelte';
|
|
6
|
-
import {
|
|
6
|
+
import { RichText } from './fields/rich-text/json.js';
|
|
7
7
|
import LiveConsumer from './live/Consumer.svelte';
|
|
8
8
|
import LiveEdit from './live/LiveEdit.svelte';
|
|
9
9
|
import LiveProvider from './live/Provider.svelte';
|
|
10
10
|
export type { SSEEvent, SSEHandler } from './core/plugins/sse/index.js';
|
|
11
11
|
export type { RichTextNodeRenderer, RichTextNodeRendererProps } from './fields/rich-text/core/types.js';
|
|
12
12
|
export type { JSONContent } from '@tiptap/core';
|
|
13
|
-
export { createI18n, getI18nContext,
|
|
13
|
+
export { createI18n, getI18nContext, LiveConsumer, LiveEdit, LiveProvider, openSse, Relation, RenderRichText, RichText, setI18nContext };
|
package/dist/public.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
import { getI18nContext, setI18nContext } from './core/i18n/context.js';
|
|
4
4
|
import { createI18n } from './core/i18n/index.js';
|
|
5
5
|
import { openSse } from './core/plugins/sse/index.js';
|
|
6
|
-
import {
|
|
6
|
+
import { Relation } from './fields/relation/relation.js';
|
|
7
7
|
import RenderRichText from './fields/rich-text/core/render-rich-text.svelte';
|
|
8
|
-
import {
|
|
8
|
+
import { RichText } from './fields/rich-text/json.js';
|
|
9
9
|
import LiveConsumer from './live/Consumer.svelte';
|
|
10
10
|
import LiveEdit from './live/LiveEdit.svelte';
|
|
11
11
|
import LiveProvider from './live/Provider.svelte';
|
|
12
|
-
export { createI18n, getI18nContext,
|
|
12
|
+
export { createI18n, getI18nContext, LiveConsumer, LiveEdit, LiveProvider, openSse, Relation, RenderRichText, RichText, setI18nContext };
|
package/dist/types.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type { CollectionProps, FieldPanelTableConfig, FormErrors, Navigation, Ro
|
|
|
10
10
|
export type { DocumentFormContext } from './panel/context/documentForm.svelte.js';
|
|
11
11
|
export type { JsonFile, UploadDoc } from './core/prototype/collection/upload/types.js';
|
|
12
12
|
export type { Link } from './fields/link/types.js';
|
|
13
|
-
export type {
|
|
13
|
+
export type { WithRelationInput, WithRelationResolved } from './core/fields/types.js';
|
|
14
14
|
export type { RouteHandlers } from './core/routes/handler.server.js';
|
|
15
15
|
export type { Plugin } from './core/plugins/index.js';
|
|
16
16
|
export type { SSEAccess, SSEConfig } from './core/plugins/sse/types.js';
|
package/dist/util/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generic type utilities. Nothing here names a rime type — that is the rule that keeps this
|
|
3
|
-
* file in util/. The
|
|
3
|
+
* file in util/. The ones that do (WithRelationResolved, WithoutBuilders) are in
|
|
4
4
|
* core/fields/types.ts.
|
|
5
5
|
*/
|
|
6
6
|
export type OmitPreservingDiscrimination<T, K extends keyof T> = T extends any ? Omit<T, K> : never;
|
package/dist/util/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generic type utilities. Nothing here names a rime type — that is the rule that keeps this
|
|
3
|
-
* file in util/. The
|
|
3
|
+
* file in util/. The ones that do (WithRelationResolved, WithoutBuilders) are in
|
|
4
4
|
* core/fields/types.ts.
|
|
5
5
|
*/
|
|
6
6
|
/**
|
package/package.json
CHANGED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { RelationRef, RelationValue } from '../types.js';
|
|
2
|
-
import type { Relation } from './index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Checks if a relation field's value is populated with full documents.
|
|
5
|
-
*
|
|
6
|
-
* A relation is populated when it is a non-empty array of documents: objects that are not
|
|
7
|
-
* relation references (`id`, `relationTo`, `documentId`). Anything else is not populated.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* isRelationPopulated([{ id: '7674…', title: 'Home' }]); // true
|
|
11
|
-
* isRelationPopulated('7674e91b-598a-4a72-a5cd-9594736a34dd'); // false
|
|
12
|
-
* isRelationPopulated([{ id: '7674…', relationTo: 'articles', documentId: 'b674…' }]); // false
|
|
13
|
-
* isRelationPopulated([]); // false
|
|
14
|
-
* isRelationPopulated(undefined); // false
|
|
15
|
-
* isRelationPopulated(null); // false
|
|
16
|
-
*/
|
|
17
|
-
export declare const isRelationPopulated: <T>(value: RelationValue<T> | null | undefined) => value is T[];
|
|
18
|
-
/**
|
|
19
|
-
* Checks if a relation value is resolved (contains the actual referenced document).
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* // Returns true for a resolved relation
|
|
23
|
-
* isRelationResolved({ title: 'Home Page', _prototype: 'collection', _type: 'pages' });
|
|
24
|
-
*/
|
|
25
|
-
export declare const isRelationResolved: <T>(value: any) => value is T;
|
|
26
|
-
/**
|
|
27
|
-
* Checks if a relation value is a reference (contains only the relationTo and documentId).
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* // Returns true for a relation reference
|
|
31
|
-
* isRelationRef({ relationTo: 'pages', documentId: '123' });
|
|
32
|
-
*/
|
|
33
|
-
export declare const isRelationRef: (value: unknown) => value is RelationRef;
|
|
34
|
-
/**
|
|
35
|
-
* Checks if a relation value is unresolved (contains only reference information).
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* // Returns true for an unresolved relation
|
|
39
|
-
* isRelationUnresolved({ relationTo: 'pages', documentId: '123' });
|
|
40
|
-
*/
|
|
41
|
-
export declare const isRelationUnresolved: (value: any) => value is Omit<Relation, "path" | "position" | "ownerId">;
|
|
42
|
-
/**
|
|
43
|
-
* Resolves a relation reference to the actual document it points to.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* // Resolves a relation reference to the actual document
|
|
47
|
-
* const doc = await resolveRelationRef({ relationTo: 'pages', documentId: '123' });
|
|
48
|
-
*/
|
|
49
|
-
export declare function resolveRelationRef<T>(item: T | RelationRef | string): Promise<T>;
|
|
50
|
-
/**
|
|
51
|
-
* Resolves a relation field value to the actual documents it points to.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* // Resolves a relation value to the actual documents
|
|
55
|
-
* const docs = await resolveRelation([{ relationTo: 'pages', documentId: '123' }]);
|
|
56
|
-
*/
|
|
57
|
-
export declare function resolveRelation<T>(value: RelationValue<T> | null | undefined): Promise<T[] | null | undefined>;
|