From f4dc3abc39428d2412ab29214248afd3006e8134 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:01:19 +0900 Subject: [PATCH 01/10] enhance(embed): add ability to pin color mode --- bskyembed/snippet/embed.ts | 1 + bskyembed/src/color-mode.ts | 6 ++++ bskyembed/src/screens/landing.tsx | 59 ++++++++++++++++++++++++++----- bskyembed/src/screens/post.tsx | 15 ++++++-- 4 files changed, 70 insertions(+), 11 deletions(-) diff --git a/bskyembed/snippet/embed.ts b/bskyembed/snippet/embed.ts index 3c1b14b955..4a56539b3c 100644 --- a/bskyembed/snippet/embed.ts +++ b/bskyembed/snippet/embed.ts @@ -68,6 +68,7 @@ function scan(node = document) { if (ref_url.startsWith('http')) { searchParams.set('ref_url', encodeURIComponent(ref_url)) } + searchParams.set('colorMode', embed.dataset.blueskyColorMode || 'auto') const iframe = document.createElement('iframe') iframe.setAttribute('data-bluesky-id', id) diff --git a/bskyembed/src/color-mode.ts b/bskyembed/src/color-mode.ts index 2b392c6178..7cbdfd4801 100644 --- a/bskyembed/src/color-mode.ts +++ b/bskyembed/src/color-mode.ts @@ -1,3 +1,9 @@ +export type ColorModeValues = 'auto' | 'light' | 'dark' + +export function assertColorModeValues(value: string): value is ColorModeValues { + return ['auto', 'light', 'dark'].includes(value) +} + export function applyTheme(theme: 'light' | 'dark') { document.documentElement.classList.remove('light', 'dark') document.documentElement.classList.add(theme) diff --git a/bskyembed/src/screens/landing.tsx b/bskyembed/src/screens/landing.tsx index a3448e90ac..82e8c9d394 100644 --- a/bskyembed/src/screens/landing.tsx +++ b/bskyembed/src/screens/landing.tsx @@ -6,7 +6,11 @@ import {useEffect, useMemo, useRef, useState} from 'preact/hooks' import arrowBottom from '../../assets/arrowBottom_stroke2_corner0_rounded.svg' import logo from '../../assets/logo.svg' -import {initColorMode} from '../color-mode' +import { + assertColorModeValues, + ColorModeValues, + initColorMode, +} from '../color-mode' import {Container} from '../components/container' import {Link} from '../components/link' import {Post} from '../components/post' @@ -32,6 +36,7 @@ render(, root) function LandingPage() { const [uri, setUri] = useState('') + const [colorMode, setColorMode] = useState('auto') const [error, setError] = useState(null) const [loading, setLoading] = useState(false) const [thread, setThread] = useState( @@ -128,16 +133,44 @@ function LandingPage() { placeholder={DEFAULT_POST} /> +
+ + Want to customize more? + +
+
+ + +
+
+
+ {loading ? ( -
+
) : (
- {!error && thread && uri && } - {!error && thread && } + {!error && thread && uri && ( + + )} +
+ {!error && thread && } +
{error && (

{error}

@@ -168,7 +201,13 @@ function Skeleton() { ) } -function Snippet({thread}: {thread: AppBskyFeedDefs.ThreadViewPost}) { +function Snippet({ + thread, + colorMode, +}: { + thread: AppBskyFeedDefs.ThreadViewPost + colorMode: ColorModeValues +}) { const ref = useRef(null) const [copied, setCopied] = useState(false) @@ -204,9 +243,11 @@ function Snippet({thread}: {thread: AppBskyFeedDefs.ThreadViewPost}) { // x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x return `

${escapeHtml(record.text)}${ + )}" data-bluesky-cid="${escapeHtml( + thread.post.cid, + )}" data-bluesky-embed-color-mode="${escapeHtml( + colorMode, + )}">

${escapeHtml(record.text)}${ record.embed ? `

[image or embed]` : '' @@ -217,7 +258,7 @@ function Snippet({thread}: {thread: AppBskyFeedDefs.ThreadViewPost}) { )}) ${escapeHtml( niceDate(thread.post.indexedAt), )}

` - }, [thread]) + }, [thread, colorMode]) return (
diff --git a/bskyembed/src/screens/post.tsx b/bskyembed/src/screens/post.tsx index 1764442b73..5eacc3e632 100644 --- a/bskyembed/src/screens/post.tsx +++ b/bskyembed/src/screens/post.tsx @@ -4,7 +4,7 @@ import {AppBskyFeedDefs, AtpAgent} from '@atproto/api' import {h, render} from 'preact' import logo from '../../assets/logo.svg' -import {initColorMode} from '../color-mode' +import {applyTheme, assertColorModeValues, initColorMode} from '../color-mode' import {Container} from '../components/container' import {Link} from '../components/link' import {Post} from '../components/post' @@ -22,7 +22,18 @@ if (!uri) { throw new Error('No uri in path') } -initColorMode() +const query = new URLSearchParams(window.location.search) +const colorMode = query.get('colorMode') + +if ( + colorMode != null && + assertColorModeValues(colorMode) && + colorMode !== 'auto' +) { + applyTheme(colorMode) +} else { + initColorMode() +} agent .getPostThread({ From c2b30f6e2ee8163f0c93e75f59933e9520b95ebe Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Fri, 13 Dec 2024 09:02:11 +0900 Subject: [PATCH 02/10] fix: Move color mode dropdown to the root section --- bskyembed/src/screens/landing.tsx | 58 +++++++++++++++---------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/bskyembed/src/screens/landing.tsx b/bskyembed/src/screens/landing.tsx index 82e8c9d394..c58ceae30f 100644 --- a/bskyembed/src/screens/landing.tsx +++ b/bskyembed/src/screens/landing.tsx @@ -125,37 +125,37 @@ function LandingPage() {

Embed a Bluesky Post

- setUri(e.currentTarget.value)} - className="border rounded-lg py-3 w-full max-w-[600px] px-4 dark:bg-dimmedBg dark:border-slate-500" - placeholder={DEFAULT_POST} - /> +
+ setUri(e.currentTarget.value)} + className="border rounded-lg py-3 px-4 dark:bg-dimmedBg dark:border-slate-500" + placeholder={DEFAULT_POST} + /> -
- - Want to customize more? - -
-
- - -
+
+ +
-
+
From 81011d9d94e620e9cc8af68831466181af006163 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Fri, 13 Dec 2024 09:41:34 +0900 Subject: [PATCH 03/10] auto -> system --- bskyembed/snippet/embed.ts | 2 +- bskyembed/src/color-mode.ts | 4 ++-- bskyembed/src/screens/landing.tsx | 4 ++-- bskyembed/src/screens/post.tsx | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bskyembed/snippet/embed.ts b/bskyembed/snippet/embed.ts index 4a56539b3c..7de7af1fec 100644 --- a/bskyembed/snippet/embed.ts +++ b/bskyembed/snippet/embed.ts @@ -68,7 +68,7 @@ function scan(node = document) { if (ref_url.startsWith('http')) { searchParams.set('ref_url', encodeURIComponent(ref_url)) } - searchParams.set('colorMode', embed.dataset.blueskyColorMode || 'auto') + searchParams.set('colorMode', embed.dataset.blueskyColorMode || 'system') const iframe = document.createElement('iframe') iframe.setAttribute('data-bluesky-id', id) diff --git a/bskyembed/src/color-mode.ts b/bskyembed/src/color-mode.ts index 7cbdfd4801..fcca48a072 100644 --- a/bskyembed/src/color-mode.ts +++ b/bskyembed/src/color-mode.ts @@ -1,7 +1,7 @@ -export type ColorModeValues = 'auto' | 'light' | 'dark' +export type ColorModeValues = 'system' | 'light' | 'dark' export function assertColorModeValues(value: string): value is ColorModeValues { - return ['auto', 'light', 'dark'].includes(value) + return ['system', 'light', 'dark'].includes(value) } export function applyTheme(theme: 'light' | 'dark') { diff --git a/bskyembed/src/screens/landing.tsx b/bskyembed/src/screens/landing.tsx index c58ceae30f..d53ec66934 100644 --- a/bskyembed/src/screens/landing.tsx +++ b/bskyembed/src/screens/landing.tsx @@ -36,7 +36,7 @@ render(, root) function LandingPage() { const [uri, setUri] = useState('') - const [colorMode, setColorMode] = useState('auto') + const [colorMode, setColorMode] = useState('system') const [error, setError] = useState(null) const [loading, setLoading] = useState(false) const [thread, setThread] = useState( @@ -150,7 +150,7 @@ function LandingPage() { }} id="colorModeSelect" className="block border w-full rounded-lg text-sm px-3 py-2 dark:bg-dimmedBg dark:border-slate-500"> - + diff --git a/bskyembed/src/screens/post.tsx b/bskyembed/src/screens/post.tsx index 5eacc3e632..2d837deaee 100644 --- a/bskyembed/src/screens/post.tsx +++ b/bskyembed/src/screens/post.tsx @@ -28,7 +28,7 @@ const colorMode = query.get('colorMode') if ( colorMode != null && assertColorModeValues(colorMode) && - colorMode !== 'auto' + colorMode !== 'system' ) { applyTheme(colorMode) } else { From d1fed1b5d5cfaa36cf05193be8ae9f329f18c073 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Thu, 19 Dec 2024 16:43:22 +0000 Subject: [PATCH 04/10] style tweaks --- bskyembed/src/screens/landing.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bskyembed/src/screens/landing.tsx b/bskyembed/src/screens/landing.tsx index d53ec66934..6f6c65eb97 100644 --- a/bskyembed/src/screens/landing.tsx +++ b/bskyembed/src/screens/landing.tsx @@ -1,6 +1,6 @@ import '../index.css' -import {AppBskyFeedDefs, AppBskyFeedPost, AtUri, BskyAgent} from '@atproto/api' +import {AppBskyFeedDefs, AppBskyFeedPost, AtpAgent, AtUri} from '@atproto/api' import {h, render} from 'preact' import {useEffect, useMemo, useRef, useState} from 'preact/hooks' @@ -28,7 +28,7 @@ if (!root) throw new Error('No root element') initColorMode() -const agent = new BskyAgent({ +const agent = new AtpAgent({ service: 'https://public.api.bsky.app', }) @@ -130,13 +130,13 @@ function LandingPage() { type="text" value={uri} onInput={e => setUri(e.currentTarget.value)} - className="border rounded-lg py-3 px-4 dark:bg-dimmedBg dark:border-slate-500" + className="border rounded-lg py-3 px-4 dark:bg-dimmedBg dark:border-slate-500" placeholder={DEFAULT_POST} />
@@ -149,7 +149,7 @@ function LandingPage() { } }} id="colorModeSelect" - className="block border w-full rounded-lg text-sm px-3 py-2 dark:bg-dimmedBg dark:border-slate-500"> + className="bg-white block border w-full rounded-lg text-sm px-3 py-2 dark:bg-dimmedBg dark:border-slate-500"> From e76be6811cda58714bb0d195289a97965de7de38 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Thu, 19 Dec 2024 16:43:39 +0000 Subject: [PATCH 05/10] default to light theme --- bskyembed/src/screens/post.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/bskyembed/src/screens/post.tsx b/bskyembed/src/screens/post.tsx index 2d837deaee..cea698b869 100644 --- a/bskyembed/src/screens/post.tsx +++ b/bskyembed/src/screens/post.tsx @@ -23,13 +23,11 @@ if (!uri) { } const query = new URLSearchParams(window.location.search) -const colorMode = query.get('colorMode') -if ( - colorMode != null && - assertColorModeValues(colorMode) && - colorMode !== 'system' -) { +// theme - default to light mode +const colorMode = query.get('colorMode') ?? 'light' + +if (assertColorModeValues(colorMode) && colorMode !== 'system') { applyTheme(colorMode) } else { initColorMode() From ec660f5e5f177e75f067ee2cbce6123a967a5407 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Thu, 19 Dec 2024 16:47:25 +0000 Subject: [PATCH 06/10] try and fix eslint --- .eslintrc.js | 1 + bskyembed/.eslintrc | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 8f8383bcc7..f18f5745eb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -107,6 +107,7 @@ module.exports = { 'bskyweb', '*.html', 'bskyweb', + 'bskyembed', 'src/locale/locales/_build/', 'src/locale/locales/**/*.js', ], diff --git a/bskyembed/.eslintrc b/bskyembed/.eslintrc index 2b290d5815..c21e1ec518 100644 --- a/bskyembed/.eslintrc +++ b/bskyembed/.eslintrc @@ -16,6 +16,6 @@ "parserOptions": { "sourceType": "module", "ecmaVersion": "latest", - "project": "./bskyembed/tsconfig.json" + "project": "./tsconfig.json" } } From 45336d39ab77c488f45a1db24cc2c35551f12f5a Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Thu, 19 Dec 2024 17:06:30 +0000 Subject: [PATCH 07/10] fix dropdown styles on other browsers --- .eslintrc.js | 2 +- bskyembed/.eslintrc | 2 +- bskyembed/src/index.css | 11 +++++++++++ bskyembed/src/screens/landing.tsx | 10 ++++------ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index f18f5745eb..6cf3cdbcc4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -104,7 +104,6 @@ module.exports = { '*.lock', '.husky', 'patches', - 'bskyweb', '*.html', 'bskyweb', 'bskyembed', @@ -117,5 +116,6 @@ module.exports = { parserOptions: { sourceType: 'module', ecmaVersion: 'latest', + projectSerivce: true, }, } diff --git a/bskyembed/.eslintrc b/bskyembed/.eslintrc index c21e1ec518..2b290d5815 100644 --- a/bskyembed/.eslintrc +++ b/bskyembed/.eslintrc @@ -16,6 +16,6 @@ "parserOptions": { "sourceType": "module", "ecmaVersion": "latest", - "project": "./tsconfig.json" + "project": "./bskyembed/tsconfig.json" } } diff --git a/bskyembed/src/index.css b/bskyembed/src/index.css index 289e34cf00..efd9f4a4e7 100644 --- a/bskyembed/src/index.css +++ b/bskyembed/src/index.css @@ -9,3 +9,14 @@ :root { color-scheme: light dark; } + +select { + background-image: url("data:image/svg+xml,"); + background-repeat: no-repeat; + background-position: calc(100% - 0.75rem) center; + padding-right: 2rem; + + @media (prefers-color-scheme: dark) { + background-image: url("data:image/svg+xml,"); + } +} diff --git a/bskyembed/src/screens/landing.tsx b/bskyembed/src/screens/landing.tsx index 6f6c65eb97..b2b6625275 100644 --- a/bskyembed/src/screens/landing.tsx +++ b/bskyembed/src/screens/landing.tsx @@ -125,7 +125,7 @@ function LandingPage() {

Embed a Bluesky Post

-
+
-
-