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
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import { unserialize } from "php-serialize";
|
|
2
2
|
import { acfComponentAutoloader } from "../../core/acf-component-autoloader";
|
|
3
|
-
import { ACFGoogleMapsObject, ACFIconObject, ACFLinkObject } from "@/acf-functions/types/components/field-props";
|
|
4
3
|
import { mapChoiceObject } from "./helpers/map-choice-object";
|
|
5
4
|
import { processURL } from "@/services/utilities/process-url";
|
|
6
|
-
|
|
7
5
|
const components = await acfComponentAutoloader();
|
|
8
|
-
|
|
9
6
|
/**
|
|
10
7
|
* Parses PHP serialized string into JavaScript object or array.
|
|
11
8
|
*
|
|
12
9
|
* @param {string} [string] - PHP serialized string.
|
|
13
10
|
* @returns {unknown[] | { [key: string]: unknown }} Parsed object or array.
|
|
14
11
|
*/
|
|
15
|
-
function parsePhp(string
|
|
16
|
-
|
|
12
|
+
function parsePhp(string) {
|
|
13
|
+
var _a;
|
|
14
|
+
return (_a = unserialize(string !== null && string !== void 0 ? string : 'a:0:{}')) !== null && _a !== void 0 ? _a : [];
|
|
17
15
|
}
|
|
18
|
-
|
|
19
16
|
/**
|
|
20
17
|
* Gets array of object IDs from string value.
|
|
21
18
|
*
|
|
@@ -23,17 +20,18 @@ function parsePhp(string?: string): unknown[] | { [key: string]: unknown } {
|
|
|
23
20
|
* @param {boolean} multiple - Indicates if multiple IDs are expected.
|
|
24
21
|
* @returns {number[]} Array of parsed object IDs.
|
|
25
22
|
*/
|
|
26
|
-
function getObjectIDs(value
|
|
23
|
+
function getObjectIDs(value, multiple) {
|
|
24
|
+
var _a;
|
|
27
25
|
if (multiple) {
|
|
28
26
|
const postValueArray = parsePhp(value);
|
|
29
|
-
if (!Array.isArray(postValueArray))
|
|
30
|
-
|
|
27
|
+
if (!Array.isArray(postValueArray))
|
|
28
|
+
return [];
|
|
31
29
|
return postValueArray.map(Number).filter(Boolean);
|
|
32
|
-
}
|
|
33
|
-
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return [(_a = Number(value)) !== null && _a !== void 0 ? _a : 0];
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
|
-
|
|
37
35
|
/**
|
|
38
36
|
* Maps individual ACF field to corresponding value.
|
|
39
37
|
*
|
|
@@ -41,12 +39,13 @@ function getObjectIDs(value: string, multiple: boolean): number[] {
|
|
|
41
39
|
* @param {ACFRawValues} rawValues - Raw values map.
|
|
42
40
|
* @returns {Promise<any>} Promise resolving to mapped value.
|
|
43
41
|
*/
|
|
44
|
-
export async function mapField(field
|
|
42
|
+
export async function mapField(field, rawValues) {
|
|
43
|
+
var _a, _b, _c, _d, _e, _f;
|
|
45
44
|
/**
|
|
46
45
|
* Basic scalar values and strings.
|
|
47
46
|
* These are stored as simple strings in the database and require no complex parsing.
|
|
48
47
|
*/
|
|
49
|
-
switch (field.type){
|
|
48
|
+
switch (field.type) {
|
|
50
49
|
case 'color_picker':
|
|
51
50
|
case 'date_picker':
|
|
52
51
|
case 'date_time_picker':
|
|
@@ -60,7 +59,6 @@ export async function mapField(field: NextpressField, rawValues: ACFRawValues):
|
|
|
60
59
|
case 'file':
|
|
61
60
|
case 'image':
|
|
62
61
|
return rawValues.get(field.name);
|
|
63
|
-
|
|
64
62
|
/**
|
|
65
63
|
* Numeric fields.
|
|
66
64
|
* Casts the raw string from the database into a strict JavaScript Number.
|
|
@@ -68,64 +66,58 @@ export async function mapField(field: NextpressField, rawValues: ACFRawValues):
|
|
|
68
66
|
case 'number':
|
|
69
67
|
case 'range':
|
|
70
68
|
return Number(rawValues.get(field.name));
|
|
71
|
-
|
|
72
69
|
/**
|
|
73
70
|
* True/False boolean field.
|
|
74
71
|
* Converts the truthy/falsy raw string/number into a strict JavaScript boolean.
|
|
75
72
|
*/
|
|
76
73
|
case 'true_false':
|
|
77
74
|
return !!rawValues.get(field.name);
|
|
78
|
-
|
|
79
75
|
/**
|
|
80
76
|
* Google Map field.
|
|
81
77
|
* Deserializes the PHP array containing map data (address, lat, lng) into a structured object.
|
|
82
78
|
*/
|
|
83
79
|
case 'google_map':
|
|
84
80
|
const mapValue = parsePhp(rawValues.get(field.name));
|
|
85
|
-
if (Array.isArray(mapValue))
|
|
86
|
-
|
|
87
|
-
const mapObject
|
|
81
|
+
if (Array.isArray(mapValue))
|
|
82
|
+
return;
|
|
83
|
+
const mapObject = mapValue;
|
|
88
84
|
return mapObject;
|
|
89
|
-
|
|
90
85
|
/**
|
|
91
86
|
* Icon Picker field.
|
|
92
87
|
* Deserializes the PHP array and respects the return format (either a raw string class or an object).
|
|
93
88
|
*/
|
|
94
89
|
case 'icon_picker':
|
|
95
90
|
const iconValue = parsePhp(rawValues.get(field.name));
|
|
96
|
-
if (Array.isArray(iconValue))
|
|
97
|
-
|
|
98
|
-
const iconObject
|
|
91
|
+
if (Array.isArray(iconValue))
|
|
92
|
+
return;
|
|
93
|
+
const iconObject = iconValue;
|
|
99
94
|
if (field.return_format === 'string') {
|
|
100
95
|
return iconObject.value;
|
|
101
|
-
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
102
98
|
return iconObject;
|
|
103
99
|
}
|
|
104
|
-
|
|
105
100
|
/**
|
|
106
101
|
* Button Group field.
|
|
107
102
|
* Maps the selected choice value to its corresponding label/array using the choice map.
|
|
108
103
|
*/
|
|
109
104
|
case 'button_group':
|
|
110
|
-
return mapChoiceObject(field.return_format
|
|
111
|
-
|
|
105
|
+
return mapChoiceObject((_a = field.return_format) !== null && _a !== void 0 ? _a : 'value', rawValues.get(field.name));
|
|
112
106
|
/**
|
|
113
107
|
* Checkbox field.
|
|
114
108
|
* Deserializes the array of selected options and maps each one to the requested return format.
|
|
115
109
|
*/
|
|
116
110
|
case 'checkbox':
|
|
117
111
|
const checkBoxValues = parsePhp(rawValues.get(field.name));
|
|
118
|
-
if (!Array.isArray(checkBoxValues))
|
|
119
|
-
|
|
120
|
-
return checkBoxValues.map(value => mapChoiceObject(field.return_format
|
|
121
|
-
|
|
112
|
+
if (!Array.isArray(checkBoxValues))
|
|
113
|
+
return;
|
|
114
|
+
return checkBoxValues.map(value => { var _a; return mapChoiceObject((_a = field.return_format) !== null && _a !== void 0 ? _a : 'value', typeof value === 'string' ? value : undefined, field.choices); });
|
|
122
115
|
/**
|
|
123
116
|
* Radio field.
|
|
124
117
|
* Maps a single selected choice using the field's available choices.
|
|
125
118
|
*/
|
|
126
119
|
case 'radio':
|
|
127
|
-
return mapChoiceObject(field.return_format
|
|
128
|
-
|
|
120
|
+
return mapChoiceObject((_b = field.return_format) !== null && _b !== void 0 ? _b : 'value', rawValues.get(field.name), field.choices);
|
|
129
121
|
/**
|
|
130
122
|
* Select field.
|
|
131
123
|
* Handles both multi-select (deserializes array) and single-select (processes raw string),
|
|
@@ -134,23 +126,22 @@ export async function mapField(field: NextpressField, rawValues: ACFRawValues):
|
|
|
134
126
|
case 'select':
|
|
135
127
|
if (field.multiple === 1) {
|
|
136
128
|
const selectValues = parsePhp(rawValues.get(field.name));
|
|
137
|
-
if (!Array.isArray(selectValues))
|
|
138
|
-
|
|
139
|
-
return selectValues.map(value => mapChoiceObject(field.return_format
|
|
140
|
-
}
|
|
141
|
-
|
|
129
|
+
if (!Array.isArray(selectValues))
|
|
130
|
+
return;
|
|
131
|
+
return selectValues.map(value => { var _a; return mapChoiceObject((_a = field.return_format) !== null && _a !== void 0 ? _a : 'value', typeof value === 'string' ? value : undefined, field.choices); });
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
return mapChoiceObject((_c = field.return_format) !== null && _c !== void 0 ? _c : 'value', rawValues.get(field.name), field.choices);
|
|
142
135
|
}
|
|
143
|
-
|
|
144
136
|
/**
|
|
145
137
|
* Gallery field.
|
|
146
138
|
* Deserializes the PHP array of image IDs or objects.
|
|
147
139
|
*/
|
|
148
140
|
case 'gallery':
|
|
149
141
|
const galleryValues = parsePhp(rawValues.get(field.name));
|
|
150
|
-
if (!Array.isArray(galleryValues))
|
|
151
|
-
|
|
142
|
+
if (!Array.isArray(galleryValues))
|
|
143
|
+
return;
|
|
152
144
|
return galleryValues;
|
|
153
|
-
|
|
154
145
|
/**
|
|
155
146
|
* Flexible Content field.
|
|
156
147
|
* Iterates over saved layout names, extracts the relevant prefixed sub-fields for each block,
|
|
@@ -158,50 +149,38 @@ export async function mapField(field: NextpressField, rawValues: ACFRawValues):
|
|
|
158
149
|
*/
|
|
159
150
|
case 'flexible_content':
|
|
160
151
|
const layoutValues = parsePhp(rawValues.get(field.name));
|
|
161
|
-
if (!Array.isArray(layoutValues))
|
|
162
|
-
|
|
152
|
+
if (!Array.isArray(layoutValues))
|
|
153
|
+
return;
|
|
163
154
|
const layouts = field.layouts;
|
|
164
155
|
const fcRawEntries = Array.from(rawValues.entries());
|
|
165
|
-
|
|
166
156
|
const promises = layoutValues.map(async (layoutValue, index) => {
|
|
167
|
-
const layout = layouts
|
|
168
|
-
|
|
157
|
+
const layout = layouts === null || layouts === void 0 ? void 0 : layouts.find(layout => layout.name === layoutValue);
|
|
169
158
|
const prefix = `${field.name}_${index}_`;
|
|
170
159
|
const prefixLength = prefix.length;
|
|
171
|
-
|
|
172
|
-
const component = components.find(comp => comp.layout.name === layout?.name);
|
|
173
|
-
|
|
160
|
+
const component = components.find(comp => comp.layout.name === (layout === null || layout === void 0 ? void 0 : layout.name));
|
|
174
161
|
const subFieldEntries = fcRawEntries
|
|
175
162
|
.filter(([key]) => key.startsWith(prefix))
|
|
176
|
-
.map(([key, value]) => [key.slice(prefixLength), value]
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
const resolvedValues = await mapLayout(layout as any, flexibleValues);
|
|
181
|
-
|
|
163
|
+
.map(([key, value]) => [key.slice(prefixLength), value]);
|
|
164
|
+
const flexibleValues = new Map(subFieldEntries);
|
|
165
|
+
const resolvedValues = await mapLayout(layout, flexibleValues);
|
|
182
166
|
return {
|
|
183
|
-
Component: component
|
|
167
|
+
Component: component === null || component === void 0 ? void 0 : component.Component,
|
|
184
168
|
content: resolvedValues
|
|
185
169
|
};
|
|
186
170
|
});
|
|
187
|
-
|
|
188
171
|
return Promise.all(promises);
|
|
189
|
-
|
|
190
172
|
/**
|
|
191
173
|
* Group field.
|
|
192
174
|
* Strips the parent group prefix from the database keys and recursively maps the internal sub-fields.
|
|
193
175
|
*/
|
|
194
176
|
case 'group':
|
|
195
|
-
const groupValues = new Map(
|
|
196
|
-
[
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
);
|
|
203
|
-
return await mapLayout(field as any, groupValues);
|
|
204
|
-
|
|
177
|
+
const groupValues = new Map([...rawValues.entries()]
|
|
178
|
+
.filter(([key]) => key.startsWith(field.name) && key !== field.name)
|
|
179
|
+
.map(([key, value]) => {
|
|
180
|
+
const newKey = key.replace(`${field.name}_`, '');
|
|
181
|
+
return [newKey, value];
|
|
182
|
+
}));
|
|
183
|
+
return await mapLayout(field, groupValues);
|
|
205
184
|
/**
|
|
206
185
|
* Repeater field.
|
|
207
186
|
* Gets the total repeat count, then iterates to extract prefixed sub-fields for each row,
|
|
@@ -210,44 +189,36 @@ export async function mapField(field: NextpressField, rawValues: ACFRawValues):
|
|
|
210
189
|
case 'repeater':
|
|
211
190
|
const repeaterRepeats = Number(rawValues.get(field.name)) || 0;
|
|
212
191
|
const repeaterResults = [];
|
|
213
|
-
|
|
214
192
|
const rRawEntries = Array.from(rawValues.entries());
|
|
215
|
-
|
|
216
193
|
for (let index = 0; index < repeaterRepeats; index++) {
|
|
217
194
|
const prefix = `${field.name}_${index}_`;
|
|
218
195
|
const prefixLength = prefix.length;
|
|
219
|
-
|
|
220
196
|
const subFieldEntries = rRawEntries
|
|
221
197
|
.filter(([key]) => key.startsWith(prefix))
|
|
222
|
-
.map(([key, value]) => [key.slice(prefixLength), value]
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
repeaterResults.push(mapLayout(field as any, repeatValues));
|
|
198
|
+
.map(([key, value]) => [key.slice(prefixLength), value]);
|
|
199
|
+
const repeatValues = new Map(subFieldEntries);
|
|
200
|
+
repeaterResults.push(mapLayout(field, repeatValues));
|
|
227
201
|
}
|
|
228
|
-
|
|
229
202
|
return Promise.all(repeaterResults);
|
|
230
|
-
|
|
231
203
|
/**
|
|
232
204
|
* Link field.
|
|
233
205
|
* Deserializes link properties (title, url, target) and returns either the raw URL string or a structured object.
|
|
234
206
|
*/
|
|
235
207
|
case 'link':
|
|
236
208
|
const linkValue = parsePhp(rawValues.get(field.name));
|
|
237
|
-
if (Array.isArray(linkValue))
|
|
238
|
-
|
|
239
|
-
const linkObject
|
|
209
|
+
if (Array.isArray(linkValue))
|
|
210
|
+
return;
|
|
211
|
+
const linkObject = {
|
|
240
212
|
title: typeof linkValue.title === 'string' ? linkValue.title : '',
|
|
241
213
|
url: typeof linkValue.url === 'string' ? processURL(linkValue.url) : '',
|
|
242
214
|
target: typeof linkValue.target === 'string' ? linkValue.target : '',
|
|
243
|
-
}
|
|
244
|
-
|
|
215
|
+
};
|
|
245
216
|
if (field.return_format === 'url') {
|
|
246
217
|
return linkObject.url;
|
|
247
|
-
} else {
|
|
248
|
-
return linkObject
|
|
249
218
|
}
|
|
250
|
-
|
|
219
|
+
else {
|
|
220
|
+
return linkObject;
|
|
221
|
+
}
|
|
251
222
|
/**
|
|
252
223
|
* Page Link field.
|
|
253
224
|
* Retrieves internal post paths dynamically based on post ID, or falls back to standard external URLs.
|
|
@@ -255,88 +226,82 @@ export async function mapField(field: NextpressField, rawValues: ACFRawValues):
|
|
|
255
226
|
case 'page_link':
|
|
256
227
|
if (field.multiple == 1) {
|
|
257
228
|
const pageLinkValue = parsePhp(rawValues.get(field.name));
|
|
258
|
-
if (!Array.isArray(pageLinkValue))
|
|
229
|
+
if (!Array.isArray(pageLinkValue))
|
|
230
|
+
return;
|
|
259
231
|
const pageLinkIds = pageLinkValue.map(Number).filter(Boolean);
|
|
260
|
-
|
|
261
232
|
const posts = await getPosts(pageLinkIds);
|
|
262
233
|
const postPaths = new Map(posts.map(post => [post.ID, post.path]));
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
234
|
+
return pageLinkValue.map(page => postPaths.has(Number(page)) ? postPaths.get(Number(page)) : processURL(page));
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
266
237
|
const pageLinkValue = rawValues.get(field.name);
|
|
267
238
|
const pageLinkId = Number(rawValues.get(field.name));
|
|
268
|
-
if (!pageLinkValue)
|
|
269
|
-
|
|
270
|
-
return pageLinkId ? (await getPost(pageLinkId))
|
|
239
|
+
if (!pageLinkValue)
|
|
240
|
+
return;
|
|
241
|
+
return pageLinkId ? (_d = (await getPost(pageLinkId))) === null || _d === void 0 ? void 0 : _d.path : processURL(pageLinkValue);
|
|
271
242
|
}
|
|
272
|
-
|
|
273
243
|
/**
|
|
274
244
|
* Post Object field.
|
|
275
245
|
* Returns either the raw Post IDs or uses the Entity Loader to fetch and return the complete post models.
|
|
276
246
|
*/
|
|
277
247
|
case 'post_object':
|
|
278
|
-
const postObjectIds
|
|
279
|
-
|
|
248
|
+
const postObjectIds = getObjectIDs((_e = rawValues.get(field.name)) !== null && _e !== void 0 ? _e : '', !!field.multiple);
|
|
280
249
|
if (field.return_format === 'id') {
|
|
281
250
|
return field.multiple ? postObjectIds : postObjectIds[0];
|
|
282
|
-
}
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
283
253
|
postLoader.prime(postObjectIds);
|
|
284
254
|
const posts = await Promise.all(postObjectIds.map(id => getPost(id)));
|
|
285
255
|
return field.multiple ? posts : posts[0];
|
|
286
256
|
}
|
|
287
|
-
|
|
288
257
|
/**
|
|
289
258
|
* Relationship field.
|
|
290
259
|
* Extracts multiple selected IDs from a PHP array, returning them directly or fetching the associated post models.
|
|
291
260
|
*/
|
|
292
261
|
case 'relationship':
|
|
293
262
|
const relationshipArray = parsePhp(rawValues.get(field.name));
|
|
294
|
-
if (!Array.isArray(relationshipArray))
|
|
295
|
-
|
|
263
|
+
if (!Array.isArray(relationshipArray))
|
|
264
|
+
return [];
|
|
296
265
|
const relationshipIds = relationshipArray.map(Number).filter(Boolean);
|
|
297
|
-
|
|
298
266
|
if (field.return_format === 'id') {
|
|
299
267
|
return relationshipIds;
|
|
300
|
-
}
|
|
268
|
+
}
|
|
269
|
+
{
|
|
301
270
|
postLoader.prime(relationshipIds);
|
|
302
271
|
return await Promise.all(relationshipIds.map(id => getPost(id)));
|
|
303
272
|
}
|
|
304
|
-
|
|
305
273
|
/**
|
|
306
274
|
* Taxonomy field.
|
|
307
275
|
* Parses selected Term IDs and optionally fetches the complete taxonomy Term objects from the database.
|
|
308
276
|
*/
|
|
309
277
|
case 'taxonomy':
|
|
310
|
-
const termObjectIds = parsePhp(rawValues.get(field.name))
|
|
311
|
-
if (!Array.isArray(termObjectIds))
|
|
312
|
-
|
|
278
|
+
const termObjectIds = parsePhp(rawValues.get(field.name));
|
|
279
|
+
if (!Array.isArray(termObjectIds))
|
|
280
|
+
return [];
|
|
313
281
|
const termIds = termObjectIds.map(Number).filter(Boolean);
|
|
314
|
-
|
|
315
282
|
if (field.return_format === 'id') {
|
|
316
283
|
return field.multiple ? termIds : termIds[0];
|
|
317
|
-
}
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
318
286
|
const terms = await Promise.all(termIds.map(id => getTerm(id)));
|
|
319
287
|
return field.multiple ? terms : terms[0];
|
|
320
288
|
}
|
|
321
|
-
|
|
322
289
|
/**
|
|
323
290
|
* User field.
|
|
324
291
|
* Extracts User IDs and returns either the raw IDs or fetches and returns the full User entity objects.
|
|
325
292
|
*/
|
|
326
293
|
case 'user':
|
|
327
|
-
const userObjectIds
|
|
328
|
-
|
|
294
|
+
const userObjectIds = getObjectIDs((_f = rawValues.get(field.name)) !== null && _f !== void 0 ? _f : '', !!field.multiple);
|
|
329
295
|
if (field.return_format === 'id') {
|
|
330
296
|
return field.multiple ? userObjectIds : userObjectIds[0];
|
|
331
|
-
}
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
332
299
|
const users = await Promise.all(userObjectIds.map(id => getUser(id)));
|
|
333
300
|
return field.multiple ? users : users[0];
|
|
334
301
|
}
|
|
335
|
-
|
|
336
|
-
|
|
302
|
+
}
|
|
337
303
|
return undefined;
|
|
338
304
|
}
|
|
339
|
-
|
|
340
305
|
/**
|
|
341
306
|
* Maps layout configuration to values object.
|
|
342
307
|
*
|
|
@@ -344,16 +309,15 @@ export async function mapField(field: NextpressField, rawValues: ACFRawValues):
|
|
|
344
309
|
* @param {ACFRawValues} rawValues - Raw values map.
|
|
345
310
|
* @returns {Promise<{ [key: string]: any }>} Promise resolving to layout values object.
|
|
346
311
|
*/
|
|
347
|
-
export async function mapLayout(layout
|
|
348
|
-
const values
|
|
349
|
-
|
|
312
|
+
export async function mapLayout(layout, rawValues) {
|
|
313
|
+
const values = {};
|
|
350
314
|
for (const subField of layout.sub_fields) {
|
|
351
315
|
try {
|
|
352
|
-
values[subField.name] = await mapField(subField, rawValues)
|
|
353
|
-
}
|
|
316
|
+
values[subField.name] = await mapField(subField, rawValues);
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
354
319
|
console.warn('Failed to map sub field: ', subField.name, error.message);
|
|
355
320
|
}
|
|
356
321
|
}
|
|
357
|
-
|
|
358
322
|
return values;
|
|
359
323
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IOption } from "./option.interface";
|
|
2
|
+
/**
|
|
3
|
+
* Implementation of IOption entity.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Option implements IOption {
|
|
6
|
+
optionId: number;
|
|
7
|
+
constructor(optionId: number);
|
|
8
|
+
/** Raw option data from database. */
|
|
9
|
+
private optionData?;
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves array of Option instances by IDs.
|
|
12
|
+
*
|
|
13
|
+
* @param {number[]} ids - Array of option IDs to retrieve.
|
|
14
|
+
* @returns {Promise<Option[]>} Promise resolving to array of Option instances.
|
|
15
|
+
*/
|
|
16
|
+
static get(ids: number[]): Promise<Option[]>;
|
|
17
|
+
get optionName(): string;
|
|
18
|
+
get optionValue(): string;
|
|
19
|
+
}
|
|
@@ -1,43 +1,36 @@
|
|
|
1
1
|
import { wpdb } from "@/wpdb/wpdb";
|
|
2
|
-
import { IOption } from "./option.interface";
|
|
3
|
-
|
|
4
2
|
/**
|
|
5
3
|
* Implementation of IOption entity.
|
|
6
4
|
*/
|
|
7
|
-
export class Option
|
|
8
|
-
{
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
private optionData?: Record<string, any>;
|
|
13
|
-
|
|
5
|
+
export class Option {
|
|
6
|
+
constructor(optionId) {
|
|
7
|
+
this.optionId = optionId;
|
|
8
|
+
}
|
|
9
|
+
;
|
|
14
10
|
/**
|
|
15
11
|
* Retrieves array of Option instances by IDs.
|
|
16
12
|
*
|
|
17
13
|
* @param {number[]} ids - Array of option IDs to retrieve.
|
|
18
14
|
* @returns {Promise<Option[]>} Promise resolving to array of Option instances.
|
|
19
15
|
*/
|
|
20
|
-
static async get(ids
|
|
16
|
+
static async get(ids) {
|
|
21
17
|
ids = ids.filter(Boolean);
|
|
22
|
-
if (!ids || !ids.length)
|
|
23
|
-
|
|
18
|
+
if (!ids || !ids.length)
|
|
19
|
+
return [];
|
|
24
20
|
const optionData = await wpdb
|
|
25
21
|
.selectFrom('wpOptions')
|
|
26
22
|
.where('optionId', 'in', ids)
|
|
27
23
|
.select(['optionId', 'optionName', 'optionValue'])
|
|
28
24
|
.execute();
|
|
29
|
-
|
|
30
25
|
const optionDataMap = new Map(optionData.map(option => [Number(option.optionId), option]));
|
|
31
|
-
|
|
32
26
|
return ids.map(id => {
|
|
33
27
|
const instance = new Option(id);
|
|
34
|
-
|
|
35
28
|
instance.optionData = optionDataMap.get(id);
|
|
36
|
-
|
|
37
29
|
return instance;
|
|
38
|
-
})
|
|
30
|
+
});
|
|
39
31
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
get optionValue()
|
|
32
|
+
get optionName() { var _a, _b; return (_b = (_a = this.optionData) === null || _a === void 0 ? void 0 : _a['optionName']) !== null && _b !== void 0 ? _b : ''; }
|
|
33
|
+
;
|
|
34
|
+
get optionValue() { var _a, _b; return (_b = (_a = this.optionData) === null || _a === void 0 ? void 0 : _a['optionValue']) !== null && _b !== void 0 ? _b : ''; }
|
|
35
|
+
;
|
|
43
36
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Fields } from "../common";
|
|
2
|
+
import { IPost, PostImageAttributes, MenuItemAttributes } from "./post.interface";
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of IPost entity.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Post implements IPost {
|
|
7
|
+
ID: number;
|
|
8
|
+
constructor(ID: number);
|
|
9
|
+
/** Raw post data from database. */
|
|
10
|
+
private postData?;
|
|
11
|
+
/** Map of post meta key-value pairs. */
|
|
12
|
+
private metaMap?;
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves array of Post instances by IDs.
|
|
15
|
+
*
|
|
16
|
+
* @param {number[]} ids - Array of post IDs to retrieve.
|
|
17
|
+
* @returns {Promise<Post[]>} Promise resolving to array of Post instances.
|
|
18
|
+
*/
|
|
19
|
+
static get(ids: number[]): Promise<Post[]>;
|
|
20
|
+
get path(): string;
|
|
21
|
+
get thumbnailId(): number;
|
|
22
|
+
private _imageAttributes?;
|
|
23
|
+
get imageAttributes(): PostImageAttributes;
|
|
24
|
+
private _menuItemAttributes?;
|
|
25
|
+
get menuItemAttributes(): MenuItemAttributes | null;
|
|
26
|
+
private _postExcerpt?;
|
|
27
|
+
get postExcerpt(): string;
|
|
28
|
+
get commentCount(): number;
|
|
29
|
+
get commentStatus(): string;
|
|
30
|
+
get guid(): string;
|
|
31
|
+
get menuOrder(): number;
|
|
32
|
+
get pinged(): string;
|
|
33
|
+
get pingStatus(): string;
|
|
34
|
+
get postAuthor(): number;
|
|
35
|
+
get postContent(): string;
|
|
36
|
+
get postContentFiltered(): string;
|
|
37
|
+
get postDate(): Date;
|
|
38
|
+
get postDateGmt(): Date;
|
|
39
|
+
get postMimeType(): string;
|
|
40
|
+
get postModified(): Date;
|
|
41
|
+
get postModifiedGmt(): Date;
|
|
42
|
+
get postName(): string;
|
|
43
|
+
get postParent(): number;
|
|
44
|
+
get postPassword(): string;
|
|
45
|
+
get postStatus(): string;
|
|
46
|
+
get postTitle(): string;
|
|
47
|
+
get postType(): string;
|
|
48
|
+
get toPing(): string;
|
|
49
|
+
getFields(name: string): Promise<Fields>;
|
|
50
|
+
}
|