@bygghammar/cms-platform 0.11.0 → 0.13.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/migrations/20260728113741_f9744b19-078b-46e5-b00f-31c84aaf71ab.sql +111 -0
- package/migrations/20260728113757_4156a886-21fb-4a1f-9c12-acb7bb145102.sql +5 -0
- package/migrations/20260728113823_6e0237e1-99e3-4e1a-8a68-804b7bcdbbb8.sql +1 -0
- package/migrations/20260728115305_506d92b4-129f-4d2b-961f-cf76e592677e.sql +92 -0
- package/migrations/20260728115320_717d4447-f433-4a1d-89d2-fc8f028d4ac6.sql +1 -0
- package/migrations/20260728115347_c77f5a56-19db-4117-bb60-9ad692b817ab.sql +11 -0
- package/migrations/20260728132052_b692dcfe-a944-4a19-afd0-187f7600feb8.sql +63 -0
- package/migrations/20260728183318_05b05a47-ba05-4a66-ab8f-69f2688fea84.sql +209 -0
- package/migrations/20260728193035_84b68d27-c3f3-4516-a3a9-15fc6f476163.sql +17 -0
- package/migrations/20260728193707_8438ee2d-d589-4048-86e2-464fd209af80.sql +37 -0
- package/migrations/20260729055312_08862d7e-0279-4d4f-8709-a59b9f068c55.sql +5 -0
- package/migrations/20260729055348_418b7e36-4877-4304-831f-290ca73e56f3.sql +133 -0
- package/migrations/20260729055358_20b467e2-4efd-42c1-bd34-773ed6b77fc5.sql +3 -0
- package/migrations/20260729061039_306859eb-a38c-44ef-af1a-6c02a8fd84db.sql +43 -0
- package/migrations/20260730065600_54c25861-3355-4600-a72f-3d67b457ecb1.sql +54 -0
- package/migrations/20260730071745_d4904314-15ff-4c58-ac66-85e7371e04b5.sql +113 -0
- package/migrations/20260730071914_48163aa3-830e-4dcc-bdd4-c35be282ab87.sql +22 -0
- package/migrations/20260730085949_bcfc3270-ea80-4617-86a3-2555ed34a280.sql +24 -0
- package/migrations/20260730095256_c977c30e-b285-4041-8804-c0bd72b6d9b3.sql +13 -0
- package/migrations/20260730100057_e341b887-eb0e-4a74-850e-0ee5ffb70d7a.sql +38 -0
- package/migrations/20260730103703_d5c4e1b7-1e2c-4dd0-be4e-185c159ade69.sql +62 -0
- package/migrations/20260730105635_3557b7da-919e-48db-8c92-8221d68d3cf9.sql +29 -0
- package/migrations/20260730120308_12ff8cfb-43f9-4070-abde-61531ad3b75f.sql +73 -0
- package/migrations/20260730125024_1baf8926-12a2-48f4-8edc-7309941309e9.sql +18 -0
- package/migrations/20260730173510_feb974d1-510e-4f52-9e20-5fd0582d8952.sql +107 -0
- package/migrations/20260730175409_9f60743f-f5e1-418c-a700-c91fb3704db8.sql +9 -0
- package/migrations/20260730181224_1c52ff16-c7a2-4ef1-a0a8-e493c2c9106f.sql +7 -0
- package/migrations/20260730183129_933adb75-f985-4d82-ad5d-213b69fd42e5.sql +32 -0
- package/migrations/20260730183918_7bc7a827-2100-49f1-bc6e-24509249350b.sql +68 -0
- package/migrations/20260730202628_7ceade5e-644c-4bc2-91b8-594133329f31.sql +1 -0
- package/migrations/20260730211056_57f42049-00b4-473b-a2cd-65a13570b8d2.sql +16 -0
- package/migrations/20260730214340_98af2e55-9031-4c11-9659-c47a37a8d6b7.sql +1 -0
- package/migrations/20260731091630_8a6f28ce-5833-4901-ab17-27648cef32ec.sql +149 -0
- package/migrations/20260731094716_4c68a1df-83ed-4ba8-8019-fa2fe2b9681e.sql +65 -0
- package/migrations/20260731191655_fef97c3c-1397-47b4-8b56-afb020298e97.sql +165 -0
- package/migrations/20260731192212_95772a2f-19a1-4013-b463-2eb161e96737.sql +135 -0
- package/migrations/20260731192815_c490653e-1232-4ad9-a150-3c83d2b90f5e.sql +13 -0
- package/migrations/20260731193135_7966e740-5e86-4b14-8e1d-5119069666ba.sql +2 -0
- package/migrations/20260731193245_599790d0-ca5e-4b5d-a3e7-d69b2a79e1a3.sql +13 -0
- package/migrations/20260731212959_a748cb0d-4dc7-45dc-be90-f6bacbfab26c.sql +9 -0
- package/migrations/20260801003057_1195f4c1-fb54-42dc-9718-638a25e6a82e.sql +3 -0
- package/migrations/20260801003300_fc591960-cb41-41cf-837d-2eef23b29ca9.sql +40 -0
- package/migrations/20260802151445_a56b0023-eaf7-41e2-a7fb-d4beddfc587c.sql +3 -0
- package/migrations/20260802202621_d661af8a-8513-4b54-b375-f963ae824c8f.sql +225 -0
- package/migrations/20260802202702_c30cd837-744c-4641-85f1-edd3a7ebbcb6.sql +16 -0
- package/migrations/20260802202720_4418d18d-c851-42dc-9345-78fc330128ae.sql +2 -0
- package/migrations/20260803132514_78ba1f53-c85b-4457-96b1-7d49c5c8b494.sql +34 -0
- package/migrations/20260803181201_28c8aa09-baa8-431c-8338-90b1af9c8172.sql +22 -0
- package/migrations/20260803201518_6e8a6028-b70f-4a7d-8bc9-95c86304e7ae.sql +12 -0
- package/migrations/20260803201535_32a9a213-cb92-4035-b8cd-8211ca34af68.sql +12 -0
- package/migrations/20260811103505_29df753d-14fa-4a05-8fea-f4207785fba3.sql +35 -0
- package/migrations/20260811112455_217c4028-f587-4c98-9e4f-9e6c452ab761.sql +20 -0
- package/migrations/20260811114438_6687d67d-bad3-4803-9638-8b7670d2e5d4.sql +86 -0
- package/migrations/20260811130318_7cb95e95-9baa-40af-8f3f-de1d4e09cec4.sql +1 -0
- package/migrations/20260811220548_80d99ec2-bd4b-475d-a627-9408bb60ce56.sql +1 -0
- package/migrations/20260811222519_6b040f56-4de3-49e0-92e4-d9deec5ead6a.sql +3 -0
- package/migrations/20260812000000_seed_voyara_content.sql +390 -0
- package/migrations/20260818040722_1bdf1b8f-7fb0-4ae8-8ecf-73f1fadff3c2.sql +2 -0
- package/migrations/20260818040808_69a5e832-57e8-4aa7-aff8-7fd7777faa7c.sql +15 -0
- package/migrations/20260818040839_e6523163-bbf5-4a39-9233-91759059569a.sql +26 -0
- package/package.json +9 -4
- package/src/backoffice/media/ReviewImageUpload.tsx +104 -0
- package/src/backoffice/seo/PageSeoPanelView.tsx +406 -0
- package/src/platform/contract.ts +92 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
DROP TABLE IF EXISTS public._mig_probe;
|
|
2
|
+
|
|
3
|
+
CREATE OR REPLACE VIEW public.forms_public
|
|
4
|
+
WITH (security_invoker = false, security_barrier = true) AS
|
|
5
|
+
SELECT f.id, f.key, f.name, f.form_type, f.fields, f.public_settings
|
|
6
|
+
FROM public.forms f
|
|
7
|
+
WHERE f.is_active = true AND f.deleted_at IS NULL;
|
|
8
|
+
|
|
9
|
+
GRANT SELECT ON public.forms_public TO anon, authenticated, service_role;
|
|
10
|
+
|
|
11
|
+
-- Lovable Cloud applies this operation through its sandbox_exec role. Fresh
|
|
12
|
+
-- self-hosted Supabase installations do not define that provider-specific role,
|
|
13
|
+
-- and the migration runner already connects as the PostgreSQL owner.
|
|
14
|
+
DROP POLICY IF EXISTS "forms public read active" ON public.forms;
|
|
15
|
+
REVOKE ALL ON public.forms FROM anon;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
DROP VIEW IF EXISTS public.forms_public;
|
|
2
|
+
|
|
3
|
+
CREATE OR REPLACE FUNCTION public.form_public_runtime(_key text)
|
|
4
|
+
RETURNS jsonb
|
|
5
|
+
LANGUAGE sql
|
|
6
|
+
STABLE SECURITY DEFINER
|
|
7
|
+
SET search_path TO ''
|
|
8
|
+
AS $function$
|
|
9
|
+
SELECT pg_catalog.jsonb_strip_nulls(
|
|
10
|
+
pg_catalog.jsonb_build_object(
|
|
11
|
+
'id', pg_catalog.to_jsonb(f.id),
|
|
12
|
+
'key', pg_catalog.to_jsonb(f.key),
|
|
13
|
+
'name', f.name,
|
|
14
|
+
'form_type', pg_catalog.to_jsonb(f.form_type),
|
|
15
|
+
'fields', f.fields,
|
|
16
|
+
'public_settings', f.public_settings,
|
|
17
|
+
'spamMinSeconds', f.private_settings -> 'spamMinSeconds',
|
|
18
|
+
'savePartials', f.private_settings -> 'savePartials'
|
|
19
|
+
)
|
|
20
|
+
)
|
|
21
|
+
FROM public.forms f
|
|
22
|
+
WHERE f.key = _key
|
|
23
|
+
AND f.is_active = true
|
|
24
|
+
AND f.deleted_at IS NULL
|
|
25
|
+
LIMIT 1
|
|
26
|
+
$function$;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bygghammar/cms-platform",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Shared CMS platform: blocks, block types, i18n core, UI primitives and design-token contract used by every Bygghammar/Voyara site.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
"access": "public"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
|
-
"
|
|
13
|
-
"
|
|
12
|
+
"README.md",
|
|
13
|
+
"migrations",
|
|
14
|
+
"src"
|
|
14
15
|
],
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|
|
@@ -90,7 +91,11 @@
|
|
|
90
91
|
"./backoffice/media/MediaMetaDialog": "./src/backoffice/media/MediaMetaDialog.tsx",
|
|
91
92
|
"./backoffice/SectionThumb": "./src/backoffice/SectionThumb.tsx",
|
|
92
93
|
"./backoffice/PageImagePicker": "./src/backoffice/PageImagePicker.tsx",
|
|
93
|
-
"./backoffice/seo/page-seo-form": "./src/backoffice/seo/page-seo-form.ts"
|
|
94
|
+
"./backoffice/seo/page-seo-form": "./src/backoffice/seo/page-seo-form.ts",
|
|
95
|
+
"./platform/contract": "./src/platform/contract.ts",
|
|
96
|
+
"./backoffice/media/ReviewImageUpload": "./src/backoffice/media/ReviewImageUpload.tsx",
|
|
97
|
+
"./migrations/*": "./migrations/*",
|
|
98
|
+
"./backoffice/seo/PageSeoPanelView": "./src/backoffice/seo/PageSeoPanelView.tsx"
|
|
94
99
|
},
|
|
95
100
|
"dependencies": {
|
|
96
101
|
"fflate": "^0.8.3"
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { useRef, useState } from "react";
|
|
2
|
+
import { Loader2, Upload } from "lucide-react";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
prepareReviewImage,
|
|
6
|
+
reviewImageSlug,
|
|
7
|
+
ACCEPTED_SOURCE_TYPES,
|
|
8
|
+
MAX_SOURCE_BYTES,
|
|
9
|
+
} from "../../media/review-image";
|
|
10
|
+
|
|
11
|
+
function humanBytes(n: number) {
|
|
12
|
+
if (n < 1024) return `${n} B`;
|
|
13
|
+
if (n < 1024 * 1024) return `${(n / 1024).toFixed(0)} KB`;
|
|
14
|
+
return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type ReviewImageUploadProps = {
|
|
18
|
+
/** Host upload: receives the slug and browser-encoded variants, returns the stored URL. */
|
|
19
|
+
upload: (input: {
|
|
20
|
+
slug: string;
|
|
21
|
+
variants: { width: number; data: string }[];
|
|
22
|
+
}) => Promise<{ url: string; bytes: number }>;
|
|
23
|
+
onUploaded: (url: string) => void;
|
|
24
|
+
/** Optional cache invalidation after a successful upload (e.g. media library). */
|
|
25
|
+
onInvalidate?: () => void | Promise<void>;
|
|
26
|
+
notify?: {
|
|
27
|
+
success: (message: string) => void;
|
|
28
|
+
error: (message: string) => void;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Uploads a review image: cover-cropped to 16:10 and re-encoded to WebP at
|
|
34
|
+
* 480/768/1200/1920 in the browser, then re-validated server-side before storage.
|
|
35
|
+
*
|
|
36
|
+
* Host-agnostic: storage happens through the injected `upload` function.
|
|
37
|
+
*/
|
|
38
|
+
export function ReviewImageUpload({
|
|
39
|
+
upload,
|
|
40
|
+
onUploaded,
|
|
41
|
+
onInvalidate,
|
|
42
|
+
notify,
|
|
43
|
+
}: ReviewImageUploadProps) {
|
|
44
|
+
const input = useRef<HTMLInputElement>(null);
|
|
45
|
+
const [busy, setBusy] = useState(false);
|
|
46
|
+
|
|
47
|
+
const fail = (message: string) => notify?.error(message);
|
|
48
|
+
|
|
49
|
+
const handle = async (file: File | undefined) => {
|
|
50
|
+
if (!file) return;
|
|
51
|
+
if (!ACCEPTED_SOURCE_TYPES.test(file.type)) {
|
|
52
|
+
fail("Unsupported image type. Use JPEG, PNG, WebP, AVIF or GIF.");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (file.size > MAX_SOURCE_BYTES) {
|
|
56
|
+
fail("Image is too large (max 15 MB).");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
setBusy(true);
|
|
60
|
+
try {
|
|
61
|
+
const prepared = await prepareReviewImage(file);
|
|
62
|
+
const res = await upload({
|
|
63
|
+
slug: reviewImageSlug(file.name),
|
|
64
|
+
variants: prepared.variants.map((v) => ({ width: v.width, data: v.data })),
|
|
65
|
+
});
|
|
66
|
+
if (!res.url) throw new Error("Upload returned no URL.");
|
|
67
|
+
onUploaded(res.url);
|
|
68
|
+
await onInvalidate?.();
|
|
69
|
+
notify?.success(
|
|
70
|
+
`Image uploaded — ${humanBytes(prepared.sourceBytes)} → ${humanBytes(res.bytes)} in 4 sizes`,
|
|
71
|
+
);
|
|
72
|
+
} catch (err) {
|
|
73
|
+
fail(err instanceof Error ? err.message : "Upload failed");
|
|
74
|
+
} finally {
|
|
75
|
+
setBusy(false);
|
|
76
|
+
if (input.current) input.current.value = "";
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<div>
|
|
82
|
+
<input
|
|
83
|
+
ref={input}
|
|
84
|
+
type="file"
|
|
85
|
+
accept="image/*"
|
|
86
|
+
className="hidden"
|
|
87
|
+
onChange={(e) => handle(e.target.files?.[0])}
|
|
88
|
+
/>
|
|
89
|
+
<button
|
|
90
|
+
type="button"
|
|
91
|
+
disabled={busy}
|
|
92
|
+
onClick={() => input.current?.click()}
|
|
93
|
+
className="inline-flex items-center gap-2 border border-ink/15 bg-white px-3 py-1.5 text-xs uppercase tracking-[0.18em] text-ink hover:border-sea disabled:opacity-50"
|
|
94
|
+
>
|
|
95
|
+
{busy ? <Loader2 className="size-3.5 animate-spin" /> : <Upload className="size-3.5" />}
|
|
96
|
+
{busy ? "Optimizing…" : "Upload image"}
|
|
97
|
+
</button>
|
|
98
|
+
<p className="mt-1.5 text-[0.7rem] text-ink/55">
|
|
99
|
+
Auto-cropped to 16:10 and compressed to WebP (480/768/1200/1920). Max 15 MB. PNGs with
|
|
100
|
+
transparency keep their alpha channel and receive a PNG fallback.
|
|
101
|
+
</p>
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-agnostic page SEO editor UI.
|
|
3
|
+
*
|
|
4
|
+
* All data access is injected: the host builds the initial form from its own
|
|
5
|
+
* page registry + CMS overrides, supplies locale/domain facts, media metadata
|
|
6
|
+
* lookup and the media pickers, and performs save/reset. This component owns
|
|
7
|
+
* only editing state and presentation, so every site gets the same screen.
|
|
8
|
+
*/
|
|
9
|
+
import { useEffect, useMemo, useState, type ReactNode } from "react";
|
|
10
|
+
import { Download, ImageIcon, Images, RotateCcw, Save, Sparkles, X } from "lucide-react";
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
mergeMediaMetaIntoForm,
|
|
14
|
+
pageSeoPreviewCanonical,
|
|
15
|
+
pageSeoPreviewPath,
|
|
16
|
+
type PageSeoFormShape,
|
|
17
|
+
} from "./page-seo-form";
|
|
18
|
+
|
|
19
|
+
export type PageSeoImageCandidate = { url: string; hero?: boolean };
|
|
20
|
+
|
|
21
|
+
export type PageSeoMediaMeta = Parameters<typeof mergeMediaMetaIntoForm>[0]["meta"];
|
|
22
|
+
|
|
23
|
+
export type PageSeoPanelViewProps = {
|
|
24
|
+
/** Form values built by the host (registry defaults merged with overrides). */
|
|
25
|
+
initialForm: PageSeoFormShape;
|
|
26
|
+
locales: readonly string[];
|
|
27
|
+
defaultLocale: string;
|
|
28
|
+
/** True when the page exists only in the CMS (no code registry entry). */
|
|
29
|
+
isCmsPage?: boolean;
|
|
30
|
+
/** Current registry route for a locale, shown in the preview panel. */
|
|
31
|
+
registryRoute: (locale: string) => string;
|
|
32
|
+
/** Public origin used to build the canonical preview URL. */
|
|
33
|
+
originForLocale: (locale: string) => string;
|
|
34
|
+
/** Images found on this page, for the "use hero / pick from page" buttons. */
|
|
35
|
+
pageImages: readonly PageSeoImageCandidate[];
|
|
36
|
+
/** Saved media-library metadata for an image URL, or null when none exists. */
|
|
37
|
+
lookupMeta: (src: string) => PageSeoMediaMeta | null;
|
|
38
|
+
/** Persist the form. Return false when saving failed (host shows the error). */
|
|
39
|
+
onSave: (form: PageSeoFormShape) => Promise<boolean>;
|
|
40
|
+
/** Remove the override; only enabled when `canReset`. */
|
|
41
|
+
onReset: () => Promise<void>;
|
|
42
|
+
canReset?: boolean;
|
|
43
|
+
renderMediaPicker: (args: { onPick: (url: string) => void; onClose: () => void }) => ReactNode;
|
|
44
|
+
renderPageImagePicker: (args: {
|
|
45
|
+
onPick: (url: string) => void;
|
|
46
|
+
onClose: () => void;
|
|
47
|
+
}) => ReactNode;
|
|
48
|
+
notify: {
|
|
49
|
+
success: (message: string) => void;
|
|
50
|
+
error: (message: string) => void;
|
|
51
|
+
info: (message: string) => void;
|
|
52
|
+
};
|
|
53
|
+
confirm?: (message: string) => boolean;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export function PageSeoPanelView({
|
|
57
|
+
initialForm,
|
|
58
|
+
locales,
|
|
59
|
+
defaultLocale,
|
|
60
|
+
isCmsPage,
|
|
61
|
+
registryRoute,
|
|
62
|
+
originForLocale,
|
|
63
|
+
pageImages,
|
|
64
|
+
lookupMeta,
|
|
65
|
+
onSave,
|
|
66
|
+
onReset,
|
|
67
|
+
canReset,
|
|
68
|
+
renderMediaPicker,
|
|
69
|
+
renderPageImagePicker,
|
|
70
|
+
notify,
|
|
71
|
+
confirm,
|
|
72
|
+
}: PageSeoPanelViewProps) {
|
|
73
|
+
const [busy, setBusy] = useState(false);
|
|
74
|
+
const [dirty, setDirty] = useState(false);
|
|
75
|
+
const [activeLocale, setActiveLocale] = useState<string>(defaultLocale);
|
|
76
|
+
const [picking, setPicking] = useState(false);
|
|
77
|
+
const [pickingOnPage, setPickingOnPage] = useState(false);
|
|
78
|
+
const [form, setForm] = useState<PageSeoFormShape>(initialForm);
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
setForm(initialForm);
|
|
82
|
+
setDirty(false);
|
|
83
|
+
}, [initialForm]);
|
|
84
|
+
|
|
85
|
+
const heroImage = useMemo(
|
|
86
|
+
() => pageImages.find((c) => c.hero) ?? pageImages[0],
|
|
87
|
+
[pageImages],
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const updateLocalized = (
|
|
91
|
+
group: "slugs" | keyof PageSeoFormShape["seo"],
|
|
92
|
+
locale: string,
|
|
93
|
+
value: string,
|
|
94
|
+
) => {
|
|
95
|
+
setDirty(true);
|
|
96
|
+
setForm((f) => {
|
|
97
|
+
if (group === "slugs") return { ...f, slugs: { ...f.slugs, [locale]: value } };
|
|
98
|
+
const seoField = f.seo[group];
|
|
99
|
+
if (typeof seoField === "string") return f;
|
|
100
|
+
return { ...f, seo: { ...f.seo, [group]: { ...seoField, [locale]: value } } };
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const updateString = (field: "ogImageSrc" | "robots", value: string) => {
|
|
105
|
+
setDirty(true);
|
|
106
|
+
setForm((f) => ({ ...f, seo: { ...f.seo, [field]: value } }));
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/** Copy saved media metadata into the SEO fields. */
|
|
110
|
+
const importFromMedia = (src: string, overwrite: boolean) => {
|
|
111
|
+
const meta = lookupMeta(src);
|
|
112
|
+
if (!meta) return false;
|
|
113
|
+
setDirty(true);
|
|
114
|
+
setForm((f) => mergeMediaMetaIntoForm({ form: f, locales, meta, overwrite }));
|
|
115
|
+
return true;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const onPickMedia = (url: string) => {
|
|
119
|
+
updateString("ogImageSrc", url);
|
|
120
|
+
setPicking(false);
|
|
121
|
+
setPickingOnPage(false);
|
|
122
|
+
const imported = importFromMedia(url, false);
|
|
123
|
+
notify.success(
|
|
124
|
+
imported
|
|
125
|
+
? "Image selected — metadata imported from the media library"
|
|
126
|
+
: "Image selected (no metadata saved on this asset yet)",
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const handleSave = async () => {
|
|
131
|
+
setBusy(true);
|
|
132
|
+
try {
|
|
133
|
+
if (await onSave(form)) setDirty(false);
|
|
134
|
+
} finally {
|
|
135
|
+
setBusy(false);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const handleReset = async () => {
|
|
140
|
+
if (!canReset) {
|
|
141
|
+
notify.info("Nothing to reset — this page already uses defaults.");
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const ask = confirm ?? ((m: string) => window.confirm(m));
|
|
145
|
+
if (!ask("Remove your changes and revert to the defaults from the codebase?")) return;
|
|
146
|
+
setBusy(true);
|
|
147
|
+
try {
|
|
148
|
+
await onReset();
|
|
149
|
+
} finally {
|
|
150
|
+
setBusy(false);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const previewPath = pageSeoPreviewPath({
|
|
155
|
+
slug: form.slugs[activeLocale] ?? "",
|
|
156
|
+
locale: activeLocale,
|
|
157
|
+
defaultLocale,
|
|
158
|
+
});
|
|
159
|
+
const previewCanonical = pageSeoPreviewCanonical({
|
|
160
|
+
path: previewPath,
|
|
161
|
+
origin: originForLocale(activeLocale),
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
return (
|
|
165
|
+
<div>
|
|
166
|
+
{isCmsPage && (
|
|
167
|
+
<p className="mb-4 text-xs text-ink/55">
|
|
168
|
+
This page was created in the page builder. Its URL and metadata are stored in the CMS —
|
|
169
|
+
set the slug below (empty = site root).
|
|
170
|
+
</p>
|
|
171
|
+
)}
|
|
172
|
+
{locales.length > 1 && (
|
|
173
|
+
<div className="flex gap-2 border-b border-ink/10">
|
|
174
|
+
{locales.map((l) => (
|
|
175
|
+
<button
|
|
176
|
+
key={l}
|
|
177
|
+
onClick={() => setActiveLocale(l)}
|
|
178
|
+
className={[
|
|
179
|
+
"px-4 py-2 text-xs uppercase tracking-[0.22em] border-b-2 -mb-px",
|
|
180
|
+
activeLocale === l
|
|
181
|
+
? "border-ink text-ink"
|
|
182
|
+
: "border-transparent text-ink/50 hover:text-ink",
|
|
183
|
+
].join(" ")}
|
|
184
|
+
>
|
|
185
|
+
{l}
|
|
186
|
+
</button>
|
|
187
|
+
))}
|
|
188
|
+
</div>
|
|
189
|
+
)}
|
|
190
|
+
|
|
191
|
+
<div className="mt-8 grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
192
|
+
<Field label="Slug" hint={`Empty = root for ${activeLocale}. E.g. "boka"`}>
|
|
193
|
+
<input
|
|
194
|
+
value={form.slugs[activeLocale] ?? ""}
|
|
195
|
+
onChange={(e) => updateLocalized("slugs", activeLocale, e.target.value)}
|
|
196
|
+
className="seo-input"
|
|
197
|
+
/>
|
|
198
|
+
</Field>
|
|
199
|
+
<Field label="Robots" hint="E.g. noindex,nofollow — empty = default">
|
|
200
|
+
<input
|
|
201
|
+
value={form.seo.robots}
|
|
202
|
+
onChange={(e) => updateString("robots", e.target.value)}
|
|
203
|
+
className="seo-input"
|
|
204
|
+
/>
|
|
205
|
+
</Field>
|
|
206
|
+
<Field label="Title" full>
|
|
207
|
+
<input
|
|
208
|
+
value={form.seo.title[activeLocale] ?? ""}
|
|
209
|
+
onChange={(e) => updateLocalized("title", activeLocale, e.target.value)}
|
|
210
|
+
className="seo-input"
|
|
211
|
+
/>
|
|
212
|
+
</Field>
|
|
213
|
+
<Field label="Meta description" full>
|
|
214
|
+
<textarea
|
|
215
|
+
rows={3}
|
|
216
|
+
value={form.seo.description[activeLocale] ?? ""}
|
|
217
|
+
onChange={(e) => updateLocalized("description", activeLocale, e.target.value)}
|
|
218
|
+
className="seo-input"
|
|
219
|
+
/>
|
|
220
|
+
</Field>
|
|
221
|
+
<Field label="OG title" hint="Share title (fallback: title)">
|
|
222
|
+
<input
|
|
223
|
+
value={form.seo.ogTitle[activeLocale] ?? ""}
|
|
224
|
+
onChange={(e) => updateLocalized("ogTitle", activeLocale, e.target.value)}
|
|
225
|
+
className="seo-input"
|
|
226
|
+
/>
|
|
227
|
+
</Field>
|
|
228
|
+
<Field label="OG description" hint="Share text (fallback: meta description)">
|
|
229
|
+
<input
|
|
230
|
+
value={form.seo.ogDescription[activeLocale] ?? ""}
|
|
231
|
+
onChange={(e) => updateLocalized("ogDescription", activeLocale, e.target.value)}
|
|
232
|
+
className="seo-input"
|
|
233
|
+
/>
|
|
234
|
+
</Field>
|
|
235
|
+
<Field label="OG image" hint="Pick from the media library or paste an absolute https URL">
|
|
236
|
+
<div className="space-y-2">
|
|
237
|
+
<div className="flex gap-2">
|
|
238
|
+
<input
|
|
239
|
+
value={form.seo.ogImageSrc}
|
|
240
|
+
onChange={(e) => updateString("ogImageSrc", e.target.value)}
|
|
241
|
+
className="seo-input"
|
|
242
|
+
placeholder="https://…"
|
|
243
|
+
/>
|
|
244
|
+
<button
|
|
245
|
+
type="button"
|
|
246
|
+
onClick={() => setPicking(true)}
|
|
247
|
+
className="inline-flex shrink-0 items-center gap-1.5 border border-ink/20 px-3 text-[0.7rem] uppercase tracking-widest hover:border-sea"
|
|
248
|
+
>
|
|
249
|
+
<ImageIcon className="size-3.5" />
|
|
250
|
+
Choose
|
|
251
|
+
</button>
|
|
252
|
+
{form.seo.ogImageSrc ? (
|
|
253
|
+
<button
|
|
254
|
+
type="button"
|
|
255
|
+
onClick={() => updateString("ogImageSrc", "")}
|
|
256
|
+
className="inline-flex shrink-0 items-center border border-ink/20 px-2 text-ink/60 hover:border-sea"
|
|
257
|
+
title="Clear"
|
|
258
|
+
>
|
|
259
|
+
<X className="size-3.5" />
|
|
260
|
+
</button>
|
|
261
|
+
) : null}
|
|
262
|
+
</div>
|
|
263
|
+
<div className="flex flex-wrap gap-2">
|
|
264
|
+
<button
|
|
265
|
+
type="button"
|
|
266
|
+
disabled={!heroImage}
|
|
267
|
+
onClick={() => heroImage && onPickMedia(heroImage.url)}
|
|
268
|
+
className="inline-flex items-center gap-1.5 border border-ink/20 px-3 py-1.5 text-[0.7rem] uppercase tracking-widest hover:border-sea disabled:opacity-40"
|
|
269
|
+
title={heroImage?.url}
|
|
270
|
+
>
|
|
271
|
+
<Sparkles className="size-3.5" />
|
|
272
|
+
Use hero image
|
|
273
|
+
</button>
|
|
274
|
+
<button
|
|
275
|
+
type="button"
|
|
276
|
+
disabled={pageImages.length === 0}
|
|
277
|
+
onClick={() => setPickingOnPage(true)}
|
|
278
|
+
className="inline-flex items-center gap-1.5 border border-ink/20 px-3 py-1.5 text-[0.7rem] uppercase tracking-widest hover:border-sea disabled:opacity-40"
|
|
279
|
+
>
|
|
280
|
+
<Images className="size-3.5" />
|
|
281
|
+
Pick from this page ({pageImages.length})
|
|
282
|
+
</button>
|
|
283
|
+
</div>
|
|
284
|
+
{form.seo.ogImageSrc ? (
|
|
285
|
+
<div className="flex items-center gap-3">
|
|
286
|
+
<img
|
|
287
|
+
src={form.seo.ogImageSrc}
|
|
288
|
+
alt=""
|
|
289
|
+
className="h-16 w-28 border border-ink/10 object-cover"
|
|
290
|
+
/>
|
|
291
|
+
<button
|
|
292
|
+
type="button"
|
|
293
|
+
onClick={() => {
|
|
294
|
+
const ok = importFromMedia(form.seo.ogImageSrc, true);
|
|
295
|
+
(ok ? notify.success : notify.info)(
|
|
296
|
+
ok
|
|
297
|
+
? "Imported alt, OG title and description from the media library"
|
|
298
|
+
: "This image has no metadata saved in the media library yet",
|
|
299
|
+
);
|
|
300
|
+
}}
|
|
301
|
+
className="inline-flex items-center gap-1.5 border border-ink/20 px-3 py-1.5 text-[0.7rem] uppercase tracking-widest hover:border-sea"
|
|
302
|
+
>
|
|
303
|
+
<Download className="size-3.5" />
|
|
304
|
+
Import image metadata
|
|
305
|
+
</button>
|
|
306
|
+
</div>
|
|
307
|
+
) : null}
|
|
308
|
+
</div>
|
|
309
|
+
</Field>
|
|
310
|
+
<Field label={`OG image alt (${activeLocale})`}>
|
|
311
|
+
<input
|
|
312
|
+
value={form.seo.ogImageAlt[activeLocale] ?? ""}
|
|
313
|
+
onChange={(e) => updateLocalized("ogImageAlt", activeLocale, e.target.value)}
|
|
314
|
+
className="seo-input"
|
|
315
|
+
/>
|
|
316
|
+
</Field>
|
|
317
|
+
<Field label="Keywords" full hint="Comma-separated list">
|
|
318
|
+
<input
|
|
319
|
+
value={form.seo.keywords[activeLocale] ?? ""}
|
|
320
|
+
onChange={(e) => updateLocalized("keywords", activeLocale, e.target.value)}
|
|
321
|
+
className="seo-input"
|
|
322
|
+
/>
|
|
323
|
+
</Field>
|
|
324
|
+
</div>
|
|
325
|
+
|
|
326
|
+
<div className="mt-10 border border-ink/10 bg-white p-6">
|
|
327
|
+
<div className="text-[0.65rem] uppercase tracking-[0.22em] text-ink/55">Preview</div>
|
|
328
|
+
<dl className="mt-4 grid grid-cols-1 md:grid-cols-[140px_1fr] gap-x-6 gap-y-2 text-sm">
|
|
329
|
+
<dt className="text-ink/50">Canonical</dt>
|
|
330
|
+
<dd className="font-mono text-ink/80 break-all">{previewCanonical}</dd>
|
|
331
|
+
<dt className="text-ink/50">Route</dt>
|
|
332
|
+
<dd className="font-mono text-ink/80">
|
|
333
|
+
{previewPath} (current registry: {registryRoute(activeLocale)})
|
|
334
|
+
</dd>
|
|
335
|
+
<dt className="text-ink/50"><title></dt>
|
|
336
|
+
<dd className="text-ink/80">
|
|
337
|
+
{form.seo.title[activeLocale] || <em className="text-ink/40">empty</em>}
|
|
338
|
+
</dd>
|
|
339
|
+
<dt className="text-ink/50">description</dt>
|
|
340
|
+
<dd className="text-ink/80">
|
|
341
|
+
{form.seo.description[activeLocale] || <em className="text-ink/40">empty</em>}
|
|
342
|
+
</dd>
|
|
343
|
+
</dl>
|
|
344
|
+
</div>
|
|
345
|
+
|
|
346
|
+
<div className="mt-8 flex flex-wrap items-center gap-3">
|
|
347
|
+
<button
|
|
348
|
+
onClick={handleSave}
|
|
349
|
+
disabled={busy || !dirty}
|
|
350
|
+
className="inline-flex items-center gap-2 bg-ink text-paper px-6 py-3 text-xs uppercase tracking-[0.22em] hover:bg-ink/85 disabled:opacity-50"
|
|
351
|
+
>
|
|
352
|
+
<Save className="size-4" />
|
|
353
|
+
{busy ? "Saving…" : "Save"}
|
|
354
|
+
</button>
|
|
355
|
+
<button
|
|
356
|
+
onClick={handleReset}
|
|
357
|
+
disabled={busy || !canReset}
|
|
358
|
+
className="inline-flex items-center gap-2 border border-ink/20 px-6 py-3 text-xs uppercase tracking-[0.22em] hover:border-ink disabled:opacity-40"
|
|
359
|
+
>
|
|
360
|
+
<RotateCcw className="size-4" />
|
|
361
|
+
Reset to default
|
|
362
|
+
</button>
|
|
363
|
+
{dirty && (
|
|
364
|
+
<span className="text-xs text-sea uppercase tracking-[0.22em]">unsaved changes</span>
|
|
365
|
+
)}
|
|
366
|
+
</div>
|
|
367
|
+
|
|
368
|
+
{picking && renderMediaPicker({ onPick: onPickMedia, onClose: () => setPicking(false) })}
|
|
369
|
+
{pickingOnPage &&
|
|
370
|
+
renderPageImagePicker({ onPick: onPickMedia, onClose: () => setPickingOnPage(false) })}
|
|
371
|
+
|
|
372
|
+
<style>{`
|
|
373
|
+
.seo-input {
|
|
374
|
+
width: 100%;
|
|
375
|
+
background: white;
|
|
376
|
+
border: 1px solid rgb(0 0 0 / 0.15);
|
|
377
|
+
padding: 0.65rem 0.85rem;
|
|
378
|
+
font-size: 0.9rem;
|
|
379
|
+
outline: none;
|
|
380
|
+
color: var(--ink);
|
|
381
|
+
}
|
|
382
|
+
.seo-input:focus { border-color: var(--sea); }
|
|
383
|
+
`}</style>
|
|
384
|
+
</div>
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function Field({
|
|
389
|
+
label,
|
|
390
|
+
hint,
|
|
391
|
+
full,
|
|
392
|
+
children,
|
|
393
|
+
}: {
|
|
394
|
+
label: string;
|
|
395
|
+
hint?: string;
|
|
396
|
+
full?: boolean;
|
|
397
|
+
children: ReactNode;
|
|
398
|
+
}) {
|
|
399
|
+
return (
|
|
400
|
+
<label className={full ? "md:col-span-2" : ""}>
|
|
401
|
+
<div className="text-[0.65rem] uppercase tracking-[0.22em] text-ink/55">{label}</div>
|
|
402
|
+
<div className="mt-2">{children}</div>
|
|
403
|
+
{hint && <div className="mt-1 text-xs text-ink/45">{hint}</div>}
|
|
404
|
+
</label>
|
|
405
|
+
);
|
|
406
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform contract version + canonical schema manifest (Phase 5).
|
|
3
|
+
*
|
|
4
|
+
* The package ships the canonical database migrations under `/migrations`.
|
|
5
|
+
* A site asserts compatibility by comparing its own applied migration set
|
|
6
|
+
* against `SCHEMA_MIGRATIONS` and by pinning `PLATFORM_CONTRACT_VERSION`.
|
|
7
|
+
*
|
|
8
|
+
* Bump `PLATFORM_CONTRACT_VERSION` whenever a shared screen starts requiring
|
|
9
|
+
* schema or adapter capabilities an older site would not have.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const PLATFORM_CONTRACT_VERSION = 1 as const;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Canonical migration filenames, oldest first. Files live in the published
|
|
16
|
+
* package at `@bygghammar/cms-platform/migrations/<name>`.
|
|
17
|
+
*/
|
|
18
|
+
export const SCHEMA_MIGRATIONS: readonly string[] = [
|
|
19
|
+
"20260728113741_f9744b19-078b-46e5-b00f-31c84aaf71ab.sql",
|
|
20
|
+
"20260728113757_4156a886-21fb-4a1f-9c12-acb7bb145102.sql",
|
|
21
|
+
"20260728113823_6e0237e1-99e3-4e1a-8a68-804b7bcdbbb8.sql",
|
|
22
|
+
"20260728115305_506d92b4-129f-4d2b-961f-cf76e592677e.sql",
|
|
23
|
+
"20260728115320_717d4447-f433-4a1d-89d2-fc8f028d4ac6.sql",
|
|
24
|
+
"20260728115347_c77f5a56-19db-4117-bb60-9ad692b817ab.sql",
|
|
25
|
+
"20260728132052_b692dcfe-a944-4a19-afd0-187f7600feb8.sql",
|
|
26
|
+
"20260728183318_05b05a47-ba05-4a66-ab8f-69f2688fea84.sql",
|
|
27
|
+
"20260728193035_84b68d27-c3f3-4516-a3a9-15fc6f476163.sql",
|
|
28
|
+
"20260728193707_8438ee2d-d589-4048-86e2-464fd209af80.sql",
|
|
29
|
+
"20260729055312_08862d7e-0279-4d4f-8709-a59b9f068c55.sql",
|
|
30
|
+
"20260729055348_418b7e36-4877-4304-831f-290ca73e56f3.sql",
|
|
31
|
+
"20260729055358_20b467e2-4efd-42c1-bd34-773ed6b77fc5.sql",
|
|
32
|
+
"20260729061039_306859eb-a38c-44ef-af1a-6c02a8fd84db.sql",
|
|
33
|
+
"20260730065600_54c25861-3355-4600-a72f-3d67b457ecb1.sql",
|
|
34
|
+
"20260730071745_d4904314-15ff-4c58-ac66-85e7371e04b5.sql",
|
|
35
|
+
"20260730071914_48163aa3-830e-4dcc-bdd4-c35be282ab87.sql",
|
|
36
|
+
"20260730085949_bcfc3270-ea80-4617-86a3-2555ed34a280.sql",
|
|
37
|
+
"20260730095256_c977c30e-b285-4041-8804-c0bd72b6d9b3.sql",
|
|
38
|
+
"20260730100057_e341b887-eb0e-4a74-850e-0ee5ffb70d7a.sql",
|
|
39
|
+
"20260730103703_d5c4e1b7-1e2c-4dd0-be4e-185c159ade69.sql",
|
|
40
|
+
"20260730105635_3557b7da-919e-48db-8c92-8221d68d3cf9.sql",
|
|
41
|
+
"20260730120308_12ff8cfb-43f9-4070-abde-61531ad3b75f.sql",
|
|
42
|
+
"20260730125024_1baf8926-12a2-48f4-8edc-7309941309e9.sql",
|
|
43
|
+
"20260730173510_feb974d1-510e-4f52-9e20-5fd0582d8952.sql",
|
|
44
|
+
"20260730175409_9f60743f-f5e1-418c-a700-c91fb3704db8.sql",
|
|
45
|
+
"20260730181224_1c52ff16-c7a2-4ef1-a0a8-e493c2c9106f.sql",
|
|
46
|
+
"20260730183129_933adb75-f985-4d82-ad5d-213b69fd42e5.sql",
|
|
47
|
+
"20260730183918_7bc7a827-2100-49f1-bc6e-24509249350b.sql",
|
|
48
|
+
"20260730202628_7ceade5e-644c-4bc2-91b8-594133329f31.sql",
|
|
49
|
+
"20260730211056_57f42049-00b4-473b-a2cd-65a13570b8d2.sql",
|
|
50
|
+
"20260730214340_98af2e55-9031-4c11-9659-c47a37a8d6b7.sql",
|
|
51
|
+
"20260731091630_8a6f28ce-5833-4901-ab17-27648cef32ec.sql",
|
|
52
|
+
"20260731094716_4c68a1df-83ed-4ba8-8019-fa2fe2b9681e.sql",
|
|
53
|
+
"20260731191655_fef97c3c-1397-47b4-8b56-afb020298e97.sql",
|
|
54
|
+
"20260731192212_95772a2f-19a1-4013-b463-2eb161e96737.sql",
|
|
55
|
+
"20260731192815_c490653e-1232-4ad9-a150-3c83d2b90f5e.sql",
|
|
56
|
+
"20260731193135_7966e740-5e86-4b14-8e1d-5119069666ba.sql",
|
|
57
|
+
"20260731193245_599790d0-ca5e-4b5d-a3e7-d69b2a79e1a3.sql",
|
|
58
|
+
"20260731212959_a748cb0d-4dc7-45dc-be90-f6bacbfab26c.sql",
|
|
59
|
+
"20260801003057_1195f4c1-fb54-42dc-9718-638a25e6a82e.sql",
|
|
60
|
+
"20260801003300_fc591960-cb41-41cf-837d-2eef23b29ca9.sql",
|
|
61
|
+
"20260802151445_a56b0023-eaf7-41e2-a7fb-d4beddfc587c.sql",
|
|
62
|
+
"20260802202621_d661af8a-8513-4b54-b375-f963ae824c8f.sql",
|
|
63
|
+
"20260802202702_c30cd837-744c-4641-85f1-edd3a7ebbcb6.sql",
|
|
64
|
+
"20260802202720_4418d18d-c851-42dc-9345-78fc330128ae.sql",
|
|
65
|
+
"20260803132514_78ba1f53-c85b-4457-96b1-7d49c5c8b494.sql",
|
|
66
|
+
"20260803181201_28c8aa09-baa8-431c-8338-90b1af9c8172.sql",
|
|
67
|
+
"20260803201518_6e8a6028-b70f-4a7d-8bc9-95c86304e7ae.sql",
|
|
68
|
+
"20260803201535_32a9a213-cb92-4035-b8cd-8211ca34af68.sql",
|
|
69
|
+
"20260811103505_29df753d-14fa-4a05-8fea-f4207785fba3.sql",
|
|
70
|
+
"20260811112455_217c4028-f587-4c98-9e4f-9e6c452ab761.sql",
|
|
71
|
+
"20260811114438_6687d67d-bad3-4803-9638-8b7670d2e5d4.sql",
|
|
72
|
+
"20260811130318_7cb95e95-9baa-40af-8f3f-de1d4e09cec4.sql",
|
|
73
|
+
"20260811220548_80d99ec2-bd4b-475d-a627-9408bb60ce56.sql",
|
|
74
|
+
"20260811222519_6b040f56-4de3-49e0-92e4-d9deec5ead6a.sql",
|
|
75
|
+
"20260812000000_seed_voyara_content.sql",
|
|
76
|
+
"20260818040722_1bdf1b8f-7fb0-4ae8-8ecf-73f1fadff3c2.sql",
|
|
77
|
+
"20260818040808_69a5e832-57e8-4aa7-aff8-7fd7777faa7c.sql",
|
|
78
|
+
"20260818040839_e6523163-bbf5-4a39-9233-91759059569a.sql",
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
export function missingMigrations(applied: readonly string[]): string[] {
|
|
82
|
+
const set = new Set(applied);
|
|
83
|
+
return SCHEMA_MIGRATIONS.filter((m) => !set.has(m));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function assertPlatformContract(expected: number): void {
|
|
87
|
+
if (expected !== PLATFORM_CONTRACT_VERSION) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`Platform contract mismatch: site expects v${expected}, package provides v${PLATFORM_CONTRACT_VERSION}.`,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|