@realadvisor-sites/kit-astro 0.0.0-stage → 0.4.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/LICENSE +21 -0
- package/README.md +38 -2
- package/astro.d.mts +4 -0
- package/astro.mjs +122 -0
- package/components/ConsentBanner.astro +35 -0
- package/components/EnquiryForm.astro +149 -0
- package/components/LegalContent.astro +32 -0
- package/components/ListingsMap.astro +153 -0
- package/components/ListingsPager.astro +45 -0
- package/components/ListingsSearch.astro +490 -0
- package/components/RaImage.astro +79 -0
- package/components/form/Button.astro +25 -0
- package/components/form/Combobox.astro +41 -0
- package/components/form/Input.astro +26 -0
- package/components/form/Select.astro +35 -0
- package/lib/ra.ts +145 -0
- package/middleware.ts +93 -0
- package/package.json +44 -4
- package/tools/keep-assets.mjs +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 RealAdvisor SA
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @realadvisor/sites-kit-astro
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Astro 5 kit for RealAdvisor sites on Cloudflare Workers, built on
|
|
4
|
+
`@realadvisor/sites-kit-core`. A site installs both, the same version:
|
|
5
|
+
|
|
6
|
+
```json
|
|
7
|
+
"@realadvisor/sites-kit-astro": "npm:@realadvisor-sites/kit-astro@^0.4.0",
|
|
8
|
+
"@realadvisor/sites-kit-core": "npm:@realadvisor-sites/kit-core@^0.4.0",
|
|
9
|
+
"@realadvisor/sites-sdk": "npm:@realadvisor-sites/sdk@^0.4.0"
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
In this repo the template and examples use paths instead (`file:../kit-astro`).
|
|
13
|
+
|
|
14
|
+
| Import | What |
|
|
15
|
+
| --- | --- |
|
|
16
|
+
| `@realadvisor/sites-kit-astro` | `sitesKit()`, the Astro integration: middleware, security headers, data env, `site.json`, `virtual:sites-kit/site` and `virtual:sites-kit/fixtures`. |
|
|
17
|
+
| `@realadvisor/sites-kit-astro/ra` | `ra`, the site's one data client: live with `SITES_API_URL` + `SITES_API_KEY`, else the fixture in `src/data/`. Server side only. |
|
|
18
|
+
| `@realadvisor/sites-kit-astro/components/<Name>.astro` | `ListingsSearch`, `ListingsMap`, `ListingsPager`, `EnquiryForm`, `RaImage`, `LegalContent`, `ConsentBanner`, `form/*` (`Input`, `Select`, `Combobox`, `Button`). |
|
|
19
|
+
| `@realadvisor/sites-kit-astro/middleware` | Added by the integration; never imported by a site. |
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
// astro.config.mjs
|
|
23
|
+
import { defineConfig } from 'astro/config';
|
|
24
|
+
import cloudflare from '@astrojs/cloudflare';
|
|
25
|
+
import sitesKit from '@realadvisor/sites-kit-astro';
|
|
26
|
+
|
|
27
|
+
export default defineConfig({
|
|
28
|
+
adapter: cloudflare({ imageService: 'passthrough', platformProxy: { enabled: true } }),
|
|
29
|
+
integrations: [sitesKit()],
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Everything shared with the React kit (i18n, formatting, legal texts, SEO,
|
|
34
|
+
search, images, security headers, browser scripts, the `sites-kit` tools and
|
|
35
|
+
the agent's rules in `AGENTS.md` and `DESIGN.md`) is in the core.
|
|
36
|
+
|
|
37
|
+
Sources are TypeScript and Astro, compiled by the site's Vite. `astro.mjs`
|
|
38
|
+
and `tools/keep-assets.mjs` are plain JS: Astro loads its config's
|
|
39
|
+
dependencies without compiling them.
|
package/astro.d.mts
ADDED
package/astro.mjs
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The kit's Astro integration: everything a RealAdvisor site needs from its
|
|
3
|
+
* config, so the site's astro.config.mjs is three lines.
|
|
4
|
+
*
|
|
5
|
+
* import { defineConfig } from 'astro/config';
|
|
6
|
+
* import cloudflare from '@astrojs/cloudflare';
|
|
7
|
+
* import sitesKit from '@realadvisor/sites-kit-astro';
|
|
8
|
+
*
|
|
9
|
+
* export default defineConfig({
|
|
10
|
+
* adapter: cloudflare({ imageService: 'passthrough', platformProxy: { enabled: true } }),
|
|
11
|
+
* integrations: [sitesKit()],
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* It adds:
|
|
15
|
+
* - the middleware (Worker env per request, full render before answering,
|
|
16
|
+
* 301s from site.json, security headers);
|
|
17
|
+
* - `virtual:sites-kit/site` (site.json with its defaults) and
|
|
18
|
+
* `virtual:sites-kit/fixtures` (src/data/*.json) for the kit modules;
|
|
19
|
+
* - the data env (SITES_API_URL, SITES_API_KEY, SITES_FIXTURE);
|
|
20
|
+
* - dist/_headers (security headers for prerendered pages and assets);
|
|
21
|
+
* - keepReferencedAssets (a stylesheet Astro inlines but a script still loads ships too);
|
|
22
|
+
* - dev server and build settings the CRM preview and the CSP depend on.
|
|
23
|
+
*
|
|
24
|
+
* Plain JS on purpose: Astro loads astro.config's dependencies natively.
|
|
25
|
+
*/
|
|
26
|
+
import { writeFileSync } from 'node:fs';
|
|
27
|
+
import { fileURLToPath } from 'node:url';
|
|
28
|
+
import { readSiteConfig, SITE_CONFIG_FILE } from '@realadvisor/sites-kit-core/site-config';
|
|
29
|
+
import { securityHeaders } from '@realadvisor/sites-kit-core/security';
|
|
30
|
+
import { keepReferencedAssets } from './tools/keep-assets.mjs';
|
|
31
|
+
|
|
32
|
+
const PKG = '@realadvisor/sites-kit-astro';
|
|
33
|
+
const CORE = '@realadvisor/sites-kit-core';
|
|
34
|
+
const SITE_ID = 'virtual:sites-kit/site';
|
|
35
|
+
const FIXTURES_ID = 'virtual:sites-kit/fixtures';
|
|
36
|
+
const resolved = (id) => `\0${id}`;
|
|
37
|
+
|
|
38
|
+
const TYPES = `declare module '${SITE_ID}' {
|
|
39
|
+
const site: import('${CORE}/site-config').SiteConfig;
|
|
40
|
+
export default site;
|
|
41
|
+
}
|
|
42
|
+
declare module '${FIXTURES_ID}' {
|
|
43
|
+
const fixtures: Record<string, { default: import('${CORE}').SiteFixture }>;
|
|
44
|
+
export default fixtures;
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
|
|
48
|
+
/** @returns {import('vite').Plugin} */
|
|
49
|
+
function sitesKitVite(root) {
|
|
50
|
+
return {
|
|
51
|
+
name: 'sites-kit',
|
|
52
|
+
resolveId(id) {
|
|
53
|
+
if (id === SITE_ID || id === FIXTURES_ID) return resolved(id);
|
|
54
|
+
return undefined;
|
|
55
|
+
},
|
|
56
|
+
load(id) {
|
|
57
|
+
if (id === resolved(SITE_ID)) {
|
|
58
|
+
return `export default ${JSON.stringify(readSiteConfig(fileURLToPath(root)))};`;
|
|
59
|
+
}
|
|
60
|
+
if (id === resolved(FIXTURES_ID)) {
|
|
61
|
+
// Root-relative: the site's src/data, wherever the kit is installed.
|
|
62
|
+
return "export default import.meta.glob('/src/data/*.json', { eager: true });";
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** @returns {import('astro').AstroIntegration} */
|
|
70
|
+
export default function sitesKit() {
|
|
71
|
+
return {
|
|
72
|
+
name: PKG,
|
|
73
|
+
hooks: {
|
|
74
|
+
'astro:config:setup': ({ config, updateConfig, addMiddleware, addWatchFile }) => {
|
|
75
|
+
// Fails the build early on a broken site.json, naming the field.
|
|
76
|
+
readSiteConfig(fileURLToPath(config.root));
|
|
77
|
+
// A site.json change restarts the dev server, like a config change.
|
|
78
|
+
addWatchFile(new URL(SITE_CONFIG_FILE, config.root));
|
|
79
|
+
addMiddleware({ entrypoint: `${PKG}/middleware`, order: 'pre' });
|
|
80
|
+
updateConfig({
|
|
81
|
+
// Replaced at publish (SITE_URL); canonical URLs, OG and the sitemap use it.
|
|
82
|
+
...(config.site ? {} : { site: process.env.SITE_URL || 'https://example.realadvisor.site' }),
|
|
83
|
+
integrations: [keepReferencedAssets()],
|
|
84
|
+
// host: the sandbox preview URL reaches the dev server on every interface.
|
|
85
|
+
// No port: the site's `astro dev --port` decides (default 4321).
|
|
86
|
+
server: { host: true },
|
|
87
|
+
// Keeps the dev toolbar out of screenshots and the CRM preview.
|
|
88
|
+
devToolbar: { enabled: false },
|
|
89
|
+
env: {
|
|
90
|
+
schema: {
|
|
91
|
+
SITES_API_URL: { type: 'string', context: 'server', access: 'public', optional: true },
|
|
92
|
+
SITES_API_KEY: { type: 'string', context: 'server', access: 'secret', optional: true },
|
|
93
|
+
SITES_FIXTURE: { type: 'string', context: 'server', access: 'public', optional: true },
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
vite: {
|
|
97
|
+
plugins: [sitesKitVite(config.root)],
|
|
98
|
+
// Sandbox previews are served on *.vercel.run; without this Vite answers 403 "Blocked request".
|
|
99
|
+
server: { allowedHosts: true },
|
|
100
|
+
// The kit ships TypeScript and .astro sources: Vite compiles them like the site's own.
|
|
101
|
+
ssr: { noExternal: [PKG, CORE] },
|
|
102
|
+
optimizeDeps: { exclude: [PKG, CORE] },
|
|
103
|
+
// Never inline <script> bundles: the CSP has no 'unsafe-inline' for scripts, so every
|
|
104
|
+
// script is a /_astro/*.js file ('self'). Other assets keep Vite's default limit.
|
|
105
|
+
build: { assetsInlineLimit: (file) => (file.endsWith('.js') ? false : undefined) },
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
'astro:config:done': ({ injectTypes }) => {
|
|
110
|
+
injectTypes({ filename: 'sites-kit.d.ts', content: TYPES });
|
|
111
|
+
},
|
|
112
|
+
'astro:build:done': ({ dir }) => {
|
|
113
|
+
// Preview-safe frame-ancestors: static files are shared by preview and production builds.
|
|
114
|
+
const lines = Object.entries(securityHeaders(true)).map(([k, v]) => ` ${k}: ${v}`);
|
|
115
|
+
writeFileSync(
|
|
116
|
+
new URL('_headers', dir),
|
|
117
|
+
`/*\n${lines.join('\n')}\n strict-transport-security: max-age=31536000; includeSubDomains\n`,
|
|
118
|
+
);
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Minimal analytics consent banner. Base.astro renders it only when
|
|
4
|
+
* ANALYTICS_ID (GA4 measurement id) is set; without it the site sets no
|
|
5
|
+
* analytics cookie and shows no banner. Analytics loads only after "Accept".
|
|
6
|
+
* Restyle with tokens; keep both buttons equal in weight.
|
|
7
|
+
*/
|
|
8
|
+
import { t, lang, privacyPath } from '@realadvisor/sites-kit-core/i18n';
|
|
9
|
+
import '@realadvisor/sites-kit-core/styles/form.css';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
analyticsId: string;
|
|
13
|
+
/** Page locale (Base passes its own). */
|
|
14
|
+
locale?: string;
|
|
15
|
+
}
|
|
16
|
+
const { analyticsId, locale } = Astro.props;
|
|
17
|
+
const l = locale ? lang(locale) : lang();
|
|
18
|
+
---
|
|
19
|
+
<div class="consent" role="region" aria-label="Cookies" hidden data-consent={analyticsId}>
|
|
20
|
+
<p>{t('consentText', {}, l)} <a href={privacyPath(locale)}>{t('privacyLink', {}, l)}</a></p>
|
|
21
|
+
<div class="consent-actions">
|
|
22
|
+
<button type="button" class="btn btn--secondary" data-choice="denied">{t('decline', {}, l)}</button>
|
|
23
|
+
<button type="button" class="btn btn--secondary" data-choice="granted">{t('accept', {}, l)}</button>
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
<style is:global>
|
|
27
|
+
.consent { position: fixed; z-index: 50; inset: auto 16px 16px 16px; max-width: 560px; display: grid; gap: 12px; padding: 16px; background: var(--bg, #fff); color: var(--text, #111); border: 1px solid var(--line, #ddd); border-radius: var(--radius-card, 8px); box-shadow: 0 8px 24px rgb(0 0 0 / .12); font-size: 0.9375rem; }
|
|
28
|
+
.consent p { margin: 0; }
|
|
29
|
+
.consent a { color: inherit; }
|
|
30
|
+
.consent-actions { display: flex; gap: 8px; flex-wrap: wrap; }
|
|
31
|
+
.consent-actions .btn { flex: 1; }
|
|
32
|
+
</style>
|
|
33
|
+
<script>
|
|
34
|
+
import '@realadvisor/sites-kit-core/client/consent';
|
|
35
|
+
</script>
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* THE enquiry form. Every form that sends a message to the agency uses this
|
|
4
|
+
* component (contact page, listing detail, valuation, agent page). Never build
|
|
5
|
+
* another form, never post to a third-party form service, never use mailto.
|
|
6
|
+
*
|
|
7
|
+
* <EnquiryForm listingId={listing.id} agentId={listing.agent?.id}
|
|
8
|
+
* agentName={listing.agent?.first_name} message={`… (réf. ${listing.id})`} />
|
|
9
|
+
* <EnquiryForm contactReason="valuation" id="valuation" />
|
|
10
|
+
* <EnquiryForm developmentId={dev.id} units={unitOptions(dev.units)} /> development page
|
|
11
|
+
* <EnquiryForm developmentId={dev.id} lotId={unit.id} /> one unit of it
|
|
12
|
+
*
|
|
13
|
+
* Posts to /api/enquiry. Works without JS (303 back to the page with
|
|
14
|
+
* ?enquiry=sent|preview|error). With JS: inline validation, "sending" state,
|
|
15
|
+
* success / preview / error replace or top the form. Each submission carries
|
|
16
|
+
* an idempotencyKey (made at render, fresh per page view with JS, kept on a
|
|
17
|
+
* retry): a double click or a retry never makes a second enquiry, and the
|
|
18
|
+
* button stays disabled while sending. Style it with the form
|
|
19
|
+
* tokens; do not change its fields or script.
|
|
20
|
+
*
|
|
21
|
+
* Bot protection: a Cloudflare Turnstile widget (site key from rest-api,
|
|
22
|
+
* `turnstileSiteKey()` in lib/ra.ts; invisible unless Cloudflare wants an
|
|
23
|
+
* interaction), loaded when the form comes into view. Its token goes as
|
|
24
|
+
* `turnstileToken`; rest-api verifies it. Tokens are single use: the widget
|
|
25
|
+
* is reset after a failed send. Preview sites render none (they never send);
|
|
26
|
+
* fixture mode renders a stand-in that never loads Turnstile. Never add another
|
|
27
|
+
* captcha or a honeypot. Without JavaScript there is no token: the enquiry is
|
|
28
|
+
* refused (?enquiry=error).
|
|
29
|
+
*/
|
|
30
|
+
import Input from './form/Input.astro';
|
|
31
|
+
import Button from './form/Button.astro';
|
|
32
|
+
import Select from './form/Select.astro';
|
|
33
|
+
import { t as tr, lang, localeOfPath, privacyPath, type StringKey } from '@realadvisor/sites-kit-core/i18n';
|
|
34
|
+
import { FIXTURE_TURNSTILE_SITE_KEY } from '@realadvisor/sites-sdk';
|
|
35
|
+
import { turnstileSiteKey } from '../lib/ra';
|
|
36
|
+
import { siteMode } from '@realadvisor/sites-kit-core/env';
|
|
37
|
+
|
|
38
|
+
interface Props {
|
|
39
|
+
/** Unique per page when the page has two forms. */
|
|
40
|
+
id?: string;
|
|
41
|
+
listingId?: string;
|
|
42
|
+
agentId?: string;
|
|
43
|
+
/** First name shown in the success message ("Marie will get back to you"). */
|
|
44
|
+
agentName?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Enquiry about a development (`dev.id`): the CRM links it to the
|
|
47
|
+
* development and sends it to its broker. Never name the development in
|
|
48
|
+
* `message` instead.
|
|
49
|
+
*/
|
|
50
|
+
developmentId?: string;
|
|
51
|
+
/** One unit (`unit.id`) of `developmentId`: the CRM files it on that unit. */
|
|
52
|
+
lotId?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Without lotId: the units a visitor can ask about (`unitOptions(dev.units)`
|
|
55
|
+
* in lib/developments.ts), shown as a REQUIRED select: every development
|
|
56
|
+
* enquiry is filed on a unit (the CRM counts it per development).
|
|
57
|
+
* `selectedUnit` preselects one (?lot=<id>). No enquirable unit (all sold,
|
|
58
|
+
* none published): the form sends the development alone.
|
|
59
|
+
*/
|
|
60
|
+
units?: Array<{ value: string; label: string }>;
|
|
61
|
+
selectedUnit?: string;
|
|
62
|
+
/** Only without listingId / lotId. Default for a development: `buy`. */
|
|
63
|
+
contactReason?: 'buy' | 'sell' | 'valuation' | 'other';
|
|
64
|
+
/** Prefilled message. */
|
|
65
|
+
message?: string;
|
|
66
|
+
/** Submit label. Default: "Envoyer ma demande" in the site language. */
|
|
67
|
+
submitLabel?: string;
|
|
68
|
+
/** Page locale on a multi-language site (e.g. 'en-CH'). Default: from the URL (`/en/...`). */
|
|
69
|
+
locale?: string;
|
|
70
|
+
class?: string;
|
|
71
|
+
}
|
|
72
|
+
if (Astro.isPrerendered && import.meta.env.PROD) {
|
|
73
|
+
// Preview mode is read per request: the page must render on request.
|
|
74
|
+
throw new Error(`EnquiryForm on ${Astro.url.pathname}: add \`export const prerender = false\` to the page.`);
|
|
75
|
+
}
|
|
76
|
+
const { id = 'enquiry', listingId, agentId, agentName, developmentId, lotId, units, selectedUnit, message, submitLabel, class: cls } = Astro.props;
|
|
77
|
+
const contactReason = Astro.props.contactReason ?? (developmentId ? 'buy' : undefined);
|
|
78
|
+
const locale = Astro.props.locale ?? localeOfPath(Astro.url.pathname);
|
|
79
|
+
const t = (key: StringKey, vars: Record<string, string> = {}) => tr(key, vars, lang(locale));
|
|
80
|
+
const success = agentName ? t('sentBy', { name: agentName }) : t('sent');
|
|
81
|
+
const f = (name: string) => `${id}-${name}`;
|
|
82
|
+
// A development form without lotId must choose a unit while the development has one to ask about.
|
|
83
|
+
const unitSelect = !!developmentId && !lotId && !!units && units.length > 0;
|
|
84
|
+
// Preview sites never send: no widget there.
|
|
85
|
+
const siteKey = siteMode() === 'preview' ? null : await turnstileSiteKey();
|
|
86
|
+
---
|
|
87
|
+
<div class:list={['enquiry', cls]} id={id} data-enquiry>
|
|
88
|
+
<p class="enquiry-status" role="status" aria-live="polite" tabindex="-1" hidden data-status></p>
|
|
89
|
+
<form
|
|
90
|
+
method="post"
|
|
91
|
+
action="/api/enquiry"
|
|
92
|
+
novalidate
|
|
93
|
+
data-msg-sent={success}
|
|
94
|
+
data-msg-preview={t('preview')}
|
|
95
|
+
data-msg-error={t('error')}
|
|
96
|
+
data-msg-required={t('required')}
|
|
97
|
+
data-msg-email={t('invalidEmail')}
|
|
98
|
+
data-msg-unit={t('unitRequired')}
|
|
99
|
+
data-msg-sending={t('sending')}
|
|
100
|
+
data-msg-verify={t('verifyFailed')}
|
|
101
|
+
data-msg-rejected={t('rejected')}
|
|
102
|
+
>
|
|
103
|
+
{listingId && <input type="hidden" name="listingId" value={listingId} />}
|
|
104
|
+
{agentId && <input type="hidden" name="agentId" value={agentId} />}
|
|
105
|
+
{developmentId && <input type="hidden" name="developmentId" value={developmentId} />}
|
|
106
|
+
{developmentId && lotId && <input type="hidden" name="lotId" value={lotId} />}
|
|
107
|
+
{!listingId && !lotId && contactReason && <input type="hidden" name="contactReason" value={contactReason} />}
|
|
108
|
+
<input type="hidden" name="locale" value={locale} />
|
|
109
|
+
<input type="hidden" name="idempotencyKey" value={crypto.randomUUID()} data-idempotency />
|
|
110
|
+
<input type="hidden" name="redirect" value={`#${id}`} data-redirect />
|
|
111
|
+
<div class="enquiry-grid">
|
|
112
|
+
<div>
|
|
113
|
+
<Input id={f('name')} label={`${t('name')} *`} name="name" required maxlength={100} autocomplete="name" aria-describedby={f('name-err')} />
|
|
114
|
+
<p class="field-error" id={f('name-err')} hidden></p>
|
|
115
|
+
</div>
|
|
116
|
+
<div>
|
|
117
|
+
<Input id={f('email')} label={`${t('email')} *`} name="email" type="email" required maxlength={200} autocomplete="email" aria-describedby={f('email-err')} />
|
|
118
|
+
<p class="field-error" id={f('email-err')} hidden></p>
|
|
119
|
+
</div>
|
|
120
|
+
<div>
|
|
121
|
+
<Input id={f('phone')} label={`${t('phone')} ${t('optional')}`} name="phone" type="tel" maxlength={40} autocomplete="tel" />
|
|
122
|
+
</div>
|
|
123
|
+
{unitSelect && (
|
|
124
|
+
<div class="enquiry-full">
|
|
125
|
+
<Select id={f('lot')} label={`${t('unitOfInterest')} *`} name="lotId" options={units!} value={selectedUnit} placeholder={t('chooseUnit')} required aria-describedby={f('lot-err')} />
|
|
126
|
+
<p class="field-error" id={f('lot-err')} hidden></p>
|
|
127
|
+
</div>
|
|
128
|
+
)}
|
|
129
|
+
<div class="enquiry-full">
|
|
130
|
+
<Input id={f('message')} label={`${t('message')} *`} name="message" multiline required maxlength={5000} value={message} aria-describedby={f('message-err')} />
|
|
131
|
+
<p class="field-error" id={f('message-err')} hidden></p>
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
{siteKey && (
|
|
135
|
+
<div
|
|
136
|
+
class="enquiry-turnstile"
|
|
137
|
+
data-turnstile={siteKey === FIXTURE_TURNSTILE_SITE_KEY ? 'fixture' : 'live'}
|
|
138
|
+
data-sitekey={siteKey}
|
|
139
|
+
data-lang={lang(locale)}
|
|
140
|
+
></div>
|
|
141
|
+
)}
|
|
142
|
+
<Button type="submit">{submitLabel ?? t('send')}</Button>
|
|
143
|
+
<p class="enquiry-note">{t('privacyNote')} <a href={privacyPath(locale)}>{t('privacyLink')}</a></p>
|
|
144
|
+
</form>
|
|
145
|
+
</div>
|
|
146
|
+
|
|
147
|
+
<script>
|
|
148
|
+
import '@realadvisor/sites-kit-core/client/enquiry';
|
|
149
|
+
</script>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Renders legal sections from lib/legal.ts. Style it with your tokens;
|
|
4
|
+
* never edit the text here or in the pages (AGENTS.md: legal text comes only
|
|
5
|
+
* from the template and agency data).
|
|
6
|
+
*/
|
|
7
|
+
import type { LegalSection } from '@realadvisor/sites-kit-core/legal';
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
sections: LegalSection[];
|
|
11
|
+
class?: string;
|
|
12
|
+
}
|
|
13
|
+
const { sections, class: cls } = Astro.props;
|
|
14
|
+
---
|
|
15
|
+
<div class:list={['legal', cls]}>
|
|
16
|
+
{sections.map((s) => (
|
|
17
|
+
<section>
|
|
18
|
+
<h2>{s.heading}</h2>
|
|
19
|
+
{s.rows && (
|
|
20
|
+
<dl>
|
|
21
|
+
{s.rows.map((r) => (
|
|
22
|
+
<div>
|
|
23
|
+
<dt>{r.label}</dt>
|
|
24
|
+
<dd>{r.href ? <a href={r.href}>{r.value}</a> : r.value}</dd>
|
|
25
|
+
</div>
|
|
26
|
+
))}
|
|
27
|
+
</dl>
|
|
28
|
+
)}
|
|
29
|
+
{s.paragraphs?.map((p) => <p>{p}</p>)}
|
|
30
|
+
</section>
|
|
31
|
+
))}
|
|
32
|
+
</div>
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Map search for /listings: every listing with coordinates on an OSM map,
|
|
4
|
+
* clustered markers, a popup card per marker, zoom buttons, drag / wheel /
|
|
5
|
+
* pinch / keyboard. Pass `list`: the id of the element that holds the
|
|
6
|
+
* result cards, each card with `data-listing-id={l.id}`; hovering a card
|
|
7
|
+
* highlights its marker and moving the map shows only the cards in view.
|
|
8
|
+
*
|
|
9
|
+
* <ListingsMap listings={all} list="results" />
|
|
10
|
+
* <ul id="results">{all.map((l) => <li data-listing-id={l.id}>…</li>)}</ul>
|
|
11
|
+
*
|
|
12
|
+
* Clicking a pin marks its cards `.is-selected` (style it) and scrolls the
|
|
13
|
+
* list to them. `view` ({ z, lat, lng }, e.g. from `?map=`) opens there
|
|
14
|
+
* instead of fitting the listings; `sync` writes the visitor's view back
|
|
15
|
+
* into the URL (`?map=z/lat/lng`, replaceState). Each list-filtering move
|
|
16
|
+
* dispatches a bubbling `ra:map-area` event ({ count, total, all? }).
|
|
17
|
+
* Maps swapped in later: `mountMaps(el)` from @realadvisor/sites-kit-core/client/listings-map.ts.
|
|
18
|
+
*
|
|
19
|
+
* No library, no iframe, no inline script (@realadvisor/sites-kit-core/client/listings-map.ts is
|
|
20
|
+
* bundled; data goes through data-* attributes). Tiles come from
|
|
21
|
+
* tile.openstreetmap.org, the only map host the CSP allows. Restyle with
|
|
22
|
+
* tokens (--accent, --text, --paper); height: `--map-h` on a parent
|
|
23
|
+
* (default 60vh). Keep the attribution.
|
|
24
|
+
*/
|
|
25
|
+
import type { Listing } from '../lib/ra';
|
|
26
|
+
import { formatPrice, listingUrl } from '@realadvisor/sites-kit-core/format';
|
|
27
|
+
import { img } from '@realadvisor/sites-kit-core/image';
|
|
28
|
+
import { localePath, lang, pluralForms, propertyTypeLabel, t } from '@realadvisor/sites-kit-core/i18n';
|
|
29
|
+
|
|
30
|
+
interface Props {
|
|
31
|
+
listings: Listing[];
|
|
32
|
+
/** id of the list whose cards (`data-listing-id`) follow the map. */
|
|
33
|
+
list?: string;
|
|
34
|
+
/** Page locale on a multi-language site (e.g. 'en-CH'). */
|
|
35
|
+
locale?: string;
|
|
36
|
+
/** First view (zoom, centre) instead of fitting the listings. */
|
|
37
|
+
view?: { z: number; lat: number; lng: number };
|
|
38
|
+
/** Keep the visitor's view in the URL as `?map=z/lat/lng`. */
|
|
39
|
+
sync?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* `server`: the page filters its list by the map area (ListingsSearch does,
|
|
42
|
+
* with `?bbox=`); the map only reports its bounds in `ra:map-area`.
|
|
43
|
+
* Default: the map hides the cards outside its view.
|
|
44
|
+
*/
|
|
45
|
+
listMode?: 'client' | 'server';
|
|
46
|
+
/** Listing URL (default: `/listings/<slug>` in the page language). */
|
|
47
|
+
href?: (l: Listing) => string;
|
|
48
|
+
/** Popup price (default: `formatPrice`), e.g. a replica's "CHF 1'250'000.–". */
|
|
49
|
+
price?: (l: Listing) => string;
|
|
50
|
+
class?: string;
|
|
51
|
+
}
|
|
52
|
+
const { listings, list, locale, view, sync, listMode, href, price, class: cls } = Astro.props;
|
|
53
|
+
const l = lang(locale);
|
|
54
|
+
const points = listings
|
|
55
|
+
.filter((x) => x.address.lat != null && x.address.lng != null)
|
|
56
|
+
.map((x) => ({
|
|
57
|
+
id: x.id,
|
|
58
|
+
lat: x.address.lat,
|
|
59
|
+
lng: x.address.lng,
|
|
60
|
+
url: href ? href(x) : localePath(listingUrl(x), locale),
|
|
61
|
+
title: x.title,
|
|
62
|
+
// The popup's eyebrow: the property type in the page language ("Attique"), never a generic "Bien".
|
|
63
|
+
type: propertyTypeLabel(x.property_type, locale),
|
|
64
|
+
price: price ? price(x) : formatPrice(x),
|
|
65
|
+
photo: x.photos[0]?.url ? img(x.photos[0].url, { w: 320, h: 213 }) : undefined,
|
|
66
|
+
}));
|
|
67
|
+
const labels = {
|
|
68
|
+
lang: l,
|
|
69
|
+
inArea: pluralForms('inArea', l),
|
|
70
|
+
listings: pluralForms('listings', l),
|
|
71
|
+
showAll: t('showAll', {}, l),
|
|
72
|
+
close: t('close', {}, l),
|
|
73
|
+
};
|
|
74
|
+
---
|
|
75
|
+
<div class:list={['ra-map', cls]} data-ra-map data-points={JSON.stringify(points)} data-labels={JSON.stringify(labels)} data-list={list} data-view={view ? JSON.stringify(view) : undefined} data-sync={sync || undefined} data-list-mode={listMode === 'server' ? 'server' : undefined}>
|
|
76
|
+
<div class="ra-map-viewport" data-map-viewport tabindex="0" role="application" aria-label={t('mapLabel', {}, l)} aria-roledescription="map">
|
|
77
|
+
<div class="ra-map-tiles" data-map-tiles aria-hidden="true"></div>
|
|
78
|
+
<div class="ra-map-markers" data-map-markers></div>
|
|
79
|
+
<div class="ra-map-popup" data-map-popup></div>
|
|
80
|
+
</div>
|
|
81
|
+
<div class="ra-map-status" data-map-status role="status">
|
|
82
|
+
<span data-map-count></span>
|
|
83
|
+
<button type="button">{t('showAll', {}, l)}</button>
|
|
84
|
+
</div>
|
|
85
|
+
<div class="ra-map-zoom">
|
|
86
|
+
<button type="button" data-map-zoom="1" aria-label={t('zoomIn', {}, l)}>+</button>
|
|
87
|
+
<button type="button" data-map-zoom="-1" aria-label={t('zoomOut', {}, l)}>−</button>
|
|
88
|
+
</div>
|
|
89
|
+
<p class="ra-map-attr">© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">{t('osmContributors', {}, l)}</a></p>
|
|
90
|
+
</div>
|
|
91
|
+
|
|
92
|
+
<script>
|
|
93
|
+
import '@realadvisor/sites-kit-core/client/listings-map';
|
|
94
|
+
</script>
|
|
95
|
+
|
|
96
|
+
<style>
|
|
97
|
+
/* overflow-anchor: tiles and markers come and go; the browser must not anchor the page scroll on them (the page jumped on zoom). */
|
|
98
|
+
.ra-map { position: relative; overflow: hidden; height: var(--map-h, 60vh); min-height: 320px; background: #f2f0ec; touch-action: none; overflow-anchor: none; }
|
|
99
|
+
.ra-map-viewport { position: absolute; inset: 0; cursor: grab; outline-offset: -3px; }
|
|
100
|
+
.ra-map-viewport:active { cursor: grabbing; }
|
|
101
|
+
.ra-map-tiles { position: absolute; inset: 0; filter: grayscale(1) sepia(.18) contrast(.92) brightness(1.06); }
|
|
102
|
+
.ra-map-tiles :global(img) { position: absolute; left: 0; top: 0; width: 256px; height: 256px; max-width: none; user-select: none; -webkit-user-drag: none; opacity: 0; transition: opacity .2s; }
|
|
103
|
+
.ra-map-tiles :global(img.is-loaded) { opacity: 1; }
|
|
104
|
+
.ra-map-markers { position: absolute; inset: 0; pointer-events: none; }
|
|
105
|
+
.ra-map-markers :global(button) {
|
|
106
|
+
position: absolute; left: 0; top: 0; pointer-events: auto; cursor: pointer; border: 2px solid var(--paper, #fff);
|
|
107
|
+
background: var(--accent, #134266); color: var(--paper, #fff); font: 600 14px/1 system-ui, sans-serif;
|
|
108
|
+
box-shadow: 0 2px 6px rgb(0 0 0 / .3); transition: background .15s, scale .15s; will-change: translate;
|
|
109
|
+
}
|
|
110
|
+
/* A 22px dot inside a 44px (invisible) touch target. */
|
|
111
|
+
.ra-map-markers :global(.ra-map-pin) { width: 44px; height: 44px; margin: -22px 0 0 -22px; padding: 0; border: 0; border-radius: 50%; background: none; box-shadow: none; }
|
|
112
|
+
.ra-map-markers :global(.ra-map-pin)::after { content: ''; position: absolute; inset: 11px; border: 2px solid var(--paper, #fff); border-radius: 50%; background: var(--accent, #134266); box-shadow: 0 2px 6px rgb(0 0 0 / .3); transition: background .15s; }
|
|
113
|
+
/* Clusters grow with their count and carry a soft halo (as on most portals). */
|
|
114
|
+
.ra-map-markers :global(.ra-map-cluster) {
|
|
115
|
+
--d: 36px; min-width: var(--d); height: var(--d); margin: calc(var(--d) / -2) 0 0 calc(var(--d) / -2); border-radius: 999px; padding: 0 8px;
|
|
116
|
+
box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent, #134266) 22%, transparent), 0 2px 6px rgb(0 0 0 / .3);
|
|
117
|
+
}
|
|
118
|
+
.ra-map-markers :global(.ra-map-cluster.is-m) { --d: 44px; }
|
|
119
|
+
.ra-map-markers :global(.ra-map-cluster.is-l) { --d: 52px; font-size: 15px; }
|
|
120
|
+
.ra-map-markers :global(button:hover), .ra-map-markers :global(button.is-active), .ra-map-markers :global(button.is-selected), .ra-map-markers :global(button:focus-visible) { scale: 1.15; z-index: 1; }
|
|
121
|
+
.ra-map-markers :global(.ra-map-cluster:hover), .ra-map-markers :global(.ra-map-cluster.is-active), .ra-map-markers :global(.ra-map-cluster:focus-visible),
|
|
122
|
+
.ra-map-markers :global(.ra-map-pin:hover)::after, .ra-map-markers :global(.ra-map-pin.is-active)::after, .ra-map-markers :global(.ra-map-pin.is-selected)::after, .ra-map-markers :global(.ra-map-pin:focus-visible)::after { background: var(--text, #1c1b19); }
|
|
123
|
+
/* Placed by the script: above or below its marker, clear of the edges and the zoom buttons. */
|
|
124
|
+
.ra-map-popup {
|
|
125
|
+
position: absolute; left: 0; top: 0; z-index: 4; width: min(260px, calc(100% - 16px)); max-height: min(340px, calc(100% - 16px)); overflow: auto;
|
|
126
|
+
background: var(--paper, #fff); color: var(--text, #1c1b19); box-shadow: 0 6px 20px rgb(0 0 0 / .25); cursor: auto;
|
|
127
|
+
visibility: hidden; pointer-events: none; opacity: 0;
|
|
128
|
+
}
|
|
129
|
+
.ra-map-popup:global(.is-open) { visibility: visible; pointer-events: auto; opacity: 1; }
|
|
130
|
+
.ra-map-popup :global(.ra-map-card) { display: grid; gap: 4px; padding: 0 0 12px; color: inherit; text-decoration: none; }
|
|
131
|
+
.ra-map-popup :global(.ra-map-card + .ra-map-card) { border-top: 1px solid var(--line, #d6d3cf); padding-top: 12px; }
|
|
132
|
+
.ra-map-popup :global(.ra-map-card img) { width: 100%; height: auto; aspect-ratio: 3 / 2; object-fit: cover; }
|
|
133
|
+
.ra-map-popup :global(.ra-map-card-type), .ra-map-popup :global(.ra-map-card-title), .ra-map-popup :global(.ra-map-card-price) { padding: 0 12px; }
|
|
134
|
+
.ra-map-popup :global(.ra-map-card-type) { font-size: 12px; letter-spacing: .04em; text-transform: uppercase; opacity: .75; }
|
|
135
|
+
.ra-map-popup :global(.ra-map-card-price) { font-weight: 600; }
|
|
136
|
+
.ra-map-popup :global(.ra-map-close) { position: sticky; top: 4px; float: right; margin: 4px 4px -48px 0; width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgb(255 255 255 / .9); color: #1c1b19; font-size: 22px; cursor: pointer; z-index: 1; }
|
|
137
|
+
.ra-map-status {
|
|
138
|
+
position: absolute; left: 12px; top: 12px; z-index: 3; display: flex; gap: 12px; align-items: center; padding: 6px 6px 6px 14px;
|
|
139
|
+
background: var(--paper, #fff); box-shadow: 0 2px 8px rgb(0 0 0 / .2); visibility: hidden; pointer-events: none; opacity: 0;
|
|
140
|
+
}
|
|
141
|
+
/* Only its button takes clicks: the markers under the pill stay reachable. */
|
|
142
|
+
.ra-map-status:global(.is-open) { visibility: visible; opacity: 1; }
|
|
143
|
+
.ra-map-status:global(.is-open) button { pointer-events: auto; }
|
|
144
|
+
.ra-map-status button, .ra-map-zoom button { min-height: 44px; min-width: 44px; border: 0; background: var(--paper, #fff); color: var(--text, #1c1b19); font: inherit; cursor: pointer; }
|
|
145
|
+
.ra-map-status button { text-decoration: underline; }
|
|
146
|
+
.ra-map-zoom { position: absolute; right: 12px; top: 12px; z-index: 3; display: grid; box-shadow: 0 2px 8px rgb(0 0 0 / .2); }
|
|
147
|
+
.ra-map-zoom button { font-size: 22px; }
|
|
148
|
+
.ra-map-zoom button:disabled { color: #999; cursor: default; }
|
|
149
|
+
.ra-map-zoom button + button { border-top: 1px solid var(--line, #d6d3cf); }
|
|
150
|
+
.ra-map-attr { position: absolute; right: 0; bottom: 0; z-index: 3; margin: 0; padding: 2px 6px; font-size: 11px; color: #444; background: rgb(255 255 255 / .8); }
|
|
151
|
+
.ra-map-attr a { color: inherit; }
|
|
152
|
+
@media (prefers-reduced-motion: reduce) { .ra-map-markers :global(button), .ra-map-markers :global(.ra-map-pin)::after, .ra-map-tiles :global(img) { transition: none; } }
|
|
153
|
+
</style>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Numbered pages of ListingsSearch (1 … 4 5 6 … 12, prev / next with `rel`).
|
|
4
|
+
* Rendered by ListingsSearch only: under the grid, or under the cards
|
|
5
|
+
* column of the map view. Styled there (`.rs-pager`).
|
|
6
|
+
*/
|
|
7
|
+
import { pageList, type SearchResult } from '@realadvisor/sites-kit-core/search';
|
|
8
|
+
import { LOCALE } from '@realadvisor/sites-kit-core/format';
|
|
9
|
+
import { lang, t } from '@realadvisor/sites-kit-core/i18n';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
result: SearchResult;
|
|
13
|
+
href: (over: { page?: number }) => string;
|
|
14
|
+
locale?: string;
|
|
15
|
+
}
|
|
16
|
+
const { result, href, locale = LOCALE } = Astro.props;
|
|
17
|
+
const l = lang(locale);
|
|
18
|
+
const pages = pageList(result.page, result.pages);
|
|
19
|
+
---
|
|
20
|
+
{result.pages > 1 && result.total > 0 && (
|
|
21
|
+
<nav class="rs-pager" data-rs-pager aria-label={t('pagination', {}, l)}>
|
|
22
|
+
{result.page > 1 ? <a class="rs-step" href={href({ page: result.page - 1 > 1 ? result.page - 1 : undefined })} rel="prev" data-rs-nav>‹ <span>{t('prevPage', {}, l)}</span></a> : <span class="rs-step" aria-hidden="true"></span>}
|
|
23
|
+
<ol>
|
|
24
|
+
{pages.map((n) => n == null ? <li class="rs-gap" aria-hidden="true">…</li> : (
|
|
25
|
+
<li><a href={href({ page: n > 1 ? n : undefined })} data-rs-nav aria-current={n === result.page ? 'page' : undefined} aria-label={`${t('page', {}, l)} ${n}`}>{n}</a></li>
|
|
26
|
+
))}
|
|
27
|
+
</ol>
|
|
28
|
+
{result.page < result.pages ? <a class="rs-step" href={href({ page: result.page + 1 })} rel="next" data-rs-nav><span>{t('nextPage', {}, l)}</span> ›</a> : <span class="rs-step" aria-hidden="true"></span>}
|
|
29
|
+
</nav>
|
|
30
|
+
)}
|
|
31
|
+
|
|
32
|
+
<style>
|
|
33
|
+
.rs-pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--rs-line); }
|
|
34
|
+
.rs-pager ol { display: flex; gap: 4px; list-style: none; margin: 0; padding: 0; }
|
|
35
|
+
.rs-pager a, .rs-gap { display: grid; place-items: center; min-width: 44px; height: 44px; color: var(--rs-ink); text-decoration: none; font-variant-numeric: tabular-nums; border-radius: var(--control-radius, 8px); }
|
|
36
|
+
.rs-pager a:hover { background: color-mix(in srgb, var(--rs-ink) 6%, transparent); }
|
|
37
|
+
.rs-pager a[aria-current] { background: var(--rs-on); color: var(--rs-on-ink); }
|
|
38
|
+
.rs-step { display: inline-flex !important; gap: 6px; padding: 0 12px; min-width: 96px; }
|
|
39
|
+
.rs-step:last-child { justify-content: end; }
|
|
40
|
+
@media (max-width: 639px) {
|
|
41
|
+
.rs-step span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
|
|
42
|
+
.rs-step { min-width: 44px; padding: 0; }
|
|
43
|
+
.rs-pager ol li:not(:has([aria-current])):not(:first-child):not(:last-child) { display: none; }
|
|
44
|
+
}
|
|
45
|
+
</style>
|