corvée(dépendances) ajoute Carbon Fields

This commit is contained in:
gcch 2024-08-09 18:45:01 +02:00
commit 62368587e5
459 changed files with 72750 additions and 26 deletions

View file

@ -0,0 +1,29 @@
/**
* Returns an action object used to setup the definitions state when first opening an editor.
*
* @param {Object} definitions
* @return {Object}
*/
export function setupContainerDefinitions( definitions ) {
return {
type: 'SETUP_CONTAINER_DEFINITIONS',
payload: {
definitions
}
};
}
/**
* Returns an action object used to setup the definitions state when first opening an editor.
*
* @param {Object} definitions
* @return {Object}
*/
export function setupFieldDefinitions( definitions ) {
return {
type: 'SETUP_FIELD_DEFINITIONS',
payload: {
definitions
}
};
}

View file

@ -0,0 +1,20 @@
/**
* External dependencies.
*/
import { registerStore } from '@wordpress/data';
/**
* Internal dependencies.
*/
import reducer from './reducer';
import * as actions from './actions';
import * as selectors from './selectors';
/**
* Register the store.
*/
registerStore( 'carbon-fields/blocks', {
reducer,
actions,
selectors
} );

View file

@ -0,0 +1,43 @@
/**
* External dependencies.
*/
import { combineReducers } from '@wordpress/data';
/**
* The reducer that keeps track of container definitions keyed by block's name.
*
* @param {Object} state
* @param {Object} action
* @return {Object}
*/
export function containerDefinitionsByBlockName( state = {}, action ) {
switch ( action.type ) {
case 'SETUP_CONTAINER_DEFINITIONS':
return action.payload.definitions;
default:
return state;
}
}
/**
* The reducer that keeps track of field definitions keyed by block's name.
*
* @param {Object} state
* @param {Object} action
* @return {Object}
*/
export function fieldDefinitionsByBlockName( state = {}, action ) {
switch ( action.type ) {
case 'SETUP_FIELD_DEFINITIONS':
return action.payload.definitions;
default:
return state;
}
}
export default combineReducers( {
containerDefinitionsByBlockName,
fieldDefinitionsByBlockName
} );

View file

@ -0,0 +1,25 @@
/**
* Get the container by a given block name.
*
* @param {Object} state
* @param {string} blockName
* @return {Object}
*/
export function getContainerDefinitionByBlockName( state, blockName ) {
return state.containerDefinitionsByBlockName[
blockName.replace( 'carbon-fields/', '' )
] || {};
}
/**
* Get the fields by a given block name.
*
* @param {Object} state
* @param {string} blockName
* @return {Object[]}
*/
export function getFieldDefinitionsByBlockName( state, blockName ) {
return state.fieldDefinitionsByBlockName[
blockName.replace( 'carbon-fields/', '' )
] || [];
}