diff --git a/plugins/field-config/plugin-form/index.js b/plugins/field-config/plugin-form/index.js index 66b33c9..aa9351b 100644 --- a/plugins/field-config/plugin-form/index.js +++ b/plugins/field-config/plugin-form/index.js @@ -24,7 +24,6 @@ export const handlePluginFormConfig = ({ name, config, formik }) => { if (index == null || !type) return; const ctd = formik.values.surferSeoAnalyzer[index].content_type; const { sourceFields } = getCachedElement(validFieldsCacheKey); - console.log(sourceFields); const keysToClearOnCtdChange = ['source']; diff --git a/plugins/index.js b/plugins/index.js index 66e57f7..2579c9c 100644 --- a/plugins/index.js +++ b/plugins/index.js @@ -5,10 +5,11 @@ import { handleManagePlugin } from './manage/index.js'; import { handlePluginFormConfig } from './field-config/plugin-form/index.js'; import { createSidebar } from './sidebar/index.js'; import { parsePluginSettings } from '../common/helpers.js'; +import i18n from 'i18next'; const setupSurferSeo = () => { (() => { - if (void 0 !== window.surferGuidelines) return; + // if (void 0 !== window.surferGuidelines) return; window.surferGuidelines = { init(...i) { window.__sg_in = i; @@ -41,26 +42,48 @@ const appendStyles = () => { }; registerFn(pluginInfo, (handler, _, { getPluginSettings, getLanguage }) => { + const getSettings = (contentType) => { + const pluginConfig = parsePluginSettings(getPluginSettings()); + return pluginConfig?.[contentType?.name]; + }; + setupSurferSeo(); appendStyles(); - const pluginConfig = parsePluginSettings(getPluginSettings()); + const language = getLanguage(); + if (language !== i18n.language) { + i18n.changeLanguage(language); + } handler.on('flotiq.plugins.manage::form-schema', (data) => handleManagePlugin(data), ); handler.on('flotiq.form.field::config', (data) => { - if ( - data.contentType?.id === pluginInfo.id && - data.contentType?.nonCtdSchema && - data.name - ) { - return handlePluginFormConfig(data); - } + return handlePluginFormConfig(data); + }); + + handler.on( + 'flotiq.form.sidebar-panel::add', + ({ contentType, contentObject }) => { + const ctdConfig = getSettings(contentType); + if (!ctdConfig) return; + + return createSidebar(contentObject?.id); + }, + ); + + handler.on('flotiq.form::add', ({ formik, contentType }) => { + const ctdConfig = getSettings(contentType); + if (!ctdConfig) return; + + const source = formik.values[ctdConfig.source]; + window.surferGuidelines.setHtml(source); }); - handler.on('flotiq.form.sidebar-panel::add', ({ formik }) => { - return createSidebar(formik, pluginConfig); + handler.on('flotiq.language::changed', ({ language }) => { + if (language !== i18n.language) { + i18n.changeLanguage(language); + } }); }); diff --git a/plugins/manage/index.js b/plugins/manage/index.js index 95d6ebb..9811c3f 100644 --- a/plugins/manage/index.js +++ b/plugins/manage/index.js @@ -1,7 +1,4 @@ -import { - addObjectToCache, - getCachedElement, -} from '../../common/plugin-element-cache.js'; +import { addObjectToCache } from '../../common/plugin-element-cache.js'; import { getValidFields, validFieldsCacheKey, diff --git a/plugins/sidebar/index.js b/plugins/sidebar/index.js index e7d7e17..585dcc7 100644 --- a/plugins/sidebar/index.js +++ b/plugins/sidebar/index.js @@ -4,8 +4,8 @@ import { getCachedElement, } from '../../common/plugin-element-cache.js'; -export const createSidebar = (formik, pluginConfig) => { - const containerCacheKey = `${pluginInfo.id}-surferseo-content-analyzer-container`; +export const createSidebar = (id) => { + const containerCacheKey = `${pluginInfo.id}-${id || ''}-surferseo-content-analyzer-container`; let contentAnalyzerContainer = getCachedElement(containerCacheKey)?.element; if (!contentAnalyzerContainer) { @@ -14,13 +14,11 @@ export const createSidebar = (formik, pluginConfig) => { window.surferGuidelines.init( contentAnalyzerContainer.querySelector('#surfer-guidelines-placeholder'), - 'sharing-token', + null, ); addElementToCache(contentAnalyzerContainer, containerCacheKey); } - console.log(formik, pluginConfig); - return contentAnalyzerContainer; }; diff --git a/plugins/styles/style.css b/plugins/styles/style.css index 26b4579..2612ac9 100644 --- a/plugins/styles/style.css +++ b/plugins/styles/style.css @@ -11,6 +11,6 @@ width: 100%; border: 0; border-radius: 0.5rem; - height: 400px; + height: 450px; overflow-y: scroll; }