@jayyuen66/dsh-dir-prep-organize 0.1.0
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/LICENSE +21 -0
- package/README.md +213 -0
- package/agents/academic/academic-anthropologist.md +124 -0
- package/agents/academic/academic-geographer.md +126 -0
- package/agents/academic/academic-historian.md +122 -0
- package/agents/academic/academic-narratologist.md +117 -0
- package/agents/academic/academic-psychologist.md +117 -0
- package/agents/academic/academic-study-planner.md +262 -0
- package/agents/company/chief-executive-officer.md +104 -0
- package/agents/company/chief-financial-officer.md +390 -0
- package/agents/company/chief-marketing-officer.md +95 -0
- package/agents/company/chief-of-staff.md +278 -0
- package/agents/company/chief-operating-officer.md +88 -0
- package/agents/company/chief-product-officer.md +91 -0
- package/agents/company/chief-technology-officer.md +98 -0
- package/agents/design/design-brand-guardian.md +321 -0
- package/agents/design/design-image-prompt-engineer.md +255 -0
- package/agents/design/design-inclusive-visuals-specialist.md +177 -0
- package/agents/design/design-persona-walkthrough.md +271 -0
- package/agents/design/design-ui-designer.md +382 -0
- package/agents/design/design-ux-architect.md +482 -0
- package/agents/design/design-ux-researcher.md +328 -0
- package/agents/design/design-video-prompt-engineer.md +110 -0
- package/agents/design/design-visual-storyteller.md +159 -0
- package/agents/design/design-whimsy-injector.md +453 -0
- package/agents/engineering/engineering-ai-data-remediation-engineer.md +209 -0
- package/agents/engineering/engineering-ai-engineer.md +161 -0
- package/agents/engineering/engineering-autonomous-optimization-architect.md +115 -0
- package/agents/engineering/engineering-backend-architect.md +234 -0
- package/agents/engineering/engineering-cms-developer.md +534 -0
- package/agents/engineering/engineering-code-reviewer.md +172 -0
- package/agents/engineering/engineering-codebase-onboarding-engineer.md +172 -0
- package/agents/engineering/engineering-data-engineer.md +324 -0
- package/agents/engineering/engineering-database-optimizer.md +175 -0
- package/agents/engineering/engineering-devops-automator.md +375 -0
- package/agents/engineering/engineering-dingtalk-integration-developer.md +574 -0
- package/agents/engineering/engineering-drupal-shopping-cart.md +359 -0
- package/agents/engineering/engineering-email-intelligence-engineer.md +349 -0
- package/agents/engineering/engineering-embedded-firmware-engineer.md +168 -0
- package/agents/engineering/engineering-embedded-linux-driver-engineer.md +255 -0
- package/agents/engineering/engineering-feishu-integration-developer.md +597 -0
- package/agents/engineering/engineering-filament-optimization-specialist.md +283 -0
- package/agents/engineering/engineering-fpga-digital-design-engineer.md +227 -0
- package/agents/engineering/engineering-frontend-developer.md +224 -0
- package/agents/engineering/engineering-git-workflow-master.md +220 -0
- package/agents/engineering/engineering-incident-response-commander.md +465 -0
- package/agents/engineering/engineering-iot-solution-architect.md +220 -0
- package/agents/engineering/engineering-it-service-manager.md +560 -0
- package/agents/engineering/engineering-mechanical-design-engineer.md +311 -0
- package/agents/engineering/engineering-minimal-change-engineer.md +206 -0
- package/agents/engineering/engineering-mobile-app-builder.md +434 -0
- package/agents/engineering/engineering-multi-agent-systems-architect.md +599 -0
- package/agents/engineering/engineering-network-engineer-china.md +162 -0
- package/agents/engineering/engineering-orgscript-engineer.md +112 -0
- package/agents/engineering/engineering-pc-host-engineer.md +231 -0
- package/agents/engineering/engineering-prompt-engineer.md +203 -0
- package/agents/engineering/engineering-rapid-prototyper.md +461 -0
- package/agents/engineering/engineering-security-engineer.md +303 -0
- package/agents/engineering/engineering-senior-developer.md +177 -0
- package/agents/engineering/engineering-software-architect.md +200 -0
- package/agents/engineering/engineering-solidity-smart-contract-engineer.md +541 -0
- package/agents/engineering/engineering-sre.md +233 -0
- package/agents/engineering/engineering-technical-writer.md +409 -0
- package/agents/engineering/engineering-threat-detection-engineer.md +553 -0
- package/agents/engineering/engineering-voice-ai-integration-engineer.md +560 -0
- package/agents/engineering/engineering-wechat-mini-program-developer.md +288 -0
- package/agents/engineering/engineering-wordpress-shopping-cart.md +345 -0
- package/agents/finance/finance-bookkeeper-controller.md +271 -0
- package/agents/finance/finance-financial-analyst.md +244 -0
- package/agents/finance/finance-financial-forecaster.md +213 -0
- package/agents/finance/finance-fpa-analyst.md +272 -0
- package/agents/finance/finance-fraud-detector.md +241 -0
- package/agents/finance/finance-hk-stock-compliance-reviewer.md +316 -0
- package/agents/finance/finance-investment-researcher.md +283 -0
- package/agents/finance/finance-invoice-manager.md +242 -0
- package/agents/finance/finance-tax-strategist.md +250 -0
- package/agents/game-development/blender/blender-addon-engineer.md +233 -0
- package/agents/game-development/game-audio-engineer.md +265 -0
- package/agents/game-development/game-designer.md +168 -0
- package/agents/game-development/godot/godot-gameplay-scripter.md +335 -0
- package/agents/game-development/godot/godot-multiplayer-engineer.md +296 -0
- package/agents/game-development/godot/godot-shader-developer.md +267 -0
- package/agents/game-development/level-designer.md +209 -0
- package/agents/game-development/narrative-designer.md +244 -0
- package/agents/game-development/roblox-studio/roblox-avatar-creator.md +298 -0
- package/agents/game-development/roblox-studio/roblox-experience-designer.md +306 -0
- package/agents/game-development/roblox-studio/roblox-systems-scripter.md +325 -0
- package/agents/game-development/technical-artist.md +230 -0
- package/agents/game-development/unity/unity-architect.md +272 -0
- package/agents/game-development/unity/unity-editor-tool-developer.md +300 -0
- package/agents/game-development/unity/unity-multiplayer-engineer.md +238 -0
- package/agents/game-development/unity/unity-shader-graph-artist.md +270 -0
- package/agents/game-development/unreal-engine/unreal-multiplayer-architect.md +314 -0
- package/agents/game-development/unreal-engine/unreal-systems-engineer.md +311 -0
- package/agents/game-development/unreal-engine/unreal-technical-artist.md +256 -0
- package/agents/game-development/unreal-engine/unreal-world-builder.md +274 -0
- package/agents/gis/gis-3d-scene-developer.md +110 -0
- package/agents/gis/gis-analyst.md +90 -0
- package/agents/gis/gis-bim-specialist.md +107 -0
- package/agents/gis/gis-cartography-designer.md +149 -0
- package/agents/gis/gis-drone-reality-mapping.md +119 -0
- package/agents/gis/gis-geoai-ml-engineer.md +104 -0
- package/agents/gis/gis-geoprocessing-specialist.md +96 -0
- package/agents/gis/gis-qa-engineer.md +132 -0
- package/agents/gis/gis-solution-engineer.md +100 -0
- package/agents/gis/gis-spatial-data-engineer.md +96 -0
- package/agents/gis/gis-spatial-data-scientist.md +110 -0
- package/agents/gis/gis-technical-consultant.md +85 -0
- package/agents/gis/gis-web-gis-developer.md +107 -0
- package/agents/hr/hr-performance-reviewer.md +248 -0
- package/agents/hr/hr-recruiter.md +232 -0
- package/agents/integrations/README.md +174 -0
- package/agents/integrations/aider/README.md +38 -0
- package/agents/integrations/antigravity/README.md +49 -0
- package/agents/integrations/claude-code/README.md +31 -0
- package/agents/integrations/cursor/README.md +55 -0
- package/agents/integrations/gemini-cli/README.md +40 -0
- package/agents/integrations/github-copilot/README.md +32 -0
- package/agents/integrations/mcp-memory/README.md +79 -0
- package/agents/integrations/mcp-memory/backend-architect-with-memory.md +247 -0
- package/agents/integrations/mcp-memory/setup.sh +74 -0
- package/agents/integrations/openclaw/README.md +34 -0
- package/agents/integrations/opencode/README.md +62 -0
- package/agents/integrations/trae/README.md +108 -0
- package/agents/integrations/windsurf/README.md +26 -0
- package/agents/legal/legal-contract-reviewer.md +240 -0
- package/agents/legal/legal-policy-writer.md +308 -0
- package/agents/marketing/marketing-aeo-foundations.md +533 -0
- package/agents/marketing/marketing-agentic-search-optimizer.md +313 -0
- package/agents/marketing/marketing-ai-citation-strategist.md +721 -0
- package/agents/marketing/marketing-app-store-optimizer.md +319 -0
- package/agents/marketing/marketing-baidu-seo-specialist.md +220 -0
- package/agents/marketing/marketing-bilibili-strategist.md +194 -0
- package/agents/marketing/marketing-book-co-author.md +109 -0
- package/agents/marketing/marketing-carousel-growth-engine.md +215 -0
- package/agents/marketing/marketing-china-ecommerce-operator.md +277 -0
- package/agents/marketing/marketing-china-market-localization-strategist.md +282 -0
- package/agents/marketing/marketing-content-creator.md +145 -0
- package/agents/marketing/marketing-cross-border-ecommerce.md +260 -0
- package/agents/marketing/marketing-daily-news-briefing.md +303 -0
- package/agents/marketing/marketing-douyin-strategist.md +150 -0
- package/agents/marketing/marketing-ecommerce-operator.md +216 -0
- package/agents/marketing/marketing-email-strategist.md +248 -0
- package/agents/marketing/marketing-global-podcast-strategist.md +204 -0
- package/agents/marketing/marketing-growth-hacker.md +121 -0
- package/agents/marketing/marketing-instagram-curator.md +179 -0
- package/agents/marketing/marketing-knowledge-commerce-strategist.md +384 -0
- package/agents/marketing/marketing-kuaishou-strategist.md +182 -0
- package/agents/marketing/marketing-linkedin-content-creator.md +232 -0
- package/agents/marketing/marketing-livestream-commerce-coach.md +303 -0
- package/agents/marketing/marketing-multi-platform-publisher.md +216 -0
- package/agents/marketing/marketing-podcast-strategist.md +278 -0
- package/agents/marketing/marketing-pr-communications-manager.md +472 -0
- package/agents/marketing/marketing-private-domain-operator.md +309 -0
- package/agents/marketing/marketing-reddit-community-builder.md +127 -0
- package/agents/marketing/marketing-search-growth-orchestrator.md +372 -0
- package/agents/marketing/marketing-seo-specialist.md +480 -0
- package/agents/marketing/marketing-short-video-editing-coach.md +413 -0
- package/agents/marketing/marketing-social-media-strategist.md +118 -0
- package/agents/marketing/marketing-tiktok-strategist.md +124 -0
- package/agents/marketing/marketing-twitter-engager.md +132 -0
- package/agents/marketing/marketing-video-optimization-specialist.md +128 -0
- package/agents/marketing/marketing-wechat-official-account.md +158 -0
- package/agents/marketing/marketing-wechat-operator.md +156 -0
- package/agents/marketing/marketing-weibo-strategist.md +241 -0
- package/agents/marketing/marketing-weixin-channels-strategist.md +297 -0
- package/agents/marketing/marketing-x-twitter-intelligence-analyst.md +160 -0
- package/agents/marketing/marketing-xiaohongshu-operator.md +139 -0
- package/agents/marketing/marketing-xiaohongshu-specialist.md +151 -0
- package/agents/marketing/marketing-zhihu-strategist.md +175 -0
- package/agents/paid-media/paid-media-auditor.md +170 -0
- package/agents/paid-media/paid-media-creative-strategist.md +173 -0
- package/agents/paid-media/paid-media-paid-social-strategist.md +180 -0
- package/agents/paid-media/paid-media-ppc-strategist.md +180 -0
- package/agents/paid-media/paid-media-programmatic-buyer.md +177 -0
- package/agents/paid-media/paid-media-search-query-analyst.md +182 -0
- package/agents/paid-media/paid-media-tracking-specialist.md +199 -0
- package/agents/product/product-behavioral-nudge-engine.md +246 -0
- package/agents/product/product-feedback-synthesizer.md +175 -0
- package/agents/product/product-manager.md +474 -0
- package/agents/product/product-sprint-prioritizer.md +133 -0
- package/agents/product/product-trend-researcher.md +143 -0
- package/agents/project-management/project-management-experiment-tracker.md +206 -0
- package/agents/project-management/project-management-jira-workflow-steward.md +249 -0
- package/agents/project-management/project-management-meeting-notes-specialist.md +94 -0
- package/agents/project-management/project-management-project-shepherd.md +202 -0
- package/agents/project-management/project-management-studio-operations.md +208 -0
- package/agents/project-management/project-management-studio-producer.md +211 -0
- package/agents/project-management/project-manager-senior.md +135 -0
- package/agents/sales/sales-account-strategist.md +243 -0
- package/agents/sales/sales-coach.md +291 -0
- package/agents/sales/sales-deal-strategist.md +204 -0
- package/agents/sales/sales-discovery-coach.md +230 -0
- package/agents/sales/sales-engineer.md +200 -0
- package/agents/sales/sales-offer-lead-gen-strategist.md +256 -0
- package/agents/sales/sales-outbound-strategist.md +208 -0
- package/agents/sales/sales-pipeline-analyst.md +284 -0
- package/agents/sales/sales-proposal-strategist.md +233 -0
- package/agents/security/security-appsec-engineer.md +490 -0
- package/agents/security/security-architect.md +303 -0
- package/agents/security/security-blockchain-security-auditor.md +462 -0
- package/agents/security/security-cloud-security-architect.md +522 -0
- package/agents/security/security-compliance-auditor.md +157 -0
- package/agents/security/security-incident-responder.md +436 -0
- package/agents/security/security-penetration-tester.md +398 -0
- package/agents/security/security-senior-secops.md +751 -0
- package/agents/security/security-threat-detection-engineer.md +533 -0
- package/agents/security/security-threat-intelligence-analyst.md +643 -0
- package/agents/spatial-computing/macos-spatial-metal-engineer.md +337 -0
- package/agents/spatial-computing/terminal-integration-specialist.md +236 -0
- package/agents/spatial-computing/visionos-spatial-engineer.md +282 -0
- package/agents/spatial-computing/xr-cockpit-interaction-specialist.md +220 -0
- package/agents/spatial-computing/xr-immersive-developer.md +229 -0
- package/agents/spatial-computing/xr-interface-architect.md +253 -0
- package/agents/specialized/accounts-payable-agent.md +212 -0
- package/agents/specialized/agentic-identity-trust.md +388 -0
- package/agents/specialized/agents-orchestrator.md +366 -0
- package/agents/specialized/authenticity-appraiser.md +38 -0
- package/agents/specialized/automation-governance-architect.md +215 -0
- package/agents/specialized/business-strategist.md +487 -0
- package/agents/specialized/change-management-consultant.md +495 -0
- package/agents/specialized/corporate-training-designer.md +191 -0
- package/agents/specialized/customer-success-manager.md +458 -0
- package/agents/specialized/data-consolidation-agent.md +327 -0
- package/agents/specialized/data-privacy-officer.md +411 -0
- package/agents/specialized/esg-sustainability-officer.md +395 -0
- package/agents/specialized/gaokao-college-advisor.md +333 -0
- package/agents/specialized/government-digital-presales-consultant.md +362 -0
- package/agents/specialized/grant-writer.md +510 -0
- package/agents/specialized/healthcare-customer-service.md +388 -0
- package/agents/specialized/healthcare-marketing-compliance.md +394 -0
- package/agents/specialized/hospitality-guest-services.md +597 -0
- package/agents/specialized/hr-onboarding.md +450 -0
- package/agents/specialized/identity-graph-operator.md +270 -0
- package/agents/specialized/language-translator.md +275 -0
- package/agents/specialized/legal-billing-time-tracking.md +566 -0
- package/agents/specialized/legal-client-intake.md +487 -0
- package/agents/specialized/legal-document-review.md +452 -0
- package/agents/specialized/livestock-archive-auditor.md +135 -0
- package/agents/specialized/loan-officer-assistant.md +549 -0
- package/agents/specialized/lsp-index-engineer.md +334 -0
- package/agents/specialized/ma-integration-manager.md +426 -0
- package/agents/specialized/medical-billing-coding-specialist.md +489 -0
- package/agents/specialized/operations-manager.md +398 -0
- package/agents/specialized/organizational-psychologist.md +390 -0
- package/agents/specialized/personal-growth-mentor.md +158 -0
- package/agents/specialized/prompt-engineer.md +176 -0
- package/agents/specialized/real-estate-buyer-seller.md +594 -0
- package/agents/specialized/recruitment-specialist.md +508 -0
- package/agents/specialized/report-distribution-agent.md +354 -0
- package/agents/specialized/retail-customer-returns.md +564 -0
- package/agents/specialized/sales-data-extraction-agent.md +159 -0
- package/agents/specialized/specialized-ai-policy-writer.md +217 -0
- package/agents/specialized/specialized-civil-engineer.md +355 -0
- package/agents/specialized/specialized-cultural-intelligence-strategist.md +168 -0
- package/agents/specialized/specialized-developer-advocate.md +334 -0
- package/agents/specialized/specialized-document-generator.md +346 -0
- package/agents/specialized/specialized-french-consulting-market.md +191 -0
- package/agents/specialized/specialized-korean-business-navigator.md +215 -0
- package/agents/specialized/specialized-mcp-builder.md +351 -0
- package/agents/specialized/specialized-meeting-assistant.md +236 -0
- package/agents/specialized/specialized-model-qa.md +507 -0
- package/agents/specialized/specialized-pricing-analyst.md +242 -0
- package/agents/specialized/specialized-pricing-optimizer.md +254 -0
- package/agents/specialized/specialized-risk-assessor.md +240 -0
- package/agents/specialized/specialized-salesforce-architect.md +179 -0
- package/agents/specialized/specialized-strategy-duel-agent.md +129 -0
- package/agents/specialized/specialized-workflow-architect.md +596 -0
- package/agents/specialized/study-abroad-advisor.md +281 -0
- package/agents/specialized/technical-translator-agent.md +167 -0
- package/agents/specialized/travel-planner.md +38 -0
- package/agents/specialized/zk-steward.md +228 -0
- package/agents/strategy/EXECUTIVE-BRIEF.md +95 -0
- package/agents/strategy/QUICKSTART.md +190 -0
- package/agents/strategy/coordination/agent-activation-prompts.md +401 -0
- package/agents/strategy/coordination/handoff-templates.md +357 -0
- package/agents/strategy/nexus-strategy.md +1105 -0
- package/agents/strategy/playbooks/phase-0-discovery.md +178 -0
- package/agents/strategy/playbooks/phase-1-strategy.md +238 -0
- package/agents/strategy/playbooks/phase-2-foundation.md +278 -0
- package/agents/strategy/playbooks/phase-3-build.md +286 -0
- package/agents/strategy/playbooks/phase-4-hardening.md +332 -0
- package/agents/strategy/playbooks/phase-5-launch.md +277 -0
- package/agents/strategy/playbooks/phase-6-operate.md +318 -0
- package/agents/strategy/runbooks/scenario-enterprise-feature.md +157 -0
- package/agents/strategy/runbooks/scenario-incident-response.md +217 -0
- package/agents/strategy/runbooks/scenario-marketing-campaign.md +187 -0
- package/agents/strategy/runbooks/scenario-startup-mvp.md +154 -0
- package/agents/supply-chain/supply-chain-garment-factory-planning-engineer.md +262 -0
- package/agents/supply-chain/supply-chain-inventory-forecaster.md +212 -0
- package/agents/supply-chain/supply-chain-route-optimizer.md +224 -0
- package/agents/supply-chain/supply-chain-strategist.md +581 -0
- package/agents/supply-chain/supply-chain-vendor-evaluator.md +232 -0
- package/agents/support/support-analytics-reporter.md +364 -0
- package/agents/support/support-executive-summary-generator.md +217 -0
- package/agents/support/support-finance-tracker.md +447 -0
- package/agents/support/support-infrastructure-maintainer.md +623 -0
- package/agents/support/support-legal-compliance-checker.md +587 -0
- package/agents/support/support-recruitment-specialist.md +508 -0
- package/agents/support/support-support-responder.md +584 -0
- package/agents/testing/testing-accessibility-auditor.md +329 -0
- package/agents/testing/testing-api-tester.md +305 -0
- package/agents/testing/testing-embedded-qa-engineer.md +258 -0
- package/agents/testing/testing-evidence-collector.md +153 -0
- package/agents/testing/testing-performance-benchmarker.md +196 -0
- package/agents/testing/testing-reality-checker.md +235 -0
- package/agents/testing/testing-test-results-analyzer.md +313 -0
- package/agents/testing/testing-tool-evaluator.md +402 -0
- package/agents/testing/testing-workflow-optimizer.md +458 -0
- package/client.js +1683 -0
- package/cordis.patch.yml +30 -0
- package/host.js +2055 -0
- package/icon.svg +1 -0
- package/package.json +108 -0
package/client.js
ADDED
|
@@ -0,0 +1,1683 @@
|
|
|
1
|
+
// GENERATED by buildClient() in build-client.mjs — edit src/client-entry.ts, then run `node build-client.mjs`.
|
|
2
|
+
window.__ModuleLoader__.load({
|
|
3
|
+
id: '@jayyuen66/dsh-dir-prep-organize',
|
|
4
|
+
factory: (require) => {
|
|
5
|
+
var module = { exports: {} };
|
|
6
|
+
var exports = module.exports;
|
|
7
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
+
let react = require("react");
|
|
9
|
+
//#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.0_@deepseek-ai+cordis@4.0.4_eslint-plugin-sonarjs@4.2._a5b0027b68963132c312048d042510c0/node_modules/@jayyuen66/dsh-plugin-shared/dist/record.js
|
|
10
|
+
/** 对象类型守卫:非 `null` 的 `object` 且非数组(`Record` 索引签名投影的基础)。 */
|
|
11
|
+
function isRecord(value) {
|
|
12
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/templates.ts
|
|
16
|
+
/** 一条提示引导词/角色模板(settings 持久化形状:全 string 字段的普通对象,
|
|
17
|
+
* 满足 dsh-settings cloneJsonShaped 的 JSON 白名单)。description/group/emoji
|
|
18
|
+
* 为必填(空串表示未设置),保证下拉与设置卡无缺字段分支。 */
|
|
19
|
+
/** 视觉标记进入下拉前缀的最大字符数。 */
|
|
20
|
+
const EMOJI_MAX_LENGTH = 12;
|
|
21
|
+
/**
|
|
22
|
+
* 导入条目并入现有草稿:与既有 id 碰撞时确定性改写(追加 `-i` 直到唯一)。
|
|
23
|
+
* 返回新数组(不改输入),保证 pre-save 阶段 React key 唯一(保存前的 id 去重,
|
|
24
|
+
* sanitizeTemplateList 的确定性补 id 只兜底缺失/空,不负责碰撞改写)。
|
|
25
|
+
*/
|
|
26
|
+
function mergeImportedTemplates(existing, incoming) {
|
|
27
|
+
const ids = new Set(existing.map(({ id }) => id));
|
|
28
|
+
const out = [...existing];
|
|
29
|
+
for (const { id: baseId, ...rest } of incoming) {
|
|
30
|
+
let id = baseId;
|
|
31
|
+
if (ids.has(id)) {
|
|
32
|
+
id = `${baseId}-i`;
|
|
33
|
+
while (ids.has(id)) id = `${id}i`;
|
|
34
|
+
}
|
|
35
|
+
ids.add(id);
|
|
36
|
+
out.push({
|
|
37
|
+
...rest,
|
|
38
|
+
id
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
/** 任意来源(settings 快照 / 设置卡草稿)→ 合法模板列表(纯函数,测试锁死)。
|
|
44
|
+
*
|
|
45
|
+
* - 非数组输入 → [](调用方自行决定是否回落 DEFAULT_TEMPLATES);
|
|
46
|
+
* - 剔除非对象条目与 name/text trim 后为空的条目;
|
|
47
|
+
* - name/text/description/group 一律 trim;emoji trim 后截断至 12 字符;
|
|
48
|
+
* - id 缺失或与已收集 id 撞名 → 确定性补 `tpl-<index>`(仍撞则追加
|
|
49
|
+
* `-<index>` 直到唯一)——同输入同输出,可测试;
|
|
50
|
+
* - 绝不修改输入(深比较测试锁死)。 */
|
|
51
|
+
/** 字段 → trim 后的 string;非字符串一律 ""(与旧版逐字段三元的判据同语义)。 */
|
|
52
|
+
function trimField(value) {
|
|
53
|
+
return typeof value === "string" ? value.trim() : "";
|
|
54
|
+
}
|
|
55
|
+
/** id 缺失或与已收集 id 撞名 → 确定性补 `tpl-<index>`(仍撞则追加 `-<index>` 直到唯一)。
|
|
56
|
+
* 只负责取名,不登记 `seen`——登记由调用方在装配条目时做(同旧版顺序)。 */
|
|
57
|
+
function uniqueEntryId(candidate, index, seen) {
|
|
58
|
+
if (candidate !== "" && !seen.has(candidate)) return candidate;
|
|
59
|
+
let id = `tpl-${index}`;
|
|
60
|
+
while (seen.has(id)) id = `${id}-${index}`;
|
|
61
|
+
return id;
|
|
62
|
+
}
|
|
63
|
+
/** 单条归一化:剔除坏条目/空 name|text;id 缺失或撞名 → 确定性补 tpl-<index>,
|
|
64
|
+
* 返回 undefined 表示该条应被剔除。 */
|
|
65
|
+
function normalizeEntry(item, index, seen) {
|
|
66
|
+
let result;
|
|
67
|
+
if (isRecord(item)) {
|
|
68
|
+
const { id, name, description, text, group, emoji } = item;
|
|
69
|
+
const nextName = trimField(name);
|
|
70
|
+
const nextText = trimField(text);
|
|
71
|
+
if (nextName !== "" && nextText !== "") {
|
|
72
|
+
const nextId = uniqueEntryId(trimField(id), index, seen);
|
|
73
|
+
seen.add(nextId);
|
|
74
|
+
result = {
|
|
75
|
+
id: nextId,
|
|
76
|
+
name: nextName,
|
|
77
|
+
description: trimField(description),
|
|
78
|
+
text: nextText,
|
|
79
|
+
group: trimField(group),
|
|
80
|
+
emoji: trimField(emoji).slice(0, EMOJI_MAX_LENGTH)
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
function sanitizeTemplateList(raw) {
|
|
87
|
+
if (!Array.isArray(raw)) return [];
|
|
88
|
+
const seen = /* @__PURE__ */ new Set();
|
|
89
|
+
const out = [];
|
|
90
|
+
for (const [index, item] of raw.entries()) {
|
|
91
|
+
const entry = normalizeEntry(item, index, seen);
|
|
92
|
+
if (entry !== void 0) out.push(entry);
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
/** 任意来源(settings 快照 / 设置卡草稿)→ 合法的「导入允许目录」列表(纯函数)。
|
|
97
|
+
* host 的导入策略是「会话 cwd + 内置角色库 + importAllowRoots」,绝对路径默认拒绝,
|
|
98
|
+
* 这里登记的每一项都是**放一个读盘口子**,故:
|
|
99
|
+
* - 非数组 → [](未设置 = 一条都不登记,不是"全放行");
|
|
100
|
+
* - 非字符串 / trim 后为空 → 丢弃(空串在 host 侧 path.resolve 会落到进程 cwd,
|
|
101
|
+
* 绝不能让它变成一个隐式允许根);
|
|
102
|
+
* - 去重(同一目录登记两次没有额外语义,界面上也不该出现两行)。 */
|
|
103
|
+
function sanitizeAllowRoots(raw) {
|
|
104
|
+
const out = [];
|
|
105
|
+
if (Array.isArray(raw)) for (const item of raw) {
|
|
106
|
+
const root = typeof item === "string" ? item.trim() : "";
|
|
107
|
+
if (root !== "" && !out.includes(root)) out.push(root);
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/ui-messages.ts
|
|
113
|
+
const UI_MESSAGES = {
|
|
114
|
+
zh: {
|
|
115
|
+
cardTitle: "提示词模板(输入框「模板」下拉)",
|
|
116
|
+
cardDescription: "「模板」下拉的数据源:内置精选角色集(生成自插件 agents/ 角色库,可增删改);留空点「导入角色」可一键导入内置全部角色,导入路径按「会话 cwd + 内置角色库 + 下方导入允许目录」放行。编辑后点「保存」生效,重启不丢。",
|
|
117
|
+
statusReadOnly: "设置源不可写:编辑已禁用;下拉仍按当前列表生效。",
|
|
118
|
+
statusNotReady: "设置源未就绪:显示当前生效列表,就绪后可编辑。",
|
|
119
|
+
addTemplate: "+ 新增模板",
|
|
120
|
+
saveTitleDirty: "写入模板列表与导入允许目录(模板生效于新拉开的菜单)",
|
|
121
|
+
saveTitleClean: "无未保存修改",
|
|
122
|
+
saving: "保存中…",
|
|
123
|
+
save: "保存",
|
|
124
|
+
revert: "撤销",
|
|
125
|
+
resetTitle: "丢弃模板列表的全部自定义,回到内置默认(不影响已登记的导入允许目录;两步确认,点击即生效)",
|
|
126
|
+
resetConfirm: "确认恢复默认?再点一次(4 秒内)",
|
|
127
|
+
resetDefault: "恢复默认",
|
|
128
|
+
footHint: "说明:编辑/新增/删除先在本地暂存,点「保存」一次写入(模板与导入允许目录同理);清空名称或正文的条目保存时会被剔除(删除请用行内「删除」);恢复默认只回滚模板列表。",
|
|
129
|
+
saveFailed: "保存失败:",
|
|
130
|
+
newTemplateName: "新模板 {index}",
|
|
131
|
+
newTemplateText: "(填写模板正文:发给 AI 的引导词;[product] 类占位符用户发送前填写)",
|
|
132
|
+
persistUnconfirmed: "{action}结果不可确认:设置源未就绪(宿主未回读成功)",
|
|
133
|
+
persistRejected: "{action}未生效:宿主拒绝了本次写入(当前 revision {revision})",
|
|
134
|
+
rowAriaEmoji: "模板 {index} 视觉标记",
|
|
135
|
+
rowEmojiTitle: "可选视觉标记(emoji 或短文本),下拉菜单显示在名称前",
|
|
136
|
+
rowPlaceholderName: "菜单显示名",
|
|
137
|
+
rowAriaName: "模板 {index} 名称",
|
|
138
|
+
rowPlaceholderGroup: "分组",
|
|
139
|
+
rowAriaGroup: "模板 {index} 分组",
|
|
140
|
+
rowGroupTitle: "下拉按此分组展示;留空归入「通用」",
|
|
141
|
+
rowDeleteTitle: "删除此模板",
|
|
142
|
+
rowDelete: "删除",
|
|
143
|
+
rowPlaceholderDescription: "一句话介绍(下拉悬停时显示;如:威胁建模与 OWASP 代码审计)",
|
|
144
|
+
rowAriaDescription: "模板 {index} 一句话介绍",
|
|
145
|
+
rowPlaceholderText: "模板正文(发送给 AI 的引导词;[product] 类占位符由用户发送前填写)",
|
|
146
|
+
rowAriaText: "模板 {index} 正文",
|
|
147
|
+
importFailedUnknown: "导入失败(未知错误)",
|
|
148
|
+
importEmpty: "目录下没有符合条件的角色 .md(需含 name 的 frontmatter)",
|
|
149
|
+
importAllDone: "已从内置角色库导入全部 {count} 条{skips},编辑后点「保存」生效",
|
|
150
|
+
importFromDone: "已从 {path} 导入 {count} 条{skips},编辑后点「保存」生效",
|
|
151
|
+
importPlaceholder: "留空 = 导入内置全部角色;或填 .md / 目录路径(须在允许根内)",
|
|
152
|
+
importAriaPath: "角色导入路径",
|
|
153
|
+
importBtnTitle: "留空 = 一键导入内置全部角色;填路径 = 导入该 .md 或目录下的角色(路径须在允许根内)",
|
|
154
|
+
importing: "导入中…",
|
|
155
|
+
importRoles: "导入角色",
|
|
156
|
+
importErrorPrefix: "导入失败:",
|
|
157
|
+
importHint: "导入说明:留空导入内置角色库全部(agents/);填路径时只放行「会话 cwd」「内置角色库 agents/」与下方「导入允许目录」之内的路径——绝对路径默认拒绝,越界会直接报「导入路径越界」并回显解析后的路径。本卡没有会话上下文,故只能填内置库或已登记目录里的路径。目录扫描顶层 + 一层子目录 .md(跳过隐藏项),文件须含 name 的 frontmatter,正文将提炼为模板正文。",
|
|
158
|
+
skipDeeper: "{count} 个更深层 .md 未扫描(导入只扫两层)",
|
|
159
|
+
skipTooLarge: "{count} 个文件超字节上限被跳过",
|
|
160
|
+
skipUnreadable: "{count} 个文件读取失败",
|
|
161
|
+
skipUnnamed: "{count} 个非角色文件(frontmatter 无 name)",
|
|
162
|
+
skipSummary: "({list})",
|
|
163
|
+
skipSeparator: ",",
|
|
164
|
+
rootsHeading: "导入允许目录(importAllowRoots)",
|
|
165
|
+
rootsAriaRow: "导入允许目录 {index}",
|
|
166
|
+
rootsRowTitle: "该目录(含其子目录)内的角色 .md 可经「导入角色」读取",
|
|
167
|
+
rootsRemoveTitle: "移除此允许目录",
|
|
168
|
+
rootsRemove: "移除",
|
|
169
|
+
rootsAddPlaceholder: "新增一个允许导入的目录绝对路径",
|
|
170
|
+
rootsAddAria: "新增导入允许目录",
|
|
171
|
+
rootsAddTitle: "加入待保存的允许目录列表",
|
|
172
|
+
rootsAdd: "登记目录",
|
|
173
|
+
rootsHint: "绝对路径默认拒绝:只有「当前会话 cwd」「插件内置角色库 agents/」与本列表登记的目录之内可导入。设置页没有会话上下文,卡上填的路径必须落在内置库或本列表内。改完点底部「保存」生效。",
|
|
174
|
+
dockOrganizeEntry: "整理",
|
|
175
|
+
dockTemplatesEntry: "模板",
|
|
176
|
+
organizeIdle: "整理",
|
|
177
|
+
organizeLoading: "整理中",
|
|
178
|
+
organizeFailedShort: "失败",
|
|
179
|
+
organizeIdleTitle: "根据当前目录结构整理输入框内容(主键直接整理;▾ 可选角色视角)",
|
|
180
|
+
organizeFailedTitle: "整理失败:{message}",
|
|
181
|
+
organizeCaretAria: "选择整理角色视角",
|
|
182
|
+
organizeCaretTitle: "以某角色视角整理(角色来自下方模板库)",
|
|
183
|
+
organizeMainAria: "整理输入框内容",
|
|
184
|
+
organizeDirectItem: "直接整理(默认,不带角色)",
|
|
185
|
+
organizeNoTemplates: "无模板可选为整理视角",
|
|
186
|
+
organizeRoleItem: "以「{name}」视角整理",
|
|
187
|
+
organizeWriteBackUnavailable: "输入框动作不可用,无法写回",
|
|
188
|
+
templatesIdleTitle: "选择一条提示引导词插入输入框(空则填入,非空追加;按分组展示;[product] 类占位符发送前自己补)",
|
|
189
|
+
templatesBrokenTitle: "输入框动作不可用,无法插入",
|
|
190
|
+
templatesGroupCommon: "通用",
|
|
191
|
+
templatesAria: "插入提示引导词模板",
|
|
192
|
+
templatesEmptyHint: "无模板:在设置页「提示词模板」中添加或恢复默认",
|
|
193
|
+
builtinLoading: "正在载入内置角色模板…",
|
|
194
|
+
builtinFailed: "内置模板加载失败:{message}",
|
|
195
|
+
builtinRetry: "重试"
|
|
196
|
+
},
|
|
197
|
+
en: {
|
|
198
|
+
cardTitle: "Prompt templates (input-box \"Template\" dropdown)",
|
|
199
|
+
cardDescription: "Data source of the \"Template\" dropdown: a curated built-in role set (generated from this plugin's agents/ role library; add, edit and delete are supported). Leave the path empty and press \"Import roles\" to import the whole built-in library; import paths are allowed within \"session cwd + built-in role library + the import allowed directories below\". Press \"Save\" after editing — it survives restarts.",
|
|
200
|
+
statusReadOnly: "Settings source is read-only: editing is disabled; the dropdown still uses the current list.",
|
|
201
|
+
statusNotReady: "Settings source is not ready yet: showing the list currently in effect, editing unlocks once it is ready.",
|
|
202
|
+
addTemplate: "+ Add template",
|
|
203
|
+
saveTitleDirty: "Write the template list and the import allowed directories (templates take effect in newly opened menus)",
|
|
204
|
+
saveTitleClean: "No unsaved changes",
|
|
205
|
+
saving: "Saving…",
|
|
206
|
+
save: "Save",
|
|
207
|
+
revert: "Revert",
|
|
208
|
+
resetTitle: "Discard every customization of the template list and go back to the built-in defaults (registered import directories are untouched; two-step confirm, takes effect on the next click)",
|
|
209
|
+
resetConfirm: "Restore defaults? Click once more (within 4s)",
|
|
210
|
+
resetDefault: "Restore defaults",
|
|
211
|
+
footHint: "Note: edits, additions and deletions are staged locally first and written in one go when you press \"Save\" (same for templates and import directories); entries whose name or body is empty are dropped on save (use the inline \"Delete\" instead); \"Restore defaults\" only rolls back the template list.",
|
|
212
|
+
saveFailed: "Save failed: ",
|
|
213
|
+
newTemplateName: "New template {index}",
|
|
214
|
+
newTemplateText: "(Template body: the prompt sent to the AI; fill [product]-style placeholders yourself before sending)",
|
|
215
|
+
persistUnconfirmed: "{action} cannot be confirmed: the settings source is not ready (host read-back failed)",
|
|
216
|
+
persistRejected: "{action} did not take effect: the host rejected this write (current revision {revision})",
|
|
217
|
+
rowAriaEmoji: "Visual mark of template {index}",
|
|
218
|
+
rowEmojiTitle: "Optional visual mark (emoji or short text), shown before the name in the dropdown",
|
|
219
|
+
rowPlaceholderName: "Menu display name",
|
|
220
|
+
rowAriaName: "Name of template {index}",
|
|
221
|
+
rowPlaceholderGroup: "Group",
|
|
222
|
+
rowAriaGroup: "Group of template {index}",
|
|
223
|
+
rowGroupTitle: "The dropdown groups entries by this value; leave empty to fall into \"General\"",
|
|
224
|
+
rowDeleteTitle: "Delete this template",
|
|
225
|
+
rowDelete: "Delete",
|
|
226
|
+
rowPlaceholderDescription: "One-line intro (shown on dropdown hover; e.g. threat modelling and OWASP code auditing)",
|
|
227
|
+
rowAriaDescription: "One-line intro of template {index}",
|
|
228
|
+
rowPlaceholderText: "Template body (the prompt sent to the AI; [product]-style placeholders are filled in before sending)",
|
|
229
|
+
rowAriaText: "Body of template {index}",
|
|
230
|
+
importFailedUnknown: "Import failed (unknown error)",
|
|
231
|
+
importEmpty: "No qualifying role .md in that directory (frontmatter must contain name)",
|
|
232
|
+
importAllDone: "Imported all {count} entries from the built-in role library{skips}; press \"Save\" after editing",
|
|
233
|
+
importFromDone: "Imported {count} entries from {path}{skips}; press \"Save\" after editing",
|
|
234
|
+
importPlaceholder: "Empty = import every built-in role; or a .md / directory path (must be inside an allowed root)",
|
|
235
|
+
importAriaPath: "Role import path",
|
|
236
|
+
importBtnTitle: "Empty imports the whole built-in role library in one click; a path imports that .md or the roles in that directory (must be inside an allowed root)",
|
|
237
|
+
importing: "Importing…",
|
|
238
|
+
importRoles: "Import roles",
|
|
239
|
+
importErrorPrefix: "Import failed: ",
|
|
240
|
+
importHint: "Import notes: an empty path imports the whole built-in role library (agents/); an explicit path is only allowed inside \"session cwd\", \"built-in role library agents/\" and the \"import allowed directories\" below — absolute paths are refused by default, and anything out of bounds reports \"import path out of bounds\" with the resolved path echoed back. This card has no session context, so explicit paths must live in the built-in library or a registered directory. Directory scans cover the top level plus one level of sub-directory .md files (hidden entries skipped), each file needs a frontmatter name, and its body is condensed into the template text.",
|
|
241
|
+
skipDeeper: "{count} deeper .md files were not scanned (imports cover two levels)",
|
|
242
|
+
skipTooLarge: "{count} files were skipped for exceeding the byte limit",
|
|
243
|
+
skipUnreadable: "{count} files could not be read",
|
|
244
|
+
skipUnnamed: "{count} non-role files (no name in frontmatter)",
|
|
245
|
+
skipSummary: " ({list})",
|
|
246
|
+
skipSeparator: ", ",
|
|
247
|
+
rootsHeading: "Import allowed directories (importAllowRoots)",
|
|
248
|
+
rootsAriaRow: "Import allowed directory {index}",
|
|
249
|
+
rootsRowTitle: "Role .md files inside this directory (and its subdirectories) can be read by \"Import roles\"",
|
|
250
|
+
rootsRemoveTitle: "Remove this allowed directory",
|
|
251
|
+
rootsRemove: "Remove",
|
|
252
|
+
rootsAddPlaceholder: "Absolute path of a directory newly allowed for imports",
|
|
253
|
+
rootsAddAria: "Add an import allowed directory",
|
|
254
|
+
rootsAddTitle: "Add it to the pending allowed-directory list",
|
|
255
|
+
rootsAdd: "Register directory",
|
|
256
|
+
rootsHint: "Absolute paths are refused by default: imports only succeed inside \"the current session cwd\", \"the plugin's built-in role library agents/\" and the directories registered below. The settings page has no session context, so a path typed here must fall inside the built-in library or this list. Press \"Save\" at the bottom to apply.",
|
|
257
|
+
dockOrganizeEntry: "Organize",
|
|
258
|
+
dockTemplatesEntry: "Templates",
|
|
259
|
+
organizeIdle: "Organize",
|
|
260
|
+
organizeLoading: "Organizing",
|
|
261
|
+
organizeFailedShort: "Failed",
|
|
262
|
+
organizeIdleTitle: "Organize the input-box content from the current directory structure (main key organizes directly; ▾ picks a role perspective)",
|
|
263
|
+
organizeFailedTitle: "Organize failed: {message}",
|
|
264
|
+
organizeCaretAria: "Choose a role perspective for organizing",
|
|
265
|
+
organizeCaretTitle: "Organize from a role's perspective (roles come from the template library below)",
|
|
266
|
+
organizeMainAria: "Organize the input-box content",
|
|
267
|
+
organizeDirectItem: "Organize directly (default, no role)",
|
|
268
|
+
organizeNoTemplates: "No templates available as an organize perspective",
|
|
269
|
+
organizeRoleItem: "Organize as \"{name}\"",
|
|
270
|
+
organizeWriteBackUnavailable: "Input-box actions unavailable; cannot write back",
|
|
271
|
+
templatesIdleTitle: "Pick a prompt template to insert into the input box (empty fills it, non-empty appends; grouped display; fill [product]-style placeholders yourself before sending)",
|
|
272
|
+
templatesBrokenTitle: "Input-box actions unavailable; cannot insert",
|
|
273
|
+
templatesGroupCommon: "General",
|
|
274
|
+
templatesAria: "Insert a prompt template",
|
|
275
|
+
templatesEmptyHint: "No templates: add or restore defaults under \"Prompt templates\" in the settings page",
|
|
276
|
+
builtinLoading: "Loading built-in role templates…",
|
|
277
|
+
builtinFailed: "Failed to load built-in templates: {message}",
|
|
278
|
+
builtinRetry: "Retry"
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region node_modules/.pnpm/@jayyuen66+dsh-plugin-shared@0.1.0_@deepseek-ai+cordis@4.0.4_eslint-plugin-sonarjs@4.2._a5b0027b68963132c312048d042510c0/node_modules/@jayyuen66/dsh-plugin-shared/dist/errors.js
|
|
283
|
+
/** `Error` 取 `message`,其余一律 `String(error)`(`null` → `"null"`,对象 → 其 `toString()`)。 */
|
|
284
|
+
function errorText(error) {
|
|
285
|
+
return error instanceof Error ? error.message : String(error);
|
|
286
|
+
}
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src/client-entry.ts
|
|
289
|
+
const NS = "dir-prep-organize";
|
|
290
|
+
const BUNDLE_PKG = "@jayyuen66/dsh-dir-prep-organize";
|
|
291
|
+
const CONTEXT_URL = "/_dsh/dir-prep/context";
|
|
292
|
+
const MODEL_URL = "/_dsh/dir-prep/model";
|
|
293
|
+
const ORGANIZE_URL = "/_dsh/dir-prep/organize";
|
|
294
|
+
const IMPORT_URL = "/_dsh/dir-prep/import";
|
|
295
|
+
const FETCH_TIMEOUT_MS = 125e3;
|
|
296
|
+
const ERROR_FLASH_MS = 4e3;
|
|
297
|
+
const RESET_CONFIRM_MS = 4e3;
|
|
298
|
+
const EMOJI_PLACEHOLDER = "😀";
|
|
299
|
+
const ROOT_PATH_PLACEHOLDER = "/Users/me/roles";
|
|
300
|
+
const CSS = [
|
|
301
|
+
".dpi-btn{appearance:none;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font:inherit;font-size:12px;line-height:1;border-radius:8px;padding:6px 10px;cursor:pointer;display:inline-flex;align-items:center;gap:6px;transition:background .16s,border-color .16s,color .16s}",
|
|
302
|
+
".dpi-btn:hover:not(:disabled){border-color:var(--dsw-alias-label-dimmed);background:var(--dsw-alias-bg-layer-2)}",
|
|
303
|
+
".dpi-btn:disabled{opacity:.55;cursor:not-allowed}",
|
|
304
|
+
".dpi-btn:disabled[data-state=\"loading\"]{cursor:progress}",
|
|
305
|
+
".dpi-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}",
|
|
306
|
+
".dpi-btn svg{width:14px;height:14px;flex:none}",
|
|
307
|
+
".dpi-btn-err{border-color:var(--dsw-alias-state-error-primary);color:var(--dsw-alias-state-error-secondary)}",
|
|
308
|
+
".dpi-spin{animation:dpi-rotate .8s linear infinite}",
|
|
309
|
+
"@keyframes dpi-rotate{to{transform:rotate(360deg)}}",
|
|
310
|
+
".dpi-wrap{position:relative;display:inline-flex}",
|
|
311
|
+
".dpi-menu{position:absolute;bottom:calc(100% + 6px);right:0;z-index:50;min-width:224px;max-height:340px;overflow-y:auto;background:var(--dsw-menu-surface-fill);backdrop-filter:var(--dsw-menu-backdrop-filter);border:0;border-radius:10px;padding:4px;display:flex;flex-direction:column;gap:2px;box-shadow:var(--dsw-elevation-panel)}",
|
|
312
|
+
".dpi-item{appearance:none;border:none;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:12px;line-height:1.4;text-align:left;border-radius:6px;padding:8px 10px;cursor:pointer;white-space:nowrap}",
|
|
313
|
+
".dpi-item:hover,.dpi-item:focus-visible{background:var(--dsw-alias-bg-layer-2)}",
|
|
314
|
+
".dpi-item-empty{color:var(--dsw-alias-label-tertiary);cursor:default;font-size:12px;padding:8px 10px;white-space:nowrap}",
|
|
315
|
+
".dpi-split{display:inline-flex;align-items:stretch}",
|
|
316
|
+
".dpi-split .dpi-main{border-top-right-radius:0;border-bottom-right-radius:0;padding-right:8px}",
|
|
317
|
+
".dpi-split .dpi-caret{border-left:none;border-top-left-radius:0;border-bottom-left-radius:0;padding-left:4px;padding-right:6px}",
|
|
318
|
+
".dpi-split .dpi-caret svg{width:10px;height:10px}",
|
|
319
|
+
".dpi-group{padding:2px 0}",
|
|
320
|
+
".dpi-grouph{font-size:11px;font-weight:600;color:var(--dsw-alias-label-tertiary);padding:6px 10px 2px;letter-spacing:.02em}",
|
|
321
|
+
".dpic-card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;list-style:none;transition:border-color .16s,background .16s}",
|
|
322
|
+
".dpic-card:hover{border-color:var(--dsw-alias-label-dimmed)}",
|
|
323
|
+
".dpic-card-open{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}",
|
|
324
|
+
".dpic-header{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:transparent;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}",
|
|
325
|
+
".dpic-head{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}",
|
|
326
|
+
".dpic-title{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}",
|
|
327
|
+
".dpic-desc{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}",
|
|
328
|
+
".dpic-chevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s}",
|
|
329
|
+
".dpic-chevron-open{transform:rotate(180deg)}",
|
|
330
|
+
".dpic-body{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding:8px 0 12px;list-style:none}",
|
|
331
|
+
".dpic-row{padding:10px 0;border-bottom:1px dashed var(--dsw-alias-border-l2)}",
|
|
332
|
+
".dpic-rowhead{display:flex;gap:8px;align-items:center}",
|
|
333
|
+
".dpic-idx{font-size:12px;color:var(--dsw-alias-label-tertiary);flex:none;min-width:26px}",
|
|
334
|
+
".dpic-name{flex:1;min-width:0;box-sizing:border-box;font:inherit;font-size:12px;color:var(--dsw-alias-label-primary,inherit);background:var(--dsw-alias-bg-layer-1,transparent);border:1px solid var(--dsw-alias-border-l2,transparent);border-radius:8px;padding:6px 8px}",
|
|
335
|
+
".dpic-del{appearance:none;border:1px solid var(--dsw-alias-border-l2);background:transparent;color:var(--dsw-alias-label-tertiary);font:inherit;font-size:12px;border-radius:6px;padding:4px 8px;cursor:pointer;flex:none}",
|
|
336
|
+
".dpic-del:hover:not(:disabled){border-color:var(--dsw-alias-state-error-primary);color:var(--dsw-alias-state-error-primary)}",
|
|
337
|
+
".dpic-del:disabled{opacity:.55;cursor:not-allowed}",
|
|
338
|
+
".dpic-text{width:100%;box-sizing:border-box;font:inherit;font-size:12px;line-height:1.6;color:var(--dsw-alias-label-primary,inherit);background:var(--dsw-alias-bg-layer-1,transparent);border:1px solid var(--dsw-alias-border-l2,transparent);border-radius:8px;padding:8px;margin-top:6px;min-height:96px;resize:vertical}",
|
|
339
|
+
".dpic-name:focus,.dpic-text:focus{outline:none;border-color:var(--dsw-alias-brand-primary)}",
|
|
340
|
+
".dpic-emoji{width:44px;flex:none;box-sizing:border-box;font:inherit;font-size:13px;text-align:center;color:var(--dsw-alias-label-primary,inherit);background:var(--dsw-alias-bg-layer-1,transparent);border:1px solid var(--dsw-alias-border-l2,transparent);border-radius:8px;padding:6px 4px}",
|
|
341
|
+
".dpic-group{width:84px;flex:none;box-sizing:border-box;font:inherit;font-size:12px;color:var(--dsw-alias-label-primary,inherit);background:var(--dsw-alias-bg-layer-1,transparent);border:1px solid var(--dsw-alias-border-l2,transparent);border-radius:8px;padding:6px 8px}",
|
|
342
|
+
".dpic-desc{width:100%;box-sizing:border-box;font:inherit;font-size:12px;color:var(--dsw-alias-label-primary,inherit);background:var(--dsw-alias-bg-layer-1,transparent);border:1px solid var(--dsw-alias-border-l2,transparent);border-radius:8px;padding:6px 8px;margin-top:6px}",
|
|
343
|
+
".dpic-emoji:focus,.dpic-group:focus,.dpic-desc:focus{outline:none;border-color:var(--dsw-alias-brand-primary)}",
|
|
344
|
+
".dpic-importrow{padding:12px 0;border-bottom:1px dashed var(--dsw-alias-border-l2)}",
|
|
345
|
+
".dpic-importpath{flex:1;min-width:0;box-sizing:border-box;font:inherit;font-size:12px;color:var(--dsw-alias-label-primary,inherit);background:var(--dsw-alias-bg-layer-1,transparent);border:1px solid var(--dsw-alias-border-l2,transparent);border-radius:8px;padding:6px 8px}",
|
|
346
|
+
".dpic-importpath:focus{outline:none;border-color:var(--dsw-alias-brand-primary)}",
|
|
347
|
+
".dpic-foot{display:flex;gap:8px;align-items:center;padding-top:10px;flex-wrap:wrap}",
|
|
348
|
+
".dpic-btn{appearance:none;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font:inherit;font-size:12px;border-radius:8px;padding:6px 10px;cursor:pointer}",
|
|
349
|
+
".dpic-btn:hover:not(:disabled){border-color:var(--dsw-alias-label-dimmed);background:var(--dsw-alias-bg-layer-2)}",
|
|
350
|
+
".dpic-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}",
|
|
351
|
+
".dpic-btn:disabled{opacity:.55;cursor:not-allowed}",
|
|
352
|
+
".dpic-btn-primary{background:var(--dsw-alias-brand-primary);border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-label-primary-foreground)}",
|
|
353
|
+
".dpic-btn-primary:disabled{opacity:.55;cursor:not-allowed}",
|
|
354
|
+
".dpic-btn-danger{color:var(--dsw-alias-state-error-primary)}",
|
|
355
|
+
".dpic-btn-danger:hover:not(:disabled){border-color:var(--dsw-alias-state-error-primary)}",
|
|
356
|
+
".dpic-hint{font-size:12px;color:var(--dsw-alias-label-tertiary);line-height:1.5;padding-top:6px}",
|
|
357
|
+
".dpic-err{color:var(--dsw-alias-state-error-primary)}"
|
|
358
|
+
].join("\n");
|
|
359
|
+
const CLASS_ITEM_EMPTY = "dpi-item-empty";
|
|
360
|
+
const CLASS_ROW_HEAD = "dpic-rowhead";
|
|
361
|
+
const CLASS_IMPORT_PATH = "dpic-importpath";
|
|
362
|
+
const SLOT_INPUT_RIGHT = "conversation.input.right";
|
|
363
|
+
function parseDirEntry(raw) {
|
|
364
|
+
const { name, isDir, sizeBytes, snippet } = isRecord(raw) ? raw : {};
|
|
365
|
+
return {
|
|
366
|
+
name: typeof name === "string" ? name : "",
|
|
367
|
+
isDir: isDir === true,
|
|
368
|
+
sizeBytes: typeof sizeBytes === "number" ? sizeBytes : 0,
|
|
369
|
+
...typeof snippet === "string" ? { snippet } : {}
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
function parseContextResponse(raw) {
|
|
373
|
+
const { ok, error, csrf, cwd, truncated, entries } = isRecord(raw) ? raw : {};
|
|
374
|
+
const parsedEntries = Array.isArray(entries) ? entries.map((entry) => parseDirEntry(entry)) : void 0;
|
|
375
|
+
return {
|
|
376
|
+
ok: ok === true,
|
|
377
|
+
...typeof error === "string" ? { error } : {},
|
|
378
|
+
...typeof csrf === "string" ? { csrf } : {},
|
|
379
|
+
...typeof cwd === "string" ? { cwd } : {},
|
|
380
|
+
...truncated === true ? { truncated: true } : {},
|
|
381
|
+
...parsedEntries === void 0 ? {} : { entries: parsedEntries }
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
function parseModelResponse(raw) {
|
|
385
|
+
const { ok, error, csrf, provider, model, reasoningEffort } = isRecord(raw) ? raw : {};
|
|
386
|
+
return {
|
|
387
|
+
ok: ok === true,
|
|
388
|
+
...typeof error === "string" ? { error } : {},
|
|
389
|
+
...typeof csrf === "string" ? { csrf } : {},
|
|
390
|
+
...typeof provider === "string" ? { provider } : {},
|
|
391
|
+
...typeof model === "string" ? { model } : {},
|
|
392
|
+
...typeof reasoningEffort === "string" ? { reasoningEffort } : {}
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
function parseOrganizeResponse(raw) {
|
|
396
|
+
const { ok, error, content } = isRecord(raw) ? raw : {};
|
|
397
|
+
return {
|
|
398
|
+
ok: ok === true,
|
|
399
|
+
...typeof error === "string" ? { error } : {},
|
|
400
|
+
...typeof content === "string" ? { content } : {}
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
function countField(value) {
|
|
404
|
+
return typeof value === "number" && value > 0 ? value : 0;
|
|
405
|
+
}
|
|
406
|
+
function parseImportSkips(rec) {
|
|
407
|
+
const { tooLarge, unreadable, deeper, unnamed } = rec;
|
|
408
|
+
return {
|
|
409
|
+
tooLarge: countField(tooLarge),
|
|
410
|
+
unreadable: countField(unreadable),
|
|
411
|
+
deeper: countField(deeper),
|
|
412
|
+
unnamed: countField(unnamed)
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
function formatImportSkips(t, skips) {
|
|
416
|
+
if (skips === void 0) return "";
|
|
417
|
+
const parts = [];
|
|
418
|
+
if (skips.deeper > 0) parts.push(t("skipDeeper", { count: skips.deeper }));
|
|
419
|
+
if (skips.tooLarge > 0) parts.push(t("skipTooLarge", { count: skips.tooLarge }));
|
|
420
|
+
if (skips.unreadable > 0) parts.push(t("skipUnreadable", { count: skips.unreadable }));
|
|
421
|
+
if (skips.unnamed > 0) parts.push(t("skipUnnamed", { count: skips.unnamed }));
|
|
422
|
+
return parts.length === 0 ? "" : t("skipSummary", { list: parts.join(t("skipSeparator")) });
|
|
423
|
+
}
|
|
424
|
+
function parseImportResponse(raw) {
|
|
425
|
+
const { ok, error, count, truncated, skipped, entries } = isRecord(raw) ? raw : {};
|
|
426
|
+
const parsedEntries = Array.isArray(entries) ? sanitizeTemplateList(entries) : void 0;
|
|
427
|
+
return {
|
|
428
|
+
ok: ok === true,
|
|
429
|
+
...typeof error === "string" ? { error } : {},
|
|
430
|
+
...typeof count === "number" ? { count } : {},
|
|
431
|
+
...truncated === true ? { truncated: true } : {},
|
|
432
|
+
...isRecord(skipped) ? { skipped: parseImportSkips(skipped) } : {},
|
|
433
|
+
...parsedEntries === void 0 ? {} : { entries: parsedEntries }
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
function formatContextSummary(resp) {
|
|
437
|
+
const entries = resp.entries ?? [];
|
|
438
|
+
const lines = [`当前目录: ${resp.cwd ?? "(未提供)"}`];
|
|
439
|
+
const files = entries.filter((entry) => !entry.isDir);
|
|
440
|
+
const dirs = entries.filter((entry) => entry.isDir);
|
|
441
|
+
lines.push(`文件 ${files.length} 个, 目录 ${dirs.length} 个`);
|
|
442
|
+
if (resp.truncated === true) lines.push("(以上条目按上限截断,目录树并未完整列出,勿据此判断文件不存在)");
|
|
443
|
+
for (const dir of dirs) lines.push(`📁 ${dir.name}/`);
|
|
444
|
+
for (const file of files) {
|
|
445
|
+
const size = file.sizeBytes > 1024 ? `${(file.sizeBytes / 1024).toFixed(1)}KB` : `${file.sizeBytes}B`;
|
|
446
|
+
let line = `📄 ${file.name} (${size})`;
|
|
447
|
+
if (file.snippet !== void 0 && file.snippet.length > 0) line += ` ↳ ${file.snippet.replaceAll("\n", " ")}`;
|
|
448
|
+
lines.push(line);
|
|
449
|
+
}
|
|
450
|
+
return lines.join("\n");
|
|
451
|
+
}
|
|
452
|
+
async function httpErrorMessage(response) {
|
|
453
|
+
const fallback = `HTTP ${String(response.status)}`;
|
|
454
|
+
const body = await response.json().catch(() => null);
|
|
455
|
+
const { error } = isRecord(body) ? body : {};
|
|
456
|
+
return typeof error === "string" && error.length > 0 ? error : fallback;
|
|
457
|
+
}
|
|
458
|
+
async function fetchJson(url, init, timeoutMs = FETCH_TIMEOUT_MS) {
|
|
459
|
+
const controller = new AbortController();
|
|
460
|
+
const timer = setTimeout(() => {
|
|
461
|
+
controller.abort();
|
|
462
|
+
}, timeoutMs);
|
|
463
|
+
try {
|
|
464
|
+
const headers = new Headers(init?.headers);
|
|
465
|
+
headers.set("accept", "application/json");
|
|
466
|
+
const response = await fetch(url, {
|
|
467
|
+
...init,
|
|
468
|
+
signal: controller.signal,
|
|
469
|
+
headers
|
|
470
|
+
});
|
|
471
|
+
if (!response.ok) throw new Error(await httpErrorMessage(response));
|
|
472
|
+
return await response.json();
|
|
473
|
+
} catch (error) {
|
|
474
|
+
if (error instanceof Error && error.name === "AbortError") throw new Error("请求超时", { cause: error });
|
|
475
|
+
throw new Error(errorText(error), { cause: error });
|
|
476
|
+
} finally {
|
|
477
|
+
clearTimeout(timer);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
const BUILTIN_TEMPLATES_URL = "/_dsh/dir-prep/default-templates";
|
|
481
|
+
const builtinInitial = {
|
|
482
|
+
phase: "idle",
|
|
483
|
+
list: [],
|
|
484
|
+
error: ""
|
|
485
|
+
};
|
|
486
|
+
let builtinState = builtinInitial;
|
|
487
|
+
let builtinInflight = null;
|
|
488
|
+
const builtinListeners = /* @__PURE__ */ new Set();
|
|
489
|
+
function setBuiltinState(next) {
|
|
490
|
+
if (next === builtinState) return builtinState;
|
|
491
|
+
builtinState = next;
|
|
492
|
+
for (const listener of builtinListeners) listener();
|
|
493
|
+
return next;
|
|
494
|
+
}
|
|
495
|
+
function builtinTemplatesSnapshot() {
|
|
496
|
+
return builtinState;
|
|
497
|
+
}
|
|
498
|
+
async function loadBuiltinTemplates() {
|
|
499
|
+
if (builtinState.phase === "ready") return builtinState;
|
|
500
|
+
if (builtinInflight !== null) return await builtinInflight;
|
|
501
|
+
builtinInflight = (async () => {
|
|
502
|
+
setBuiltinState({
|
|
503
|
+
phase: "loading",
|
|
504
|
+
list: builtinState.list,
|
|
505
|
+
error: ""
|
|
506
|
+
});
|
|
507
|
+
let settled;
|
|
508
|
+
try {
|
|
509
|
+
const body = await fetchJson(BUILTIN_TEMPLATES_URL);
|
|
510
|
+
const payload = isRecord(body) ? body : void 0;
|
|
511
|
+
const okKey = "ok";
|
|
512
|
+
const templatesKey = "templates";
|
|
513
|
+
const rawReason = payload?.["error"];
|
|
514
|
+
settled = payload?.[okKey] === true ? {
|
|
515
|
+
phase: "ready",
|
|
516
|
+
list: sanitizeTemplateList(payload[templatesKey]),
|
|
517
|
+
error: ""
|
|
518
|
+
} : {
|
|
519
|
+
phase: "error",
|
|
520
|
+
list: [],
|
|
521
|
+
error: typeof rawReason === "string" && rawReason.trim() !== "" ? rawReason : "内置模板响应不是合法载荷"
|
|
522
|
+
};
|
|
523
|
+
} catch (error) {
|
|
524
|
+
settled = {
|
|
525
|
+
phase: "error",
|
|
526
|
+
list: [],
|
|
527
|
+
error: errorText(error)
|
|
528
|
+
};
|
|
529
|
+
} finally {
|
|
530
|
+
builtinInflight = null;
|
|
531
|
+
}
|
|
532
|
+
return setBuiltinState(settled);
|
|
533
|
+
})();
|
|
534
|
+
return await builtinInflight;
|
|
535
|
+
}
|
|
536
|
+
function subscribeBuiltinTemplates(listener) {
|
|
537
|
+
builtinListeners.add(listener);
|
|
538
|
+
return () => {
|
|
539
|
+
builtinListeners.delete(listener);
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
function resetBuiltinTemplates() {
|
|
543
|
+
builtinInflight = null;
|
|
544
|
+
setBuiltinState(builtinInitial);
|
|
545
|
+
}
|
|
546
|
+
function builtinStatusRow(snap, t) {
|
|
547
|
+
const attrs = {
|
|
548
|
+
className: CLASS_ITEM_EMPTY,
|
|
549
|
+
"data-field": "dpi-builtin-state"
|
|
550
|
+
};
|
|
551
|
+
const retryButton = (0, react.createElement)("button", {
|
|
552
|
+
type: "button",
|
|
553
|
+
className: "dpi-builtin-retry",
|
|
554
|
+
"data-field": "dpi-builtin-retry",
|
|
555
|
+
onClick: () => {
|
|
556
|
+
loadBuiltinTemplates();
|
|
557
|
+
}
|
|
558
|
+
}, t("builtinRetry"));
|
|
559
|
+
let row;
|
|
560
|
+
if (!snap.fromSettings && snap.builtinPhase !== "ready") row = snap.builtinPhase === "error" ? (0, react.createElement)("div", attrs, t("builtinFailed", { message: snap.builtinError }), retryButton) : (0, react.createElement)("div", attrs, t("builtinLoading"));
|
|
561
|
+
return row;
|
|
562
|
+
}
|
|
563
|
+
function assertOrganizeReady(ctxRes, modelRes, prompt) {
|
|
564
|
+
if (!ctxRes.ok) throw new Error(`目录上下文失败: ${ctxRes.error ?? "未知错误"}`);
|
|
565
|
+
if (!modelRes.ok || modelRes.provider === void 0 || modelRes.model === void 0) throw new Error(`读取模型失败: ${modelRes.error ?? "未知错误"}`);
|
|
566
|
+
if (prompt.trim().length === 0) throw new Error("输入框为空,无内容可整理");
|
|
567
|
+
const csrf = ctxRes.csrf ?? modelRes.csrf ?? "";
|
|
568
|
+
if (csrf === "") throw new Error(`整理令牌缺失:${ctxRes.error ?? modelRes.error ?? "请重试"}`);
|
|
569
|
+
return csrf;
|
|
570
|
+
}
|
|
571
|
+
async function requestOrganize(args) {
|
|
572
|
+
const { csrf, ctxRes, prompt, sessionId, roleText, timeoutMs } = args;
|
|
573
|
+
const body = {
|
|
574
|
+
prompt,
|
|
575
|
+
sessionId,
|
|
576
|
+
entriesSummary: formatContextSummary(ctxRes)
|
|
577
|
+
};
|
|
578
|
+
const roleKey = "roleText";
|
|
579
|
+
if (roleText !== void 0) body[roleKey] = roleText;
|
|
580
|
+
const orgRes = parseOrganizeResponse(await fetchJson(ORGANIZE_URL, {
|
|
581
|
+
method: "POST",
|
|
582
|
+
headers: {
|
|
583
|
+
"content-type": "application/json",
|
|
584
|
+
"x-dir-prep-csrf": csrf
|
|
585
|
+
},
|
|
586
|
+
body: JSON.stringify(body)
|
|
587
|
+
}, timeoutMs));
|
|
588
|
+
if (!orgRes.ok || orgRes.content === void 0) throw new Error(orgRes.error ?? "整理失败(未知错误)");
|
|
589
|
+
return orgRes.content;
|
|
590
|
+
}
|
|
591
|
+
async function runOrganizeFlow(args) {
|
|
592
|
+
const [ctxRaw, modelRaw] = await Promise.all([fetchJson(`${CONTEXT_URL}?sessionId=${encodeURIComponent(args.sessionId)}`), fetchJson(`${MODEL_URL}?sessionId=${encodeURIComponent(args.sessionId)}`)]);
|
|
593
|
+
const ctxRes = parseContextResponse(ctxRaw);
|
|
594
|
+
return requestOrganize({
|
|
595
|
+
csrf: assertOrganizeReady(ctxRes, parseModelResponse(modelRaw), args.prompt),
|
|
596
|
+
ctxRes,
|
|
597
|
+
prompt: args.prompt,
|
|
598
|
+
sessionId: args.sessionId,
|
|
599
|
+
roleText: args.roleText,
|
|
600
|
+
timeoutMs: args.timeoutMs
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
function projectFormSnapshot(snap) {
|
|
604
|
+
const { value, status, writable, revision } = snap;
|
|
605
|
+
return {
|
|
606
|
+
value: value ?? {},
|
|
607
|
+
ready: status === "ready",
|
|
608
|
+
writable,
|
|
609
|
+
revision: revision ?? 0
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
function rawTemplatesOf(value) {
|
|
613
|
+
return value["templates"];
|
|
614
|
+
}
|
|
615
|
+
function rawAllowRootsOf(value) {
|
|
616
|
+
return value["importAllowRoots"];
|
|
617
|
+
}
|
|
618
|
+
function rawOrganizeTimeoutMsOf(value) {
|
|
619
|
+
const raw = value["organizeTimeoutMs"];
|
|
620
|
+
return typeof raw === "number" && Number.isFinite(raw) && raw > 0 ? raw : void 0;
|
|
621
|
+
}
|
|
622
|
+
function templatesStore(scope) {
|
|
623
|
+
let cachedRaw = null;
|
|
624
|
+
let cachedBuiltin = builtinState;
|
|
625
|
+
let cachedView = {
|
|
626
|
+
templates: builtinInitial.list,
|
|
627
|
+
fromSettings: false,
|
|
628
|
+
builtinPhase: "idle",
|
|
629
|
+
builtinError: "",
|
|
630
|
+
allowRoots: [],
|
|
631
|
+
ready: false,
|
|
632
|
+
writable: false,
|
|
633
|
+
organizeTimeoutMs: void 0
|
|
634
|
+
};
|
|
635
|
+
return {
|
|
636
|
+
getSnapshot() {
|
|
637
|
+
const snap = scope.getSnapshot();
|
|
638
|
+
if (snap === cachedRaw && builtinState === cachedBuiltin) return cachedView;
|
|
639
|
+
cachedRaw = snap;
|
|
640
|
+
cachedBuiltin = builtinState;
|
|
641
|
+
const projected = projectFormSnapshot(snap);
|
|
642
|
+
const rawTemplates = rawTemplatesOf(projected.value);
|
|
643
|
+
const fromSettings = Array.isArray(rawTemplates) && rawTemplates.length > 0;
|
|
644
|
+
cachedView = {
|
|
645
|
+
templates: fromSettings ? sanitizeTemplateList(rawTemplates) : cachedBuiltin.list,
|
|
646
|
+
fromSettings,
|
|
647
|
+
builtinPhase: cachedBuiltin.phase,
|
|
648
|
+
builtinError: cachedBuiltin.error,
|
|
649
|
+
allowRoots: sanitizeAllowRoots(rawAllowRootsOf(projected.value)),
|
|
650
|
+
ready: projected.ready,
|
|
651
|
+
writable: projected.writable,
|
|
652
|
+
organizeTimeoutMs: rawOrganizeTimeoutMsOf(projected.value)
|
|
653
|
+
};
|
|
654
|
+
return cachedView;
|
|
655
|
+
},
|
|
656
|
+
subscribe(listener) {
|
|
657
|
+
const offForm = scope.subscribe(listener);
|
|
658
|
+
const offBuiltin = subscribeBuiltinTemplates(listener);
|
|
659
|
+
return () => {
|
|
660
|
+
offForm();
|
|
661
|
+
offBuiltin();
|
|
662
|
+
};
|
|
663
|
+
},
|
|
664
|
+
readBack() {
|
|
665
|
+
const projected = projectFormSnapshot(scope.getSnapshot());
|
|
666
|
+
return {
|
|
667
|
+
ready: projected.ready,
|
|
668
|
+
revision: projected.revision,
|
|
669
|
+
templates: sanitizeTemplateList(rawTemplatesOf(projected.value)),
|
|
670
|
+
allowRoots: sanitizeAllowRoots(rawAllowRootsOf(projected.value))
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
function persistError(t, persisted, expected, action, opts) {
|
|
676
|
+
let message;
|
|
677
|
+
const revertedToBase = opts?.treatEmptyAsReverted === true && persisted.templates.length === 0 && expected.length > 0;
|
|
678
|
+
if (!persisted.ready) message = t("persistUnconfirmed", { action });
|
|
679
|
+
else if (!revertedToBase && JSON.stringify(persisted.templates) !== JSON.stringify(expected)) message = t("persistRejected", {
|
|
680
|
+
action,
|
|
681
|
+
revision: persisted.revision
|
|
682
|
+
});
|
|
683
|
+
return message;
|
|
684
|
+
}
|
|
685
|
+
function rootsPersistError(t, persisted, expected, action) {
|
|
686
|
+
let message;
|
|
687
|
+
if (!persisted.ready) message = t("persistUnconfirmed", { action });
|
|
688
|
+
else if (JSON.stringify(persisted.allowRoots) !== JSON.stringify(expected)) message = t("persistRejected", {
|
|
689
|
+
action,
|
|
690
|
+
revision: persisted.revision
|
|
691
|
+
});
|
|
692
|
+
return message;
|
|
693
|
+
}
|
|
694
|
+
function applyTemplateToDraft(current, template) {
|
|
695
|
+
const base = typeof current === "string" ? current.trimEnd() : "";
|
|
696
|
+
if (base.length === 0) return template;
|
|
697
|
+
return `${base}\n\n${template}`;
|
|
698
|
+
}
|
|
699
|
+
function svgPathProps(dValue, strokeLinejoin = false) {
|
|
700
|
+
const entries = [
|
|
701
|
+
["d", dValue],
|
|
702
|
+
["fill", "none"],
|
|
703
|
+
["stroke", "currentColor"],
|
|
704
|
+
["strokeWidth", 1.5],
|
|
705
|
+
["strokeLinecap", "round"]
|
|
706
|
+
];
|
|
707
|
+
if (strokeLinejoin) entries.push(["strokeLinejoin", "round"]);
|
|
708
|
+
return Object.fromEntries(entries);
|
|
709
|
+
}
|
|
710
|
+
function svgSpinProps() {
|
|
711
|
+
return Object.fromEntries([
|
|
712
|
+
["cx", 7],
|
|
713
|
+
["cy", 7],
|
|
714
|
+
["r", 5.5],
|
|
715
|
+
["fill", "none"],
|
|
716
|
+
["stroke", "currentColor"],
|
|
717
|
+
["strokeWidth", 1.5],
|
|
718
|
+
["strokeDasharray", "26 10"],
|
|
719
|
+
["strokeLinecap", "round"]
|
|
720
|
+
]);
|
|
721
|
+
}
|
|
722
|
+
function TidyIcon() {
|
|
723
|
+
return (0, react.createElement)("svg", {
|
|
724
|
+
width: 14,
|
|
725
|
+
height: 14,
|
|
726
|
+
viewBox: "0 0 14 14",
|
|
727
|
+
"aria-hidden": true
|
|
728
|
+
}, (0, react.createElement)("path", svgPathProps("M2 4l5 4 5-4", true)), (0, react.createElement)("path", svgPathProps("M2 8.5l5 4 5-4", true)));
|
|
729
|
+
}
|
|
730
|
+
function SpinIcon() {
|
|
731
|
+
return (0, react.createElement)("svg", {
|
|
732
|
+
width: 14,
|
|
733
|
+
height: 14,
|
|
734
|
+
viewBox: "0 0 14 14",
|
|
735
|
+
"aria-hidden": true,
|
|
736
|
+
className: "dpi-spin"
|
|
737
|
+
}, (0, react.createElement)("circle", svgSpinProps()));
|
|
738
|
+
}
|
|
739
|
+
function FailIcon() {
|
|
740
|
+
return (0, react.createElement)("svg", {
|
|
741
|
+
width: 14,
|
|
742
|
+
height: 14,
|
|
743
|
+
viewBox: "0 0 14 14",
|
|
744
|
+
"aria-hidden": true
|
|
745
|
+
}, (0, react.createElement)("path", svgPathProps("M3 3l8 8M11 3l-8 8")));
|
|
746
|
+
}
|
|
747
|
+
function TemplateIcon() {
|
|
748
|
+
return (0, react.createElement)("svg", {
|
|
749
|
+
width: 14,
|
|
750
|
+
height: 14,
|
|
751
|
+
viewBox: "0 0 14 14",
|
|
752
|
+
"aria-hidden": true
|
|
753
|
+
}, (0, react.createElement)("path", svgPathProps("M2.5 3.5h9M2.5 7h9M2.5 10.5h5.5")));
|
|
754
|
+
}
|
|
755
|
+
function CaretIcon() {
|
|
756
|
+
return (0, react.createElement)("svg", {
|
|
757
|
+
width: 14,
|
|
758
|
+
height: 14,
|
|
759
|
+
viewBox: "0 0 14 14",
|
|
760
|
+
"aria-hidden": true
|
|
761
|
+
}, (0, react.createElement)("path", svgPathProps("M2.5 5.5L7 9.5l4.5-4", true)));
|
|
762
|
+
}
|
|
763
|
+
function useMenuDismiss(open, wrapRef, close) {
|
|
764
|
+
(0, react.useEffect)(() => {
|
|
765
|
+
function onDown(event) {
|
|
766
|
+
if (wrapRef.current !== null && event.target instanceof Node && !wrapRef.current.contains(event.target)) close();
|
|
767
|
+
}
|
|
768
|
+
function onKey(event) {
|
|
769
|
+
if (event.key === "Escape") close();
|
|
770
|
+
}
|
|
771
|
+
if (open) {
|
|
772
|
+
document.addEventListener("mousedown", onDown);
|
|
773
|
+
document.addEventListener("keydown", onKey);
|
|
774
|
+
}
|
|
775
|
+
return () => {
|
|
776
|
+
document.removeEventListener("mousedown", onDown);
|
|
777
|
+
document.removeEventListener("keydown", onKey);
|
|
778
|
+
};
|
|
779
|
+
}, [
|
|
780
|
+
close,
|
|
781
|
+
open,
|
|
782
|
+
wrapRef
|
|
783
|
+
]);
|
|
784
|
+
}
|
|
785
|
+
async function runOrganizeClick(args) {
|
|
786
|
+
const { loading, seq, prompt, sessionId, timeoutMs, roleText, setLoading, setMenuOpen, setFailed, flashTimer, writeDraft } = args;
|
|
787
|
+
if (loading) return;
|
|
788
|
+
seq.current += 1;
|
|
789
|
+
const mySeq = seq.current;
|
|
790
|
+
setLoading(true);
|
|
791
|
+
setFailed(void 0);
|
|
792
|
+
setMenuOpen(false);
|
|
793
|
+
try {
|
|
794
|
+
const content = await runOrganizeFlow({
|
|
795
|
+
prompt,
|
|
796
|
+
sessionId,
|
|
797
|
+
...roleText === void 0 ? {} : { roleText },
|
|
798
|
+
timeoutMs
|
|
799
|
+
});
|
|
800
|
+
if (seq.current !== mySeq) return;
|
|
801
|
+
writeDraft(content);
|
|
802
|
+
} catch (error) {
|
|
803
|
+
if (seq.current !== mySeq) return;
|
|
804
|
+
setFailed(errorText(error));
|
|
805
|
+
if (flashTimer.current !== null) clearTimeout(flashTimer.current);
|
|
806
|
+
flashTimer.current = setTimeout(() => {
|
|
807
|
+
setFailed(void 0);
|
|
808
|
+
}, ERROR_FLASH_MS);
|
|
809
|
+
} finally {
|
|
810
|
+
if (seq.current === mySeq) setLoading(false);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
function createOrganizeMainButton(ui) {
|
|
814
|
+
const { t, icon, label, state, errClass, errTitle, loading, onRun } = ui;
|
|
815
|
+
return (0, react.createElement)("button", {
|
|
816
|
+
type: "button",
|
|
817
|
+
className: `dpi-btn dpi-main${errClass}`,
|
|
818
|
+
"aria-label": t("organizeMainAria"),
|
|
819
|
+
title: errTitle,
|
|
820
|
+
"data-field": "dpi-organize-btn",
|
|
821
|
+
"data-state": state,
|
|
822
|
+
disabled: loading,
|
|
823
|
+
onClick: () => {
|
|
824
|
+
onRun();
|
|
825
|
+
}
|
|
826
|
+
}, icon, label);
|
|
827
|
+
}
|
|
828
|
+
function createOrganizeCaret(ui) {
|
|
829
|
+
const { t, errClass, menuOpen, loading, onToggleMenu } = ui;
|
|
830
|
+
return (0, react.createElement)("button", {
|
|
831
|
+
type: "button",
|
|
832
|
+
className: `dpi-btn dpi-caret${errClass}`,
|
|
833
|
+
"aria-label": t("organizeCaretAria"),
|
|
834
|
+
"aria-haspopup": "menu",
|
|
835
|
+
"aria-expanded": menuOpen,
|
|
836
|
+
title: t("organizeCaretTitle"),
|
|
837
|
+
"data-field": "dpi-organize-caret",
|
|
838
|
+
"data-state": menuOpen ? "open" : "idle",
|
|
839
|
+
disabled: loading,
|
|
840
|
+
onClick: onToggleMenu
|
|
841
|
+
}, (0, react.createElement)(CaretIcon));
|
|
842
|
+
}
|
|
843
|
+
function createOrganizeRoleMenu(ui) {
|
|
844
|
+
const { t, templates, onRun, directItemLabel, noTemplatesLabel, builtinRow } = ui;
|
|
845
|
+
return (0, react.createElement)("div", {
|
|
846
|
+
className: "dpi-menu",
|
|
847
|
+
role: "menu",
|
|
848
|
+
"data-field": "dpi-organize-menu"
|
|
849
|
+
}, (0, react.createElement)("button", {
|
|
850
|
+
type: "button",
|
|
851
|
+
className: "dpi-item",
|
|
852
|
+
role: "menuitem",
|
|
853
|
+
"data-field": "dpi-organize-role-direct",
|
|
854
|
+
onClick: () => {
|
|
855
|
+
onRun();
|
|
856
|
+
}
|
|
857
|
+
}, directItemLabel), templates.length === 0 ? builtinRow ?? (0, react.createElement)("div", { className: CLASS_ITEM_EMPTY }, noTemplatesLabel) : templates.map((tpl) => (0, react.createElement)("button", {
|
|
858
|
+
key: tpl.id,
|
|
859
|
+
type: "button",
|
|
860
|
+
className: "dpi-item",
|
|
861
|
+
role: "menuitem",
|
|
862
|
+
"data-field": "dpi-organize-role-item",
|
|
863
|
+
title: tpl.description === "" ? tpl.text : tpl.description,
|
|
864
|
+
onClick: () => {
|
|
865
|
+
onRun(tpl.text);
|
|
866
|
+
}
|
|
867
|
+
}, `${tpl.emoji === "" ? "" : `${tpl.emoji} `}${t("organizeRoleItem", { name: tpl.name })}`)));
|
|
868
|
+
}
|
|
869
|
+
function createOrganizeButton() {
|
|
870
|
+
return function OrganizeButton(props) {
|
|
871
|
+
const [loading, setLoading] = (0, react.useState)(false);
|
|
872
|
+
const [failed, setFailed] = (0, react.useState)(void 0);
|
|
873
|
+
const [menuOpen, setMenuOpen] = (0, react.useState)(false);
|
|
874
|
+
const seq = (0, react.useRef)(0);
|
|
875
|
+
const flashTimer = (0, react.useRef)(null);
|
|
876
|
+
const wrapRef = (0, react.useRef)(null);
|
|
877
|
+
const draft = props.useInput === void 0 ? "" : props.useInput((state) => state.draft) ?? "";
|
|
878
|
+
const snap = props.useCard((state) => state);
|
|
879
|
+
const { templates } = snap;
|
|
880
|
+
useMenuDismiss(menuOpen, wrapRef, () => {
|
|
881
|
+
setMenuOpen(false);
|
|
882
|
+
});
|
|
883
|
+
(0, react.useEffect)(() => () => {
|
|
884
|
+
seq.current += 1;
|
|
885
|
+
if (flashTimer.current !== null) clearTimeout(flashTimer.current);
|
|
886
|
+
}, []);
|
|
887
|
+
async function handleOrganize(roleText) {
|
|
888
|
+
await runOrganizeClick({
|
|
889
|
+
loading,
|
|
890
|
+
seq,
|
|
891
|
+
prompt: draft,
|
|
892
|
+
sessionId: props.sessionId ?? "",
|
|
893
|
+
timeoutMs: (snap.organizeTimeoutMs ?? 12e4) + 5e3,
|
|
894
|
+
roleText,
|
|
895
|
+
setLoading,
|
|
896
|
+
setMenuOpen,
|
|
897
|
+
setFailed,
|
|
898
|
+
flashTimer,
|
|
899
|
+
writeDraft: (content) => {
|
|
900
|
+
const actions = props.inputActions;
|
|
901
|
+
if (actions === void 0 || typeof actions.setDraft !== "function") throw new Error(props.t("organizeWriteBackUnavailable"));
|
|
902
|
+
actions.setDraft(content);
|
|
903
|
+
}
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
function openMenu() {
|
|
907
|
+
if (!snap.fromSettings) loadBuiltinTemplates();
|
|
908
|
+
setMenuOpen((prev) => !prev);
|
|
909
|
+
}
|
|
910
|
+
let icon;
|
|
911
|
+
let label;
|
|
912
|
+
let state;
|
|
913
|
+
if (failed !== void 0) {
|
|
914
|
+
icon = (0, react.createElement)(FailIcon);
|
|
915
|
+
label = props.t("organizeFailedShort");
|
|
916
|
+
state = "error";
|
|
917
|
+
} else if (loading) {
|
|
918
|
+
icon = (0, react.createElement)(SpinIcon);
|
|
919
|
+
label = props.t("organizeLoading");
|
|
920
|
+
state = "loading";
|
|
921
|
+
} else {
|
|
922
|
+
icon = (0, react.createElement)(TidyIcon);
|
|
923
|
+
label = props.t("organizeIdle");
|
|
924
|
+
state = "idle";
|
|
925
|
+
}
|
|
926
|
+
const ui = {
|
|
927
|
+
t: props.t,
|
|
928
|
+
errTitle: failed === void 0 ? props.t("organizeIdleTitle") : props.t("organizeFailedTitle", { message: failed }),
|
|
929
|
+
icon,
|
|
930
|
+
label,
|
|
931
|
+
state,
|
|
932
|
+
errClass: failed === void 0 ? "" : " dpi-btn-err",
|
|
933
|
+
directItemLabel: props.t("organizeDirectItem"),
|
|
934
|
+
noTemplatesLabel: props.t("organizeNoTemplates"),
|
|
935
|
+
builtinRow: builtinStatusRow(snap, props.t),
|
|
936
|
+
loading,
|
|
937
|
+
menuOpen,
|
|
938
|
+
templates,
|
|
939
|
+
onRun: handleOrganize,
|
|
940
|
+
onToggleMenu: openMenu
|
|
941
|
+
};
|
|
942
|
+
return (0, react.createElement)("span", {
|
|
943
|
+
className: "dpi-wrap dpi-split",
|
|
944
|
+
ref: wrapRef
|
|
945
|
+
}, createOrganizeMainButton(ui), createOrganizeCaret(ui), menuOpen ? createOrganizeRoleMenu(ui) : null);
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
function createTemplateButton() {
|
|
949
|
+
return function TemplateButton(props) {
|
|
950
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
951
|
+
const wrapRef = (0, react.useRef)(null);
|
|
952
|
+
const draft = props.useInput === void 0 ? "" : props.useInput((state) => state.draft) ?? "";
|
|
953
|
+
const snap = props.useCard((state) => state);
|
|
954
|
+
const { templates } = snap;
|
|
955
|
+
useMenuDismiss(open, wrapRef, () => {
|
|
956
|
+
setOpen(false);
|
|
957
|
+
});
|
|
958
|
+
function pick(text) {
|
|
959
|
+
setOpen(false);
|
|
960
|
+
const actions = props.inputActions;
|
|
961
|
+
if (actions === void 0 || typeof actions.setDraft !== "function") return;
|
|
962
|
+
actions.setDraft(applyTemplateToDraft(draft, text));
|
|
963
|
+
}
|
|
964
|
+
const canWrite = props.inputActions !== void 0 && typeof props.inputActions.setDraft === "function";
|
|
965
|
+
const title = canWrite ? props.t("templatesIdleTitle") : props.t("templatesBrokenTitle");
|
|
966
|
+
const groupedMap = /* @__PURE__ */ new Map();
|
|
967
|
+
for (const tpl of templates) {
|
|
968
|
+
const key = tpl.group.trim() === "" ? props.t("templatesGroupCommon") : tpl.group;
|
|
969
|
+
const bucket = groupedMap.get(key) ?? [];
|
|
970
|
+
bucket.push(tpl);
|
|
971
|
+
groupedMap.set(key, bucket);
|
|
972
|
+
}
|
|
973
|
+
const grouped = [...groupedMap.entries()].map(([group, items]) => ({
|
|
974
|
+
group,
|
|
975
|
+
items
|
|
976
|
+
}));
|
|
977
|
+
const emptyHintLabel = props.t("templatesEmptyHint");
|
|
978
|
+
const builtinRow = builtinStatusRow(snap, props.t);
|
|
979
|
+
return (0, react.createElement)("span", {
|
|
980
|
+
className: "dpi-wrap",
|
|
981
|
+
ref: wrapRef
|
|
982
|
+
}, (0, react.createElement)("button", {
|
|
983
|
+
type: "button",
|
|
984
|
+
className: "dpi-btn",
|
|
985
|
+
"aria-label": props.t("templatesAria"),
|
|
986
|
+
"aria-haspopup": "menu",
|
|
987
|
+
"aria-expanded": open,
|
|
988
|
+
title,
|
|
989
|
+
"data-field": "dpi-template-btn",
|
|
990
|
+
"data-state": open ? "open" : "idle",
|
|
991
|
+
disabled: !canWrite,
|
|
992
|
+
onClick: () => {
|
|
993
|
+
if (!snap.fromSettings) loadBuiltinTemplates();
|
|
994
|
+
setOpen((prev) => !prev);
|
|
995
|
+
}
|
|
996
|
+
}, (0, react.createElement)(TemplateIcon), props.t("dockTemplatesEntry")), open ? (0, react.createElement)("div", {
|
|
997
|
+
className: "dpi-menu",
|
|
998
|
+
role: "menu",
|
|
999
|
+
"data-field": "dpi-template-menu"
|
|
1000
|
+
}, templates.length === 0 ? builtinRow ?? (0, react.createElement)("div", { className: CLASS_ITEM_EMPTY }, emptyHintLabel) : grouped.map((slot) => (0, react.createElement)("div", {
|
|
1001
|
+
key: slot.group,
|
|
1002
|
+
className: "dpi-group"
|
|
1003
|
+
}, (0, react.createElement)("div", {
|
|
1004
|
+
className: "dpi-grouph",
|
|
1005
|
+
role: "presentation"
|
|
1006
|
+
}, slot.group), slot.items.map((tpl) => (0, react.createElement)("button", {
|
|
1007
|
+
key: tpl.id,
|
|
1008
|
+
type: "button",
|
|
1009
|
+
className: "dpi-item",
|
|
1010
|
+
role: "menuitem",
|
|
1011
|
+
"data-field": "dpi-template-item",
|
|
1012
|
+
title: tpl.description === "" ? tpl.text : tpl.description,
|
|
1013
|
+
onClick: () => {
|
|
1014
|
+
pick(tpl.text);
|
|
1015
|
+
}
|
|
1016
|
+
}, `${tpl.emoji === "" ? "" : `${tpl.emoji} `}${tpl.name}`))))) : null);
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
function newTemplateId() {
|
|
1020
|
+
let id;
|
|
1021
|
+
try {
|
|
1022
|
+
id = `tpl-${crypto.randomUUID()}`;
|
|
1023
|
+
} catch {
|
|
1024
|
+
id = `tpl-${Date.now().toString(36)}-${Math.floor(Math.random() * 1e9).toString(36)}`;
|
|
1025
|
+
}
|
|
1026
|
+
return id;
|
|
1027
|
+
}
|
|
1028
|
+
function createTemplateRowElement(view) {
|
|
1029
|
+
const { t, rowNum, disabled, values, setters } = view;
|
|
1030
|
+
const indexMark = (0, react.createElement)("span", { className: "dpic-idx" }, `#${rowNum}`);
|
|
1031
|
+
const emojiInput = (0, react.createElement)("input", {
|
|
1032
|
+
type: "text",
|
|
1033
|
+
className: "dpic-emoji",
|
|
1034
|
+
value: values.emoji,
|
|
1035
|
+
placeholder: EMOJI_PLACEHOLDER,
|
|
1036
|
+
disabled,
|
|
1037
|
+
"aria-label": t("rowAriaEmoji", { index: rowNum }),
|
|
1038
|
+
title: t("rowEmojiTitle"),
|
|
1039
|
+
onChange: (event) => {
|
|
1040
|
+
setters.emoji(event.target.value);
|
|
1041
|
+
},
|
|
1042
|
+
onBlur: view.onBlur
|
|
1043
|
+
});
|
|
1044
|
+
const nameInput = (0, react.createElement)("input", {
|
|
1045
|
+
type: "text",
|
|
1046
|
+
className: "dpic-name",
|
|
1047
|
+
value: values.name,
|
|
1048
|
+
placeholder: t("rowPlaceholderName"),
|
|
1049
|
+
disabled,
|
|
1050
|
+
"aria-label": t("rowAriaName", { index: rowNum }),
|
|
1051
|
+
onChange: (event) => {
|
|
1052
|
+
setters.name(event.target.value);
|
|
1053
|
+
},
|
|
1054
|
+
onBlur: view.onBlur
|
|
1055
|
+
});
|
|
1056
|
+
const groupInput = (0, react.createElement)("input", {
|
|
1057
|
+
type: "text",
|
|
1058
|
+
className: "dpic-group",
|
|
1059
|
+
value: values.group,
|
|
1060
|
+
placeholder: t("rowPlaceholderGroup"),
|
|
1061
|
+
disabled,
|
|
1062
|
+
"aria-label": t("rowAriaGroup", { index: rowNum }),
|
|
1063
|
+
title: t("rowGroupTitle"),
|
|
1064
|
+
onChange: (event) => {
|
|
1065
|
+
setters.group(event.target.value);
|
|
1066
|
+
},
|
|
1067
|
+
onBlur: view.onBlur
|
|
1068
|
+
});
|
|
1069
|
+
const deleteButton = (0, react.createElement)("button", {
|
|
1070
|
+
type: "button",
|
|
1071
|
+
className: "dpic-del",
|
|
1072
|
+
disabled,
|
|
1073
|
+
title: t("rowDeleteTitle"),
|
|
1074
|
+
onClick: () => {
|
|
1075
|
+
view.onDelete(view.templateId);
|
|
1076
|
+
}
|
|
1077
|
+
}, t("rowDelete"));
|
|
1078
|
+
const descriptionInput = (0, react.createElement)("input", {
|
|
1079
|
+
type: "text",
|
|
1080
|
+
className: "dpic-desc",
|
|
1081
|
+
value: values.description,
|
|
1082
|
+
placeholder: t("rowPlaceholderDescription"),
|
|
1083
|
+
disabled,
|
|
1084
|
+
"aria-label": t("rowAriaDescription", { index: rowNum }),
|
|
1085
|
+
onChange: (event) => {
|
|
1086
|
+
setters.description(event.target.value);
|
|
1087
|
+
},
|
|
1088
|
+
onBlur: view.onBlur
|
|
1089
|
+
});
|
|
1090
|
+
const textArea = (0, react.createElement)("textarea", {
|
|
1091
|
+
className: "dpic-text",
|
|
1092
|
+
value: values.text,
|
|
1093
|
+
rows: 6,
|
|
1094
|
+
placeholder: t("rowPlaceholderText"),
|
|
1095
|
+
disabled,
|
|
1096
|
+
"aria-label": t("rowAriaText", { index: rowNum }),
|
|
1097
|
+
onChange: (event) => {
|
|
1098
|
+
setters.text(event.target.value);
|
|
1099
|
+
},
|
|
1100
|
+
onBlur: view.onBlur
|
|
1101
|
+
});
|
|
1102
|
+
return (0, react.createElement)("li", { className: "dpic-row" }, (0, react.createElement)("div", { className: CLASS_ROW_HEAD }, indexMark, emojiInput, nameInput, groupInput, deleteButton), descriptionInput, textArea);
|
|
1103
|
+
}
|
|
1104
|
+
function TemplateRow(props) {
|
|
1105
|
+
const { t } = props;
|
|
1106
|
+
const [name, setName] = (0, react.useState)(props.template.name);
|
|
1107
|
+
const [emoji, setEmoji] = (0, react.useState)(props.template.emoji);
|
|
1108
|
+
const [group, setGroup] = (0, react.useState)(props.template.group);
|
|
1109
|
+
const [description, setDescription] = (0, react.useState)(props.template.description);
|
|
1110
|
+
const [text, setText] = (0, react.useState)(props.template.text);
|
|
1111
|
+
const rowNum = String(props.index + 1);
|
|
1112
|
+
(0, react.useEffect)(() => {
|
|
1113
|
+
setName(props.template.name);
|
|
1114
|
+
setEmoji(props.template.emoji);
|
|
1115
|
+
setGroup(props.template.group);
|
|
1116
|
+
setDescription(props.template.description);
|
|
1117
|
+
setText(props.template.text);
|
|
1118
|
+
}, [
|
|
1119
|
+
props.template.id,
|
|
1120
|
+
props.template.name,
|
|
1121
|
+
props.template.emoji,
|
|
1122
|
+
props.template.group,
|
|
1123
|
+
props.template.description,
|
|
1124
|
+
props.template.text
|
|
1125
|
+
]);
|
|
1126
|
+
function commit() {
|
|
1127
|
+
const nextName = name.trim();
|
|
1128
|
+
const nextText = text.trim();
|
|
1129
|
+
if (nextName === "" || nextText === "") return;
|
|
1130
|
+
const nextEmoji = emoji.trim();
|
|
1131
|
+
const nextGroup = group.trim();
|
|
1132
|
+
const nextDescription = description.trim();
|
|
1133
|
+
if (nextName === props.template.name && nextEmoji === props.template.emoji && nextGroup === props.template.group && nextDescription === props.template.description && nextText === props.template.text) return;
|
|
1134
|
+
props.onCommit(props.template.id, {
|
|
1135
|
+
name: nextName,
|
|
1136
|
+
emoji: nextEmoji,
|
|
1137
|
+
group: nextGroup,
|
|
1138
|
+
description: nextDescription,
|
|
1139
|
+
text: nextText
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
return createTemplateRowElement({
|
|
1143
|
+
t,
|
|
1144
|
+
rowNum,
|
|
1145
|
+
disabled: props.disabled,
|
|
1146
|
+
templateId: props.template.id,
|
|
1147
|
+
values: {
|
|
1148
|
+
name,
|
|
1149
|
+
emoji,
|
|
1150
|
+
group,
|
|
1151
|
+
description,
|
|
1152
|
+
text
|
|
1153
|
+
},
|
|
1154
|
+
setters: {
|
|
1155
|
+
name: setName,
|
|
1156
|
+
emoji: setEmoji,
|
|
1157
|
+
group: setGroup,
|
|
1158
|
+
text: setText,
|
|
1159
|
+
description: setDescription
|
|
1160
|
+
},
|
|
1161
|
+
onBlur: commit,
|
|
1162
|
+
onDelete: props.onDelete
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
function ImportPanel(props) {
|
|
1166
|
+
const { t } = props;
|
|
1167
|
+
const [importPath, setImportPath] = (0, react.useState)("");
|
|
1168
|
+
const [importBusy, setImportBusy] = (0, react.useState)(false);
|
|
1169
|
+
const [importMsg, setImportMsg] = (0, react.useState)("");
|
|
1170
|
+
const [importError, setImportError] = (0, react.useState)("");
|
|
1171
|
+
async function onImport() {
|
|
1172
|
+
if (importBusy) return;
|
|
1173
|
+
const target = importPath.trim();
|
|
1174
|
+
setImportBusy(true);
|
|
1175
|
+
setImportError("");
|
|
1176
|
+
setImportMsg("");
|
|
1177
|
+
try {
|
|
1178
|
+
const resp = parseImportResponse(await fetchJson(IMPORT_URL, {
|
|
1179
|
+
method: "POST",
|
|
1180
|
+
headers: { "content-type": "application/json" },
|
|
1181
|
+
body: JSON.stringify({
|
|
1182
|
+
path: target,
|
|
1183
|
+
sessionId: ""
|
|
1184
|
+
})
|
|
1185
|
+
}));
|
|
1186
|
+
if (!resp.ok || resp.entries === void 0) throw new Error(resp.error ?? t("importFailedUnknown"));
|
|
1187
|
+
const usable = resp.entries.length;
|
|
1188
|
+
const count = Math.min(resp.count ?? usable, usable);
|
|
1189
|
+
if (count === 0) {
|
|
1190
|
+
setImportError(t("importEmpty"));
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
props.onImported(resp.entries);
|
|
1194
|
+
setImportPath("");
|
|
1195
|
+
const skipNote = formatImportSkips(t, resp.skipped);
|
|
1196
|
+
setImportMsg(target.length === 0 ? t("importAllDone", {
|
|
1197
|
+
count,
|
|
1198
|
+
skips: skipNote
|
|
1199
|
+
}) : t("importFromDone", {
|
|
1200
|
+
path: target,
|
|
1201
|
+
count,
|
|
1202
|
+
skips: skipNote
|
|
1203
|
+
}));
|
|
1204
|
+
} catch (error) {
|
|
1205
|
+
setImportError(errorText(error));
|
|
1206
|
+
} finally {
|
|
1207
|
+
setImportBusy(false);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
const canImport = props.editable && !importBusy;
|
|
1211
|
+
const importPathInput = (0, react.createElement)("input", {
|
|
1212
|
+
type: "text",
|
|
1213
|
+
className: CLASS_IMPORT_PATH,
|
|
1214
|
+
value: importPath,
|
|
1215
|
+
placeholder: t("importPlaceholder"),
|
|
1216
|
+
disabled: !canImport,
|
|
1217
|
+
"aria-label": t("importAriaPath"),
|
|
1218
|
+
onChange: (event) => {
|
|
1219
|
+
setImportPath(event.target.value);
|
|
1220
|
+
},
|
|
1221
|
+
onKeyDown: (event) => {
|
|
1222
|
+
if (event.key === "Enter") onImport();
|
|
1223
|
+
}
|
|
1224
|
+
});
|
|
1225
|
+
const importBtn = (0, react.createElement)("button", {
|
|
1226
|
+
type: "button",
|
|
1227
|
+
className: "dpic-btn",
|
|
1228
|
+
disabled: !canImport,
|
|
1229
|
+
title: t("importBtnTitle"),
|
|
1230
|
+
onClick: onImport
|
|
1231
|
+
}, importBusy ? t("importing") : t("importRoles"));
|
|
1232
|
+
const importMsgEl = importMsg === "" ? null : (0, react.createElement)("div", { className: "dpic-hint" }, importMsg);
|
|
1233
|
+
const importErrorEl = importError === "" ? null : (0, react.createElement)("div", { className: "dpic-hint dpic-err" }, `${t("importErrorPrefix")}${importError}`);
|
|
1234
|
+
const importHintEl = (0, react.createElement)("div", { className: "dpic-hint" }, t("importHint"));
|
|
1235
|
+
return (0, react.createElement)("li", { className: "dpic-importrow" }, (0, react.createElement)("div", { className: CLASS_ROW_HEAD }, importPathInput, importBtn), importMsgEl, importErrorEl, importHintEl);
|
|
1236
|
+
}
|
|
1237
|
+
function AllowRootsPanel(props) {
|
|
1238
|
+
const { t } = props;
|
|
1239
|
+
const [pending, setPending] = (0, react.useState)("");
|
|
1240
|
+
const canAdd = !props.disabled && pending.trim().length > 0;
|
|
1241
|
+
const rowTitle = t("rootsRowTitle");
|
|
1242
|
+
const removeTitle = t("rootsRemoveTitle");
|
|
1243
|
+
const removeLabel = t("rootsRemove");
|
|
1244
|
+
const rows = props.roots.map((root, index) => {
|
|
1245
|
+
const rowAria = t("rootsAriaRow", { index: index + 1 });
|
|
1246
|
+
const rowInput = (0, react.createElement)("input", {
|
|
1247
|
+
type: "text",
|
|
1248
|
+
className: CLASS_IMPORT_PATH,
|
|
1249
|
+
value: root,
|
|
1250
|
+
placeholder: ROOT_PATH_PLACEHOLDER,
|
|
1251
|
+
disabled: props.disabled,
|
|
1252
|
+
"aria-label": rowAria,
|
|
1253
|
+
title: rowTitle,
|
|
1254
|
+
onChange: (event) => {
|
|
1255
|
+
props.onChangeRoot(index, event.target.value);
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
const rowButton = (0, react.createElement)("button", {
|
|
1259
|
+
type: "button",
|
|
1260
|
+
className: "dpic-del",
|
|
1261
|
+
disabled: props.disabled,
|
|
1262
|
+
title: removeTitle,
|
|
1263
|
+
onClick: () => {
|
|
1264
|
+
props.onDeleteRoot(index);
|
|
1265
|
+
}
|
|
1266
|
+
}, removeLabel);
|
|
1267
|
+
return (0, react.createElement)("div", {
|
|
1268
|
+
className: CLASS_ROW_HEAD,
|
|
1269
|
+
key: `allow-root-${String(index)}`
|
|
1270
|
+
}, rowInput, rowButton);
|
|
1271
|
+
});
|
|
1272
|
+
const addPlaceholder = t("rootsAddPlaceholder");
|
|
1273
|
+
const addAria = t("rootsAddAria");
|
|
1274
|
+
const addTitle = t("rootsAddTitle");
|
|
1275
|
+
const addLabel = t("rootsAdd");
|
|
1276
|
+
const addInput = (0, react.createElement)("input", {
|
|
1277
|
+
type: "text",
|
|
1278
|
+
className: CLASS_IMPORT_PATH,
|
|
1279
|
+
value: pending,
|
|
1280
|
+
placeholder: addPlaceholder,
|
|
1281
|
+
disabled: props.disabled,
|
|
1282
|
+
"aria-label": addAria,
|
|
1283
|
+
onChange: (event) => {
|
|
1284
|
+
setPending(event.target.value);
|
|
1285
|
+
},
|
|
1286
|
+
onKeyDown: (event) => {
|
|
1287
|
+
if (event.key === "Enter" && canAdd) {
|
|
1288
|
+
props.onAddRoot(pending.trim());
|
|
1289
|
+
setPending("");
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
});
|
|
1293
|
+
const addButton = (0, react.createElement)("button", {
|
|
1294
|
+
type: "button",
|
|
1295
|
+
className: "dpic-btn",
|
|
1296
|
+
disabled: !canAdd,
|
|
1297
|
+
title: addTitle,
|
|
1298
|
+
onClick: () => {
|
|
1299
|
+
props.onAddRoot(pending.trim());
|
|
1300
|
+
setPending("");
|
|
1301
|
+
}
|
|
1302
|
+
}, addLabel);
|
|
1303
|
+
const addRow = (0, react.createElement)("div", { className: CLASS_ROW_HEAD }, addInput, addButton);
|
|
1304
|
+
return (0, react.createElement)("li", {
|
|
1305
|
+
className: "dpic-importrow",
|
|
1306
|
+
"data-field": "allow-roots"
|
|
1307
|
+
}, (0, react.createElement)("div", { className: "dpic-hint" }, t("rootsHeading")), rows, addRow, (0, react.createElement)("div", { className: "dpic-hint" }, t("rootsHint")));
|
|
1308
|
+
}
|
|
1309
|
+
function CardFootBar(props) {
|
|
1310
|
+
const { foot, editable, anythingDirty, busy, confirmReset } = props;
|
|
1311
|
+
return (0, react.createElement)("li", { className: "dpic-foot" }, (0, react.createElement)("button", {
|
|
1312
|
+
type: "button",
|
|
1313
|
+
className: "dpic-btn",
|
|
1314
|
+
disabled: !editable,
|
|
1315
|
+
onClick: props.onAdd
|
|
1316
|
+
}, foot.add), (0, react.createElement)("button", {
|
|
1317
|
+
type: "button",
|
|
1318
|
+
className: "dpic-btn dpic-btn-primary",
|
|
1319
|
+
"data-field": "save",
|
|
1320
|
+
disabled: !editable || !anythingDirty || busy,
|
|
1321
|
+
title: anythingDirty ? foot.saveTitleDirty : foot.saveTitleClean,
|
|
1322
|
+
onClick: props.onSave
|
|
1323
|
+
}, busy ? foot.saving : foot.save), (0, react.createElement)("button", {
|
|
1324
|
+
type: "button",
|
|
1325
|
+
className: "dpic-btn",
|
|
1326
|
+
"data-field": "discard",
|
|
1327
|
+
disabled: !editable || !anythingDirty || busy,
|
|
1328
|
+
onClick: props.onDiscard
|
|
1329
|
+
}, foot.revert), (0, react.createElement)("button", {
|
|
1330
|
+
type: "button",
|
|
1331
|
+
className: "dpic-btn dpic-btn-danger",
|
|
1332
|
+
disabled: !editable,
|
|
1333
|
+
title: foot.resetTitle,
|
|
1334
|
+
onClick: props.onReset
|
|
1335
|
+
}, confirmReset ? foot.resetConfirm : foot.reset));
|
|
1336
|
+
}
|
|
1337
|
+
function cardFootLabels(t) {
|
|
1338
|
+
return {
|
|
1339
|
+
add: t("addTemplate"),
|
|
1340
|
+
save: t("save"),
|
|
1341
|
+
saving: t("saving"),
|
|
1342
|
+
revert: t("revert"),
|
|
1343
|
+
reset: t("resetDefault"),
|
|
1344
|
+
resetConfirm: t("resetConfirm"),
|
|
1345
|
+
saveTitleDirty: t("saveTitleDirty"),
|
|
1346
|
+
saveTitleClean: t("saveTitleClean"),
|
|
1347
|
+
resetTitle: t("resetTitle")
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
function cardStatusHint(snap, t) {
|
|
1351
|
+
let hint;
|
|
1352
|
+
if (snap.ready) hint = snap.writable ? "" : t("statusReadOnly");
|
|
1353
|
+
else hint = t("statusNotReady");
|
|
1354
|
+
return hint;
|
|
1355
|
+
}
|
|
1356
|
+
function createCardHeader(view) {
|
|
1357
|
+
const { t, open, setOpen } = view;
|
|
1358
|
+
const headTitle = (0, react.createElement)("div", { className: "dpic-title" }, t("cardTitle"));
|
|
1359
|
+
const headDesc = (0, react.createElement)("div", { className: "dpic-desc" }, t("cardDescription"));
|
|
1360
|
+
const headBlock = (0, react.createElement)("div", { className: "dpic-head" }, headTitle, headDesc);
|
|
1361
|
+
const chevronPath = (0, react.createElement)("path", svgPathProps("M3 5l4 4 4-4", true));
|
|
1362
|
+
const chevron = (0, react.createElement)("svg", {
|
|
1363
|
+
width: 14,
|
|
1364
|
+
height: 14,
|
|
1365
|
+
viewBox: "0 0 14 14",
|
|
1366
|
+
"aria-hidden": true,
|
|
1367
|
+
className: `dpic-chevron${open ? " dpic-chevron-open" : ""}`
|
|
1368
|
+
}, chevronPath);
|
|
1369
|
+
return (0, react.createElement)("button", {
|
|
1370
|
+
type: "button",
|
|
1371
|
+
className: "dpic-header",
|
|
1372
|
+
"aria-expanded": open,
|
|
1373
|
+
onClick: () => {
|
|
1374
|
+
setOpen((prev) => !prev);
|
|
1375
|
+
}
|
|
1376
|
+
}, headBlock, chevron);
|
|
1377
|
+
}
|
|
1378
|
+
function createDraftActions(t, draft, rootsDraft, setDraft, setRootsDraft) {
|
|
1379
|
+
function onCommit(id, fields) {
|
|
1380
|
+
setDraft(draft.map((tpl) => tpl.id === id ? {
|
|
1381
|
+
...tpl,
|
|
1382
|
+
...fields
|
|
1383
|
+
} : tpl));
|
|
1384
|
+
}
|
|
1385
|
+
function onDelete(id) {
|
|
1386
|
+
setDraft(draft.filter((tpl) => tpl.id !== id));
|
|
1387
|
+
}
|
|
1388
|
+
function onAdd() {
|
|
1389
|
+
setDraft([...draft, {
|
|
1390
|
+
id: newTemplateId(),
|
|
1391
|
+
name: t("newTemplateName", { index: draft.length + 1 }),
|
|
1392
|
+
description: "",
|
|
1393
|
+
text: t("newTemplateText"),
|
|
1394
|
+
group: "",
|
|
1395
|
+
emoji: ""
|
|
1396
|
+
}]);
|
|
1397
|
+
}
|
|
1398
|
+
function onImported(incoming) {
|
|
1399
|
+
setDraft(mergeImportedTemplates(draft, incoming));
|
|
1400
|
+
}
|
|
1401
|
+
function onRootChange(index, value) {
|
|
1402
|
+
setRootsDraft(rootsDraft.map((root, idx) => idx === index ? value : root));
|
|
1403
|
+
}
|
|
1404
|
+
function onRootDelete(index) {
|
|
1405
|
+
setRootsDraft(rootsDraft.filter((_root, idx) => idx !== index));
|
|
1406
|
+
}
|
|
1407
|
+
function onRootAdd(value) {
|
|
1408
|
+
setRootsDraft([...rootsDraft, value]);
|
|
1409
|
+
}
|
|
1410
|
+
return {
|
|
1411
|
+
onCommit,
|
|
1412
|
+
onDelete,
|
|
1413
|
+
onAdd,
|
|
1414
|
+
onImported,
|
|
1415
|
+
onRootChange,
|
|
1416
|
+
onRootDelete,
|
|
1417
|
+
onRootAdd
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
function verifyTemplatesPersisted(t, persisted, expected, action, opts) {
|
|
1421
|
+
const problem = persistError(t, persisted, expected, t(action), opts);
|
|
1422
|
+
if (problem !== void 0) throw new Error(problem);
|
|
1423
|
+
}
|
|
1424
|
+
function verifyRootsPersisted(t, persisted, expected) {
|
|
1425
|
+
const problem = rootsPersistError(t, persisted, expected, t("save"));
|
|
1426
|
+
if (problem !== void 0) throw new Error(problem);
|
|
1427
|
+
}
|
|
1428
|
+
function createPersistActions(args) {
|
|
1429
|
+
const { t, editable, dirty, rootsDirty, anythingDirty, confirmReset, templates, allowRoots, draft, rootsDraft, set, unset, readBack, setDraft, setDraftFor, setRootsDraft, setBusy, setSaveError, setConfirmReset } = args;
|
|
1430
|
+
function reportError(err) {
|
|
1431
|
+
console.error("[dir-prep-organize] templates settings write failed:", err);
|
|
1432
|
+
setSaveError(errorText(err));
|
|
1433
|
+
}
|
|
1434
|
+
async function onSave() {
|
|
1435
|
+
if (!editable || !anythingDirty) return;
|
|
1436
|
+
setBusy(true);
|
|
1437
|
+
setSaveError("");
|
|
1438
|
+
const next = sanitizeTemplateList(draft);
|
|
1439
|
+
const nextRoots = sanitizeAllowRoots(rootsDraft);
|
|
1440
|
+
try {
|
|
1441
|
+
if (dirty) {
|
|
1442
|
+
await set("templates", next);
|
|
1443
|
+
verifyTemplatesPersisted(t, readBack(), next, "save");
|
|
1444
|
+
}
|
|
1445
|
+
if (rootsDirty) {
|
|
1446
|
+
await set("importAllowRoots", nextRoots);
|
|
1447
|
+
verifyRootsPersisted(t, readBack(), nextRoots);
|
|
1448
|
+
}
|
|
1449
|
+
setBusy(false);
|
|
1450
|
+
setDraft(next);
|
|
1451
|
+
setRootsDraft(nextRoots);
|
|
1452
|
+
} catch (error) {
|
|
1453
|
+
setBusy(false);
|
|
1454
|
+
reportError(error);
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
function onDiscard() {
|
|
1458
|
+
setDraft(templates);
|
|
1459
|
+
setRootsDraft(allowRoots);
|
|
1460
|
+
setSaveError("");
|
|
1461
|
+
}
|
|
1462
|
+
function onReset() {
|
|
1463
|
+
if (!confirmReset) {
|
|
1464
|
+
setConfirmReset(true);
|
|
1465
|
+
return;
|
|
1466
|
+
}
|
|
1467
|
+
setConfirmReset(false);
|
|
1468
|
+
(async () => {
|
|
1469
|
+
try {
|
|
1470
|
+
const builtin = await loadBuiltinTemplates();
|
|
1471
|
+
if (builtin.phase !== "ready") throw new Error(builtin.error);
|
|
1472
|
+
await unset("templates");
|
|
1473
|
+
verifyTemplatesPersisted(t, readBack(), builtin.list, "resetDefault", { treatEmptyAsReverted: true });
|
|
1474
|
+
setSaveError("");
|
|
1475
|
+
setDraft(builtin.list);
|
|
1476
|
+
setDraftFor(builtin.list);
|
|
1477
|
+
setRootsDraft(allowRoots);
|
|
1478
|
+
} catch (error) {
|
|
1479
|
+
reportError(error);
|
|
1480
|
+
}
|
|
1481
|
+
})();
|
|
1482
|
+
}
|
|
1483
|
+
return {
|
|
1484
|
+
onSave,
|
|
1485
|
+
onDiscard,
|
|
1486
|
+
onReset
|
|
1487
|
+
};
|
|
1488
|
+
}
|
|
1489
|
+
/** 展开态正文(状态行 + 模板行表 + 卡底动作条 + 导入面 + 允许目录面 + 底部提示)。 */
|
|
1490
|
+
function createCardBody(view) {
|
|
1491
|
+
const { t, statusHint, draft, rootsDraft, foot, editable, anythingDirty, busy, confirmReset, saveError } = view;
|
|
1492
|
+
const { onCommit, onDelete, onAdd, onImported, onRootChange, onRootDelete, onRootAdd } = view.draftActions;
|
|
1493
|
+
const { onSave, onDiscard, onReset } = view.persistActions;
|
|
1494
|
+
return (0, react.createElement)("ul", { className: "dpic-body" }, statusHint === "" ? null : (0, react.createElement)("li", { className: "dpic-hint" }, statusHint), draft.map((tpl, idx) => (0, react.createElement)(TemplateRow, {
|
|
1495
|
+
key: tpl.id,
|
|
1496
|
+
t,
|
|
1497
|
+
index: idx,
|
|
1498
|
+
template: tpl,
|
|
1499
|
+
disabled: !editable,
|
|
1500
|
+
onCommit,
|
|
1501
|
+
onDelete
|
|
1502
|
+
})), (0, react.createElement)(CardFootBar, {
|
|
1503
|
+
foot,
|
|
1504
|
+
editable,
|
|
1505
|
+
anythingDirty,
|
|
1506
|
+
busy,
|
|
1507
|
+
confirmReset,
|
|
1508
|
+
onAdd,
|
|
1509
|
+
onSave,
|
|
1510
|
+
onDiscard,
|
|
1511
|
+
onReset
|
|
1512
|
+
}), (0, react.createElement)(ImportPanel, {
|
|
1513
|
+
t,
|
|
1514
|
+
editable,
|
|
1515
|
+
onImported
|
|
1516
|
+
}), (0, react.createElement)(AllowRootsPanel, {
|
|
1517
|
+
t,
|
|
1518
|
+
roots: rootsDraft,
|
|
1519
|
+
disabled: !editable,
|
|
1520
|
+
onChangeRoot: onRootChange,
|
|
1521
|
+
onDeleteRoot: onRootDelete,
|
|
1522
|
+
onAddRoot: onRootAdd
|
|
1523
|
+
}), (0, react.createElement)("li", { className: "dpic-hint" }, t("footHint")), saveError === "" ? null : (0, react.createElement)("li", { className: "dpic-hint dpic-err" }, `${t("saveFailed")}${saveError}`));
|
|
1524
|
+
}
|
|
1525
|
+
function TemplatesCard(props) {
|
|
1526
|
+
const { t } = props;
|
|
1527
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
1528
|
+
const [confirmReset, setConfirmReset] = (0, react.useState)(false);
|
|
1529
|
+
const [saveError, setSaveError] = (0, react.useState)("");
|
|
1530
|
+
const [busy, setBusy] = (0, react.useState)(false);
|
|
1531
|
+
const foot = cardFootLabels(t);
|
|
1532
|
+
const snap = props.useCard((state) => state);
|
|
1533
|
+
const { templates } = snap;
|
|
1534
|
+
const editable = snap.ready && snap.writable;
|
|
1535
|
+
const statusHint = cardStatusHint(snap, t);
|
|
1536
|
+
(0, react.useEffect)(() => {
|
|
1537
|
+
if (!snap.fromSettings) loadBuiltinTemplates();
|
|
1538
|
+
}, [snap.fromSettings]);
|
|
1539
|
+
const [draft, setDraft] = (0, react.useState)(templates);
|
|
1540
|
+
const [draftFor, setDraftFor] = (0, react.useState)(templates);
|
|
1541
|
+
(0, react.useEffect)(() => {
|
|
1542
|
+
if (draftFor !== templates) {
|
|
1543
|
+
setDraftFor(templates);
|
|
1544
|
+
setDraft((prev) => JSON.stringify(prev) === JSON.stringify(draftFor) ? templates : prev);
|
|
1545
|
+
}
|
|
1546
|
+
}, [templates, draftFor]);
|
|
1547
|
+
(0, react.useEffect)(() => {
|
|
1548
|
+
let timer;
|
|
1549
|
+
if (confirmReset) timer = setTimeout(() => {
|
|
1550
|
+
setConfirmReset(false);
|
|
1551
|
+
}, RESET_CONFIRM_MS);
|
|
1552
|
+
return () => {
|
|
1553
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
1554
|
+
};
|
|
1555
|
+
}, [confirmReset]);
|
|
1556
|
+
const [rootsDraft, setRootsDraft] = (0, react.useState)(snap.allowRoots);
|
|
1557
|
+
const [rootsFor, setRootsFor] = (0, react.useState)(snap.allowRoots);
|
|
1558
|
+
(0, react.useEffect)(() => {
|
|
1559
|
+
if (rootsFor !== snap.allowRoots) {
|
|
1560
|
+
setRootsFor(snap.allowRoots);
|
|
1561
|
+
setRootsDraft((prev) => JSON.stringify(prev) === JSON.stringify(rootsFor) ? snap.allowRoots : prev);
|
|
1562
|
+
}
|
|
1563
|
+
}, [rootsFor, snap.allowRoots]);
|
|
1564
|
+
const dirty = JSON.stringify(draft) !== JSON.stringify(templates);
|
|
1565
|
+
const rootsDirty = JSON.stringify(sanitizeAllowRoots(rootsDraft)) !== JSON.stringify(snap.allowRoots);
|
|
1566
|
+
const anythingDirty = dirty || rootsDirty;
|
|
1567
|
+
const draftActions = createDraftActions(t, draft, rootsDraft, setDraft, setRootsDraft);
|
|
1568
|
+
const persistActions = createPersistActions({
|
|
1569
|
+
t,
|
|
1570
|
+
editable,
|
|
1571
|
+
dirty,
|
|
1572
|
+
rootsDirty,
|
|
1573
|
+
anythingDirty,
|
|
1574
|
+
confirmReset,
|
|
1575
|
+
templates,
|
|
1576
|
+
allowRoots: snap.allowRoots,
|
|
1577
|
+
draft,
|
|
1578
|
+
rootsDraft,
|
|
1579
|
+
set: props.set,
|
|
1580
|
+
unset: props.unset,
|
|
1581
|
+
readBack: props.readBack,
|
|
1582
|
+
setDraft,
|
|
1583
|
+
setDraftFor,
|
|
1584
|
+
setRootsDraft,
|
|
1585
|
+
setBusy,
|
|
1586
|
+
setSaveError,
|
|
1587
|
+
setConfirmReset
|
|
1588
|
+
});
|
|
1589
|
+
const headerBtn = createCardHeader({
|
|
1590
|
+
t,
|
|
1591
|
+
open,
|
|
1592
|
+
setOpen
|
|
1593
|
+
});
|
|
1594
|
+
const bodyList = open ? createCardBody({
|
|
1595
|
+
t,
|
|
1596
|
+
statusHint,
|
|
1597
|
+
draft,
|
|
1598
|
+
rootsDraft,
|
|
1599
|
+
foot,
|
|
1600
|
+
editable,
|
|
1601
|
+
anythingDirty,
|
|
1602
|
+
busy,
|
|
1603
|
+
confirmReset,
|
|
1604
|
+
saveError,
|
|
1605
|
+
draftActions,
|
|
1606
|
+
persistActions
|
|
1607
|
+
}) : null;
|
|
1608
|
+
return (0, react.createElement)("li", { className: `dpic-card${open ? " dpic-card-open" : ""}` }, headerBtn, bodyList);
|
|
1609
|
+
}
|
|
1610
|
+
const inject = [
|
|
1611
|
+
"slots",
|
|
1612
|
+
"configForms",
|
|
1613
|
+
"locale"
|
|
1614
|
+
];
|
|
1615
|
+
function apply(ctx) {
|
|
1616
|
+
ctx.effect(() => {
|
|
1617
|
+
const tag = document.createElement("style");
|
|
1618
|
+
tag.id = "dir-prep-organize-css";
|
|
1619
|
+
tag.textContent = CSS;
|
|
1620
|
+
document.head.append(tag);
|
|
1621
|
+
return () => {
|
|
1622
|
+
tag.remove();
|
|
1623
|
+
};
|
|
1624
|
+
}, "dir-prep-organize: styles");
|
|
1625
|
+
const scope = ctx.configForms.get(NS);
|
|
1626
|
+
const store = templatesStore(scope);
|
|
1627
|
+
const OrganizeButton = createOrganizeButton();
|
|
1628
|
+
const TemplateButton = createTemplateButton();
|
|
1629
|
+
ctx.effect(() => ctx.locale.register(NS, UI_MESSAGES), "dir-prep-organize-card: locale dictionaries");
|
|
1630
|
+
const t = ctx.locale.bind(NS);
|
|
1631
|
+
const dockInject = () => ({ hooks: { card: store } });
|
|
1632
|
+
ctx.slots.inject(SLOT_INPUT_RIGHT, () => {
|
|
1633
|
+
const unregisterOrganize = ctx.slots.register({
|
|
1634
|
+
name: SLOT_INPUT_RIGHT,
|
|
1635
|
+
id: NS,
|
|
1636
|
+
order: 99,
|
|
1637
|
+
label: () => t("dockOrganizeEntry"),
|
|
1638
|
+
locale: NS,
|
|
1639
|
+
inject: dockInject
|
|
1640
|
+
}, OrganizeButton);
|
|
1641
|
+
const unregisterTemplates = ctx.slots.register({
|
|
1642
|
+
name: SLOT_INPUT_RIGHT,
|
|
1643
|
+
id: `${NS}-templates`,
|
|
1644
|
+
order: 100,
|
|
1645
|
+
label: () => t("dockTemplatesEntry"),
|
|
1646
|
+
locale: NS,
|
|
1647
|
+
inject: dockInject
|
|
1648
|
+
}, TemplateButton);
|
|
1649
|
+
return () => {
|
|
1650
|
+
unregisterOrganize();
|
|
1651
|
+
unregisterTemplates();
|
|
1652
|
+
};
|
|
1653
|
+
});
|
|
1654
|
+
ctx.slots.inject("plugins.bundle.config", () => {
|
|
1655
|
+
return ctx.slots.register({
|
|
1656
|
+
name: "plugins.bundle.config",
|
|
1657
|
+
key: BUNDLE_PKG,
|
|
1658
|
+
inject: () => ({
|
|
1659
|
+
t,
|
|
1660
|
+
hooks: { card: store },
|
|
1661
|
+
set: (field, value) => scope.set(field, value),
|
|
1662
|
+
unset: (field) => scope.unset(field),
|
|
1663
|
+
readBack: () => store.readBack()
|
|
1664
|
+
})
|
|
1665
|
+
}, TemplatesCard);
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
//#endregion
|
|
1669
|
+
exports.apply = apply;
|
|
1670
|
+
exports.applyTemplateToDraft = applyTemplateToDraft;
|
|
1671
|
+
exports.builtinTemplatesSnapshot = builtinTemplatesSnapshot;
|
|
1672
|
+
exports.formatContextSummary = formatContextSummary;
|
|
1673
|
+
exports.formatImportSkips = formatImportSkips;
|
|
1674
|
+
exports.inject = inject;
|
|
1675
|
+
exports.loadBuiltinTemplates = loadBuiltinTemplates;
|
|
1676
|
+
exports.persistError = persistError;
|
|
1677
|
+
exports.rawOrganizeTimeoutMsOf = rawOrganizeTimeoutMsOf;
|
|
1678
|
+
exports.resetBuiltinTemplates = resetBuiltinTemplates;
|
|
1679
|
+
exports.rootsPersistError = rootsPersistError;
|
|
1680
|
+
exports.subscribeBuiltinTemplates = subscribeBuiltinTemplates;
|
|
1681
|
+
return module.exports;
|
|
1682
|
+
},
|
|
1683
|
+
});
|