@forgewp/compiler 0.4.2 → 0.4.4
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/README.md +70 -3
- package/bin/add.js +30 -15
- package/bin/analyze.js +66 -1
- package/bin/cli.js +149 -70
- package/bin/doctor.js +21 -12
- package/bin/export.js +69 -20
- package/bin/fresh.js +6 -1
- package/bin/i18n-extract.js +3 -10
- package/bin/i18n-translate.js +15 -24
- package/bin/make-block.js +24 -0
- package/bin/make-editable.js +166 -0
- package/bin/make-form.js +131 -0
- package/bin/make-island.js +11 -0
- package/bin/make-loop.js +147 -0
- package/bin/make-mail.js +27 -0
- package/bin/make-page.js +83 -0
- package/bin/make-post-type.js +68 -29
- package/bin/make-sandbox.js +609 -0
- package/bin/make-section.js +221 -0
- package/bin/make-shell.js +375 -0
- package/bin/repair.js +14 -26
- package/bin/seed.js +119 -0
- package/bin/sync-routes.js +107 -85
- package/lib/adapters/html-adapter.js +13 -3
- package/lib/adapters/stub-adapter.js +10 -2
- package/lib/add-component.js +153 -92
- package/lib/asset-loader.js +333 -1
- package/lib/assets/asset-graph.js +432 -0
- package/lib/assets/asset-pipeline.js +125 -0
- package/lib/assets/diagnostics-report.js +345 -0
- package/lib/assets/external-fetcher.js +173 -0
- package/lib/assets/font-orchestrator.js +348 -0
- package/lib/assets/font-usage-scanner.js +242 -0
- package/lib/assets/image-optimizer.js +229 -0
- package/lib/assets/index.js +51 -0
- package/lib/assets/preload-generator.js +70 -0
- package/lib/assets/public-url.js +153 -0
- package/lib/block-authoring-help.js +11 -0
- package/lib/blocks/ast-parser.js +67 -0
- package/lib/blocks/discover-blocks.js +146 -0
- package/lib/blocks/editor-scope.js +733 -0
- package/lib/blocks/editor-transpiler.js +1229 -0
- package/lib/blocks/index.js +2838 -0
- package/lib/blocks/php-transpiler.js +4928 -0
- package/lib/blocks/scanner.js +1487 -0
- package/lib/blocks/shared-utils.js +290 -0
- package/lib/blocks/source-sanitize.js +1449 -0
- package/lib/blueprints.js +77 -5
- package/lib/build-assets.js +38 -33
- package/lib/collect-page-template-routes.js +102 -0
- package/lib/collect-static-routes.js +175 -0
- package/lib/diagnostics.js +58 -33
- package/lib/export-theme.js +84 -5
- package/lib/extract-template-content.js +90 -0
- package/lib/forms-preview.js +42 -0
- package/lib/functions/cpt-routing.js +69 -0
- package/lib/functions/forms.js +2461 -0
- package/lib/functions/hydration-enqueuer.js +400 -0
- package/lib/functions/index.js +1623 -0
- package/lib/functions/load-menus.js +112 -0
- package/lib/functions/load-translations.js +148 -0
- package/lib/functions/rest-endpoints.js +2923 -0
- package/lib/functions/routing.js +765 -0
- package/lib/functions/seed-mock-data.js +392 -0
- package/lib/functions/seed-products.js +481 -0
- package/lib/functions/settings-page.js +273 -0
- package/lib/functions/theme-setup.js +494 -0
- package/lib/generate-theme.js +2076 -303
- package/lib/hydration/editable-schemas.js +332 -0
- package/lib/hydration/enter-hidden-initial.js +65 -0
- package/lib/hydration/form-schemas.js +227 -0
- package/lib/hydration/index.js +12 -0
- package/lib/hydration/is-interactive.js +951 -0
- package/lib/hydration/island-split.js +1231 -0
- package/lib/hydration/islands-scanner.js +599 -0
- package/lib/hydration/resolve-island-chunk.js +103 -0
- package/lib/hydration/resolve-island-component.js +52 -0
- package/lib/hydration/rollup-inputs.js +81 -0
- package/lib/hydration/root-class-extractor.js +220 -0
- package/lib/hydration/scan-app-providers.js +154 -0
- package/lib/hydration/static-lint.js +382 -0
- package/lib/hydration/transform.js +257 -0
- package/lib/hydration/uses-block-area.js +49 -0
- package/lib/hydration/utils.js +119 -0
- package/lib/i18n/translation-cache.js +141 -0
- package/lib/icon-registry.js +72 -0
- package/lib/index.d.ts +324 -8
- package/lib/index.js +3 -2
- package/lib/load-config.js +338 -144
- package/lib/mail-templates.js +37 -0
- package/lib/markup-processor.js +483 -92
- package/lib/node-runtime.js +7 -0
- package/lib/page-config-plugin.js +84 -0
- package/lib/php-builders.js +383 -42
- package/lib/react-adapter.js +1053 -246
- package/lib/registration-metadata.js +11 -0
- package/lib/render-theme.mts +1410 -543
- package/lib/route-layout.js +76 -0
- package/lib/template-discovery.js +58 -0
- package/lib/theme-compatibility.js +32 -0
- package/lib/validate-export.js +51 -2
- package/lib/validate.js +27 -5
- package/lib/virtual-plugin.js +319 -0
- package/lib/walkthrough.md +26 -0
- package/package.json +17 -5
- package/templates/PresetsStyle.tsx +1 -1
- package/templates/auth/cms/email-logs.json +9 -0
- package/templates/auth/cms/menus.json +11 -0
- package/templates/auth/cms/mock-data.json +123 -0
- package/templates/auth/cms/roles.json +7 -0
- package/templates/auth/cms/sessions.json +1 -0
- package/templates/auth/cms/site-settings.json +28 -0
- package/templates/auth/cms/translations.json +4 -0
- package/templates/auth/cms/users.json +46 -0
- package/templates/auth/components/dashboard-view-wrapper.tsx +168 -0
- package/templates/auth/components/forgot-password-form-wrapper.tsx +141 -0
- package/templates/auth/components/login-form-wrapper.tsx +300 -0
- package/templates/auth/components/reset-password-form-wrapper.tsx +190 -0
- package/templates/auth/components/signup-form-wrapper.tsx +257 -0
- package/templates/auth/components/verify-email-view-wrapper.tsx +265 -0
- package/templates/auth/pages/DashboardPage.tsx +12 -0
- package/templates/auth/pages/ForgotPasswordPage.tsx +11 -0
- package/templates/auth/pages/LoginPage.tsx +11 -0
- package/templates/auth/pages/ResetPasswordPage.tsx +11 -0
- package/templates/auth/pages/SignUpPage.tsx +11 -0
- package/templates/auth/pages/VerifyEmailPage.tsx +11 -0
- package/templates/auth/ui/button.tsx +57 -0
- package/templates/auth/ui/card.tsx +76 -0
- package/templates/auth/ui/field.tsx +242 -0
- package/templates/auth/ui/input.tsx +22 -0
- package/templates/auth/ui/label.tsx +24 -0
- package/templates/auth/ui/separator.tsx +31 -0
- package/templates/forgewp-config.ts +70 -3
- package/templates/menus.json +12 -10
- package/templates/mock-data.json +122 -433
- package/templates/products.json +5 -0
- package/templates/roles.json +7 -0
- package/templates/sessions.json +1 -0
- package/templates/users.json +38 -0
- package/templates/wordpress.tsx +1835 -1297
- package/bin/make-template.js +0 -145
- package/lib/block-compiler.js +0 -552
- package/lib/functions-builder.js +0 -2044
- package/lib/hydration-scanner.js +0 -821
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a WordPress Admin settings page for all site options detected
|
|
3
|
+
* via useWpOption() calls in the theme source.
|
|
4
|
+
*
|
|
5
|
+
* Options annotated with { postType: '...' } get a Select2 AJAX-powered
|
|
6
|
+
* post picker instead of a plain text input — scales to thousands of posts.
|
|
7
|
+
*
|
|
8
|
+
* @param {Array<{name: string, label: string, defaultValue: string, postType?: string|null}>} wpOptions
|
|
9
|
+
* @param {{textDomain: string}} config
|
|
10
|
+
* @returns {string} PHP code to append to functions.php
|
|
11
|
+
*/
|
|
12
|
+
export function buildSettingsPagePhp(wpOptions, config) {
|
|
13
|
+
if (!wpOptions || wpOptions.length === 0) return '';
|
|
14
|
+
|
|
15
|
+
const textDomain = config.textDomain || 'forgewp';
|
|
16
|
+
const fnPrefix = textDomain.replace(/-/g, '_');
|
|
17
|
+
const pageSlug = `${textDomain}-theme-options`;
|
|
18
|
+
const optionGroup = `${fnPrefix}_theme_options`;
|
|
19
|
+
const capability = 'manage_options';
|
|
20
|
+
const sectionId = `${fnPrefix}_main_section`;
|
|
21
|
+
const ajaxAction = `${fnPrefix}_search_posts`;
|
|
22
|
+
const nonceName = `${fnPrefix}_search_posts_nonce`;
|
|
23
|
+
|
|
24
|
+
const hasPostPicker = wpOptions.some(o => o.postType);
|
|
25
|
+
|
|
26
|
+
// ── register_setting() calls ───────────────────────────────────────────────
|
|
27
|
+
const registerCalls = wpOptions.map(({ name, label, defaultValue, postType }) => {
|
|
28
|
+
// Post-picker fields store a post ID; sanitize as absint-compatible integer string
|
|
29
|
+
const sanitize = postType
|
|
30
|
+
? 'absint'
|
|
31
|
+
: (name.includes('url') || name.includes('link') ? 'esc_url_raw' : 'sanitize_text_field');
|
|
32
|
+
return `
|
|
33
|
+
register_setting('${optionGroup}', '${name}', array(
|
|
34
|
+
'type' => 'string',
|
|
35
|
+
'sanitize_callback' => '${sanitize}',
|
|
36
|
+
'default' => '${(defaultValue || '').replace(/'/g, "\\'")}',
|
|
37
|
+
));`;
|
|
38
|
+
}).join('\n');
|
|
39
|
+
|
|
40
|
+
// ── add_settings_field() calls ─────────────────────────────────────────────
|
|
41
|
+
const fieldCalls = wpOptions.map(({ name, label }) => {
|
|
42
|
+
const escapedLabel = (label || name).replace(/'/g, "\\'");
|
|
43
|
+
return `
|
|
44
|
+
add_settings_field(
|
|
45
|
+
'${name}',
|
|
46
|
+
__('${escapedLabel}', '${textDomain}'),
|
|
47
|
+
'${fnPrefix}_render_field_${name}',
|
|
48
|
+
'${pageSlug}',
|
|
49
|
+
'${sectionId}'
|
|
50
|
+
);`;
|
|
51
|
+
}).join('\n');
|
|
52
|
+
|
|
53
|
+
// ── Individual field render callbacks ─────────────────────────────────────
|
|
54
|
+
const fieldCallbacks = wpOptions.map(({ name, label, defaultValue, postType }) => {
|
|
55
|
+
const escapedLabel = (label || name).replace(/'/g, "\\'");
|
|
56
|
+
const escapedDefault = (defaultValue || '').replace(/'/g, "\\'");
|
|
57
|
+
|
|
58
|
+
if (postType) {
|
|
59
|
+
// Select2-powered post picker
|
|
60
|
+
return `
|
|
61
|
+
function ${fnPrefix}_render_field_${name}() {
|
|
62
|
+
$value = get_option('${name}', '${escapedDefault}');
|
|
63
|
+
$selected_title = '';
|
|
64
|
+
if ($value && intval($value) > 0) {
|
|
65
|
+
$selected_post = get_post(intval($value));
|
|
66
|
+
$selected_title = $selected_post ? $selected_post->post_title . ' (ID: ' . $value . ')' : '';
|
|
67
|
+
}
|
|
68
|
+
?>
|
|
69
|
+
<select id="<?php echo esc_attr('${name}'); ?>"
|
|
70
|
+
name="<?php echo esc_attr('${name}'); ?>"
|
|
71
|
+
class="forgewp-post-select"
|
|
72
|
+
data-post-type="<?php echo esc_attr('${postType}'); ?>"
|
|
73
|
+
data-nonce="<?php echo esc_attr(wp_create_nonce('${nonceName}')); ?>"
|
|
74
|
+
style="min-width:400px">
|
|
75
|
+
<?php if ($value && $selected_title) : ?>
|
|
76
|
+
<option value="<?php echo esc_attr($value); ?>" selected>
|
|
77
|
+
<?php echo esc_html($selected_title); ?>
|
|
78
|
+
</option>
|
|
79
|
+
<?php else : ?>
|
|
80
|
+
<option value=""><?php _e('— Select a post —', '${textDomain}'); ?></option>
|
|
81
|
+
<?php endif; ?>
|
|
82
|
+
</select>
|
|
83
|
+
<p class="description"><?php _e('${escapedLabel}', '${textDomain}'); ?></p>
|
|
84
|
+
<?php
|
|
85
|
+
}`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Plain text input
|
|
89
|
+
return `
|
|
90
|
+
function ${fnPrefix}_render_field_${name}() {
|
|
91
|
+
$value = get_option('${name}', '${escapedDefault}');
|
|
92
|
+
echo '<input type="text" id="${name}" name="${name}" value="' . esc_attr($value) . '" class="regular-text" />';
|
|
93
|
+
echo '<p class="description">${escapedLabel}</p>';
|
|
94
|
+
}`;
|
|
95
|
+
}).join('\n');
|
|
96
|
+
|
|
97
|
+
// ── Select2 AJAX search handler (only emitted when there are postType options) ──
|
|
98
|
+
const ajaxHandler = hasPostPicker ? `
|
|
99
|
+
/**
|
|
100
|
+
* ForgeWP AJAX: search posts by type for the Theme Options post picker.
|
|
101
|
+
*/
|
|
102
|
+
if (!function_exists('${fnPrefix}_ajax_search_posts')) {
|
|
103
|
+
function ${fnPrefix}_ajax_search_posts() {
|
|
104
|
+
check_ajax_referer('${nonceName}', 'nonce');
|
|
105
|
+
if (!current_user_can('${capability}')) {
|
|
106
|
+
wp_send_json_error('Unauthorized', 403);
|
|
107
|
+
}
|
|
108
|
+
$post_type = isset($_GET['post_type']) ? sanitize_key($_GET['post_type']) : 'post';
|
|
109
|
+
$search = isset($_GET['search']) ? sanitize_text_field($_GET['search']) : '';
|
|
110
|
+
$results = array();
|
|
111
|
+
$query = new WP_Query(array(
|
|
112
|
+
'post_type' => $post_type,
|
|
113
|
+
'post_status' => 'publish',
|
|
114
|
+
's' => $search,
|
|
115
|
+
'posts_per_page' => 40,
|
|
116
|
+
'orderby' => 'title',
|
|
117
|
+
'order' => 'ASC',
|
|
118
|
+
'no_found_rows' => true,
|
|
119
|
+
));
|
|
120
|
+
foreach ($query->posts as $post) {
|
|
121
|
+
$results[] = array(
|
|
122
|
+
'id' => $post->ID,
|
|
123
|
+
'text' => $post->post_title . ' (ID: ' . $post->ID . ')',
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
wp_send_json_success($results);
|
|
127
|
+
}
|
|
128
|
+
add_action('wp_ajax_${ajaxAction}', '${fnPrefix}_ajax_search_posts');
|
|
129
|
+
}
|
|
130
|
+
` : '';
|
|
131
|
+
|
|
132
|
+
// ── Admin script enqueue (Select2 init + AJAX wiring) ─────────────────────
|
|
133
|
+
// WordPress core does NOT ship a public 'select2' script/style handle — calling
|
|
134
|
+
// wp_enqueue_script('select2') silently no-ops against an unregistered handle, which
|
|
135
|
+
// means the library never loads and the field falls back to a plain <select> containing
|
|
136
|
+
// only the single server-rendered <option> for the currently-stored value. We vendor our
|
|
137
|
+
// own copy of Select2 into the exported theme (see generate-theme.js) and enqueue that.
|
|
138
|
+
const select2Handle = `${fnPrefix}-select2`;
|
|
139
|
+
const enqueueScript = hasPostPicker ? `
|
|
140
|
+
if (!function_exists('${fnPrefix}_enqueue_options_page_assets')) {
|
|
141
|
+
function ${fnPrefix}_enqueue_options_page_assets($hook) {
|
|
142
|
+
// Only load on our settings page
|
|
143
|
+
if ($hook !== 'appearance_page_${pageSlug}') return;
|
|
144
|
+
|
|
145
|
+
$select2_js = get_template_directory() . '/assets/vendor/select2/select2.min.js';
|
|
146
|
+
$select2_css = get_template_directory() . '/assets/vendor/select2/select2.min.css';
|
|
147
|
+
if (!file_exists($select2_js)) return;
|
|
148
|
+
|
|
149
|
+
wp_enqueue_script(
|
|
150
|
+
'${select2Handle}',
|
|
151
|
+
get_template_directory_uri() . '/assets/vendor/select2/select2.min.js',
|
|
152
|
+
array('jquery'),
|
|
153
|
+
FORGEWP_THEME_VERSION,
|
|
154
|
+
true
|
|
155
|
+
);
|
|
156
|
+
if (file_exists($select2_css)) {
|
|
157
|
+
wp_enqueue_style(
|
|
158
|
+
'${select2Handle}',
|
|
159
|
+
get_template_directory_uri() . '/assets/vendor/select2/select2.min.css',
|
|
160
|
+
array(),
|
|
161
|
+
FORGEWP_THEME_VERSION
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Inline initialisation script
|
|
166
|
+
$init_js = "
|
|
167
|
+
jQuery(function($) {
|
|
168
|
+
$('.forgewp-post-select').each(function() {
|
|
169
|
+
var \\$select = $(this);
|
|
170
|
+
var postType = \\$select.data('post-type');
|
|
171
|
+
var nonce = \\$select.data('nonce');
|
|
172
|
+
var ajaxUrl = " . json_encode(admin_url('admin-ajax.php')) . ";
|
|
173
|
+
\\$select.select2({
|
|
174
|
+
placeholder: '— Type to search —',
|
|
175
|
+
allowClear: true,
|
|
176
|
+
minimumInputLength: 0,
|
|
177
|
+
ajax: {
|
|
178
|
+
url: ajaxUrl,
|
|
179
|
+
dataType: 'json',
|
|
180
|
+
delay: 250,
|
|
181
|
+
data: function(params) {
|
|
182
|
+
return {
|
|
183
|
+
action: '${ajaxAction}',
|
|
184
|
+
nonce: nonce,
|
|
185
|
+
post_type: postType,
|
|
186
|
+
search: params.term || '',
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
processResults: function(data) {
|
|
190
|
+
if (!data.success) return { results: [] };
|
|
191
|
+
return { results: data.data };
|
|
192
|
+
},
|
|
193
|
+
cache: true,
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
";
|
|
199
|
+
wp_add_inline_script('${select2Handle}', $init_js);
|
|
200
|
+
}
|
|
201
|
+
add_action('admin_enqueue_scripts', '${fnPrefix}_enqueue_options_page_assets');
|
|
202
|
+
}
|
|
203
|
+
` : '';
|
|
204
|
+
|
|
205
|
+
return `
|
|
206
|
+
/**
|
|
207
|
+
* ForgeWP Theme Options — Auto-generated from useWpOption() calls detected in source.
|
|
208
|
+
* Manage these at Appearance → Theme Options in the WordPress admin.
|
|
209
|
+
*
|
|
210
|
+
* Options with a postType annotation use a Select2 AJAX-powered post picker
|
|
211
|
+
* that scales to any number of posts without performance issues.
|
|
212
|
+
*/
|
|
213
|
+
|
|
214
|
+
${ajaxHandler}
|
|
215
|
+
${enqueueScript}
|
|
216
|
+
|
|
217
|
+
if (!function_exists('${fnPrefix}_register_settings')) {
|
|
218
|
+
function ${fnPrefix}_register_settings() {
|
|
219
|
+
${registerCalls}
|
|
220
|
+
|
|
221
|
+
add_settings_section(
|
|
222
|
+
'${sectionId}',
|
|
223
|
+
__('Theme Options', '${textDomain}'),
|
|
224
|
+
'__return_false',
|
|
225
|
+
'${pageSlug}'
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
${fieldCalls}
|
|
229
|
+
}
|
|
230
|
+
add_action('admin_init', '${fnPrefix}_register_settings');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (!function_exists('${fnPrefix}_add_options_page')) {
|
|
234
|
+
function ${fnPrefix}_add_options_page() {
|
|
235
|
+
add_theme_page(
|
|
236
|
+
__('Theme Options', '${textDomain}'),
|
|
237
|
+
__('Theme Options', '${textDomain}'),
|
|
238
|
+
'${capability}',
|
|
239
|
+
'${pageSlug}',
|
|
240
|
+
'${fnPrefix}_render_options_page'
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
add_action('admin_menu', '${fnPrefix}_add_options_page');
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (!function_exists('${fnPrefix}_render_options_page')) {
|
|
247
|
+
function ${fnPrefix}_render_options_page() {
|
|
248
|
+
if (!current_user_can('${capability}')) {
|
|
249
|
+
wp_die(__('You do not have permission to access this page.', '${textDomain}'));
|
|
250
|
+
}
|
|
251
|
+
?>
|
|
252
|
+
<div class="wrap">
|
|
253
|
+
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
|
|
254
|
+
<?php if (isset($_GET['settings-updated'])) : ?>
|
|
255
|
+
<div id="message" class="notice notice-success is-dismissible">
|
|
256
|
+
<p><?php _e('Settings saved.', '${textDomain}'); ?></p>
|
|
257
|
+
</div>
|
|
258
|
+
<?php endif; ?>
|
|
259
|
+
<form method="post" action="options.php">
|
|
260
|
+
<?php
|
|
261
|
+
settings_fields('${optionGroup}');
|
|
262
|
+
do_settings_sections('${pageSlug}');
|
|
263
|
+
submit_button(__('Save Settings', '${textDomain}'));
|
|
264
|
+
?>
|
|
265
|
+
</form>
|
|
266
|
+
</div>
|
|
267
|
+
<?php
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
${fieldCallbacks}
|
|
272
|
+
`;
|
|
273
|
+
}
|