PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.15
Yatra – Travel Booking & Tour Operator Software v3.0.15
3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 All 83 releases
yatra / assets / js / blocks / page-content.js

page-content.js in Yatra – Travel Booking & Tour Operator Software 3.0.15, at assets/js/blocks/page-content.js

90 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Yatra Page Content — block-editor registration.
3 *
4 * A dynamic, server-rendered block. PHP owns the front-end output via
5 * Yatra\Core\Template\FseTemplates::renderPageContentBlock(). The editor
6 * needs its own registration so the block:
7 * - Appears in the inserter / list view.
8 * - Renders a recognisable placeholder while editing a template.
9 * - Doesn't trigger the "Your site doesn't include support for the
10 * yatra/page-content block" warning when parsed from saved templates.
11 *
12 * No build step: this file is enqueued directly as a classic script that
13 * uses the wp.* globals provided by the editor.
14 */
15 ( function ( wp ) {
16 if ( ! wp || ! wp.blocks || ! wp.element ) {
17 return;
18 }
19 if ( wp.blocks.getBlockType && wp.blocks.getBlockType( 'yatra/page-content' ) ) {
20 return; // Already registered — avoid duplicate-registration console errors.
21 }
22
23 var el = wp.element.createElement;
24 var __ = ( wp.i18n && wp.i18n.__ ) ? wp.i18n.__ : function ( s ) { return s; };
25 var useBlockProps =
26 wp.blockEditor && wp.blockEditor.useBlockProps
27 ? wp.blockEditor.useBlockProps
28 : function () { return {}; };
29
30 wp.blocks.registerBlockType( 'yatra/page-content', {
31 apiVersion: 2,
32 title: __( 'Yatra Page Content', 'yatra' ),
33 description: __(
34 'Renders the current Yatra page (single trip, listing, booking, etc.) based on the request route.',
35 'yatra'
36 ),
37 category: 'theme',
38 icon: 'admin-site-alt3',
39 keywords: [ 'yatra', 'trip', 'booking', 'page' ],
40 supports: {
41 html: false,
42 reusable: false,
43 inserter: true,
44 multiple: false,
45 },
46 attributes: {
47 template: { type: 'string', default: '' },
48 },
49 edit: function ( props ) {
50 var template = ( props.attributes && props.attributes.template ) || '';
51 var label = template
52 ? __( 'Yatra Page Content', 'yatra' ) + ' — ' + template
53 : __( 'Yatra Page Content', 'yatra' );
54
55 return el(
56 'div',
57 useBlockProps( {
58 className: 'yatra-page-content-placeholder',
59 style: {
60 padding: '24px',
61 border: '1px dashed #c3c4c7',
62 background: '#f6f7f7',
63 color: '#50575e',
64 textAlign: 'center',
65 fontFamily:
66 '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
67 },
68 } ),
69 el(
70 'strong',
71 { style: { display: 'block', marginBottom: '6px' } },
72 label
73 ),
74 el(
75 'span',
76 { style: { fontSize: '13px' } },
77 __(
78 'Rendered on the front-end based on the current route. No editor preview.',
79 'yatra'
80 )
81 )
82 );
83 },
84 save: function () {
85 // Dynamic block — render handled by PHP render_callback.
86 return null;
87 },
88 } );
89 } )( window.wp );
90