From 39afb07db0d9e35eaa1756bd7a9ddf8e2cd10667 Mon Sep 17 00:00:00 2001 From: oliver Date: Fri, 9 Oct 2026 22:46:34 +0800 Subject: [PATCH] Adapt dsh-mind-map plugin for Desktop 0.2 soft inject slots. Use ui-slots/locale inject paths and host schemastery resolution so the linked plugin boots without hard settingsScope. Co-authored-by: Cursor --- packages/dsh-plugin/lib/client.js | 96 ++++++++++++++++++++++++------- packages/dsh-plugin/lib/index.js | 4 ++ packages/dsh-plugin/package.json | 4 +- 3 files changed, 82 insertions(+), 22 deletions(-) diff --git a/packages/dsh-plugin/lib/client.js b/packages/dsh-plugin/lib/client.js index 1b53e7f..ae2bd4d 100644 --- a/packages/dsh-plugin/lib/client.js +++ b/packages/dsh-plugin/lib/client.js @@ -16,7 +16,8 @@ window.__ModuleLoader__.load({ const { useEffect, useId, useState } = React const name = 'dsh-mind-map' - const inject = ['slots', 'locale', 'settingsScope'] + // Desktop 0.2 removed settingsScope (configForms). Do not hard-inject it. + const inject = ['slots', 'locale'] const NS = 'dsh-mind-map' const API = '/dsh-mind-map' const LOCALE_NS = 'settings.dshMindMap' @@ -1250,26 +1251,81 @@ window.__ModuleLoader__.load({ } }, 'dsh-mind-map: ui-open poll') - const scope = ctx.settingsScope.bind({ namespace: NS }) - const form = createForm(scope) - ctx.slots.inject('settings.plugin.item', () => - ctx.slots.register( - { - name: 'settings.plugin.item', - key: NS, - locale: LOCALE_NS, - inject: () => ({ - hooks: { card: form.store }, - edit: (field, value) => form.edit(field, value), - save: () => { - form.save() + const mountSettingsCard = (scope) => { + if (!scope || typeof scope.getSnapshot !== 'function') return + const form = createForm(scope) + try { + ctx.slots.inject('settings.plugin.item', () => + ctx.slots.register( + { + name: 'settings.plugin.item', + key: NS, + locale: LOCALE_NS, + inject: () => ({ + hooks: { card: form.store }, + edit: (field, value) => form.edit(field, value), + save: () => { + form.save() + }, + discard: () => form.discard(), + }), }, - discard: () => form.discard(), - }), - }, - SettingsCard, - ), - ) + SettingsCard, + ), + ) + } catch (err) { + ctx.logger?.warn?.('dsh-mind-map: settings.plugin.item unavailable: %s', err) + } + } + + let mounted = false + const tryMount = (scope, source) => { + if (mounted || !scope) return + mounted = true + ctx.logger?.info?.('dsh-mind-map: settings card via %s', source) + mountSettingsCard(scope) + } + + // DSH ≥0.1.7 / 0.2.0 — configForms + ctx.inject(['configForms'], (formsCtx) => { + const forms = formsCtx.configForms || formsCtx.get?.('configForms') + if (!forms || typeof forms.get !== 'function') return + const candidates = [NS, 'dsh-mind-map'] + const hit = candidates + .map((id) => { + try { + return { id, scope: forms.get(id) } + } catch { + return null + } + }) + .find((row) => row?.scope && typeof row.scope.getSnapshot === 'function') + if (hit) tryMount(hit.scope, `configForms:${hit.id}`) + if (typeof forms.whileServed === 'function') { + formsCtx.effect( + () => + forms.whileServed(candidates, (served) => { + const id = candidates.find((c) => served.has(c)) + if (!id) return () => {} + try { + tryMount(forms.get(id), `whileServed:${id}`) + } catch { + /* ignore */ + } + return () => {} + }), + 'dsh-mind-map: configForms whileServed', + ) + } + }) + + // DSH ≤0.1.5 — settingsScope + ctx.inject(['settingsScope'], (scopeCtx) => { + if (mounted) return + const binder = scopeCtx.settingsScope || scopeCtx.get?.('settingsScope') + if (!binder || typeof binder.bind !== 'function') return + tryMount(binder.bind({ namespace: NS }), 'settingsScope') + }) } exports.name = name diff --git a/packages/dsh-plugin/lib/index.js b/packages/dsh-plugin/lib/index.js index 6f8cf4b..1fb1277 100644 --- a/packages/dsh-plugin/lib/index.js +++ b/packages/dsh-plugin/lib/index.js @@ -33,6 +33,10 @@ async function importHostPkg(id) { const scoped = id.startsWith('@') const parts = scoped ? id.split('/') : [id] const candidates = [ + join(dshHome, 'profiles', 'node_modules', ...parts, 'lib', 'index.mjs'), + join(dshHome, 'profiles', 'node_modules', ...parts, 'lib', 'index.js'), + join(dshHome, 'profiles', 'desktop', 'node_modules', ...parts, 'lib', 'index.mjs'), + join(dshHome, 'profiles', 'desktop', 'node_modules', ...parts, 'lib', 'index.js'), join(dshHome, 'profiles', 'web', 'node_modules', ...parts, 'lib', 'index.mjs'), join(dshHome, 'profiles', 'web', 'node_modules', ...parts, 'lib', 'index.js'), ] diff --git a/packages/dsh-plugin/package.json b/packages/dsh-plugin/package.json index f8884f5..ff74051 100644 --- a/packages/dsh-plugin/package.json +++ b/packages/dsh-plugin/package.json @@ -1,6 +1,6 @@ { "name": "dsh-mind-map", - "version": "0.1.0", + "version": "0.1.1", "description": "AI 双向无限画布:DSH 右侧思维导图 Tab;对话用 DSH。", "type": "module", "main": "lib/index.js", @@ -28,7 +28,7 @@ "platform": "web", "immediately": true, "inject": [ - "@deepseek-ai/dsh-client-ui-settings-plugins", + "@deepseek-ai/dsh-client-ui-slots", "@deepseek-ai/dsh-client-locale" ] }