PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / trunk
JetFormBuilder — Dynamic Blocks Form Builder vtrunk
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / html-parser / admin / HtmlParserModal.js
jetformbuilder / modules / html-parser / admin Last commit date
HtmlParserButton.js 1 year ago HtmlParserFooter.js 1 year ago HtmlParserModal.js 1 year ago index.js 1 year ago serialize.js 1 year ago
HtmlParserModal.js
156 lines
1 import {
2 TextareaControl,
3 Button,
4 Flex,
5 Notice,
6 Modal,
7 } from '@wordpress/components';
8 import { useState } from '@wordpress/element';
9 import { __ } from '@wordpress/i18n';
10 import HtmlParserFooter from './HtmlParserFooter';
11
12 const {
13 parseHTMLtoBlocks,
14 getFormInnerFields,
15 } = JetFormBuilderParser;
16
17 export default function HtmlParserModal( {setShowModal} ) {
18 const [ html, setHtml ] = useState( '' );
19 const [ formHTML, setFormHTML ] = useState( '' );
20 const [ isParsing, setParsing ] = useState( false );
21 const [ error, setError ] = useState( '' );
22
23 const handleSubmit = () => {
24 setParsing( true );
25 setError( '' );
26
27 try {
28 const innerHTML = getFormInnerFields( html );
29
30 const styledHTML = `
31 <div class="jet-form-builder-html-parser-preview">
32 <style>
33 .jet-form-builder-html-parser-preview {
34 pointer-events: none;
35 }
36 .jet-form-builder-html-parser-preview textarea,
37 .jet-form-builder-html-parser-preview input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
38 .jet-form-builder-html-parser-preview select {
39 display: block;
40 width: 100% !important;
41 max-width: 100% !important;
42 margin-bottom: 10px;
43 }
44 .jet-form-builder-html-parser-preview label {
45 display:block;
46 margin-bottom:5px;
47 }
48 .jet-form-builder-html-parser-preview br {
49 display:none;
50 }
51 .jet-form-builder-html-parser-preview input[type="submit"],
52 .jet-form-builder-html-parser-preview button {
53 display:block;
54 border: none;
55 background-color: #0071a1;
56 color: #fff;
57 padding: 10px 20px;
58 cursor: pointer;
59 }
60 </style>
61 ${innerHTML}
62 </div>
63 `;
64
65 setFormHTML( styledHTML );
66 } catch ( err ) {
67 console.error( err );
68 setError(
69 err?.message ||
70 __( 'Failed to parse HTML.', 'jet-form-builder' )
71 );
72 } finally {
73 setParsing( false );
74 }
75 };
76
77 return (
78 <Modal
79 style={ { width: '60vw' } }
80 onRequestClose={ () => setShowModal( false ) }
81 title={ __( 'Import HTML Form', 'jet-form-builder' ) }
82 className="jfb-html-parser-modal"
83 >
84 { error && (
85 <Notice
86 status="error"
87 isDismissible
88 onRemove={ () => setError( '' ) }
89 >
90 { error }
91 </Notice>
92 ) }
93
94 { Boolean( formHTML.length ) ? (
95 <>
96 <div
97 dangerouslySetInnerHTML={ { __html: formHTML } }
98 style={ {
99 padding: '2em 1em',
100 backgroundColor: '#f6f7f7',
101 marginBottom: '1em',
102 } }
103 />
104
105 <HtmlParserFooter
106 clearHTML={ () => setFormHTML( '' ) }
107 formHTML={ formHTML }
108 rawHTML={ html }
109 setShowModal={ setShowModal }
110 />
111 </>
112 ) : (
113 <>
114 <TextareaControl
115 label={ __( 'Paste your HTML here', 'jet-form-builder' ) }
116 value={ html }
117 onChange={ setHtml }
118 rows={ 7 }
119 />
120
121 <ul style={ {
122 listStyle: 'disc',
123 paddingInlineStart: '1em',
124 } }>
125 <li>{ __(
126 'You can use any HTML code that contains form elements, but only headings, form controls, and buttons will be parsed.',
127 'jet-form-builder',
128 ) }</li>
129 <li>{ __(
130 `All the code you paste here will be parsed into a single Form, even if it contains more than one <form> tag.`,
131 'jet-form-builder',
132 ) }</li>
133 <li>{ __(
134 `The parser can only understand form elements and structure; it can't parse styling or behavior.`,
135 'jet-form-builder',
136 ) }</li>
137 </ul>
138
139 <Flex justify="flex-end" style={ { marginTop: '1em' } }>
140 <Button
141 isPrimary
142 isBusy={ isParsing }
143 disabled={ isParsing || !html.trim().length }
144 onClick={ handleSubmit }
145 >
146 { isParsing
147 ? __( 'Parsing...', 'jet-form-builder' )
148 : __( 'Parse HTML', 'jet-form-builder' ) }
149 </Button>
150 </Flex>
151 </>
152 ) }
153 </Modal>
154 );
155 }
156