@cmssy/core 9.7.0 → 9.7.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/index.cjs CHANGED
@@ -789,14 +789,26 @@ function isResolvedRecord(value) {
789
789
  function isListShaped(field) {
790
790
  return field.relationMode === "all" || field.relationType === "hasMany" || field.multiple === true;
791
791
  }
792
- function normalizeRelationContent(content, schema) {
792
+ function normalizeRelationContent(content, schema, resolved) {
793
793
  for (const [key, field] of Object.entries(schema)) {
794
794
  if (field.type !== "relation") continue;
795
795
  const value = content[key];
796
+ const fallback = resolved?.[key];
796
797
  if (isListShaped(field)) {
797
- content[key] = Array.isArray(value) ? value.filter(isResolvedRecord) : [];
798
+ if (Array.isArray(value)) {
799
+ const records = value.filter(isResolvedRecord);
800
+ if (records.length > 0 || value.length === 0) {
801
+ content[key] = records;
802
+ continue;
803
+ }
804
+ }
805
+ content[key] = Array.isArray(fallback) ? fallback.filter(isResolvedRecord) : [];
798
806
  } else if (!isResolvedRecord(value)) {
799
- delete content[key];
807
+ if (value != null && value !== "" && isResolvedRecord(fallback)) {
808
+ content[key] = fallback;
809
+ } else {
810
+ delete content[key];
811
+ }
800
812
  }
801
813
  }
802
814
  }
package/dist/index.d.cts CHANGED
@@ -168,9 +168,11 @@ type BlockSchemaMap = Record<string, Record<string, FieldDefinition>>;
168
168
  * The editor canvas renders stored content without the server-side resolve, so
169
169
  * a relation field there holds raw ids - or the "" a freshly inserted block is
170
170
  * seeded with. A component is typed against resolved records, so anything that
171
- * is not one is coerced to the safe empty shape instead of reaching it.
171
+ * is not one falls back to the server-resolved value for that key (the admin
172
+ * hydrates the canvas with raw stored content, clobbering it), and only then
173
+ * to the safe empty shape.
172
174
  */
173
- declare function normalizeRelationContent(content: Record<string, unknown>, schema: Record<string, FieldDefinition>): void;
175
+ declare function normalizeRelationContent(content: Record<string, unknown>, schema: Record<string, FieldDefinition>, resolved?: Record<string, unknown>): void;
174
176
  /**
175
177
  * Resolves every `fields.relation` value on the given block contents in place:
176
178
  * stored record ids become full records (one batched read for the whole page),
package/dist/index.d.ts CHANGED
@@ -168,9 +168,11 @@ type BlockSchemaMap = Record<string, Record<string, FieldDefinition>>;
168
168
  * The editor canvas renders stored content without the server-side resolve, so
169
169
  * a relation field there holds raw ids - or the "" a freshly inserted block is
170
170
  * seeded with. A component is typed against resolved records, so anything that
171
- * is not one is coerced to the safe empty shape instead of reaching it.
171
+ * is not one falls back to the server-resolved value for that key (the admin
172
+ * hydrates the canvas with raw stored content, clobbering it), and only then
173
+ * to the safe empty shape.
172
174
  */
173
- declare function normalizeRelationContent(content: Record<string, unknown>, schema: Record<string, FieldDefinition>): void;
175
+ declare function normalizeRelationContent(content: Record<string, unknown>, schema: Record<string, FieldDefinition>, resolved?: Record<string, unknown>): void;
174
176
  /**
175
177
  * Resolves every `fields.relation` value on the given block contents in place:
176
178
  * stored record ids become full records (one batched read for the whole page),
package/dist/index.js CHANGED
@@ -787,14 +787,26 @@ function isResolvedRecord(value) {
787
787
  function isListShaped(field) {
788
788
  return field.relationMode === "all" || field.relationType === "hasMany" || field.multiple === true;
789
789
  }
790
- function normalizeRelationContent(content, schema) {
790
+ function normalizeRelationContent(content, schema, resolved) {
791
791
  for (const [key, field] of Object.entries(schema)) {
792
792
  if (field.type !== "relation") continue;
793
793
  const value = content[key];
794
+ const fallback = resolved?.[key];
794
795
  if (isListShaped(field)) {
795
- content[key] = Array.isArray(value) ? value.filter(isResolvedRecord) : [];
796
+ if (Array.isArray(value)) {
797
+ const records = value.filter(isResolvedRecord);
798
+ if (records.length > 0 || value.length === 0) {
799
+ content[key] = records;
800
+ continue;
801
+ }
802
+ }
803
+ content[key] = Array.isArray(fallback) ? fallback.filter(isResolvedRecord) : [];
796
804
  } else if (!isResolvedRecord(value)) {
797
- delete content[key];
805
+ if (value != null && value !== "" && isResolvedRecord(fallback)) {
806
+ content[key] = fallback;
807
+ } else {
808
+ delete content[key];
809
+ }
798
810
  }
799
811
  }
800
812
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/core",
3
- "version": "9.7.0",
3
+ "version": "9.7.2",
4
4
  "description": "Framework-agnostic cmssy client: content, commerce, config, editor protocol. No React, no Next.",
5
5
  "keywords": [
6
6
  "cmssy",