nextpress-core 1.1.0 → 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.
Files changed (227) hide show
  1. package/cli/install.js +27 -0
  2. package/{dist/acf-functions/core/acf-builder.js → lib/acf-functions/core/acf-builder.ts} +45 -17
  3. package/{dist/acf-functions/core/acf-component-autoloader.js → lib/acf-functions/core/acf-component-autoloader.ts} +13 -7
  4. package/{dist/acf-functions/core/acf-field-group-autoloader.js → lib/acf-functions/core/acf-field-group-autoloader.ts} +11 -5
  5. package/{dist/acf-functions/services/define-field-group.d.ts → lib/acf-functions/services/define-field-group.ts} +4 -1
  6. package/{dist/acf-functions/services/define-layout.d.ts → lib/acf-functions/services/define-layout.ts} +4 -1
  7. package/lib/acf-functions/services/map-fields/helpers/map-choice-object.ts +20 -0
  8. package/{dist/acf-functions/services/map-fields/map-fields.js → lib/acf-functions/services/map-fields/map-fields.ts} +128 -89
  9. package/{dist/acf-functions/types/acf-field-group.d.ts → lib/acf-functions/types/acf-field-group.ts} +49 -28
  10. package/lib/acf-functions/types/acf-field.ts +2853 -0
  11. package/lib/acf-functions/types/acf-layout.ts +22 -0
  12. package/lib/acf-functions/types/components/field-props.ts +189 -0
  13. package/{dist/acf-functions/types/components/nextpress-component.d.ts → lib/acf-functions/types/components/nextpress-component.ts} +4 -3
  14. package/lib/ambient.d.ts +16 -0
  15. package/{dist/entities/common.d.ts → lib/entities/common.ts} +6 -4
  16. package/{dist/entities/option/option.interface.d.ts → lib/entities/option/option.interface.ts} +3 -3
  17. package/{dist/entities/option/option.js → lib/entities/option/option.ts} +21 -14
  18. package/{dist/entities/post/post.interface.d.ts → lib/entities/post/post.interface.ts} +26 -21
  19. package/lib/entities/post/post.ts +209 -0
  20. package/{dist/entities/term/term.interface.d.ts → lib/entities/term/term.interface.ts} +3 -3
  21. package/lib/entities/term/term.ts +82 -0
  22. package/{dist/entities/user/user.interface.d.ts → lib/entities/user/user.interface.ts} +2 -1
  23. package/lib/entities/user/user.ts +86 -0
  24. package/{dist/globals/entity-loader/entity-loader-base.js → lib/globals/entity-loader/entity-loader-base.ts} +64 -10
  25. package/{dist/globals/entity-loader/entity-loader.interface.d.ts → lib/globals/entity-loader/entity-loader.ts} +2 -4
  26. package/lib/globals/entity-loader/option-loader.ts +56 -0
  27. package/lib/globals/entity-loader/post-loader.ts +60 -0
  28. package/lib/globals/entity-loader/term-loader.ts +60 -0
  29. package/lib/globals/entity-loader/user-loader.ts +61 -0
  30. package/lib/globals/get-field/get-field.ts +76 -0
  31. package/{dist/globals/globals.js → lib/globals/globals.ts} +8 -3
  32. package/{dist/globals/nextpress-config/nextpress-config.interface.d.ts → lib/globals/nextpress-config/nextpress-config.interface.ts} +10 -6
  33. package/lib/globals/nextpress-config/nextpress-config.ts +8 -0
  34. package/lib/globals/queried-object/queried-object.ts +124 -0
  35. package/{dist/repository/optionquery/option-query-args.d.ts → lib/repository/optionquery/option-query-args.ts} +5 -2
  36. package/lib/repository/optionquery/option-query.ts +29 -0
  37. package/{dist/repository/postquery/post-query-args.d.ts → lib/repository/postquery/post-query-args.ts} +10 -6
  38. package/lib/repository/postquery/post-query.ts +282 -0
  39. package/{dist/repository/termquery/term-query-args.d.ts → lib/repository/termquery/term-query-args.ts} +16 -6
  40. package/lib/repository/termquery/term-query.ts +244 -0
  41. package/{dist/repository/userquery/user-query-args.d.ts → lib/repository/userquery/user-query-args.ts} +19 -7
  42. package/{dist/repository/userquery/user-query.js → lib/repository/userquery/user-query.ts} +93 -76
  43. package/{dist/router/helpers.js → lib/router/helpers.ts} +4 -4
  44. package/{dist/router/nextpress-layout.js → lib/router/nextpress-layout.tsx} +28 -9
  45. package/{dist/router/routes/not-found-page.js → lib/router/nextpress-not-found-route.tsx} +7 -5
  46. package/{dist/router/nextpress-proxy.js → lib/router/nextpress-proxy.ts} +15 -3
  47. package/{dist/router/nextpress-static-params.js → lib/router/nextpress-static-params.ts} +17 -5
  48. package/{dist/router/router.js → lib/router/router.tsx} +29 -22
  49. package/{dist/router/routes/api/api-get-admin-bar.js → lib/router/routes/api/api-get-admin-bar.ts} +8 -6
  50. package/{dist/router/routes/api/api-get-draft-mode.js → lib/router/routes/api/api-get-draft-mode.ts} +15 -6
  51. package/{dist/router/routes/api/api-get-field-groups.js → lib/router/routes/api/api-get-field-groups.ts} +13 -8
  52. package/{dist/router/routes/api/api-post-revalidate.js → lib/router/routes/api/api-post-revalidate.ts} +6 -4
  53. package/{dist/router/routes/api/helpers.js → lib/router/routes/api/helpers.ts} +4 -3
  54. package/lib/router/routes/author-archive.tsx +75 -0
  55. package/lib/router/routes/post-index-page.tsx +58 -0
  56. package/lib/router/routes/singular-page.tsx +78 -0
  57. package/lib/router/routes/site-front-page.tsx +51 -0
  58. package/lib/router/routes/term-archive.tsx +93 -0
  59. package/{dist/router/types.d.ts → lib/router/types.ts} +4 -2
  60. package/{dist/services/get-menu.js → lib/services/get-menu.ts} +56 -32
  61. package/{dist/services/get-theme-mods.js → lib/services/get-theme-mods.ts} +6 -4
  62. package/{dist/services/metadata/get-blogname.js → lib/services/metadata/get-blogname.ts} +2 -2
  63. package/{dist/services/metadata/get-favicon-url.js → lib/services/metadata/get-favicon-url.ts} +5 -4
  64. package/{dist/services/metadata/get-language-attribute.js → lib/services/metadata/get-language-attribute.ts} +1 -1
  65. package/{dist/services/utilities/capitalise-first-letter.js → lib/services/utilities/capitalise-first-letter.ts} +2 -3
  66. package/{dist/services/utilities/esc-html.js → lib/services/utilities/esc-html.ts} +3 -1
  67. package/{dist/services/utilities/get-date-time-formatter.js → lib/services/utilities/get-date-time-formatter.ts} +16 -6
  68. package/{dist/services/utilities/kses-post.js → lib/services/utilities/kses-post.ts} +2 -1
  69. package/{dist/services/utilities/process-url.js → lib/services/utilities/process-url.ts} +4 -3
  70. package/{dist/template-heirarchy/_autoloader/template-autoloader.js → lib/template-heirarchy/_autoloader/template-autoloader.ts} +18 -9
  71. package/{dist/template-heirarchy/archive/archive.js → lib/template-heirarchy/archive/archive.tsx} +10 -7
  72. package/{dist/template-heirarchy/archive/author.js → lib/template-heirarchy/archive/author.tsx} +10 -7
  73. package/{dist/template-heirarchy/archive/category.js → lib/template-heirarchy/archive/category.tsx} +11 -7
  74. package/{dist/template-heirarchy/archive/posttypearchive.js → lib/template-heirarchy/archive/posttypearchive.tsx} +11 -8
  75. package/{dist/template-heirarchy/archive/tag.js → lib/template-heirarchy/archive/tag.tsx} +12 -7
  76. package/{dist/template-heirarchy/archive/taxonomy.js → lib/template-heirarchy/archive/taxonomy.tsx} +10 -7
  77. package/{dist/template-heirarchy/home/home.js → lib/template-heirarchy/home/home.tsx} +10 -7
  78. package/{dist/template-heirarchy/index.js → lib/template-heirarchy/index.tsx} +9 -5
  79. package/{dist/template-heirarchy/not-found.tsx/not-found.js → lib/template-heirarchy/not-found.tsx/not-found.tsx} +10 -7
  80. package/{dist/template-heirarchy/page/page.js → lib/template-heirarchy/page/page.tsx} +10 -7
  81. package/{dist/template-heirarchy/page/posttype.js → lib/template-heirarchy/page/posttype.tsx} +12 -8
  82. package/{dist/template-heirarchy/page/single.js → lib/template-heirarchy/page/single.tsx} +10 -7
  83. package/{dist/template-heirarchy/page/singular.js → lib/template-heirarchy/page/singular.tsx} +10 -7
  84. package/lib/ui/render-attachment-image.tsx +28 -0
  85. package/lib/ui/render-components.tsx +12 -0
  86. package/lib/ui/render-the-admin-bar.tsx +79 -0
  87. package/lib/ui/render-the-logo.tsx +24 -0
  88. package/{dist/wpdb/wpdb.interface.d.ts → lib/wpdb/wpdb.interface.ts} +20 -1
  89. package/{dist/wpdb/wpdb.js → lib/wpdb/wpdb.ts} +9 -5
  90. package/package.json +8 -43
  91. package/dist/acf-functions/core/acf-builder.d.ts +0 -51
  92. package/dist/acf-functions/core/acf-component-autoloader.d.ts +0 -11
  93. package/dist/acf-functions/core/acf-field-group-autoloader.d.ts +0 -10
  94. package/dist/acf-functions/field-props.d.ts +0 -196
  95. package/dist/acf-functions/field-props.js +0 -1
  96. package/dist/acf-functions/index.d.ts +0 -13
  97. package/dist/acf-functions/index.js +0 -13
  98. package/dist/acf-functions/services/define-field-group.js +0 -10
  99. package/dist/acf-functions/services/define-layout.js +0 -10
  100. package/dist/acf-functions/services/map-fields/helpers/map-choice-object.d.ts +0 -2
  101. package/dist/acf-functions/services/map-fields/helpers/map-choice-object.js +0 -18
  102. package/dist/acf-functions/services/map-fields/map-fields.d.ts +0 -21
  103. package/dist/acf-functions/types/acf-field-group.js +0 -1
  104. package/dist/acf-functions/types/acf-field.d.ts +0 -2813
  105. package/dist/acf-functions/types/acf-field.js +0 -1
  106. package/dist/acf-functions/types/acf-layout.d.ts +0 -19
  107. package/dist/acf-functions/types/acf-layout.js +0 -1
  108. package/dist/acf-functions/types/acf-values.js +0 -1
  109. package/dist/acf-functions/types/components/field-props.d.ts +0 -196
  110. package/dist/acf-functions/types/components/field-props.js +0 -1
  111. package/dist/acf-functions/types/components/nextpress-component.js +0 -1
  112. package/dist/entities/common.js +0 -1
  113. package/dist/entities/index.d.ts +0 -9
  114. package/dist/entities/index.js +0 -9
  115. package/dist/entities/option/option.d.ts +0 -19
  116. package/dist/entities/option/option.interface.js +0 -2
  117. package/dist/entities/post/post.d.ts +0 -50
  118. package/dist/entities/post/post.interface.js +0 -2
  119. package/dist/entities/post/post.js +0 -184
  120. package/dist/entities/term/term.d.ts +0 -28
  121. package/dist/entities/term/term.interface.js +0 -1
  122. package/dist/entities/term/term.js +0 -67
  123. package/dist/entities/user/user.d.ts +0 -27
  124. package/dist/entities/user/user.interface.js +0 -1
  125. package/dist/entities/user/user.js +0 -74
  126. package/dist/globals/entity-loader/entity-loader-base.d.ts +0 -65
  127. package/dist/globals/entity-loader/entity-loader.interface.js +0 -1
  128. package/dist/globals/entity-loader/option-loader.d.ts +0 -15
  129. package/dist/globals/entity-loader/option-loader.js +0 -31
  130. package/dist/globals/entity-loader/post-loader.d.ts +0 -21
  131. package/dist/globals/entity-loader/post-loader.js +0 -28
  132. package/dist/globals/entity-loader/term-loader.d.ts +0 -21
  133. package/dist/globals/entity-loader/term-loader.js +0 -28
  134. package/dist/globals/entity-loader/user-loader.d.ts +0 -21
  135. package/dist/globals/entity-loader/user-loader.js +0 -28
  136. package/dist/globals/get-field/get-field.d.ts +0 -18
  137. package/dist/globals/get-field/get-field.js +0 -44
  138. package/dist/globals/globals.d.ts +0 -18
  139. package/dist/globals/index.d.ts +0 -10
  140. package/dist/globals/index.js +0 -10
  141. package/dist/globals/nextpress-config/nextpress-config.d.ts +0 -4
  142. package/dist/globals/nextpress-config/nextpress-config.interface.js +0 -1
  143. package/dist/globals/nextpress-config/nextpress-config.js +0 -2
  144. package/dist/globals/queried-object/queried-object.d.ts +0 -62
  145. package/dist/globals/queried-object/queried-object.js +0 -56
  146. package/dist/repository/index.d.ts +0 -5
  147. package/dist/repository/index.js +0 -5
  148. package/dist/repository/optionquery/option-query-args.js +0 -1
  149. package/dist/repository/optionquery/option-query.d.ts +0 -12
  150. package/dist/repository/optionquery/option-query.js +0 -20
  151. package/dist/repository/postquery/post-query-args.js +0 -1
  152. package/dist/repository/postquery/post-query.d.ts +0 -12
  153. package/dist/repository/postquery/post-query.js +0 -272
  154. package/dist/repository/termquery/term-query-args.js +0 -1
  155. package/dist/repository/termquery/term-query.d.ts +0 -11
  156. package/dist/repository/termquery/term-query.js +0 -213
  157. package/dist/repository/userquery/user-query-args.js +0 -1
  158. package/dist/repository/userquery/user-query.d.ts +0 -12
  159. package/dist/router/helpers.d.ts +0 -14
  160. package/dist/router/index.d.ts +0 -17
  161. package/dist/router/index.js +0 -17
  162. package/dist/router/nextpress-layout.d.ts +0 -11
  163. package/dist/router/nextpress-proxy.d.ts +0 -8
  164. package/dist/router/nextpress-static-params.d.ts +0 -9
  165. package/dist/router/router.d.ts +0 -23
  166. package/dist/router/routes/api/api-get-admin-bar.d.ts +0 -8
  167. package/dist/router/routes/api/api-get-draft-mode.d.ts +0 -8
  168. package/dist/router/routes/api/api-get-field-groups.d.ts +0 -7
  169. package/dist/router/routes/api/api-post-revalidate.d.ts +0 -7
  170. package/dist/router/routes/api/helpers.d.ts +0 -8
  171. package/dist/router/routes/author-archive.d.ts +0 -25
  172. package/dist/router/routes/author-archive.js +0 -49
  173. package/dist/router/routes/not-found-page.d.ts +0 -15
  174. package/dist/router/routes/post-index-page.d.ts +0 -25
  175. package/dist/router/routes/post-index-page.js +0 -33
  176. package/dist/router/routes/singular-page.d.ts +0 -29
  177. package/dist/router/routes/singular-page.js +0 -51
  178. package/dist/router/routes/site-front-page.d.ts +0 -27
  179. package/dist/router/routes/site-front-page.js +0 -26
  180. package/dist/router/routes/term-archive.d.ts +0 -29
  181. package/dist/router/routes/term-archive.js +0 -65
  182. package/dist/router/types.js +0 -1
  183. package/dist/services/get-menu.d.ts +0 -13
  184. package/dist/services/get-theme-mods.d.ts +0 -7
  185. package/dist/services/index.d.ts +0 -10
  186. package/dist/services/index.js +0 -10
  187. package/dist/services/metadata/get-blogname.d.ts +0 -6
  188. package/dist/services/metadata/get-favicon-url.d.ts +0 -6
  189. package/dist/services/metadata/get-language-attribute.d.ts +0 -6
  190. package/dist/services/services.d.ts +0 -3
  191. package/dist/services/services.js +0 -3
  192. package/dist/services/utilities/capitalise-first-letter.d.ts +0 -7
  193. package/dist/services/utilities/esc-html.d.ts +0 -7
  194. package/dist/services/utilities/get-date-time-formatter.d.ts +0 -6
  195. package/dist/services/utilities/index.d.ts +0 -0
  196. package/dist/services/utilities/index.js +0 -1
  197. package/dist/services/utilities/kses-post.d.ts +0 -7
  198. package/dist/services/utilities/process-url.d.ts +0 -7
  199. package/dist/template-heirarchy/_autoloader/template-autoloader.d.ts +0 -9
  200. package/dist/template-heirarchy/archive/archive.d.ts +0 -16
  201. package/dist/template-heirarchy/archive/author.d.ts +0 -16
  202. package/dist/template-heirarchy/archive/category.d.ts +0 -16
  203. package/dist/template-heirarchy/archive/posttypearchive.d.ts +0 -24
  204. package/dist/template-heirarchy/archive/tag.d.ts +0 -16
  205. package/dist/template-heirarchy/archive/taxonomy.d.ts +0 -16
  206. package/dist/template-heirarchy/home/home.d.ts +0 -16
  207. package/dist/template-heirarchy/index.d.ts +0 -17
  208. package/dist/template-heirarchy/not-found.tsx/not-found.d.ts +0 -16
  209. package/dist/template-heirarchy/page/page.d.ts +0 -16
  210. package/dist/template-heirarchy/page/posttype.d.ts +0 -24
  211. package/dist/template-heirarchy/page/single.d.ts +0 -16
  212. package/dist/template-heirarchy/page/singular.d.ts +0 -16
  213. package/dist/ui/index.d.ts +0 -4
  214. package/dist/ui/index.js +0 -4
  215. package/dist/ui/render-attachment-image.d.ts +0 -12
  216. package/dist/ui/render-attachment-image.js +0 -24
  217. package/dist/ui/render-components.d.ts +0 -9
  218. package/dist/ui/render-components.js +0 -7
  219. package/dist/ui/render-the-admin-bar.d.ts +0 -8
  220. package/dist/ui/render-the-admin-bar.js +0 -36
  221. package/dist/ui/render-the-logo.d.ts +0 -10
  222. package/dist/ui/render-the-logo.js +0 -16
  223. package/dist/wpdb/index.d.ts +0 -0
  224. package/dist/wpdb/index.js +0 -1
  225. package/dist/wpdb/wpdb.d.ts +0 -3
  226. package/dist/wpdb/wpdb.interface.js +0 -5
  227. /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 "@/services/utilities/process-url";
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
- var _a;
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
- return [];
32
+ if (!Array.isArray(postValueArray)) return [];
33
+
29
34
  return postValueArray.map(Number).filter(Boolean);
