@ftshare-lab/dsh-kline 0.6.10 → 0.6.11
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/CHANGELOG.md +10 -0
- package/README.en.md +110 -55
- package/README.md +107 -52
- package/config/dsh-tool-catalog.json +1 -1
- package/docs/embedding.md +34 -0
- package/docs/guide.en.md +1 -1
- package/docs/guide.md +2 -2
- package/docs/npm-release.md +6 -6
- package/docs/release-acceptance-v0.6.11.md +21 -0
- package/docs/release-notes-v0.6.11.md +16 -0
- package/lib/client/PanelHost.js +46 -0
- package/lib/client/generated-view.js +2 -2
- package/lib/client/host-options.js +41 -0
- package/lib/client/host-panels.js +111 -0
- package/lib/client/index.js +19 -4
- package/lib/client/mode-preferences.js +21 -1
- package/lib/client/native-sidebar.js +3 -1
- package/lib/client/ui-onboarding.js +7 -1
- package/lib/client.js +207 -8
- package/lib/client.js.map +1 -1
- package/lib/types/client/PanelHost.d.ts +25 -0
- package/lib/types/client/client-context.d.ts +2 -0
- package/lib/types/client/generated-view.d.ts +1 -1
- package/lib/types/client/host-options.d.ts +38 -0
- package/lib/types/client/host-panels.d.ts +55 -0
- package/lib/types/client/mode-preferences.d.ts +13 -1
- package/lib/types/client/ui-onboarding.d.ts +2 -1
- package/package.json +7 -5
- package/screenshots.json +4 -7
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The optional host contract for panel mounts.
|
|
3
|
+
*
|
|
4
|
+
* A host that already owns a bounded panel declares a slot of its own and asks
|
|
5
|
+
* the chart to fill it through the `klinePanels` service. The chart therefore
|
|
6
|
+
* never learns a host's slot names, and a host that does not ask sees the
|
|
7
|
+
* plugin exactly as it was before this contract existed.
|
|
8
|
+
*
|
|
9
|
+
* Kept free of React, like `native-sidebar-register.ts`, so the registration
|
|
10
|
+
* policy is testable with fake slot services.
|
|
11
|
+
*/
|
|
12
|
+
/** Coordinate caller lifetimes independently of the current slot-service lifetime. */
|
|
13
|
+
export function createPanelMountRegistry() {
|
|
14
|
+
const requests = new Map();
|
|
15
|
+
let current;
|
|
16
|
+
const disconnect = (connection) => {
|
|
17
|
+
if (current === connection)
|
|
18
|
+
current = undefined;
|
|
19
|
+
const disposers = [...connection.mounted.values()];
|
|
20
|
+
connection.mounted.clear();
|
|
21
|
+
const errors = [];
|
|
22
|
+
for (const dispose of disposers) {
|
|
23
|
+
try {
|
|
24
|
+
dispose();
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
errors.push(error);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (errors.length)
|
|
31
|
+
throw new AggregateError(errors, 'Could not release host chart panels');
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
mount(seat, options) {
|
|
35
|
+
const chrome = options?.chrome ?? 'chart-search';
|
|
36
|
+
let request = requests.get(seat);
|
|
37
|
+
if (request && request.chrome !== chrome)
|
|
38
|
+
throw new Error(`Chart panel "${seat}" is already mounted with different chrome`);
|
|
39
|
+
if (!request) {
|
|
40
|
+
request = { chrome, users: 0 };
|
|
41
|
+
requests.set(seat, request);
|
|
42
|
+
try {
|
|
43
|
+
if (current)
|
|
44
|
+
current.mounted.set(seat, current.service.mount(seat, { chrome }));
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
requests.delete(seat);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const lease = request;
|
|
52
|
+
lease.users += 1;
|
|
53
|
+
let released = false;
|
|
54
|
+
return () => {
|
|
55
|
+
if (released)
|
|
56
|
+
return;
|
|
57
|
+
released = true;
|
|
58
|
+
if (--lease.users > 0 || requests.get(seat) !== lease)
|
|
59
|
+
return;
|
|
60
|
+
requests.delete(seat);
|
|
61
|
+
const dispose = current?.mounted.get(seat);
|
|
62
|
+
current?.mounted.delete(seat);
|
|
63
|
+
dispose?.();
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
connect(service) {
|
|
67
|
+
if (current)
|
|
68
|
+
disconnect(current);
|
|
69
|
+
const connection = { service, mounted: new Map() };
|
|
70
|
+
current = connection;
|
|
71
|
+
try {
|
|
72
|
+
for (const [seat, request] of requests) {
|
|
73
|
+
connection.mounted.set(seat, service.mount(seat, { chrome: request.chrome }));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
try {
|
|
78
|
+
disconnect(connection);
|
|
79
|
+
}
|
|
80
|
+
catch (cleanupError) {
|
|
81
|
+
throw new AggregateError([error, cleanupError], 'Could not attach host chart panels');
|
|
82
|
+
}
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
return () => disconnect(connection);
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Turn slot services plus a body factory into the `klinePanels` service.
|
|
91
|
+
* @param host - the host services a mount registers into.
|
|
92
|
+
* @param body - the component body for one seat (one per mounted seat).
|
|
93
|
+
* @returns the service a host calls; nothing is registered until it calls.
|
|
94
|
+
*/
|
|
95
|
+
export function createPanelMounts(host, body) {
|
|
96
|
+
return {
|
|
97
|
+
mount(seat, options) {
|
|
98
|
+
// `slots.inject` returns the factory's disposer when the seat is already
|
|
99
|
+
// declared, and the injection's own disposer otherwise — the same shape
|
|
100
|
+
// the native tab registration relies on.
|
|
101
|
+
const dispose = host.slots.inject(seat, () => host.slots.register({ name: seat }, body(seat, options?.chrome)));
|
|
102
|
+
let released = false;
|
|
103
|
+
return () => {
|
|
104
|
+
if (released)
|
|
105
|
+
return;
|
|
106
|
+
released = true;
|
|
107
|
+
dispose?.();
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
package/lib/client/index.js
CHANGED
|
@@ -6,8 +6,10 @@ import { ClassicShell } from './ClassicShell';
|
|
|
6
6
|
import { BetterSidebarBridge } from './BetterSidebarTab';
|
|
7
7
|
import { NativeSidebarBridgeView, registerNativeSidebar } from './native-sidebar';
|
|
8
8
|
import { cleanClassicTabs, isSidebarUsable } from './sidebar-integration';
|
|
9
|
-
import { InterfaceContext, readDisplayMode, resolveDisplayMode } from './mode-preferences';
|
|
9
|
+
import { InterfaceContext, readDisplayMode, resolveDisplayMode, shouldDrawClassicLauncher } from './mode-preferences';
|
|
10
10
|
import { captureOnboarding } from './ui-onboarding';
|
|
11
|
+
import { readHostOptions, setHostOptions, subscribeHostOptions } from "./host-options.js";
|
|
12
|
+
import { registerPanelHosts } from './PanelHost';
|
|
11
13
|
export const inject = ['sessions'];
|
|
12
14
|
export function apply(ctx) {
|
|
13
15
|
let service;
|
|
@@ -20,18 +22,28 @@ export function apply(ctx) {
|
|
|
20
22
|
// Registered before the router paints, so the first frame already knows
|
|
21
23
|
// whether the host owns a right column this plugin can put a tab in.
|
|
22
24
|
const native = registerNativeSidebar(ctx, emit);
|
|
25
|
+
// A host client plugin can provide `klineHost` to switch the chrome it wants
|
|
26
|
+
// (its own chart entry, its own first-run experience). Without that service
|
|
27
|
+
// every default below stays exactly as upstream.
|
|
28
|
+
ctx.inject(['klineHost'], scoped => {
|
|
29
|
+
scoped.effect(() => {
|
|
30
|
+
setHostOptions(scoped.get('klineHost'));
|
|
31
|
+
return () => setHostOptions(undefined);
|
|
32
|
+
}, 'dsh-kline: host options');
|
|
33
|
+
});
|
|
23
34
|
function Router() {
|
|
24
35
|
const sidebar = useSyncExternalStore(subscribe, () => service);
|
|
25
36
|
const nativeTab = useSyncExternalStore(subscribe, () => native.available());
|
|
37
|
+
const host = useSyncExternalStore(subscribeHostOptions, readHostOptions);
|
|
26
38
|
const conversation = useSyncExternalStore(subscribeSessions, () => currentConversationId(ctx.sessions.list.getSnapshot()));
|
|
27
39
|
const available = nativeTab || isSidebarUsable(sidebar);
|
|
28
|
-
const mode = resolveDisplayMode(preference, available);
|
|
40
|
+
const mode = resolveDisplayMode(preference, available, host);
|
|
29
41
|
// A tab body lives in a Session, so before one exists the chart has no
|
|
30
42
|
// tab to live in — whichever column the host owns. The classic launcher
|
|
31
43
|
// covers that screen, which is what the old aria-label probe approximated
|
|
32
44
|
// and only ever got right in an English UI.
|
|
33
|
-
const
|
|
34
|
-
return _jsxs(InterfaceContext.Provider, { value: { preference, mode, available }, children: [nativeTab && mode === 'better-sidebar' && _jsx(NativeSidebarBridgeView, { bridge: native, sessions: ctx.sessions }), !nativeTab && sidebar && _jsx(BetterSidebarBridge, { service: sidebar, sessions: ctx.sessions }), nativeTab && sidebar && _jsx(RetireBetterSidebarTabs, { service: sidebar }),
|
|
45
|
+
const drawClassicLauncher = shouldDrawClassicLauncher(host, mode, conversation !== undefined);
|
|
46
|
+
return _jsxs(InterfaceContext.Provider, { value: { preference, mode, available }, children: [nativeTab && mode === 'better-sidebar' && _jsx(NativeSidebarBridgeView, { bridge: native, sessions: ctx.sessions }), !nativeTab && sidebar && _jsx(BetterSidebarBridge, { service: sidebar, sessions: ctx.sessions }), nativeTab && sidebar && _jsx(RetireBetterSidebarTabs, { service: sidebar }), drawClassicLauncher && _jsx(ClassicShell, { sessions: ctx.sessions })] });
|
|
35
47
|
}
|
|
36
48
|
ctx.effect(() => {
|
|
37
49
|
const host = document.createElement('div');
|
|
@@ -49,6 +61,9 @@ export function apply(ctx) {
|
|
|
49
61
|
return () => { service = undefined; emit(); };
|
|
50
62
|
}, 'dsh-kline: optional sidebar');
|
|
51
63
|
});
|
|
64
|
+
// A host that owns bounded panels (a paper-trading rail, a canvas card) asks
|
|
65
|
+
// the chart to fill its own slot; hosts that never ask keep the plugin as is.
|
|
66
|
+
registerPanelHosts(ctx);
|
|
52
67
|
}
|
|
53
68
|
/**
|
|
54
69
|
* Remove the tabs this plugin saved into Better Sidebar's workbench once the
|
|
@@ -12,12 +12,32 @@ export function readDisplayMode(storage = globalThis.localStorage) {
|
|
|
12
12
|
return 'classic';
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
export function resolveDisplayMode(preference, available) {
|
|
15
|
+
export function resolveDisplayMode(preference, available, host) {
|
|
16
|
+
// A host that owns the chart entry uses its column whenever it offers one,
|
|
17
|
+
// whatever the user's stored preference says: there is no floating launcher
|
|
18
|
+
// left to fall back to. Omitted host options keep the upstream rule below.
|
|
19
|
+
if (host?.entry === 'tab')
|
|
20
|
+
return available ? 'better-sidebar' : 'classic';
|
|
16
21
|
// A chart should be available before a new DSH conversation has created a
|
|
17
22
|
// workbench session. The native tab is therefore opt-in; the classic K
|
|
18
23
|
// launcher remains the dependable default.
|
|
19
24
|
return preference === 'better-sidebar' && available ? 'better-sidebar' : 'classic';
|
|
20
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Whether the floating classic launcher is drawn for this frame.
|
|
28
|
+
*
|
|
29
|
+
* Upstream keeps it for classic mode and for screens without a Session, where
|
|
30
|
+
* the tab body cannot live yet. A host that declared `entry: 'tab'` owns the
|
|
31
|
+
* chart entry instead, so it never draws the launcher.
|
|
32
|
+
* @param host - the host options, if the host provided any.
|
|
33
|
+
* @param mode - the interface mode this frame resolved to.
|
|
34
|
+
* @param hasConversation - whether a Session exists to host a tab body.
|
|
35
|
+
*/
|
|
36
|
+
export function shouldDrawClassicLauncher(host, mode, hasConversation) {
|
|
37
|
+
if (host?.entry === 'tab')
|
|
38
|
+
return false;
|
|
39
|
+
return mode === 'classic' || !hasConversation;
|
|
40
|
+
}
|
|
21
41
|
export function readAutoOpen(storage = globalThis.localStorage) {
|
|
22
42
|
try {
|
|
23
43
|
return storage.getItem(AUTO_OPEN_KEY) !== 'false';
|
|
@@ -4,6 +4,7 @@ import { useChartReference } from './chart-session-resolver';
|
|
|
4
4
|
import { KlineTabContent } from './BetterSidebarTab';
|
|
5
5
|
import { currentConversationId } from './conversation';
|
|
6
6
|
import { InterfaceContext, readAutoOpen, readDisplayMode, resolveDisplayMode } from './mode-preferences';
|
|
7
|
+
import { readHostOptions, subscribeHostOptions } from "./host-options.js";
|
|
7
8
|
import { registerNativeTab } from './native-sidebar-register';
|
|
8
9
|
/**
|
|
9
10
|
* The chart as a tab of the host's own right column.
|
|
@@ -25,7 +26,8 @@ import { registerNativeTab } from './native-sidebar-register';
|
|
|
25
26
|
export function NativeKlineTabBody({ sessionId, sessions, useTabInfo }) {
|
|
26
27
|
const visible = useTabInfo().tab.visible;
|
|
27
28
|
const preference = useMemo(readDisplayMode, []);
|
|
28
|
-
const
|
|
29
|
+
const host = useSyncExternalStore(subscribeHostOptions, readHostOptions);
|
|
30
|
+
const mode = resolveDisplayMode(preference, true, host);
|
|
29
31
|
const subscribe = useCallback((listener) => sessions.list.subscribe(listener), [sessions]);
|
|
30
32
|
const activeConversation = useSyncExternalStore(subscribe, () => currentConversationId(sessions.list.getSnapshot()));
|
|
31
33
|
return (_jsx(InterfaceContext.Provider, { value: { preference, mode, available: true }, children: _jsx("div", { "data-dsh-kline-tab": "", style: { width: '100%', height: '100%', minHeight: 0, overflow: 'hidden' }, children: mode !== 'better-sidebar'
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UI_SEEN_KEY } from "./mode-preferences.js";
|
|
2
|
+
import { readHostOptions } from "./host-options.js";
|
|
2
3
|
export const ONBOARDING_KEY = 'dsh-kline:onboarding-version:v2';
|
|
3
4
|
let existingUser;
|
|
4
5
|
export function hasPreviousUsage(storage) {
|
|
@@ -18,7 +19,12 @@ export function hasPreviousUsage(storage) {
|
|
|
18
19
|
export function captureOnboarding(storage = globalThis.localStorage) {
|
|
19
20
|
existingUser ??= hasPreviousUsage(storage);
|
|
20
21
|
}
|
|
21
|
-
export function onboardingKind(storage = globalThis.localStorage) {
|
|
22
|
+
export function onboardingKind(storage = globalThis.localStorage, host = readHostOptions()) {
|
|
23
|
+
// A host that runs its own first-run experience suppresses both dialogs
|
|
24
|
+
// without touching the storage: nothing is written, so a later standalone
|
|
25
|
+
// run still sees the same state.
|
|
26
|
+
if (host?.onboarding === 'off')
|
|
27
|
+
return 'none';
|
|
22
28
|
captureOnboarding(storage);
|
|
23
29
|
return classifyOnboarding(storage, existingUser === true);
|
|
24
30
|
}
|