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,1064 @@
|
|
|
1
|
+
/* 边界:引擎只放机制与时机,不认任何具体名字、不为单个位置打补丁 */
|
|
2
|
+
/* 页面描述(PDL):入口、插槽、摆放、页面里的块,以及渲染它们的引擎。
|
|
3
|
+
外壳(窄栏、对话侧栏的入口区、设置菜单、工作台启动面板)、页面插槽(输入框工具、消息操作)、
|
|
4
|
+
行插槽(工作台每种列表行的悬停操作)都从这份描述生成。
|
|
5
|
+
摆放分层:核心默认 → 插件(manifest 里的 pdl 段,见 data.js)→ 用户调整(存在这台设备上)。
|
|
6
|
+
规则在所有层之上:设置入口始终在窄栏;成员、插件扩展、系统配置始终留在设置菜单(拖出去是复制)。 */
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
/* ═════════════ 描述 ═════════════ */
|
|
12
|
+
|
|
13
|
+
/* 能力条件;插件注册时会加上 plugin.<id> */
|
|
14
|
+
const WHEN = pdlReads('when');
|
|
15
|
+
|
|
16
|
+
/* 弹窗:盖在投影上的、用完即弃的内容。每个弹窗只声明三件事:
|
|
17
|
+
- at 初始位置:trigger 跟着触发它的东西(元素;点击处 / 选中的文字 / 光标由打开它的动作给出,引擎在那里放一个看不见的锚点,见 anchor.js 的 spotAt),或者相对它所在的地方固定(center 窗口中间 / corner 容器的角 / top 窗口顶部 / fill 铺满)。都是相对的,没有页面坐标;
|
|
18
|
+
- exit 退出方式:outside 点外面 · esc · x(只有声明了 x 才画 ×)· pick 在里面执行了一个动作(留在原弹窗里的除外:换了一页,或者节点声明了 stay)· leave 指针离开(共用的悬停规则);
|
|
19
|
+
- drag 能否拖:拖动是相对初始位置的偏移,只在这次打开期间有效。
|
|
20
|
+
另外两条和弹窗无关的声明:focus 遮罩(任何 PDL 节点都能声明);fixLayer 进栈后下面的弹窗不能被提到它上面(确认框 / 对话框链)。
|
|
21
|
+
state:触发它的是一个状态(不是元素),状态结束它就关;close:关闭动作(退出方式都走它,离开前的未保存确认在容器层,见 frame.js 的 leave);body:框架给内容的那一层(page = 和对话流同一层)。
|
|
22
|
+
demo:组件目录里“打开看看”依次执行的动作(组件目录用);via:除了 demo 的动作,还有哪些 PDL 会打开它(目录数“使用几处”用) */
|
|
23
|
+
const PDL_POPUPS = {};
|
|
24
|
+
/* 身份组件悬停时做什么(触发元素的声明):按身份种类,值是动作名;成员 → 打开成员悬停卡 */
|
|
25
|
+
const PDL_WHO = {}; /* 成员悬停卡只在消息的作者行(作者头像 + 名字);别的放置处(成员列表、胶囊、叠放、已读、输入框)没有 */
|
|
26
|
+
function popExits(k, how) { return ((PDL_POPUPS[k] || {}).exit || []).indexOf(how) >= 0; }
|
|
27
|
+
|
|
28
|
+
/* 入口:movable 能否拖动、keep 只能待在哪些插槽、scope 页面 / 行插槽里的元素 */
|
|
29
|
+
/* 工作台里的工具也是入口:拖到窄栏或侧栏,点了在右侧打开 */
|
|
30
|
+
|
|
31
|
+
/* 插槽:display 怎么画;accepts 接受哪些入口;itemActions 进入这个插槽的每个入口都叠加的操作;scope 页面 / 行插槽 */
|
|
32
|
+
const PDL_SLOTS = {};
|
|
33
|
+
/* 页面插槽里的元素:按 when 决定出不出现,按 use 选组件库里的哪个组件来画 */
|
|
34
|
+
|
|
35
|
+
/* 行插槽:每种列表行一个,面板只交出这一行的数据(ctx),按钮由 lrow 统一画。
|
|
36
|
+
一个行操作:title(可以用 {key} 引用这一行的数据)、icon、open.action、args(属性名: ctx 里的键)、
|
|
37
|
+
need(这一行有这个数据才出现,'!x' 表示没有才出现)、guard([规则名, 参数]:为什么现在不能用)、when */
|
|
38
|
+
const PDL_GUARDS = {};
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
/* 页面里的块:系统配置的小节顺序和出现条件 */
|
|
42
|
+
const PDL_PAGES = {};
|
|
43
|
+
|
|
44
|
+
/* ═════════════ 插件注册 ═════════════
|
|
45
|
+
插件的入口、摆放、贡献、节点、图标合并进来;入口的条件自动是“插件已启用”。图标注册在插件自己的命名空间(plugin:<id>/…)。
|
|
46
|
+
被打开的东西是 views 里的一个节点:PDL 视图,或 type: 'frame' 的独立页面(src、route、bridge、focus);panel 是它在标签式容器里那一项的标题和图标 */
|
|
47
|
+
const PDL_PLUGINS = []; /* 已注册(已安装)的插件,按安装顺序 */
|
|
48
|
+
const PDL_PLUGIN_REQ = {}; /* 插件 → 它登记的请求(名字 → { path 插件内相对路径, method, query });读写都走宿主的通用转发 /api/plugins/<id>/<path> */
|
|
49
|
+
const PDL_INSERT_SKIPS = {}; /* 插件 → 没插进去的插入([{ id, reason }],插件详情里可见) */
|
|
50
|
+
const PDL_PLUGIN_FRAGS = {}; /* 插件 → 它登记的 PDL 片段(生效的描述里列出它提供了什么) */ /* 插件 → 它对宿主的操作(和用户层同一种格式) */
|
|
51
|
+
/* ═════════════ 插槽基数:keyed / chain / single ═════════════
|
|
52
|
+
贡献项:{ id, slot, key?(keyed), match?(chain), priority?(越小越先), when?, plugin?, … 其余是这一项的数据(节点模板、卡片描述、提示内容) }
|
|
53
|
+
核心的默认项也走 pdlContribute,所以插件和核心是同一种数据。 */
|
|
54
|
+
const PDL_SLOT_ITEMS = {};
|
|
55
|
+
/* 插件只能“加”:keyed 插槽里插件不能占用核心已有的 key(拒绝并记下,插件详情里可见);
|
|
56
|
+
排序时核心项永远在插件项之前,插件的 priority 只在插件之间比较——插件替换不了核心模板。 */
|
|
57
|
+
const PDL_SLOT_REJECTS = {}; /* 插件 → [{ slot, key, reason }] */
|
|
58
|
+
function pdlContribute(slot, item) {
|
|
59
|
+
const list = PDL_SLOT_ITEMS[slot] = PDL_SLOT_ITEMS[slot] || [];
|
|
60
|
+
if (item.plugin && item.key != null && PDL_SLOTS[slot] && PDL_SLOTS[slot].cardinality === 'keyed' && list.some(function (x) { return !x.plugin && x.key === item.key; })) {
|
|
61
|
+
(PDL_SLOT_REJECTS[item.plugin] = PDL_SLOT_REJECTS[item.plugin] || []).push({ slot: slot, key: item.key, reason: 'host' }); return;
|
|
62
|
+
}
|
|
63
|
+
list.push(Object.assign({ priority: 100 }, item));
|
|
64
|
+
}
|
|
65
|
+
function pdlSlotItems(slot) { return (PDL_SLOT_ITEMS[slot] || []).filter(function (x) { return pdlWhen(x.when); }).sort(function (a, b) { return ((a.plugin ? 1 : 0) - (b.plugin ? 1 : 0)) || (a.priority - b.priority); }); }
|
|
66
|
+
/* keyed:按 key 取节点模板;只有核心项和插件新登记的 key(插件不能遮蔽核心) */
|
|
67
|
+
function pdlSlotTemplate(slot, key) { const hit = pdlSlotItems(slot).find(function (x) { return x.key === key || (x.keys && x.keys.indexOf(key) >= 0); }); if (hit && hit.plugin) pdlPluginNeed(hit.plugin); return hit ? hit.node : null; } /* keys:一个模板画几种类型 */
|
|
68
|
+
/* typed:按渲染类型取模板。类型写成“容器.子类型……”,取最长的、已登记且可用的前缀——插件不在(没装、停用)时逐级退回宿主的容器;
|
|
69
|
+
一个都没有返回 null(调用方画默认)。降级关系写在类型名里,跟着数据走,不靠插件的声明 */
|
|
70
|
+
function pdlTyped(slot, type) {
|
|
71
|
+
for (let t = String(type || ''); t; t = t.lastIndexOf('.') > 0 ? t.slice(0, t.lastIndexOf('.')) : '') { const n = pdlSlotTemplate(slot, t); if (n) return n; }
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
/* chain:ctx 里的字段包含 match 里写的文字就算认领;都不认领返回 null(用默认渲染) */
|
|
75
|
+
function pdlMatch(m, ctx) { return Object.keys(m || {}).every(function (k) { return ctx[k] != null && String(ctx[k]).indexOf(m[k]) >= 0; }); }
|
|
76
|
+
function pdlChain(slot, ctx) { return pdlSlotItems(slot).find(function (x) { return pdlMatch(x.match, ctx); }) || null; }
|
|
77
|
+
/* single:只放一个,核心项优先,其次插件里 priority 小的 */
|
|
78
|
+
function pdlSingle(slot) { return pdlSlotItems(slot)[0] || null; }
|
|
79
|
+
|
|
80
|
+
/* 核心的默认项:消息节点模板(views-chat.js 的 PDL_NODES)、输入框上方的提示 */
|
|
81
|
+
|
|
82
|
+
/* 通用 PDL 片段登记:内置模块和插件写入同一组表。
|
|
83
|
+
pk / plug 只提供插件来源、启停条件与图标命名空间;不决定内容用哪套渲染。 */
|
|
84
|
+
/* 片段里给人看的名字(入口标题、面板标签):t:键 在登记时取文案(插件的文案先登记);别的原样 */
|
|
85
|
+
function pdlText(x) { return typeof x === 'string' && x.indexOf('t:') === 0 ? tc(x.slice(2)) : x; }
|
|
86
|
+
/* 插件的视图带上它是谁的:有 sources 的视图向应用的通用 VM.plugin 要数据;视图里用通用插件动作(plugin)的参数补上插件 id */
|
|
87
|
+
const PDL_ACT_KEYS = ['act', 'action', 'change', 'input', 'go']; /* 写动作名的属性(插件的通用动作补上插件 id;公开边界按它们查) */
|
|
88
|
+
function pdlTagActs(x, pk) {
|
|
89
|
+
if (Array.isArray(x)) { x.forEach(function (y) { pdlTagActs(y, pk); }); return; } if (!x || typeof x !== 'object') return;
|
|
90
|
+
if (PDL_ACT_KEYS.some(function (k) { return x[k] === 'plugin' || x[k] === 'plugSet'; })) x.args = Object.assign({}, x.args, { plugin: pk });
|
|
91
|
+
if (x.okAct === 'plugin') x.okArgs = Object.assign({}, x.okArgs, { plugin: pk });
|
|
92
|
+
Object.keys(x).forEach(function (k) { pdlTagActs(x[k], pk); });
|
|
93
|
+
}
|
|
94
|
+
/* 公开目录由应用登记;整个片段(包括延迟子树)在写入任何登记表前校验。 */
|
|
95
|
+
function pdlPluginRejects(frag, pk) {
|
|
96
|
+
const out = [], pub = ENGINE_PARTS.pluginPublic;
|
|
97
|
+
const local = function (v) { return pk && typeof v === 'string' && v.startsWith('plugin:' + pk + '/'); };
|
|
98
|
+
function act(v, path) {
|
|
99
|
+
if (typeof v === 'string') { if (pub.acts.indexOf(v) < 0 && v !== '' && !local(v)) out.push({ key: v, slot: path, reason: 'private action' }); }
|
|
100
|
+
else if (v && v.map) Object.keys(v.map).forEach(function (k) { act(v.map[k], path); });
|
|
101
|
+
}
|
|
102
|
+
function walk(x, path) {
|
|
103
|
+
if (!x || typeof x !== 'object') return;
|
|
104
|
+
if (x.vm && !local(x.vm)) out.push({ key: x.vm, slot: path + '.vm', reason: 'private source' });
|
|
105
|
+
Object.keys(x.sources || {}).forEach(function (k) { const s = x.sources[k]; if (s.indexOf('host:') === 0 && pub.data.indexOf(s.slice(5).split('.')[0]) < 0) out.push({ key: s, slot: path, reason: 'private source' }); });
|
|
106
|
+
Object.keys(x).forEach(function (k) {
|
|
107
|
+
if (PDL_ACT_KEYS.concat(['itemAct', 'okAct']).indexOf(k) >= 0) { if (x[k] && typeof x[k] === 'object' && !x[k].map) walk(x[k], path + '.' + k); else act(x[k], path + '.' + k); }
|
|
108
|
+
else if (k === 'on') Object.keys(x[k]).forEach(function (ev) { if (typeof x[k][ev] === 'string') act(x[k][ev], path + '.on.' + ev); else walk(x[k][ev], path + '.on.' + ev); });
|
|
109
|
+
else if (k !== 'requests' && k !== 'i18n') walk(x[k], path + '.' + k);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
walk(frag, 'pdl'); return out;
|
|
113
|
+
}
|
|
114
|
+
/* 片段里的节点(视图、独立页面)、请求、弹窗:登记时一次,延迟加载的插件取回子树时再一次(inserts 是它登记过的插入,找弹窗归哪个入口) */
|
|
115
|
+
function pdlRegisterNodes(frag, pk, inserts) {
|
|
116
|
+
const owner = pk ? { plugin: pk } : {};
|
|
117
|
+
Object.keys(frag.views || {}).forEach(function (id) { const v = frag.views[id]; if (pk) { v.plugin = pk; pdlTagActs(v, pk); } PDL_VIEWS[id] = v; });
|
|
118
|
+
if (pk && frag.requests) PDL_PLUGIN_REQ[pk] = frag.requests;
|
|
119
|
+
Object.keys(frag.popups || {}).forEach(function (k) {
|
|
120
|
+
const d = frag.popups[k], f = Object.keys(PDL_VIEWS).find(function (id) { return PDL_VIEWS[id].popup === k; });
|
|
121
|
+
const ins = (inserts || []).find(function (x) { return ((x.node || {}).open || {}).node === f; }), entry = ins ? (pk ? 'plugin:' + pk + '/' : '') + ins.id : null;
|
|
122
|
+
const body = Object.assign({}, d, f && PDL_VIEWS[f].type !== 'frame' ? { view: f } : {}); /* 视图节点画视图;独立页面画通用浮窗里的框 */
|
|
123
|
+
PDL_POPUPS[k] = Object.assign({}, d, owner, { close: 'close', closeArgs: { path: 's.popOn.{k}' } }, entry ? { demo: [{ act: 'open', args: { ref: entry } }] } : {});
|
|
124
|
+
POPUPS[k] = function () { return S.popOn[k] && (!pk || plugOn(pk)) ? ENGINE_PARTS.framePopup(k, pk, body) : ''; };
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/* 延迟加载:宿主给了加载口 ENGINE_PARTS.pluginLoad(插件) → Promise<子树> 时,插件登记的是索引(插入、模板、行、图标、文案、节点的声明);
|
|
128
|
+
子树(视图的内容、弹窗、请求)在它第一次投影时取回:画到它插进来的节点、它的模板,或者打开它的节点。取回后登记、再画。
|
|
129
|
+
没有加载口时登记的就是整个片段。插件撤掉时一起忘掉 */
|
|
130
|
+
const PDL_PLUGIN_LOADED = {};
|
|
131
|
+
function pdlPluginNeed(pk) {
|
|
132
|
+
if (!ENGINE_PARTS.pluginLoad || !PDL_PLUGIN_FRAGS[pk]) return;
|
|
133
|
+
if (PDL_PLUGIN_LOADED[pk]) return PDL_PLUGIN_LOADED[pk];
|
|
134
|
+
const at = PDL_PLUGIN_LOADED[pk] = ENGINE_PARTS.pluginLoad(pk).then(async function (sub) {
|
|
135
|
+
const frag = PDL_PLUGIN_FRAGS[pk]; if (PDL_PLUGIN_LOADED[pk] !== at || !frag) return;
|
|
136
|
+
const rejects = pdlPluginRejects(sub, pk); if (rejects.length) { PDL_SLOT_REJECTS[pk] = rejects; render(true); return; }
|
|
137
|
+
const { module, js, css } = sub.components || {};
|
|
138
|
+
const cw = js || css ? pdlComponentsLoad({ js, css }, pk) : ''; if (cw) { PDL_SLOT_REJECTS[pk] = [{ key: pk, slot: 'components', reason: cw }]; render(true); return; }
|
|
139
|
+
if (module) await ENGINE_PARTS.pluginMount(pk, module);
|
|
140
|
+
if (PDL_PLUGIN_LOADED[pk] !== at) return;
|
|
141
|
+
pdlRegisterNodes(sub, pk, frag.inserts);
|
|
142
|
+
PDL_PLUGIN_FRAGS[pk] = Object.assign({}, frag, { views: Object.assign({}, frag.views, sub.views), popups: sub.popups, requests: sub.requests, loaded: true });
|
|
143
|
+
if (frag.inserts) pdlTreeChanged(); else renderForget(); /* 插入可能锚在刚取回的子树里:从头再插一遍 */
|
|
144
|
+
render(true);
|
|
145
|
+
}).catch(function (error) {
|
|
146
|
+
if (PDL_PLUGIN_LOADED[pk] !== at) return;
|
|
147
|
+
PDL_SLOT_REJECTS[pk] = [{ key: pk, slot: 'components', reason: error.message }];
|
|
148
|
+
console.error(error);
|
|
149
|
+
render(true);
|
|
150
|
+
});
|
|
151
|
+
return at;
|
|
152
|
+
}
|
|
153
|
+
treeMatch('[data-entry^="plugin:"]', function (el) { const id = el.dataset.entry; pdlPluginNeed(id.slice(7, id.indexOf('/'))); }); /* 插件插进来的节点进了文档(进树通知) */
|
|
154
|
+
/* 插件组件:片段的 components { js, css } 只画(组件库同一种写法),新增的名字在 plugin:<插件>/ 下;replaces { 块类型: { use, props } } 全局替换宿主的这个块,
|
|
155
|
+
props 要和 PDL_SCHEMA 里这个块的属性一样。同一个块同一时间只有一个启用中的替换者:启用时应用查 pdlReplaceConflict,冲突就不启用。
|
|
156
|
+
有 replaces 的插件随索引加载组件(替换从第一屏起就要生效),其余随子树。脚本收不回:组件变了的更新整页重新载入 */
|
|
157
|
+
const PDL_COMP_LOADED = {}; /* 插件 → 已运行的组件(原文);替换表 PDL_REPLACES 在 pdl-view.js(画块的地方) */
|
|
158
|
+
function pdlComponentsLoad(c, pk) {
|
|
159
|
+
const sig = JSON.stringify(c); if (PDL_COMP_LOADED[pk] === sig) return '';
|
|
160
|
+
if (PDL_COMP_LOADED[pk]) { location.reload(); return ''; }
|
|
161
|
+
Object.keys(PDL_COMPONENTS).forEach(function (k) { Object.defineProperty(PDL_COMPONENTS, k, { writable: false, configurable: false }); }); /* 已有的组件插件改不了 */
|
|
162
|
+
const add = function (tag, text) { const el = document.createElement(tag); el.textContent = text; document.head.appendChild(el); };
|
|
163
|
+
(c.css || []).forEach(function (x) { add('style', x); }); (c.js || []).forEach(function (x) { add('script', x); });
|
|
164
|
+
PDL_COMP_LOADED[pk] = sig;
|
|
165
|
+
const bad = Object.keys(PDL_COMPONENTS).filter(function (k) { return Object.getOwnPropertyDescriptor(PDL_COMPONENTS, k).writable && k.indexOf('plugin:' + pk + '/') !== 0; });
|
|
166
|
+
bad.forEach(function (k) { delete PDL_COMPONENTS[k]; }); /* 只能在自己的命名空间里新增 */
|
|
167
|
+
return bad.length ? 'component ' + bad.join(', ') : '';
|
|
168
|
+
}
|
|
169
|
+
function pdlReplacesWhy(frag, pk) {
|
|
170
|
+
return Object.keys(frag.replaces || {}).map(function (t) {
|
|
171
|
+
const r = frag.replaces[t], want = Object.keys(PDL_SCHEMA[t] || {}).sort().join(), have = (r.props || []).slice().sort().join();
|
|
172
|
+
return !PDL_SCHEMA[t] ? 'replaces ' + t + ': not a block' : r.use.indexOf('plugin:' + pk + '/') !== 0 || !PDL_COMPONENTS[r.use] ? 'replaces ' + t + ': ' + r.use : want !== have ? 'replaces ' + t + ': props differ' : '';
|
|
173
|
+
}).filter(Boolean);
|
|
174
|
+
}
|
|
175
|
+
function pdlReplacesSet(frag, pk) {
|
|
176
|
+
Object.keys(frag.replaces || {}).forEach(function (t) { (PDL_REPLACES[t] = PDL_REPLACES[t] || []).push({ pk: pk, use: frag.replaces[t].use }); });
|
|
177
|
+
}
|
|
178
|
+
/* 启用前:这个插件要替换的块,已经被另一个启用中的插件替换了 → { type, by } */
|
|
179
|
+
function pdlReplaceConflict(pk) {
|
|
180
|
+
const own = (PDL_PLUGIN_FRAGS[pk] || {}).replaces || {};
|
|
181
|
+
for (const t of Object.keys(own)) { const by = (PDL_REPLACES[t] || []).find(function (x) { return x.pk !== pk && plugOn(x.pk); }); if (by) return { type: t, by: by.pk }; }
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
function pdlRegister(frag, pk, plug) {
|
|
185
|
+
if (pk) delete PDL_SLOT_REJECTS[pk];
|
|
186
|
+
if (pk) { const rejects = pdlPluginRejects(frag, pk); if (rejects.length) { PDL_SLOT_REJECTS[pk] = rejects; return; } }
|
|
187
|
+
const big = pk && pdlLimitWhy(frag); if (big) { PDL_SLOT_REJECTS[pk] = [{ key: pk, slot: '', reason: big }]; return; }
|
|
188
|
+
if (pk && frag.components && (frag.replaces || !ENGINE_PARTS.pluginLoad)) {
|
|
189
|
+
const why = [pdlComponentsLoad(frag.components, pk)].concat(pdlReplacesWhy(frag, pk)).filter(Boolean);
|
|
190
|
+
if (why.length) { PDL_SLOT_REJECTS[pk] = why.map(function (w) { return { key: pk, slot: 'components', reason: w }; }); return; }
|
|
191
|
+
pdlReplacesSet(frag, pk);
|
|
192
|
+
} /* 上限(主题文档):插件片段登记时校验一次,超了整个不登记 */
|
|
193
|
+
const owner = pk ? { plugin: pk } : {}, cond = pk ? 'plugin.' + pk : null;
|
|
194
|
+
const ns = function (ic) { return ic && frag.icons && frag.icons[ic] && pk ? 'plugin:' + pk + '/' + ic : ic; };
|
|
195
|
+
Object.keys(frag.icons || {}).forEach(function (n) { const one = {}; one[ns(n)] = frag.icons[n]; ENGINE_PARTS.icons(one); });
|
|
196
|
+
if (frag.icon && plug) plug.icon = ns(frag.icon);
|
|
197
|
+
if (pk) WHEN[cond] = function () { return plugOn(pk); };
|
|
198
|
+
Object.keys(frag.rows || {}).forEach(function (id) { if (pk) pdlTagActs(frag.rows[id], pk); PDL_ROWS[id] = frag.rows[id]; }); /* 插件自己的行模板(名字由插件起,建议带上它的前缀) */
|
|
199
|
+
if (frag.i18n) defineI18nPack(frag.ns || pk, frag.i18n); /* 插件的文案:按语言分({ zh: {…}, en: {…} }),键在它的 ns 下,视图里写 t:<ns>.<键> */
|
|
200
|
+
pdlRegisterNodes(frag, pk, frag.inserts);
|
|
201
|
+
(frag.templates || []).forEach(function (x) { /* 模板登记(按类型画,不是摆放) */
|
|
202
|
+
const item = Object.assign({}, x, owner, { icon: ns(x.icon), id: pk ? 'plugin:' + pk + '/' + x.id : x.id });
|
|
203
|
+
if (pk && item.node) { item.node.plugin = pk; pdlTagActs(item.node, pk); }
|
|
204
|
+
if (cond) item.when = x.when ? [cond, x.when] : cond;
|
|
205
|
+
pdlContribute(x.slot, item);
|
|
206
|
+
});
|
|
207
|
+
/* 插进来的节点:保留 t: 键在渲染时按当前语言取值,图标加上前缀(和模板一样) */
|
|
208
|
+
const inserts = (frag.inserts || []).map(function (x) {
|
|
209
|
+
if (!x.node) return x;
|
|
210
|
+
const node = Object.assign({}, x.node, { icon: ns(x.node.icon) });
|
|
211
|
+
if (pk) pdlTagActs(node, pk);
|
|
212
|
+
if (pk && node.sources && !node.type) {
|
|
213
|
+
const key = 'plugin:' + pk + '/' + x.id;
|
|
214
|
+
BADGES[key] = function () { const root = pdlSourceOf(Object.assign({ plugin: pk }, x.node)); return x.node.badge ? pv(x.node.badge, root, root) : null; };
|
|
215
|
+
node.badge = key;
|
|
216
|
+
}
|
|
217
|
+
return Object.assign({}, x, { node: node });
|
|
218
|
+
});
|
|
219
|
+
/* 内置模块的插入就是主题的一部分:登记时直接放进主题声明(不带 ins,不随插件重算) */
|
|
220
|
+
if (!pk) inserts.forEach(function (x) { if (!pdlInsertOne(pdlTreeIndex(), x, Object.assign({ id: x.id }, x.node))) throw new Error('builtin insert ' + x.id + ' found no anchor'); });
|
|
221
|
+
if (pk) {
|
|
222
|
+
PDL_PLUGIN_FRAGS[pk] = Object.assign({}, frag, { inserts: inserts });
|
|
223
|
+
PDL_PLUGINS.push(pk);
|
|
224
|
+
if (frag.inserts) pdlTreeChanged(); else renderForget(); /* 定义变了:上一次画的都作废 */
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/* 插件装上、更新、卸下时应用重读片段:先撤掉它登记过的(按它登记的片段逐项撤),再按新片段登记。
|
|
228
|
+
图标和文案在插件自己的命名空间里,留着不会被引用,重新登记时覆盖 */
|
|
229
|
+
function pdlUnregister(pk) {
|
|
230
|
+
const frag = PDL_PLUGIN_FRAGS[pk]; if (!frag) return;
|
|
231
|
+
Object.keys(frag.views || {}).forEach(function (id) { if (PDL_VIEWS[id] && PDL_VIEWS[id].plugin === pk) delete PDL_VIEWS[id]; });
|
|
232
|
+
Object.keys(frag.rows || {}).forEach(function (id) { delete PDL_ROWS[id]; });
|
|
233
|
+
(frag.inserts || []).forEach(function (x) { if (x.node && x.node.sources) delete BADGES['plugin:' + pk + '/' + x.id]; });
|
|
234
|
+
Object.keys(PDL_REPLACES).forEach(function (t) { PDL_REPLACES[t] = PDL_REPLACES[t].filter(function (x) { return x.pk !== pk; }); });
|
|
235
|
+
Object.keys(frag.popups || {}).forEach(function (k) { delete PDL_POPUPS[k]; delete POPUPS[k]; delete S.popOn[k]; });
|
|
236
|
+
Object.keys(PDL_SLOT_ITEMS).forEach(function (slot) { PDL_SLOT_ITEMS[slot] = PDL_SLOT_ITEMS[slot].filter(function (x) { return x.plugin !== pk; }); });
|
|
237
|
+
[PDL_PLUGIN_REQ, PDL_PLUGIN_FRAGS, PDL_SLOT_REJECTS].forEach(function (m) { delete m[pk]; });
|
|
238
|
+
delete WHEN['plugin.' + pk]; delete PDL_PLUGIN_LOADED[pk];
|
|
239
|
+
PDL_PLUGINS.splice(PDL_PLUGINS.indexOf(pk), 1);
|
|
240
|
+
if (frag.inserts) pdlTreeChanged(); else renderForget(); /* 从主题文档重算一遍(用户放过的插件节点还是引用,插件回来时回到原处) */
|
|
241
|
+
}
|
|
242
|
+
/* ═════════════ 插入点═════════════
|
|
243
|
+
插件把自己的节点插进这棵树(容器树、内容容器、视图、消息模板、行模板;按树算,和屏幕上画没画出来无关)。
|
|
244
|
+
定位:anchor 是一个公开的节点 id——容器 id、入口 id、块的字面 key、动作名 act;with 是一组条件(都要成立),每条
|
|
245
|
+
{ anchors(其中之一), direction: up | down | any, depth }。depth 全文一种数法:0 是锚点所在的容器(锚点本身是容器时就是它自己),
|
|
246
|
+
往上每层加 1,超过根就停在根。插入:at before | after 相对锚点本身;inside 放进它(after: 兄弟 id,那个兄弟不在时按 id 字典序);
|
|
247
|
+
写了 depth 时参照点换成往上第 depth 层的容器。命中几处插几处,同一个容器只插一次;一处都没有就用 fallback,还没有就跳过并记下。
|
|
248
|
+
插进来的节点带 ins 和 key(都是 plugin:<插件>/<节点 id>),只在运行时的树上——每次插件登记 / 撤销都先拿掉再从头插;
|
|
249
|
+
用户挪过它(自定义主题里有 { ref: 它 })就放在用户放的地方。 */
|
|
250
|
+
const PDL_INS_LISTS = ['kids', 'blocks', 'items', 'rows', 'ctls', 'body', 'side', 'lanes'];
|
|
251
|
+
/* 树的索引:每个节点 { node, list(它所在的数组;经对象属性挂着的为 null), up(它的容器), rid(登记表里的根:它的登记 id) }。
|
|
252
|
+
共用的模板对象在每个用到它的地方各算一次;一条祖先链上同一个对象只走一次 */
|
|
253
|
+
function pdlTreeIndex() {
|
|
254
|
+
const all = [], roots = new Set();
|
|
255
|
+
const walk = function (x, up, path) {
|
|
256
|
+
Object.keys(x).forEach(function (k) {
|
|
257
|
+
const v = x[k], one = function (y, list) { if (path.has(y)) return; const e = { node: y, list: list, up: up }; all.push(e); path.add(y); walk(y, e, path); path.delete(y); };
|
|
258
|
+
if (Array.isArray(v)) v.forEach(function (y) { if (y && typeof y === 'object' && !Array.isArray(y)) one(y, v); });
|
|
259
|
+
else if (v && typeof v === 'object' && !path.has(v)) { if (v.type) one(v, null); else { path.add(v); walk(v, up, path); path.delete(v); } }
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
const root = function (n, rid) { if (!n || typeof n !== 'object' || roots.has(n)) return; roots.add(n); const e = { node: n, list: null, up: null, rid: rid }; all.push(e); walk(n, e, new Set([n])); };
|
|
263
|
+
root(pdlTree(), null);
|
|
264
|
+
[PDL_SLOTS, PDL_VIEWS, PDL_NODES, PDL_ROWS].forEach(function (reg) { Object.keys(reg).forEach(function (id) { if (!reg[id].cardinality) root(reg[id], id); }); }); /* 带基数的是模板登记(按类型取模板),不是树上的容器 */
|
|
265
|
+
return all;
|
|
266
|
+
}
|
|
267
|
+
function pdlLeafName(n) { const lit = function (v) { return typeof v === 'string' && !/^[@$]/.test(v) ? v : null; }; return [lit(n.key), lit(n.act), lit(n.id)]; }
|
|
268
|
+
function pdlEName(e) { return pdlLeafName(e.node).concat(e.rid ? [e.rid] : []); }
|
|
269
|
+
function pdlNamed(e, names) { const ns = pdlEName(e); return names.some(function (x) { return ns.indexOf(x) >= 0; }); }
|
|
270
|
+
function pdlIsBox(n) { return PDL_INS_LISTS.some(function (k) { return Array.isArray(n[k]); }); }
|
|
271
|
+
/* 第 depth 层的容器:0 是锚点所在的容器(锚点本身是容器时就是它自己),超过根停在根 */
|
|
272
|
+
function pdlLevel(e, depth) { let c = pdlIsBox(e.node) ? e : e.up || e; for (let i = 0; i < (depth || 0) && c.up; i++) c = c.up; return c; }
|
|
273
|
+
function pdlWithin(e, scope, depth) { let x = e.up; for (let d = 0; x && (depth == null || d <= depth); d++, x = x.up) if (x === scope) return true; return false; }
|
|
274
|
+
function pdlWithOk(all, e, cond) {
|
|
275
|
+
const c0 = pdlLevel(e, 0), depth = cond.depth || 0, dir = cond.direction || 'up', names = [].concat(cond.anchors || []);
|
|
276
|
+
return all.some(function (o) {
|
|
277
|
+
if (o === e || !pdlNamed(o, names)) return false;
|
|
278
|
+
const upOk = (dir === 'up' || dir === 'any') && pdlWithin(o, pdlLevel(e, depth));
|
|
279
|
+
const downOk = (dir === 'down' || dir === 'any') && pdlWithin(o, c0, depth);
|
|
280
|
+
return upOk || downOk;
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
function pdlAnchorFind(all, spec) {
|
|
284
|
+
return all.filter(function (e) { return pdlNamed(e, [spec.anchor]) && (spec.with || []).every(function (c) { return pdlWithOk(all, e, c); }); });
|
|
285
|
+
}
|
|
286
|
+
function pdlInsertOne(all, ins, node) {
|
|
287
|
+
const hits = pdlAnchorFind(all, ins), done = new Set();
|
|
288
|
+
hits.forEach(function (e) {
|
|
289
|
+
const ref = ins.depth == null ? e : pdlLevel(e, ins.depth);
|
|
290
|
+
const list = ins.at === 'inside' ? ref.node[ins.part || PDL_INS_LISTS.find(function (k) { return Array.isArray(ref.node[k]); })] : ref.list; /* part:组件的哪一部分(块列表属性,比如消息的 below) */
|
|
291
|
+
if (!list || done.has(list)) return; done.add(list);
|
|
292
|
+
const copy = pdlClone(node);
|
|
293
|
+
if (ins.at === 'inside') pdlKidsPlace(list, copy, ins.after);
|
|
294
|
+
else { const i = list.indexOf(ref.node); list.splice(ins.at === 'before' ? i : i + 1, 0, copy); }
|
|
295
|
+
});
|
|
296
|
+
return done.size;
|
|
297
|
+
}
|
|
298
|
+
function pdlInsertsApply() {
|
|
299
|
+
pdlTreeIndex().forEach(function (e) { const i = e.node.ins && e.list ? e.list.indexOf(e.node) : -1; if (i >= 0) e.list.splice(i, 1); });
|
|
300
|
+
Object.keys(PDL_INSERT_SKIPS).forEach(function (pk) { delete PDL_INSERT_SKIPS[pk]; });
|
|
301
|
+
const all = PDL_PLUGINS.slice().sort().reduce(function (a, pk) {
|
|
302
|
+
return a.concat((PDL_PLUGIN_FRAGS[pk].inserts || []).map(function (x) { return { pk: pk, ins: x }; }));
|
|
303
|
+
}, []).sort(function (a, b) { return (a.ins.priority || 100) - (b.ins.priority || 100); });
|
|
304
|
+
all.forEach(function (x) {
|
|
305
|
+
const pk = x.pk, ins = x.ins, ref = 'plugin:' + pk + '/' + ins.id;
|
|
306
|
+
const node = Object.assign({}, ins.node, { ins: ref, key: ref, id: ref, plugin: pk });
|
|
307
|
+
const tree = pdlTreeIndex(), mine = tree.filter(function (e) { return e.node.ref === ref && e.list; });
|
|
308
|
+
if (mine.length) { mine.forEach(function (e) { const own = Object.assign({}, e.node); delete own.ref; e.list.splice(e.list.indexOf(e.node), 1, Object.assign(pdlClone(node), own)); }); return; } /* 用户放过它:放在用户放的地方,用户改的属性(隐藏、格子、名字、开到哪)照旧 */
|
|
309
|
+
if (pdlInsertOne(tree, ins, node)) return;
|
|
310
|
+
if (ins.fallback && pdlInsertOne(tree, Object.assign({ id: ins.id }, ins.fallback), node)) return;
|
|
311
|
+
if (ENGINE_PARTS.pluginLoad && !PDL_PLUGIN_FRAGS[pk].loaded) return; /* 锚点可能在它还没取回的子树里:取回后重算,在那之前不算找不到 */
|
|
312
|
+
(PDL_INSERT_SKIPS[pk] = PDL_INSERT_SKIPS[pk] || []).push({ id: ins.id, anchor: ins.anchor, reason: 'missing' });
|
|
313
|
+
});
|
|
314
|
+
pdlEntryReset();
|
|
315
|
+
PV_LOC.lang = null; /* 本地化的副本按节点缓存:树变了重新取 */
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/* ═════════════ 加载规则(主题声明完之后调用;声明在 theme/<主题>/layout.js,规则在引擎) ═════════════ */
|
|
319
|
+
/* 节点模板用“插槽/键”声明归属,进入对应的 keyed 插槽。 */
|
|
320
|
+
function pdlNodeSlots() { Object.keys(PDL_NODES).forEach(function (k) { const at = k.indexOf('/'); if (at < 0) return; const slot = k.slice(0, at), key = k.slice(at + 1); pdlContribute(slot, { id: 'core/' + key, key: key, node: PDL_NODES[k] }); }); }
|
|
321
|
+
/* ═════════════ 摆放 ═════════════ */
|
|
322
|
+
function pdlClone(o) { return JSON.parse(JSON.stringify(o)); }
|
|
323
|
+
/* when 可以是多个条件,全部满足才出现 */
|
|
324
|
+
/* 条件(一个或一组,都成立才算):能力条件的名字(WHEN,应用登记),或者对这一处上下文 sc 的条件——'@字段' / '!@字段'(pvOk,比如消息操作的“这条是成员发的”)。
|
|
325
|
+
引擎不认条件和字段的名字,它们来自声明 */
|
|
326
|
+
function pdlWhen(w, sc) { if (!w) return true; return (Array.isArray(w) ? w : [w]).every(function (x) { if (/^!?(?:@|plugin:)/.test(x)) return pvOk(x, sc || {}, sc || {}); return WHEN[x] ? !!WHEN[x]() : false; }); }
|
|
327
|
+
S.pdlSkin = 'default'; /* 由当前主题决定(pdl-doc.js 的 pdlThemeSync) */
|
|
328
|
+
/* ═════════════ 界面树:区域 → 容器 → 操作组 → 项(同一棵树服务三件事:用户编辑、插件定位、显示 / 隐藏) ═════════════
|
|
329
|
+
由 PDL 本身生成(布局里的区域、外壳插槽、页面描述里带 key 的块、页面插槽),不是手写的清单。 */
|
|
330
|
+
const PDL_REGION_ESSENTIAL = { rail: true, main: true }; /* 窄栏(设置入口在这)和主区不能隐藏 */
|
|
331
|
+
function pdlViewNodes(blocks, out) {
|
|
332
|
+
(blocks || []).forEach(function (b) {
|
|
333
|
+
if (!b || typeof b !== 'object') return;
|
|
334
|
+
const here = b.key ? { key: b.key, kind: b.kind || 'action', essential: !!b.essential, locked: !!b.locked, label: b.key, children: [] } : null;
|
|
335
|
+
const kids = here ? here.children : out;
|
|
336
|
+
if (b.type === 'view' && PDL_VIEWS[b.id]) pdlViewNodes(PDL_VIEWS[b.id].blocks, kids);
|
|
337
|
+
if (b.type === 'slot' && PDL_SLOTS[b.slot]) { if (here) here.slot = b.slot; }
|
|
338
|
+
['blocks', 'items', 'head', 'bar', 'top', 'body', 'dock', 'side'].forEach(function (f) { if (Array.isArray(b[f])) pdlViewNodes(b[f], kids); });
|
|
339
|
+
if (Array.isArray(b.lanes)) b.lanes.forEach(function (l) { pdlViewNodes(l.items, kids); });
|
|
340
|
+
if (here) out.push(here);
|
|
341
|
+
});
|
|
342
|
+
return out;
|
|
343
|
+
}
|
|
344
|
+
function pdlNodeTree() {
|
|
345
|
+
const slotNode = function (s) {
|
|
346
|
+
const d = PDL_SLOTS[s];
|
|
347
|
+
return { key: s, kind: d.scope ? 'actions' : 'container', label: null, title: d.label, slot: s,
|
|
348
|
+
children: (d.kids || []).filter(function (n) { return !n.type && !n.ref; }).map(function (n) { const k = pdlId(n); return { key: k, kind: pdlKindOf(k), title: n.title, essential: !!n.essential || !!n.move, plugin: n.plugin || null, children: [] }; }) };
|
|
349
|
+
};
|
|
350
|
+
/* 区域里的节点:区域声明了 nodes { view, slots }(这个区域代表的那一页的视图、页里的插槽)就是那一页的节点 + 这些插槽;否则是这个布局容器用 slots 声明的内容容器 */
|
|
351
|
+
return pdlLayout().order.map(function (r) {
|
|
352
|
+
const rd = pdlLayout().regions[r], nd = rd.nodes, box = pdlNode(r) || {};
|
|
353
|
+
const kids = nd ? pdlViewNodes(PDL_VIEWS[nd.view].blocks, []).concat((nd.slots || []).map(slotNode)) : (box.slots || []).filter(function (s) { return PDL_SLOTS[s]; }).map(slotNode);
|
|
354
|
+
return { key: 'region:' + r, kind: 'region', title: rd.label, essential: true, children: kids };
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
function pdlNodeFind(key, nodes) { for (const n of nodes || pdlNodeTree()) { if (n.key === key) return n; const f = pdlNodeFind(key, n.children); if (f) return f; } return null; }
|
|
358
|
+
/* 隐藏:节点自己的 hidden(不是删除:升级、恢复都只是把开关打开)。必要元素永远不隐藏 */
|
|
359
|
+
A.pdlHideToggle = function (d) {
|
|
360
|
+
const k = d.k, n = pdlNodeFind(k); if (!n || n.essential) return;
|
|
361
|
+
pdlNodeSet(k, { hidden: pdlNodeHidden(k) ? null : true });
|
|
362
|
+
render(true);
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
/* 插件加进菜单插槽的项:交给菜单(宿主自己的项写在 MENU_FNS 里) */
|
|
366
|
+
function pdlMenuItems(slot, data) {
|
|
367
|
+
if (pdlNodeHidden(slot)) return [];
|
|
368
|
+
return pdlKids(slot).map(function (id) {
|
|
369
|
+
const e = pdlEntry(id); if (!e || !pdlWhen(e.when) || pdlNodeHidden(id)) return null;
|
|
370
|
+
return { label: e.title, act: e.open.action, data: Object.assign({ entry: id }, e.open.args, data || {}) };
|
|
371
|
+
}).filter(Boolean);
|
|
372
|
+
}
|
|
373
|
+
/* 分组标题:键是稳定的 '#键',显示文字是节点的 label(用户改过的),否则来自文案包;用户自己加的标题(文案包里没有)直接显示键后面的字 */
|
|
374
|
+
function pdlHeadLabel(id) {
|
|
375
|
+
const own = (pdlEntry(id) || {}).label; if (own) return own;
|
|
376
|
+
const k = 'pdlDoc.heads.' + id.slice(1), v = tc(k); return v === k ? id.slice(1) : v;
|
|
377
|
+
}
|
|
378
|
+
/* 窄栏里有没有这个入口(它自己,或指向它的引用按钮) */
|
|
379
|
+
function pdlRailRef(id) { return ['rail.top', 'rail.bottom'].map(function (s) { return (PDL_SLOTS[s].kids || []).find(function (n) { return n.id === id || n.ref === id; }); }).find(Boolean) || null; }
|
|
380
|
+
function pdlInRail(id) { return !!pdlRailRef(id); }
|
|
381
|
+
|
|
382
|
+
/* ═════════════ 渲染 ═════════════ */
|
|
383
|
+
/* frame:插件界面在哪个区域打开(main 整页、overlay 浮窗、panel 右侧工作台) */
|
|
384
|
+
/* ═════════════ 布局:逻辑区域(两层:默认 → 覆盖;渲染只用合并后的结果) ═════════════
|
|
385
|
+
默认:区域的顺序和属性(工作台是标签式区域);皮肤的布局数据叠在上面。区域的先后就是容器树的先后(pdlTree,自定义主题里整棵存);
|
|
386
|
+
入口开到哪写在入口(和它所在的容器)上(pdlOpenOf)。
|
|
387
|
+
区域顺序在编辑布局里拖区域顶上的把手调整(区域是同级节点之间换位置,里面的东西跟着走);窄栏放着设置入口,固定不动。
|
|
388
|
+
受保护区域 = 放着设置入口的那个区域(由摆放推出,不按位置写死),永远不能被占用。 */
|
|
389
|
+
const PDL_LAYOUT = {};
|
|
390
|
+
/* 空间(第二栏显示什么):主页 home、属于它的路由 routes(prefix:插件页面的路由前缀);没列出的路由属于 fallback 空间。
|
|
391
|
+
start:打开时进入它的主页;panel:工作台在这个空间里;own:进出它的路由就换空间。别的字段(threadView / threadRoutes)引擎不读,归应用 */
|
|
392
|
+
const PDL_SPACES = {};
|
|
393
|
+
const PDL_LAYOUT_SKINS = {}; /* 皮肤自己的布局数据(区域顺序、入口在哪打开);返回带不带上一层的标题不是皮肤的开关,按容器 / 打开方式声明 */
|
|
394
|
+
/* 结构页里加的容器(容器树上不在默认树里的):它用 slots 声明自己的内容容器 ct:<键>(在自定义主题里),编辑布局时可以把入口拖进来 */
|
|
395
|
+
function pdlTreeWalk(n, f, p) { f(n, p); (n.kids || []).forEach(function (k) { pdlTreeWalk(k, f, n); }); }
|
|
396
|
+
function pdlTreeBuiltin(k) { let hit = false; pdlTreeWalk(PDL_LAYOUT.tree, function (n) { if (n.key === k) hit = true; }); return hit; }
|
|
397
|
+
/* ───────── 结构(主题计算器的“结构”页编辑的容器树)─────────
|
|
398
|
+
只编辑容器:加、删(只有空的能删)、移动 / 换父容器、属性(名字、方向、在父容器里的份额)。元素只在页面的编辑布局里移动,从不删除。
|
|
399
|
+
锁(都由声明推出,不认名字):空间的结构(空间容器 = 分组标题,页面容器 = 详情)锁住;内置容器只能在父容器里换顺序(它们的画法和位置有关),用户加的容器可以换父容器。
|
|
400
|
+
每次编辑都是对当前主题文档的一次编辑(系统主题先自动复制,带撤销) */
|
|
401
|
+
function pdlCtInfo(k) {
|
|
402
|
+
const t = pdlTree(); let node = null, parent = null;
|
|
403
|
+
pdlTreeWalk(t, function (n, p) { if (n.key === k) { node = n; parent = p; } });
|
|
404
|
+
if (!node) return null;
|
|
405
|
+
const builtin = pdlTreeBuiltin(k), entries = pdlKids('ct:' + k).length;
|
|
406
|
+
const locked = !!node.space || !!node.pages || !parent;
|
|
407
|
+
const accepts = !builtin || (node.kids && node.kids.length > 0); /* 能放子容器:用户加的盒子、内置的布局容器(有子容器的) */
|
|
408
|
+
const empty = !builtin && !(node.kids && node.kids.length) && !entries;
|
|
409
|
+
const hosts = pdlEntryIds().filter(function (id) { const e = pdlEntry(id), o = e.open && !e.open.ref && !e.ref ? pdlOpenOf(id) : null; return o && o.target === k; }); /* 开在这里的按钮(真声明;引用跟着真声明) */
|
|
410
|
+
return { node: node, parent: parent, builtin: builtin, locked: locked, accepts: accepts, empty: empty, hosts: hosts,
|
|
411
|
+
whyDel: locked ? tc('structure.whyLocked') : !empty ? tc('structure.whyNotEmpty') : hosts.length ? tc('structure.whyHosting') : '', /* 内置容器放着内置内容,永远不空;有按钮开在这里的先迁移承载 */
|
|
412
|
+
whyMove: locked ? tc('structure.whyLocked') : '' };
|
|
413
|
+
}
|
|
414
|
+
function pdlTreeEdit(fn, also) {
|
|
415
|
+
const t = pdlClone(pdlTree()); fn(t);
|
|
416
|
+
pdlDocEdit(function (full) { full.layout = Object.assign({}, full.layout || {}, { tree: t }); if (also) also(full); });
|
|
417
|
+
pdlTreeChanged();
|
|
418
|
+
}
|
|
419
|
+
function pdlTreeFind(t, k) { let r = null; pdlTreeWalk(t, function (n, p) { if (n.key === k) r = { n: n, p: p }; }); return r; }
|
|
420
|
+
/* 加一个子容器(空的:页面上不占地方,编辑布局时是虚线的落点) */
|
|
421
|
+
function pdlCtAdd(parentKey) {
|
|
422
|
+
const info = pdlCtInfo(parentKey); if (!info || !info.accepts) return null;
|
|
423
|
+
const key = 'c' + Date.now().toString(36); let n = 1; pdlTreeWalk(pdlTree(), function (x) { if (!pdlTreeBuiltin(x.key)) n += 1; });
|
|
424
|
+
const label = tc('structure.newName', n);
|
|
425
|
+
pdlTreeEdit(function (t) { const f = pdlTreeFind(t, parentKey); f.n.kids = (f.n.kids || []).concat([{ key: key, label: label, dir: 'column', span: 'fit', hideEmpty: true, slots: ['ct:' + key] }]); },
|
|
426
|
+
function (full) { full.slots = full.slots || {}; full.slots['ct:' + key] = { display: 'icon', label: label, accepts: '*', kids: [] }; });
|
|
427
|
+
return key;
|
|
428
|
+
}
|
|
429
|
+
function pdlCtDel(k) { const info = pdlCtInfo(k); if (!info || info.whyDel) return false; pdlTreeEdit(function (t) { const f = pdlTreeFind(t, k); f.p.kids = f.p.kids.filter(function (x) { return x.key !== k; }); }, function (full) { if (full.slots) delete full.slots['ct:' + k]; }); return true; }
|
|
430
|
+
/* 移动:放到 target 的前面 / 后面(同一个父容器里换顺序,或者换父容器)或里面(成为它的最后一个子容器) */
|
|
431
|
+
function pdlCtMoveWhy(k, target, zone) {
|
|
432
|
+
const a = pdlCtInfo(k), b = pdlCtInfo(target); if (!a || !b || k === target) return 'x';
|
|
433
|
+
if (a.whyMove) return a.whyMove;
|
|
434
|
+
let inside = false; pdlTreeWalk(a.node, function (n) { if (n.key === target) inside = true; }); if (inside) return 'x';
|
|
435
|
+
const parent = zone === 'inside' ? b.node : b.parent; if (!parent) return 'x';
|
|
436
|
+
if (zone === 'inside' && !b.accepts) return tc('structure.whyNoKids');
|
|
437
|
+
if (a.builtin && parent.key !== a.parent.key) return tc('structure.whyBuiltinMove');
|
|
438
|
+
return '';
|
|
439
|
+
}
|
|
440
|
+
function pdlCtMove(k, target, zone) {
|
|
441
|
+
if (pdlCtMoveWhy(k, target, zone)) return false;
|
|
442
|
+
pdlTreeEdit(function (t) {
|
|
443
|
+
const f = pdlTreeFind(t, k); f.p.kids = f.p.kids.filter(function (x) { return x.key !== k; });
|
|
444
|
+
const g = pdlTreeFind(t, target);
|
|
445
|
+
if (zone === 'inside') { g.n.kids = (g.n.kids || []).concat([f.n]); return; }
|
|
446
|
+
const sib = g.p.kids, i = sib.indexOf(g.n); sib.splice(zone === 'after' ? i + 1 : i, 0, f.n);
|
|
447
|
+
});
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
/* 单个按钮改开到哪(迁移承载也是它):改的是按钮自己的 open(锚点 = 选的容器,层级 0),在当前主题文档里 */
|
|
451
|
+
function pdlOpenRebind(id, to) {
|
|
452
|
+
const e = pdlEntry(id), o = pdlOpenOf(id); if (!e || !o || o.forced) return false;
|
|
453
|
+
const open = Object.assign({}, e.open, { anchor: to, as: o.as }); delete open.depth;
|
|
454
|
+
pdlNodeSet(id, { open: open });
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
function pdlCtSet(k, props) { pdlTreeEdit(function (t) { const f = pdlTreeFind(t, k); Object.assign(f.n, props); }); }
|
|
458
|
+
/* 当前主题文档里的布局覆盖(只读这里;改的时候走 pdlDocEdit,在系统主题上会先复制出自定义主题) */
|
|
459
|
+
function pdlLayoutMerge(base, ov) {
|
|
460
|
+
if (!ov) return base;
|
|
461
|
+
if (ov.order) base.order = ov.order.slice();
|
|
462
|
+
Object.keys(ov.regions || {}).forEach(function (k) { base.regions[k] = Object.assign({}, base.regions[k] || {}, ov.regions[k]); });
|
|
463
|
+
return base;
|
|
464
|
+
}
|
|
465
|
+
function pdlLayout() {
|
|
466
|
+
const L = pdlLayoutMerge(pdlClone(PDL_LAYOUT), PDL_LAYOUT_SKINS[S.pdlSkin] || null);
|
|
467
|
+
/* 区域的顺序就是它们在生效的容器树里的先后(用户拖区域 = 改树,pdlTreeOrder) */
|
|
468
|
+
const order = []; pdlTreeWalk(pdlTree(), function (n) { if (L.order.indexOf(n.key) >= 0 && order.indexOf(n.key) < 0) order.push(n.key); });
|
|
469
|
+
L.order = order.concat(L.order.filter(function (k) { return order.indexOf(k) < 0; }));
|
|
470
|
+
return L;
|
|
471
|
+
}
|
|
472
|
+
/* 生效的容器树:当前主题文档里的(full.layout.tree:结构页、编辑布局拖区域都改它)或默认的。结果按主题文档缓存(主题换了 / 文档改了就作废) */
|
|
473
|
+
let PDL_TREE_C = null;
|
|
474
|
+
function pdlTreeReset() { PDL_TREE_C = null; }
|
|
475
|
+
function pdlTree() {
|
|
476
|
+
if (PDL_TREE_C) return PDL_TREE_C;
|
|
477
|
+
const f = S.pdlDoc && S.pdlDoc.full, ut = f && f.layout && f.layout.tree;
|
|
478
|
+
return (PDL_TREE_C = pdlClone(ut || PDL_LAYOUT.tree));
|
|
479
|
+
}
|
|
480
|
+
/* 编辑布局拖区域:按拖完的顺序(区域键,跨了 flat 容器)重排树里每一层的孩子 */
|
|
481
|
+
function pdlTreeOrder(list) {
|
|
482
|
+
const keys = function (n) { return [n.key].concat([].concat.apply([], (n.kids || []).map(keys))); };
|
|
483
|
+
const sortKids = function (n) {
|
|
484
|
+
(n.kids || []).forEach(sortKids);
|
|
485
|
+
if (!n.kids) return;
|
|
486
|
+
const rank = function (k) { const xs = keys(k).map(function (x) { return list.indexOf(x); }).filter(function (i) { return i >= 0; }); return xs.length ? Math.min.apply(null, xs) : -1; };
|
|
487
|
+
const ranked = n.kids.filter(function (k) { return rank(k) >= 0; }).sort(function (a, b) { return rank(a) - rank(b); });
|
|
488
|
+
let i = 0; n.kids = n.kids.map(function (k) { return rank(k) >= 0 ? ranked[i++] : k; });
|
|
489
|
+
};
|
|
490
|
+
pdlTreeEdit(sortKids);
|
|
491
|
+
}
|
|
492
|
+
/* ═════════════ 打开═════════════
|
|
493
|
+
入口的 open:{ page | view | frame | space | action, anchor?, depth?, as? } 或 { ref: 另一个入口, args? }。开到哪写在触发它的入口上:
|
|
494
|
+
入口自己写了 anchor / depth / as 就用它;没写用所在容器(内容容器,或放它的布局容器)声明的 opens;容器的 opens 带 force 时一律按容器的。
|
|
495
|
+
anchor 是一个 id(入口、内容容器、布局容器),depth 从锚点所在的容器往上数(锚点是容器时就是它自己),超过根停在根。
|
|
496
|
+
as:cover 进目标容器的叠(导航,返回照通用返回);beside 和它的兄弟并排(标签式容器里是一项);float 进弹窗栈。
|
|
497
|
+
没有触发者的节点(只从地址进来的)用它自己声明的 open。 */
|
|
498
|
+
/* 从锚点往外的容器链:内容容器 → 放它的布局容器 → …;锚点在视图里时顺着声明树往上(只算容器),出了视图的根接上触发元素所在的布局容器链 */
|
|
499
|
+
function pdlOpenChain(anchor, el) {
|
|
500
|
+
const out = [];
|
|
501
|
+
let box = null;
|
|
502
|
+
if (pdlSlotDef(anchor)) { out.push(anchor); box = pdlSlotBox(anchor); }
|
|
503
|
+
else if (pdlSlotOf(anchor)) { const s = pdlSlotOf(anchor); out.push(s); box = pdlSlotBox(s); }
|
|
504
|
+
else if (ctNode(anchor)) box = anchor;
|
|
505
|
+
else {
|
|
506
|
+
const hit = pdlTreeIndex().find(function (e) { return pdlNamed(e, [anchor]); }); if (!hit) return out;
|
|
507
|
+
for (let x = pdlIsBox(hit.node) ? hit : hit.up; x && !x.rid; x = x.up) if (pdlIsBox(x.node) && x.node.key) out.push(x.node.key);
|
|
508
|
+
return out.concat(el ? trigChain(el).chain : ctAnc(ctPages()));
|
|
509
|
+
}
|
|
510
|
+
for (let c = box; c; c = ctParent(c)) out.push(c);
|
|
511
|
+
return out;
|
|
512
|
+
}
|
|
513
|
+
function pdlOpenTarget(spec, el) {
|
|
514
|
+
const chain = pdlOpenChain(spec.anchor, el); if (!chain.length) return ctPages();
|
|
515
|
+
const c = chain[Math.min(spec.depth || 0, chain.length - 1)];
|
|
516
|
+
return pdlSlotDef(c) ? pdlSlotBox(c) || ctPages() : c; /* 内容容器自己没有叠:开进放它的布局容器 */
|
|
517
|
+
}
|
|
518
|
+
function pdlOpenOf(id, el, read) {
|
|
519
|
+
const e = pdlEntry(id); if (!e || !e.open) return null;
|
|
520
|
+
const data = read && e.sources ? VM.plugin(e.plugin, e.sources) : {};
|
|
521
|
+
let o = read ? pvDeep(e.open, data, data) : Object.assign({}, e.open), owner = id;
|
|
522
|
+
if (o.ref) { const t = pdlEntry(o.ref); if (!t || !t.open) return null; owner = o.ref; o = Object.assign({}, t.open, o.args ? { args: Object.assign({}, t.open.args, o.args) } : {}); } /* 引用:照真声明打开,参数可以覆盖 */
|
|
523
|
+
if (o.action || o.space) return o;
|
|
524
|
+
const slot = pdlSlotOf(owner), box = slot && pdlSlotBox(slot), rule = ((slot && pdlSlotDef(slot)) || {}).opens || (box && (pdlNode(box) || {}).opens) || null;
|
|
525
|
+
const own = o.as || o.anchor ? { anchor: o.anchor || owner, depth: o.depth, as: o.as } : null;
|
|
526
|
+
const use = rule && rule.force ? rule : own || rule || { anchor: ctPages(), as: 'cover' };
|
|
527
|
+
o.as = use.as || 'cover'; o.target = use.as === 'float' ? null : pdlOpenTarget(use, el); o.forced = !!(rule && rule.force);
|
|
528
|
+
if (o.node && PDL_VIEWS[o.node]) { const n = PDL_VIEWS[o.node]; o.focus = !!n.focus; o.popup = n.popup || null; }
|
|
529
|
+
return o;
|
|
530
|
+
}
|
|
531
|
+
/* 一个页面的真声明:打开它的那个入口(不是引用);没有就是 null(页面开到页面容器) */
|
|
532
|
+
function pdlPageDecl(page) { return pdlEntryIds().find(function (id) { const o = (pdlEntry(id) || {}).open || {}; return o.page === page && !o.ref; }) || null; }
|
|
533
|
+
/* 一个节点归哪个入口(谁打开它);没有就用它自己声明的 open */
|
|
534
|
+
function pdlNodeOwner(n) { return pdlEntryIds().find(function (id) { const o = (pdlEntry(id) || {}).open || {}; return o.node === n && !o.ref; }) || null; }
|
|
535
|
+
function pdlNodeOpen(n) { const owner = pdlNodeOwner(n); if (owner) return pdlOpenOf(owner); const own = (PDL_VIEWS[n] || {}).open; return own ? Object.assign({ node: n, as: own.as || 'cover', target: own.as === 'float' ? null : pdlOpenTarget(own) }) : { node: n, as: 'cover', target: ctPages() }; }
|
|
536
|
+
function pdlNodeCur(n, o) {
|
|
537
|
+
if (o.as === 'float') return !!S.popOn[o.popup];
|
|
538
|
+
if (REGION_TABS[o.target]) return rtCur(o.target) === n; /* 开进标签式容器:那一项就是它 */
|
|
539
|
+
return !!navFrameAt('node:' + n);
|
|
540
|
+
}
|
|
541
|
+
function pdlEntryAlso(e) {
|
|
542
|
+
const own = e.also || [];
|
|
543
|
+
if (!e.alsoFrom) return own;
|
|
544
|
+
return own.concat(pdlKids(e.alsoFrom).map(function (id) { return (pdlEntry(id) || {}).open || {}; }).map(function (open) { return open.page; }).filter(Boolean));
|
|
545
|
+
}
|
|
546
|
+
function pdlCur(id) {
|
|
547
|
+
const e = pdlEntry(id), o = pdlOpenOf(id); if (!o) return false;
|
|
548
|
+
if (o.space) return space() === o.space;
|
|
549
|
+
if (o.node && PDL_VIEWS[o.node]) return pdlNodeCur(o.node, o);
|
|
550
|
+
if (REGION_TABS[o.target]) return rtCur(o.target) === (o.node || ENGINE_PARTS.rtPageKey(o.target, id));
|
|
551
|
+
if (o.page) return S.route === o.page || pdlEntryAlso(e).indexOf(S.route) >= 0;
|
|
552
|
+
if (o.action && e.on) return !!S[e.on];
|
|
553
|
+
return false;
|
|
554
|
+
}
|
|
555
|
+
/* 行插槽:给出这一行的操作(交给 lrow 的 acts) */
|
|
556
|
+
function pdlNeed(n, c) { return (Array.isArray(n) ? n : n ? [n] : []).every(function (k) { return k[0] === '!' ? !c[k.slice(1)] : !!c[k]; }); }
|
|
557
|
+
function pdlFill(t, c) { return t.replace(/\{(\w+)\}/g, function (_, k) { return c[k] == null ? '' : c[k]; }); }
|
|
558
|
+
function pdlEntryActionReady(e) {
|
|
559
|
+
const action = e.open?.action;
|
|
560
|
+
if (!e.plugin || !action?.startsWith('plugin:') || A[action]) return true;
|
|
561
|
+
pdlPluginNeed(e.plugin);
|
|
562
|
+
return false;
|
|
563
|
+
}
|
|
564
|
+
function pdlActs(slot, c) {
|
|
565
|
+
return pdlKids(slot).map(function (id) {
|
|
566
|
+
const e = pdlEntry(id); if (!e || !pdlWhen(e.when, c) || !pdlNeed(e.need, c) || !pdlEntryActionReady(e)) return null;
|
|
567
|
+
/* 守卫给原因(数据);入口声明了 why 时按它写成字(行上下文 + guard = 守卫给的原因) */
|
|
568
|
+
const g = e.guard && PDL_GUARDS[e.guard[0]] ? PDL_GUARDS[e.guard[0]](c, e.guard[1]) : '', why = g && e.why ? pv(e.why, Object.assign({}, c, { guard: g }), c) : g || '';
|
|
569
|
+
const data = Object.keys(e.args || {}).map(function (a) { return ' data-' + a + '="' + h(c[e.args[a]] == null ? '' : c[e.args[a]]) + '"'; }).join('') + (e.plugin ? ' data-entry="' + id + '"' : '');
|
|
570
|
+
return { label: pdlFill(pdlText(e.title), c), icon: e.icon, act: e.open.action, data: argAttrs(e.open.args) + data, why: why };
|
|
571
|
+
}).filter(Boolean);
|
|
572
|
+
}
|
|
573
|
+
/* 标签式容器的工具菜单(布局声明 chrome.tools,比如工作台的启动面板):里面的页面入口变成容器里的一项(组件库的 rtPage),
|
|
574
|
+
打开 frame 的入口在插件启用时登记成一项,停用 / 挪出去时拿掉(正开着就收起容器) */
|
|
575
|
+
const PANEL_FRAMES = {}; /* 标签式容器 → 这一轮登记成一项的 frame 键(下一轮不在了就拿掉) */
|
|
576
|
+
function pdlPanelSync() {
|
|
577
|
+
Object.keys(REGION_TABS).forEach(function (r) {
|
|
578
|
+
const slot = rtCfg(r).tools; if (!slot) return;
|
|
579
|
+
const list = pdlKids(slot), now = {}, previous = PANEL_FRAMES[r] || {};
|
|
580
|
+
ENGINE_PARTS.rtPagePrune(r, pdlEntryIds().filter(function (id) { const o = pdlOpenOf(id); return o && o.target === r && !pdlNodeHidden(id); })); /* 不再开到这里的入口:它的项收起 */
|
|
581
|
+
list.forEach(function (id) { const e = pdlEntry(id); if (e && e.open && e.open.page && pdlWhen(e.when) && !pdlNodeHidden(id)) ENGINE_PARTS.rtPage(r, id); });
|
|
582
|
+
/* 开到这个容器的节点(入口放在哪都一样:开到哪由入口决定):登记成一项,键是节点 id */
|
|
583
|
+
pdlEntryIds().forEach(function (id) {
|
|
584
|
+
const e = pdlEntry(id), n = e && e.open && !e.open.ref && e.open.node, nd = n && PDL_VIEWS[n]; if (!nd || !pdlWhen(e.when) || pdlNodeHidden(id)) return;
|
|
585
|
+
const o = pdlOpenOf(id); if (!o || o.target !== r) return;
|
|
586
|
+
const view = VIEW_ENTRIES.get(n);
|
|
587
|
+
if (!view) now[n] = registerView({ id: n, view: n, title: e.title, icon: e.icon, group: e.group || rtCfg(r).pageGroup });
|
|
588
|
+
else if (view === previous[n]) now[n] = view;
|
|
589
|
+
});
|
|
590
|
+
Object.entries(previous).forEach(function ([key, view]) {
|
|
591
|
+
if (now[key] || VIEW_ENTRIES.get(key) !== view) return;
|
|
592
|
+
VIEW_ENTRIES.delete(key);
|
|
593
|
+
if (rtCur(r) === key) navTabs(r).open = false;
|
|
594
|
+
});
|
|
595
|
+
PANEL_FRAMES[r] = now;
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
beforeRender(pdlPanelSync);
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
/* ═════════════ 动作 ═════════════ */
|
|
602
|
+
/* 声明里不是参数的键(打开到哪、怎么开) */
|
|
603
|
+
const OPEN_KEYS = { ref: 1, page: 1, node: 1, action: 1, space: 1, anchor: 1, depth: 1, as: 1, exit: 1, address: 1, path: 1, v: 1, cast: 1, from: 1, entry: 1, replace: 1 }; /* from / entry:触发者在哪个插槽里、它是哪个入口(编辑布局用),不是参数 */
|
|
604
|
+
function pdlOpenSpec(d, el) {
|
|
605
|
+
if (el === undefined) el = ACT_FROM; /* 程序里的打开:按正在处理的那次操作的触发者算 */
|
|
606
|
+
const args = {}; Object.keys(d).forEach(function (k) { if (!OPEN_KEYS[k]) args[k] = d[k]; });
|
|
607
|
+
if (d.ref) { const o = pdlOpenOf(d.ref, el, true); if (!o) return; if (o.space) { spaceOpen(o.space); return; } if (o.action) { actFn(o.action)(Object.assign({}, o.args, args), null); return; } pdlOpenNode(Object.assign({}, o, { args: Object.assign({}, o.args, args) }), el, d.ref); return; } /* 引用:照真声明打开,参数覆盖同名的 */
|
|
608
|
+
const m = d.page && !PAGES[d.page] && /^([a-zA-Z]+)-(.+)$/.exec(d.page); /* 页名-参数(地址的写法):拆开 */
|
|
609
|
+
if (m && PAGES[m[1]]) { d = Object.assign({}, d, { page: m[1] }); args.p = m[2]; }
|
|
610
|
+
if (d.page && !d.anchor) { pagesOpen(d.page, args, el, { address: d.address, ask: true, replace: d.replace === true || d.replace === 'true', exit: d.exit ? String(d.exit).split(',') : null }); return; } /* 页面,没写开在哪:开到页面容器(从内容里开别的空间的页面时盖在原处,见 pagesOpen) */
|
|
611
|
+
const as = d.as || 'cover', target = as === 'float' ? null : pdlOpenTarget({ anchor: d.anchor, depth: d.depth }, el);
|
|
612
|
+
if (d.node && REGION_TABS[target]) { ENGINE_PARTS.openTab(target, d.node); return; } /* 标签式容器里的一项:和入口打开它同一条路 */
|
|
613
|
+
pdlOpenNode({ page: d.page, node: d.node, args: args, as: as, target: target, exit: d.exit ? String(d.exit).split(',') : null }, el);
|
|
614
|
+
}
|
|
615
|
+
/* 节点上的事件:入口写 on: { <事件>: { open } }(点击就是入口自己的 open)。声明过的每种事件在文档上只听一次;
|
|
616
|
+
事件落在一个入口(data-entry)上、它声明了这个事件,就照声明打开,触发处是指针所在的点(浮着开的贴着它) */
|
|
617
|
+
const PDL_ON = {};
|
|
618
|
+
function pdlOnListen() {
|
|
619
|
+
pdlEntryIds().forEach(function (id) { Object.keys((pdlEntry(id) || {}).on || {}).forEach(function (ev) { if (!PDL_ON[ev]) { PDL_ON[ev] = true; document.addEventListener(ev, pdlOnEvent, true); } }); });
|
|
620
|
+
}
|
|
621
|
+
function pdlOnEvent(e) {
|
|
622
|
+
const el = e.target.closest && e.target.closest('[data-entry]'), d = el && pdlEntry(el.dataset.entry), on = d && pdlWhen(d.when) && d.on && d.on[e.type];
|
|
623
|
+
if (!on || !on.open) return;
|
|
624
|
+
e.preventDefault(); e.stopPropagation();
|
|
625
|
+
spotOpen('point', el, { left: e.clientX, top: e.clientY, width: 1, height: 1 }, function (spot) { pdlOpenSpec(on.open, spot); });
|
|
626
|
+
}
|
|
627
|
+
/* 打开一个算好的 open(入口、引用、程序里按地址进来的都走这里) */
|
|
628
|
+
function pdlOpenNode(o, el, id) {
|
|
629
|
+
const nd = o.node ? PDL_VIEWS[o.node] : null; if (o.node && nd && nd.plugin && !plugOn(nd.plugin)) return;
|
|
630
|
+
if (nd && nd.plugin) pdlPluginNeed(nd.plugin);
|
|
631
|
+
if (o.as === 'float') { S.popOn[nd.popup] = !S.popOn[nd.popup]; if (o.after) o.after(); render(true); return; } /* 浮窗之间不互斥(弹窗栈管层级) */
|
|
632
|
+
const tab = REGION_TABS[o.target];
|
|
633
|
+
if (tab) {
|
|
634
|
+
const k = o.node || ENGINE_PARTS.rtPage(o.target, id);
|
|
635
|
+
if (tab.visible(k) && tab.exists(k)) { rtReveal(o.target, k, o.after ? { after: o.after } : undefined); return; }
|
|
636
|
+
if (tab.visible(k) && tab.shown && tab.shown(k)) { if (o.after) o.after(); return; }
|
|
637
|
+
if (o.page && PAGES[o.page]) { pagesOpen(o.page, o.args || {}, el, { address: o.address, replace: o.replace, exit: o.exit, after: o.after }); return; }
|
|
638
|
+
rtReveal(o.target, k, o.after ? { after: o.after } : undefined); return;
|
|
639
|
+
} /* 标签式容器:容器可见且能承载时作为它的一项;容器不可用且有独立页面时退回页面 */
|
|
640
|
+
const f = nd ? 'node:' + o.node : o.page;
|
|
641
|
+
if (o.as === 'beside') { const on = NAV.on[o.target] = NAV.on[o.target] || []; if (on.indexOf(f) < 0) on.push(f); if (o.after) o.after(); render(true); return; } /* 并排:已经开着就不再开一份;关由它自己(close { beside }) */
|
|
642
|
+
if (!ctNode(o.target)) { const c = o.target; navLeave(navIdsFrom(c, 1), function () { navPushRaw(c, f, o.args || {}, navTitleAt(el)); if (o.after) o.after(); navAfter(); }); return; } /* 视图里的容器:压进它自己的叠,返回在它左上角 */
|
|
643
|
+
if (nd) {
|
|
644
|
+
const at = navFrameAt('node:' + o.node); /* 入口还露在外面时再点一下就关掉 */
|
|
645
|
+
if (at) { if (navDepth(at) > 1) navBack(at); else navClose(at); if (o.after) o.after(); return; }
|
|
646
|
+
navReset({ popupsOnly: true });
|
|
647
|
+
navOpen({ f: 'node:' + o.node, a: o.args || {}, into: o.target, push: !!nd.focus, exit: o.exit || nd.exit }, el); if (o.after) o.after(); return;
|
|
648
|
+
}
|
|
649
|
+
if (o.page && o.target === ctPages()) { pagesOpen(o.page, o.args || {}, el, { address: o.address, replace: o.replace, exit: o.exit, after: o.after }); return; } /* 主区:只换主区,第二栏不变 */
|
|
650
|
+
if (o.page) { navOpen({ f: o.page, a: o.args || {}, into: o.target }, el); if (o.after) o.after(); }
|
|
651
|
+
}
|
|
652
|
+
/* 切换空间:只有这里改第二栏(空间容器的栈顶);页面容器切到这个空间上次停的那一页(没去过:它的主页)。切走的空间不销毁,它的页面隐藏着留下(proj.js navHide),回来时原样回来。
|
|
653
|
+
已经在这个空间:回到它的主页 */
|
|
654
|
+
function spaceOpen(v) {
|
|
655
|
+
const t = v !== S.space && navSpaceTarget(v);
|
|
656
|
+
if (!t) { go((PDL_SPACES[v] || {}).home || S.route); return; }
|
|
657
|
+
navSwitchC(ctPages(), t.f, t.a, { space: v });
|
|
658
|
+
};
|
|
659
|
+
/* 关掉一个打开的节点(close { node }):在栈里就返回一层,在栈底就关掉它所在的覆盖 */
|
|
660
|
+
function nodeClose(k) {
|
|
661
|
+
const pop = (PDL_VIEWS[k] || {}).popup; if (pop && S.popOrder.indexOf(pop) >= 0) { popClose(pop); return; } /* 浮着开的节点:关它所在的弹窗 */
|
|
662
|
+
const at = navFrameAt('node:' + k); if (at) { if (navDepth(at) > 1) navBack(at); else navClose(at); }
|
|
663
|
+
}
|
|
664
|
+
/* 固定到窄栏 / 从窄栏取下(显式添加副本;编辑布局拖动是移动):在窄栏里(上方或下方)就取下,否则放进上方。k 是入口的规范键。窄栏立即变化就是反馈 */
|
|
665
|
+
A.rail = function (d) {
|
|
666
|
+
const id = d.k; if (!pdlEntry(id)) return;
|
|
667
|
+
const n = pdlRailRef(id);
|
|
668
|
+
if (n && n.ref) pdlNodeDrop(n.id); else if (!n) pdlNodeAdd('rail.top', { id: id + '@rail', ref: id }); /* 固定 = 窄栏里放一个引用按钮(它自己在窄栏里的不算固定) */
|
|
669
|
+
render(true);
|
|
670
|
+
};
|
|
671
|
+
/* 查看页面描述(主题计算器 ⋯):对话框里是生效的 PDL,确认 = 复制(复制不弹提示) */
|
|
672
|
+
DIALOGS.pdl = function () {
|
|
673
|
+
return { title: tc('entryLayout.visibility.title'), text: tc('entryLayout.visibility.text'), doc: { json: true, text: JSON.stringify(pdlEffective(), null, 2) }, ok: tc('common.copy'), wide: true, on: function () { copyText(JSON.stringify(pdlEffective(), null, 2)); } };
|
|
674
|
+
};
|
|
675
|
+
/* 恢复默认布局:能撤回 */
|
|
676
|
+
RESETS.layout = { get: function () { return pdlThemes().active; }, set: function (v) { const t = pdlThemes(); t.active = v; pdlThemesSave(t); pdlThemeSync(); }, def: function () { return PDL_SYS_THEMES[0].id; }, text: function () { return tc('entryLayout.reset.toast'); } };
|
|
677
|
+
|
|
678
|
+
/* ═════════════ 编辑布局 ═════════════
|
|
679
|
+
入口在对话侧栏标题的 ⋯ 菜单里。平时什么都不能拖;进入编辑后,所有看得见的导航容器一起进入编辑(窄栏、侧栏、设置菜单、工作台启动面板),
|
|
680
|
+
编辑条的 × 或 Esc 退出。换空间时一直保持编辑——窄栏在每个空间都在,用它把入口带到另一个空间(先拖到窄栏,再从窄栏拖进新露出来的容器)。
|
|
681
|
+
能拖到哪儿由节点在 PDL 里的种类决定,不按节点单独标:
|
|
682
|
+
- 入口(打开一个页面 / 工具 / 浮窗 / 空间的):可以跨容器移动;
|
|
683
|
+
- 动作(只执行一个操作的):只能在自己的容器里调整顺序;
|
|
684
|
+
- 设置菜单里的项:锚定在设置里——拖出去是在新位置放一个快捷方式,原项不动;设置菜单里只能调整分组标题的顺序和分组名;
|
|
685
|
+
- 锁定的(窄栏的品牌标志、设置入口只能在窄栏)不能拿走;
|
|
686
|
+
- 页面内容(表单、表格、设置行、成员详情、面板正文)跟着数据结构走,不在编辑布局的范围里。
|
|
687
|
+
每次调整都是对用户完整布局文档的一次编辑(pdlDocEdit)。 */
|
|
688
|
+
function pdlKindOf(id) {
|
|
689
|
+
const e = pdlEntry(id); if (!e) return null;
|
|
690
|
+
if (e.scope) return 'content';
|
|
691
|
+
const o = e.open || {};
|
|
692
|
+
return o.page || o.node || o.space || o.ref || e.on ? 'entry' : 'action';
|
|
693
|
+
}
|
|
694
|
+
S.editLayout = false;
|
|
695
|
+
/* 编辑布局是一个状态(s.editLayout):进入 = set,结束 = close;body 上的 edit-layout 跟着状态走 */
|
|
696
|
+
function editLayoutSync() { document.body.classList.toggle('edit-layout', !!S.editLayout); if (!S.editLayout && S.editLeaf) { S.editLeaf = null; editLeafShow(null); } } /* 结束编辑:悬停叶子的小标签一起收掉 */
|
|
697
|
+
onRender(editLayoutSync);
|
|
698
|
+
/* 分组标题改名(编辑布局里):写进主题文档的 labels */
|
|
699
|
+
ENT.navHead = { get: function (id) { return { id: id, name: pdlHeadLabel(id) }; }, inlineEdit: 'navHead', title: function () { return tc('pdlDoc.renameTitle'); }, rename: function (x, v) { pdlNodeSet(x.id, { label: v }); } };
|
|
700
|
+
|
|
701
|
+
/* ───────── 拖动(只在编辑布局时) ─────────
|
|
702
|
+
用的是组件库唯一的拖动机制(core.js 的 EDGE_DRAG,和弹窗框架同一个手势):可编辑的节点(data-edit)边缘出现移动光标,按住拖;
|
|
703
|
+
编辑布局时点节点本身不做任何事(不会误点进去)。节点的种类决定能放到哪:
|
|
704
|
+
entry 入口 → 任意插槽 / 窄栏的格子 / 工作台;head 分组标题 → 同一插槽里两个分组之间;cell 格子容器里的项 → 同一个容器的任意一格;
|
|
705
|
+
order / region 容器、区域 → 同级之间换位置(兄弟用 FLIP 让位);tool 工作台工具 → 插槽。 */
|
|
706
|
+
const DRAG = { id: null, from: null, head: null };
|
|
707
|
+
function dropTarget(e) {
|
|
708
|
+
const slotEl = e.target.closest && e.target.closest('[data-slot]'); if (!slotEl || PDL_SLOTS[slotEl.dataset.slot].scope) return null;
|
|
709
|
+
const horiz = getComputedStyle(slotEl).flexDirection === 'row';
|
|
710
|
+
const kids = Array.prototype.slice.call(slotEl.children).filter(function (k) { return k.dataset.entry || k.dataset.head; });
|
|
711
|
+
let before = null;
|
|
712
|
+
for (const k of kids) { const r = k.getBoundingClientRect(); if (horiz ? e.clientX < r.left + r.width / 2 : e.clientY < r.top + r.height / 2) { before = k; break; } }
|
|
713
|
+
return { slot: slotEl.dataset.slot, el: slotEl, before: before };
|
|
714
|
+
}
|
|
715
|
+
function clearMarks() { document.querySelectorAll('.drop-before, .drop-after, .drop-end, .pdl-over').forEach(function (x) { x.classList.remove('drop-before', 'drop-after', 'drop-end', 'pdl-over'); }); const c = document.getElementById('cell-drop'); if (c) c.remove(); }
|
|
716
|
+
function endDrag() { DRAG.id = null; DRAG.from = null; DRAG.head = null; clearMarks(); document.body.classList.remove('pdl-dragging'); const b = document.getElementById('pdl-bin'); if (b) b.remove(); }
|
|
717
|
+
/* 一次放下是否允许:返回拒绝的原因(文案键),允许返回 '' */
|
|
718
|
+
function pdlDropWhy(id, from, to) {
|
|
719
|
+
if (DRAG.head) return to === from ? '' : 'pdlDoc.settingsFixed';
|
|
720
|
+
if (!pdlMoveOk(id, to)) return 'pdlDoc.stayInContainer'; /* 声明了移动范围(move)的只能在范围里 */
|
|
721
|
+
if (((pdlEntry(id) || pdlNode(id) || {}).scope === 'row') !== (((pdlSlotDef(to) || {}).scope) === 'row')) return 'pdlDoc.stayInContainer'; /* 行里的操作(要行的数据)只进行的容器 */
|
|
722
|
+
if (PDL_SLOTS[to] && PDL_SLOTS[to].accepts === 'page') { const o = pdlOpenOf(id); if (!o || !(o.page || o.node)) return 'pdlDoc.stayInContainer'; } /* 只收页面的插槽(标签式容器的工具插槽):只有打开页面 / 视图的入口放得进去 */
|
|
723
|
+
return '';
|
|
724
|
+
}
|
|
725
|
+
/* 格子容器里鼠标对着哪一格:靠近起始端算从头数,靠近结束端算从尾数(结束端放下的项贴着尾巴,窗口大小变了也贴着) */
|
|
726
|
+
function cellAt(box, e, span) {
|
|
727
|
+
const col = box.classList.contains('cells-col'), r = box.getBoundingClientRect(), cs = getComputedStyle(box);
|
|
728
|
+
const size = parseFloat(cs.getPropertyValue('--cell')) || 32, len = col ? r.height : r.width, pos = (col ? e.clientY - r.top : e.clientX - r.left);
|
|
729
|
+
const a0 = parseFloat(col ? cs.paddingTop : cs.paddingLeft) || 0, a1 = parseFloat(col ? cs.paddingBottom : cs.paddingRight) || 0;
|
|
730
|
+
const hit = e.target && e.target.closest && e.target.closest('.citem'); /* 落在别的项上:占它那一格(同一端、同一格号),它往后让 */
|
|
731
|
+
if (hit && hit.parentElement === box) return { anchor: hit.dataset.anchor, cell: +hit.dataset.cell, size: size, col: col, r: r, a0: a0, a1: a1 };
|
|
732
|
+
if (pos < len / 2) return { anchor: 'start', cell: Math.max(0, Math.floor((pos - a0) / size)), size: size, col: col, r: r, a0: a0, a1: a1 };
|
|
733
|
+
return { anchor: 'end', cell: Math.max(0, Math.floor((len - pos - a1) / size) - ((span || 1) - 1)), size: size, col: col, r: r, a0: a0, a1: a1 };
|
|
734
|
+
}
|
|
735
|
+
/* 落点提示:一块和 span 一样大的高亮,画在那一格上 */
|
|
736
|
+
function cellMark(box, at, span) {
|
|
737
|
+
/* 落点画在格子容器里面:从哪一端数第几格、占几格(格号和格宽来自结构),不用页面坐标 */
|
|
738
|
+
let m = document.getElementById('cell-drop'); if (!m || m.parentElement !== box) { if (m) m.remove(); m = document.createElement('div'); m.id = 'cell-drop'; box.appendChild(m); }
|
|
739
|
+
m.className = 'cell-drop ' + at.anchor; m.setAttribute('style', '--u-cell:' + at.cell + ';--u-n:' + (span || 1));
|
|
740
|
+
}
|
|
741
|
+
/* 放下:位置写进当前主题文档的 cells[容器](place 操作);重叠时新放的占位,原来的往后让(cellsResolve) */
|
|
742
|
+
function cellPlace(container, key, at) { const cell = { cell: { anchor: at.anchor, cell: at.cell, t: Date.now() } }; const e = pdlTreeIndex().find(function (x) { return pdlNamed(x, [key]); }); if (e && e.up && !pdlNamed(e.up, [container])) pdlNodeMove(key, container, undefined, cell); else pdlNodeSet(key, cell); } /* 换了格子容器:节点挪过去(带上格子位置) */
|
|
743
|
+
|
|
744
|
+
/* 入口放下(插槽、窄栏格子、工作台、移出) */
|
|
745
|
+
function entryDrop(e) {
|
|
746
|
+
const id = DRAG.id, from = DRAG.from, head = DRAG.head, ent = pdlEntry(id);
|
|
747
|
+
if (e.target.closest && e.target.closest('#pdl-bin')) { /* 移出:引用按钮删掉;入口隐藏(声明了必要、移动范围的不移出) */
|
|
748
|
+
if (!ent || ent.essential || ent.move) return;
|
|
749
|
+
if (ent.ref) pdlNodeDrop(id); else pdlNodeSet(id, { hidden: true });
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
/* 窄栏:一列格子,放到任意一格;放在起始一半进“上方”,结束一半进“下方” */
|
|
753
|
+
const rail = !head && e.target.closest && e.target.closest('[data-cells="rail"]');
|
|
754
|
+
if (rail) {
|
|
755
|
+
const at = cellAt(rail, e, 1), to = at.anchor === 'start' ? 'rail.top' : 'rail.bottom';
|
|
756
|
+
if (pdlDropWhy(id, from, to)) return; /* 放不下:回到原处 */
|
|
757
|
+
pdlNodeMove(id, to, undefined, { cell: { anchor: at.anchor, cell: at.cell, t: Date.now() } });
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
const ws = e.target.closest && e.target.closest('[data-tools]'); /* 放进标签式容器:组件声明的落点(data-tools = 容器的工具插槽,比如启动面板、标签条) */
|
|
761
|
+
const t = ws ? null : dropTarget(e), to = ws && !head ? ws.dataset.tools : (t || {}).slot;
|
|
762
|
+
if (!to) return;
|
|
763
|
+
if (pdlDropWhy(id, from, to)) return; /* 放不下:回到原处 */
|
|
764
|
+
if (ws) {
|
|
765
|
+
const r = pdlSlotBox(to);
|
|
766
|
+
if (from !== to) pdlNodeMove(id, to);
|
|
767
|
+
pdlPanelSync(); rtReveal(r, ENGINE_PARTS.rtPageKey(r, id), { preview: undefined, args: null }); return;
|
|
768
|
+
}
|
|
769
|
+
const beforeKey = t.before ? (t.before.dataset.entry || t.before.dataset.head) : null;
|
|
770
|
+
const kids = pdlKids(to).filter(function (x) { return x !== id; });
|
|
771
|
+
if (head) { /* 分组标题带着它下面的入口一起移动,只能落在两个分组之间 */
|
|
772
|
+
const list = pdlKids(to), at = list.indexOf(id); let end = at + 1; while (end < list.length && list[end][0] !== '#') end += 1;
|
|
773
|
+
const block = list.slice(at, end), rest = list.filter(function (x) { return block.indexOf(x) < 0; });
|
|
774
|
+
let idx = beforeKey ? rest.indexOf(beforeKey) : rest.length; if (idx < 0) idx = rest.length;
|
|
775
|
+
while (idx > 0 && idx < rest.length && rest[idx][0] !== '#') idx += 1;
|
|
776
|
+
rest.splice.apply(rest, [idx, 0].concat(block)); pdlKidsOrder(to, rest); return;
|
|
777
|
+
}
|
|
778
|
+
const bi = beforeKey ? kids.indexOf(beforeKey) : -1;
|
|
779
|
+
pdlNodeMove(id, to, bi < 0 ? undefined : bi === 0 ? null : kids[bi - 1]); /* 放在 beforeKey 前面 = 放在它前一个兄弟后面 */
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/* 拖动中:节点跟着鼠标(translate),自己不挡命中检测;落点用鼠标下面的元素判断 */
|
|
783
|
+
function under(e, self) { self.style.pointerEvents = 'none'; const t = document.elementFromPoint(e.clientX, e.clientY); self.style.pointerEvents = ''; return { target: t || document.body, clientX: e.clientX, clientY: e.clientY }; }
|
|
784
|
+
function pdlCommitOrder(box) {
|
|
785
|
+
const keys = Array.from(box.children).filter(function (k) { return k.dataset.okey; }).map(function (k) { return k.dataset.okey; });
|
|
786
|
+
const save = box.dataset.orderAct && actFn(box.dataset.orderAct);
|
|
787
|
+
if (save) { save(Object.assign(actionArgs(box), { keys: keys })); return; }
|
|
788
|
+
const c = box.dataset.ocontainer;
|
|
789
|
+
if (c === 'app.regions' || c === 'main.split') pdlTreeOrder(keys); else pdlNodeSet(c, { order: keys });
|
|
790
|
+
render(true);
|
|
791
|
+
}
|
|
792
|
+
/* 标签栏先在 DOM 中预排。取消或交给另一处的动作时还原原序,只有在栏内放下才保存。 */
|
|
793
|
+
function pdlStripDrag(el, down) {
|
|
794
|
+
const box = el.parentElement, next = el.nextElementSibling, bounds = el.getBoundingClientRect();
|
|
795
|
+
const targets = el.dataset.dragAct ? Array.from(document.querySelectorAll('[data-drop-act]')).filter(function (t) {
|
|
796
|
+
return t.dataset.dropAct === el.dataset.dragAct && t.getClientRects().length;
|
|
797
|
+
}) : [];
|
|
798
|
+
const ghost = el.cloneNode(true);
|
|
799
|
+
ghost.inert = true; ghost.setAttribute('aria-hidden', 'true'); ghost.classList.add('order-ghost');
|
|
800
|
+
Object.assign(ghost.style, { left: bounds.left + 'px', top: bounds.top + 'px', width: bounds.width + 'px', height: bounds.height + 'px' });
|
|
801
|
+
document.body.appendChild(ghost);
|
|
802
|
+
el.classList.add('order-placeholder');
|
|
803
|
+
targets.forEach(function (t) { t.classList.add('order-drop-ready'); });
|
|
804
|
+
let over, frame = 0, pointerX;
|
|
805
|
+
function insert(ref) {
|
|
806
|
+
if (el === ref || el.nextElementSibling === ref) return;
|
|
807
|
+
flipMove(box, function () { if (box.moveBefore) box.moveBefore(el, ref); else box.insertBefore(el, ref); }, el);
|
|
808
|
+
}
|
|
809
|
+
function restore() {
|
|
810
|
+
if (el.parentElement === box) insert(next?.parentElement === box ? next : null);
|
|
811
|
+
}
|
|
812
|
+
function destination(hit) {
|
|
813
|
+
const t = hit?.closest('[data-drop-act]');
|
|
814
|
+
return targets.includes(t) ? t : null;
|
|
815
|
+
}
|
|
816
|
+
// 用各页签最终的布局位置判定是否越过中点,快速反向时不受动画偏移影响。
|
|
817
|
+
function reorderAt(x) {
|
|
818
|
+
if (!el.dataset.okey) return;
|
|
819
|
+
const pos = x - box.getBoundingClientRect().left + box.scrollLeft - box.clientLeft;
|
|
820
|
+
const before = Array.from(box.children).find(function (k) {
|
|
821
|
+
return k !== el && k.dataset.okey && pos < k.offsetLeft + k.offsetWidth / 2;
|
|
822
|
+
});
|
|
823
|
+
insert(before || null);
|
|
824
|
+
}
|
|
825
|
+
function scrollEdge() {
|
|
826
|
+
const rect = box.getBoundingClientRect(), edge = Math.min(28, rect.width / 4);
|
|
827
|
+
const speed = Math.max(0, pointerX - rect.right + edge) - Math.max(0, rect.left + edge - pointerX);
|
|
828
|
+
const prev = box.scrollLeft;
|
|
829
|
+
if (speed) box.scrollLeft += Math.sign(speed) * Math.ceil(Math.abs(speed) / 3);
|
|
830
|
+
if (prev !== box.scrollLeft) { reorderAt(pointerX); frame = requestAnimationFrame(scrollEdge); }
|
|
831
|
+
}
|
|
832
|
+
return {
|
|
833
|
+
move: function (e) {
|
|
834
|
+
cancelAnimationFrame(frame);
|
|
835
|
+
pointerX = e.clientX;
|
|
836
|
+
ghost.style.translate = (pointerX - down.clientX) + 'px ' + (e.clientY - down.clientY) + 'px';
|
|
837
|
+
const hit = document.elementFromPoint(pointerX, e.clientY);
|
|
838
|
+
over?.classList.remove('order-drop-over');
|
|
839
|
+
over = destination(hit); over?.classList.add('order-drop-over');
|
|
840
|
+
if (box.contains(hit)) { reorderAt(pointerX); if (el.dataset.okey) frame = requestAnimationFrame(scrollEdge); }
|
|
841
|
+
else restore();
|
|
842
|
+
},
|
|
843
|
+
end: function (e, moved) {
|
|
844
|
+
cancelAnimationFrame(frame);
|
|
845
|
+
const hit = moved && el.isConnected ? document.elementFromPoint(e.clientX, e.clientY) : null;
|
|
846
|
+
const drop = destination(hit), inside = box.contains(hit) && !!el.dataset.okey;
|
|
847
|
+
if (inside) reorderAt(e.clientX); else restore();
|
|
848
|
+
// 记录落位再提交,排序触发的重画可以立即替换整条标签栏。
|
|
849
|
+
if (inside && dragMotion()) {
|
|
850
|
+
const end = el.getBoundingClientRect(), from = ghost.getBoundingClientRect();
|
|
851
|
+
const landing = ghost.animate([{ transform: 'none', opacity: 1 }, {
|
|
852
|
+
transform: 'translate(' + (end.left - from.left) + 'px,' + (end.top - from.top) + 'px)', opacity: 0
|
|
853
|
+
}], { duration: ms('--dur-fast'), easing: 'ease-out' });
|
|
854
|
+
landing.finished.then(function () { ghost.remove(); }, function () { ghost.remove(); });
|
|
855
|
+
} else ghost.remove();
|
|
856
|
+
el.classList.remove('order-placeholder');
|
|
857
|
+
targets.forEach(function (t) { t.classList.remove('order-drop-ready', 'order-drop-over'); });
|
|
858
|
+
if (drop) actFn(drop.dataset.dropAct)?.(actionArgs(el));
|
|
859
|
+
else if (inside && next !== el.nextElementSibling) pdlCommitOrder(box);
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
EDGE_DRAG.push({
|
|
864
|
+
find: function (t) {
|
|
865
|
+
if (!t || !t.closest) return null;
|
|
866
|
+
const el = t.closest('[data-edit]'); if (!el || el.dataset.locked) return null;
|
|
867
|
+
if (el.dataset.edit === 'move') return el.closest('[data-move-act]') ? { el: el, whole: true } : null; /* 移到别的容器(对话拖进 / 拖出分组):所在的容器声明了 data-move */
|
|
868
|
+
if (!S.editLayout && el.dataset.edit === 'order' && el.parentElement?.hasAttribute('data-drag-handles')) {
|
|
869
|
+
return t.closest('[data-drag-handle]') && (el.dataset.okey || el.dataset.dragAct) ? { el: el, whole: true, distance: 5 } : null;
|
|
870
|
+
}
|
|
871
|
+
if (!S.editLayout) { const box = el.dataset.edit === 'order' && el.parentElement && el.parentElement.closest('[data-ocontainer]'); if (!box || !box.dataset.orderAct) return null; } /* 平时只有会话状态的容器能拖(它声明了顺序存哪:data-order-act);主题的布局只在编辑布局时动 */
|
|
872
|
+
return { el: el, whole: true }; /* 编辑布局时整块都是抓手(平时的窗口只有边缘) */
|
|
873
|
+
},
|
|
874
|
+
start: function (el, e0) {
|
|
875
|
+
const kind = el.dataset.edit, sx = e0.clientX, sy = e0.clientY;
|
|
876
|
+
if (!S.editLayout && kind === 'order' && el.parentElement?.hasAttribute('data-drag-handles')) return pdlStripDrag(el, e0);
|
|
877
|
+
const follow = function (e) { el.style.translate = (e.clientX - sx) + 'px ' + (e.clientY - sy) + 'px'; };
|
|
878
|
+
const done = function () { el.style.translate = ''; el.classList.remove('edit-drag'); document.body.classList.remove('pdl-dragging'); editShow(null); };
|
|
879
|
+
el.classList.add('edit-drag'); document.body.classList.add('pdl-dragging');
|
|
880
|
+
/* 拖的时候把“能放在哪”画出来:入口 → 所有接收入口的容器;别的 → 只有它自己的容器(连同格子) */
|
|
881
|
+
editShow(kind === 'entry' || kind === 'tool' ? document.querySelectorAll('[data-slot]:not([data-scope]), [data-cells="rail"], [data-tools]') : [el.closest(kind === 'cell' ? '[data-cells]' : kind === 'head' ? '[data-slot]' : '[data-ocontainer]') || el.parentElement]);
|
|
882
|
+
if (kind === 'entry' || kind === 'head' || kind === 'tool') {
|
|
883
|
+
if (kind === 'head') { DRAG.head = el.dataset.head; DRAG.id = el.dataset.head; DRAG.from = el.dataset.from; }
|
|
884
|
+
else if (kind === 'entry') { DRAG.id = el.dataset.entry; DRAG.from = el.dataset.from || null; }
|
|
885
|
+
else { const slot = el.closest('[data-tools]').dataset.tools; DRAG.id = ENGINE_PARTS.rtPageEntry(pdlSlotBox(slot), el.dataset.k); DRAG.from = slot; }
|
|
886
|
+
if (DRAG.from && !DRAG.head && !document.getElementById('pdl-bin')) document.body.insertAdjacentHTML('beforeend', ENGINE_PARTS.dragBin(tc('entryLayout.actions.dragBin', pdlText(PDL_SLOTS[DRAG.from].label))));
|
|
887
|
+
return {
|
|
888
|
+
move: function (e) {
|
|
889
|
+
follow(e); clearMarks(); const u = under(e, el);
|
|
890
|
+
const bin = u.target.closest && u.target.closest('#pdl-bin'); if (bin) { bin.classList.add('pdl-over'); return; }
|
|
891
|
+
const rail = !DRAG.head && u.target.closest && u.target.closest('[data-cells="rail"]');
|
|
892
|
+
if (rail) { const at = cellAt(rail, u, 1); if (!pdlDropWhy(DRAG.id, DRAG.from, at.anchor === 'start' ? 'rail.top' : 'rail.bottom')) cellMark(rail, at, 1); return; }
|
|
893
|
+
const ws = u.target.closest && u.target.closest('[data-tools]');
|
|
894
|
+
if (ws && !DRAG.head && !pdlDropWhy(DRAG.id, DRAG.from, ws.dataset.tools)) { ws.classList.add('pdl-over'); return; }
|
|
895
|
+
const t = dropTarget(u); if (!t || pdlDropWhy(DRAG.id, DRAG.from, t.slot)) return;
|
|
896
|
+
if (t.before) t.before.classList.add('drop-before'); else t.el.classList.add('drop-end');
|
|
897
|
+
},
|
|
898
|
+
end: function (e, moved) { const u = under(e, el); done(); if (moved) entryDrop(u); endDrag(); render(true); }
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
if (kind === 'move') { /* 移到同一类的容器(data-move 相同):放下时交给目标容器声明的动作(data-move-act),参数 = 目标容器的 data + 被拖的 id。
|
|
902
|
+
容器还可以声明放在行上是什么意思(data-move-rows,数据给的):insert = 插在那一行前 / 后(target + after,同一个容器里也行);onto = 放到那一行上(target);没声明就只认容器 */
|
|
903
|
+
const from = el.closest('[data-move-act]'), family = from.dataset.move;
|
|
904
|
+
let to = null, at = null;
|
|
905
|
+
return {
|
|
906
|
+
move: function (e) {
|
|
907
|
+
follow(e); clearMarks(); at = null;
|
|
908
|
+
const u = under(e, el), b = u.target.closest && u.target.closest('[data-move-act]'), row = b && b.dataset.move === family && u.target.closest('[data-move-key]'), how = b && b.dataset.moveRows;
|
|
909
|
+
to = b && b.dataset.move === family ? b : null;
|
|
910
|
+
if (to && row && row !== el && how) {
|
|
911
|
+
const r = row.getBoundingClientRect(), after = e.clientY > r.top + r.height / 2;
|
|
912
|
+
at = how === 'insert' ? { target: row.dataset.moveKey, after: String(after) } : { target: row.dataset.moveKey };
|
|
913
|
+
row.classList.add(how === 'insert' ? (after ? 'drop-after' : 'drop-before') : 'pdl-over'); return;
|
|
914
|
+
}
|
|
915
|
+
if (to === from) to = null; if (to) to.classList.add('pdl-over');
|
|
916
|
+
},
|
|
917
|
+
end: function (e, moved) { done(); clearMarks(); if (moved && to && actFn(to.dataset.moveAct)) actFn(to.dataset.moveAct)(Object.assign(actionArgs(to), { id: el.dataset.moveKey }, at || {})); render(true); }
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
if (kind === 'cell') { /* 格子容器里的项:放到任意一格;移动范围(move)允许的话也能放进别的格子容器 */
|
|
921
|
+
const span = +getComputedStyle(el).getPropertyValue('--u-span') || 1, key = el.dataset.ckey;
|
|
922
|
+
let at = null, to = null;
|
|
923
|
+
return {
|
|
924
|
+
move: function (e) { follow(e); const u = under(e, el), b = u.target.closest && u.target.closest('[data-cells]'); clearMarks(); to = b && b.dataset.cells !== 'rail' && !pdlDropWhy(key, null, b.dataset.cells) ? b : null; at = to ? cellAt(to, u, span) : null; if (at) cellMark(to, at, span); },
|
|
925
|
+
end: function (e, moved) { done(); clearMarks(); if (moved && at) cellPlace(to.dataset.cells, key, at); render(true); }
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
/* order / region:同级之间换位置(兄弟 FLIP 让位);放下记一条 order[容器] */
|
|
929
|
+
const box = el.parentElement && el.parentElement.closest('[data-ocontainer]'); if (!box || el.parentElement !== box) { done(); return null; }
|
|
930
|
+
return {
|
|
931
|
+
move: function (e) {
|
|
932
|
+
follow(e); const u = under(e, el);
|
|
933
|
+
let sib = u.target; while (sib && sib.parentElement !== box) sib = sib.parentElement; /* 鼠标下面属于这个容器的那一个兄弟(里面可能还套着别的可编辑节点) */
|
|
934
|
+
if (!sib || sib === el || !sib.dataset.okey || sib.dataset.locked) return;
|
|
935
|
+
const r = sib.getBoundingClientRect(), horiz = getComputedStyle(box).flexDirection === 'row' || getComputedStyle(box).display === 'grid';
|
|
936
|
+
const after = horiz ? e.clientX > r.left + r.width / 2 : e.clientY > r.top + r.height / 2, ref = after ? sib.nextElementSibling : sib;
|
|
937
|
+
if (ref === el || (ref === el.nextElementSibling && !after)) return;
|
|
938
|
+
el.style.translate = ''; flipMove(box, function () { box.insertBefore(el, ref); });
|
|
939
|
+
},
|
|
940
|
+
end: function (e, moved) {
|
|
941
|
+
done(); if (moved) pdlCommitOrder(box);
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
});
|
|
946
|
+
/* 编辑布局时悬停一个有公开名字的叶子(格子里的项、插槽里的入口):叶子下方贴一个小标签,显示它的名字,可以复制它的定位——
|
|
947
|
+
按唯一(名字不唯一时加上最少的 with,层数多留一层余量)或直接(同名的都算)。格子里的项是插入点(inserts);插槽里的入口用 ops 的路径 */
|
|
948
|
+
S.editLeaf = null;
|
|
949
|
+
document.addEventListener('mouseover', function (e) {
|
|
950
|
+
if (!S.editLayout || !e.target.closest || e.buttons) return; /* 拖动中不出标签 */
|
|
951
|
+
const el = e.target.closest('[data-ckey], [data-entry]'); if (!el) return;
|
|
952
|
+
const box = el.closest('[data-cells], [data-slot]'), entry = !el.dataset.ckey;
|
|
953
|
+
const leaf = { name: el.dataset.ckey || el.dataset.entry, entry: entry, within: entry ? el.dataset.from : box ? box.dataset.cells || box.dataset.slot : '' }; /* 入口按它所在的插槽(窄栏的格子合了上下两个插槽) */
|
|
954
|
+
if (S.editLeaf && S.editLeaf.name === leaf.name && S.editLeaf.within === leaf.within) return;
|
|
955
|
+
S.editLeaf = leaf; editLeafShow(null); EDIT_LEAF.t = setTimeout(function () { editLeafShow(el); }, ms('--tip-delay')); /* 和提示一样停一下才出,换一个叶子先收起 */
|
|
956
|
+
});
|
|
957
|
+
const EDIT_LEAF = { el: null, t: 0 };
|
|
958
|
+
/* 按下(开始拖动、点别处)就收起标签,不挡住拖放的落点 */
|
|
959
|
+
document.addEventListener('pointerdown', function (e) { if (S.editLeaf && !(e.target.closest && e.target.closest('.edit-leaf'))) { S.editLeaf = null; editLeafShow(null); } }, true);
|
|
960
|
+
function editLeafShow(at) {
|
|
961
|
+
if (!EDIT_LEAF.el) { EDIT_LEAF.el = document.createElement('div'); EDIT_LEAF.el.className = 'edit-leaf'; EDIT_LEAF.el.setAttribute('popover', 'manual'); document.body.appendChild(EDIT_LEAF.el); }
|
|
962
|
+
const t = EDIT_LEAF.el; clearTimeout(EDIT_LEAF.t);
|
|
963
|
+
if (!at) { t.hidePopover(); anchorTo('editLeaf', null); return; }
|
|
964
|
+
if (!S.editLeaf) return;
|
|
965
|
+
t.innerHTML = ENGINE_PARTS.editLeaf(S.editLeaf); t.style.setProperty('--u-anchor', anchorTo('editLeaf', at, function () { editLeafShow(null); })); t.showPopover();
|
|
966
|
+
}
|
|
967
|
+
function pdlAnchorSpec(leaf, unique) {
|
|
968
|
+
if (leaf.entry) return { anchor: leaf.name, at: 'after' }; /* 入口的 id 全树唯一 */
|
|
969
|
+
const all = pdlTreeIndex(), plain = { anchor: leaf.name }, hits = pdlAnchorFind(all, plain);
|
|
970
|
+
if (!unique || hits.length < 2) return plain;
|
|
971
|
+
const inBox = function (e) { for (let x = e.up; x; x = x.up) if (x.node.key === leaf.within || x.rid === leaf.within) return true; return false; };
|
|
972
|
+
const target = hits.find(inBox) || hits[0], only = function (spec) { const r = pdlAnchorFind(all, spec); return r.length > 0 && r.every(function (x) { return x.node === target.node; }); };
|
|
973
|
+
for (let d = 0; d < 6; d++) {
|
|
974
|
+
const scope = pdlLevel(target, d), names = [];
|
|
975
|
+
all.forEach(function (o) { if (o !== target && scope && pdlWithin(o, scope)) pdlLeafName(o.node).forEach(function (n) { if (n && n !== leaf.name && names.indexOf(n) < 0) names.push(n); }); });
|
|
976
|
+
const hit = names.find(function (n) { return only({ anchor: leaf.name, with: [{ anchors: [n], depth: d }] }); });
|
|
977
|
+
if (hit) return { anchor: leaf.name, with: [{ anchors: [hit], depth: only({ anchor: leaf.name, with: [{ anchors: [hit], depth: d + 1 }] }) ? d + 1 : d }] };
|
|
978
|
+
}
|
|
979
|
+
return plain;
|
|
980
|
+
}
|
|
981
|
+
/* 编辑布局是只读的:点什么都不打开(不会误点进去、不会误触发),悬停展开、提示也关掉;只有编辑条、弹窗的 ×、分组改名这些编辑控件照常 */
|
|
982
|
+
document.addEventListener('click', function (e) {
|
|
983
|
+
if (!S.editLayout || !e.target.closest) return;
|
|
984
|
+
if (e.target.closest('[data-pop="editbar"], .edit-leaf, .pdl-head-act, [data-act="close"][data-popup]')) return;
|
|
985
|
+
e.stopImmediatePropagation(); e.preventDefault();
|
|
986
|
+
}, true);
|
|
987
|
+
function editShow(list) { document.querySelectorAll('.edit-home').forEach(function (x) { x.classList.remove('edit-home'); }); Array.prototype.forEach.call(list || [], function (x) { if (x) x.classList.add('edit-home'); }); }
|
|
988
|
+
|
|
989
|
+
/* 系统配置的小节顺序:来自用户文档(页面内容不在编辑布局的范围里,没有拖动入口) */
|
|
990
|
+
function sysOrder() { return PDL_PAGES.system.blocks.map(function (b) { return b.id; }); }
|
|
991
|
+
|
|
992
|
+
/* ═════════════ 生效的描述(agent 读到的就是这个) ═════════════ */
|
|
993
|
+
function pdlEffective() {
|
|
994
|
+
const slots = {};
|
|
995
|
+
Object.keys(PDL_SLOTS).forEach(function (s) {
|
|
996
|
+
const d = PDL_SLOTS[s]; if (!d.kids) return; /* 模板登记(按类型画的)不在这里 */
|
|
997
|
+
const items = pdlKids(s).filter(function (id) { return id && id[0] !== '#'; }).map(function (id) {
|
|
998
|
+
const e = pdlEntry(id);
|
|
999
|
+
if (!e) return { id: id, state: 'unknown' };
|
|
1000
|
+
const it = { id: id, title: e.title, open: e.open, when: e.when || null, visible: pdlWhen(e.when), current: pdlCur(id), badge: e.badge && BADGES[e.badge] ? BADGES[e.badge]() : null };
|
|
1001
|
+
if (e.move) it.move = e.move; if (e.ref) it.ref = e.ref; if (e.hidden) it.hidden = true;
|
|
1002
|
+
return it;
|
|
1003
|
+
}).filter(function (it) { const e = pdlEntry(it.id); return !e || !e.plugin || plugOn(e.plugin); }).map(function (it) {
|
|
1004
|
+
const e = pdlEntry(it.id);
|
|
1005
|
+
if (e) {
|
|
1006
|
+
it.from = e.plugin ? 'plugin:' + e.plugin : 'core'; if (e.use) it.use = e.use; if (e.open.node && PDL_VIEWS[e.open.node]) it.node = e.open.node;
|
|
1007
|
+
if (d.scope === 'row') { if (e.need) it.need = e.need; if (e.guard) it.guard = e.guard; if (e.args) it.args = e.args; }
|
|
1008
|
+
}
|
|
1009
|
+
return it;
|
|
1010
|
+
});
|
|
1011
|
+
slots[s] = { display: d.display, items: items, accepts: d.accepts || '*', itemActions: d.itemActions || [], scope: d.scope || 'shell' };
|
|
1012
|
+
});
|
|
1013
|
+
const pages = { system: { blocks: sysOrder().map(function (id) { const b = PDL_PAGES.system.blocks.find(function (x) { return x.id === id; }) || {}; return { id: id, when: b.when || null, visible: pdlWhen(b.when) }; }) } };
|
|
1014
|
+
return { pdl: '0.1', layout: S.layout || 'three', theme: S.pdlPalette + '/' + stMode(), route: S.route, tabs: Object.keys(REGION_TABS).reduce(function (o, r) { o[r] = rtCur(r); return o; }, {}), userAdjusted: !!S.pdlDoc,
|
|
1015
|
+
rules: ['rules apply above every layer, plugins cannot override'], slots: slots, pages: pages,
|
|
1016
|
+
plugins: PDL_PLUGINS.map(function (k) { const f = PDL_PLUGIN_FRAGS[k]; return { id: k, enabled: plugOn(k), inserts: f.inserts || [], insertsSkipped: PDL_INSERT_SKIPS[k] || [], nodes: Object.keys(f.views || {}) }; }),
|
|
1017
|
+
merge: ['theme tree', 'custom theme (by id)', 'plugin inserts (priority, then plugin id)'], guards: Object.keys(PDL_GUARDS), slotItems: Object.keys(PDL_SLOT_ITEMS).reduce(function (o, k) { o[k] = { cardinality: PDL_SLOTS[k] && PDL_SLOTS[k].cardinality, items: PDL_SLOT_ITEMS[k].map(function (x) { return { id: x.id, key: x.key || null, match: x.match || null, priority: x.priority, plugin: x.plugin || null, active: pdlWhen(x.when) }; }) }; return o; }, {}), skin: S.pdlSkin, views: pdlViewTree(),
|
|
1018
|
+
layout: { defaults: PDL_LAYOUT, skin: PDL_LAYOUT_SKINS[S.pdlSkin] || null, effective: pdlLayout() }, popups: PDL_POPUPS, popupStack: (S.popOrder || []).slice(), projection: navSnapshot(), tree: pdlTree(), space: space() };
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
/* ───────── 标签式区域(布局数据里 tabs: true 的区域)─────────
|
|
1022
|
+
宿主画控制条:首页标签 + 打开过的内容(每个一个标签,可固定、可关、预览标签会被下一个预览替换)+ 放不下的“还有 N 个”+ 区域动作;
|
|
1023
|
+
内容区上方是通用“返回”。标签状态按区域存,由区域的绑定方提供(rtBind);控制条的样子和动作来自布局数据 regions[r].chrome。 */
|
|
1024
|
+
|
|
1025
|
+
/* ═════════════ 主题的 PDL 数据 ═════════════
|
|
1026
|
+
主题是纯数据(主题包的 pdl.json;内置主题由构建从 theme/<主题>/pdl/*.json 生成调用)。按原来的顺序填进各个登记表:
|
|
1027
|
+
frags 是有名字的片段,别处写 { $frag: 名 } 引用(加载时换成同一个对象;片段是一列块、引用写在一列里时,展开进这一列);视图、行、节点模板里的文案在画的时候取,
|
|
1028
|
+
其余部分(入口、面板、分组、配色名……)在这里取一次;{ $panels: 容器 } 是那个标签式容器的工具入口(组件库按面板登记生成);
|
|
1029
|
+
空间的 routesFrom 把这些插槽里入口打开的页面加进它的路由;nav 是空间 → 画第二栏的视图;modules 按内置模块登记 */
|
|
1030
|
+
const PDL_THEME = {}; /* 当前主题的清单:id、name、version、contractVersion(theme.yaml 去掉 pdl 段) */
|
|
1031
|
+
function pdlThemeLoad(pdl, manifest) {
|
|
1032
|
+
Object.assign(PDL_THEME, manifest);
|
|
1033
|
+
const frags = {}, expand = function (x) {
|
|
1034
|
+
if (Array.isArray(x)) return x.reduce(function (out, y) { const e = expand(y); if (y && y.$frag && Array.isArray(e)) out.push.apply(out, e); else out.push(e); return out; }, []);
|
|
1035
|
+
if (!x || typeof x !== 'object') return x;
|
|
1036
|
+
if (x.$t) return tc.apply(null, [x.$t].concat(x.args)); /* 带参数的文案:加载时取一次 */
|
|
1037
|
+
if (x.$frag) { if (!frags[x.$frag]) { frags[x.$frag] = {}; frags[x.$frag] = expand(pdl.frags[x.$frag]); } return frags[x.$frag]; }
|
|
1038
|
+
const o = {}; Object.keys(x).forEach(function (k) { o[k] = expand(x[k]); }); return o;
|
|
1039
|
+
};
|
|
1040
|
+
const text = function (x) {
|
|
1041
|
+
if (typeof x === 'string') return x.indexOf('t:') === 0 ? tc(x.slice(2)) : x;
|
|
1042
|
+
if (Array.isArray(x)) return x.map(text);
|
|
1043
|
+
if (!x || typeof x !== 'object') return x;
|
|
1044
|
+
const o = {}; Object.keys(x).forEach(function (k) { o[k] = text(x[k]); }); return o;
|
|
1045
|
+
};
|
|
1046
|
+
Object.keys(pdl.frags || {}).forEach(function (n) { PDL_FRAGS[n] = expand({ $frag: n }); });
|
|
1047
|
+
Object.assign(PDL_VIEWS, expand(pdl.views || {})); Object.assign(PDL_ROWS, expand(pdl.rows || {})); Object.assign(PDL_NODES, expand(pdl.nodes || {}));
|
|
1048
|
+
Object.assign(TITLES, pdl.titles || {});
|
|
1049
|
+
WS_GROUPS.push.apply(WS_GROUPS, pdl.panelGroups || []); BUILTIN_PALETTES.push.apply(BUILTIN_PALETTES, pdl.palettes || []); PDL_SYS_THEMES.push.apply(PDL_SYS_THEMES, pdl.sysThemes || []);
|
|
1050
|
+
Object.assign(PDL_POPUPS, expand(pdl.popups || {})); Object.assign(PDL_WHO, pdl.who || {});
|
|
1051
|
+
const slots = expand(pdl.slots || {}), entries = {};
|
|
1052
|
+
Object.keys(slots).forEach(function (s) { (Array.isArray(slots[s].kids) ? slots[s].kids : []).forEach(function (e) { if (e && e.id) entries[e.id] = e; }); });
|
|
1053
|
+
Object.keys(slots).forEach(function (s) { const k = slots[s].kids; if (k && k.$panels) slots[s].kids = ENGINE_PARTS.panelEntries(k.$panels, entries); });
|
|
1054
|
+
Object.assign(PDL_SLOTS, slots);
|
|
1055
|
+
Object.assign(PDL_LAYOUT, expand(pdl.layout || {})); Object.assign(PDL_PAGES, expand(pdl.pages || {}));
|
|
1056
|
+
const spaces = expand(pdl.spaces || {});
|
|
1057
|
+
Object.keys(spaces).forEach(function (k) { const sp = spaces[k]; (sp.routesFrom || []).forEach(function (s) { sp.routes = sp.routes.concat(PDL_SLOTS[s].kids.map(pdlId)); }); delete sp.routesFrom; });
|
|
1058
|
+
Object.assign(PDL_SPACES, spaces);
|
|
1059
|
+
pdlNodeSlots();
|
|
1060
|
+
(pdl.contributions || []).forEach(function (c) { pdlContribute(c.slot, text(c.item)); });
|
|
1061
|
+
Object.keys(pdl.nav || {}).forEach(function (sp) { const id = pdl.nav[sp]; NAV_OVERRIDE[sp] = function () { return PDL_VIEWS[id].vm ? pdlView(id) : pdlViewOf(id, {}); }; });
|
|
1062
|
+
(pdl.modules || []).forEach(function (m) { pdlRegister(expand(m)); });
|
|
1063
|
+
if (pdl.tokens) themeTokens(pdl.tokens);
|
|
1064
|
+
}
|