hostlet 0.0.0-stage → 0.1.0-alpha.1
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 +233 -2
- package/bin/hostlet.js +61 -0
- package/console/app/api.js +1223 -0
- package/console/app/boot.js +165 -0
- package/console/app/cards.js +222 -0
- package/console/app/compose-quote.js +127 -0
- package/console/app/config-form.js +727 -0
- package/console/app/document-drafts.js +62 -0
- package/console/app/document-tools.mjs +67 -0
- package/console/app/documents.js +106 -0
- package/console/app/pages.js +6483 -0
- package/console/app/plugins.js +509 -0
- package/console/app/preview-tools.js +172 -0
- package/console/app/reference-labels.js +118 -0
- package/console/app/selection.js +372 -0
- package/console/app/store.js +57 -0
- package/console/app/text-anchor.js +26 -0
- package/console/app/topic-local.js +322 -0
- package/console/app/topic-nav.js +414 -0
- package/console/app/topic-status.js +109 -0
- package/console/app/views.js +43 -0
- package/console/apple-touch-icon.png +0 -0
- package/console/avatars/agy.svg +34 -0
- package/console/avatars/alhena.svg +36 -0
- package/console/avatars/castor.svg +38 -0
- package/console/avatars/claude.svg +34 -0
- package/console/avatars/codex.svg +34 -0
- package/console/avatars/devin.svg +34 -0
- package/console/avatars/echo.svg +34 -0
- package/console/avatars/kimi.svg +33 -0
- package/console/avatars/opencode.svg +33 -0
- package/console/avatars/pinion.svg +34 -0
- package/console/avatars/sprocket.svg +34 -0
- package/console/avatars/vela.svg +44 -0
- package/console/avatars/wasat.svg +38 -0
- package/console/clients/agy.svg +1 -0
- package/console/clients/claude.svg +1 -0
- package/console/clients/codex.svg +1 -0
- package/console/clients/devin.svg +1 -0
- package/console/clients/kimi.svg +1 -0
- package/console/clients/opencode.svg +1 -0
- package/console/favicon.ico +0 -0
- package/console/favicon.svg +16 -0
- package/console/index.html +99 -0
- package/console/pdl/engine/README.md +13 -0
- package/console/pdl/engine/anchor.js +195 -0
- package/console/pdl/engine/core.js +1340 -0
- package/console/pdl/engine/frame.js +1252 -0
- package/console/pdl/engine/i18n.js +67 -0
- package/console/pdl/engine/pdl-check.js +102 -0
- package/console/pdl/engine/pdl-doc.js +353 -0
- package/console/pdl/engine/pdl-view.js +280 -0
- package/console/pdl/engine/pdl.js +1064 -0
- package/console/pdl/engine/platform.js +18 -0
- package/console/pdl/engine/proj.js +279 -0
- package/console/pdl/engine/theme.js +176 -0
- package/console/pdl/engine/tree.js +171 -0
- package/console/pdl/engine/units.js +546 -0
- package/console/pdl/library/README.md +28 -0
- package/console/pdl/library/blocks.js +1512 -0
- package/console/pdl/library/buttons.js +86 -0
- package/console/pdl/library/capsules.js +130 -0
- package/console/pdl/library/charts.js +287 -0
- package/console/pdl/library/code.js +98 -0
- package/console/pdl/library/css/base.css +12 -0
- package/console/pdl/library/css/blocks.css +98 -0
- package/console/pdl/library/css/capsules.css +42 -0
- package/console/pdl/library/css/catalog-page.css +24 -0
- package/console/pdl/library/css/chat.css +100 -0
- package/console/pdl/library/css/composer-top.css +145 -0
- package/console/pdl/library/css/controls.css +195 -0
- package/console/pdl/library/css/drag.css +29 -0
- package/console/pdl/library/css/edit-layout.css +93 -0
- package/console/pdl/library/css/floating-window.css +30 -0
- package/console/pdl/library/css/hover.css +50 -0
- package/console/pdl/library/css/label-search.css +37 -0
- package/console/pdl/library/css/layers.css +43 -0
- package/console/pdl/library/css/library-parts.css +33 -0
- package/console/pdl/library/css/library.css +117 -0
- package/console/pdl/library/css/member-select.css +34 -0
- package/console/pdl/library/css/message.css +72 -0
- package/console/pdl/library/css/page.css +104 -0
- package/console/pdl/library/css/parts.css +338 -0
- package/console/pdl/library/css/responsive.css +40 -0
- package/console/pdl/library/css/roles.css +28 -0
- package/console/pdl/library/css/rows.css +231 -0
- package/console/pdl/library/css/settings-rows.css +37 -0
- package/console/pdl/library/css/shell.css +59 -0
- package/console/pdl/library/css/stream.css +296 -0
- package/console/pdl/library/css/theme-calculator.css +18 -0
- package/console/pdl/library/css/thumb-choice.css +69 -0
- package/console/pdl/library/css/tweaks.css +16 -0
- package/console/pdl/library/css/widgets.css +211 -0
- package/console/pdl/library/css/workbench.css +59 -0
- package/console/pdl/library/feedback.js +83 -0
- package/console/pdl/library/floating-window.mjs +100 -0
- package/console/pdl/library/fold.js +238 -0
- package/console/pdl/library/format.js +53 -0
- package/console/pdl/library/frames.js +123 -0
- package/console/pdl/library/icons.js +165 -0
- package/console/pdl/library/identity.js +149 -0
- package/console/pdl/library/inputs.js +801 -0
- package/console/pdl/library/label-search.js +214 -0
- package/console/pdl/library/markdown-text.js +115 -0
- package/console/pdl/library/markdown.js +150 -0
- package/console/pdl/library/media-viewer.js +293 -0
- package/console/pdl/library/member-select.mjs +32 -0
- package/console/pdl/library/message.js +105 -0
- package/console/pdl/library/motion.js +56 -0
- package/console/pdl/library/overlays.js +165 -0
- package/console/pdl/library/page.js +142 -0
- package/console/pdl/library/plugin-form.js +154 -0
- package/console/pdl/library/registry.js +198 -0
- package/console/pdl/library/rows.js +523 -0
- package/console/pdl/library/shell.js +151 -0
- package/console/pdl/library/stream.js +58 -0
- package/console/pdl/library/tabs.js +259 -0
- package/console/pdl/library/theme-calculator.js +300 -0
- package/console/pdl/library/widgets.js +114 -0
- package/console/pdl/load-order.json +74 -0
- package/console/pdl/platform/README.md +3 -0
- package/console/pdl/platform/rich-markdown.mjs +17 -0
- package/console/pdl/platform/web-links.js +26 -0
- package/console/pdl/platform/web.js +80 -0
- package/console/sdk-browser/mentions.d.mts +16 -0
- package/console/sdk-browser/mentions.mjs +84 -0
- package/console/theme/assets.js +21 -0
- package/console/theme/theme.json +9417 -0
- package/console/theme/tokens.json +444 -0
- package/dist/core/a2a.d.ts +288 -0
- package/dist/core/a2a.js +2197 -0
- package/dist/core/address.d.ts +34 -0
- package/dist/core/address.js +33 -0
- package/dist/core/approval-inputs.d.ts +17 -0
- package/dist/core/approval-inputs.js +70 -0
- package/dist/core/archive.d.ts +19 -0
- package/dist/core/archive.js +135 -0
- package/dist/core/attachments.d.ts +17 -0
- package/dist/core/attachments.js +143 -0
- package/dist/core/blocked-handoffs.d.ts +132 -0
- package/dist/core/blocked-handoffs.js +349 -0
- package/dist/core/config-schema.d.ts +124 -0
- package/dist/core/config-schema.js +192 -0
- package/dist/core/config.d.ts +117 -0
- package/dist/core/config.js +638 -0
- package/dist/core/disk-usage.d.ts +26 -0
- package/dist/core/disk-usage.js +83 -0
- package/dist/core/documents.d.ts +9 -0
- package/dist/core/documents.js +48 -0
- package/dist/core/entry.d.ts +316 -0
- package/dist/core/entry.js +711 -0
- package/dist/core/home.d.ts +76 -0
- package/dist/core/home.js +449 -0
- package/dist/core/i18n.d.ts +36 -0
- package/dist/core/i18n.js +458 -0
- package/dist/core/instances.d.ts +224 -0
- package/dist/core/instances.js +1272 -0
- package/dist/core/members.d.ts +190 -0
- package/dist/core/members.js +358 -0
- package/dist/core/mentions.d.ts +12 -0
- package/dist/core/mentions.js +49 -0
- package/dist/core/messages.d.ts +876 -0
- package/dist/core/messages.js +916 -0
- package/dist/core/notices.d.ts +88 -0
- package/dist/core/notices.js +54 -0
- package/dist/core/ops.d.ts +117 -0
- package/dist/core/ops.js +146 -0
- package/dist/core/package.d.ts +2 -0
- package/dist/core/package.js +14 -0
- package/dist/core/parts.d.ts +25 -0
- package/dist/core/parts.js +119 -0
- package/dist/core/plugins/catalog.d.ts +14 -0
- package/dist/core/plugins/catalog.js +54 -0
- package/dist/core/plugins/external.d.ts +7 -0
- package/dist/core/plugins/external.js +921 -0
- package/dist/core/plugins/index.d.ts +5 -0
- package/dist/core/plugins/index.js +51 -0
- package/dist/core/plugins/npm.d.ts +12 -0
- package/dist/core/plugins/npm.js +99 -0
- package/dist/core/plugins/plugin-manifest.d.ts +12 -0
- package/dist/core/plugins/plugin-manifest.js +231 -0
- package/dist/core/push.d.ts +22 -0
- package/dist/core/push.js +63 -0
- package/dist/core/resource.d.ts +77 -0
- package/dist/core/resource.js +48 -0
- package/dist/core/spawn.d.ts +12 -0
- package/dist/core/spawn.js +30 -0
- package/dist/core/storage-inventory.d.ts +118 -0
- package/dist/core/storage-inventory.js +279 -0
- package/dist/core/storage.d.ts +45 -0
- package/dist/core/storage.js +602 -0
- package/dist/core/store.d.ts +15 -0
- package/dist/core/store.js +33 -0
- package/dist/core/topic-index.d.ts +19 -0
- package/dist/core/topic-index.js +70 -0
- package/dist/core/topic-ops.d.ts +139 -0
- package/dist/core/topic-ops.js +507 -0
- package/dist/core/topic-status.d.ts +32 -0
- package/dist/core/topic-status.js +105 -0
- package/dist/core/topics.d.ts +327 -0
- package/dist/core/topics.js +786 -0
- package/dist/core/turn-clients.d.ts +1 -0
- package/dist/core/turn-clients.js +5 -0
- package/dist/core/types.d.ts +2866 -0
- package/dist/core/types.js +166 -0
- package/dist/core/util.d.ts +10 -0
- package/dist/core/util.js +47 -0
- package/dist/main.d.ts +12 -0
- package/dist/main.js +82 -0
- package/dist/plugins/adapter-acp/index.d.ts +3 -0
- package/dist/plugins/adapter-acp/index.js +57 -0
- package/dist/plugins/adapter-acp/plugin.yaml +100 -0
- package/dist/plugins/adapter-agy/command.d.ts +9 -0
- package/dist/plugins/adapter-agy/command.js +34 -0
- package/dist/plugins/adapter-agy/index.d.ts +5 -0
- package/dist/plugins/adapter-agy/index.js +65 -0
- package/dist/plugins/adapter-agy/quota.d.ts +2 -0
- package/dist/plugins/adapter-agy/quota.js +155 -0
- package/dist/plugins/adapter-agy/terminal.d.ts +6 -0
- package/dist/plugins/adapter-agy/terminal.js +132 -0
- package/dist/plugins/adapter-agy/version.d.ts +9 -0
- package/dist/plugins/adapter-agy/version.js +17 -0
- package/dist/plugins/adapter-claude/index.d.ts +43 -0
- package/dist/plugins/adapter-claude/index.js +412 -0
- package/dist/plugins/adapter-claude/quota.d.ts +14 -0
- package/dist/plugins/adapter-claude/quota.js +103 -0
- package/dist/plugins/adapter-codex/index.d.ts +4 -0
- package/dist/plugins/adapter-codex/index.js +688 -0
- package/dist/plugins/adapter-codex/responses-model.d.ts +9 -0
- package/dist/plugins/adapter-codex/responses-model.js +82 -0
- package/dist/plugins/adapter-kimi/index.d.ts +4 -0
- package/dist/plugins/adapter-kimi/index.js +51 -0
- package/dist/plugins/adapter-kimi/quota.d.ts +3 -0
- package/dist/plugins/adapter-kimi/quota.js +171 -0
- package/dist/plugins/adapter-opencode/index.d.ts +12 -0
- package/dist/plugins/adapter-opencode/index.js +64 -0
- package/dist/plugins/annotations/console/cards.css +189 -0
- package/dist/plugins/annotations/console/cards.mjs +439 -0
- package/dist/plugins/annotations/console/pdl.json +52 -0
- package/dist/plugins/annotations/console/view.mjs +241 -0
- package/dist/plugins/annotations/console/window.mjs +219 -0
- package/dist/plugins/annotations/followups.d.ts +51 -0
- package/dist/plugins/annotations/followups.js +112 -0
- package/dist/plugins/annotations/index.d.ts +3 -0
- package/dist/plugins/annotations/index.js +298 -0
- package/dist/plugins/annotations/plugin.yaml +3 -0
- package/dist/plugins/ask-choice/index.d.ts +9 -0
- package/dist/plugins/ask-choice/index.js +24 -0
- package/dist/plugins/ask-choice/plugin.yaml +2 -0
- package/dist/plugins/background/index.d.ts +2 -0
- package/dist/plugins/background/index.js +398 -0
- package/dist/plugins/background/plugin.yaml +7 -0
- package/dist/plugins/builtin.json +37 -0
- package/dist/plugins/cards/console/pdl.json +516 -0
- package/dist/plugins/cards/console/view.mjs +67 -0
- package/dist/plugins/cards/index.d.ts +8 -0
- package/dist/plugins/cards/index.js +627 -0
- package/dist/plugins/cards/plugin.yaml +3 -0
- package/dist/plugins/console/browser.d.ts +2 -0
- package/dist/plugins/console/browser.js +115 -0
- package/dist/plugins/console/console/pdl.json +38 -0
- package/dist/plugins/console/console/view.mjs +26 -0
- package/dist/plugins/console/index.d.ts +4 -0
- package/dist/plugins/console/index.js +94 -0
- package/dist/plugins/console/picker.d.ts +2 -0
- package/dist/plugins/console/picker.js +48 -0
- package/dist/plugins/console/plugin.yaml +3 -0
- package/dist/plugins/console/topic-view.d.ts +3 -0
- package/dist/plugins/console/topic-view.js +388 -0
- package/dist/plugins/handoff/index.d.ts +2 -0
- package/dist/plugins/handoff/index.js +147 -0
- package/dist/plugins/handoff/plugin.yaml +8 -0
- package/dist/plugins/host-api/index.d.ts +7 -0
- package/dist/plugins/host-api/index.js +310 -0
- package/dist/plugins/host-api/plugin.yaml +2 -0
- package/dist/plugins/host-api/signing.d.ts +63 -0
- package/dist/plugins/host-api/signing.js +427 -0
- package/dist/plugins/host-api/skills/host-ops/SKILL.md +28 -0
- package/dist/plugins/host-api/skills/hostlet-plugin-dev/SKILL.md +38 -0
- package/dist/plugins/inbox/index.d.ts +15 -0
- package/dist/plugins/inbox/index.js +161 -0
- package/dist/plugins/inbox/plugin.yaml +2 -0
- package/dist/plugins/keys/account-directories.d.ts +18 -0
- package/dist/plugins/keys/account-directories.js +86 -0
- package/dist/plugins/keys/account-storage.d.ts +18 -0
- package/dist/plugins/keys/account-storage.js +112 -0
- package/dist/plugins/keys/console/pdl.json +710 -0
- package/dist/plugins/keys/console/view.mjs +619 -0
- package/dist/plugins/keys/index.d.ts +7 -0
- package/dist/plugins/keys/index.js +842 -0
- package/dist/plugins/keys/login-link.d.ts +2 -0
- package/dist/plugins/keys/login-link.js +15 -0
- package/dist/plugins/keys/plugin.yaml +3 -0
- package/dist/plugins/keys/quota-history.d.ts +91 -0
- package/dist/plugins/keys/quota-history.js +420 -0
- package/dist/plugins/mcp/console/pdl.json +412 -0
- package/dist/plugins/mcp/console/view.mjs +207 -0
- package/dist/plugins/mcp/index.d.ts +7 -0
- package/dist/plugins/mcp/index.js +494 -0
- package/dist/plugins/mcp/plugin.yaml +3 -0
- package/dist/plugins/member-health/index.d.ts +2 -0
- package/dist/plugins/member-health/index.js +478 -0
- package/dist/plugins/member-health/plugin.yaml +2 -0
- package/dist/plugins/memory/capabilities.d.ts +10 -0
- package/dist/plugins/memory/capabilities.js +70 -0
- package/dist/plugins/memory/console/pdl.json +459 -0
- package/dist/plugins/memory/console/view.mjs +254 -0
- package/dist/plugins/memory/corpus.d.ts +60 -0
- package/dist/plugins/memory/corpus.js +521 -0
- package/dist/plugins/memory/engines/fts-tree-diversity.d.ts +8 -0
- package/dist/plugins/memory/engines/fts-tree-diversity.js +49 -0
- package/dist/plugins/memory/engines/fts-tree-text.d.ts +12 -0
- package/dist/plugins/memory/engines/fts-tree-text.js +93 -0
- package/dist/plugins/memory/engines/fts-tree.d.ts +4 -0
- package/dist/plugins/memory/engines/fts-tree.js +387 -0
- package/dist/plugins/memory/engines/search.d.ts +9 -0
- package/dist/plugins/memory/engines/search.js +35 -0
- package/dist/plugins/memory/index.d.ts +3 -0
- package/dist/plugins/memory/index.js +465 -0
- package/dist/plugins/memory/notes.d.ts +22 -0
- package/dist/plugins/memory/notes.js +140 -0
- package/dist/plugins/memory/plugin.yaml +23 -0
- package/dist/plugins/model-profiles/index.d.ts +2 -0
- package/dist/plugins/model-profiles/index.js +916 -0
- package/dist/plugins/model-profiles/plugin.yaml +13 -0
- package/dist/plugins/model-profiles/review-source.d.ts +11 -0
- package/dist/plugins/model-profiles/review-source.js +640 -0
- package/dist/plugins/model-profiles/rules.d.ts +130 -0
- package/dist/plugins/model-profiles/rules.js +729 -0
- package/dist/plugins/model-profiles/skills/model-profile/SKILL.md +59 -0
- package/dist/plugins/model-profiles/sources.d.ts +61 -0
- package/dist/plugins/model-profiles/sources.js +375 -0
- package/dist/plugins/model-profiles/storage.d.ts +84 -0
- package/dist/plugins/model-profiles/storage.js +315 -0
- package/dist/plugins/model-profiles/types.d.ts +179 -0
- package/dist/plugins/model-profiles/types.js +12 -0
- package/dist/plugins/model-profiles/wakeup.d.ts +29 -0
- package/dist/plugins/model-profiles/wakeup.js +390 -0
- package/dist/plugins/models/index.d.ts +2 -0
- package/dist/plugins/models/index.js +63 -0
- package/dist/plugins/models/plugin.yaml +8 -0
- package/dist/plugins/ops/collector.d.ts +22 -0
- package/dist/plugins/ops/collector.js +48 -0
- package/dist/plugins/ops/config.d.ts +11 -0
- package/dist/plugins/ops/config.js +13 -0
- package/dist/plugins/ops/console/pdl.json +676 -0
- package/dist/plugins/ops/console/view.mjs +700 -0
- package/dist/plugins/ops/index.d.ts +3 -0
- package/dist/plugins/ops/index.js +20 -0
- package/dist/plugins/ops/journal.d.ts +7 -0
- package/dist/plugins/ops/journal.js +109 -0
- package/dist/plugins/ops/metrics.d.ts +3 -0
- package/dist/plugins/ops/metrics.js +81 -0
- package/dist/plugins/ops/plugin.yaml +63 -0
- package/dist/plugins/ops/samples.d.ts +54 -0
- package/dist/plugins/ops/samples.js +100 -0
- package/dist/plugins/ops/trace.d.ts +3 -0
- package/dist/plugins/ops/trace.js +104 -0
- package/dist/plugins/ops/usage.d.ts +2 -0
- package/dist/plugins/ops/usage.js +152 -0
- package/dist/plugins/plans/acceptance.d.ts +284 -0
- package/dist/plugins/plans/acceptance.js +247 -0
- package/dist/plugins/plans/blocked.d.ts +25 -0
- package/dist/plugins/plans/blocked.js +66 -0
- package/dist/plugins/plans/console/pdl.json +639 -0
- package/dist/plugins/plans/console/view.d.mts +2 -0
- package/dist/plugins/plans/console/view.mjs +855 -0
- package/dist/plugins/plans/dependencies.d.ts +5 -0
- package/dist/plugins/plans/dependencies.js +21 -0
- package/dist/plugins/plans/index.d.ts +72 -0
- package/dist/plugins/plans/index.js +2057 -0
- package/dist/plugins/plans/plugin.yaml +44 -0
- package/dist/plugins/plans/progress.d.ts +82 -0
- package/dist/plugins/plans/progress.js +516 -0
- package/dist/plugins/prompt/index.d.ts +8 -0
- package/dist/plugins/prompt/index.js +361 -0
- package/dist/plugins/prompt/plugin.yaml +2 -0
- package/dist/plugins/recovery/console/pdl.json +50 -0
- package/dist/plugins/recovery/console/view.mjs +46 -0
- package/dist/plugins/recovery/index.d.ts +9 -0
- package/dist/plugins/recovery/index.js +454 -0
- package/dist/plugins/recovery/plugin.yaml +9 -0
- package/dist/plugins/recovery/probe.d.ts +11 -0
- package/dist/plugins/recovery/probe.js +128 -0
- package/dist/plugins/restart/console/pdl.json +112 -0
- package/dist/plugins/restart/console/view.mjs +85 -0
- package/dist/plugins/restart/index.d.ts +10 -0
- package/dist/plugins/restart/index.js +669 -0
- package/dist/plugins/restart/plugin.yaml +9 -0
- package/dist/plugins/restart/scope.d.ts +6 -0
- package/dist/plugins/restart/scope.js +44 -0
- package/dist/plugins/schedule/console/pdl.json +696 -0
- package/dist/plugins/schedule/console/view.mjs +398 -0
- package/dist/plugins/schedule/events.d.ts +76 -0
- package/dist/plugins/schedule/events.js +158 -0
- package/dist/plugins/schedule/index.d.ts +32 -0
- package/dist/plugins/schedule/index.js +1199 -0
- package/dist/plugins/schedule/plugin.yaml +26 -0
- package/dist/plugins/schedule/when.d.ts +14 -0
- package/dist/plugins/schedule/when.js +83 -0
- package/dist/plugins/sessions/console/pdl.json +259 -0
- package/dist/plugins/sessions/console/view.mjs +355 -0
- package/dist/plugins/sessions/index.d.ts +3 -0
- package/dist/plugins/sessions/index.js +126 -0
- package/dist/plugins/sessions/participants.d.ts +28 -0
- package/dist/plugins/sessions/participants.js +83 -0
- package/dist/plugins/sessions/plugin.yaml +3 -0
- package/dist/plugins/signals/console/pdl.json +802 -0
- package/dist/plugins/signals/console/view.mjs +284 -0
- package/dist/plugins/signals/content.d.ts +31 -0
- package/dist/plugins/signals/content.js +151 -0
- package/dist/plugins/signals/index.d.ts +2 -0
- package/dist/plugins/signals/index.js +601 -0
- package/dist/plugins/signals/plugin.yaml +32 -0
- package/dist/plugins/signals/skills/signal-sources/SKILL.md +27 -0
- package/dist/plugins/skills/console/pdl.json +254 -0
- package/dist/plugins/skills/console/view.mjs +204 -0
- package/dist/plugins/skills/index.d.ts +11 -0
- package/dist/plugins/skills/index.js +567 -0
- package/dist/plugins/skills/install.d.ts +69 -0
- package/dist/plugins/skills/install.js +265 -0
- package/dist/plugins/skills/plugin.yaml +24 -0
- package/dist/plugins/skills/safety-scan.d.ts +17 -0
- package/dist/plugins/skills/safety-scan.js +78 -0
- package/dist/plugins/skills/skills/skill-ops/SKILL.md +29 -0
- package/dist/plugins/terminal/console/pdl.json +115 -0
- package/dist/plugins/terminal/console/view.mjs +178 -0
- package/dist/plugins/terminal/index.d.ts +3 -0
- package/dist/plugins/terminal/index.js +204 -0
- package/dist/plugins/terminal/plugin.yaml +2 -0
- package/dist/plugins/tools/index.d.ts +3 -0
- package/dist/plugins/tools/index.js +455 -0
- package/dist/plugins/tools/plugin.yaml +2 -0
- package/dist/plugins/tools/token.d.ts +61 -0
- package/dist/plugins/tools/token.js +179 -0
- package/dist/plugins/topic-tools/index.d.ts +9 -0
- package/dist/plugins/topic-tools/index.js +29 -0
- package/dist/plugins/topic-tools/plugin.yaml +2 -0
- package/dist/plugins/topic-tools/skills/topic-tidy/SKILL.md +108 -0
- package/dist/plugins/works/console/pdl.json +120 -0
- package/dist/plugins/works/console/view.mjs +91 -0
- package/dist/plugins/works/document-words.d.ts +50 -0
- package/dist/plugins/works/document-words.js +27 -0
- package/dist/plugins/works/editors.d.ts +3 -0
- package/dist/plugins/works/editors.js +162 -0
- package/dist/plugins/works/events.d.ts +58 -0
- package/dist/plugins/works/events.js +82 -0
- package/dist/plugins/works/files.d.ts +23 -0
- package/dist/plugins/works/files.js +53 -0
- package/dist/plugins/works/index.d.ts +9 -0
- package/dist/plugins/works/index.js +1088 -0
- package/dist/plugins/works/plugin.yaml +9 -0
- package/dist/plugins/works/preview.d.ts +10 -0
- package/dist/plugins/works/preview.js +30 -0
- package/dist/plugins/works/project.d.ts +3 -0
- package/dist/plugins/works/project.js +245 -0
- package/dist/plugins/works/resource.d.ts +28 -0
- package/dist/plugins/works/resource.js +71 -0
- package/dist/plugins/works/retention.d.ts +36 -0
- package/dist/plugins/works/retention.js +295 -0
- package/dist/plugins/works/skills/works-ops/SKILL.md +14 -0
- package/dist/plugins/works/viewers.d.ts +13 -0
- package/dist/plugins/works/viewers.js +87 -0
- package/dist/plugins/works/web/anchors.js +94 -0
- package/dist/plugins/works/web/document-edit.js +245 -0
- package/dist/plugins/works/web/preview-bridge.js +142 -0
- package/dist/plugins/works/web/reading-position.js +74 -0
- package/dist/plugins/works/web/view.html +1118 -0
- package/dist/runtime/runtime.d.ts +210 -0
- package/dist/runtime/runtime.js +338 -0
- package/dist/sdk/adapter-kit.d.ts +1 -0
- package/dist/sdk/adapter-kit.js +1 -0
- package/dist/sdk/client.d.ts +163 -0
- package/dist/sdk/client.js +43 -0
- package/dist/sdk/contracts.d.ts +1263 -0
- package/dist/sdk/contracts.js +1 -0
- package/dist/sdk/index.d.ts +57 -0
- package/dist/sdk/index.js +27 -0
- package/dist/sdk/source-choice.d.ts +40 -0
- package/dist/sdk/source-choice.js +217 -0
- package/dist/sdk/topic-text.d.ts +5 -0
- package/dist/sdk/topic-text.js +26 -0
- package/dist/sdk/transport.d.ts +12 -0
- package/dist/sdk/transport.js +34 -0
- package/node_modules/@hostlet/adapter-kit/dist/acp.d.ts +88 -0
- package/node_modules/@hostlet/adapter-kit/dist/acp.js +674 -0
- package/node_modules/@hostlet/adapter-kit/dist/command.d.ts +18 -0
- package/node_modules/@hostlet/adapter-kit/dist/command.js +39 -0
- package/node_modules/@hostlet/adapter-kit/dist/index.d.ts +8 -0
- package/node_modules/@hostlet/adapter-kit/dist/index.js +6 -0
- package/node_modules/@hostlet/adapter-kit/dist/models.d.ts +29 -0
- package/node_modules/@hostlet/adapter-kit/dist/models.js +108 -0
- package/node_modules/@hostlet/adapter-kit/dist/quota.d.ts +3 -0
- package/node_modules/@hostlet/adapter-kit/dist/quota.js +4 -0
- package/node_modules/@hostlet/adapter-kit/dist/rpc.d.ts +29 -0
- package/node_modules/@hostlet/adapter-kit/dist/rpc.js +84 -0
- package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.d.ts +5 -0
- package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.js +37 -0
- package/node_modules/@hostlet/adapter-kit/package.json +16 -0
- package/node_modules/@hostlet/platform/dist/desktop.d.ts +16 -0
- package/node_modules/@hostlet/platform/dist/desktop.js +270 -0
- package/node_modules/@hostlet/platform/dist/files.d.ts +24 -0
- package/node_modules/@hostlet/platform/dist/files.js +113 -0
- package/node_modules/@hostlet/platform/dist/index.d.ts +6 -0
- package/node_modules/@hostlet/platform/dist/index.js +4 -0
- package/node_modules/@hostlet/platform/dist/paths.d.ts +4 -0
- package/node_modules/@hostlet/platform/dist/paths.js +9 -0
- package/node_modules/@hostlet/platform/dist/process.d.ts +45 -0
- package/node_modules/@hostlet/platform/dist/process.js +297 -0
- package/node_modules/@hostlet/platform/package.json +14 -0
- package/package.json +60 -4
|
@@ -0,0 +1,801 @@
|
|
|
1
|
+
/* 边界:一个含义一个组件、不为接口定制、不按位置推导样式 */
|
|
2
|
+
/* 输入类:输入框、选择、成员选择、取色、单选 / 勾选、字段与字段错误、搜索、补全提示、标签 / 键值编辑器 */
|
|
3
|
+
'use strict';
|
|
4
|
+
/* 勾选标记(方框 + 勾):唯一的画法。勾选控件(pdl-check)、目标勾选、只读清单都用它;on 也可以由外层的 aria-checked / 原生 :checked 给 */
|
|
5
|
+
function checkInd(on) { return '<span class="box' + (on ? ' on' : '') + '" aria-hidden="true">' + icon('check', 12) + '</span>'; }
|
|
6
|
+
/* 设置行里的选择(Keeper 式:当前值 + 上下箭头)。change 交给 CHANGES 里的键;data 是附加属性(比如 ' data-k="font"')。
|
|
7
|
+
选项可以是 [值, 文字] 或直接是文字。 */
|
|
8
|
+
function pick(id, opts, val, label, change, data) { return sel(id, opts, val, { label: label, change: change, data: data }); } /* 设置行里的值:就是下拉本身(下拉只有一个样子) */
|
|
9
|
+
/* 下拉:选项可以是字符串(值 = 显示文字),也可以是 { v, label }——值是模型里的枚举,文字来自文案;功能代码只比较枚举 */
|
|
10
|
+
/* 下拉(组件库唯一一个,只有一个样子:宽度是最宽的那个选项,不按所在的表单 / 筛选 / 设置行换样子)。
|
|
11
|
+
选项可以是字符串、[值, 文字] 或 { v, label }——值是模型里的枚举,文字来自文案;功能代码只比较枚举 */
|
|
12
|
+
/* 重画后弹窗里的值会被恢复到隐藏的 select 上:让看得见的按钮文字跟上 */
|
|
13
|
+
function selSync() { document.querySelectorAll('.select-wrap > select.sr').forEach(function (s) { const b = s.nextElementSibling, o = s.options[s.selectedIndex], v0 = b && b.querySelector('.select-v'), v = v0 && (v0.querySelector('.select-t') || v0); if (v && o && v.textContent !== o.textContent) v.textContent = o.textContent; }); }
|
|
14
|
+
const SEL = {}; /* 下拉 id → { lead: 前导函数(菜单项和按钮画同一个前导), multi: 多选的选项和值 };每次画 sel 时更新 */
|
|
15
|
+
/* o.multi(多选:成员多选也是它):值是一组;选中项平铺成带移除按钮(×)的标签,末尾跟「+ 添加」按钮打开菜单(每项就地开关,stay),
|
|
16
|
+
点了执行声明的 act(参数 args,再加 key(缺省 v)= 这一项的值)——多选的值不在原生 select 上,由动作改数据,重画时标签与打勾跟着变 */
|
|
17
|
+
function sel(id, opts, val, o) {
|
|
18
|
+
o = o || {};
|
|
19
|
+
const ov = function (x) { return Array.isArray(x) ? x : x && typeof x === 'object' ? [x.v, x.label, x.why, x.remove, x.short, x.sub] : [x, x]; }; /* 选项可以声明 remove { act, args, label }:菜单里这一项末尾有删除;sub:菜单里这一项的第二行说明 */
|
|
20
|
+
if (o.multi) return selMulti(id, opts.map(ov), val, o);
|
|
21
|
+
const ps = opts.map(ov);
|
|
22
|
+
const cur = ps.find(function (p) { return p[0] === val; }) || ps[0] || ['', ''];
|
|
23
|
+
/* 选项的前导(o.lead(值) → 一段前导内容:头像、图标……,没有就是空):按钮上的当前值、量宽用的每个选项、点开的菜单项都画同一个前导。
|
|
24
|
+
选项的通用排法只有一条(core.css .select-v / .select-sz):前导 + 文字一行、垂直居中、省略只在文字上——不按前导是什么换样子 */
|
|
25
|
+
const lead = function (v) { return o.lead ? o.lead(v) || '' : ''; };
|
|
26
|
+
SEL[id] = { lead: o.lead || null, span: o.span };
|
|
27
|
+
/* 值的载体是一个隐藏的原生 select(表单读值、change 事件、未保存检测都照旧);看得见的是组件库自己的按钮,点开是组件库的菜单(不用系统的下拉) */
|
|
28
|
+
return '<div class="select-wrap' + (o.cls ? ' ' + o.cls : '') + '"' + (o.span ? ' data-span="' + o.span + '" style="--u-span:var(--span-' + o.span + ')"' : '') + '>' +
|
|
29
|
+
'<select class="sr" tabindex="-1" aria-hidden="true" id="' + h(id) + '"' + (o.change ? ' data-change="' + o.change + '"' : '') + (o.data || '') + '>' +
|
|
30
|
+
ps.map(function (p) { const why = typeof p[2] === 'string' ? p[2] : ''; return '<option value="' + h(p[0]) + '"' + (p[0] === val ? ' selected' : '') + (why ? ' disabled data-tip="' + h(why) + '"' : '') + (p[3] ? ' data-rm="' + h(JSON.stringify(p[3])) + '"' : '') + (p[5] ? ' data-sub="' + h(p[5]) + '"' : '') + '>' + h(p[1]) + '</option>'; }).join('') + '</select>' + /* 第三项是“为什么现在不能选”:选项停用,悬停看原因 */
|
|
31
|
+
'<button type="button" class="select' + (o.mono ? ' mono' : '') + '" data-act="selOpen" data-for="' + h(id) + '" aria-haspopup="menu"' + (o.invalid ? ' aria-invalid="true"' : '') + (o.label ? ' aria-label="' + h(o.label) + '"' : '') + (o.disabled ? ' disabled' : '') + (o.tip ? ' data-tip="' + h(o.tip) + '"' : '') + '>' + /* 整个改不了(disabled):停用,悬停看原因(tip) */
|
|
32
|
+
(o.prefix ? '<span class="select-p">' + h(o.prefix) + '</span>' : '') + '<span class="select-vs"><span class="select-v">' + lead(cur[0]) + '<span class="select-t">' + h(cur[1]) + '</span></span>' + ps.map(function (p) { return '<span class="select-sz" aria-hidden="true">' + lead(p[0]) + '<span class="select-t">' + h(p[1]) + '</span></span>'; }).join('') + '</span>' + icon('updown', 13) + '</button></div>'; /* 宽度 = 最宽的选项(和原生下拉一样):换一个值,同一行后面的东西不挪 */
|
|
33
|
+
}
|
|
34
|
+
/* 下拉(sel)点开:组件库的菜单,选项来自隐藏的原生 select(文字、停用原因、末尾的删除),每项带和按钮上一样的前导;选中后改它的值并发出 change,原来的处理照旧 */
|
|
35
|
+
function selMulti(id, ps, val, o) {
|
|
36
|
+
const on = [].concat(val || []).filter(function (v) { return ps.some(function (p) { return p[0] === v; }); }), lead = function (v) { return o.lead ? o.lead(v) || '' : ''; };
|
|
37
|
+
SEL[id] = { lead: o.lead || null, multi: { ps: ps, on: on, act: o.act, args: o.args || {}, key: o.key || 'v' } };
|
|
38
|
+
const chips = on.map(function (v) {
|
|
39
|
+
const p = ps.find(function (x) { return x[0] === v; });
|
|
40
|
+
const name = p[4] || p[1];
|
|
41
|
+
return chipHtml({
|
|
42
|
+
lead: lead(v),
|
|
43
|
+
label: h(name),
|
|
44
|
+
ellip: true,
|
|
45
|
+
tip: p[1] !== name ? h(p[1]) : '',
|
|
46
|
+
x: o.disabled ? '' : chipX('selToggle', argAttrs({ for: id, v: v }), tc('chip.remove', name)),
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
const addLabel = tc('common.add');
|
|
50
|
+
const addAria = o.label ? addLabel + ' ' + o.label : addLabel;
|
|
51
|
+
const add = o.disabled ? '' : btn(addLabel, {
|
|
52
|
+
sm: true, icon: 'plus', act: 'selOpen',
|
|
53
|
+
data: ' id="' + h(id) + '" data-for="' + h(id) + '" aria-haspopup="menu" aria-label="' + h(addAria) + '"',
|
|
54
|
+
disabled: on.length >= ps.length,
|
|
55
|
+
});
|
|
56
|
+
return '<div class="chips tag-ed' + (o.cls ? ' ' + o.cls : '') + '"' + (o.disabled ? ' id="' + h(id) + '"' : '') + '>' +
|
|
57
|
+
(chips.length ? chips.join('') : o.none ? '<span class="faint chip-empty">' + h(o.none) + '</span>' : '') +
|
|
58
|
+
add + '</div>';
|
|
59
|
+
}
|
|
60
|
+
A.selOpen = function (d, el) {
|
|
61
|
+
const m = SEL[d.for] && SEL[d.for].multi;
|
|
62
|
+
if (m) { /* 多选:列出尚未选中的项(已选项直接以标签展示并点 × 移除) */
|
|
63
|
+
S.menu = { sel: d.for, q: '', get items() {
|
|
64
|
+
const x = (SEL[d.for] && SEL[d.for].multi) || m, lead = SEL[d.for] && SEL[d.for].lead;
|
|
65
|
+
return x.ps.filter(function (p) { return x.on.indexOf(p[0]) < 0; }).map(function (p) {
|
|
66
|
+
return { lead: lead ? lead(p[0]) || '' : '', label: p[1], sub: p[5], act: 'selToggle', data: { for: d.for, v: p[0] }, stay: true };
|
|
67
|
+
});
|
|
68
|
+
} }; menuAnchor(el);
|
|
69
|
+
render(true); return;
|
|
70
|
+
}
|
|
71
|
+
const s = document.getElementById(d.for); if (!s) return;
|
|
72
|
+
const lead = SEL[d.for] && SEL[d.for].lead;
|
|
73
|
+
S.menu = { span: SEL[d.for] && SEL[d.for].span, items: Array.prototype.map.call(s.options, function (o) { return { label: o.textContent, sub: o.dataset.sub || '', lead: lead ? lead(o.value) || '' : '', act: 'selPick', data: { for: d.for, v: o.value }, cur: o.selected, why: o.disabled ? o.dataset.tip || ' ' : '', x: o.dataset.rm ? JSON.parse(o.dataset.rm) : null }; }), sel: d.for, q: '' }; menuAnchor(el);
|
|
74
|
+
render(true);
|
|
75
|
+
};
|
|
76
|
+
/* 多选的一项:先在组件自己记着的值上翻过来(菜单立即更新或选满自动关闭),再执行声明的动作(参数 args + key = 这一项的值) */
|
|
77
|
+
A.selToggle = function (d, el) {
|
|
78
|
+
const x = SEL[d.for] && SEL[d.for].multi; if (!x) return;
|
|
79
|
+
const v = String(d.v), i = x.on.map(String).indexOf(v), a = Object.assign({}, x.args); a[x.key] = d.v;
|
|
80
|
+
if (i >= 0) x.on.splice(i, 1); else x.on.push(d.v);
|
|
81
|
+
if (S.menu && S.menu.sel === d.for && x.ps.every(function (p) { return x.on.indexOf(p[0]) >= 0; })) S.menu = null;
|
|
82
|
+
return actFn(x.act)(a, el);
|
|
83
|
+
};
|
|
84
|
+
/* 带候选的输入框(PDL input 的 listFrom):框尾的按钮点开组件库的菜单,候选可以带第二行说明;选中的值写回输入框,和手动输入一样发出 input + change */
|
|
85
|
+
const COMBO = {};
|
|
86
|
+
A.comboOpen = function (d, el) {
|
|
87
|
+
const input = document.getElementById(d.for); if (!input) return;
|
|
88
|
+
S.menu = { sel: d.for, q: '', items: (COMBO[d.for] || []).map(function (c) { return { label: c.label, sub: c.sub || '', act: 'comboPick', data: { for: d.for, v: c.v }, cur: c.v === input.value }; }) }; menuAnchor(el);
|
|
89
|
+
render(true);
|
|
90
|
+
};
|
|
91
|
+
A.comboPick = function (d) {
|
|
92
|
+
const input = document.getElementById(d.for); S.menu = null; if (!input) { render(true); return; }
|
|
93
|
+
input.value = d.v; input.dispatchEvent(new Event('input', { bubbles: true })); input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
94
|
+
render(true);
|
|
95
|
+
};
|
|
96
|
+
INPUTS.menuQ = function (e) { if (S.menu) { S.menu.q = e.target.value; render(true); } };
|
|
97
|
+
A.selPick = function (d) {
|
|
98
|
+
const s = document.getElementById(d.for);
|
|
99
|
+
if (!s) { render(true); return; }
|
|
100
|
+
if (s.value !== d.v) { s.value = d.v; s.dispatchEvent(new Event('change', { bubbles: true })); }
|
|
101
|
+
render(true);
|
|
102
|
+
};
|
|
103
|
+
/* 日期输入沿用原字段 id 和日期值。原生输入承载值、事件和校验,按钮打开共用日历。 */
|
|
104
|
+
const DATE_POP_ID = 'pdl-date-picker';
|
|
105
|
+
let datePicker = null;
|
|
106
|
+
function datePoint(value) {
|
|
107
|
+
const parts = /^(\d{4,})-(\d{2})-(\d{2})$/.exec(value);
|
|
108
|
+
if (!parts) return NaN;
|
|
109
|
+
const year = +parts[1], month = +parts[2] - 1, day = +parts[3];
|
|
110
|
+
const d = calendarDate(year, month, day);
|
|
111
|
+
return year > 0 && d.getFullYear() === year && d.getMonth() === month && d.getDate() === day ? d.getTime() : NaN;
|
|
112
|
+
}
|
|
113
|
+
function dateDisplay(value, placeholder) {
|
|
114
|
+
const at = datePoint(value);
|
|
115
|
+
return Number.isFinite(at) ? new Intl.DateTimeFormat(i18nLang(), { year: 'numeric', month: '2-digit', day: '2-digit' }).format(at) : placeholder;
|
|
116
|
+
}
|
|
117
|
+
function dateCtl(o) {
|
|
118
|
+
const id = h(o.id), label = o.label || o.aria || o.placeholder || tc('calendar.pick'), placeholder = o.placeholder || tc('calendar.pick');
|
|
119
|
+
return '<span class="date-field"><input class="sr date-input" tabindex="-1" aria-hidden="true" type="date" id="' + id + '" value="' + h(o.value || '') + '" data-placeholder="' + h(placeholder) + '"' +
|
|
120
|
+
(o.min != null ? ' min="' + h(o.min) + '"' : '') + (o.maxv != null ? ' max="' + h(o.maxv) + '"' : '') +
|
|
121
|
+
(o.input ? ' data-input="' + h(o.input) + '"' : '') + (o.change ? ' data-change="' + h(o.change) + '"' : '') + (o.data || '') +
|
|
122
|
+
(o.disabled ? ' disabled' : '') + (o.ro ? ' readonly' : '') + '>' +
|
|
123
|
+
'<button type="button" class="input date-trigger' + (o.mono ? ' mono' : '') + '" id="' + id + '-date-trigger" data-act="dateOpen" data-for="' + id + '" aria-haspopup="dialog" aria-expanded="false" aria-label="' + h(label) + '" aria-describedby="' + id + '-date-value"' +
|
|
124
|
+
(o.on ? (o.data || '') + onAttrs(o.on) : '') +
|
|
125
|
+
(o.invalid ? ' aria-invalid="true"' : '') + (o.value ? '' : ' data-empty') + (o.disabled || o.ro ? ' disabled' : '') + '>' +
|
|
126
|
+
'<span id="' + id + '-date-value">' + h(dateDisplay(o.value, placeholder)) + '</span>' + icon('expand', 13) + '</button></span>';
|
|
127
|
+
}
|
|
128
|
+
function dateCtlSync(input) {
|
|
129
|
+
const trigger = input.nextElementSibling, open = datePicker?.id === input.id;
|
|
130
|
+
const text = dateDisplay(input.value, input.dataset.placeholder), label = trigger.firstElementChild;
|
|
131
|
+
if (label.textContent !== text) label.textContent = text;
|
|
132
|
+
trigger.toggleAttribute('data-empty', !input.value);
|
|
133
|
+
if (trigger.getAttribute('aria-expanded') !== String(open)) trigger.setAttribute('aria-expanded', String(open));
|
|
134
|
+
if (open && !trigger.hasAttribute('aria-controls')) trigger.setAttribute('aria-controls', DATE_POP_ID);
|
|
135
|
+
else if (!open) trigger.removeAttribute('aria-controls');
|
|
136
|
+
}
|
|
137
|
+
function dateBounds(input) {
|
|
138
|
+
const min = datePoint(input.min), max = datePoint(input.max);
|
|
139
|
+
return { min: Number.isFinite(min) ? min : calendarDate(1, 0, 1).getTime(), max: Number.isFinite(max) ? max : Infinity };
|
|
140
|
+
}
|
|
141
|
+
function dateToday() {
|
|
142
|
+
const d = new Date(ioNow());
|
|
143
|
+
return calendarDate(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
|
|
144
|
+
}
|
|
145
|
+
function dateMonth(at, step) {
|
|
146
|
+
const d = new Date(at);
|
|
147
|
+
return calendarDate(d.getFullYear(), d.getMonth() + step, 1).getTime();
|
|
148
|
+
}
|
|
149
|
+
POPUPS.datePicker = function () {
|
|
150
|
+
if (!datePicker) return '';
|
|
151
|
+
const input = document.getElementById(datePicker.id);
|
|
152
|
+
if (!input || input.disabled || input.readOnly) { datePicker = null; return ''; }
|
|
153
|
+
const month = datePicker.month, value = datePoint(input.value), today = dateToday(), bounds = dateBounds(input);
|
|
154
|
+
const move = function (step, label, icon, disabled) {
|
|
155
|
+
return btn(label, { act: 'dateMove', iconOnly: true, icon: icon, sm: true, disabled: disabled, data: argAttrs({ step: step }) });
|
|
156
|
+
};
|
|
157
|
+
return floatHtml({ cls: 'pop date-picker', attrs: ' id="' + DATE_POP_ID + '"', label: input.nextElementSibling.getAttribute('aria-label'),
|
|
158
|
+
head: move(-1, tc('calendar.prev'), 'left', month <= bounds.min) +
|
|
159
|
+
'<span class="u-strong grow date-month" aria-live="polite">' + h(new Intl.DateTimeFormat(i18nLang(), { year: 'numeric', month: 'long' }).format(month)) + '</span>' +
|
|
160
|
+
move(1, tc('calendar.next'), 'right', !(dateMonth(month, 1) <= bounds.max)),
|
|
161
|
+
body: PDL_COMPONENTS.calendar(Object.assign({ anchor: month, value: value, today: today, mode: 'month', act: 'datePick', tabIndex: -1 }, bounds)),
|
|
162
|
+
foot: btn(tc('common.clear'), { act: 'datePick', sm: true, disabled: !input.value, data: argAttrs({ v: null }) }) +
|
|
163
|
+
btn(tc('format.today'), { act: 'datePick', sm: true, disabled: today < bounds.min || today > bounds.max, data: argAttrs({ v: today }) })
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
/* 日期网格只有一个 Tab 停靠点,方向键逐日或逐周移动。 */
|
|
167
|
+
function dateTabStop(picker, day) {
|
|
168
|
+
const old = picker.querySelector('.calendar-day[tabindex="0"]');
|
|
169
|
+
if (old) old.tabIndex = -1;
|
|
170
|
+
day = day || picker.querySelector('.calendar-day[aria-pressed="true"]:enabled') ||
|
|
171
|
+
picker.querySelector('.calendar-day[data-today="true"]:enabled') || picker.querySelector('.calendar-day[data-outside="false"]:enabled') ||
|
|
172
|
+
picker.querySelector('.calendar-day:enabled');
|
|
173
|
+
if (day) day.tabIndex = 0;
|
|
174
|
+
return day;
|
|
175
|
+
}
|
|
176
|
+
A.dateOpen = function (d) {
|
|
177
|
+
const input = document.getElementById(d.for);
|
|
178
|
+
if (!input || input.disabled || input.readOnly) return;
|
|
179
|
+
if (datePicker?.id === input.id) return A.dateClose();
|
|
180
|
+
const { min, max } = dateBounds(input), value = datePoint(input.value);
|
|
181
|
+
datePicker = { id: input.id, month: dateMonth(Number.isFinite(value) ? value : Math.max(min, Math.min(dateToday(), max)), 0) };
|
|
182
|
+
popRefresh('datePicker');
|
|
183
|
+
dateCtlSync(input);
|
|
184
|
+
const picker = document.getElementById(DATE_POP_ID), day = dateTabStop(picker);
|
|
185
|
+
(day || picker.querySelector('button:enabled'))?.focus();
|
|
186
|
+
};
|
|
187
|
+
A.dateClose = function () {
|
|
188
|
+
const input = datePicker && document.getElementById(datePicker.id);
|
|
189
|
+
/* Return focus before removing the popup so an enclosing focus-based picker stays open. */
|
|
190
|
+
if (input && document.activeElement?.closest('#' + DATE_POP_ID)) input.nextElementSibling.focus({ preventScroll: true });
|
|
191
|
+
datePicker = null;
|
|
192
|
+
popRefresh('datePicker');
|
|
193
|
+
if (input?.isConnected) dateCtlSync(input);
|
|
194
|
+
};
|
|
195
|
+
A.dateMove = function (d, el) {
|
|
196
|
+
datePicker.month = dateMonth(datePicker.month, d.step);
|
|
197
|
+
popRefresh('datePicker');
|
|
198
|
+
const picker = document.getElementById(DATE_POP_ID), day = dateTabStop(picker);
|
|
199
|
+
if (!el.isConnected || el.disabled) (day || picker.querySelector('button:enabled'))?.focus();
|
|
200
|
+
};
|
|
201
|
+
A.datePick = function (d) {
|
|
202
|
+
const input = document.getElementById(datePicker.id), before = input.value;
|
|
203
|
+
const day = new Date(d.v);
|
|
204
|
+
input.value = d.v === null ? '' : [String(day.getFullYear()).padStart(4, '0'), String(day.getMonth() + 1).padStart(2, '0'), String(day.getDate()).padStart(2, '0')].join('-');
|
|
205
|
+
A.dateClose();
|
|
206
|
+
if (input.value === before) return;
|
|
207
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
208
|
+
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
209
|
+
};
|
|
210
|
+
KEY_FNS.push(function (e) {
|
|
211
|
+
const step = { ArrowLeft: -1, ArrowRight: 1, ArrowUp: -7, ArrowDown: 7 }[e.key];
|
|
212
|
+
const picker = step && e.target.closest('#' + DATE_POP_ID);
|
|
213
|
+
if (!picker || !e.target.matches('.calendar-day')) return false;
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
const d = new Date(Number(e.target.dataset.v)), next = calendarDate(d.getFullYear(), d.getMonth(), d.getDate() + step);
|
|
216
|
+
const { min, max } = dateBounds(document.getElementById(datePicker.id));
|
|
217
|
+
if (next >= min && next <= max) {
|
|
218
|
+
const month = dateMonth(next, 0);
|
|
219
|
+
if (month !== datePicker.month) { datePicker.month = month; popRefresh('datePicker'); }
|
|
220
|
+
document.getElementById(DATE_POP_ID).querySelector('.calendar-day[data-v="' + next.getTime() + '"]')?.focus();
|
|
221
|
+
}
|
|
222
|
+
return true;
|
|
223
|
+
});
|
|
224
|
+
document.addEventListener('focusin', function (e) {
|
|
225
|
+
const el = e.target;
|
|
226
|
+
if (el.matches('.date-input')) el.nextElementSibling.focus({ preventScroll: true });
|
|
227
|
+
else if (el.matches('.date-picker .calendar-day')) dateTabStop(el.closest('#' + DATE_POP_ID), el);
|
|
228
|
+
});
|
|
229
|
+
/* 点原字段的 label 也打开组件库浮层。 */
|
|
230
|
+
document.addEventListener('click', function (e) {
|
|
231
|
+
if (!e.target.matches('.date-input')) return;
|
|
232
|
+
e.preventDefault();
|
|
233
|
+
e.target.nextElementSibling.click();
|
|
234
|
+
}, true);
|
|
235
|
+
document.addEventListener('invalid', function (e) {
|
|
236
|
+
const input = e.target;
|
|
237
|
+
if (!input.matches('.date-input')) return;
|
|
238
|
+
e.preventDefault();
|
|
239
|
+
if (!input.form || input.form.querySelector(':invalid') === input) fieldErr(input.id, input.validationMessage);
|
|
240
|
+
}, true);
|
|
241
|
+
PAINT_SYNC.push(function () {
|
|
242
|
+
document.querySelectorAll('.date-input').forEach(dateCtlSync);
|
|
243
|
+
const picker = document.getElementById(DATE_POP_ID);
|
|
244
|
+
if (picker) dateTabStop(picker, picker.querySelector('.calendar-day:focus'));
|
|
245
|
+
});
|
|
246
|
+
/* 选成员(组件库唯一一个成员选择器):单选就是下拉 sel(),前导是成员的头像(值是成员 id);
|
|
247
|
+
多选渲染为可移除的成员标签(头像 + 名字 + ×)加「+ 添加」按钮,点开同一种菜单,每项是一个就地的开关(stay),动作由声明给,参数里带成员 id。
|
|
248
|
+
o = { id, pool: [id], value: id | [id], none(不选时那一项的文字), multi, act, args(参数属性串), change, data, label } */
|
|
249
|
+
function memberLead(id) { return id ? whoAva(id, { size: 's', tip: false }) : ''; } /* 空值是“不选”那一项:没有前导 */
|
|
250
|
+
function memberLabel(id) { const m = WHO_DATA.member(id); return m.name + ' ' + m.handle; }
|
|
251
|
+
function memberPick(o) {
|
|
252
|
+
const ps = (o.none != null && !o.multi ? [['', o.none]] : []).concat(o.pool.map(function (id) { return { v: id, label: memberLabel(id), short: WHO_DATA.member(id).name }; }));
|
|
253
|
+
return sel(o.id, ps, o.multi ? o.value || [] : o.value || '', { lead: memberLead, change: o.change, data: o.data, label: o.label, multi: !!o.multi, act: o.act, args: o.args, key: 'id', none: o.none, disabled: o.disabled }); /* 单选、多选都是下拉本身(multi 模式),前导是头像 */
|
|
254
|
+
}
|
|
255
|
+
/* 取色(组件库唯一一个,不用系统取色器):值的载体是隐藏的原生颜色输入(input 事件、未保存检测照旧);看得见的是一个色块按钮,
|
|
256
|
+
点开组件库的浮层:色轮(一圈是色相,圆心到边是饱和度)+ 明度滑块 + 预览 + 主题里已有的颜色 + 十六进制输入。和下拉 sel() 同一个模式。
|
|
257
|
+
选中的颜色存成固定值(十六进制),原样画出来,不按浅色 / 深色推导别的值 */
|
|
258
|
+
/* o.input:值变了交给哪个输入处理;o.slots = 'name':主题的成员色槽位排在前面;o.preview:旁边一段文字用这个颜色(名字的预览),浮层里也用它预览;
|
|
259
|
+
o.kind = 'slot':只在主题的成员色槽位里单选(见下面 colorSlots)——取色只有这一个组件,槽位单选是它的变体 */
|
|
260
|
+
function colorCtl(o) {
|
|
261
|
+
if (o.kind === 'slot') return colorSlots(o);
|
|
262
|
+
if (o.value && typeof o.value === 'object') o = Object.assign({}, o, { value: FORMATS.color(o.value) });
|
|
263
|
+
if (!o.value && o.default) o = Object.assign({}, o, { value: getComputedStyle(document.documentElement).getPropertyValue(o.default).trim().toLowerCase() });
|
|
264
|
+
return '<span class="color-wrap"><input type="color" class="sr tok-color" tabindex="-1" aria-hidden="true" id="' + h(o.id) + '" value="' + h(o.value) + '"' + (o.tok ? ' data-tok="' + h(o.tok) + '"' : '') + (o.input ? ' data-input="' + h(o.input) + '"' : '') + (o.slots ? ' data-slots="' + h(o.slots) + '"' : '') + (o.preview ? ' data-preview="' + h(o.preview) + '"' : '') + '>' +
|
|
265
|
+
'<button type="button" class="color-sw" data-act="colorOpen" data-for="' + h(o.id) + '" aria-haspopup="dialog" aria-label="' + h(o.label || tc('control.color')) + '" style="--sw:' + h(o.value) + '"></button>' +
|
|
266
|
+
(o.preview ? '<span class="color-name" style="--sw:' + h(o.value) + '">' + h(o.preview) + '</span>' : '') + '</span>';
|
|
267
|
+
}
|
|
268
|
+
/* 取色的 slot 变体:只在主题的 6 个成员色槽位里单选一个(值是槽位号,不是固定值)——主人的两种颜色、目录里的 tints 控件。
|
|
269
|
+
o = { value: 槽位号, act, label, name(放在对话框字段里时的字段 id:点了改字段的数据), data } */
|
|
270
|
+
function colorSlots(o) {
|
|
271
|
+
return '<span class="pdl-tint-picker" role="radiogroup" aria-label="' + h(o.label || tc('control.color')) + '"' + (o.name ? ' data-swatch="' + h(o.name) + '"' : '') + '>' + [1, 2, 3, 4, 5, 6].map(function (n) { return '<button type="button" role="radio" aria-checked="' + (o.value === n) + '" aria-label="' + h(tc('control.colorN', n)) + '" data-act="' + o.act + '"' + (o.data || '') + ' data-v="' + n + '" data-n="' + n + '" style="--u-background:var(--tint-' + n + ')" class="u-v-background"></button>'; }).join('') + '</span>';
|
|
272
|
+
}
|
|
273
|
+
/* 槽位单选点了一项:在对话框字段里就改字段的数据(重画);不在字段里就只是就地改选中(单选的行为属于这个组件) */
|
|
274
|
+
A.swatch = function (d, el) {
|
|
275
|
+
const f = dlgFieldById(el.parentNode.dataset.swatch); if (f) { dlgSync(); f.swatch.cur = +d.n; render(true); return; }
|
|
276
|
+
el.parentNode.querySelectorAll('[role="radio"]').forEach(function (b) { b.setAttribute('aria-checked', b === el ? 'true' : 'false'); });
|
|
277
|
+
};
|
|
278
|
+
/* 色轮的颜色模型是 HSL:色相 h(度,0 在正上方、顺时针)、饱和度 s 和明度 l(0–1)。浮层上只写这三个变量,色轮、圆点、滑块、预览的颜色都由 CSS 推出 */
|
|
279
|
+
function hexHsl(hex) {
|
|
280
|
+
const c = [1, 3, 5].map(function (i) { return (parseInt(String(hex).slice(i, i + 2), 16) || 0) / 255; }), mx = Math.max.apply(null, c), mn = Math.min.apply(null, c), l = (mx + mn) / 2, d = mx - mn;
|
|
281
|
+
if (!d) return { h: 0, s: 0, l: l };
|
|
282
|
+
const s = d / (1 - Math.abs(2 * l - 1)), hh = mx === c[0] ? ((c[1] - c[2]) / d + 6) % 6 : mx === c[1] ? (c[2] - c[0]) / d + 2 : (c[0] - c[1]) / d + 4;
|
|
283
|
+
return { h: hh * 60, s: Math.min(1, s), l: l };
|
|
284
|
+
}
|
|
285
|
+
function hslHex(o) {
|
|
286
|
+
const a = o.s * Math.min(o.l, 1 - o.l), f = function (n) { const k = (n + o.h / 30) % 12; return o.l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1)); };
|
|
287
|
+
return '#' + [0, 8, 4].map(function (n) { return ('0' + Math.round(Math.max(0, Math.min(1, f(n))) * 255).toString(16)).slice(-2); }).join('');
|
|
288
|
+
}
|
|
289
|
+
/* 取色的三个动作(组件库的原件,登记进动作表):打开浮层、选定一个颜色、输入十六进制 */
|
|
290
|
+
Object.assign(A, {
|
|
291
|
+
/* 取色:组件库的浮层(色轮 + 明度 + 预览 + 主题已有颜色 + 十六进制)。浮层每次画都按隐藏输入现在的值(选了之后浮层留着,接着调);
|
|
292
|
+
色轮的 HSL 记在菜单上,十六进制往返不丢色相(灰色时色相照旧) */
|
|
293
|
+
colorOpen: function (d, el) {
|
|
294
|
+
const s = document.getElementById(d.for); if (!s) return;
|
|
295
|
+
const cs = getComputedStyle(document.documentElement), seen = {};
|
|
296
|
+
const names = ['--name-1', '--name-2', '--name-3', '--name-4', '--name-5', '--name-6'], base = ['--accent', '--ok', '--warn', '--danger', '--info'];
|
|
297
|
+
const val = function (l) { return l.map(function (t) { return cs.getPropertyValue(t).trim().toLowerCase(); }).filter(function (v) { if (!/^#[0-9a-f]{6}$/.test(v) || seen[v]) return false; seen[v] = 1; return true; }); };
|
|
298
|
+
const theme = (s.dataset.slots === 'name' ? [names, base] : [base, names]).map(val); /* 主题已有的颜色按组各一行(成员色槽位 / 强调和状态色),点了就是那个固定值 */
|
|
299
|
+
const preview = s.dataset.preview || '';
|
|
300
|
+
S.menu = { sel: d.for, label: el.getAttribute('aria-label'), hsl: hexHsl(s.value.toLowerCase()),
|
|
301
|
+
get html() { const x = document.getElementById(d.for), hex = x ? x.value.toLowerCase() : hslHex(this.hsl); if (hslHex(this.hsl) !== hex) this.hsl = hexHsl(hex); return colorPopHtml({ for: d.for, hex: hex, hsl: this.hsl, theme: theme, preview: preview }); } };
|
|
302
|
+
menuAnchor(el);
|
|
303
|
+
render(true);
|
|
304
|
+
},
|
|
305
|
+
/* 选定一个颜色(固定值):改隐藏输入的值并发出 input,原来的处理照旧;浮层留着(keep:色轮已经记下了 HSL) */
|
|
306
|
+
colorSet: function (d) {
|
|
307
|
+
const s = document.getElementById(d.for), v = String(d.v || '').toLowerCase();
|
|
308
|
+
if (!/^#[0-9a-f]{6}$/.test(v)) return;
|
|
309
|
+
if (S.menu && S.menu.hsl && !d.keep) S.menu.hsl = hexHsl(v);
|
|
310
|
+
if (s && s.value.toLowerCase() !== v) { s.value = v; s.dispatchEvent(new Event('input', { bubbles: true })); }
|
|
311
|
+
render(true);
|
|
312
|
+
},
|
|
313
|
+
colorHex: function (d, el) { const v = (el.value || '').trim(); A.colorSet({ for: d.for, v: v.charAt(0) === '#' ? v : '#' + v }); }
|
|
314
|
+
});
|
|
315
|
+
function colorVars(o) { return '--h:' + o.h.toFixed(1) + ';--s:' + o.s.toFixed(3) + ';--l:' + o.l.toFixed(3); }
|
|
316
|
+
/* 取色浮层的内容(组件库):色轮 · 明度 · 预览(名字或色块)+ 十六进制 · 主题已有的颜色(每组一行,点了就是这个固定值) */
|
|
317
|
+
function colorPopHtml(o) {
|
|
318
|
+
const sw = function (v) { return '<button type="button" class="color-sw" data-act="colorSet" data-stay data-for="' + h(o.for) + '" data-v="' + v + '" style="--sw:' + v + '"' + (v === o.hex ? ' aria-current="true"' : '') + ' aria-label="' + v + '"></button>'; };
|
|
319
|
+
return '<div class="color-pop" data-for="' + h(o.for) + '" style="' + colorVars(o.hsl) + '">' +
|
|
320
|
+
'<div class="color-wheel" id="color-wheel" role="slider" tabindex="0" aria-label="' + h(tc('control.colorWheel')) + '" aria-valuetext="' + o.hex + '"><span class="color-dot"></span></div>' +
|
|
321
|
+
'<input type="range" class="color-l" id="color-l" min="0" max="100" step="1" value="' + Math.round(o.hsl.l * 100) + '" aria-label="' + h(tc('control.colorLight')) + '">' +
|
|
322
|
+
'<div class="color-out">' + (o.preview ? '<span class="color-name">' + h(o.preview) + '</span>' : '<span class="color-now"></span>') +
|
|
323
|
+
'<input class="input mono" id="color-hex" value="' + h(o.hex) + '" maxlength="7" aria-label="HEX" data-for="' + h(o.for) + '" data-on-enter="colorHex"></div>' +
|
|
324
|
+
o.theme.filter(function (g) { return g.length; }).map(function (g) { return '<div class="color-row">' + g.map(sw).join('') + '</div>'; }).join('') + '</div>';
|
|
325
|
+
}
|
|
326
|
+
/* 色轮的拖动和按键(组件库,唯一一处):按下 / 拖动只改浮层上的变量(边拖边预览),松手才写进隐藏输入(发出 input);
|
|
327
|
+
方向键:左右转色相、上下改饱和度,每按一下就写进去;明度滑块边拖边预览,松手写进去 */
|
|
328
|
+
function colorLive(p, o) {
|
|
329
|
+
if (S.menu) S.menu.hsl = o;
|
|
330
|
+
p.style.cssText = colorVars(o); const hex = hslHex(o), x = p.querySelector('#color-hex'), w = p.querySelector('.color-wheel');
|
|
331
|
+
if (x) x.value = hex; if (w) w.setAttribute('aria-valuetext', hex);
|
|
332
|
+
}
|
|
333
|
+
function colorCommit(p) { if (S.menu && S.menu.hsl) A.colorSet({ for: p.dataset.for, v: hslHex(S.menu.hsl), keep: true }); }
|
|
334
|
+
(function () {
|
|
335
|
+
let drag = null;
|
|
336
|
+
const at = function (w, e) {
|
|
337
|
+
const r = w.getBoundingClientRect(), dx = e.clientX - (r.left + r.width / 2), dy = e.clientY - (r.top + r.height / 2);
|
|
338
|
+
let hh = Math.atan2(dx, -dy) * 180 / Math.PI; if (hh < 0) hh += 360;
|
|
339
|
+
return { h: hh, s: Math.min(1, Math.hypot(dx, dy) / (r.width / 2)), l: S.menu && S.menu.hsl ? S.menu.hsl.l : 0.5 };
|
|
340
|
+
};
|
|
341
|
+
document.addEventListener('pointerdown', function (e) {
|
|
342
|
+
const w = e.target.closest && e.target.closest('.color-wheel'); if (!w || e.button) return;
|
|
343
|
+
drag = { w: w, p: w.closest('.color-pop') }; try { w.setPointerCapture(e.pointerId); } catch (err) { /* 有的浏览器不支持 */ }
|
|
344
|
+
w.focus({ preventScroll: true, focusVisible: false }); /* 方向键接着调;指针按下不画焦点环 */ colorLive(drag.p, at(w, e)); e.preventDefault();
|
|
345
|
+
});
|
|
346
|
+
document.addEventListener('pointermove', function (e) { if (drag) colorLive(drag.p, at(drag.w, e)); });
|
|
347
|
+
document.addEventListener('pointerup', function () { if (!drag) return; const d = drag; drag = null; colorCommit(d.p); });
|
|
348
|
+
document.addEventListener('input', function (e) { const t = e.target; if (!t.classList || !t.classList.contains('color-l') || !S.menu || !S.menu.hsl) return; colorLive(t.closest('.color-pop'), Object.assign({}, S.menu.hsl, { l: t.value / 100 })); });
|
|
349
|
+
document.addEventListener('change', function (e) { const t = e.target; if (t.classList && t.classList.contains('color-l')) colorCommit(t.closest('.color-pop')); });
|
|
350
|
+
KEY_FNS.push(function (e) {
|
|
351
|
+
const p = e.target.closest && e.target.closest('.color-pop'); if (!p || !/^Arrow/.test(e.key)) return false;
|
|
352
|
+
if (!e.target.classList.contains('color-wheel') || !S.menu || !S.menu.hsl) return true; /* 滑块和输入框自己处理方向键(不让菜单的上下键抢走) */
|
|
353
|
+
const o = Object.assign({}, S.menu.hsl), big = e.shiftKey ? 3 : 1;
|
|
354
|
+
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') o.h = (o.h + (e.key === 'ArrowRight' ? 5 : -5) * big + 360) % 360;
|
|
355
|
+
else o.s = Math.max(0, Math.min(1, o.s + (e.key === 'ArrowUp' ? 0.05 : -0.05) * big));
|
|
356
|
+
e.preventDefault(); colorLive(p, o); colorCommit(p); return true;
|
|
357
|
+
});
|
|
358
|
+
})();
|
|
359
|
+
function inp(id, val, ph, o) { o = o || {}; return '<input class="input' + (o.mono ? ' mono' : '') + '" id="' + id + '" value="' + h(val) + '" placeholder="' + h(ph || '') + '"' + (o.readonly ? ' readonly' : '') + (o.dirty === false ? '' : ' data-input="dirty"') + (o.style ? ' style="' + o.style + '"' : '') + '>'; }
|
|
360
|
+
/* 单选项:o.act 换成自己的动作(默认 radio),o.plain 标题不加粗 */
|
|
361
|
+
function opt(g, v, cur, title, sub, o = {}) {
|
|
362
|
+
const action = o.ro ? ' aria-readonly="true"' : ' tabindex="0" data-act="' + (o.act || 'radio') + '"' + (o.data || '');
|
|
363
|
+
return '<div class="opt" role="radio" aria-checked="' + (v === cur) + '" data-g="' + g + '" data-v="' + h(v) + '"' + action +
|
|
364
|
+
'><span class="radio"></span><div class="row-main"><div class="' + (o.plain ? 'u-w-normal ' : '') + 'row-title">' +
|
|
365
|
+
h(title) + '</div>' + (sub ? '<div class="row-sub">' + h(sub) + '</div>' : '') + '</div></div>';
|
|
366
|
+
}
|
|
367
|
+
/* 勾选框按钮:[框] 标签(标签是已经转义好的片段) */
|
|
368
|
+
function checkBox(on, label, act, data, disabled, ro) {
|
|
369
|
+
const tag = ro ? 'span' : 'button';
|
|
370
|
+
const action = ro ? ' aria-readonly="true"' : ' type="button" data-act="' + act + '"' + (data || '') + (disabled ? ' disabled' : '');
|
|
371
|
+
return '<' + tag + ' class="pdl-check" role="checkbox" aria-checked="' + (on === 'mixed' ? 'mixed' : !!on) +
|
|
372
|
+
'"' + action + '>' + checkInd() + label + '</' + tag + '>';
|
|
373
|
+
}
|
|
374
|
+
/* 单行输入框:o.mono 等宽、o.max 最长、o.disabled、o.input 输入时的处理(默认 pdlField) */
|
|
375
|
+
function textInput(id, val, ph, o) { o = o || {}; return '<input class="input' + (o.mono ? ' mono' : '') + '" id="' + id + '" value="' + h(val == null ? '' : val) + '" placeholder="' + h(ph || '') + '" data-input="' + (o.input || 'pdlField') + '"' + (o.max ? ' maxlength="' + o.max + '"' : '') + (o.disabled ? ' disabled' : '') + (o.type ? ' type="' + o.type + '"' : '') + (o.k != null ? ' data-k="' + h(o.k) + '"' : '') + '>'; }
|
|
376
|
+
/* 一个输入框(组件库,表单输入的唯一规则):回车提交,Esc 取消(声明了 cancel 时失焦也取消;没声明时 Esc 清空);
|
|
377
|
+
提交只有框里最后一个图标,框外不放“添加 / 保存 / 创建 / 取消”这类文字按钮。一个框里可以有几个输入(“听成 → 应为”),中间一个箭头;
|
|
378
|
+
提交前可以放一个框里的小件(选颜色)。提交的动作拿到 { 框上的参数…, v: 第一个输入的值, vals: 每个输入的值 }。
|
|
379
|
+
o = { id, value, placeholder, label, mono, list, listFrom, input, go, data(参数属性串), icon, goLabel, cancel, more: [{ id, value, placeholder, label, mono }], extra } */
|
|
380
|
+
function goField(o, addDraft) {
|
|
381
|
+
if (o.add) {
|
|
382
|
+
const open = !!S.folds['field:' + o.id], data = ' data-field="' + h(o.id) + '"';
|
|
383
|
+
return '<span class="field-add" data-add-field="' + h(o.id) + '" data-open="' + open + '">' +
|
|
384
|
+
btn(o.label || tc('common.add'), { iconOnly: true, icon: 'plus', act: 'fieldAddToggle', data: data + ' aria-expanded="' + open + '"' }) +
|
|
385
|
+
goField(Object.assign({}, o, { add: false, go: 'fieldAddCommit', cancel: 'fieldAddCancel', data: (o.data || '') + data + ' data-commit="' + h(o.go) + '"' }), true) + '</span>';
|
|
386
|
+
}
|
|
387
|
+
const one = function (x) {
|
|
388
|
+
/* 新增项的未绑定草稿只在输入节点里,旁边的行变化时复用该节点。 */
|
|
389
|
+
const keep = addDraft && x.id && x.value == null && !x.input ? ' data-island="field-draft:' + h(x.id) + '"' : '';
|
|
390
|
+
return '<input class="input' + (x.mono ? ' mono' : '') + '" id="' + h(x.id) + '" value="' + h(x.value == null ? '' : x.value) + '" placeholder="' + h(x.placeholder || '') + '" aria-label="' + h(x.label || x.placeholder || '') + '"' + keep + (x.list ? ' list="' + h(x.list) + '"' : '') + (x.input ? ' data-input="' + x.input + '"' : '') + ' data-on-enter="fieldGo" data-on-esc="fieldEsc"' + (o.cancel ? ' data-on-blur="fieldBlur"' : '') + ' autocomplete="off" spellcheck="false">';
|
|
391
|
+
};
|
|
392
|
+
return '<span class="ifield" data-go="' + h(o.go) + '"' + (o.cancel ? ' data-cancel="' + h(o.cancel) + '"' : '') + (o.data || '') + '>' + [o].concat(o.more || []).map(one).join('<span class="ifield-sep" aria-hidden="true">' + icon('right', 12) + '</span>') + (o.extra || '') +
|
|
393
|
+
btn(o.goLabel || tc('common.add'), { iconOnly: true, sm: true, icon: o.icon || 'check', act: 'fieldGo', cls: 'ifield-go' }) + '</span>' +
|
|
394
|
+
(o.list ? '<datalist id="' + h(o.list) + '">' + (o.listFrom || []).map(function (x) { return '<option value="' + h(x) + '">'; }).join('') + '</datalist>' : '');
|
|
395
|
+
}
|
|
396
|
+
/* 添加与编辑共用同一个输入框;加号只负责本地展开,不重画外层容器。 */
|
|
397
|
+
function fieldAddSet(id, open) {
|
|
398
|
+
S.folds['field:' + id] = open;
|
|
399
|
+
const input = document.getElementById(id), host = input && input.closest('.field-add');
|
|
400
|
+
if (!host) return;
|
|
401
|
+
localOpen(host, open, host.querySelector('[data-act="fieldAddToggle"]'));
|
|
402
|
+
if (open) input.focus(); else input.value = '';
|
|
403
|
+
}
|
|
404
|
+
A.fieldAddToggle = function (d) { fieldAddSet(d.field, !S.folds['field:' + d.field]); };
|
|
405
|
+
A.fieldAddCancel = function (d) { fieldAddSet(d.field, false); };
|
|
406
|
+
A.fieldAddCommit = function (d, el) { const out = actFn(d.commit)(d, el); Promise.resolve(out).then(function (ok) { if (ok !== false) fieldAddSet(d.field, false); }); return out; }; /* 提交(同步或异步)成功后才收起并清空;后端拒绝时草稿留着 */
|
|
407
|
+
function fieldError(p) { return '<div class="field-err" data-for="' + h(p.id) + '" role="alert">' + status('danger', p.text) + '</div>'; }
|
|
408
|
+
PDL_COMPONENTS.fieldError = function (p, sc, root) { return fieldError({ id: pv(p.id, sc, root), text: pv(p.text, sc, root) }); };
|
|
409
|
+
PDL_COMPONENTS.fieldError.catalog = { g: 'basics', props: { id: 'catalog-field', text: '$.sub' } };
|
|
410
|
+
function fieldErrSync() {
|
|
411
|
+
Object.keys(FIELD_ERR).forEach(function (id) {
|
|
412
|
+
const el = document.getElementById(id); if (!el) { delete FIELD_ERR[id]; return; }
|
|
413
|
+
(el.classList.contains('date-input') ? el.nextElementSibling : el).setAttribute('aria-invalid', 'true');
|
|
414
|
+
const host = el.closest('.ifield, .input-lead, .select-wrap, .date-field') || el, nx = host.nextElementSibling;
|
|
415
|
+
if (nx && nx.classList.contains('field-err') && nx.dataset.for === id) return;
|
|
416
|
+
host.insertAdjacentHTML('afterend', fieldError({ id: id, text: FIELD_ERR[id] }));
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
ENGINE_PARTS.fieldErr = fieldErrSync;
|
|
420
|
+
onRender(fieldErrSync);
|
|
421
|
+
document.addEventListener('input', function (e) {
|
|
422
|
+
const id = e.target && e.target.id; if (!id || !FIELD_ERR[id]) return;
|
|
423
|
+
delete FIELD_ERR[id];
|
|
424
|
+
(e.target.classList.contains('date-input') ? e.target.nextElementSibling : e.target).removeAttribute('aria-invalid');
|
|
425
|
+
const m = document.querySelector('.field-err[data-for="' + CSS.escape(id) + '"]'); if (m) m.remove();
|
|
426
|
+
});
|
|
427
|
+
/* 搜索框的放大镜就是“搜”:纯图标按钮(墨色,悬停变强调色)。在表单里就提交表单(回车也提交),不在表单里就把焦点放进框里;不另放“搜索”文字按钮 */
|
|
428
|
+
function searchGo() { return '<button type="button" class="search-go" data-act="searchGo" aria-label="' + h(tc('common.search')) + '" data-tip="' + h(tc('common.search')) + '">' + icon('search', 14) + '</button>'; }
|
|
429
|
+
A.searchGo = function (d, el) { const f = el.closest('form'), i = el.parentElement.querySelector('input'); if (f) f.requestSubmit(); else if (i) i.focus(); };
|
|
430
|
+
function search(id, ph, val, inputKey, cls) { return '<div class="search' + (cls ? ' ' + cls : '') + '">' + searchGo() + '<input class="input" id="' + id + '" placeholder="' + h(ph) + '" aria-label="' + h(ph) + '" value="' + h(val || '') + '"' + (inputKey ? ' data-input="' + inputKey + '"' : '') + '></div>'; }
|
|
431
|
+
/* 返回:唯一的画法(back 含义的图标 + 去处的名字);没有名字时只有图标,名字进 aria-label */
|
|
432
|
+
/* 缩略图单选的一项(组件库):一个小窗口(窄栏、侧栏、页面、一张卡片、强调色的一笔),颜色是数据(这套主题在某个外观下的几个值),写成 --u-* 交给样式。
|
|
433
|
+
thumb 给一份就是一个窗口;给两份就左右各半(自动 = 左浅右深)。下面是名字;当前项用标准的选中样式 */
|
|
434
|
+
function modeThumb(x, act, args, ro) {
|
|
435
|
+
const win = function (c) { const v = Object.assign({}, snapTokens(c.palette, c.mode), (themeVals(c.palette) || {})[c.mode] || {}); return '<span class="thumb-win" style="--u-rail:' + h(v['bg-rail']) + ';--u-nav:' + h(v['bg-nav']) + ';--u-page:' + h(v['bg-page']) + ';--u-group:' + h(v['bg-group']) + ';--u-fg:' + h(v['fg-muted']) + ';--u-accent:' + h(v.accent) + '"><i class="tw-rail"></i><i class="tw-nav"></i><i class="tw-page"><b class="tw-card"></b><b class="tw-dot"></b></i></span>'; };
|
|
436
|
+
const tag = ro ? 'span' : 'button';
|
|
437
|
+
const action = ro ? ' aria-readonly="true"' : ' type="button"' + actAttrs(act, Object.assign({}, args, { v: x.v }));
|
|
438
|
+
return '<' + tag + ' class="thumb-opt" role="radio" aria-checked="' + !!x.active + '"' + action +
|
|
439
|
+
'><span class="thumb' + (x.thumb.length > 1 ? ' split' : '') + '">' + x.thumb.map(win).join('') +
|
|
440
|
+
'</span><span class="thumb-l">' + h(tc('modeThumb.label', x.v)) + '</span></' + tag + '>';
|
|
441
|
+
}
|
|
442
|
+
function checkMark(on, act, data, label) { return '<button type="button" class="pdl-check" role="checkbox" aria-checked="' + !!on + '" aria-label="' + h(label || tc('common.select')) + '" data-act="' + act + '"' + (data || '') + '>' + checkInd() + '</button>'; } /* 只有方框的勾选:同一个勾选组件(pdl-check),不另画一种 */
|
|
443
|
+
PAINT_SYNC.push(selSync);
|
|
444
|
+
/* 没有绑定值的输入:草稿在应用的表单草稿里(状态路径 cs.f,按输入框 id) */
|
|
445
|
+
function pdlDraftValue(id) { return (pathGet('cs.f') || {})[id] || ''; }
|
|
446
|
+
function pdlDraftField(id, val, ph, o) { return textInput(id, val == null ? pdlDraftValue(id) : val, ph, o); }
|
|
447
|
+
function pdlSelectField(id, opts, cur, change) { return sel(id, opts, cur, { change: change || 'pdlSelectField', label: id }); }
|
|
448
|
+
function pdlRadioField(g, v, title, sub, ro) { return opt(g, v, (pathGet('cs.f') || {})['r-' + g], title, sub, { act: 'set', data: ' data-path="cs.f.r-' + h(g) + '"', plain: true, ro: ro }); }
|
|
449
|
+
|
|
450
|
+
/* 导出只带组件库登记的素材引用,用户自己的背景不属于主题。 */
|
|
451
|
+
/* 滑块边拖边更新:自己的数值,和同一个值的其他滑块(同 data-input + data-k)一起跟着动;提交仍在 change */
|
|
452
|
+
document.addEventListener('input', function (e) {
|
|
453
|
+
const r = e.target; if (!r.classList || !r.classList.contains('ws-range')) return;
|
|
454
|
+
const same = r.dataset.input && r.dataset.k ? document.querySelectorAll('.ws-range[data-input="' + r.dataset.input + '"][data-k="' + r.dataset.k + '"]') : [r];
|
|
455
|
+
Array.prototype.forEach.call(same, function (x) { if (x !== r) x.value = r.value; const o = x.id && document.getElementById(x.id + '-o'); if (o) o.textContent = r.value + (x.dataset.unit || ''); });
|
|
456
|
+
}, true);
|
|
457
|
+
|
|
458
|
+
/* ───────── 表单里的两个编辑器(组件库) ─────────
|
|
459
|
+
chipBox:可增删的一组标签(@ 名字、擅长标签、额外参数);表单里改的是草稿(重画),弹窗里直接改 DOM。
|
|
460
|
+
kvEditor:键值对(环境变量、标头)或一列值(参数);值可以掩码、可以显示;只读时只列出键名 */
|
|
461
|
+
/* 标签编辑器(组件库唯一一个):一排标签 + 同一排里加一项的输入框。chips 是画好的标签;id / kind / k:一列字的编辑器(chipAdd / chipDel 按它们找数据) */
|
|
462
|
+
function tagEditor(o) {
|
|
463
|
+
return '<div class="chips tag-ed"' + (o.id ? ' id="' + h(o.id) + '" data-kind="' + h(o.kind || '') + '" data-k="' + h(o.k || '') + '"' : '') + '>' + (o.chips.length ? o.chips.join('') : o.empty ? '<span class="faint chip-empty">' + h(o.empty) + '</span>' : '') + (o.field || '') + '</div>';
|
|
464
|
+
}
|
|
465
|
+
function chipBox(id, vals, o, renderValues) {
|
|
466
|
+
o = o || {};
|
|
467
|
+
const ed = argAttrs({ for: id, kind: o.kind || '', k: o.k || '' }); /* 增删的动作拿到的参数:哪个编辑器(for)、哪种值(kind)、草稿里的哪一格(k)、哪一项(v)——动作不回头读页面 */
|
|
468
|
+
const draw = function (v) { return chipHtml({ label: h(v), attrs: ' data-v="' + h(v) + '"', x: o.lock && o.lock === v ? '' : chipX('chipDel', ed + argAttrs({ v: v }), tc('chip.remove', v)) }); };
|
|
469
|
+
return tagEditor({ id: id, kind: o.kind, k: o.k, empty: o.empty || tc('chip.empty'), chips: renderValues ? renderValues(vals, draw, [ed, o.lock]) : vals.map(draw),
|
|
470
|
+
field: goField({ add: true, id: id + '-in', placeholder: o.ph || tc('common.add'), label: o.label || tc('common.add'), go: 'chipAdd', data: ed, goLabel: tc('common.add') }) }); /* 加一项:回车或框尾的勾号提交(表单输入的唯一规则) */
|
|
471
|
+
}
|
|
472
|
+
function kvEditor(o) {
|
|
473
|
+
/* path:草稿在状态里的位置(通用动作 listOp / toggle 用;增删是 listOp,显示 / 隐藏值是 toggle 这一行的第 3 格) */
|
|
474
|
+
const P = function (p) { return o.path ? ' data-path="' + h(p) + '"' + (o.single ? '' : ' data-shape="pair"') : ''; };
|
|
475
|
+
const A = function (a, extra, p) { return ' data-act="' + a + '" data-l="' + h(o.key) + '"' + P(p || o.path) + (extra || ''); };
|
|
476
|
+
if (o.ro) return o.rows.length ? '<span class="chips">' + o.rows.map(function (r) { return chipHtml({ cls: 'mono', label: h(o.single ? r.v : r.k) }); }).join('') + '</span>' : '<span class="muted">' + h(o.empty || tc('common.none')) + '</span>';
|
|
477
|
+
const inp = function (key, val, ph, extra) { return '<input class="input mono" data-draft="' + key + '"' + (o.input ? ' data-input="' + o.input + '"' : '') + ' value="' + h(val) + '" placeholder="' + h(ph || '') + '"' + (extra || '') + '>'; };
|
|
478
|
+
return '<div class="cap-kvs">' + o.rows.map(function (r, i) {
|
|
479
|
+
const del = btn(tc(o.single ? 'kv.deleteItem' : 'kv.deleteRow'), { sm: true, iconOnly: true, icon: 'delete', data: A(o.del, ' data-i="' + i + '" data-op="del"') });
|
|
480
|
+
if (o.single) return '<div class="cap-kv cap-arg">' + inp(o.key + ':' + i, r.v, r.ph, ' aria-label="' + h(tc('kv.itemN', i + 1)) + '"') + del + '</div>';
|
|
481
|
+
return '<div class="cap-kv">' + inp(o.key + ':' + i + ':k', r.k, o.keyPh || tc('kv.key'), ' aria-label="' + h(tc('kv.key')) + '"') + '<div class="cap-pw">' + inp(o.key + ':' + i + ':v', r.v, r.ph || tc('kv.value'), ' type="' + (r.show ? 'text' : 'password') + '" aria-label="' + h(tc('kv.valueOf', r.k)) + '"') +
|
|
482
|
+
btn(tc(r.show ? 'kv.hide' : 'kv.show'), { sm: true, iconOnly: true, icon: 'eye', data: A(o.eye, ' data-i="' + i + '"', o.path + '.' + i + '.2'), pressed: !!r.show }) + '</div>' + del + '</div>';
|
|
483
|
+
}).join('') + btn(o.add, { sm: true, icon: 'plus', act: o.del, data: ' data-l="' + h(o.key) + '" data-op="add"' + P(o.path) }) + '</div>';
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/* ───────── 多行输入:按内容长高(grow)、同行补全(complete)─────────
|
|
487
|
+
grow:浏览器按内容定高度(CSS field-sizing: content,见 core.css),最少 --ta-rows-min 行、最多 --ta-rows-max 行,再多就在框里滚动;不量、不改 style。
|
|
488
|
+
complete:候选里第一条以已输入内容开头的(至少输入了 2 个字、光标在末尾),剩下的部分淡色接在已输入的字后面(同一行);
|
|
489
|
+
Tab / → 采纳,接着打字就覆盖掉。都是组件自己的本地行为:打字不重画 */
|
|
490
|
+
const TA_COMPLETE = {}, TA_GHOST_CSS = {};
|
|
491
|
+
/* 覆盖层和输入框同一套排版:已输入的字透明占位,只露出后面的淡色部分。排版抄成一条按输入框 id 的样式规则(组件自己的样式表),
|
|
492
|
+
不写在覆盖层的 style 上——重画会把元素的属性换回声明的样子;每次更新补全时重抄(输入框的内边距可能随状态变) */
|
|
493
|
+
function taGhostStyle(ta) {
|
|
494
|
+
const cs = getComputedStyle(ta), pad = ['Top', 'Right', 'Bottom', 'Left'].map(function (d) { return (parseFloat(cs['padding' + d]) + parseFloat(cs['border' + d + 'Width'])) + 'px'; }).join(' '); /* 覆盖层没有边框:输入框的边框宽度算进内边距 */
|
|
495
|
+
const rule = '.ta-wrap:has(> #' + CSS.escape(ta.id) + ') > .ta-ghost { font-family: ' + cs.fontFamily + '; font-size: ' + cs.fontSize + '; font-weight: ' + cs.fontWeight + '; font-style: ' + cs.fontStyle + '; line-height: ' + cs.lineHeight + '; letter-spacing: ' + cs.letterSpacing + '; text-indent: ' + cs.textIndent + '; white-space: ' + cs.whiteSpace + '; word-break: ' + cs.wordBreak + '; overflow-wrap: ' + cs.overflowWrap + '; padding: ' + pad + '; }';
|
|
496
|
+
if (TA_GHOST_CSS[ta.id] === rule) return;
|
|
497
|
+
TA_GHOST_CSS[ta.id] = rule;
|
|
498
|
+
let st = document.getElementById('ta-ghost-css'); if (!st) { st = document.createElement('style'); st.id = 'ta-ghost-css'; document.head.appendChild(st); }
|
|
499
|
+
st.textContent = Object.keys(TA_GHOST_CSS).map(function (k) { return TA_GHOST_CSS[k]; }).join('\n');
|
|
500
|
+
}
|
|
501
|
+
function taGhost(ta) {
|
|
502
|
+
const g = ta.parentElement && ta.parentElement.querySelector(':scope > .ta-ghost'); if (!g) return;
|
|
503
|
+
const list = TA_COMPLETE[ta.id] || [], v = ta.value, end = ta.selectionStart === v.length && ta.selectionEnd === v.length;
|
|
504
|
+
const hit = v.length >= 2 && end ? list.find(function (x) { return typeof x === 'string' && x.indexOf(v) === 0 && x.length > v.length; }) || '' : '';
|
|
505
|
+
taGhostStyle(ta);
|
|
506
|
+
g.children[0].textContent = v; g.children[1].textContent = hit ? hit.slice(v.length) : '';
|
|
507
|
+
if (hit) ta.dataset.ghost = hit; else delete ta.dataset.ghost; /* 滚动对齐交给下面的 scroll 监听:打字时不读 scrollTop(读它会让整页先排一次版) */
|
|
508
|
+
}
|
|
509
|
+
document.addEventListener('input', function (e) { const t = e.target; if (t && t.tagName === 'TEXTAREA' && TA_COMPLETE[t.id]) taGhost(t); }, true);
|
|
510
|
+
document.addEventListener('selectionchange', function () { const t = document.activeElement; if (t && t.tagName === 'TEXTAREA' && TA_COMPLETE[t.id]) taGhost(t); });
|
|
511
|
+
document.addEventListener('scroll', function (e) { const t = e.target; if (t && t.tagName === 'TEXTAREA') { const g = t.parentElement.querySelector(':scope > .ta-ghost'); if (g) g.scrollTop = t.scrollTop; } }, true);
|
|
512
|
+
KEY_FNS.push(function (e) {
|
|
513
|
+
const t = e.target; if (!t || t.tagName !== 'TEXTAREA' || !t.dataset.ghost || e.isComposing || (e.key !== 'Tab' && e.key !== 'ArrowRight') || e.shiftKey || e.metaKey || e.ctrlKey || e.altKey) return false;
|
|
514
|
+
if (t.selectionStart !== t.value.length || t.selectionEnd !== t.value.length || document.querySelector('.pop-host')) return false; /* 开着弹层时 Tab 是选候选(弹层自己的键) */
|
|
515
|
+
e.preventDefault(); t.value = t.dataset.ghost; t.setSelectionRange(t.value.length, t.value.length); t.dispatchEvent(new Event('input', { bubbles: true }));
|
|
516
|
+
return true;
|
|
517
|
+
});
|
|
518
|
+
treeMatch('.ta-wrap > textarea', taGhost);
|
|
519
|
+
/* ───────── 目录登记:这个文件里的组件 ───────── */
|
|
520
|
+
Object.assign(LIB_CATALOG, {
|
|
521
|
+
colorCtl: { g: 'basics', inline: true, via: [], ex: function (s) { return colorCtl({ id: 'cat-col', value: s.color.value, label: s.color.label }); } }, /* 取色:组件库原件(PDL 的 color 控件也画它:成员的代表色) */
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
/* Paint draft marks and a read-only suffix below the native text input. */
|
|
525
|
+
function draftMirror(el) { return el.parentElement.querySelector(':scope > .hl-compose-mirror'); }
|
|
526
|
+
function draftMirrorScroll(el, mirror) {
|
|
527
|
+
if (mirror.hasAttribute('data-preview')) return;
|
|
528
|
+
mirror.scrollTop = el.scrollTop;
|
|
529
|
+
mirror.scrollLeft = el.scrollLeft;
|
|
530
|
+
}
|
|
531
|
+
function draftMirrorSize(el, mirror) {
|
|
532
|
+
const style = getComputedStyle(el);
|
|
533
|
+
const props = ['fontFamily', 'fontSize', 'fontWeight', 'fontStyle', 'lineHeight', 'letterSpacing', 'wordSpacing', 'tabSize',
|
|
534
|
+
'textIndent', 'textAlign', 'direction', 'textTransform', 'whiteSpace', 'wordBreak', 'overflowWrap', 'padding'];
|
|
535
|
+
props.forEach(function (key) { mirror.style[key] = style[key]; });
|
|
536
|
+
if (mirror.hasAttribute('data-preview')) {
|
|
537
|
+
for (const property of ['top', 'left', 'width', 'height']) mirror.style.removeProperty(property);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
mirror.style.top = el.offsetTop + el.clientTop + 'px';
|
|
541
|
+
mirror.style.left = el.offsetLeft + el.clientLeft + 'px';
|
|
542
|
+
mirror.style.width = el.clientWidth + 'px';
|
|
543
|
+
mirror.style.height = el.clientHeight + 'px';
|
|
544
|
+
draftMirrorScroll(el, mirror);
|
|
545
|
+
}
|
|
546
|
+
function paintDraftMirror(el, marks, preview = '') {
|
|
547
|
+
const text = el.value;
|
|
548
|
+
let mirror = draftMirror(el);
|
|
549
|
+
const hadPreview = !!mirror?.hasAttribute('data-preview');
|
|
550
|
+
const parent = el.parentElement;
|
|
551
|
+
if (!marks.length && !preview) {
|
|
552
|
+
const top = hadPreview ? parent.scrollTop : 0;
|
|
553
|
+
mirror?.remove();
|
|
554
|
+
if (hadPreview) el.scrollTop = top;
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
let start = 0, html = '';
|
|
558
|
+
for (const m of marks) {
|
|
559
|
+
const kind = m.kind ? ' data-kind="' + h(m.kind) + '"' : '';
|
|
560
|
+
const style = m.kind === 'mention' ? ' style="--mention-c:' + h(m.color || 'var(--accent)') + '"' : '';
|
|
561
|
+
html += h(text.slice(start, m.start)) + '<mark' + kind + style + '>' + h(text.slice(m.start, m.end)) + '</mark>';
|
|
562
|
+
start = m.end;
|
|
563
|
+
}
|
|
564
|
+
html += h(text.slice(start));
|
|
565
|
+
if (preview) {
|
|
566
|
+
const gap = text && !/\s$/.test(text) ? ' ' : '';
|
|
567
|
+
html += '<span class="hl-compose-preview">' + h(gap + preview) + '</span>';
|
|
568
|
+
} else if (text.endsWith('\n')) html += '\u200b';
|
|
569
|
+
if (mirror?._hlMarkup === html) return;
|
|
570
|
+
const viewport = hadPreview ? parent : el;
|
|
571
|
+
const top = preview || hadPreview ? viewport.scrollTop : 0;
|
|
572
|
+
const startsAtEnd = !hadPreview && (document.activeElement !== el || el.selectionEnd === text.length);
|
|
573
|
+
const follow = !!preview && (startsAtEnd || top + viewport.clientHeight >= viewport.scrollHeight - 2);
|
|
574
|
+
const needsSize = !mirror || hadPreview !== !!preview;
|
|
575
|
+
if (!mirror) {
|
|
576
|
+
mirror = document.createElement('div');
|
|
577
|
+
mirror.className = 'hl-compose-mirror';
|
|
578
|
+
mirror.setAttribute('aria-hidden', 'true');
|
|
579
|
+
el.before(mirror);
|
|
580
|
+
}
|
|
581
|
+
mirror.toggleAttribute('data-preview', !!preview);
|
|
582
|
+
mirror._hlMarkup = html;
|
|
583
|
+
mirror.innerHTML = html;
|
|
584
|
+
if (needsSize) draftMirrorSize(el, mirror);
|
|
585
|
+
if (preview) {
|
|
586
|
+
if (follow) parent.scrollTop = parent.scrollHeight;
|
|
587
|
+
else if (!hadPreview) parent.scrollTop = top;
|
|
588
|
+
} else {
|
|
589
|
+
if (hadPreview) el.scrollTop = top;
|
|
590
|
+
draftMirrorScroll(el, mirror);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/* ───────── 原地编辑(组件库唯一一套单行原地编辑能力) ─────────
|
|
595
|
+
用于对话栏标题、列表行、树行、分组头、配置自定义数值等原位改名 / 单值输入。
|
|
596
|
+
- 键级响应(INLINE_EDIT):只重画进入 / 退出编辑的单个节点,不波及兄弟行
|
|
597
|
+
- Enter 或 blur 自动保存;Esc 取消并恢复原值(不触发 blur 二次提交)
|
|
598
|
+
- 空值不保存并恢复原值;无变更不发请求;异步保存防重入,失败还原原值
|
|
599
|
+
- 指针在框外按下引发 blur 时延至 pointerup 后提交重画,避免同步销毁相邻按钮吞掉点击 */
|
|
600
|
+
const INLINE_EDIT = pdlKeyed('inlineEdit');
|
|
601
|
+
const INLINE_EDIT_DECL = {};
|
|
602
|
+
let INLINE_EDIT_CUR = null;
|
|
603
|
+
let INLINE_EDIT_POINTER_OUT = false;
|
|
604
|
+
let INLINE_EDIT_PENDING_COMMIT = null;
|
|
605
|
+
|
|
606
|
+
function inlineEditId(key) {
|
|
607
|
+
return 'ie-' + String(key).replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
608
|
+
}
|
|
609
|
+
function inlineEditState(key) {
|
|
610
|
+
return key ? INLINE_EDIT.get(String(key)) || null : null;
|
|
611
|
+
}
|
|
612
|
+
function inlineEditReg(spec) {
|
|
613
|
+
if (!spec || !spec.key) return null;
|
|
614
|
+
const k = String(spec.key);
|
|
615
|
+
INLINE_EDIT_DECL[k] = Object.assign({ key: k }, spec);
|
|
616
|
+
return INLINE_EDIT_DECL[k];
|
|
617
|
+
}
|
|
618
|
+
function inlineEditClear(cur) {
|
|
619
|
+
if (!cur) return;
|
|
620
|
+
cur.done = true;
|
|
621
|
+
if (INLINE_EDIT_CUR === cur) INLINE_EDIT_CUR = null;
|
|
622
|
+
if (INLINE_EDIT.peek(cur.key) === cur) INLINE_EDIT.delete(cur.key);
|
|
623
|
+
}
|
|
624
|
+
function inlineEditFocus(cur) {
|
|
625
|
+
const el = document.getElementById(cur.id);
|
|
626
|
+
if (!el) return false;
|
|
627
|
+
el.focus();
|
|
628
|
+
if (el.setSelectionRange && el.type !== 'number') {
|
|
629
|
+
const v = el.value || '';
|
|
630
|
+
if (cur.selectStem) {
|
|
631
|
+
const dot = v.lastIndexOf('.');
|
|
632
|
+
if (dot > 0) { el.setSelectionRange(0, dot); return true; }
|
|
633
|
+
}
|
|
634
|
+
el.setSelectionRange(0, v.length);
|
|
635
|
+
} else if (el.select) {
|
|
636
|
+
try { el.select(); } catch (_err) { /* ignore */ }
|
|
637
|
+
}
|
|
638
|
+
return true;
|
|
639
|
+
}
|
|
640
|
+
function inlineEditOpen(keyOrSpec, overrides) {
|
|
641
|
+
const base = typeof keyOrSpec === 'string' ? INLINE_EDIT_DECL[keyOrSpec] : keyOrSpec;
|
|
642
|
+
const spec = base ? Object.assign({}, base, overrides || {}) : (overrides && typeof keyOrSpec === 'string' ? Object.assign({ key: keyOrSpec }, overrides) : null);
|
|
643
|
+
if (!spec || !spec.key) return false;
|
|
644
|
+
const key = String(spec.key);
|
|
645
|
+
if (INLINE_EDIT_PENDING_COMMIT) {
|
|
646
|
+
const pending = INLINE_EDIT_PENDING_COMMIT;
|
|
647
|
+
INLINE_EDIT_PENDING_COMMIT = null;
|
|
648
|
+
pending();
|
|
649
|
+
}
|
|
650
|
+
if (INLINE_EDIT_CUR && INLINE_EDIT_CUR.key !== key) {
|
|
651
|
+
inlineEditClear(INLINE_EDIT_CUR);
|
|
652
|
+
}
|
|
653
|
+
const initial = spec.value == null ? '' : String(spec.value);
|
|
654
|
+
const cur = {
|
|
655
|
+
key: key,
|
|
656
|
+
id: inlineEditId(key),
|
|
657
|
+
original: initial,
|
|
658
|
+
value: initial,
|
|
659
|
+
act: spec.act || '',
|
|
660
|
+
args: spec.args || {},
|
|
661
|
+
label: spec.label || tc('common.rename'),
|
|
662
|
+
max: spec.max || 200,
|
|
663
|
+
inputType: spec.inputType || 'text',
|
|
664
|
+
selectStem: !!spec.selectStem,
|
|
665
|
+
alwaysSave: !!spec.alwaysSave,
|
|
666
|
+
saving: false,
|
|
667
|
+
done: false
|
|
668
|
+
};
|
|
669
|
+
if (S.menu) S.menu = null;
|
|
670
|
+
INLINE_EDIT_CUR = cur;
|
|
671
|
+
INLINE_EDIT.set(key, cur);
|
|
672
|
+
render(true);
|
|
673
|
+
const mounted = typeof document !== 'undefined' && document.body && document.body.children && document.body.children.length > 0;
|
|
674
|
+
if (!inlineEditFocus(cur) && mounted) {
|
|
675
|
+
inlineEditClear(cur);
|
|
676
|
+
render(true);
|
|
677
|
+
return false;
|
|
678
|
+
}
|
|
679
|
+
return true;
|
|
680
|
+
}
|
|
681
|
+
function inlineEditInput(o) {
|
|
682
|
+
const st = o.state || inlineEditState(o.key);
|
|
683
|
+
if (!st) return '';
|
|
684
|
+
const type = st.inputType || o.inputType || 'text';
|
|
685
|
+
const max = st.max || o.max || 200;
|
|
686
|
+
const cls = 'input inline-edit-input' + (o.cls ? ' ' + o.cls : '') + (st.saving ? ' saving' : '');
|
|
687
|
+
return '<input class="' + cls + '" id="' + h(st.id) + '" type="' + h(type) + '" value="' + h(st.value) + '"' +
|
|
688
|
+
(type === 'text' ? ' maxlength="' + h(String(max)) + '"' : '') +
|
|
689
|
+
' aria-label="' + h(st.label || o.label || tc('common.rename')) + '"' +
|
|
690
|
+
' data-ie-key="' + h(st.key) + '" data-input="inlineEditInput" data-on-enter="inlineEditCommit" data-on-esc="inlineEditCancel" data-on-blur="inlineEditBlur"' +
|
|
691
|
+
(st.saving ? ' readonly' : '') + ' autocomplete="off" spellcheck="false">';
|
|
692
|
+
}
|
|
693
|
+
function inlineEditFail(err) {
|
|
694
|
+
toast(err && err.i18n && typeof tcText === 'function' ? tcText(err.i18n, err.message) : String((err && err.message) || err));
|
|
695
|
+
}
|
|
696
|
+
function inlineEditFinish(cur, rawValue) {
|
|
697
|
+
if (!cur || cur.done || cur.saving) return;
|
|
698
|
+
cur.done = true;
|
|
699
|
+
if (INLINE_EDIT_CUR === cur) INLINE_EDIT_CUR = null;
|
|
700
|
+
const trimmed = String(rawValue == null ? cur.value : rawValue).trim();
|
|
701
|
+
const original = String(cur.original == null ? '' : cur.original).trim();
|
|
702
|
+
if (!trimmed || (!cur.alwaysSave && trimmed === original)) {
|
|
703
|
+
if (INLINE_EDIT.peek(cur.key) === cur) INLINE_EDIT.delete(cur.key);
|
|
704
|
+
render(true);
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
const fn = cur.act && actFn(cur.act);
|
|
708
|
+
if (!fn) {
|
|
709
|
+
if (INLINE_EDIT.peek(cur.key) === cur) INLINE_EDIT.delete(cur.key);
|
|
710
|
+
render(true);
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
cur.saving = true;
|
|
714
|
+
cur.value = trimmed;
|
|
715
|
+
let out;
|
|
716
|
+
try {
|
|
717
|
+
out = fn(Object.assign({}, cur.args, { v: trimmed }));
|
|
718
|
+
} catch (err) {
|
|
719
|
+
if (INLINE_EDIT.peek(cur.key) === cur) INLINE_EDIT.delete(cur.key);
|
|
720
|
+
render(true);
|
|
721
|
+
inlineEditFail(err);
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
if (out && typeof out.then === 'function') {
|
|
725
|
+
return Promise.resolve(out).then(function () {
|
|
726
|
+
if (INLINE_EDIT.peek(cur.key) === cur) INLINE_EDIT.delete(cur.key);
|
|
727
|
+
render(true);
|
|
728
|
+
}, function (err) {
|
|
729
|
+
if (INLINE_EDIT.peek(cur.key) === cur) INLINE_EDIT.delete(cur.key);
|
|
730
|
+
render(true);
|
|
731
|
+
inlineEditFail(err);
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
if (INLINE_EDIT.peek(cur.key) === cur) INLINE_EDIT.delete(cur.key);
|
|
735
|
+
render(true);
|
|
736
|
+
return out;
|
|
737
|
+
}
|
|
738
|
+
document.addEventListener('pointerdown', function (e) {
|
|
739
|
+
if (!INLINE_EDIT_CUR || INLINE_EDIT_CUR.done) { INLINE_EDIT_POINTER_OUT = false; return; }
|
|
740
|
+
const input = document.getElementById(INLINE_EDIT_CUR.id);
|
|
741
|
+
INLINE_EDIT_POINTER_OUT = !!(input && !input.contains(e.target));
|
|
742
|
+
}, true);
|
|
743
|
+
function inlineEditFlushPointer() {
|
|
744
|
+
INLINE_EDIT_POINTER_OUT = false;
|
|
745
|
+
const fn = INLINE_EDIT_PENDING_COMMIT;
|
|
746
|
+
INLINE_EDIT_PENDING_COMMIT = null;
|
|
747
|
+
if (fn) setTimeout(fn, 0);
|
|
748
|
+
}
|
|
749
|
+
document.addEventListener('pointerup', inlineEditFlushPointer, true);
|
|
750
|
+
document.addEventListener('pointercancel', inlineEditFlushPointer, true);
|
|
751
|
+
NAV_RESET.push(function (o) {
|
|
752
|
+
if (o && o.popupsOnly) return;
|
|
753
|
+
if (INLINE_EDIT_PENDING_COMMIT) {
|
|
754
|
+
const fn = INLINE_EDIT_PENDING_COMMIT;
|
|
755
|
+
INLINE_EDIT_PENDING_COMMIT = null;
|
|
756
|
+
fn();
|
|
757
|
+
} else if (INLINE_EDIT_CUR && !INLINE_EDIT_CUR.done) {
|
|
758
|
+
inlineEditClear(INLINE_EDIT_CUR);
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
INPUTS.inlineEditInput = function (e) {
|
|
762
|
+
const key = e.target && e.target.dataset && e.target.dataset.ieKey;
|
|
763
|
+
const cur = key ? INLINE_EDIT.peek(key) : null;
|
|
764
|
+
if (cur && !cur.done && !cur.saving) cur.value = e.target.value;
|
|
765
|
+
};
|
|
766
|
+
Object.assign(A, {
|
|
767
|
+
inlineEditStart: function (d) {
|
|
768
|
+
if (d && d.key) inlineEditOpen(d.key);
|
|
769
|
+
},
|
|
770
|
+
inlineEditCommit: function (d, el) {
|
|
771
|
+
const key = (el && el.dataset && el.dataset.ieKey) || (d && d.key);
|
|
772
|
+
const cur = key ? INLINE_EDIT.peek(key) : INLINE_EDIT_CUR;
|
|
773
|
+
if (!cur || cur.done || cur.saving) return false;
|
|
774
|
+
INLINE_EDIT_PENDING_COMMIT = null;
|
|
775
|
+
INLINE_EDIT_POINTER_OUT = false;
|
|
776
|
+
inlineEditFinish(cur, el ? el.value : cur.value);
|
|
777
|
+
return true;
|
|
778
|
+
},
|
|
779
|
+
inlineEditCancel: function (d, el) {
|
|
780
|
+
const key = (el && el.dataset && el.dataset.ieKey) || (d && d.key);
|
|
781
|
+
const cur = key ? INLINE_EDIT.peek(key) : INLINE_EDIT_CUR;
|
|
782
|
+
if (!cur || cur.done) return false;
|
|
783
|
+
INLINE_EDIT_PENDING_COMMIT = null;
|
|
784
|
+
INLINE_EDIT_POINTER_OUT = false;
|
|
785
|
+
inlineEditClear(cur);
|
|
786
|
+
render(true);
|
|
787
|
+
return true;
|
|
788
|
+
},
|
|
789
|
+
inlineEditBlur: function (d, el) {
|
|
790
|
+
const key = (el && el.dataset && el.dataset.ieKey) || (d && d.key);
|
|
791
|
+
const cur = key ? INLINE_EDIT.peek(key) : INLINE_EDIT_CUR;
|
|
792
|
+
if (!cur || cur.done || cur.saving) return false;
|
|
793
|
+
const valNow = el ? el.value : cur.value;
|
|
794
|
+
if (INLINE_EDIT_POINTER_OUT) {
|
|
795
|
+
INLINE_EDIT_PENDING_COMMIT = function () { inlineEditFinish(cur, valNow); };
|
|
796
|
+
return true;
|
|
797
|
+
}
|
|
798
|
+
inlineEditFinish(cur, valNow);
|
|
799
|
+
return true;
|
|
800
|
+
}
|
|
801
|
+
});
|