@wp-typia/project-tools 0.22.10 → 0.23.1
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/runtime/ai-feature-artifacts.js +4 -1
- package/dist/runtime/block-generator-service-spec.js +2 -1
- package/dist/runtime/cli-add-block-json.js +5 -1
- package/dist/runtime/cli-add-collision.d.ts +25 -0
- package/dist/runtime/cli-add-collision.js +76 -0
- package/dist/runtime/cli-add-help.js +12 -2
- package/dist/runtime/cli-add-kind-ids.d.ts +1 -1
- package/dist/runtime/cli-add-kind-ids.js +3 -0
- package/dist/runtime/cli-add-types.d.ts +129 -0
- package/dist/runtime/cli-add-types.js +26 -0
- package/dist/runtime/cli-add-validation.d.ts +97 -1
- package/dist/runtime/cli-add-validation.js +313 -1
- package/dist/runtime/cli-add-workspace-ability-scaffold.js +4 -1
- package/dist/runtime/cli-add-workspace-admin-view-scaffold.js +79 -20
- package/dist/runtime/cli-add-workspace-admin-view-source.js +11 -2
- package/dist/runtime/cli-add-workspace-admin-view-templates-core-data.d.ts +34 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-core-data.js +483 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-default.d.ts +30 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-default.js +310 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-rest.d.ts +25 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-rest.js +124 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-settings.d.ts +34 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-settings.js +370 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-shared.d.ts +49 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates-shared.js +259 -0
- package/dist/runtime/cli-add-workspace-admin-view-templates.d.ts +19 -10
- package/dist/runtime/cli-add-workspace-admin-view-templates.js +31 -971
- package/dist/runtime/cli-add-workspace-admin-view-types.d.ts +21 -0
- package/dist/runtime/cli-add-workspace-admin-view-types.js +22 -0
- package/dist/runtime/cli-add-workspace-ai-anchors.js +125 -32
- package/dist/runtime/cli-add-workspace-ai-source-emitters.js +17 -1
- package/dist/runtime/cli-add-workspace-contract-source-emitters.d.ts +15 -0
- package/dist/runtime/cli-add-workspace-contract-source-emitters.js +42 -0
- package/dist/runtime/cli-add-workspace-contract.d.ts +15 -0
- package/dist/runtime/cli-add-workspace-contract.js +65 -0
- package/dist/runtime/cli-add-workspace-integration-env.d.ts +26 -0
- package/dist/runtime/cli-add-workspace-integration-env.js +428 -0
- package/dist/runtime/cli-add-workspace-post-meta-anchors.d.ts +23 -0
- package/dist/runtime/cli-add-workspace-post-meta-anchors.js +244 -0
- package/dist/runtime/cli-add-workspace-post-meta-source-emitters.d.ts +63 -0
- package/dist/runtime/cli-add-workspace-post-meta-source-emitters.js +179 -0
- package/dist/runtime/cli-add-workspace-post-meta.d.ts +15 -0
- package/dist/runtime/cli-add-workspace-post-meta.js +107 -0
- package/dist/runtime/cli-add-workspace-rest-anchors.d.ts +9 -0
- package/dist/runtime/cli-add-workspace-rest-anchors.js +326 -21
- package/dist/runtime/cli-add-workspace-rest-generated.d.ts +9 -0
- package/dist/runtime/cli-add-workspace-rest-generated.js +158 -0
- package/dist/runtime/cli-add-workspace-rest-manual.d.ts +8 -0
- package/dist/runtime/cli-add-workspace-rest-manual.js +279 -0
- package/dist/runtime/cli-add-workspace-rest-php-templates.d.ts +24 -0
- package/dist/runtime/cli-add-workspace-rest-php-templates.js +678 -0
- package/dist/runtime/cli-add-workspace-rest-source-emitters.d.ts +98 -2
- package/dist/runtime/cli-add-workspace-rest-source-emitters.js +323 -29
- package/dist/runtime/cli-add-workspace-rest-types.d.ts +108 -0
- package/dist/runtime/cli-add-workspace-rest-types.js +1 -0
- package/dist/runtime/cli-add-workspace-rest.d.ts +3 -7
- package/dist/runtime/cli-add-workspace-rest.js +34 -481
- package/dist/runtime/cli-add-workspace.d.ts +15 -0
- package/dist/runtime/cli-add-workspace.js +15 -0
- package/dist/runtime/cli-add.d.ts +1 -1
- package/dist/runtime/cli-add.js +1 -1
- package/dist/runtime/cli-core.d.ts +3 -2
- package/dist/runtime/cli-core.js +3 -2
- package/dist/runtime/cli-diagnostics.d.ts +3 -1
- package/dist/runtime/cli-diagnostics.js +17 -5
- package/dist/runtime/cli-doctor-environment.js +1 -3
- package/dist/runtime/cli-doctor-workspace-bindings.js +4 -1
- package/dist/runtime/cli-doctor-workspace-block-addons.d.ts +12 -0
- package/dist/runtime/cli-doctor-workspace-block-addons.js +134 -0
- package/dist/runtime/cli-doctor-workspace-block-iframe.d.ts +9 -0
- package/dist/runtime/cli-doctor-workspace-block-iframe.js +228 -0
- package/dist/runtime/cli-doctor-workspace-block-metadata.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-block-metadata.js +111 -0
- package/dist/runtime/cli-doctor-workspace-blocks.js +6 -424
- package/dist/runtime/cli-doctor-workspace-features-abilities.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-abilities.js +112 -0
- package/dist/runtime/cli-doctor-workspace-features-admin-views.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-admin-views.js +128 -0
- package/dist/runtime/cli-doctor-workspace-features-ai.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-ai.js +57 -0
- package/dist/runtime/cli-doctor-workspace-features-editor-plugins.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-editor-plugins.js +80 -0
- package/dist/runtime/cli-doctor-workspace-features-post-meta.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-post-meta.js +77 -0
- package/dist/runtime/cli-doctor-workspace-features-rest.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features-rest.js +120 -0
- package/dist/runtime/cli-doctor-workspace-features.js +14 -369
- package/dist/runtime/cli-doctor-workspace-package.d.ts +25 -3
- package/dist/runtime/cli-doctor-workspace-package.js +35 -13
- package/dist/runtime/cli-doctor-workspace-shared.d.ts +2 -0
- package/dist/runtime/cli-doctor-workspace-shared.js +2 -0
- package/dist/runtime/cli-doctor-workspace.js +8 -3
- package/dist/runtime/cli-doctor.d.ts +52 -3
- package/dist/runtime/cli-doctor.js +79 -8
- package/dist/runtime/cli-help.js +10 -0
- package/dist/runtime/cli-init-package-json.js +4 -2
- package/dist/runtime/cli-init-templates.js +11 -1
- package/dist/runtime/cli-prompt.d.ts +16 -2
- package/dist/runtime/cli-prompt.js +29 -12
- package/dist/runtime/cli-scaffold.d.ts +2 -1
- package/dist/runtime/cli-scaffold.js +19 -10
- package/dist/runtime/contract-artifacts.d.ts +14 -0
- package/dist/runtime/contract-artifacts.js +15 -0
- package/dist/runtime/external-template-guards.js +4 -6
- package/dist/runtime/index.d.ts +2 -2
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/json-utils.d.ts +62 -4
- package/dist/runtime/json-utils.js +78 -4
- package/dist/runtime/local-dev-presets.js +4 -1
- package/dist/runtime/migration-ui-capability.js +4 -1
- package/dist/runtime/migration-utils.js +4 -1
- package/dist/runtime/package-managers.js +6 -1
- package/dist/runtime/package-versions.js +6 -1
- package/dist/runtime/rest-resource-artifacts.d.ts +57 -1
- package/dist/runtime/rest-resource-artifacts.js +97 -1
- package/dist/runtime/scaffold-bootstrap.js +7 -2
- package/dist/runtime/scaffold-package-manager-files.js +5 -1
- package/dist/runtime/scaffold-repository-reference.js +4 -2
- package/dist/runtime/scaffold-template-variables.js +2 -1
- package/dist/runtime/scaffold.d.ts +18 -1
- package/dist/runtime/scaffold.js +55 -2
- package/dist/runtime/temp-roots.js +4 -1
- package/dist/runtime/template-layers.js +4 -1
- package/dist/runtime/template-registry.js +9 -3
- package/dist/runtime/template-render.d.ts +1 -1
- package/dist/runtime/template-render.js +1 -1
- package/dist/runtime/template-source-cache-markers.d.ts +37 -0
- package/dist/runtime/template-source-cache-markers.js +125 -0
- package/dist/runtime/template-source-cache.d.ts +1 -4
- package/dist/runtime/template-source-cache.js +16 -122
- package/dist/runtime/template-source-contracts.d.ts +2 -0
- package/dist/runtime/template-source-external.d.ts +4 -2
- package/dist/runtime/template-source-external.js +4 -2
- package/dist/runtime/template-source-normalization.js +2 -1
- package/dist/runtime/template-source-remote.d.ts +8 -4
- package/dist/runtime/template-source-remote.js +26 -9
- package/dist/runtime/template-source-seeds.js +10 -3
- package/dist/runtime/workspace-inventory-mutations.js +54 -4
- package/dist/runtime/workspace-inventory-parser-entries.d.ts +17 -0
- package/dist/runtime/workspace-inventory-parser-entries.js +157 -0
- package/dist/runtime/workspace-inventory-parser-validation.d.ts +104 -0
- package/dist/runtime/workspace-inventory-parser-validation.js +34 -0
- package/dist/runtime/workspace-inventory-parser.d.ts +3 -44
- package/dist/runtime/workspace-inventory-parser.js +7 -464
- package/dist/runtime/workspace-inventory-read.d.ts +9 -2
- package/dist/runtime/workspace-inventory-read.js +9 -2
- package/dist/runtime/workspace-inventory-section-descriptors.d.ts +19 -0
- package/dist/runtime/workspace-inventory-section-descriptors.js +435 -0
- package/dist/runtime/workspace-inventory-templates.d.ts +16 -1
- package/dist/runtime/workspace-inventory-templates.js +75 -4
- package/dist/runtime/workspace-inventory-types.d.ts +52 -2
- package/dist/runtime/workspace-inventory.d.ts +2 -2
- package/dist/runtime/workspace-inventory.js +1 -1
- package/dist/runtime/workspace-project.js +4 -6
- package/package.json +2 -2
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
import { quoteTsString } from './cli-add-shared.js';
|
|
2
|
+
import { toCamelCase, toPascalCase, toTitleCase } from './string-case.js';
|
|
3
|
+
/**
|
|
4
|
+
* Builds TypeScript item and dataset types for a core-data-backed admin view.
|
|
5
|
+
*
|
|
6
|
+
* @param adminViewSlug - Admin-view slug used to derive generated type names.
|
|
7
|
+
* @param coreDataSource - WordPress core-data entity source for the admin view.
|
|
8
|
+
* @returns Generated TypeScript source for core-data admin-view types.
|
|
9
|
+
*/
|
|
10
|
+
export function buildCoreDataAdminViewTypesSource(adminViewSlug, coreDataSource) {
|
|
11
|
+
const pascalName = toPascalCase(adminViewSlug);
|
|
12
|
+
const coreDataRecordTypeName = `${pascalName}CoreDataRecord`;
|
|
13
|
+
const itemTypeName = `${pascalName}AdminViewItem`;
|
|
14
|
+
const dataSetTypeName = `${pascalName}AdminViewDataSet`;
|
|
15
|
+
if (coreDataSource.entityKind === 'taxonomy') {
|
|
16
|
+
return `export interface ${coreDataRecordTypeName} {
|
|
17
|
+
\tcount?: number;
|
|
18
|
+
\tdescription?: string;
|
|
19
|
+
\tid: number;
|
|
20
|
+
\tlink?: string;
|
|
21
|
+
\tmeta?: Record<string, unknown>;
|
|
22
|
+
\tname?: string;
|
|
23
|
+
\tparent?: number;
|
|
24
|
+
\tslug?: string;
|
|
25
|
+
\ttaxonomy?: string;
|
|
26
|
+
\t[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ${itemTypeName} {
|
|
30
|
+
\tcount: number;
|
|
31
|
+
\tdescription: string;
|
|
32
|
+
\tid: number;
|
|
33
|
+
\tlink: string;
|
|
34
|
+
\tname: string;
|
|
35
|
+
\tparent: number;
|
|
36
|
+
\traw: ${coreDataRecordTypeName};
|
|
37
|
+
\tslug: string;
|
|
38
|
+
\ttaxonomy: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ${dataSetTypeName} {
|
|
42
|
+
\titems: ${itemTypeName}[];
|
|
43
|
+
\tpaginationInfo: {
|
|
44
|
+
\t\ttotalItems: number;
|
|
45
|
+
\t\ttotalPages: number;
|
|
46
|
+
\t};
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
return `export interface ${coreDataRecordTypeName} {
|
|
51
|
+
\tid: number;
|
|
52
|
+
\tdate?: string;
|
|
53
|
+
\tmodified?: string;
|
|
54
|
+
\tname?: string;
|
|
55
|
+
\tslug?: string;
|
|
56
|
+
\tstatus?: string;
|
|
57
|
+
\ttitle?: string | {
|
|
58
|
+
\t\traw?: string;
|
|
59
|
+
\t\trendered?: string;
|
|
60
|
+
\t};
|
|
61
|
+
\t[key: string]: unknown;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface ${itemTypeName} {
|
|
65
|
+
\tid: number;
|
|
66
|
+
\traw: ${coreDataRecordTypeName};
|
|
67
|
+
\tslug: string;
|
|
68
|
+
\tstatus: string;
|
|
69
|
+
\ttitle: string;
|
|
70
|
+
\tupdatedAt: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface ${dataSetTypeName} {
|
|
74
|
+
\titems: ${itemTypeName}[];
|
|
75
|
+
\tpaginationInfo: {
|
|
76
|
+
\t\ttotalItems: number;
|
|
77
|
+
\t\ttotalPages: number;
|
|
78
|
+
\t};
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Builds a DataViews config module for a core-data-backed admin view.
|
|
84
|
+
*
|
|
85
|
+
* @param adminViewSlug - Admin-view slug used to derive generated identifiers.
|
|
86
|
+
* @param textDomain - WordPress i18n text domain for generated labels.
|
|
87
|
+
* @param coreDataSource - WordPress core-data entity source for field selection.
|
|
88
|
+
* @returns Generated TypeScript source for the core-data DataViews config.
|
|
89
|
+
*/
|
|
90
|
+
export function buildCoreDataAdminViewConfigSource(adminViewSlug, textDomain, coreDataSource) {
|
|
91
|
+
const pascalName = toPascalCase(adminViewSlug);
|
|
92
|
+
const camelName = toCamelCase(adminViewSlug);
|
|
93
|
+
const itemTypeName = `${pascalName}AdminViewItem`;
|
|
94
|
+
const dataViewsName = `${camelName}AdminDataViews`;
|
|
95
|
+
const isTaxonomyCoreDataSource = coreDataSource.entityKind === 'taxonomy';
|
|
96
|
+
const defaultViewFields = isTaxonomyCoreDataSource
|
|
97
|
+
? "['name', 'slug', 'count']"
|
|
98
|
+
: "['title', 'slug', 'status', 'updatedAt']";
|
|
99
|
+
const titleFieldSource = isTaxonomyCoreDataSource
|
|
100
|
+
? "\ttitleField: 'name',\n"
|
|
101
|
+
: "\ttitleField: 'title',\n";
|
|
102
|
+
const defaultViewEnhancementsSource = isTaxonomyCoreDataSource
|
|
103
|
+
? "\t\ttitleField: 'name',\n"
|
|
104
|
+
: "\t\ttitleField: 'title',\n";
|
|
105
|
+
const additionalFieldsSource = isTaxonomyCoreDataSource
|
|
106
|
+
? `\t\tcount: {
|
|
107
|
+
\t\t\tlabel: __( 'Count', ${quoteTsString(textDomain)} ),
|
|
108
|
+
\t\t\tschema: { type: 'integer' },
|
|
109
|
+
\t\t},
|
|
110
|
+
\t\tdescription: {
|
|
111
|
+
\t\t\tlabel: __( 'Description', ${quoteTsString(textDomain)} ),
|
|
112
|
+
\t\t\tschema: { type: 'string' },
|
|
113
|
+
\t\t},
|
|
114
|
+
\t\tlink: {
|
|
115
|
+
\t\t\tlabel: __( 'Link', ${quoteTsString(textDomain)} ),
|
|
116
|
+
\t\t\tschema: { format: 'uri', type: 'string' },
|
|
117
|
+
\t\t},
|
|
118
|
+
\t\tname: {
|
|
119
|
+
\t\t\tenableGlobalSearch: true,
|
|
120
|
+
\t\t\tlabel: __( 'Name', ${quoteTsString(textDomain)} ),
|
|
121
|
+
\t\t\tschema: { type: 'string' },
|
|
122
|
+
\t\t},
|
|
123
|
+
\t\tparent: {
|
|
124
|
+
\t\t\tlabel: __( 'Parent', ${quoteTsString(textDomain)} ),
|
|
125
|
+
\t\t\tschema: { type: 'integer' },
|
|
126
|
+
\t\t},
|
|
127
|
+
\t\tslug: {
|
|
128
|
+
\t\t\tenableGlobalSearch: true,
|
|
129
|
+
\t\t\tlabel: __( 'Slug', ${quoteTsString(textDomain)} ),
|
|
130
|
+
\t\t\tschema: { type: 'string' },
|
|
131
|
+
\t\t},
|
|
132
|
+
\t\ttaxonomy: {
|
|
133
|
+
\t\t\tlabel: __( 'Taxonomy', ${quoteTsString(textDomain)} ),
|
|
134
|
+
\t\t\tschema: { type: 'string' },
|
|
135
|
+
\t\t},`
|
|
136
|
+
: `\t\tslug: {
|
|
137
|
+
\t\t\tenableGlobalSearch: true,
|
|
138
|
+
\t\t\tlabel: __( 'Slug', ${quoteTsString(textDomain)} ),
|
|
139
|
+
\t\t\tschema: { type: 'string' },
|
|
140
|
+
\t\t},
|
|
141
|
+
\t\tstatus: {
|
|
142
|
+
\t\t\tlabel: __( 'Status', ${quoteTsString(textDomain)} ),
|
|
143
|
+
\t\t\tschema: { type: 'string' },
|
|
144
|
+
\t\t},
|
|
145
|
+
\t\ttitle: {
|
|
146
|
+
\t\t\tenableGlobalSearch: true,
|
|
147
|
+
\t\t\tlabel: __( 'Title', ${quoteTsString(textDomain)} ),
|
|
148
|
+
\t\t\tschema: { type: 'string' },
|
|
149
|
+
\t\t},
|
|
150
|
+
\t\tupdatedAt: {
|
|
151
|
+
\t\t\tlabel: __( 'Updated', ${quoteTsString(textDomain)} ),
|
|
152
|
+
\t\t\tschema: { format: 'date-time', type: 'string' },
|
|
153
|
+
\t\t\ttype: 'datetime',
|
|
154
|
+
\t\t},`;
|
|
155
|
+
return `import { defineDataViews } from '@wp-typia/dataviews';
|
|
156
|
+
import { __ } from '@wordpress/i18n';
|
|
157
|
+
|
|
158
|
+
import type { ${itemTypeName} } from './types';
|
|
159
|
+
|
|
160
|
+
export const ${dataViewsName} = defineDataViews<${itemTypeName}>({
|
|
161
|
+
\tidField: 'id',
|
|
162
|
+
\tsearch: true,
|
|
163
|
+
\tsearchLabel: __( 'Search records', ${quoteTsString(textDomain)} ),
|
|
164
|
+
${titleFieldSource}
|
|
165
|
+
\tdefaultView: {
|
|
166
|
+
\t\tfields: ${defaultViewFields},
|
|
167
|
+
\t\tpage: 1,
|
|
168
|
+
\t\tperPage: 10,
|
|
169
|
+
${defaultViewEnhancementsSource}
|
|
170
|
+
\t\ttype: 'table',
|
|
171
|
+
\t},
|
|
172
|
+
\tfields: {
|
|
173
|
+
\t\tid: {
|
|
174
|
+
\t\t\tenableHiding: false,
|
|
175
|
+
\t\t\tlabel: __( 'ID', ${quoteTsString(textDomain)} ),
|
|
176
|
+
\t\t\treadOnly: true,
|
|
177
|
+
\t\t\tschema: { type: 'integer' },
|
|
178
|
+
\t\t},
|
|
179
|
+
${additionalFieldsSource}
|
|
180
|
+
\t},
|
|
181
|
+
});
|
|
182
|
+
`;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Builds data hooks for loading records from the WordPress core-data store.
|
|
186
|
+
*
|
|
187
|
+
* @param adminViewSlug - Admin-view slug used to derive generated identifiers.
|
|
188
|
+
* @param coreDataSource - WordPress core-data entity source for generated hooks.
|
|
189
|
+
* @returns Generated TypeScript source for core-data data access.
|
|
190
|
+
*/
|
|
191
|
+
export function buildCoreDataAdminViewDataSource(adminViewSlug, coreDataSource) {
|
|
192
|
+
const pascalName = toPascalCase(adminViewSlug);
|
|
193
|
+
const camelName = toCamelCase(adminViewSlug);
|
|
194
|
+
const coreDataRecordTypeName = `${pascalName}CoreDataRecord`;
|
|
195
|
+
const dataSetTypeName = `${pascalName}AdminViewDataSet`;
|
|
196
|
+
const itemTypeName = `${pascalName}AdminViewItem`;
|
|
197
|
+
const queryTypeName = `${pascalName}AdminViewQuery`;
|
|
198
|
+
const dataViewsName = `${camelName}AdminDataViews`;
|
|
199
|
+
const useEntityRecordName = `use${pascalName}EntityRecord`;
|
|
200
|
+
const useEntityRecordsName = `use${pascalName}EntityRecords`;
|
|
201
|
+
const useAdminViewDataName = `use${pascalName}AdminViewData`;
|
|
202
|
+
if (coreDataSource.entityKind === 'taxonomy') {
|
|
203
|
+
return `import type { DataViewsView } from '@wp-typia/dataviews';
|
|
204
|
+
import { useEntityRecord, useEntityRecords } from '@wordpress/core-data';
|
|
205
|
+
import { useMemo } from '@wordpress/element';
|
|
206
|
+
|
|
207
|
+
import { ${dataViewsName} } from './config';
|
|
208
|
+
import type {
|
|
209
|
+
\t${coreDataRecordTypeName},
|
|
210
|
+
\t${dataSetTypeName},
|
|
211
|
+
\t${itemTypeName},
|
|
212
|
+
} from './types';
|
|
213
|
+
|
|
214
|
+
export interface ${queryTypeName} {
|
|
215
|
+
\tpage?: number;
|
|
216
|
+
\tper_page?: number;
|
|
217
|
+
\tsearch?: string;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const CORE_DATA_ENTITY_KIND = ${quoteTsString(coreDataSource.entityKind)};
|
|
221
|
+
const CORE_DATA_ENTITY_NAME = ${quoteTsString(coreDataSource.entityName)};
|
|
222
|
+
|
|
223
|
+
function normalizeCoreDataNumber(value: unknown): number {
|
|
224
|
+
\treturn typeof value === 'number' && Number.isFinite(value) ? value : 0;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function normalizeCoreDataString(value: unknown): string {
|
|
228
|
+
\treturn typeof value === 'string' ? value : '';
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function normalizeTaxonomyRecord(record: ${coreDataRecordTypeName}): ${itemTypeName} {
|
|
232
|
+
\treturn {
|
|
233
|
+
\t\tcount: normalizeCoreDataNumber(record.count),
|
|
234
|
+
\t\tdescription: normalizeCoreDataString(record.description),
|
|
235
|
+
\t\tid: record.id,
|
|
236
|
+
\t\tlink: normalizeCoreDataString(record.link),
|
|
237
|
+
\t\tname: normalizeCoreDataString(record.name) || normalizeCoreDataString(record.slug),
|
|
238
|
+
\t\tparent: normalizeCoreDataNumber(record.parent),
|
|
239
|
+
\t\traw: record,
|
|
240
|
+
\t\tslug: normalizeCoreDataString(record.slug),
|
|
241
|
+
\t\ttaxonomy: normalizeCoreDataString(record.taxonomy),
|
|
242
|
+
\t};
|
|
243
|
+
\t}
|
|
244
|
+
|
|
245
|
+
export function ${useEntityRecordName}(recordId: number | undefined) {
|
|
246
|
+
\treturn useEntityRecord<${coreDataRecordTypeName}>(
|
|
247
|
+
\t\tCORE_DATA_ENTITY_KIND,
|
|
248
|
+
\t\tCORE_DATA_ENTITY_NAME,
|
|
249
|
+
\t\trecordId ?? 0,
|
|
250
|
+
\t\t{ enabled: typeof recordId === 'number' },
|
|
251
|
+
\t);
|
|
252
|
+
\t}
|
|
253
|
+
|
|
254
|
+
export function ${useEntityRecordsName}(view: DataViewsView<${itemTypeName}>) {
|
|
255
|
+
\tconst query = ${dataViewsName}.toQueryArgs<${queryTypeName}>(view, {
|
|
256
|
+
\t\tperPageParam: 'per_page',
|
|
257
|
+
\t});
|
|
258
|
+
|
|
259
|
+
\treturn useEntityRecords<${coreDataRecordTypeName}>(
|
|
260
|
+
\t\tCORE_DATA_ENTITY_KIND,
|
|
261
|
+
\t\tCORE_DATA_ENTITY_NAME,
|
|
262
|
+
\t\tquery,
|
|
263
|
+
\t);
|
|
264
|
+
\t}
|
|
265
|
+
|
|
266
|
+
export function ${useAdminViewDataName}(view: DataViewsView<${itemTypeName}>) {
|
|
267
|
+
\tconst { hasResolved, isResolving, records, totalItems, totalPages } =
|
|
268
|
+
\t\t${useEntityRecordsName}(view);
|
|
269
|
+
\tconst items = useMemo(
|
|
270
|
+
\t\t() => (records ?? []).map((record) => normalizeTaxonomyRecord(record)),
|
|
271
|
+
\t\t[records],
|
|
272
|
+
\t);
|
|
273
|
+
\tconst dataSet = useMemo<${dataSetTypeName}>(
|
|
274
|
+
\t\t() => ({
|
|
275
|
+
\t\t\titems,
|
|
276
|
+
\t\t\tpaginationInfo: {
|
|
277
|
+
\t\t\t\ttotalItems: totalItems ?? items.length,
|
|
278
|
+
\t\t\t\ttotalPages: Math.max(1, totalPages ?? 1),
|
|
279
|
+
\t\t\t},
|
|
280
|
+
\t\t}),
|
|
281
|
+
\t\t[items, totalItems, totalPages],
|
|
282
|
+
\t);
|
|
283
|
+
\tconst error =
|
|
284
|
+
\t\t!isResolving && hasResolved && records === null
|
|
285
|
+
\t\t\t? 'Unable to load core-data entity records.'
|
|
286
|
+
\t\t\t: null;
|
|
287
|
+
|
|
288
|
+
\treturn {
|
|
289
|
+
\t\tdataSet,
|
|
290
|
+
\t\terror,
|
|
291
|
+
\t\tisLoading: isResolving,
|
|
292
|
+
\t};
|
|
293
|
+
\t}
|
|
294
|
+
`;
|
|
295
|
+
}
|
|
296
|
+
return `import type { DataViewsView } from '@wp-typia/dataviews';
|
|
297
|
+
import { useEntityRecord, useEntityRecords } from '@wordpress/core-data';
|
|
298
|
+
import { useMemo } from '@wordpress/element';
|
|
299
|
+
|
|
300
|
+
import { ${dataViewsName} } from './config';
|
|
301
|
+
import type {
|
|
302
|
+
\t${coreDataRecordTypeName},
|
|
303
|
+
\t${dataSetTypeName},
|
|
304
|
+
\t${itemTypeName},
|
|
305
|
+
} from './types';
|
|
306
|
+
|
|
307
|
+
export interface ${queryTypeName} {
|
|
308
|
+
\tpage?: number;
|
|
309
|
+
\tper_page?: number;
|
|
310
|
+
\tsearch?: string;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const CORE_DATA_ENTITY_KIND = ${quoteTsString(coreDataSource.entityKind)};
|
|
314
|
+
const CORE_DATA_ENTITY_NAME = ${quoteTsString(coreDataSource.entityName)};
|
|
315
|
+
|
|
316
|
+
function normalizeCoreDataString(value: unknown): string {
|
|
317
|
+
\treturn typeof value === 'string' ? value : '';
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function normalizeCoreDataTitle(record: ${coreDataRecordTypeName}): string {
|
|
321
|
+
\tif (typeof record.title === 'string') {
|
|
322
|
+
\t\treturn record.title;
|
|
323
|
+
\t}
|
|
324
|
+
\tif (record.title && typeof record.title === 'object') {
|
|
325
|
+
\t\tif (typeof record.title.rendered === 'string') {
|
|
326
|
+
\t\t\treturn record.title.rendered;
|
|
327
|
+
\t\t}
|
|
328
|
+
\t\tif (typeof record.title.raw === 'string') {
|
|
329
|
+
\t\t\treturn record.title.raw;
|
|
330
|
+
\t\t}
|
|
331
|
+
\t}
|
|
332
|
+
|
|
333
|
+
\treturn normalizeCoreDataString(record.name) || normalizeCoreDataString(record.slug);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function normalizeCoreDataUpdatedAt(record: ${coreDataRecordTypeName}): string {
|
|
337
|
+
\treturn normalizeCoreDataString(record.modified) || normalizeCoreDataString(record.date);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function normalizeCoreDataRecord(record: ${coreDataRecordTypeName}): ${itemTypeName} {
|
|
341
|
+
\treturn {
|
|
342
|
+
\t\tid: record.id,
|
|
343
|
+
\t\traw: record,
|
|
344
|
+
\t\tslug: normalizeCoreDataString(record.slug),
|
|
345
|
+
\t\tstatus: normalizeCoreDataString(record.status),
|
|
346
|
+
\t\ttitle: normalizeCoreDataTitle(record),
|
|
347
|
+
\t\tupdatedAt: normalizeCoreDataUpdatedAt(record),
|
|
348
|
+
\t};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export function ${useEntityRecordName}(recordId: number | undefined) {
|
|
352
|
+
\treturn useEntityRecord<${coreDataRecordTypeName}>(
|
|
353
|
+
\t\tCORE_DATA_ENTITY_KIND,
|
|
354
|
+
\t\tCORE_DATA_ENTITY_NAME,
|
|
355
|
+
\t\trecordId ?? 0,
|
|
356
|
+
\t\t{ enabled: typeof recordId === 'number' },
|
|
357
|
+
\t);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export function ${useEntityRecordsName}(view: DataViewsView<${itemTypeName}>) {
|
|
361
|
+
\tconst query = ${dataViewsName}.toQueryArgs<${queryTypeName}>(view, {
|
|
362
|
+
\t\tperPageParam: 'per_page',
|
|
363
|
+
\t});
|
|
364
|
+
|
|
365
|
+
\treturn useEntityRecords<${coreDataRecordTypeName}>(
|
|
366
|
+
\t\tCORE_DATA_ENTITY_KIND,
|
|
367
|
+
\t\tCORE_DATA_ENTITY_NAME,
|
|
368
|
+
\t\tquery,
|
|
369
|
+
\t);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export function ${useAdminViewDataName}(view: DataViewsView<${itemTypeName}>) {
|
|
373
|
+
\tconst { hasResolved, isResolving, records, totalItems, totalPages } =
|
|
374
|
+
\t\t${useEntityRecordsName}(view);
|
|
375
|
+
\tconst items = useMemo(
|
|
376
|
+
\t\t() => (records ?? []).map((record) => normalizeCoreDataRecord(record)),
|
|
377
|
+
\t\t[records],
|
|
378
|
+
\t);
|
|
379
|
+
\tconst dataSet = useMemo<${dataSetTypeName}>(
|
|
380
|
+
\t\t() => ({
|
|
381
|
+
\t\t\titems,
|
|
382
|
+
\t\t\tpaginationInfo: {
|
|
383
|
+
\t\t\t\ttotalItems: totalItems ?? items.length,
|
|
384
|
+
\t\t\t\ttotalPages: Math.max(1, totalPages ?? 1),
|
|
385
|
+
\t\t\t},
|
|
386
|
+
\t\t}),
|
|
387
|
+
\t\t[items, totalItems, totalPages],
|
|
388
|
+
\t);
|
|
389
|
+
\tconst error =
|
|
390
|
+
\t\t!isResolving && hasResolved && records === null
|
|
391
|
+
\t\t\t? 'Unable to load core-data entity records.'
|
|
392
|
+
\t\t\t: null;
|
|
393
|
+
|
|
394
|
+
\treturn {
|
|
395
|
+
\t\tdataSet,
|
|
396
|
+
\t\terror,
|
|
397
|
+
\t\tisLoading: isResolving,
|
|
398
|
+
\t};
|
|
399
|
+
}
|
|
400
|
+
`;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Builds the React screen module for a core-data-backed admin view.
|
|
404
|
+
*
|
|
405
|
+
* @param adminViewSlug - Admin-view slug used to derive generated identifiers.
|
|
406
|
+
* @param textDomain - WordPress i18n text domain for generated labels.
|
|
407
|
+
* @returns Generated TSX source for the core-data admin-view screen.
|
|
408
|
+
*/
|
|
409
|
+
export function buildCoreDataAdminViewScreenSource(adminViewSlug, textDomain) {
|
|
410
|
+
const pascalName = toPascalCase(adminViewSlug);
|
|
411
|
+
const camelName = toCamelCase(adminViewSlug);
|
|
412
|
+
const itemTypeName = `${pascalName}AdminViewItem`;
|
|
413
|
+
const dataSetTypeName = `${pascalName}AdminViewDataSet`;
|
|
414
|
+
const componentName = `${pascalName}AdminViewScreen`;
|
|
415
|
+
const dataViewsName = `${camelName}AdminDataViews`;
|
|
416
|
+
const useAdminViewDataName = `use${pascalName}AdminViewData`;
|
|
417
|
+
const title = toTitleCase(adminViewSlug);
|
|
418
|
+
return `import type { DataViewsConfig, DataViewsView } from '@wp-typia/dataviews';
|
|
419
|
+
import { Notice, Spinner } from '@wordpress/components';
|
|
420
|
+
import { useState } from '@wordpress/element';
|
|
421
|
+
import { __ } from '@wordpress/i18n';
|
|
422
|
+
import { DataViews } from '@wordpress/dataviews/wp';
|
|
423
|
+
|
|
424
|
+
import { ${dataViewsName} } from './config';
|
|
425
|
+
import { ${useAdminViewDataName} } from './data';
|
|
426
|
+
import type { ${dataSetTypeName}, ${itemTypeName} } from './types';
|
|
427
|
+
|
|
428
|
+
const TypedDataViews = DataViews as unknown as <TItem extends object>(
|
|
429
|
+
\tprops: DataViewsConfig<TItem>,
|
|
430
|
+
) => ReturnType<typeof DataViews>;
|
|
431
|
+
|
|
432
|
+
const EMPTY_DATA_SET: ${dataSetTypeName} = {
|
|
433
|
+
\titems: [],
|
|
434
|
+
\tpaginationInfo: {
|
|
435
|
+
\t\ttotalItems: 0,
|
|
436
|
+
\t\ttotalPages: 1,
|
|
437
|
+
\t},
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
export function ${componentName}() {
|
|
441
|
+
\tconst [view, setView] = useState<DataViewsView<${itemTypeName}>>(
|
|
442
|
+
\t\t${dataViewsName}.defaultView,
|
|
443
|
+
\t);
|
|
444
|
+
\tconst {
|
|
445
|
+
\t\tdataSet = EMPTY_DATA_SET,
|
|
446
|
+
\t\terror,
|
|
447
|
+
\t\tisLoading,
|
|
448
|
+
\t} = ${useAdminViewDataName}(view);
|
|
449
|
+
\tconst config = ${dataViewsName}.createConfig({
|
|
450
|
+
\t\tdata: dataSet.items,
|
|
451
|
+
\t\tisLoading,
|
|
452
|
+
\t\tonChangeView: setView,
|
|
453
|
+
\t\tpaginationInfo: dataSet.paginationInfo,
|
|
454
|
+
\t\tview,
|
|
455
|
+
\t});
|
|
456
|
+
|
|
457
|
+
\treturn (
|
|
458
|
+
\t\t<div className="wp-typia-admin-view-screen">
|
|
459
|
+
\t\t\t<header className="wp-typia-admin-view-screen__header">
|
|
460
|
+
\t\t\t\t<div>
|
|
461
|
+
\t\t\t\t\t<p className="wp-typia-admin-view-screen__eyebrow">
|
|
462
|
+
\t\t\t\t\t\t{ __( 'DataViews admin screen', ${quoteTsString(textDomain)} ) }
|
|
463
|
+
\t\t\t\t\t</p>
|
|
464
|
+
\t\t\t\t\t<h1>{ __( ${quoteTsString(title)}, ${quoteTsString(textDomain)} ) }</h1>
|
|
465
|
+
\t\t\t\t\t<p>
|
|
466
|
+
\t\t\t\t\t\t{ __( 'This screen reads from the WordPress core-data entity store. Extend data.ts when you need entity-specific field mapping or edit flows.', ${quoteTsString(textDomain)} ) }
|
|
467
|
+
\t\t\t\t\t</p>
|
|
468
|
+
\t\t\t\t</div>
|
|
469
|
+
\t\t\t\t<div className="wp-typia-admin-view-screen__actions">
|
|
470
|
+
\t\t\t\t\t{ isLoading ? <Spinner /> : null }
|
|
471
|
+
\t\t\t\t</div>
|
|
472
|
+
\t\t\t</header>
|
|
473
|
+
\t\t\t{ error ? (
|
|
474
|
+
\t\t\t\t<Notice isDismissible={ false } status="error">
|
|
475
|
+
\t\t\t\t\t{ error }
|
|
476
|
+
\t\t\t\t</Notice>
|
|
477
|
+
\t\t\t) : null }
|
|
478
|
+
\t\t\t<TypedDataViews<${itemTypeName}> { ...config } />
|
|
479
|
+
\t\t</div>
|
|
480
|
+
\t);
|
|
481
|
+
}
|
|
482
|
+
`;
|
|
483
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds starter item and dataset types for the default admin-view variant.
|
|
3
|
+
*
|
|
4
|
+
* @param adminViewSlug - Admin-view slug used to derive generated type names.
|
|
5
|
+
* @returns Generated TypeScript source for default admin-view types.
|
|
6
|
+
*/
|
|
7
|
+
export declare function buildDefaultAdminViewTypesSource(adminViewSlug: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Builds a DataViews config module for the default admin-view variant.
|
|
10
|
+
*
|
|
11
|
+
* @param adminViewSlug - Admin-view slug used to derive generated identifiers.
|
|
12
|
+
* @param textDomain - WordPress i18n text domain for generated labels.
|
|
13
|
+
* @returns Generated TypeScript source for the default DataViews config.
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildDefaultAdminViewConfigSource(adminViewSlug: string, textDomain: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Builds an in-memory starter data module for the default admin-view variant.
|
|
18
|
+
*
|
|
19
|
+
* @param adminViewSlug - Admin-view slug used to derive generated identifiers.
|
|
20
|
+
* @returns Generated TypeScript source for starter data loading.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildDefaultAdminViewDataSource(adminViewSlug: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Builds the React screen module for the default admin-view variant.
|
|
25
|
+
*
|
|
26
|
+
* @param adminViewSlug - Admin-view slug used to derive generated identifiers.
|
|
27
|
+
* @param textDomain - WordPress i18n text domain for generated labels.
|
|
28
|
+
* @returns Generated TSX source for the default admin-view screen.
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildAdminViewScreenSource(adminViewSlug: string, textDomain: string): string;
|