30
- }
31
- else {
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
- return;
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
- return;
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((_a = field.return_format) !== null && _a !== void 0 ? _a : 'value', rawValues.get(field.name));
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
- 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); });
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((_b = field.return_format) !== null && _b !== void 0 ? _b : 'value', rawValues.get(field.name), field.choices);
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
- 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);
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
- return;
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
- return;
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 === null || layouts === void 0 ? void 0 : layouts.find(layout => layout.name === layoutValue);
170
+ const layout = layouts?.find(layout => layout.name === layoutValue);
171
+
158
172
  const prefix = `${field.name}_${index}_`;
159
173
  const prefixLength = prefix.length;
160
- const component = components.find(comp => comp.layout.name === (layout === null || layout === void 0 ? void 0 : layout.name));
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
- const flexibleValues = new Map(subFieldEntries);
165
- const resolvedValues = await mapLayout(layout, flexibleValues);
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 === null || component === void 0 ? void 0 : 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([...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);
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
- const repeatValues = new Map(subFieldEntries);
200
- repeaterResults.push(mapLayout(field, repeatValues));
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
- return;
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
- else {
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
- return pageLinkValue.map(page => postPaths.has(Number(page)) ? postPaths.get(Number(page)) : processURL(page));
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
- return;
241
- return pageLinkId ? (_d = (await getPost(pageLinkId))) === null || _d === void 0 ? void 0 : _d.path : processURL(pageLinkValue);
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((_e = rawValues.get(field.name)) !== null && _e !== void 0 ? _e : '', !!field.multiple);
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
- return [];
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
- return [];
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((_f = rawValues.get(field.name)) !== null && _f !== void 0 ? _f : '', !!field.multiple);
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
  }
@@ -1,9 +1,13 @@
1
1
  import { NextpressField, ACFField } from "./acf-field";
2
- type TransformACFFieldGroup<T> = T extends any ? Omit<T, 'key' | 'fields'> & ('fields' extends keyof T ? {
3
- fields: NextpressField[];
4
- } : []) : never;
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?: ("permalink" | "the_content" | "excerpt" | "custom_fields" | "discussion" | "comments" | "revisions" | "slug" | "author" | "format" | "page_attributes" | "featured_image" | "categories" | "tags" | "send-trackbacks")[];
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
- export type ACFLocationGroup = [ACFLocationRule, ...ACFLocationRule[]];
84
- export interface ACFLocationRule {
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 {};