Skip to content

Commit f4e96a5

Browse files
authored
Merge pull request #8 from koddsson/some-fixes
Some fixes to issues we found while getting up and running
2 parents 4b58cb5 + bd18ff3 commit f4e96a5

File tree

3 files changed

+43
-26
lines changed

3 files changed

+43
-26
lines changed

SECURITY.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<toot-embed src="https://sunny.garden/@knowler/109487032491438808"></toot-embed>
1010

1111
<script type="module">
12+
import 'https://cdn.skypack.dev/pin/urlpattern-polyfill@v6.0.2-Xkk1InwdFsTyUXRMqTq0/mode=imports,min/optimized/urlpattern-polyfill.js'
13+
import 'https://cdn.skypack.dev/pin/element-internals-polyfill@v1.1.18-z4BovnhHcCqD1ZdZNRfe/mode=imports,min/optimized/element-internals-polyfill.js'
1214
// import 'https://unpkg.com/@github/toot-embed-boilerplate@latest/dist/toot-embed.js'
1315
import '../src/toot-embed-element.ts'
1416
</script>

src/toot-embed-element.ts

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
const html = String.raw
22
const styles = new CSSStyleSheet()
33
styles.replaceSync(`
4-
:host(:not(:--loading)) {
5-
display: grid;
6-
max-inline-size: 36em;
7-
padding: 0.5em;
8-
gap: 0.5em;
9-
border: 0.0625em solid grey;
10-
border-radius: 0.5em;
11-
grid-template:
12-
"avatar author-link author-link" max-content
13-
"content content content" max-content
14-
"backlink backlink backlink" max-content
15-
/ min-content auto auto;
4+
@supports selector(:--loading) {
5+
:host(:not(:--loading)) {
6+
display: grid;
7+
max-inline-size: 36em;
8+
padding: 0.5em;
9+
gap: 0.5em;
10+
border: 0.0625em solid grey;
11+
border-radius: 0.5em;
12+
grid-template:
13+
"avatar author-link author-link" max-content
14+
"content content content" max-content
15+
"backlink backlink backlink" max-content
16+
/ min-content auto auto;
17+
}
18+
}
19+
20+
@supports not selector(:--loading) {
21+
:host(:not([internals-loading])) {
22+
display: grid;
23+
max-inline-size: 36em;
24+
padding: 0.5em;
25+
gap: 0.5em;
26+
border: 0.0625em solid grey;
27+
border-radius: 0.5em;
28+
grid-template:
29+
"avatar author-link author-link" max-content
30+
"content content content" max-content
31+
"backlink backlink backlink" max-content
32+
/ min-content auto auto;
33+
}
1634
}
1735
1836
[part="avatar"] {
@@ -94,7 +112,7 @@ class TootEmbedElement extends HTMLElement {
94112
connectedCallback(): void {
95113
this.#internals = this.attachInternals()
96114
this.#internals.role = 'article'
97-
this.#renderRoot = this.attachShadow({ mode: 'open' })
115+
this.#renderRoot = this.attachShadow({mode: 'open'})
98116
this.#renderRoot.adoptedStyleSheets.push(styles)
99117
if (this.querySelector('script[type="application/json"]')) {
100118
return this.#render(JSON.parse(this.querySelector('script[type="application/json"]').textContent))
@@ -111,7 +129,7 @@ class TootEmbedElement extends HTMLElement {
111129

112130
async load() {
113131
this.#internals.states.add('--loading')
114-
const { tootId } = this.#useParams();
132+
const {tootId} = this.#useParams()
115133
const apiURL = new URL(`/api/v1/statuses/${tootId}`, this.src)
116134
const response = await fetch(apiURL)
117135
console.log(response)
@@ -121,19 +139,17 @@ class TootEmbedElement extends HTMLElement {
121139
}
122140

123141
#render(json) {
124-
const { account, url, content } = json
142+
const {account, url, content} = json
125143
console.log(json)
126144
const handleURL = new URL(account.url)
127145
const {handle} = this.#useParams()
128146
this.#renderRoot.innerHTML = html`
129-
<img part="avatar" src="${account.avatar}" alt="">
147+
<img part="avatar" src="${account.avatar}" alt="" />
130148
<a part="author-link" href="${handleURL.href}">
131149
<span part="author-name">${account.display_name}</span>
132150
<span part="author-handle">@${handle}@${handleURL.hostname}</span>
133151
</a>
134-
<div part="content">
135-
${content}
136-
</div>
152+
<div part="content">${content}</div>
137153
<a part="backlink" href="${url}" rel="bookmark">Original Toot</a>
138154
`
139155
this.#internals.states.add('--ready')
@@ -143,16 +159,16 @@ class TootEmbedElement extends HTMLElement {
143159
// URLPattern only works in Chromium right now.
144160
// Could refactor this to use RegExp for compatibility
145161
/* @ts-ignore */
146-
#shortPattern = new URLPattern({ pathname: '/@:handle/:tootId(\\d+)' })
162+
#shortPattern = new URLPattern({pathname: '/@:handle/:tootId(\\d+)'})
147163
/* @ts-ignore */
148-
#longPattern = new URLPattern({ pathname: '/users/:handle/statuses/:tootId(\\d+)' })
164+
#longPattern = new URLPattern({pathname: '/users/:handle/statuses/:tootId(\\d+)'})
149165
// Toot URLs can have two different formats:
150166
// 1. https://indieweb.social/@keithamus/109524390152251545
151167
// 2. https://indieweb.social/users/keithamus/statuses/109524390152251545
152-
#useParams(): { [key: string]: string } {
153-
const groups = (this.#shortPattern.exec(this.src) ?? this.#longPattern.exec(this.src))?.pathname.groups;
154-
if (groups) return groups;
155-
throw `This doesn’t seem to be a toot URL: ${this.src}`;
168+
#useParams(): {[key: string]: string} {
169+
const groups = (this.#shortPattern.exec(this.src) ?? this.#longPattern.exec(this.src))?.pathname.groups
170+
if (groups) return groups
171+
throw `This doesn’t seem to be a toot URL: ${this.src}`
156172
}
157173
}
158174

0 commit comments

Comments
 (0)