@nocobase/client-v2 2.2.50 → 2.2.52

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.
@@ -0,0 +1,42 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import { useRequest } from 'ahooks';
11
+ import type { FlowModel } from '@nocobase/flow-engine';
12
+ import React, { useEffect } from 'react';
13
+ import { isRouteContentConfirmed } from './FlowModelRepository';
14
+
15
+ // Keep the current renderer mounted while the first editor confirms the stored page or grid.
16
+ export function useRouteContentRequest(
17
+ load: (forEditing: boolean) => Promise<FlowModel>,
18
+ editing: boolean,
19
+ refreshDeps: unknown[],
20
+ ) {
21
+ const { data, error, loading, refresh } = useRequest(
22
+ async () => ({ model: await load(editing), confirmed: editing, refreshDeps }),
23
+ { refreshDeps },
24
+ );
25
+ const current = data && refreshDeps.every((dep, i) => Object.is(dep, data.refreshDeps[i])) ? data : undefined;
26
+ const needsConfirmation =
27
+ editing && !!current?.model && !current.confirmed && !isRouteContentConfirmed(current.model);
28
+ useEffect(() => {
29
+ if (needsConfirmation && !loading && !error) refresh();
30
+ }, [needsConfirmation, loading, error, refresh]);
31
+
32
+ return { model: current?.model, error, loading, needsConfirmation };
33
+ }
34
+
35
+ export function RouteContent({ pending, children }: React.PropsWithChildren<{ pending: boolean }>) {
36
+ // React 18 forwards inert as a string attribute. Keep the same DOM and component state during initialization.
37
+ return (
38
+ <div style={{ display: 'contents' }} {...(pending ? { inert: '' } : {})}>
39
+ {children}
40
+ </div>
41
+ );
42
+ }