Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Make the address map a design-system component

Damian Legawiec06260f1ad8fc
diff --git a/packages/dashboard-core/src/locales/ar.json b/packages/dashboard-core/src/locales/ar.json
index bea9fc81bf..4610b055b3 100644
--- a/packages/dashboard-core/src/locales/ar.json
+++ b/packages/dashboard-core/src/locales/ar.json
@@ -90,6 +90,9 @@
"view_all": "عرض الكل",
"view_details": "عرض التفاصيل"
},
+ "address": {
+ "not_located_yet": "تظهر الخريطة بعد تحديد موقع هذا العنوان."
+ },
"auth": {
"back_to_login": "العودة إلى تسجيل الدخول",
"forgot_password": {
diff --git a/packages/dashboard-core/src/locales/de.json b/packages/dashboard-core/src/locales/de.json
index 9ba9f78363..9eb318a9ed 100644
--- a/packages/dashboard-core/src/locales/de.json
+++ b/packages/dashboard-core/src/locales/de.json
@@ -90,6 +90,9 @@
"view_all": "Alle anzeigen",
"view_details": "Details anzeigen"
},
+ "address": {
+ "not_located_yet": "Die Karte erscheint, sobald diese Adresse gefunden wurde."
+ },
"auth": {
"back_to_login": "Zurück zur Anmeldung",
"forgot_password": {
diff --git a/packages/dashboard-core/src/locales/en.json b/packages/dashboard-core/src/locales/en.json
index 2f98592048..4484cf7fa6 100644
--- a/packages/dashboard-core/src/locales/en.json
+++ b/packages/dashboard-core/src/locales/en.json
@@ -90,6 +90,9 @@
"view_all": "View all",
"view_details": "View details"
},
+ "address": {
+ "not_located_yet": "The map appears once this address has been located."
+ },
"auth": {
"back_to_login": "Back to sign in",
"forgot_password": {
diff --git a/packages/dashboard-core/src/locales/fr.json b/packages/dashboard-core/src/locales/fr.json
index 2cbb0c01d4..1250c33a4a 100644
--- a/packages/dashboard-core/src/locales/fr.json
+++ b/packages/dashboard-core/src/locales/fr.json
@@ -90,6 +90,9 @@
"view_all": "Tout afficher",
"view_details": "Voir les détails"
},
+ "address": {
+ "not_located_yet": "La carte apparaît une fois cette adresse localisée."
+ },
"auth": {
"back_to_login": "Retour à la connexion",
"forgot_password": {
diff --git a/packages/dashboard-core/src/locales/pl.json b/packages/dashboard-core/src/locales/pl.json
index 9c7af0dc42..830edaa8af 100644
--- a/packages/dashboard-core/src/locales/pl.json
+++ b/packages/dashboard-core/src/locales/pl.json
@@ -90,6 +90,9 @@
"view_all": "Zobacz wszystko",
"view_details": "Zobacz szczegóły"
},
+ "address": {
+ "not_located_yet": "Mapa pojawi się, gdy adres zostanie zlokalizowany."
+ },
"auth": {
"back_to_login": "Powrót do logowania",
"forgot_password": {
diff --git a/packages/dashboard-core/src/locales/zh-CN.json b/packages/dashboard-core/src/locales/zh-CN.json
index 8e8e6c5742..5326454cea 100644
--- a/packages/dashboard-core/src/locales/zh-CN.json
+++ b/packages/dashboard-core/src/locales/zh-CN.json
@@ -90,6 +90,9 @@
"view_all": "查看全部",
"view_details": "查看详情"
},
+ "address": {
+ "not_located_yet": "定位完成后将显示地图。"
+ },
"auth": {
"back_to_login": "返回登录",
"forgot_password": {
diff --git a/packages/dashboard-ui/package.json b/packages/dashboard-ui/package.json
index 071347a9dc..d512d69b95 100644
--- a/packages/dashboard-ui/package.json
+++ b/packages/dashboard-ui/package.json
@@ -2,7 +2,7 @@
"name": "@spree/dashboard-ui",
"license": "MIT",
"version": "0.13.1",
- "description": "Spree Dashboard design system — shadcn primitives, headless composed components, and design tokens. Source-only package; consumers compile via their own Vite/Tailwind setup. Developer Preview.",
+ "description": "Spree Dashboard design system \u2014 shadcn primitives, headless composed components, and design tokens. Source-only package; consumers compile via their own Vite/Tailwind setup. Developer Preview.",
"author": "Vendo Connect Inc.",
"homepage": "https://spreecommerce.org",
"repository": {
@@ -71,6 +71,7 @@
"date-fns-tz": "^3.2.0",
"flag-icons": "^7.5.0",
"lucide-react": "^1.14.0",
+ "maplibre-gl": "^6.4.0",
"react-colorful": "^5.7.0",
"react-day-picker": "^9.14.0",
"recharts": "^3.8.1",
@@ -78,9 +79,11 @@
"tw-animate-css": "^1.4.0"
},
"devDependencies": {
+ "@types/geojson": "^7946.0.16",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"shadcn": "^4.7.0",
- "typescript": "~6.0.3"
+ "typescript": "~6.0.3",
+ "vite": "^8.0.16"
}
}
diff --git a/packages/dashboard-ui/src/index.ts b/packages/dashboard-ui/src/index.ts
index 1ebdbac4d1..7979a0aee4 100644
--- a/packages/dashboard-ui/src/index.ts
+++ b/packages/dashboard-ui/src/index.ts
@@ -24,6 +24,7 @@ export { requiredMessage } from './lib/validation-messages'
// Spree composed components — headless, accept data via props
// ---------------------------------------------------------------------------
export * from './spree/address-block'
+export * from './spree/address-map'
export * from './spree/back-button'
export * from './spree/bulk-dialog'
export * from './spree/bulk-price-table'
diff --git a/packages/dashboard-ui/src/spree/address-map.tsx b/packages/dashboard-ui/src/spree/address-map.tsx
new file mode 100644
index 0000000000..8438694438
--- /dev/null
+++ b/packages/dashboard-ui/src/spree/address-map.tsx
@@ -0,0 +1,62 @@
+import { lazy, Suspense } from 'react'
+import { useTranslation } from 'react-i18next'
+
+/**
+ * Structural shape `<AddressMap>` needs. Declared here rather than imported
+ * so the design system stays decoupled from any SDK's `Address` type — the
+ * same reason `<AddressBlock>` carries its own.
+ */
+export interface AddressMapValue {
+ latitude?: number | null
+ longitude?: number | null
+}
+
+// MapLibre and its styles are a few megabytes for a map that appears on one
+// card of a page, so it is loaded on demand and every other screen is spared.
+const LazyMap = lazy(async () => ({ default: (await import('../ui/map')).Map }))
+const LazyMapControls = lazy(async () => ({ default: (await import('../ui/map')).MapControls }))
+const LazyMapMarker = lazy(async () => ({ default: (await import('../ui/map')).MapMarker }))
+const LazyMarkerContent = lazy(async () => ({ default: (await import('../ui/map')).MarkerContent }))
+const LazyMarkerTooltip = lazy(async () => ({ default: (await import('../ui/map')).MarkerTooltip }))
+
+/**
+ * Where an address actually is, beside the lines that describe it — a returns
+ * address is what shoppers are told to post to, so it is worth seeing on a map
+ * rather than trusting as typed.
+ *
+ * Coordinates are geocoded in the background after an address is saved, so a
+ * freshly entered one has none yet; the map is simply absent until then rather
+ * than showing the middle of the ocean.
+ */
+export function AddressMap({
+ address,
+ label,
+ className,
+}: {
+ address: AddressMapValue
+ /** Names whose address the pin marks — a seller, a customer, a branch. */
+ label?: string
+ className?: string
+}) {
+ const { t } = useTranslation()
+ const { latitude, longitude } = address
+
+ if (latitude == null || longitude == null) {
+ return <p className="text-muted-foreground text-xs">{t('admin.address.not_located_yet')}</p>
+ }
+
+ return (
+ <div className={className ?? 'h-40 overflow-hidden rounded-md border'}>
+ <Suspense fallback={<div className="size-full animate-pulse bg-muted" />}>
+ <LazyMap center={[longitude, latitude]} zoom={13}>
+ <LazyMapControls />
+ <LazyMapMarker longitude={longitude} latitude={latitude}>
+ {/* The default pin; the tooltip names whose address it is. */}
+ <LazyMarkerContent />
+ {label && <LazyMarkerTooltip>{label}</LazyMarkerTooltip>}
+ </LazyMapMarker>
+ </LazyMap>
+ </Suspense>
+ </div>
+ )
+}
diff --git a/packages/dashboard/src/components/ui/map.tsx b/packages/dashboard-ui/src/ui/map.tsx
similarity index 99%
rename from packages/dashboard/src/components/ui/map.tsx
rename to packages/dashboard-ui/src/ui/map.tsx
index 19d25bba8a..1cb8449e24 100644
--- a/packages/dashboard/src/components/ui/map.tsx
+++ b/packages/dashboard-ui/src/ui/map.tsx
@@ -4,9 +4,6 @@ import type { MarkerOptions, PopupOptions } from 'maplibre-gl'
import * as MapLibreGL from 'maplibre-gl'
import 'maplibre-gl/dist/maplibre-gl.css'
-// `cn` lives in the design system here rather than a local lib/utils, which
-// is the one edit made to this vendored registry component.
-import { cn } from '@spree/dashboard-ui'
import type * as GeoJSON from 'geojson'
import { Loader2, Locate, Maximize, Minus, Plus, X } from 'lucide-react'
// `?worker&url` hands the file to the bundler, which emits it as its own chunk
@@ -26,6 +23,7 @@ import {
useState,
} from 'react'
import { createPortal } from 'react-dom'
+import { cn } from '../lib/utils'
// The worker ships in the package, so it is bundled and served from this
// origin. The registry's default fetches it from unpkg at runtime, which means
diff --git a/packages/dashboard-ui/tsconfig.json b/packages/dashboard-ui/tsconfig.json
index 3501ca104c..1d24be51d8 100644
--- a/packages/dashboard-ui/tsconfig.json
+++ b/packages/dashboard-ui/tsconfig.json
@@ -1,6 +1,10 @@
{
"compilerOptions": {
"target": "ES2022",
+ // The map primitive imports maplibre's stylesheet and its worker through
+ // Vite's `?worker&url`, both of which are typed by vite/client. The
+ // package is source-only, so the consumer's bundler resolves them.
+ "types": ["vite/client"],
"ignoreDeprecations": "6.0",
"useDefineForClassFields": true,
"lib": ["ES2022", "DOM", "DOM.Iterable"],
diff --git a/packages/dashboard/package.json b/packages/dashboard/package.json
index f506e9ad9f..1527ee46d9 100644
--- a/packages/dashboard/package.json
+++ b/packages/dashboard/package.json
@@ -2,7 +2,7 @@
"name": "@spree/dashboard",
"license": "MIT",
"version": "0.13.1",
- "description": "Spree Dashboard app shell — the next-gen React admin for Spree Commerce. Routes, resource hooks, schemas, locales, and the <Dashboard /> component. Source-only package; hosts compile it via @spree/dashboard/vite. Developer Preview.",
+ "description": "Spree Dashboard app shell \u2014 the next-gen React admin for Spree Commerce. Routes, resource hooks, schemas, locales, and the <Dashboard /> component. Source-only package; hosts compile it via @spree/dashboard/vite. Developer Preview.",
"author": "Vendo Connect Inc.",
"homepage": "https://spreecommerce.org",
"repository": {
@@ -81,7 +81,6 @@
"flag-icons": "^7.5.0",
"i18next": "^26.2.0",
"lucide-react": "^1.14.0",
- "maplibre-gl": "^6.4.0",
"next-themes": "^0.4.6",
"react": "^19.2.6",
"react-colorful": "^5.7.0",
@@ -98,7 +97,6 @@
"devDependencies": {
"@playwright/test": "^1.59.1",
"@spree/dashboard-plugin-example": "workspace:^",
- "@types/geojson": "^7946.0.16",
"@types/node": "^25.6.0",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
diff --git a/packages/dashboard/src/components/spree/sellers/seller-address-card.tsx b/packages/dashboard/src/components/spree/sellers/seller-address-card.tsx
index eebfc069f4..878e80c982 100644
--- a/packages/dashboard/src/components/spree/sellers/seller-address-card.tsx
+++ b/packages/dashboard/src/components/spree/sellers/seller-address-card.tsx
@@ -2,6 +2,7 @@ import type { Seller } from '@spree/admin-sdk'
import { AddressFormDialog } from '@spree/dashboard-core'
import {
AddressBlock,
+ AddressMap,
Badge,
Button,
Card,
@@ -14,7 +15,6 @@ import { PencilIcon } from 'lucide-react'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useUpdateSeller } from '../../../hooks/use-sellers'
-import { SellerAddressMap } from './seller-address-map'
type AddressKey = 'billing_address' | 'returns_address'
@@ -77,7 +77,7 @@ export function SellerAddressCard({
<>
{/* No title: the card header already names it. */}
<AddressBlock address={address} />
- <SellerAddressMap address={address} label={seller.name} />
+ <AddressMap address={address} label={seller.name} />
</>
) : (
<p className="py-4 text-center text-muted-foreground text-sm">
diff --git a/packages/dashboard/src/components/spree/sellers/seller-address-map.tsx b/packages/dashboard/src/components/spree/sellers/seller-address-map.tsx
deleted file mode 100644
index c5579b2c2a..0000000000
--- a/packages/dashboard/src/components/spree/sellers/seller-address-map.tsx
+++ /dev/null
@@ -1,66 +0,0 @@
-import type { Address } from '@spree/admin-sdk'
-import { lazy, Suspense } from 'react'
-import { useTranslation } from 'react-i18next'
-
-// MapLibre and its styles are a few megabytes, and a map appears on one card
-// of one page — loaded on demand so every other screen does not carry it.
-const LazyMap = lazy(async () => {
- const map = await import('../../ui/map')
-
- return { default: map.Map }
-})
-const LazyMapControls = lazy(async () => {
- const map = await import('../../ui/map')
-
- return { default: map.MapControls }
-})
-const LazyMapMarker = lazy(async () => {
- const map = await import('../../ui/map')
-
- return { default: map.MapMarker }
-})
-const LazyMarkerContent = lazy(async () => {
- const map = await import('../../ui/map')
-
- return { default: map.MarkerContent }
-})
-const LazyMarkerTooltip = lazy(async () => {
- const map = await import('../../ui/map')
-
- return { default: map.MarkerTooltip }
-})
-
-/**
- * Where an address actually is, beside the lines that describe it — a returns
- * address is what shoppers are told to post to, so it is worth seeing on a map
- * rather than trusting as typed.
- *
- * Coordinates are geocoded in the background after the address is saved, so a
- * freshly entered one has none yet; the map is simply absent until then rather
- * than showing the middle of the ocean.
- */
-export function SellerAddressMap({ address, label }: { address: Address; label?: string }) {
- const { t } = useTranslation()
- const { latitude, longitude } = address
-
- if (latitude == null || longitude == null) {
- return (
- <p className="text-muted-foreground text-xs">{t('admin.sellers.address.not_located_yet')}</p>
- )
- }
-
- return (
- <div className="h-40 overflow-hidden rounded-md border">
- <Suspense fallback={<div className="size-full animate-pulse bg-muted" />}>
- <LazyMap center={[longitude, latitude]} zoom={13}>
- <LazyMapControls />
- <LazyMapMarker longitude={longitude} latitude={latitude}>
- {/* The default pin; the tooltip names whose address it is. */}
- <LazyMarkerContent />
- {label && <LazyMarkerTooltip>{label}</LazyMarkerTooltip>}
- </LazyMapMarker>
- </LazyMap>
- </Suspense>
- </div>
- )
-}
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index f318018632..586db8074e 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -4092,7 +4092,6 @@
"address": {
"filled": "مكتمل",
"not_filled": "غير مكتمل",
- "not_located_yet": "تظهر الخريطة بعد تحديد موقع هذا العنوان.",
"not_provided_by_seller": "لم يقدّمه البائع بعد"
},
"approve_override_confirm": {
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 659ea27fbc..11e676ca31 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -4073,7 +4073,6 @@
"address": {
"filled": "Ausgefüllt",
"not_filled": "Nicht ausgefüllt",
- "not_located_yet": "Die Karte erscheint, sobald diese Adresse gefunden wurde.",
"not_provided_by_seller": "Vom Verkäufer noch nicht angegeben"
},
"approve_override_confirm": {
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index b2367155ff..9a3471024d 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -4073,7 +4073,6 @@
"address": {
"filled": "Filled",
"not_filled": "Not filled",
- "not_located_yet": "The map appears once this address has been located.",
"not_provided_by_seller": "Not yet provided by the seller"
},
"approve_override_confirm": {
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index e7200b5a04..3b430d875f 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -4073,7 +4073,6 @@
"address": {
"filled": "Renseignée",
"not_filled": "Non renseignée",
- "not_located_yet": "La carte apparaît une fois cette adresse localisée.",
"not_provided_by_seller": "Pas encore fournie par le vendeur"
},
"approve_override_confirm": {
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index e28c7a08ab..a3bdd074d4 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -4133,7 +4133,6 @@
"address": {
"filled": "Uzupełniony",
"not_filled": "Nieuzupełniony",
- "not_located_yet": "Mapa pojawi się, gdy adres zostanie zlokalizowany.",
"not_provided_by_seller": "Sprzedawca jeszcze go nie podał"
},
"approve_override_confirm": {
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index 9d6b7ff157..6efe34e881 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -4066,7 +4066,6 @@
"address": {
"filled": "已填写",
"not_filled": "未填写",
- "not_located_yet": "定位完成后将显示地图。",
"not_provided_by_seller": "卖家尚未提供"
},
"approve_override_confirm": {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 7d85063556..4b9bfa21d9 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -237,9 +237,6 @@ importers:
lucide-react:
specifier: ^1.14.0
version: 1.14.0([email protected])
- maplibre-gl:
- specifier: ^6.4.0
- version: 6.4.0
next-themes:
specifier: ^0.4.6
@@ -283,9 +280,6 @@ importers:
'@spree/dashboard-plugin-example':
specifier: workspace:^
version: link:../dashboard-plugin-example
- '@types/geojson':
- specifier: ^7946.0.16
- version: 7946.0.16
'@types/node':
specifier: ^25.6.0
version: 25.6.0
@@ -565,6 +559,9 @@ importers:
lucide-react:
specifier: ^1.14.0
version: 1.14.0([email protected])
+ maplibre-gl:
+ specifier: ^6.4.0
+ version: 6.4.0
react:
specifier: ^19.2.6
version: 19.2.6
@@ -593,6 +590,9 @@ importers:
specifier: ^1.4.0
version: 1.4.0
devDependencies:
+ '@types/geojson':
+ specifier: ^7946.0.16
+ version: 7946.0.16
'@types/react':
specifier: ^19.2.14
version: 19.2.14
@@ -605,6 +605,9 @@ importers:
typescript:
specifier: ~6.0.3
version: 6.0.3
+ vite:
+ specifier: ^8.0.16
packages/docs:
devDependencies:
@@ -4241,16 +4244,6 @@ packages:
resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==}
engines: {node: '>=8'}
- resolution: {integrity: sha512-UM/ByIoFra8yzV75n1o0Puu0bw5U/9UNnDacrJNspekBewIfsQ3D6ez1nvlWpt7aTsO6rujQtifBpycwIivqlg==}
- peerDependencies:
- '@types/react': ^18.0.0 || ^19.0.0
- react: ^18.0.0 || ^19.0.0 || ^19.0.0-rc
- react-dom: ^18.0.0 || ^19.0.0 || ^19.0.0-rc
- peerDependenciesMeta:
- '@types/react':
- optional: true
-
resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==}
engines: {node: '>=0.10.0'}
@@ -8041,13 +8034,6 @@ snapshots:
- dependencies:
- react: 19.2.6
- react-dom: 19.2.6([email protected])
- optionalDependencies:
- '@types/react': 19.2.14
-