rimecms 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/dist/adapter-sqlite/read.server.js +4 -4
  2. package/dist/adapter-sqlite/table.server.d.ts +3 -6
  3. package/dist/adapter-sqlite/table.server.js +3 -6
  4. package/dist/adapter-sqlite/transform.server.d.ts +1 -1
  5. package/dist/adapter-sqlite/transform.server.js +3 -2
  6. package/dist/adapter-sqlite/write.server.d.ts +13 -15
  7. package/dist/adapter-sqlite/write.server.js +15 -17
  8. package/dist/core/adapter.d.ts +19 -33
  9. package/dist/core/adapter.js +0 -12
  10. package/dist/core/auth/augment.js +2 -1
  11. package/dist/core/auth/hooks/augment-fields-password.server.d.ts +2 -2
  12. package/dist/core/auth/hooks/augment-fields-password.server.js +2 -2
  13. package/dist/core/auth/tables.d.ts +2 -5
  14. package/dist/core/auth/tables.js +3 -7
  15. package/dist/core/auth/validate-config.d.ts +3 -8
  16. package/dist/core/auth/validate-config.js +4 -10
  17. package/dist/core/config/types.d.ts +6 -6
  18. package/dist/core/config/validate.server.js +11 -0
  19. package/dist/core/fields/builders/boolean-builder.d.ts +2 -2
  20. package/dist/core/fields/builders/boolean-builder.js +4 -1
  21. package/dist/core/fields/builders/select-builder.d.ts +3 -3
  22. package/dist/core/fields/builders/select-builder.js +4 -2
  23. package/dist/core/fields/complete.d.ts +18 -0
  24. package/dist/core/fields/complete.js +32 -0
  25. package/dist/core/fields/empty.d.ts +14 -0
  26. package/dist/core/fields/empty.js +13 -0
  27. package/dist/core/fields/initial.d.ts +32 -0
  28. package/dist/core/fields/initial.js +47 -0
  29. package/dist/core/fields/util.d.ts +0 -16
  30. package/dist/core/fields/util.js +0 -29
  31. package/dist/core/i18n/en/fields.d.ts +1 -1
  32. package/dist/core/i18n/en/fields.js +1 -1
  33. package/dist/core/i18n/fr/fields.d.ts +1 -1
  34. package/dist/core/i18n/fr/fields.js +1 -1
  35. package/dist/core/pipeline/build-document.server.d.ts +4 -10
  36. package/dist/core/pipeline/build-document.server.js +8 -17
  37. package/dist/core/pipeline/hooks/data-config-map.server.d.ts +1 -1
  38. package/dist/core/pipeline/hooks/data-config-map.server.js +1 -1
  39. package/dist/core/pipeline/hooks/process-document-fields.server.d.ts +3 -2
  40. package/dist/core/pipeline/hooks/process-document-fields.server.js +3 -16
  41. package/dist/core/pipeline/hooks/set-default-values.server.d.ts +15 -4
  42. package/dist/core/pipeline/hooks/set-default-values.server.js +50 -25
  43. package/dist/core/pipeline/hooks/validate-fields.server.js +1 -1
  44. package/dist/core/pipeline/run.server.js +1 -2
  45. package/dist/core/prototype/area/api.server.d.ts +4 -6
  46. package/dist/core/prototype/area/api.server.js +4 -6
  47. package/dist/core/prototype/area/definition.server.js +23 -9
  48. package/dist/core/prototype/area/hooks.server.js +1 -1
  49. package/dist/core/prototype/collection/api.server.d.ts +5 -6
  50. package/dist/core/prototype/collection/api.server.js +5 -6
  51. package/dist/core/prototype/collection/definition.js +3 -8
  52. package/dist/core/prototype/collection/hooks/merge-with-initial.server.d.ts +15 -0
  53. package/dist/core/prototype/collection/hooks/merge-with-initial.server.js +20 -0
  54. package/dist/core/prototype/collection/hooks.server.js +5 -5
  55. package/dist/core/prototype/collection/nested/module.js +1 -1
  56. package/dist/core/prototype/collection/nested/module.server.js +1 -1
  57. package/dist/core/prototype/collection/operations/duplicate.js +4 -8
  58. package/dist/core/prototype/collection/upload/directories/derive.js +2 -2
  59. package/dist/core/prototype/collection/upload/hooks/handle-path-creation.server.js +2 -2
  60. package/dist/core/prototype/define.d.ts +2 -2
  61. package/dist/core/prototype/define.js +4 -4
  62. package/dist/core/prototype/initial.d.ts +23 -0
  63. package/dist/core/prototype/initial.js +19 -0
  64. package/dist/core/prototype/shared/versions/augment.d.ts +2 -4
  65. package/dist/core/prototype/shared/versions/augment.js +4 -6
  66. package/dist/core/prototype/shared/versions/configure.server.js +3 -3
  67. package/dist/core/prototype/shared/versions/hooks/fallback-data-from-original.d.ts +14 -2
  68. package/dist/core/prototype/shared/versions/hooks/fallback-data-from-original.js +28 -22
  69. package/dist/core/prototype/shared/versions/hooks/handle-new-version.server.js +3 -4
  70. package/dist/core/prototype/shared/versions/{blank.d.ts → initial.d.ts} +2 -4
  71. package/dist/core/prototype/shared/versions/{blank.js → initial.js} +2 -4
  72. package/dist/core/prototype/when.d.ts +2 -6
  73. package/dist/core/prototype/when.js +2 -6
  74. package/dist/fields/blocks/component/AddBlockButton.svelte +2 -2
  75. package/dist/fields/blocks/component/focus/BlocksFocus.svelte +16 -10
  76. package/dist/fields/blocks/component/focus/Inspector.svelte +27 -3
  77. package/dist/fields/blocks/component/focus/LayersList.svelte +4 -1
  78. package/dist/fields/blocks/component/focus/Renders.svelte +55 -11
  79. package/dist/fields/blocks/component/focus/Renders.svelte.d.ts +3 -0
  80. package/dist/fields/blocks/component/focus/StageAdd.svelte +42 -0
  81. package/dist/fields/blocks/component/focus/StageAdd.svelte.d.ts +6 -0
  82. package/dist/fields/blocks/component/focus/focus.svelte.d.ts +6 -4
  83. package/dist/fields/blocks/component/focus/focus.svelte.js +34 -8
  84. package/dist/fields/blocks/defaults.d.ts +22 -0
  85. package/dist/fields/blocks/defaults.js +23 -0
  86. package/dist/fields/blocks/index.d.ts +42 -5
  87. package/dist/fields/blocks/index.js +37 -1
  88. package/dist/fields/combobox/index.d.ts +2 -2
  89. package/dist/fields/combobox/index.js +2 -1
  90. package/dist/fields/date/index.d.ts +2 -2
  91. package/dist/fields/date/index.js +2 -1
  92. package/dist/fields/email/index.d.ts +2 -2
  93. package/dist/fields/email/index.js +2 -1
  94. package/dist/fields/group/index.d.ts +1 -0
  95. package/dist/fields/link/index.d.ts +3 -2
  96. package/dist/fields/link/index.js +2 -1
  97. package/dist/fields/number/index.d.ts +3 -2
  98. package/dist/fields/number/index.js +2 -1
  99. package/dist/fields/relation/component/RelationInline.svelte +1 -2
  100. package/dist/fields/relation/component/default/Default.svelte +1 -1
  101. package/dist/fields/relation/component/upload/Create.svelte +1 -1
  102. package/dist/fields/relation/index.d.ts +2 -2
  103. package/dist/fields/relation/index.js +2 -1
  104. package/dist/fields/rich-text/index.d.ts +2 -2
  105. package/dist/fields/rich-text/index.js +2 -1
  106. package/dist/fields/slug/index.d.ts +3 -2
  107. package/dist/fields/slug/index.js +2 -1
  108. package/dist/fields/text/index.d.ts +3 -2
  109. package/dist/fields/text/index.js +2 -1
  110. package/dist/fields/textarea/index.d.ts +3 -2
  111. package/dist/fields/textarea/index.js +2 -1
  112. package/dist/fields/time/index.d.ts +2 -2
  113. package/dist/fields/time/index.js +2 -1
  114. package/dist/fields/toggle/index.d.ts +3 -2
  115. package/dist/fields/toggle/index.js +2 -2
  116. package/dist/fields/tree/component/AddItemButton.svelte +3 -4
  117. package/dist/fields/tree/component/AddItemButton.svelte.d.ts +1 -1
  118. package/dist/fields/tree/defaults.d.ts +21 -0
  119. package/dist/fields/tree/defaults.js +18 -0
  120. package/dist/fields/tree/index.d.ts +17 -3
  121. package/dist/fields/tree/index.js +27 -0
  122. package/dist/fields/types.d.ts +14 -0
  123. package/dist/panel/components/ui/button/button.svelte +2 -3
  124. package/dist/panel/context/blocks-ops.d.ts +0 -1
  125. package/dist/panel/context/blocks-ops.js +1 -2
  126. package/dist/panel/pages/collection-document/load.server.js +1 -1
  127. package/dist/panel/style/index.css +4 -3
  128. package/dist/panel/style/palette.css +3 -3
  129. package/dist/panel/style/scheme.css +1 -0
  130. package/dist/util/object.d.ts +2 -2
  131. package/dist/util/object.js +3 -3
  132. package/dist/util/random.d.ts +2 -0
  133. package/dist/util/random.js +2 -0
  134. package/package.json +1 -1
  135. package/dist/core/fields/blank.d.ts +0 -21
  136. package/dist/core/fields/blank.js +0 -37
  137. package/dist/core/prototype/blank.d.ts +0 -26
  138. package/dist/core/prototype/blank.js +0 -22
  139. package/dist/core/prototype/collection/hooks/merge-with-blank.server.d.ts +0 -9
  140. package/dist/core/prototype/collection/hooks/merge-with-blank.server.js +0 -14
  141. package/dist/fields/blocks/component/focus/StagePlaceholder.svelte +0 -66
  142. package/dist/fields/blocks/component/focus/StagePlaceholder.svelte.d.ts +0 -3
