commands
4 months ago
pro
2 months ago
acf-escaped-html-notice.asset.php
1 year ago
acf-escaped-html-notice.js
1 year ago
acf-escaped-html-notice.js.map
1 year ago
acf-escaped-html-notice.min.asset.php
9 months ago
acf-escaped-html-notice.min.js
9 months ago
acf-field-group.asset.php
5 months ago
acf-field-group.js
5 months ago
acf-field-group.js.map
5 months ago
acf-field-group.min.asset.php
5 months ago
acf-field-group.min.js
5 months ago
acf-input.asset.php
2 months ago
acf-input.js
2 months ago
acf-input.js.map
2 months ago
acf-input.min.asset.php
2 months ago
acf-input.min.js
2 months ago
acf-internal-post-type.asset.php
9 months ago
acf-internal-post-type.js
9 months ago
acf-internal-post-type.js.map
9 months ago
acf-internal-post-type.min.asset.php
9 months ago
acf-internal-post-type.min.js
9 months ago
acf.asset.php
9 months ago
acf.js
9 months ago
acf.js.map
9 months ago
acf.min.asset.php
9 months ago
acf.min.js
9 months ago
index.php
1 year ago
scf-bindings.asset.php
8 months ago
scf-bindings.js
8 months ago
scf-bindings.js.map
8 months ago
scf-bindings.min.asset.php
8 months ago
scf-bindings.min.js
8 months ago
scf-bindings.js
1158 lines
| 1 | /******/ (() => { // webpackBootstrap |
| 2 | /******/ "use strict"; |
| 3 | /******/ var __webpack_modules__ = ({ |
| 4 | |
| 5 | /***/ "./assets/src/js/bindings/block-editor.js": |
| 6 | /*!************************************************!*\ |
| 7 | !*** ./assets/src/js/bindings/block-editor.js ***! |
| 8 | \************************************************/ |
| 9 | /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { |
| 10 | |
| 11 | __webpack_require__.r(__webpack_exports__); |
| 12 | /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); |
| 13 | /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__); |
| 14 | /* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/hooks */ "@wordpress/hooks"); |
| 15 | /* harmony import */ var _wordpress_hooks__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__); |
| 16 | /* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose"); |
| 17 | /* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_2__); |
| 18 | /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor"); |
| 19 | /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__); |
| 20 | /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components"); |
| 21 | /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__); |
| 22 | /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); |
| 23 | /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__); |
| 24 | /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./constants */ "./assets/src/js/bindings/constants.js"); |
| 25 | /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./utils */ "./assets/src/js/bindings/utils.js"); |
| 26 | /* harmony import */ var _hooks__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./hooks */ "./assets/src/js/bindings/hooks.js"); |
| 27 | /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! react/jsx-runtime */ "react/jsx-runtime"); |
| 28 | /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__); |
| 29 | /** |
| 30 | * WordPress dependencies |
| 31 | */ |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | /** |
| 40 | * Internal dependencies |
| 41 | */ |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | /** |
| 47 | * Add custom block binding controls to supported blocks. |
| 48 | * |
| 49 | * @since 6.5.0 |
| 50 | */ |
| 51 | |
| 52 | const withCustomControls = (0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_2__.createHigherOrderComponent)(BlockEdit => { |
| 53 | return props => { |
| 54 | const bindableAttributes = (0,_utils__WEBPACK_IMPORTED_MODULE_7__.getBindableAttributes)(props.name); |
| 55 | const { |
| 56 | updateBlockBindings, |
| 57 | removeAllBlockBindings |
| 58 | } = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.useBlockBindingsUtils)(); |
| 59 | |
| 60 | // Get editor context |
| 61 | const { |
| 62 | isSiteEditor, |
| 63 | templatePostType |
| 64 | } = (0,_hooks__WEBPACK_IMPORTED_MODULE_8__.useSiteEditorContext)(); |
| 65 | |
| 66 | // Get fields based on editor context |
| 67 | const postEditorFields = (0,_hooks__WEBPACK_IMPORTED_MODULE_8__.usePostEditorFields)(); |
| 68 | const { |
| 69 | fields: siteEditorFields |
| 70 | } = (0,_hooks__WEBPACK_IMPORTED_MODULE_8__.useSiteEditorFields)(templatePostType); |
| 71 | |
| 72 | // Use appropriate fields based on context |
| 73 | const activeFields = isSiteEditor ? siteEditorFields : postEditorFields; |
| 74 | |
| 75 | // Convert fields to options format |
| 76 | const allFieldOptions = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useMemo)(() => (0,_utils__WEBPACK_IMPORTED_MODULE_7__.fieldsToOptions)(activeFields), [activeFields]); |
| 77 | |
| 78 | // Track bound fields |
| 79 | const { |
| 80 | boundFields, |
| 81 | setBoundFields |
| 82 | } = (0,_hooks__WEBPACK_IMPORTED_MODULE_8__.useBoundFields)(props.attributes); |
| 83 | |
| 84 | // Get filtered field options for a specific attribute |
| 85 | const getAttributeFieldOptions = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useCallback)((attribute = null) => { |
| 86 | return (0,_utils__WEBPACK_IMPORTED_MODULE_7__.getFilteredFieldOptions)(allFieldOptions, props.name, attribute); |
| 87 | }, [allFieldOptions, props.name]); |
| 88 | |
| 89 | // Check if all attributes can use unified binding mode |
| 90 | const canUseAllAttributesMode = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useMemo)(() => (0,_utils__WEBPACK_IMPORTED_MODULE_7__.canUseUnifiedBinding)(props.name, bindableAttributes), [props.name, bindableAttributes]); |
| 91 | |
| 92 | // Handle field selection changes |
| 93 | const handleFieldChange = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useCallback)((attribute, value) => { |
| 94 | if (Array.isArray(attribute)) { |
| 95 | // Handle multiple attributes at once |
| 96 | const newBoundFields = { |
| 97 | ...boundFields |
| 98 | }; |
| 99 | const bindings = {}; |
| 100 | attribute.forEach(attr => { |
| 101 | newBoundFields[attr] = value; |
| 102 | bindings[attr] = value ? { |
| 103 | source: _constants__WEBPACK_IMPORTED_MODULE_6__.BINDING_SOURCE, |
| 104 | args: { |
| 105 | key: value |
| 106 | } |
| 107 | } : undefined; |
| 108 | }); |
| 109 | setBoundFields(newBoundFields); |
| 110 | updateBlockBindings(bindings); |
| 111 | } else { |
| 112 | // Handle single attribute |
| 113 | setBoundFields(prev => ({ |
| 114 | ...prev, |
| 115 | [attribute]: value |
| 116 | })); |
| 117 | updateBlockBindings({ |
| 118 | [attribute]: value ? { |
| 119 | source: _constants__WEBPACK_IMPORTED_MODULE_6__.BINDING_SOURCE, |
| 120 | args: { |
| 121 | key: value |
| 122 | } |
| 123 | } : undefined |
| 124 | }); |
| 125 | } |
| 126 | }, [boundFields, setBoundFields, updateBlockBindings]); |
| 127 | |
| 128 | // Handle reset all bindings |
| 129 | const handleReset = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useCallback)(() => { |
| 130 | removeAllBlockBindings(); |
| 131 | setBoundFields({}); |
| 132 | }, [removeAllBlockBindings, setBoundFields]); |
| 133 | |
| 134 | // Determine if we should show the panel |
| 135 | const shouldShowPanel = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useMemo)(() => { |
| 136 | // In site editor, show panel if block has bindable attributes |
| 137 | if (isSiteEditor) { |
| 138 | return bindableAttributes && bindableAttributes.length > 0; |
| 139 | } |
| 140 | // In post editor, only show if we have fields available |
| 141 | return allFieldOptions.length > 0 && bindableAttributes && bindableAttributes.length > 0; |
| 142 | }, [isSiteEditor, allFieldOptions, bindableAttributes]); |
| 143 | if (!shouldShowPanel) { |
| 144 | return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(BlockEdit, { |
| 145 | ...props |
| 146 | }); |
| 147 | } |
| 148 | return /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.Fragment, { |
| 149 | children: [/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_3__.InspectorControls, { |
| 150 | ...props, |
| 151 | children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.__experimentalToolsPanel, { |
| 152 | label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__.__)('Connect to a field', 'secure-custom-fields'), |
| 153 | resetAll: handleReset, |
| 154 | children: canUseAllAttributesMode ? /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.__experimentalToolsPanelItem, { |
| 155 | hasValue: () => !!boundFields[bindableAttributes[0]], |
| 156 | label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__.__)('All attributes', 'secure-custom-fields'), |
| 157 | onDeselect: () => handleFieldChange(bindableAttributes, null), |
| 158 | isShownByDefault: true, |
| 159 | children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ComboboxControl, { |
| 160 | label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__.__)('Field', 'secure-custom-fields'), |
| 161 | placeholder: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__.__)('Select a field', 'secure-custom-fields'), |
| 162 | options: getAttributeFieldOptions(), |
| 163 | value: boundFields[bindableAttributes[0]] || '', |
| 164 | onChange: value => handleFieldChange(bindableAttributes, value), |
| 165 | __next40pxDefaultSize: true, |
| 166 | __nextHasNoMarginBottom: true |
| 167 | }) |
| 168 | }) : bindableAttributes.map(attribute => /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.__experimentalToolsPanelItem, { |
| 169 | hasValue: () => !!boundFields[attribute], |
| 170 | label: attribute, |
| 171 | onDeselect: () => handleFieldChange(attribute, null), |
| 172 | isShownByDefault: true, |
| 173 | children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(_wordpress_components__WEBPACK_IMPORTED_MODULE_4__.ComboboxControl, { |
| 174 | label: attribute, |
| 175 | placeholder: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__.__)('Select a field', 'secure-custom-fields'), |
| 176 | options: getAttributeFieldOptions(attribute), |
| 177 | value: boundFields[attribute] || '', |
| 178 | onChange: value => handleFieldChange(attribute, value), |
| 179 | __next40pxDefaultSize: true, |
| 180 | __nextHasNoMarginBottom: true |
| 181 | }) |
| 182 | }, `scf-binding-${attribute}`)) |
| 183 | }) |
| 184 | }), /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_9__.jsx)(BlockEdit, { |
| 185 | ...props |
| 186 | })] |
| 187 | }); |
| 188 | }; |
| 189 | }, 'withCustomControls'); |
| 190 | (0,_wordpress_hooks__WEBPACK_IMPORTED_MODULE_1__.addFilter)('editor.BlockEdit', 'secure-custom-fields/with-custom-controls', withCustomControls); |
| 191 | |
| 192 | /***/ }), |
| 193 | |
| 194 | /***/ "./assets/src/js/bindings/constants.js": |
| 195 | /*!*********************************************!*\ |
| 196 | !*** ./assets/src/js/bindings/constants.js ***! |
| 197 | \*********************************************/ |
| 198 | /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { |
| 199 | |
| 200 | __webpack_require__.r(__webpack_exports__); |
| 201 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 202 | /* harmony export */ BINDING_SOURCE: () => (/* binding */ BINDING_SOURCE), |
| 203 | /* harmony export */ BLOCK_BINDINGS_CONFIG: () => (/* binding */ BLOCK_BINDINGS_CONFIG) |
| 204 | /* harmony export */ }); |
| 205 | /** |
| 206 | * Block binding configuration |
| 207 | * |
| 208 | * Defines which SCF field types can be bound to specific block attributes. |
| 209 | */ |
| 210 | const BLOCK_BINDINGS_CONFIG = { |
| 211 | 'core/paragraph': { |
| 212 | content: ['text', 'textarea', 'date_picker', 'number', 'range'] |
| 213 | }, |
| 214 | 'core/heading': { |
| 215 | content: ['text', 'textarea', 'date_picker', 'number', 'range'] |
| 216 | }, |
| 217 | 'core/image': { |
| 218 | id: ['image'], |
| 219 | url: ['image'], |
| 220 | title: ['image'], |
| 221 | alt: ['image'] |
| 222 | }, |
| 223 | 'core/button': { |
| 224 | url: ['url'], |
| 225 | text: ['text', 'checkbox', 'select', 'date_picker'], |
| 226 | linkTarget: ['text', 'checkbox', 'select'], |
| 227 | rel: ['text', 'checkbox', 'select'] |
| 228 | } |
| 229 | }; |
| 230 | |
| 231 | /** |
| 232 | * Binding source identifier |
| 233 | */ |
| 234 | const BINDING_SOURCE = 'acf/field'; |
| 235 | |
| 236 | /***/ }), |
| 237 | |
| 238 | /***/ "./assets/src/js/bindings/field-processing.js": |
| 239 | /*!****************************************************!*\ |
| 240 | !*** ./assets/src/js/bindings/field-processing.js ***! |
| 241 | \****************************************************/ |
| 242 | /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { |
| 243 | |
| 244 | __webpack_require__.r(__webpack_exports__); |
| 245 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 246 | /* harmony export */ formatFieldLabel: () => (/* binding */ formatFieldLabel), |
| 247 | /* harmony export */ getFieldLabel: () => (/* binding */ getFieldLabel), |
| 248 | /* harmony export */ getSCFFields: () => (/* binding */ getSCFFields), |
| 249 | /* harmony export */ processFieldBinding: () => (/* binding */ processFieldBinding), |
| 250 | /* harmony export */ resolveImageAttribute: () => (/* binding */ resolveImageAttribute) |
| 251 | /* harmony export */ }); |
| 252 | /** |
| 253 | * Field processing utilities for block bindings |
| 254 | * |
| 255 | * @since 6.5.0 |
| 256 | */ |
| 257 | |
| 258 | /** |
| 259 | * Gets the SCF fields from the post entity. |
| 260 | * |
| 261 | * @since 6.5.0 |
| 262 | * |
| 263 | * @param {Object} post The post entity object. |
| 264 | * @return {Object} The SCF fields object with source data. |
| 265 | */ |
| 266 | function getSCFFields(post) { |
| 267 | if (!post?.acf) { |
| 268 | return {}; |
| 269 | } |
| 270 | |
| 271 | // Extract only the _source fields which contain the formatted data |
| 272 | const sourceFields = {}; |
| 273 | Object.entries(post.acf).forEach(([key, value]) => { |
| 274 | if (key.endsWith('_source')) { |
| 275 | // Remove the _source suffix to get the field name |
| 276 | const fieldName = key.replace('_source', ''); |
| 277 | sourceFields[fieldName] = value; |
| 278 | } |
| 279 | }); |
| 280 | return sourceFields; |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Resolves image attribute values from an image object. |
| 285 | * |
| 286 | * @since 6.5.0 |
| 287 | * |
| 288 | * @param {Object} imageObj The image object from SCF field data. |
| 289 | * @param {string} attribute The attribute to resolve (url, alt, title, id). |
| 290 | * @return {string|number} The resolved attribute value. |
| 291 | */ |
| 292 | function resolveImageAttribute(imageObj, attribute) { |
| 293 | if (!imageObj) { |
| 294 | return ''; |
| 295 | } |
| 296 | switch (attribute) { |
| 297 | case 'url': |
| 298 | return imageObj.url || ''; |
| 299 | case 'alt': |
| 300 | return imageObj.alt || ''; |
| 301 | case 'title': |
| 302 | return imageObj.title || ''; |
| 303 | case 'id': |
| 304 | return imageObj.id || imageObj.ID || ''; |
| 305 | default: |
| 306 | return ''; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Processes a single field binding and returns its resolved value. |
| 312 | * |
| 313 | * @since 6.7.0 |
| 314 | * |
| 315 | * @param {string} attribute The attribute being bound. |
| 316 | * @param {Object} args The binding arguments. |
| 317 | * @param {Object} scfFields The SCF fields object. |
| 318 | * @return {string} The resolved field value. |
| 319 | */ |
| 320 | function processFieldBinding(attribute, args, scfFields) { |
| 321 | const fieldName = args?.key; |
| 322 | const fieldConfig = scfFields[fieldName]; |
| 323 | if (!fieldConfig) { |
| 324 | return ''; |
| 325 | } |
| 326 | const fieldType = fieldConfig.type; |
| 327 | const fieldValue = fieldConfig.formatted_value; |
| 328 | switch (fieldType) { |
| 329 | case 'image': |
| 330 | return resolveImageAttribute(fieldValue, attribute); |
| 331 | case 'checkbox': |
| 332 | // For checkbox fields, join array values or return as string |
| 333 | if (Array.isArray(fieldValue)) { |
| 334 | return fieldValue.join(', '); |
| 335 | } |
| 336 | return fieldValue ? String(fieldValue) : ''; |
| 337 | case 'number': |
| 338 | case 'range': |
| 339 | return fieldValue ? String(fieldValue) : ''; |
| 340 | case 'date_picker': |
| 341 | case 'text': |
| 342 | case 'textarea': |
| 343 | case 'url': |
| 344 | case 'email': |
| 345 | case 'select': |
| 346 | default: |
| 347 | return fieldValue ? String(fieldValue) : ''; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * Formats a field key into a human-readable label. |
| 353 | * |
| 354 | * @since 6.7.0 |
| 355 | * |
| 356 | * @param {string} fieldKey The field key (e.g., 'my_field_name'). |
| 357 | * @return {string} Formatted label (e.g., 'My Field Name'). |
| 358 | */ |
| 359 | function formatFieldLabel(fieldKey) { |
| 360 | if (!fieldKey) { |
| 361 | return ''; |
| 362 | } |
| 363 | return fieldKey.split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' '); |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Gets the field label from metadata or formats the field key. |
| 368 | * |
| 369 | * @since 6.7.0 |
| 370 | * @param {string} fieldKey The field key. |
| 371 | * @param {Object} fieldMetadata Optional field metadata object. |
| 372 | * @param {string} defaultLabel Optional default label to use. |
| 373 | * @return {string} The field label. |
| 374 | */ |
| 375 | function getFieldLabel(fieldKey, fieldMetadata = null, defaultLabel = '') { |
| 376 | if (!fieldKey) { |
| 377 | return defaultLabel; |
| 378 | } |
| 379 | |
| 380 | // Try to get the label from the provided metadata |
| 381 | if (fieldMetadata && fieldMetadata[fieldKey]?.label) { |
| 382 | return fieldMetadata[fieldKey].label; |
| 383 | } |
| 384 | |
| 385 | // Fallback: format field key as a label |
| 386 | return formatFieldLabel(fieldKey); |
| 387 | } |
| 388 | |
| 389 | /***/ }), |
| 390 | |
| 391 | /***/ "./assets/src/js/bindings/fieldMetadataCache.js": |
| 392 | /*!******************************************************!*\ |
| 393 | !*** ./assets/src/js/bindings/fieldMetadataCache.js ***! |
| 394 | \******************************************************/ |
| 395 | /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { |
| 396 | |
| 397 | __webpack_require__.r(__webpack_exports__); |
| 398 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 399 | /* harmony export */ addFieldMetadata: () => (/* binding */ addFieldMetadata), |
| 400 | /* harmony export */ clearFieldMetadata: () => (/* binding */ clearFieldMetadata), |
| 401 | /* harmony export */ getAllFieldMetadata: () => (/* binding */ getAllFieldMetadata), |
| 402 | /* harmony export */ getFieldMetadata: () => (/* binding */ getFieldMetadata), |
| 403 | /* harmony export */ hasFieldMetadata: () => (/* binding */ hasFieldMetadata), |
| 404 | /* harmony export */ setFieldMetadata: () => (/* binding */ setFieldMetadata) |
| 405 | /* harmony export */ }); |
| 406 | /** |
| 407 | * SCF Field Metadata Cache |
| 408 | * |
| 409 | * @since 6.7.0 |
| 410 | * Simple cache for field metadata used in block bindings. |
| 411 | */ |
| 412 | |
| 413 | let fieldMetadataCache = {}; |
| 414 | |
| 415 | /** |
| 416 | * Set field metadata, replacing all existing data. |
| 417 | * |
| 418 | * @param {Object} fields - Field metadata object keyed by field key. |
| 419 | */ |
| 420 | const setFieldMetadata = fields => { |
| 421 | fieldMetadataCache = fields || {}; |
| 422 | }; |
| 423 | |
| 424 | /** |
| 425 | * Add field metadata, merging with existing data. |
| 426 | * |
| 427 | * @param {Object} fields - Field metadata object keyed by field key. |
| 428 | */ |
| 429 | const addFieldMetadata = fields => { |
| 430 | fieldMetadataCache = { |
| 431 | ...fieldMetadataCache, |
| 432 | ...fields |
| 433 | }; |
| 434 | }; |
| 435 | |
| 436 | /** |
| 437 | * Clear all field metadata. |
| 438 | */ |
| 439 | const clearFieldMetadata = () => { |
| 440 | fieldMetadataCache = {}; |
| 441 | }; |
| 442 | |
| 443 | /** |
| 444 | * Get field metadata for a specific field. |
| 445 | * |
| 446 | * @param {string} fieldKey - The field key to retrieve metadata for. |
| 447 | * @return {Object|null} Field metadata object or null if not found. |
| 448 | */ |
| 449 | const getFieldMetadata = fieldKey => { |
| 450 | return fieldMetadataCache[fieldKey] || null; |
| 451 | }; |
| 452 | |
| 453 | /** |
| 454 | * Get all field metadata. |
| 455 | * |
| 456 | * @return {Object} All field metadata. |
| 457 | */ |
| 458 | const getAllFieldMetadata = () => { |
| 459 | return fieldMetadataCache; |
| 460 | }; |
| 461 | |
| 462 | /** |
| 463 | * Check if field metadata exists for a given key. |
| 464 | * |
| 465 | * @param {string} fieldKey - The field key to check. |
| 466 | * @return {boolean} True if metadata exists, false otherwise. |
| 467 | */ |
| 468 | const hasFieldMetadata = fieldKey => { |
| 469 | return !!fieldMetadataCache[fieldKey]; |
| 470 | }; |
| 471 | |
| 472 | /***/ }), |
| 473 | |
| 474 | /***/ "./assets/src/js/bindings/hooks.js": |
| 475 | /*!*****************************************!*\ |
| 476 | !*** ./assets/src/js/bindings/hooks.js ***! |
| 477 | \*****************************************/ |
| 478 | /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { |
| 479 | |
| 480 | __webpack_require__.r(__webpack_exports__); |
| 481 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 482 | /* harmony export */ useBoundFields: () => (/* binding */ useBoundFields), |
| 483 | /* harmony export */ usePostEditorFields: () => (/* binding */ usePostEditorFields), |
| 484 | /* harmony export */ useSiteEditorContext: () => (/* binding */ useSiteEditorContext), |
| 485 | /* harmony export */ useSiteEditorFields: () => (/* binding */ useSiteEditorFields) |
| 486 | /* harmony export */ }); |
| 487 | /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); |
| 488 | /* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__); |
| 489 | /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 490 | /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_1__); |
| 491 | /* harmony import */ var _wordpress_core_data__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/core-data */ "@wordpress/core-data"); |
| 492 | /* harmony import */ var _wordpress_core_data__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_core_data__WEBPACK_IMPORTED_MODULE_2__); |
| 493 | /* harmony import */ var _wordpress_editor__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/editor */ "@wordpress/editor"); |
| 494 | /* harmony import */ var _wordpress_editor__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_editor__WEBPACK_IMPORTED_MODULE_3__); |
| 495 | /* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/api-fetch */ "@wordpress/api-fetch"); |
| 496 | /* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_4__); |
| 497 | /* harmony import */ var _wordpress_url__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/url */ "@wordpress/url"); |
| 498 | /* harmony import */ var _wordpress_url__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_url__WEBPACK_IMPORTED_MODULE_5__); |
| 499 | /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./utils */ "./assets/src/js/bindings/utils.js"); |
| 500 | /* harmony import */ var _fieldMetadataCache__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./fieldMetadataCache */ "./assets/src/js/bindings/fieldMetadataCache.js"); |
| 501 | /** |
| 502 | * Custom hooks for block bindings |
| 503 | */ |
| 504 | |
| 505 | |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | |
| 511 | |
| 512 | |
| 513 | |
| 514 | /** |
| 515 | * Custom hook to detect if we're in the site editor and get the template info. |
| 516 | * |
| 517 | * @since 6.7.0 |
| 518 | * @return {Object} Object containing isSiteEditor flag and templatePostType. |
| 519 | */ |
| 520 | function useSiteEditorContext() { |
| 521 | return (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.useSelect)(select => { |
| 522 | const { |
| 523 | getCurrentPostType, |
| 524 | getCurrentPostId |
| 525 | } = select(_wordpress_editor__WEBPACK_IMPORTED_MODULE_3__.store); |
| 526 | const { |
| 527 | getEditedEntityRecord |
| 528 | } = select(_wordpress_core_data__WEBPACK_IMPORTED_MODULE_2__.store); |
| 529 | const postType = getCurrentPostType(); |
| 530 | const postId = getCurrentPostId(); |
| 531 | const isSiteEditor = postType === 'wp_template'; |
| 532 | if (!isSiteEditor) { |
| 533 | return { |
| 534 | isSiteEditor: false, |
| 535 | templatePostType: null |
| 536 | }; |
| 537 | } |
| 538 | const template = getEditedEntityRecord('postType', 'wp_template', postId); |
| 539 | const templatePostType = (0,_utils__WEBPACK_IMPORTED_MODULE_6__.extractPostTypeFromTemplate)(template?.slug || ''); |
| 540 | return { |
| 541 | isSiteEditor: true, |
| 542 | templatePostType |
| 543 | }; |
| 544 | }, []); |
| 545 | } |
| 546 | |
| 547 | /** |
| 548 | * Custom hook to get SCF fields for the current post editor context. |
| 549 | * |
| 550 | * @since 6.7.0 |
| 551 | * @return {Object} Object containing the fields map. |
| 552 | */ |
| 553 | function usePostEditorFields() { |
| 554 | return (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.useSelect)(select => { |
| 555 | const { |
| 556 | getCurrentPostType, |
| 557 | getCurrentPostId |
| 558 | } = select(_wordpress_editor__WEBPACK_IMPORTED_MODULE_3__.store); |
| 559 | const { |
| 560 | getEditedEntityRecord |
| 561 | } = select(_wordpress_core_data__WEBPACK_IMPORTED_MODULE_2__.store); |
| 562 | const postType = getCurrentPostType(); |
| 563 | const postId = getCurrentPostId(); |
| 564 | if (!postType || !postId || postType === 'wp_template') { |
| 565 | return {}; |
| 566 | } |
| 567 | const record = getEditedEntityRecord('postType', postType, postId); |
| 568 | |
| 569 | // Extract fields that have '_source' counterparts |
| 570 | const sourcedFields = {}; |
| 571 | if (record?.acf) { |
| 572 | Object.entries(record.acf).forEach(([key, value]) => { |
| 573 | if (key.endsWith('_source')) { |
| 574 | const baseFieldName = key.replace('_source', ''); |
| 575 | if (Object.hasOwn(record.acf, baseFieldName)) { |
| 576 | sourcedFields[baseFieldName] = value; |
| 577 | } |
| 578 | } |
| 579 | }); |
| 580 | } |
| 581 | return sourcedFields; |
| 582 | }, []); |
| 583 | } |
| 584 | |
| 585 | /** |
| 586 | * Custom hook to fetch and manage SCF field groups from the REST API. |
| 587 | * |
| 588 | * @since 6.7.0 |
| 589 | * @param {string|null} postType The post type to fetch fields for. |
| 590 | * @return {Object} Object containing fields, isLoading, and error. |
| 591 | */ |
| 592 | function useSiteEditorFields(postType) { |
| 593 | const [fields, setFields] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useState)({}); |
| 594 | const [isLoading, setIsLoading] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useState)(false); |
| 595 | const [error, setError] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useState)(null); |
| 596 | (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => { |
| 597 | if (!postType) { |
| 598 | setFields({}); |
| 599 | setIsLoading(false); |
| 600 | setError(null); |
| 601 | return; |
| 602 | } |
| 603 | let isCancelled = false; |
| 604 | setIsLoading(true); |
| 605 | setError(null); |
| 606 | const fetchFields = async () => { |
| 607 | try { |
| 608 | const path = (0,_wordpress_url__WEBPACK_IMPORTED_MODULE_5__.addQueryArgs)(`/wp/v2/types/${postType}`, { |
| 609 | context: 'edit' |
| 610 | }); |
| 611 | const postTypeData = await _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_4___default()({ |
| 612 | path |
| 613 | }); |
| 614 | if (isCancelled) { |
| 615 | return; |
| 616 | } |
| 617 | const fieldsMap = (0,_utils__WEBPACK_IMPORTED_MODULE_6__.formatFieldGroupsData)(postTypeData.scf_field_groups); |
| 618 | |
| 619 | // Store field metadata in the data store |
| 620 | (0,_fieldMetadataCache__WEBPACK_IMPORTED_MODULE_7__.addFieldMetadata)(fieldsMap); |
| 621 | setFields(fieldsMap); |
| 622 | setIsLoading(false); |
| 623 | } catch (err) { |
| 624 | if (!isCancelled) { |
| 625 | setError(err); |
| 626 | setIsLoading(false); |
| 627 | } |
| 628 | } |
| 629 | }; |
| 630 | fetchFields(); |
| 631 | |
| 632 | // Cleanup function to prevent state updates after unmount |
| 633 | return () => { |
| 634 | isCancelled = true; |
| 635 | }; |
| 636 | }, [postType]); |
| 637 | return { |
| 638 | fields, |
| 639 | isLoading, |
| 640 | error |
| 641 | }; |
| 642 | } |
| 643 | |
| 644 | /** |
| 645 | * Custom hook to manage block bindings state. |
| 646 | * |
| 647 | * @since 6.7.0 |
| 648 | * @param {Object} blockAttributes The block attributes object. |
| 649 | * @return {Object} Object containing boundFields and sync function. |
| 650 | */ |
| 651 | function useBoundFields(blockAttributes) { |
| 652 | const [boundFields, setBoundFields] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useState)({}); |
| 653 | (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => { |
| 654 | const currentBindings = blockAttributes?.metadata?.bindings || {}; |
| 655 | const newBoundFields = {}; |
| 656 | Object.keys(currentBindings).forEach(attribute => { |
| 657 | if (currentBindings[attribute]?.args?.key) { |
| 658 | newBoundFields[attribute] = currentBindings[attribute].args.key; |
| 659 | } |
| 660 | }); |
| 661 | setBoundFields(newBoundFields); |
| 662 | }, [blockAttributes?.metadata?.bindings]); |
| 663 | return { |
| 664 | boundFields, |
| 665 | setBoundFields |
| 666 | }; |
| 667 | } |
| 668 | |
| 669 | /***/ }), |
| 670 | |
| 671 | /***/ "./assets/src/js/bindings/sources.js": |
| 672 | /*!*******************************************!*\ |
| 673 | !*** ./assets/src/js/bindings/sources.js ***! |
| 674 | \*******************************************/ |
| 675 | /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { |
| 676 | |
| 677 | __webpack_require__.r(__webpack_exports__); |
| 678 | /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks"); |
| 679 | /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__); |
| 680 | /* harmony import */ var _wordpress_core_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/core-data */ "@wordpress/core-data"); |
| 681 | /* harmony import */ var _wordpress_core_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_core_data__WEBPACK_IMPORTED_MODULE_1__); |
| 682 | /* harmony import */ var _wordpress_editor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/editor */ "@wordpress/editor"); |
| 683 | /* harmony import */ var _wordpress_editor__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_editor__WEBPACK_IMPORTED_MODULE_2__); |
| 684 | /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); |
| 685 | /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__); |
| 686 | /* harmony import */ var _field_processing__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./field-processing */ "./assets/src/js/bindings/field-processing.js"); |
| 687 | /* harmony import */ var _fieldMetadataCache__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./fieldMetadataCache */ "./assets/src/js/bindings/fieldMetadataCache.js"); |
| 688 | /** |
| 689 | * WordPress dependencies |
| 690 | */ |
| 691 | |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | /** |
| 697 | * Internal dependencies |
| 698 | */ |
| 699 | |
| 700 | |
| 701 | |
| 702 | /** |
| 703 | * Register the SCF field binding source. |
| 704 | */ |
| 705 | (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__.registerBlockBindingsSource)({ |
| 706 | name: 'acf/field', |
| 707 | label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('SCF Fields', 'secure-custom-fields'), |
| 708 | getLabel({ |
| 709 | args, |
| 710 | select |
| 711 | }) { |
| 712 | const fieldKey = args?.key; |
| 713 | if (!fieldKey) { |
| 714 | return (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('SCF Fields', 'secure-custom-fields'); |
| 715 | } |
| 716 | const fieldMetadata = (0,_fieldMetadataCache__WEBPACK_IMPORTED_MODULE_5__.getFieldMetadata)(fieldKey); |
| 717 | if (fieldMetadata?.label) { |
| 718 | return fieldMetadata.label; |
| 719 | } |
| 720 | return (0,_field_processing__WEBPACK_IMPORTED_MODULE_4__.formatFieldLabel)(fieldKey); |
| 721 | }, |
| 722 | getValues({ |
| 723 | context, |
| 724 | bindings, |
| 725 | select |
| 726 | }) { |
| 727 | const { |
| 728 | getCurrentPostType |
| 729 | } = select(_wordpress_editor__WEBPACK_IMPORTED_MODULE_2__.store); |
| 730 | const currentPostType = getCurrentPostType(); |
| 731 | const isSiteEditor = currentPostType === 'wp_template'; |
| 732 | |
| 733 | // In site editor, return field labels as placeholder values |
| 734 | if (isSiteEditor) { |
| 735 | const result = {}; |
| 736 | Object.entries(bindings).forEach(([attribute, { |
| 737 | args |
| 738 | } = {}]) => { |
| 739 | const fieldKey = args?.key; |
| 740 | if (!fieldKey) { |
| 741 | result[attribute] = ''; |
| 742 | return; |
| 743 | } |
| 744 | const fieldMetadata = (0,_fieldMetadataCache__WEBPACK_IMPORTED_MODULE_5__.getFieldMetadata)(fieldKey); |
| 745 | result[attribute] = fieldMetadata?.label || (0,_field_processing__WEBPACK_IMPORTED_MODULE_4__.formatFieldLabel)(fieldKey); |
| 746 | }); |
| 747 | return result; |
| 748 | } |
| 749 | |
| 750 | // Regular post editor - get actual field values |
| 751 | const { |
| 752 | getEditedEntityRecord |
| 753 | } = select(_wordpress_core_data__WEBPACK_IMPORTED_MODULE_1__.store); |
| 754 | const post = context?.postType && context?.postId ? getEditedEntityRecord('postType', context.postType, context.postId) : undefined; |
| 755 | const scfFields = (0,_field_processing__WEBPACK_IMPORTED_MODULE_4__.getSCFFields)(post); |
| 756 | const result = {}; |
| 757 | Object.entries(bindings).forEach(([attribute, { |
| 758 | args |
| 759 | } = {}]) => { |
| 760 | const value = (0,_field_processing__WEBPACK_IMPORTED_MODULE_4__.processFieldBinding)(attribute, args, scfFields); |
| 761 | result[attribute] = value; |
| 762 | }); |
| 763 | return result; |
| 764 | }, |
| 765 | canUserEditValue() { |
| 766 | return false; |
| 767 | } |
| 768 | }); |
| 769 | |
| 770 | /***/ }), |
| 771 | |
| 772 | /***/ "./assets/src/js/bindings/utils.js": |
| 773 | /*!*****************************************!*\ |
| 774 | !*** ./assets/src/js/bindings/utils.js ***! |
| 775 | \*****************************************/ |
| 776 | /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { |
| 777 | |
| 778 | __webpack_require__.r(__webpack_exports__); |
| 779 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 780 | /* harmony export */ canUseUnifiedBinding: () => (/* binding */ canUseUnifiedBinding), |
| 781 | /* harmony export */ extractPostTypeFromTemplate: () => (/* binding */ extractPostTypeFromTemplate), |
| 782 | /* harmony export */ fieldsToOptions: () => (/* binding */ fieldsToOptions), |
| 783 | /* harmony export */ formatFieldGroupsData: () => (/* binding */ formatFieldGroupsData), |
| 784 | /* harmony export */ getAllowedFieldTypes: () => (/* binding */ getAllowedFieldTypes), |
| 785 | /* harmony export */ getBindableAttributes: () => (/* binding */ getBindableAttributes), |
| 786 | /* harmony export */ getFilteredFieldOptions: () => (/* binding */ getFilteredFieldOptions) |
| 787 | /* harmony export */ }); |
| 788 | /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants */ "./assets/src/js/bindings/constants.js"); |
| 789 | /** |
| 790 | * Utility functions for block bindings |
| 791 | */ |
| 792 | |
| 793 | |
| 794 | |
| 795 | /** |
| 796 | * Gets the bindable attributes for a given block. |
| 797 | * |
| 798 | * @since 6.7.0 |
| 799 | * @param {string} blockName The name of the block. |
| 800 | * @return {string[]} The bindable attributes for the block. |
| 801 | */ |
| 802 | function getBindableAttributes(blockName) { |
| 803 | const config = _constants__WEBPACK_IMPORTED_MODULE_0__.BLOCK_BINDINGS_CONFIG[blockName]; |
| 804 | return config ? Object.keys(config) : []; |
| 805 | } |
| 806 | |
| 807 | /** |
| 808 | * Gets the allowed field types for a specific block attribute. |
| 809 | * |
| 810 | * @since 6.7.0 |
| 811 | * @param {string} blockName The name of the block. |
| 812 | * @param {string|null} attribute The attribute name, or null for all types. |
| 813 | * @return {string[]|null} The allowed field types, or null if no restrictions. |
| 814 | */ |
| 815 | function getAllowedFieldTypes(blockName, attribute = null) { |
| 816 | const blockConfig = _constants__WEBPACK_IMPORTED_MODULE_0__.BLOCK_BINDINGS_CONFIG[blockName]; |
| 817 | if (!blockConfig) { |
| 818 | return null; |
| 819 | } |
| 820 | if (attribute) { |
| 821 | return blockConfig[attribute] || null; |
| 822 | } |
| 823 | |
| 824 | // Get all unique field types for the block |
| 825 | return [...new Set(Object.values(blockConfig).flat())]; |
| 826 | } |
| 827 | |
| 828 | /** |
| 829 | * Filters field options based on allowed field types. |
| 830 | * |
| 831 | * @since 6.7.0 |
| 832 | * @param {Array} fieldOptions Array of field option objects with value, label, and type. |
| 833 | * @param {string} blockName The name of the block. |
| 834 | * @param {string|null} attribute The attribute name, or null for all types. |
| 835 | * @return {Array} Filtered array of field options. |
| 836 | */ |
| 837 | function getFilteredFieldOptions(fieldOptions, blockName, attribute = null) { |
| 838 | if (!fieldOptions || fieldOptions.length === 0) { |
| 839 | return []; |
| 840 | } |
| 841 | const allowedTypes = getAllowedFieldTypes(blockName, attribute); |
| 842 | if (!allowedTypes) { |
| 843 | return fieldOptions; |
| 844 | } |
| 845 | return fieldOptions.filter(option => allowedTypes.includes(option.type)); |
| 846 | } |
| 847 | |
| 848 | /** |
| 849 | * Checks if all bindable attributes for a block support the same field types. |
| 850 | * |
| 851 | * @since 6.7.0 |
| 852 | * @param {string} blockName The name of the block. |
| 853 | * @param {string[]} bindableAttributes Array of bindable attribute names. |
| 854 | * @return {boolean} True if all attributes support the same field types. |
| 855 | */ |
| 856 | function canUseUnifiedBinding(blockName, bindableAttributes) { |
| 857 | if (!bindableAttributes || bindableAttributes.length <= 1) { |
| 858 | return false; |
| 859 | } |
| 860 | const blockConfig = _constants__WEBPACK_IMPORTED_MODULE_0__.BLOCK_BINDINGS_CONFIG[blockName]; |
| 861 | if (!blockConfig) { |
| 862 | return false; |
| 863 | } |
| 864 | const firstAttributeTypes = blockConfig[bindableAttributes[0]] || []; |
| 865 | return bindableAttributes.every(attr => { |
| 866 | const attrTypes = blockConfig[attr] || []; |
| 867 | return attrTypes.length === firstAttributeTypes.length && attrTypes.every(type => firstAttributeTypes.includes(type)); |
| 868 | }); |
| 869 | } |
| 870 | |
| 871 | /** |
| 872 | * Extracts the post type from a template slug. |
| 873 | * |
| 874 | * @since 6.7.0 |
| 875 | * @param {string} templateSlug The template slug (e.g., 'single-product', 'archive-post'). |
| 876 | * @return {string|null} The extracted post type, or null if not detected. |
| 877 | */ |
| 878 | function extractPostTypeFromTemplate(templateSlug) { |
| 879 | if (!templateSlug) { |
| 880 | return null; |
| 881 | } |
| 882 | |
| 883 | // Handle single templates |
| 884 | if (templateSlug.startsWith('single-')) { |
| 885 | return templateSlug.replace('single-', ''); |
| 886 | } |
| 887 | |
| 888 | // Handle archive templates |
| 889 | if (templateSlug.startsWith('archive-')) { |
| 890 | return templateSlug.replace('archive-', ''); |
| 891 | } |
| 892 | |
| 893 | // Default single template maps to 'post' |
| 894 | if (templateSlug === 'single') { |
| 895 | return 'post'; |
| 896 | } |
| 897 | return null; |
| 898 | } |
| 899 | |
| 900 | /** |
| 901 | * Formats field data from API response into a usable structure. |
| 902 | * |
| 903 | * @since 6.7.0 |
| 904 | * @param {Array} fieldGroups Array of field group objects from the API. |
| 905 | * @return {Object} Formatted fields map with field name as key. |
| 906 | */ |
| 907 | function formatFieldGroupsData(fieldGroups) { |
| 908 | const fieldsMap = {}; |
| 909 | if (!Array.isArray(fieldGroups)) { |
| 910 | return fieldsMap; |
| 911 | } |
| 912 | fieldGroups.forEach(group => { |
| 913 | if (Array.isArray(group.fields)) { |
| 914 | group.fields.forEach(field => { |
| 915 | fieldsMap[field.name] = { |
| 916 | label: field.label, |
| 917 | type: field.type |
| 918 | }; |
| 919 | }); |
| 920 | } |
| 921 | }); |
| 922 | return fieldsMap; |
| 923 | } |
| 924 | |
| 925 | /** |
| 926 | * Converts fields map to options array for ComboboxControl. |
| 927 | * |
| 928 | * @since 6.7.0 |
| 929 | * @param {Object} fieldsMap Object with field data. |
| 930 | * @return {Array} Array of option objects with value, label, and type. |
| 931 | */ |
| 932 | function fieldsToOptions(fieldsMap) { |
| 933 | if (!fieldsMap || Object.keys(fieldsMap).length === 0) { |
| 934 | return []; |
| 935 | } |
| 936 | return Object.entries(fieldsMap).map(([fieldName, fieldConfig]) => ({ |
| 937 | value: fieldName, |
| 938 | label: fieldConfig.label, |
| 939 | type: fieldConfig.type |
| 940 | })); |
| 941 | } |
| 942 | |
| 943 | /***/ }), |
| 944 | |
| 945 | /***/ "@wordpress/api-fetch": |
| 946 | /*!**********************************!*\ |
| 947 | !*** external ["wp","apiFetch"] ***! |
| 948 | \**********************************/ |
| 949 | /***/ ((module) => { |
| 950 | |
| 951 | module.exports = window["wp"]["apiFetch"]; |
| 952 | |
| 953 | /***/ }), |
| 954 | |
| 955 | /***/ "@wordpress/block-editor": |
| 956 | /*!*************************************!*\ |
| 957 | !*** external ["wp","blockEditor"] ***! |
| 958 | \*************************************/ |
| 959 | /***/ ((module) => { |
| 960 | |
| 961 | module.exports = window["wp"]["blockEditor"]; |
| 962 | |
| 963 | /***/ }), |
| 964 | |
| 965 | /***/ "@wordpress/blocks": |
| 966 | /*!********************************!*\ |
| 967 | !*** external ["wp","blocks"] ***! |
| 968 | \********************************/ |
| 969 | /***/ ((module) => { |
| 970 | |
| 971 | module.exports = window["wp"]["blocks"]; |
| 972 | |
| 973 | /***/ }), |
| 974 | |
| 975 | /***/ "@wordpress/components": |
| 976 | /*!************************************!*\ |
| 977 | !*** external ["wp","components"] ***! |
| 978 | \************************************/ |
| 979 | /***/ ((module) => { |
| 980 | |
| 981 | module.exports = window["wp"]["components"]; |
| 982 | |
| 983 | /***/ }), |
| 984 | |
| 985 | /***/ "@wordpress/compose": |
| 986 | /*!*********************************!*\ |
| 987 | !*** external ["wp","compose"] ***! |
| 988 | \*********************************/ |
| 989 | /***/ ((module) => { |
| 990 | |
| 991 | module.exports = window["wp"]["compose"]; |
| 992 | |
| 993 | /***/ }), |
| 994 | |
| 995 | /***/ "@wordpress/core-data": |
| 996 | /*!**********************************!*\ |
| 997 | !*** external ["wp","coreData"] ***! |
| 998 | \**********************************/ |
| 999 | /***/ ((module) => { |
| 1000 | |
| 1001 | module.exports = window["wp"]["coreData"]; |
| 1002 | |
| 1003 | /***/ }), |
| 1004 | |
| 1005 | /***/ "@wordpress/data": |
| 1006 | /*!******************************!*\ |
| 1007 | !*** external ["wp","data"] ***! |
| 1008 | \******************************/ |
| 1009 | /***/ ((module) => { |
| 1010 | |
| 1011 | module.exports = window["wp"]["data"]; |
| 1012 | |
| 1013 | /***/ }), |
| 1014 | |
| 1015 | /***/ "@wordpress/editor": |
| 1016 | /*!********************************!*\ |
| 1017 | !*** external ["wp","editor"] ***! |
| 1018 | \********************************/ |
| 1019 | /***/ ((module) => { |
| 1020 | |
| 1021 | module.exports = window["wp"]["editor"]; |
| 1022 | |
| 1023 | /***/ }), |
| 1024 | |
| 1025 | /***/ "@wordpress/element": |
| 1026 | /*!*********************************!*\ |
| 1027 | !*** external ["wp","element"] ***! |
| 1028 | \*********************************/ |
| 1029 | /***/ ((module) => { |
| 1030 | |
| 1031 | module.exports = window["wp"]["element"]; |
| 1032 | |
| 1033 | /***/ }), |
| 1034 | |
| 1035 | /***/ "@wordpress/hooks": |
| 1036 | /*!*******************************!*\ |
| 1037 | !*** external ["wp","hooks"] ***! |
| 1038 | \*******************************/ |
| 1039 | /***/ ((module) => { |
| 1040 | |
| 1041 | module.exports = window["wp"]["hooks"]; |
| 1042 | |
| 1043 | /***/ }), |
| 1044 | |
| 1045 | /***/ "@wordpress/i18n": |
| 1046 | /*!******************************!*\ |
| 1047 | !*** external ["wp","i18n"] ***! |
| 1048 | \******************************/ |
| 1049 | /***/ ((module) => { |
| 1050 | |
| 1051 | module.exports = window["wp"]["i18n"]; |
| 1052 | |
| 1053 | /***/ }), |
| 1054 | |
| 1055 | /***/ "@wordpress/url": |
| 1056 | /*!*****************************!*\ |
| 1057 | !*** external ["wp","url"] ***! |
| 1058 | \*****************************/ |
| 1059 | /***/ ((module) => { |
| 1060 | |
| 1061 | module.exports = window["wp"]["url"]; |
| 1062 | |
| 1063 | /***/ }), |
| 1064 | |
| 1065 | /***/ "react/jsx-runtime": |
| 1066 | /*!**********************************!*\ |
| 1067 | !*** external "ReactJSXRuntime" ***! |
| 1068 | \**********************************/ |
| 1069 | /***/ ((module) => { |
| 1070 | |
| 1071 | module.exports = window["ReactJSXRuntime"]; |
| 1072 | |
| 1073 | /***/ }) |
| 1074 | |
| 1075 | /******/ }); |
| 1076 | /************************************************************************/ |
| 1077 | /******/ // The module cache |
| 1078 | /******/ var __webpack_module_cache__ = {}; |
| 1079 | /******/ |
| 1080 | /******/ // The require function |
| 1081 | /******/ function __webpack_require__(moduleId) { |
| 1082 | /******/ // Check if module is in cache |
| 1083 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; |
| 1084 | /******/ if (cachedModule !== undefined) { |
| 1085 | /******/ return cachedModule.exports; |
| 1086 | /******/ } |
| 1087 | /******/ // Create a new module (and put it into the cache) |
| 1088 | /******/ var module = __webpack_module_cache__[moduleId] = { |
| 1089 | /******/ // no module.id needed |
| 1090 | /******/ // no module.loaded needed |
| 1091 | /******/ exports: {} |
| 1092 | /******/ }; |
| 1093 | /******/ |
| 1094 | /******/ // Execute the module function |
| 1095 | /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
| 1096 | /******/ |
| 1097 | /******/ // Return the exports of the module |
| 1098 | /******/ return module.exports; |
| 1099 | /******/ } |
| 1100 | /******/ |
| 1101 | /************************************************************************/ |
| 1102 | /******/ /* webpack/runtime/compat get default export */ |
| 1103 | /******/ (() => { |
| 1104 | /******/ // getDefaultExport function for compatibility with non-harmony modules |
| 1105 | /******/ __webpack_require__.n = (module) => { |
| 1106 | /******/ var getter = module && module.__esModule ? |
| 1107 | /******/ () => (module['default']) : |
| 1108 | /******/ () => (module); |
| 1109 | /******/ __webpack_require__.d(getter, { a: getter }); |
| 1110 | /******/ return getter; |
| 1111 | /******/ }; |
| 1112 | /******/ })(); |
| 1113 | /******/ |
| 1114 | /******/ /* webpack/runtime/define property getters */ |
| 1115 | /******/ (() => { |
| 1116 | /******/ // define getter functions for harmony exports |
| 1117 | /******/ __webpack_require__.d = (exports, definition) => { |
| 1118 | /******/ for(var key in definition) { |
| 1119 | /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
| 1120 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
| 1121 | /******/ } |
| 1122 | /******/ } |
| 1123 | /******/ }; |
| 1124 | /******/ })(); |
| 1125 | /******/ |
| 1126 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
| 1127 | /******/ (() => { |
| 1128 | /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
| 1129 | /******/ })(); |
| 1130 | /******/ |
| 1131 | /******/ /* webpack/runtime/make namespace object */ |
| 1132 | /******/ (() => { |
| 1133 | /******/ // define __esModule on exports |
| 1134 | /******/ __webpack_require__.r = (exports) => { |
| 1135 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
| 1136 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| 1137 | /******/ } |
| 1138 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 1139 | /******/ }; |
| 1140 | /******/ })(); |
| 1141 | /******/ |
| 1142 | /************************************************************************/ |
| 1143 | var __webpack_exports__ = {}; |
| 1144 | // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk. |
| 1145 | (() => { |
| 1146 | /*!*****************************************!*\ |
| 1147 | !*** ./assets/src/js/bindings/index.js ***! |
| 1148 | \*****************************************/ |
| 1149 | __webpack_require__.r(__webpack_exports__); |
| 1150 | /* harmony import */ var _sources_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./sources.js */ "./assets/src/js/bindings/sources.js"); |
| 1151 | /* harmony import */ var _block_editor_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./block-editor.js */ "./assets/src/js/bindings/block-editor.js"); |
| 1152 | |
| 1153 | |
| 1154 | })(); |
| 1155 | |
| 1156 | /******/ })() |
| 1157 | ; |
| 1158 | //# sourceMappingURL=scf-bindings.js.map |