Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 287fbe1

Browse files
authoredJun 6, 2024··
v1.1.8 (#59)
2 parents d4cfc15 + ac707a6 commit 287fbe1

21 files changed

+4133
-4030
lines changed
 

‎assets/css/field.scss ‎assets/field.css

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
}
2626

2727
svg {
28-
position: absolute;
29-
top: 2px;
30-
left: 2px;
28+
@apply absolute top-[2px] left-[2px];
3129
}
3230
}
3331
}

‎assets/js/field.js ‎assets/field.js

File renamed without changes.

‎bud.config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Bud } from '@roots/bud'
2+
3+
export default async (bud: Bud) => {
4+
bud
5+
.setPath('@src', 'assets')
6+
.setPath('@dist', 'public')
7+
.entry(['field.js', 'field.css'])
8+
.hash()
9+
}

‎composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"php": ">=7.2"
1515
},
1616
"require-dev": {
17-
"squizlabs/php_codesniffer": "^3.5"
17+
"squizlabs/php_codesniffer": "^3.10"
1818
},
1919
"autoload": {
2020
"psr-4": {

‎composer.lock

+41-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+7-11
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@
22
"name": "acf-editor-palette",
33
"private": true,
44
"scripts": {
5-
"build": "npx mix",
6-
"build:production": "npx mix --production",
7-
"start": "npx mix watch"
8-
},
9-
"devDependencies": {
10-
"autoprefixer": "^10.3.3",
11-
"laravel-mix": "^6.0.28",
12-
"postcss": "^8.3.6",
13-
"sass": "^1.38.2",
14-
"sass-loader": "^12.1.0",
15-
"tailwindcss": "^2.2.9"
5+
"build": "bud build"
166
},
177
"dependencies": {
188
"tinycolor2": "^1.4.2"
9+
},
10+
"devDependencies": {
11+
"@roots/bud": "^6.21.0",
12+
"@roots/bud-postcss": "^6.21.0",
13+
"@roots/bud-tailwindcss": "^6.21.0",
14+
"tailwindcss": "^3.4.4"
1915
}
2016
}

‎plugin.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin Name: Advanced Custom Fields: Editor Palette Field
55
* Plugin URI: https://github.com/log1x/acf-editor-palette
66
* Description: A Gutenberg-like editor palette color picker field for Advanced Custom Fields.
7-
* Version: 1.1.7
7+
* Version: 1.1.8
88
* Author: Brandon Nifong
99
* Author URI: https://github.com/log1x
1010
*/
@@ -13,7 +13,7 @@
1313

1414
add_filter('after_setup_theme', new class
1515
{
16-
/**
16+
/**
1717
* The field label.
1818
*
1919
* @var string

‎public/css/field.css

-1
This file was deleted.

‎public/css/field.d1c65e.css

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎public/entrypoints.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"field": {
3+
"js": [
4+
"js/runtime.b89547.js",
5+
"js/field.563bb8.js"
6+
],
7+
"css": [
8+
"css/field.d1c65e.css"
9+
]
10+
}
11+
}

‎public/js/field.563bb8.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎public/js/field.js

-1
This file was deleted.

‎public/js/runtime.b89547.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎public/manifest.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"field.css": "css/field.d1c65e.css",
3+
"field.js": "js/field.563bb8.js",
4+
"runtime.js": "js/runtime.b89547.js",
5+
"entrypoints.json": "entrypoints.json"
6+
}

‎public/mix-manifest.json

-4
This file was deleted.

‎src/Concerns/Asset.php

+43-9
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,53 @@
55
trait Asset
66
{
77
/**
8-
* Resolve an asset URI from Laravel Mix's manifest.
9-
*
10-
* @param string $asset
11-
* @return string
8+
* The manifest.
129
*/
13-
public function asset($asset = null)
10+
public array $manifest = [];
11+
12+
/**
13+
* Retrieve the URI of an asset.
14+
*/
15+
public function asset(?string $asset = null): string
16+
{
17+
$asset = $this->manifest($asset);
18+
19+
return $this->uri . $asset;
20+
}
21+
22+
/**
23+
* Retrieve the content of an asset.
24+
*/
25+
public function inlineAsset(string $asset): ?string
1426
{
15-
if (! file_exists($manifest = $this->path . 'mix-manifest.json')) {
16-
return $this->uri . $asset;
27+
$path = $this->path . $this->manifest($asset);
28+
29+
if (! file_exists($path)) {
30+
return null;
31+
}
32+
33+
return file_get_contents($path);
34+
}
35+
36+
/**
37+
* Retrieve the manifest.
38+
*/
39+
public function manifest(?string $asset = null): array|string
40+
{
41+
if ($this->manifest) {
42+
return $asset
43+
? $this->manifest[$asset]
44+
: $this->manifest;
45+
}
46+
47+
if (! file_exists($manifest = $this->path . 'manifest.json')) {
48+
return [];
1749
}
1850

19-
$manifest = json_decode(file_get_contents($manifest), true);
51+
$this->manifest = json_decode(file_get_contents($manifest), true);
2052

21-
return $this->uri . ($manifest[$asset] ?? $asset);
53+
return $asset
54+
? $this->manifest[$asset]
55+
: $this->manifest;
2256
}
2357
}

‎src/Concerns/Palette.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trait Palette
77
/**
88
* Retrieve the editor color palette.
99
*
10-
* @param string $color
10+
* @param string $color
1111
* @return string[]
1212
*/
1313
public function palette($color = null)
@@ -40,11 +40,11 @@ public function palette($color = null)
4040
$value['slug'] => array_merge($value, [
4141
'text' => sprintf('has-text-color has-%s-color', $value['slug']),
4242
'background' => sprintf('has-background has-%s-background-color', $value['slug']),
43-
])
43+
]),
4444
]);
4545
}
4646

