@erxes/ui 4.0.0-v2.5 → 4.0.0-v2.7
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 +13 -0
- package/dist/components/icon-tip.d.ts +7 -0
- package/dist/components/icon-tip.js +16 -0
- package/dist/hooks/use-page-hotkey.d.ts +11 -0
- package/dist/hooks/use-page-hotkey.js +21 -0
- package/dist/index.d.ts +17 -2
- package/dist/index.js +16 -1
- package/dist/modules/list/DisplayMenu.d.ts +13 -0
- package/dist/modules/list/DisplayMenu.js +66 -0
- package/dist/modules/list/ListFilter.d.ts +44 -0
- package/dist/modules/list/ListFilter.js +39 -0
- package/dist/modules/list/ViewBar.d.ts +13 -0
- package/dist/modules/list/ViewBar.js +30 -0
- package/dist/modules/record-panel/PanelDescriptionEditor.d.ts +9 -0
- package/dist/modules/record-panel/PanelDescriptionEditor.js +39 -0
- package/dist/modules/record-panel/PanelDescriptionField.d.ts +9 -0
- package/dist/modules/record-panel/PanelDescriptionField.js +35 -0
- package/dist/modules/record-panel/PanelField.d.ts +11 -0
- package/dist/modules/record-panel/PanelField.js +41 -0
- package/dist/modules/record-panel/PanelForm.d.ts +22 -0
- package/dist/modules/record-panel/PanelForm.js +81 -0
- package/dist/modules/record-panel/PanelLabel.d.ts +5 -0
- package/dist/modules/record-panel/PanelLabel.js +50 -0
- package/dist/modules/record-panel/PanelSection.d.ts +9 -0
- package/dist/modules/record-panel/PanelSection.js +21 -0
- package/dist/modules/record-panel/panelExpansion.d.ts +10 -0
- package/dist/modules/record-panel/panelExpansion.js +7 -0
- package/dist/modules/record-panel/useSaveOnLeave.d.ts +14 -0
- package/dist/modules/record-panel/useSaveOnLeave.js +42 -0
- package/dist/modules/records/ContactLink.d.ts +13 -0
- package/dist/modules/records/ContactLink.js +77 -0
- package/dist/modules/records/contacts.d.ts +35 -0
- package/dist/modules/records/contacts.js +10 -0
- package/dist/modules/records/openRecord.d.ts +39 -0
- package/dist/modules/records/openRecord.js +46 -0
- package/dist/types/UIConfig.d.ts +101 -0
- package/dist/utils/host-component.d.ts +10 -0
- package/dist/utils/host-component.js +34 -0
- package/dist/utils/plugin-runtime.d.ts +3 -1
- package/dist/utils/plugin-runtime.js +51 -9
- package/dist/utils/record-timeline.d.ts +2 -4
- package/dist/utils/record-timeline.js +4 -17
- package/package.json +2 -1
|
@@ -4,6 +4,8 @@ import { z } from "zod";
|
|
|
4
4
|
// src/utils/plugin-runtime.ts
|
|
5
5
|
let runtime = null;
|
|
6
6
|
const sessions = /* @__PURE__ */ new Map();
|
|
7
|
+
/** A token is replaced this long before it ends, so no call carries one about to expire. */
|
|
8
|
+
const RENEW_BEFORE_MS = 3e4;
|
|
7
9
|
const setPluginRuntime = (next) => {
|
|
8
10
|
runtime = next;
|
|
9
11
|
sessions.clear();
|
|
@@ -13,19 +15,58 @@ const need = () => {
|
|
|
13
15
|
if (!runtime) throw new Error("erxes plugin runtime is not available (open the plugin inside erxes)");
|
|
14
16
|
return runtime;
|
|
15
17
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const Lifetime = jsonOf(z.object({
|
|
19
|
+
iat: z.number(),
|
|
20
|
+
exp: z.number()
|
|
21
|
+
}));
|
|
22
|
+
/** A JWT's claims as text; '' for a token that isn't one (its lifetime then comes from `expiresAt`). */
|
|
23
|
+
const claimsText = (token) => {
|
|
24
|
+
try {
|
|
25
|
+
return atob((token.split(".")[1] ?? "").replaceAll("-", "+").replaceAll("_", "/"));
|
|
26
|
+
} catch {
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* How long a token lasts, from its own claims (both core's clock), so a
|
|
32
|
+
* browser whose clock is set wrong still renews on time.
|
|
33
|
+
*/
|
|
34
|
+
const lifetimeMs = (session) => {
|
|
35
|
+
const claims = Lifetime.safeParse(claimsText(session.token));
|
|
36
|
+
return claims.success ? (claims.data.exp - claims.data.iat) * 1e3 : new Date(session.expiresAt).getTime() - Date.now();
|
|
37
|
+
};
|
|
38
|
+
const renew = (plugin) => {
|
|
39
|
+
const request = need().session(plugin).then((session) => ({
|
|
40
|
+
session,
|
|
41
|
+
endsAt: Date.now() + lifetimeMs(session)
|
|
42
|
+
}));
|
|
21
43
|
sessions.set(plugin, request);
|
|
22
|
-
request.catch(() =>
|
|
44
|
+
request.catch(() => {
|
|
45
|
+
if (sessions.get(plugin) === request) sessions.delete(plugin);
|
|
46
|
+
});
|
|
23
47
|
return request;
|
|
24
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* This member's session for `plugin`, renewed 30 seconds before it ends.
|
|
51
|
+
* `refused` is a token the plugin just turned down: it is replaced once, for
|
|
52
|
+
* every call that failed with it at the same time.
|
|
53
|
+
*/
|
|
54
|
+
const sessionOf = async (plugin, refused) => {
|
|
55
|
+
const cached = sessions.get(plugin);
|
|
56
|
+
if (cached) {
|
|
57
|
+
const held = await cached.catch(() => null);
|
|
58
|
+
if (held && held.session.token !== refused && held.endsAt - Date.now() > RENEW_BEFORE_MS) return held.session;
|
|
59
|
+
const renewing = sessions.get(plugin);
|
|
60
|
+
if (renewing && renewing !== cached) return (await renewing).session;
|
|
61
|
+
}
|
|
62
|
+
return (await renew(plugin)).session;
|
|
63
|
+
};
|
|
25
64
|
const join = (base, path) => `${base.replace(/\/+$/, "")}/${path.replace(/^\/+/, "")}`;
|
|
26
65
|
/**
|
|
27
66
|
* `fetch` against a plugin's API as the signed-in member. Relative paths are
|
|
28
|
-
* resolved against the plugin's API address; a 401 renews the token once
|
|
67
|
+
* resolved against the plugin's API address; a 401 renews the token once and
|
|
68
|
+
* sends the call again, so `init.body` must be one that can be sent twice
|
|
69
|
+
* (text, an ArrayBuffer, a Blob or FormData, not a stream).
|
|
29
70
|
*/
|
|
30
71
|
const pluginFetch = async (plugin, path, init = {}) => {
|
|
31
72
|
const send = async (session) => {
|
|
@@ -38,8 +79,9 @@ const pluginFetch = async (plugin, path, init = {}) => {
|
|
|
38
79
|
credentials: "omit"
|
|
39
80
|
});
|
|
40
81
|
};
|
|
41
|
-
const
|
|
42
|
-
|
|
82
|
+
const session = await sessionOf(plugin);
|
|
83
|
+
const response = await send(session);
|
|
84
|
+
return response.status === 401 ? send(await sessionOf(plugin, session.token)) : response;
|
|
43
85
|
};
|
|
44
86
|
const errorBody = z.object({ message: z.string() });
|
|
45
87
|
/**
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { ComponentType } from "react";
|
|
2
1
|
/**
|
|
3
2
|
* Core's timeline, for plugin UIs: `<RecordTimeline type="hr.employee" id={employee.id} />`
|
|
4
3
|
* shows notes, mentions, pins, reactions, logged calls and the plugin's own
|
|
5
4
|
* entries for one of its records (the type must be in the plugin's manifest
|
|
6
|
-
* `timelines`). The host app (web) registers the component
|
|
7
|
-
* Module Federation singleton, so every plugin gets the host's.
|
|
5
|
+
* `timelines`). The host app (web) registers the component.
|
|
8
6
|
*/
|
|
9
7
|
export type RecordTimelineProps = {
|
|
10
8
|
type: string;
|
|
11
9
|
id: string;
|
|
12
10
|
};
|
|
13
|
-
export declare const setRecordTimeline: (component: ComponentType<RecordTimelineProps> | null) => void;
|
|
11
|
+
export declare const setRecordTimeline: (component: import("react").ComponentType<RecordTimelineProps> | null) => void;
|
|
14
12
|
export declare const RecordTimeline: (props: RecordTimelineProps) => import("react").JSX.Element | null;
|
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useSyncExternalStore } from "react";
|
|
1
|
+
import { hostComponent } from "./host-component.js";
|
|
3
2
|
// src/utils/record-timeline.tsx
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
registered = component;
|
|
8
|
-
listeners.forEach((listener) => listener());
|
|
9
|
-
};
|
|
10
|
-
const subscribe = (listener) => {
|
|
11
|
-
listeners.add(listener);
|
|
12
|
-
return () => listeners.delete(listener);
|
|
13
|
-
};
|
|
14
|
-
const RecordTimeline = (props) => {
|
|
15
|
-
const Component = useSyncExternalStore(subscribe, () => registered, () => registered);
|
|
16
|
-
if (!Component) return null;
|
|
17
|
-
return /* @__PURE__ */ jsx(Component, { ...props });
|
|
18
|
-
};
|
|
3
|
+
const timeline = hostComponent();
|
|
4
|
+
const setRecordTimeline = timeline.set;
|
|
5
|
+
const RecordTimeline = timeline.Host;
|
|
19
6
|
export { RecordTimeline, setRecordTimeline };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@erxes/ui",
|
|
3
|
-
"version": "4.0.0-v2.
|
|
3
|
+
"version": "4.0.0-v2.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "erxes design system: UI primitives, layout, hooks and shared frontend state",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -73,6 +73,7 @@
|
|
|
73
73
|
"@types/node": "^26.6.6",
|
|
74
74
|
"@types/react": "19.3.0",
|
|
75
75
|
"@types/react-dom": "19.3.0",
|
|
76
|
+
"happy-dom": "21.0.4",
|
|
76
77
|
"jotai": "^3.0.2",
|
|
77
78
|
"nuqs": "^2.10.3",
|
|
78
79
|
"react": "^19.3.1",
|