nextpress-core 2.0.2 → 2.1.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.
@@ -3,30 +3,39 @@ import path from 'path';
3
3
  import { NextpressComponent } from '../types/components/nextpress-component';
4
4
 
5
5
  /**
6
- * Autoloads ACF components dynamically from the templates directory.
6
+ * Autoloads ACF components dynamically from nested directories within the templates directory.
7
7
  * * **Requirements for it to work:**
8
- * Each `.tsx` file within the `src/app/_templates/components/` directory MUST export the following:
9
- * 1. `layout` (Named Export): The configuration for the ACF layout, typically defined using the `defineLayout` function.
10
- * 2. `default` (Default Export): The React component (JSX/TSX function) that renders the layout.
8
+ * Each `.tsx` file within `src/app/_templates/components/{any-dir}/` MUST export the following:
9
+ * 1. `layout` (Named Export): The configuration for the ACF layout.
10
+ * 2. `default` (Default Export): The React component that renders the layout.
11
11
  *
12
12
  * @returns {Promise<NextpressComponent[]>} A promise resolving to an array of mapped layout configurations and their respective components.
13
13
  */
14
14
  export async function acfComponentAutoloader(): Promise<NextpressComponent[]> {
15
- const absolutePath = path.join(process.cwd(), 'src', 'app', '_templates', 'components');
16
- const files = fs.readdirSync(absolutePath);
17
-
15
+ const basePath = path.join(process.cwd(), 'src', 'app', '_templates', 'components');
18
16
  const layouts: NextpressComponent[] = [];
19
17
 
20
- for (const file of files) {
21
- if (!file.endsWith('.tsx')) continue;
18
+ const items = fs.readdirSync(basePath, { withFileTypes: true });
19
+
20
+ for (const item of items) {
21
+ if (!item.isDirectory()) continue;
22
+
23
+ const dirName = item.name;
24
+ const dirPath = path.join(basePath, dirName);
25
+ const files = fs.readdirSync(dirPath);
26
+
27
+ for (const file of files) {
28
+ if (!file.endsWith('.tsx')) continue;
29
+
30
+ const imported = await import(`@/app/_templates/components/${dirName}/${file}`);
22
31
 
23
- const imported = await import(`@/app/_templates/components/${file}`);
32
+ const layout = imported.layout;
33
+ const component = imported.default;
24
34
 
25
- const layout = imported.layout;
26
- const component = imported.default;
27
- if (!layout || !component) continue;
35
+ if (!layout || !component) continue;
28
36
 
29
- layouts.push({layout, Component: component});
37
+ layouts.push({ layout, Component: component });
38
+ }
30
39
  }
31
40
 
32
41
  return layouts;
@@ -11,7 +11,7 @@ import { NextpressFieldGroup } from '../types/acf-field-group';
11
11
  * @returns {Promise<NextpressFieldGroup[]>} A promise resolving to an array of loaded ACF field group configurations.
12
12
  */
13
13
  export async function acfFieldGroupAutoloader(): Promise<NextpressFieldGroup[]> {
14
- const absolutePath = path.join(process.cwd(), 'src', 'app', '_templates', 'components', 'field-groups');
14
+ const absolutePath = path.join(process.cwd(), 'src', 'app', '_templates', 'field-groups');
15
15
  const files = fs.readdirSync(absolutePath);
16
16
 
17
17
  const fieldGroups: NextpressFieldGroup[] = [];
@@ -19,7 +19,7 @@ export async function acfFieldGroupAutoloader(): Promise<NextpressFieldGroup[]>
19
19
  for (const file of files) {
20
20
  if (!file.endsWith('.ts')) continue;
21
21
 
22
- const imported = await import(`@/app/_templates/components/field-groups/${file}`);
22
+ const imported = await import(`@/app/_templates/field-groups/${file}`);
23
23
  const fieldGroup = imported.default;
24
24
 
25
25
  fieldGroups.push(fieldGroup);
@@ -2760,7 +2760,7 @@ type NewLines = "wpautop" | "br" | ""
2760
2760
  type Choices =
2761
2761
  | Record<string, string>;
2762
2762
  /**
2763
- * Value returned (value, label, or both as array)
2763
+ * Value returned (value or label and value as array)
2764
2764
  */
2765
2765
  type ReturnFormatChoice = "value" | "label" | "array"
2766
2766
  /**
@@ -74,26 +74,26 @@ type MapFieldType<Field> =
74
74
  ? string | null
75
75
  : Field extends { type: 'textarea' }
76
76
  ? string | null
77
- : Field extends { type: 'button_group' }
77
+ : Field extends { type: 'button_group' } & { choices: Record<string, string>}
78
78
  ? Field extends { return_format: 'array' }
79
- ? ACFChoiceObject | null
80
- : string | null
81
- : Field extends { type: 'checkbox' }
79
+ ? ACFChoiceObject<Field> | null
80
+ : keyof Field['choices'] | null
81
+ : Field extends { type: 'checkbox' } & { choices: Record<string, string>}
82
82
  ? Field extends { return_format: 'array' }
83
- ? ACFChoiceObject[]
84
- : string[]
85
- : Field extends { type: 'radio' }
83
+ ? ACFChoiceObject<Field>[]
84
+ : (keyof Field['choices'])[]
85
+ : Field extends { type: 'radio' } & { choices: Record<string, string>}
86
86
  ? Field extends { return_format: 'array' }
87
- ? ACFChoiceObject | null
88
- : string | null
89
- : Field extends { type: 'select' }
87
+ ? ACFChoiceObject<Field> | null
88
+ : keyof Field['choices'] | null
89
+ : Field extends { type: 'select' } & { choices: Record<string, string>}
90
90
  ? Field extends { multiple: 1 }
91
91
  ? Field extends { return_format: 'array' }
92
- ? ACFChoiceObject[]
93
- : string[]
92
+ ? ACFChoiceObject<Field>[]
93
+ : (keyof Field['choices'])[]
94
94
  : Field extends { return_format: 'array' }
95
- ? ACFChoiceObject | null
96
- : string | null
95
+ ? ACFChoiceObject<Field> | null
96
+ : keyof Field['choices'] | null
97
97
  : Field extends { type: 'true_false' }
98
98
  ? boolean
99
99
  : Field extends { type: 'file' }
@@ -165,9 +165,9 @@ export type ACFLinkObject = {
165
165
  target: string
166
166
  }
167
167
 
168
- export type ACFChoiceObject = {
169
- label?: string
170
- value?: string,
168
+ export type ACFChoiceObject<T extends {choices: Record<string, string>}> = {
169
+ label: T['choices'][keyof T['choices']] | null,
170
+ value: keyof T['choices'] | null
171
171
  }
172
172
 
173
173
  export type ACFGoogleMapsObject = {
@@ -1,5 +1,4 @@
1
1
  import "@nextpress/globals/globals";
2
- import "@/app/_css/globals.css";
3
2
  import { LayoutTemplate } from "@/app/_templates/layout";
4
3
  import { cookies, draftMode } from "next/headers";
5
4
  import fonts from "@/fonts";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextpress-core",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "Nextpress Core",
5
5
  "keywords": [],
6
6
  "bin": {