anhedral 0.15.0 → 0.16.0
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/README.md +29 -38
- package/assets/stack/ai-schema.ts.txt +5 -0
- package/assets/stack/ai.ts.txt +30 -0
- package/assets/stack/api-index.ts.txt +15 -0
- package/assets/stack/auth-features.ts.txt +4 -0
- package/assets/stack/auth-journal.json.txt +13 -0
- package/assets/stack/auth-migration.sql.txt +53 -0
- package/assets/stack/auth-routes.ts.txt +11 -0
- package/assets/stack/auth-schema.ts.txt +64 -0
- package/assets/stack/auth-snapshot.json.txt +346 -0
- package/assets/stack/auth.ts.txt +32 -0
- package/assets/stack/billing-mode.ts.txt +8 -0
- package/assets/stack/billing-schema.ts.txt +11 -0
- package/assets/stack/desktop.rs.txt +21 -0
- package/assets/stack/entitlement-guard.ts.txt +32 -0
- package/assets/stack/entitlements.ts.txt +8 -0
- package/assets/stack/events-schema.ts.txt +12 -0
- package/assets/stack/events.ts.txt +59 -0
- package/assets/stack/mobile-auth.ts.txt +25 -0
- package/assets/stack/mobile-billing.tsx.txt +63 -0
- package/assets/stack/mobile-session.tsx.txt +83 -0
- package/assets/stack/native-button.tsx.txt +108 -0
- package/assets/stack/native-global.css.txt +4 -0
- package/assets/stack/native-lib-utils.ts.txt +5 -0
- package/assets/stack/native-metro.config.js.txt +6 -0
- package/assets/stack/native-nativewind-env.d.ts.txt +1 -0
- package/assets/stack/native-tailwind.config.js.txt +73 -0
- package/assets/stack/native-text.tsx.txt +89 -0
- package/assets/stack/purchases.ts.txt +65 -0
- package/assets/stack/revenuecat.ts.txt +88 -0
- package/assets/stack/rtc-schema.ts.txt +10 -0
- package/assets/stack/rtc.ts.txt +122 -0
- package/assets/stack/security.ts.txt +31 -0
- package/assets/stack/storage.ts.txt +36 -0
- package/assets/stack/stripe.ts.txt +126 -0
- package/assets/stack/web-sign-in.tsx.txt +51 -0
- package/assets/ui/LICENSE.react-native-reusables +21 -0
- package/assets/ui/UPSTREAM.json +7 -1
- package/assets/ui/catalog.json +891 -0
- package/assets/ui/extensions/registry.json +6 -0
- package/assets/ui/native/_controls.tsx +521 -0
- package/assets/ui/native/_core.tsx +118 -0
- package/assets/ui/native/_data.tsx +200 -0
- package/assets/ui/native/_display.tsx +453 -0
- package/assets/ui/native/_feedback.tsx +242 -0
- package/assets/ui/native/_legacy-dialog.tsx +38 -0
- package/assets/ui/native/_motion.tsx +520 -0
- package/assets/ui/native/_overlay.tsx +402 -0
- package/assets/ui/native/_selection.tsx +366 -0
- package/assets/ui/native/accordion.tsx +1 -0
- package/assets/ui/native/alert-dialog.tsx +11 -0
- package/assets/ui/native/alert.tsx +1 -0
- package/assets/ui/native/aspect-ratio.tsx +1 -0
- package/assets/ui/native/attachment.tsx +8 -0
- package/assets/ui/native/avatar.tsx +8 -0
- package/assets/ui/native/badge.tsx +1 -0
- package/assets/ui/native/breadcrumb.tsx +9 -0
- package/assets/ui/native/bubble.tsx +1 -0
- package/assets/ui/native/button-group.tsx +1 -0
- package/assets/ui/native/button.tsx +2 -1
- package/assets/ui/native/calendar.tsx +170 -0
- package/assets/ui/native/card.tsx +16 -5
- package/assets/ui/native/carousel.tsx +1 -0
- package/assets/ui/native/chart.tsx +193 -0
- package/assets/ui/native/checkbox.tsx +1 -0
- package/assets/ui/native/code-block.tsx +137 -0
- package/assets/ui/native/collapsible.tsx +1 -0
- package/assets/ui/native/combobox.tsx +1 -0
- package/assets/ui/native/command.tsx +11 -0
- package/assets/ui/native/context-menu.tsx +16 -0
- package/assets/ui/native/data-table.tsx +1 -0
- package/assets/ui/native/date-picker.tsx +43 -0
- package/assets/ui/native/dialog.tsx +14 -74
- package/assets/ui/native/direction.tsx +1 -0
- package/assets/ui/native/drawer.tsx +10 -0
- package/assets/ui/native/dropdown-menu.tsx +16 -0
- package/assets/ui/native/empty.tsx +8 -0
- package/assets/ui/native/field.tsx +13 -0
- package/assets/ui/native/hover-card.tsx +1 -0
- package/assets/ui/native/input-group.tsx +8 -0
- package/assets/ui/native/input-otp.tsx +1 -0
- package/assets/ui/native/input.tsx +2 -1
- package/assets/ui/native/item.tsx +12 -0
- package/assets/ui/native/kbd.tsx +1 -0
- package/assets/ui/native/marker.tsx +1 -0
- package/assets/ui/native/menubar.tsx +17 -0
- package/assets/ui/native/message-scroller.tsx +6 -0
- package/assets/ui/native/message.tsx +10 -0
- package/assets/ui/native/native-select.tsx +1 -0
- package/assets/ui/native/navigation-menu.tsx +10 -0
- package/assets/ui/native/pagination.tsx +9 -0
- package/assets/ui/native/popover.tsx +1 -0
- package/assets/ui/native/progress.tsx +1 -0
- package/assets/ui/native/questionnaire.tsx +130 -0
- package/assets/ui/native/radio-group.tsx +1 -0
- package/assets/ui/native/registry.json +1103 -0
- package/assets/ui/native/resizable.tsx +1 -0
- package/assets/ui/native/scroll-area.tsx +1 -0
- package/assets/ui/native/select.tsx +11 -0
- package/assets/ui/native/separator.tsx +1 -0
- package/assets/ui/native/sheet.tsx +10 -0
- package/assets/ui/native/sidebar.tsx +22 -0
- package/assets/ui/native/skeleton.tsx +1 -0
- package/assets/ui/native/slider.tsx +1 -0
- package/assets/ui/native/spinner.tsx +1 -0
- package/assets/ui/native/switch.tsx +1 -0
- package/assets/ui/native/table.tsx +10 -0
- package/assets/ui/native/tabs.tsx +1 -0
- package/assets/ui/native/textarea.tsx +1 -0
- package/assets/ui/native/toast.tsx +11 -0
- package/assets/ui/native/toggle-group.tsx +1 -0
- package/assets/ui/native/toggle.tsx +1 -0
- package/assets/ui/native/tooltip.tsx +1 -0
- package/assets/ui/native/trace.tsx +20 -0
- package/assets/ui/native/typography.tsx +15 -0
- package/dist/bin.js +7 -12
- package/dist/capabilities.d.ts +4 -33
- package/dist/capabilities.js +2 -66
- package/dist/capability-catalog.d.ts +83 -0
- package/dist/capability-catalog.js +121 -0
- package/dist/capability-command.d.ts +3 -0
- package/dist/capability-command.js +188 -0
- package/dist/capability-editor.d.ts +17 -0
- package/dist/capability-editor.js +97 -0
- package/dist/capability-recipes.d.ts +4 -0
- package/dist/capability-recipes.js +520 -0
- package/dist/capability-references.d.ts +4 -0
- package/dist/capability-references.js +7 -0
- package/dist/cli-commands.d.ts +1 -2
- package/dist/cli-commands.js +10 -104
- package/dist/cli-output.d.ts +1 -2
- package/dist/cli-output.js +6 -251
- package/dist/command-schema.js +39 -322
- package/dist/dependencies.d.ts +29 -6
- package/dist/dependencies.js +61 -14
- package/dist/index.d.ts +1 -42
- package/dist/index.js +1 -27
- package/dist/platforms/mobile.js +1 -20
- package/dist/platforms/web.d.ts +1 -1
- package/dist/platforms/web.js +27 -75
- package/dist/project-config.d.ts +2 -13
- package/dist/project-config.js +10 -82
- package/dist/registry/options.js +1 -5
- package/dist/registry/resolve.d.ts +1 -1
- package/dist/registry/resolve.js +2 -10
- package/dist/registry/usage.js +3 -9
- package/dist/scaffold/backend.js +0 -3
- package/dist/scaffold/database.js +2 -1
- package/dist/scaffold/documentation.js +82 -20
- package/dist/scaffold/expo-runtime.js +3 -4
- package/dist/scaffold/native-ui.js +12 -7
- package/dist/scaffold/stack-documentation.js +1 -1
- package/dist/scaffold/storage.d.ts +2 -0
- package/dist/scaffold/storage.js +21 -0
- package/dist/scaffold/workspace.js +26 -21
- package/dist/stack-registry.d.ts +2 -8
- package/dist/stack-registry.js +11 -87
- package/dist/standard.js +1 -11
- package/dist/ui-catalog.d.ts +26 -0
- package/dist/ui-catalog.js +31 -0
- package/dist/ui-command.d.ts +3 -0
- package/dist/ui-command.js +219 -0
- package/dist/ui-project.d.ts +22 -0
- package/dist/ui-project.js +110 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/anhedral-stack.md +4 -20
- package/docs/capabilities.md +110 -0
- package/docs/native-ui.md +102 -0
- package/docs/software-factory.md +16 -44
- package/docs/stack-standard.md +11 -60
- package/docs/ui.md +33 -0
- package/docs/verification.md +191 -0
- package/package.json +19 -18
- package/dist/access.d.ts +0 -10
- package/dist/access.js +0 -93
- package/dist/auth-schema-snapshot.d.ts +0 -346
- package/dist/auth-schema-snapshot.js +0 -347
- package/dist/auth-schema.d.ts +0 -1
- package/dist/auth-schema.js +0 -57
- package/dist/capability-contract.d.ts +0 -47
- package/dist/capability-contract.js +0 -129
- package/dist/catalog-model.d.ts +0 -24
- package/dist/catalog-model.js +0 -1
- package/dist/catalog-registration.d.ts +0 -16
- package/dist/catalog-registration.js +0 -22
- package/dist/catalog-snapshot.d.ts +0 -5
- package/dist/catalog-snapshot.js +0 -97
- package/dist/cli-delivery.d.ts +0 -3
- package/dist/cli-delivery.js +0 -112
- package/dist/cloudflare.d.ts +0 -25
- package/dist/cloudflare.js +0 -226
- package/dist/delivery-evidence.d.ts +0 -62
- package/dist/delivery-evidence.js +0 -157
- package/dist/delivery.d.ts +0 -82
- package/dist/delivery.js +0 -489
- package/dist/inspector-model.d.ts +0 -123
- package/dist/inspector-model.js +0 -1
- package/dist/integration-service-readers.d.ts +0 -12
- package/dist/integration-service-readers.js +0 -92
- package/dist/lifecycle-model.d.ts +0 -15
- package/dist/lifecycle-model.js +0 -20
- package/dist/lifecycle.d.ts +0 -11
- package/dist/lifecycle.js +0 -91
- package/dist/management.d.ts +0 -3
- package/dist/management.js +0 -47
- package/dist/mobile-delivery.d.ts +0 -77
- package/dist/mobile-delivery.js +0 -370
- package/dist/project-catalog.d.ts +0 -41
- package/dist/project-catalog.js +0 -288
- package/dist/project-inspector.d.ts +0 -4
- package/dist/project-inspector.js +0 -671
- package/dist/project-lifecycle.d.ts +0 -25
- package/dist/project-lifecycle.js +0 -57
- package/dist/project-state.d.ts +0 -47
- package/dist/project-state.js +0 -480
- package/dist/provider-auth.d.ts +0 -41
- package/dist/provider-auth.js +0 -180
- package/dist/provider-readiness.d.ts +0 -30
- package/dist/provider-readiness.js +0 -85
- package/dist/providers/adapters.d.ts +0 -17
- package/dist/providers/adapters.js +0 -103
- package/dist/providers/api.d.ts +0 -29
- package/dist/providers/api.js +0 -253
- package/dist/providers/config.d.ts +0 -15
- package/dist/providers/config.js +0 -136
- package/dist/providers/definitions.d.ts +0 -115
- package/dist/providers/definitions.js +0 -42
- package/dist/providers/provision.d.ts +0 -24
- package/dist/providers/provision.js +0 -76
- package/dist/providers/receipts.d.ts +0 -20
- package/dist/providers/receipts.js +0 -56
- package/dist/providers/recovery-verification.d.ts +0 -7
- package/dist/providers/recovery-verification.js +0 -52
- package/dist/providers/recovery.d.ts +0 -30
- package/dist/providers/recovery.js +0 -34
- package/dist/providers/runtime.d.ts +0 -10
- package/dist/providers/runtime.js +0 -234
- package/dist/providers/schema.d.ts +0 -28
- package/dist/providers/schema.js +0 -49
- package/dist/providers/state.d.ts +0 -55
- package/dist/providers/state.js +0 -283
- package/dist/provision.d.ts +0 -47
- package/dist/provision.js +0 -208
- package/dist/r2-service-data.d.ts +0 -2
- package/dist/r2-service-data.js +0 -136
- package/dist/readiness.d.ts +0 -23
- package/dist/readiness.js +0 -117
- package/dist/registry/add.d.ts +0 -24
- package/dist/registry/add.js +0 -210
- package/dist/registry/bootstrap.d.ts +0 -3
- package/dist/registry/bootstrap.js +0 -5
- package/dist/registry/commands.d.ts +0 -3
- package/dist/registry/commands.js +0 -83
- package/dist/registry/preview.d.ts +0 -11
- package/dist/registry/preview.js +0 -91
- package/dist/registry/receipt.d.ts +0 -3
- package/dist/registry/receipt.js +0 -68
- package/dist/repository.d.ts +0 -24
- package/dist/repository.js +0 -96
- package/dist/scaffold/auth.d.ts +0 -2
- package/dist/scaffold/auth.js +0 -76
- package/dist/scaffold/billing-config.d.ts +0 -1
- package/dist/scaffold/billing-config.js +0 -73
- package/dist/scaffold/billing-contracts.d.ts +0 -2
- package/dist/scaffold/billing-contracts.js +0 -48
- package/dist/scaffold/billing-providers.d.ts +0 -1
- package/dist/scaffold/billing-providers.js +0 -249
- package/dist/scaffold/billing-schema.d.ts +0 -1
- package/dist/scaffold/billing-schema.js +0 -34
- package/dist/scaffold/billing-security.d.ts +0 -1
- package/dist/scaffold/billing-security.js +0 -46
- package/dist/scaffold/billing-server.d.ts +0 -1
- package/dist/scaffold/billing-server.js +0 -139
- package/dist/scaffold/billing-store.d.ts +0 -1
- package/dist/scaffold/billing-store.js +0 -72
- package/dist/scaffold/billing.d.ts +0 -2
- package/dist/scaffold/billing.js +0 -208
- package/dist/scaffold/expo-auth.d.ts +0 -3
- package/dist/scaffold/expo-auth.js +0 -203
- package/dist/scaffold/expo-billing.d.ts +0 -3
- package/dist/scaffold/expo-billing.js +0 -257
- package/dist/scaffold/integrations.d.ts +0 -2
- package/dist/scaffold/integrations.js +0 -11
- package/dist/scaffold/managed-email.d.ts +0 -3
- package/dist/scaffold/managed-email.js +0 -47
- package/dist/scaffold/password-reset.d.ts +0 -1
- package/dist/scaffold/password-reset.js +0 -99
- package/dist/scaffold/private-files.d.ts +0 -2
- package/dist/scaffold/private-files.js +0 -78
- package/dist/scaffold/web-billing.d.ts +0 -2
- package/dist/scaffold/web-billing.js +0 -48
- package/dist/service-deletion.d.ts +0 -29
- package/dist/service-deletion.js +0 -195
- package/dist/service-descriptor.d.ts +0 -10
- package/dist/service-descriptor.js +0 -71
- package/dist/service-model.d.ts +0 -49
- package/dist/service-model.js +0 -8
- package/dist/service-operations.d.ts +0 -29
- package/dist/service-operations.js +0 -48
- package/dist/service-readers.d.ts +0 -8
- package/dist/service-readers.js +0 -216
- package/dist/services-command.d.ts +0 -39
- package/dist/services-command.js +0 -96
- package/dist/ship.d.ts +0 -35
- package/dist/ship.js +0 -107
- package/docs/assets/anhedral-stack-light.png +0 -0
- package/docs/assets/anhedral-stack.png +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { betterAuth } from 'better-auth/minimal';
|
|
3
|
+
import { drizzleAdapter } from '@better-auth/drizzle-adapter';
|
|
4
|
+
import { platformAuthPlugins } from './auth-platform';
|
|
5
|
+
import { bearer } from 'better-auth/plugins/bearer';
|
|
6
|
+
import { createDatabase } from '@workspace/db';
|
|
7
|
+
import * as schema from '@workspace/db/schema';
|
|
8
|
+
import { authFeatures } from './auth-features';
|
|
9
|
+
import type { AppEnv } from './environment';
|
|
10
|
+
|
|
11
|
+
export const authConfiguration = z.object({
|
|
12
|
+
PUBLIC_APP_URL: z.url().regex(/^https?:\/\//),
|
|
13
|
+
BETTER_AUTH_SECRET: z.string().min(32),
|
|
14
|
+
});
|
|
15
|
+
export function createAuth(env: AppEnv['Bindings']) {
|
|
16
|
+
const configuration = authConfiguration.parse(env);
|
|
17
|
+
const origin = new URL(configuration.PUBLIC_APP_URL).origin;
|
|
18
|
+
return betterAuth({
|
|
19
|
+
secret: configuration.BETTER_AUTH_SECRET,
|
|
20
|
+
baseURL: origin,
|
|
21
|
+
basePath: '/api/auth',
|
|
22
|
+
database: drizzleAdapter(createDatabase(env.DB), { provider: 'sqlite', schema }),
|
|
23
|
+
emailAndPassword: { enabled: authFeatures.emailPassword },
|
|
24
|
+
trustedOrigins: [
|
|
25
|
+
origin,
|
|
26
|
+
...(env.AUTH_TRUSTED_ORIGINS?.split(',')
|
|
27
|
+
.map((v) => v.trim())
|
|
28
|
+
.filter(Boolean) ?? []),
|
|
29
|
+
],
|
|
30
|
+
plugins: [bearer(), ...platformAuthPlugins()],
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { AppEnv } from './environment';
|
|
3
|
+
const environment = z.enum(['sandbox', 'live']);
|
|
4
|
+
export function billingEnvironment(env: AppEnv['Bindings']) {
|
|
5
|
+
return environment.parse(env.BILLING_ENVIRONMENT || 'sandbox');
|
|
6
|
+
}
|
|
7
|
+
// The CLI never sets live mode or credentials. Operators choose the environment
|
|
8
|
+
// explicitly, configure matching provider scope and validate it before rollout.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { sqliteTable, text, integer, primaryKey } from 'drizzle-orm/sqlite-core';
|
|
2
|
+
// Durable receipts deduplicate delivery; they are not proof of an entitlement.
|
|
3
|
+
export const billingReceipt = sqliteTable(
|
|
4
|
+
'billing_receipt',
|
|
5
|
+
{
|
|
6
|
+
provider: text('provider').notNull(),
|
|
7
|
+
eventId: text('event_id').notNull(),
|
|
8
|
+
receivedAt: integer('received_at').notNull(),
|
|
9
|
+
},
|
|
10
|
+
(t) => [primaryKey({ columns: [t.provider, t.eventId] })],
|
|
11
|
+
);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
use gpui::{App, Application, Context, Window, WindowOptions, div, prelude::*};
|
|
2
|
+
|
|
3
|
+
struct Desktop;
|
|
4
|
+
impl Render for Desktop {
|
|
5
|
+
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
|
6
|
+
div()
|
|
7
|
+
.flex()
|
|
8
|
+
.flex_col()
|
|
9
|
+
.p_8()
|
|
10
|
+
.gap_4()
|
|
11
|
+
.child("Your native application")
|
|
12
|
+
.child("Configure an authenticated backend client for your product.")
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
fn main() {
|
|
16
|
+
Application::new().run(|cx: &mut App| {
|
|
17
|
+
cx.open_window(WindowOptions::default(), |_, cx| cx.new(|_| Desktop))
|
|
18
|
+
.expect("Open application window");
|
|
19
|
+
cx.activate(true);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type MiddlewareHandler } from 'hono';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { billingProviders } from './billing-providers';
|
|
4
|
+
import type { AppEnv } from './environment';
|
|
5
|
+
const policy = z.enum(['stripe', 'revenuecat', 'either']);
|
|
6
|
+
function selectedProviders(env: AppEnv['Bindings']) {
|
|
7
|
+
const selected = policy.parse(env.BILLING_PROVIDER);
|
|
8
|
+
return selected === 'either' ? Object.keys(billingProviders) : [selected];
|
|
9
|
+
}
|
|
10
|
+
async function providerEntitlement(name: string, env: AppEnv['Bindings'], subject: string) {
|
|
11
|
+
const resolve = billingProviders[name];
|
|
12
|
+
if (!resolve) throw Error('Selected billing provider is not installed');
|
|
13
|
+
return resolve(env, subject);
|
|
14
|
+
}
|
|
15
|
+
async function entitled(env: AppEnv['Bindings'], subject: string) {
|
|
16
|
+
const checks = await Promise.all(
|
|
17
|
+
selectedProviders(env).map((name) => providerEntitlement(name, env, subject).catch(() => null)),
|
|
18
|
+
);
|
|
19
|
+
if (checks.includes(true)) return true;
|
|
20
|
+
if (checks.includes(null)) throw Error('Billing provider unavailable');
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
export const requireEntitlement: MiddlewareHandler<AppEnv> = async (c, next) => {
|
|
24
|
+
if (!c.get('userId')) return c.json({ error: 'Unauthorized' }, 401);
|
|
25
|
+
try {
|
|
26
|
+
if (!(await entitled(c.env, c.get('userId'))))
|
|
27
|
+
return c.json({ error: 'Subscription required' }, 403);
|
|
28
|
+
} catch {
|
|
29
|
+
return c.json({ error: 'Billing needs configuration or is temporarily unavailable' }, 503);
|
|
30
|
+
}
|
|
31
|
+
await next();
|
|
32
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { requireSession } from '../security';
|
|
3
|
+
import { requireEntitlement } from '../entitlement-guard';
|
|
4
|
+
import type { AppEnv } from '../environment';
|
|
5
|
+
export const entitlementRoutes = new Hono<AppEnv>();
|
|
6
|
+
entitlementRoutes.get('/billing/access', requireSession, requireEntitlement, (c) =>
|
|
7
|
+
c.json({ allowed: true }),
|
|
8
|
+
);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { sqliteTable, text, integer, index } from 'drizzle-orm/sqlite-core';
|
|
2
|
+
export const applicationEvent = sqliteTable(
|
|
3
|
+
'application_event',
|
|
4
|
+
{
|
|
5
|
+
id: text('id').primaryKey(),
|
|
6
|
+
userId: text('user_id').notNull(),
|
|
7
|
+
topic: text('topic').notNull(),
|
|
8
|
+
data: text('data').notNull(),
|
|
9
|
+
createdAt: integer('created_at').notNull(),
|
|
10
|
+
},
|
|
11
|
+
(t) => [index('application_event_user_time').on(t.userId, t.createdAt)],
|
|
12
|
+
);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { streamSSE } from 'hono/streaming';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { requireSession } from '../security';
|
|
5
|
+
import type { AppEnv } from '../environment';
|
|
6
|
+
export const eventRoutes = new Hono<AppEnv>();
|
|
7
|
+
const input = z.object({
|
|
8
|
+
topic: z.string().regex(/^[a-zA-Z0-9._-]{1,80}$/),
|
|
9
|
+
data: z.unknown().optional(),
|
|
10
|
+
});
|
|
11
|
+
function eventCursor(header: string | undefined) {
|
|
12
|
+
if (!header) return { since: Date.now(), afterId: '' };
|
|
13
|
+
const match = /^(\d+):([a-f0-9-]{36})$/.exec(header);
|
|
14
|
+
if (!match) return null;
|
|
15
|
+
const since = Number(match[1]);
|
|
16
|
+
if (!Number.isSafeInteger(since)) return null;
|
|
17
|
+
return { since, afterId: match[2] };
|
|
18
|
+
}
|
|
19
|
+
eventRoutes.use('/events', requireSession);
|
|
20
|
+
eventRoutes.post('/events', async (c) => {
|
|
21
|
+
const body = input.safeParse(await c.req.json().catch(() => null));
|
|
22
|
+
if (!body.success) return c.json({ error: 'Invalid event' }, 400);
|
|
23
|
+
const data = JSON.stringify(body.data.data ?? null);
|
|
24
|
+
if (new TextEncoder().encode(data).byteLength > 8192)
|
|
25
|
+
return c.json({ error: 'Event too large' }, 413);
|
|
26
|
+
const id = crypto.randomUUID();
|
|
27
|
+
// Allocate a strictly increasing owner cursor atomically, including equal-ms writes.
|
|
28
|
+
await c.env.DB.prepare(
|
|
29
|
+
'INSERT INTO application_event(id,user_id,topic,data,created_at) SELECT ?,?,?,?,MAX(?,COALESCE((SELECT MAX(created_at)+1 FROM application_event WHERE user_id=?),0))',
|
|
30
|
+
)
|
|
31
|
+
.bind(id, c.get('userId'), body.data.topic, data, Date.now(), c.get('userId'))
|
|
32
|
+
.run();
|
|
33
|
+
return c.json({ id }, 201);
|
|
34
|
+
});
|
|
35
|
+
eventRoutes.get('/events', (c) => {
|
|
36
|
+
const userId = c.get('userId');
|
|
37
|
+
const cursor = eventCursor(c.req.header('last-event-id'));
|
|
38
|
+
if (!cursor) return c.json({ error: 'Invalid event cursor' }, 400);
|
|
39
|
+
return streamSSE(c, async (stream) => {
|
|
40
|
+
for (let tick = 0; tick < 30 && !stream.aborted; tick++) {
|
|
41
|
+
const rows = await c.env.DB.prepare(
|
|
42
|
+
'SELECT id,topic,data,created_at FROM application_event WHERE user_id = ? AND (created_at > ? OR (created_at = ? AND id > ?)) ORDER BY created_at,id LIMIT 100',
|
|
43
|
+
)
|
|
44
|
+
.bind(userId, cursor.since, cursor.since, cursor.afterId)
|
|
45
|
+
.all<{ id: string; topic: string; data: string; created_at: number }>();
|
|
46
|
+
for (const row of rows.results) {
|
|
47
|
+
await stream.writeSSE({
|
|
48
|
+
id: row.created_at + ':' + row.id,
|
|
49
|
+
event: row.topic,
|
|
50
|
+
data: row.data,
|
|
51
|
+
});
|
|
52
|
+
cursor.since = row.created_at;
|
|
53
|
+
cursor.afterId = row.id;
|
|
54
|
+
}
|
|
55
|
+
await stream.writeSSE({ event: 'heartbeat', data: '{}' });
|
|
56
|
+
await stream.sleep(1000);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createAuthClient } from 'better-auth/react';
|
|
2
|
+
import { expoClient } from '@better-auth/expo/client';
|
|
3
|
+
import * as SecureStore from 'expo-secure-store';
|
|
4
|
+
const configured = process.env.EXPO_PUBLIC_API_URL;
|
|
5
|
+
const baseURL = configured || 'http://127.0.0.1:8787';
|
|
6
|
+
if (configured && !__DEV__ && !configured.startsWith('https://'))
|
|
7
|
+
throw Error('Production API connections require HTTPS');
|
|
8
|
+
export const authClient = createAuthClient({
|
|
9
|
+
baseURL,
|
|
10
|
+
plugins: [expoClient({ scheme: __SCHEME__, storagePrefix: __SCHEME__, storage: SecureStore })],
|
|
11
|
+
});
|
|
12
|
+
export async function apiRequest(route: string, init: RequestInit = {}) {
|
|
13
|
+
if (!/^\/[a-zA-Z0-9/_?=&%.-]*$/.test(route)) throw Error('Choose an application API path');
|
|
14
|
+
const headers = new Headers(init.headers);
|
|
15
|
+
headers.delete('authorization');
|
|
16
|
+
headers.delete('origin');
|
|
17
|
+
const cookie = await authClient.getCookie();
|
|
18
|
+
if (cookie) headers.set('cookie', cookie);
|
|
19
|
+
headers.set('expo-origin', __SCHEME__ + '://');
|
|
20
|
+
return fetch(baseURL.replace(/\/$/, '') + '/api' + route, {
|
|
21
|
+
...init,
|
|
22
|
+
headers,
|
|
23
|
+
redirect: 'error',
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { View, Text } from 'react-native';
|
|
3
|
+
import { type PurchasesPackage } from 'react-native-purchases';
|
|
4
|
+
import {
|
|
5
|
+
connectPurchases,
|
|
6
|
+
purchase,
|
|
7
|
+
restorePurchases,
|
|
8
|
+
manageSubscriptions,
|
|
9
|
+
} from '../lib/purchases';
|
|
10
|
+
import { ActionButton } from './action-button';
|
|
11
|
+
export function BillingControls() {
|
|
12
|
+
const [packages, setPackages] = useState<PurchasesPackage[]>([]);
|
|
13
|
+
const [message, setMessage] = useState('');
|
|
14
|
+
const [busy, setBusy] = useState(false);
|
|
15
|
+
async function action(work: () => Promise<unknown>) {
|
|
16
|
+
setBusy(true);
|
|
17
|
+
try {
|
|
18
|
+
await work();
|
|
19
|
+
setMessage('Subscription updated.');
|
|
20
|
+
} catch {
|
|
21
|
+
setMessage('Purchase service is unavailable or the action was cancelled.');
|
|
22
|
+
} finally {
|
|
23
|
+
setBusy(false);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return (
|
|
27
|
+
<View style={{ padding: 16, gap: 8 }}>
|
|
28
|
+
<ActionButton
|
|
29
|
+
label="View subscriptions"
|
|
30
|
+
disabled={busy}
|
|
31
|
+
onPress={() =>
|
|
32
|
+
void action(async () => {
|
|
33
|
+
const offerings = await connectPurchases();
|
|
34
|
+
setPackages(
|
|
35
|
+
(offerings.current?.availablePackages ?? []).filter(
|
|
36
|
+
(value) => value.product.subscriptionPeriod !== null,
|
|
37
|
+
),
|
|
38
|
+
);
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
/>
|
|
42
|
+
{packages.map((value) => (
|
|
43
|
+
<ActionButton
|
|
44
|
+
key={value.identifier}
|
|
45
|
+
label={value.product.title + ' ' + value.product.priceString}
|
|
46
|
+
disabled={busy}
|
|
47
|
+
onPress={() => void action(() => purchase(value))}
|
|
48
|
+
/>
|
|
49
|
+
))}
|
|
50
|
+
<ActionButton
|
|
51
|
+
label="Restore purchases"
|
|
52
|
+
disabled={busy}
|
|
53
|
+
onPress={() => void action(restorePurchases)}
|
|
54
|
+
/>
|
|
55
|
+
<ActionButton
|
|
56
|
+
label="Manage subscriptions"
|
|
57
|
+
disabled={busy}
|
|
58
|
+
onPress={() => void action(manageSubscriptions)}
|
|
59
|
+
/>
|
|
60
|
+
<Text accessibilityLiveRegion="polite">{message}</Text>
|
|
61
|
+
</View>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { useState, type ReactNode } from 'react';
|
|
2
|
+
import { View, Text, TextInput } from 'react-native';
|
|
3
|
+
import { authClient, apiRequest } from '../lib/auth-client';
|
|
4
|
+
import { ActionButton } from './action-button';
|
|
5
|
+
|
|
6
|
+
export function SessionControls({
|
|
7
|
+
children,
|
|
8
|
+
onSignOut,
|
|
9
|
+
}: {
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
onSignOut?: () => Promise<void>;
|
|
12
|
+
}) {
|
|
13
|
+
if (!process.env.EXPO_PUBLIC_API_URL) return <Text>Connection setup is required.</Text>;
|
|
14
|
+
return <ConfiguredSessionControls onSignOut={onSignOut}>{children}</ConfiguredSessionControls>;
|
|
15
|
+
}
|
|
16
|
+
function ConfiguredSessionControls({
|
|
17
|
+
children,
|
|
18
|
+
onSignOut,
|
|
19
|
+
}: {
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
onSignOut?: () => Promise<void>;
|
|
22
|
+
}) {
|
|
23
|
+
const { data: session } = authClient.useSession();
|
|
24
|
+
const [email, setEmail] = useState('');
|
|
25
|
+
const [password, setPassword] = useState('');
|
|
26
|
+
const [message, setMessage] = useState('');
|
|
27
|
+
const [busy, setBusy] = useState(false);
|
|
28
|
+
async function verifySignIn() {
|
|
29
|
+
const result = await authClient.signIn.email({ email, password });
|
|
30
|
+
if (result.error) throw Error('Sign in failed');
|
|
31
|
+
const response = await apiRequest('/session');
|
|
32
|
+
if (!response.ok) throw Error('Session unavailable');
|
|
33
|
+
}
|
|
34
|
+
async function signIn() {
|
|
35
|
+
setBusy(true);
|
|
36
|
+
try {
|
|
37
|
+
await verifySignIn();
|
|
38
|
+
setMessage('Signed in');
|
|
39
|
+
} catch {
|
|
40
|
+
setMessage('Unable to sign in');
|
|
41
|
+
} finally {
|
|
42
|
+
setBusy(false);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function signOut() {
|
|
47
|
+
try {
|
|
48
|
+
await onSignOut?.();
|
|
49
|
+
} catch {
|
|
50
|
+
setMessage('The purchase connection needs attention.');
|
|
51
|
+
} finally {
|
|
52
|
+
await authClient.signOut();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (session)
|
|
56
|
+
return (
|
|
57
|
+
<View>
|
|
58
|
+
<Text>{session.user.email}</Text>
|
|
59
|
+
{children}
|
|
60
|
+
<ActionButton label="Sign out" onPress={() => void signOut()} />
|
|
61
|
+
</View>
|
|
62
|
+
);
|
|
63
|
+
return (
|
|
64
|
+
<View style={{ padding: 16, gap: 8 }}>
|
|
65
|
+
<Text>Sign in</Text>
|
|
66
|
+
<TextInput
|
|
67
|
+
accessibilityLabel="Email"
|
|
68
|
+
autoCapitalize="none"
|
|
69
|
+
keyboardType="email-address"
|
|
70
|
+
value={email}
|
|
71
|
+
onChangeText={setEmail}
|
|
72
|
+
/>
|
|
73
|
+
<TextInput
|
|
74
|
+
accessibilityLabel="Password"
|
|
75
|
+
secureTextEntry
|
|
76
|
+
value={password}
|
|
77
|
+
onChangeText={setPassword}
|
|
78
|
+
/>
|
|
79
|
+
<ActionButton label="Sign in" disabled={busy} onPress={() => void signIn()} />
|
|
80
|
+
<Text accessibilityLiveRegion="polite">{message}</Text>
|
|
81
|
+
</View>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { TextClassContext } from '@/components/ui/text';
|
|
2
|
+
import { cn } from '@/lib/utils';
|
|
3
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
4
|
+
import { Platform, Pressable } from 'react-native';
|
|
5
|
+
|
|
6
|
+
const buttonVariants = cva(
|
|
7
|
+
cn(
|
|
8
|
+
'group shrink-0 flex-row items-center justify-center gap-2 rounded-md shadow-none',
|
|
9
|
+
Platform.select({
|
|
10
|
+
web: "focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive whitespace-nowrap outline-none transition-all focus-visible:ring-[3px] disabled:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
11
|
+
}),
|
|
12
|
+
),
|
|
13
|
+
{
|
|
14
|
+
variants: {
|
|
15
|
+
variant: {
|
|
16
|
+
default: cn(
|
|
17
|
+
'bg-primary active:bg-primary/90 shadow-sm shadow-black/5',
|
|
18
|
+
Platform.select({ web: 'hover:bg-primary/90' }),
|
|
19
|
+
),
|
|
20
|
+
destructive: cn(
|
|
21
|
+
'bg-destructive active:bg-destructive/90 dark:bg-destructive/60 shadow-sm shadow-black/5',
|
|
22
|
+
Platform.select({
|
|
23
|
+
web: 'hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40',
|
|
24
|
+
}),
|
|
25
|
+
),
|
|
26
|
+
outline: cn(
|
|
27
|
+
'border-border bg-background active:bg-accent dark:bg-input/30 dark:border-input dark:active:bg-input/50 border shadow-sm shadow-black/5',
|
|
28
|
+
Platform.select({
|
|
29
|
+
web: 'hover:bg-accent dark:hover:bg-input/50',
|
|
30
|
+
}),
|
|
31
|
+
),
|
|
32
|
+
secondary: cn(
|
|
33
|
+
'bg-secondary active:bg-secondary/80 shadow-sm shadow-black/5',
|
|
34
|
+
Platform.select({ web: 'hover:bg-secondary/80' }),
|
|
35
|
+
),
|
|
36
|
+
ghost: cn(
|
|
37
|
+
'active:bg-accent dark:active:bg-accent/50',
|
|
38
|
+
Platform.select({ web: 'hover:bg-accent dark:hover:bg-accent/50' }),
|
|
39
|
+
),
|
|
40
|
+
link: '',
|
|
41
|
+
},
|
|
42
|
+
size: {
|
|
43
|
+
default: cn('h-10 px-4 py-2 sm:h-9', Platform.select({ web: 'has-[>svg]:px-3' })),
|
|
44
|
+
sm: cn('h-9 gap-1.5 rounded-md px-3 sm:h-8', Platform.select({ web: 'has-[>svg]:px-2.5' })),
|
|
45
|
+
lg: cn('h-11 rounded-md px-6 sm:h-10', Platform.select({ web: 'has-[>svg]:px-4' })),
|
|
46
|
+
icon: 'h-10 w-10 sm:h-9 sm:w-9',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
defaultVariants: {
|
|
50
|
+
variant: 'default',
|
|
51
|
+
size: 'default',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const buttonTextVariants = cva(
|
|
57
|
+
cn(
|
|
58
|
+
'text-foreground text-sm font-medium',
|
|
59
|
+
Platform.select({ web: 'pointer-events-none transition-colors' }),
|
|
60
|
+
),
|
|
61
|
+
{
|
|
62
|
+
variants: {
|
|
63
|
+
variant: {
|
|
64
|
+
default: 'text-primary-foreground',
|
|
65
|
+
destructive: 'text-white',
|
|
66
|
+
outline: cn(
|
|
67
|
+
'group-active:text-accent-foreground',
|
|
68
|
+
Platform.select({ web: 'group-hover:text-accent-foreground' }),
|
|
69
|
+
),
|
|
70
|
+
secondary: 'text-secondary-foreground',
|
|
71
|
+
ghost: 'group-active:text-accent-foreground',
|
|
72
|
+
link: cn(
|
|
73
|
+
'text-primary group-active:underline',
|
|
74
|
+
Platform.select({ web: 'underline-offset-4 hover:underline group-hover:underline' }),
|
|
75
|
+
),
|
|
76
|
+
},
|
|
77
|
+
size: {
|
|
78
|
+
default: '',
|
|
79
|
+
sm: '',
|
|
80
|
+
lg: '',
|
|
81
|
+
icon: '',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
defaultVariants: {
|
|
85
|
+
variant: 'default',
|
|
86
|
+
size: 'default',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
type ButtonProps = React.ComponentProps<typeof Pressable> &
|
|
92
|
+
React.RefAttributes<typeof Pressable> &
|
|
93
|
+
VariantProps<typeof buttonVariants>;
|
|
94
|
+
|
|
95
|
+
function Button({ className, variant, size, ...props }: ButtonProps) {
|
|
96
|
+
return (
|
|
97
|
+
<TextClassContext.Provider value={buttonTextVariants({ variant, size })}>
|
|
98
|
+
<Pressable
|
|
99
|
+
className={cn(props.disabled && 'opacity-50', buttonVariants({ variant, size }), className)}
|
|
100
|
+
role="button"
|
|
101
|
+
{...props}
|
|
102
|
+
/>
|
|
103
|
+
</TextClassContext.Provider>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { Button, buttonTextVariants, buttonVariants };
|
|
108
|
+
export type { ButtonProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="nativewind/types" />
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const { hairlineWidth } = require('nativewind/theme');
|
|
2
|
+
|
|
3
|
+
/** @type {import('tailwindcss').Config} */
|
|
4
|
+
module.exports = {
|
|
5
|
+
darkMode: 'class',
|
|
6
|
+
content: ['./app/**/*.{ts,tsx}', './components/**/*.{ts,tsx}'],
|
|
7
|
+
presets: [require('nativewind/preset')],
|
|
8
|
+
theme: {
|
|
9
|
+
extend: {
|
|
10
|
+
colors: {
|
|
11
|
+
border: 'hsl(var(--border))',
|
|
12
|
+
input: 'hsl(var(--input))',
|
|
13
|
+
ring: 'hsl(var(--ring))',
|
|
14
|
+
background: 'hsl(var(--background))',
|
|
15
|
+
foreground: 'hsl(var(--foreground))',
|
|
16
|
+
primary: {
|
|
17
|
+
DEFAULT: 'hsl(var(--primary))',
|
|
18
|
+
foreground: 'hsl(var(--primary-foreground))',
|
|
19
|
+
},
|
|
20
|
+
secondary: {
|
|
21
|
+
DEFAULT: 'hsl(var(--secondary))',
|
|
22
|
+
foreground: 'hsl(var(--secondary-foreground))',
|
|
23
|
+
},
|
|
24
|
+
destructive: {
|
|
25
|
+
DEFAULT: 'hsl(var(--destructive))',
|
|
26
|
+
foreground: 'hsl(var(--destructive-foreground))',
|
|
27
|
+
},
|
|
28
|
+
muted: {
|
|
29
|
+
DEFAULT: 'hsl(var(--muted))',
|
|
30
|
+
foreground: 'hsl(var(--muted-foreground))',
|
|
31
|
+
},
|
|
32
|
+
accent: {
|
|
33
|
+
DEFAULT: 'hsl(var(--accent))',
|
|
34
|
+
foreground: 'hsl(var(--accent-foreground))',
|
|
35
|
+
},
|
|
36
|
+
popover: {
|
|
37
|
+
DEFAULT: 'hsl(var(--popover))',
|
|
38
|
+
foreground: 'hsl(var(--popover-foreground))',
|
|
39
|
+
},
|
|
40
|
+
card: {
|
|
41
|
+
DEFAULT: 'hsl(var(--card))',
|
|
42
|
+
foreground: 'hsl(var(--card-foreground))',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
borderRadius: {
|
|
46
|
+
lg: 'var(--radius)',
|
|
47
|
+
md: 'calc(var(--radius) - 2px)',
|
|
48
|
+
sm: 'calc(var(--radius) - 4px)',
|
|
49
|
+
},
|
|
50
|
+
borderWidth: {
|
|
51
|
+
hairline: hairlineWidth(),
|
|
52
|
+
},
|
|
53
|
+
keyframes: {
|
|
54
|
+
'accordion-down': {
|
|
55
|
+
from: { height: '0' },
|
|
56
|
+
to: { height: 'var(--radix-accordion-content-height)' },
|
|
57
|
+
},
|
|
58
|
+
'accordion-up': {
|
|
59
|
+
from: { height: 'var(--radix-accordion-content-height)' },
|
|
60
|
+
to: { height: '0' },
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
animation: {
|
|
64
|
+
'accordion-down': 'accordion-down 0.2s ease-out',
|
|
65
|
+
'accordion-up': 'accordion-up 0.2s ease-out',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
future: {
|
|
70
|
+
hoverOnlyWhenSupported: true,
|
|
71
|
+
},
|
|
72
|
+
plugins: [require('tailwindcss-animate')],
|
|
73
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { cn } from '@/lib/utils';
|
|
2
|
+
import { Slot } from '@rn-primitives/slot';
|
|
3
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { Platform, Text as RNText, type Role } from 'react-native';
|
|
6
|
+
|
|
7
|
+
const textVariants = cva(
|
|
8
|
+
cn(
|
|
9
|
+
'text-foreground text-base',
|
|
10
|
+
Platform.select({
|
|
11
|
+
web: 'select-text',
|
|
12
|
+
}),
|
|
13
|
+
),
|
|
14
|
+
{
|
|
15
|
+
variants: {
|
|
16
|
+
variant: {
|
|
17
|
+
default: '',
|
|
18
|
+
h1: cn(
|
|
19
|
+
'text-center text-4xl font-extrabold tracking-tight',
|
|
20
|
+
Platform.select({ web: 'scroll-m-20 text-balance' }),
|
|
21
|
+
),
|
|
22
|
+
h2: cn(
|
|
23
|
+
'border-border border-b pb-2 text-3xl font-semibold tracking-tight',
|
|
24
|
+
Platform.select({ web: 'scroll-m-20 first:mt-0' }),
|
|
25
|
+
),
|
|
26
|
+
h3: cn('text-2xl font-semibold tracking-tight', Platform.select({ web: 'scroll-m-20' })),
|
|
27
|
+
h4: cn('text-xl font-semibold tracking-tight', Platform.select({ web: 'scroll-m-20' })),
|
|
28
|
+
p: 'mt-3 leading-7 sm:mt-6',
|
|
29
|
+
blockquote: 'mt-4 border-l-2 pl-3 italic sm:mt-6 sm:pl-6',
|
|
30
|
+
code: cn(
|
|
31
|
+
'bg-muted relative rounded px-[0.3rem] py-[0.2rem] font-mono text-sm font-semibold',
|
|
32
|
+
),
|
|
33
|
+
lead: 'text-muted-foreground text-xl',
|
|
34
|
+
large: 'text-lg font-semibold',
|
|
35
|
+
small: 'text-sm font-medium leading-none',
|
|
36
|
+
muted: 'text-muted-foreground text-sm',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
defaultVariants: {
|
|
40
|
+
variant: 'default',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
type TextVariantProps = VariantProps<typeof textVariants>;
|
|
46
|
+
|
|
47
|
+
type TextVariant = NonNullable<TextVariantProps['variant']>;
|
|
48
|
+
|
|
49
|
+
const ROLE: Partial<Record<TextVariant, Role>> = {
|
|
50
|
+
h1: 'heading',
|
|
51
|
+
h2: 'heading',
|
|
52
|
+
h3: 'heading',
|
|
53
|
+
h4: 'heading',
|
|
54
|
+
blockquote: Platform.select({ web: 'blockquote' as Role }),
|
|
55
|
+
code: Platform.select({ web: 'code' as Role }),
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const ARIA_LEVEL: Partial<Record<TextVariant, string>> = {
|
|
59
|
+
h1: '1',
|
|
60
|
+
h2: '2',
|
|
61
|
+
h3: '3',
|
|
62
|
+
h4: '4',
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const TextClassContext = React.createContext<string | undefined>(undefined);
|
|
66
|
+
|
|
67
|
+
function Text({
|
|
68
|
+
className,
|
|
69
|
+
asChild = false,
|
|
70
|
+
variant = 'default',
|
|
71
|
+
...props
|
|
72
|
+
}: React.ComponentProps<typeof RNText> &
|
|
73
|
+
React.RefAttributes<typeof RNText> &
|
|
74
|
+
TextVariantProps & {
|
|
75
|
+
asChild?: boolean;
|
|
76
|
+
}) {
|
|
77
|
+
const textClass = React.useContext(TextClassContext);
|
|
78
|
+
const Component = asChild ? Slot : RNText;
|
|
79
|
+
return (
|
|
80
|
+
<Component
|
|
81
|
+
className={cn(textVariants({ variant }), textClass, className)}
|
|
82
|
+
role={variant ? ROLE[variant] : undefined}
|
|
83
|
+
aria-level={variant ? ARIA_LEVEL[variant] : undefined}
|
|
84
|
+
{...props}
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { Text, TextClassContext };
|