@nextblock-cms/db 0.14.2 → 0.14.4
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/lib/supabase/server.d.ts
CHANGED
|
@@ -1871,6 +1871,57 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
|
|
|
1871
1871
|
};
|
|
1872
1872
|
Relationships: [];
|
|
1873
1873
|
};
|
|
1874
|
+
site_themes: {
|
|
1875
|
+
Row: {
|
|
1876
|
+
color_scheme: string;
|
|
1877
|
+
created_at: string;
|
|
1878
|
+
description: string | null;
|
|
1879
|
+
extra_css: string | null;
|
|
1880
|
+
icon: string;
|
|
1881
|
+
id: string;
|
|
1882
|
+
is_active: boolean;
|
|
1883
|
+
is_default: boolean;
|
|
1884
|
+
is_system: boolean;
|
|
1885
|
+
name: string;
|
|
1886
|
+
slug: string;
|
|
1887
|
+
sort_order: number;
|
|
1888
|
+
tokens: import('./types').Json;
|
|
1889
|
+
updated_at: string;
|
|
1890
|
+
};
|
|
1891
|
+
Insert: {
|
|
1892
|
+
color_scheme?: string;
|
|
1893
|
+
created_at?: string;
|
|
1894
|
+
description?: string | null;
|
|
1895
|
+
extra_css?: string | null;
|
|
1896
|
+
icon?: string;
|
|
1897
|
+
id?: string;
|
|
1898
|
+
is_active?: boolean;
|
|
1899
|
+
is_default?: boolean;
|
|
1900
|
+
is_system?: boolean;
|
|
1901
|
+
name: string;
|
|
1902
|
+
slug: string;
|
|
1903
|
+
sort_order?: number;
|
|
1904
|
+
tokens?: import('./types').Json;
|
|
1905
|
+
updated_at?: string;
|
|
1906
|
+
};
|
|
1907
|
+
Update: {
|
|
1908
|
+
color_scheme?: string;
|
|
1909
|
+
created_at?: string;
|
|
1910
|
+
description?: string | null;
|
|
1911
|
+
extra_css?: string | null;
|
|
1912
|
+
icon?: string;
|
|
1913
|
+
id?: string;
|
|
1914
|
+
is_active?: boolean;
|
|
1915
|
+
is_default?: boolean;
|
|
1916
|
+
is_system?: boolean;
|
|
1917
|
+
name?: string;
|
|
1918
|
+
slug?: string;
|
|
1919
|
+
sort_order?: number;
|
|
1920
|
+
tokens?: import('./types').Json;
|
|
1921
|
+
updated_at?: string;
|
|
1922
|
+
};
|
|
1923
|
+
Relationships: [];
|
|
1924
|
+
};
|
|
1874
1925
|
system_alerts: {
|
|
1875
1926
|
Row: {
|
|
1876
1927
|
alert_type: string;
|
|
@@ -2302,6 +2353,6 @@ export declare const getServiceRoleSupabaseClient: () => import('@supabase/supab
|
|
|
2302
2353
|
};
|
|
2303
2354
|
CompositeTypes: { [_ in never]: never; };
|
|
2304
2355
|
}, {
|
|
2305
|
-
PostgrestVersion: "14.
|
|
2356
|
+
PostgrestVersion: "14.15";
|
|
2306
2357
|
}>;
|
|
2307
2358
|
export {};
|
package/lib/supabase/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export type Json = string | number | boolean | null | {
|
|
|
3
3
|
} | Json[];
|
|
4
4
|
export type Database = {
|
|
5
5
|
__InternalSupabase: {
|
|
6
|
-
PostgrestVersion: "14.
|
|
6
|
+
PostgrestVersion: "14.15";
|
|
7
7
|
};
|
|
8
8
|
public: {
|
|
9
9
|
Tables: {
|
|
@@ -1943,6 +1943,57 @@ export type Database = {
|
|
|
1943
1943
|
};
|
|
1944
1944
|
Relationships: [];
|
|
1945
1945
|
};
|
|
1946
|
+
site_themes: {
|
|
1947
|
+
Row: {
|
|
1948
|
+
color_scheme: string;
|
|
1949
|
+
created_at: string;
|
|
1950
|
+
description: string | null;
|
|
1951
|
+
extra_css: string | null;
|
|
1952
|
+
icon: string;
|
|
1953
|
+
id: string;
|
|
1954
|
+
is_active: boolean;
|
|
1955
|
+
is_default: boolean;
|
|
1956
|
+
is_system: boolean;
|
|
1957
|
+
name: string;
|
|
1958
|
+
slug: string;
|
|
1959
|
+
sort_order: number;
|
|
1960
|
+
tokens: Json;
|
|
1961
|
+
updated_at: string;
|
|
1962
|
+
};
|
|
1963
|
+
Insert: {
|
|
1964
|
+
color_scheme?: string;
|
|
1965
|
+
created_at?: string;
|
|
1966
|
+
description?: string | null;
|
|
1967
|
+
extra_css?: string | null;
|
|
1968
|
+
icon?: string;
|
|
1969
|
+
id?: string;
|
|
1970
|
+
is_active?: boolean;
|
|
1971
|
+
is_default?: boolean;
|
|
1972
|
+
is_system?: boolean;
|
|
1973
|
+
name: string;
|
|
1974
|
+
slug: string;
|
|
1975
|
+
sort_order?: number;
|
|
1976
|
+
tokens?: Json;
|
|
1977
|
+
updated_at?: string;
|
|
1978
|
+
};
|
|
1979
|
+
Update: {
|
|
1980
|
+
color_scheme?: string;
|
|
1981
|
+
created_at?: string;
|
|
1982
|
+
description?: string | null;
|
|
1983
|
+
extra_css?: string | null;
|
|
1984
|
+
icon?: string;
|
|
1985
|
+
id?: string;
|
|
1986
|
+
is_active?: boolean;
|
|
1987
|
+
is_default?: boolean;
|
|
1988
|
+
is_system?: boolean;
|
|
1989
|
+
name?: string;
|
|
1990
|
+
slug?: string;
|
|
1991
|
+
sort_order?: number;
|
|
1992
|
+
tokens?: Json;
|
|
1993
|
+
updated_at?: string;
|
|
1994
|
+
};
|
|
1995
|
+
Relationships: [];
|
|
1996
|
+
};
|
|
1946
1997
|
system_alerts: {
|
|
1947
1998
|
Row: {
|
|
1948
1999
|
alert_type: string;
|
package/package.json
CHANGED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
-- Editable site themes.
|
|
2
|
+
--
|
|
3
|
+
-- Themes used to be hardcoded CSS classes in libs/ui/src/styles/theme.css
|
|
4
|
+
-- (:root / .dark / .vibrant) with the switcher list duplicated in
|
|
5
|
+
-- apps/nextblock/app/providers.tsx and components/theme-switcher.tsx. This moves
|
|
6
|
+
-- the palette into the database so an ADMIN can retint the site, add themes and
|
|
7
|
+
-- remove them from /cms/settings/global-css without a redeploy.
|
|
8
|
+
--
|
|
9
|
+
-- Rendering: apps/nextblock/lib/themes/buildThemeCss.ts turns each row into a
|
|
10
|
+
-- `:root.<slug> { --token: value; ... }` rule injected into <head> by
|
|
11
|
+
-- app/layout.tsx. The `:root.x` form is two-class specificity, so generated
|
|
12
|
+
-- themes always beat the (0,1,0) fallback rules still shipped in theme.css for
|
|
13
|
+
-- consumers of the published @nextblock-cms/ui package.
|
|
14
|
+
--
|
|
15
|
+
-- Forward-only and idempotent.
|
|
16
|
+
|
|
17
|
+
CREATE TABLE IF NOT EXISTS public.site_themes (
|
|
18
|
+
id uuid DEFAULT gen_random_uuid() NOT NULL,
|
|
19
|
+
slug text NOT NULL,
|
|
20
|
+
name text NOT NULL,
|
|
21
|
+
description text,
|
|
22
|
+
-- lucide-react icon name rendered by the theme switcher.
|
|
23
|
+
icon text NOT NULL DEFAULT 'Palette',
|
|
24
|
+
-- Drives the CSS `color-scheme` property and decides whether the theme also
|
|
25
|
+
-- carries Tailwind's `.dark` class so `dark:` variants resolve correctly.
|
|
26
|
+
color_scheme text NOT NULL DEFAULT 'light',
|
|
27
|
+
-- Flat map of design token -> raw CSS value, keys WITHOUT the leading `--`,
|
|
28
|
+
-- e.g. {"background": "0 0% 100%", "radius": "0.75rem"}.
|
|
29
|
+
tokens jsonb NOT NULL DEFAULT '{}'::jsonb,
|
|
30
|
+
-- Optional per-theme CSS, emitted nested inside the theme rule so it is
|
|
31
|
+
-- automatically scoped. Authors use the `&` nesting selector,
|
|
32
|
+
-- e.g. `& h1 { text-shadow: 0 0 5px hsl(var(--primary)); }`.
|
|
33
|
+
extra_css text,
|
|
34
|
+
-- System themes cannot be deleted: next-themes' `enableSystem` resolves to
|
|
35
|
+
-- 'light' or 'dark', so those two slugs must always exist.
|
|
36
|
+
is_system boolean DEFAULT false NOT NULL,
|
|
37
|
+
is_default boolean DEFAULT false NOT NULL,
|
|
38
|
+
is_active boolean DEFAULT true NOT NULL,
|
|
39
|
+
sort_order integer DEFAULT 0 NOT NULL,
|
|
40
|
+
created_at timestamp with time zone DEFAULT now() NOT NULL,
|
|
41
|
+
updated_at timestamp with time zone DEFAULT now() NOT NULL,
|
|
42
|
+
CONSTRAINT site_themes_pkey PRIMARY KEY (id),
|
|
43
|
+
CONSTRAINT site_themes_slug_key UNIQUE (slug),
|
|
44
|
+
CONSTRAINT site_themes_color_scheme_check CHECK ((color_scheme = ANY (ARRAY['light'::text, 'dark'::text]))),
|
|
45
|
+
-- The slug becomes a CSS class and a next-themes value; keep it safe for both.
|
|
46
|
+
CONSTRAINT site_themes_slug_format_check CHECK ((slug ~ '^[a-z][a-z0-9-]{0,38}[a-z0-9]$')),
|
|
47
|
+
CONSTRAINT site_themes_tokens_is_object_check CHECK ((jsonb_typeof(tokens) = 'object'))
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
COMMENT ON TABLE public.site_themes IS 'Editable colour themes. Each row renders to a `:root.<slug>` CSS rule injected by the root layout. Publicly readable (anonymous visitors need the palette); only ADMIN may write.';
|
|
51
|
+
|
|
52
|
+
CREATE INDEX IF NOT EXISTS site_themes_active_sort_idx ON public.site_themes USING btree (is_active, sort_order);
|
|
53
|
+
|
|
54
|
+
-- Exactly one default theme.
|
|
55
|
+
CREATE UNIQUE INDEX IF NOT EXISTS site_themes_single_default_idx ON public.site_themes USING btree (is_default) WHERE (is_default = true);
|
|
56
|
+
|
|
57
|
+
DROP TRIGGER IF EXISTS set_site_themes_updated_at ON public.site_themes;
|
|
58
|
+
CREATE TRIGGER set_site_themes_updated_at
|
|
59
|
+
BEFORE UPDATE ON public.site_themes
|
|
60
|
+
FOR EACH ROW EXECUTE FUNCTION public.set_current_timestamp_updated_at();
|
|
61
|
+
|
|
62
|
+
-- A system theme must never be deleted, whoever asks.
|
|
63
|
+
CREATE OR REPLACE FUNCTION public.prevent_system_theme_delete() RETURNS trigger
|
|
64
|
+
LANGUAGE plpgsql
|
|
65
|
+
SET search_path = ''
|
|
66
|
+
AS $$
|
|
67
|
+
BEGIN
|
|
68
|
+
IF OLD.is_system THEN
|
|
69
|
+
RAISE EXCEPTION 'Theme "%" is a system theme and cannot be deleted', OLD.slug
|
|
70
|
+
USING ERRCODE = 'restrict_violation';
|
|
71
|
+
END IF;
|
|
72
|
+
RETURN OLD;
|
|
73
|
+
END;
|
|
74
|
+
$$;
|
|
75
|
+
|
|
76
|
+
DROP TRIGGER IF EXISTS trg_prevent_system_theme_delete ON public.site_themes;
|
|
77
|
+
CREATE TRIGGER trg_prevent_system_theme_delete
|
|
78
|
+
BEFORE DELETE ON public.site_themes
|
|
79
|
+
FOR EACH ROW EXECUTE FUNCTION public.prevent_system_theme_delete();
|
|
80
|
+
|
|
81
|
+
-- Promoting a theme to default demotes the previous one, so the unique partial
|
|
82
|
+
-- index above can never trip on a normal "make this the default" write.
|
|
83
|
+
CREATE OR REPLACE FUNCTION public.handle_default_theme_change() RETURNS trigger
|
|
84
|
+
LANGUAGE plpgsql
|
|
85
|
+
SET search_path = ''
|
|
86
|
+
AS $$
|
|
87
|
+
BEGIN
|
|
88
|
+
IF NEW.is_default THEN
|
|
89
|
+
UPDATE public.site_themes
|
|
90
|
+
SET is_default = false
|
|
91
|
+
WHERE id <> NEW.id AND is_default;
|
|
92
|
+
END IF;
|
|
93
|
+
RETURN NEW;
|
|
94
|
+
END;
|
|
95
|
+
$$;
|
|
96
|
+
|
|
97
|
+
DROP TRIGGER IF EXISTS trg_handle_default_theme_change ON public.site_themes;
|
|
98
|
+
CREATE TRIGGER trg_handle_default_theme_change
|
|
99
|
+
AFTER INSERT OR UPDATE OF is_default ON public.site_themes
|
|
100
|
+
FOR EACH ROW WHEN (NEW.is_default) EXECUTE FUNCTION public.handle_default_theme_change();
|
|
101
|
+
|
|
102
|
+
ALTER TABLE public.site_themes ENABLE ROW LEVEL SECURITY;
|
|
103
|
+
|
|
104
|
+
GRANT ALL ON TABLE public.site_themes TO anon;
|
|
105
|
+
GRANT ALL ON TABLE public.site_themes TO authenticated;
|
|
106
|
+
GRANT ALL ON TABLE public.site_themes TO service_role;
|
|
107
|
+
|
|
108
|
+
DROP POLICY IF EXISTS "Public read active themes" ON public.site_themes;
|
|
109
|
+
CREATE POLICY "Public read active themes" ON public.site_themes
|
|
110
|
+
FOR SELECT TO authenticated, anon USING (true);
|
|
111
|
+
|
|
112
|
+
DROP POLICY IF EXISTS "Admins insert themes" ON public.site_themes;
|
|
113
|
+
CREATE POLICY "Admins insert themes" ON public.site_themes
|
|
114
|
+
FOR INSERT TO authenticated
|
|
115
|
+
WITH CHECK (((SELECT public.get_current_user_role()) = 'ADMIN'::public.user_role));
|
|
116
|
+
|
|
117
|
+
DROP POLICY IF EXISTS "Admins update themes" ON public.site_themes;
|
|
118
|
+
CREATE POLICY "Admins update themes" ON public.site_themes
|
|
119
|
+
FOR UPDATE TO authenticated
|
|
120
|
+
USING (((SELECT public.get_current_user_role()) = 'ADMIN'::public.user_role))
|
|
121
|
+
WITH CHECK (((SELECT public.get_current_user_role()) = 'ADMIN'::public.user_role));
|
|
122
|
+
|
|
123
|
+
DROP POLICY IF EXISTS "Admins delete themes" ON public.site_themes;
|
|
124
|
+
CREATE POLICY "Admins delete themes" ON public.site_themes
|
|
125
|
+
FOR DELETE TO authenticated
|
|
126
|
+
USING (((SELECT public.get_current_user_role()) = 'ADMIN'::public.user_role));
|
|
127
|
+
|
|
128
|
+
DROP POLICY IF EXISTS "Service role manages themes" ON public.site_themes;
|
|
129
|
+
CREATE POLICY "Service role manages themes" ON public.site_themes
|
|
130
|
+
TO service_role USING (true) WITH CHECK (true);
|
|
131
|
+
|
|
132
|
+
-- Seed the three shipped themes from libs/ui/src/styles/theme.css.
|
|
133
|
+
-- `--warning` / `--warning-foreground` are declared in the Tailwind theme
|
|
134
|
+
-- (libs/ui/tailwind.config.js) but were never defined in CSS, so bg-warning and
|
|
135
|
+
-- text-warning resolved to an invalid colour. They are given real values here.
|
|
136
|
+
INSERT INTO public.site_themes (slug, name, description, icon, color_scheme, is_system, is_default, sort_order, tokens, extra_css)
|
|
137
|
+
VALUES
|
|
138
|
+
(
|
|
139
|
+
'light', 'Light', 'Clean, technical, stark.', 'Sun', 'light', true, true, 10,
|
|
140
|
+
'{
|
|
141
|
+
"background": "0 0% 100%",
|
|
142
|
+
"foreground": "222 47% 11%",
|
|
143
|
+
"card": "0 0% 100%",
|
|
144
|
+
"card-foreground": "222 47% 11%",
|
|
145
|
+
"popover": "0 0% 100%",
|
|
146
|
+
"popover-foreground": "222 47% 11%",
|
|
147
|
+
"primary": "211.55 50.26% 37.84%",
|
|
148
|
+
"primary-foreground": "210 40% 98%",
|
|
149
|
+
"secondary": "210 40% 96.1%",
|
|
150
|
+
"secondary-foreground": "222 47% 11%",
|
|
151
|
+
"muted": "210 40% 96.1%",
|
|
152
|
+
"muted-foreground": "215 16% 47%",
|
|
153
|
+
"accent": "210 40% 96.1%",
|
|
154
|
+
"accent-foreground": "222 47% 11%",
|
|
155
|
+
"destructive": "0 84.2% 60.2%",
|
|
156
|
+
"destructive-foreground": "210 40% 98%",
|
|
157
|
+
"warning": "38 92% 50%",
|
|
158
|
+
"warning-foreground": "222 47% 11%",
|
|
159
|
+
"border": "214.3 31.8% 91.4%",
|
|
160
|
+
"input": "214.3 31.8% 91.4%",
|
|
161
|
+
"ring": "211.55 50.26% 37.84%",
|
|
162
|
+
"radius": "0.75rem",
|
|
163
|
+
"chart-1": "211.55 50.26% 37.84%",
|
|
164
|
+
"chart-2": "215 16% 47%",
|
|
165
|
+
"chart-3": "215 25% 27%",
|
|
166
|
+
"chart-4": "210 40% 96%",
|
|
167
|
+
"chart-5": "214 32% 91%"
|
|
168
|
+
}'::jsonb,
|
|
169
|
+
NULL
|
|
170
|
+
),
|
|
171
|
+
(
|
|
172
|
+
'dark', 'Dark', 'Midnight / neon tech.', 'Moon', 'dark', true, false, 20,
|
|
173
|
+
'{
|
|
174
|
+
"background": "222 47% 2%",
|
|
175
|
+
"foreground": "210 40% 98%",
|
|
176
|
+
"card": "222 47% 11%",
|
|
177
|
+
"card-foreground": "210 40% 98%",
|
|
178
|
+
"popover": "222 47% 11%",
|
|
179
|
+
"popover-foreground": "210 40% 98%",
|
|
180
|
+
"primary": "217 91% 60%",
|
|
181
|
+
"primary-foreground": "222 47% 11%",
|
|
182
|
+
"secondary": "217.2 32.6% 17.5%",
|
|
183
|
+
"secondary-foreground": "210 40% 98%",
|
|
184
|
+
"muted": "217.2 32.6% 17.5%",
|
|
185
|
+
"muted-foreground": "215 20.2% 65.1%",
|
|
186
|
+
"accent": "217.2 32.6% 17.5%",
|
|
187
|
+
"accent-foreground": "210 40% 98%",
|
|
188
|
+
"destructive": "0 62.8% 30.6%",
|
|
189
|
+
"destructive-foreground": "210 40% 98%",
|
|
190
|
+
"warning": "38 92% 50%",
|
|
191
|
+
"warning-foreground": "222 47% 11%",
|
|
192
|
+
"border": "217.2 32.6% 17.5%",
|
|
193
|
+
"input": "217.2 32.6% 17.5%",
|
|
194
|
+
"ring": "224 76% 48%",
|
|
195
|
+
"radius": "0.75rem",
|
|
196
|
+
"chart-1": "220 70% 50%",
|
|
197
|
+
"chart-2": "160 60% 45%",
|
|
198
|
+
"chart-3": "30 80% 55%",
|
|
199
|
+
"chart-4": "280 65% 60%",
|
|
200
|
+
"chart-5": "340 75% 55%"
|
|
201
|
+
}'::jsonb,
|
|
202
|
+
NULL
|
|
203
|
+
),
|
|
204
|
+
(
|
|
205
|
+
'vibrant', 'Vibrant', 'Cyberpunk neon.', 'Zap', 'dark', false, false, 30,
|
|
206
|
+
'{
|
|
207
|
+
"background": "260 50% 5%",
|
|
208
|
+
"foreground": "180 100% 90%",
|
|
209
|
+
"card": "260 50% 8%",
|
|
210
|
+
"card-foreground": "180 100% 90%",
|
|
211
|
+
"popover": "260 50% 8%",
|
|
212
|
+
"popover-foreground": "180 100% 90%",
|
|
213
|
+
"primary": "320 100% 55%",
|
|
214
|
+
"primary-foreground": "0 0% 100%",
|
|
215
|
+
"secondary": "180 100% 50%",
|
|
216
|
+
"secondary-foreground": "260 50% 5%",
|
|
217
|
+
"muted": "260 30% 15%",
|
|
218
|
+
"muted-foreground": "260 20% 65%",
|
|
219
|
+
"accent": "280 100% 50%",
|
|
220
|
+
"accent-foreground": "0 0% 100%",
|
|
221
|
+
"destructive": "0 100% 50%",
|
|
222
|
+
"destructive-foreground": "0 0% 100%",
|
|
223
|
+
"warning": "60 100% 50%",
|
|
224
|
+
"warning-foreground": "260 50% 5%",
|
|
225
|
+
"border": "320 100% 55%",
|
|
226
|
+
"input": "260 30% 15%",
|
|
227
|
+
"ring": "320 100% 55%",
|
|
228
|
+
"radius": "0px",
|
|
229
|
+
"chart-1": "320 100% 55%",
|
|
230
|
+
"chart-2": "180 100% 50%",
|
|
231
|
+
"chart-3": "280 100% 50%",
|
|
232
|
+
"chart-4": "60 100% 50%",
|
|
233
|
+
"chart-5": "120 100% 50%"
|
|
234
|
+
}'::jsonb,
|
|
235
|
+
'& h1, & h2, & h3, & h4, & h5, & h6 {
|
|
236
|
+
text-shadow: 0 0 5px hsl(var(--primary)), 0 0 10px hsl(var(--secondary));
|
|
237
|
+
}
|
|
238
|
+
& button, & [role="button"] {
|
|
239
|
+
box-shadow: 0 0 5px hsl(var(--primary) / 0.5);
|
|
240
|
+
transition: box-shadow 0.3s ease;
|
|
241
|
+
}
|
|
242
|
+
& button:hover, & [role="button"]:hover {
|
|
243
|
+
box-shadow: 0 0 15px hsl(var(--primary));
|
|
244
|
+
}
|
|
245
|
+
& .card, & [class*="card"] {
|
|
246
|
+
border: 1px solid hsl(var(--primary));
|
|
247
|
+
box-shadow: 0 0 10px hsl(var(--primary) / 0.2);
|
|
248
|
+
}
|
|
249
|
+
& .border {
|
|
250
|
+
border-color: hsl(var(--border));
|
|
251
|
+
box-shadow: 0 0 5px hsl(var(--border) / 0.3);
|
|
252
|
+
}'
|
|
253
|
+
)
|
|
254
|
+
ON CONFLICT (slug) DO NOTHING;
|