From 20ce6468520e76b0fb2931a5fac368157d950b1d Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 7 Jun 2021 03:14:48 +0300 Subject: [WIP] MUCH better approach to replacing emojis with still versions --- src/components/rich_content/rich_content.jsx | 66 +++++++++++++++++++++++++++ src/components/rich_content/rich_content.scss | 0 2 files changed, 66 insertions(+) create mode 100644 src/components/rich_content/rich_content.jsx create mode 100644 src/components/rich_content/rich_content.scss (limited to 'src/components/rich_content') diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx new file mode 100644 index 00000000..3b29eb4c --- /dev/null +++ b/src/components/rich_content/rich_content.jsx @@ -0,0 +1,66 @@ +import Vue from 'vue' +import { mapGetters } from 'vuex' +import { processHtml } from 'src/services/tiny_post_html_processor/tiny_post_html_processor.service.js' +import { convertHtml, getTagName, processTextForEmoji, getAttrs } from 'src/services/mini_html_converter/mini_html_converter.service.js' +import { mentionMatchesUrl, extractTagFromUrl } from 'src/services/matcher/matcher.service.js' +import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' +import StillImage from 'src/components/still-image/still-image.vue' + +import './rich_content.scss' + +export default Vue.component('RichContent', { + name: 'RichContent', + props: { + html: { + required: true, + type: String + }, + emoji: { + required: true, + type: Array + } + }, + render (h) { + const renderImage = (tag) => { + return + } + const structure = convertHtml(this.html) + const processItem = (item) => { + if (typeof item === 'string') { + if (item.includes(':')) { + return processTextForEmoji( + item, + this.emoji, + ({ shortcode, url }) => { + return + } + ) + } else { + return item + } + } + if (Array.isArray(item)) { + const [opener, children] = item + const Tag = getTagName(opener) + if (Tag === 'img') { + return renderImage(opener) + } + if (children !== undefined) { + return + { children.map(processItem) } + + } else { + return + } + } + } + return
+ { structure.map(processItem) } +
+ } +}) diff --git a/src/components/rich_content/rich_content.scss b/src/components/rich_content/rich_content.scss new file mode 100644 index 00000000..e69de29b -- cgit v1.2.3-70-g09d2 From 5970ddf9ac5ed7b7a855ed4c025a2f5f62e256fa Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 7 Jun 2021 12:22:15 +0300 Subject: fix escaped apostrophes --- src/components/rich_content/rich_content.jsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/components/rich_content') diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx index 3b29eb4c..a5c010de 100644 --- a/src/components/rich_content/rich_content.jsx +++ b/src/components/rich_content/rich_content.jsx @@ -1,9 +1,6 @@ import Vue from 'vue' -import { mapGetters } from 'vuex' -import { processHtml } from 'src/services/tiny_post_html_processor/tiny_post_html_processor.service.js' +import { unescape } from 'lodash' import { convertHtml, getTagName, processTextForEmoji, getAttrs } from 'src/services/mini_html_converter/mini_html_converter.service.js' -import { mentionMatchesUrl, extractTagFromUrl } from 'src/services/matcher/matcher.service.js' -import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' import StillImage from 'src/components/still-image/still-image.vue' import './rich_content.scss' @@ -29,7 +26,7 @@ export default Vue.component('RichContent', { if (typeof item === 'string') { if (item.includes(':')) { return processTextForEmoji( - item, + unescape(item), this.emoji, ({ shortcode, url }) => { return Date: Mon, 7 Jun 2021 12:49:54 +0300 Subject: move styles to richcontent --- src/components/rich_content/rich_content.jsx | 9 +-- src/components/rich_content/rich_content.scss | 70 ++++++++++++++++++++++++ src/components/status_content/status_content.vue | 55 +------------------ 3 files changed, 76 insertions(+), 58 deletions(-) (limited to 'src/components/rich_content') diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx index a5c010de..7bff23cd 100644 --- a/src/components/rich_content/rich_content.jsx +++ b/src/components/rich_content/rich_content.jsx @@ -19,7 +19,8 @@ export default Vue.component('RichContent', { }, render (h) { const renderImage = (tag) => { - return + const attrs = getAttrs(tag) + return } const structure = convertHtml(this.html) const processItem = (item) => { @@ -30,7 +31,7 @@ export default Vue.component('RichContent', { this.emoji, ({ shortcode, url }) => { return + return { structure.map(processItem) } - + } }) diff --git a/src/components/rich_content/rich_content.scss b/src/components/rich_content/rich_content.scss index e69de29b..2fcd3911 100644 --- a/src/components/rich_content/rich_content.scss +++ b/src/components/rich_content/rich_content.scss @@ -0,0 +1,70 @@ +.RichContent { + font-family: var(--postFont, sans-serif); + line-height: 1.4em; + white-space: pre-wrap; + overflow-wrap: break-word; + word-wrap: break-word; + word-break: break-word; + + blockquote { + margin: 0.2em 0 0.2em 2em; + font-style: italic; + } + + pre { + overflow: auto; + } + + code, + samp, + kbd, + var, + pre { + font-family: var(--postCodeFont, monospace); + } + + p { + margin: 0 0 1em 0; + } + + p:last-child { + margin: 0 0 0 0; + } + + h1 { + font-size: 1.1em; + line-height: 1.2em; + margin: 1.4em 0; + } + + h2 { + font-size: 1.1em; + margin: 1em 0; + } + + h3 { + font-size: 1em; + margin: 1.2em 0; + } + + h4 { + margin: 1.1em 0; + } + + .img { + display: inline-block; + } + + .emoji { + width: 32px; + height: 32px; + } + + .img, + video { + max-width: 100%; + max-height: 400px; + vertical-align: middle; + object-fit: contain; + } +} diff --git a/src/components/status_content/status_content.vue b/src/components/status_content/status_content.vue index fa095d43..31cd5a2e 100644 --- a/src/components/status_content/status_content.vue +++ b/src/components/status_content/status_content.vue @@ -185,16 +185,11 @@ $status-margin: 0.75em; } } - img, video { + video { max-width: 100%; max-height: 400px; vertical-align: middle; object-fit: contain; - - &.emoji { - width: 32px; - height: 32px; - } } .summary-wrapper { @@ -230,54 +225,6 @@ $status-margin: 0.75em; } .status-content { - font-family: var(--postFont, sans-serif); - line-height: 1.4em; - white-space: pre-wrap; - overflow-wrap: break-word; - word-wrap: break-word; - word-break: break-word; - - blockquote { - margin: 0.2em 0 0.2em 2em; - font-style: italic; - } - - pre { - overflow: auto; - } - - code, samp, kbd, var, pre { - font-family: var(--postCodeFont, monospace); - } - - p { - margin: 0 0 1em 0; - } - - p:last-child { - margin: 0 0 0 0; - } - - h1 { - font-size: 1.1em; - line-height: 1.2em; - margin: 1.4em 0; - } - - h2 { - font-size: 1.1em; - margin: 1.0em 0; - } - - h3 { - font-size: 1em; - margin: 1.2em 0; - } - - h4 { - margin: 1.1em 0; - } - &.single-line { white-space: nowrap; text-overflow: ellipsis; -- cgit v1.2.3-70-g09d2 From 22c8f71945c6d114bf4db89c87eb1b166775f2d6 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 7 Jun 2021 16:16:10 +0300 Subject: mention link --- src/components/mention_link/mention_link.js | 71 +++++++++++++++++++++++++ src/components/mention_link/mention_link.scss | 49 +++++++++++++++++ src/components/mention_link/mention_link.vue | 17 ++++++ src/components/rich_content/rich_content.jsx | 16 ++++-- src/components/status_content/status_content.js | 7 +++ src/modules/users.js | 4 ++ 6 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 src/components/mention_link/mention_link.js create mode 100644 src/components/mention_link/mention_link.scss create mode 100644 src/components/mention_link/mention_link.vue (limited to 'src/components/rich_content') diff --git a/src/components/mention_link/mention_link.js b/src/components/mention_link/mention_link.js new file mode 100644 index 00000000..ade598d8 --- /dev/null +++ b/src/components/mention_link/mention_link.js @@ -0,0 +1,71 @@ +import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' +import { getTextColor, rgb2hex } from 'src/services/color_convert/color_convert.js' +import { mapGetters, mapState } from 'vuex' +import { convert } from 'chromatism' + +const MentionLink = { + name: 'MentionLink', + props: { + url: { + required: true, + type: String + }, + content: { + required: true, + type: String + }, + origattrs: { + required: true, + type: Object + } + }, + methods: { + onClick () { + const link = generateProfileLink(this.user.id, this.user.screen_name) + this.$router.push(link) + } + }, + computed: { + user () { + return this.$store.getters.findUserByUrl(this.url) + }, + isYou () { + // FIXME why user !== currentUser??? + return this.user.screen_name === this.currentUser.screen_name + }, + userName () { + return this.userNameFullUi.split('@')[0] + }, + userNameFull () { + return this.user.screen_name + }, + userNameFullUi () { + return this.user.screen_name_ui + }, + highlight () { + return this.mergedConfig.highlight[this.user.screen_name] + }, + bg () { + if (this.highlight) return this.highlight.color + }, + text () { + if (this.bg) { + const linkColor = this.mergedConfig.customTheme.colors.link + const color = getTextColor(convert(this.bg).rgb, convert(linkColor).rgb) + return rgb2hex(color) + } + }, + style () { + return [ + this.bg && `--mention-bg: ${this.bg}`, + this.text && `--mention-text: ${this.text}` + ].filter(_ => _).join('; ') + }, + ...mapGetters(['mergedConfig']), + ...mapState({ + currentUser: state => state.users.currentUser + }) + } +} + +export default MentionLink diff --git a/src/components/mention_link/mention_link.scss b/src/components/mention_link/mention_link.scss new file mode 100644 index 00000000..237d9205 --- /dev/null +++ b/src/components/mention_link/mention_link.scss @@ -0,0 +1,49 @@ +.MentionLink { + position: relative; + white-space: normal; + display: inline-block; + + & .new, + & .original, + & .full { + padding: 0 2px; + margin: 0 -2px; + display: inline-block; + border-radius: 2px; + } + + .original { + opacity: 0.5; + } + + .full { + pointer-events: none; + position: absolute; + opacity: 0; + top: 0; + bottom: 0; + left: 0; + word-wrap: normal; + white-space: nowrap; + transition: opacity 0.2s ease; + background-color: var(--mention-bg, var(--popover)); + color: var(--mention-text, var(--link)); + z-index: 1; + } + + .new { + background-color: var(--mention-bg); + color: var(--mention-text, var(--link)); + + &.-you { + & .shortName, + & .full { + font-weight: 600; + } + } + } + + &:hover .new .full { + opacity: 1; + } +} diff --git a/src/components/mention_link/mention_link.vue b/src/components/mention_link/mention_link.vue new file mode 100644 index 00000000..84ed3205 --- /dev/null +++ b/src/components/mention_link/mention_link.vue @@ -0,0 +1,17 @@ + + + diff --git a/src/components/still-image/still-image.vue b/src/components/still-image/still-image.vue index d3eb5925..a3610b51 100644 --- a/src/components/still-image/still-image.vue +++ b/src/components/still-image/still-image.vue @@ -30,7 +30,7 @@ position: relative; line-height: 0; overflow: hidden; - display: flex; + display: inline-flex; align-items: center; canvas { @@ -53,6 +53,7 @@ &.animated { &::before { + zoom: var(--_still_image-label-scale, 1); content: 'gif'; position: absolute; line-height: 10px; diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index 9f63feb6..8dc22823 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -54,6 +54,7 @@ export const parseUser = (data) => { return output } + output.emoji = data.emojis output.name = data.display_name output.name_html = addEmojis(escape(data.display_name), data.emojis) -- cgit v1.2.3-70-g09d2 From 60903272366e1f236041841af3dca86628901a35 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 7 Jun 2021 20:02:09 +0300 Subject: moved some post styles into status body since they inferfere with usernames --- src/components/rich_content/rich_content.scss | 7 ------- src/components/status_body/status_body.scss | 11 +++++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'src/components/rich_content') diff --git a/src/components/rich_content/rich_content.scss b/src/components/rich_content/rich_content.scss index a486babf..12cb9776 100644 --- a/src/components/rich_content/rich_content.scss +++ b/src/components/rich_content/rich_content.scss @@ -1,11 +1,4 @@ .RichContent { - font-family: var(--postFont, sans-serif); - line-height: 1.4em; - white-space: pre-wrap; - overflow-wrap: break-word; - word-wrap: break-word; - word-break: break-word; - blockquote { margin: 0.2em 0 0.2em 2em; font-style: italic; diff --git a/src/components/status_body/status_body.scss b/src/components/status_body/status_body.scss index 6282919c..b65e3b27 100644 --- a/src/components/status_body/status_body.scss +++ b/src/components/status_body/status_body.scss @@ -1,10 +1,21 @@ @import '../../_variables.scss'; .StatusBody { + .emoji { --_still_image-label-scale: 0.5; } + & .text, + & .summary { + font-family: var(--postFont, sans-serif); + white-space: pre-wrap; + overflow-wrap: break-word; + word-wrap: break-word; + word-break: break-word; + line-height: 1.4em; + } + .summary { display: block; font-style: italic; -- cgit v1.2.3-70-g09d2 From 3abd357694c29c84d213d7d2a7a954ab2a591da0 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 8 Jun 2021 11:38:44 +0300 Subject: moving mentions into separate row --- src/components/mention_link/mention_link.js | 20 +++++++++++-- src/components/mention_link/mention_link.scss | 5 ++++ src/components/mention_link/mention_link.vue | 2 +- src/components/rich_content/rich_content.jsx | 19 +++++++++--- src/components/status/status.js | 22 ++++++++++---- src/components/status/status.scss | 3 +- src/components/status/status.vue | 43 ++++++++++++++++++++++----- src/i18n/en.json | 1 + 8 files changed, 94 insertions(+), 21 deletions(-) (limited to 'src/components/rich_content') diff --git a/src/components/mention_link/mention_link.js b/src/components/mention_link/mention_link.js index d26ae337..465c7d00 100644 --- a/src/components/mention_link/mention_link.js +++ b/src/components/mention_link/mention_link.js @@ -14,8 +14,14 @@ const MentionLink = { type: String }, origattrs: { - required: true, - type: Object + required: false, + type: Object, + default: {} + }, + firstMention: { + required: false, + type: Boolean, + default: false } }, methods: { @@ -61,6 +67,16 @@ const MentionLink = { return rest } }, + classnames () { + return [ + { + '-you': this.isYou, + '-highlighted': this.highlight, + '-firstMention': this.firstMention + }, + this.highlightType + ] + }, ...mapGetters(['mergedConfig']), ...mapState({ currentUser: state => state.users.currentUser diff --git a/src/components/mention_link/mention_link.scss b/src/components/mention_link/mention_link.scss index 78a9816c..dec11014 100644 --- a/src/components/mention_link/mention_link.scss +++ b/src/components/mention_link/mention_link.scss @@ -39,10 +39,15 @@ } .new { + &.-firstMention { + display: none; + } + &, &.-highlighted { .short { line-height: 1.5; + font-size: inherit; &::before { display: inline-block; diff --git a/src/components/mention_link/mention_link.vue b/src/components/mention_link/mention_link.vue index d8d45a1b..05f6fd91 100644 --- a/src/components/mention_link/mention_link.vue +++ b/src/components/mention_link/mention_link.vue @@ -12,7 +12,7 @@ v-if="user" class="new" :style="style" - :class="[{ '-you': isYou, '-highlighted': highlight }, highlightType]" + :class="classnames" >