47-
return ! empty($color) ? (
47+
return ! empty($color) && is_string($color) ? (
4848
$colors[$color] ?? null
4949
) : $colors;
5050
}

‎src/Field.php

+17-18
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ class Field extends \acf_field
2121

2222
/**
2323
* Create a new Field instance.
24-
*
25-
* @param callable $plugin
26-
* @return void
2724
*/
2825
public function __construct(callable $plugin)
2926
{
@@ -39,13 +36,14 @@ public function __construct(callable $plugin)
3936
/**
4037
* The rendered field type.
4138
*
42-
* @param array $field
39+
* @param array $field
4340
* @return void
4441
*/
4542
public function render_field($field)
4643
{
4744
if (empty($palette = $this->palette())) {
4845
echo __('The theme editor palette is empty.', 'acf-editor-palette');
46+
4947
return;
5048
}
5149

@@ -55,7 +53,6 @@ public function render_field($field)
5553
});
5654
}
5755

58-
5956
if (! empty($allowed = $field['allowed_colors']) && is_array($allowed)) {
6057
$palette = array_filter($palette, function ($color) use ($allowed) {
6158
return in_array($color['slug'], $allowed);
@@ -64,6 +61,7 @@ public function render_field($field)
6461

6562
if (empty($palette)) {
6663
echo __('There are no colors available.', 'acf-editor-palette');
64+
6765
return;
6866
}
6967

@@ -124,7 +122,7 @@ class="components-button components-circular-option-picker__option acf-js-toolti
124122
echo '</ul>';
125123

126124
echo '<div class="components-circular-option-picker__custom-clear-wrapper">' .
127-
'<button type="button" class="components-button components-circular-option-picker__clear is-secondary is-small">' . // phpcs:ignore
125+
'<button type="button" class="components-button components-circular-option-picker__clear is-secondary is-small">'. // phpcs:ignore
128126
__('Clear', 'acf-editor-palette') .
129127
'</button>' .
130128
'</div>';
@@ -135,7 +133,7 @@ class="components-button components-circular-option-picker__option acf-js-toolti
135133
/**
136134
* The rendered field type settings.
137135
*
138-
* @param array $field
136+
* @param array $field
139137
* @return void
140138
*/
141139
public function render_field_settings($field)
@@ -214,9 +212,9 @@ public function render_field_settings($field)
214212
/**
215213
* The formatted field value.
216214
*
217-
* @param mixed $value
218-
* @param int $post_id
219-
* @param array $field
215+
* @param mixed $value
216+
* @param int $post_id
217+
* @param array $field
220218
* @return mixed
221219
*/
222220
public function format_value($value, $post_id, $field)
@@ -235,9 +233,9 @@ public function format_value($value, $post_id, $field)
235233
* it is valid and can be saved.
236234
*
237235
* @param bool $valid
238-
* @param mixed $value
239-
* @param array $field
240-
* @param array $input
236+
* @param mixed $value
237+
* @param array $field
238+
* @param array $input
241239
* @return bool
242240
*/
243241
public function validate_value($valid, $value, $field, $input)
@@ -256,9 +254,9 @@ public function validate_value($valid, $value, $field, $input)
256254
/**
257255
* The field value before saving to the database.
258256
*
259-
* @param mixed $value
260-
* @param int $post_id
261-
* @param array $field
257+
* @param mixed $value
258+
* @param int $post_id
259+
* @param array $field
262260
* @return mixed
263261
*/
264262
public function update_value($value, $post_id, $field)
@@ -279,8 +277,9 @@ public function update_value($value, $post_id, $field)
279277
*/
280278
public function input_admin_enqueue_scripts()
281279
{
282-
wp_enqueue_style($this->name, $this->asset('css/field.css'), ['wp-components'], null);
283-
wp_enqueue_script($this->name, $this->asset('js/field.js'), [], null, true);
280+
wp_enqueue_style($this->name, $this->asset('field.css'), ['wp-components'], null);
281+
wp_enqueue_script($this->name, $this->asset('field.js'), [], null, true);
282+
wp_add_inline_script($this->name, $this->inlineAsset('runtime.js'));
284283
}
285284

286285
/**

‎tailwind.config.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
module.exports = {
2-
purge: false,
3-
darkMode: false, // or 'media' or 'class'
4-
theme: {
5-
extend: {},
6-
},
7-
variants: {
8-
extend: {},
9-
},
10-
plugins: [],
2+
content: ['./src/**/*.php', './assets/field.js'],
113
}

‎webpack.mix.js

-23
This file was deleted.

‎yarn.lock

+3,988-3,928
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.