nextpress-core 1.0.3 → 2.0.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/cli/install.js +27 -0
- package/{dist/acf-functions/core/acf-builder.js → lib/acf-functions/core/acf-builder.ts} +45 -17
- package/{dist/acf-functions/core/acf-component-autoloader.js → lib/acf-functions/core/acf-component-autoloader.ts} +13 -7
- package/{dist/acf-functions/core/acf-field-group-autoloader.js → lib/acf-functions/core/acf-field-group-autoloader.ts} +11 -5
- package/{dist/acf-functions/services/define-field-group.d.ts → lib/acf-functions/services/define-field-group.ts} +4 -1
- package/{dist/acf-functions/services/define-layout.d.ts → lib/acf-functions/services/define-layout.ts} +4 -1
- package/lib/acf-functions/services/map-fields/helpers/map-choice-object.ts +20 -0
- package/{dist/acf-functions/services/map-fields/map-fields.js → lib/acf-functions/services/map-fields/map-fields.ts} +128 -89
- package/{dist/acf-functions/types/acf-field-group.d.ts → lib/acf-functions/types/acf-field-group.ts} +49 -28
- package/lib/acf-functions/types/acf-field.ts +2853 -0
- package/lib/acf-functions/types/acf-layout.ts +22 -0
- package/lib/acf-functions/types/components/field-props.ts +189 -0
- package/{dist/acf-functions/types/components/nextpress-component.d.ts → lib/acf-functions/types/components/nextpress-component.ts} +4 -3
- package/lib/ambient.d.ts +16 -0
- package/{dist/entities/common.d.ts → lib/entities/common.ts} +6 -4
- package/{dist/entities/option/option.interface.d.ts → lib/entities/option/option.interface.ts} +3 -3
- package/{dist/entities/option/option.js → lib/entities/option/option.ts} +21 -14
- package/{dist/entities/post/post.interface.d.ts → lib/entities/post/post.interface.ts} +26 -21
- package/lib/entities/post/post.ts +209 -0
- package/{dist/entities/term/term.interface.d.ts → lib/entities/term/term.interface.ts} +3 -3
- package/lib/entities/term/term.ts +82 -0
- package/{dist/entities/user/user.interface.d.ts → lib/entities/user/user.interface.ts} +2 -1
- package/lib/entities/user/user.ts +86 -0
- package/{dist/globals/entity-loader/entity-loader-base.js → lib/globals/entity-loader/entity-loader-base.ts} +64 -10
- package/{dist/globals/entity-loader/entity-loader.interface.d.ts → lib/globals/entity-loader/entity-loader.ts} +2 -4
- package/lib/globals/entity-loader/option-loader.ts +56 -0
- package/lib/globals/entity-loader/post-loader.ts +60 -0
- package/lib/globals/entity-loader/term-loader.ts +60 -0
- package/lib/globals/entity-loader/user-loader.ts +61 -0
- package/lib/globals/get-field/get-field.ts +76 -0
- package/{dist/globals/globals.js → lib/globals/globals.ts} +8 -3
- package/{dist/globals/nextpress-config/nextpress-config.interface.d.ts → lib/globals/nextpress-config/nextpress-config.interface.ts} +10 -6
- package/lib/globals/nextpress-config/nextpress-config.ts +8 -0
- package/lib/globals/queried-object/queried-object.ts +124 -0
- package/{dist/repository/optionquery/option-query-args.d.ts → lib/repository/optionquery/option-query-args.ts} +5 -2
- package/lib/repository/optionquery/option-query.ts +29 -0
- package/{dist/repository/postquery/post-query-args.d.ts → lib/repository/postquery/post-query-args.ts} +10 -6
- package/lib/repository/postquery/post-query.ts +282 -0
- package/{dist/repository/termquery/term-query-args.d.ts → lib/repository/termquery/term-query-args.ts} +16 -6
- package/lib/repository/termquery/term-query.ts +244 -0
- package/{dist/repository/userquery/user-query-args.d.ts → lib/repository/userquery/user-query-args.ts} +19 -7
- package/{dist/repository/userquery/user-query.js → lib/repository/userquery/user-query.ts} +93 -76
- package/{dist/router/helpers.js → lib/router/helpers.ts} +4 -4
- package/{dist/router/nextpress-layout.js → lib/router/nextpress-layout.tsx} +28 -9
- package/{dist/router/routes/not-found-page.js → lib/router/nextpress-not-found-route.tsx} +7 -5
- package/{dist/router/nextpress-proxy.js → lib/router/nextpress-proxy.ts} +15 -3
- package/{dist/router/nextpress-static-params.js → lib/router/nextpress-static-params.ts} +17 -5
- package/{dist/router/router.js → lib/router/router.tsx} +29 -22
- package/{dist/router/routes/api/api-get-admin-bar.js → lib/router/routes/api/api-get-admin-bar.ts} +8 -6
- package/{dist/router/routes/api/api-get-draft-mode.js → lib/router/routes/api/api-get-draft-mode.ts} +15 -6
- package/{dist/router/routes/api/api-get-field-groups.js → lib/router/routes/api/api-get-field-groups.ts} +13 -8
- package/{dist/router/routes/api/api-post-revalidate.js → lib/router/routes/api/api-post-revalidate.ts} +6 -4
- package/{dist/router/routes/api/helpers.js → lib/router/routes/api/helpers.ts} +4 -3
- package/lib/router/routes/author-archive.tsx +75 -0
- package/lib/router/routes/post-index-page.tsx +58 -0
- package/lib/router/routes/singular-page.tsx +78 -0
- package/lib/router/routes/site-front-page.tsx +51 -0
- package/lib/router/routes/term-archive.tsx +93 -0
- package/{dist/router/types.d.ts → lib/router/types.ts} +4 -2
- package/{dist/services/get-menu.js → lib/services/get-menu.ts} +56 -32
- package/{dist/services/get-theme-mods.js → lib/services/get-theme-mods.ts} +6 -4
- package/{dist/services/metadata/get-blogname.js → lib/services/metadata/get-blogname.ts} +2 -2
- package/{dist/services/metadata/get-favicon-url.js → lib/services/metadata/get-favicon-url.ts} +5 -4
- package/{dist/services/metadata/get-language-attribute.js → lib/services/metadata/get-language-attribute.ts} +1 -1
- package/{dist/services/utilities/capitalise-first-letter.js → lib/services/utilities/capitalise-first-letter.ts} +2 -3
- package/{dist/services/utilities/esc-html.js → lib/services/utilities/esc-html.ts} +3 -1
- package/{dist/services/utilities/get-date-time-formatter.js → lib/services/utilities/get-date-time-formatter.ts} +16 -6
- package/{dist/services/utilities/kses-post.js → lib/services/utilities/kses-post.ts} +2 -1
- package/{dist/services/utilities/process-url.js → lib/services/utilities/process-url.ts} +4 -3
- package/{dist/template-heirarchy/_autoloader/template-autoloader.js → lib/template-heirarchy/_autoloader/template-autoloader.ts} +18 -9
- package/{dist/template-heirarchy/archive/archive.js → lib/template-heirarchy/archive/archive.tsx} +10 -7
- package/{dist/template-heirarchy/archive/author.js → lib/template-heirarchy/archive/author.tsx} +10 -7
- package/{dist/template-heirarchy/archive/category.js → lib/template-heirarchy/archive/category.tsx} +11 -7
- package/{dist/template-heirarchy/archive/posttypearchive.js → lib/template-heirarchy/archive/posttypearchive.tsx} +11 -8
- package/{dist/template-heirarchy/archive/tag.js → lib/template-heirarchy/archive/tag.tsx} +12 -7
- package/{dist/template-heirarchy/archive/taxonomy.js → lib/template-heirarchy/archive/taxonomy.tsx} +10 -7
- package/{dist/template-heirarchy/home/home.js → lib/template-heirarchy/home/home.tsx} +10 -7
- package/{dist/template-heirarchy/index.js → lib/template-heirarchy/index.tsx} +9 -5
- package/{dist/template-heirarchy/not-found.tsx/not-found.js → lib/template-heirarchy/not-found.tsx/not-found.tsx} +10 -7
- package/{dist/template-heirarchy/page/page.js → lib/template-heirarchy/page/page.tsx} +10 -7
- package/{dist/template-heirarchy/page/posttype.js → lib/template-heirarchy/page/posttype.tsx} +12 -8
- package/{dist/template-heirarchy/page/single.js → lib/template-heirarchy/page/single.tsx} +10 -7
- package/{dist/template-heirarchy/page/singular.js → lib/template-heirarchy/page/singular.tsx} +10 -7
- package/lib/ui/render-attachment-image.tsx +28 -0
- package/lib/ui/render-components.tsx +12 -0
- package/lib/ui/render-the-admin-bar.tsx +79 -0
- package/lib/ui/render-the-logo.tsx +24 -0
- package/{dist/wpdb/wpdb.interface.d.ts → lib/wpdb/wpdb.interface.ts} +20 -1
- package/{dist/wpdb/wpdb.js → lib/wpdb/wpdb.ts} +9 -5
- package/package.json +8 -15
- package/dist/acf-functions/core/acf-builder.d.ts +0 -51
- package/dist/acf-functions/core/acf-component-autoloader.d.ts +0 -11
- package/dist/acf-functions/core/acf-field-group-autoloader.d.ts +0 -10
- package/dist/acf-functions/field-props.d.ts +0 -196
- package/dist/acf-functions/field-props.js +0 -1
- package/dist/acf-functions/services/define-field-group.js +0 -10
- package/dist/acf-functions/services/define-layout.js +0 -10
- package/dist/acf-functions/services/map-fields/helpers/map-choice-object.d.ts +0 -2
- package/dist/acf-functions/services/map-fields/helpers/map-choice-object.js +0 -18
- package/dist/acf-functions/services/map-fields/map-fields.d.ts +0 -21
- package/dist/acf-functions/types/acf-field-group.js +0 -1
- package/dist/acf-functions/types/acf-field.d.ts +0 -2813
- package/dist/acf-functions/types/acf-field.js +0 -1
- package/dist/acf-functions/types/acf-layout.d.ts +0 -19
- package/dist/acf-functions/types/acf-layout.js +0 -1
- package/dist/acf-functions/types/acf-values.js +0 -1
- package/dist/acf-functions/types/components/field-props.d.ts +0 -196
- package/dist/acf-functions/types/components/field-props.js +0 -1
- package/dist/acf-functions/types/components/nextpress-component.js +0 -1
- package/dist/entities/common.js +0 -1
- package/dist/entities/option/option.d.ts +0 -19
- package/dist/entities/option/option.interface.js +0 -2
- package/dist/entities/post/post.d.ts +0 -50
- package/dist/entities/post/post.interface.js +0 -2
- package/dist/entities/post/post.js +0 -184
- package/dist/entities/term/term.d.ts +0 -28
- package/dist/entities/term/term.interface.js +0 -1
- package/dist/entities/term/term.js +0 -67
- package/dist/entities/user/user.d.ts +0 -27
- package/dist/entities/user/user.interface.js +0 -1
- package/dist/entities/user/user.js +0 -74
- package/dist/globals/entity-loader/entity-loader-base.d.ts +0 -65
- package/dist/globals/entity-loader/entity-loader.interface.js +0 -1
- package/dist/globals/entity-loader/option-loader.d.ts +0 -15
- package/dist/globals/entity-loader/option-loader.js +0 -31
- package/dist/globals/entity-loader/post-loader.d.ts +0 -21
- package/dist/globals/entity-loader/post-loader.js +0 -28
- package/dist/globals/entity-loader/term-loader.d.ts +0 -21
- package/dist/globals/entity-loader/term-loader.js +0 -28
- package/dist/globals/entity-loader/user-loader.d.ts +0 -21
- package/dist/globals/entity-loader/user-loader.js +0 -28
- package/dist/globals/get-field/get-field.d.ts +0 -18
- package/dist/globals/get-field/get-field.js +0 -44
- package/dist/globals/globals.d.ts +0 -18
- package/dist/globals/nextpress-config/nextpress-config.d.ts +0 -4
- package/dist/globals/nextpress-config/nextpress-config.interface.js +0 -1
- package/dist/globals/nextpress-config/nextpress-config.js +0 -2
- package/dist/globals/queried-object/queried-object.d.ts +0 -62
- package/dist/globals/queried-object/queried-object.js +0 -56
- package/dist/repository/optionquery/option-query-args.js +0 -1
- package/dist/repository/optionquery/option-query.d.ts +0 -12
- package/dist/repository/optionquery/option-query.js +0 -20
- package/dist/repository/postquery/post-query-args.js +0 -1
- package/dist/repository/postquery/post-query.d.ts +0 -12
- package/dist/repository/postquery/post-query.js +0 -272
- package/dist/repository/termquery/term-query-args.js +0 -1
- package/dist/repository/termquery/term-query.d.ts +0 -11
- package/dist/repository/termquery/term-query.js +0 -213
- package/dist/repository/userquery/user-query-args.js +0 -1
- package/dist/repository/userquery/user-query.d.ts +0 -12
- package/dist/router/helpers.d.ts +0 -14
- package/dist/router/nextpress-layout.d.ts +0 -11
- package/dist/router/nextpress-proxy.d.ts +0 -8
- package/dist/router/nextpress-static-params.d.ts +0 -9
- package/dist/router/router.d.ts +0 -23
- package/dist/router/routes/api/api-get-admin-bar.d.ts +0 -8
- package/dist/router/routes/api/api-get-draft-mode.d.ts +0 -8
- package/dist/router/routes/api/api-get-field-groups.d.ts +0 -7
- package/dist/router/routes/api/api-post-revalidate.d.ts +0 -7
- package/dist/router/routes/api/helpers.d.ts +0 -8
- package/dist/router/routes/author-archive.d.ts +0 -25
- package/dist/router/routes/author-archive.js +0 -49
- package/dist/router/routes/not-found-page.d.ts +0 -15
- package/dist/router/routes/post-index-page.d.ts +0 -25
- package/dist/router/routes/post-index-page.js +0 -33
- package/dist/router/routes/singular-page.d.ts +0 -29
- package/dist/router/routes/singular-page.js +0 -51
- package/dist/router/routes/site-front-page.d.ts +0 -27
- package/dist/router/routes/site-front-page.js +0 -26
- package/dist/router/routes/term-archive.d.ts +0 -29
- package/dist/router/routes/term-archive.js +0 -65
- package/dist/router/types.js +0 -1
- package/dist/services/get-menu.d.ts +0 -13
- package/dist/services/get-theme-mods.d.ts +0 -7
- package/dist/services/metadata/get-blogname.d.ts +0 -6
- package/dist/services/metadata/get-favicon-url.d.ts +0 -6
- package/dist/services/metadata/get-language-attribute.d.ts +0 -6
- package/dist/services/services.d.ts +0 -3
- package/dist/services/services.js +0 -3
- package/dist/services/utilities/capitalise-first-letter.d.ts +0 -7
- package/dist/services/utilities/esc-html.d.ts +0 -7
- package/dist/services/utilities/get-date-time-formatter.d.ts +0 -6
- package/dist/services/utilities/index.d.ts +0 -0
- package/dist/services/utilities/index.js +0 -1
- package/dist/services/utilities/kses-post.d.ts +0 -7
- package/dist/services/utilities/process-url.d.ts +0 -7
- package/dist/template-heirarchy/_autoloader/template-autoloader.d.ts +0 -9
- package/dist/template-heirarchy/archive/archive.d.ts +0 -16
- package/dist/template-heirarchy/archive/author.d.ts +0 -16
- package/dist/template-heirarchy/archive/category.d.ts +0 -16
- package/dist/template-heirarchy/archive/posttypearchive.d.ts +0 -24
- package/dist/template-heirarchy/archive/tag.d.ts +0 -16
- package/dist/template-heirarchy/archive/taxonomy.d.ts +0 -16
- package/dist/template-heirarchy/home/home.d.ts +0 -16
- package/dist/template-heirarchy/index.d.ts +0 -17
- package/dist/template-heirarchy/not-found.tsx/not-found.d.ts +0 -16
- package/dist/template-heirarchy/page/page.d.ts +0 -16
- package/dist/template-heirarchy/page/posttype.d.ts +0 -24
- package/dist/template-heirarchy/page/single.d.ts +0 -16
- package/dist/template-heirarchy/page/singular.d.ts +0 -16
- package/dist/ui/render-attachment-image.d.ts +0 -12
- package/dist/ui/render-attachment-image.js +0 -24
- package/dist/ui/render-components.d.ts +0 -9
- package/dist/ui/render-components.js +0 -7
- package/dist/ui/render-the-admin-bar.d.ts +0 -8
- package/dist/ui/render-the-admin-bar.js +0 -36
- package/dist/ui/render-the-logo.d.ts +0 -10
- package/dist/ui/render-the-logo.js +0 -16
- package/dist/wpdb/wpdb.d.ts +0 -3
- package/dist/wpdb/wpdb.interface.js +0 -5
- /package/{dist/acf-functions/types/acf-values.d.ts → lib/acf-functions/types/acf-values.ts} +0 -0
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import { unserialize } from "php-serialize";
|
|
2
2
|
import { acfComponentAutoloader } from "../../core/acf-component-autoloader";
|
|
3
|
+
import { ACFGoogleMapsObject, ACFIconObject, ACFLinkObject } from "nextpress/acf-functions/types/components/field-props";
|
|
4
|
+
import { NextpressField } from "nextpress/acf-functions/types/acf-field";
|
|
5
|
+
import { NextpressLayout } from "nextpress/acf-functions/types/acf-layout";
|
|
6
|
+
import { ACFRawValues } from "nextpress/acf-functions/types/acf-values";
|
|
3
7
|
import { mapChoiceObject } from "./helpers/map-choice-object";
|
|
4
|
-
import { processURL } from "
|
|
8
|
+
import { processURL } from "nextpress/services/utilities/process-url";
|
|
9
|
+
|
|
5
10
|
const components = await acfComponentAutoloader();
|
|
11
|
+
|
|
6
12
|
/**
|
|
7
13
|
* Parses PHP serialized string into JavaScript object or array.
|
|
8
14
|
*
|
|
9
15
|
* @param {string} [string] - PHP serialized string.
|
|
10
16
|
* @returns {unknown[] | { [key: string]: unknown }} Parsed object or array.
|
|
11
17
|
*/
|
|
12
|
-
function parsePhp(string) {
|
|
13
|
-
|
|
14
|
-
return (_a = unserialize(string !== null && string !== void 0 ? string : 'a:0:{}')) !== null && _a !== void 0 ? _a : [];
|
|
18
|
+
function parsePhp(string?: string): unknown[] | { [key: string]: unknown } {
|
|
19
|
+
return unserialize(string ?? 'a:0:{}') ?? [];
|
|
15
20
|
}
|
|
21
|
+
|
|
16
22
|
/**
|
|
17
23
|
* Gets array of object IDs from string value.
|
|
18
24
|
*
|
|
@@ -20,18 +26,17 @@ function parsePhp(string) {
|
|
|
20
26
|
* @param {boolean} multiple - Indicates if multiple IDs are expected.
|
|
21
27
|
* @returns {number[]} Array of parsed object IDs.
|
|
22
28
|
*/
|
|
23
|
-
function getObjectIDs(value, multiple) {
|
|
24
|
-
var _a;
|
|
29
|
+
function getObjectIDs(value: string, multiple: boolean): number[] {
|
|
25
30
|
if (multiple) {
|
|
26
31
|
const postValueArray = parsePhp(value);
|
|
27
|
-
if (!Array.isArray(postValueArray))
|
|
28
|
-
|
|
32
|
+
if (!Array.isArray(postValueArray)) return [];
|
|
33
|
+
|
|
29
34
|
return postValueArray.map(Number).filter(Boolean);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return [(_a = Number(value)) !== null && _a !== void 0 ? _a : 0];
|
|
35
|
+
} else {
|
|
36
|
+
return [Number(value) ?? 0]
|
|
33
37
|
}
|
|
34
38
|
}
|
|
39
|
+
|
|
35
40
|
/**
|
|
36
41
|
* Maps individual ACF field to corresponding value.
|
|
37
42
|
*
|
|
@@ -39,13 +44,12 @@ function getObjectIDs(value, multiple) {
|
|
|
39
44
|
* @param {ACFRawValues} rawValues - Raw values map.
|
|
40
45
|
* @returns {Promise<any>} Promise resolving to mapped value.
|
|
41
46
|
*/
|
|
42
|
-
export async function mapField(field, rawValues) {
|
|
43
|
-
var _a, _b, _c, _d, _e, _f;
|
|
47
|
+
export async function mapField(field: NextpressField, rawValues: ACFRawValues): Promise<any> {
|
|
44
48
|
/**
|
|
45
49
|
* Basic scalar values and strings.
|
|
46
50
|
* These are stored as simple strings in the database and require no complex parsing.
|
|
47
51
|
*/
|
|
48
|
-
switch (field.type)
|
|
52
|
+
switch (field.type){
|
|
49
53
|
case 'color_picker':
|
|
50
54
|
case 'date_picker':
|
|
51
55
|
case 'date_time_picker':
|
|
@@ -59,6 +63,7 @@ export async function mapField(field, rawValues) {
|
|
|
59
63
|
case 'file':
|
|
60
64
|
case 'image':
|
|
61
65
|
return rawValues.get(field.name);
|
|
66
|
+
|
|
62
67
|
/**
|
|
63
68
|
* Numeric fields.
|
|
64
69
|
* Casts the raw string from the database into a strict JavaScript Number.
|
|
@@ -66,58 +71,64 @@ export async function mapField(field, rawValues) {
|
|
|
66
71
|
case 'number':
|
|
67
72
|
case 'range':
|
|
68
73
|
return Number(rawValues.get(field.name));
|
|
74
|
+
|
|
69
75
|
/**
|
|
70
76
|
* True/False boolean field.
|
|
71
77
|
* Converts the truthy/falsy raw string/number into a strict JavaScript boolean.
|
|
72
78
|
*/
|
|
73
79
|
case 'true_false':
|
|
74
80
|
return !!rawValues.get(field.name);
|
|
81
|
+
|
|
75
82
|
/**
|
|
76
83
|
* Google Map field.
|
|
77
84
|
* Deserializes the PHP array containing map data (address, lat, lng) into a structured object.
|
|
78
85
|
*/
|
|
79
86
|
case 'google_map':
|
|
80
87
|
const mapValue = parsePhp(rawValues.get(field.name));
|
|
81
|
-
if (Array.isArray(mapValue))
|
|
82
|
-
|
|
83
|
-
const mapObject = mapValue;
|
|
88
|
+
if (Array.isArray(mapValue)) return;
|
|
89
|
+
|
|
90
|
+
const mapObject: ACFGoogleMapsObject = mapValue as ACFGoogleMapsObject;
|
|
84
91
|
return mapObject;
|
|
92
|
+
|
|
85
93
|
/**
|
|
86
94
|
* Icon Picker field.
|
|
87
95
|
* Deserializes the PHP array and respects the return format (either a raw string class or an object).
|
|
88
96
|
*/
|
|
89
97
|
case 'icon_picker':
|
|
90
98
|
const iconValue = parsePhp(rawValues.get(field.name));
|
|
91
|
-
if (Array.isArray(iconValue))
|
|
92
|
-
|
|
93
|
-
const iconObject = iconValue;
|
|
99
|
+
if (Array.isArray(iconValue)) return;
|
|
100
|
+
|
|
101
|
+
const iconObject: ACFIconObject = iconValue as ACFIconObject;
|
|
94
102
|
if (field.return_format === 'string') {
|
|
95
103
|
return iconObject.value;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
104
|
+
} else {
|
|
98
105
|
return iconObject;
|
|
99
106
|
}
|
|
107
|
+
|
|
100
108
|
/**
|
|
101
109
|
* Button Group field.
|
|
102
110
|
* Maps the selected choice value to its corresponding label/array using the choice map.
|
|
103
111
|
*/
|
|
104
112
|
case 'button_group':
|
|
105
|
-
return mapChoiceObject(
|
|
113
|
+
return mapChoiceObject(field.return_format ?? 'value', rawValues.get(field.name));
|
|
114
|
+
|
|
106
115
|
/**
|
|
107
116
|
* Checkbox field.
|
|
108
117
|
* Deserializes the array of selected options and maps each one to the requested return format.
|
|
109
118
|
*/
|
|
110
119
|
case 'checkbox':
|
|
111
120
|
const checkBoxValues = parsePhp(rawValues.get(field.name));
|
|
112
|
-
if (!Array.isArray(checkBoxValues))
|
|
113
|
-
|
|
114
|
-
return checkBoxValues.map(value =>
|
|
121
|
+
if (!Array.isArray(checkBoxValues)) return;
|
|
122
|
+
|
|
123
|
+
return checkBoxValues.map(value => mapChoiceObject(field.return_format ?? 'value', typeof value === 'string' ? value : undefined, field.choices));
|
|
124
|
+
|
|
115
125
|
/**
|
|
116
126
|
* Radio field.
|
|
117
127
|
* Maps a single selected choice using the field's available choices.
|
|
118
128
|
*/
|
|
119
129
|
case 'radio':
|
|
120
|
-
return mapChoiceObject(
|
|
130
|
+
return mapChoiceObject(field.return_format ?? 'value', rawValues.get(field.name), field.choices);
|
|
131
|
+
|
|
121
132
|
/**
|
|
122
133
|
* Select field.
|
|
123
134
|
* Handles both multi-select (deserializes array) and single-select (processes raw string),
|
|
@@ -126,22 +137,23 @@ export async function mapField(field, rawValues) {
|
|
|
126
137
|
case 'select':
|
|
127
138
|
if (field.multiple === 1) {
|
|
128
139
|
const selectValues = parsePhp(rawValues.get(field.name));
|
|
129
|
-
if (!Array.isArray(selectValues))
|
|
130
|
-
|
|
131
|
-
return selectValues.map(value =>
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return mapChoiceObject((_c = field.return_format) !== null && _c !== void 0 ? _c : 'value', rawValues.get(field.name), field.choices);
|
|
140
|
+
if (!Array.isArray(selectValues)) return;
|
|
141
|
+
|
|
142
|
+
return selectValues.map(value => mapChoiceObject(field.return_format ?? 'value', typeof value === 'string' ? value : undefined, field.choices));
|
|
143
|
+
} else {
|
|
144
|
+
return mapChoiceObject(field.return_format ?? 'value', rawValues.get(field.name), field.choices);
|
|
135
145
|
}
|
|
146
|
+
|
|
136
147
|
/**
|
|
137
148
|
* Gallery field.
|
|
138
149
|
* Deserializes the PHP array of image IDs or objects.
|
|
139
150
|
*/
|
|
140
151
|
case 'gallery':
|
|
141
152
|
const galleryValues = parsePhp(rawValues.get(field.name));
|
|
142
|
-
if (!Array.isArray(galleryValues))
|
|
143
|
-
|
|
153
|
+
if (!Array.isArray(galleryValues)) return;
|
|
154
|
+
|
|
144
155
|
return galleryValues;
|
|
156
|
+
|
|
145
157
|
/**
|
|
146
158
|
* Flexible Content field.
|
|
147
159
|
* Iterates over saved layout names, extracts the relevant prefixed sub-fields for each block,
|
|
@@ -149,38 +161,50 @@ export async function mapField(field, rawValues) {
|
|
|
149
161
|
*/
|
|
150
162
|
case 'flexible_content':
|
|
151
163
|
const layoutValues = parsePhp(rawValues.get(field.name));
|
|
152
|
-
if (!Array.isArray(layoutValues))
|
|
153
|
-
|
|
164
|
+
if (!Array.isArray(layoutValues)) return;
|
|
165
|
+
|
|
154
166
|
const layouts = field.layouts;
|
|
155
167
|
const fcRawEntries = Array.from(rawValues.entries());
|
|
168
|
+
|
|
156
169
|
const promises = layoutValues.map(async (layoutValue, index) => {
|
|
157
|
-
const layout = layouts
|
|
170
|
+
const layout = layouts?.find(layout => layout.name === layoutValue);
|
|
171
|
+
|
|
158
172
|
const prefix = `${field.name}_${index}_`;
|
|
159
173
|
const prefixLength = prefix.length;
|
|
160
|
-
|
|
174
|
+
|
|
175
|
+
const component = components.find(comp => comp.layout.name === layout?.name);
|
|
176
|
+
|
|
161
177
|
const subFieldEntries = fcRawEntries
|
|
162
178
|
.filter(([key]) => key.startsWith(prefix))
|
|
163
|
-
.map(([key, value]) => [key.slice(prefixLength), value]);
|
|
164
|
-
|
|
165
|
-
const
|
|
179
|
+
.map(([key, value]) => [key.slice(prefixLength), value] as [string, any]);
|
|
180
|
+
|
|
181
|
+
const flexibleValues = new Map<string, any>(subFieldEntries);
|
|
182
|
+
|
|
183
|
+
const resolvedValues = await mapLayout(layout as any, flexibleValues);
|
|
184
|
+
|
|
166
185
|
return {
|
|
167
|
-
Component: component
|
|
186
|
+
Component: component?.Component,
|
|
168
187
|
content: resolvedValues
|
|
169
188
|
};
|
|
170
189
|
});
|
|
190
|
+
|
|
171
191
|
return Promise.all(promises);
|
|
192
|
+
|
|
172
193
|
/**
|
|
173
194
|
* Group field.
|
|
174
195
|
* Strips the parent group prefix from the database keys and recursively maps the internal sub-fields.
|
|
175
196
|
*/
|
|
176
197
|
case 'group':
|
|
177
|
-
const groupValues = new Map(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
198
|
+
const groupValues = new Map(
|
|
199
|
+
[...rawValues.entries()]
|
|
200
|
+
.filter(([key]) => key.startsWith(field.name) && key !== field.name)
|
|
201
|
+
.map(([key, value]) => {
|
|
202
|
+
const newKey = key.replace(`${field.name}_`, '');
|
|
203
|
+
return [newKey, value];
|
|
204
|
+
})
|
|
205
|
+
);
|
|
206
|
+
return await mapLayout(field as any, groupValues);
|
|
207
|
+
|
|
184
208
|
/**
|
|
185
209
|
* Repeater field.
|
|
186
210
|
* Gets the total repeat count, then iterates to extract prefixed sub-fields for each row,
|
|
@@ -189,36 +213,44 @@ export async function mapField(field, rawValues) {
|
|
|
189
213
|
case 'repeater':
|
|
190
214
|
const repeaterRepeats = Number(rawValues.get(field.name)) || 0;
|
|
191
215
|
const repeaterResults = [];
|
|
216
|
+
|
|
192
217
|
const rRawEntries = Array.from(rawValues.entries());
|
|
218
|
+
|
|
193
219
|
for (let index = 0; index < repeaterRepeats; index++) {
|
|
194
220
|
const prefix = `${field.name}_${index}_`;
|
|
195
221
|
const prefixLength = prefix.length;
|
|
222
|
+
|
|
196
223
|
const subFieldEntries = rRawEntries
|
|
197
224
|
.filter(([key]) => key.startsWith(prefix))
|
|
198
|
-
.map(([key, value]) => [key.slice(prefixLength), value]);
|
|
199
|
-
|
|
200
|
-
|
|
225
|
+
.map(([key, value]) => [key.slice(prefixLength), value] as [string, any]);
|
|
226
|
+
|
|
227
|
+
const repeatValues = new Map<string, any>(subFieldEntries);
|
|
228
|
+
|
|
229
|
+
repeaterResults.push(mapLayout(field as any, repeatValues));
|
|
201
230
|
}
|
|
231
|
+
|
|
202
232
|
return Promise.all(repeaterResults);
|
|
233
|
+
|
|
203
234
|
/**
|
|
204
235
|
* Link field.
|
|
205
236
|
* Deserializes link properties (title, url, target) and returns either the raw URL string or a structured object.
|
|
206
237
|
*/
|
|
207
238
|
case 'link':
|
|
208
239
|
const linkValue = parsePhp(rawValues.get(field.name));
|
|
209
|
-
if (Array.isArray(linkValue))
|
|
210
|
-
|
|
211
|
-
const linkObject = {
|
|
240
|
+
if (Array.isArray(linkValue)) return;
|
|
241
|
+
|
|
242
|
+
const linkObject: ACFLinkObject = {
|
|
212
243
|
title: typeof linkValue.title === 'string' ? linkValue.title : '',
|
|
213
244
|
url: typeof linkValue.url === 'string' ? processURL(linkValue.url) : '',
|
|
214
245
|
target: typeof linkValue.target === 'string' ? linkValue.target : '',
|
|
215
|
-
}
|
|
246
|
+
}
|
|
247
|
+
|
|
216
248
|
if (field.return_format === 'url') {
|
|
217
249
|
return linkObject.url;
|
|
250
|
+
} else {
|
|
251
|
+
return linkObject
|
|
218
252
|
}
|
|
219
|
-
|
|
220
|
-
return linkObject;
|
|
221
|
-
}
|
|
253
|
+
|
|
222
254
|
/**
|
|
223
255
|
* Page Link field.
|
|
224
256
|
* Retrieves internal post paths dynamically based on post ID, or falls back to standard external URLs.
|
|
@@ -226,82 +258,88 @@ export async function mapField(field, rawValues) {
|
|
|
226
258
|
case 'page_link':
|
|
227
259
|
if (field.multiple == 1) {
|
|
228
260
|
const pageLinkValue = parsePhp(rawValues.get(field.name));
|
|
229
|
-
if (!Array.isArray(pageLinkValue))
|
|
230
|
-
return;
|
|
261
|
+
if (!Array.isArray(pageLinkValue)) return;
|
|
231
262
|
const pageLinkIds = pageLinkValue.map(Number).filter(Boolean);
|
|
263
|
+
|
|
232
264
|
const posts = await getPosts(pageLinkIds);
|
|
233
265
|
const postPaths = new Map(posts.map(post => [post.ID, post.path]));
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
else {
|
|
266
|
+
|
|
267
|
+
return pageLinkValue.map(page => postPaths.has(Number(page)) ? postPaths.get(Number(page)) : processURL(page as string));
|
|
268
|
+
} else {
|
|
237
269
|
const pageLinkValue = rawValues.get(field.name);
|
|
238
270
|
const pageLinkId = Number(rawValues.get(field.name));
|
|
239
|
-
if (!pageLinkValue)
|
|
240
|
-
|
|
241
|
-
return pageLinkId ? (
|
|
271
|
+
if (!pageLinkValue) return;
|
|
272
|
+
|
|
273
|
+
return pageLinkId ? (await getPost(pageLinkId))?.path : processURL(pageLinkValue);
|
|
242
274
|
}
|
|
275
|
+
|
|
243
276
|
/**
|
|
244
277
|
* Post Object field.
|
|
245
278
|
* Returns either the raw Post IDs or uses the Entity Loader to fetch and return the complete post models.
|
|
246
279
|
*/
|
|
247
280
|
case 'post_object':
|
|
248
|
-
const postObjectIds = getObjectIDs(
|
|
281
|
+
const postObjectIds: number[] = getObjectIDs(rawValues.get(field.name) ?? '', !!field.multiple)
|
|
282
|
+
|
|
249
283
|
if (field.return_format === 'id') {
|
|
250
284
|
return field.multiple ? postObjectIds : postObjectIds[0];
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
285
|
+
} else {
|
|
253
286
|
postLoader.prime(postObjectIds);
|
|
254
287
|
const posts = await Promise.all(postObjectIds.map(id => getPost(id)));
|
|
255
288
|
return field.multiple ? posts : posts[0];
|
|
256
289
|
}
|
|
290
|
+
|
|
257
291
|
/**
|
|
258
292
|
* Relationship field.
|
|
259
293
|
* Extracts multiple selected IDs from a PHP array, returning them directly or fetching the associated post models.
|
|
260
294
|
*/
|
|
261
295
|
case 'relationship':
|
|
262
296
|
const relationshipArray = parsePhp(rawValues.get(field.name));
|
|
263
|
-
if (!Array.isArray(relationshipArray))
|
|
264
|
-
|
|
297
|
+
if (!Array.isArray(relationshipArray)) return [];
|
|
298
|
+
|
|
265
299
|
const relationshipIds = relationshipArray.map(Number).filter(Boolean);
|
|
300
|
+
|
|
266
301
|
if (field.return_format === 'id') {
|
|
267
302
|
return relationshipIds;
|
|
268
|
-
}
|
|
269
|
-
{
|
|
303
|
+
} {
|
|
270
304
|
postLoader.prime(relationshipIds);
|
|
271
305
|
return await Promise.all(relationshipIds.map(id => getPost(id)));
|
|
272
306
|
}
|
|
307
|
+
|
|
273
308
|
/**
|
|
274
309
|
* Taxonomy field.
|
|
275
310
|
* Parses selected Term IDs and optionally fetches the complete taxonomy Term objects from the database.
|
|
276
311
|
*/
|
|
277
312
|
case 'taxonomy':
|
|
278
|
-
const termObjectIds = parsePhp(rawValues.get(field.name))
|
|
279
|
-
if (!Array.isArray(termObjectIds))
|
|
280
|
-
|
|
313
|
+
const termObjectIds = parsePhp(rawValues.get(field.name))
|
|
314
|
+
if (!Array.isArray(termObjectIds)) return [];
|
|
315
|
+
|
|
281
316
|
const termIds = termObjectIds.map(Number).filter(Boolean);
|
|
317
|
+
|
|
282
318
|
if (field.return_format === 'id') {
|
|
283
319
|
return field.multiple ? termIds : termIds[0];
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
320
|
+
} else {
|
|
286
321
|
const terms = await Promise.all(termIds.map(id => getTerm(id)));
|
|
287
322
|
return field.multiple ? terms : terms[0];
|
|
288
323
|
}
|
|
324
|
+
|
|
289
325
|
/**
|
|
290
326
|
* User field.
|
|
291
327
|
* Extracts User IDs and returns either the raw IDs or fetches and returns the full User entity objects.
|
|
292
328
|
*/
|
|
293
329
|
case 'user':
|
|
294
|
-
const userObjectIds = getObjectIDs(
|
|
330
|
+
const userObjectIds: number[] = getObjectIDs(rawValues.get(field.name) ?? '', !!field.multiple)
|
|
331
|
+
|
|
295
332
|
if (field.return_format === 'id') {
|
|
296
333
|
return field.multiple ? userObjectIds : userObjectIds[0];
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
334
|
+
} else {
|
|
299
335
|
const users = await Promise.all(userObjectIds.map(id => getUser(id)));
|
|
300
336
|
return field.multiple ? users : users[0];
|
|
301
337
|
}
|
|
302
|
-
|
|
338
|
+
}
|
|
339
|
+
|
|
303
340
|
return undefined;
|
|
304
341
|
}
|
|
342
|
+
|
|
305
343
|
/**
|
|
306
344
|
* Maps layout configuration to values object.
|
|
307
345
|
*
|
|
@@ -309,15 +347,16 @@ export async function mapField(field, rawValues) {
|
|
|
309
347
|
* @param {ACFRawValues} rawValues - Raw values map.
|
|
310
348
|
* @returns {Promise<{ [key: string]: any }>} Promise resolving to layout values object.
|
|
311
349
|
*/
|
|
312
|
-
export async function mapLayout(layout, rawValues)
|
|
313
|
-
const values = {};
|
|
350
|
+
export async function mapLayout(layout: NextpressLayout, rawValues: ACFRawValues) {
|
|
351
|
+
const values: { [key: string]: any } = {};
|
|
352
|
+
|
|
314
353
|
for (const subField of layout.sub_fields) {
|
|
315
354
|
try {
|
|
316
|
-
values[subField.name] = await mapField(subField, rawValues)
|
|
317
|
-
}
|
|
318
|
-
catch (error) {
|
|
355
|
+
values[subField.name] = await mapField(subField, rawValues)
|
|
356
|
+
} catch (error: any) {
|
|
319
357
|
console.warn('Failed to map sub field: ', subField.name, error.message);
|
|
320
358
|
}
|
|
321
359
|
}
|
|
360
|
+
|
|
322
361
|
return values;
|
|
323
362
|
}
|
package/{dist/acf-functions/types/acf-field-group.d.ts → lib/acf-functions/types/acf-field-group.ts}
RENAMED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { NextpressField, ACFField } from "./acf-field";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
|
|
3
|
+
type TransformACFFieldGroup<T> = T extends any
|
|
4
|
+
? Omit<T, 'key' | 'fields'> &
|
|
5
|
+
('fields' extends keyof T ? { fields: NextpressField[] } : [])
|
|
6
|
+
: never;
|
|
7
|
+
|
|
5
8
|
/** ACF Field Group without key constraints to allow key generation */
|
|
6
|
-
export type NextpressFieldGroup = TransformACFFieldGroup<ACFFieldGroup
|
|
9
|
+
export type NextpressFieldGroup = TransformACFFieldGroup<ACFFieldGroup>
|
|
10
|
+
|
|
7
11
|
/**
|
|
8
12
|
* Represents an Advanced Custom Fields (ACF) Field Group configuration.
|
|
9
13
|
*/
|
|
@@ -11,89 +15,106 @@ export interface ACFFieldGroup {
|
|
|
11
15
|
/**
|
|
12
16
|
* Unique identifier for the field group with group_ prefix (e.g. 'group_abc123')
|
|
13
17
|
*/
|
|
14
|
-
key: string
|
|
18
|
+
key: string
|
|
15
19
|
/**
|
|
16
20
|
* The title/name of this entity
|
|
17
21
|
*/
|
|
18
|
-
title: string
|
|
22
|
+
title: string
|
|
19
23
|
/**
|
|
20
24
|
* Array of field definitions. If empty array, field group appears but contains no fields.
|
|
21
25
|
*/
|
|
22
|
-
fields: ACFField[]
|
|
26
|
+
fields: ACFField[]
|
|
23
27
|
/**
|
|
24
28
|
* The order of this entity in the admin menu
|
|
25
29
|
*/
|
|
26
|
-
menu_order?: number
|
|
30
|
+
menu_order?: number
|
|
27
31
|
/**
|
|
28
32
|
* [ACF] Whether this entity is active
|
|
29
33
|
*/
|
|
30
|
-
active?: boolean
|
|
34
|
+
active?: boolean
|
|
31
35
|
/**
|
|
32
36
|
* [ACF Export Only] Unix timestamp of last modification
|
|
33
37
|
*/
|
|
34
|
-
modified?: number
|
|
38
|
+
modified?: number
|
|
35
39
|
/**
|
|
36
40
|
* Location rules determining where this field group appears. Array of rule groups (OR logic between groups, AND logic within groups). If omitted or empty, field group won't appear on any edit screens.
|
|
37
41
|
*/
|
|
38
|
-
location?: ACFLocationGroup[]
|
|
42
|
+
location?: ACFLocationGroup[]
|
|
39
43
|
/**
|
|
40
44
|
* Position of the field group on the edit screen
|
|
41
45
|
*/
|
|
42
|
-
position?: "normal" | "side" | "acf_after_title"
|
|
46
|
+
position?: "normal" | "side" | "acf_after_title"
|
|
43
47
|
/**
|
|
44
48
|
* Visual style of the field group metabox
|
|
45
49
|
*/
|
|
46
|
-
style?: "default" | "seamless"
|
|
50
|
+
style?: "default" | "seamless"
|
|
47
51
|
/**
|
|
48
52
|
* Placement of field labels relative to fields
|
|
49
53
|
*/
|
|
50
|
-
label_placement?: "top" | "left"
|
|
54
|
+
label_placement?: "top" | "left"
|
|
51
55
|
/**
|
|
52
56
|
* Placement of field instructions
|
|
53
57
|
*/
|
|
54
|
-
instruction_placement?: "label" | "field"
|
|
58
|
+
instruction_placement?: "label" | "field"
|
|
55
59
|
/**
|
|
56
60
|
* Screen elements to hide when this field group is displayed
|
|
57
61
|
*/
|
|
58
|
-
hide_on_screen?: (
|
|
62
|
+
hide_on_screen?: (
|
|
63
|
+
| "permalink"
|
|
64
|
+
| "the_content"
|
|
65
|
+
| "excerpt"
|
|
66
|
+
| "custom_fields"
|
|
67
|
+
| "discussion"
|
|
68
|
+
| "comments"
|
|
69
|
+
| "revisions"
|
|
70
|
+
| "slug"
|
|
71
|
+
| "author"
|
|
72
|
+
| "format"
|
|
73
|
+
| "page_attributes"
|
|
74
|
+
| "featured_image"
|
|
75
|
+
| "categories"
|
|
76
|
+
| "tags"
|
|
77
|
+
| "send-trackbacks"
|
|
78
|
+
)[]
|
|
59
79
|
/**
|
|
60
80
|
* Description of the field group
|
|
61
81
|
*/
|
|
62
|
-
description?: string
|
|
82
|
+
description?: string
|
|
63
83
|
/**
|
|
64
84
|
* Whether to expose this field group's fields in the REST API
|
|
65
85
|
*/
|
|
66
|
-
show_in_rest?: boolean | number
|
|
86
|
+
show_in_rest?: boolean | number
|
|
67
87
|
/**
|
|
68
88
|
* Whether to expose this field group to AI integrations
|
|
69
89
|
*/
|
|
70
|
-
allow_ai_access?: boolean | number
|
|
90
|
+
allow_ai_access?: boolean | number
|
|
71
91
|
/**
|
|
72
92
|
* Description that helps AI integrations understand how to use this field group
|
|
73
93
|
*/
|
|
74
|
-
ai_description?: string
|
|
94
|
+
ai_description?: string
|
|
75
95
|
/**
|
|
76
96
|
* Alternative display title for the field group
|
|
77
97
|
*/
|
|
78
|
-
display_title?: string
|
|
98
|
+
display_title?: string
|
|
79
99
|
}
|
|
100
|
+
|
|
80
101
|
/**
|
|
81
102
|
* Group of location rules (AND logic within group)
|
|
82
103
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
104
|
+
type ACFLocationGroup = [ACFLocationRule, ...ACFLocationRule[]]
|
|
105
|
+
|
|
106
|
+
interface ACFLocationRule {
|
|
85
107
|
/**
|
|
86
108
|
* The parameter to compare (e.g. 'post_type', 'page_template', 'user_role')
|
|
87
109
|
*/
|
|
88
|
-
param: string
|
|
110
|
+
param: string
|
|
89
111
|
/**
|
|
90
112
|
* Comparison operator
|
|
91
113
|
*/
|
|
92
|
-
operator: "==" | "!="
|
|
114
|
+
operator: "==" | "!="
|
|
93
115
|
/**
|
|
94
116
|
* Value to compare against
|
|
95
117
|
*/
|
|
96
|
-
value: string
|
|
97
|
-
[k: string]: unknown
|
|
118
|
+
value: string
|
|
119
|
+
[k: string]: unknown
|
|
98
120
|
}
|
|
99
|
-
export {};
|