From c889f302f6a19ebcf4322011e1c8e668b7be114e Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Sat, 25 Feb 2023 17:13:26 +0100 Subject: [PATCH] :bug: (wordpress) Fix admin critical bug and better lib import --- .../publish/components/embeds/EmbedButton.tsx | 17 +++- .../Javascript/JavascriptBubbleSnippet.tsx | 30 +++--- .../Javascript/JavascriptPopupSnippet.tsx | 6 +- .../Javascript/JavascriptStandardSnippet.tsx | 16 +-- .../instructions/ScriptBubbleInstructions.tsx | 24 +++-- .../instructions/ScriptPopupInstructions.tsx | 21 ++-- .../ScriptStandardInstructions.tsx | 21 ++-- .../embeds/snippetParsers/bubble.ts | 14 +-- .../components/embeds/snippetParsers/popup.ts | 14 +-- .../embeds/snippetParsers/shared.ts | 2 +- .../embeds/snippetParsers/standard.ts | 15 +-- packages/wordpress/package.json | 6 +- packages/wordpress/trunk/README.txt | 7 +- .../trunk/admin/class-typebot-admin.php | 1 + .../admin/partials/typebot-admin-display.php | 8 +- .../trunk/includes/class-typebot.php | 1 - .../trunk/public/class-typebot-public.php | 97 ++++++++++++------- packages/wordpress/trunk/typebot.php | 4 +- 18 files changed, 177 insertions(+), 127 deletions(-) diff --git a/apps/builder/src/features/publish/components/embeds/EmbedButton.tsx b/apps/builder/src/features/publish/components/embeds/EmbedButton.tsx index c8aeb73f81e..c7c11e67b27 100644 --- a/apps/builder/src/features/publish/components/embeds/EmbedButton.tsx +++ b/apps/builder/src/features/publish/components/embeds/EmbedButton.tsx @@ -1,4 +1,11 @@ -import { Button, useDisclosure, VStack, WrapItem, Text } from '@chakra-ui/react' +import { + Button, + useDisclosure, + VStack, + WrapItem, + Text, + useColorModeValue, +} from '@chakra-ui/react' import { WordpressLogo, ShopifyLogo, @@ -116,7 +123,13 @@ export const integrationsList = [ ), (props: Pick) => ( } + logo={ + + } label="Script" Modal={ScriptModal} {...props} diff --git a/apps/builder/src/features/publish/components/embeds/modals/Javascript/JavascriptBubbleSnippet.tsx b/apps/builder/src/features/publish/components/embeds/modals/Javascript/JavascriptBubbleSnippet.tsx index fe840bf05fc..c669e352781 100644 --- a/apps/builder/src/features/publish/components/embeds/modals/Javascript/JavascriptBubbleSnippet.tsx +++ b/apps/builder/src/features/publish/components/embeds/modals/Javascript/JavascriptBubbleSnippet.tsx @@ -1,6 +1,6 @@ import prettier from 'prettier/standalone' import parserHtml from 'prettier/parser-html' -import { parseInitBubbleCode } from '../../snippetParsers' +import { parseInitBubbleCode, typebotImportCode } from '../../snippetParsers' import { useTypebot } from '@/features/editor' import { CodeEditor } from '@/components/CodeEditor' import { BubbleProps } from '@typebot.io/js' @@ -13,19 +13,21 @@ export const JavascriptBubbleSnippet = ({ theme, previewMessage }: Props) => { const { typebot } = useTypebot() const snippet = prettier.format( - ``, + ``, { parser: 'html', plugins: [parserHtml], diff --git a/apps/builder/src/features/publish/components/embeds/modals/Javascript/JavascriptPopupSnippet.tsx b/apps/builder/src/features/publish/components/embeds/modals/Javascript/JavascriptPopupSnippet.tsx index ddc50a736dc..20997070cc7 100644 --- a/apps/builder/src/features/publish/components/embeds/modals/Javascript/JavascriptPopupSnippet.tsx +++ b/apps/builder/src/features/publish/components/embeds/modals/Javascript/JavascriptPopupSnippet.tsx @@ -1,7 +1,7 @@ import { useTypebot } from '@/features/editor' import parserHtml from 'prettier/parser-html' import prettier from 'prettier/standalone' -import { parseInitPopupCode } from '../../snippetParsers' +import { parseInitPopupCode, typebotImportCode } from '../../snippetParsers' import { CodeEditor } from '@/components/CodeEditor' import { PopupProps } from '@typebot.io/js' import { isCloudProdInstance } from '@/utils/helpers' @@ -29,5 +29,7 @@ export const JavascriptPopupSnippet = ({ autoShowDelay }: Props) => { const createSnippet = (params: PopupProps): string => { const jsCode = parseInitPopupCode(params) - return `` + return `` } diff --git a/apps/builder/src/features/publish/components/embeds/modals/Javascript/JavascriptStandardSnippet.tsx b/apps/builder/src/features/publish/components/embeds/modals/Javascript/JavascriptStandardSnippet.tsx index dd3b7aaa97e..951a7a9a79a 100644 --- a/apps/builder/src/features/publish/components/embeds/modals/Javascript/JavascriptStandardSnippet.tsx +++ b/apps/builder/src/features/publish/components/embeds/modals/Javascript/JavascriptStandardSnippet.tsx @@ -1,6 +1,6 @@ import parserHtml from 'prettier/parser-html' import prettier from 'prettier/standalone' -import { parseInitStandardCode } from '../../snippetParsers' +import { parseInitStandardCode, typebotImportCode } from '../../snippetParsers' import { useTypebot } from '@/features/editor' import { CodeEditor } from '@/components/CodeEditor' import { isCloudProdInstance } from '@/utils/helpers' @@ -31,12 +31,14 @@ export const JavascriptStandardSnippet = ({ export const parseStandardHeadCode = (publicId?: string | null) => prettier.format( - ``, + ``, { parser: 'html', plugins: [parserHtml] } ) diff --git a/apps/builder/src/features/publish/components/embeds/modals/Script/instructions/ScriptBubbleInstructions.tsx b/apps/builder/src/features/publish/components/embeds/modals/Script/instructions/ScriptBubbleInstructions.tsx index aa680f0c993..67378646f0b 100644 --- a/apps/builder/src/features/publish/components/embeds/modals/Script/instructions/ScriptBubbleInstructions.tsx +++ b/apps/builder/src/features/publish/components/embeds/modals/Script/instructions/ScriptBubbleInstructions.tsx @@ -7,7 +7,11 @@ import { Typebot } from 'models' import { useState } from 'react' import { env, getViewerUrl } from 'utils' import { BubbleSettings } from '../../../settings/BubbleSettings/BubbleSettings' -import { parseInlineScript, parseInitBubbleCode } from '../../../snippetParsers' +import { + parseInlineScript, + parseInitBubbleCode, + typebotImportCode, +} from '../../../snippetParsers' export const parseDefaultBubbleTheme = (typebot?: Typebot) => ({ button: { @@ -29,14 +33,16 @@ export const ScriptBubbleInstructions = () => { useState() const scriptSnippet = parseInlineScript( - parseInitBubbleCode({ - typebot: typebot?.publicId ?? '', - apiHost: isCloudProdInstance - ? undefined - : env('VIEWER_INTERNAL_URL') ?? getViewerUrl(), - theme, - previewMessage, - }) + `${typebotImportCode} + +${parseInitBubbleCode({ + typebot: typebot?.publicId ?? '', + apiHost: isCloudProdInstance + ? undefined + : env('VIEWER_INTERNAL_URL') ?? getViewerUrl(), + theme, + previewMessage, +})}` ) return ( diff --git a/apps/builder/src/features/publish/components/embeds/modals/Script/instructions/ScriptPopupInstructions.tsx b/apps/builder/src/features/publish/components/embeds/modals/Script/instructions/ScriptPopupInstructions.tsx index f4f46705435..68e189f10f0 100644 --- a/apps/builder/src/features/publish/components/embeds/modals/Script/instructions/ScriptPopupInstructions.tsx +++ b/apps/builder/src/features/publish/components/embeds/modals/Script/instructions/ScriptPopupInstructions.tsx @@ -6,20 +6,25 @@ import { useState } from 'react' import { env, getViewerUrl } from 'utils' import { PopupSettings } from '../../../settings/PopupSettings' import { parseInitPopupCode } from '../../../snippetParsers' -import { parseInlineScript } from '../../../snippetParsers/shared' +import { + parseInlineScript, + typebotImportCode, +} from '../../../snippetParsers/shared' export const ScriptPopupInstructions = () => { const { typebot } = useTypebot() const [inputValue, setInputValue] = useState() const scriptSnippet = parseInlineScript( - parseInitPopupCode({ - typebot: typebot?.publicId ?? '', - apiHost: isCloudProdInstance - ? undefined - : env('VIEWER_INTERNAL_URL') ?? getViewerUrl(), - autoShowDelay: inputValue, - }) + `${typebotImportCode} + +${parseInitPopupCode({ + typebot: typebot?.publicId ?? '', + apiHost: isCloudProdInstance + ? undefined + : env('VIEWER_INTERNAL_URL') ?? getViewerUrl(), + autoShowDelay: inputValue, +})}` ) return ( diff --git a/apps/builder/src/features/publish/components/embeds/modals/Script/instructions/ScriptStandardInstructions.tsx b/apps/builder/src/features/publish/components/embeds/modals/Script/instructions/ScriptStandardInstructions.tsx index 48ed4ea6ef1..1756a7bb3ee 100644 --- a/apps/builder/src/features/publish/components/embeds/modals/Script/instructions/ScriptStandardInstructions.tsx +++ b/apps/builder/src/features/publish/components/embeds/modals/Script/instructions/ScriptStandardInstructions.tsx @@ -7,7 +7,10 @@ import { env, getViewerUrl } from 'utils' import { StandardSettings } from '../../../settings/StandardSettings' import { parseInitStandardCode } from '../../../snippetParsers/standard' import { parseStandardElementCode } from '../../Javascript/JavascriptStandardSnippet' -import { parseInlineScript } from '../../../snippetParsers/shared' +import { + parseInlineScript, + typebotImportCode, +} from '../../../snippetParsers/shared' export const ScriptStandardInstructions = () => { const { typebot } = useTypebot() @@ -24,14 +27,14 @@ export const ScriptStandardInstructions = () => { inputValues.heightLabel ) - const scriptSnippet = parseInlineScript( - parseInitStandardCode({ - typebot: typebot?.publicId ?? '', - apiHost: isCloudProdInstance - ? undefined - : env('VIEWER_INTERNAL_URL') ?? getViewerUrl(), - }) - ) + const scriptSnippet = parseInlineScript(`${typebotImportCode} + +${parseInitStandardCode({ + typebot: typebot?.publicId ?? '', + apiHost: isCloudProdInstance + ? undefined + : env('VIEWER_INTERNAL_URL') ?? getViewerUrl(), +})}`) return ( diff --git a/apps/builder/src/features/publish/components/embeds/snippetParsers/bubble.ts b/apps/builder/src/features/publish/components/embeds/snippetParsers/bubble.ts index a616acabb1e..3dc852fbc80 100644 --- a/apps/builder/src/features/publish/components/embeds/snippetParsers/bubble.ts +++ b/apps/builder/src/features/publish/components/embeds/snippetParsers/bubble.ts @@ -6,7 +6,6 @@ import { parseBotProps, parseNumberOrBoolParam, parseReactBotProps, - typebotImportUrl, } from './shared' const parseButtonTheme = ( @@ -111,15 +110,10 @@ export const parseInitBubbleCode = ({ const botProps = parseBotProps({ typebot, apiHost }) const bubbleProps = parseBubbleProps({ previewMessage, theme }) - return prettier.format( - `import Typebot from '${typebotImportUrl}' - - Typebot.initBubble({${botProps}${bubbleProps}});`, - { - parser: 'babel', - plugins: [parserBabel], - } - ) + return prettier.format(`Typebot.initBubble({${botProps}${bubbleProps}});`, { + parser: 'babel', + plugins: [parserBabel], + }) } const parseReactBubbleTheme = (theme: BubbleProps['theme']): string => { diff --git a/apps/builder/src/features/publish/components/embeds/snippetParsers/popup.ts b/apps/builder/src/features/publish/components/embeds/snippetParsers/popup.ts index 40b0e9f97b3..1845a6ef305 100644 --- a/apps/builder/src/features/publish/components/embeds/snippetParsers/popup.ts +++ b/apps/builder/src/features/publish/components/embeds/snippetParsers/popup.ts @@ -8,7 +8,6 @@ import { parseReactNumberOrBoolParam, parseReactStringParam, parseStringParam, - typebotImportUrl, } from './shared' const parsePopupTheme = (theme: PopupProps['theme']): string => { @@ -41,15 +40,10 @@ export const parseInitPopupCode = ({ const botProps = parseBotProps({ typebot, apiHost }) const bubbleProps = parsePopupProps({ theme, autoShowDelay }) - return prettier.format( - `import Typebot from '${typebotImportUrl}' - - Typebot.initPopup({${botProps}${bubbleProps}});`, - { - parser: 'babel', - plugins: [parserBabel], - } - ) + return prettier.format(`Typebot.initPopup({${botProps}${bubbleProps}});`, { + parser: 'babel', + plugins: [parserBabel], + }) } const parseReactThemeProp = (theme: PopupProps['theme']): string => { diff --git a/apps/builder/src/features/publish/components/embeds/snippetParsers/shared.ts b/apps/builder/src/features/publish/components/embeds/snippetParsers/shared.ts index 40b46f4b493..f21605178ca 100644 --- a/apps/builder/src/features/publish/components/embeds/snippetParsers/shared.ts +++ b/apps/builder/src/features/publish/components/embeds/snippetParsers/shared.ts @@ -31,7 +31,7 @@ export const parseReactBotProps = ({ typebot, apiHost }: BotProps) => { return `${typebotLine} ${apiHostLine}` } -export const typebotImportUrl = `https://cdn.jsdelivr.net/npm/@typebot.io/js@0.0.14/dist/web.js` +export const typebotImportCode = `import Typebot from 'https://cdn.jsdelivr.net/npm/@typebot.io/js@0.0/dist/web.js'` export const parseInlineScript = (script: string) => prettier.format( diff --git a/apps/builder/src/features/publish/components/embeds/snippetParsers/standard.ts b/apps/builder/src/features/publish/components/embeds/snippetParsers/standard.ts index d52e2b9f370..bd69248dd22 100644 --- a/apps/builder/src/features/publish/components/embeds/snippetParsers/standard.ts +++ b/apps/builder/src/features/publish/components/embeds/snippetParsers/standard.ts @@ -1,7 +1,7 @@ import { BotProps } from '@typebot.io/js' import parserBabel from 'prettier/parser-babel' import prettier from 'prettier/standalone' -import { parseBotProps, typebotImportUrl } from './shared' +import { parseBotProps } from './shared' export const parseInitStandardCode = ({ typebot, @@ -9,13 +9,8 @@ export const parseInitStandardCode = ({ }: Pick) => { const botProps = parseBotProps({ typebot, apiHost }) - return prettier.format( - `import Typebot from '${typebotImportUrl}' - - Typebot.initStandard({${botProps}});`, - { - parser: 'babel', - plugins: [parserBabel], - } - ) + return prettier.format(`Typebot.initStandard({${botProps}});`, { + parser: 'babel', + plugins: [parserBabel], + }) } diff --git a/packages/wordpress/package.json b/packages/wordpress/package.json index 941406d93b7..d36d57b5f48 100644 --- a/packages/wordpress/package.json +++ b/packages/wordpress/package.json @@ -1,6 +1,6 @@ { "name": "wordpress", - "version": "2.1.11", + "version": "3.1.0", "main": "index.js", "repository": "https://github.com/baptisteArno/typebot.io", "author": "baptisteArno", @@ -11,7 +11,7 @@ }, "scripts": { "deploy": "pnpm copy && pnpm commit", - "copy": "svn copy ./trunk ./tags/3.0.1", - "commit": "svn ci -m 'Fix standard flow not proceeding'" + "copy": "svn copy ./trunk ./tags/3.1.0", + "commit": "svn ci -m 'Fix admin critical bug and introduce excluded pages'" } } diff --git a/packages/wordpress/trunk/README.txt b/packages/wordpress/trunk/README.txt index aabaf09d8c6..6ccdd5ac84a 100644 --- a/packages/wordpress/trunk/README.txt +++ b/packages/wordpress/trunk/README.txt @@ -5,7 +5,7 @@ Requires at least: 5.0 Tested up to: 6.0 License: GPL 2.0 License URI: http://www.gnu.org/licenses/gpl-2.0.txt -Stable Tag: 3.0.1 +Stable Tag: 3.1.0 Build beautiful conversational forms @@ -26,6 +26,11 @@ This plugin relies on Typebot which is a tool that allows you to create conversa 3. Activate your Typebot with the "Typebot" admin button located in the sidebar == Changelog == += 3.1.0 = +* Breaking change! You will need to import the new code snippet again. +* Fix wp admin crash +* Introduce excluded pages input + = 3.0.1 = * Fix flow not proceeding on unknown domains diff --git a/packages/wordpress/trunk/admin/class-typebot-admin.php b/packages/wordpress/trunk/admin/class-typebot-admin.php index c5edb10f8b7..c90627988e3 100644 --- a/packages/wordpress/trunk/admin/class-typebot-admin.php +++ b/packages/wordpress/trunk/admin/class-typebot-admin.php @@ -26,5 +26,6 @@ public function typebot_settings_callback() public function register_typebot_settings() { register_setting('typebot', 'init_snippet'); + register_setting('typebot', 'excluded_pages'); } } diff --git a/packages/wordpress/trunk/admin/partials/typebot-admin-display.php b/packages/wordpress/trunk/admin/partials/typebot-admin-display.php index dd551c5c1bc..068eb32d6bf 100644 --- a/packages/wordpress/trunk/admin/partials/typebot-admin-display.php +++ b/packages/wordpress/trunk/admin/partials/typebot-admin-display.php @@ -11,7 +11,13 @@ ?>
- + +
+ +
+ +

Example: /app/*, /user/*, /admin/settings

+
diff --git a/packages/wordpress/trunk/includes/class-typebot.php b/packages/wordpress/trunk/includes/class-typebot.php index af0bbbd1028..e3f14ec7227 100644 --- a/packages/wordpress/trunk/includes/class-typebot.php +++ b/packages/wordpress/trunk/includes/class-typebot.php @@ -42,7 +42,6 @@ private function set_locale() private function define_admin_hooks() { $plugin_admin = new Typebot_Admin($this->get_version()); - $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); $this->loader->add_action('admin_menu', $plugin_admin, 'my_admin_menu'); $this->loader->add_action('admin_init', $plugin_admin, 'register_typebot_settings'); } diff --git a/packages/wordpress/trunk/public/class-typebot-public.php b/packages/wordpress/trunk/public/class-typebot-public.php index 02cb71eb554..f5932c3e6a6 100644 --- a/packages/wordpress/trunk/public/class-typebot-public.php +++ b/packages/wordpress/trunk/public/class-typebot-public.php @@ -4,55 +4,78 @@ class Typebot_Public { public function add_head_code() { - function add_module_type($tag, $handle) + function parse_wp_user() { - if ('typebot' !== $handle) { - return $tag; - } - $tag = str_replace( - 'parse_wp_user()); - if (get_option('init_snippet') && get_option('init_snippet') !== '') { - wp_add_inline_script('typebot', get_option('init_snippet')); - wp_add_inline_script('typebot', 'Typebot.setPrefilledVariables({ typebotWpUser });'); - } - } - - private function parse_wp_user() - { - $wp_user = wp_get_current_user(); - return 'if(typeof window.typebotWpUser === "undefined"){ + $wp_user = wp_get_current_user(); + echo ''; + } + + function typebot_script() + { + echo ''; + } + add_action('wp_head', 'parse_wp_user'); + add_action('wp_footer', 'typebot_script'); } public function add_typebot_container($attributes = []) { - $lib_url = "https://cdn.jsdelivr.net/npm/@typebot.io/js@0.0.14/dist/web.js"; + $lib_url = "https://cdn.jsdelivr.net/npm/@typebot.io/js@0.0/dist/web.js"; $width = '100%'; $height = '500px'; if (array_key_exists('width', $attributes)) { diff --git a/packages/wordpress/trunk/typebot.php b/packages/wordpress/trunk/typebot.php index 7fc3c351171..0160b523b7f 100644 --- a/packages/wordpress/trunk/typebot.php +++ b/packages/wordpress/trunk/typebot.php @@ -3,7 +3,7 @@ /** * Plugin Name: Typebot * Description: Convert more with conversational forms - * Version: 3.0.1 + * Version: 3.1.0 * Author: Typebot * Author URI: http://typebot.io/ * License: GPL-2.0+ @@ -16,7 +16,7 @@ die(); } -define('TYPEBOT_VERSION', '3.0.1'); +define('TYPEBOT_VERSION', '3.1.0'); function activate_typebot() {