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.
- 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 -43
- 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/index.d.ts +0 -13
- package/dist/acf-functions/index.js +0 -13
- 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/index.d.ts +0 -9
- package/dist/entities/index.js +0 -9
- 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/index.d.ts +0 -10
- package/dist/globals/index.js +0 -10
- 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/index.d.ts +0 -5
- package/dist/repository/index.js +0 -5
- 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/index.d.ts +0 -17
- package/dist/router/index.js +0 -17
- 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/index.d.ts +0 -10
- package/dist/services/index.js +0 -10
- 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/index.d.ts +0 -4
- package/dist/ui/index.js +0 -4
- 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/index.d.ts +0 -0
- package/dist/wpdb/index.js +0 -1
- 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
package/cli/install.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
9
|
+
|
|
10
|
+
const sourceDir = path.join(__dirname, '..', 'lib');
|
|
11
|
+
const destDir = path.join(process.cwd(), '.nextpress');
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
if (!fs.existsSync(sourceDir)) {
|
|
15
|
+
console.error(`Error: Source folder does not exist at ${sourceDir}`);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (fs.existsSync(destDir)) {
|
|
20
|
+
fs.rmSync(destDir, { recursive: true, force: true });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
fs.cpSync(sourceDir, destDir, { recursive: true });
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.error('Error:', err.message);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
@@ -1,39 +1,53 @@
|
|
|
1
|
+
import { NextpressField, ACFField } from "../types/acf-field";
|
|
2
|
+
import { ACFFieldGroup, NextpressFieldGroup } from "../types/acf-field-group";
|
|
3
|
+
import { NextpressLayout, ACFLayout } from "../types/acf-layout";
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* Class representing ACF builder.
|
|
3
7
|
*/
|
|
4
|
-
export class ACFBuilder
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
;
|
|
8
|
+
export class ACFBuilder
|
|
9
|
+
{
|
|
10
|
+
/** Array of ACF field groups. */
|
|
11
|
+
private fieldGroups: ACFFieldGroup[] = [];
|
|
12
|
+
|
|
13
|
+
public constructor() {};
|
|
14
|
+
|
|
10
15
|
/**
|
|
11
16
|
* Gets built field groups.
|
|
12
17
|
*
|
|
13
18
|
* @returns {ACFFieldGroup[]} Array of field groups.
|
|
14
19
|
*/
|
|
15
|
-
getFieldGroups() {
|
|
20
|
+
public getFieldGroups(): ACFFieldGroup[] {
|
|
16
21
|
return this.fieldGroups;
|
|
17
22
|
}
|
|
23
|
+
|
|
18
24
|
/**
|
|
19
25
|
* Converts field groups to JSON string.
|
|
20
26
|
*
|
|
21
27
|
* @returns {string} JSON string representation of field groups.
|
|
22
28
|
*/
|
|
23
|
-
toJSON() {
|
|
29
|
+
public toJSON(): string {
|
|
24
30
|
return JSON.stringify(this.fieldGroups);
|
|
25
31
|
}
|
|
32
|
+
|
|
26
33
|
/**
|
|
27
34
|
* Registers and processes Nextpress field groups.
|
|
28
35
|
*
|
|
29
36
|
* @param {NextpressFieldGroup[]} fieldGroups - Array of field groups to register.
|
|
30
37
|
* @returns {this} Current instance.
|
|
31
38
|
*/
|
|
32
|
-
registerFieldGroups(fieldGroups) {
|
|
33
|
-
const keyedFieldGroups = fieldGroups.map(fieldGroup => (
|
|
39
|
+
public registerFieldGroups(fieldGroups: NextpressFieldGroup[]): this {
|
|
40
|
+
const keyedFieldGroups: ACFFieldGroup[] = fieldGroups.map(fieldGroup => ({
|
|
41
|
+
...fieldGroup,
|
|
42
|
+
key: `group_${this.formatKeySuffix(fieldGroup.title)}`,
|
|
43
|
+
fields: this.setFieldKeys(fieldGroup.fields, fieldGroup.title),
|
|
44
|
+
}));
|
|
45
|
+
|
|
34
46
|
this.fieldGroups = [...this.fieldGroups, ...keyedFieldGroups];
|
|
47
|
+
|
|
35
48
|
return this;
|
|
36
49
|
}
|
|
50
|
+
|
|
37
51
|
/**
|
|
38
52
|
* Sets keys for fields based on parent name.
|
|
39
53
|
*
|
|
@@ -41,18 +55,26 @@ export class ACFBuilder {
|
|
|
41
55
|
* @param {string} parentName - Parent string name.
|
|
42
56
|
* @returns {ACFField[]} Array of fields with generated keys.
|
|
43
57
|
*/
|
|
44
|
-
setFieldKeys(fields, parentName) {
|
|
58
|
+
private setFieldKeys(fields: NextpressField[], parentName: string): ACFField[] {
|
|
45
59
|
return fields.map(field => {
|
|
46
60
|
const keySuffix = this.formatKeySuffix(`${parentName}_${field.name}`);
|
|
61
|
+
|
|
47
62
|
const childFields = field.sub_fields
|
|
48
63
|
? this.setFieldKeys(field.sub_fields, keySuffix)
|
|
49
64
|
: undefined;
|
|
65
|
+
|
|
50
66
|
const childLayouts = field.layouts
|
|
51
67
|
? this.setLayoutKeys(field.layouts, keySuffix)
|
|
52
68
|
: undefined;
|
|
53
|
-
|
|
54
|
-
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
...field,
|
|
72
|
+
key: `field_${keySuffix}`,
|
|
73
|
+
sub_fields: childFields,
|
|
74
|
+
layouts: childLayouts
|
|
75
|
+
}});
|
|
55
76
|
}
|
|
77
|
+
|
|
56
78
|
/**
|
|
57
79
|
* Sets keys for layouts based on parent name.
|
|
58
80
|
*
|
|
@@ -60,22 +82,28 @@ export class ACFBuilder {
|
|
|
60
82
|
* @param {string} parentName - Parent string name.
|
|
61
83
|
* @returns {ACFLayout[]} Array of layouts with generated keys.
|
|
62
84
|
*/
|
|
63
|
-
setLayoutKeys(layouts, parentName) {
|
|
85
|
+
private setLayoutKeys(layouts: NextpressLayout[], parentName: string): ACFLayout[] {
|
|
64
86
|
return layouts.map(layout => {
|
|
65
87
|
const keySuffix = this.formatKeySuffix(`${parentName}_${layout.name}`);
|
|
88
|
+
|
|
66
89
|
const childFields = layout.sub_fields
|
|
67
90
|
? this.setFieldKeys(layout.sub_fields, `${parentName}_${layout.name}`)
|
|
68
91
|
: undefined;
|
|
69
|
-
|
|
70
|
-
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
...layout,
|
|
95
|
+
key: `layout_${keySuffix}`,
|
|
96
|
+
sub_fields: childFields || [],
|
|
97
|
+
}})
|
|
71
98
|
}
|
|
99
|
+
|
|
72
100
|
/**
|
|
73
101
|
* Formats suffix string.
|
|
74
102
|
*
|
|
75
103
|
* @param {string} suffix - Suffix to format.
|
|
76
104
|
* @returns {string} Formatted string.
|
|
77
105
|
*/
|
|
78
|
-
formatKeySuffix(suffix) {
|
|
106
|
+
private formatKeySuffix(suffix: string): string {
|
|
79
107
|
return suffix.replace(/[\s-]+/g, '_').toLowerCase();
|
|
80
108
|
}
|
|
81
109
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import { NextpressComponent } from '../types/components/nextpress-component';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Autoloads ACF components dynamically from the templates directory.
|
|
5
7
|
* * **Requirements for it to work:**
|
|
@@ -9,19 +11,23 @@ import path from 'path';
|
|
|
9
11
|
*
|
|
10
12
|
* @returns {Promise<NextpressComponent[]>} A promise resolving to an array of mapped layout configurations and their respective components.
|
|
11
13
|
*/
|
|
12
|
-
export async function acfComponentAutoloader() {
|
|
14
|
+
export async function acfComponentAutoloader(): Promise<NextpressComponent[]> {
|
|
13
15
|
const absolutePath = path.join(process.cwd(), 'src', 'app', '_templates', 'components');
|
|
14
16
|
const files = fs.readdirSync(absolutePath);
|
|
15
|
-
|
|
17
|
+
|
|
18
|
+
const layouts: NextpressComponent[] = [];
|
|
19
|
+
|
|
16
20
|
for (const file of files) {
|
|
17
|
-
if (!file.endsWith('.tsx'))
|
|
18
|
-
|
|
21
|
+
if (!file.endsWith('.tsx')) continue;
|
|
22
|
+
|
|
19
23
|
const imported = await import(`@/app/_templates/components/${file}`);
|
|
24
|
+
|
|
20
25
|
const layout = imported.layout;
|
|
21
26
|
const component = imported.default;
|
|
22
|
-
if (!layout || !component)
|
|
23
|
-
|
|
24
|
-
layouts.push({
|
|
27
|
+
if (!layout || !component) continue;
|
|
28
|
+
|
|
29
|
+
layouts.push({layout, Component: component});
|
|
25
30
|
}
|
|
31
|
+
|
|
26
32
|
return layouts;
|
|
27
33
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import { NextpressFieldGroup } from '../types/acf-field-group';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Autoloads ACF field groups dynamically from the field-groups directory.
|
|
5
7
|
* * **Requirements for it to work:**
|
|
@@ -8,16 +10,20 @@ import path from 'path';
|
|
|
8
10
|
*
|
|
9
11
|
* @returns {Promise<NextpressFieldGroup[]>} A promise resolving to an array of loaded ACF field group configurations.
|
|
10
12
|
*/
|
|
11
|
-
export async function acfFieldGroupAutoloader() {
|
|
13
|
+
export async function acfFieldGroupAutoloader(): Promise<NextpressFieldGroup[]> {
|
|
12
14
|
const absolutePath = path.join(process.cwd(), 'src', 'app', '_templates', 'components', 'field-groups');
|
|
13
15
|
const files = fs.readdirSync(absolutePath);
|
|
14
|
-
|
|
16
|
+
|
|
17
|
+
const fieldGroups: NextpressFieldGroup[] = [];
|
|
18
|
+
|
|
15
19
|
for (const file of files) {
|
|
16
|
-
if (!file.endsWith('.ts'))
|
|
17
|
-
|
|
18
|
-
const imported = await import(
|
|
20
|
+
if (!file.endsWith('.ts')) continue;
|
|
21
|
+
|
|
22
|
+
const imported = await import(`../../../../app/_templates/components/field-groups/${file}`);
|
|
19
23
|
const fieldGroup = imported.default;
|
|
24
|
+
|
|
20
25
|
fieldGroups.push(fieldGroup);
|
|
21
26
|
}
|
|
27
|
+
|
|
22
28
|
return fieldGroups;
|
|
23
29
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NextpressFieldGroup } from "../types/acf-field-group";
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Defines field group configuration and applies typing.
|
|
4
5
|
*
|
|
@@ -6,4 +7,6 @@ import { NextpressFieldGroup } from "../types/acf-field-group";
|
|
|
6
7
|
* @param {T} layout - Field group configuration object.
|
|
7
8
|
* @returns {T} Passed field group configuration object.
|
|
8
9
|
*/
|
|
9
|
-
export
|
|
10
|
+
export function defineFieldGroup<const T extends NextpressFieldGroup>(layout: T): T {
|
|
11
|
+
return layout;
|
|
12
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NextpressLayout } from "../types/acf-layout";
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Defines layout configuration and applies typing.
|
|
4
5
|
*
|
|
@@ -6,4 +7,6 @@ import { NextpressLayout } from "../types/acf-layout";
|
|
|
6
7
|
* @param {T} layout - Layout configuration object.
|
|
7
8
|
* @returns {T} Passed layout configuration object.
|
|
8
9
|
*/
|
|
9
|
-
export
|
|
10
|
+
export function defineLayout<const T extends NextpressLayout>(layout: T): T {
|
|
11
|
+
return layout;
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ACFChoiceObject } from "nextpress/acf-functions/types/components/field-props";
|
|
2
|
+
|
|
3
|
+
export function mapChoiceObject(return_format: 'array' | 'label' | 'value', value?: string, choices?: any): ACFChoiceObject | string | undefined {
|
|
4
|
+
if (return_format === 'value') {
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
if (!choices) return;
|
|
8
|
+
|
|
9
|
+
const label = choices[value ?? ''];
|
|
10
|
+
|
|
11
|
+
if (return_format === 'array') {
|
|
12
|
+
const result: ACFChoiceObject = {
|
|
13
|
+
label: label,
|
|
14
|
+
value: value
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
} else if (return_format === 'label') {
|
|
18
|
+
return label;
|
|
19
|
+
}
|
|
20
|
+
}
|