nextpress-core 1.0.0 → 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.
- package/dist/acf-functions/core/acf-builder.d.ts +50 -0
- package/{lib/acf-functions/core/acf-builder.ts → dist/acf-functions/core/acf-builder.js} +17 -41
- package/dist/acf-functions/core/acf-component-autoloader.d.ts +11 -0
- package/{lib/acf-functions/core/acf-component-autoloader.ts → dist/acf-functions/core/acf-component-autoloader.js} +7 -13
- package/dist/acf-functions/core/acf-field-group-autoloader.d.ts +9 -0
- package/{lib/acf-functions/core/acf-field-group-autoloader.ts → dist/acf-functions/core/acf-field-group-autoloader.js} +4 -9
- package/dist/acf-functions/field-props.d.ts +196 -0
- package/dist/acf-functions/field-props.js +1 -0
- package/dist/acf-functions/services/define-field-group.d.ts +8 -0
- package/{lib/acf-functions/services/define-field-group.ts → dist/acf-functions/services/define-field-group.js} +1 -1
- package/dist/acf-functions/services/define-layout.d.ts +8 -0
- package/{lib/acf-functions/services/define-layout.ts → dist/acf-functions/services/define-layout.js} +1 -1
- package/dist/acf-functions/services/map-fields/helpers/map-choice-object.d.ts +2 -0
- package/dist/acf-functions/services/map-fields/helpers/map-choice-object.js +18 -0
- package/dist/acf-functions/services/map-fields/map-fields.d.ts +18 -0
- package/{lib/acf-functions/services/map-fields/map-fields.ts → dist/acf-functions/services/map-fields/map-fields.js} +88 -124
- package/dist/entities/option/option.d.ts +19 -0
- package/{lib/entities/option/option.ts → dist/entities/option/option.js} +13 -20
- package/dist/entities/post/post.d.ts +50 -0
- package/dist/entities/post/post.js +184 -0
- package/dist/entities/term/term.d.ts +28 -0
- package/dist/entities/term/term.js +67 -0
- package/dist/entities/user/user.d.ts +27 -0
- package/dist/entities/user/user.js +74 -0
- package/dist/globals/entity-loader/entity-loader-base.d.ts +65 -0
- package/{lib/globals/entity-loader/entity-loader-base.ts → dist/globals/entity-loader/entity-loader-base.js} +10 -64
- package/dist/globals/entity-loader/option-loader.d.ts +15 -0
- package/dist/globals/entity-loader/option-loader.js +31 -0
- package/dist/globals/entity-loader/post-loader.d.ts +21 -0
- package/dist/globals/entity-loader/post-loader.js +28 -0
- package/dist/globals/entity-loader/term-loader.d.ts +21 -0
- package/dist/globals/entity-loader/term-loader.js +28 -0
- package/dist/globals/entity-loader/user-loader.d.ts +21 -0
- package/dist/globals/entity-loader/user-loader.js +28 -0
- package/dist/globals/get-field/get-field.d.ts +17 -0
- package/dist/globals/get-field/get-field.js +44 -0
- package/dist/globals/globals.d.ts +18 -0
- package/{lib/globals/globals.ts → dist/globals/globals.js} +3 -8
- package/dist/globals/nextpress-config/nextpress-config.d.ts +4 -0
- package/{lib/globals/nextpress-config/nextpress-config.ts → dist/globals/nextpress-config/nextpress-config.js} +0 -5
- package/dist/globals/queried-object/queried-object.d.ts +62 -0
- package/dist/globals/queried-object/queried-object.js +56 -0
- package/dist/repository/optionquery/option-query.d.ts +12 -0
- package/dist/repository/optionquery/option-query.js +20 -0
- package/dist/repository/postquery/post-query.d.ts +12 -0
- package/dist/repository/postquery/post-query.js +272 -0
- package/dist/repository/termquery/term-query.d.ts +11 -0
- package/dist/repository/termquery/term-query.js +213 -0
- package/dist/repository/userquery/user-query.d.ts +12 -0
- package/{lib/repository/userquery/user-query.ts → dist/repository/userquery/user-query.js} +75 -91
- package/dist/router/helpers.d.ts +14 -0
- package/{lib/router/helpers.ts → dist/router/helpers.js} +4 -4
- package/dist/router/nextpress-layout.d.ts +11 -0
- package/{lib/router/nextpress-layout.tsx → dist/router/nextpress-layout.js} +6 -23
- package/dist/router/nextpress-proxy.d.ts +8 -0
- package/{lib/router/nextpress-proxy.ts → dist/router/nextpress-proxy.js} +3 -15
- package/dist/router/nextpress-static-params.d.ts +9 -0
- package/{lib/router/nextpress-static-params.ts → dist/router/nextpress-static-params.js} +5 -17
- package/dist/router/router.d.ts +23 -0
- package/{lib/router/router.tsx → dist/router/router.js} +21 -29
- package/dist/router/routes/api/api-get-admin-bar.d.ts +8 -0
- package/{lib/router/routes/api/api-get-admin-bar.ts → dist/router/routes/api/api-get-admin-bar.js} +6 -8
- package/dist/router/routes/api/api-get-draft-mode.d.ts +8 -0
- package/{lib/router/routes/api/api-get-draft-mode.ts → dist/router/routes/api/api-get-draft-mode.js} +6 -15
- package/dist/router/routes/api/api-get-field-groups.d.ts +7 -0
- package/{lib/router/routes/api/api-get-field-groups.ts → dist/router/routes/api/api-get-field-groups.js} +6 -11
- package/dist/router/routes/api/api-post-revalidate.d.ts +7 -0
- package/{lib/router/routes/api/api-post-revalidate.ts → dist/router/routes/api/api-post-revalidate.js} +4 -6
- package/dist/router/routes/api/helpers.d.ts +8 -0
- package/{lib/router/routes/api/helpers.ts → dist/router/routes/api/helpers.js} +3 -4
- package/dist/router/routes/author-archive.d.ts +25 -0
- package/{lib/router/routes/author-archive.tsx → dist/router/routes/author-archive.js} +11 -37
- package/dist/router/routes/not-found-page.d.ts +15 -0
- package/{lib/router/routes/not-found-page.tsx → dist/router/routes/not-found-page.js} +3 -5
- package/dist/router/routes/post-index-page.d.ts +25 -0
- package/dist/router/routes/post-index-page.js +33 -0
- package/dist/router/routes/singular-page.d.ts +29 -0
- package/dist/router/routes/singular-page.js +51 -0
- package/dist/router/routes/site-front-page.d.ts +27 -0
- package/dist/router/routes/site-front-page.js +26 -0
- package/dist/router/routes/term-archive.d.ts +29 -0
- package/{lib/router/routes/term-archive.tsx → dist/router/routes/term-archive.js} +17 -45
- package/dist/services/get-menu.d.ts +13 -0
- package/{lib/services/get-menu.ts → dist/services/get-menu.js} +32 -56
- package/dist/services/get-theme-mods.d.ts +7 -0
- package/{lib/services/get-theme-mods.ts → dist/services/get-theme-mods.js} +4 -6
- package/dist/services/metadata/get-blogname.d.ts +6 -0
- package/{lib/services/metadata/get-blogname.ts → dist/services/metadata/get-blogname.js} +2 -2
- package/dist/services/metadata/get-favicon-url.d.ts +6 -0
- package/{lib/services/metadata/get-favicon-url.ts → dist/services/metadata/get-favicon-url.js} +4 -5
- package/dist/services/metadata/get-language-attribute.d.ts +6 -0
- package/{lib/services/metadata/get-language-attribute.ts → dist/services/metadata/get-language-attribute.js} +1 -1
- package/{lib/services/services.ts → dist/services/services.d.ts} +1 -5
- package/dist/services/services.js +3 -0
- package/dist/services/utilities/capitalise-first-letter.d.ts +7 -0
- package/{lib/services/utilities/capitalise-first-letter.ts → dist/services/utilities/capitalise-first-letter.js} +3 -2
- package/dist/services/utilities/esc-html.d.ts +7 -0
- package/{lib/services/utilities/esc-html.ts → dist/services/utilities/esc-html.js} +1 -3
- package/dist/services/utilities/get-date-time-formatter.d.ts +6 -0
- package/{lib/services/utilities/get-date-time-formatter.ts → dist/services/utilities/get-date-time-formatter.js} +6 -16
- package/dist/services/utilities/index.js +1 -0
- package/dist/services/utilities/kses-post.d.ts +7 -0
- package/{lib/services/utilities/kses-post.ts → dist/services/utilities/kses-post.js} +1 -2
- package/dist/services/utilities/process-url.d.ts +7 -0
- package/{lib/services/utilities/process-url.ts → dist/services/utilities/process-url.js} +3 -4
- package/dist/template-heirarchy/_autoloader/template-autoloader.d.ts +9 -0
- package/{lib/template-heirarchy/_autoloader/template-autoloader.ts → dist/template-heirarchy/_autoloader/template-autoloader.js} +9 -18
- package/dist/template-heirarchy/archive/archive.d.ts +16 -0
- package/{lib/template-heirarchy/archive/archive.tsx → dist/template-heirarchy/archive/archive.js} +7 -10
- package/dist/template-heirarchy/archive/author.d.ts +16 -0
- package/{lib/template-heirarchy/archive/author.tsx → dist/template-heirarchy/archive/author.js} +7 -10
- package/dist/template-heirarchy/archive/category.d.ts +16 -0
- package/{lib/template-heirarchy/archive/category.tsx → dist/template-heirarchy/archive/category.js} +7 -11
- package/dist/template-heirarchy/archive/posttypearchive.d.ts +24 -0
- package/{lib/template-heirarchy/archive/posttypearchive.tsx → dist/template-heirarchy/archive/posttypearchive.js} +7 -10
- package/dist/template-heirarchy/archive/tag.d.ts +16 -0
- package/{lib/template-heirarchy/archive/tag.tsx → dist/template-heirarchy/archive/tag.js} +7 -12
- package/dist/template-heirarchy/archive/taxonomy.d.ts +16 -0
- package/{lib/template-heirarchy/archive/taxonomy.tsx → dist/template-heirarchy/archive/taxonomy.js} +7 -10
- package/dist/template-heirarchy/home/home.d.ts +16 -0
- package/{lib/template-heirarchy/home/home.tsx → dist/template-heirarchy/home/home.js} +7 -10
- package/dist/template-heirarchy/index.d.ts +17 -0
- package/{lib/template-heirarchy/index.tsx → dist/template-heirarchy/index.js} +5 -9
- package/dist/template-heirarchy/not-found.tsx/not-found.d.ts +16 -0
- package/{lib/template-heirarchy/not-found.tsx/not-found.tsx → dist/template-heirarchy/not-found.tsx/not-found.js} +7 -10
- package/dist/template-heirarchy/page/page.d.ts +16 -0
- package/{lib/template-heirarchy/page/page.tsx → dist/template-heirarchy/page/page.js} +7 -10
- package/dist/template-heirarchy/page/posttype.d.ts +24 -0
- package/{lib/template-heirarchy/page/posttype.tsx → dist/template-heirarchy/page/posttype.js} +7 -11
- package/dist/template-heirarchy/page/single.d.ts +16 -0
- package/{lib/template-heirarchy/page/single.tsx → dist/template-heirarchy/page/single.js} +7 -10
- package/dist/template-heirarchy/page/singular.d.ts +16 -0
- package/{lib/template-heirarchy/page/singular.tsx → dist/template-heirarchy/page/singular.js} +7 -10
- package/dist/ui/render-attachment-image.d.ts +12 -0
- package/dist/ui/render-attachment-image.js +24 -0
- package/{lib/ui/render-components.tsx → dist/ui/render-components.d.ts} +4 -7
- package/dist/ui/render-components.js +7 -0
- package/dist/ui/render-the-admin-bar.d.ts +8 -0
- package/dist/ui/render-the-admin-bar.js +36 -0
- package/dist/ui/render-the-logo.d.ts +10 -0
- package/dist/ui/render-the-logo.js +16 -0
- package/dist/wpdb/wpdb.d.ts +3 -0
- package/{lib/wpdb/wpdb.ts → dist/wpdb/wpdb.js} +5 -9
- package/package.json +7 -3
- package/lib/acf-functions/services/map-fields/helpers/map-choice-object.ts +0 -20
- package/lib/acf-functions/types/acf-field-group.d.ts +0 -118
- package/lib/acf-functions/types/acf-field.d.ts +0 -2851
- package/lib/acf-functions/types/acf-layout.d.ts +0 -20
- package/lib/acf-functions/types/acf-values.d.ts +0 -4
- package/lib/acf-functions/types/components/field-props.d.ts +0 -189
- package/lib/acf-functions/types/components/nextpress-component.d.ts +0 -11
- package/lib/ambient.d.ts +0 -15
- package/lib/entities/common.d.ts +0 -30
- package/lib/entities/option/option.interface.d.ts +0 -8
- package/lib/entities/post/post.interface.d.ts +0 -72
- package/lib/entities/post/post.ts +0 -209
- package/lib/entities/term/term.interface.d.ts +0 -8
- package/lib/entities/term/term.ts +0 -82
- package/lib/entities/user/user.interface.d.ts +0 -10
- package/lib/entities/user/user.ts +0 -86
- package/lib/globals/entity-loader/entity-loader.d.ts +0 -50
- package/lib/globals/entity-loader/option-loader.ts +0 -56
- package/lib/globals/entity-loader/post-loader.ts +0 -59
- package/lib/globals/entity-loader/term-loader.ts +0 -59
- package/lib/globals/entity-loader/user-loader.ts +0 -60
- package/lib/globals/get-field/get-field.ts +0 -75
- package/lib/globals/nextpress-config/nextpress-config.interface.d.ts +0 -18
- package/lib/globals/queried-object/queried-object.ts +0 -124
- package/lib/repository/optionquery/option-query-args.d.ts +0 -21
- package/lib/repository/optionquery/option-query.ts +0 -29
- package/lib/repository/postquery/post-query-args.d.ts +0 -108
- package/lib/repository/postquery/post-query.ts +0 -281
- package/lib/repository/termquery/term-query-args.d.ts +0 -61
- package/lib/repository/termquery/term-query.ts +0 -243
- package/lib/repository/userquery/user-query-args.d.ts +0 -75
- package/lib/router/routes/post-index-page.tsx +0 -58
- package/lib/router/routes/singular-page.tsx +0 -78
- package/lib/router/routes/site-front-page.tsx +0 -51
- package/lib/router/types.d.ts +0 -9
- package/lib/ui/render-attachment-image.tsx +0 -29
- package/lib/ui/render-the-admin-bar.tsx +0 -79
- package/lib/ui/render-the-logo.tsx +0 -24
- package/lib/wpdb/wpdb.interface.d.ts +0 -171
- /package/{lib/services/utilities/index.ts → dist/services/utilities/index.d.ts} +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class representing ACF builder.
|
|
3
|
+
*/
|
|
4
|
+
export declare class ACFBuilder {
|
|
5
|
+
/** Array of ACF field groups. */
|
|
6
|
+
private fieldGroups;
|
|
7
|
+
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Gets built field groups.
|
|
10
|
+
*
|
|
11
|
+
* @returns {ACFFieldGroup[]} Array of field groups.
|
|
12
|
+
*/
|
|
13
|
+
getFieldGroups(): ACFFieldGroup[];
|
|
14
|
+
/**
|
|
15
|
+
* Converts field groups to JSON string.
|
|
16
|
+
*
|
|
17
|
+
* @returns {string} JSON string representation of field groups.
|
|
18
|
+
*/
|
|
19
|
+
toJSON(): string;
|
|
20
|
+
/**
|
|
21
|
+
* Registers and processes Nextpress field groups.
|
|
22
|
+
*
|
|
23
|
+
* @param {NextpressFieldGroup[]} fieldGroups - Array of field groups to register.
|
|
24
|
+
* @returns {this} Current instance.
|
|
25
|
+
*/
|
|
26
|
+
registerFieldGroups(fieldGroups: NextpressFieldGroup[]): this;
|
|
27
|
+
/**
|
|
28
|
+
* Sets keys for fields based on parent name.
|
|
29
|
+
*
|
|
30
|
+
* @param {NextpressField[]} fields - Array of fields to process.
|
|
31
|
+
* @param {string} parentName - Parent string name.
|
|
32
|
+
* @returns {ACFField[]} Array of fields with generated keys.
|
|
33
|
+
*/
|
|
34
|
+
private setFieldKeys;
|
|
35
|
+
/**
|
|
36
|
+
* Sets keys for layouts based on parent name.
|
|
37
|
+
*
|
|
38
|
+
* @param {NextpressLayout[]} layouts - Array of layouts to process.
|
|
39
|
+
* @param {string} parentName - Parent string name.
|
|
40
|
+
* @returns {ACFLayout[]} Array of layouts with generated keys.
|
|
41
|
+
*/
|
|
42
|
+
private setLayoutKeys;
|
|
43
|
+
/**
|
|
44
|
+
* Formats suffix string.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} suffix - Suffix to format.
|
|
47
|
+
* @returns {string} Formatted string.
|
|
48
|
+
*/
|
|
49
|
+
private formatKeySuffix;
|
|
50
|
+
}
|
|
@@ -1,49 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Class representing ACF builder.
|
|
3
3
|
*/
|
|
4
|
-
export class ACFBuilder
|
|
5
|
-
{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
export class ACFBuilder {
|
|
5
|
+
constructor() {
|
|
6
|
+
/** Array of ACF field groups. */
|
|
7
|
+
this.fieldGroups = [];
|
|
8
|
+
}
|
|
9
|
+
;
|
|
11
10
|
/**
|
|
12
11
|
* Gets built field groups.
|
|
13
12
|
*
|
|
14
13
|
* @returns {ACFFieldGroup[]} Array of field groups.
|
|
15
14
|
*/
|
|
16
|
-
|
|
15
|
+
getFieldGroups() {
|
|
17
16
|
return this.fieldGroups;
|
|
18
17
|
}
|
|
19
|
-
|
|
20
18
|
/**
|
|
21
19
|
* Converts field groups to JSON string.
|
|
22
20
|
*
|
|
23
21
|
* @returns {string} JSON string representation of field groups.
|
|
24
22
|
*/
|
|
25
|
-
|
|
23
|
+
toJSON() {
|
|
26
24
|
return JSON.stringify(this.fieldGroups);
|
|
27
25
|
}
|
|
28
|
-
|
|
29
26
|
/**
|
|
30
27
|
* Registers and processes Nextpress field groups.
|
|
31
28
|
*
|
|
32
29
|
* @param {NextpressFieldGroup[]} fieldGroups - Array of field groups to register.
|
|
33
30
|
* @returns {this} Current instance.
|
|
34
31
|
*/
|
|
35
|
-
|
|
36
|
-
const keyedFieldGroups
|
|
37
|
-
...fieldGroup,
|
|
38
|
-
key: `group_${this.formatKeySuffix(fieldGroup.title)}`,
|
|
39
|
-
fields: this.setFieldKeys(fieldGroup.fields, fieldGroup.title),
|
|
40
|
-
}));
|
|
41
|
-
|
|
32
|
+
registerFieldGroups(fieldGroups) {
|
|
33
|
+
const keyedFieldGroups = fieldGroups.map(fieldGroup => (Object.assign(Object.assign({}, fieldGroup), { key: `group_${this.formatKeySuffix(fieldGroup.title)}`, fields: this.setFieldKeys(fieldGroup.fields, fieldGroup.title) })));
|
|
42
34
|
this.fieldGroups = [...this.fieldGroups, ...keyedFieldGroups];
|
|
43
|
-
|
|
44
35
|
return this;
|
|
45
36
|
}
|
|
46
|
-
|
|
47
37
|
/**
|
|
48
38
|
* Sets keys for fields based on parent name.
|
|
49
39
|
*
|
|
@@ -51,26 +41,18 @@ export class ACFBuilder
|
|
|
51
41
|
* @param {string} parentName - Parent string name.
|
|
52
42
|
* @returns {ACFField[]} Array of fields with generated keys.
|
|
53
43
|
*/
|
|
54
|
-
|
|
44
|
+
setFieldKeys(fields, parentName) {
|
|
55
45
|
return fields.map(field => {
|
|
56
46
|
const keySuffix = this.formatKeySuffix(`${parentName}_${field.name}`);
|
|
57
|
-
|
|
58
47
|
const childFields = field.sub_fields
|
|
59
48
|
? this.setFieldKeys(field.sub_fields, keySuffix)
|
|
60
49
|
: undefined;
|
|
61
|
-
|
|
62
50
|
const childLayouts = field.layouts
|
|
63
51
|
? this.setLayoutKeys(field.layouts, keySuffix)
|
|
64
52
|
: undefined;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
...field,
|
|
68
|
-
key: `field_${keySuffix}`,
|
|
69
|
-
sub_fields: childFields,
|
|
70
|
-
layouts: childLayouts
|
|
71
|
-
}});
|
|
53
|
+
return Object.assign(Object.assign({}, field), { key: `field_${keySuffix}`, sub_fields: childFields, layouts: childLayouts });
|
|
54
|
+
});
|
|
72
55
|
}
|
|
73
|
-
|
|
74
56
|
/**
|
|
75
57
|
* Sets keys for layouts based on parent name.
|
|
76
58
|
*
|
|
@@ -78,28 +60,22 @@ export class ACFBuilder
|
|
|
78
60
|
* @param {string} parentName - Parent string name.
|
|
79
61
|
* @returns {ACFLayout[]} Array of layouts with generated keys.
|
|
80
62
|
*/
|
|
81
|
-
|
|
63
|
+
setLayoutKeys(layouts, parentName) {
|
|
82
64
|
return layouts.map(layout => {
|
|
83
65
|
const keySuffix = this.formatKeySuffix(`${parentName}_${layout.name}`);
|
|
84
|
-
|
|
85
66
|
const childFields = layout.sub_fields
|
|
86
67
|
? this.setFieldKeys(layout.sub_fields, `${parentName}_${layout.name}`)
|
|
87
68
|
: undefined;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
...layout,
|
|
91
|
-
key: `layout_${keySuffix}`,
|
|
92
|
-
sub_fields: childFields || [],
|
|
93
|
-
}})
|
|
69
|
+
return Object.assign(Object.assign({}, layout), { key: `layout_${keySuffix}`, sub_fields: childFields || [] });
|
|
70
|
+
});
|
|
94
71
|
}
|
|
95
|
-
|
|
96
72
|
/**
|
|
97
73
|
* Formats suffix string.
|
|
98
74
|
*
|
|
99
75
|
* @param {string} suffix - Suffix to format.
|
|
100
76
|
* @returns {string} Formatted string.
|
|
101
77
|
*/
|
|
102
|
-
|
|
78
|
+
formatKeySuffix(suffix) {
|
|
103
79
|
return suffix.replace(/[\s-]+/g, '_').toLowerCase();
|
|
104
80
|
}
|
|
105
81
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NextpressComponent } from '../types/components/nextpress-component';
|
|
2
|
+
/**
|
|
3
|
+
* Autoloads ACF components dynamically from the templates directory.
|
|
4
|
+
* * **Requirements for it to work:**
|
|
5
|
+
* Each `.tsx` file within the `src/app/_templates/components/` directory MUST export the following:
|
|
6
|
+
* 1. `layout` (Named Export): The configuration for the ACF layout, typically defined using the `defineLayout` function.
|
|
7
|
+
* 2. `default` (Default Export): The React component (JSX/TSX function) that renders the layout.
|
|
8
|
+
*
|
|
9
|
+
* @returns {Promise<NextpressComponent[]>} A promise resolving to an array of mapped layout configurations and their respective components.
|
|
10
|
+
*/
|
|
11
|
+
export declare function acfComponentAutoloader(): Promise<NextpressComponent[]>;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import { NextpressComponent } from '../types/components/nextpress-component';
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* Autoloads ACF components dynamically from the templates directory.
|
|
7
5
|
* * **Requirements for it to work:**
|
|
@@ -11,23 +9,19 @@ import { NextpressComponent } from '../types/components/nextpress-component';
|
|
|
11
9
|
*
|
|
12
10
|
* @returns {Promise<NextpressComponent[]>} A promise resolving to an array of mapped layout configurations and their respective components.
|
|
13
11
|
*/
|
|
14
|
-
export async function acfComponentAutoloader()
|
|
12
|
+
export async function acfComponentAutoloader() {
|
|
15
13
|
const absolutePath = path.join(process.cwd(), 'src', 'app', '_templates', 'components');
|
|
16
14
|
const files = fs.readdirSync(absolutePath);
|
|
17
|
-
|
|
18
|
-
const layouts: NextpressComponent[] = [];
|
|
19
|
-
|
|
15
|
+
const layouts = [];
|
|
20
16
|
for (const file of files) {
|
|
21
|
-
if (!file.endsWith('.tsx'))
|
|
22
|
-
|
|
17
|
+
if (!file.endsWith('.tsx'))
|
|
18
|
+
continue;
|
|
23
19
|
const imported = await import(`@/app/_templates/components/${file}`);
|
|
24
|
-
|
|
25
20
|
const layout = imported.layout;
|
|
26
21
|
const component = imported.default;
|
|
27
|
-
if (!layout || !component)
|
|
28
|
-
|
|
29
|
-
layouts.push({layout, Component: component});
|
|
22
|
+
if (!layout || !component)
|
|
23
|
+
continue;
|
|
24
|
+
layouts.push({ layout, Component: component });
|
|
30
25
|
}
|
|
31
|
-
|
|
32
26
|
return layouts;
|
|
33
27
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Autoloads ACF field groups dynamically from the field-groups directory.
|
|
3
|
+
* * **Requirements for it to work:**
|
|
4
|
+
* Each `.ts` file within the `src/app/_templates/components/field-groups/` directory MUST export the following:
|
|
5
|
+
* 1. `default` (Default Export): The configuration object for the ACF Field Group, typically defined using the `defineFieldGroup` function.
|
|
6
|
+
*
|
|
7
|
+
* @returns {Promise<NextpressFieldGroup[]>} A promise resolving to an array of loaded ACF field group configurations.
|
|
8
|
+
*/
|
|
9
|
+
export declare function acfFieldGroupAutoloader(): Promise<NextpressFieldGroup[]>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* Autoloads ACF field groups dynamically from the field-groups directory.
|
|
6
5
|
* * **Requirements for it to work:**
|
|
@@ -9,20 +8,16 @@ import path from 'path';
|
|
|
9
8
|
*
|
|
10
9
|
* @returns {Promise<NextpressFieldGroup[]>} A promise resolving to an array of loaded ACF field group configurations.
|
|
11
10
|
*/
|
|
12
|
-
export async function acfFieldGroupAutoloader()
|
|
11
|
+
export async function acfFieldGroupAutoloader() {
|
|
13
12
|
const absolutePath = path.join(process.cwd(), 'src', 'app', '_templates', 'components', 'field-groups');
|
|
14
13
|
const files = fs.readdirSync(absolutePath);
|
|
15
|
-
|
|
16
|
-
const fieldGroups: NextpressFieldGroup[] = [];
|
|
17
|
-
|
|
14
|
+
const fieldGroups = [];
|
|
18
15
|
for (const file of files) {
|
|
19
|
-
if (!file.endsWith('.ts'))
|
|
20
|
-
|
|
16
|
+
if (!file.endsWith('.ts'))
|
|
17
|
+
continue;
|
|
21
18
|
const imported = await import(`@/app/_templates/components/field-groups/${file}`);
|
|
22
19
|
const fieldGroup = imported.default;
|
|
23
|
-
|
|
24
20
|
fieldGroups.push(fieldGroup);
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
return fieldGroups;
|
|
28
23
|
}
|
|
@@ -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 {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines field group configuration and applies typing.
|
|
3
|
+
*
|
|
4
|
+
* @template T - Field group type extending NextpressFieldGroup.
|
|
5
|
+
* @param {T} layout - Field group configuration object.
|
|
6
|
+
* @returns {T} Passed field group configuration object.
|
|
7
|
+
*/
|
|
8
|
+
export declare function defineFieldGroup<const T extends NextpressFieldGroup>(layout: T): T;
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* @param {T} layout - Field group configuration object.
|
|
6
6
|
* @returns {T} Passed field group configuration object.
|
|
7
7
|
*/
|
|
8
|
-
export function defineFieldGroup
|
|
8
|
+
export function defineFieldGroup(layout) {
|
|
9
9
|
return layout;
|
|
10
10
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines layout configuration and applies typing.
|
|
3
|
+
*
|
|
4
|
+
* @template T - Layout type extending NextpressLayout.
|
|
5
|
+
* @param {T} layout - Layout configuration object.
|
|
6
|
+
* @returns {T} Passed layout configuration object.
|
|
7
|
+
*/
|
|
8
|
+
export declare function defineLayout<const T extends NextpressLayout>(layout: T): T;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function mapChoiceObject(return_format, value, choices) {
|
|
2
|
+
if (return_format === 'value') {
|
|
3
|
+
return value;
|
|
4
|
+
}
|
|
5
|
+
if (!choices)
|
|
6
|
+
return;
|
|
7
|
+
const label = choices[value !== null && value !== void 0 ? value : ''];
|
|
8
|
+
if (return_format === 'array') {
|
|
9
|
+
const result = {
|
|
10
|
+
label: label,
|
|
11
|
+
value: value
|
|
12
|
+
};
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
else if (return_format === 'label') {
|
|
16
|
+
return label;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps individual ACF field to corresponding value.
|
|
3
|
+
*
|
|
4
|
+
* @param {NextpressField} field - Field configuration.
|
|
5
|
+
* @param {ACFRawValues} rawValues - Raw values map.
|
|
6
|
+
* @returns {Promise<any>} Promise resolving to mapped value.
|
|
7
|
+
*/
|
|
8
|
+
export declare function mapField(field: NextpressField, rawValues: ACFRawValues): Promise<any>;
|
|
9
|
+
/**
|
|
10
|
+
* Maps layout configuration to values object.
|
|
11
|
+
*
|
|
12
|
+
* @param {NextpressLayout} layout - Layout configuration.
|
|
13
|
+
* @param {ACFRawValues} rawValues - Raw values map.
|
|
14
|
+
* @returns {Promise<{ [key: string]: any }>} Promise resolving to layout values object.
|
|
15
|
+
*/
|
|
16
|
+
export declare function mapLayout(layout: NextpressLayout, rawValues: ACFRawValues): Promise<{
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}>;
|