@firecms/core 3.4.0-canary.cb27f16 → 3.4.0-canary.ce97da7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/components/ErrorBoundary.d.ts +1 -3
- package/dist/components/LicenseBanner.d.ts +23 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/contexts/LicenseStatusContext.d.ts +16 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/plugin_translations.d.ts +38 -0
- package/dist/core/pro_plugins.d.ts +40 -0
- package/dist/de-DMp6cIY1.js +702 -0
- package/dist/de-DMp6cIY1.js.map +1 -0
- package/dist/editor/extensions/Image.d.ts +11 -0
- package/dist/editor/index.d.ts +2 -1
- package/dist/editor/lazy_editor.d.ts +6 -0
- package/dist/editor-BSo_aS1I.js +4563 -0
- package/dist/editor-BSo_aS1I.js.map +1 -0
- package/dist/fr-Cckz4IkR.js +702 -0
- package/dist/fr-Cckz4IkR.js.map +1 -0
- package/dist/hi-CDCoIqbu.js +702 -0
- package/dist/hi-CDCoIqbu.js.map +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useLicenseStatus.d.ts +16 -0
- package/dist/hooks/useProjectLog.d.ts +11 -6
- package/dist/hooks/useTranslation.d.ts +1 -1
- package/dist/index.es.js +7938 -15928
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +7710 -6925
- package/dist/index.umd.js.map +1 -1
- package/dist/it-BJCUqixj.js +702 -0
- package/dist/it-BJCUqixj.js.map +1 -0
- package/dist/pl-DgT_joFf.js +704 -0
- package/dist/pl-DgT_joFf.js.map +1 -0
- package/dist/pt-B3dN3x0X.js +704 -0
- package/dist/pt-B3dN3x0X.js.map +1 -0
- package/dist/types/analytics.d.ts +1 -1
- package/dist/types/firecms.d.ts +18 -1
- package/dist/types/firecms_context.d.ts +8 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/license.d.ts +54 -0
- package/dist/types/plugins.d.ts +9 -1
- package/dist/types/translations.d.ts +35 -2
- package/dist/util/date_fns_locales.d.ts +18 -0
- package/dist/util/index.d.ts +1 -0
- package/dist/util/lazy_eager.d.ts +3 -3
- package/package.json +4 -4
- package/src/app/Scaffold.tsx +7 -0
- package/src/components/ErrorBoundary.tsx +12 -18
- package/src/components/LicenseBanner.tsx +209 -0
- package/src/components/index.tsx +1 -0
- package/src/contexts/LicenseStatusContext.tsx +50 -0
- package/src/core/DefaultAppBar.tsx +28 -16
- package/src/core/FireCMS.tsx +73 -47
- package/src/core/SideDialogs.tsx +44 -1
- package/src/core/index.tsx +1 -0
- package/src/core/plugin_translations.ts +87 -0
- package/src/core/pro_plugins.ts +79 -0
- package/src/editor/components/SlashCommandMenu.tsx +4 -1
- package/src/editor/extensions/Image.ts +17 -1
- package/src/editor/hooks/useProseMirror.ts +5 -0
- package/src/editor/index.ts +11 -1
- package/src/editor/lazy_editor.tsx +33 -0
- package/src/hooks/index.tsx +2 -0
- package/src/hooks/useBuildNavigationController.tsx +47 -7
- package/src/hooks/useFireCMSContext.tsx +7 -3
- package/src/hooks/useLicenseStatus.tsx +32 -0
- package/src/hooks/useProjectLog.tsx +27 -9
- package/src/hooks/useTranslation.ts +3 -1
- package/src/i18n/FireCMSi18nProvider.tsx +164 -34
- package/src/locales/de.ts +18 -2
- package/src/locales/en.ts +21 -3
- package/src/locales/es.ts +18 -2
- package/src/locales/fr.ts +18 -2
- package/src/locales/hi.ts +18 -2
- package/src/locales/it.ts +18 -2
- package/src/locales/pl.ts +18 -2
- package/src/locales/pt.ts +18 -2
- package/src/preview/components/DatePreview.tsx +2 -4
- package/src/types/analytics.ts +3 -0
- package/src/types/firecms.tsx +19 -1
- package/src/types/firecms_context.tsx +9 -0
- package/src/types/index.ts +1 -0
- package/src/types/license.ts +62 -0
- package/src/types/plugins.tsx +10 -1
- package/src/types/translations.ts +35 -2
- package/src/util/date_fns_locales.ts +168 -0
- package/src/util/index.ts +1 -0
- package/src/util/lazy_eager.tsx +30 -8
- package/src/util/navigation_utils.ts +6 -1
- package/src/util/useStorageUploadController.tsx +6 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Alert, Button, CloseIcon, IconButton } from "@firecms/ui";
|
|
3
|
+
import { AccessResponse } from "../types";
|
|
4
|
+
import { getLicenseSubscribeUrl } from "../core/pro_plugins";
|
|
5
|
+
import { useLicenseStatus } from "../hooks/useLicenseStatus";
|
|
6
|
+
import { useTranslation } from "../hooks/useTranslation";
|
|
7
|
+
|
|
8
|
+
const DISMISSED_STORAGE_KEY = "firecms_license_banner_dismissed";
|
|
9
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @group Components
|
|
13
|
+
*/
|
|
14
|
+
export interface LicenseBannerProps {
|
|
15
|
+
/**
|
|
16
|
+
* Applied to the banner's outer element when there is something to show.
|
|
17
|
+
*/
|
|
18
|
+
className?: string;
|
|
19
|
+
style?: React.CSSProperties;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type BannerContent = {
|
|
23
|
+
state: string;
|
|
24
|
+
color: "info" | "warning";
|
|
25
|
+
message: string;
|
|
26
|
+
linkLabel: string;
|
|
27
|
+
href: string;
|
|
28
|
+
dismissible: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Tells the user where their FireCMS PRO license stands: days left in the
|
|
33
|
+
* trial, a paused state, or a license that covers fewer projects than are
|
|
34
|
+
* linked to it. Renders nothing when licensed, when no license is needed, and
|
|
35
|
+
* while the status is unknown.
|
|
36
|
+
*
|
|
37
|
+
* The default `Scaffold` already renders it above the main content. Place it
|
|
38
|
+
* yourself only in a custom layout.
|
|
39
|
+
*
|
|
40
|
+
* @group Components
|
|
41
|
+
*/
|
|
42
|
+
export function LicenseBanner({
|
|
43
|
+
className,
|
|
44
|
+
style
|
|
45
|
+
}: LicenseBannerProps) {
|
|
46
|
+
|
|
47
|
+
const licenseStatus = useLicenseStatus();
|
|
48
|
+
const { t, i18n } = useTranslation();
|
|
49
|
+
|
|
50
|
+
// States dismissed in this browser session; a different state shows again.
|
|
51
|
+
const [dismissed, setDismissed] = useState<string[]>(readDismissed);
|
|
52
|
+
|
|
53
|
+
// `language`, not `resolvedLanguage`: locale bundles are added after init,
|
|
54
|
+
// and `resolvedLanguage` stays on the English fallback when they are.
|
|
55
|
+
const content = licenseStatus
|
|
56
|
+
? buildBannerContent(licenseStatus, t, i18n?.language)
|
|
57
|
+
: null;
|
|
58
|
+
|
|
59
|
+
if (!content || (content.dismissible && dismissed.includes(content.state)))
|
|
60
|
+
return null;
|
|
61
|
+
|
|
62
|
+
const dismiss = () => {
|
|
63
|
+
const next = [...dismissed, content.state];
|
|
64
|
+
writeDismissed(next);
|
|
65
|
+
setDismissed(next);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div className={className} style={style}>
|
|
70
|
+
<Alert
|
|
71
|
+
color={content.color}
|
|
72
|
+
size={"small"}
|
|
73
|
+
className={"text-sm"}
|
|
74
|
+
action={<div className={"flex flex-row items-center gap-1 flex-shrink-0"}>
|
|
75
|
+
<Button
|
|
76
|
+
variant={"text"}
|
|
77
|
+
size={"small"}
|
|
78
|
+
component={"a"}
|
|
79
|
+
href={content.href}
|
|
80
|
+
target={"_blank"}
|
|
81
|
+
rel={"noopener noreferrer"}>
|
|
82
|
+
{content.linkLabel}
|
|
83
|
+
</Button>
|
|
84
|
+
{content.dismissible && <IconButton
|
|
85
|
+
size={"small"}
|
|
86
|
+
aria-label={t("close")}
|
|
87
|
+
onClick={dismiss}>
|
|
88
|
+
<CloseIcon size={"small"}/>
|
|
89
|
+
</IconButton>}
|
|
90
|
+
</div>}>
|
|
91
|
+
{content.message}
|
|
92
|
+
</Alert>
|
|
93
|
+
</div>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
type Translate = ReturnType<typeof useTranslation>["t"];
|
|
98
|
+
|
|
99
|
+
function buildBannerContent(status: AccessResponse,
|
|
100
|
+
t: Translate,
|
|
101
|
+
language: string | undefined): BannerContent | null {
|
|
102
|
+
const href = getLicenseSubscribeUrl(status);
|
|
103
|
+
switch (status.licenseState) {
|
|
104
|
+
case "trial": {
|
|
105
|
+
const days = trialDaysLeft(status);
|
|
106
|
+
if (days === null) return null;
|
|
107
|
+
return {
|
|
108
|
+
state: "trial",
|
|
109
|
+
color: "info",
|
|
110
|
+
message: t("license_trial_banner", {
|
|
111
|
+
count: days,
|
|
112
|
+
days: String(days)
|
|
113
|
+
}),
|
|
114
|
+
linkLabel: t("license_get_license"),
|
|
115
|
+
href,
|
|
116
|
+
dismissible: true
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
case "expired": {
|
|
120
|
+
const date = formatDate(status.trialEndsAt, language);
|
|
121
|
+
return {
|
|
122
|
+
state: "expired",
|
|
123
|
+
color: "warning",
|
|
124
|
+
message: date
|
|
125
|
+
? t("license_expired_banner", { date })
|
|
126
|
+
: t("license_expired_banner_undated"),
|
|
127
|
+
linkLabel: t("license_get_license"),
|
|
128
|
+
href,
|
|
129
|
+
dismissible: false
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
case "invalid_project":
|
|
133
|
+
return {
|
|
134
|
+
state: "invalid_project",
|
|
135
|
+
color: "warning",
|
|
136
|
+
message: status.projectId
|
|
137
|
+
? t("license_invalid_project_banner", { projectId: status.projectId })
|
|
138
|
+
: t("license_invalid_project_banner_unnamed"),
|
|
139
|
+
linkLabel: t("license_add_project_to_license"),
|
|
140
|
+
href,
|
|
141
|
+
dismissible: false
|
|
142
|
+
};
|
|
143
|
+
case "over_quota": {
|
|
144
|
+
const licensed = status.licensedProjects;
|
|
145
|
+
const actual = status.linkedProjects;
|
|
146
|
+
if (!isCount(licensed) || !isCount(actual)) return null;
|
|
147
|
+
return {
|
|
148
|
+
state: "over_quota",
|
|
149
|
+
color: "info",
|
|
150
|
+
message: t("license_over_quota_banner", {
|
|
151
|
+
count: licensed,
|
|
152
|
+
licensed: String(licensed),
|
|
153
|
+
actual: String(actual)
|
|
154
|
+
}),
|
|
155
|
+
linkLabel: t("license_update_license"),
|
|
156
|
+
href,
|
|
157
|
+
dismissible: true
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
default:
|
|
161
|
+
// licensed, not_required, whitelisted, and servers too old to say
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function isCount(value: unknown): value is number {
|
|
167
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function trialDaysLeft(status: AccessResponse): number | null {
|
|
171
|
+
if (isCount(status.daysLeft)) return Math.ceil(status.daysLeft);
|
|
172
|
+
const end = status.trialEndsAt ? new Date(status.trialEndsAt).getTime() : NaN;
|
|
173
|
+
if (Number.isNaN(end)) return null;
|
|
174
|
+
return Math.max(0, Math.ceil((end - Date.now()) / DAY_MS));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function formatDate(iso: string | undefined, language: string | undefined): string | null {
|
|
178
|
+
if (!iso) return null;
|
|
179
|
+
const date = new Date(iso);
|
|
180
|
+
if (Number.isNaN(date.getTime())) return null;
|
|
181
|
+
const options: Intl.DateTimeFormatOptions = {
|
|
182
|
+
year: "numeric",
|
|
183
|
+
month: "long",
|
|
184
|
+
day: "numeric"
|
|
185
|
+
};
|
|
186
|
+
try {
|
|
187
|
+
return new Intl.DateTimeFormat(language, options).format(date);
|
|
188
|
+
} catch {
|
|
189
|
+
return date.toLocaleDateString(undefined, options);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function readDismissed(): string[] {
|
|
194
|
+
try {
|
|
195
|
+
const value = sessionStorage.getItem(DISMISSED_STORAGE_KEY);
|
|
196
|
+
const parsed = value ? JSON.parse(value) : [];
|
|
197
|
+
return Array.isArray(parsed) ? parsed.filter((s): s is string => typeof s === "string") : [];
|
|
198
|
+
} catch {
|
|
199
|
+
return [];
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function writeDismissed(states: string[]) {
|
|
204
|
+
try {
|
|
205
|
+
sessionStorage.setItem(DISMISSED_STORAGE_KEY, JSON.stringify(states));
|
|
206
|
+
} catch {
|
|
207
|
+
// Private mode or storage disabled: dismissed for this page view only.
|
|
208
|
+
}
|
|
209
|
+
}
|
package/src/components/index.tsx
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { AccessResponse } from "../types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* License status of the enclosing `FireCMS`. `undefined` means there is no
|
|
6
|
+
* `FireCMS` above; `null` means the check has not answered (or was skipped).
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export const LicenseStatusContext = React.createContext<AccessResponse | null | undefined>(undefined);
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
* The same status, published outside React's tree.
|
|
13
|
+
*
|
|
14
|
+
* `useBuildNavigationController` runs in the app component that renders
|
|
15
|
+
* `<FireCMS>`, above it, so it cannot read the context. It still has to know
|
|
16
|
+
* when PRO is paused: it applies the plugins' collection, view and home page
|
|
17
|
+
* navigation contributions itself. `FireCMS` publishes here, and the navigation
|
|
18
|
+
* controller subscribes with `useSyncExternalStore`.
|
|
19
|
+
*
|
|
20
|
+
* One value per page: two `FireCMS` instances on one page would share it, which
|
|
21
|
+
* is harmless because both check the same project.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
let currentStatus: AccessResponse | null = null;
|
|
25
|
+
const listeners = new Set<() => void>();
|
|
26
|
+
|
|
27
|
+
/** @internal */
|
|
28
|
+
export function getLicenseStatusSnapshot(): AccessResponse | null {
|
|
29
|
+
return currentStatus;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @internal */
|
|
33
|
+
export function getServerLicenseStatusSnapshot(): AccessResponse | null {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @internal */
|
|
38
|
+
export function subscribeLicenseStatus(listener: () => void): () => void {
|
|
39
|
+
listeners.add(listener);
|
|
40
|
+
return () => {
|
|
41
|
+
listeners.delete(listener);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** @internal */
|
|
46
|
+
export function publishLicenseStatus(status: AccessResponse | null): void {
|
|
47
|
+
if (status === currentStatus) return;
|
|
48
|
+
currentStatus = status;
|
|
49
|
+
listeners.forEach(listener => listener());
|
|
50
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
3
|
import { Link, useNavigate } from "react-router-dom";
|
|
4
|
-
import { ErrorBoundary,
|
|
4
|
+
import { ErrorBoundary, LanguageToggle } from "../components";
|
|
5
5
|
import {
|
|
6
6
|
Avatar,
|
|
7
7
|
BrightnessMediumIcon,
|
|
@@ -20,6 +20,7 @@ import { useAuthController, useLargeLayout, useModeController, useNavigationCont
|
|
|
20
20
|
import { User } from "../types";
|
|
21
21
|
import { useApp } from "../app/useApp";
|
|
22
22
|
import { useBreadcrumbsController } from "../hooks/useBreadcrumbsController";
|
|
23
|
+
import { DrawerLogo } from "./DefaultDrawer";
|
|
23
24
|
|
|
24
25
|
export type DefaultAppBarProps<ADDITIONAL_PROPS = object> = {
|
|
25
26
|
|
|
@@ -119,32 +120,43 @@ export const DefaultAppBar = function DefaultAppBar({
|
|
|
119
120
|
"flex flex-row gap-2 px-4 items-center",
|
|
120
121
|
{
|
|
121
122
|
"pl-[19rem]": drawerOpen && largeLayout,
|
|
122
|
-
|
|
123
|
+
// The title has to sit at the same x whether or not a Drawer
|
|
124
|
+
// is mounted, so the bar reserves the collapsed rail's width
|
|
125
|
+
// in both cases. Only a pinned-open drawer moves it, in step
|
|
126
|
+
// with the drawer itself.
|
|
127
|
+
"pl-24": !(drawerOpen && largeLayout) && (hasDrawer || largeLayout),
|
|
123
128
|
"z-10": largeLayout,
|
|
124
129
|
"duration-100": drawerOpen && largeLayout,
|
|
125
130
|
},
|
|
126
131
|
className)}>
|
|
127
132
|
|
|
128
133
|
|
|
134
|
+
{/* Rendering DrawerLogo itself, rather than rebuilding its box here,
|
|
135
|
+
is what keeps the mark from moving when a screen with a drawer
|
|
136
|
+
follows one without: matching it by hand still left it 4px high,
|
|
137
|
+
because DrawerLogo centres a 40px box under `pt-4` instead of
|
|
138
|
+
centring in the 64px bar.
|
|
139
|
+
|
|
140
|
+
Gated on `largeLayout`, not on `lg:`: useLargeLayout resolves at
|
|
141
|
+
min-width 1025px while Tailwind's `lg:` starts at 1024px, and at
|
|
142
|
+
exactly 1024px the logo would render into a bar that had not
|
|
143
|
+
reserved room for it, landing on top of the title. */}
|
|
144
|
+
{navigation && !hasDrawer && largeLayout &&
|
|
145
|
+
<div className={"absolute left-0 top-0"}>
|
|
146
|
+
<DrawerLogo logo={logo} />
|
|
147
|
+
</div>}
|
|
148
|
+
|
|
129
149
|
{navigation && <div className="mr-2 hidden lg:block">
|
|
130
150
|
<Link
|
|
131
151
|
className="visited:text-inherit visited:dark:text-inherit block"
|
|
132
152
|
to={navigation?.basePath ?? "/"}
|
|
133
153
|
>
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
{typeof title === "string"
|
|
142
|
-
? <Typography variant="subtitle1"
|
|
143
|
-
noWrap>
|
|
144
|
-
{title}
|
|
145
|
-
</Typography>
|
|
146
|
-
: title}
|
|
147
|
-
</div>
|
|
154
|
+
{typeof title === "string"
|
|
155
|
+
? <Typography variant="subtitle1"
|
|
156
|
+
noWrap>
|
|
157
|
+
{title}
|
|
158
|
+
</Typography>
|
|
159
|
+
: title}
|
|
148
160
|
</Link>
|
|
149
161
|
</div>}
|
|
150
162
|
|
package/src/core/FireCMS.tsx
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import React, { useEffect, useMemo } from "react";
|
|
4
|
-
import { CenteredView
|
|
3
|
+
import React, { useEffect, useMemo, useRef } from "react";
|
|
4
|
+
import { CenteredView } from "@firecms/ui";
|
|
5
|
+
import { AppliedBundles, applyPluginTranslations, createAppliedBundles } from "./plugin_translations";
|
|
6
|
+
import { filterPausedPlugins, isProPaused } from "./pro_plugins";
|
|
5
7
|
import { AuthController } from "../types";
|
|
6
8
|
import { CustomizationController, FireCMSContext, FireCMSPlugin, FireCMSProps, User } from "../types";
|
|
7
9
|
import { AuthControllerContext, ModeControllerProvider } from "../contexts";
|
|
@@ -23,6 +25,7 @@ import { AnalyticsContext } from "../contexts/AnalyticsContext";
|
|
|
23
25
|
import { useProjectLog } from "../hooks/useProjectLog";
|
|
24
26
|
import { BreadcrumbsProvider } from "../contexts/BreacrumbsContext";
|
|
25
27
|
import { InternalUserManagementContext } from "../contexts/InternalUserManagementContext";
|
|
28
|
+
import { LicenseStatusContext, publishLicenseStatus } from "../contexts/LicenseStatusContext";
|
|
26
29
|
|
|
27
30
|
/**
|
|
28
31
|
* If you are using independent components of the CMS
|
|
@@ -54,6 +57,7 @@ export function FireCMS<USER extends User>(props: FireCMSProps<USER>) {
|
|
|
54
57
|
components,
|
|
55
58
|
navigationController,
|
|
56
59
|
apiKey,
|
|
60
|
+
telemetry,
|
|
57
61
|
userManagement: _userManagement
|
|
58
62
|
} = props;
|
|
59
63
|
|
|
@@ -61,11 +65,42 @@ export function FireCMS<USER extends User>(props: FireCMSProps<USER>) {
|
|
|
61
65
|
console.warn("The `plugins` prop is deprecated in the FireCMS component. You should pass your plugins to `useBuildNavigationController` instead.");
|
|
62
66
|
}
|
|
63
67
|
|
|
64
|
-
const {
|
|
68
|
+
const { i18n } = useTranslation();
|
|
65
69
|
|
|
66
70
|
const modeController = useBuildModeController();
|
|
67
71
|
|
|
68
|
-
|
|
72
|
+
// Every plugin the app mounts. The license check is sent all of their keys:
|
|
73
|
+
// the server decides from them whether the project needs a license.
|
|
74
|
+
const allPlugins = navigationController.plugins ?? _pluginsProp;
|
|
75
|
+
|
|
76
|
+
const licenseStatus = useProjectLog({
|
|
77
|
+
apiKey,
|
|
78
|
+
telemetry,
|
|
79
|
+
authController,
|
|
80
|
+
dataSourceDelegate,
|
|
81
|
+
plugins: allPlugins
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// The CMS always renders. While PRO is paused, PRO plugins drop out of
|
|
85
|
+
// everything below (providers, form, collection view and home page
|
|
86
|
+
// contributions); `useBuildNavigationController` drops their collection,
|
|
87
|
+
// view and navigation contributions from the status published below.
|
|
88
|
+
const plugins = useMemo(
|
|
89
|
+
() => filterPausedPlugins(allPlugins, licenseStatus),
|
|
90
|
+
[allPlugins, licenseStatus]
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
publishLicenseStatus(licenseStatus);
|
|
95
|
+
if (licenseStatus?.message) {
|
|
96
|
+
if (isProPaused(licenseStatus)) console.warn(licenseStatus.message);
|
|
97
|
+
else console.debug(licenseStatus.message);
|
|
98
|
+
}
|
|
99
|
+
}, [licenseStatus]);
|
|
100
|
+
|
|
101
|
+
// The status belongs to this FireCMS; do not leave it to a later one.
|
|
102
|
+
useEffect(() => () => publishLicenseStatus(null), []);
|
|
103
|
+
|
|
69
104
|
const userManagement = plugins?.find(p => p.userManagement)?.userManagement
|
|
70
105
|
?? _userManagement
|
|
71
106
|
?? {
|
|
@@ -95,13 +130,6 @@ export function FireCMS<USER extends User>(props: FireCMSProps<USER>) {
|
|
|
95
130
|
onAnalyticsEvent
|
|
96
131
|
}), []);
|
|
97
132
|
|
|
98
|
-
const accessResponse = useProjectLog({
|
|
99
|
-
apiKey,
|
|
100
|
-
authController,
|
|
101
|
-
dataSourceDelegate,
|
|
102
|
-
plugins
|
|
103
|
-
});
|
|
104
|
-
|
|
105
133
|
/**
|
|
106
134
|
* Controller in charge of fetching and persisting data
|
|
107
135
|
*/
|
|
@@ -112,27 +140,42 @@ export function FireCMS<USER extends User>(props: FireCMSProps<USER>) {
|
|
|
112
140
|
authController
|
|
113
141
|
});
|
|
114
142
|
|
|
115
|
-
// Inject plugin translations into the
|
|
143
|
+
// Inject plugin translations into the live i18next instance.
|
|
144
|
+
//
|
|
145
|
+
// The work, and the reason repeat writes have to be suppressed, is in
|
|
146
|
+
// `applyPluginTranslations`. Paused plugins keep their strings: app code
|
|
147
|
+
// may render their components directly, and strings unlock nothing.
|
|
148
|
+
const appliedBundles = useRef<AppliedBundles>(createAppliedBundles());
|
|
149
|
+
const appliedTo = useRef<unknown>(null);
|
|
150
|
+
|
|
116
151
|
useEffect(() => {
|
|
117
152
|
if (!i18n) return;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
153
|
+
|
|
154
|
+
// A different instance has its own store and has been written nothing.
|
|
155
|
+
// Reset here rather than in an effect of its own, which would run after
|
|
156
|
+
// this one and wipe the record of what this pass just wrote.
|
|
157
|
+
if (appliedTo.current !== i18n) {
|
|
158
|
+
appliedTo.current = i18n;
|
|
159
|
+
appliedBundles.current = createAppliedBundles();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
let active = true;
|
|
163
|
+
const isActive = () => active;
|
|
164
|
+
const applyFor = (language: string) => applyPluginTranslations({
|
|
165
|
+
i18n,
|
|
166
|
+
plugins: allPlugins,
|
|
167
|
+
language,
|
|
168
|
+
applied: appliedBundles.current,
|
|
169
|
+
isActive
|
|
130
170
|
});
|
|
131
|
-
}, [i18n, plugins]);
|
|
132
171
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
172
|
+
applyFor(i18n.language ?? "en");
|
|
173
|
+
i18n.on("languageChanged", applyFor);
|
|
174
|
+
return () => {
|
|
175
|
+
active = false;
|
|
176
|
+
i18n.off("languageChanged", applyFor);
|
|
177
|
+
};
|
|
178
|
+
}, [i18n, allPlugins]);
|
|
136
179
|
|
|
137
180
|
if (navigationController.navigationLoadingError) {
|
|
138
181
|
return (
|
|
@@ -154,26 +197,8 @@ export function FireCMS<USER extends User>(props: FireCMSProps<USER>) {
|
|
|
154
197
|
);
|
|
155
198
|
}
|
|
156
199
|
|
|
157
|
-
if (accessResponse?.blocked) {
|
|
158
|
-
return (
|
|
159
|
-
<CenteredView maxWidth={"md"} fullScreen={true} className={"flex flex-col gap-2"}>
|
|
160
|
-
{/* eslint-disable-next-line i18next/no-literal-string */}
|
|
161
|
-
<Typography variant={"h4"} gutterBottom>
|
|
162
|
-
{t("license_needed")}
|
|
163
|
-
</Typography>
|
|
164
|
-
<Typography>
|
|
165
|
-
{(() => {
|
|
166
|
-
const parts = t("license_description", { email: "%%EMAIL%%" }).split("%%EMAIL%%");
|
|
167
|
-
return <>{parts[0]}<a href={"mailto:hello@firecms.co"}>hello@firecms.co</a>{parts[1]}</>;
|
|
168
|
-
})()}
|
|
169
|
-
</Typography>
|
|
170
|
-
{accessResponse?.message &&
|
|
171
|
-
<Typography>{accessResponse?.message}</Typography>}
|
|
172
|
-
</CenteredView>
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
200
|
return (
|
|
201
|
+
<LicenseStatusContext.Provider value={licenseStatus}>
|
|
177
202
|
<AnalyticsContext.Provider value={analyticsController}>
|
|
178
203
|
<CustomizationControllerContext.Provider value={customizationController}>
|
|
179
204
|
<UserConfigurationPersistenceContext.Provider
|
|
@@ -209,6 +234,7 @@ export function FireCMS<USER extends User>(props: FireCMSProps<USER>) {
|
|
|
209
234
|
</UserConfigurationPersistenceContext.Provider>
|
|
210
235
|
</CustomizationControllerContext.Provider>
|
|
211
236
|
</AnalyticsContext.Provider>
|
|
237
|
+
</LicenseStatusContext.Provider>
|
|
212
238
|
);
|
|
213
239
|
|
|
214
240
|
}
|
package/src/core/SideDialogs.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useContext, useEffect, useState } from "react";
|
|
1
|
+
import React, { useContext, useEffect, useRef, useState } from "react";
|
|
2
2
|
import { useSideDialogsController } from "../hooks";
|
|
3
3
|
import { EntitySidePanelProps, SideDialogPanelProps } from "../types";
|
|
4
4
|
import { Sheet } from "@firecms/ui";
|
|
@@ -67,6 +67,40 @@ export function SideDialogs() {
|
|
|
67
67
|
</>;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
// Menus, selects and popovers opened inside a side dialog are dismissed by Radix as
|
|
71
|
+
// soon as the pointer goes down, but the dialog underneath only makes up its mind on
|
|
72
|
+
// the click that follows, when that layer is already gone and the dialog looks like
|
|
73
|
+
// the topmost one. Without this, the click that dismisses an open menu also asks the
|
|
74
|
+
// panel to close, and an edited entity greets the user with the unsaved changes dialog.
|
|
75
|
+
const NESTED_LAYER_SELECTOR = [
|
|
76
|
+
"[data-radix-menu-content]",
|
|
77
|
+
"[data-radix-select-viewport]",
|
|
78
|
+
"[data-radix-popper-content-wrapper] [role=\"dialog\"]",
|
|
79
|
+
"[data-suggestion-menu=\"true\"]"
|
|
80
|
+
].join(",");
|
|
81
|
+
|
|
82
|
+
function useNestedLayerOpenOnPointerDown() {
|
|
83
|
+
const ref = useRef(false);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
const onPointerDown = () => {
|
|
86
|
+
ref.current = Array.from(document.querySelectorAll(NESTED_LAYER_SELECTOR))
|
|
87
|
+
.some(element => window.getComputedStyle(element).visibility !== "hidden");
|
|
88
|
+
};
|
|
89
|
+
// the keyboard dismisses one layer at a time on its own, so a stale pointer
|
|
90
|
+
// interaction must not swallow a close requested with Escape
|
|
91
|
+
const onKeyDown = () => {
|
|
92
|
+
ref.current = false;
|
|
93
|
+
};
|
|
94
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
95
|
+
document.addEventListener("keydown", onKeyDown, true);
|
|
96
|
+
return () => {
|
|
97
|
+
document.removeEventListener("pointerdown", onPointerDown, true);
|
|
98
|
+
document.removeEventListener("keydown", onKeyDown, true);
|
|
99
|
+
};
|
|
100
|
+
}, []);
|
|
101
|
+
return ref;
|
|
102
|
+
}
|
|
103
|
+
|
|
70
104
|
function SideDialogView({
|
|
71
105
|
offsetPosition,
|
|
72
106
|
panel
|
|
@@ -82,6 +116,8 @@ function SideDialogView({
|
|
|
82
116
|
|
|
83
117
|
const [pendingClose, setPendingClose] = useState(false);
|
|
84
118
|
|
|
119
|
+
const nestedLayerOpenOnPointerDown = useNestedLayerOpenOnPointerDown();
|
|
120
|
+
|
|
85
121
|
const widthRef = React.useRef<string | undefined>(panel?.width);
|
|
86
122
|
const width = widthRef.current;
|
|
87
123
|
|
|
@@ -144,6 +180,13 @@ function SideDialogView({
|
|
|
144
180
|
// Let Tiptap handle closing the menu first
|
|
145
181
|
return;
|
|
146
182
|
}
|
|
183
|
+
// this interaction started on top of a menu or popover: it dismissed
|
|
184
|
+
// that layer, it was not a request to close the panel. The flag is
|
|
185
|
+
// left alone because a single click asks to close more than once;
|
|
186
|
+
// the next pointer or key interaction recomputes it.
|
|
187
|
+
if (nestedLayerOpenOnPointerDown.current) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
147
190
|
onCloseRequest();
|
|
148
191
|
}
|
|
149
192
|
}}
|
package/src/core/index.tsx
CHANGED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { i18n } from "i18next";
|
|
2
|
+
import { FireCMSPlugin, PluginTranslations } from "../types";
|
|
3
|
+
|
|
4
|
+
const FIRECMS_NS = "firecms_core";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Record of which bundles have already been written to which locale, so the
|
|
8
|
+
* same one is never written twice.
|
|
9
|
+
*
|
|
10
|
+
* Plugin translation objects are module-level constants and a lazily loaded one
|
|
11
|
+
* resolves to the same module object every time, so identity is a sound test.
|
|
12
|
+
*/
|
|
13
|
+
export type AppliedBundles = Map<string, Set<object>>;
|
|
14
|
+
|
|
15
|
+
export function createAppliedBundles(): AppliedBundles {
|
|
16
|
+
return new Map();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Write the plugins' strings for one language into a live i18next instance.
|
|
21
|
+
*
|
|
22
|
+
* Only the language in use is resolved, plus English, which every other language
|
|
23
|
+
* falls back to — a locale given as a function is a bundle that has not been
|
|
24
|
+
* downloaded yet, and downloading all of them would undo the point of deferring
|
|
25
|
+
* them. Plain records are applied for every locale, as before: they are already
|
|
26
|
+
* in the bundle, so there is nothing to save by holding them back.
|
|
27
|
+
*
|
|
28
|
+
* `applied` is what stops the injection feeding itself. A write raises a store
|
|
29
|
+
* event; the event repaints everything subscribed to this instance, including
|
|
30
|
+
* the component that owns the `plugins` array — the collection editor and SaaS
|
|
31
|
+
* plugin hooks both call `useTranslation` — and that array is an inline literal,
|
|
32
|
+
* so its fresh identity re-runs the effect that called this. react-i18next
|
|
33
|
+
* happens to stop re-rendering after one pass, but that is a bail-out rather
|
|
34
|
+
* than a guarantee, and the redundant writes are worth avoiding regardless.
|
|
35
|
+
*
|
|
36
|
+
* Returns a function that reports whether the caller is still mounted, so a
|
|
37
|
+
* bundle that arrives after unmount is dropped rather than written.
|
|
38
|
+
*/
|
|
39
|
+
export function applyPluginTranslations({
|
|
40
|
+
i18n,
|
|
41
|
+
plugins,
|
|
42
|
+
language,
|
|
43
|
+
applied,
|
|
44
|
+
isActive = () => true
|
|
45
|
+
}: {
|
|
46
|
+
i18n: i18n;
|
|
47
|
+
plugins?: FireCMSPlugin<any, any, any>[];
|
|
48
|
+
language: string;
|
|
49
|
+
applied: AppliedBundles;
|
|
50
|
+
isActive?: () => boolean;
|
|
51
|
+
}) {
|
|
52
|
+
const wanted = new Set([language.split("-")[0], "en"]);
|
|
53
|
+
|
|
54
|
+
const add = (locale: string, bundle: PluginTranslations) => {
|
|
55
|
+
if (!isActive()) return;
|
|
56
|
+
let written = applied.get(locale);
|
|
57
|
+
if (!written) {
|
|
58
|
+
written = new Set();
|
|
59
|
+
applied.set(locale, written);
|
|
60
|
+
}
|
|
61
|
+
if (written.has(bundle)) return;
|
|
62
|
+
written.add(bundle);
|
|
63
|
+
i18n.addResourceBundle(
|
|
64
|
+
locale,
|
|
65
|
+
FIRECMS_NS,
|
|
66
|
+
bundle,
|
|
67
|
+
true, // deep merge
|
|
68
|
+
true // overwrite
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
plugins?.forEach((plugin) => {
|
|
73
|
+
if (!plugin.i18n) return;
|
|
74
|
+
Object.entries(plugin.i18n).forEach(([locale, translations]) => {
|
|
75
|
+
if (typeof translations === "function") {
|
|
76
|
+
if (!wanted.has(locale.split("-")[0])) return;
|
|
77
|
+
translations()
|
|
78
|
+
.then((bundle) => add(locale, bundle))
|
|
79
|
+
.catch(() => {
|
|
80
|
+
// A locale that fails to load falls back to English.
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
add(locale, translations);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|