@prismicio/types-internal 4.2.0-pr.13.d30a344 → 4.2.0-pr.15.33ed5f7
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/helpers/customTypeModel.d.ts +2 -1
- package/dist/helpers/customTypeModel.d.ts.map +1 -1
- package/dist/helpers/customTypeModel.js +6 -0
- package/dist/helpers/customTypeModel.js.map +1 -1
- package/dist/helpers/documentContent.d.ts +2 -1
- package/dist/helpers/documentContent.d.ts.map +1 -1
- package/dist/helpers/documentContent.js +4 -0
- package/dist/helpers/documentContent.js.map +1 -1
- package/dist/helpers/fieldModel.d.ts +7 -0
- package/dist/helpers/fieldModel.d.ts.map +1 -0
- package/dist/helpers/fieldModel.js +13 -0
- package/dist/helpers/fieldModel.js.map +1 -0
- package/dist/helpers/repository.d.ts +7 -0
- package/dist/helpers/repository.d.ts.map +1 -0
- package/dist/helpers/repository.js +15 -0
- package/dist/helpers/repository.js.map +1 -0
- package/dist/helpers/sliceModel.d.ts +8 -0
- package/dist/helpers/sliceModel.d.ts.map +1 -0
- package/dist/helpers/sliceModel.js +16 -0
- package/dist/helpers/sliceModel.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/model/customType.d.ts.map +1 -1
- package/dist/model/customType.js +0 -5
- package/dist/model/customType.js.map +1 -1
- package/dist/model/image.js +1 -1
- package/dist/model/image.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers/customTypeModel.ts +16 -0
- package/src/helpers/documentContent.ts +10 -0
- package/src/helpers/fieldModel.ts +18 -0
- package/src/helpers/repository.ts +25 -0
- package/src/helpers/sliceModel.ts +18 -0
- package/src/index.ts +3 -0
- package/src/model/customType.ts +0 -7
- package/src/model/image.ts +1 -1
|
@@ -3,12 +3,13 @@ import { DynamicCustomTypeModel, StaticCustomTypeModel, StaticCustomTypeModelTab
|
|
|
3
3
|
|
|
4
4
|
//#region src/helpers/customTypeModel.d.ts
|
|
5
5
|
declare namespace customTypeModel_d_exports {
|
|
6
|
-
export { collectSharedSlices, filterMissingSharedSlices, flatten, toStatic };
|
|
6
|
+
export { collectSharedSlices, filterMissingSharedSlices, flatten, serializeID, toStatic };
|
|
7
7
|
}
|
|
8
8
|
declare function toStatic(customType: DynamicCustomTypeModel, sharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>): StaticCustomTypeModel;
|
|
9
9
|
declare function flatten(customType: StaticCustomTypeModel): StaticCustomTypeModelTab;
|
|
10
10
|
declare function collectSharedSlices(customType: StaticCustomTypeModel): Record<string, SharedSliceModel>;
|
|
11
11
|
declare function filterMissingSharedSlices<TCustomType extends StaticCustomTypeModel | DynamicCustomTypeModel>(customType: TCustomType, sharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>): TCustomType;
|
|
12
|
+
declare function serializeID(input: string): string;
|
|
12
13
|
//#endregion
|
|
13
14
|
export { customTypeModel_d_exports };
|
|
14
15
|
//# sourceMappingURL=customTypeModel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customTypeModel.d.ts","names":[],"sources":["../../src/helpers/customTypeModel.ts"],"mappings":";;;;;;;iBAOgB,QAAA,CACf,UAAA,EAAY,sBAAA,EACZ,YAAA,EAAc,GAAA,SAAY,gBAAA,IAAoB,MAAA,SAAe,gBAAA,IAC3D,qBAAA;AAAA,iBAwCa,OAAA,CAAQ,UAAA,EAAY,qBAAA,GAAwB,wBAAA;AAAA,iBAI5C,mBAAA,CACf,UAAA,EAAY,qBAAA,GACV,MAAA,SAAe,gBAAA;AAAA,iBAiBF,yBAAA,qBACK,qBAAA,GAAwB,sBAAA,CAAA,CAE5C,UAAA,EAAY,WAAA,EACZ,YAAA,EAAc,GAAA,SAAY,gBAAA,IAAoB,MAAA,SAAe,gBAAA,IAC3D,WAAA"}
|
|
1
|
+
{"version":3,"file":"customTypeModel.d.ts","names":[],"sources":["../../src/helpers/customTypeModel.ts"],"mappings":";;;;;;;iBAOgB,QAAA,CACf,UAAA,EAAY,sBAAA,EACZ,YAAA,EAAc,GAAA,SAAY,gBAAA,IAAoB,MAAA,SAAe,gBAAA,IAC3D,qBAAA;AAAA,iBAwCa,OAAA,CAAQ,UAAA,EAAY,qBAAA,GAAwB,wBAAA;AAAA,iBAI5C,mBAAA,CACf,UAAA,EAAY,qBAAA,GACV,MAAA,SAAe,gBAAA;AAAA,iBAiBF,yBAAA,qBACK,qBAAA,GAAwB,sBAAA,CAAA,CAE5C,UAAA,EAAY,WAAA,EACZ,YAAA,EAAc,GAAA,SAAY,gBAAA,IAAoB,MAAA,SAAe,gBAAA,IAC3D,WAAA;AAAA,iBAuCa,WAAA,CAAY,KAAA"}
|
|
@@ -4,6 +4,7 @@ var customTypeModel_exports = /* @__PURE__ */ __exportAll({
|
|
|
4
4
|
collectSharedSlices: () => collectSharedSlices,
|
|
5
5
|
filterMissingSharedSlices: () => filterMissingSharedSlices,
|
|
6
6
|
flatten: () => flatten,
|
|
7
|
+
serializeID: () => serializeID,
|
|
7
8
|
toStatic: () => toStatic
|
|
8
9
|
});
|
|
9
10
|
function toStatic(customType, sharedSlices) {
|
|
@@ -79,6 +80,11 @@ function filterMissingSharedSlices(customType, sharedSlices) {
|
|
|
79
80
|
json
|
|
80
81
|
};
|
|
81
82
|
}
|
|
83
|
+
function serializeID(input) {
|
|
84
|
+
const normalized = input.trim().normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
85
|
+
if (normalized.length === 0) throw new Error(`Cannot serialize "${input}": result is empty.`);
|
|
86
|
+
return normalized;
|
|
87
|
+
}
|
|
82
88
|
//#endregion
|
|
83
89
|
export { collectSharedSlices, customTypeModel_exports, flatten };
|
|
84
90
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customTypeModel.js","names":[],"sources":["../../src/helpers/customTypeModel.ts"],"sourcesContent":["import type {\n\tDynamicCustomTypeModel,\n\tStaticCustomTypeModel,\n\tStaticCustomTypeModelTab,\n} from \"../model/customType\"\nimport type { SharedSliceModel, StaticSliceModel } from \"../model/slice\"\n\nexport function toStatic(\n\tcustomType: DynamicCustomTypeModel,\n\tsharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>,\n): StaticCustomTypeModel {\n\tconst json: StaticCustomTypeModel[\"json\"] = {}\n\n\tconst sharedSlicesMap =\n\t\tsharedSlices instanceof Map ? sharedSlices : new Map(Object.entries(sharedSlices))\n\n\tfor (const [tabKey, tab] of Object.entries(customType.json)) {\n\t\tconst tabJSON: StaticCustomTypeModel[\"json\"][string] = {}\n\t\tfor (const [key, widget] of Object.entries(tab)) {\n\t\t\tswitch (widget.type) {\n\t\t\t\tcase \"Slices\":\n\t\t\t\tcase \"Choice\":\n\t\t\t\t\tconst choices: Record<string, StaticSliceModel> = {}\n\t\t\t\t\tfor (const [id, model] of Object.entries(widget.config?.choices || {})) {\n\t\t\t\t\t\tif (model.type === \"SharedSlice\") {\n\t\t\t\t\t\t\tconst sharedSlice = sharedSlicesMap.get(id)\n\t\t\t\t\t\t\tif (sharedSlice) {\n\t\t\t\t\t\t\t\tchoices[id] = sharedSlice\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tchoices[id] = model\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\ttabJSON[key] = {\n\t\t\t\t\t\t...widget,\n\t\t\t\t\t\tconfig: { ...widget.config, choices },\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\ttabJSON[key] = widget\n\t\t\t}\n\t\t}\n\n\t\tjson[tabKey] = tabJSON\n\t}\n\n\treturn { ...customType, json }\n}\n\nexport function flatten(customType: StaticCustomTypeModel): StaticCustomTypeModelTab {\n\treturn Object.values(customType.json).reduce((acc, fields) => ({ ...acc, ...fields }), {})\n}\n\nexport function collectSharedSlices(\n\tcustomType: StaticCustomTypeModel,\n): Record<string, SharedSliceModel> {\n\tconst sharedSlices: Record<string, SharedSliceModel> = {}\n\n\tconst flattened = flatten(customType)\n\tfor (const widget of Object.values(flattened)) {\n\t\tif (widget.type === \"Slices\" || widget.type === \"Choice\") {\n\t\t\tfor (const [id, model] of Object.entries(widget.config?.choices || {})) {\n\t\t\t\tif (model.type === \"SharedSlice\") {\n\t\t\t\t\tsharedSlices[id] = model\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn sharedSlices\n}\n\nexport function filterMissingSharedSlices<\n\tTCustomType extends StaticCustomTypeModel | DynamicCustomTypeModel,\n>(\n\tcustomType: TCustomType,\n\tsharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>,\n): TCustomType {\n\tconst json: TCustomType[\"json\"] = {}\n\n\tconst sharedSlicesMap =\n\t\tsharedSlices instanceof Map ? sharedSlices : new Map(Object.entries(sharedSlices))\n\n\tfor (const [tabKey, tab] of Object.entries(customType.json)) {\n\t\tconst tabJSON: typeof tab = {}\n\t\tfor (const [key, widget] of Object.entries(tab)) {\n\t\t\tswitch (widget.type) {\n\t\t\t\tcase \"Slices\":\n\t\t\t\tcase \"Choice\":\n\t\t\t\t\tconst choices: Required<typeof widget>[\"config\"][\"choices\"] = {}\n\t\t\t\t\tfor (const [id, model] of Object.entries(widget.config?.choices || {})) {\n\t\t\t\t\t\tif (model.type === \"SharedSlice\") {\n\t\t\t\t\t\t\tif (sharedSlicesMap.get(id)) {\n\t\t\t\t\t\t\t\tchoices[id] = model\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tchoices[id] = model\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\ttabJSON[key] = {\n\t\t\t\t\t\t...widget,\n\t\t\t\t\t\tconfig: { ...widget.config, choices },\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\ttabJSON[key] = widget\n\t\t\t}\n\t\t}\n\n\t\tjson[tabKey] = tabJSON\n\t}\n\n\treturn { ...customType, json }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"customTypeModel.js","names":[],"sources":["../../src/helpers/customTypeModel.ts"],"sourcesContent":["import type {\n\tDynamicCustomTypeModel,\n\tStaticCustomTypeModel,\n\tStaticCustomTypeModelTab,\n} from \"../model/customType\"\nimport type { SharedSliceModel, StaticSliceModel } from \"../model/slice\"\n\nexport function toStatic(\n\tcustomType: DynamicCustomTypeModel,\n\tsharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>,\n): StaticCustomTypeModel {\n\tconst json: StaticCustomTypeModel[\"json\"] = {}\n\n\tconst sharedSlicesMap =\n\t\tsharedSlices instanceof Map ? sharedSlices : new Map(Object.entries(sharedSlices))\n\n\tfor (const [tabKey, tab] of Object.entries(customType.json)) {\n\t\tconst tabJSON: StaticCustomTypeModel[\"json\"][string] = {}\n\t\tfor (const [key, widget] of Object.entries(tab)) {\n\t\t\tswitch (widget.type) {\n\t\t\t\tcase \"Slices\":\n\t\t\t\tcase \"Choice\":\n\t\t\t\t\tconst choices: Record<string, StaticSliceModel> = {}\n\t\t\t\t\tfor (const [id, model] of Object.entries(widget.config?.choices || {})) {\n\t\t\t\t\t\tif (model.type === \"SharedSlice\") {\n\t\t\t\t\t\t\tconst sharedSlice = sharedSlicesMap.get(id)\n\t\t\t\t\t\t\tif (sharedSlice) {\n\t\t\t\t\t\t\t\tchoices[id] = sharedSlice\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tchoices[id] = model\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\ttabJSON[key] = {\n\t\t\t\t\t\t...widget,\n\t\t\t\t\t\tconfig: { ...widget.config, choices },\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\ttabJSON[key] = widget\n\t\t\t}\n\t\t}\n\n\t\tjson[tabKey] = tabJSON\n\t}\n\n\treturn { ...customType, json }\n}\n\nexport function flatten(customType: StaticCustomTypeModel): StaticCustomTypeModelTab {\n\treturn Object.values(customType.json).reduce((acc, fields) => ({ ...acc, ...fields }), {})\n}\n\nexport function collectSharedSlices(\n\tcustomType: StaticCustomTypeModel,\n): Record<string, SharedSliceModel> {\n\tconst sharedSlices: Record<string, SharedSliceModel> = {}\n\n\tconst flattened = flatten(customType)\n\tfor (const widget of Object.values(flattened)) {\n\t\tif (widget.type === \"Slices\" || widget.type === \"Choice\") {\n\t\t\tfor (const [id, model] of Object.entries(widget.config?.choices || {})) {\n\t\t\t\tif (model.type === \"SharedSlice\") {\n\t\t\t\t\tsharedSlices[id] = model\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn sharedSlices\n}\n\nexport function filterMissingSharedSlices<\n\tTCustomType extends StaticCustomTypeModel | DynamicCustomTypeModel,\n>(\n\tcustomType: TCustomType,\n\tsharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>,\n): TCustomType {\n\tconst json: TCustomType[\"json\"] = {}\n\n\tconst sharedSlicesMap =\n\t\tsharedSlices instanceof Map ? sharedSlices : new Map(Object.entries(sharedSlices))\n\n\tfor (const [tabKey, tab] of Object.entries(customType.json)) {\n\t\tconst tabJSON: typeof tab = {}\n\t\tfor (const [key, widget] of Object.entries(tab)) {\n\t\t\tswitch (widget.type) {\n\t\t\t\tcase \"Slices\":\n\t\t\t\tcase \"Choice\":\n\t\t\t\t\tconst choices: Required<typeof widget>[\"config\"][\"choices\"] = {}\n\t\t\t\t\tfor (const [id, model] of Object.entries(widget.config?.choices || {})) {\n\t\t\t\t\t\tif (model.type === \"SharedSlice\") {\n\t\t\t\t\t\t\tif (sharedSlicesMap.get(id)) {\n\t\t\t\t\t\t\t\tchoices[id] = model\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tchoices[id] = model\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\ttabJSON[key] = {\n\t\t\t\t\t\t...widget,\n\t\t\t\t\t\tconfig: { ...widget.config, choices },\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\ttabJSON[key] = widget\n\t\t\t}\n\t\t}\n\n\t\tjson[tabKey] = tabJSON\n\t}\n\n\treturn { ...customType, json }\n}\n\nexport function serializeID(input: string): string {\n\tconst normalized = input\n\t\t.trim()\n\t\t.normalize(\"NFD\")\n\t\t.replace(/\\p{M}/gu, \"\")\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9]+/g, \"_\")\n\t\t.replace(/^_+|_+$/g, \"\")\n\n\tif (normalized.length === 0) {\n\t\tthrow new Error(`Cannot serialize \"${input}\": result is empty.`)\n\t}\n\n\treturn normalized\n}\n"],"mappings":";;;;;;;;;AAOA,SAAgB,SACf,YACA,cACwB;CACxB,MAAM,OAAsC,EAAE;CAE9C,MAAM,kBACL,wBAAwB,MAAM,eAAe,IAAI,IAAI,OAAO,QAAQ,aAAa,CAAC;AAEnF,MAAK,MAAM,CAAC,QAAQ,QAAQ,OAAO,QAAQ,WAAW,KAAK,EAAE;EAC5D,MAAM,UAAiD,EAAE;AACzD,OAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,IAAI,CAC9C,SAAQ,OAAO,MAAf;GACC,KAAK;GACL,KAAK;IACJ,MAAM,UAA4C,EAAE;AACpD,SAAK,MAAM,CAAC,IAAI,UAAU,OAAO,QAAQ,OAAO,QAAQ,WAAW,EAAE,CAAC,CACrE,KAAI,MAAM,SAAS,eAAe;KACjC,MAAM,cAAc,gBAAgB,IAAI,GAAG;AAC3C,SAAI,YACH,SAAQ,MAAM;UAGf,SAAQ,MAAM;AAIhB,YAAQ,OAAO;KACd,GAAG;KACH,QAAQ;MAAE,GAAG,OAAO;MAAQ;MAAS;KACrC;AACD;GACD,QACC,SAAQ,OAAO;;AAIlB,OAAK,UAAU;;AAGhB,QAAO;EAAE,GAAG;EAAY;EAAM;;AAG/B,SAAgB,QAAQ,YAA6D;AACpF,QAAO,OAAO,OAAO,WAAW,KAAK,CAAC,QAAQ,KAAK,YAAY;EAAE,GAAG;EAAK,GAAG;EAAQ,GAAG,EAAE,CAAC;;AAG3F,SAAgB,oBACf,YACmC;CACnC,MAAM,eAAiD,EAAE;CAEzD,MAAM,YAAY,QAAQ,WAAW;AACrC,MAAK,MAAM,UAAU,OAAO,OAAO,UAAU,CAC5C,KAAI,OAAO,SAAS,YAAY,OAAO,SAAS;OAC1C,MAAM,CAAC,IAAI,UAAU,OAAO,QAAQ,OAAO,QAAQ,WAAW,EAAE,CAAC,CACrE,KAAI,MAAM,SAAS,cAClB,cAAa,MAAM;;AAMvB,QAAO;;AAGR,SAAgB,0BAGf,YACA,cACc;CACd,MAAM,OAA4B,EAAE;CAEpC,MAAM,kBACL,wBAAwB,MAAM,eAAe,IAAI,IAAI,OAAO,QAAQ,aAAa,CAAC;AAEnF,MAAK,MAAM,CAAC,QAAQ,QAAQ,OAAO,QAAQ,WAAW,KAAK,EAAE;EAC5D,MAAM,UAAsB,EAAE;AAC9B,OAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,IAAI,CAC9C,SAAQ,OAAO,MAAf;GACC,KAAK;GACL,KAAK;IACJ,MAAM,UAAwD,EAAE;AAChE,SAAK,MAAM,CAAC,IAAI,UAAU,OAAO,QAAQ,OAAO,QAAQ,WAAW,EAAE,CAAC,CACrE,KAAI,MAAM,SAAS;SACd,gBAAgB,IAAI,GAAG,CAC1B,SAAQ,MAAM;UAGf,SAAQ,MAAM;AAIhB,YAAQ,OAAO;KACd,GAAG;KACH,QAAQ;MAAE,GAAG,OAAO;MAAQ;MAAS;KACrC;AACD;GACD,QACC,SAAQ,OAAO;;AAIlB,OAAK,UAAU;;AAGhB,QAAO;EAAE,GAAG;EAAY;EAAM;;AAG/B,SAAgB,YAAY,OAAuB;CAClD,MAAM,aAAa,MACjB,MAAM,CACN,UAAU,MAAM,CAChB,QAAQ,WAAW,GAAG,CACtB,aAAa,CACb,QAAQ,eAAe,IAAI,CAC3B,QAAQ,YAAY,GAAG;AAEzB,KAAI,WAAW,WAAW,EACzB,OAAM,IAAI,MAAM,qBAAqB,MAAM,qBAAqB;AAGjE,QAAO"}
|
|
@@ -6,7 +6,7 @@ import { DocumentLegacy } from "../content/legacy/document.js";
|
|
|
6
6
|
|
|
7
7
|
//#region src/helpers/documentContent.d.ts
|
|
8
8
|
declare namespace documentContent_d_exports {
|
|
9
|
-
export { collectWidgets, fromLegacy, toLegacy };
|
|
9
|
+
export { collectWidgets, fromLegacy, serializeUID, toLegacy };
|
|
10
10
|
}
|
|
11
11
|
declare function collectWidgets<TWidgetContent extends WidgetContent>(document: DocumentContent, test: (content: WidgetContent, args: {
|
|
12
12
|
path: Path;
|
|
@@ -15,6 +15,7 @@ declare function collectWidgets<TWidgetContent extends WidgetContent>(document:
|
|
|
15
15
|
}) => content is TWidgetContent): Record<string, TWidgetContent>;
|
|
16
16
|
declare function fromLegacy(legacy: DocumentLegacy, model: StaticCustomTypeModel): DocumentContent | undefined;
|
|
17
17
|
declare function toLegacy(document: DocumentContent): DocumentLegacy;
|
|
18
|
+
declare function serializeUID(input: string): string;
|
|
18
19
|
//#endregion
|
|
19
20
|
export { documentContent_d_exports };
|
|
20
21
|
//# sourceMappingURL=documentContent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentContent.d.ts","names":[],"sources":["../../src/helpers/documentContent.ts"],"mappings":";;;;;;;;;;iBAkBgB,cAAA,wBAAsC,aAAA,CAAA,CACrD,QAAA,EAAU,eAAA,EACV,IAAA,GACC,OAAA,EAAS,aAAA,EACT,IAAA;EACC,IAAA,EAAM,IAAA;EACN,GAAA;EACA,KAAA;AAAA,MAEG,OAAA,IAAW,cAAA,GACd,MAAA,SAAe,cAAA;AAAA,iBAgBF,UAAA,CACf,MAAA,EAAQ,cAAA,EACR,KAAA,EAAO,qBAAA,GACL,eAAA;AAAA,iBAwDa,QAAA,CAAS,QAAA,EAAU,eAAA,GAAkB,cAAA"}
|
|
1
|
+
{"version":3,"file":"documentContent.d.ts","names":[],"sources":["../../src/helpers/documentContent.ts"],"mappings":";;;;;;;;;;iBAkBgB,cAAA,wBAAsC,aAAA,CAAA,CACrD,QAAA,EAAU,eAAA,EACV,IAAA,GACC,OAAA,EAAS,aAAA,EACT,IAAA;EACC,IAAA,EAAM,IAAA;EACN,GAAA;EACA,KAAA;AAAA,MAEG,OAAA,IAAW,cAAA,GACd,MAAA,SAAe,cAAA;AAAA,iBAgBF,UAAA,CACf,MAAA,EAAQ,cAAA,EACR,KAAA,EAAO,qBAAA,GACL,eAAA;AAAA,iBAwDa,QAAA,CAAS,QAAA,EAAU,eAAA,GAAkB,cAAA;AAAA,iBAMrC,YAAA,CAAa,KAAA"}
|
|
@@ -13,6 +13,7 @@ import { z } from "zod/mini";
|
|
|
13
13
|
var documentContent_exports = /* @__PURE__ */ __exportAll({
|
|
14
14
|
collectWidgets: () => collectWidgets,
|
|
15
15
|
fromLegacy: () => fromLegacy,
|
|
16
|
+
serializeUID: () => serializeUID,
|
|
16
17
|
toLegacy: () => toLegacy
|
|
17
18
|
});
|
|
18
19
|
function collectWidgets(document, test) {
|
|
@@ -58,6 +59,9 @@ function toLegacy(document) {
|
|
|
58
59
|
...keys
|
|
59
60
|
};
|
|
60
61
|
}
|
|
62
|
+
function serializeUID(input) {
|
|
63
|
+
return input.replace(/ /g, "-").normalize("NFD").replace(/\p{M}/gu, "").replace(/[^\p{L}\d_.-]/gu, "").toLowerCase();
|
|
64
|
+
}
|
|
61
65
|
//#endregion
|
|
62
66
|
export { documentContent_exports };
|
|
63
67
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentContent.js","names":["contentPath.serialize","customTypeModel.collectSharedSlices","sliceContent.compositeToShared","sliceContent.legacyToShared"],"sources":["../../src/helpers/documentContent.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\nimport { DocumentLegacyCodec } from \"../content/codec/document\"\nimport { defaultCtx } from \"../content/codec/legacyContentCtx\"\nimport type { DocumentContent } from \"../content/document\"\nimport type { DocumentLegacy } from \"../content/legacy/document\"\nimport { DocumentLegacySchema } from \"../content/legacy/document\"\nimport { isNestableContent } from \"../content/nestable\"\nimport type { CompositeSliceItemContent, LegacySliceItemContent } from \"../content/slices\"\nimport type { WidgetContent } from \"../content/widget\"\nimport type { StaticCustomTypeModel } from \"../model/customType\"\nimport type { FieldOrSliceType } from \"../model/widget\"\nimport { FieldOrSliceTypeSchema } from \"../model/widget\"\nimport * as contentPath from \"./contentPath\"\nimport * as customTypeModel from \"./customTypeModel\"\nimport * as sliceContent from \"./sliceContent\"\nimport { traverseDocumentContent } from \"./traverseContent\"\n\nexport function collectWidgets<TWidgetContent extends WidgetContent>(\n\tdocument: DocumentContent,\n\ttest: (\n\t\tcontent: WidgetContent,\n\t\targs: {\n\t\t\tpath: contentPath.Path\n\t\t\tkey: string\n\t\t\tapiID: string\n\t\t},\n\t) => content is TWidgetContent,\n): Record<string, TWidgetContent> {\n\tconst collected: Record<string, TWidgetContent> = {}\n\n\ttraverseDocumentContent(document, {\n\t\ttransformWidget: ({ content, ...args }) => {\n\t\t\tif (test(content, args)) {\n\t\t\t\tcollected[contentPath.serialize(args.path)] = content\n\t\t\t}\n\n\t\t\treturn content\n\t\t},\n\t})\n\n\treturn collected\n}\n\nexport function fromLegacy(\n\tlegacy: DocumentLegacy,\n\tmodel: StaticCustomTypeModel,\n): DocumentContent | undefined {\n\tconst parsed = DocumentLegacySchema.safeParse(legacy)\n\tif (!parsed.success) {\n\t\treturn\n\t}\n\n\tconst types = new Map<string, FieldOrSliceType>()\n\tconst keys = new Map<string, string>()\n\tconst widgets: DocumentLegacy = {}\n\tfor (const [key, value] of Object.entries(parsed.data)) {\n\t\tif (key.endsWith(\"_TYPE\")) {\n\t\t\tconst parsed = FieldOrSliceTypeSchema.safeParse(value)\n\t\t\tif (parsed.success) {\n\t\t\t\ttypes.set(key.substring(0, key.length - 5), parsed.data)\n\t\t\t}\n\t\t} else if (key.endsWith(\"_KEY\")) {\n\t\t\tconst parsed = z.uuidv4().safeParse(value)\n\t\t\tif (parsed.success) {\n\t\t\t\tkeys.set(key.substring(0, key.length - 4), parsed.data)\n\t\t\t}\n\t\t} else if (!key.endsWith(\"_POSITION\")) {\n\t\t\twidgets[key] = value\n\t\t}\n\t}\n\n\tconst result = DocumentLegacyCodec(defaultCtx(\"\", types, keys)).toContent(widgets)\n\tif (!result.success) {\n\t\treturn\n\t}\n\n\tconst needsMigration = Object.values(customTypeModel.collectSharedSlices(model)).some((slice) =>\n\t\tBoolean(slice.legacyPaths),\n\t)\n\n\tif (needsMigration) {\n\t\treturn traverseDocumentContent(result.data, {\n\t\t\tmodel,\n\t\t\ttransformSlice: ({ content, model }) => {\n\t\t\t\tif (model?.type === \"SharedSlice\") {\n\t\t\t\t\tif (content.widget.__TYPE__ === \"CompositeSliceContent\") {\n\t\t\t\t\t\treturn sliceContent.compositeToShared(content as CompositeSliceItemContent, model)\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tcontent.widget.__TYPE__ === \"GroupContentType\" ||\n\t\t\t\t\t\tisNestableContent(content.widget)\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn sliceContent.legacyToShared(content as LegacySliceItemContent, model)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn content\n\t\t\t},\n\t\t})\n\t}\n\n\treturn result.data\n}\n\nexport function toLegacy(document: DocumentContent): DocumentLegacy {\n\tconst { content, types, keys } = DocumentLegacyCodec(defaultCtx(\"\")).fromContent(document)\n\n\treturn { ...content, ...types, ...keys }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"documentContent.js","names":["contentPath.serialize","customTypeModel.collectSharedSlices","sliceContent.compositeToShared","sliceContent.legacyToShared"],"sources":["../../src/helpers/documentContent.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\nimport { DocumentLegacyCodec } from \"../content/codec/document\"\nimport { defaultCtx } from \"../content/codec/legacyContentCtx\"\nimport type { DocumentContent } from \"../content/document\"\nimport type { DocumentLegacy } from \"../content/legacy/document\"\nimport { DocumentLegacySchema } from \"../content/legacy/document\"\nimport { isNestableContent } from \"../content/nestable\"\nimport type { CompositeSliceItemContent, LegacySliceItemContent } from \"../content/slices\"\nimport type { WidgetContent } from \"../content/widget\"\nimport type { StaticCustomTypeModel } from \"../model/customType\"\nimport type { FieldOrSliceType } from \"../model/widget\"\nimport { FieldOrSliceTypeSchema } from \"../model/widget\"\nimport * as contentPath from \"./contentPath\"\nimport * as customTypeModel from \"./customTypeModel\"\nimport * as sliceContent from \"./sliceContent\"\nimport { traverseDocumentContent } from \"./traverseContent\"\n\nexport function collectWidgets<TWidgetContent extends WidgetContent>(\n\tdocument: DocumentContent,\n\ttest: (\n\t\tcontent: WidgetContent,\n\t\targs: {\n\t\t\tpath: contentPath.Path\n\t\t\tkey: string\n\t\t\tapiID: string\n\t\t},\n\t) => content is TWidgetContent,\n): Record<string, TWidgetContent> {\n\tconst collected: Record<string, TWidgetContent> = {}\n\n\ttraverseDocumentContent(document, {\n\t\ttransformWidget: ({ content, ...args }) => {\n\t\t\tif (test(content, args)) {\n\t\t\t\tcollected[contentPath.serialize(args.path)] = content\n\t\t\t}\n\n\t\t\treturn content\n\t\t},\n\t})\n\n\treturn collected\n}\n\nexport function fromLegacy(\n\tlegacy: DocumentLegacy,\n\tmodel: StaticCustomTypeModel,\n): DocumentContent | undefined {\n\tconst parsed = DocumentLegacySchema.safeParse(legacy)\n\tif (!parsed.success) {\n\t\treturn\n\t}\n\n\tconst types = new Map<string, FieldOrSliceType>()\n\tconst keys = new Map<string, string>()\n\tconst widgets: DocumentLegacy = {}\n\tfor (const [key, value] of Object.entries(parsed.data)) {\n\t\tif (key.endsWith(\"_TYPE\")) {\n\t\t\tconst parsed = FieldOrSliceTypeSchema.safeParse(value)\n\t\t\tif (parsed.success) {\n\t\t\t\ttypes.set(key.substring(0, key.length - 5), parsed.data)\n\t\t\t}\n\t\t} else if (key.endsWith(\"_KEY\")) {\n\t\t\tconst parsed = z.uuidv4().safeParse(value)\n\t\t\tif (parsed.success) {\n\t\t\t\tkeys.set(key.substring(0, key.length - 4), parsed.data)\n\t\t\t}\n\t\t} else if (!key.endsWith(\"_POSITION\")) {\n\t\t\twidgets[key] = value\n\t\t}\n\t}\n\n\tconst result = DocumentLegacyCodec(defaultCtx(\"\", types, keys)).toContent(widgets)\n\tif (!result.success) {\n\t\treturn\n\t}\n\n\tconst needsMigration = Object.values(customTypeModel.collectSharedSlices(model)).some((slice) =>\n\t\tBoolean(slice.legacyPaths),\n\t)\n\n\tif (needsMigration) {\n\t\treturn traverseDocumentContent(result.data, {\n\t\t\tmodel,\n\t\t\ttransformSlice: ({ content, model }) => {\n\t\t\t\tif (model?.type === \"SharedSlice\") {\n\t\t\t\t\tif (content.widget.__TYPE__ === \"CompositeSliceContent\") {\n\t\t\t\t\t\treturn sliceContent.compositeToShared(content as CompositeSliceItemContent, model)\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tcontent.widget.__TYPE__ === \"GroupContentType\" ||\n\t\t\t\t\t\tisNestableContent(content.widget)\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn sliceContent.legacyToShared(content as LegacySliceItemContent, model)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn content\n\t\t\t},\n\t\t})\n\t}\n\n\treturn result.data\n}\n\nexport function toLegacy(document: DocumentContent): DocumentLegacy {\n\tconst { content, types, keys } = DocumentLegacyCodec(defaultCtx(\"\")).fromContent(document)\n\n\treturn { ...content, ...types, ...keys }\n}\n\nexport function serializeUID(input: string): string {\n\tconst nowhitespace = input.replace(/ /g, \"-\")\n\n\tconst normalized = nowhitespace.normalize(\"NFD\").replace(/\\p{M}/gu, \"\")\n\n\tconst slug = normalized.replace(/[^\\p{L}\\d_.-]/gu, \"\")\n\n\treturn slug.toLowerCase()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,SAAgB,eACf,UACA,MAQiC;CACjC,MAAM,YAA4C,EAAE;AAEpD,yBAAwB,UAAU,EACjC,kBAAkB,EAAE,SAAS,GAAG,WAAW;AAC1C,MAAI,KAAK,SAAS,KAAK,CACtB,WAAUA,UAAsB,KAAK,KAAK,IAAI;AAG/C,SAAO;IAER,CAAC;AAEF,QAAO;;AAGR,SAAgB,WACf,QACA,OAC8B;CAC9B,MAAM,SAAS,qBAAqB,UAAU,OAAO;AACrD,KAAI,CAAC,OAAO,QACX;CAGD,MAAM,wBAAQ,IAAI,KAA+B;CACjD,MAAM,uBAAO,IAAI,KAAqB;CACtC,MAAM,UAA0B,EAAE;AAClC,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,KAAK,CACrD,KAAI,IAAI,SAAS,QAAQ,EAAE;EAC1B,MAAM,SAAS,uBAAuB,UAAU,MAAM;AACtD,MAAI,OAAO,QACV,OAAM,IAAI,IAAI,UAAU,GAAG,IAAI,SAAS,EAAE,EAAE,OAAO,KAAK;YAE/C,IAAI,SAAS,OAAO,EAAE;EAChC,MAAM,SAAS,EAAE,QAAQ,CAAC,UAAU,MAAM;AAC1C,MAAI,OAAO,QACV,MAAK,IAAI,IAAI,UAAU,GAAG,IAAI,SAAS,EAAE,EAAE,OAAO,KAAK;YAE9C,CAAC,IAAI,SAAS,YAAY,CACpC,SAAQ,OAAO;CAIjB,MAAM,SAAS,oBAAoB,WAAW,IAAI,OAAO,KAAK,CAAC,CAAC,UAAU,QAAQ;AAClF,KAAI,CAAC,OAAO,QACX;AAOD,KAJuB,OAAO,OAAOC,oBAAoC,MAAM,CAAC,CAAC,MAAM,UACtF,QAAQ,MAAM,YAAY,CAC1B,CAGA,QAAO,wBAAwB,OAAO,MAAM;EAC3C;EACA,iBAAiB,EAAE,SAAS,YAAY;AACvC,OAAI,OAAO,SAAS;QACf,QAAQ,OAAO,aAAa,wBAC/B,QAAOC,kBAA+B,SAAsC,MAAM;aAElF,QAAQ,OAAO,aAAa,sBAC5B,kBAAkB,QAAQ,OAAO,CAEjC,QAAOC,eAA4B,SAAmC,MAAM;;AAG9E,UAAO;;EAER,CAAC;AAGH,QAAO,OAAO;;AAGf,SAAgB,SAAS,UAA2C;CACnE,MAAM,EAAE,SAAS,OAAO,SAAS,oBAAoB,WAAW,GAAG,CAAC,CAAC,YAAY,SAAS;AAE1F,QAAO;EAAE,GAAG;EAAS,GAAG;EAAO,GAAG;EAAM;;AAGzC,SAAgB,aAAa,OAAuB;AAOnD,QANqB,MAAM,QAAQ,MAAM,IAAI,CAEb,UAAU,MAAM,CAAC,QAAQ,WAAW,GAAG,CAE/C,QAAQ,mBAAmB,GAAG,CAE1C,aAAa"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldModel.d.ts","names":[],"sources":["../../src/helpers/fieldModel.ts"],"mappings":";;;iBAAgB,WAAA,CAAY,KAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
//#region src/helpers/fieldModel.ts
|
|
3
|
+
var fieldModel_exports = /* @__PURE__ */ __exportAll({ serializeID: () => serializeID });
|
|
4
|
+
function serializeID(input) {
|
|
5
|
+
const tokens = input.trim().normalize("NFD").replace(/\p{M}/gu, "").split(/[^A-Za-z0-9]+/).filter(Boolean);
|
|
6
|
+
if (tokens.length === 0) throw new Error(`Cannot serialize "${input}": result is empty.`);
|
|
7
|
+
const [first, ...rest] = tokens;
|
|
8
|
+
return first.toLowerCase() + rest.map((token) => token.charAt(0).toUpperCase() + token.slice(1).toLowerCase()).join("");
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { fieldModel_exports };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=fieldModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldModel.js","names":[],"sources":["../../src/helpers/fieldModel.ts"],"sourcesContent":["export function serializeID(input: string): string {\n\tconst tokens = input\n\t\t.trim()\n\t\t.normalize(\"NFD\")\n\t\t.replace(/\\p{M}/gu, \"\")\n\t\t.split(/[^A-Za-z0-9]+/)\n\t\t.filter(Boolean)\n\n\tif (tokens.length === 0) {\n\t\tthrow new Error(`Cannot serialize \"${input}\": result is empty.`)\n\t}\n\n\tconst [first, ...rest] = tokens\n\treturn (\n\t\tfirst.toLowerCase() +\n\t\trest.map((token) => token.charAt(0).toUpperCase() + token.slice(1).toLowerCase()).join(\"\")\n\t)\n}\n"],"mappings":";;;AAAA,SAAgB,YAAY,OAAuB;CAClD,MAAM,SAAS,MACb,MAAM,CACN,UAAU,MAAM,CAChB,QAAQ,WAAW,GAAG,CACtB,MAAM,gBAAgB,CACtB,OAAO,QAAQ;AAEjB,KAAI,OAAO,WAAW,EACrB,OAAM,IAAI,MAAM,qBAAqB,MAAM,qBAAqB;CAGjE,MAAM,CAAC,OAAO,GAAG,QAAQ;AACzB,QACC,MAAM,aAAa,GACnB,KAAK,KAAK,UAAU,MAAM,OAAO,EAAE,CAAC,aAAa,GAAG,MAAM,MAAM,EAAE,CAAC,aAAa,CAAC,CAAC,KAAK,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.d.ts","names":[],"sources":["../../src/helpers/repository.ts"],"mappings":";;;iBAGgB,YAAA,CAAa,KAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
//#region src/helpers/repository.ts
|
|
3
|
+
var repository_exports = /* @__PURE__ */ __exportAll({ serializeUID: () => serializeUID });
|
|
4
|
+
const MIN_LENGTH = 4;
|
|
5
|
+
const MAX_LENGTH = 63;
|
|
6
|
+
function serializeUID(input) {
|
|
7
|
+
const normalized = input.trim().normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
8
|
+
const truncated = normalized.length > MAX_LENGTH ? normalized.slice(0, MAX_LENGTH).replace(/-+$/, "") : normalized;
|
|
9
|
+
if (truncated.length < MIN_LENGTH) throw new Error(`Cannot serialize "${input}" to a repository ID: result must be between ${MIN_LENGTH} and ${MAX_LENGTH} characters.`);
|
|
10
|
+
return truncated;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { repository_exports };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.js","names":[],"sources":["../../src/helpers/repository.ts"],"sourcesContent":["const MIN_LENGTH = 4\nconst MAX_LENGTH = 63\n\nexport function serializeUID(input: string): string {\n\tconst normalized = input\n\t\t.trim()\n\t\t.normalize(\"NFD\")\n\t\t.replace(/\\p{M}/gu, \"\")\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9]+/g, \"-\")\n\t\t.replace(/^-+|-+$/g, \"\")\n\n\tconst truncated =\n\t\tnormalized.length > MAX_LENGTH\n\t\t\t? normalized.slice(0, MAX_LENGTH).replace(/-+$/, \"\")\n\t\t\t: normalized\n\n\tif (truncated.length < MIN_LENGTH) {\n\t\tthrow new Error(\n\t\t\t`Cannot serialize \"${input}\" to a repository ID: result must be between ${MIN_LENGTH} and ${MAX_LENGTH} characters.`,\n\t\t)\n\t}\n\n\treturn truncated\n}\n"],"mappings":";;;AAAA,MAAM,aAAa;AACnB,MAAM,aAAa;AAEnB,SAAgB,aAAa,OAAuB;CACnD,MAAM,aAAa,MACjB,MAAM,CACN,UAAU,MAAM,CAChB,QAAQ,WAAW,GAAG,CACtB,aAAa,CACb,QAAQ,eAAe,IAAI,CAC3B,QAAQ,YAAY,GAAG;CAEzB,MAAM,YACL,WAAW,SAAS,aACjB,WAAW,MAAM,GAAG,WAAW,CAAC,QAAQ,OAAO,GAAG,GAClD;AAEJ,KAAI,UAAU,SAAS,WACtB,OAAM,IAAI,MACT,qBAAqB,MAAM,+CAA+C,WAAW,OAAO,WAAW,cACvG;AAGF,QAAO"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare namespace sliceModel_d_exports {
|
|
2
|
+
export { serializeID, serializeVariationID };
|
|
3
|
+
}
|
|
4
|
+
declare function serializeID(input: string): string;
|
|
5
|
+
declare const serializeVariationID: typeof serializeID;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { sliceModel_d_exports };
|
|
8
|
+
//# sourceMappingURL=sliceModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sliceModel.d.ts","names":[],"sources":["../../src/helpers/sliceModel.ts"],"mappings":";;;iBAAgB,WAAA,CAAY,KAAA;AAAA,cAiBf,oBAAA,SAAoB,WAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
//#region src/helpers/sliceModel.ts
|
|
3
|
+
var sliceModel_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
+
serializeID: () => serializeID,
|
|
5
|
+
serializeVariationID: () => serializeVariationID
|
|
6
|
+
});
|
|
7
|
+
function serializeID(input) {
|
|
8
|
+
const tokens = input.trim().normalize("NFD").replace(/\p{M}/gu, "").split(/[^A-Za-z0-9]+/).filter(Boolean);
|
|
9
|
+
if (tokens.length === 0) throw new Error(`Cannot serialize "${input}": result is empty.`);
|
|
10
|
+
return tokens.map((token) => token.charAt(0).toUpperCase() + token.slice(1).toLowerCase()).join("");
|
|
11
|
+
}
|
|
12
|
+
const serializeVariationID = serializeID;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { sliceModel_exports };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=sliceModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sliceModel.js","names":[],"sources":["../../src/helpers/sliceModel.ts"],"sourcesContent":["export function serializeID(input: string): string {\n\tconst tokens = input\n\t\t.trim()\n\t\t.normalize(\"NFD\")\n\t\t.replace(/\\p{M}/gu, \"\")\n\t\t.split(/[^A-Za-z0-9]+/)\n\t\t.filter(Boolean)\n\n\tif (tokens.length === 0) {\n\t\tthrow new Error(`Cannot serialize \"${input}\": result is empty.`)\n\t}\n\n\treturn tokens\n\t\t.map((token) => token.charAt(0).toUpperCase() + token.slice(1).toLowerCase())\n\t\t.join(\"\")\n}\n\nexport const serializeVariationID = serializeID\n"],"mappings":";;;;;;AAAA,SAAgB,YAAY,OAAuB;CAClD,MAAM,SAAS,MACb,MAAM,CACN,UAAU,MAAM,CAChB,QAAQ,WAAW,GAAG,CACtB,MAAM,gBAAgB,CACtB,OAAO,QAAQ;AAEjB,KAAI,OAAO,WAAW,EACrB,OAAM,IAAI,MAAM,qBAAqB,MAAM,qBAAqB;AAGjE,QAAO,OACL,KAAK,UAAU,MAAM,OAAO,EAAE,CAAC,aAAa,GAAG,MAAM,MAAM,EAAE,CAAC,aAAa,CAAC,CAC5E,KAAK,GAAG;;AAGX,MAAa,uBAAuB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -50,9 +50,12 @@ import { LegacyContentCtx, defaultCtx, getFieldCtx } from "./content/codec/legac
|
|
|
50
50
|
import { contentPath_d_exports } from "./helpers/contentPath.js";
|
|
51
51
|
import { customTypeModel_d_exports } from "./helpers/customTypeModel.js";
|
|
52
52
|
import { documentContent_d_exports } from "./helpers/documentContent.js";
|
|
53
|
+
import { fieldModel_d_exports } from "./helpers/fieldModel.js";
|
|
54
|
+
import { repository_d_exports } from "./helpers/repository.js";
|
|
53
55
|
import { sliceContent_d_exports } from "./helpers/sliceContent.js";
|
|
56
|
+
import { sliceModel_d_exports } from "./helpers/sliceModel.js";
|
|
54
57
|
import { withDefaultContent_d_exports } from "./helpers/withDefaultContent.js";
|
|
55
58
|
import { imageContent_d_exports } from "./helpers/imageContent.js";
|
|
56
59
|
import { TraverseSliceContentFunction, TraverseWidgetContentFunction, traverseCompositeSliceContent, traverseDocumentContent, traverseGroupContent, traverseGroupItemsContent, traverseLegacySliceContent, traverseRepeatableContent, traverseSharedSliceContent, traverseSlicesContent, traverseTableContent } from "./helpers/traverseContent.js";
|
|
57
60
|
import { TraverseSliceContentWithModelFunction, TraverseWidgetContentWithModelFunction, traverseCompositeSliceContentWithModel, traverseDocumentContentWithModel, traverseGroupContentWithModel, traverseGroupItemsContentWithModel, traverseLegacySliceContentWithModel, traverseRepeatableContentWithModel, traverseSharedSliceContentWithModel, traverseSlicesContentWithModel, traverseTableContentWithModel } from "./helpers/traverseContentWithModel.js";
|
|
58
|
-
export { type Asset, type BooleanContent, type BooleanModel, type ColorContent, type ColorModel, type CompositeSliceContent, type CompositeSliceItemContent, type CompositeSliceModel, type CustomTypeModel, type DateContent, type DateModel, type DocumentContent, type DynamicCustomTypeModel, type DynamicCustomTypeModelTab, type DynamicSliceModel, type DynamicSlicesModel, type DynamicWidgetModel, type Embed, type EmbedContent, type EmbedModel, type EmptyContent, type EmptyLinkContent, type FieldContent, type FieldModelType, type FilledLinkContent, type GeoPointContent, type GeoPointModel, type GroupContent, type GroupItemContent, type GroupModel, type HexaColorCode, type ImageContent, type ImageContentView, type ImageModel, type IntegrationFieldContent, type IntegrationFieldModel, LegacyContentCtx, type LegacySliceContent, type LegacySliceItemContent, type LegacySliceModel, type LinkContent, type LinkModel, type NestableContent, type NestableModel, type NestedGroupModel, type NonEmptyString, type NumberContent, type NumberModel, type RangeContent, type RangeModel, type RepeatableContent, type RichTextContent, type RichTextContentBlock, type RichTextContentEmbedBlock, type RichTextContentImageBlock, type RichTextContentSpan, type RichTextContentTextBlock, type RichTextModel, RichTextModelNodeType, type RichTextModelNodeTypes, RichTextNodeType, type RichTextNodeTypes, type SelectContent, type SelectModel, type SeparatorContent, type SeparatorModel, type SharedSliceContent, type SharedSliceItemContent, type SharedSliceModel, type SharedSliceModelVariation, type SharedSliceRefModel, type SharedSliceVariationContentModel, type SliceContent, type SliceContentModel, type SliceItemContent, type SliceModelType, type SlicesContent, type StaticCustomTypeModel, type StaticCustomTypeModelTab, type StaticSliceModel, type StaticSlicesModel, type StaticWidgetModel, TableCellModelNodeTypes, type TableContent, type TableModel, type TextContent, type TextModel, type TimestampContent, type TimestampModel, type TraverseSliceContentFunction, type TraverseSliceContentWithModelFunction, type TraverseWidgetContentFunction, type TraverseWidgetContentWithModelFunction, type UIDContent, type UIDModel, type WidgetContent, type WidgetKey, contentPath_d_exports as contentPath, customTypeModel_d_exports as customTypeModel, defaultCtx, documentContent_d_exports as documentContent, getFieldCtx, imageContent_d_exports as imageContent, sliceContent_d_exports as sliceContent, traverseCompositeSliceContent, traverseCompositeSliceContentWithModel, traverseDocumentContent, traverseDocumentContentWithModel, traverseGroupContent, traverseGroupContentWithModel, traverseGroupItemsContent, traverseGroupItemsContentWithModel, traverseLegacySliceContent, traverseLegacySliceContentWithModel, traverseRepeatableContent, traverseRepeatableContentWithModel, traverseSharedSliceContent, traverseSharedSliceContentWithModel, traverseSlicesContent, traverseSlicesContentWithModel, traverseTableContent, traverseTableContentWithModel, withDefaultContent_d_exports as withDefaultContent };
|
|
61
|
+
export { type Asset, type BooleanContent, type BooleanModel, type ColorContent, type ColorModel, type CompositeSliceContent, type CompositeSliceItemContent, type CompositeSliceModel, type CustomTypeModel, type DateContent, type DateModel, type DocumentContent, type DynamicCustomTypeModel, type DynamicCustomTypeModelTab, type DynamicSliceModel, type DynamicSlicesModel, type DynamicWidgetModel, type Embed, type EmbedContent, type EmbedModel, type EmptyContent, type EmptyLinkContent, type FieldContent, type FieldModelType, type FilledLinkContent, type GeoPointContent, type GeoPointModel, type GroupContent, type GroupItemContent, type GroupModel, type HexaColorCode, type ImageContent, type ImageContentView, type ImageModel, type IntegrationFieldContent, type IntegrationFieldModel, LegacyContentCtx, type LegacySliceContent, type LegacySliceItemContent, type LegacySliceModel, type LinkContent, type LinkModel, type NestableContent, type NestableModel, type NestedGroupModel, type NonEmptyString, type NumberContent, type NumberModel, type RangeContent, type RangeModel, type RepeatableContent, type RichTextContent, type RichTextContentBlock, type RichTextContentEmbedBlock, type RichTextContentImageBlock, type RichTextContentSpan, type RichTextContentTextBlock, type RichTextModel, RichTextModelNodeType, type RichTextModelNodeTypes, RichTextNodeType, type RichTextNodeTypes, type SelectContent, type SelectModel, type SeparatorContent, type SeparatorModel, type SharedSliceContent, type SharedSliceItemContent, type SharedSliceModel, type SharedSliceModelVariation, type SharedSliceRefModel, type SharedSliceVariationContentModel, type SliceContent, type SliceContentModel, type SliceItemContent, type SliceModelType, type SlicesContent, type StaticCustomTypeModel, type StaticCustomTypeModelTab, type StaticSliceModel, type StaticSlicesModel, type StaticWidgetModel, TableCellModelNodeTypes, type TableContent, type TableModel, type TextContent, type TextModel, type TimestampContent, type TimestampModel, type TraverseSliceContentFunction, type TraverseSliceContentWithModelFunction, type TraverseWidgetContentFunction, type TraverseWidgetContentWithModelFunction, type UIDContent, type UIDModel, type WidgetContent, type WidgetKey, contentPath_d_exports as contentPath, customTypeModel_d_exports as customTypeModel, defaultCtx, documentContent_d_exports as documentContent, fieldModel_d_exports as fieldModel, getFieldCtx, imageContent_d_exports as imageContent, repository_d_exports as repository, sliceContent_d_exports as sliceContent, sliceModel_d_exports as sliceModel, traverseCompositeSliceContent, traverseCompositeSliceContentWithModel, traverseDocumentContent, traverseDocumentContentWithModel, traverseGroupContent, traverseGroupContentWithModel, traverseGroupItemsContent, traverseGroupItemsContentWithModel, traverseLegacySliceContent, traverseLegacySliceContentWithModel, traverseRepeatableContent, traverseRepeatableContentWithModel, traverseSharedSliceContent, traverseSharedSliceContentWithModel, traverseSlicesContent, traverseSlicesContentWithModel, traverseTableContent, traverseTableContentWithModel, withDefaultContent_d_exports as withDefaultContent };
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,10 @@ import { customTypeModel_exports } from "./helpers/customTypeModel.js";
|
|
|
8
8
|
import { sliceContent_exports } from "./helpers/sliceContent.js";
|
|
9
9
|
import { traverseCompositeSliceContent, traverseDocumentContent, traverseGroupContent, traverseGroupItemsContent, traverseLegacySliceContent, traverseRepeatableContent, traverseSharedSliceContent, traverseSlicesContent, traverseTableContent } from "./helpers/traverseContent.js";
|
|
10
10
|
import { documentContent_exports } from "./helpers/documentContent.js";
|
|
11
|
+
import { fieldModel_exports } from "./helpers/fieldModel.js";
|
|
12
|
+
import { repository_exports } from "./helpers/repository.js";
|
|
13
|
+
import { sliceModel_exports } from "./helpers/sliceModel.js";
|
|
11
14
|
import { withDefaultContent_exports } from "./helpers/withDefaultContent.js";
|
|
12
15
|
import { imageContent_exports } from "./helpers/imageContent.js";
|
|
13
16
|
import { traverseCompositeSliceContentWithModel, traverseDocumentContentWithModel, traverseGroupContentWithModel, traverseGroupItemsContentWithModel, traverseLegacySliceContentWithModel, traverseRepeatableContentWithModel, traverseSharedSliceContentWithModel, traverseSlicesContentWithModel, traverseTableContentWithModel } from "./helpers/traverseContentWithModel.js";
|
|
14
|
-
export { LegacyContentCtx, RichTextModelNodeType, RichTextNodeType, TableCellModelNodeTypes, contentPath_exports as contentPath, customTypeModel_exports as customTypeModel, defaultCtx, documentContent_exports as documentContent, getFieldCtx, imageContent_exports as imageContent, sliceContent_exports as sliceContent, traverseCompositeSliceContent, traverseCompositeSliceContentWithModel, traverseDocumentContent, traverseDocumentContentWithModel, traverseGroupContent, traverseGroupContentWithModel, traverseGroupItemsContent, traverseGroupItemsContentWithModel, traverseLegacySliceContent, traverseLegacySliceContentWithModel, traverseRepeatableContent, traverseRepeatableContentWithModel, traverseSharedSliceContent, traverseSharedSliceContentWithModel, traverseSlicesContent, traverseSlicesContentWithModel, traverseTableContent, traverseTableContentWithModel, withDefaultContent_exports as withDefaultContent };
|
|
17
|
+
export { LegacyContentCtx, RichTextModelNodeType, RichTextNodeType, TableCellModelNodeTypes, contentPath_exports as contentPath, customTypeModel_exports as customTypeModel, defaultCtx, documentContent_exports as documentContent, fieldModel_exports as fieldModel, getFieldCtx, imageContent_exports as imageContent, repository_exports as repository, sliceContent_exports as sliceContent, sliceModel_exports as sliceModel, traverseCompositeSliceContent, traverseCompositeSliceContentWithModel, traverseDocumentContent, traverseDocumentContentWithModel, traverseGroupContent, traverseGroupContentWithModel, traverseGroupItemsContent, traverseGroupItemsContentWithModel, traverseLegacySliceContent, traverseLegacySliceContentWithModel, traverseRepeatableContent, traverseRepeatableContentWithModel, traverseSharedSliceContent, traverseSharedSliceContentWithModel, traverseSlicesContent, traverseSlicesContentWithModel, traverseTableContent, traverseTableContentWithModel, withDefaultContent_exports as withDefaultContent };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customType.d.ts","names":[],"sources":["../../src/model/customType.ts"],"mappings":";;;;cAMa,8BAAA,EAA8B,CAAA,CAAA,aAAA,CAAA,CAAA,CAAA,aAAA,UAAA,CAAA,CAAA,WAAA,CAAA,iBAAA,WAAA,CAAA,CAAA,IAAA,CAAA,iBAAA,CAAA,iBAAA;AAAA,KAC/B,wBAAA,GAA2B,CAAA,CAAE,KAAA,QAAa,8BAAA;AAAA,cAEzC,+BAAA,EAA+B,CAAA,CAAA,aAAA,CAAA,CAAA,CAAA,aAAA,UAAA,CAAA,CAAA,WAAA,CAAA,kBAAA,WAAA,CAAA,CAAA,IAAA,CAAA,iBAAA,CAAA,kBAAA;AAAA,KAChC,yBAAA,GAA4B,CAAA,CAAE,KAAA,QAAa,+BAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"customType.d.ts","names":[],"sources":["../../src/model/customType.ts"],"mappings":";;;;cAMa,8BAAA,EAA8B,CAAA,CAAA,aAAA,CAAA,CAAA,CAAA,aAAA,UAAA,CAAA,CAAA,WAAA,CAAA,iBAAA,WAAA,CAAA,CAAA,IAAA,CAAA,iBAAA,CAAA,iBAAA;AAAA,KAC/B,wBAAA,GAA2B,CAAA,CAAE,KAAA,QAAa,8BAAA;AAAA,cAEzC,+BAAA,EAA+B,CAAA,CAAA,aAAA,CAAA,CAAA,CAAA,aAAA,UAAA,CAAA,CAAA,WAAA,CAAA,kBAAA,WAAA,CAAA,CAAA,IAAA,CAAA,iBAAA,CAAA,kBAAA;AAAA,KAChC,yBAAA,GAA4B,CAAA,CAAE,KAAA,QAAa,+BAAA;AAAA,cAwD1C,2BAAA,EAA2B,CAAA,CAAA,aAAA;;;;;;;;;;;KAC5B,qBAAA,GAAwB,CAAA,CAAE,KAAA,QAAa,2BAAA;AAAA,cAEtC,4BAAA,EAA4B,CAAA,CAAA,aAAA;;;;;;;;;;;KAC7B,sBAAA,GAAyB,CAAA,CAAE,KAAA,QAAa,4BAAA;;KAKxC,eAAA,GAAkB,sBAAA"}
|
package/dist/model/customType.js
CHANGED
|
@@ -15,11 +15,6 @@ const createCustomTypeSchema = (sectionSchema) => z.object({
|
|
|
15
15
|
}).check(z.superRefine((model, ctx) => {
|
|
16
16
|
const { json } = model;
|
|
17
17
|
const tabEntries = Object.entries(json);
|
|
18
|
-
if (tabEntries.length === 0) ctx.addIssue({
|
|
19
|
-
code: "custom",
|
|
20
|
-
message: `Custom type "${model.id}" must have at least one tab`,
|
|
21
|
-
path: ["json"]
|
|
22
|
-
});
|
|
23
18
|
const existingWidgetKeys = /* @__PURE__ */ new Map();
|
|
24
19
|
for (const [tabID, tab] of tabEntries) for (const [widgetID, widget] of Object.entries(tab)) {
|
|
25
20
|
if (widget.type === "UID" && widgetID !== "uid") ctx.addIssue({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customType.js","names":[],"sources":["../../src/model/customType.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\nimport { WidgetKeySchema } from \"../common/widgetKey\"\nimport { DynamicWidgetModelSchema, StaticWidgetModelSchema } from \"./widget\"\n\n// Tab\nexport const StaticCustomTypeModelTabSchema = z.record(WidgetKeySchema, StaticWidgetModelSchema)\nexport type StaticCustomTypeModelTab = z.infer<typeof StaticCustomTypeModelTabSchema>\n\nexport const DynamicCustomTypeModelTabSchema = z.record(WidgetKeySchema, DynamicWidgetModelSchema)\nexport type DynamicCustomTypeModelTab = z.infer<typeof DynamicCustomTypeModelTabSchema>\n\n// Custom types\nexport const CustomTypeFormatSchema = z.enum([\"page\", \"custom\"])\nexport type CustomTypeFormat = z.infer<typeof CustomTypeFormatSchema>\n\n// Factory to create CustomType schema with configurable section type\nconst createCustomTypeSchema = <\n\tT extends typeof StaticCustomTypeModelTabSchema | typeof DynamicCustomTypeModelTabSchema,\n>(\n\tsectionSchema: T,\n) =>\n\tz\n\t\t.object({\n\t\t\tid: z.string(),\n\t\t\tlabel: z.nullish(z.string()),\n\t\t\trepeatable: z._default(z.boolean(), true),\n\t\t\tjson: z.record(z.string(), sectionSchema),\n\t\t\tstatus: z._default(z.boolean(), true),\n\t\t\tformat: z._default(CustomTypeFormatSchema, \"custom\"),\n\t\t})\n\t\t.check(\n\t\t\tz.superRefine((model, ctx) => {\n\t\t\t\tconst { json } = model\n\n\t\t\t\tconst tabEntries = Object.entries(json)\n\
|
|
1
|
+
{"version":3,"file":"customType.js","names":[],"sources":["../../src/model/customType.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\nimport { WidgetKeySchema } from \"../common/widgetKey\"\nimport { DynamicWidgetModelSchema, StaticWidgetModelSchema } from \"./widget\"\n\n// Tab\nexport const StaticCustomTypeModelTabSchema = z.record(WidgetKeySchema, StaticWidgetModelSchema)\nexport type StaticCustomTypeModelTab = z.infer<typeof StaticCustomTypeModelTabSchema>\n\nexport const DynamicCustomTypeModelTabSchema = z.record(WidgetKeySchema, DynamicWidgetModelSchema)\nexport type DynamicCustomTypeModelTab = z.infer<typeof DynamicCustomTypeModelTabSchema>\n\n// Custom types\nexport const CustomTypeFormatSchema = z.enum([\"page\", \"custom\"])\nexport type CustomTypeFormat = z.infer<typeof CustomTypeFormatSchema>\n\n// Factory to create CustomType schema with configurable section type\nconst createCustomTypeSchema = <\n\tT extends typeof StaticCustomTypeModelTabSchema | typeof DynamicCustomTypeModelTabSchema,\n>(\n\tsectionSchema: T,\n) =>\n\tz\n\t\t.object({\n\t\t\tid: z.string(),\n\t\t\tlabel: z.nullish(z.string()),\n\t\t\trepeatable: z._default(z.boolean(), true),\n\t\t\tjson: z.record(z.string(), sectionSchema),\n\t\t\tstatus: z._default(z.boolean(), true),\n\t\t\tformat: z._default(CustomTypeFormatSchema, \"custom\"),\n\t\t})\n\t\t.check(\n\t\t\tz.superRefine((model, ctx) => {\n\t\t\t\tconst { json } = model\n\n\t\t\t\tconst tabEntries = Object.entries(json)\n\n\t\t\t\t// A map of widget IDs to the tab they belong to\n\t\t\t\t// to check for ID uniqueness across all tabs.\n\t\t\t\tconst existingWidgetKeys = new Map<string, string>()\n\t\t\t\tfor (const [tabID, tab] of tabEntries) {\n\t\t\t\t\tfor (const [widgetID, widget] of Object.entries(tab)) {\n\t\t\t\t\t\tif (widget.type === \"UID\" && widgetID !== \"uid\") {\n\t\t\t\t\t\t\tctx.addIssue({\n\t\t\t\t\t\t\t\tcode: \"custom\",\n\t\t\t\t\t\t\t\tmessage: `The UID widget ID must be set to \"uid\"`,\n\t\t\t\t\t\t\t\tpath: [\"json\", tabID, widgetID],\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst maybeTabID = existingWidgetKeys.get(widgetID)\n\t\t\t\t\t\tif (typeof maybeTabID === \"string\") {\n\t\t\t\t\t\t\tctx.addIssue({\n\t\t\t\t\t\t\t\tcode: \"custom\",\n\t\t\t\t\t\t\t\tmessage: `${widgetID} already exists in the \"${maybeTabID}\" tab`,\n\t\t\t\t\t\t\t\tpath: [\"json\", tabID, widgetID],\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\texistingWidgetKeys.set(widgetID, tabID)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}),\n\t\t)\n\nexport const StaticCustomTypeModelSchema = createCustomTypeSchema(StaticCustomTypeModelTabSchema)\nexport type StaticCustomTypeModel = z.infer<typeof StaticCustomTypeModelSchema>\n\nexport const DynamicCustomTypeModelSchema = createCustomTypeSchema(DynamicCustomTypeModelTabSchema)\nexport type DynamicCustomTypeModel = z.infer<typeof DynamicCustomTypeModelSchema>\n\n/** @deprecated Use DynamicCustomTypeModelSchema instead */\nexport const CustomTypeModelSchema = DynamicCustomTypeModelSchema\n/** @deprecated Use DynamicCustomTypeModel instead */\nexport type CustomTypeModel = DynamicCustomTypeModel\n"],"mappings":";;;;AAMA,MAAa,iCAAiC,EAAE,OAAO,iBAAiB,wBAAwB;AAGhG,MAAa,kCAAkC,EAAE,OAAO,iBAAiB,yBAAyB;AAIlG,MAAa,yBAAyB,EAAE,KAAK,CAAC,QAAQ,SAAS,CAAC;AAIhE,MAAM,0BAGL,kBAEA,EACE,OAAO;CACP,IAAI,EAAE,QAAQ;CACd,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC;CAC5B,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK;CACzC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc;CACzC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK;CACrC,QAAQ,EAAE,SAAS,wBAAwB,SAAS;CACpD,CAAC,CACD,MACA,EAAE,aAAa,OAAO,QAAQ;CAC7B,MAAM,EAAE,SAAS;CAEjB,MAAM,aAAa,OAAO,QAAQ,KAAK;CAIvC,MAAM,qCAAqB,IAAI,KAAqB;AACpD,MAAK,MAAM,CAAC,OAAO,QAAQ,WAC1B,MAAK,MAAM,CAAC,UAAU,WAAW,OAAO,QAAQ,IAAI,EAAE;AACrD,MAAI,OAAO,SAAS,SAAS,aAAa,MACzC,KAAI,SAAS;GACZ,MAAM;GACN,SAAS;GACT,MAAM;IAAC;IAAQ;IAAO;IAAS;GAC/B,CAAC;EAGH,MAAM,aAAa,mBAAmB,IAAI,SAAS;AACnD,MAAI,OAAO,eAAe,UAAU;AACnC,OAAI,SAAS;IACZ,MAAM;IACN,SAAS,GAAG,SAAS,0BAA0B,WAAW;IAC1D,MAAM;KAAC;KAAQ;KAAO;KAAS;IAC/B,CAAC;AACF;;AAGD,qBAAmB,IAAI,UAAU,MAAM;;EAGxC,CACF;AAEH,MAAa,8BAA8B,uBAAuB,+BAA+B;AAGjG,MAAa,+BAA+B,uBAAuB,gCAAgC"}
|
package/dist/model/image.js
CHANGED
|
@@ -12,7 +12,7 @@ const SideConstraintSchema = z.union([
|
|
|
12
12
|
z.pipe(z.literal("auto"), z.transform(() => null)),
|
|
13
13
|
z.pipe(z.literal(""), z.transform(() => null)),
|
|
14
14
|
z.null(),
|
|
15
|
-
z.
|
|
15
|
+
z.int(),
|
|
16
16
|
z.pipe(z.string(), z.transform((s) => parseInt(s.replace("px", ""), 10)))
|
|
17
17
|
]);
|
|
18
18
|
const ImageConstraintSchema = z.object({
|
package/dist/model/image.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.js","names":[],"sources":["../../src/model/image.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\n/**\n * SideConstraint accepts multiple input formats and normalizes to number | null:\n * - Integer values\n * - String integers (e.g., \"100\")\n * - Pixel strings (e.g., \"100px\")\n * - \"auto\" or \"\" → null\n * - null\n */\nexport const SideConstraintSchema: z.ZodMiniType<number | null> = z.union([\n\tz.pipe(\n\t\tz.literal(\"auto\"),\n\t\tz.transform(() => null),\n\t),\n\tz.pipe(\n\t\tz.literal(\"\"),\n\t\tz.transform(() => null),\n\t),\n\tz.null(),\n\tz.
|
|
1
|
+
{"version":3,"file":"image.js","names":[],"sources":["../../src/model/image.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\n/**\n * SideConstraint accepts multiple input formats and normalizes to number | null:\n * - Integer values\n * - String integers (e.g., \"100\")\n * - Pixel strings (e.g., \"100px\")\n * - \"auto\" or \"\" → null\n * - null\n */\nexport const SideConstraintSchema: z.ZodMiniType<number | null> = z.union([\n\tz.pipe(\n\t\tz.literal(\"auto\"),\n\t\tz.transform(() => null),\n\t),\n\tz.pipe(\n\t\tz.literal(\"\"),\n\t\tz.transform(() => null),\n\t),\n\tz.null(),\n\tz.int(),\n\tz.pipe(\n\t\tz.string(),\n\t\tz.transform((s: string) => parseInt(s.replace(\"px\", \"\"), 10)),\n\t),\n])\n\nexport const ImageConstraintSchema = z.object({\n\twidth: z.optional(SideConstraintSchema),\n\theight: z.optional(SideConstraintSchema),\n})\n\nexport type ImageConstraint = z.infer<typeof ImageConstraintSchema>\n\nconst ThumbnailSchema = z.object({\n\tname: z.string(),\n\twidth: z.optional(SideConstraintSchema),\n\theight: z.optional(SideConstraintSchema),\n})\n\nconst ImageConfigSchema = z.object({\n\tlabel: z.nullish(z.string()),\n\tplaceholder: z.optional(z.string()),\n\tconstraint: z.optional(ImageConstraintSchema),\n\tthumbnails: z.optional(z.array(ThumbnailSchema)),\n})\n\nexport const ImageModelSchema = z.object({\n\ttype: z.literal(\"Image\"),\n\tfieldset: z.nullish(z.string()),\n\tconfig: z.optional(ImageConfigSchema),\n})\n\nexport type ImageModel = z.infer<typeof ImageModelSchema>\n"],"mappings":";;;;;;;;;;AAUA,MAAa,uBAAqD,EAAE,MAAM;CACzE,EAAE,KACD,EAAE,QAAQ,OAAO,EACjB,EAAE,gBAAgB,KAAK,CACvB;CACD,EAAE,KACD,EAAE,QAAQ,GAAG,EACb,EAAE,gBAAgB,KAAK,CACvB;CACD,EAAE,MAAM;CACR,EAAE,KAAK;CACP,EAAE,KACD,EAAE,QAAQ,EACV,EAAE,WAAW,MAAc,SAAS,EAAE,QAAQ,MAAM,GAAG,EAAE,GAAG,CAAC,CAC7D;CACD,CAAC;AAEF,MAAa,wBAAwB,EAAE,OAAO;CAC7C,OAAO,EAAE,SAAS,qBAAqB;CACvC,QAAQ,EAAE,SAAS,qBAAqB;CACxC,CAAC;AAIF,MAAM,kBAAkB,EAAE,OAAO;CAChC,MAAM,EAAE,QAAQ;CAChB,OAAO,EAAE,SAAS,qBAAqB;CACvC,QAAQ,EAAE,SAAS,qBAAqB;CACxC,CAAC;AAEF,MAAM,oBAAoB,EAAE,OAAO;CAClC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC;CAC5B,aAAa,EAAE,SAAS,EAAE,QAAQ,CAAC;CACnC,YAAY,EAAE,SAAS,sBAAsB;CAC7C,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;CAChD,CAAC;AAEF,MAAa,mBAAmB,EAAE,OAAO;CACxC,MAAM,EAAE,QAAQ,QAAQ;CACxB,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC;CAC/B,QAAQ,EAAE,SAAS,kBAAkB;CACrC,CAAC"}
|
package/package.json
CHANGED
|
@@ -114,3 +114,19 @@ export function filterMissingSharedSlices<
|
|
|
114
114
|
|
|
115
115
|
return { ...customType, json }
|
|
116
116
|
}
|
|
117
|
+
|
|
118
|
+
export function serializeID(input: string): string {
|
|
119
|
+
const normalized = input
|
|
120
|
+
.trim()
|
|
121
|
+
.normalize("NFD")
|
|
122
|
+
.replace(/\p{M}/gu, "")
|
|
123
|
+
.toLowerCase()
|
|
124
|
+
.replace(/[^a-z0-9]+/g, "_")
|
|
125
|
+
.replace(/^_+|_+$/g, "")
|
|
126
|
+
|
|
127
|
+
if (normalized.length === 0) {
|
|
128
|
+
throw new Error(`Cannot serialize "${input}": result is empty.`)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return normalized
|
|
132
|
+
}
|
|
@@ -106,3 +106,13 @@ export function toLegacy(document: DocumentContent): DocumentLegacy {
|
|
|
106
106
|
|
|
107
107
|
return { ...content, ...types, ...keys }
|
|
108
108
|
}
|
|
109
|
+
|
|
110
|
+
export function serializeUID(input: string): string {
|
|
111
|
+
const nowhitespace = input.replace(/ /g, "-")
|
|
112
|
+
|
|
113
|
+
const normalized = nowhitespace.normalize("NFD").replace(/\p{M}/gu, "")
|
|
114
|
+
|
|
115
|
+
const slug = normalized.replace(/[^\p{L}\d_.-]/gu, "")
|
|
116
|
+
|
|
117
|
+
return slug.toLowerCase()
|
|
118
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function serializeID(input: string): string {
|
|
2
|
+
const tokens = input
|
|
3
|
+
.trim()
|
|
4
|
+
.normalize("NFD")
|
|
5
|
+
.replace(/\p{M}/gu, "")
|
|
6
|
+
.split(/[^A-Za-z0-9]+/)
|
|
7
|
+
.filter(Boolean)
|
|
8
|
+
|
|
9
|
+
if (tokens.length === 0) {
|
|
10
|
+
throw new Error(`Cannot serialize "${input}": result is empty.`)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const [first, ...rest] = tokens
|
|
14
|
+
return (
|
|
15
|
+
first.toLowerCase() +
|
|
16
|
+
rest.map((token) => token.charAt(0).toUpperCase() + token.slice(1).toLowerCase()).join("")
|
|
17
|
+
)
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const MIN_LENGTH = 4
|
|
2
|
+
const MAX_LENGTH = 63
|
|
3
|
+
|
|
4
|
+
export function serializeUID(input: string): string {
|
|
5
|
+
const normalized = input
|
|
6
|
+
.trim()
|
|
7
|
+
.normalize("NFD")
|
|
8
|
+
.replace(/\p{M}/gu, "")
|
|
9
|
+
.toLowerCase()
|
|
10
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
11
|
+
.replace(/^-+|-+$/g, "")
|
|
12
|
+
|
|
13
|
+
const truncated =
|
|
14
|
+
normalized.length > MAX_LENGTH
|
|
15
|
+
? normalized.slice(0, MAX_LENGTH).replace(/-+$/, "")
|
|
16
|
+
: normalized
|
|
17
|
+
|
|
18
|
+
if (truncated.length < MIN_LENGTH) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
`Cannot serialize "${input}" to a repository ID: result must be between ${MIN_LENGTH} and ${MAX_LENGTH} characters.`,
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return truncated
|
|
25
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function serializeID(input: string): string {
|
|
2
|
+
const tokens = input
|
|
3
|
+
.trim()
|
|
4
|
+
.normalize("NFD")
|
|
5
|
+
.replace(/\p{M}/gu, "")
|
|
6
|
+
.split(/[^A-Za-z0-9]+/)
|
|
7
|
+
.filter(Boolean)
|
|
8
|
+
|
|
9
|
+
if (tokens.length === 0) {
|
|
10
|
+
throw new Error(`Cannot serialize "${input}": result is empty.`)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return tokens
|
|
14
|
+
.map((token) => token.charAt(0).toUpperCase() + token.slice(1).toLowerCase())
|
|
15
|
+
.join("")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const serializeVariationID = serializeID
|
package/src/index.ts
CHANGED
|
@@ -106,7 +106,10 @@ export { LegacyContentCtx, getFieldCtx, defaultCtx } from "./content/codec/legac
|
|
|
106
106
|
export * as contentPath from "./helpers/contentPath"
|
|
107
107
|
export * as customTypeModel from "./helpers/customTypeModel"
|
|
108
108
|
export * as documentContent from "./helpers/documentContent"
|
|
109
|
+
export * as fieldModel from "./helpers/fieldModel"
|
|
110
|
+
export * as repository from "./helpers/repository"
|
|
109
111
|
export * as sliceContent from "./helpers/sliceContent"
|
|
112
|
+
export * as sliceModel from "./helpers/sliceModel"
|
|
110
113
|
export * as withDefaultContent from "./helpers/withDefaultContent"
|
|
111
114
|
export * as imageContent from "./helpers/imageContent"
|
|
112
115
|
export {
|
package/src/model/customType.ts
CHANGED
|
@@ -34,13 +34,6 @@ const createCustomTypeSchema = <
|
|
|
34
34
|
const { json } = model
|
|
35
35
|
|
|
36
36
|
const tabEntries = Object.entries(json)
|
|
37
|
-
if (tabEntries.length === 0) {
|
|
38
|
-
ctx.addIssue({
|
|
39
|
-
code: "custom",
|
|
40
|
-
message: `Custom type "${model.id}" must have at least one tab`,
|
|
41
|
-
path: ["json"],
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
37
|
|
|
45
38
|
// A map of widget IDs to the tab they belong to
|
|
46
39
|
// to check for ID uniqueness across all tabs.
|
package/src/model/image.ts
CHANGED