MCPcopy
hub / github.com/puckeditor/puck / FieldsInternal

Function FieldsInternal

packages/core/components/Puck/components/Fields/index.tsx:181–231  ·  view source on GitHub ↗
({ wrapFields = true }: { wrapFields?: boolean })

Source from the content-addressed store, hash-verified

179const FieldsChildMemo = memo(FieldsChild);
180
181const FieldsInternal = ({ wrapFields = true }: { wrapFields?: boolean }) => {
182 const overrides = useAppStore((s) => s.overrides);
183 const componentResolving = useAppStore((s) => {
184 const loadingCount = s.selectedItem
185 ? s.componentState[s.selectedItem.props.id]?.loadingCount
186 : s.componentState["root"]?.loadingCount;
187
188 return (loadingCount ?? 0) > 0;
189 });
190 const itemSelector = useAppStore(useShallow((s) => s.state.ui.itemSelector));
191 const id = useAppStore((s) => s.selectedItem?.props.id);
192 const appStore = useAppStoreApi();
193 useRegisterFieldsSlice(appStore, id);
194
195 const fieldsLoading = useAppStore((s) => s.fields.loading);
196 const fieldNames = useAppStore(
197 useShallow((s) => {
198 if (s.fields.id === id) {
199 return Object.keys(s.fields.fields);
200 }
201
202 return [];
203 })
204 );
205
206 const isLoading = fieldsLoading || componentResolving;
207
208 const Wrapper = useMemo(() => overrides.fields || DefaultFields, [overrides]);
209
210 return (
211 <form
212 className={getClassName({ wrapFields })}
213 onSubmit={(e) => {
214 e.preventDefault();
215 }}
216 >
217 <Wrapper isLoading={isLoading} itemSelector={itemSelector}>
218 {fieldNames.map((fieldName) => (
219 <FieldsChildMemo key={fieldName} fieldName={fieldName} />
220 ))}
221 </Wrapper>
222 {isLoading && (
223 <div className={getClassName("loadingOverlay")}>
224 <div className={getClassName("loadingOverlayInner")}>
225 <Loader size={16} />
226 </div>
227 </div>
228 )}
229 </form>
230 );
231};
232
233export const Fields = memo(FieldsInternal);

Callers

nothing calls this directly

Calls 3

useAppStoreFunction · 0.90
useAppStoreApiFunction · 0.90
useRegisterFieldsSliceFunction · 0.90

Tested by

no test coverage detected