Add massive collection of CSS, JavaScript and theme assets that were previously excluded: **CSS Files (681 total):** - HVAC plugin-specific styles (hvac-*.css): 34 files including dashboard, certificates, registration, mobile nav, accessibility fixes, animations, and welcome popup - Theme framework files (Astra, builder systems, layouts): 200+ files - Plugin compatibility styles (WooCommerce, WPForms, Elementor, Contact Form 7): 150+ files - WordPress core and editor styles: 50+ files - Responsive and RTL language support: 200+ files **JavaScript Files (400+ total):** - HVAC plugin functionality (hvac-*.js): 27 files including menu systems, dashboard enhancements, profile sharing, mobile responsive features, accessibility, and animations - Framework and library files: jQuery plugins, GSAP, AOS, Swiper, Chart.js, Lottie, Isotope - Plugin compatibility scripts: WPForms, WooCommerce, Elementor, Contact Form 7, LifterLMS - WordPress core functionality: customizer, admin, block editor compatibility - Third-party integrations: Stripe, SMTP, analytics, search functionality **Assets:** - Certificate background images and logos - Comprehensive theme styling infrastructure - Mobile-responsive design systems - Cross-browser compatibility assets - Performance-optimized minified versions **Updated .gitignore:** - Fixed asset directory whitelisting patterns to properly include CSS/JS/images - Added proper directory structure recognition (!/assets/css/, !/assets/js/, etc.) - Maintains security by excluding sensitive files while including essential assets This commit provides the complete frontend infrastructure needed for: - Full theme functionality and styling - Plugin feature implementations - Mobile responsiveness and accessibility - Cross-browser compatibility - Performance optimization - Developer workflow support
170 lines
3.3 KiB
JavaScript
170 lines
3.3 KiB
JavaScript
/* global wpforms_ai_chat_element */
|
|
|
|
/**
|
|
* @param wpforms_ai_chat_element.ajaxurl
|
|
* @param wpforms_ai_chat_element.errors.network
|
|
* @param wpforms_ai_chat_element.errors.default
|
|
*/
|
|
|
|
/**
|
|
* The WPForms AI API wrapper.
|
|
*
|
|
* @since 1.9.1
|
|
*
|
|
* @return {Function} The app cloning function.
|
|
*/
|
|
export default function() { // eslint-disable-line no-unused-vars, max-lines-per-function
|
|
/**
|
|
* Public functions and properties.
|
|
*
|
|
* @since 1.9.1
|
|
*
|
|
* @type {Object}
|
|
*/
|
|
const app = {
|
|
/**
|
|
* AI chat mode.
|
|
*
|
|
* @since 1.9.1
|
|
*
|
|
* @type {string}
|
|
*/
|
|
mode: '',
|
|
|
|
/**
|
|
* AI AJAX actions.
|
|
*
|
|
* @since 1.9.1
|
|
*
|
|
* @type {Object}
|
|
*/
|
|
actions: {
|
|
rate: 'wpforms_rate_ai_response',
|
|
choices: 'wpforms_get_ai_choices',
|
|
forms: 'wpforms_get_ai_form',
|
|
},
|
|
|
|
/**
|
|
* AJAX request.
|
|
*
|
|
* @param {Object} data Data to send.
|
|
*
|
|
* @return {Promise} The fetch result data promise.
|
|
*/
|
|
// eslint-disable-next-line complexity
|
|
async ajax( data ) {
|
|
if ( ! data.nonce ) {
|
|
data.nonce = wpforms_ai_chat_element.nonce;
|
|
}
|
|
|
|
const options = {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
body: new URLSearchParams( data ).toString(),
|
|
};
|
|
|
|
const response = await fetch( wpforms_ai_chat_element.ajaxurl, options )
|
|
.catch( ( error ) => {
|
|
if ( error.message === 'Failed to fetch' ) {
|
|
throw new Error( wpforms_ai_chat_element.errors.network );
|
|
} else {
|
|
throw new Error( error.message );
|
|
}
|
|
} );
|
|
|
|
if ( ! response.ok ) {
|
|
throw new Error( wpforms_ai_chat_element.errors.network );
|
|
}
|
|
|
|
const result = await response.json();
|
|
|
|
if ( ! result.success || result.data?.error ) {
|
|
throw new Error(
|
|
result.data?.error ?? wpforms_ai_chat_element.errors.default,
|
|
{
|
|
cause: result.data?.code ?? 400,
|
|
} );
|
|
}
|
|
|
|
return result.data;
|
|
},
|
|
|
|
/**
|
|
* Prompt.
|
|
*
|
|
* @param {string} prompt The question to ask.
|
|
* @param {string} sessionId Session ID.
|
|
*
|
|
* @return {Promise} The response data in promise.
|
|
*/
|
|
async prompt( prompt, sessionId ) {
|
|
const data = {
|
|
action: app.actions[ this.mode ] ?? app.actions.choices,
|
|
prompt,
|
|
};
|
|
|
|
if ( sessionId ) {
|
|
data.session_id = sessionId; // eslint-disable-line camelcase
|
|
}
|
|
|
|
return app.ajax( data );
|
|
},
|
|
|
|
/**
|
|
* Rate.
|
|
*
|
|
* @param {boolean} helpful Whether the response was helpful or not.
|
|
* @param {string} responseId Response ID.
|
|
*
|
|
* @return {Promise} The response data in promise.
|
|
*/
|
|
async rate( helpful, responseId ) {
|
|
const data = {
|
|
action: app.actions.rate,
|
|
helpful,
|
|
response_id: responseId, // eslint-disable-line camelcase
|
|
};
|
|
|
|
return app.ajax( data );
|
|
},
|
|
|
|
setUp() {
|
|
app.actions = {
|
|
...app.actions,
|
|
...wpforms_ai_chat_element.actions,
|
|
};
|
|
|
|
return this;
|
|
},
|
|
|
|
/**
|
|
* Set the AI chat mode.
|
|
*
|
|
* @since 1.9.1
|
|
*
|
|
* @param {string} mode The mode to set.
|
|
*
|
|
* @return {Object} The app object.
|
|
*/
|
|
setMode( mode ) {
|
|
this.mode = mode;
|
|
|
|
return this;
|
|
},
|
|
};
|
|
|
|
/**
|
|
* Return a clone of an app object.
|
|
*
|
|
* @since 1.9.1
|
|
*
|
|
* @param {string} mode The AI prompt mode.
|
|
*
|
|
* @return {Object} Cloned app object.
|
|
*/
|
|
return function( mode ) {
|
|
const obj = { ...app };
|
|
|
|
return obj.setUp().setMode( mode );
|
|
};
|
|
}
|