@atmo-dev/kit 0.12.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/RichText.svelte +17 -1
- package/dist/components/RichText.svelte.d.ts +8 -0
- package/dist/components/SembleCollectionPicker.svelte +221 -0
- package/dist/components/SembleCollectionPicker.svelte.d.ts +14 -0
- package/dist/components/SembleCollectionView.svelte +153 -0
- package/dist/components/SembleCollectionView.svelte.d.ts +10 -0
- package/dist/events/EventComments.svelte +15 -2
- package/dist/events/EventView.svelte +77 -8
- package/dist/events/conference.d.ts +2 -0
- package/dist/events/editor/LinkedRecordsPicker.svelte +44 -3
- package/dist/events/editor/LinksSection.svelte +29 -9
- package/dist/events/event-view/EventLinkEmbed.svelte +49 -0
- package/dist/events/event-view/EventLinkEmbed.svelte.d.ts +14 -0
- package/dist/events/event-view/PostLinkEmbed.svelte +71 -0
- package/dist/events/event-view/PostLinkEmbed.svelte.d.ts +11 -0
- package/dist/events/event-view/ProfileLinkEmbed.svelte +67 -0
- package/dist/events/event-view/ProfileLinkEmbed.svelte.d.ts +11 -0
- package/dist/events/linked-records.d.ts +20 -0
- package/dist/events/linked-records.js +32 -2
- package/dist/events/schedule/ScheduleEventCell.svelte +3 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +5 -1
- package/dist/richtext/document.d.ts +9 -0
- package/dist/richtext/document.js +35 -0
- package/dist/richtext.d.ts +1 -1
- package/dist/richtext.js +1 -1
- package/dist/semble/types.d.ts +46 -0
- package/dist/semble/types.js +1 -0
- package/dist/semble/urls.d.ts +2 -0
- package/dist/semble/urls.js +43 -0
- package/dist/semble/xrpc.d.ts +3 -0
- package/dist/semble/xrpc.js +131 -0
- package/dist/semble.d.ts +3 -0
- package/dist/semble.js +2 -0
- package/dist/social/posts.d.ts +7 -0
- package/dist/social/posts.js +21 -0
- package/dist/social/urls.d.ts +10 -0
- package/dist/social/urls.js +43 -1
- package/dist/social.d.ts +3 -1
- package/dist/social.js +2 -1
- package/package.json +7 -2
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { isLinkedActor } from '../grain/urls.js';
|
|
2
|
+
export function parseSembleLink(input) {
|
|
3
|
+
try {
|
|
4
|
+
const raw = input.trim();
|
|
5
|
+
let actor;
|
|
6
|
+
let rkey;
|
|
7
|
+
if (raw.startsWith('at://')) {
|
|
8
|
+
const match = /^at:\/\/([^/]+)\/network\.cosmik\.collection\/([^/?#]+)$/.exec(raw);
|
|
9
|
+
if (!match)
|
|
10
|
+
return null;
|
|
11
|
+
[, actor, rkey] = match;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
const url = new URL(/^semble\.so\//i.test(raw) ? `https://${raw}` : raw);
|
|
15
|
+
if (!['https:', 'http:'].includes(url.protocol) ||
|
|
16
|
+
url.hostname !== 'semble.so' ||
|
|
17
|
+
url.username ||
|
|
18
|
+
url.password ||
|
|
19
|
+
url.port)
|
|
20
|
+
return null;
|
|
21
|
+
const match = /^\/profile\/([^/]+)\/collections\/([^/]+)\/?$/.exec(url.pathname);
|
|
22
|
+
if (!match)
|
|
23
|
+
return null;
|
|
24
|
+
actor = decodeURIComponent(match[1]);
|
|
25
|
+
rkey = decodeURIComponent(match[2]);
|
|
26
|
+
}
|
|
27
|
+
if (!isLinkedActor(actor) ||
|
|
28
|
+
!/^[A-Za-z0-9._~:-]{1,512}$/.test(rkey) ||
|
|
29
|
+
['.', '..'].includes(rkey))
|
|
30
|
+
return null;
|
|
31
|
+
if (!actor.startsWith('did:'))
|
|
32
|
+
actor = actor.toLowerCase();
|
|
33
|
+
return {
|
|
34
|
+
actor,
|
|
35
|
+
rkey,
|
|
36
|
+
atUri: `at://${actor}/network.cosmik.collection/${rkey}`,
|
|
37
|
+
url: `https://semble.so/profile/${actor.replaceAll('%', '%25')}/collections/${rkey}`
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { isLinkedActor } from '../grain/urls.js';
|
|
2
|
+
import { safeHttpUrl } from '../urls.js';
|
|
3
|
+
import { parseSembleLink } from './urls.js';
|
|
4
|
+
// Semble's API is deliberately isolated here; never proxy a user-supplied host.
|
|
5
|
+
const ORIGIN = 'https://api.semble.so';
|
|
6
|
+
const CARD_LIMIT = 50;
|
|
7
|
+
const LIST_LIMIT = 24;
|
|
8
|
+
function object(value) {
|
|
9
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
10
|
+
}
|
|
11
|
+
/** Page metadata is third-party text of any length. */
|
|
12
|
+
function text(value, max = 300) {
|
|
13
|
+
return typeof value === 'string' ? value.trim().slice(0, max) : '';
|
|
14
|
+
}
|
|
15
|
+
function image(value) {
|
|
16
|
+
const url = safeHttpUrl(text(value, 2048));
|
|
17
|
+
return url?.startsWith('https://') ? url : undefined;
|
|
18
|
+
}
|
|
19
|
+
function actor(value) {
|
|
20
|
+
const user = object(value);
|
|
21
|
+
const did = text(user.id);
|
|
22
|
+
if (!did.startsWith('did:') || !isLinkedActor(did))
|
|
23
|
+
return null;
|
|
24
|
+
return { did, handle: text(user.handle) || did, displayName: text(user.name, 100) || undefined };
|
|
25
|
+
}
|
|
26
|
+
function collection(value) {
|
|
27
|
+
const c = object(value);
|
|
28
|
+
const ref = parseSembleLink(text(c.uri, 1024));
|
|
29
|
+
const creator = actor(c.author);
|
|
30
|
+
if (!ref || !creator || ref.actor !== creator.did)
|
|
31
|
+
throw new Error('Invalid Semble collection');
|
|
32
|
+
return {
|
|
33
|
+
uri: ref.atUri,
|
|
34
|
+
url: ref.url,
|
|
35
|
+
name: text(c.name, 100) || 'Untitled collection',
|
|
36
|
+
description: text(c.description, 500) || undefined,
|
|
37
|
+
creator,
|
|
38
|
+
cardCount: typeof c.cardCount === 'number' && c.cardCount > 0 ? Math.floor(c.cardCount) : 0
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function card(value, creator) {
|
|
42
|
+
const c = object(value), content = object(c.cardContent);
|
|
43
|
+
const url = safeHttpUrl(text(c.url, 2048));
|
|
44
|
+
const id = text(c.uri, 1024) || text(c.id);
|
|
45
|
+
if (!url || !id)
|
|
46
|
+
return null;
|
|
47
|
+
const host = new URL(url).hostname.replace(/^www\./, '');
|
|
48
|
+
const addedBy = actor(c.author);
|
|
49
|
+
const title = text(content.title) || host;
|
|
50
|
+
const description = text(content.description, 500);
|
|
51
|
+
const preview = image(content.imageUrl);
|
|
52
|
+
return {
|
|
53
|
+
id,
|
|
54
|
+
url,
|
|
55
|
+
title,
|
|
56
|
+
site: text(content.siteName, 100) || host,
|
|
57
|
+
// Posts and similar pages repeat their text as both title and description.
|
|
58
|
+
description: description && !description.startsWith(title) ? description : undefined,
|
|
59
|
+
...(preview ? { image: preview } : {}),
|
|
60
|
+
note: text(object(c.note).text, 1000) || undefined,
|
|
61
|
+
...(addedBy && addedBy.did !== creator.did ? { addedBy } : {})
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Current Semble API implementation; not a configurable proxy or an app session. */
|
|
65
|
+
export function createSembleXrpcClient(fetchImpl = fetch) {
|
|
66
|
+
async function request(method, params) {
|
|
67
|
+
const url = new URL(`/xrpc/${method}`, ORIGIN);
|
|
68
|
+
url.search = new URLSearchParams(params).toString();
|
|
69
|
+
const response = await fetchImpl(url, {
|
|
70
|
+
headers: { accept: 'application/json' },
|
|
71
|
+
signal: AbortSignal.timeout(5000),
|
|
72
|
+
redirect: 'error'
|
|
73
|
+
});
|
|
74
|
+
if (!response.ok)
|
|
75
|
+
throw new Error(`Semble unavailable (${response.status})`);
|
|
76
|
+
return object(await response.json());
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
async getCollection(reference) {
|
|
80
|
+
const ref = parseSembleLink(reference);
|
|
81
|
+
if (!ref)
|
|
82
|
+
throw new Error('Invalid Semble reference');
|
|
83
|
+
const data = await request('network.cosmik.collection.getByAtUri', {
|
|
84
|
+
handle: ref.actor,
|
|
85
|
+
recordKey: ref.rkey,
|
|
86
|
+
limit: String(CARD_LIMIT)
|
|
87
|
+
});
|
|
88
|
+
const result = collection(data);
|
|
89
|
+
const canonical = parseSembleLink(result.uri);
|
|
90
|
+
if (canonical.rkey !== ref.rkey ||
|
|
91
|
+
(ref.actor.startsWith('did:') && canonical.actor !== ref.actor))
|
|
92
|
+
throw new Error('Mismatched Semble collection');
|
|
93
|
+
// The API can list a card twice; ids must be unique for keyed rendering.
|
|
94
|
+
const cards = new Map();
|
|
95
|
+
for (const value of (Array.isArray(data.urlCards) ? data.urlCards : []).slice(0, CARD_LIMIT)) {
|
|
96
|
+
const item = card(value, result.creator);
|
|
97
|
+
if (item && !cards.has(item.id))
|
|
98
|
+
cards.set(item.id, item);
|
|
99
|
+
}
|
|
100
|
+
return { ...result, cards: [...cards.values()] };
|
|
101
|
+
},
|
|
102
|
+
async listCollections(identifier, cursor) {
|
|
103
|
+
if (!isLinkedActor(identifier))
|
|
104
|
+
throw new Error('Invalid actor');
|
|
105
|
+
if (cursor !== undefined && !/^[1-9]\d{0,3}$/.test(cursor))
|
|
106
|
+
throw new Error('Invalid cursor');
|
|
107
|
+
const data = await request('network.cosmik.collection.listByUser', {
|
|
108
|
+
identifier,
|
|
109
|
+
limit: String(LIST_LIMIT),
|
|
110
|
+
page: cursor ?? '1'
|
|
111
|
+
});
|
|
112
|
+
if (!Array.isArray(data.collections))
|
|
113
|
+
throw new Error('Invalid Semble collections');
|
|
114
|
+
// One malformed entry must not hide the rest of the list.
|
|
115
|
+
const collections = data.collections.flatMap((value) => {
|
|
116
|
+
try {
|
|
117
|
+
const item = collection(value);
|
|
118
|
+
return !identifier.startsWith('did:') || item.creator.did === identifier ? [item] : [];
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
const pagination = object(data.pagination);
|
|
125
|
+
const next = pagination.hasMore === true && typeof pagination.currentPage === 'number'
|
|
126
|
+
? String(pagination.currentPage + 1)
|
|
127
|
+
: undefined;
|
|
128
|
+
return { collections, ...(next && next !== cursor ? { cursor: next } : {}) };
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
package/dist/semble.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { SembleClient, SembleCard, SembleCollection, SembleCollectionPage, SembleCollectionList, SembleReference, SembleSelection } from './semble/types.js';
|
|
2
|
+
export { parseSembleLink } from './semble/urls.js';
|
|
3
|
+
export { createSembleXrpcClient } from './semble/xrpc.js';
|
package/dist/semble.js
ADDED
package/dist/social/posts.d.ts
CHANGED
|
@@ -133,5 +133,12 @@ type BlueskyEmbedView = {
|
|
|
133
133
|
record?: RecordView;
|
|
134
134
|
media?: BlueskyEmbedView;
|
|
135
135
|
};
|
|
136
|
+
/**
|
|
137
|
+
* Whether an AppView view carries a moderation label anywhere: for a post, on the post, its
|
|
138
|
+
* author, or anything it embeds (a quoted post and its author, at any depth). Apps without the
|
|
139
|
+
* viewer's moderation preferences can use it to leave such content out. Pass a single post
|
|
140
|
+
* view, not a thread: a thread's replies would count too.
|
|
141
|
+
*/
|
|
142
|
+
export declare function hasModerationLabel(value: unknown, depth?: number): boolean;
|
|
136
143
|
export declare function blueskyPostToPostData(post: BlueskyPostView, depth?: number): PostData;
|
|
137
144
|
export {};
|
package/dist/social/posts.js
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import { isActorIdentifier, isRecordKey } from '@atcute/lexicons/syntax';
|
|
2
2
|
import { blueskyProfileUrl } from './urls.js';
|
|
3
|
+
/**
|
|
4
|
+
* Whether an AppView view carries a moderation label anywhere: for a post, on the post, its
|
|
5
|
+
* author, or anything it embeds (a quoted post and its author, at any depth). Apps without the
|
|
6
|
+
* viewer's moderation preferences can use it to leave such content out. Pass a single post
|
|
7
|
+
* view, not a thread: a thread's replies would count too.
|
|
8
|
+
*/
|
|
9
|
+
export function hasModerationLabel(value, depth = 0) {
|
|
10
|
+
if (!value || typeof value !== 'object')
|
|
11
|
+
return false;
|
|
12
|
+
// Deeper than any real view nests: treat as labeled rather than render it unchecked.
|
|
13
|
+
if (depth > 12)
|
|
14
|
+
return true;
|
|
15
|
+
if (Array.isArray(value))
|
|
16
|
+
return value.some((item) => hasModerationLabel(item, depth + 1));
|
|
17
|
+
const { labels } = value;
|
|
18
|
+
// Views list labels; records self-label with `{ values: [...] }`.
|
|
19
|
+
const list = Array.isArray(labels) ? labels : labels?.values;
|
|
20
|
+
if (Array.isArray(list) && list.some((label) => !label?.neg))
|
|
21
|
+
return true;
|
|
22
|
+
return Object.entries(value).some(([key, child]) => key !== 'labels' && hasModerationLabel(child, depth + 1));
|
|
23
|
+
}
|
|
3
24
|
/** Convert record-view variants without mistaking blocked authors or starter packs for posts. */
|
|
4
25
|
function recordEmbed(record, depth) {
|
|
5
26
|
const type = record.$type;
|
package/dist/social/urls.d.ts
CHANGED
|
@@ -7,3 +7,13 @@ export declare function socialProfileUrl(identifier: string, client?: PreferredS
|
|
|
7
7
|
export declare function socialHashtagUrl(tag: string, client?: PreferredSocialClient | null): string;
|
|
8
8
|
/** Open a feed-post AT URI in the viewer's preferred Bluesky-compatible client. */
|
|
9
9
|
export declare function socialPostUrl(uri: string, client?: PreferredSocialClient | null): string | null;
|
|
10
|
+
/** Recognize a post link on Bluesky or another listed client. Syntax only; the post may not exist. */
|
|
11
|
+
export declare function parseSocialPostUrl(value: string): {
|
|
12
|
+
actor: string;
|
|
13
|
+
rkey: string;
|
|
14
|
+
uri: string;
|
|
15
|
+
} | null;
|
|
16
|
+
/** Recognize a profile link on Bluesky or another listed client. Syntax only. */
|
|
17
|
+
export declare function parseSocialProfileUrl(value: string): {
|
|
18
|
+
actor: string;
|
|
19
|
+
} | null;
|
package/dist/social/urls.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isActorIdentifier, isDid, isRecordKey } from '@atcute/lexicons/syntax';
|
|
2
|
-
import { socialClientInfo } from './preferred-client.js';
|
|
2
|
+
import { socialClientInfo, socialClients } from './preferred-client.js';
|
|
3
3
|
/** Bluesky expects literal DIDs in its routes, including colons and did:web escapes. */
|
|
4
4
|
export function blueskyProfileUrl(identifier) {
|
|
5
5
|
return socialProfileUrl(identifier);
|
|
@@ -20,3 +20,45 @@ export function socialPostUrl(uri, client) {
|
|
|
20
20
|
return null;
|
|
21
21
|
return `${socialProfileUrl(match[1], client)}/post/${encodeURIComponent(match[2])}`;
|
|
22
22
|
}
|
|
23
|
+
const postHosts = new Set(socialClients.map(({ url }) => new URL(url).hostname));
|
|
24
|
+
/** The path of a link to one of the listed clients, e.g. `/profile/alice.example`. */
|
|
25
|
+
function clientPath(value) {
|
|
26
|
+
try {
|
|
27
|
+
const url = new URL(value);
|
|
28
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.port)
|
|
29
|
+
return null;
|
|
30
|
+
return postHosts.has(url.hostname) ? url.pathname : null;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Recognize a post link on Bluesky or another listed client. Syntax only; the post may not exist. */
|
|
37
|
+
export function parseSocialPostUrl(value) {
|
|
38
|
+
try {
|
|
39
|
+
const match = /^\/profile\/([^/]+)\/post\/([^/]+)\/?$/.exec(clientPath(value) ?? '');
|
|
40
|
+
if (!match)
|
|
41
|
+
return null;
|
|
42
|
+
const actor = decodeURIComponent(match[1]);
|
|
43
|
+
const rkey = decodeURIComponent(match[2]);
|
|
44
|
+
if (!isActorIdentifier(actor) || !isRecordKey(rkey))
|
|
45
|
+
return null;
|
|
46
|
+
return { actor, rkey, uri: `at://${actor}/app.bsky.feed.post/${rkey}` };
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Recognize a profile link on Bluesky or another listed client. Syntax only. */
|
|
53
|
+
export function parseSocialProfileUrl(value) {
|
|
54
|
+
try {
|
|
55
|
+
const match = /^\/profile\/([^/]+)\/?$/.exec(clientPath(value) ?? '');
|
|
56
|
+
if (!match)
|
|
57
|
+
return null;
|
|
58
|
+
const actor = decodeURIComponent(match[1]);
|
|
59
|
+
return isActorIdentifier(actor) ? { actor } : null;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
package/dist/social.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ export { PREFERRED_CLIENT_COLLECTION, PREFERRED_CLIENT_RKEY, PREFERRED_CLIENT_SC
|
|
|
2
2
|
export type { SocialClientId, PreferredSocialClient } from './social/preferred-client.js';
|
|
3
3
|
export { defaultExternalEmbedProviders, youtubeEmbedProvider, klipyEmbedProvider, resolveExternalEmbed } from './social/external-embeds.js';
|
|
4
4
|
export type { ExternalPostEmbed, ExternalEmbedProvider, ExternalEmbedPlayer } from './social/external-embeds.js';
|
|
5
|
-
export {
|
|
5
|
+
export { blueskyPostToPostData, hasModerationLabel } from './social/posts.js';
|
|
6
|
+
export type { PostData, PostEmbed, BlueskyPostView } from './social/posts.js';
|
|
7
|
+
export { blueskyProfileUrl, socialProfileUrl, socialPostUrl, socialHashtagUrl, parseSocialPostUrl, parseSocialProfileUrl } from './social/urls.js';
|
package/dist/social.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { PREFERRED_CLIENT_COLLECTION, PREFERRED_CLIENT_RKEY, PREFERRED_CLIENT_SCOPE, socialClients, normalizeSocialClientUrl, parsePreferredSocialClient, preferredSocialClientRecord, socialClientInfo } from './social/preferred-client.js';
|
|
2
2
|
export { defaultExternalEmbedProviders, youtubeEmbedProvider, klipyEmbedProvider, resolveExternalEmbed } from './social/external-embeds.js';
|
|
3
|
-
export {
|
|
3
|
+
export { blueskyPostToPostData, hasModerationLabel } from './social/posts.js';
|
|
4
|
+
export { blueskyProfileUrl, socialProfileUrl, socialPostUrl, socialHashtagUrl, parseSocialPostUrl, parseSocialProfileUrl } from './social/urls.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atmo-dev/kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "The shared UI foundation for Atmo apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -48,6 +48,10 @@
|
|
|
48
48
|
"types": "./dist/grain.d.ts",
|
|
49
49
|
"default": "./dist/grain.js"
|
|
50
50
|
},
|
|
51
|
+
"./semble": {
|
|
52
|
+
"types": "./dist/semble.d.ts",
|
|
53
|
+
"default": "./dist/semble.js"
|
|
54
|
+
},
|
|
51
55
|
"./streamplace": {
|
|
52
56
|
"types": "./dist/streamplace.d.ts",
|
|
53
57
|
"default": "./dist/streamplace.js"
|
|
@@ -175,7 +179,8 @@
|
|
|
175
179
|
"test": "pnpm test:unit --run && pnpm test:e2e && pnpm test:package",
|
|
176
180
|
"test:ci": "pnpm test:unit --run --no-file-parallelism && pnpm test:e2e && pnpm test:package",
|
|
177
181
|
"test:e2e": "playwright test",
|
|
178
|
-
"test:package": "pnpm prepack &&
|
|
182
|
+
"test:package": "pnpm prepack && pnpm test:package:built",
|
|
183
|
+
"test:package:built": "node --test scripts/test-*-package.mjs",
|
|
179
184
|
"changeset": "changeset",
|
|
180
185
|
"version-packages": "changeset version && pnpm install --lockfile-only --no-frozen-lockfile --ignore-scripts",
|
|
181
186
|
"release": "pnpm prepack && changeset publish"
|