rimecms 1.1.1 → 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 +30 -0
- 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/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/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 +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
|
@@ -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 { JSONContent } from '@tiptap/core';
|
|
5
5
|
import type { RichTextFeature } from './core/types.js';
|
|
6
6
|
export declare class RichTextFieldBuilder extends FormFieldBuilder<RichTextField> {
|
|
@@ -27,7 +27,7 @@ export declare class RichTextFieldBuilder extends FormFieldBuilder<RichTextField
|
|
|
27
27
|
static readonly jsonParse: (value: string) => string;
|
|
28
28
|
static readonly sanitize: (value: unknown) => any;
|
|
29
29
|
static readonly stringify: (value: string) => string;
|
|
30
|
-
defaultValue(value: RichTextContent | DefaultValueFn<RichTextContent
|
|
30
|
+
defaultValue(value: RichTextContent | DefaultValueFn<RichTextContent>, options?: DefaultOptions): this;
|
|
31
31
|
get dataType(): DataType;
|
|
32
32
|
protected generateType(): string;
|
|
33
33
|
}
|
|
@@ -95,8 +95,9 @@ export class RichTextFieldBuilder extends FormFieldBuilder {
|
|
|
95
95
|
}
|
|
96
96
|
return value;
|
|
97
97
|
};
|
|
98
|
-
defaultValue(value) {
|
|
98
|
+
defaultValue(value, options) {
|
|
99
99
|
this.field.defaultValue = value;
|
|
100
|
+
this.field.defaultFill = options?.fill;
|
|
100
101
|
return this;
|
|
101
102
|
}
|
|
102
103
|
get dataType() {
|
|
@@ -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 slug: (name: string) => SlugFieldBuilder;
|
|
5
5
|
export declare class SlugFieldBuilder extends FormFieldBuilder<SlugField> {
|
|
6
6
|
constructor(name: string);
|
|
@@ -15,7 +15,7 @@ export declare class SlugFieldBuilder extends FormFieldBuilder<SlugField> {
|
|
|
15
15
|
placeholder(placeholder: string): this;
|
|
16
16
|
slugify(fieldName: string): this;
|
|
17
17
|
layout(layout: 'compact' | 'default'): this;
|
|
18
|
-
defaultValue(value: string | DefaultValueFn<string
|
|
18
|
+
defaultValue(value: string | DefaultValueFn<string>, options?: DefaultOptions): this;
|
|
19
19
|
unique(bool?: boolean): this;
|
|
20
20
|
get dataType(): DataType;
|
|
21
21
|
isTitle(): this;
|
|
@@ -53,6 +53,7 @@ export declare class SlugFieldBuilder extends FormFieldBuilder<SlugField> {
|
|
|
53
53
|
onChange?: import("../types.js").FieldHookClient[] | undefined;
|
|
54
54
|
} | undefined;
|
|
55
55
|
defaultValue?: string | DefaultValueFn<string> | undefined;
|
|
56
|
+
defaultFill?: import("../types.js").DefaultFill | undefined;
|
|
56
57
|
isEmpty: (value: unknown) => boolean;
|
|
57
58
|
root?: boolean | undefined;
|
|
58
59
|
index?: boolean | undefined;
|
|
@@ -31,8 +31,9 @@ export class SlugFieldBuilder extends FormFieldBuilder {
|
|
|
31
31
|
this.field.layout = layout;
|
|
32
32
|
return this;
|
|
33
33
|
}
|
|
34
|
-
defaultValue(value) {
|
|
34
|
+
defaultValue(value, options) {
|
|
35
35
|
this.field.defaultValue = value;
|
|
36
|
+
this.field.defaultFill = options?.fill;
|
|
36
37
|
return this;
|
|
37
38
|
}
|
|
38
39
|
unique(bool) {
|
|
@@ -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
|
/****************************************************/
|
|
5
5
|
export declare class TextFieldBuilder extends FormFieldBuilder<TextField> {
|
|
6
6
|
constructor(name: string);
|
|
7
7
|
unique(bool?: boolean): this;
|
|
8
8
|
get component(): import("svelte").Component<import("./component/props").TextFieldProps, {}, "">;
|
|
9
9
|
get cell(): null;
|
|
10
|
-
defaultValue(value: string | DefaultValueFn<string
|
|
10
|
+
defaultValue(value: string | DefaultValueFn<string>, options?: DefaultOptions): this;
|
|
11
11
|
get dataType(): DataType;
|
|
12
12
|
isTitle(): this;
|
|
13
13
|
placeholder(str: string): this;
|
|
@@ -50,6 +50,7 @@ export declare class TextFieldBuilder extends FormFieldBuilder<TextField> {
|
|
|
50
50
|
beforeValidate?: import("../types.js").FieldHookShared<any>[] | undefined;
|
|
51
51
|
onChange?: import("../types.js").FieldHookClient[] | undefined;
|
|
52
52
|
} | undefined;
|
|
53
|
+
defaultFill?: import("../types.js").DefaultFill | undefined;
|
|
53
54
|
isEmpty: (value: unknown) => boolean;
|
|
54
55
|
root?: boolean | undefined;
|
|
55
56
|
index?: boolean | undefined;
|
|
@@ -19,8 +19,9 @@ export class TextFieldBuilder extends FormFieldBuilder {
|
|
|
19
19
|
get cell() {
|
|
20
20
|
return null;
|
|
21
21
|
}
|
|
22
|
-
defaultValue(value) {
|
|
22
|
+
defaultValue(value, options) {
|
|
23
23
|
this.field.defaultValue = value;
|
|
24
|
+
this.field.defaultFill = options?.fill;
|
|
24
25
|
return this;
|
|
25
26
|
}
|
|
26
27
|
get dataType() {
|
|
@@ -1,12 +1,12 @@
|
|
|
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 textarea: (name: string) => TextAreaFieldBuilder;
|
|
5
5
|
export declare class TextAreaFieldBuilder extends FormFieldBuilder<TextAreaField> {
|
|
6
6
|
constructor(name: string);
|
|
7
7
|
get component(): import("svelte").Component<import("./component/props").TextAreaFieldProps, {}, "">;
|
|
8
8
|
get cell(): null;
|
|
9
|
-
defaultValue(value: string | DefaultValueFn<string
|
|
9
|
+
defaultValue(value: string | DefaultValueFn<string>, options?: DefaultOptions): this;
|
|
10
10
|
get dataType(): DataType;
|
|
11
11
|
isTitle(): this;
|
|
12
12
|
placeholder(str: string): this;
|
|
@@ -44,6 +44,7 @@ export declare class TextAreaFieldBuilder extends FormFieldBuilder<TextAreaField
|
|
|
44
44
|
onChange?: import("../types.js").FieldHookClient[] | undefined;
|
|
45
45
|
} | undefined;
|
|
46
46
|
defaultValue?: string | DefaultValueFn<string> | undefined;
|
|
47
|
+
defaultFill?: import("../types.js").DefaultFill | undefined;
|
|
47
48
|
isEmpty: (value: unknown) => boolean;
|
|
48
49
|
root?: boolean | undefined;
|
|
49
50
|
index?: boolean | undefined;
|
|
@@ -15,8 +15,9 @@ export class TextAreaFieldBuilder extends FormFieldBuilder {
|
|
|
15
15
|
get cell() {
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
|
-
defaultValue(value) {
|
|
18
|
+
defaultValue(value, options) {
|
|
19
19
|
this.field.defaultValue = value;
|
|
20
|
+
this.field.defaultFill = options?.fill;
|
|
20
21
|
return this;
|
|
21
22
|
}
|
|
22
23
|
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, FormField } from '../types.js';
|
|
3
|
+
import type { DefaultOptions, DefaultValueFn, FormField } from '../types.js';
|
|
4
4
|
export declare const time: (name: string) => TimeFieldBuilder;
|
|
5
5
|
export declare class TimeFieldBuilder extends FormFieldBuilder<TimeField> {
|
|
6
6
|
constructor(name: string);
|
|
7
7
|
get component(): import("svelte").Component<import("./component/props").TimeFieldProps, {}, "">;
|
|
8
|
-
defaultValue(value: string | DefaultValueFn<string
|
|
8
|
+
defaultValue(value: string | DefaultValueFn<string>, options?: DefaultOptions): this;
|
|
9
9
|
get dataType(): DataType;
|
|
10
10
|
protected generateType(): string;
|
|
11
11
|
}
|
|
@@ -15,8 +15,9 @@ export class TimeFieldBuilder extends FormFieldBuilder {
|
|
|
15
15
|
get component() {
|
|
16
16
|
return TimeComponent;
|
|
17
17
|
}
|
|
18
|
-
defaultValue(value) {
|
|
18
|
+
defaultValue(value, options) {
|
|
19
19
|
this.field.defaultValue = value;
|
|
20
|
+
this.field.defaultFill = options?.fill;
|
|
20
21
|
return this;
|
|
21
22
|
}
|
|
22
23
|
get dataType() {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { BooleanFieldBuilder } from '../../core/fields/builders/boolean-builder.js';
|
|
2
|
-
import type { DefaultValueFn, FormField } from '../types.js';
|
|
2
|
+
import type { DefaultOptions, DefaultValueFn, FormField } from '../types.js';
|
|
3
3
|
export declare class ToggleFieldBuilder extends BooleanFieldBuilder<ToggleField> {
|
|
4
4
|
constructor(name: string);
|
|
5
5
|
get component(): import("svelte").Component<import("./component/props").ToggleProps, {}, "">;
|
|
6
6
|
get cell(): import("svelte").Component<{
|
|
7
7
|
value: boolean | null;
|
|
8
8
|
}, {}, "">;
|
|
9
|
-
defaultValue(value: boolean | DefaultValueFn<boolean
|
|
9
|
+
defaultValue(value: boolean | DefaultValueFn<boolean>, options?: DefaultOptions): this;
|
|
10
10
|
compile(): {
|
|
11
11
|
type: "toggle";
|
|
12
12
|
defaultValue?: (boolean | DefaultValueFn<boolean>) | undefined;
|
|
@@ -41,6 +41,7 @@ export declare class ToggleFieldBuilder extends BooleanFieldBuilder<ToggleField>
|
|
|
41
41
|
beforeValidate?: import("../types.js").FieldHookShared<any>[] | undefined;
|
|
42
42
|
onChange?: import("../types.js").FieldHookClient[] | undefined;
|
|
43
43
|
} | undefined;
|
|
44
|
+
defaultFill?: import("../types.js").DefaultFill | undefined;
|
|
44
45
|
isEmpty: (value: unknown) => boolean;
|
|
45
46
|
root?: boolean | undefined;
|
|
46
47
|
index?: boolean | undefined;
|
|
@@ -4,7 +4,6 @@ import Toggle from './component/Toggle.svelte';
|
|
|
4
4
|
export class ToggleFieldBuilder extends BooleanFieldBuilder {
|
|
5
5
|
constructor(name) {
|
|
6
6
|
super(name, 'toggle');
|
|
7
|
-
this.field.isEmpty = (value) => typeof value !== 'boolean';
|
|
8
7
|
}
|
|
9
8
|
get component() {
|
|
10
9
|
return Toggle;
|
|
@@ -12,8 +11,9 @@ export class ToggleFieldBuilder extends BooleanFieldBuilder {
|
|
|
12
11
|
get cell() {
|
|
13
12
|
return Cell;
|
|
14
13
|
}
|
|
15
|
-
defaultValue(value) {
|
|
14
|
+
defaultValue(value, options) {
|
|
16
15
|
this.field.defaultValue = value;
|
|
16
|
+
this.field.defaultFill = options?.fill;
|
|
17
17
|
return this;
|
|
18
18
|
}
|
|
19
19
|
compile() {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { FieldBuilder } from '../../../core/fields/builders';
|
|
3
|
-
import {
|
|
3
|
+
import { initialValues } from '../../../core/fields/initial.js';
|
|
4
4
|
import type { Field } from '../../types.js';
|
|
5
5
|
import Button from '../../../panel/components/ui/button/button.svelte';
|
|
6
6
|
import type { Dic } from '../../../util/types';
|
|
7
7
|
import { Plus } from '@lucide/svelte';
|
|
8
8
|
import type { Snippet } from 'svelte';
|
|
9
9
|
|
|
10
|
-
type AddItem = (
|
|
10
|
+
type AddItem = (values: Dic) => void;
|
|
11
11
|
type Props = {
|
|
12
12
|
size: 'default' | 'sm';
|
|
13
13
|
class: string;
|
|
@@ -18,8 +18,7 @@
|
|
|
18
18
|
const { class: className, fields, addItem, size, children }: Props = $props();
|
|
19
19
|
|
|
20
20
|
const add = () => {
|
|
21
|
-
|
|
22
|
-
addItem(empty);
|
|
21
|
+
addItem(initialValues(fields));
|
|
23
22
|
};
|
|
24
23
|
</script>
|
|
25
24
|
|
|
@@ -2,7 +2,7 @@ import type { FieldBuilder } from '../../../core/fields/builders';
|
|
|
2
2
|
import type { Field } from '../../types.js';
|
|
3
3
|
import type { Dic } from '../../../util/types';
|
|
4
4
|
import type { Snippet } from 'svelte';
|
|
5
|
-
type AddItem = (
|
|
5
|
+
type AddItem = (values: Dic) => void;
|
|
6
6
|
type Props = {
|
|
7
7
|
size: 'default' | 'sm';
|
|
8
8
|
class: string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { FieldBuilder } from '../../core/fields/builders/field-builder.js';
|
|
2
|
+
import type { Field } from '../types.js';
|
|
3
|
+
import type { Dic } from '../../util/types.js';
|
|
4
|
+
/** A tree item in a default: the values it starts with, and its own items. */
|
|
5
|
+
export type TreeItemDefault = Dic & {
|
|
6
|
+
_children?: TreeItemDefault[];
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A default tree as a document holds it: each item with a fresh temporary id and the initial
|
|
10
|
+
* values of the tree's fields, the values it names winning, its `_children` completed the same
|
|
11
|
+
* way. A new copy on each call.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* completeTree([text('label')], [{ label: 'Home', _children: [{ label: 'About' }] }]);
|
|
15
|
+
* // [{
|
|
16
|
+
* // id: 'temp-…', path: null, position: null, label: 'Home',
|
|
17
|
+
* // _children: [{ id: 'temp-…', path: null, position: null, label: 'About', _children: [] }]
|
|
18
|
+
* // }]
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const completeTree: (fields: FieldBuilder<Field>[], value: TreeItemDefault[]) => Dic[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { completeItem } from '../../core/fields/complete.js';
|
|
2
|
+
/**
|
|
3
|
+
* A default tree as a document holds it: each item with a fresh temporary id and the initial
|
|
4
|
+
* values of the tree's fields, the values it names winning, its `_children` completed the same
|
|
5
|
+
* way. A new copy on each call.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* completeTree([text('label')], [{ label: 'Home', _children: [{ label: 'About' }] }]);
|
|
9
|
+
* // [{
|
|
10
|
+
* // id: 'temp-…', path: null, position: null, label: 'Home',
|
|
11
|
+
* // _children: [{ id: 'temp-…', path: null, position: null, label: 'About', _children: [] }]
|
|
12
|
+
* // }]
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export const completeTree = (fields, value) => value.map((given) => ({
|
|
16
|
+
...completeItem(fields, given),
|
|
17
|
+
_children: completeTree(fields, given._children ?? [])
|
|
18
|
+
}));
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { FieldBuilder, type FieldNode, type ValueNode } from '../../core/fields/builders/field-builder.js';
|
|
2
|
-
import { FormFieldBuilder } from '../../core/fields/builders/form-field-builder.js';
|
|
3
|
-
import type {
|
|
2
|
+
import { FormFieldBuilder, type FormFieldUse } from '../../core/fields/builders/form-field-builder.js';
|
|
3
|
+
import type { CompletesDefault } from '../../core/fields/complete.js';
|
|
4
|
+
import type { DefaultOptions, DefaultValueFn, Field, FormField } from '../types.js';
|
|
4
5
|
import type { Dic } from '../../util/types.js';
|
|
6
|
+
import { type TreeItemDefault } from './defaults.js';
|
|
5
7
|
export declare const tree: (name: string) => TreeBuilder;
|
|
6
8
|
export declare class TreeBuilder extends FormFieldBuilder<TreeField> {
|
|
7
9
|
constructor(name: string);
|
|
@@ -15,6 +17,17 @@ export declare class TreeBuilder extends FormFieldBuilder<TreeField> {
|
|
|
15
17
|
addItemLabel(label: string): this;
|
|
16
18
|
renderTitle(render: TreeFieldBlockRenderTitle): this;
|
|
17
19
|
maxDepth(n: number): this;
|
|
20
|
+
/**
|
|
21
|
+
* The items a new document starts with. Each names the values it starts with and its own
|
|
22
|
+
* `_children`; the rest comes from the tree's fields.
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* tree('nav').fields(text('label')).defaultValue([{ label: 'Home', _children: [{ label: 'About' }] }]);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
defaultValue(value: TreeItemDefault[] | DefaultValueFn<TreeItemDefault[]>, options?: DefaultOptions): this;
|
|
29
|
+
/** The default completed as a document holds it — see `completeTree`. */
|
|
30
|
+
get use(): FormFieldUse<TreeField> & CompletesDefault<TreeItemDefault>;
|
|
18
31
|
localized(): this;
|
|
19
32
|
compile(): {
|
|
20
33
|
fields: ({
|
|
@@ -63,7 +76,8 @@ export declare class TreeBuilder extends FormFieldBuilder<TreeField> {
|
|
|
63
76
|
beforeValidate?: import("../types.js").FieldHookShared[];
|
|
64
77
|
onChange?: import("../types.js").FieldHookClient[];
|
|
65
78
|
};
|
|
66
|
-
defaultValue?:
|
|
79
|
+
defaultValue?: DefaultValueFn<any> | unknown;
|
|
80
|
+
defaultFill?: import("../types.js").DefaultFill;
|
|
67
81
|
isEmpty: (value: unknown) => boolean;
|
|
68
82
|
root?: boolean;
|
|
69
83
|
index?: boolean;
|
|
@@ -6,6 +6,7 @@ import { number } from '../number/index.js';
|
|
|
6
6
|
import { text } from '../text/index.js';
|
|
7
7
|
import Cell from './component/Cell.svelte';
|
|
8
8
|
import Tree from './component/Tree.svelte';
|
|
9
|
+
import { completeTree } from './defaults.js';
|
|
9
10
|
export const tree = (name) => new TreeBuilder(name);
|
|
10
11
|
export class TreeBuilder extends FormFieldBuilder {
|
|
11
12
|
constructor(name) {
|
|
@@ -38,6 +39,32 @@ export class TreeBuilder extends FormFieldBuilder {
|
|
|
38
39
|
this.field.maxDepth = n;
|
|
39
40
|
return this;
|
|
40
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* The items a new document starts with. Each names the values it starts with and its own
|
|
44
|
+
* `_children`; the rest comes from the tree's fields.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* tree('nav').fields(text('label')).defaultValue([{ label: 'Home', _children: [{ label: 'About' }] }]);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
defaultValue(value, options) {
|
|
51
|
+
this.field.defaultValue = value;
|
|
52
|
+
this.field.defaultFill = options?.fill;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
/** The default completed as a document holds it — see `completeTree`. */
|
|
56
|
+
get use() {
|
|
57
|
+
const use = super.use;
|
|
58
|
+
const completeDefault = (value) => completeTree(this.field.fields, value);
|
|
59
|
+
return {
|
|
60
|
+
...use,
|
|
61
|
+
completeDefault,
|
|
62
|
+
defaultValue: (context = {}) => {
|
|
63
|
+
const value = use.defaultValue(context);
|
|
64
|
+
return Array.isArray(value) ? completeDefault(value) : [];
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
41
68
|
localized() {
|
|
42
69
|
if (this.field.fields.length === 0) {
|
|
43
70
|
throw new Error('localized() must be called after fields assignment');
|
package/dist/fields/types.d.ts
CHANGED
|
@@ -64,6 +64,8 @@ export type FormField = Field & {
|
|
|
64
64
|
table?: FieldPanelTableConfig;
|
|
65
65
|
hooks?: FieldHooks;
|
|
66
66
|
defaultValue?: DefaultValueFn<any> | unknown;
|
|
67
|
+
/** When the default fills the field. Set by `defaultValue(value, { fill })`. */
|
|
68
|
+
defaultFill?: DefaultFill;
|
|
67
69
|
isEmpty: (value: unknown) => boolean;
|
|
68
70
|
/** Kept on the base row of a versioned config, shared by every version. Set by `$root()`. */
|
|
69
71
|
root?: boolean;
|
|
@@ -73,6 +75,18 @@ export type FormField = Field & {
|
|
|
73
75
|
export type DefaultValueFn<T> = ({ event }: {
|
|
74
76
|
event?: RequestEvent;
|
|
75
77
|
}) => T;
|
|
78
|
+
/**
|
|
79
|
+
* When a default fills its field.
|
|
80
|
+
*
|
|
81
|
+
* ```ts
|
|
82
|
+
* text('title').defaultValue('Untitled') // 'create': a new document starts with it
|
|
83
|
+
* text('title').defaultValue('Untitled', { fill: 'save' }) // 'save': and a save never leaves it empty
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export type DefaultFill = 'create' | 'save';
|
|
87
|
+
export type DefaultOptions = {
|
|
88
|
+
fill?: DefaultFill;
|
|
89
|
+
};
|
|
76
90
|
export type FieldHookContext<T extends FormField = FormField> = {
|
|
77
91
|
event: RequestEvent;
|
|
78
92
|
/** The document Id being processed */
|
|
@@ -24,7 +24,6 @@ export type BlockClipboardData = {
|
|
|
24
24
|
block: GenericBlock;
|
|
25
25
|
};
|
|
26
26
|
export declare const CLIPBOARD_KIND = "block";
|
|
27
|
-
export declare const tempId: () => string;
|
|
28
27
|
/** `sections.0.items.2` -> `{ list: 'sections.0.items', index: 2 }` */
|
|
29
28
|
export declare const parseBlockPath: (path: string) => BlockAt;
|
|
30
29
|
export declare const blockPath: (at: BlockAt) => string;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { getValueAtPath, isObjectLiteral, setValueAtPath } from '../../util/object.js';
|
|
2
2
|
import { normalizeFieldPath } from '../../util/string.js';
|
|
3
|
-
import {
|
|
3
|
+
import { tempId } from '../../util/random.js';
|
|
4
4
|
import cloneDeep from 'clone-deep';
|
|
5
5
|
export const CLIPBOARD_KIND = 'block';
|
|
6
|
-
export const tempId = () => `temp-${randomId(8)}`;
|
|
7
6
|
/** `sections.0.items.2` -> `{ list: 'sections.0.items', index: 2 }` */
|
|
8
7
|
export const parseBlockPath = (path) => {
|
|
9
8
|
const normalized = normalizeFieldPath(path);
|
|
@@ -30,7 +30,7 @@ export async function documentLoad(event) {
|
|
|
30
30
|
if (!authorized) {
|
|
31
31
|
throw handleError(new RimeError(RimeError.UNAUTHORIZED), { context: ERROR_CONTEXT.LOAD });
|
|
32
32
|
}
|
|
33
|
-
doc = collection.
|
|
33
|
+
doc = collection.initial();
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
36
|
/** Check for authorizations */
|
package/dist/util/object.d.ts
CHANGED
|
@@ -40,11 +40,11 @@ export declare const omitId: <T extends {
|
|
|
40
40
|
* Anything the object holds is the object's — `null` included, an array as it is.
|
|
41
41
|
*
|
|
42
42
|
* ```
|
|
43
|
-
*
|
|
43
|
+
* withDefaultValues({ title: 'T', seo: { og: null } }, { title: null, body: null, seo: { og: null, meta: null } })
|
|
44
44
|
* // { title: 'T', seo: { og: null, meta: null }, body: null }
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
|
-
export declare const
|
|
47
|
+
export declare const withDefaultValues: <T extends Dic>(obj: T, defaults: Dic) => T;
|
|
48
48
|
/**
|
|
49
49
|
* Type guard to check if an object has all the specified properties.
|
|
50
50
|
*
|
package/dist/util/object.js
CHANGED
|
@@ -59,18 +59,18 @@ export const omitId = (obj) => omit(['id'], obj);
|
|
|
59
59
|
* Anything the object holds is the object's — `null` included, an array as it is.
|
|
60
60
|
*
|
|
61
61
|
* ```
|
|
62
|
-
*
|
|
62
|
+
* withDefaultValues({ title: 'T', seo: { og: null } }, { title: null, body: null, seo: { og: null, meta: null } })
|
|
63
63
|
* // { title: 'T', seo: { og: null, meta: null }, body: null }
|
|
64
64
|
* ```
|
|
65
65
|
*/
|
|
66
|
-
export const
|
|
66
|
+
export const withDefaultValues = (obj, defaults) => {
|
|
67
67
|
const out = { ...obj };
|
|
68
68
|
for (const key of Object.keys(defaults)) {
|
|
69
69
|
const value = obj[key];
|
|
70
70
|
if (value === undefined)
|
|
71
71
|
out[key] = defaults[key];
|
|
72
72
|
else if (isObjectLiteral(value) && isObjectLiteral(defaults[key])) {
|
|
73
|
-
out[key] =
|
|
73
|
+
out[key] = withDefaultValues(value, defaults[key]);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
return out;
|
package/dist/util/random.d.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* // Result example: "a7bF9cD3eZ"
|
|
9
9
|
*/
|
|
10
10
|
export declare const randomId: (length: number) => string;
|
|
11
|
+
/** The id of a row not saved yet: a save adds it and gives it a real one. `temp-3f9aK2bQ` */
|
|
12
|
+
export declare const tempId: () => string;
|
|
11
13
|
/**
|
|
12
14
|
* Generate a secure random password with uppercase, lowercase, numbers and symbols
|
|
13
15
|
*
|
package/dist/util/random.js
CHANGED
|
@@ -27,6 +27,8 @@ export const randomId = (length) => {
|
|
|
27
27
|
}
|
|
28
28
|
return result;
|
|
29
29
|
};
|
|
30
|
+
/** The id of a row not saved yet: a save adds it and gives it a real one. `temp-3f9aK2bQ` */
|
|
31
|
+
export const tempId = () => `temp-${randomId(8)}`;
|
|
30
32
|
/**
|
|
31
33
|
* Generate a secure random password with uppercase, lowercase, numbers and symbols
|
|
32
34
|
*
|
package/package.json
CHANGED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { FieldBuilder } from './builders/field-builder.js';
|
|
2
|
-
import type { Field } from '../../fields/types.js';
|
|
3
|
-
import type { Dic } from '../../util/types.js';
|
|
4
|
-
import type { RequestEvent } from '@sveltejs/kit';
|
|
5
|
-
/** What a field is handed to build its blank value. The event is a default's, and boot has none. */
|
|
6
|
-
export type BlankContext = {
|
|
7
|
-
event?: RequestEvent;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* A list of fields as a blank object, each field contributing its own members.
|
|
11
|
-
*
|
|
12
|
-
* A branch opens an object, a leaf holds its default, and a repeater holds its own — `#` in a
|
|
13
|
-
* segment means only a document can name the children.
|
|
14
|
-
*
|
|
15
|
-
* ```
|
|
16
|
-
* group('attributes').fields(text('title')) -> { attributes: { title: null } }
|
|
17
|
-
* tabs(tab('meta').fields(text('title'))) -> { meta: { title: null } }
|
|
18
|
-
* blocks('layout', [...]) -> { layout: [] }
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export declare const blankFields: (fields: FieldBuilder<Field>[], context?: BlankContext) => Dic;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { isFormField } from './util.js';
|
|
2
|
-
/**
|
|
3
|
-
* A list of fields as a blank object, each field contributing its own members.
|
|
4
|
-
*
|
|
5
|
-
* A branch opens an object, a leaf holds its default, and a repeater holds its own — `#` in a
|
|
6
|
-
* segment means only a document can name the children.
|
|
7
|
-
*
|
|
8
|
-
* ```
|
|
9
|
-
* group('attributes').fields(text('title')) -> { attributes: { title: null } }
|
|
10
|
-
* tabs(tab('meta').fields(text('title'))) -> { meta: { title: null } }
|
|
11
|
-
* blocks('layout', [...]) -> { layout: [] }
|
|
12
|
-
* ```
|
|
13
|
-
*/
|
|
14
|
-
export const blankFields = (fields, context = {}) => {
|
|
15
|
-
const doc = {};
|
|
16
|
-
for (const field of fields) {
|
|
17
|
-
try {
|
|
18
|
-
const nodes = field.use.nodes();
|
|
19
|
-
if (!nodes.length || nodes.some((node) => node.segment.includes('#'))) {
|
|
20
|
-
if (isFormField(field))
|
|
21
|
-
doc[field.name] = field.use.defaultValue(context) ?? null;
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
// Its name opens an object, or it has none and its branches land on this one.
|
|
25
|
-
const target = field.name ? (doc[field.name] = {}) : doc;
|
|
26
|
-
for (const node of nodes) {
|
|
27
|
-
const bucket = node.segment ? (target[node.segment] = {}) : target;
|
|
28
|
-
Object.assign(bucket, blankFields(node.fields, context));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
console.error(`Building the blank value of ${field.type} field "${field.name}" failed.`);
|
|
33
|
-
throw err;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return doc;
|
|
37
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { FieldBuilder } from '../fields/builders/field-builder.js';
|
|
2
|
-
import type { GenericDoc } from './types.js';
|
|
3
|
-
import type { Field } from '../../fields/types.js';
|
|
4
|
-
import type { RequestEvent } from '@sveltejs/kit';
|
|
5
|
-
/** What `blank` reads off the config it is a method of. */
|
|
6
|
-
type BlankOwner = {
|
|
7
|
-
fields: FieldBuilder<Field>[];
|
|
8
|
-
slug: string;
|
|
9
|
-
type: string;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* A document of this config's shape with every default applied, and no id.
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* const page = config.getCollection('pages').blank();
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* Written as a standalone function so every config carries the same one — `definePrototype.create`
|
|
19
|
-
* for an authored config, and the three derivations that build a config by hand. The event is a
|
|
20
|
-
* field default's; boot has none, and a default that reads it gets `undefined` there.
|
|
21
|
-
*
|
|
22
|
-
* Nothing feature-shaped lands here: a feature adds to a blank document through
|
|
23
|
-
* `FeatureDefinition.blank`, which the local API folds.
|
|
24
|
-
*/
|
|
25
|
-
export declare function blank(this: BlankOwner, event?: RequestEvent): GenericDoc;
|
|
26
|
-
export {};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { blankFields } from '../fields/blank.js';
|
|
2
|
-
/**
|
|
3
|
-
* A document of this config's shape with every default applied, and no id.
|
|
4
|
-
*
|
|
5
|
-
* ```ts
|
|
6
|
-
* const page = config.getCollection('pages').blank();
|
|
7
|
-
* ```
|
|
8
|
-
*
|
|
9
|
-
* Written as a standalone function so every config carries the same one — `definePrototype.create`
|
|
10
|
-
* for an authored config, and the three derivations that build a config by hand. The event is a
|
|
11
|
-
* field default's; boot has none, and a default that reads it gets `undefined` there.
|
|
12
|
-
*
|
|
13
|
-
* Nothing feature-shaped lands here: a feature adds to a blank document through
|
|
14
|
-
* `FeatureDefinition.blank`, which the local API folds.
|
|
15
|
-
*/
|
|
16
|
-
export function blank(event) {
|
|
17
|
-
return {
|
|
18
|
-
...blankFields(this.fields, { event }),
|
|
19
|
-
_type: this.slug,
|
|
20
|
-
_prototype: this.type
|
|
21
|
-
};
|
|
22
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fills the incoming data from a blank document, so a create starts from every field the config
|
|
3
|
-
* declares rather than only the ones the caller sent.
|
|
4
|
-
*
|
|
5
|
-
* What the caller sent is kept as sent: an upload's `File` is not a plain object and is not
|
|
6
|
-
* walked, a key no field declares has no blank to fill from. The data's own nested objects are
|
|
7
|
-
* shared with the caller's payload from here on, not copied.
|
|
8
|
-
*/
|
|
9
|
-
export declare const mergeWithBlankDocument: import("../../../pipeline/types").Hook<"raw", "create", "before">;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Hooks } from '../../../pipeline/define-hook.js';
|
|
2
|
-
import { withDefaults } from '../../../../util/object.js';
|
|
3
|
-
/**
|
|
4
|
-
* Fills the incoming data from a blank document, so a create starts from every field the config
|
|
5
|
-
* declares rather than only the ones the caller sent.
|
|
6
|
-
*
|
|
7
|
-
* What the caller sent is kept as sent: an upload's `File` is not a plain object and is not
|
|
8
|
-
* walked, a key no field declares has no blank to fill from. The data's own nested objects are
|
|
9
|
-
* shared with the caller's payload from here on, not copied.
|
|
10
|
-
*/
|
|
11
|
-
export const mergeWithBlankDocument = Hooks.beforeCreate(async function mergeWithBlankDocument(args) {
|
|
12
|
-
const blank = args.config.blank(args.event);
|
|
13
|
-
return { ...args, data: withDefaults(args.data, blank) };
|
|
14
|
-
});
|