From 0f4a4d7527433eef6e95c51edea47bcfa33bbf7c Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 11 Oct 2022 11:51:15 +0200 Subject: Move some modules from flavours/glitch/utils/ back to flavours/glitch/features/compose/util/ --- .../features/compose/components/compose_form.js | 2 +- .../glitch/features/compose/util/counter.js | 9 +++++++ .../glitch/features/compose/util/url_regex.js | 30 ++++++++++++++++++++++ app/javascript/flavours/glitch/utils/counter.js | 9 ------- app/javascript/flavours/glitch/utils/url_regex.js | 30 ---------------------- 5 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 app/javascript/flavours/glitch/features/compose/util/counter.js create mode 100644 app/javascript/flavours/glitch/features/compose/util/url_regex.js delete mode 100644 app/javascript/flavours/glitch/utils/counter.js delete mode 100644 app/javascript/flavours/glitch/utils/url_regex.js (limited to 'app/javascript/flavours/glitch') diff --git a/app/javascript/flavours/glitch/features/compose/components/compose_form.js b/app/javascript/flavours/glitch/features/compose/components/compose_form.js index 4fc8f0884..3a9fa01e1 100644 --- a/app/javascript/flavours/glitch/features/compose/components/compose_form.js +++ b/app/javascript/flavours/glitch/features/compose/components/compose_form.js @@ -11,7 +11,7 @@ import UploadFormContainer from '../containers/upload_form_container'; import WarningContainer from '../containers/warning_container'; import { isMobile } from 'flavours/glitch/utils/is_mobile'; import ImmutablePureComponent from 'react-immutable-pure-component'; -import { countableText } from 'flavours/glitch/utils/counter'; +import { countableText } from '../util/counter'; import OptionsContainer from '../containers/options_container'; import Publisher from './publisher'; import TextareaIcons from './textarea_icons'; diff --git a/app/javascript/flavours/glitch/features/compose/util/counter.js b/app/javascript/flavours/glitch/features/compose/util/counter.js new file mode 100644 index 000000000..7aa9e87b1 --- /dev/null +++ b/app/javascript/flavours/glitch/features/compose/util/counter.js @@ -0,0 +1,9 @@ +import { urlRegex } from './url_regex'; + +const urlPlaceholder = '$2xxxxxxxxxxxxxxxxxxxxxxx'; + +export function countableText(inputText) { + return inputText + .replace(urlRegex, urlPlaceholder) + .replace(/(^|[^\/\w])@(([a-z0-9_]+)@[a-z0-9\.\-]+[a-z0-9]+)/ig, '$1@$3'); +}; diff --git a/app/javascript/flavours/glitch/features/compose/util/url_regex.js b/app/javascript/flavours/glitch/features/compose/util/url_regex.js new file mode 100644 index 000000000..9c2005c53 --- /dev/null +++ b/app/javascript/flavours/glitch/features/compose/util/url_regex.js @@ -0,0 +1,30 @@ +import regexSupplant from 'twitter-text/dist/lib/regexSupplant'; +import validUrlPrecedingChars from 'twitter-text/dist/regexp/validUrlPrecedingChars'; +import validDomain from 'twitter-text/dist/regexp/validDomain'; +import validPortNumber from 'twitter-text/dist/regexp/validPortNumber'; +import validUrlPath from 'twitter-text/dist/regexp/validUrlPath'; +import validUrlQueryChars from 'twitter-text/dist/regexp/validUrlQueryChars'; +import validUrlQueryEndingChars from 'twitter-text/dist/regexp/validUrlQueryEndingChars'; + +// The difference with twitter-text's extractURL is that the protocol isn't +// optional. + +export const urlRegex = regexSupplant( + '(' + // $1 URL + '(#{validUrlPrecedingChars})' + // $2 + '(https?:\\/\\/)' + // $3 Protocol + '(#{validDomain})' + // $4 Domain(s) + '(?::(#{validPortNumber}))?' + // $5 Port number (optional) + '(\\/#{validUrlPath}*)?' + // $6 URL Path + '(\\?#{validUrlQueryChars}*#{validUrlQueryEndingChars})?' + // $7 Query String + ')', + { + validUrlPrecedingChars, + validDomain, + validPortNumber, + validUrlPath, + validUrlQueryChars, + validUrlQueryEndingChars, + }, + 'gi', +); diff --git a/app/javascript/flavours/glitch/utils/counter.js b/app/javascript/flavours/glitch/utils/counter.js deleted file mode 100644 index 7aa9e87b1..000000000 --- a/app/javascript/flavours/glitch/utils/counter.js +++ /dev/null @@ -1,9 +0,0 @@ -import { urlRegex } from './url_regex'; - -const urlPlaceholder = '$2xxxxxxxxxxxxxxxxxxxxxxx'; - -export function countableText(inputText) { - return inputText - .replace(urlRegex, urlPlaceholder) - .replace(/(^|[^\/\w])@(([a-z0-9_]+)@[a-z0-9\.\-]+[a-z0-9]+)/ig, '$1@$3'); -}; diff --git a/app/javascript/flavours/glitch/utils/url_regex.js b/app/javascript/flavours/glitch/utils/url_regex.js deleted file mode 100644 index 9c2005c53..000000000 --- a/app/javascript/flavours/glitch/utils/url_regex.js +++ /dev/null @@ -1,30 +0,0 @@ -import regexSupplant from 'twitter-text/dist/lib/regexSupplant'; -import validUrlPrecedingChars from 'twitter-text/dist/regexp/validUrlPrecedingChars'; -import validDomain from 'twitter-text/dist/regexp/validDomain'; -import validPortNumber from 'twitter-text/dist/regexp/validPortNumber'; -import validUrlPath from 'twitter-text/dist/regexp/validUrlPath'; -import validUrlQueryChars from 'twitter-text/dist/regexp/validUrlQueryChars'; -import validUrlQueryEndingChars from 'twitter-text/dist/regexp/validUrlQueryEndingChars'; - -// The difference with twitter-text's extractURL is that the protocol isn't -// optional. - -export const urlRegex = regexSupplant( - '(' + // $1 URL - '(#{validUrlPrecedingChars})' + // $2 - '(https?:\\/\\/)' + // $3 Protocol - '(#{validDomain})' + // $4 Domain(s) - '(?::(#{validPortNumber}))?' + // $5 Port number (optional) - '(\\/#{validUrlPath}*)?' + // $6 URL Path - '(\\?#{validUrlQueryChars}*#{validUrlQueryEndingChars})?' + // $7 Query String - ')', - { - validUrlPrecedingChars, - validDomain, - validPortNumber, - validUrlPath, - validUrlQueryChars, - validUrlQueryEndingChars, - }, - 'gi', -); -- cgit