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
|
@@ -27,17 +27,12 @@ export const collection = definePrototype({
|
|
|
27
27
|
name: 'collection',
|
|
28
28
|
/**
|
|
29
29
|
* **Everything that shapes a collection config, in the order it runs** — which is the order the
|
|
30
|
-
* fields land in, and therefore column order (CONTRIBUTING rule 2).
|
|
31
|
-
*
|
|
32
|
-
* This was two declarations: `augments: [augmentLabel]` for the prototype's own, and
|
|
33
|
-
* `features: [auth, panel, upload, …]` for the rest, folded by `applyAugments`, each entry
|
|
34
|
-
* gated by a `FeatureDefinition.enabled` predicate declared in its own file. Reading the chain
|
|
35
|
-
* meant opening ten of them. It is one list now, and the guard is beside the step.
|
|
30
|
+
* fields land in, and therefore column order (CONTRIBUTING rule 2). A step that does not always
|
|
31
|
+
* apply has its guard beside it.
|
|
36
32
|
*
|
|
37
33
|
* `auth` is first because `title` resolves `asTitle` from the fallback `auth` and `upload` each
|
|
38
34
|
* offer, so both have to have run before it. `metas` is last because metas close the table.
|
|
39
|
-
* `augmentVersions` carries its own guard on its first line
|
|
40
|
-
* what `enabled` used to answer, and the unguarded steps are the six that answered `() => true`.
|
|
35
|
+
* `augmentVersions` carries its own guard on its first line.
|
|
41
36
|
*
|
|
42
37
|
* `panel` and `cors` are not here: neither has an augment. They shape the whole config and are
|
|
43
38
|
* called by the config chain — see `config/build.ts`.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gives a create the fields the caller did not send, from the initial document: each field's
|
|
3
|
+
* default, `null` without one. A field sent, empty included, is kept as sent.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* text('title').defaultValue('Untitled');
|
|
7
|
+
* // POST {} -> { title: 'Untitled' }
|
|
8
|
+
* // POST { title: null } -> { title: null }
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* An upload's `File` is not a plain object and is not walked, a key no field declares has no
|
|
12
|
+
* initial value to fill from. The data's own nested objects are shared with the caller's payload
|
|
13
|
+
* from here on, not copied.
|
|
14
|
+
*/
|
|
15
|
+
export declare const mergeWithInitialDocument: import("../../../pipeline/types").Hook<"raw", "create", "before">;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Hooks } from '../../../pipeline/define-hook.js';
|
|
2
|
+
import { withDefaultValues } from '../../../../util/object.js';
|
|
3
|
+
/**
|
|
4
|
+
* Gives a create the fields the caller did not send, from the initial document: each field's
|
|
5
|
+
* default, `null` without one. A field sent, empty included, is kept as sent.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* text('title').defaultValue('Untitled');
|
|
9
|
+
* // POST {} -> { title: 'Untitled' }
|
|
10
|
+
* // POST { title: null } -> { title: null }
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* An upload's `File` is not a plain object and is not walked, a key no field declares has no
|
|
14
|
+
* initial value to fill from. The data's own nested objects are shared with the caller's payload
|
|
15
|
+
* from here on, not copied.
|
|
16
|
+
*/
|
|
17
|
+
export const mergeWithInitialDocument = Hooks.beforeCreate(async function mergeWithInitialDocument(args) {
|
|
18
|
+
const initial = args.config.initial(args.event);
|
|
19
|
+
return { ...args, data: withDefaultValues(args.data, initial) };
|
|
20
|
+
});
|
|
@@ -23,7 +23,7 @@ import * as url from '../shared/url/hooks/index.server.js';
|
|
|
23
23
|
import { isVersioned, isVersionsCollection } from '../shared/versions/enabled.js';
|
|
24
24
|
import * as versions from '../shared/versions/hooks/index.server.js';
|
|
25
25
|
import { when } from '../when.js';
|
|
26
|
-
import {
|
|
26
|
+
import { mergeWithInitialDocument } from './hooks/merge-with-initial.server.js';
|
|
27
27
|
/**
|
|
28
28
|
* Every hook a collection can run, in the order it runs them.
|
|
29
29
|
*
|
|
@@ -72,14 +72,14 @@ export const collectionHooks = {
|
|
|
72
72
|
// First, on the submission as sent. Unconditional: the derived versions collection carries
|
|
73
73
|
// the flag and is not itself versioned.
|
|
74
74
|
versions.stripAutoSaveFlag,
|
|
75
|
-
|
|
75
|
+
mergeWithInitialDocument,
|
|
76
76
|
// After the merge: it appends the password field, and the config map below has to see it.
|
|
77
77
|
when(isAuth, auth.augmentFieldsPassword),
|
|
78
78
|
// Above `buildDataConfigMap`: that map is what the write turns into `incomingPaths`, the set
|
|
79
79
|
// of paths the request may touch, so a field added to `data` below it is dropped in silence.
|
|
80
80
|
metas.stampCreatedBy,
|
|
81
|
-
buildDataConfigMap,
|
|
82
81
|
setDefaultValues,
|
|
82
|
+
buildDataConfigMap,
|
|
83
83
|
// Above validation, which reads an id where a read handed back the document.
|
|
84
84
|
normalizeResolvedReferences,
|
|
85
85
|
validateFields,
|
|
@@ -112,10 +112,10 @@ export const collectionHooks = {
|
|
|
112
112
|
when(isVersioned, versions.handleNewVersion),
|
|
113
113
|
// Between the two: below `handleNewVersion`, which reads the submission *as sent* to work out
|
|
114
114
|
// what the previous version did not carry, and above `buildDataConfigMap`, whose keys are the
|
|
115
|
-
// paths the write may touch — a stamp below that is dropped in silence.
|
|
115
|
+
// paths the write may touch — a stamp or a default below that is dropped in silence.
|
|
116
116
|
metas.stampUpdatedBy,
|
|
117
|
-
buildDataConfigMap,
|
|
118
117
|
setDefaultValues,
|
|
118
|
+
buildDataConfigMap,
|
|
119
119
|
normalizeResolvedReferences,
|
|
120
120
|
validateFields,
|
|
121
121
|
when(isUpload, upload.handlePathCreation),
|
|
@@ -12,6 +12,6 @@ export const augmentNested = (config) => ({
|
|
|
12
12
|
fields: [
|
|
13
13
|
...(config.fields || []),
|
|
14
14
|
text('_parent').hidden().$root(),
|
|
15
|
-
number('_position').defaultValue(0).hidden().$root()
|
|
15
|
+
number('_position').defaultValue(0, { fill: 'save' }).hidden().$root()
|
|
16
16
|
]
|
|
17
17
|
});
|
|
@@ -39,16 +39,12 @@ export const duplicate = async (args) => {
|
|
|
39
39
|
data = normalizeProps(data, locale);
|
|
40
40
|
delete data.id;
|
|
41
41
|
/**
|
|
42
|
-
* A copy is a new document, so it starts where a new document starts
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* naming a feature's vocabulary to say "a copy of a published document is not published".
|
|
46
|
-
* True, and not this operation's rule: the feature that adds `status` already declares its
|
|
47
|
-
* default, and `setDefaultValues` applies it on every create. Carrying the original's value
|
|
48
|
-
* over is what made the reset necessary.
|
|
42
|
+
* A copy is a new document, so it starts where a new document starts: a copy of a published
|
|
43
|
+
* document is not published. The feature that adds `status` declares its default, and a create
|
|
44
|
+
* gives it to a field not sent.
|
|
49
45
|
*
|
|
50
46
|
* Unconditional, and safe for a config with no such field: `delete` on an absent key is a
|
|
51
|
-
* no-op
|
|
47
|
+
* no-op.
|
|
52
48
|
*/
|
|
53
49
|
delete data.status;
|
|
54
50
|
return data;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { initial } from '../../../initial.js';
|
|
2
2
|
import { prototypeKebab } from '../../../naming.js';
|
|
3
3
|
import { date } from '../../../../../fields/date/index.js';
|
|
4
4
|
import { text } from '../../../../../fields/text/index.js';
|
|
@@ -15,7 +15,7 @@ export function makeUploadDirectoriesCollectionClient(collection) {
|
|
|
15
15
|
const directoriesCollection = {
|
|
16
16
|
slug: slug,
|
|
17
17
|
kebab: prototypeKebab(slug),
|
|
18
|
-
|
|
18
|
+
initial,
|
|
19
19
|
versions: undefined,
|
|
20
20
|
access: {
|
|
21
21
|
read: directoriesConfig?.access?.read || collection.access.read,
|
|
@@ -16,9 +16,9 @@ export const handlePathCreation = Hooks.beforeUpsert(async function handlePathCr
|
|
|
16
16
|
* An update that says nothing about the path leaves it alone; a create always has one.
|
|
17
17
|
*
|
|
18
18
|
* `getSegments` answers `root` for a missing *or null* path, which is what makes the second
|
|
19
|
-
* half true — and null is the case that matters, because the
|
|
19
|
+
* half true — and null is the case that matters, because the initial document a create is
|
|
20
20
|
* merged with puts `_path: null` in `data`. A test for `'_path' in data` therefore never
|
|
21
|
-
* fires on a create
|
|
21
|
+
* fires on a create.
|
|
22
22
|
*/
|
|
23
23
|
if (args.operation !== 'create' && !args.data._path)
|
|
24
24
|
return args;
|
|
@@ -91,8 +91,8 @@ export type PrototypeApiContext<C extends BuiltPrototype = BuiltPrototype> = {
|
|
|
91
91
|
isSystemOperation: boolean;
|
|
92
92
|
/** The locale to act in: the one asked for, else the request's, else the config's default. */
|
|
93
93
|
fallbackLocale(locale?: string): string | undefined;
|
|
94
|
-
/**
|
|
95
|
-
|
|
94
|
+
/** What a new document of this config starts with: every default applied, and no id. */
|
|
95
|
+
initial(): GenericDoc;
|
|
96
96
|
/**
|
|
97
97
|
* Which **version row** a read means. `undefined` for a config that is not versioned, which is
|
|
98
98
|
* "the document's own row". See `versionsReadQuery`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isStaff } from '../auth/access.js';
|
|
2
2
|
import { FileText } from '@lucide/svelte';
|
|
3
|
-
import {
|
|
3
|
+
import { initial } from './initial.js';
|
|
4
4
|
import { prototypeKebab } from './naming.js';
|
|
5
5
|
export const definePrototype = (options = {}) => {
|
|
6
6
|
const name = options.name ?? '';
|
|
@@ -18,13 +18,13 @@ export const definePrototype = (options = {}) => {
|
|
|
18
18
|
* `pipeline/build.server.ts` — so a derived config resolves by the same line as an authored one.
|
|
19
19
|
*/
|
|
20
20
|
const create = (slug, incomingConfig) => {
|
|
21
|
-
const
|
|
22
|
-
const augmented = augments().reduce((current, augment) => augment(current),
|
|
21
|
+
const seed = { ...incomingConfig, slug, _titleFallback: 'id' };
|
|
22
|
+
const augmented = augments().reduce((current, augment) => augment(current), seed);
|
|
23
23
|
return {
|
|
24
24
|
...augmented,
|
|
25
25
|
type: name,
|
|
26
26
|
slug,
|
|
27
|
-
|
|
27
|
+
initial,
|
|
28
28
|
kebab: prototypeKebab(slug),
|
|
29
29
|
fields: augmented.fields || [],
|
|
30
30
|
icon: augmented.icon || FileText,
|
|
@@ -0,0 +1,23 @@
|
|
|
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 `initial` reads off the config it is a method of. */
|
|
6
|
+
type InitialOwner = {
|
|
7
|
+
fields: FieldBuilder<Field>[];
|
|
8
|
+
slug: string;
|
|
9
|
+
type: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* What a new document of this config starts with: every default applied, and no id.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const page = config.getCollection('pages').initial();
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* A standalone function, so every config carries the same one: `definePrototype.create` for an
|
|
19
|
+
* authored config, and the three derivations that build a config by hand. The event is a field
|
|
20
|
+
* default's; boot has none, and a default that reads it gets `undefined` there.
|
|
21
|
+
*/
|
|
22
|
+
export declare function initial(this: InitialOwner, event?: RequestEvent): GenericDoc;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { initialValues } from '../fields/initial.js';
|
|
2
|
+
/**
|
|
3
|
+
* What a new document of this config starts with: every default applied, and no id.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* const page = config.getCollection('pages').initial();
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* A standalone function, so every config carries the same one: `definePrototype.create` for an
|
|
10
|
+
* authored config, and the three derivations that build a config by hand. The event is a field
|
|
11
|
+
* default's; boot has none, and a default that reads it gets `undefined` there.
|
|
12
|
+
*/
|
|
13
|
+
export function initial(event) {
|
|
14
|
+
return {
|
|
15
|
+
...initialValues(this.fields, { event }),
|
|
16
|
+
_type: this.slug,
|
|
17
|
+
_prototype: this.type
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -14,10 +14,8 @@ export type WithVersionsConfig<T> = Omit<T, 'versions'> & {
|
|
|
14
14
|
* Normalises `versions`, adds the `status` field when drafts are on and `isAutoSave` when
|
|
15
15
|
* auto-save is, and — when this config is versioned — states **where its content lives**.
|
|
16
16
|
*
|
|
17
|
-
* `_versions` is
|
|
18
|
-
* `
|
|
19
|
-
* are in `adapter-sqlite/`, so it has to be a config member rather than a call: reading data keeps
|
|
20
|
-
* the adapter naming no feature.
|
|
17
|
+
* `_versions` is a config member rather than a call because two of its readers are in
|
|
18
|
+
* `adapter-sqlite/`: reading it keeps the adapter naming no feature.
|
|
21
19
|
*/
|
|
22
20
|
export declare const augmentVersions: <T extends Input>(config: T) => WithVersionsConfig<T>;
|
|
23
21
|
export {};
|
|
@@ -6,10 +6,8 @@ import { toggle } from '../../../../fields/toggle/index.js';
|
|
|
6
6
|
* Normalises `versions`, adds the `status` field when drafts are on and `isAutoSave` when
|
|
7
7
|
* auto-save is, and — when this config is versioned — states **where its content lives**.
|
|
8
8
|
*
|
|
9
|
-
* `_versions` is
|
|
10
|
-
* `
|
|
11
|
-
* are in `adapter-sqlite/`, so it has to be a config member rather than a call: reading data keeps
|
|
12
|
-
* the adapter naming no feature.
|
|
9
|
+
* `_versions` is a config member rather than a call because two of its readers are in
|
|
10
|
+
* `adapter-sqlite/`: reading it keeps the adapter naming no feature.
|
|
13
11
|
*/
|
|
14
12
|
export const augmentVersions = (config) => {
|
|
15
13
|
const fields = [...(config.fields || [])];
|
|
@@ -22,13 +20,13 @@ export const augmentVersions = (config) => {
|
|
|
22
20
|
maxVersions: typeof versions === 'boolean' ? 12 : (versions.maxVersions ?? 12)
|
|
23
21
|
};
|
|
24
22
|
if (normalizedVersions.draft) {
|
|
25
|
-
fields.push(text('status').defaultValue(VERSIONS_STATUS.DRAFT).hidden());
|
|
23
|
+
fields.push(text('status').defaultValue(VERSIONS_STATUS.DRAFT, { fill: 'save' }).hidden());
|
|
26
24
|
}
|
|
27
25
|
// `required()` makes the column not null with a default, so a migration backfills every
|
|
28
26
|
// existing row as `false`. Reads filter on `isAutoSave != true`, and SQLite does not count a
|
|
29
27
|
// null row as passing that.
|
|
30
28
|
if (normalizedVersions.draft && normalizedVersions.autoSave) {
|
|
31
|
-
fields.push(toggle('isAutoSave').defaultValue(false).required().hidden());
|
|
29
|
+
fields.push(toggle('isAutoSave').defaultValue(false, { fill: 'save' }).required().hidden());
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
32
|
else {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { withVersionsSuffix } from './naming.js';
|
|
2
|
-
import {
|
|
2
|
+
import { initial } from '../../initial.js';
|
|
3
3
|
import { prototypeKebab } from '../../naming.js';
|
|
4
4
|
import { isStaff } from '../../../auth/access.js';
|
|
5
5
|
/**
|
|
@@ -30,7 +30,7 @@ export function configureVersions(config) {
|
|
|
30
30
|
slug: withVersionsSuffix(collection.slug),
|
|
31
31
|
kebab: prototypeKebab(withVersionsSuffix(collection.slug)),
|
|
32
32
|
versions: undefined,
|
|
33
|
-
|
|
33
|
+
initial,
|
|
34
34
|
access: versionsAccess(collection.access),
|
|
35
35
|
$hooks: collection.$hooks,
|
|
36
36
|
fields: contentFields(collection),
|
|
@@ -58,7 +58,7 @@ export function configureVersions(config) {
|
|
|
58
58
|
kebab: prototypeKebab(withVersionsSuffix(area.slug)),
|
|
59
59
|
icon: area.icon,
|
|
60
60
|
versions: undefined,
|
|
61
|
-
|
|
61
|
+
initial,
|
|
62
62
|
access: versionsAccess(area.access),
|
|
63
63
|
asTitle: area.asTitle,
|
|
64
64
|
asThumbnail: null,
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import type { Dic } from '../../../../../util/types.js';
|
|
2
2
|
import type { ConfigMap } from '../../../../pipeline/config-map/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* A new version holds the whole document: each field the update did not send takes the previous
|
|
5
|
+
* version's value. A field sent empty stays empty, so a field cleared on purpose stays cleared.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* // previous version: { title: 'A', intro: 'B' }
|
|
9
|
+
* fallbackDataFromOriginal({ data: { title: 'C' }, … }) // { title: 'C', intro: 'B' }
|
|
10
|
+
* fallbackDataFromOriginal({ data: { title: 'C', intro: null }, … }) // { title: 'C', intro: null }
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* A list sent — blocks, tree items, relations — is the update's as sent: nothing is taken into it
|
|
14
|
+
* from the previous version's list.
|
|
15
|
+
*/
|
|
3
16
|
export declare const fallbackDataFromOriginal: <T extends Dic>(args: {
|
|
4
17
|
data: T;
|
|
5
18
|
original: T;
|
|
6
19
|
configMap: ConfigMap;
|
|
7
20
|
ignore: string[];
|
|
8
|
-
|
|
9
|
-
}) => Promise<T>;
|
|
21
|
+
}) => T;
|
|
@@ -1,31 +1,37 @@
|
|
|
1
|
-
import { logger } from '../../../../logger.server.js';
|
|
2
1
|
import { getValueAtPath, setValueAtPath } from '../../../../../util/object.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
/**
|
|
3
|
+
* A new version holds the whole document: each field the update did not send takes the previous
|
|
4
|
+
* version's value. A field sent empty stays empty, so a field cleared on purpose stays cleared.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* // previous version: { title: 'A', intro: 'B' }
|
|
8
|
+
* fallbackDataFromOriginal({ data: { title: 'C' }, … }) // { title: 'C', intro: 'B' }
|
|
9
|
+
* fallbackDataFromOriginal({ data: { title: 'C', intro: null }, … }) // { title: 'C', intro: null }
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* A list sent — blocks, tree items, relations — is the update's as sent: nothing is taken into it
|
|
13
|
+
* from the previous version's list.
|
|
14
|
+
*/
|
|
15
|
+
export const fallbackDataFromOriginal = (args) => {
|
|
6
16
|
const { original, configMap, ignore } = args;
|
|
7
17
|
let output = { ...args.data };
|
|
8
|
-
for (const
|
|
9
|
-
// skip keys in ignore list
|
|
18
|
+
for (const key of Object.keys(configMap)) {
|
|
10
19
|
if (ignore.includes(key))
|
|
11
20
|
continue;
|
|
12
|
-
|
|
13
|
-
const shouldUpdate = (config.get.required && mode === 'required') || mode === 'all';
|
|
14
|
-
if (!shouldUpdate)
|
|
21
|
+
if (getValueAtPath(key, output) !== undefined)
|
|
15
22
|
continue;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
isEmpty = config.use.isEmpty(value);
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
isEmpty = false;
|
|
23
|
-
logger.warn(`Error while checking if field ${key} is empty`);
|
|
24
|
-
}
|
|
25
|
-
if (isEmpty) {
|
|
26
|
-
value = await getValueAtPath(key, original);
|
|
27
|
-
output = setValueAtPath(key, output, value);
|
|
28
|
-
}
|
|
23
|
+
if (insideSentList(key, output))
|
|
24
|
+
continue;
|
|
25
|
+
output = setValueAtPath(key, output, getValueAtPath(key, original));
|
|
29
26
|
}
|
|
30
27
|
return output;
|
|
31
28
|
};
|
|
29
|
+
/** `sections.0.title` is inside a sent list when `sections` is an array in the data. */
|
|
30
|
+
const insideSentList = (key, data) => {
|
|
31
|
+
const parts = key.split('.');
|
|
32
|
+
for (let length = 1; length < parts.length; length++) {
|
|
33
|
+
if (Array.isArray(getValueAtPath(parts.slice(0, length).join('.'), data)))
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
};
|
|
@@ -174,13 +174,12 @@ async function prepareDataForNewVersion(args) {
|
|
|
174
174
|
if (config.type === 'collection' && config.upload && !data.file) {
|
|
175
175
|
data.file = (await fileForDocument(originalDoc)) ?? data.file;
|
|
176
176
|
}
|
|
177
|
-
//
|
|
178
|
-
data =
|
|
177
|
+
// The fields the update did not send, from the previous version.
|
|
178
|
+
data = fallbackDataFromOriginal({
|
|
179
179
|
data,
|
|
180
180
|
original: originalDoc,
|
|
181
181
|
configMap: originalConfigMap,
|
|
182
|
-
ignore: ['status']
|
|
183
|
-
mode: 'all'
|
|
182
|
+
ignore: ['status']
|
|
184
183
|
});
|
|
185
184
|
// Set default status to "draft" if no data.status
|
|
186
185
|
if (!data.status) {
|
|
@@ -6,8 +6,6 @@ import type { Dic } from '../../../../util/types.js';
|
|
|
6
6
|
* `status = published`. The `status` field's own default is `draft`, which is right for every
|
|
7
7
|
* version made after this one.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
* only `boot` seeds a row, only an area is booted, and a create never publishes. So the caller is
|
|
11
|
-
* the answer — this one is `ensureExists`, and nothing else calls it.
|
|
9
|
+
* Only an area's boot seeds a row, through `ensureExists`, which is the one caller.
|
|
12
10
|
*/
|
|
13
|
-
export declare const
|
|
11
|
+
export declare const initialVersion: (doc: Dic, config: Dic) => Dic;
|
|
@@ -6,10 +6,8 @@ import { VERSIONS_STATUS } from './constant.js';
|
|
|
6
6
|
* `status = published`. The `status` field's own default is `draft`, which is right for every
|
|
7
7
|
* version made after this one.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
* only `boot` seeds a row, only an area is booted, and a create never publishes. So the caller is
|
|
11
|
-
* the answer — this one is `ensureExists`, and nothing else calls it.
|
|
9
|
+
* Only an area's boot seeds a row, through `ensureExists`, which is the one caller.
|
|
12
10
|
*/
|
|
13
|
-
export const
|
|
11
|
+
export const initialVersion = (doc, config) => config.versions?.draft
|
|
14
12
|
? { ...doc, status: VERSIONS_STATUS.PUBLISHED }
|
|
15
13
|
: doc;
|
|
@@ -13,12 +13,8 @@ import type { Dic } from '../../util/types.js';
|
|
|
13
13
|
* with a promise. `carriesConfig` below is the whole of the difference, and `R` is what lets an
|
|
14
14
|
* async step through.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* name → predicate map in `buildPipeline`. Neither was visible where the step was placed, which
|
|
19
|
-
* is the only place the question is interesting.
|
|
20
|
-
*
|
|
21
|
-
* A step with no guard runs always — which is what six of the ten features declared anyway.
|
|
16
|
+
* The guard sits where the step is placed, so the list says when each step runs. A step with no
|
|
17
|
+
* guard runs always.
|
|
22
18
|
*/
|
|
23
19
|
export declare const when: <T, R>(applies: (config: Dic) => boolean, step: (subject: T) => R) => ((subject: T) => R | T) & {
|
|
24
20
|
step: (subject: T) => R;
|
|
@@ -12,12 +12,8 @@
|
|
|
12
12
|
* with a promise. `carriesConfig` below is the whole of the difference, and `R` is what lets an
|
|
13
13
|
* async step through.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* name → predicate map in `buildPipeline`. Neither was visible where the step was placed, which
|
|
18
|
-
* is the only place the question is interesting.
|
|
19
|
-
*
|
|
20
|
-
* A step with no guard runs always — which is what six of the ten features declared anyway.
|
|
15
|
+
* The guard sits where the step is placed, so the list says when each step runs. A step with no
|
|
16
|
+
* guard runs always.
|
|
21
17
|
*/
|
|
22
18
|
export const when = (applies, step) => {
|
|
23
19
|
const guarded = (subject) => applies(carriesConfig(subject) ? subject.config : subject) ? step(subject) : subject;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { initialValues } from '../../../core/fields/initial.js';
|
|
3
3
|
import { t__ } from '../../../core/i18n/index.js';
|
|
4
4
|
import type { GenericBlock } from '../../../core/prototype/types.js';
|
|
5
5
|
import Button from '../../../panel/components/ui/button/button.svelte';
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
const add = (block: BlocksFieldBlock) => {
|
|
23
23
|
open = false;
|
|
24
24
|
const empty = {
|
|
25
|
-
...
|
|
25
|
+
...initialValues(block.fields),
|
|
26
26
|
type: block.name
|
|
27
27
|
};
|
|
28
28
|
addBlock(empty);
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
import Palette from './Palette.svelte';
|
|
22
22
|
import Inspector from './Inspector.svelte';
|
|
23
23
|
import Renders from './Renders.svelte';
|
|
24
|
-
import StagePlaceholder from './StagePlaceholder.svelte';
|
|
25
24
|
|
|
26
25
|
const { form }: { form: DocumentFormContext } = $props();
|
|
27
26
|
|
|
@@ -409,15 +408,12 @@
|
|
|
409
408
|
<div class="rz-blocks-focus__body">
|
|
410
409
|
<!--
|
|
411
410
|
The stage: the open list, or the narrowed block alone with what it holds. A click beside the
|
|
412
|
-
blocks selects the root; the blocks stop their own clicks.
|
|
411
|
+
blocks selects the root; the blocks and their lists stop their own clicks.
|
|
413
412
|
-->
|
|
414
413
|
<section class="rz-blocks-focus__renders" role="presentation" onclick={focus.selectRoot}>
|
|
415
414
|
{#key focus.path}
|
|
416
415
|
<Renders {form} list={stageList} only={focus.narrowedRow?.index} onRemove={requestRemove} />
|
|
417
416
|
{/key}
|
|
418
|
-
{#if count && !focus.locked}
|
|
419
|
-
<StagePlaceholder />
|
|
420
|
-
{/if}
|
|
421
417
|
</section>
|
|
422
418
|
|
|
423
419
|
{#if narrow}
|
|
@@ -575,18 +571,11 @@
|
|
|
575
571
|
min-height: 0;
|
|
576
572
|
}
|
|
577
573
|
|
|
578
|
-
.rz-blocks-focus__renders > :global(.rz-renders)
|
|
579
|
-
.rz-blocks-focus__renders > :global(.rz-stage-placeholder) {
|
|
574
|
+
.rz-blocks-focus__renders > :global(.rz-renders) {
|
|
580
575
|
max-width: var(--rz-document-width, 60rem);
|
|
581
576
|
margin-inline: auto;
|
|
582
577
|
}
|
|
583
578
|
|
|
584
|
-
/* Under the blocks, one gap further down. */
|
|
585
|
-
.rz-blocks-focus__renders > :global(.rz-stage-placeholder) {
|
|
586
|
-
display: block;
|
|
587
|
-
margin-top: var(--rz-size-3);
|
|
588
|
-
}
|
|
589
|
-
|
|
590
579
|
.rz-blocks-focus__panel,
|
|
591
580
|
.rz-blocks-focus__renders {
|
|
592
581
|
min-width: 0;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { Button } from '../../../../panel/components/ui/button/index.js';
|
|
6
6
|
import { withBlockTypes } from '../../../../panel/context/blocks-ops.js';
|
|
7
7
|
import type { DocumentFormContext } from '../../../../panel/context/documentForm.svelte.js';
|
|
8
|
-
import { Focus, ToyBrick } from '@lucide/svelte';
|
|
8
|
+
import { Focus, Plus, ToyBrick } from '@lucide/svelte';
|
|
9
9
|
import { getBlocksFocusContext } from './focus.svelte.js';
|
|
10
10
|
|
|
11
11
|
type Props = { form: DocumentFormContext };
|
|
@@ -30,11 +30,20 @@
|
|
|
30
30
|
? t__('fields.blocks_count', '1')
|
|
31
31
|
: t__('fields.blocks_count|m|p', String(count));
|
|
32
32
|
};
|
|
33
|
+
|
|
34
|
+
/** Opens the picker on the list: the block picked goes at its end. */
|
|
35
|
+
function addTo(list: string) {
|
|
36
|
+
focus.selectList(list);
|
|
37
|
+
focus.pick();
|
|
38
|
+
}
|
|
33
39
|
</script>
|
|
34
40
|
|
|
35
41
|
{#if row && rendered}
|
|
36
42
|
{@const Icon = row.config?.icon ?? ToyBrick}
|
|
37
|
-
<!--
|
|
43
|
+
<!--
|
|
44
|
+
The selected block: its head, its fields, then how many blocks each of its lists holds, and a
|
|
45
|
+
button that adds one.
|
|
46
|
+
-->
|
|
38
47
|
<article class="rz-inspector" data-block-path={row.path}>
|
|
39
48
|
<header class="rz-inspector__header">
|
|
40
49
|
<span class="rz-inspector__icon"><Icon size={14} /></span>
|
|
@@ -63,6 +72,17 @@
|
|
|
63
72
|
<li class="rz-inspector__list">
|
|
64
73
|
<span>{child.label}</span>
|
|
65
74
|
<span class="rz-inspector__count">{countOf(child.list)}</span>
|
|
75
|
+
{#if !focus.locked}
|
|
76
|
+
<button
|
|
77
|
+
type="button"
|
|
78
|
+
class="rz-inspector__add"
|
|
79
|
+
title={t__('fields.add_block')}
|
|
80
|
+
aria-label={t__('fields.add_block')}
|
|
81
|
+
onclick={() => addTo(child.list)}
|
|
82
|
+
>
|
|
83
|
+
<Plus size={14} />
|
|
84
|
+
</button>
|
|
85
|
+
{/if}
|
|
66
86
|
</li>
|
|
67
87
|
{/each}
|
|
68
88
|
</ul>
|
|
@@ -150,11 +170,31 @@
|
|
|
150
170
|
|
|
151
171
|
.rz-inspector__list {
|
|
152
172
|
display: flex;
|
|
153
|
-
|
|
173
|
+
align-items: center;
|
|
154
174
|
gap: var(--rz-size-2);
|
|
155
175
|
}
|
|
156
176
|
|
|
177
|
+
/* On the right, then the button. */
|
|
157
178
|
.rz-inspector__count {
|
|
179
|
+
margin-left: auto;
|
|
158
180
|
color: var(--rz-fg-subtle);
|
|
159
181
|
}
|
|
182
|
+
|
|
183
|
+
.rz-inspector__add {
|
|
184
|
+
display: grid;
|
|
185
|
+
place-items: center;
|
|
186
|
+
width: var(--rz-size-6);
|
|
187
|
+
height: var(--rz-size-6);
|
|
188
|
+
flex-shrink: 0;
|
|
189
|
+
border-radius: var(--rz-radius-sm);
|
|
190
|
+
color: var(--rz-fg-subtle);
|
|
191
|
+
&:hover {
|
|
192
|
+
color: var(--rz-fg);
|
|
193
|
+
background-color: var(--rz-bg-hover);
|
|
194
|
+
}
|
|
195
|
+
&:focus-visible {
|
|
196
|
+
outline: 2px solid var(--rz-accent-border);
|
|
197
|
+
outline-offset: 2px;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
160
200
|
</style>
|