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,727 @@
|
|
|
1
|
+
/* The single schema-driven configuration form model. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const CF_STATES = new Map();
|
|
5
|
+
const CF_TRACK = typeof pdlTrack === 'function' ? pdlTrack({ rev: 0 }, 'CF') : { rev: 0 };
|
|
6
|
+
function cfTouch() { CF_TRACK.rev++; }
|
|
7
|
+
const pcfText = function (value) { return value == null ? '' : Array.isArray(value) ? JSON.stringify(value) : String(value); };
|
|
8
|
+
const pcfId = function (name, key) { return 'pcf-' + name + '-' + key.replaceAll('#', '-'); };
|
|
9
|
+
|
|
10
|
+
function pcfEffective(field, draft) {
|
|
11
|
+
return ((field.readonly ? undefined : draft[field.key]) ?? field.currentValue) || pcfText(field.default);
|
|
12
|
+
}
|
|
13
|
+
function pcfFields(state) {
|
|
14
|
+
const fields = state.detail.configFields, variants = state.detail.configurationVariants;
|
|
15
|
+
const values = Object.fromEntries(fields.map(function (field) { return [field.key, pcfEffective(field, state.draft) || undefined]; }));
|
|
16
|
+
const active = variants && oneOfKeys(fields.map(function (field) { return field.key; }), variants, values);
|
|
17
|
+
return fields.filter(function (field) { return !field.hidden && (!active || active[field.key]); });
|
|
18
|
+
}
|
|
19
|
+
function pcfRequired(field, valueOf) {
|
|
20
|
+
if (!field.requiredWhen) return !!field.required;
|
|
21
|
+
const actual = valueOf(field.requiredWhen.key);
|
|
22
|
+
return actual !== '' && actual != null && [field.requiredWhen.value].flat().some(function (value) { return String(value) === String(actual); });
|
|
23
|
+
}
|
|
24
|
+
function pcfTopRequired(state, field) {
|
|
25
|
+
if (field.requiredWhen) {
|
|
26
|
+
const ref = state.fields.get(field.requiredWhen.key);
|
|
27
|
+
if (!ref) return !!field.requiredNow;
|
|
28
|
+
if (ref.kind === 'secret' && ref.currentValue && !Object.hasOwn(state.draft, ref.key)) return !!field.requiredNow;
|
|
29
|
+
}
|
|
30
|
+
return pcfRequired(field, function (key) {
|
|
31
|
+
const ref = state.fields.get(key);
|
|
32
|
+
return ref ? pcfEffective(ref, state.draft) : undefined;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function pcfUpdates(state) {
|
|
36
|
+
return Object.fromEntries(pcfFields(state).flatMap(function (field) {
|
|
37
|
+
if (field.readonly || (field.managedBy && !field.managedCall) || field.kind === 'operation') return [];
|
|
38
|
+
if (field.kind === 'map') {
|
|
39
|
+
if (!pcfMapDirty(state, field)) return [];
|
|
40
|
+
return [[field.key, JSON.stringify(pcfMapAssemble(state.mapRows.get(field.key)))]];
|
|
41
|
+
}
|
|
42
|
+
const value = state.draft[field.key];
|
|
43
|
+
return value !== undefined && value !== pcfEffective(field, {}) ? [[field.key, value || null]] : [];
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
function pcfDirty(name) {
|
|
47
|
+
const state = CF_STATES.get(name);
|
|
48
|
+
return !!state && Object.keys(pcfUpdates(state)).length > 0;
|
|
49
|
+
}
|
|
50
|
+
function pcfReset(name) { CF_STATES.delete(name); }
|
|
51
|
+
function pcfResetPrefix(prefix) {
|
|
52
|
+
CF_STATES.forEach(function (_state, key) { if (key.startsWith(prefix)) CF_STATES.delete(key); });
|
|
53
|
+
}
|
|
54
|
+
formDraft('cf', {
|
|
55
|
+
dirty: function () {
|
|
56
|
+
return Array.from(document.querySelectorAll('form[data-form="cf"]')).some(function (form) { return pcfDirty(form.dataset.p || form.dataset.scope); });
|
|
57
|
+
},
|
|
58
|
+
drop: function () { CF_STATES.clear(); }
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
function pcfRows(state, field) {
|
|
62
|
+
return JSON.parse(pcfEffective(field, state.draft) || '[]');
|
|
63
|
+
}
|
|
64
|
+
function pcfCell(row, field) {
|
|
65
|
+
return Object.hasOwn(row, field.key) ? row[field.key] : field.default;
|
|
66
|
+
}
|
|
67
|
+
function pcfControl(row, raw, field, mapItems) {
|
|
68
|
+
return Object.assign(row, {
|
|
69
|
+
value: field.kind === 'boolean' ? raw === 'true' : raw,
|
|
70
|
+
options: field.options || [],
|
|
71
|
+
suggestions: field.suggestions || [],
|
|
72
|
+
presets: field.presets || [],
|
|
73
|
+
unit: field.unit,
|
|
74
|
+
items: field.kind === 'list' ? JSON.parse(raw || '[]') : field.kind === 'map' ? (mapItems || pcfMapParse(raw)) : undefined
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function pcfRow(state, field, key, raw, req) {
|
|
78
|
+
const mapItems = field.kind === 'map' && state.fields.get(key) === field
|
|
79
|
+
? pcfMapRows(state, key).map(function (r) { return { k: r.k, v: r.v, show: !!r.show }; })
|
|
80
|
+
: undefined;
|
|
81
|
+
return pcfControl({ key: key, id: pcfId(state.detail.name, key), kind: field.kind, label: field.label,
|
|
82
|
+
desc: field.description, req: req, readonly: !!field.readonly, err: state.errors[key] || field.error,
|
|
83
|
+
refreshAction: field.refreshAction, refreshBusy: !!field.refreshBusy, refreshLabel: field.refreshLabel, refreshTip: field.refreshTip,
|
|
84
|
+
hasSuggestions: Array.isArray(field.suggestions), placeholder: field.placeholder || pcfText(field.inherited) }, raw, field, mapItems);
|
|
85
|
+
}
|
|
86
|
+
function cfText(value) { return pcfText(value); }
|
|
87
|
+
function cfValue(field, raw) {
|
|
88
|
+
if (raw === '' || raw == null) return raw;
|
|
89
|
+
if (field.kind === 'boolean') return raw === true || raw === 'true';
|
|
90
|
+
if (field.kind === 'number') return Number(raw);
|
|
91
|
+
if (['list', 'map', 'records'].includes(field.kind)) {
|
|
92
|
+
try { return JSON.parse(raw); } catch { return field.kind === 'map' ? {} : []; }
|
|
93
|
+
}
|
|
94
|
+
return raw;
|
|
95
|
+
}
|
|
96
|
+
function cfValues(detail) {
|
|
97
|
+
const name = detail.stateKey || detail.scope || detail.name;
|
|
98
|
+
let state = CF_STATES.get(name);
|
|
99
|
+
if (!state || state.input !== detail) {
|
|
100
|
+
pcfModel(detail);
|
|
101
|
+
state = CF_STATES.get(name);
|
|
102
|
+
}
|
|
103
|
+
const out = {};
|
|
104
|
+
if (!state) return out;
|
|
105
|
+
(detail.fields || detail.configFields).forEach(function (field) {
|
|
106
|
+
if (field.kind === 'operation') return;
|
|
107
|
+
if (field.kind === 'map') {
|
|
108
|
+
const rows = pcfMapRows(state, field.key);
|
|
109
|
+
const err = pcfMapValidate(rows, field.label || field.key);
|
|
110
|
+
if (err) {
|
|
111
|
+
state.errors[field.key] = err;
|
|
112
|
+
throw new Error(err);
|
|
113
|
+
}
|
|
114
|
+
delete state.errors[field.key];
|
|
115
|
+
out[field.key] = pcfMapAssemble(rows);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
out[field.key] = cfValue(field, pcfGet(state, field.key));
|
|
119
|
+
});
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
function cfMembers() {
|
|
123
|
+
return (HL.members || []).filter(function (m) { return m.enabled !== false && m.canReceive !== false; }).map(function (m) { return m.id; });
|
|
124
|
+
}
|
|
125
|
+
function cfNormalize(input) {
|
|
126
|
+
if (!input) return input;
|
|
127
|
+
if (input.configFields) {
|
|
128
|
+
input.scope = input.scope || input.name;
|
|
129
|
+
return input;
|
|
130
|
+
}
|
|
131
|
+
const group = input.fields ? input : (typeof hlConfigGroup === 'function' ? hlConfigGroup(input.scope) : null);
|
|
132
|
+
if (!group) return { name: input.scope || '', scope: input.scope || '', steps: [], configFields: [] };
|
|
133
|
+
const fields = (input.fields || group.fields || []).map(function (field) {
|
|
134
|
+
const raw = field.value == null ? '' : typeof field.value === 'object' ? JSON.stringify(field.value) : String(field.value);
|
|
135
|
+
return Object.assign({}, field, {
|
|
136
|
+
currentValue: field.kind === 'secret' ? (field.hasValue ? '1' : '') : raw,
|
|
137
|
+
options: field.kind === 'member' ? cfMembers() : (field.options || []),
|
|
138
|
+
presets: field.recordPresets || field.presets || [],
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
return {
|
|
142
|
+
name: input.stateKey || group.scope, scope: group.scope, title: input.title || group.title,
|
|
143
|
+
steps: input.steps || group.steps || [], configurationVariants: input.variants || group.variants,
|
|
144
|
+
configFields: fields, commitMode: input.commitMode,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function cfInstantField(field) {
|
|
148
|
+
if (field.hidden || (field.managedBy && !field.managedCall) || field.readonly || field.requiredWhen) return false;
|
|
149
|
+
return ['boolean', 'select', 'member'].includes(field.kind) || (field.kind === 'number' && !!field.unit && Array.isArray(field.presets) && !!field.presets.length);
|
|
150
|
+
}
|
|
151
|
+
function cfFormMode(detail) {
|
|
152
|
+
if (detail.commitMode === 'external') return 'external';
|
|
153
|
+
const fields = detail.configFields.filter(function (field) { return !field.hidden && (!field.managedBy || field.managedCall); });
|
|
154
|
+
const simple = !detail.steps.length && !detail.configurationVariants && fields.length && fields.every(cfInstantField) && !detail.configFields.some(function (field) { return field.requiredWhen; });
|
|
155
|
+
return simple ? 'instant' : 'batch';
|
|
156
|
+
}
|
|
157
|
+
function cfLimitOptions(state, row, field) {
|
|
158
|
+
if (field.kind !== 'select') return;
|
|
159
|
+
const options = (field.options || []).slice();
|
|
160
|
+
const rules = state.detail.configFields.flatMap(function (other) {
|
|
161
|
+
if (other.key === field.key) return [];
|
|
162
|
+
const value = pcfEffective(other, state.draft);
|
|
163
|
+
const choice = (other.suggestions || other.options || []).find(function (one) { return String(one.value) === value; });
|
|
164
|
+
return choice?.allowedValues && Object.hasOwn(choice.allowedValues, field.key) ? [choice.allowedValues[field.key]] : [];
|
|
165
|
+
});
|
|
166
|
+
if (!rules.length) {
|
|
167
|
+
if (row.value !== '' && !options.some(function (one) { return one.value === row.value; })) options.unshift({ value: row.value, label: row.value });
|
|
168
|
+
row.options = options;
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const fallback = pcfText(field.default);
|
|
172
|
+
row.options = options.filter(function (one) {
|
|
173
|
+
return one.value === '' || one.value === fallback || rules.every(function (values) { return values.includes(one.value); });
|
|
174
|
+
});
|
|
175
|
+
if (row.options.some(function (one) { return one.value === row.value; })) return;
|
|
176
|
+
row.value = (row.options.find(function (one) { return one.value === fallback; }) || row.options[0] || { value: '' }).value;
|
|
177
|
+
pcfSet(state, field.key, row.value);
|
|
178
|
+
}
|
|
179
|
+
function cfFillReadonly(state) {
|
|
180
|
+
const filled = Object.create(null);
|
|
181
|
+
state.detail.configFields.forEach(function (source) {
|
|
182
|
+
const value = pcfEffective(source, state.draft);
|
|
183
|
+
const choice = (source.suggestions || source.options || []).find(function (one) { return String(one.value) === value; });
|
|
184
|
+
if (!choice?.fill) return;
|
|
185
|
+
Object.keys(choice.fill).forEach(function (key) {
|
|
186
|
+
if (state.fields.get(key)?.readonly) filled[key] = String(choice.fill[key]);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
state.fillDraft = filled;
|
|
190
|
+
}
|
|
191
|
+
function pcfModel(input) {
|
|
192
|
+
void CF_TRACK.rev;
|
|
193
|
+
const detail = cfNormalize(input);
|
|
194
|
+
const name = detail.name;
|
|
195
|
+
let state = CF_STATES.get(name);
|
|
196
|
+
if (!state) {
|
|
197
|
+
state = { draft: Object.create(null), mapRows: new Map(), errors: {}, operations: new Map(), nextRowId: 1 };
|
|
198
|
+
CF_STATES.set(name, state);
|
|
199
|
+
}
|
|
200
|
+
if (!state.mapRows) state.mapRows = new Map();
|
|
201
|
+
if (!state.nextRowId) state.nextRowId = 1;
|
|
202
|
+
state.input = input;
|
|
203
|
+
state.detail = detail;
|
|
204
|
+
state.fields = new Map(detail.configFields.map(function (field) { return [field.key, field]; }));
|
|
205
|
+
cfFillReadonly(state);
|
|
206
|
+
const visible = pcfFields(state);
|
|
207
|
+
const modeField = visible.find(function (field) {
|
|
208
|
+
return field.kind === 'select' && field.options.some(function (option) {
|
|
209
|
+
return detail.steps.some(function (step) { return step.mode === option.value; });
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
const mode = modeField ? pcfEffective(modeField, state.draft) : '';
|
|
213
|
+
const steps = detail.steps.filter(function (step) { return !step.mode || step.mode === mode; });
|
|
214
|
+
const rows = visible.map(function (field) {
|
|
215
|
+
if (field.kind === 'operation') {
|
|
216
|
+
return { key: field.key, label: field.label, desc: field.description, kind: field.kind, operation: pcfOperation(state, field) };
|
|
217
|
+
}
|
|
218
|
+
const key = field.key, isSecret = field.kind === 'secret';
|
|
219
|
+
const managed = !!field.managedBy;
|
|
220
|
+
const draft = managed && !field.managedCall ? undefined : field.readonly ? state.fillDraft[key] : state.draft[key];
|
|
221
|
+
const raw = draft ?? (isSecret ? '' : pcfEffective(field, state.draft));
|
|
222
|
+
const row = pcfRow(state, field, key, raw, pcfTopRequired(state, field));
|
|
223
|
+
if (managed) row.readonly = !field.managedCall;
|
|
224
|
+
row.currentValue = draft === '' ? null : field.currentValue;
|
|
225
|
+
row.defaultValue = pcfText(field.default);
|
|
226
|
+
row.canClear = isSecret && !row.req && !!row.currentValue;
|
|
227
|
+
if (field.kind === 'records') {
|
|
228
|
+
row.presets = field.presets || [];
|
|
229
|
+
row.items = pcfRows(state, field).map(function (record, i) {
|
|
230
|
+
const valueOf = function (sub) {
|
|
231
|
+
const sf = field.recordFields.find(function (f) { return f.key === sub; });
|
|
232
|
+
return sf ? pcfCell(record, sf) : undefined;
|
|
233
|
+
};
|
|
234
|
+
return { i: i, name: record.name || record.id, rows: field.recordFields.filter(function (sub) { return !sub.hidden; }).map(function (sub) {
|
|
235
|
+
const rawSub = pcfText(valueOf(sub.key));
|
|
236
|
+
const item = pcfRow(state, sub, key + '#' + i + '#' + sub.key, sub.kind === 'number' && sub.unit === 'percent' ? cfPercentDisplay(rawSub) : rawSub, pcfRequired(sub, valueOf));
|
|
237
|
+
const defText = sub.kind === 'number' && sub.unit === 'percent' ? cfPercentDisplay(pcfText(sub.default)) : pcfText(sub.default);
|
|
238
|
+
return Object.assign(item, { schemaKey: sub.key, record: true, readonly: row.readonly, placeholder: defText || tc('pcf.unset') });
|
|
239
|
+
}) };
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
return row;
|
|
243
|
+
});
|
|
244
|
+
const commitMode = cfFormMode(detail);
|
|
245
|
+
rows.forEach(function (row) {
|
|
246
|
+
const field = state.fields.get(row.key) || {};
|
|
247
|
+
cfLimitOptions(state, row, field);
|
|
248
|
+
row.instant = commitMode === 'instant' && cfInstantField(field);
|
|
249
|
+
if (row.kind === 'number' && row.unit === 'percent' && !(row.instant && Array.isArray(row.presets) && row.presets.length)) {
|
|
250
|
+
row.value = cfPercentDisplay(row.value);
|
|
251
|
+
row.currentValue = cfPercentDisplay(row.currentValue);
|
|
252
|
+
row.defaultValue = cfPercentDisplay(row.defaultValue);
|
|
253
|
+
row.placeholder = cfPercentDisplay(row.placeholder);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
return { p: name, scope: detail.scope, title: detail.title, mode: commitMode, compact: commitMode === 'instant', external: commitMode === 'external', installed: true, steps: steps, rows: rows, fieldCount: detail.configFields.length, dirty: Object.keys(pcfUpdates(state)).length > 0 };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function pcfSet(state, key, value) {
|
|
260
|
+
state.draft[key] = value;
|
|
261
|
+
delete state.errors[key];
|
|
262
|
+
}
|
|
263
|
+
function pcfPut(state, path, value) {
|
|
264
|
+
const [key, index, sub] = path.split('#');
|
|
265
|
+
if (sub === undefined) return pcfSet(state, key, value);
|
|
266
|
+
const field = state.fields.get(key), rows = pcfRows(state, field), row = rows[Number(index)];
|
|
267
|
+
const kind = field.recordFields.find(function (f) { return f.key === sub; }).kind;
|
|
268
|
+
if (value === '') delete row[sub];
|
|
269
|
+
else row[sub] = kind === 'list' ? JSON.parse(value) : kind === 'boolean' ? value === 'true' : kind === 'number' ? Number(value) : value;
|
|
270
|
+
pcfSet(state, key, JSON.stringify(rows));
|
|
271
|
+
delete state.errors[path];
|
|
272
|
+
}
|
|
273
|
+
function pcfGet(state, path) {
|
|
274
|
+
const [key, index, sub] = path.split('#'), field = state.fields.get(key);
|
|
275
|
+
if (sub === undefined) {
|
|
276
|
+
if (field?.kind === 'map' && state.mapRows?.has(key)) return JSON.stringify(pcfMapAssemble(state.mapRows.get(key)));
|
|
277
|
+
return pcfEffective(field, state.draft);
|
|
278
|
+
}
|
|
279
|
+
const sf = field.recordFields.find(function (f) { return f.key === sub; });
|
|
280
|
+
return pcfText(pcfCell(pcfRows(state, field)[Number(index)], sf));
|
|
281
|
+
}
|
|
282
|
+
function pcfReadonly(state, path) {
|
|
283
|
+
const field = state.fields.get(path.split('#')[0]);
|
|
284
|
+
return field.readonly || (field.managedBy && !field.managedCall) || field.kind === 'operation';
|
|
285
|
+
}
|
|
286
|
+
function pcfListChange(path, name, edit, redraw) {
|
|
287
|
+
const state = CF_STATES.get(name);
|
|
288
|
+
if (pcfReadonly(state, path)) return;
|
|
289
|
+
const items = JSON.parse(pcfGet(state, path) || '[]');
|
|
290
|
+
edit(items);
|
|
291
|
+
pcfPut(state, path, JSON.stringify(items));
|
|
292
|
+
if (redraw) { cfTouch(); render(true); }
|
|
293
|
+
markDirty();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function pcfMapParse(raw) {
|
|
297
|
+
try {
|
|
298
|
+
const obj = JSON.parse(raw || '{}');
|
|
299
|
+
return obj && typeof obj === 'object' && !Array.isArray(obj)
|
|
300
|
+
? Object.entries(obj).map(function (pair) { return { k: pair[0], v: pair[1] == null ? '' : String(pair[1]), show: false }; })
|
|
301
|
+
: [];
|
|
302
|
+
} catch { return []; }
|
|
303
|
+
}
|
|
304
|
+
function pcfMapRows(state, key) {
|
|
305
|
+
if (state.mapRows && state.mapRows.has(key)) return state.mapRows.get(key);
|
|
306
|
+
const field = state.fields.get(key);
|
|
307
|
+
return pcfMapParse(field ? pcfEffective(field, state.draft) : '{}');
|
|
308
|
+
}
|
|
309
|
+
function pcfMapRowsMut(state, key) {
|
|
310
|
+
if (!state.mapRows) state.mapRows = new Map();
|
|
311
|
+
if (!state.nextRowId) state.nextRowId = 1;
|
|
312
|
+
if (!state.mapRows.has(key)) {
|
|
313
|
+
state.mapRows.set(key, pcfMapRows(state, key).map(function (r) {
|
|
314
|
+
return { id: state.nextRowId++, k: r.k, v: r.v, show: !!r.show };
|
|
315
|
+
}));
|
|
316
|
+
}
|
|
317
|
+
return state.mapRows.get(key);
|
|
318
|
+
}
|
|
319
|
+
function pcfMapDirty(state, field) {
|
|
320
|
+
if (!state.mapRows || !state.mapRows.has(field.key)) return false;
|
|
321
|
+
const rows = state.mapRows.get(field.key), base = pcfMapParse(pcfEffective(field, {}));
|
|
322
|
+
if (rows.length !== base.length) return true;
|
|
323
|
+
for (let i = 0; i < rows.length; i++) {
|
|
324
|
+
if (String(rows[i].k ?? '') !== base[i].k || String(rows[i].v ?? '') !== base[i].v) return true;
|
|
325
|
+
}
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
function pcfMapValidate(rows, label) {
|
|
329
|
+
const seen = new Set();
|
|
330
|
+
for (const row of rows) {
|
|
331
|
+
const k = String(row.k ?? '').trim();
|
|
332
|
+
if (!k) return tc('pcf.mapEmptyKey', label);
|
|
333
|
+
if (seen.has(k)) return tc('pcf.mapDupKey', label, k);
|
|
334
|
+
seen.add(k);
|
|
335
|
+
}
|
|
336
|
+
return '';
|
|
337
|
+
}
|
|
338
|
+
function pcfMapAssemble(rows) {
|
|
339
|
+
const out = {};
|
|
340
|
+
for (const row of rows) {
|
|
341
|
+
const k = String(row.k ?? '').trim();
|
|
342
|
+
if (k) out[k] = String(row.v ?? '');
|
|
343
|
+
}
|
|
344
|
+
return out;
|
|
345
|
+
}
|
|
346
|
+
function cfPercentDisplay(value) {
|
|
347
|
+
if (value === '' || value == null) return '';
|
|
348
|
+
const n = Number(value);
|
|
349
|
+
return Number.isFinite(n) ? String(Number((n * 100).toFixed(6))) : String(value);
|
|
350
|
+
}
|
|
351
|
+
function cfPercentStore(value) {
|
|
352
|
+
if (value === '' || value == null) return '';
|
|
353
|
+
const n = Number(value);
|
|
354
|
+
return Number.isFinite(n) ? String(Number((n / 100).toFixed(8))) : String(value);
|
|
355
|
+
}
|
|
356
|
+
function cfInstantReady(state) { return !!(state && state.detail && cfFormMode(state.detail) === 'instant'); }
|
|
357
|
+
function pcfCallManaged(field, value) {
|
|
358
|
+
const call = field.managedCall;
|
|
359
|
+
return hlFetch(call.method, call.path, { [call.key]: call.inputType === 'list' ? JSON.parse(value) : value });
|
|
360
|
+
}
|
|
361
|
+
async function pcfSaveManaged(name, key) {
|
|
362
|
+
const state = CF_STATES.get(name), field = state && state.fields.get(key);
|
|
363
|
+
if (!state || !field?.managedCall || state.saving || !Object.hasOwn(state.draft, key)) return;
|
|
364
|
+
const submitted = pcfText(state.draft[key]);
|
|
365
|
+
state.saving = true;
|
|
366
|
+
try {
|
|
367
|
+
await pcfCallManaged(field, submitted);
|
|
368
|
+
if (pcfText(state.draft[key]) === submitted) delete state.draft[key];
|
|
369
|
+
await hlConfigRefresh().catch(function () {});
|
|
370
|
+
} finally {
|
|
371
|
+
state.saving = false;
|
|
372
|
+
cfTouch();
|
|
373
|
+
render(true);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
function cfSaveInstant(name, key) {
|
|
377
|
+
const state = CF_STATES.get(name), field = state && state.fields.get(key);
|
|
378
|
+
if (!state || !field || !cfInstantReady(state) || !cfInstantField(field) || !Object.hasOwn(state.draft, key)) return;
|
|
379
|
+
if (state.draft[key] === '__custom__') return;
|
|
380
|
+
if (field.managedCall) return pcfSaveManaged(name, key).catch(hlFail);
|
|
381
|
+
pcfSave(name).catch(hlFail);
|
|
382
|
+
}
|
|
383
|
+
INPUTS.pcfIn = INPUTS.pcfRecIn = function (e) {
|
|
384
|
+
const t = e.target, state = CF_STATES.get(t.dataset.p);
|
|
385
|
+
if (pcfReadonly(state, t.dataset.k)) return;
|
|
386
|
+
const wasDirty = pcfDirty(t.dataset.p);
|
|
387
|
+
const parts = t.dataset.k.split('#');
|
|
388
|
+
const topField = state.fields.get(parts[0]);
|
|
389
|
+
const activeField = parts[2] === undefined ? topField : topField?.recordFields?.find(function (f) { return f.key === parts[2]; });
|
|
390
|
+
const stored = t.tagName !== 'SELECT' && activeField?.kind === 'number' && activeField.unit === 'percent' ? cfPercentStore(t.value) : t.value;
|
|
391
|
+
pcfPut(state, t.dataset.k, stored);
|
|
392
|
+
const field = state.fields.get(t.dataset.k), choice = field && (field.suggestions || field.options || []).find(function (one) { return String(one.value) === t.value; });
|
|
393
|
+
if (choice && choice.fill) Object.keys(choice.fill).forEach(function (key) {
|
|
394
|
+
const target = state.fields.get(key);
|
|
395
|
+
if (!target || Object.hasOwn(state.draft, key)) return;
|
|
396
|
+
const current = pcfEffective(target, state.draft);
|
|
397
|
+
if (target.readonly) state.fillDraft[key] = String(choice.fill[key]);
|
|
398
|
+
else if (!current || current === pcfText(target.default)) pcfSet(state, key, String(choice.fill[key]));
|
|
399
|
+
});
|
|
400
|
+
t.removeAttribute('aria-invalid');
|
|
401
|
+
markDirty();
|
|
402
|
+
if (cfFormMode(state.detail) === 'batch' && pcfDirty(t.dataset.p) !== wasDirty) { cfTouch(); render(true); }
|
|
403
|
+
};
|
|
404
|
+
CHANGES.pcfSel = CHANGES.pcfRecSel = function (e) {
|
|
405
|
+
const args = actionArgs(e.target);
|
|
406
|
+
if (e.target.value === '__custom__') {
|
|
407
|
+
cfTouch();
|
|
408
|
+
A.cfCustom({ p: args.p, k: args.k });
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
INPUTS.pcfIn(e);
|
|
412
|
+
cfSaveInstant(args.p, args.k);
|
|
413
|
+
cfTouch();
|
|
414
|
+
render(true);
|
|
415
|
+
};
|
|
416
|
+
INPUTS.pcfListIn = function (e) {
|
|
417
|
+
const t = e.target, m = /^(.*)\|(.*):(\d+)(?::([kv]))?$/.exec(t.dataset.draft);
|
|
418
|
+
if (!m) return;
|
|
419
|
+
const name = m[1], path = m[2], index = Number(m[3]), part = m[4], state = CF_STATES.get(name), field = state && state.fields.get(path);
|
|
420
|
+
if (!field || pcfReadonly(state, path)) return;
|
|
421
|
+
if (field.kind === 'map') {
|
|
422
|
+
const wasDirty = pcfDirty(name);
|
|
423
|
+
const rows = pcfMapRowsMut(state, path);
|
|
424
|
+
if (!rows[index]) rows[index] = { id: state.nextRowId++, k: '', v: '', show: false };
|
|
425
|
+
if (part === 'k') rows[index].k = t.value;
|
|
426
|
+
else rows[index].v = t.value;
|
|
427
|
+
delete state.errors[path];
|
|
428
|
+
markDirty();
|
|
429
|
+
if (cfFormMode(state.detail) === 'batch' && pcfDirty(name) !== wasDirty) { cfTouch(); render(true); }
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
const wasDirty = pcfDirty(name);
|
|
433
|
+
pcfListChange(path, name, function (items) { items[index] = t.value; });
|
|
434
|
+
if (cfFormMode(state.detail) === 'batch' && pcfDirty(name) !== wasDirty) { cfTouch(); render(true); }
|
|
435
|
+
};
|
|
436
|
+
A.pcfOp = function (d) {
|
|
437
|
+
if (d.f) return pcfOperationClick(d);
|
|
438
|
+
if (d.op === 'add' || d.op === 'del' || (!d.op && d.l && d.i !== undefined)) {
|
|
439
|
+
const splitAt = d.l ? d.l.lastIndexOf('|') : -1;
|
|
440
|
+
const name = splitAt >= 0 ? d.l.slice(0, splitAt) : '';
|
|
441
|
+
const path = splitAt >= 0 ? d.l.slice(splitAt + 1) : '';
|
|
442
|
+
const state0 = CF_STATES.get(name), field0 = state0 && state0.fields.get(path);
|
|
443
|
+
if (field0?.kind === 'map') {
|
|
444
|
+
if (pcfReadonly(state0, path)) return;
|
|
445
|
+
const rows = pcfMapRowsMut(state0, path);
|
|
446
|
+
if (d.op === 'add') rows.push({ id: state0.nextRowId++, k: '', v: '', show: false });
|
|
447
|
+
else if (d.op === 'del') rows.splice(Number(d.i), 1);
|
|
448
|
+
else if (rows[Number(d.i)]) rows[Number(d.i)].show = !rows[Number(d.i)].show;
|
|
449
|
+
delete state0.errors[path];
|
|
450
|
+
markDirty();
|
|
451
|
+
cfTouch();
|
|
452
|
+
render(true);
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
if (d.op === 'add' || d.op === 'del') {
|
|
456
|
+
return pcfListChange(path, name, function (items) { if (d.op === 'add') items.push(''); else items.splice(Number(d.i), 1); }, true);
|
|
457
|
+
}
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
const state = CF_STATES.get(d.p);
|
|
461
|
+
if (d.k && pcfReadonly(state, d.k)) return;
|
|
462
|
+
if (d.op === 'bool' || d.op === 'recBool') { pcfPut(state, d.k, pcfGet(state, d.k) === 'true' ? 'false' : 'true'); cfSaveInstant(d.p, d.k); }
|
|
463
|
+
if (d.op === 'clear') pcfSet(state, d.k, '');
|
|
464
|
+
if (d.op === 'recAdd' || d.op === 'recDel') {
|
|
465
|
+
const field = state.fields.get(d.k), rows = pcfRows(state, field);
|
|
466
|
+
if (d.op === 'recAdd') rows.push(field.presets?.find(function (preset) { return preset.id === d.preset; })?.value || {});
|
|
467
|
+
else rows.splice(Number(d.i), 1);
|
|
468
|
+
pcfSet(state, d.k, JSON.stringify(rows));
|
|
469
|
+
}
|
|
470
|
+
if (d.op === 'discard') pcfReset(d.p);
|
|
471
|
+
cfTouch();
|
|
472
|
+
render(true);
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
async function pcfSave(name) {
|
|
476
|
+
const state = CF_STATES.get(name);
|
|
477
|
+
if (state.saving) return;
|
|
478
|
+
const updates = pcfUpdates(state), form = pcfModel(state.detail);
|
|
479
|
+
const rows = form.rows.flatMap(function (row) {
|
|
480
|
+
return row.kind === 'records' ? [row].concat(row.items.flatMap(function (item) { return item.rows; })) : [row];
|
|
481
|
+
});
|
|
482
|
+
state.errors = {};
|
|
483
|
+
for (const row of rows) {
|
|
484
|
+
if (row.kind === 'operation') continue;
|
|
485
|
+
if (row.kind === 'map') {
|
|
486
|
+
const mapRows = pcfMapRows(state, row.key);
|
|
487
|
+
const mapErr = pcfMapValidate(mapRows, row.label || row.key);
|
|
488
|
+
if (mapErr) { state.errors[row.key] = mapErr; continue; }
|
|
489
|
+
if (row.req && !mapRows.length) state.errors[row.key] = tc('pcf.fill', row.label || row.key);
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
const value = pcfGet(state, row.key);
|
|
493
|
+
if (row.req && (!value.trim() || (Array.isArray(row.items) && !row.items.length))) {
|
|
494
|
+
state.errors[row.key] = tc('pcf.fill', row.label || row.key);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
const first = Object.keys(state.errors)[0];
|
|
498
|
+
if (first) {
|
|
499
|
+
cfTouch();
|
|
500
|
+
render(true);
|
|
501
|
+
focusField(pcfId(name, first));
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
if (!Object.keys(updates).length) return;
|
|
505
|
+
state.saving = true;
|
|
506
|
+
const submitted = { ...updates }, managed = {}, patch = {}, mapSnapshots = {};
|
|
507
|
+
Object.keys(submitted).forEach(function (key) {
|
|
508
|
+
const value = submitted[key];
|
|
509
|
+
if (state.fields.get(key)?.kind === 'map' && state.mapRows?.has(key)) {
|
|
510
|
+
mapSnapshots[key] = JSON.stringify(state.mapRows.get(key));
|
|
511
|
+
}
|
|
512
|
+
if (state.fields.get(key).managedCall) managed[key] = value;
|
|
513
|
+
else patch[key] = value;
|
|
514
|
+
});
|
|
515
|
+
cfTouch();
|
|
516
|
+
render(true);
|
|
517
|
+
let savedAny = false;
|
|
518
|
+
try {
|
|
519
|
+
if (Object.keys(patch).length) await hlFetch('PUT', '/api/config', { scope: state.detail.scope, updates: patch });
|
|
520
|
+
if (Object.keys(patch).length) savedAny = true;
|
|
521
|
+
for (const key of Object.keys(patch)) {
|
|
522
|
+
if (state.draft[key] === patch[key]) delete state.draft[key];
|
|
523
|
+
if (Object.hasOwn(mapSnapshots, key) && JSON.stringify(state.mapRows?.get(key)) === mapSnapshots[key]) state.mapRows.delete(key);
|
|
524
|
+
}
|
|
525
|
+
for (const key of Object.keys(managed)) {
|
|
526
|
+
const val = pcfText(managed[key]);
|
|
527
|
+
await pcfCallManaged(state.fields.get(key), val);
|
|
528
|
+
savedAny = true;
|
|
529
|
+
if (pcfText(state.draft[key]) === val) delete state.draft[key];
|
|
530
|
+
}
|
|
531
|
+
} finally {
|
|
532
|
+
if (savedAny) await hlConfigRefresh().catch(function () {});
|
|
533
|
+
state.saving = false;
|
|
534
|
+
cfTouch();
|
|
535
|
+
render(true);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
function pcfOperationActive(state, op) {
|
|
539
|
+
const name = state.detail.name;
|
|
540
|
+
return CF_STATES.get(name) === state && op.field.available;
|
|
541
|
+
}
|
|
542
|
+
function pcfOperationStep(op, id = op.step) {
|
|
543
|
+
return op.field.actions.find(function (step) { return step.id === id; });
|
|
544
|
+
}
|
|
545
|
+
function pcfOperation(state, field) {
|
|
546
|
+
let op = state.operations.get(field.key);
|
|
547
|
+
if (!op) {
|
|
548
|
+
op = { step: field.actions[0].id };
|
|
549
|
+
state.operations.set(field.key, op);
|
|
550
|
+
}
|
|
551
|
+
if (op.field !== field) {
|
|
552
|
+
op.field = field;
|
|
553
|
+
clearTimeout(op.timer);
|
|
554
|
+
if (!pcfOperationStep(op)) op.step = field.actions[0].id;
|
|
555
|
+
if (!op.busy && field.statusCall && pcfOperationActive(state, op)) {
|
|
556
|
+
op.busy = true;
|
|
557
|
+
op.polling = false;
|
|
558
|
+
op.error = op.label = op.image = op.text = undefined;
|
|
559
|
+
queueMicrotask(function () { pcfOperationRequest(state, op, null, field.statusCall); });
|
|
560
|
+
} else if (!op.busy) pcfOperationSchedule(state, op);
|
|
561
|
+
}
|
|
562
|
+
const step = pcfOperationStep(op) || field.actions[0];
|
|
563
|
+
return { p: state.detail.name, f: field.key, step: step, available: field.available,
|
|
564
|
+
busy: op.busy, polling: op.polling, err: op.error, label: op.label, image: op.image, text: op.text,
|
|
565
|
+
seconds: op.polling ? Math.max(0, Math.ceil((op.deadline - Date.now()) / 1000)) : 0 };
|
|
566
|
+
}
|
|
567
|
+
function pcfOperationResult(state, op, from, result) {
|
|
568
|
+
const link = result.state === 'done' ? from?.next : result.state === 'error' ? from?.rollback : undefined;
|
|
569
|
+
const to = pcfOperationStep(op, result.step || link || op.step);
|
|
570
|
+
if (!to) throw new Error(tc('pcf.operationUnavailable'));
|
|
571
|
+
const kind = result.render || from?.resultRender;
|
|
572
|
+
if (kind === 'img' && /^(?:data:image\/(?:png|jpeg|gif|webp);base64,|https:\/\/)/i.test(result.data?.url || '')) op.image = result.data.url;
|
|
573
|
+
if (kind === 'text') op.text = result.data;
|
|
574
|
+
if (result.label !== undefined) op.label = result.label;
|
|
575
|
+
if (result.saved) {
|
|
576
|
+
for (const key of op.field.target) {
|
|
577
|
+
delete state.draft[key];
|
|
578
|
+
delete state.errors[key];
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
const polling = to.render === 'polling' && result.state !== 'error' &&
|
|
582
|
+
(!from || to.id !== from.id || result.state === 'pending');
|
|
583
|
+
if (polling && (!from || to.id !== op.step || !op.polling)) {
|
|
584
|
+
op.deadline = Math.min(Date.now() + to.timeout * 1000, result.expiresAt ?? Infinity);
|
|
585
|
+
}
|
|
586
|
+
op.pollAfter = result.pollAfter ?? op.pollAfter ?? 1000;
|
|
587
|
+
op.step = to.id;
|
|
588
|
+
op.polling = polling;
|
|
589
|
+
op.error = result.state === 'error' ? result.label || tc('pcf.operationUnavailable') : '';
|
|
590
|
+
if (!polling && kind !== 'img') op.image = undefined;
|
|
591
|
+
}
|
|
592
|
+
function pcfOperationExpired(state, op, step) {
|
|
593
|
+
pcfOperationResult(state, op, step, { state: 'error', label: tc('pcf.operationExpired') });
|
|
594
|
+
cfTouch();
|
|
595
|
+
render(true);
|
|
596
|
+
}
|
|
597
|
+
function pcfOperationSchedule(state, op) {
|
|
598
|
+
if (!op.polling || !pcfOperationActive(state, op)) return;
|
|
599
|
+
const step = pcfOperationStep(op), wait = Math.min(op.pollAfter, op.deadline - Date.now());
|
|
600
|
+
op.timer = setTimeout(function () {
|
|
601
|
+
if (!pcfOperationActive(state, op)) return;
|
|
602
|
+
if (Date.now() >= op.deadline) return pcfOperationExpired(state, op, step);
|
|
603
|
+
pcfOperationRequest(state, op, step, step.call);
|
|
604
|
+
}, Math.max(0, wait));
|
|
605
|
+
}
|
|
606
|
+
async function pcfOperationRequest(state, op, step, call, body = {}) {
|
|
607
|
+
if (!pcfOperationActive(state, op)) { op.busy = false; return; }
|
|
608
|
+
clearTimeout(op.timer);
|
|
609
|
+
op.busy = true;
|
|
610
|
+
if (step?.render === 'button') {
|
|
611
|
+
op.error = op.label = op.text = op.image = undefined;
|
|
612
|
+
op.pollAfter = undefined;
|
|
613
|
+
}
|
|
614
|
+
const controller = new AbortController();
|
|
615
|
+
op.request = controller;
|
|
616
|
+
const limit = step?.render === 'polling' ? setTimeout(function () { controller.abort(); }, Math.max(0, op.deadline - Date.now())) : undefined;
|
|
617
|
+
cfTouch();
|
|
618
|
+
render(true);
|
|
619
|
+
try {
|
|
620
|
+
const result = await hlFetch('POST', call.path, body, controller.signal);
|
|
621
|
+
if (op.request === controller && CF_STATES.get(state.detail.name) === state) pcfOperationResult(state, op, step, result);
|
|
622
|
+
} catch (error) {
|
|
623
|
+
if (op.request === controller && CF_STATES.get(state.detail.name) === state) {
|
|
624
|
+
if (controller.signal.aborted) pcfOperationExpired(state, op, step);
|
|
625
|
+
else pcfOperationResult(state, op, step, { state: 'error', label: error.message });
|
|
626
|
+
}
|
|
627
|
+
} finally {
|
|
628
|
+
clearTimeout(limit);
|
|
629
|
+
if (op.request === controller) {
|
|
630
|
+
op.request = undefined;
|
|
631
|
+
op.busy = false;
|
|
632
|
+
pcfOperationSchedule(state, op);
|
|
633
|
+
if (CF_STATES.get(state.detail.name) === state) { cfTouch(); render(true); }
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
function pcfOperationClick(d) {
|
|
638
|
+
const state = CF_STATES.get(d.p), op = state?.operations.get(d.f);
|
|
639
|
+
if (!op || !pcfOperationActive(state, op)) return;
|
|
640
|
+
const current = pcfOperationStep(op);
|
|
641
|
+
const cancel = current.cancel === d.a;
|
|
642
|
+
if (op.busy && !(cancel && op.polling)) return;
|
|
643
|
+
if (!cancel && current.id !== d.a) return;
|
|
644
|
+
const step = cancel ? pcfOperationStep(op, d.a) : current;
|
|
645
|
+
if (step.render !== 'button') return;
|
|
646
|
+
const call = step.call;
|
|
647
|
+
if (!call.ask.length) {
|
|
648
|
+
if (cancel) {
|
|
649
|
+
op.request?.abort();
|
|
650
|
+
op.polling = false;
|
|
651
|
+
}
|
|
652
|
+
return pcfOperationRequest(state, op, step, call);
|
|
653
|
+
}
|
|
654
|
+
const needsTopics = call.ask.some(function (ask) { return ask.topic && !ask.options; });
|
|
655
|
+
if (needsTopics && !HL_TOPIC_CATALOG) {
|
|
656
|
+
return hlTopicCatalogRead().then(function () {
|
|
657
|
+
if (pcfOperationActive(state, op) && !S.dialog) return pcfOperationClick(d);
|
|
658
|
+
}, function (error) {
|
|
659
|
+
if (pcfOperationActive(state, op)) hlFail(error);
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
const topics = needsTopics ? hlTopicCatalog().filter(function (topic) { return topic.archivedAt == null; }) : [];
|
|
663
|
+
const fields = call.ask.map(function (ask) {
|
|
664
|
+
const id = pcfId(d.p, d.f) + '-arg-' + ask.key, req = ask.required !== false;
|
|
665
|
+
const choices = ask.options ?? (ask.topic ? topics.map(function (topic) {
|
|
666
|
+
return { value: topic.id, label: hlTopicPath(topic.id).map(function (part) { return part.title; }).join(' › ') };
|
|
667
|
+
}) : undefined);
|
|
668
|
+
const selected = ask.topic && req ? choices?.findIndex(function (choice) { return choice.value === HL.topic?.id; }) : -1;
|
|
669
|
+
// The empty control value means no selection. A schema choice can itself be an empty string.
|
|
670
|
+
const options = choices && [['', tc(req ? 'pcf.choose' : 'common.none')]].concat(choices.map(function (choice, i) {
|
|
671
|
+
return [String(i), choice.label];
|
|
672
|
+
}));
|
|
673
|
+
return { id: id, key: ask.key, label: ask.label, req: req, choices: choices, options: options,
|
|
674
|
+
value: selected >= 0 ? String(selected) : '' };
|
|
675
|
+
});
|
|
676
|
+
dialog({ title: step.label, ok: tc('hl.common.ok'), danger: false, fields: fields,
|
|
677
|
+
on: function () {
|
|
678
|
+
const values = fields.map(function (field) { return val(field.id); });
|
|
679
|
+
if (values.some(function (value, i) { return !value && fields[i].req; })) return false;
|
|
680
|
+
if (pcfOperationActive(state, op) && !op.busy) {
|
|
681
|
+
const body = Object.fromEntries(fields.flatMap(function (field, i) {
|
|
682
|
+
const value = values[i];
|
|
683
|
+
return value ? [[field.key, field.choices ? field.choices[Number(value)].value : value]] : [];
|
|
684
|
+
}));
|
|
685
|
+
return pcfOperationRequest(state, op, step, call, body);
|
|
686
|
+
}
|
|
687
|
+
} });
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
A.cfCustom = function (d) {
|
|
691
|
+
const state = CF_STATES.get(d.p), field = state && state.fields.get(d.k);
|
|
692
|
+
if (!state || !field || pcfReadonly(state, d.k)) return;
|
|
693
|
+
const current = pcfGet(state, d.k);
|
|
694
|
+
const shown = field.unit === 'percent' ? cfPercentDisplay(current) : current;
|
|
695
|
+
inlineEditOpen({
|
|
696
|
+
key: 'cf-custom:' + d.p + ':' + d.k,
|
|
697
|
+
value: shown == null ? '' : String(shown),
|
|
698
|
+
inputType: 'number',
|
|
699
|
+
label: field.label || field.key,
|
|
700
|
+
act: 'cfCustomSave',
|
|
701
|
+
args: { p: d.p, k: d.k },
|
|
702
|
+
alwaysSave: true
|
|
703
|
+
});
|
|
704
|
+
};
|
|
705
|
+
A.cfCustomSave = function (d) {
|
|
706
|
+
const state = CF_STATES.get(d.p), field = state && state.fields.get(d.k);
|
|
707
|
+
if (!state || !field || pcfReadonly(state, d.k)) return;
|
|
708
|
+
const v = String(d && d.v || '').trim();
|
|
709
|
+
if (v === '') return;
|
|
710
|
+
pcfPut(state, d.k, field.unit === 'percent' ? cfPercentStore(v) : v);
|
|
711
|
+
return field.managedCall ? pcfSaveManaged(d.p, d.k) : pcfSave(d.p);
|
|
712
|
+
};
|
|
713
|
+
/* Unified config registry aliases. */
|
|
714
|
+
const cfModel = pcfModel, cfDirty = pcfDirty, cfReset = pcfReset, cfResetPrefix = pcfResetPrefix;
|
|
715
|
+
INPUTS.cfIn = INPUTS.pcfIn; INPUTS.cfRecIn = INPUTS.pcfRecIn; INPUTS.cfListIn = INPUTS.pcfListIn;
|
|
716
|
+
CHANGES.cfSel = CHANGES.pcfSel; CHANGES.cfRecSel = CHANGES.pcfRecSel;
|
|
717
|
+
A.cfOp = A.pcfOp;
|
|
718
|
+
FORMS.cf = function (form) { return pcfSave(form.dataset.p || form.dataset.scope).catch(hlFail); };
|
|
719
|
+
VM.hlConfigGroupView = function (input) {
|
|
720
|
+
const data = input || {};
|
|
721
|
+
let group = data.fields ? data : hlConfigGroup(data.scope);
|
|
722
|
+
if (!data.fields && group?.scope.startsWith('plugin:')) group = hlRegistrationGroup(group, data.registration || 'manifest');
|
|
723
|
+
if (!group) return null;
|
|
724
|
+
if (!data.section) return { form: cfModel(Object.assign({}, group, data)) };
|
|
725
|
+
const fields = group.fields.filter(function (field) { return field.section === data.section; });
|
|
726
|
+
return fields.length ? { form: cfModel(Object.assign({}, group, { stateKey: group.scope + ':' + data.section, fields: fields })) } : null;
|
|
727
|
+
};
|