Skip to content

Commit 41a727c

Browse files
authored
Backports: Updates 6.6.0, 6.6.1, 6.6.2 (#229)
* Backport all PHP * Backport options-page * update acf min * Update internal post type * Add fields * Update more input min assets * Update input min * All JS except blocks v3 * Migrate css * Upgrade minimum WP version * Blocks v3 first approach * V3 blocks loading correctly * Fix css not showing * fix prettier * Fix more prettier * Migrate 6-6-1 except blocks * Add 6.6.1 blocks changes * Backport 6.6.2 * More fixes * Add unit test * V3 Blocks now save default field values even if the block wasn't interacted with before saving * Add more changes
1 parent 783b4f6 commit 41a727c

File tree

74 files changed

+26949
-23322
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+26949
-23322
lines changed

assets/src/js/_acf-condition-types.js

Lines changed: 59 additions & 59 deletions
Large diffs are not rendered by default.

assets/src/js/_acf-field-button-group.js

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import { update } from '@wordpress/icons';
2+
13
( function ( $, undefined ) {
2-
var Field = acf.Field.extend( {
4+
const Field = acf.Field.extend( {
35
type: 'button_group',
46

57
events: {
68
'click input[type="radio"]': 'onClick',
9+
'keydown label': 'onKeyDown',
710
},
811

912
$control: function () {
@@ -13,29 +16,80 @@
1316
$input: function () {
1417
return this.$( 'input:checked' );
1518
},
19+
initialize: function () {
20+
this.updateButtonStates();
21+
},
1622

1723
setValue: function ( val ) {
1824
this.$( 'input[value="' + val + '"]' )
1925
.prop( 'checked', true )
2026
.trigger( 'change' );
27+
this.updateButtonStates();
2128
},
2229

30+
updateButtonStates: function () {
31+
const labels = this.$control().find( 'label' );
32+
const input = this.$input();
33+
labels
34+
.removeClass( 'selected' )
35+
.attr( 'aria-checked', 'false' )
36+
.attr( 'tabindex', '-1' );
37+
if ( input.length ) {
38+
// If there's a checked input, mark its parent label as selected
39+
input
40+
.parent( 'label' )
41+
.addClass( 'selected' )
42+
.attr( 'aria-checked', 'true' )
43+
.attr( 'tabindex', '0' );
44+
} else {
45+
labels.first().attr( 'tabindex', '0' );
46+
}
47+
},
2348
onClick: function ( e, $el ) {
24-
// vars
25-
var $label = $el.parent( 'label' );
26-
var selected = $label.hasClass( 'selected' );
49+
this.selectButton( $el.parent( 'label' ) );
50+
},
51+
onKeyDown: function ( event, label ) {
52+
const key = event.which;
2753

28-
// remove previous selected
29-
this.$( '.selected' ).removeClass( 'selected' );
54+
// Space or Enter: select the button
55+
if ( key === 13 || key === 32 ) {
56+
event.preventDefault();
57+
this.selectButton( label );
58+
return;
59+
}
60+
61+
// Arrow keys: move focus between buttons
62+
if ( key === 37 || key === 39 || key === 38 || key === 40 ) {
63+
event.preventDefault();
64+
const labels = this.$control().find( 'label' );
65+
const currentIndex = labels.index( label );
66+
let nextIndex;
67+
68+
// Left/Up arrow: move to previous, wrap to last if at start
69+
if ( key === 37 || key === 38 ) {
70+
nextIndex =
71+
currentIndex > 0 ? currentIndex - 1 : labels.length - 1;
72+
}
73+
// Right/Down arrow: move to next, wrap to first if at end
74+
else {
75+
nextIndex =
76+
currentIndex < labels.length - 1 ? currentIndex + 1 : 0;
77+
}
3078

31-
// add active class
32-
$label.addClass( 'selected' );
79+
const nextLabel = labels.eq( nextIndex );
80+
labels.attr( 'tabindex', '-1' );
81+
nextLabel.attr( 'tabindex', '0' ).trigger( 'focus' );
82+
}
83+
},
3384

34-
// allow null
35-
if ( this.get( 'allow_null' ) && selected ) {
36-
$label.removeClass( 'selected' );
37-
$el.prop( 'checked', false ).trigger( 'change' );
85+
selectButton: function ( element ) {
86+
const inputRadio = element.find( 'input[type="radio"]' );
87+
const isSelected = element.hasClass( 'selected' );
88+
inputRadio.prop( 'checked', true ).trigger( 'change' );
89+
if ( this.get( 'allow_null' ) && isSelected ) {
90+
inputRadio.prop( 'checked', false ).trigger( 'change' );
3891
}
92+
this.updateButtonStates();
3993
},
4094
} );
4195

assets/src/js/_acf-field-checkbox.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
'click .acf-add-checkbox': 'onClickAdd',
88
'click .acf-checkbox-toggle': 'onClickToggle',
99
'click .acf-checkbox-custom': 'onClickCustom',
10+
'keydown input[type="checkbox"]': 'onKeyDownInput',
1011
},
1112

1213
$control: function () {
@@ -71,24 +72,21 @@
7172
.parent()
7273
.find( 'input[type="text"]' )
7374
.last()
74-
.focus();
75+
.trigger( 'focus' );
7576
},
7677

7778
onClickToggle: function ( e, $el ) {
7879
// Vars.
79-
var checked = $el.prop( 'checked' );
80-
var $inputs = this.$( 'input[type="checkbox"]' );
81-
var $labels = this.$( 'label' );
82-
83-
// Update "checked" state.
84-
$inputs.prop( 'checked', checked );
85-
86-
// Add or remove "selected" class.
87-
if ( checked ) {
88-
$labels.addClass( 'selected' );
89-
} else {
90-
$labels.removeClass( 'selected' );
91-
}
80+
const inputs = this.$inputs();
81+
const hasUnchecked = $inputs.not( ':checked' ).length > 0;
82+
inputs.each( function () {
83+
$inputs.each( function () {
84+
jQuery( this )
85+
.prop( 'checked', hasUnchecked )
86+
.trigger( 'change' );
87+
} );
88+
} );
89+
$el.prop( 'checked', hasUnchecked );
9290
},
9391

9492
onClickCustom: function ( e, $el ) {
@@ -109,6 +107,23 @@
109107
}
110108
}
111109
},
110+
onKeyDownInput: function ( e, $el ) {
111+
// Check if Enter key (keyCode 13) was pressed
112+
if ( e.which === 13 ) {
113+
// Prevent default form submission
114+
e.preventDefault();
115+
116+
// Toggle the checkbox state and trigger change event
117+
$el.prop( 'checked', ! $el.prop( 'checked' ) ).trigger(
118+
'change'
119+
);
120+
121+
// If this is the "Select All" toggle checkbox, run the toggle logic
122+
if ( $el.is( '.acf-checkbox-toggle' ) ) {
123+
this.onClickToggle( e, $el );
124+
}
125+
}
126+
},
112127
} );
113128

114129
acf.registerFieldType( Field );

assets/src/js/_acf-field-color-picker.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,26 @@
4949
change: onChange,
5050
clear: onChange,
5151
};
52+
if ( 'custom' === $inputText.data( 'acf-palette-type' ) ) {
53+
const paletteColor = $inputText
54+
.data( 'acf-palette-colors' )
55+
.match(
56+
/#(?:[0-9a-fA-F]{3}){1,2}|rgba?\([\s*(\d|.)+\s*,]+\)/g
57+
);
58+
if ( paletteColor ) {
59+
let trimmed = paletteColor.map( ( color ) => color.trim() );
60+
args.palettes = trimmed;
61+
}
62+
}
5263

5364
// filter
5465
var args = acf.applyFilters( 'color_picker_args', args, this );
55-
66+
if ( Array.isArray( args.palettes ) && args.palettes.length > 10 ) {
67+
// Add class for large custom palette styling
68+
this.$control().addClass(
69+
'acf-color-picker-large-custom-palette'
70+
);
71+
}
5672
// initialize
5773
$inputText.wpColorPicker( args );
5874
},

