Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upkeep/scripts: Reorganize JS #804

Merged
merged 29 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
51deca8
Merge branch 'develop' of github.com:10up/classifai into develop
Sidsector9 Jun 28, 2024
a4f125c
Merge branch 'develop' of github.com:10up/classifai into develop
Sidsector9 Jul 30, 2024
066630e
Merge branch 'develop' of github.com:10up/classifai into develop
Sidsector9 Aug 20, 2024
018dff0
Merge branch 'develop' of github.com:10up/classifai into develop
Sidsector9 Sep 5, 2024
bba2004
Merge branch 'develop' of github.com:10up/classifai into develop
Sidsector9 Sep 19, 2024
bdcc3bf
move text to speech out as a separate plugin
Sidsector9 Sep 19, 2024
ca7566f
move classification out as a separate plugin
Sidsector9 Sep 19, 2024
a385f73
move content resizing out as a separate plugin
Sidsector9 Sep 19, 2024
731fd1f
move title generation out as a separate plugin
Sidsector9 Sep 19, 2024
02a55ef
fix gutenberg plugin names
Sidsector9 Sep 19, 2024
40f464e
move exerpt generation out as a separate plugin
Sidsector9 Sep 19, 2024
76967bd
move title and exerpt generation (classic) out as a separate plugin
Sidsector9 Sep 19, 2024
dce784f
move image generation out as a separate plugin
Sidsector9 Sep 19, 2024
803ff9e
move text to speech (frontend) out as a separate plugin
Sidsector9 Sep 20, 2024
6669139
move .scss files to feature directories
Sidsector9 Sep 20, 2024
c922609
fix title & excerpt generation implementation
Sidsector9 Sep 20, 2024
1252d14
move commands out to plugins
Sidsector9 Sep 20, 2024
07b442f
move previewer out to plugins
Sidsector9 Sep 20, 2024
4e90772
rename directory from plugins to features
Sidsector9 Sep 20, 2024
6c723ba
fix linting errors
Sidsector9 Sep 20, 2024
f0d7329
improve linting script
Sidsector9 Sep 20, 2024
11891b3
fix e2e tests
Sidsector9 Sep 20, 2024
0f2bf9e
move extend media block script out to features
Sidsector9 Sep 21, 2024
322a97e
move ocr and media-upload related features to features director
Sidsector9 Sep 21, 2024
03a34e5
fix webpack.config.js
Sidsector9 Sep 21, 2024
76a372e
ignore webpack config in eslintrc
Sidsector9 Sep 21, 2024
00376be
fix styling issues
Sidsector9 Sep 26, 2024
b4bfea6
add missing ClassifAI icon
Sidsector9 Sep 26, 2024
4a50fe0
eslint fixes
Sidsector9 Sep 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{

Check warning on line 1 in .eslintrc.json

View workflow job for this annotation

GitHub Actions / eslint

File ignored by default.
"globals": {
"wp": "readonly",
"jQuery": "readonly",
Expand All @@ -24,5 +24,5 @@
"Block": "readonly"
},
"extends": ["plugin:@wordpress/eslint-plugin/recommended"],
"ignorePatterns": ["*.json"]
"ignorePatterns": ["*.json", "webpack.config.js"]
}
2 changes: 1 addition & 1 deletion assets/img/block-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions includes/Classifai/Features/AudioTranscriptsGeneration.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ public function rest_endpoint_callback( WP_REST_Request $request ) {
*/
public function enqueue_admin_assets() {
wp_enqueue_script(
'classifai-media-script',
CLASSIFAI_PLUGIN_URL . 'dist/media.js',
array_merge( get_asset_info( 'media', 'dependencies' ), array( 'jquery', 'media-editor', 'lodash' ) ),
get_asset_info( 'media', 'version' ),
'classifai-plugin-media-processing-js',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-media-processing.js',
array_merge( get_asset_info( 'classifai-plugin-media-processing', 'dependencies' ), array( 'jquery', 'media-editor', 'lodash' ) ),
get_asset_info( 'classifai-plugin-media-processing', 'version' ),
true
);
}
Expand Down
32 changes: 16 additions & 16 deletions includes/Classifai/Features/Classification.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,18 +303,18 @@ public function rest_after_insert( \WP_Post $post ) {
*/
public function enqueue_admin_assets() {
wp_enqueue_script(
'classifai-language-processing-script',
CLASSIFAI_PLUGIN_URL . 'dist/language-processing.js',
get_asset_info( 'language-processing', 'dependencies' ),
get_asset_info( 'language-processing', 'version' ),
'classifai-plugin-classification-previewer-js',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-classification-previewer.js',
get_asset_info( 'classifai-plugin-classification-previewer', 'dependencies' ),
get_asset_info( 'classifai-plugin-classification-previewer', 'version' ),
true
);

wp_enqueue_style(
'classifai-language-processing-style',
CLASSIFAI_PLUGIN_URL . 'dist/language-processing.css',
'classifai-plugin-classification-previewer-css',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-classification-previewer.css',
array(),
get_asset_info( 'language-processing', 'version' ),
get_asset_info( 'classifai-plugin-classification-previewer', 'version' ),
'all'
);
}
Expand All @@ -326,10 +326,10 @@ public function enqueue_editor_assets() {
global $post;

wp_enqueue_script(
'classifai-editor',
CLASSIFAI_PLUGIN_URL . 'dist/editor.js',
get_asset_info( 'editor', 'dependencies' ),
get_asset_info( 'editor', 'version' ),
'classifai-plugin-classification-ibm-watson-js',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-classification-ibm-watson.js',
get_asset_info( 'classifai-plugin-classification-ibm-watson', 'dependencies' ),
get_asset_info( 'classifai-plugin-classification-ibm-watson', 'version' ),
true
);

Expand All @@ -338,15 +338,15 @@ public function enqueue_editor_assets() {
}

wp_enqueue_script(
'classifai-gutenberg-plugin',
CLASSIFAI_PLUGIN_URL . 'dist/gutenberg-plugin.js',
array_merge( get_asset_info( 'gutenberg-plugin', 'dependencies' ), array( 'lodash' ) ),
get_asset_info( 'gutenberg-plugin', 'version' ),
'classifai-plugin-classification-js',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-classification.js',
array_merge( get_asset_info( 'classifai-plugin-classification', 'dependencies' ), array( 'lodash' ), array( Feature::PLUGIN_AREA_SCRIPT ) ),
get_asset_info( 'classifai-plugin-classification', 'version' ),
true
);

wp_add_inline_script(
'classifai-gutenberg-plugin',
'classifai-plugin-classification-js',
sprintf(
'var classifaiPostData = %s;',
wp_json_encode(
Expand Down
32 changes: 7 additions & 25 deletions includes/Classifai/Features/ContentResizing.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ static function () {
*/
public function feature_setup() {
add_action( 'enqueue_block_assets', [ $this, 'enqueue_editor_assets' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] );
}

/**
Expand Down Expand Up @@ -189,39 +188,22 @@ public function enqueue_editor_assets() {
}

wp_enqueue_script(
'classifai-content-resizing-plugin-js',
CLASSIFAI_PLUGIN_URL . 'dist/content-resizing-plugin.js',
get_asset_info( 'content-resizing-plugin', 'dependencies' ),
get_asset_info( 'content-resizing-plugin', 'version' ),
'classifai-plugin-content-resizing-js',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-content-resizing.js',
get_asset_info( 'classifai-plugin-content-resizing', 'dependencies' ),
get_asset_info( 'classifai-plugin-content-resizing', 'version' ),
true
);

wp_enqueue_style(
'classifai-content-resizing-plugin-css',
CLASSIFAI_PLUGIN_URL . 'dist/content-resizing-plugin.css',
'classifai-plugin-content-resizing-css',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-content-resizing.css',
[],
get_asset_info( 'content-resizing-plugin', 'version' ),
get_asset_info( 'classifai-plugin-content-resizing', 'version' ),
'all'
);
}

/**
* Enqueue the admin scripts.
*
* @param string $hook_suffix The current admin page.
*/
public function enqueue_admin_assets( string $hook_suffix ) {
// Load asset in new post and edit post screens.
if ( 'post.php' === $hook_suffix || 'post-new.php' === $hook_suffix ) {
wp_enqueue_style(
'classifai-language-processing-style',
CLASSIFAI_PLUGIN_URL . 'dist/language-processing.css',
[],
get_asset_info( 'language-processing', 'version' ),
);
}
}

/**
* Get the description for the enable field.
*
Expand Down
31 changes: 12 additions & 19 deletions includes/Classifai/Features/ExcerptGeneration.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ public function enqueue_editor_assets() {

// This script removes the core excerpt panel and replaces it with our own.
wp_enqueue_script(
'classifai-post-excerpt',
CLASSIFAI_PLUGIN_URL . 'dist/post-excerpt.js',
array_merge( get_asset_info( 'post-excerpt', 'dependencies' ), [ 'lodash' ] ),
get_asset_info( 'post-excerpt', 'version' ),
'classifai-plugin-excerpt-generation-js',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-excerpt-generation.js',
array_merge( get_asset_info( 'classifai-plugin-excerpt-generation', 'dependencies' ), [ 'lodash' ] ),
get_asset_info( 'classifai-plugin-excerpt-generation', 'version' ),
true
);
}
Expand All @@ -220,23 +220,23 @@ public function enqueue_admin_assets( string $hook_suffix ) {
if ( $screen && ! $screen->is_block_editor() ) {
if ( post_type_supports( $screen->post_type, 'excerpt' ) ) {
wp_enqueue_style(
'classifai-generate-title-classic-css',
CLASSIFAI_PLUGIN_URL . 'dist/generate-title-classic.css',
'classifai-plugin-classic-excerpt-generation-css',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-classic-excerpt-generation.css',
[],
get_asset_info( 'generate-title-classic', 'version' ),
get_asset_info( 'classifai-plugin-classic-excerpt-generation', 'version' ),
'all'
);

wp_enqueue_script(
'classifai-generate-excerpt-classic-js',
CLASSIFAI_PLUGIN_URL . 'dist/generate-excerpt-classic.js',
array_merge( get_asset_info( 'generate-excerpt-classic', 'dependencies' ), array( 'wp-api' ) ),
get_asset_info( 'generate-excerpt-classic', 'version' ),
'classifai-plugin-classic-excerpt-generation-js',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-classic-excerpt-generation.js',
array_merge( get_asset_info( 'classifai-plugin-classic-excerpt-generation', 'dependencies' ), array( 'wp-api' ) ),
get_asset_info( 'classifai-plugin-classic-excerpt-generation', 'version' ),
true
);

wp_add_inline_script(
'classifai-generate-excerpt-classic-js',
'classifai-plugin-classic-excerpt-generation-js',
sprintf(
'var classifaiGenerateExcerpt = %s;',
wp_json_encode(
Expand All @@ -251,13 +251,6 @@ public function enqueue_admin_assets( string $hook_suffix ) {
);
}
}

wp_enqueue_style(
'classifai-language-processing-style',
CLASSIFAI_PLUGIN_URL . 'dist/language-processing.css',
[],
get_asset_info( 'language-processing', 'version' ),
);
Comment on lines -254 to -260
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the language processing CSS file contains some CSS of the excerpt generation model. Removing this minor break spacing above the button.

image

}
}

Expand Down
25 changes: 25 additions & 0 deletions includes/Classifai/Features/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use WP_REST_Request;
use WP_Error;
use function Classifai\find_provider_class;
use function Classifai\get_asset_info;

abstract class Feature {
/**
Expand All @@ -16,6 +17,16 @@ abstract class Feature {
*/
const ID = '';

/**
* Plugin area script handle.
*
* Every feature that injects content into the plugin area
* should add this script as a dependency.
*
* @var string
*/
const PLUGIN_AREA_SCRIPT = 'classifai-plugin-fill-js';

/**
* Feature label.
*
Expand Down Expand Up @@ -53,6 +64,7 @@ public function setup() {
add_action( 'admin_init', [ $this, 'setup_roles' ] );
add_action( 'admin_init', [ $this, 'register_setting' ] );
add_action( 'admin_init', [ $this, 'setup_fields_sections' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'register_plugin_area_script' ] );

if ( $this->is_feature_enabled() ) {
$this->feature_setup();
Expand Down Expand Up @@ -114,6 +126,19 @@ public function get_label(): string {
);
}

/**
* Registers the plugin area script.
*/
public function register_plugin_area_script() {
wp_register_script(
self::PLUGIN_AREA_SCRIPT,
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-fill.js',
get_asset_info( 'classifai-plugin-fill', 'dependencies' ),
get_asset_info( 'classifai-plugin-fill', 'version' ),
true
);
}

/**
* Set up the fields for each section.
*
Expand Down
42 changes: 17 additions & 25 deletions includes/Classifai/Features/ImageGeneration.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,34 +186,26 @@ public function enqueue_admin_scripts( string $hook_suffix = '' ) {
wp_enqueue_media();

wp_enqueue_style(
'classifai-image-processing-style',
CLASSIFAI_PLUGIN_URL . 'dist/media-modal.css',
'classifai-plugin-image-generation-media-modal-css',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-image-generation-media-modal.css',
[],
get_asset_info( 'media-modal', 'version' ),
get_asset_info( 'classifai-plugin-image-generation-media-modal', 'version' ),
'all'
);

wp_enqueue_script(
'classifai-generate-images',
CLASSIFAI_PLUGIN_URL . 'dist/media-modal.js',
array_merge( get_asset_info( 'media-modal', 'dependencies' ), array( 'jquery', 'wp-api' ) ),
get_asset_info( 'media-modal', 'version' ),
'classifai-plugin-image-generation-media-modal-js',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-image-generation-media-modal.js',
array_merge( get_asset_info( 'classifai-plugin-image-generation-media-modal', 'dependencies' ), array( 'jquery', 'wp-api' ) ),
get_asset_info( 'classifai-plugin-image-generation-media-modal', 'version' ),
true
);

wp_enqueue_script(
'classifai-inserter-media-category',
CLASSIFAI_PLUGIN_URL . 'dist/inserter-media-category.js',
get_asset_info( 'inserter-media-category', 'dependencies' ),
get_asset_info( 'inserter-media-category', 'version' ),
true
);

wp_enqueue_script(
'classifai-extend-image-blocks',
CLASSIFAI_PLUGIN_URL . 'dist/extend-image-blocks.js',
get_asset_info( 'extend-image-blocks', 'dependencies' ),
get_asset_info( 'extend-image-blocks', 'version' ),
'classifai-plugin-inserter-media-category-js',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-inserter-media-category.js',
get_asset_info( 'classifai-plugin-inserter-media-category', 'dependencies' ),
get_asset_info( 'classifai-plugin-inserter-media-category', 'version' ),
true
);

Expand All @@ -237,7 +229,7 @@ public function enqueue_admin_scripts( string $hook_suffix = '' ) {
);

wp_localize_script(
'classifai-generate-images',
'classifai-plugin-image-generation-media-modal-js',
'classifaiDalleData',
[
'endpoint' => 'classifai/v1/generate-image',
Expand All @@ -253,15 +245,15 @@ public function enqueue_admin_scripts( string $hook_suffix = '' ) {

if ( 'classifai-generate-image' === $action ) {
wp_enqueue_script(
'classifai-generate-images-media-upload',
CLASSIFAI_PLUGIN_URL . 'dist/generate-image-media-upload.js',
array_merge( get_asset_info( 'generate-image-media-upload', 'dependencies' ), array( 'jquery' ) ),
get_asset_info( 'classifai-generate-images-media-upload', 'version' ),
'classifai-plugin-image-generation-generate-image-media-upload-js',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-image-generation-generate-image-media-upload.js',
array_merge( get_asset_info( 'classifai-plugin-image-generation-generate-image-media-upload', 'dependencies' ), array( 'jquery' ) ),
get_asset_info( 'classifai-plugin-image-generation-generate-image-media-upload', 'version' ),
true
);

wp_localize_script(
'classifai-generate-images-media-upload',
'classifai-plugin-image-generation-generate-image-media-upload-js',
'classifaiGenerateImages',
[
'upload_url' => esc_url( admin_url( 'upload.php' ) ),
Expand Down
8 changes: 4 additions & 4 deletions includes/Classifai/Features/ImageTextExtraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ public function add_ocr_data_to_api_response() {
*/
public function enqueue_editor_assets() {
wp_enqueue_script(
'editor-ocr',
CLASSIFAI_PLUGIN_URL . 'dist/editor-ocr.js',
array_merge( get_asset_info( 'editor-ocr', 'dependencies' ), array( 'lodash' ) ),
get_asset_info( 'editor-ocr', 'version' ),
'classifai-plugin-editor-ocr-js',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-editor-ocr.js',
array_merge( get_asset_info( 'classifai-plugin-editor-ocr', 'dependencies' ), array( 'lodash' ) ),
get_asset_info( 'classifai-plugin-editor-ocr', 'version' ),
true
);
}
Expand Down
Loading
Loading