@prismicio/types-internal 4.0.0-pr.9.be7806e → 4.0.0-pr.9.da3d99a
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withDefaultContent.d.ts","names":[],"sources":["../../src/helpers/withDefaultContent.ts"],"mappings":";;;;;;;;;;;;;;iBAiBgB,QAAA,CAAS,OAAA,EAAS,eAAA,EAAiB,KAAA,EAAO,qBAAA,GAAwB,eAAA;AAAA,iBAIlE,KAAA,CAAM,OAAA,EAAS,YAAA,EAAc,KAAA,EAAO,gBAAA,eAA+B,YAAA;AAAA,iBA4CnE,MAAA,kBAAwB,aAAA,aAAA,CACvC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,iBAAA,eACL,QAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"withDefaultContent.d.ts","names":[],"sources":["../../src/helpers/withDefaultContent.ts"],"mappings":";;;;;;;;;;;;;;iBAiBgB,QAAA,CAAS,OAAA,EAAS,eAAA,EAAiB,KAAA,EAAO,qBAAA,GAAwB,eAAA;AAAA,iBAIlE,KAAA,CAAM,OAAA,EAAS,YAAA,EAAc,KAAA,EAAO,gBAAA,eAA+B,YAAA;AAAA,iBA4CnE,MAAA,kBAAwB,aAAA,aAAA,CACvC,OAAA,EAAS,QAAA,EACT,KAAA,EAAO,iBAAA,eACL,QAAA;AAAA,iBA2Da,KAAA,CACf,KAAA,EAAO,YAAA,WACP,MAAA,EAAQ,MAAA,SAAe,UAAA,GAAa,aAAA,gBAClC,YAAA"}
|
|
@@ -2,7 +2,7 @@ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
|
2
2
|
import { flatten } from "./customTypeModel.js";
|
|
3
3
|
import { BooleanContentType } from "../content/boolean.js";
|
|
4
4
|
import { FieldContentType, SelectFieldType } from "../content/field.js";
|
|
5
|
-
import "../content/group.js";
|
|
5
|
+
import { GroupContentType } from "../content/group.js";
|
|
6
6
|
import "../content/slice.js";
|
|
7
7
|
import "../content/slices.js";
|
|
8
8
|
//#region src/helpers/withDefaultContent.ts
|
|
@@ -52,10 +52,16 @@ function widget(content, model) {
|
|
|
52
52
|
value
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
-
if (model.type === "Group"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
if (model.type === "Group") {
|
|
56
|
+
if (content?.__TYPE__ !== "GroupContentType") return {
|
|
57
|
+
__TYPE__: GroupContentType,
|
|
58
|
+
value: items([], model.config?.fields)
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
...content,
|
|
62
|
+
value: items(content.value, model.config?.fields)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
59
65
|
if (model.type === "Boolean" && !content) {
|
|
60
66
|
if (model.config?.default_value === void 0) return;
|
|
61
67
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withDefaultContent.js","names":["customTypeModel.flatten"],"sources":["../../src/helpers/withDefaultContent.ts"],"sourcesContent":["import { BooleanContentType } from \"../content/boolean\"\nimport type { DocumentContent } from \"../content/document\"\nimport { FieldContentType, SelectFieldType } from \"../content/field\"\nimport type { GroupContent, GroupItemContent } from \"../content/group\"\nimport { GroupContentType } from \"../content/group\"\nimport type { SliceContent } from \"../content/slice\"\nimport { CompositeSliceContentType, SharedSliceContentType } from \"../content/slice\"\nimport type { SlicesContent } from \"../content/slices\"\nimport { SlicesContentType } from \"../content/slices\"\nimport type { WidgetContent } from \"../content/widget\"\nimport type { StaticCustomTypeModel } from \"../model/customType\"\nimport type { GroupModel } from \"../model/group\"\nimport type { NestableModel } from \"../model/nestable\"\nimport type { StaticSliceModel } from \"../model/slice\"\nimport type { StaticWidgetModel } from \"../model/widget\"\nimport * as customTypeModel from \"./customTypeModel\"\n\nexport function document(content: DocumentContent, model: StaticCustomTypeModel): DocumentContent {\n\treturn record(content, customTypeModel.flatten(model))\n}\n\nexport function slice(content: SliceContent, model: StaticSliceModel | undefined): SliceContent {\n\tif (!model) {\n\t\treturn content\n\t}\n\n\tif (model.type === \"SharedSlice\") {\n\t\tif (content.__TYPE__ !== SharedSliceContentType) {\n\t\t\treturn content\n\t\t}\n\n\t\tconst variation = model.variations.find((variation) => variation.id === content.variation)\n\t\tif (!variation) {\n\t\t\treturn content\n\t\t}\n\n\t\treturn {\n\t\t\t...content,\n\t\t\tprimary: record(content.primary, variation?.primary),\n\t\t\titems: items(content.items, variation?.items),\n\t\t}\n\t}\n\n\tif (model.type === \"Slice\") {\n\t\tif (content.__TYPE__ !== CompositeSliceContentType) {\n\t\t\treturn content\n\t\t}\n\n\t\treturn {\n\t\t\t...content,\n\t\t\tnonRepeat: record(content.nonRepeat, model[\"non-repeat\"]),\n\t\t\trepeat: items(content.repeat, model.repeat),\n\t\t}\n\t}\n\n\tif (\n\t\tcontent.__TYPE__ === SharedSliceContentType ||\n\t\tcontent.__TYPE__ === CompositeSliceContentType\n\t) {\n\t\treturn content\n\t}\n\n\treturn widget(content, model)\n}\n\nexport function widget<TContent extends WidgetContent | undefined>(\n\tcontent: TContent,\n\tmodel: StaticWidgetModel | undefined,\n): TContent {\n\tif (!model) {\n\t\treturn content\n\t}\n\n\tif (\n\t\t(model.type === \"Slices\" || model.type === \"Choice\") &&\n\t\tcontent?.__TYPE__ === SlicesContentType\n\t) {\n\t\tif (!model.config?.choices) return content\n\n\t\tconst value: SlicesContent[\"value\"] = []\n\t\tfor (const sliceItem of content.value) {\n\t\t\tvalue.push({\n\t\t\t\t...sliceItem,\n\t\t\t\twidget: slice(sliceItem.widget, model.config.choices[sliceItem.name]),\n\t\t\t})\n\t\t}\n\n\t\treturn { ...content, value }\n\t}\n\n\tif (model.type === \"Group\"
|
|
1
|
+
{"version":3,"file":"withDefaultContent.js","names":["customTypeModel.flatten"],"sources":["../../src/helpers/withDefaultContent.ts"],"sourcesContent":["import { BooleanContentType } from \"../content/boolean\"\nimport type { DocumentContent } from \"../content/document\"\nimport { FieldContentType, SelectFieldType } from \"../content/field\"\nimport type { GroupContent, GroupItemContent } from \"../content/group\"\nimport { GroupContentType } from \"../content/group\"\nimport type { SliceContent } from \"../content/slice\"\nimport { CompositeSliceContentType, SharedSliceContentType } from \"../content/slice\"\nimport type { SlicesContent } from \"../content/slices\"\nimport { SlicesContentType } from \"../content/slices\"\nimport type { WidgetContent } from \"../content/widget\"\nimport type { StaticCustomTypeModel } from \"../model/customType\"\nimport type { GroupModel } from \"../model/group\"\nimport type { NestableModel } from \"../model/nestable\"\nimport type { StaticSliceModel } from \"../model/slice\"\nimport type { StaticWidgetModel } from \"../model/widget\"\nimport * as customTypeModel from \"./customTypeModel\"\n\nexport function document(content: DocumentContent, model: StaticCustomTypeModel): DocumentContent {\n\treturn record(content, customTypeModel.flatten(model))\n}\n\nexport function slice(content: SliceContent, model: StaticSliceModel | undefined): SliceContent {\n\tif (!model) {\n\t\treturn content\n\t}\n\n\tif (model.type === \"SharedSlice\") {\n\t\tif (content.__TYPE__ !== SharedSliceContentType) {\n\t\t\treturn content\n\t\t}\n\n\t\tconst variation = model.variations.find((variation) => variation.id === content.variation)\n\t\tif (!variation) {\n\t\t\treturn content\n\t\t}\n\n\t\treturn {\n\t\t\t...content,\n\t\t\tprimary: record(content.primary, variation?.primary),\n\t\t\titems: items(content.items, variation?.items),\n\t\t}\n\t}\n\n\tif (model.type === \"Slice\") {\n\t\tif (content.__TYPE__ !== CompositeSliceContentType) {\n\t\t\treturn content\n\t\t}\n\n\t\treturn {\n\t\t\t...content,\n\t\t\tnonRepeat: record(content.nonRepeat, model[\"non-repeat\"]),\n\t\t\trepeat: items(content.repeat, model.repeat),\n\t\t}\n\t}\n\n\tif (\n\t\tcontent.__TYPE__ === SharedSliceContentType ||\n\t\tcontent.__TYPE__ === CompositeSliceContentType\n\t) {\n\t\treturn content\n\t}\n\n\treturn widget(content, model)\n}\n\nexport function widget<TContent extends WidgetContent | undefined>(\n\tcontent: TContent,\n\tmodel: StaticWidgetModel | undefined,\n): TContent {\n\tif (!model) {\n\t\treturn content\n\t}\n\n\tif (\n\t\t(model.type === \"Slices\" || model.type === \"Choice\") &&\n\t\tcontent?.__TYPE__ === SlicesContentType\n\t) {\n\t\tif (!model.config?.choices) return content\n\n\t\tconst value: SlicesContent[\"value\"] = []\n\t\tfor (const sliceItem of content.value) {\n\t\t\tvalue.push({\n\t\t\t\t...sliceItem,\n\t\t\t\twidget: slice(sliceItem.widget, model.config.choices[sliceItem.name]),\n\t\t\t})\n\t\t}\n\n\t\treturn { ...content, value }\n\t}\n\n\tif (model.type === \"Group\") {\n\t\tif (content?.__TYPE__ !== GroupContentType) {\n\t\t\treturn <TContent>{\n\t\t\t\t__TYPE__: GroupContentType,\n\t\t\t\tvalue: items([], model.config?.fields),\n\t\t\t}\n\t\t}\n\n\t\treturn { ...content, value: items(content.value, model.config?.fields) }\n\t}\n\n\tif (model.type === \"Boolean\" && !content) {\n\t\tif (model.config?.default_value === undefined) {\n\t\t\treturn <TContent>undefined\n\t\t}\n\n\t\treturn <TContent>{\n\t\t\t__TYPE__: BooleanContentType,\n\t\t\tvalue: model.config.default_value,\n\t\t}\n\t}\n\n\tif (model.type === \"Select\" && !content) {\n\t\tif (!model.config?.default_value) {\n\t\t\treturn <TContent>undefined\n\t\t}\n\n\t\treturn <TContent>{\n\t\t\t__TYPE__: FieldContentType,\n\t\t\ttype: SelectFieldType,\n\t\t\tvalue: model.config.default_value,\n\t\t}\n\t}\n\n\treturn content\n}\n\nexport function items(\n\titems: GroupContent[\"value\"],\n\tfields: Record<string, GroupModel | NestableModel> | undefined,\n): GroupContent[\"value\"] {\n\tif (!fields) {\n\t\treturn items\n\t}\n\n\tconst itemsWithDefaults: GroupContent[\"value\"] = []\n\tfor (const item of items) {\n\t\tconst itemValue: GroupItemContent[\"value\"] = []\n\n\t\tconst missingFields = { ...fields }\n\t\tfor (const [key, value] of item.value) {\n\t\t\tdelete missingFields[key]\n\t\t\titemValue.push([key, widget(value, fields[key])])\n\t\t}\n\t\tfor (const [key, field] of Object.entries(missingFields)) {\n\t\t\tconst content = widget(undefined, field)\n\t\t\tif (content) {\n\t\t\t\titemValue.push([key, content])\n\t\t\t}\n\t\t}\n\n\t\titemsWithDefaults.push({ ...item, value: itemValue })\n\t}\n\n\treturn itemsWithDefaults\n}\n\nfunction record<TContent extends WidgetContent>(\n\trecord: Record<string, TContent>,\n\tfields: Record<string, StaticWidgetModel> | undefined,\n): Record<string, TContent> {\n\tif (!fields) {\n\t\treturn record\n\t}\n\n\tconst missingFields = { ...fields }\n\tconst recordWithDefaults: Record<string, TContent> = {}\n\tfor (const [key, value] of Object.entries(record)) {\n\t\tdelete missingFields[key]\n\t\trecordWithDefaults[key] = widget(value, fields[key])\n\t}\n\tfor (const [key, field] of Object.entries(missingFields)) {\n\t\tconst content = widget(undefined, field)\n\t\tif (content) {\n\t\t\trecordWithDefaults[key] = content\n\t\t}\n\t}\n\n\treturn recordWithDefaults\n}\n"],"mappings":";;;;;;;;;;;;;;AAiBA,SAAgB,SAAS,SAA0B,OAA+C;AACjG,QAAO,OAAO,SAASA,QAAwB,MAAM,CAAC;;AAGvD,SAAgB,MAAM,SAAuB,OAAmD;AAC/F,KAAI,CAAC,MACJ,QAAO;AAGR,KAAI,MAAM,SAAS,eAAe;AACjC,MAAI,QAAQ,aAAA,qBACX,QAAO;EAGR,MAAM,YAAY,MAAM,WAAW,MAAM,cAAc,UAAU,OAAO,QAAQ,UAAU;AAC1F,MAAI,CAAC,UACJ,QAAO;AAGR,SAAO;GACN,GAAG;GACH,SAAS,OAAO,QAAQ,SAAS,WAAW,QAAQ;GACpD,OAAO,MAAM,QAAQ,OAAO,WAAW,MAAM;GAC7C;;AAGF,KAAI,MAAM,SAAS,SAAS;AAC3B,MAAI,QAAQ,aAAA,wBACX,QAAO;AAGR,SAAO;GACN,GAAG;GACH,WAAW,OAAO,QAAQ,WAAW,MAAM,cAAc;GACzD,QAAQ,MAAM,QAAQ,QAAQ,MAAM,OAAO;GAC3C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aAAU,KAAK,CAAC,KAAK,OAAO,OAAO,OAAO,KAAK,CAAC,CAAC;;AAElD,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,cAAc,EAAE;GACzD,MAAM,UAAU,OAAO,KAAA,GAAW,MAAM;AACxC,OAAI,QACH,WAAU,KAAK,CAAC,KAAK,QAAQ,CAAC;;AAIhC,oBAAkB,KAAK;GAAE,GAAG;GAAM,OAAO;GAAW,CAAC;;AAGtD,QAAO;;AAGR,SAAS,OACR,QACA,QAC2B;AAC3B,KAAI,CAAC,OACJ,QAAO;CAGR,MAAM,gBAAgB,EAAE,GAAG,QAAQ;CACnC,MAAM,qBAA+C,EAAE;AACvD,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,EAAE;AAClD,SAAO,cAAc;AACrB,qBAAmB,OAAO,OAAO,OAAO,OAAO,KAAK;;AAErD,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,cAAc,EAAE;EACzD,MAAM,UAAU,OAAO,KAAA,GAAW,MAAM;AACxC,MAAI,QACH,oBAAmB,OAAO;;AAI5B,QAAO"}
|
package/package.json
CHANGED
|
@@ -88,7 +88,14 @@ export function widget<TContent extends WidgetContent | undefined>(
|
|
|
88
88
|
return { ...content, value }
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
if (model.type === "Group"
|
|
91
|
+
if (model.type === "Group") {
|
|
92
|
+
if (content?.__TYPE__ !== GroupContentType) {
|
|
93
|
+
return <TContent>{
|
|
94
|
+
__TYPE__: GroupContentType,
|
|
95
|
+
value: items([], model.config?.fields),
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
92
99
|
return { ...content, value: items(content.value, model.config?.fields) }
|
|
93
100
|
}
|
|
94
101
|
|