assets/src/js/_acf-field-file.js

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
( function ( $, undefined ) {
2-
var Field = acf.models.ImageField.extend( {
2+
const Field = acf.models.ImageField.extend( {
33
type: 'file',
44

55
$control: function () {
@@ -9,7 +9,13 @@
99
$input: function () {
1010
return this.$( 'input[type="hidden"]:first' );
1111
},
12-
12+
events: {
13+
'click a[data-name="add"]': 'onClickAdd',
14+
'click a[data-name="edit"]': 'onClickEdit',
15+
'click a[data-name="remove"]': 'onClickRemove',
16+
'change input[type="file"]': 'onChange',
17+
'keydown .file-wrap': 'onImageWrapKeydown',
18+
},
1319
validateAttachment: function ( attachment ) {
1420
// defaults
1521
attachment = attachment || {};
@@ -54,26 +60,29 @@
5460
);
5561

5662
// vars
57-
var val = attachment.id || '';
63+
const val = attachment.id || '';
5864

5965
// update val
6066
acf.val( this.$input(), val );
61-
62-
// update class
6367
if ( val ) {
68+
// update class
6469
this.$control().addClass( 'has-value' );
70+
const fileWrap = this.$( '.file-wrap' );
71+
if ( fileWrap.length ) {
72+
fileWrap.trigger( 'focus' );
73+
}
6574
} else {
6675
this.$control().removeClass( 'has-value' );
6776
}
6877
},
6978

7079
selectAttachment: function () {
7180
// vars
72-
var parent = this.parent();
73-
var multiple = parent && parent.get( 'type' ) === 'repeater';
81+
const parent = this.parent();
82+
const multiple = parent && parent.get( 'type' ) === 'repeater';
7483

7584
// new frame
76-
var frame = acf.newMediaPopup( {
85+
const frame = acf.newMediaPopup( {
7786
mode: 'select',
7887
title: acf.__( 'Select File' ),
7988
field: this.get( 'key' ),
@@ -90,9 +99,9 @@
9099
} );
91100
},
92101

93-
editAttachment: function () {
102+
editAttachment: function ( button ) {
94103
// vars
95-
var val = this.val();
104+
const val = this.val();
96105

97106
// bail early if no val
98107
if ( ! val ) {
@@ -106,9 +115,22 @@
106115
button: acf.__( 'Update File' ),
107116
attachment: val,
108117
field: this.get( 'key' ),
109-
select: $.proxy( function ( attachment, i ) {
118+
select: $.proxy( function ( attachment ) {
110119
this.render( attachment );
111120
}, this ),
121+
close: $.proxy( function () {
122+
if ( 'edit-button' === button ) {
123+
const edit = this.$el.find( 'a[data-name="edit"]' );
124+
if ( edit.length ) {
125+
edit.trigger( 'focus' );
126+
}
127+
} else {
128+
const imageWrap = this.$el.find( '.image-wrap' );
129+
if ( imageWrap.length ) {
130+
imageWrap.trigger( 'focus' );
131+
}
132+
}
133+
}, this ),
112134
} );
113135
},
114136
} );

0 commit comments

Comments
 (0)