PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.3
JetFormBuilder — Dynamic Blocks Form Builder v3.1.3
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 / assets / src / frontend / main / reporting / functions.js
jetformbuilder / assets / src / frontend / main / reporting Last commit date
restrictions 2 years ago BrowserReporting.js 2 years ago ReportingContext.js 2 years ago ReportingInterface.js 2 years ago RestrictionError.js 2 years ago functions.js 2 years ago
functions.js
139 lines
1 /**
2 * @param node {HTMLElement}
3 */
4 import BrowserReporting from './BrowserReporting';
5 import { allRejected } from '../functions';
6 import InputData from '../inputs/InputData';
7 import NativeRestriction from './restrictions/NativeRestriction';
8 import RequiredRestriction from './restrictions/RequiredRestriction';
9
10 const {
11 applyFilters,
12 } = JetPlugins.hooks;
13
14 const getReportTypes = () => applyFilters(
15 'jet.fb.reporting',
16 [
17 BrowserReporting,
18 ],
19 );
20
21 let reportTypes = [];
22
23 const getDefaultRestrictions = () => applyFilters(
24 'jet.fb.restrictions.default',
25 [
26 NativeRestriction,
27 RequiredRestriction,
28 ],
29 );
30
31 let defaultRestrictions = [];
32
33 /**
34 * @param reporting {BrowserReporting}
35 * @param node
36 * @returns {*}
37 */
38 function createDefaultRestrictions( reporting, node ) {
39 if ( !defaultRestrictions.length ) {
40 defaultRestrictions = getDefaultRestrictions();
41 }
42
43 for ( const restriction of defaultRestrictions ) {
44 const current = new restriction();
45
46 if ( !current.isSupported( node, reporting ) ) {
47 continue;
48 }
49
50 reporting.restrictions.push( current );
51 }
52
53 reporting.restrictions.forEach( item => item.setReporting( reporting ) );
54 }
55
56 /**
57 * @param input {InputData}
58 * @return {AdvancedReporting|BrowserReporting}
59 */
60 function createReport( input ) {
61 if ( !reportTypes.length ) {
62 reportTypes = getReportTypes();
63 }
64
65 for ( const reportType of reportTypes ) {
66 const current = new reportType();
67
68 if ( !current.isSupported( input.nodes[ 0 ], input ) ) {
69 continue;
70 }
71 current.setInput( input );
72
73 return current;
74 }
75
76 throw new Error( 'Something went wrong' );
77 }
78
79 /**
80 * @param inputs {InputData[]}
81 * @param silence {Boolean}
82 *
83 * @return {Function[]}
84 */
85 function getValidateCallbacks( inputs, silence = false ) {
86 const callbacks = [];
87
88 inputs?.[ 0 ]?.getContext()?.reset( { silence } );
89
90 for ( const input of inputs ) {
91 if ( !(
92 input instanceof InputData
93 ) ) {
94 console.group( 'Input is not instance of InputData' );
95 console.error( input );
96 console.groupEnd();
97
98 continue;
99 }
100 callbacks.push(
101 ( resolve, reject ) => {
102 input.reporting.validateOnChangeState().
103 then( resolve ).
104 catch( reject );
105 },
106 );
107 }
108
109 return callbacks;
110 }
111
112 /**
113 * @param inputs {InputData[]}
114 * @param silence {Boolean}
115 * @return {Promise<unknown[]>}
116 */
117 function validateInputs( inputs, silence = false ) {
118 return Promise.all(
119 getValidateCallbacks( inputs, silence ).map(
120 current => new Promise( current ),
121 ),
122 );
123 }
124
125 /**
126 * @param inputs {InputData[]}
127 * @param silence {Boolean}
128 */
129 function validateInputsAll( inputs, silence = false ) {
130 return allRejected( getValidateCallbacks( inputs, silence ) );
131 }
132
133 export {
134 createReport,
135 validateInputs,
136 validateInputsAll,
137 createDefaultRestrictions,
138 getValidateCallbacks,
139 };