dsh-sidebar-fold 0.1.6 → 0.1.13
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 +164 -135
- package/README.pt.md +171 -0
- package/README.zh.md +141 -120
- package/dsh.plugin.json +3 -3
- package/lib/client.js +910 -102
- package/locale/pt.json +6 -0
- package/package.json +6 -5
- package/src/client/constants.ts +319 -237
- package/src/client/fold.ts +1031 -657
- package/src/client/index.ts +223 -187
- package/src/client/locales.ts +330 -210
- package/src/client/menu-entry.ts +157 -0
- package/src/client/settings-card.ts +451 -334
- package/src/index.js +99 -88
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The "More" menu's shortcut row into this plugin's own settings.
|
|
3
|
+
*
|
|
4
|
+
* Why a slot row and not DOM surgery: the host's More menu is rendered by
|
|
5
|
+
* `sidebar.panellist.actions`, so a registration lands in the same list, follows
|
|
6
|
+
* the menu's own keyboard walk and its dismiss path, and survives re-renders
|
|
7
|
+
* without an observer. (The host also documents this seat as the additive way to
|
|
8
|
+
* reach a plugin's surface from the menu.)
|
|
9
|
+
*
|
|
10
|
+
* Where it lands: the shipped rows in that list are 「浏览更多插件 / 创建你的插件」,
|
|
11
|
+
* preceded by their own hairline. A list entry can only be appended to that block,
|
|
12
|
+
* so the row carries its own hairline and reads as the last item of the action
|
|
13
|
+
* group — see the README note for what exact placement would cost.
|
|
14
|
+
*
|
|
15
|
+
* Navigation: `pluginNavigation.openBundle(pkg)` is the host's own intent
|
|
16
|
+
* (`plugin-manager/lib/client.js`: selectPanel('plugins') + tab 'installed' +
|
|
17
|
+
* view {kind:'package', name}), which is the page our config card is registered
|
|
18
|
+
* on. Older lines that do not provide the service fall back to the panel itself.
|
|
19
|
+
*/
|
|
20
|
+
import { CLS, PKG_NAME } from './constants.ts'
|
|
21
|
+
import { pickDictionary } from './locales.ts'
|
|
22
|
+
|
|
23
|
+
/** The module-loader factory's `require`, injected by the host's module table. */
|
|
24
|
+
declare const require: (id: string) => any
|
|
25
|
+
// Named `menuReact`, not `react`: the build concatenates every module into one
|
|
26
|
+
// closure, and a second `const react` there is a duplicate declaration that kills
|
|
27
|
+
// the whole bundle (measured: the sidebar simply kept its shipped shape).
|
|
28
|
+
const menuReact: any = require('react')
|
|
29
|
+
|
|
30
|
+
/** The sliver of the client context this row needs to navigate. */
|
|
31
|
+
export interface MenuCtx {
|
|
32
|
+
get?: (name: string) => unknown
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The `pluginNavigation` face the host provides on 0.2.2 (`openList`/`openBundle`). */
|
|
36
|
+
interface PluginNavigation {
|
|
37
|
+
openBundle?: (packageName: string) => void
|
|
38
|
+
openList?: () => void
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A panel-selector face, used only when `pluginNavigation` is absent. */
|
|
42
|
+
interface LayoutFace {
|
|
43
|
+
selectPanel?: (id: string) => void
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The navigation face adopted through `ctx.inject` in `index.ts`.
|
|
48
|
+
*
|
|
49
|
+
* `ctx.get('pluginNavigation')` alone did not reach the service (measured: the
|
|
50
|
+
* row fell back to the panel and the package page never opened), so the row is
|
|
51
|
+
* handed the face by a scoped inject — the same arrangement the settings waists
|
|
52
|
+
* use, which also keeps the plugin alive on lines that do not provide it.
|
|
53
|
+
*/
|
|
54
|
+
let navigationFace: PluginNavigation | undefined
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Adopt the host's `pluginNavigation` service when it shows up.
|
|
58
|
+
* @param face - whatever the scoped inject resolved; anything unusable is ignored.
|
|
59
|
+
*/
|
|
60
|
+
export function adoptPluginNavigation(face: unknown): void {
|
|
61
|
+
if (face === null || typeof face !== 'object') return
|
|
62
|
+
const candidate = face as PluginNavigation
|
|
63
|
+
if (typeof candidate.openBundle === 'function' || typeof candidate.openList === 'function') navigationFace = candidate
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Open this bundle's page in the Plugin Manager.
|
|
68
|
+
*
|
|
69
|
+
* Three routes, most precise first: the bundle itself, then the plugin list, then
|
|
70
|
+
* the panel. Each is probed — none of them is a stable plugin API.
|
|
71
|
+
* @param ctx - the client context the row was registered from.
|
|
72
|
+
*/
|
|
73
|
+
export function openPluginSettings(ctx: MenuCtx): void {
|
|
74
|
+
let navigation: PluginNavigation | undefined = navigationFace
|
|
75
|
+
try {
|
|
76
|
+
navigation = navigation ?? (ctx.get?.('pluginNavigation') as PluginNavigation | undefined)
|
|
77
|
+
} catch {
|
|
78
|
+
navigation = navigation ?? undefined
|
|
79
|
+
}
|
|
80
|
+
if (typeof navigation?.openBundle === 'function') {
|
|
81
|
+
navigation.openBundle(PKG_NAME)
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
if (typeof navigation?.openList === 'function') {
|
|
85
|
+
navigation.openList()
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
let layout: LayoutFace | undefined
|
|
89
|
+
try {
|
|
90
|
+
layout = ctx.get?.('layout') as LayoutFace | undefined
|
|
91
|
+
} catch {
|
|
92
|
+
layout = undefined
|
|
93
|
+
}
|
|
94
|
+
layout?.selectPanel?.('plugins')
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** A sliders glyph, drawn here because the host `primitives` package is off-limits. */
|
|
98
|
+
function buildGlyph(): unknown {
|
|
99
|
+
const svg = (props: Record<string, unknown>, children: unknown[]): unknown =>
|
|
100
|
+
menuReact.createElement('svg', {
|
|
101
|
+
width: 16,
|
|
102
|
+
height: 16,
|
|
103
|
+
viewBox: '0 0 16 16',
|
|
104
|
+
fill: 'none',
|
|
105
|
+
stroke: 'currentColor',
|
|
106
|
+
strokeWidth: 1.3,
|
|
107
|
+
strokeLinecap: 'round',
|
|
108
|
+
strokeLinejoin: 'round',
|
|
109
|
+
'aria-hidden': 'true',
|
|
110
|
+
...props,
|
|
111
|
+
}, ...children)
|
|
112
|
+
return svg({ className: CLS.menuIcon }, [
|
|
113
|
+
menuReact.createElement('path', { key: 'a', d: 'M2.5 5.5h11M2.5 10.5h11' }),
|
|
114
|
+
menuReact.createElement('circle', { key: 'b', cx: 6, cy: 5.5, r: 1.6, fill: 'var(--dsw-alias-bg-layer-1)' }),
|
|
115
|
+
menuReact.createElement('circle', { key: 'c', cx: 10.5, cy: 10.5, r: 1.6, fill: 'var(--dsw-alias-bg-layer-1)' }),
|
|
116
|
+
])
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Build the component for one `sidebar.panellist.actions` seat.
|
|
121
|
+
*
|
|
122
|
+
* The menu hands every registration the same owner props (`onDismiss` among
|
|
123
|
+
* them), so the row closes the list before navigating — otherwise the menu would
|
|
124
|
+
* stay open over the page it just opened.
|
|
125
|
+
* @param ctx - the client context the row was registered from.
|
|
126
|
+
* @returns a React component the slot can render.
|
|
127
|
+
*/
|
|
128
|
+
export function createSettingsRow(ctx: MenuCtx): (props: { onDismiss?: () => void }) => unknown {
|
|
129
|
+
return function SidebarFoldSettingsRow(props: { onDismiss?: () => void }) {
|
|
130
|
+
const dict = pickDictionary(document.documentElement.lang ?? '')
|
|
131
|
+
const label = dict['menu.settings']
|
|
132
|
+
return menuReact.createElement(
|
|
133
|
+
'div',
|
|
134
|
+
{ className: CLS.menuGroup },
|
|
135
|
+
menuReact.createElement(
|
|
136
|
+
'button',
|
|
137
|
+
{
|
|
138
|
+
type: 'button',
|
|
139
|
+
role: 'menuitem',
|
|
140
|
+
className: CLS.menuRow,
|
|
141
|
+
title: label,
|
|
142
|
+
'aria-label': label,
|
|
143
|
+
onClick: () => {
|
|
144
|
+
try {
|
|
145
|
+
props?.onDismiss?.()
|
|
146
|
+
} catch {
|
|
147
|
+
// A menu that cannot close must not take the navigation with it.
|
|
148
|
+
}
|
|
149
|
+
openPluginSettings(ctx)
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
buildGlyph(),
|
|
153
|
+
menuReact.createElement('span', { className: CLS.menuText }, label),
|
|
154
|
+
),
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
}
|