PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.2
JetFormBuilder — Dynamic Blocks Form Builder v3.1.2
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 / package / blocks / store / selectors.js
jetformbuilder / assets / src / package / blocks / store Last commit date
actions.js 2 years ago constants.js 2 years ago dispatchers.js 2 years ago getPreparedBlocks.js 2 years ago index.js 2 years ago reducer.js 2 years ago selectors.js 2 years ago
selectors.js
171 lines
1 const selectors = {
2 getBlocks( state ) {
3 return state.blocks;
4 },
5 getBlockMap( state ) {
6 return state.blockMap;
7 },
8 getPropsToSave( state ) {
9 return state.propsToSave;
10 },
11 getFields(
12 state,
13 {
14 withInner = true,
15 currentId = false,
16 },
17 ) {
18 const fields = [];
19
20 const iterateFields = blocks => {
21 for ( const block of blocks ) {
22 if ( block.fields?.length && block.clientId !== currentId ) {
23 fields.push( ...block.fields );
24 }
25
26 if ( !withInner || !block.innerBlocks?.length ) {
27 continue;
28 }
29
30 iterateFields( block.innerBlocks );
31 }
32 };
33
34 iterateFields( state.blocks );
35
36 return fields;
37 },
38 isExecuted( state ) {
39 return state.executed;
40 },
41 isRecentlyAdded( state, clientId ) {
42 return -1 !== state.recentlyAdded.indexOf( clientId );
43 },
44 getUniqueNames( state, clientId ) {
45 const currentBlock = state.blockMap[ clientId ] ?? false;
46
47 if ( !currentBlock ) {
48 return {
49 hasChanged: false,
50 };
51 }
52
53 let hasChanged = false;
54
55 let names = currentBlock.fields.map( ( { value } ) => value );
56 const scope = currentBlock.hasOwnProperty( 'parentBlock' )
57 ? currentBlock.parentBlock.innerBlocks
58 : state.blocks;
59
60 const walkerFields = ( fields ) => {
61 for ( const field of fields ) {
62 const nameIndex = names.indexOf( field.value );
63
64 if ( -1 === nameIndex ) {
65 continue;
66 }
67
68 if ( 'field_name' === field.value ) {
69 hasChanged = true;
70 continue;
71 }
72
73 names[ nameIndex ] = `${ names[ nameIndex ] }_copy`;
74 hasChanged = true;
75 walkerFields( fields );
76 }
77 };
78
79 for ( const block of scope ) {
80 if ( clientId === block.clientId ) {
81 continue;
82 }
83 walkerFields( block.fields );
84 }
85
86 return {
87 hasChanged: hasChanged,
88 names: names.join( '|' ),
89 };
90 },
91 getSanitizedAttributes( state, attrs, { name: type } = {} ) {
92 for ( const attrsKey in attrs ) {
93 if ( !attrs.hasOwnProperty( attrsKey ) ) {
94 continue;
95 }
96
97 const sanitizers = (
98 state.sanitizers?.[ type ]?.[ attrsKey ] ??
99 state.sanitizers?.[ attrsKey ] ??
100 false
101 );
102
103 if ( !sanitizers?.length ) {
104 continue;
105 }
106
107 for ( const sanitizer of sanitizers ) {
108 if ( 'function' !== typeof sanitizer ) {
109 continue;
110 }
111 attrs[ attrsKey ] = sanitizer( attrs[ attrsKey ] );
112 }
113 }
114
115 return attrs;
116 },
117 isUniqueName( state, clientId ) {
118 const { hasChanged } = selectors.getUniqueNames( state, clientId );
119
120 return !hasChanged;
121 },
122 /**
123 * @since 3.1.0
124 *
125 * @param state
126 * @param blockId {String} Block clientId or name
127 * @returns {*}
128 */
129 getBlock( state, blockId ) {
130 return state.blocks.find( ( { name, clientId } ) => (
131 [ name, clientId ].includes( blockId )
132 ) );
133 },
134 getBlockByName( state, fieldName ) {
135 if ( !fieldName ) {
136 return false;
137 }
138
139 const iterateFields = blocks => {
140 for ( const block of blocks ) {
141 if ( block.fields.some(
142 ( { value } ) => value === fieldName,
143 ) ) {
144 return block;
145 }
146
147 if ( !block.innerBlocks?.length ) {
148 continue;
149 }
150
151 iterateFields( block.innerBlocks );
152 }
153 };
154
155 iterateFields( state.blocks );
156
157 return false;
158 },
159 getBlockNameByName( state, fieldName ) {
160 const block = selectors.getBlockByName( state, fieldName );
161
162 return block?.name ?? '';
163 },
164 getBlockById( state, clientId ) {
165 return state.blockMap[ clientId ] ?? false;
166 },
167 };
168
169 export default {
170 ...selectors,
171 };