@@ -49,7 +49,7 @@ declare class CollectionAPI<Doc extends RegisterCollection[CollectionSlug]> impl
49
49
  */
50
50
  system(isSystem?: boolean): CollectionAPI<Doc>;
51
51
  /**
52
- * A document of this collection's shape with every default applied, and no id.
52
+ * What a new document of this collection starts with: every default applied, and no id.
53
53
  *
54
54
  * An auth collection hands back nothing private. Only a collection signs in, which is why this
55
55
  * step is here and not on the area's.
@@ -57,11 +57,10 @@ declare class CollectionAPI<Doc extends RegisterCollection[CollectionSlug]> impl
57
57
  * **Likely dead, to be checked and dropped.** `withoutPrivateFields` strips `PRIVATE_FIELDS`, and
58
58
  * of those only `apiKeyId` is ever a member of `config.fields` — `augment.ts` adds it, hidden, on
59
59
  * an apiKey collection. `password` is appended per-operation by `augmentFieldsPassword`, which
60
- * runs *after* the blank merge, and the rest are columns no field declares. So the one member
61
- * this can remove is `apiKeyId`, which `removePrivateFields` takes off again on every read. If
62
- * that holds, an auth collection's blank is a blank like any other and this line is ceremony.
60
+ * runs *after* the initial merge, and the rest are columns no field declares. So the one member
61
+ * this can remove is `apiKeyId`, which `removePrivateFields` takes off again on every read.
63
62
  */
