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,46 @@
/**
* External dependencies.
*/
import { pick, cloneDeep } from 'lodash';
/**
* Carbon Fields dependencies.
*/
import { uniqueId } from '@carbon-fields/core';
/**
* Flattens a field.
*
* @param {Object} field
* @param {string} containerId
* @param {Object[]} accumulator
* @return {Object}
*/
export default function flattenField( field, containerId, accumulator ) {
field = cloneDeep( field );
// Replace the id of the field.
field.id = uniqueId();
// Keep reference to the container.
field.container_id = containerId;
// The complex fields represent a nested structure of fields.
// So we need to flat them as well.
if ( field.type === 'complex' ) {
field.value.forEach( ( group ) => {
group.id = uniqueId();
group.container_id = containerId;
group.fields = group.fields.map( ( groupField ) => flattenField( groupField, containerId, accumulator ) );
} );
}
accumulator.push( field );
return pick( field, [
'id',
'type',
'name',
'base_name'
] );
}

View file

@ -0,0 +1,23 @@
/**
* External dependencies.
*/
import create from 'callbag-create';
/**
* Callbag source factory from `addHandler` and `removeHandler` pair.
*
* @see https://github.com/Andarist/callbag-from-event-pattern
* @param {Function} addHandler
* @param {Function} removeHandler
* @param {Function} argsTransformer
* @return {Function}
*/
export default function fromEventPattern( addHandler, removeHandler, argsTransformer = ( ...args ) => args ) {
return create( ( sink ) => {
const handler = ( ...args ) => sink( 1, argsTransformer( ...args ) );
addHandler( handler );
return () => removeHandler( handler );
} );
}

View file

@ -0,0 +1,13 @@
/**
* External dependencies.
*/
import { isUndefined } from 'lodash';
/**
* Returns true if Gutenberg is presented.
*
* @return {boolean}
*/
export default function isGutenberg() {
return ! isUndefined( window._wpLoadBlockEditor );
}

View file

@ -0,0 +1,15 @@
/**
* Removes the prefix used to compact the input of Carbon Fields.
*
* @param {string} str
* @return {string}
*/
export default function stripCompactInputPrefix( str ) {
const { compactInput, compactInputKey } = window.cf.config;
if ( ! compactInput || str.indexOf( compactInputKey ) !== 0 ) {
return str;
}
return str.replace( new RegExp( `^${ compactInputKey }\\[(.+?)\\]` ), '$1' );
}

View file

@ -0,0 +1,16 @@
/**
* Source: https://github.com/kvz/locutus/blob/master/src/php/url/urldecode.js
*
* @param {string} str
* @return {string}
*/
export default function urldecode( str ) {
return decodeURIComponent( ( str + '' )
.replace( /%(?![\da-f]{2})/gi, function() {
// PHP tolerates poorly formed escape sequences
return '%25';
} )
.replace( /\+/g, '%20' )
);
}