@prismicio/mock 0.3.9 → 0.5.0-alpha.0
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/lib/buildContentRelationshipField.cjs.map +1 -1
- package/dist/lib/buildContentRelationshipField.d.ts +2 -2
- package/dist/lib/buildContentRelationshipField.js.map +1 -1
- package/dist/model/createModelMockFactory.d.ts +32 -2
- package/dist/model/link.cjs +3 -1
- package/dist/model/link.cjs.map +1 -1
- package/dist/model/link.d.ts +18 -3
- package/dist/model/link.js +3 -1
- package/dist/model/link.js.map +1 -1
- package/dist/model/linkToMedia.cjs +3 -1
- package/dist/model/linkToMedia.cjs.map +1 -1
- package/dist/model/linkToMedia.d.ts +19 -2
- package/dist/model/linkToMedia.js +3 -1
- package/dist/model/linkToMedia.js.map +1 -1
- package/dist/value/link.cjs +6 -3
- package/dist/value/link.cjs.map +1 -1
- package/dist/value/link.d.ts +1 -0
- package/dist/value/link.js +6 -3
- package/dist/value/link.js.map +1 -1
- package/dist/value/linkToMedia.cjs +5 -1
- package/dist/value/linkToMedia.cjs.map +1 -1
- package/dist/value/linkToMedia.d.ts +3 -1
- package/dist/value/linkToMedia.js +6 -2
- package/dist/value/linkToMedia.js.map +1 -1
- package/package.json +6 -5
- package/src/lib/buildContentRelationshipField.ts +4 -2
- package/src/model/link.ts +35 -15
- package/src/model/linkToMedia.ts +27 -5
- package/src/value/link.ts +9 -0
- package/src/value/linkToMedia.ts +14 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildContentRelationshipField.cjs","sources":["../../../src/lib/buildContentRelationshipField.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\n\ntype
|
|
1
|
+
{"version":3,"file":"buildContentRelationshipField.cjs","sources":["../../../src/lib/buildContentRelationshipField.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\n\ntype BuildContentRelationshipFieldConfig<\n\tDocument extends prismic.PrismicDocument,\n> = {\n\tdocument: Document;\n};\n\nexport const buildContentRelationshipField = <\n\tDocument extends prismic.PrismicDocument,\n>(\n\tconfig: BuildContentRelationshipFieldConfig<Document>,\n): prismic.ContentRelationshipField<\n\tDocument[\"type\"],\n\tDocument[\"lang\"],\n\tnever,\n\t\"filled\"\n> => {\n\treturn {\n\t\tlink_type: prismic.LinkType.Document,\n\t\tid: config.document.id,\n\t\tuid: config.document.uid || undefined,\n\t\ttype: config.document.type,\n\t\ttags: config.document.tags,\n\t\tlang: config.document.lang,\n\t\turl: config.document.url || undefined,\n\t\tslug: config.document.slugs[0],\n\t\tisBroken: false,\n\t};\n};\n"],"names":["prismic"],"mappings":";;;;;;;;;;;;;;;;;;;;AAQa,MAAA,gCAAgC,CAG5C,WAMG;AACI,SAAA;AAAA,IACN,WAAWA,mBAAQ,SAAS;AAAA,IAC5B,IAAI,OAAO,SAAS;AAAA,IACpB,KAAK,OAAO,SAAS,OAAO;AAAA,IAC5B,MAAM,OAAO,SAAS;AAAA,IACtB,MAAM,OAAO,SAAS;AAAA,IACtB,MAAM,OAAO,SAAS;AAAA,IACtB,KAAK,OAAO,SAAS,OAAO;AAAA,IAC5B,MAAM,OAAO,SAAS,MAAM,CAAC;AAAA,IAC7B,UAAU;AAAA,EAAA;AAEZ;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as prismic from "@prismicio/client";
|
|
2
|
-
type
|
|
2
|
+
type BuildContentRelationshipFieldConfig<Document extends prismic.PrismicDocument> = {
|
|
3
3
|
document: Document;
|
|
4
4
|
};
|
|
5
|
-
export declare const buildContentRelationshipField: <Document extends prismic.PrismicDocument<Record<string, any>, string, string>>(config:
|
|
5
|
+
export declare const buildContentRelationshipField: <Document extends prismic.PrismicDocument<Record<string, any>, string, string>>(config: BuildContentRelationshipFieldConfig<Document>) => prismic.ContentRelationshipField<Document["type"], Document["lang"], never, "filled">;
|
|
6
6
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildContentRelationshipField.js","sources":["../../../src/lib/buildContentRelationshipField.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\n\ntype
|
|
1
|
+
{"version":3,"file":"buildContentRelationshipField.js","sources":["../../../src/lib/buildContentRelationshipField.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\n\ntype BuildContentRelationshipFieldConfig<\n\tDocument extends prismic.PrismicDocument,\n> = {\n\tdocument: Document;\n};\n\nexport const buildContentRelationshipField = <\n\tDocument extends prismic.PrismicDocument,\n>(\n\tconfig: BuildContentRelationshipFieldConfig<Document>,\n): prismic.ContentRelationshipField<\n\tDocument[\"type\"],\n\tDocument[\"lang\"],\n\tnever,\n\t\"filled\"\n> => {\n\treturn {\n\t\tlink_type: prismic.LinkType.Document,\n\t\tid: config.document.id,\n\t\tuid: config.document.uid || undefined,\n\t\ttype: config.document.type,\n\t\ttags: config.document.tags,\n\t\tlang: config.document.lang,\n\t\turl: config.document.url || undefined,\n\t\tslug: config.document.slugs[0],\n\t\tisBroken: false,\n\t};\n};\n"],"names":[],"mappings":";AAQa,MAAA,gCAAgC,CAG5C,WAMG;AACI,SAAA;AAAA,IACN,WAAW,QAAQ,SAAS;AAAA,IAC5B,IAAI,OAAO,SAAS;AAAA,IACpB,KAAK,OAAO,SAAS,OAAO;AAAA,IAC5B,MAAM,OAAO,SAAS;AAAA,IACtB,MAAM,OAAO,SAAS;AAAA,IACtB,MAAM,OAAO,SAAS;AAAA,IACtB,KAAK,OAAO,SAAS,OAAO;AAAA,IAC5B,MAAM,OAAO,SAAS,MAAM,CAAC;AAAA,IAC7B,UAAU;AAAA,EAAA;AAEZ;"}
|
|
@@ -49,8 +49,38 @@ export declare class ModelMockFactory {
|
|
|
49
49
|
image<ThumbnailNames extends string = string>(config?: WithoutFakerConfig<MockImageModelConfig<ThumbnailNames>>): prismic.CustomTypeModelImageField<ThumbnailNames>;
|
|
50
50
|
integration(config?: WithoutFakerConfig<MockIntegrationFieldModelConfig>): prismic.CustomTypeModelIntegrationField;
|
|
51
51
|
keyText(config?: WithoutFakerConfig<MockKeyTextModelConfig>): prismic.CustomTypeModelKeyTextField;
|
|
52
|
-
link<AllowTargetBlank extends boolean = boolean>(config?: WithoutFakerConfig<MockLinkModelConfig<AllowTargetBlank>>):
|
|
53
|
-
|
|
52
|
+
link<AllowTargetBlank extends boolean = boolean>(config?: WithoutFakerConfig<MockLinkModelConfig<AllowTargetBlank>>): prismic.CustomTypeModelLinkField & {
|
|
53
|
+
config: AllowTargetBlank extends true ? {
|
|
54
|
+
allowTargetBlank: true;
|
|
55
|
+
} : {
|
|
56
|
+
allowTargetBlank?: undefined;
|
|
57
|
+
};
|
|
58
|
+
} & {
|
|
59
|
+
config: {
|
|
60
|
+
allowText: true;
|
|
61
|
+
} | {
|
|
62
|
+
allowText?: undefined;
|
|
63
|
+
};
|
|
64
|
+
} & {
|
|
65
|
+
config: {
|
|
66
|
+
repeat: true;
|
|
67
|
+
} | {
|
|
68
|
+
repeat?: undefined;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
linkToMedia(config?: WithoutFakerConfig<MockLinkToMediaModelConfig>): prismic.CustomTypeModelLinkToMediaField & {
|
|
72
|
+
config: {
|
|
73
|
+
allowText: true;
|
|
74
|
+
} | {
|
|
75
|
+
allowText?: undefined;
|
|
76
|
+
};
|
|
77
|
+
} & {
|
|
78
|
+
config: {
|
|
79
|
+
repeat: true;
|
|
80
|
+
} | {
|
|
81
|
+
repeat?: undefined;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
54
84
|
number(config?: WithoutFakerConfig<MockNumberModelConfig>): prismic.CustomTypeModelNumberField;
|
|
55
85
|
richText<WithMultipleBlocks extends boolean = boolean>(config?: WithoutFakerConfig<MockRichTextModelConfig<WithMultipleBlocks>>): WithMultipleBlocks extends true ? prismic.CustomTypeModelRichTextMultiField : prismic.CustomTypeModelRichTextSingleField;
|
|
56
86
|
select<Option extends string, DefaultOption extends Option>(config?: WithoutFakerConfig<MockSelectModelConfig<Option, DefaultOption>>): prismic.CustomTypeModelSelectField<Option, DefaultOption>;
|
package/dist/model/link.cjs
CHANGED
|
@@ -28,7 +28,9 @@ const link = (config) => {
|
|
|
28
28
|
label: index.capitalCase(faker.word()),
|
|
29
29
|
placeholder: index.sentenceCase(faker.words(3)),
|
|
30
30
|
select: null,
|
|
31
|
-
allowTargetBlank: ("allowTargetBlank" in config ? config.allowTargetBlank : faker.boolean()) || void 0
|
|
31
|
+
allowTargetBlank: ("allowTargetBlank" in config ? config.allowTargetBlank : faker.boolean()) || void 0,
|
|
32
|
+
allowText: ("allowText" in config ? config.allowText : faker.boolean()) || void 0,
|
|
33
|
+
repeat: ("repeat" in config ? config.repeat : faker.boolean()) || void 0
|
|
32
34
|
}
|
|
33
35
|
};
|
|
34
36
|
};
|
package/dist/model/link.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.cjs","sources":["../../../src/model/link.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockModelConfig } from \"../types\";\n\
|
|
1
|
+
{"version":3,"file":"link.cjs","sources":["../../../src/model/link.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockModelConfig } from \"../types\";\n\ntype MockLinkModel<\n\tAllowTargetBlank extends boolean = boolean,\n\tAllowText extends boolean = boolean,\n\tRepeat extends boolean = boolean,\n> = prismic.CustomTypeModelLinkField & {\n\tconfig: AllowTargetBlank extends true\n\t\t? { allowTargetBlank: true }\n\t\t: { allowTargetBlank?: undefined };\n} & {\n\tconfig: AllowText extends true\n\t\t? { allowText: true }\n\t\t: { allowText?: undefined };\n} & {\n\tconfig: Repeat extends true ? { repeat: true } : { repeat?: undefined };\n};\n\nexport type MockLinkModelConfig<\n\tAllowTargetBlank extends boolean = boolean,\n\tAllowText extends boolean = boolean,\n\tRepeat extends boolean = boolean,\n> = {\n\tallowTargetBlank?: AllowTargetBlank;\n\tallowText?: AllowText;\n\trepeat?: Repeat;\n} & MockModelConfig;\n\nexport const link = <\n\tAllowTargetBlank extends boolean = boolean,\n\tAllowText extends boolean = boolean,\n\tRepeat extends boolean = boolean,\n>(\n\tconfig: MockLinkModelConfig<AllowTargetBlank, AllowText, Repeat>,\n): MockLinkModel<AllowTargetBlank, AllowText, Repeat> => {\n\tconst faker = config.faker || createFaker(config.seed);\n\n\treturn {\n\t\ttype: prismic.CustomTypeModelFieldType.Link,\n\t\tconfig: {\n\t\t\tlabel: changeCase.capitalCase(faker.word()),\n\t\t\tplaceholder: changeCase.sentenceCase(faker.words(3)),\n\t\t\tselect: null,\n\t\t\tallowTargetBlank:\n\t\t\t\t(\"allowTargetBlank\" in config\n\t\t\t\t\t? config.allowTargetBlank\n\t\t\t\t\t: faker.boolean()) || undefined,\n\t\t\tallowText:\n\t\t\t\t(\"allowText\" in config ? config.allowText : faker.boolean()) ||\n\t\t\t\tundefined,\n\t\t\trepeat:\n\t\t\t\t(\"repeat\" in config ? config.repeat : faker.boolean()) || undefined,\n\t\t},\n\t} as MockLinkModel<AllowTargetBlank, AllowText, Repeat>;\n};\n"],"names":["createFaker","prismic","changeCase.capitalCase","changeCase.sentenceCase"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiCa,MAAA,OAAO,CAKnB,WACuD;AACvD,QAAM,QAAQ,OAAO,SAASA,YAAAA,YAAY,OAAO,IAAI;AAE9C,SAAA;AAAA,IACN,MAAMC,mBAAQ,yBAAyB;AAAA,IACvC,QAAQ;AAAA,MACP,OAAOC,MAAuB,YAAA,MAAM,MAAM;AAAA,MAC1C,aAAaC,MAAAA,aAAwB,MAAM,MAAM,CAAC,CAAC;AAAA,MACnD,QAAQ;AAAA,MACR,mBACE,sBAAsB,SACpB,OAAO,mBACP,MAAM,QAAc,MAAA;AAAA,MACxB,YACE,eAAe,SAAS,OAAO,YAAY,MAAM,QAClD,MAAA;AAAA,MACD,SACE,YAAY,SAAS,OAAO,SAAS,MAAM,QAAc,MAAA;AAAA,IAC3D;AAAA,EAAA;AAEH;;"}
|
package/dist/model/link.d.ts
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import * as prismic from "@prismicio/client";
|
|
2
2
|
import { MockModelConfig } from "../types";
|
|
3
|
-
|
|
3
|
+
type MockLinkModel<AllowTargetBlank extends boolean = boolean, AllowText extends boolean = boolean, Repeat extends boolean = boolean> = prismic.CustomTypeModelLinkField & {
|
|
4
4
|
config: AllowTargetBlank extends true ? {
|
|
5
5
|
allowTargetBlank: true;
|
|
6
6
|
} : {
|
|
7
7
|
allowTargetBlank?: undefined;
|
|
8
8
|
};
|
|
9
|
+
} & {
|
|
10
|
+
config: AllowText extends true ? {
|
|
11
|
+
allowText: true;
|
|
12
|
+
} : {
|
|
13
|
+
allowText?: undefined;
|
|
14
|
+
};
|
|
15
|
+
} & {
|
|
16
|
+
config: Repeat extends true ? {
|
|
17
|
+
repeat: true;
|
|
18
|
+
} : {
|
|
19
|
+
repeat?: undefined;
|
|
20
|
+
};
|
|
9
21
|
};
|
|
10
|
-
export type MockLinkModelConfig<AllowTargetBlank extends boolean = boolean> = {
|
|
22
|
+
export type MockLinkModelConfig<AllowTargetBlank extends boolean = boolean, AllowText extends boolean = boolean, Repeat extends boolean = boolean> = {
|
|
11
23
|
allowTargetBlank?: AllowTargetBlank;
|
|
24
|
+
allowText?: AllowText;
|
|
25
|
+
repeat?: Repeat;
|
|
12
26
|
} & MockModelConfig;
|
|
13
|
-
export declare const link: <AllowTargetBlank extends boolean = boolean>(config: MockLinkModelConfig<AllowTargetBlank>) => MockLinkModel<AllowTargetBlank>;
|
|
27
|
+
export declare const link: <AllowTargetBlank extends boolean = boolean, AllowText extends boolean = boolean, Repeat extends boolean = boolean>(config: MockLinkModelConfig<AllowTargetBlank, AllowText, Repeat>) => MockLinkModel<AllowTargetBlank, AllowText, Repeat>;
|
|
28
|
+
export {};
|
package/dist/model/link.js
CHANGED
|
@@ -9,7 +9,9 @@ const link = (config) => {
|
|
|
9
9
|
label: capitalCase(faker.word()),
|
|
10
10
|
placeholder: sentenceCase(faker.words(3)),
|
|
11
11
|
select: null,
|
|
12
|
-
allowTargetBlank: ("allowTargetBlank" in config ? config.allowTargetBlank : faker.boolean()) || void 0
|
|
12
|
+
allowTargetBlank: ("allowTargetBlank" in config ? config.allowTargetBlank : faker.boolean()) || void 0,
|
|
13
|
+
allowText: ("allowText" in config ? config.allowText : faker.boolean()) || void 0,
|
|
14
|
+
repeat: ("repeat" in config ? config.repeat : faker.boolean()) || void 0
|
|
13
15
|
}
|
|
14
16
|
};
|
|
15
17
|
};
|
package/dist/model/link.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","sources":["../../../src/model/link.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockModelConfig } from \"../types\";\n\
|
|
1
|
+
{"version":3,"file":"link.js","sources":["../../../src/model/link.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockModelConfig } from \"../types\";\n\ntype MockLinkModel<\n\tAllowTargetBlank extends boolean = boolean,\n\tAllowText extends boolean = boolean,\n\tRepeat extends boolean = boolean,\n> = prismic.CustomTypeModelLinkField & {\n\tconfig: AllowTargetBlank extends true\n\t\t? { allowTargetBlank: true }\n\t\t: { allowTargetBlank?: undefined };\n} & {\n\tconfig: AllowText extends true\n\t\t? { allowText: true }\n\t\t: { allowText?: undefined };\n} & {\n\tconfig: Repeat extends true ? { repeat: true } : { repeat?: undefined };\n};\n\nexport type MockLinkModelConfig<\n\tAllowTargetBlank extends boolean = boolean,\n\tAllowText extends boolean = boolean,\n\tRepeat extends boolean = boolean,\n> = {\n\tallowTargetBlank?: AllowTargetBlank;\n\tallowText?: AllowText;\n\trepeat?: Repeat;\n} & MockModelConfig;\n\nexport const link = <\n\tAllowTargetBlank extends boolean = boolean,\n\tAllowText extends boolean = boolean,\n\tRepeat extends boolean = boolean,\n>(\n\tconfig: MockLinkModelConfig<AllowTargetBlank, AllowText, Repeat>,\n): MockLinkModel<AllowTargetBlank, AllowText, Repeat> => {\n\tconst faker = config.faker || createFaker(config.seed);\n\n\treturn {\n\t\ttype: prismic.CustomTypeModelFieldType.Link,\n\t\tconfig: {\n\t\t\tlabel: changeCase.capitalCase(faker.word()),\n\t\t\tplaceholder: changeCase.sentenceCase(faker.words(3)),\n\t\t\tselect: null,\n\t\t\tallowTargetBlank:\n\t\t\t\t(\"allowTargetBlank\" in config\n\t\t\t\t\t? config.allowTargetBlank\n\t\t\t\t\t: faker.boolean()) || undefined,\n\t\t\tallowText:\n\t\t\t\t(\"allowText\" in config ? config.allowText : faker.boolean()) ||\n\t\t\t\tundefined,\n\t\t\trepeat:\n\t\t\t\t(\"repeat\" in config ? config.repeat : faker.boolean()) || undefined,\n\t\t},\n\t} as MockLinkModel<AllowTargetBlank, AllowText, Repeat>;\n};\n"],"names":["changeCase.capitalCase","changeCase.sentenceCase"],"mappings":";;;AAiCa,MAAA,OAAO,CAKnB,WACuD;AACvD,QAAM,QAAQ,OAAO,SAAS,YAAY,OAAO,IAAI;AAE9C,SAAA;AAAA,IACN,MAAM,QAAQ,yBAAyB;AAAA,IACvC,QAAQ;AAAA,MACP,OAAOA,YAAuB,MAAM,MAAM;AAAA,MAC1C,aAAaC,aAAwB,MAAM,MAAM,CAAC,CAAC;AAAA,MACnD,QAAQ;AAAA,MACR,mBACE,sBAAsB,SACpB,OAAO,mBACP,MAAM,QAAc,MAAA;AAAA,MACxB,YACE,eAAe,SAAS,OAAO,YAAY,MAAM,QAClD,MAAA;AAAA,MACD,SACE,YAAY,SAAS,OAAO,SAAS,MAAM,QAAc,MAAA;AAAA,IAC3D;AAAA,EAAA;AAEH;"}
|
|
@@ -27,7 +27,9 @@ const linkToMedia = (config) => {
|
|
|
27
27
|
config: {
|
|
28
28
|
label: index.capitalCase(faker.word()),
|
|
29
29
|
placeholder: index.sentenceCase(faker.words(3)),
|
|
30
|
-
select: prismic__namespace.CustomTypeModelLinkSelectType.Media
|
|
30
|
+
select: prismic__namespace.CustomTypeModelLinkSelectType.Media,
|
|
31
|
+
allowText: ("allowText" in config ? config.allowText : faker.boolean()) || void 0,
|
|
32
|
+
repeat: ("repeat" in config ? config.repeat : faker.boolean()) || void 0
|
|
31
33
|
}
|
|
32
34
|
};
|
|
33
35
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linkToMedia.cjs","sources":["../../../src/model/linkToMedia.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockModelConfig } from \"../types\";\n\nexport type MockLinkToMediaModelConfig = MockModelConfig;\n\nexport const linkToMedia = (\n\tconfig: MockLinkToMediaModelConfig
|
|
1
|
+
{"version":3,"file":"linkToMedia.cjs","sources":["../../../src/model/linkToMedia.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockModelConfig } from \"../types\";\n\ntype MockLinkToMediaModel<\n\tAllowText extends boolean = boolean,\n\tRepeat extends boolean = boolean,\n> = prismic.CustomTypeModelLinkToMediaField & {\n\tconfig: AllowText extends true\n\t\t? { allowText: true }\n\t\t: { allowText?: undefined };\n} & {\n\tconfig: Repeat extends true ? { repeat: true } : { repeat?: undefined };\n};\n\nexport type MockLinkToMediaModelConfig<\n\tAllowText extends boolean = boolean,\n\tRepeat extends boolean = boolean,\n> = MockModelConfig & {\n\tallowText?: AllowText;\n\trepeat?: Repeat;\n};\n\nexport const linkToMedia = <AllowText extends boolean = boolean>(\n\tconfig: MockLinkToMediaModelConfig<AllowText>,\n): MockLinkToMediaModel<AllowText> => {\n\tconst faker = config.faker || createFaker(config.seed);\n\n\treturn {\n\t\ttype: prismic.CustomTypeModelFieldType.Link,\n\t\tconfig: {\n\t\t\tlabel: changeCase.capitalCase(faker.word()),\n\t\t\tplaceholder: changeCase.sentenceCase(faker.words(3)),\n\t\t\tselect: prismic.CustomTypeModelLinkSelectType.Media,\n\t\t\tallowText:\n\t\t\t\t(\"allowText\" in config ? config.allowText : faker.boolean()) ||\n\t\t\t\tundefined,\n\t\t\trepeat:\n\t\t\t\t(\"repeat\" in config ? config.repeat : faker.boolean()) || undefined,\n\t\t},\n\t} as MockLinkToMediaModel<AllowText>;\n};\n"],"names":["createFaker","prismic","changeCase.capitalCase","changeCase.sentenceCase"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0Ba,MAAA,cAAc,CAC1B,WACoC;AACpC,QAAM,QAAQ,OAAO,SAASA,YAAAA,YAAY,OAAO,IAAI;AAE9C,SAAA;AAAA,IACN,MAAMC,mBAAQ,yBAAyB;AAAA,IACvC,QAAQ;AAAA,MACP,OAAOC,MAAuB,YAAA,MAAM,MAAM;AAAA,MAC1C,aAAaC,MAAAA,aAAwB,MAAM,MAAM,CAAC,CAAC;AAAA,MACnD,QAAQF,mBAAQ,8BAA8B;AAAA,MAC9C,YACE,eAAe,SAAS,OAAO,YAAY,MAAM,QAClD,MAAA;AAAA,MACD,SACE,YAAY,SAAS,OAAO,SAAS,MAAM,QAAc,MAAA;AAAA,IAC3D;AAAA,EAAA;AAEH;;"}
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import * as prismic from "@prismicio/client";
|
|
2
2
|
import { MockModelConfig } from "../types";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
type MockLinkToMediaModel<AllowText extends boolean = boolean, Repeat extends boolean = boolean> = prismic.CustomTypeModelLinkToMediaField & {
|
|
4
|
+
config: AllowText extends true ? {
|
|
5
|
+
allowText: true;
|
|
6
|
+
} : {
|
|
7
|
+
allowText?: undefined;
|
|
8
|
+
};
|
|
9
|
+
} & {
|
|
10
|
+
config: Repeat extends true ? {
|
|
11
|
+
repeat: true;
|
|
12
|
+
} : {
|
|
13
|
+
repeat?: undefined;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type MockLinkToMediaModelConfig<AllowText extends boolean = boolean, Repeat extends boolean = boolean> = MockModelConfig & {
|
|
17
|
+
allowText?: AllowText;
|
|
18
|
+
repeat?: Repeat;
|
|
19
|
+
};
|
|
20
|
+
export declare const linkToMedia: <AllowText extends boolean = boolean>(config: MockLinkToMediaModelConfig<AllowText>) => MockLinkToMediaModel<AllowText>;
|
|
21
|
+
export {};
|
|
@@ -8,7 +8,9 @@ const linkToMedia = (config) => {
|
|
|
8
8
|
config: {
|
|
9
9
|
label: capitalCase(faker.word()),
|
|
10
10
|
placeholder: sentenceCase(faker.words(3)),
|
|
11
|
-
select: prismic.CustomTypeModelLinkSelectType.Media
|
|
11
|
+
select: prismic.CustomTypeModelLinkSelectType.Media,
|
|
12
|
+
allowText: ("allowText" in config ? config.allowText : faker.boolean()) || void 0,
|
|
13
|
+
repeat: ("repeat" in config ? config.repeat : faker.boolean()) || void 0
|
|
12
14
|
}
|
|
13
15
|
};
|
|
14
16
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linkToMedia.js","sources":["../../../src/model/linkToMedia.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockModelConfig } from \"../types\";\n\nexport type MockLinkToMediaModelConfig = MockModelConfig;\n\nexport const linkToMedia = (\n\tconfig: MockLinkToMediaModelConfig
|
|
1
|
+
{"version":3,"file":"linkToMedia.js","sources":["../../../src/model/linkToMedia.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockModelConfig } from \"../types\";\n\ntype MockLinkToMediaModel<\n\tAllowText extends boolean = boolean,\n\tRepeat extends boolean = boolean,\n> = prismic.CustomTypeModelLinkToMediaField & {\n\tconfig: AllowText extends true\n\t\t? { allowText: true }\n\t\t: { allowText?: undefined };\n} & {\n\tconfig: Repeat extends true ? { repeat: true } : { repeat?: undefined };\n};\n\nexport type MockLinkToMediaModelConfig<\n\tAllowText extends boolean = boolean,\n\tRepeat extends boolean = boolean,\n> = MockModelConfig & {\n\tallowText?: AllowText;\n\trepeat?: Repeat;\n};\n\nexport const linkToMedia = <AllowText extends boolean = boolean>(\n\tconfig: MockLinkToMediaModelConfig<AllowText>,\n): MockLinkToMediaModel<AllowText> => {\n\tconst faker = config.faker || createFaker(config.seed);\n\n\treturn {\n\t\ttype: prismic.CustomTypeModelFieldType.Link,\n\t\tconfig: {\n\t\t\tlabel: changeCase.capitalCase(faker.word()),\n\t\t\tplaceholder: changeCase.sentenceCase(faker.words(3)),\n\t\t\tselect: prismic.CustomTypeModelLinkSelectType.Media,\n\t\t\tallowText:\n\t\t\t\t(\"allowText\" in config ? config.allowText : faker.boolean()) ||\n\t\t\t\tundefined,\n\t\t\trepeat:\n\t\t\t\t(\"repeat\" in config ? config.repeat : faker.boolean()) || undefined,\n\t\t},\n\t} as MockLinkToMediaModel<AllowText>;\n};\n"],"names":["changeCase.capitalCase","changeCase.sentenceCase"],"mappings":";;;AA0Ba,MAAA,cAAc,CAC1B,WACoC;AACpC,QAAM,QAAQ,OAAO,SAAS,YAAY,OAAO,IAAI;AAE9C,SAAA;AAAA,IACN,MAAM,QAAQ,yBAAyB;AAAA,IACvC,QAAQ;AAAA,MACP,OAAOA,YAAuB,MAAM,MAAM;AAAA,MAC1C,aAAaC,aAAwB,MAAM,MAAM,CAAC,CAAC;AAAA,MACnD,QAAQ,QAAQ,8BAA8B;AAAA,MAC9C,YACE,eAAe,SAAS,OAAO,YAAY,MAAM,QAClD,MAAA;AAAA,MACD,SACE,YAAY,SAAS,OAAO,SAAS,MAAM,QAAc,MAAA;AAAA,IAC3D;AAAA,EAAA;AAEH;"}
|
package/dist/value/link.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const prismic = require("@prismicio/client");
|
|
4
|
+
const index = require('./../_node_modules/change-case/dist/index.cjs');
|
|
4
5
|
const createFaker = require("../lib/createFaker.cjs");
|
|
5
6
|
const contentRelationship = require("./contentRelationship.cjs");
|
|
6
7
|
const linkToMedia = require("./linkToMedia.cjs");
|
|
@@ -23,7 +24,7 @@ function _interopNamespaceDefault(e) {
|
|
|
23
24
|
}
|
|
24
25
|
const prismic__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismic);
|
|
25
26
|
const link = (config) => {
|
|
26
|
-
var _a;
|
|
27
|
+
var _a, _b;
|
|
27
28
|
const faker = config.faker || createFaker.createFaker(config.seed);
|
|
28
29
|
const type = config.type || faker.randomElement([
|
|
29
30
|
prismic__namespace.LinkType.Web,
|
|
@@ -46,7 +47,8 @@ const link = (config) => {
|
|
|
46
47
|
case prismic__namespace.LinkType.Media: {
|
|
47
48
|
return linkToMedia.linkToMedia({
|
|
48
49
|
faker,
|
|
49
|
-
state: config.state
|
|
50
|
+
state: config.state,
|
|
51
|
+
withText: config.withText
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
54
|
case prismic__namespace.LinkType.Web:
|
|
@@ -55,7 +57,8 @@ const link = (config) => {
|
|
|
55
57
|
return {
|
|
56
58
|
link_type: prismic__namespace.LinkType.Web,
|
|
57
59
|
url: faker.url(),
|
|
58
|
-
target: config.withTargetBlank ?? (((_a = model.config) == null ? void 0 : _a.allowTargetBlank) && faker.boolean()) ? "_blank" : void 0
|
|
60
|
+
target: config.withTargetBlank ?? (((_a = model.config) == null ? void 0 : _a.allowTargetBlank) && faker.boolean()) ? "_blank" : void 0,
|
|
61
|
+
text: config.withText ?? (((_b = model.config) == null ? void 0 : _b.allowText) && faker.boolean()) ? index.sentenceCase(faker.words(2)) : void 0
|
|
59
62
|
};
|
|
60
63
|
}
|
|
61
64
|
}
|
package/dist/value/link.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.cjs","sources":["../../../src/value/link.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockValueStateConfig, MockValueConfig } from \"../types\";\n\nimport * as modelGen from \"../model\";\n\nimport { contentRelationship } from \"./contentRelationship\";\nimport { linkToMedia } from \"./linkToMedia\";\n\nexport type MockLinkValueConfig<\n\tLinkType extends\n\t\t(typeof prismic.LinkType)[keyof typeof prismic.LinkType] = (typeof prismic.LinkType)[keyof typeof prismic.LinkType],\n\tModel extends\n\t\tprismic.CustomTypeModelLinkField = prismic.CustomTypeModelLinkField,\n\tState extends prismic.FieldState = prismic.FieldState,\n> = {\n\ttype?: LinkType;\n\twithTargetBlank?: NonNullable<\n\t\tModel[\"config\"]\n\t>[\"allowTargetBlank\"] extends undefined\n\t\t? false\n\t\t: boolean;\n\t/**\n\t * A list of potential documents to which the field can be linked.\n\t */\n\tlinkableDocuments?: LinkType extends typeof prismic.LinkType.Document\n\t\t? prismic.PrismicDocument[]\n\t\t: never;\n} & MockValueConfig<Model> &\n\tMockValueStateConfig<State>;\n\ntype MockLinkValue<\n\tLinkType extends\n\t\t(typeof prismic.LinkType)[keyof typeof prismic.LinkType] = (typeof prismic.LinkType)[keyof typeof prismic.LinkType],\n\tState extends prismic.FieldState = \"filled\",\n> = State extends \"empty\"\n\t? prismic.EmptyLinkField<LinkType>\n\t: LinkType extends typeof prismic.LinkType.Web\n\t\t? prismic.FilledLinkToWebField\n\t\t: LinkType extends typeof prismic.LinkType.Media\n\t\t\t? prismic.FilledLinkToMediaField\n\t\t\t: LinkType extends typeof prismic.LinkType.Document\n\t\t\t\t? prismic.FilledContentRelationshipField\n\t\t\t\t: never;\n\nexport const link = <\n\tLinkType extends\n\t\t(typeof prismic.LinkType)[keyof typeof prismic.LinkType] = (typeof prismic.LinkType)[keyof typeof prismic.LinkType],\n\tModel extends\n\t\tprismic.CustomTypeModelLinkField = prismic.CustomTypeModelLinkField,\n\tState extends prismic.FieldState = \"filled\",\n>(\n\tconfig: MockLinkValueConfig<LinkType, Model, State>,\n): MockLinkValue<LinkType, State> => {\n\tconst faker = config.faker || createFaker(config.seed);\n\n\tconst type =\n\t\tconfig.type ||\n\t\tfaker.randomElement([\n\t\t\tprismic.LinkType.Web,\n\t\t\tprismic.LinkType.Document,\n\t\t\tprismic.LinkType.Media,\n\t\t]);\n\n\tif (config.state === \"empty\") {\n\t\treturn {\n\t\t\tlink_type: type,\n\t\t} as MockLinkValue<LinkType, State>;\n\t} else {\n\t\tswitch (type) {\n\t\t\tcase prismic.LinkType.Document: {\n\t\t\t\treturn contentRelationship({\n\t\t\t\t\tfaker,\n\t\t\t\t\tstate: config.state,\n\t\t\t\t\tlinkableDocuments: config.linkableDocuments,\n\t\t\t\t}) as unknown as MockLinkValue<LinkType, State>;\n\t\t\t}\n\n\t\t\tcase prismic.LinkType.Media: {\n\t\t\t\treturn linkToMedia({\n\t\t\t\t\tfaker,\n\t\t\t\t\tstate: config.state,\n\t\t\t\t}) as MockLinkValue<LinkType, State>;\n\t\t\t}\n\n\t\t\tcase prismic.LinkType.Web:\n\t\t\tdefault: {\n\t\t\t\tconst model = config.model || modelGen.link({ faker });\n\n\t\t\t\treturn {\n\t\t\t\t\tlink_type: prismic.LinkType.Web,\n\t\t\t\t\turl: faker.url(),\n\t\t\t\t\ttarget:\n\t\t\t\t\t\tconfig.withTargetBlank ??\n\t\t\t\t\t\t(model.config?.allowTargetBlank && faker.boolean())\n\t\t\t\t\t\t\t? \"_blank\"\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t} as MockLinkValue<LinkType, State>;\n\t\t\t}\n\t\t}\n\t}\n};\n"],"names":["createFaker","prismic","contentRelationship","linkToMedia","modelGen.link"],"mappings":"
|
|
1
|
+
{"version":3,"file":"link.cjs","sources":["../../../src/value/link.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockValueStateConfig, MockValueConfig } from \"../types\";\n\nimport * as modelGen from \"../model\";\n\nimport { contentRelationship } from \"./contentRelationship\";\nimport { linkToMedia } from \"./linkToMedia\";\n\nexport type MockLinkValueConfig<\n\tLinkType extends\n\t\t(typeof prismic.LinkType)[keyof typeof prismic.LinkType] = (typeof prismic.LinkType)[keyof typeof prismic.LinkType],\n\tModel extends\n\t\tprismic.CustomTypeModelLinkField = prismic.CustomTypeModelLinkField,\n\tState extends prismic.FieldState = prismic.FieldState,\n> = {\n\ttype?: LinkType;\n\twithTargetBlank?: NonNullable<\n\t\tModel[\"config\"]\n\t>[\"allowTargetBlank\"] extends undefined\n\t\t? false\n\t\t: boolean;\n\twithText?: NonNullable<Model[\"config\"]>[\"allowText\"] extends undefined\n\t\t? false\n\t\t: boolean;\n\t/**\n\t * A list of potential documents to which the field can be linked.\n\t */\n\tlinkableDocuments?: LinkType extends typeof prismic.LinkType.Document\n\t\t? prismic.PrismicDocument[]\n\t\t: never;\n} & MockValueConfig<Model> &\n\tMockValueStateConfig<State>;\n\ntype MockLinkValue<\n\tLinkType extends\n\t\t(typeof prismic.LinkType)[keyof typeof prismic.LinkType] = (typeof prismic.LinkType)[keyof typeof prismic.LinkType],\n\tState extends prismic.FieldState = \"filled\",\n> = State extends \"empty\"\n\t? prismic.EmptyLinkField<LinkType>\n\t: LinkType extends typeof prismic.LinkType.Web\n\t\t? prismic.FilledLinkToWebField\n\t\t: LinkType extends typeof prismic.LinkType.Media\n\t\t\t? prismic.FilledLinkToMediaField\n\t\t\t: LinkType extends typeof prismic.LinkType.Document\n\t\t\t\t? prismic.FilledContentRelationshipField\n\t\t\t\t: never;\n\nexport const link = <\n\tLinkType extends\n\t\t(typeof prismic.LinkType)[keyof typeof prismic.LinkType] = (typeof prismic.LinkType)[keyof typeof prismic.LinkType],\n\tModel extends\n\t\tprismic.CustomTypeModelLinkField = prismic.CustomTypeModelLinkField,\n\tState extends prismic.FieldState = \"filled\",\n>(\n\tconfig: MockLinkValueConfig<LinkType, Model, State>,\n): MockLinkValue<LinkType, State> => {\n\tconst faker = config.faker || createFaker(config.seed);\n\n\tconst type =\n\t\tconfig.type ||\n\t\tfaker.randomElement([\n\t\t\tprismic.LinkType.Web,\n\t\t\tprismic.LinkType.Document,\n\t\t\tprismic.LinkType.Media,\n\t\t]);\n\n\tif (config.state === \"empty\") {\n\t\treturn {\n\t\t\tlink_type: type,\n\t\t} as MockLinkValue<LinkType, State>;\n\t} else {\n\t\tswitch (type) {\n\t\t\tcase prismic.LinkType.Document: {\n\t\t\t\treturn contentRelationship({\n\t\t\t\t\tfaker,\n\t\t\t\t\tstate: config.state,\n\t\t\t\t\tlinkableDocuments: config.linkableDocuments,\n\t\t\t\t}) as unknown as MockLinkValue<LinkType, State>;\n\t\t\t}\n\n\t\t\tcase prismic.LinkType.Media: {\n\t\t\t\treturn linkToMedia({\n\t\t\t\t\tfaker,\n\t\t\t\t\tstate: config.state,\n\t\t\t\t\twithText: config.withText,\n\t\t\t\t}) as MockLinkValue<LinkType, State>;\n\t\t\t}\n\n\t\t\tcase prismic.LinkType.Web:\n\t\t\tdefault: {\n\t\t\t\tconst model = config.model || modelGen.link({ faker });\n\n\t\t\t\treturn {\n\t\t\t\t\tlink_type: prismic.LinkType.Web,\n\t\t\t\t\turl: faker.url(),\n\t\t\t\t\ttarget:\n\t\t\t\t\t\tconfig.withTargetBlank ??\n\t\t\t\t\t\t(model.config?.allowTargetBlank && faker.boolean())\n\t\t\t\t\t\t\t? \"_blank\"\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\ttext:\n\t\t\t\t\t\tconfig.withText ?? (model.config?.allowText && faker.boolean())\n\t\t\t\t\t\t\t? changeCase.sentenceCase(faker.words(2))\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t} as MockLinkValue<LinkType, State>;\n\t\t\t}\n\t\t}\n\t}\n};\n"],"names":["createFaker","prismic","contentRelationship","linkToMedia","modelGen.link","changeCase.sentenceCase"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAmDa,MAAA,OAAO,CAOnB,WACmC;;AACnC,QAAM,QAAQ,OAAO,SAASA,YAAAA,YAAY,OAAO,IAAI;AAErD,QAAM,OACL,OAAO,QACP,MAAM,cAAc;AAAA,IACnBC,mBAAQ,SAAS;AAAA,IACjBA,mBAAQ,SAAS;AAAA,IACjBA,mBAAQ,SAAS;AAAA,EAAA,CACjB;AAEE,MAAA,OAAO,UAAU,SAAS;AACtB,WAAA;AAAA,MACN,WAAW;AAAA,IAAA;AAAA,SAEN;AACN,YAAQ,MAAM;AAAA,MACb,KAAKA,mBAAQ,SAAS,UAAU;AAC/B,eAAOC,wCAAoB;AAAA,UAC1B;AAAA,UACA,OAAO,OAAO;AAAA,UACd,mBAAmB,OAAO;AAAA,QAAA,CAC1B;AAAA,MACF;AAAA,MAEA,KAAKD,mBAAQ,SAAS,OAAO;AAC5B,eAAOE,wBAAY;AAAA,UAClB;AAAA,UACA,OAAO,OAAO;AAAA,UACd,UAAU,OAAO;AAAA,QAAA,CACjB;AAAA,MACF;AAAA,MAEA,KAAKF,mBAAQ,SAAS;AAAA,MACtB,SAAS;AACR,cAAM,QAAQ,OAAO,SAASG,OAAAA,KAAc,EAAE,OAAO;AAE9C,eAAA;AAAA,UACN,WAAWH,mBAAQ,SAAS;AAAA,UAC5B,KAAK,MAAM,IAAK;AAAA,UAChB,QACC,OAAO,sBACN,WAAM,WAAN,mBAAc,qBAAoB,MAAM,QAAO,KAC7C,WACA;AAAA,UACJ,MACC,OAAO,eAAa,WAAM,WAAN,mBAAc,cAAa,MAAM,aAClDI,MAAwB,aAAA,MAAM,MAAM,CAAC,CAAC,IACtC;AAAA,QAAA;AAAA,MAEN;AAAA,IACD;AAAA,EACD;AACD;;"}
|
package/dist/value/link.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { MockValueStateConfig, MockValueConfig } from "../types";
|
|
|
3
3
|
export type MockLinkValueConfig<LinkType extends (typeof prismic.LinkType)[keyof typeof prismic.LinkType] = (typeof prismic.LinkType)[keyof typeof prismic.LinkType], Model extends prismic.CustomTypeModelLinkField = prismic.CustomTypeModelLinkField, State extends prismic.FieldState = prismic.FieldState> = {
|
|
4
4
|
type?: LinkType;
|
|
5
5
|
withTargetBlank?: NonNullable<Model["config"]>["allowTargetBlank"] extends undefined ? false : boolean;
|
|
6
|
+
withText?: NonNullable<Model["config"]>["allowText"] extends undefined ? false : boolean;
|
|
6
7
|
/**
|
|
7
8
|
* A list of potential documents to which the field can be linked.
|
|
8
9
|
*/
|
package/dist/value/link.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as prismic from "@prismicio/client";
|
|
2
|
+
import { sentenceCase } from './../_node_modules/change-case/dist/index.js';
|
|
2
3
|
import { createFaker } from "../lib/createFaker.js";
|
|
3
4
|
import { contentRelationship } from "./contentRelationship.js";
|
|
4
5
|
import { linkToMedia } from "./linkToMedia.js";
|
|
5
6
|
import { link as link$1 } from "../model/link.js";
|
|
6
7
|
const link = (config) => {
|
|
7
|
-
var _a;
|
|
8
|
+
var _a, _b;
|
|
8
9
|
const faker = config.faker || createFaker(config.seed);
|
|
9
10
|
const type = config.type || faker.randomElement([
|
|
10
11
|
prismic.LinkType.Web,
|
|
@@ -27,7 +28,8 @@ const link = (config) => {
|
|
|
27
28
|
case prismic.LinkType.Media: {
|
|
28
29
|
return linkToMedia({
|
|
29
30
|
faker,
|
|
30
|
-
state: config.state
|
|
31
|
+
state: config.state,
|
|
32
|
+
withText: config.withText
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
35
|
case prismic.LinkType.Web:
|
|
@@ -36,7 +38,8 @@ const link = (config) => {
|
|
|
36
38
|
return {
|
|
37
39
|
link_type: prismic.LinkType.Web,
|
|
38
40
|
url: faker.url(),
|
|
39
|
-
target: config.withTargetBlank ?? (((_a = model.config) == null ? void 0 : _a.allowTargetBlank) && faker.boolean()) ? "_blank" : void 0
|
|
41
|
+
target: config.withTargetBlank ?? (((_a = model.config) == null ? void 0 : _a.allowTargetBlank) && faker.boolean()) ? "_blank" : void 0,
|
|
42
|
+
text: config.withText ?? (((_b = model.config) == null ? void 0 : _b.allowText) && faker.boolean()) ? sentenceCase(faker.words(2)) : void 0
|
|
40
43
|
};
|
|
41
44
|
}
|
|
42
45
|
}
|
package/dist/value/link.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","sources":["../../../src/value/link.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockValueStateConfig, MockValueConfig } from \"../types\";\n\nimport * as modelGen from \"../model\";\n\nimport { contentRelationship } from \"./contentRelationship\";\nimport { linkToMedia } from \"./linkToMedia\";\n\nexport type MockLinkValueConfig<\n\tLinkType extends\n\t\t(typeof prismic.LinkType)[keyof typeof prismic.LinkType] = (typeof prismic.LinkType)[keyof typeof prismic.LinkType],\n\tModel extends\n\t\tprismic.CustomTypeModelLinkField = prismic.CustomTypeModelLinkField,\n\tState extends prismic.FieldState = prismic.FieldState,\n> = {\n\ttype?: LinkType;\n\twithTargetBlank?: NonNullable<\n\t\tModel[\"config\"]\n\t>[\"allowTargetBlank\"] extends undefined\n\t\t? false\n\t\t: boolean;\n\t/**\n\t * A list of potential documents to which the field can be linked.\n\t */\n\tlinkableDocuments?: LinkType extends typeof prismic.LinkType.Document\n\t\t? prismic.PrismicDocument[]\n\t\t: never;\n} & MockValueConfig<Model> &\n\tMockValueStateConfig<State>;\n\ntype MockLinkValue<\n\tLinkType extends\n\t\t(typeof prismic.LinkType)[keyof typeof prismic.LinkType] = (typeof prismic.LinkType)[keyof typeof prismic.LinkType],\n\tState extends prismic.FieldState = \"filled\",\n> = State extends \"empty\"\n\t? prismic.EmptyLinkField<LinkType>\n\t: LinkType extends typeof prismic.LinkType.Web\n\t\t? prismic.FilledLinkToWebField\n\t\t: LinkType extends typeof prismic.LinkType.Media\n\t\t\t? prismic.FilledLinkToMediaField\n\t\t\t: LinkType extends typeof prismic.LinkType.Document\n\t\t\t\t? prismic.FilledContentRelationshipField\n\t\t\t\t: never;\n\nexport const link = <\n\tLinkType extends\n\t\t(typeof prismic.LinkType)[keyof typeof prismic.LinkType] = (typeof prismic.LinkType)[keyof typeof prismic.LinkType],\n\tModel extends\n\t\tprismic.CustomTypeModelLinkField = prismic.CustomTypeModelLinkField,\n\tState extends prismic.FieldState = \"filled\",\n>(\n\tconfig: MockLinkValueConfig<LinkType, Model, State>,\n): MockLinkValue<LinkType, State> => {\n\tconst faker = config.faker || createFaker(config.seed);\n\n\tconst type =\n\t\tconfig.type ||\n\t\tfaker.randomElement([\n\t\t\tprismic.LinkType.Web,\n\t\t\tprismic.LinkType.Document,\n\t\t\tprismic.LinkType.Media,\n\t\t]);\n\n\tif (config.state === \"empty\") {\n\t\treturn {\n\t\t\tlink_type: type,\n\t\t} as MockLinkValue<LinkType, State>;\n\t} else {\n\t\tswitch (type) {\n\t\t\tcase prismic.LinkType.Document: {\n\t\t\t\treturn contentRelationship({\n\t\t\t\t\tfaker,\n\t\t\t\t\tstate: config.state,\n\t\t\t\t\tlinkableDocuments: config.linkableDocuments,\n\t\t\t\t}) as unknown as MockLinkValue<LinkType, State>;\n\t\t\t}\n\n\t\t\tcase prismic.LinkType.Media: {\n\t\t\t\treturn linkToMedia({\n\t\t\t\t\tfaker,\n\t\t\t\t\tstate: config.state,\n\t\t\t\t}) as MockLinkValue<LinkType, State>;\n\t\t\t}\n\n\t\t\tcase prismic.LinkType.Web:\n\t\t\tdefault: {\n\t\t\t\tconst model = config.model || modelGen.link({ faker });\n\n\t\t\t\treturn {\n\t\t\t\t\tlink_type: prismic.LinkType.Web,\n\t\t\t\t\turl: faker.url(),\n\t\t\t\t\ttarget:\n\t\t\t\t\t\tconfig.withTargetBlank ??\n\t\t\t\t\t\t(model.config?.allowTargetBlank && faker.boolean())\n\t\t\t\t\t\t\t? \"_blank\"\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t} as MockLinkValue<LinkType, State>;\n\t\t\t}\n\t\t}\n\t}\n};\n"],"names":["modelGen.link"],"mappings":"
|
|
1
|
+
{"version":3,"file":"link.js","sources":["../../../src/value/link.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockValueStateConfig, MockValueConfig } from \"../types\";\n\nimport * as modelGen from \"../model\";\n\nimport { contentRelationship } from \"./contentRelationship\";\nimport { linkToMedia } from \"./linkToMedia\";\n\nexport type MockLinkValueConfig<\n\tLinkType extends\n\t\t(typeof prismic.LinkType)[keyof typeof prismic.LinkType] = (typeof prismic.LinkType)[keyof typeof prismic.LinkType],\n\tModel extends\n\t\tprismic.CustomTypeModelLinkField = prismic.CustomTypeModelLinkField,\n\tState extends prismic.FieldState = prismic.FieldState,\n> = {\n\ttype?: LinkType;\n\twithTargetBlank?: NonNullable<\n\t\tModel[\"config\"]\n\t>[\"allowTargetBlank\"] extends undefined\n\t\t? false\n\t\t: boolean;\n\twithText?: NonNullable<Model[\"config\"]>[\"allowText\"] extends undefined\n\t\t? false\n\t\t: boolean;\n\t/**\n\t * A list of potential documents to which the field can be linked.\n\t */\n\tlinkableDocuments?: LinkType extends typeof prismic.LinkType.Document\n\t\t? prismic.PrismicDocument[]\n\t\t: never;\n} & MockValueConfig<Model> &\n\tMockValueStateConfig<State>;\n\ntype MockLinkValue<\n\tLinkType extends\n\t\t(typeof prismic.LinkType)[keyof typeof prismic.LinkType] = (typeof prismic.LinkType)[keyof typeof prismic.LinkType],\n\tState extends prismic.FieldState = \"filled\",\n> = State extends \"empty\"\n\t? prismic.EmptyLinkField<LinkType>\n\t: LinkType extends typeof prismic.LinkType.Web\n\t\t? prismic.FilledLinkToWebField\n\t\t: LinkType extends typeof prismic.LinkType.Media\n\t\t\t? prismic.FilledLinkToMediaField\n\t\t\t: LinkType extends typeof prismic.LinkType.Document\n\t\t\t\t? prismic.FilledContentRelationshipField\n\t\t\t\t: never;\n\nexport const link = <\n\tLinkType extends\n\t\t(typeof prismic.LinkType)[keyof typeof prismic.LinkType] = (typeof prismic.LinkType)[keyof typeof prismic.LinkType],\n\tModel extends\n\t\tprismic.CustomTypeModelLinkField = prismic.CustomTypeModelLinkField,\n\tState extends prismic.FieldState = \"filled\",\n>(\n\tconfig: MockLinkValueConfig<LinkType, Model, State>,\n): MockLinkValue<LinkType, State> => {\n\tconst faker = config.faker || createFaker(config.seed);\n\n\tconst type =\n\t\tconfig.type ||\n\t\tfaker.randomElement([\n\t\t\tprismic.LinkType.Web,\n\t\t\tprismic.LinkType.Document,\n\t\t\tprismic.LinkType.Media,\n\t\t]);\n\n\tif (config.state === \"empty\") {\n\t\treturn {\n\t\t\tlink_type: type,\n\t\t} as MockLinkValue<LinkType, State>;\n\t} else {\n\t\tswitch (type) {\n\t\t\tcase prismic.LinkType.Document: {\n\t\t\t\treturn contentRelationship({\n\t\t\t\t\tfaker,\n\t\t\t\t\tstate: config.state,\n\t\t\t\t\tlinkableDocuments: config.linkableDocuments,\n\t\t\t\t}) as unknown as MockLinkValue<LinkType, State>;\n\t\t\t}\n\n\t\t\tcase prismic.LinkType.Media: {\n\t\t\t\treturn linkToMedia({\n\t\t\t\t\tfaker,\n\t\t\t\t\tstate: config.state,\n\t\t\t\t\twithText: config.withText,\n\t\t\t\t}) as MockLinkValue<LinkType, State>;\n\t\t\t}\n\n\t\t\tcase prismic.LinkType.Web:\n\t\t\tdefault: {\n\t\t\t\tconst model = config.model || modelGen.link({ faker });\n\n\t\t\t\treturn {\n\t\t\t\t\tlink_type: prismic.LinkType.Web,\n\t\t\t\t\turl: faker.url(),\n\t\t\t\t\ttarget:\n\t\t\t\t\t\tconfig.withTargetBlank ??\n\t\t\t\t\t\t(model.config?.allowTargetBlank && faker.boolean())\n\t\t\t\t\t\t\t? \"_blank\"\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\ttext:\n\t\t\t\t\t\tconfig.withText ?? (model.config?.allowText && faker.boolean())\n\t\t\t\t\t\t\t? changeCase.sentenceCase(faker.words(2))\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t} as MockLinkValue<LinkType, State>;\n\t\t\t}\n\t\t}\n\t}\n};\n"],"names":["modelGen.link","changeCase.sentenceCase"],"mappings":";;;;;;AAmDa,MAAA,OAAO,CAOnB,WACmC;;AACnC,QAAM,QAAQ,OAAO,SAAS,YAAY,OAAO,IAAI;AAErD,QAAM,OACL,OAAO,QACP,MAAM,cAAc;AAAA,IACnB,QAAQ,SAAS;AAAA,IACjB,QAAQ,SAAS;AAAA,IACjB,QAAQ,SAAS;AAAA,EAAA,CACjB;AAEE,MAAA,OAAO,UAAU,SAAS;AACtB,WAAA;AAAA,MACN,WAAW;AAAA,IAAA;AAAA,SAEN;AACN,YAAQ,MAAM;AAAA,MACb,KAAK,QAAQ,SAAS,UAAU;AAC/B,eAAO,oBAAoB;AAAA,UAC1B;AAAA,UACA,OAAO,OAAO;AAAA,UACd,mBAAmB,OAAO;AAAA,QAAA,CAC1B;AAAA,MACF;AAAA,MAEA,KAAK,QAAQ,SAAS,OAAO;AAC5B,eAAO,YAAY;AAAA,UAClB;AAAA,UACA,OAAO,OAAO;AAAA,UACd,UAAU,OAAO;AAAA,QAAA,CACjB;AAAA,MACF;AAAA,MAEA,KAAK,QAAQ,SAAS;AAAA,MACtB,SAAS;AACR,cAAM,QAAQ,OAAO,SAASA,OAAc,EAAE,OAAO;AAE9C,eAAA;AAAA,UACN,WAAW,QAAQ,SAAS;AAAA,UAC5B,KAAK,MAAM,IAAK;AAAA,UAChB,QACC,OAAO,sBACN,WAAM,WAAN,mBAAc,qBAAoB,MAAM,QAAO,KAC7C,WACA;AAAA,UACJ,MACC,OAAO,eAAa,WAAM,WAAN,mBAAc,cAAa,MAAM,aAClDC,aAAwB,MAAM,MAAM,CAAC,CAAC,IACtC;AAAA,QAAA;AAAA,MAEN;AAAA,IACD;AAAA,EACD;AACD;"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const prismic = require("@prismicio/client");
|
|
4
4
|
const index = require('./../_node_modules/change-case/dist/index.cjs');
|
|
5
5
|
const createFaker = require("../lib/createFaker.cjs");
|
|
6
|
+
const link = require("../model/link.cjs");
|
|
6
7
|
function _interopNamespaceDefault(e) {
|
|
7
8
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
9
|
if (e) {
|
|
@@ -21,12 +22,14 @@ function _interopNamespaceDefault(e) {
|
|
|
21
22
|
}
|
|
22
23
|
const prismic__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismic);
|
|
23
24
|
const linkToMedia = (config) => {
|
|
25
|
+
var _a;
|
|
24
26
|
const faker = config.faker || createFaker.createFaker(config.seed);
|
|
25
27
|
if (config.state === "empty") {
|
|
26
28
|
return {
|
|
27
29
|
link_type: prismic__namespace.LinkType.Media
|
|
28
30
|
};
|
|
29
31
|
} else {
|
|
32
|
+
const model = config.model || link.link({ faker });
|
|
30
33
|
return {
|
|
31
34
|
link_type: prismic__namespace.LinkType.Media,
|
|
32
35
|
id: faker.hash(11),
|
|
@@ -35,7 +38,8 @@ const linkToMedia = (config) => {
|
|
|
35
38
|
url: faker.url(),
|
|
36
39
|
size: faker.range(500, 3e3).toString(),
|
|
37
40
|
height: faker.range(500, 3e3).toString(),
|
|
38
|
-
width: faker.range(500, 3e3).toString()
|
|
41
|
+
width: faker.range(500, 3e3).toString(),
|
|
42
|
+
text: config.withText ?? (((_a = model.config) == null ? void 0 : _a.allowText) && faker.boolean()) ? index.sentenceCase(faker.words(2)) : void 0
|
|
39
43
|
};
|
|
40
44
|
}
|
|
41
45
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linkToMedia.cjs","sources":["../../../src/value/linkToMedia.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockValueStateConfig, MockValueConfig } from \"../types\";\n\nexport type MockLinkToMediaValueConfig<\n\tModel extends\n\t\tprismic.CustomTypeModelLinkToMediaField = prismic.CustomTypeModelLinkToMediaField,\n\tState extends prismic.FieldState = prismic.FieldState,\n> =
|
|
1
|
+
{"version":3,"file":"linkToMedia.cjs","sources":["../../../src/value/linkToMedia.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockValueStateConfig, MockValueConfig } from \"../types\";\n\nimport * as modelGen from \"../model\";\n\nexport type MockLinkToMediaValueConfig<\n\tModel extends\n\t\tprismic.CustomTypeModelLinkToMediaField = prismic.CustomTypeModelLinkToMediaField,\n\tState extends prismic.FieldState = prismic.FieldState,\n> = {\n\twithText?: NonNullable<Model[\"config\"]>[\"allowText\"] extends undefined\n\t\t? false\n\t\t: boolean;\n} & MockValueConfig<Model> &\n\tMockValueStateConfig<State>;\n\ntype MockLinkToMediaValue<\n\tState extends prismic.FieldState = prismic.FieldState,\n> = prismic.LinkToMediaField<State>;\n\nexport const linkToMedia = <\n\tModel extends\n\t\tprismic.CustomTypeModelLinkToMediaField = prismic.CustomTypeModelLinkToMediaField,\n\tState extends prismic.FieldState = \"filled\",\n>(\n\tconfig: MockLinkToMediaValueConfig<Model, State>,\n): MockLinkToMediaValue<State> => {\n\tconst faker = config.faker || createFaker(config.seed);\n\n\tif (config.state === \"empty\") {\n\t\treturn {\n\t\t\tlink_type: prismic.LinkType.Media,\n\t\t} as MockLinkToMediaValue<State>;\n\t} else {\n\t\tconst model = config.model || modelGen.link({ faker });\n\n\t\treturn {\n\t\t\tlink_type: prismic.LinkType.Media,\n\t\t\tid: faker.hash(11),\n\t\t\tname: `${changeCase.snakeCase(faker.words(faker.range(1, 2)))}.example`,\n\t\t\tkind: changeCase.snakeCase(faker.word()),\n\t\t\turl: faker.url(),\n\t\t\tsize: faker.range(500, 3000).toString(),\n\t\t\theight: faker.range(500, 3000).toString(),\n\t\t\twidth: faker.range(500, 3000).toString(),\n\t\t\ttext:\n\t\t\t\tconfig.withText ?? (model.config?.allowText && faker.boolean())\n\t\t\t\t\t? changeCase.sentenceCase(faker.words(2))\n\t\t\t\t\t: undefined,\n\t\t} as MockLinkToMediaValue<State>;\n\t}\n};\n"],"names":["createFaker","prismic","modelGen.link","changeCase.snakeCase","changeCase.sentenceCase"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwBa,MAAA,cAAc,CAK1B,WACgC;;AAChC,QAAM,QAAQ,OAAO,SAASA,YAAAA,YAAY,OAAO,IAAI;AAEjD,MAAA,OAAO,UAAU,SAAS;AACtB,WAAA;AAAA,MACN,WAAWC,mBAAQ,SAAS;AAAA,IAAA;AAAA,SAEvB;AACN,UAAM,QAAQ,OAAO,SAASC,KAAAA,KAAc,EAAE,OAAO;AAE9C,WAAA;AAAA,MACN,WAAWD,mBAAQ,SAAS;AAAA,MAC5B,IAAI,MAAM,KAAK,EAAE;AAAA,MACjB,MAAM,GAAGE,gBAAqB,MAAM,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;AAAA,MAC7D,MAAMA,MAAqB,UAAA,MAAM,MAAM;AAAA,MACvC,KAAK,MAAM,IAAK;AAAA,MAChB,MAAM,MAAM,MAAM,KAAK,GAAI,EAAE,SAAU;AAAA,MACvC,QAAQ,MAAM,MAAM,KAAK,GAAI,EAAE,SAAU;AAAA,MACzC,OAAO,MAAM,MAAM,KAAK,GAAI,EAAE,SAAU;AAAA,MACxC,MACC,OAAO,eAAa,WAAM,WAAN,mBAAc,cAAa,MAAM,aAClDC,MAAwB,aAAA,MAAM,MAAM,CAAC,CAAC,IACtC;AAAA,IAAA;AAAA,EAEN;AACD;;"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as prismic from "@prismicio/client";
|
|
2
2
|
import { MockValueStateConfig, MockValueConfig } from "../types";
|
|
3
|
-
export type MockLinkToMediaValueConfig<Model extends prismic.CustomTypeModelLinkToMediaField = prismic.CustomTypeModelLinkToMediaField, State extends prismic.FieldState = prismic.FieldState> =
|
|
3
|
+
export type MockLinkToMediaValueConfig<Model extends prismic.CustomTypeModelLinkToMediaField = prismic.CustomTypeModelLinkToMediaField, State extends prismic.FieldState = prismic.FieldState> = {
|
|
4
|
+
withText?: NonNullable<Model["config"]>["allowText"] extends undefined ? false : boolean;
|
|
5
|
+
} & MockValueConfig<Model> & MockValueStateConfig<State>;
|
|
4
6
|
type MockLinkToMediaValue<State extends prismic.FieldState = prismic.FieldState> = prismic.LinkToMediaField<State>;
|
|
5
7
|
export declare const linkToMedia: <Model extends prismic.CustomTypeModelLinkToMediaField = prismic.CustomTypeModelLinkToMediaField, State extends prismic.FieldState = "filled">(config: MockLinkToMediaValueConfig<Model, State>) => MockLinkToMediaValue<State>;
|
|
6
8
|
export {};
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import * as prismic from "@prismicio/client";
|
|
2
|
-
import { snakeCase } from './../_node_modules/change-case/dist/index.js';
|
|
2
|
+
import { snakeCase, sentenceCase } from './../_node_modules/change-case/dist/index.js';
|
|
3
3
|
import { createFaker } from "../lib/createFaker.js";
|
|
4
|
+
import { link } from "../model/link.js";
|
|
4
5
|
const linkToMedia = (config) => {
|
|
6
|
+
var _a;
|
|
5
7
|
const faker = config.faker || createFaker(config.seed);
|
|
6
8
|
if (config.state === "empty") {
|
|
7
9
|
return {
|
|
8
10
|
link_type: prismic.LinkType.Media
|
|
9
11
|
};
|
|
10
12
|
} else {
|
|
13
|
+
const model = config.model || link({ faker });
|
|
11
14
|
return {
|
|
12
15
|
link_type: prismic.LinkType.Media,
|
|
13
16
|
id: faker.hash(11),
|
|
@@ -16,7 +19,8 @@ const linkToMedia = (config) => {
|
|
|
16
19
|
url: faker.url(),
|
|
17
20
|
size: faker.range(500, 3e3).toString(),
|
|
18
21
|
height: faker.range(500, 3e3).toString(),
|
|
19
|
-
width: faker.range(500, 3e3).toString()
|
|
22
|
+
width: faker.range(500, 3e3).toString(),
|
|
23
|
+
text: config.withText ?? (((_a = model.config) == null ? void 0 : _a.allowText) && faker.boolean()) ? sentenceCase(faker.words(2)) : void 0
|
|
20
24
|
};
|
|
21
25
|
}
|
|
22
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linkToMedia.js","sources":["../../../src/value/linkToMedia.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockValueStateConfig, MockValueConfig } from \"../types\";\n\nexport type MockLinkToMediaValueConfig<\n\tModel extends\n\t\tprismic.CustomTypeModelLinkToMediaField = prismic.CustomTypeModelLinkToMediaField,\n\tState extends prismic.FieldState = prismic.FieldState,\n> =
|
|
1
|
+
{"version":3,"file":"linkToMedia.js","sources":["../../../src/value/linkToMedia.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockValueStateConfig, MockValueConfig } from \"../types\";\n\nimport * as modelGen from \"../model\";\n\nexport type MockLinkToMediaValueConfig<\n\tModel extends\n\t\tprismic.CustomTypeModelLinkToMediaField = prismic.CustomTypeModelLinkToMediaField,\n\tState extends prismic.FieldState = prismic.FieldState,\n> = {\n\twithText?: NonNullable<Model[\"config\"]>[\"allowText\"] extends undefined\n\t\t? false\n\t\t: boolean;\n} & MockValueConfig<Model> &\n\tMockValueStateConfig<State>;\n\ntype MockLinkToMediaValue<\n\tState extends prismic.FieldState = prismic.FieldState,\n> = prismic.LinkToMediaField<State>;\n\nexport const linkToMedia = <\n\tModel extends\n\t\tprismic.CustomTypeModelLinkToMediaField = prismic.CustomTypeModelLinkToMediaField,\n\tState extends prismic.FieldState = \"filled\",\n>(\n\tconfig: MockLinkToMediaValueConfig<Model, State>,\n): MockLinkToMediaValue<State> => {\n\tconst faker = config.faker || createFaker(config.seed);\n\n\tif (config.state === \"empty\") {\n\t\treturn {\n\t\t\tlink_type: prismic.LinkType.Media,\n\t\t} as MockLinkToMediaValue<State>;\n\t} else {\n\t\tconst model = config.model || modelGen.link({ faker });\n\n\t\treturn {\n\t\t\tlink_type: prismic.LinkType.Media,\n\t\t\tid: faker.hash(11),\n\t\t\tname: `${changeCase.snakeCase(faker.words(faker.range(1, 2)))}.example`,\n\t\t\tkind: changeCase.snakeCase(faker.word()),\n\t\t\turl: faker.url(),\n\t\t\tsize: faker.range(500, 3000).toString(),\n\t\t\theight: faker.range(500, 3000).toString(),\n\t\t\twidth: faker.range(500, 3000).toString(),\n\t\t\ttext:\n\t\t\t\tconfig.withText ?? (model.config?.allowText && faker.boolean())\n\t\t\t\t\t? changeCase.sentenceCase(faker.words(2))\n\t\t\t\t\t: undefined,\n\t\t} as MockLinkToMediaValue<State>;\n\t}\n};\n"],"names":["modelGen.link","changeCase.snakeCase","changeCase.sentenceCase"],"mappings":";;;;AAwBa,MAAA,cAAc,CAK1B,WACgC;;AAChC,QAAM,QAAQ,OAAO,SAAS,YAAY,OAAO,IAAI;AAEjD,MAAA,OAAO,UAAU,SAAS;AACtB,WAAA;AAAA,MACN,WAAW,QAAQ,SAAS;AAAA,IAAA;AAAA,SAEvB;AACN,UAAM,QAAQ,OAAO,SAASA,KAAc,EAAE,OAAO;AAE9C,WAAA;AAAA,MACN,WAAW,QAAQ,SAAS;AAAA,MAC5B,IAAI,MAAM,KAAK,EAAE;AAAA,MACjB,MAAM,GAAGC,UAAqB,MAAM,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;AAAA,MAC7D,MAAMA,UAAqB,MAAM,MAAM;AAAA,MACvC,KAAK,MAAM,IAAK;AAAA,MAChB,MAAM,MAAM,MAAM,KAAK,GAAI,EAAE,SAAU;AAAA,MACvC,QAAQ,MAAM,MAAM,KAAK,GAAI,EAAE,SAAU;AAAA,MACzC,OAAO,MAAM,MAAM,KAAK,GAAI,EAAE,SAAU;AAAA,MACxC,MACC,OAAO,eAAa,WAAM,WAAN,mBAAc,cAAa,MAAM,aAClDC,aAAwB,MAAM,MAAM,CAAC,CAAC,IACtC;AAAA,IAAA;AAAA,EAEN;AACD;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/mock",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-alpha.0",
|
|
4
4
|
"description": "Generate mock Prismic documents, fields, Slices, and models for development and testing environments",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -49,19 +49,20 @@
|
|
|
49
49
|
"lint": "eslint --ext .js,.ts .",
|
|
50
50
|
"prepare": "npm run build",
|
|
51
51
|
"release": "npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
|
|
52
|
-
"release:alpha": "npm run test && standard-version --release-as
|
|
53
|
-
"release:alpha:dry": "standard-version --release-as
|
|
52
|
+
"release:alpha": "npm run test && standard-version --release-as minor --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
|
|
53
|
+
"release:alpha:dry": "npm run test && standard-version --release-as minor --prerelease alpha --dry-run",
|
|
54
54
|
"release:dry": "standard-version --dry-run",
|
|
55
55
|
"size": "size-limit",
|
|
56
56
|
"test": "npm run lint && npm run types && npm run unit && npm run build && npm run size",
|
|
57
57
|
"types": "tsc --noEmit",
|
|
58
|
-
"unit": "nyc --reporter=lcovonly --reporter=text --exclude-after-remap=false ava"
|
|
58
|
+
"unit": "nyc --reporter=lcovonly --reporter=text --exclude-after-remap=false ava",
|
|
59
|
+
"unit:watch": "npm run unit -- --watch"
|
|
59
60
|
},
|
|
60
61
|
"dependencies": {
|
|
61
62
|
"change-case": "^5.4.4"
|
|
62
63
|
},
|
|
63
64
|
"devDependencies": {
|
|
64
|
-
"@prismicio/client": "
|
|
65
|
+
"@prismicio/client": "7.11.0",
|
|
65
66
|
"@size-limit/preset-small-lib": "^11.1.2",
|
|
66
67
|
"@types/node": "^20.12.7",
|
|
67
68
|
"@typescript-eslint/eslint-plugin": "^7.6.0",
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import * as prismic from "@prismicio/client";
|
|
2
2
|
|
|
3
|
-
type
|
|
3
|
+
type BuildContentRelationshipFieldConfig<
|
|
4
|
+
Document extends prismic.PrismicDocument,
|
|
5
|
+
> = {
|
|
4
6
|
document: Document;
|
|
5
7
|
};
|
|
6
8
|
|
|
7
9
|
export const buildContentRelationshipField = <
|
|
8
10
|
Document extends prismic.PrismicDocument,
|
|
9
11
|
>(
|
|
10
|
-
config:
|
|
12
|
+
config: BuildContentRelationshipFieldConfig<Document>,
|
|
11
13
|
): prismic.ContentRelationshipField<
|
|
12
14
|
Document["type"],
|
|
13
15
|
Document["lang"],
|
package/src/model/link.ts
CHANGED
|
@@ -5,24 +5,39 @@ import { createFaker } from "../lib/createFaker";
|
|
|
5
5
|
|
|
6
6
|
import { MockModelConfig } from "../types";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
type MockLinkModel<
|
|
9
|
+
AllowTargetBlank extends boolean = boolean,
|
|
10
|
+
AllowText extends boolean = boolean,
|
|
11
|
+
Repeat extends boolean = boolean,
|
|
12
|
+
> = prismic.CustomTypeModelLinkField & {
|
|
13
|
+
config: AllowTargetBlank extends true
|
|
14
|
+
? { allowTargetBlank: true }
|
|
15
|
+
: { allowTargetBlank?: undefined };
|
|
16
|
+
} & {
|
|
17
|
+
config: AllowText extends true
|
|
18
|
+
? { allowText: true }
|
|
19
|
+
: { allowText?: undefined };
|
|
20
|
+
} & {
|
|
21
|
+
config: Repeat extends true ? { repeat: true } : { repeat?: undefined };
|
|
22
|
+
};
|
|
18
23
|
|
|
19
|
-
export type MockLinkModelConfig<
|
|
24
|
+
export type MockLinkModelConfig<
|
|
25
|
+
AllowTargetBlank extends boolean = boolean,
|
|
26
|
+
AllowText extends boolean = boolean,
|
|
27
|
+
Repeat extends boolean = boolean,
|
|
28
|
+
> = {
|
|
20
29
|
allowTargetBlank?: AllowTargetBlank;
|
|
30
|
+
allowText?: AllowText;
|
|
31
|
+
repeat?: Repeat;
|
|
21
32
|
} & MockModelConfig;
|
|
22
33
|
|
|
23
|
-
export const link = <
|
|
24
|
-
|
|
25
|
-
|
|
34
|
+
export const link = <
|
|
35
|
+
AllowTargetBlank extends boolean = boolean,
|
|
36
|
+
AllowText extends boolean = boolean,
|
|
37
|
+
Repeat extends boolean = boolean,
|
|
38
|
+
>(
|
|
39
|
+
config: MockLinkModelConfig<AllowTargetBlank, AllowText, Repeat>,
|
|
40
|
+
): MockLinkModel<AllowTargetBlank, AllowText, Repeat> => {
|
|
26
41
|
const faker = config.faker || createFaker(config.seed);
|
|
27
42
|
|
|
28
43
|
return {
|
|
@@ -35,6 +50,11 @@ export const link = <AllowTargetBlank extends boolean = boolean>(
|
|
|
35
50
|
("allowTargetBlank" in config
|
|
36
51
|
? config.allowTargetBlank
|
|
37
52
|
: faker.boolean()) || undefined,
|
|
53
|
+
allowText:
|
|
54
|
+
("allowText" in config ? config.allowText : faker.boolean()) ||
|
|
55
|
+
undefined,
|
|
56
|
+
repeat:
|
|
57
|
+
("repeat" in config ? config.repeat : faker.boolean()) || undefined,
|
|
38
58
|
},
|
|
39
|
-
} as MockLinkModel<AllowTargetBlank>;
|
|
59
|
+
} as MockLinkModel<AllowTargetBlank, AllowText, Repeat>;
|
|
40
60
|
};
|
package/src/model/linkToMedia.ts
CHANGED
|
@@ -5,11 +5,28 @@ import { createFaker } from "../lib/createFaker";
|
|
|
5
5
|
|
|
6
6
|
import { MockModelConfig } from "../types";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
type MockLinkToMediaModel<
|
|
9
|
+
AllowText extends boolean = boolean,
|
|
10
|
+
Repeat extends boolean = boolean,
|
|
11
|
+
> = prismic.CustomTypeModelLinkToMediaField & {
|
|
12
|
+
config: AllowText extends true
|
|
13
|
+
? { allowText: true }
|
|
14
|
+
: { allowText?: undefined };
|
|
15
|
+
} & {
|
|
16
|
+
config: Repeat extends true ? { repeat: true } : { repeat?: undefined };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type MockLinkToMediaModelConfig<
|
|
20
|
+
AllowText extends boolean = boolean,
|
|
21
|
+
Repeat extends boolean = boolean,
|
|
22
|
+
> = MockModelConfig & {
|
|
23
|
+
allowText?: AllowText;
|
|
24
|
+
repeat?: Repeat;
|
|
25
|
+
};
|
|
9
26
|
|
|
10
|
-
export const linkToMedia = (
|
|
11
|
-
config: MockLinkToMediaModelConfig
|
|
12
|
-
):
|
|
27
|
+
export const linkToMedia = <AllowText extends boolean = boolean>(
|
|
28
|
+
config: MockLinkToMediaModelConfig<AllowText>,
|
|
29
|
+
): MockLinkToMediaModel<AllowText> => {
|
|
13
30
|
const faker = config.faker || createFaker(config.seed);
|
|
14
31
|
|
|
15
32
|
return {
|
|
@@ -18,6 +35,11 @@ export const linkToMedia = (
|
|
|
18
35
|
label: changeCase.capitalCase(faker.word()),
|
|
19
36
|
placeholder: changeCase.sentenceCase(faker.words(3)),
|
|
20
37
|
select: prismic.CustomTypeModelLinkSelectType.Media,
|
|
38
|
+
allowText:
|
|
39
|
+
("allowText" in config ? config.allowText : faker.boolean()) ||
|
|
40
|
+
undefined,
|
|
41
|
+
repeat:
|
|
42
|
+
("repeat" in config ? config.repeat : faker.boolean()) || undefined,
|
|
21
43
|
},
|
|
22
|
-
}
|
|
44
|
+
} as MockLinkToMediaModel<AllowText>;
|
|
23
45
|
};
|
package/src/value/link.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as prismic from "@prismicio/client";
|
|
2
|
+
import * as changeCase from "change-case";
|
|
2
3
|
|
|
3
4
|
import { createFaker } from "../lib/createFaker";
|
|
4
5
|
|
|
@@ -22,6 +23,9 @@ export type MockLinkValueConfig<
|
|
|
22
23
|
>["allowTargetBlank"] extends undefined
|
|
23
24
|
? false
|
|
24
25
|
: boolean;
|
|
26
|
+
withText?: NonNullable<Model["config"]>["allowText"] extends undefined
|
|
27
|
+
? false
|
|
28
|
+
: boolean;
|
|
25
29
|
/**
|
|
26
30
|
* A list of potential documents to which the field can be linked.
|
|
27
31
|
*/
|
|
@@ -82,6 +86,7 @@ export const link = <
|
|
|
82
86
|
return linkToMedia({
|
|
83
87
|
faker,
|
|
84
88
|
state: config.state,
|
|
89
|
+
withText: config.withText,
|
|
85
90
|
}) as MockLinkValue<LinkType, State>;
|
|
86
91
|
}
|
|
87
92
|
|
|
@@ -97,6 +102,10 @@ export const link = <
|
|
|
97
102
|
(model.config?.allowTargetBlank && faker.boolean())
|
|
98
103
|
? "_blank"
|
|
99
104
|
: undefined,
|
|
105
|
+
text:
|
|
106
|
+
config.withText ?? (model.config?.allowText && faker.boolean())
|
|
107
|
+
? changeCase.sentenceCase(faker.words(2))
|
|
108
|
+
: undefined,
|
|
100
109
|
} as MockLinkValue<LinkType, State>;
|
|
101
110
|
}
|
|
102
111
|
}
|
package/src/value/linkToMedia.ts
CHANGED
|
@@ -5,11 +5,18 @@ import { createFaker } from "../lib/createFaker";
|
|
|
5
5
|
|
|
6
6
|
import { MockValueStateConfig, MockValueConfig } from "../types";
|
|
7
7
|
|
|
8
|
+
import * as modelGen from "../model";
|
|
9
|
+
|
|
8
10
|
export type MockLinkToMediaValueConfig<
|
|
9
11
|
Model extends
|
|
10
12
|
prismic.CustomTypeModelLinkToMediaField = prismic.CustomTypeModelLinkToMediaField,
|
|
11
13
|
State extends prismic.FieldState = prismic.FieldState,
|
|
12
|
-
> =
|
|
14
|
+
> = {
|
|
15
|
+
withText?: NonNullable<Model["config"]>["allowText"] extends undefined
|
|
16
|
+
? false
|
|
17
|
+
: boolean;
|
|
18
|
+
} & MockValueConfig<Model> &
|
|
19
|
+
MockValueStateConfig<State>;
|
|
13
20
|
|
|
14
21
|
type MockLinkToMediaValue<
|
|
15
22
|
State extends prismic.FieldState = prismic.FieldState,
|
|
@@ -29,6 +36,8 @@ export const linkToMedia = <
|
|
|
29
36
|
link_type: prismic.LinkType.Media,
|
|
30
37
|
} as MockLinkToMediaValue<State>;
|
|
31
38
|
} else {
|
|
39
|
+
const model = config.model || modelGen.link({ faker });
|
|
40
|
+
|
|
32
41
|
return {
|
|
33
42
|
link_type: prismic.LinkType.Media,
|
|
34
43
|
id: faker.hash(11),
|
|
@@ -38,6 +47,10 @@ export const linkToMedia = <
|
|
|
38
47
|
size: faker.range(500, 3000).toString(),
|
|
39
48
|
height: faker.range(500, 3000).toString(),
|
|
40
49
|
width: faker.range(500, 3000).toString(),
|
|
50
|
+
text:
|
|
51
|
+
config.withText ?? (model.config?.allowText && faker.boolean())
|
|
52
|
+
? changeCase.sentenceCase(faker.words(2))
|
|
53
|
+
: undefined,
|
|
41
54
|
} as MockLinkToMediaValue<State>;
|
|
42
55
|
}
|
|
43
56
|
};
|