64
- blank(): Doc;
63
+ initial(): Doc;
65
64
  /** The locale to act in: the one asked for, else the request's, else the config's default. */
66
65
  fallbackLocale(locale?: string): string | undefined;
67
66
  /** Which version row a read means — see `versionsReadQuery`. */
@@ -194,6 +193,6 @@ export declare const collectionApi: <Doc extends RegisterCollection[CollectionSl
194
193
  * itself and every `rime.collection(...)` in the repo would resolve to `never`. Each operation
195
194
  * exports its caller-facing arguments separately for the same reason.
196
195
  */
197
- export type CollectionApi<Doc extends RegisterCollection[CollectionSlug] = RegisterCollection[CollectionSlug]> = Pick<CollectionAPI<Doc>, 'config' | 'blank' | 'create' | 'duplicate' | 'find' | 'findById' | 'findByIds' | 'updateById' | 'updateSlugById' | 'deleteById' | 'delete' | 'system'>;
196
+ export type CollectionApi<Doc extends RegisterCollection[CollectionSlug] = RegisterCollection[CollectionSlug]> = Pick<CollectionAPI<Doc>, 'config' | 'initial' | 'create' | 'duplicate' | 'find' | 'findById' | 'findByIds' | 'updateById' | 'updateSlugById' | 'deleteById' | 'delete' | 'system'>;
198
197
  export type CollectionAccessor = <Slug extends keyof RegisterCollection>(slug: Slug) => CollectionApi<RegisterCollection[Slug]>;
199
198
  export {};
@@ -48,7 +48,7 @@ class CollectionAPI {
48
48
  return isSystem ? new CollectionAPI(this.args, true) : this;
49
49
  }
50
50
  /**
51
- * A document of this collection's shape with every default applied, and no id.
51
+ * What a new document of this collection starts with: every default applied, and no id.
52
52
  *
53
53
  * An auth collection hands back nothing private. Only a collection signs in, which is why this
54
54
  * step is here and not on the area's.
@@ -56,12 +56,11 @@ class CollectionAPI {
56
56
  * **Likely dead, to be checked and dropped.** `withoutPrivateFields` strips `PRIVATE_FIELDS`, and
57
57
  * of those only `apiKeyId` is ever a member of `config.fields` — `augment.ts` adds it, hidden, on
58
58
  * an apiKey collection. `password` is appended per-operation by `augmentFieldsPassword`, which
59
- * runs *after* the blank merge, and the rest are columns no field declares. So the one member
60
- * this can remove is `apiKeyId`, which `removePrivateFields` takes off again on every read. If
61
- * that holds, an auth collection's blank is a blank like any other and this line is ceremony.
59
+ * runs *after* the initial merge, and the rest are columns no field declares. So the one member
60
+ * this can remove is `apiKeyId`, which `removePrivateFields` takes off again on every read.
62
61
  */
63
- blank() {
64
- const doc = this.config.blank(this.event);
62
+ initial() {
63
+ const doc = this.config.initial(this.event);
65
64
  return (isAuth(this.config) ? withoutPrivateFields(doc) : doc);
66
65
  }
67
66
  /** The locale to act in: the one asked for, else the request's, else the config's default. */
@@ -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; the four `when`s are the rest of
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 { mergeWithBlankDocument } from './hooks/merge-with-blank.server.js';
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
- mergeWithBlankDocument,
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
  });
