nextpress-core 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { IPost } from "@/entities/post/post.interface";
|
|
2
|
+
import { ITerm } from "@/entities/term/term.interface";
|
|
3
|
+
import { IUser } from "@/entities/user/user.interface";
|
|
4
|
+
import { JSX } from "react";
|
|
5
|
+
type GetFields<T> = T extends {
|
|
6
|
+
fields: readonly any[];
|
|
7
|
+
} ? T['fields'] : T extends {
|
|
8
|
+
sub_fields: readonly any[];
|
|
9
|
+
} ? T['sub_fields'] : never;
|
|
10
|
+
/**
|
|
11
|
+
* Represents the properties passed to a Nextpress ACF component.
|
|
12
|
+
*
|
|
13
|
+
* @template T - The expected type of the mapped ACF fields.
|
|
14
|
+
*/
|
|
15
|
+
export type FieldProps<LayoutT> = LayoutT extends {
|
|
16
|
+
fields: readonly any[];
|
|
17
|
+
} | {
|
|
18
|
+
sub_fields: readonly any[];
|
|
19
|
+
} ? ResolvedFields<GetFields<LayoutT>> : never;
|
|
20
|
+
/**
|
|
21
|
+
* An array of ACF field configurations to a strongly-typed object representing the resolved data structure.
|
|
22
|
+
* It iterates over the array, using the `name` property of each field as the object key, and determines the expected value type using the `MapFieldType` utility.
|
|
23
|
+
*
|
|
24
|
+
* @template Fields - A readonly array of ACF field configuration objects.
|
|
25
|
+
*/
|
|
26
|
+
type ResolvedFields<Fields extends readonly any[]> = {
|
|
27
|
+
[F in Fields[number] as F['name']]: MapFieldType<F>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Maps an array of ACF Flexible Content layouts to a union type representing the resolved layout blocks.
|
|
31
|
+
* For each layout, it checks for the presence of `fields` or `sub_fields`, and resolves to a specific object
|
|
32
|
+
* structure containing the layout's React component and its deeply resolved field content.
|
|
33
|
+
*
|
|
34
|
+
* @template Layouts - A readonly array of ACF Flexible Content layout configuration objects.
|
|
35
|
+
*/
|
|
36
|
+
type ResolvedFlexibleContent<Layouts extends readonly any[]> = {
|
|
37
|
+
[L in Layouts[number] as L['name']]: L extends {
|
|
38
|
+
name: infer Name;
|
|
39
|
+
} & ({
|
|
40
|
+
fields: readonly any[];
|
|
41
|
+
} | {
|
|
42
|
+
sub_fields: readonly any[];
|
|
43
|
+
}) ? {
|
|
44
|
+
Component: () => Promise<JSX.Element>;
|
|
45
|
+
content: ResolvedFields<GetFields<L>>;
|
|
46
|
+
}[] : never;
|
|
47
|
+
}[Layouts[number]['name']];
|
|
48
|
+
type MapFieldType<Field> = Field extends {
|
|
49
|
+
type: 'color_picker';
|
|
50
|
+
} ? string | null : Field extends {
|
|
51
|
+
type: 'date_picker';
|
|
52
|
+
} ? string | null : Field extends {
|
|
53
|
+
type: 'date_time_picker';
|
|
54
|
+
} ? string | null : Field extends {
|
|
55
|
+
type: 'google_map';
|
|
56
|
+
} ? ACFGoogleMapsObject | null : Field extends {
|
|
57
|
+
type: 'icon_picker';
|
|
58
|
+
} ? Field extends {
|
|
59
|
+
return_format: 'string';
|
|
60
|
+
} ? string | null : Field extends {
|
|
61
|
+
return_format: 'array';
|
|
62
|
+
} ? ACFIconObject | null : ACFIconObject | null : Field extends {
|
|
63
|
+
type: 'time_picker';
|
|
64
|
+
} ? string | null : Field extends {
|
|
65
|
+
type: 'email';
|
|
66
|
+
} ? string | null : Field extends {
|
|
67
|
+
type: 'number';
|
|
68
|
+
} ? number | null : Field extends {
|
|
69
|
+
type: 'password';
|
|
70
|
+
} ? string | null : Field extends {
|
|
71
|
+
type: 'range';
|
|
72
|
+
} ? number | null : Field extends {
|
|
73
|
+
type: 'text';
|
|
74
|
+
} ? string | null : Field extends {
|
|
75
|
+
type: 'textarea';
|
|
76
|
+
} ? string | null : Field extends {
|
|
77
|
+
type: 'button_group';
|
|
78
|
+
} ? Field extends {
|
|
79
|
+
return_format: 'array';
|
|
80
|
+
} ? ACFChoiceObject | null : string | null : Field extends {
|
|
81
|
+
type: 'checkbox';
|
|
82
|
+
} ? Field extends {
|
|
83
|
+
return_format: 'array';
|
|
84
|
+
} ? ACFChoiceObject[] : string[] : Field extends {
|
|
85
|
+
type: 'radio';
|
|
86
|
+
} ? Field extends {
|
|
87
|
+
return_format: 'array';
|
|
88
|
+
} ? ACFChoiceObject | null : string | null : Field extends {
|
|
89
|
+
type: 'select';
|
|
90
|
+
} ? Field extends {
|
|
91
|
+
multiple: 1;
|
|
92
|
+
} ? Field extends {
|
|
93
|
+
return_format: 'array';
|
|
94
|
+
} ? ACFChoiceObject[] : string[] : Field extends {
|
|
95
|
+
return_format: 'array';
|
|
96
|
+
} ? ACFChoiceObject | null : string | null : Field extends {
|
|
97
|
+
type: 'true_false';
|
|
98
|
+
} ? boolean : Field extends {
|
|
99
|
+
type: 'file';
|
|
100
|
+
} ? number | null : Field extends {
|
|
101
|
+
type: 'gallery';
|
|
102
|
+
} ? number[] : Field extends {
|
|
103
|
+
type: 'image';
|
|
104
|
+
} ? number | null : Field extends {
|
|
105
|
+
type: 'oembed';
|
|
106
|
+
} ? string | null : Field extends {
|
|
107
|
+
type: 'wysiwyg';
|
|
108
|
+
} ? string | null : Field extends {
|
|
109
|
+
type: 'link';
|
|
110
|
+
} ? Field extends {
|
|
111
|
+
return_format: 'url';
|
|
112
|
+
} ? string | null : Field extends {
|
|
113
|
+
return_format: 'array';
|
|
114
|
+
} ? ACFLinkObject | null : ACFLinkObject : Field extends {
|
|
115
|
+
type: 'page_link';
|
|
116
|
+
} ? Field extends {
|
|
117
|
+
multiple: 1;
|
|
118
|
+
} ? string[] : string | null : Field extends {
|
|
119
|
+
type: 'post_object';
|
|
120
|
+
} ? Field extends {
|
|
121
|
+
multiple: 1;
|
|
122
|
+
} ? Field extends {
|
|
123
|
+
return_format: 'object';
|
|
124
|
+
} ? IPost[] : number[] : Field extends {
|
|
125
|
+
return_format: 'object';
|
|
126
|
+
} ? IPost | null : number | null : Field extends {
|
|
127
|
+
type: 'relationship';
|
|
128
|
+
} ? Field extends {
|
|
129
|
+
return_format: 'object';
|
|
130
|
+
} ? IPost[] | null : number[] | null : Field extends {
|
|
131
|
+
type: 'taxonomy';
|
|
132
|
+
} ? Field extends {
|
|
133
|
+
multiple: 1;
|
|
134
|
+
} ? Field extends {
|
|
135
|
+
return_format: 'object';
|
|
136
|
+
} ? ITerm[] : number[] : Field extends {
|
|
137
|
+
return_format: 'object';
|
|
138
|
+
} ? ITerm | null : number | null : Field extends {
|
|
139
|
+
type: 'user';
|
|
140
|
+
} ? Field extends {
|
|
141
|
+
multiple: 1;
|
|
142
|
+
} ? Field extends {
|
|
143
|
+
return_format: 'object';
|
|
144
|
+
} ? IUser[] : number[] : Field extends {
|
|
145
|
+
return_format: 'object';
|
|
146
|
+
} ? IUser | null : number | null : Field extends {
|
|
147
|
+
type: 'group';
|
|
148
|
+
} & ({
|
|
149
|
+
fields: readonly any[];
|
|
150
|
+
} | {
|
|
151
|
+
sub_fields: readonly any[];
|
|
152
|
+
}) ? ResolvedFields<GetFields<Field>> | null : Field extends {
|
|
153
|
+
type: 'repeater';
|
|
154
|
+
} & ({
|
|
155
|
+
fields: readonly any[];
|
|
156
|
+
} | {
|
|
157
|
+
sub_fields: readonly any[];
|
|
158
|
+
}) ? ResolvedFields<GetFields<Field>>[] | null : Field extends {
|
|
159
|
+
type: 'flexible_content';
|
|
160
|
+
layouts: readonly any[];
|
|
161
|
+
} ? ResolvedFlexibleContent<Field['layouts']> | null : Field extends {
|
|
162
|
+
fields: readonly any[];
|
|
163
|
+
} | {
|
|
164
|
+
sub_fields: readonly any[];
|
|
165
|
+
} ? ResolvedFields<GetFields<Field>> : never;
|
|
166
|
+
type ACFIconObject = {
|
|
167
|
+
type: string;
|
|
168
|
+
value: string;
|
|
169
|
+
};
|
|
170
|
+
type ACFLinkObject = {
|
|
171
|
+
title: string;
|
|
172
|
+
url: string;
|
|
173
|
+
target: string;
|
|
174
|
+
};
|
|
175
|
+
type ACFChoiceObject = {
|
|
176
|
+
label?: string;
|
|
177
|
+
value?: string;
|
|
178
|
+
};
|
|
179
|
+
type ACFGoogleMapsObject = {
|
|
180
|
+
address: string;
|
|
181
|
+
lat: string | number;
|
|
182
|
+
lng: string | number;
|
|
183
|
+
zoom: string | number;
|
|
184
|
+
place_id: string;
|
|
185
|
+
name: string;
|
|
186
|
+
street_number: string | number;
|
|
187
|
+
street_name: string;
|
|
188
|
+
street_name_short: string;
|
|
189
|
+
city: string;
|
|
190
|
+
state: string;
|
|
191
|
+
state_short: string;
|
|
192
|
+
post_code: string | number;
|
|
193
|
+
country: string;
|
|
194
|
+
country_short: string;
|
|
195
|
+
};
|
|
196
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|