@@ -18,6 +18,6 @@ export const augmentNested = (config) => ({
18
18
  .$root()
19
19
  // A read lists a document's children by it
20
20
  .$index(),
21
- number('_position').defaultValue(0).hidden().$root()
21
+ number('_position').defaultValue(0, { fill: 'save' }).hidden().$root()
22
22
  ]
23
23
  });
@@ -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
- * This was `data.status = data.status ? VERSIONS_STATUS.DRAFT : undefined` — a core operation
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, which is what the `data.status ?` test was standing in for.
47
+ * no-op.
52
48
  */
53
49
  delete data.status;
54
50
  return data;
@@ -1,4 +1,4 @@
1
- import { blank } from '../../../blank.js';
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
- blank,
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 blank document a create is
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, which is why the **adapter** was the thing defaulting it.
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
- /** A document of this config's shape with every default applied, and no id. */
95
- blank(): GenericDoc;
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 { blank } from './blank.js';
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 initial = { ...incomingConfig, slug, _titleFallback: 'id' };
22
- const augmented = augments().reduce((current, augment) => augment(current), initial);
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
- blank,
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 the answer five callers used to fold the feature list for, through a
18
- * `FeatureDefinition.shadow` seam that only this feature ever implemented. Two of those callers
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 the answer five callers used to fold the feature list for, through a
10
- * `FeatureDefinition.shadow` seam that only this feature ever implemented. Two of those callers
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 { blank } from '../../blank.js';
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
- blank,
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
- blank,
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
- mode?: "required" | "all";
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
- export const fallbackDataFromOriginal = async (args) => {
4
- //
5
- const mode = args.mode || 'all';
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 [key, config] of Object.entries(configMap)) {
9
- // skip keys in ignore list
18
+ for (const key of Object.keys(configMap)) {
10
19
  if (ignore.includes(key))
11
20
  continue;
12
- // skip if not required and mode is 'required'
13
- const shouldUpdate = (config.get.required && mode === 'required') || mode === 'all';
14
- if (!shouldUpdate)
21
+ if (getValueAtPath(key, output) !== undefined)
15
22
  continue;
16
- let value = getValueAtPath(key, output);
17
- let isEmpty;
18
- try {
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
- // Use missing required data from original version
178
- data = await fallbackDataFromOriginal({
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
- * There was a `BlankIntent` parameter saying which blank this is. It had one interesting value:
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 blankVersion: (doc: Dic, config: Dic) => Dic;
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
- * There was a `BlankIntent` parameter saying which blank this is. It had one interesting value:
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 blankVersion = (doc, config) => config.versions?.draft
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
- * This was two mechanisms. Augments were gated by a `FeatureDefinition.enabled` predicate on a
17
- * definition, folded by `applyAugments`; hooks by a `feature: 'auth'` mark on the hook and a
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
- * This was two mechanisms. Augments were gated by a `FeatureDefinition.enabled` predicate on a
16
- * definition, folded by `applyAugments`; hooks by a `feature: 'auth'` mark on the hook and a
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 { emptyValuesFromFieldConfig } from '../../../core/fields/util.js';
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
- ...emptyValuesFromFieldConfig(block.fields),
25
+ ...initialValues(block.fields),
26
26
  type: block.name
27
27
  };
28
28
  addBlock(empty);