@collabdt/core 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/components/viewers/plugins/src/PluginCard.d.ts.map +1 -1
- package/dist/core/components/viewers/plugins/src/PluginCard.js +16 -5
- package/dist/core/components/viewers/plugins/src/PluginCard.js.map +1 -1
- package/dist/core/plugins/hello-bim/manifest.json +2 -1
- package/dist/core/plugins/hello-map/manifest.json +2 -1
- package/dist/core/plugins/host/PluginDataPageHost.js +1 -1
- package/dist/core/plugins/host/PluginDataPageHost.js.map +1 -1
- package/dist/core/plugins/host/context.d.ts.map +1 -1
- package/dist/core/plugins/host/context.js +16 -0
- package/dist/core/plugins/host/context.js.map +1 -1
- package/dist/core/plugins/host/pluginIcon.d.ts +5 -0
- package/dist/core/plugins/host/pluginIcon.d.ts.map +1 -0
- package/dist/core/plugins/host/pluginIcon.js +15 -0
- package/dist/core/plugins/host/pluginIcon.js.map +1 -0
- package/dist/core/plugins/host/runtimeShims.d.ts.map +1 -1
- package/dist/core/plugins/host/runtimeShims.js +38 -0
- package/dist/core/plugins/host/runtimeShims.js.map +1 -1
- package/dist/core/plugins/host/usePluginDataPages.js +1 -1
- package/dist/core/plugins/host/usePluginDataPages.js.map +1 -1
- package/dist/core/plugins/host/usePluginToolbarTools.d.ts +0 -5
- package/dist/core/plugins/host/usePluginToolbarTools.d.ts.map +1 -1
- package/dist/core/plugins/host/usePluginToolbarTools.js +1 -12
- package/dist/core/plugins/host/usePluginToolbarTools.js.map +1 -1
- package/dist/core/plugins/host/usePluginViewerTabs.js +1 -1
- package/dist/core/plugins/host/usePluginViewerTabs.js.map +1 -1
- package/dist/core/plugins/sdk/types.d.ts +2 -0
- package/dist/core/plugins/sdk/types.d.ts.map +1 -1
- package/dist/core/plugins/sdk/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginCard.d.ts","sourceRoot":"","sources":["../../../../../../src/core/components/viewers/plugins/src/PluginCard.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PluginCard.d.ts","sourceRoot":"","sources":["../../../../../../src/core/components/viewers/plugins/src/PluginCard.tsx"],"names":[],"mappings":"AAwBA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAY9B,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAmC7D,UAAU,KAAK;IACb,OAAO,EAAE,aAAa,CAAA;IACtB,OAAO,EAAE,cAAc,CAAA;IACvB,cAAc,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAA;IAC5C,eAAe,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAC3C,sBAAsB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IAChD,gBAAgB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAC5C,WAAW,EAAE,MAAM,IAAI,CAAA;CACxB;AAED,wBAAgB,UAAU,CAAC,EACzB,OAAO,EACP,OAAO,EACP,cAAc,EACd,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,WAAW,GACZ,EAAE,KAAK,qBAoKP"}
|
|
@@ -15,9 +15,11 @@ import {
|
|
|
15
15
|
PanelRight,
|
|
16
16
|
Puzzle,
|
|
17
17
|
Scan,
|
|
18
|
+
SquareMenu,
|
|
18
19
|
SquareStack
|
|
19
20
|
} from "lucide-react";
|
|
20
21
|
import { useTranslations } from "next-intl";
|
|
22
|
+
import { resolvePluginIcon } from "../../../../plugins/host/pluginIcon";
|
|
21
23
|
import { usePluginMessage } from "../../../../plugins/sdk/messages";
|
|
22
24
|
import { cn } from "../../../../utils/utils";
|
|
23
25
|
import { Badge } from "../../../ui/Badge";
|
|
@@ -45,7 +47,7 @@ const STATUS_STYLE = {
|
|
|
45
47
|
};
|
|
46
48
|
const CAPABILITY_ICON = {
|
|
47
49
|
"map.tools": MapPin,
|
|
48
|
-
"viewer.legends":
|
|
50
|
+
"viewer.legends": SquareMenu,
|
|
49
51
|
"map.layers": Layers,
|
|
50
52
|
"bim.tools": Box,
|
|
51
53
|
"pointcloud.tools": Scan,
|
|
@@ -62,15 +64,16 @@ function PluginCard({
|
|
|
62
64
|
onSetUserEnabled,
|
|
63
65
|
onCopyError
|
|
64
66
|
}) {
|
|
65
|
-
var _a, _b, _c;
|
|
67
|
+
var _a, _b, _c, _d;
|
|
66
68
|
const t = useTranslations("PluginsPage");
|
|
67
69
|
const { manifest } = listing;
|
|
68
70
|
const status = effectiveStatus(listing);
|
|
71
|
+
const Icon = resolvePluginIcon((_a = manifest.icon) != null ? _a : "Puzzle");
|
|
69
72
|
const name = usePluginMessage(manifest.slug, "name", manifest.name);
|
|
70
|
-
const description = usePluginMessage(manifest.slug, "description", (
|
|
73
|
+
const description = usePluginMessage(manifest.slug, "description", (_b = manifest.description) != null ? _b : "");
|
|
71
74
|
const isAdmin = ability.canConfigureOrg || ability.canInstall;
|
|
72
75
|
const userMayChoose = listing.allowUserOverride && ability.canChooseForSelf && status !== "error";
|
|
73
|
-
const userEnabled = (
|
|
76
|
+
const userEnabled = (_c = listing.userEnabled) != null ? _c : listing.orgEnabled;
|
|
74
77
|
return /* @__PURE__ */ jsxs(
|
|
75
78
|
"article",
|
|
76
79
|
{
|
|
@@ -79,6 +82,14 @@ function PluginCard({
|
|
|
79
82
|
children: [
|
|
80
83
|
/* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
81
84
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
85
|
+
/* @__PURE__ */ jsx(
|
|
86
|
+
Icon,
|
|
87
|
+
{
|
|
88
|
+
"aria-hidden": true,
|
|
89
|
+
className: "h-5 w-5 shrink-0 text-muted-foreground",
|
|
90
|
+
"data-testid": `plugin-icon-${manifest.slug}`
|
|
91
|
+
}
|
|
92
|
+
),
|
|
82
93
|
/* @__PURE__ */ jsx("h2", { className: "text-lg text-foreground", children: name }),
|
|
83
94
|
/* @__PURE__ */ jsx(StatusBadge, { status }),
|
|
84
95
|
listing.bundled && /* @__PURE__ */ jsx(Badge, { variant: "outline", className: "font-normal text-muted-foreground", children: t("bundled") })
|
|
@@ -110,7 +121,7 @@ function PluginCard({
|
|
|
110
121
|
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: t("trustHeading") }),
|
|
111
122
|
/* @__PURE__ */ jsxs("ul", { className: "mt-1.5 list-disc pl-4 text-xs text-muted-foreground", children: [
|
|
112
123
|
listing.mountPath && /* @__PURE__ */ jsx("li", { children: t("trustMount", { path: listing.mountPath }) }),
|
|
113
|
-
/* @__PURE__ */ jsx("li", { children: ((
|
|
124
|
+
/* @__PURE__ */ jsx("li", { children: ((_d = manifest.requiredPermissions) == null ? void 0 : _d.length) ? t("trustPermissions", { permissions: manifest.requiredPermissions.join(", ") }) : t("trustNoPermissions") }),
|
|
114
125
|
/* @__PURE__ */ jsx("li", { children: t("trustWarning") })
|
|
115
126
|
] })
|
|
116
127
|
] })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/core/components/viewers/plugins/src/PluginCard.tsx"],"sourcesContent":["'use client'\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport {\r\n AlertTriangle,\r\n Box,\r\n CheckCircle2,\r\n CircleSlash,\r\n Eye,\r\n Lock,\r\n MapPin,\r\n Layers,\r\n Minus,\r\n PackagePlus,\r\n PanelLeft,\r\n PanelRight,\r\n Puzzle,\r\n Scan,\r\n SquareStack,\r\n} from 'lucide-react'\r\nimport { useTranslations } from 'next-intl'\r\nimport * as React from 'react'\r\n\r\nimport { usePluginMessage } from '../../../../plugins/sdk/messages'\r\nimport { cn } from '../../../../utils/utils'\r\nimport { Badge } from '../../../ui/Badge'\r\nimport { Button } from '../../../ui/Button'\r\nimport { Separator } from '../../../ui/Separator'\r\nimport { Switch } from '../../../ui/Switch'\r\n\r\nimport { effectiveStatus } from './pluginStatus'\r\n\r\nimport type { PluginListing, PluginsAbility } from '../types'\r\nimport type { LucideIcon } from 'lucide-react'\r\n\r\n// Icon and colour both, so status survives a quick scan and colour-blindness.\r\nconst STATUS_STYLE: Record<PluginListing['status'], { icon: LucideIcon; className: string }> = {\r\n running: {\r\n icon: CheckCircle2,\r\n className: 'border-green-600/40 bg-green-600/10 text-green-700 dark:text-green-400',\r\n },\r\n off: {\r\n icon: CircleSlash,\r\n className: 'border-muted-foreground/40 bg-muted text-muted-foreground',\r\n },\r\n error: {\r\n icon: AlertTriangle,\r\n className: 'border-destructive/40 bg-destructive/10 text-destructive',\r\n },\r\n available: {\r\n icon: PackagePlus,\r\n className: 'border-sky-600/40 bg-sky-600/10 text-sky-700 dark:text-sky-400',\r\n },\r\n}\r\n\r\n// Which surface a capability contributes to: a map pin reads faster than the key.\r\nconst CAPABILITY_ICON: Record<string, LucideIcon> = {\r\n 'map.tools': MapPin,\r\n 'viewer.legends': MapPin,\r\n 'map.layers': Layers,\r\n 'bim.tools': Box,\r\n 'pointcloud.tools': Scan,\r\n 'data.pages': PanelLeft,\r\n 'viewer.tabs': PanelRight,\r\n 'ui.dialogs': SquareStack,\r\n}\r\n\r\ninterface Props {\r\n listing: PluginListing\r\n ability: PluginsAbility\r\n onSetInstalled: (installed: boolean) => void\r\n onSetOrgEnabled: (enabled: boolean) => void\r\n onSetAllowUserOverride: (allow: boolean) => void\r\n onSetUserEnabled: (enabled: boolean) => void\r\n onCopyError: () => void\r\n}\r\n\r\nexport function PluginCard({\r\n listing,\r\n ability,\r\n onSetInstalled,\r\n onSetOrgEnabled,\r\n onSetAllowUserOverride,\r\n onSetUserEnabled,\r\n onCopyError,\r\n}: Props) {\r\n const t = useTranslations('PluginsPage')\r\n const { manifest } = listing\r\n // From the switches, not the host: otherwise turning a plugin off leaves the badge\r\n // reading \"Running\".\r\n const status = effectiveStatus(listing)\r\n\r\n // The plugin's catalog when it ships one, its manifest when it does not — never a\r\n // raw message key.\r\n const name = usePluginMessage(manifest.slug, 'name', manifest.name)\r\n const description = usePluginMessage(manifest.slug, 'description', manifest.description ?? '')\r\n\r\n const isAdmin = ability.canConfigureOrg || ability.canInstall\r\n const userMayChoose = listing.allowUserOverride && ability.canChooseForSelf && status !== 'error'\r\n const userEnabled = listing.userEnabled ?? listing.orgEnabled\r\n\r\n return (\r\n <article\r\n className=\"grid gap-4 rounded-xl border bg-background p-5 md:grid-cols-[minmax(0,1fr)_auto]\"\r\n data-testid={`plugin-${manifest.slug}`}\r\n >\r\n <div className=\"min-w-0\">\r\n <div className=\"flex flex-wrap items-center gap-2\">\r\n <h2 className=\"text-lg text-foreground\">{name}</h2>\r\n <StatusBadge status={status} />\r\n {listing.bundled && (\r\n <Badge variant=\"outline\" className=\"font-normal text-muted-foreground\">\r\n {t('bundled')}\r\n </Badge>\r\n )}\r\n </div>\r\n\r\n <p className=\"mt-1 text-sm text-muted-foreground\">\r\n <code>{manifest.slug}</code>\r\n <span className=\"mx-1.5 opacity-40\">·</span>\r\n <span className=\"tabular-nums\">v{manifest.version}</span>\r\n <span className=\"mx-1.5 opacity-40\">·</span>\r\n {manifest.author || t('unknownAuthor')}\r\n </p>\r\n\r\n {description && <p className=\"mt-2 max-w-[60ch] text-sm\">{description}</p>}\r\n\r\n <div className=\"mt-3 flex flex-wrap items-center gap-1.5\">\r\n <span className=\"text-xs text-muted-foreground\">{t('capabilities')}</span>\r\n {manifest.capabilities.map(capability => (\r\n <CapabilityBadge key={capability} capability={capability} />\r\n ))}\r\n </div>\r\n\r\n {status === 'error' && listing.error && (\r\n <div className=\"mt-3 rounded-xl border border-destructive/50 bg-destructive/5 p-3\">\r\n <p className=\"flex items-center gap-1.5 text-sm font-medium text-destructive\">\r\n <AlertTriangle className=\"h-4 w-4 shrink-0\" />\r\n {t('errorHeading')}\r\n </p>\r\n <p className=\"mt-1.5 overflow-x-auto text-xs\"><code>{listing.error}</code></p>\r\n <p className=\"mt-1.5 text-xs text-muted-foreground\">{t('errorHint')}</p>\r\n </div>\r\n )}\r\n\r\n {status === 'available' && (\r\n <div className=\"mt-3 rounded-xl border border-dashed p-3\">\r\n <p className=\"text-sm font-medium\">{t('trustHeading')}</p>\r\n <ul className=\"mt-1.5 list-disc pl-4 text-xs text-muted-foreground\">\r\n {listing.mountPath && <li>{t('trustMount', { path: listing.mountPath })}</li>}\r\n <li>\r\n {manifest.requiredPermissions?.length\r\n ? t('trustPermissions', { permissions: manifest.requiredPermissions.join(', ') })\r\n : t('trustNoPermissions')}\r\n </li>\r\n <li>{t('trustWarning')}</li>\r\n </ul>\r\n </div>\r\n )}\r\n </div>\r\n\r\n <div className=\"flex min-w-0 flex-col gap-2.5 md:w-[270px]\">\r\n {status === 'available' ? (\r\n ability.canInstall && (\r\n <Button size=\"sm\" onClick={() => onSetInstalled(true)}>\r\n <PackagePlus className=\"mr-1.5 h-4 w-4\" />\r\n {t('addToOrg')}\r\n </Button>\r\n )\r\n ) : (\r\n <>\r\n {isAdmin ? (\r\n <ControlGroup label={t('orgGroup')} who={t('orgGroupWho')}>\r\n {ability.canInstall && (\r\n <ControlRow label={t('orgInstalled')}>\r\n <Switch\r\n checked={listing.installed}\r\n onCheckedChange={onSetInstalled}\r\n aria-label={t('orgInstalled')}\r\n />\r\n </ControlRow>\r\n )}\r\n {ability.canConfigureOrg && (\r\n <>\r\n <ControlRow label={t('orgEnabled')}>\r\n <Switch\r\n checked={listing.orgEnabled}\r\n onCheckedChange={onSetOrgEnabled}\r\n aria-label={t('orgEnabled')}\r\n />\r\n </ControlRow>\r\n <ControlRow\r\n label={t('orgAllowOverride')}\r\n hint={listing.allowUserOverride\r\n ? t('orgAllowOverrideOnHint')\r\n : t('orgAllowOverrideOffHint')}\r\n >\r\n <Switch\r\n checked={listing.allowUserOverride}\r\n onCheckedChange={onSetAllowUserOverride}\r\n aria-label={t('orgAllowOverride')}\r\n />\r\n </ControlRow>\r\n </>\r\n )}\r\n </ControlGroup>\r\n ) : (\r\n <ControlGroup label={t('orgGroup')}>\r\n <p className=\"py-1 text-sm text-muted-foreground\">{orgSummary(listing, t)}</p>\r\n </ControlGroup>\r\n )}\r\n\r\n <ControlGroup label={t('userGroup')}>\r\n {status === 'error' ? (\r\n <Note icon={Minus} text={t('userNothingToRun')} />\r\n ) : userMayChoose ? (\r\n <ControlRow label={t('userRun')}>\r\n <Switch\r\n checked={userEnabled}\r\n onCheckedChange={onSetUserEnabled}\r\n aria-label={t('userRun')}\r\n />\r\n </ControlRow>\r\n ) : !ability.canChooseForSelf ? (\r\n // Not the admin lock below: nothing is locked, this reader just may\r\n // not change what runs.\r\n <Note icon={Eye} text={t('userReadOnly')} />\r\n ) : (\r\n <Note icon={Lock} text={listing.orgEnabled ? t('userLockedOn') : t('userLockedOff')} />\r\n )}\r\n </ControlGroup>\r\n\r\n {status === 'error' && (\r\n <Button size=\"sm\" variant=\"outline\" onClick={onCopyError}>\r\n {t('copyError')}\r\n </Button>\r\n )}\r\n </>\r\n )}\r\n </div>\r\n </article>\r\n )\r\n}\r\n\r\nfunction StatusBadge({ status }: { status: PluginListing['status'] }) {\r\n const t = useTranslations('PluginsPage')\r\n const { icon: Icon, className } = STATUS_STYLE[status]\r\n\r\n const label: Record<PluginListing['status'], string> = {\r\n running: t('statusRunning'),\r\n off: t('statusOff'),\r\n error: t('statusError'),\r\n available: t('statusAvailable'),\r\n }\r\n\r\n return (\r\n <Badge variant=\"outline\" className={cn('gap-1 font-medium', className)}>\r\n <Icon className=\"h-3.5 w-3.5\" />\r\n {label[status]}\r\n </Badge>\r\n )\r\n}\r\n\r\nfunction CapabilityBadge({ capability }: { capability: string }) {\r\n const Icon = CAPABILITY_ICON[capability] ?? Puzzle\r\n\r\n return (\r\n <Badge variant=\"secondary\" className=\"gap-1 font-normal\">\r\n <Icon className=\"h-3.5 w-3.5\" />\r\n <code>{capability}</code>\r\n </Badge>\r\n )\r\n}\r\n\r\n// A bordered, faintly-tinted box so the controls read as a panel rather than loose\r\n// text, borrowing the muted token the app uses for inset surfaces.\r\nfunction ControlGroup({\r\n label,\r\n who,\r\n children,\r\n}: {\r\n label: string\r\n who?: string\r\n children: React.ReactNode\r\n}) {\r\n return (\r\n <div className=\"rounded-xl border bg-muted/30 px-3 py-2.5\">\r\n <div className=\"flex items-center gap-1.5 text-xs text-muted-foreground\">\r\n {label}\r\n {who && (\r\n <Badge variant=\"outline\" className=\"bg-background px-1.5 py-0 text-[10px] font-normal\">\r\n {who}\r\n </Badge>\r\n )}\r\n </div>\r\n <Separator className=\"my-2\" />\r\n {children}\r\n </div>\r\n )\r\n}\r\n\r\n/** Rows inside a group are separated, so three switches do not run together. */\r\nfunction ControlRow({\r\n label,\r\n hint,\r\n children,\r\n}: {\r\n label: string\r\n hint?: string\r\n children: React.ReactNode\r\n}) {\r\n return (\r\n <div className=\"flex items-center justify-between gap-3 py-1.5 [&+&]:border-t [&+&]:border-border/60\">\r\n <span className=\"text-sm leading-tight\">\r\n {label}\r\n {hint && <small className=\"mt-0.5 block text-xs text-muted-foreground\">{hint}</small>}\r\n </span>\r\n {children}\r\n </div>\r\n )\r\n}\r\n\r\nfunction Note({ icon: Icon, text }: { icon: LucideIcon; text: string }) {\r\n return (\r\n <p className=\"flex items-start gap-1.5 py-1 text-sm text-muted-foreground\">\r\n <Icon className=\"mt-0.5 h-4 w-4 shrink-0\" />\r\n <span>{text}</span>\r\n </p>\r\n )\r\n}\r\n\r\n/** What a non-admin is told about the organization's decision. */\r\nfunction orgSummary(\r\n listing: PluginListing,\r\n t: ReturnType<typeof useTranslations<'PluginsPage'>>,\r\n): string {\r\n if (!listing.allowUserOverride) {\r\n return listing.orgEnabled ? t('orgReadOnlyForced') : t('orgReadOnlyBlocked')\r\n }\r\n return listing.orgEnabled ? t('orgReadOnlyOnOptional') : t('orgReadOnlyOffOptional')\r\n}\r\n"],"mappings":";AA6GQ,SA4EU,UA3ER,KADF;AAxGR;AAAA,EACE;AAAA,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AAEJ;AAEA,SAAS,gBAAgB,EAAE,WAAW,GAA2B;AAzQjE;AA0QE,QAAM,QAAO,qBAAgB,UAAU,MAA1B,YAA+B;AAE5C,SACE,qBAAC,SAAM,SAAQ,aAAY,WAAU,qBACnC;AAAA,wBAAC,QAAK,WAAU,eAAc;AAAA,IAC9B,oBAAC,UAAM,sBAAW;AAAA,KACpB;AAEJ;AAIA,SAAS,aAAa;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,SACE,qBAAC,SAAI,WAAU,6CACb;AAAA,yBAAC,SAAI,WAAU,2DACZ;AAAA;AAAA,MACA,OACC,oBAAC,SAAM,SAAQ,WAAU,WAAU,qDAChC,eACH;AAAA,OAEJ;AAAA,IACA,oBAAC,aAAU,WAAU,QAAO;AAAA,IAC3B;AAAA,KACH;AAEJ;AAGA,SAAS,WAAW;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,SACE,qBAAC,SAAI,WAAU,wFACb;AAAA,yBAAC,UAAK,WAAU,yBACb;AAAA;AAAA,MACA,QAAQ,oBAAC,WAAM,WAAU,8CAA8C,gBAAK;AAAA,OAC/E;AAAA,IACC;AAAA,KACH;AAEJ;AAEA,SAAS,KAAK,EAAE,MAAM,MAAM,KAAK,GAAuC;AACtE,SACE,qBAAC,OAAE,WAAU,+DACX;AAAA,wBAAC,QAAK,WAAU,2BAA0B;AAAA,IAC1C,oBAAC,UAAM,gBAAK;AAAA,KACd;AAEJ;AAGA,SAAS,WACP,SACA,GACQ;AACR,MAAI,CAAC,QAAQ,mBAAmB;AAC9B,WAAO,QAAQ,aAAa,EAAE,mBAAmB,IAAI,EAAE,oBAAoB;AAAA,EAC7E;AACA,SAAO,QAAQ,aAAa,EAAE,uBAAuB,IAAI,EAAE,wBAAwB;AACrF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/core/components/viewers/plugins/src/PluginCard.tsx"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport {\n AlertTriangle,\n Box,\n CheckCircle2,\n CircleSlash,\n Eye,\n Lock,\n MapPin,\n Layers,\n Minus,\n PackagePlus,\n PanelLeft,\n PanelRight,\n Puzzle,\n Scan,\n SquareMenu,\n SquareStack,\n} from 'lucide-react'\nimport { useTranslations } from 'next-intl'\nimport * as React from 'react'\n\nimport { resolvePluginIcon } from '../../../../plugins/host/pluginIcon'\nimport { usePluginMessage } from '../../../../plugins/sdk/messages'\nimport { cn } from '../../../../utils/utils'\nimport { Badge } from '../../../ui/Badge'\nimport { Button } from '../../../ui/Button'\nimport { Separator } from '../../../ui/Separator'\nimport { Switch } from '../../../ui/Switch'\n\nimport { effectiveStatus } from './pluginStatus'\n\nimport type { PluginListing, PluginsAbility } from '../types'\nimport type { LucideIcon } from 'lucide-react'\n\n// Icon and colour both, so status survives a quick scan and colour-blindness.\nconst STATUS_STYLE: Record<PluginListing['status'], { icon: LucideIcon; className: string }> = {\n running: {\n icon: CheckCircle2,\n className: 'border-green-600/40 bg-green-600/10 text-green-700 dark:text-green-400',\n },\n off: {\n icon: CircleSlash,\n className: 'border-muted-foreground/40 bg-muted text-muted-foreground',\n },\n error: {\n icon: AlertTriangle,\n className: 'border-destructive/40 bg-destructive/10 text-destructive',\n },\n available: {\n icon: PackagePlus,\n className: 'border-sky-600/40 bg-sky-600/10 text-sky-700 dark:text-sky-400',\n },\n}\n\n// Which surface a capability contributes to: an icon reads faster than the dotted key.\nconst CAPABILITY_ICON: Record<string, LucideIcon> = {\n 'map.tools': MapPin,\n 'viewer.legends': SquareMenu,\n 'map.layers': Layers,\n 'bim.tools': Box,\n 'pointcloud.tools': Scan,\n 'data.pages': PanelLeft,\n 'viewer.tabs': PanelRight,\n 'ui.dialogs': SquareStack,\n}\n\ninterface Props {\n listing: PluginListing\n ability: PluginsAbility\n onSetInstalled: (installed: boolean) => void\n onSetOrgEnabled: (enabled: boolean) => void\n onSetAllowUserOverride: (allow: boolean) => void\n onSetUserEnabled: (enabled: boolean) => void\n onCopyError: () => void\n}\n\nexport function PluginCard({\n listing,\n ability,\n onSetInstalled,\n onSetOrgEnabled,\n onSetAllowUserOverride,\n onSetUserEnabled,\n onCopyError,\n}: Props) {\n const t = useTranslations('PluginsPage')\n const { manifest } = listing\n // From the switches, not the host: otherwise turning a plugin off leaves the badge\n // reading \"Running\".\n const status = effectiveStatus(listing)\n\n const Icon = resolvePluginIcon(manifest.icon ?? 'Puzzle')\n\n // The plugin's catalog when it ships one, its manifest when it does not — never a\n // raw message key.\n const name = usePluginMessage(manifest.slug, 'name', manifest.name)\n const description = usePluginMessage(manifest.slug, 'description', manifest.description ?? '')\n\n const isAdmin = ability.canConfigureOrg || ability.canInstall\n const userMayChoose = listing.allowUserOverride && ability.canChooseForSelf && status !== 'error'\n const userEnabled = listing.userEnabled ?? listing.orgEnabled\n\n return (\n <article\n className=\"grid gap-4 rounded-xl border bg-background p-5 md:grid-cols-[minmax(0,1fr)_auto]\"\n data-testid={`plugin-${manifest.slug}`}\n >\n <div className=\"min-w-0\">\n <div className=\"flex flex-wrap items-center gap-2\">\n <Icon\n aria-hidden\n className=\"h-5 w-5 shrink-0 text-muted-foreground\"\n data-testid={`plugin-icon-${manifest.slug}`}\n />\n <h2 className=\"text-lg text-foreground\">{name}</h2>\n <StatusBadge status={status} />\n {listing.bundled && (\n <Badge variant=\"outline\" className=\"font-normal text-muted-foreground\">\n {t('bundled')}\n </Badge>\n )}\n </div>\n\n <p className=\"mt-1 text-sm text-muted-foreground\">\n <code>{manifest.slug}</code>\n <span className=\"mx-1.5 opacity-40\">·</span>\n <span className=\"tabular-nums\">v{manifest.version}</span>\n <span className=\"mx-1.5 opacity-40\">·</span>\n {manifest.author || t('unknownAuthor')}\n </p>\n\n {description && <p className=\"mt-2 max-w-[60ch] text-sm\">{description}</p>}\n\n <div className=\"mt-3 flex flex-wrap items-center gap-1.5\">\n <span className=\"text-xs text-muted-foreground\">{t('capabilities')}</span>\n {manifest.capabilities.map(capability => (\n <CapabilityBadge key={capability} capability={capability} />\n ))}\n </div>\n\n {status === 'error' && listing.error && (\n <div className=\"mt-3 rounded-xl border border-destructive/50 bg-destructive/5 p-3\">\n <p className=\"flex items-center gap-1.5 text-sm font-medium text-destructive\">\n <AlertTriangle className=\"h-4 w-4 shrink-0\" />\n {t('errorHeading')}\n </p>\n <p className=\"mt-1.5 overflow-x-auto text-xs\"><code>{listing.error}</code></p>\n <p className=\"mt-1.5 text-xs text-muted-foreground\">{t('errorHint')}</p>\n </div>\n )}\n\n {status === 'available' && (\n <div className=\"mt-3 rounded-xl border border-dashed p-3\">\n <p className=\"text-sm font-medium\">{t('trustHeading')}</p>\n <ul className=\"mt-1.5 list-disc pl-4 text-xs text-muted-foreground\">\n {listing.mountPath && <li>{t('trustMount', { path: listing.mountPath })}</li>}\n <li>\n {manifest.requiredPermissions?.length\n ? t('trustPermissions', { permissions: manifest.requiredPermissions.join(', ') })\n : t('trustNoPermissions')}\n </li>\n <li>{t('trustWarning')}</li>\n </ul>\n </div>\n )}\n </div>\n\n <div className=\"flex min-w-0 flex-col gap-2.5 md:w-[270px]\">\n {status === 'available' ? (\n ability.canInstall && (\n <Button size=\"sm\" onClick={() => onSetInstalled(true)}>\n <PackagePlus className=\"mr-1.5 h-4 w-4\" />\n {t('addToOrg')}\n </Button>\n )\n ) : (\n <>\n {isAdmin ? (\n <ControlGroup label={t('orgGroup')} who={t('orgGroupWho')}>\n {ability.canInstall && (\n <ControlRow label={t('orgInstalled')}>\n <Switch\n checked={listing.installed}\n onCheckedChange={onSetInstalled}\n aria-label={t('orgInstalled')}\n />\n </ControlRow>\n )}\n {ability.canConfigureOrg && (\n <>\n <ControlRow label={t('orgEnabled')}>\n <Switch\n checked={listing.orgEnabled}\n onCheckedChange={onSetOrgEnabled}\n aria-label={t('orgEnabled')}\n />\n </ControlRow>\n <ControlRow\n label={t('orgAllowOverride')}\n hint={listing.allowUserOverride\n ? t('orgAllowOverrideOnHint')\n : t('orgAllowOverrideOffHint')}\n >\n <Switch\n checked={listing.allowUserOverride}\n onCheckedChange={onSetAllowUserOverride}\n aria-label={t('orgAllowOverride')}\n />\n </ControlRow>\n </>\n )}\n </ControlGroup>\n ) : (\n <ControlGroup label={t('orgGroup')}>\n <p className=\"py-1 text-sm text-muted-foreground\">{orgSummary(listing, t)}</p>\n </ControlGroup>\n )}\n\n <ControlGroup label={t('userGroup')}>\n {status === 'error' ? (\n <Note icon={Minus} text={t('userNothingToRun')} />\n ) : userMayChoose ? (\n <ControlRow label={t('userRun')}>\n <Switch\n checked={userEnabled}\n onCheckedChange={onSetUserEnabled}\n aria-label={t('userRun')}\n />\n </ControlRow>\n ) : !ability.canChooseForSelf ? (\n // Not the admin lock below: nothing is locked, this reader just may\n // not change what runs.\n <Note icon={Eye} text={t('userReadOnly')} />\n ) : (\n <Note icon={Lock} text={listing.orgEnabled ? t('userLockedOn') : t('userLockedOff')} />\n )}\n </ControlGroup>\n\n {status === 'error' && (\n <Button size=\"sm\" variant=\"outline\" onClick={onCopyError}>\n {t('copyError')}\n </Button>\n )}\n </>\n )}\n </div>\n </article>\n )\n}\n\nfunction StatusBadge({ status }: { status: PluginListing['status'] }) {\n const t = useTranslations('PluginsPage')\n const { icon: Icon, className } = STATUS_STYLE[status]\n\n const label: Record<PluginListing['status'], string> = {\n running: t('statusRunning'),\n off: t('statusOff'),\n error: t('statusError'),\n available: t('statusAvailable'),\n }\n\n return (\n <Badge variant=\"outline\" className={cn('gap-1 font-medium', className)}>\n <Icon className=\"h-3.5 w-3.5\" />\n {label[status]}\n </Badge>\n )\n}\n\nfunction CapabilityBadge({ capability }: { capability: string }) {\n const Icon = CAPABILITY_ICON[capability] ?? Puzzle\n\n return (\n <Badge variant=\"secondary\" className=\"gap-1 font-normal\">\n <Icon className=\"h-3.5 w-3.5\" />\n <code>{capability}</code>\n </Badge>\n )\n}\n\n// A bordered, faintly-tinted box so the controls read as a panel rather than loose\n// text, borrowing the muted token the app uses for inset surfaces.\nfunction ControlGroup({\n label,\n who,\n children,\n}: {\n label: string\n who?: string\n children: React.ReactNode\n}) {\n return (\n <div className=\"rounded-xl border bg-muted/30 px-3 py-2.5\">\n <div className=\"flex items-center gap-1.5 text-xs text-muted-foreground\">\n {label}\n {who && (\n <Badge variant=\"outline\" className=\"bg-background px-1.5 py-0 text-[10px] font-normal\">\n {who}\n </Badge>\n )}\n </div>\n <Separator className=\"my-2\" />\n {children}\n </div>\n )\n}\n\n/** Rows inside a group are separated, so three switches do not run together. */\nfunction ControlRow({\n label,\n hint,\n children,\n}: {\n label: string\n hint?: string\n children: React.ReactNode\n}) {\n return (\n <div className=\"flex items-center justify-between gap-3 py-1.5 [&+&]:border-t [&+&]:border-border/60\">\n <span className=\"text-sm leading-tight\">\n {label}\n {hint && <small className=\"mt-0.5 block text-xs text-muted-foreground\">{hint}</small>}\n </span>\n {children}\n </div>\n )\n}\n\nfunction Note({ icon: Icon, text }: { icon: LucideIcon; text: string }) {\n return (\n <p className=\"flex items-start gap-1.5 py-1 text-sm text-muted-foreground\">\n <Icon className=\"mt-0.5 h-4 w-4 shrink-0\" />\n <span>{text}</span>\n </p>\n )\n}\n\n/** What a non-admin is told about the organization's decision. */\nfunction orgSummary(\n listing: PluginListing,\n t: ReturnType<typeof useTranslations<'PluginsPage'>>,\n): string {\n if (!listing.allowUserOverride) {\n return listing.orgEnabled ? t('orgReadOnlyForced') : t('orgReadOnlyBlocked')\n }\n return listing.orgEnabled ? t('orgReadOnlyOnOptional') : t('orgReadOnlyOffOptional')\n}\n"],"mappings":";AAiHQ,SAiFU,UAhFR,KADF;AA5GR;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAGhC,SAAS,yBAAyB;AACl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ab, a legend and a dialog.",
|
|
7
7
|
"author": "Collab Digital Twins",
|
|
8
|
+
"icon": "Boxes",
|
|
8
9
|
"capabilities": [
|
|
9
10
|
"bim.tools",
|
|
10
11
|
"viewer.tabs",
|
|
@@ -124,4 +125,4 @@
|
|
|
124
125
|
"isolateSpace": "Aislar este espacio"
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
|
-
}
|
|
128
|
+
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"hostApi": 1,
|
|
6
6
|
"description": "Records markers on the map and shows them everywhere: a toolbar readout, a map layer, a legend, a viewer sidebar tab, a data page and a dialog.",
|
|
7
7
|
"author": "Collab Digital Twins",
|
|
8
|
+
"icon": "MapPin",
|
|
8
9
|
"capabilities": [
|
|
9
10
|
"map.tools",
|
|
10
11
|
"map.layers",
|
|
@@ -126,4 +127,4 @@
|
|
|
126
127
|
"nameLabel": "Nombre"
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
|
-
}
|
|
130
|
+
}
|
|
@@ -29,10 +29,10 @@ import {
|
|
|
29
29
|
} from "../../components/ui/Breadcrumb";
|
|
30
30
|
import { Input } from "../../components/ui/Input";
|
|
31
31
|
import { usePluginMessageLookup } from "../sdk/messages";
|
|
32
|
+
import { resolvePluginIcon } from "./pluginIcon";
|
|
32
33
|
import { parsePluginViewerKey } from "./pluginViewerKey";
|
|
33
34
|
import { usePluginConfigs, usePluginContributions } from "./provider";
|
|
34
35
|
import { PluginScopeProvider } from "./scope";
|
|
35
|
-
import { resolvePluginIcon } from "./usePluginToolbarTools";
|
|
36
36
|
function PluginDataPageHost({ viewer }) {
|
|
37
37
|
const registrations = usePluginContributions("data.pages");
|
|
38
38
|
const target = parsePluginViewerKey(viewer);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/plugins/host/PluginDataPageHost.tsx"],"sourcesContent":["'use client'\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport { useTranslations } from 'next-intl'\r\nimport * as React from 'react'\r\n\r\nimport {\r\n Breadcrumb,\r\n BreadcrumbItem,\r\n BreadcrumbList,\r\n BreadcrumbPage,\r\n} from '../../components/ui/Breadcrumb'\r\nimport { Input } from '../../components/ui/Input'\r\nimport { usePluginMessageLookup } from '../sdk/messages'\r\n\r\nimport { parsePluginViewerKey } from './pluginViewerKey'\r\nimport { usePluginConfigs, usePluginContributions } from './provider'\r\nimport { PluginScopeProvider } from './scope'\r\nimport { resolvePluginIcon } from './usePluginToolbarTools'\r\n\r\nimport type { ViewerKey } from '../../types/dbTypes'\r\nimport type { DataPageRegistration } from '../sdk/types'\r\n\r\ntype Row = Record<string, unknown>\r\ntype Registration = DataPageRegistration & { pluginId: string }\r\n\r\n/**\r\n * Renders the `data.pages` contribution the viewer key names. The frame mirrors\r\n * `PluginsManager`, so a plugin page is indistinguishable from a built-in one.\r\n */\r\nexport function PluginDataPageHost({ viewer }: { viewer: ViewerKey }) {\r\n const registrations = usePluginContributions('data.pages')\r\n const target = parsePluginViewerKey(viewer)\r\n\r\n const registration = target\r\n ? registrations.find(\r\n candidate => candidate.pluginId === target.pluginId && candidate.id === target.pageId,\r\n )\r\n : undefined\r\n\r\n // The key comes from the URL, so rendering nothing lets `Viewer` fall back.\r\n if (!registration) return null\r\n\r\n return <PluginDataPage key={viewer} registration={registration} />\r\n}\r\n\r\nfunction PluginDataPage({ registration }: { registration: Registration }) {\r\n const tData = useTranslations('DataMenu')\r\n const message = usePluginMessageLookup()\r\n const configs = usePluginConfigs()\r\n const [searchTerm, setSearchTerm] = React.useState('')\r\n\r\n const title = message(registration.pluginId, registration.titleKey, registration.titleKey)\r\n const Icon = resolvePluginIcon(registration.icon)\r\n\r\n return (\r\n <div className=\"sm:p-2 overflow-hidden bg-[#fafafa] h-full\">\r\n <div className=\"bg-background rounded-xl shadow h-full min-h-0\">\r\n <div className=\"flex flex-col h-full min-h-0\">\r\n\r\n <div className=\"flex flex-row gap-2 justify-start items-center px-3 py-4 relative\">\r\n <Breadcrumb className=\"px-3\">\r\n <BreadcrumbList>\r\n <BreadcrumbItem>\r\n <BreadcrumbPage>{title}</BreadcrumbPage>\r\n </BreadcrumbItem>\r\n </BreadcrumbList>\r\n </Breadcrumb>\r\n </div>\r\n\r\n <div className=\"flex flex-row justify-between items-center px-6 py-6\">\r\n <div className=\"flex items-center gap-2\">\r\n <Icon className=\"h-8 w-8\" />\r\n <h1 className=\"text-2xl text-foreground\">{title}</h1>\r\n </div>\r\n </div>\r\n\r\n <div className=\"flex flex-col sm:flex-row sm:justify-end items-stretch sm:items-center px-3 sm:px-6 py-4 gap-3 sm:gap-4\">\r\n <div className=\"w-full sm:w-96\">\r\n <Input\r\n placeholder={`${tData('searchPlaceholder')} ${title}...`}\r\n value={searchTerm}\r\n onChange={event => setSearchTerm(event.target.value)}\r\n aria-label={`${tData('searchPlaceholder')} ${title}`}\r\n />\r\n </div>\r\n </div>\r\n\r\n <div className=\"flex-1 min-h-0 overflow-y-auto px-3 sm:px-6 pb-8\">\r\n {/* The rows hook and the cell renderers are the plugin's, so they run inside its\r\n scope and can reach usePluginStore, usePluginState and the rest. */}\r\n <PluginScopeProvider\r\n pluginId={registration.pluginId}\r\n config={configs[registration.pluginId]}\r\n >\r\n <PluginDataTable\r\n key={`${registration.pluginId}:${registration.id}`}\r\n registration={registration}\r\n searchTerm={searchTerm}\r\n />\r\n </PluginScopeProvider>\r\n </div>\r\n\r\n </div>\r\n </div>\r\n </div>\r\n )\r\n}\r\n\r\ninterface TableProps {\r\n registration: Registration\r\n searchTerm: string\r\n}\r\n\r\nfunction PluginDataTable({ registration, searchTerm }: TableProps) {\r\n const t = useTranslations('PluginDataPage')\r\n const message = usePluginMessageLookup()\r\n const { rows, isLoading, onRowClick } = registration.useRows()\r\n\r\n const filtered = React.useMemo(\r\n () => filterRows(rows, registration.searchKeys, searchTerm),\r\n [rows, registration.searchKeys, searchTerm],\r\n )\r\n\r\n if (isLoading && rows.length === 0) return <Empty text={t('loading')} />\r\n\r\n if (filtered.length === 0) {\r\n if (searchTerm.trim()) return <Empty text={t('noResults', { query: searchTerm.trim() })} />\r\n\r\n const empty = registration.emptyKey\r\n ? message(registration.pluginId, registration.emptyKey, registration.emptyKey)\r\n : t('empty')\r\n\r\n return <Empty text={empty} />\r\n }\r\n\r\n return (\r\n <div className=\"overflow-x-auto\">\r\n <table className=\"w-full text-sm\">\r\n <thead>\r\n <tr className=\"border-b text-left text-muted-foreground\">\r\n {registration.columns.map(column => (\r\n <th key={column.key} scope=\"col\" className=\"px-3 py-2 font-medium\">\r\n {message(registration.pluginId, column.labelKey, column.labelKey)}\r\n </th>\r\n ))}\r\n </tr>\r\n </thead>\r\n <tbody>\r\n {filtered.map((row, index) => (\r\n <tr\r\n key={rowKey(row, index)}\r\n className={onRowClick ? 'border-b hover:bg-accent/50 cursor-pointer' : 'border-b'}\r\n // Interactive only when the plugin gave it something to do.\r\n {...(onRowClick\r\n ? {\r\n role: 'button' as const,\r\n tabIndex: 0,\r\n onClick: () => onRowClick(row),\r\n onKeyDown: (event: React.KeyboardEvent) => {\r\n if (event.key !== 'Enter' && event.key !== ' ') return\r\n event.preventDefault()\r\n onRowClick(row)\r\n },\r\n }\r\n : {})}\r\n >\r\n {registration.columns.map(column => (\r\n <td key={column.key} className=\"px-3 py-2\">\r\n {column.render ? column.render(row) : formatCell(row[column.key])}\r\n </td>\r\n ))}\r\n </tr>\r\n ))}\r\n </tbody>\r\n </table>\r\n </div>\r\n )\r\n}\r\n\r\n/** A plugin's own `key` when it supplied one, so a re-render does not remount every row. */\r\nfunction rowKey(row: Row, index: number): string {\r\n return typeof row.key === 'string' ? row.key : String(index)\r\n}\r\n\r\n// Non-primitives render empty rather than \"[object Object]\"; use a column `render` instead.\r\nfunction formatCell(value: unknown): string {\r\n if (typeof value === 'string') return value\r\n if (typeof value === 'number' || typeof value === 'boolean') return String(value)\r\n return ''\r\n}\r\n\r\nfunction filterRows(rows: Row[], searchKeys: string[] | undefined, searchTerm: string): Row[] {\r\n const query = searchTerm.trim().toLowerCase()\r\n if (!query) return rows\r\n\r\n return rows.filter((row) => {\r\n const keys = searchKeys ?? Object.keys(row)\r\n return keys.some(key => formatCell(row[key]).toLowerCase().includes(query))\r\n })\r\n}\r\n\r\nfunction Empty({ text }: { text: string }) {\r\n return <p className=\"py-12 text-center text-sm text-muted-foreground\">{text}</p>\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6CS,cA4BG,YA5BH;AAxCT,SAAS,uBAAuB;AAChC,YAAY,WAAW;AAEvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa;AACtB,SAAS,8BAA8B;AAEvC,SAAS,4BAA4B;AACrC,SAAS,kBAAkB,8BAA8B;AACzD,SAAS,2BAA2B;AACpC,SAAS,yBAAyB;AAY3B,SAAS,mBAAmB,EAAE,OAAO,GAA0B;AACpE,QAAM,gBAAgB,uBAAuB,YAAY;AACzD,QAAM,SAAS,qBAAqB,MAAM;AAE1C,QAAM,eAAe,SACjB,cAAc;AAAA,IACd,eAAa,UAAU,aAAa,OAAO,YAAY,UAAU,OAAO,OAAO;AAAA,EACjF,IACE;AAGJ,MAAI,CAAC,aAAc,QAAO;AAE1B,SAAO,oBAAC,kBAA4B,gBAAR,MAAoC;AAClE;AAEA,SAAS,eAAe,EAAE,aAAa,GAAmC;AACxE,QAAM,QAAQ,gBAAgB,UAAU;AACxC,QAAM,UAAU,uBAAuB;AACvC,QAAM,UAAU,iBAAiB;AACjC,QAAM,CAAC,YAAY,aAAa,IAAI,MAAM,SAAS,EAAE;AAErD,QAAM,QAAQ,QAAQ,aAAa,UAAU,aAAa,UAAU,aAAa,QAAQ;AACzF,QAAM,OAAO,kBAAkB,aAAa,IAAI;AAEhD,SACE,oBAAC,SAAI,WAAU,8CACb,8BAAC,SAAI,WAAU,kDACb,+BAAC,SAAI,WAAU,gCAEb;AAAA,wBAAC,SAA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W,OAAwB;AAC1C,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU,UAAW,QAAO,OAAO,KAAK;AAChF,SAAO;AACT;AAEA,SAAS,WAAW,MAAa,YAAkC,YAA2B;AAC5F,QAAM,QAAQ,WAAW,KAAK,EAAE,YAAY;AAC5C,MAAI,CAAC,MAAO,QAAO;AAEnB,SAAO,KAAK,OAAO,CAAC,QAAQ;AAC1B,UAAM,OAAO,kCAAc,OAAO,KAAK,GAAG;AAC1C,WAAO,KAAK,KAAK,SAAO,WAAW,IAAI,GAAG,CAAC,EAAE,YAAY,EAAE,SAAS,KAAK,CAAC;AAAA,EAC5E,CAAC;AACH;AAEA,SAAS,MAAM,EAAE,KAAK,GAAqB;AACzC,SAAO,oBAAC,OAAE,WAAU,mDAAmD,gBAAK;AAC9E;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/plugins/host/PluginDataPageHost.tsx"],"sourcesContent":["'use client'\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport { useTranslations } from 'next-intl'\r\nimport * as React from 'react'\r\n\r\nimport {\r\n Breadcrumb,\r\n BreadcrumbItem,\r\n BreadcrumbList,\r\n BreadcrumbPage,\r\n} from '../../components/ui/Breadcrumb'\r\nimport { Input } from '../../components/ui/Input'\r\nimport { usePluginMessageLookup } from '../sdk/messages'\r\n\r\nimport { resolvePluginIcon } from './pluginIcon'\r\nimport { parsePluginViewerKey } from './pluginViewerKey'\r\nimport { usePluginConfigs, usePluginContributions } from './provider'\r\nimport { PluginScopeProvider } from './scope'\r\n\r\nimport type { ViewerKey } from '../../types/dbTypes'\r\nimport type { DataPageRegistration } from '../sdk/types'\r\n\r\ntype Row = Record<string, unknown>\r\ntype Registration = DataPageRegistration & { pluginId: string }\r\n\r\n/**\r\n * Renders the `data.pages` contribution the viewer key names. The frame mirrors\r\n * `PluginsManager`, so a plugin page is indistinguishable from a built-in one.\r\n */\r\nexport function PluginDataPageHost({ viewer }: { viewer: ViewerKey }) {\r\n const registrations = usePluginContributions('data.pages')\r\n const target = parsePluginViewerKey(viewer)\r\n\r\n const registration = target\r\n ? registrations.find(\r\n candidate => candidate.pluginId === target.pluginId && candidate.id === target.pageId,\r\n )\r\n : undefined\r\n\r\n // The key comes from the URL, so rendering nothing lets `Viewer` fall back.\r\n if (!registration) return null\r\n\r\n return <PluginDataPage key={viewer} registration={registration} />\r\n}\r\n\r\nfunction PluginDataPage({ registration }: { registration: Registration }) {\r\n const tData = useTranslations('DataMenu')\r\n const message = usePluginMessageLookup()\r\n const configs = usePluginConfigs()\r\n const [searchTerm, setSearchTerm] = React.useState('')\r\n\r\n const title = message(registration.pluginId, registration.titleKey, registration.titleKey)\r\n const Icon = resolvePluginIcon(registration.icon)\r\n\r\n return (\r\n <div className=\"sm:p-2 overflow-hidden bg-[#fafafa] h-full\">\r\n <div className=\"bg-background rounded-xl shadow h-full min-h-0\">\r\n <div className=\"flex flex-col h-full min-h-0\">\r\n\r\n <div className=\"flex flex-row gap-2 justify-start items-center px-3 py-4 relative\">\r\n <Breadcrumb className=\"px-3\">\r\n <BreadcrumbList>\r\n <BreadcrumbItem>\r\n <BreadcrumbPage>{title}</BreadcrumbPage>\r\n </BreadcrumbItem>\r\n </BreadcrumbList>\r\n </Breadcrumb>\r\n </div>\r\n\r\n <div className=\"flex flex-row justify-between items-center px-6 py-6\">\r\n <div className=\"flex items-center gap-2\">\r\n <Icon className=\"h-8 w-8\" />\r\n <h1 className=\"text-2xl text-foreground\">{title}</h1>\r\n </div>\r\n </div>\r\n\r\n <div className=\"flex flex-col sm:flex-row sm:justify-end items-stretch sm:items-center px-3 sm:px-6 py-4 gap-3 sm:gap-4\">\r\n <div className=\"w-full sm:w-96\">\r\n <Input\r\n placeholder={`${tData('searchPlaceholder')} ${title}...`}\r\n value={searchTerm}\r\n onChange={event => setSearchTerm(event.target.value)}\r\n aria-label={`${tData('searchPlaceholder')} ${title}`}\r\n />\r\n </div>\r\n </div>\r\n\r\n <div className=\"flex-1 min-h-0 overflow-y-auto px-3 sm:px-6 pb-8\">\r\n {/* The rows hook and the cell renderers are the plugin's, so they run inside its\r\n scope and can reach usePluginStore, usePluginState and the rest. */}\r\n <PluginScopeProvider\r\n pluginId={registration.pluginId}\r\n config={configs[registration.pluginId]}\r\n >\r\n <PluginDataTable\r\n key={`${registration.pluginId}:${registration.id}`}\r\n registration={registration}\r\n searchTerm={searchTerm}\r\n />\r\n </PluginScopeProvider>\r\n </div>\r\n\r\n </div>\r\n </div>\r\n </div>\r\n )\r\n}\r\n\r\ninterface TableProps {\r\n registration: Registration\r\n searchTerm: string\r\n}\r\n\r\nfunction PluginDataTable({ registration, searchTerm }: TableProps) {\r\n const t = useTranslations('PluginDataPage')\r\n const message = usePluginMessageLookup()\r\n const { rows, isLoading, onRowClick } = registration.useRows()\r\n\r\n const filtered = React.useMemo(\r\n () => filterRows(rows, registration.searchKeys, searchTerm),\r\n [rows, registration.searchKeys, searchTerm],\r\n )\r\n\r\n if (isLoading && rows.length === 0) return <Empty text={t('loading')} />\r\n\r\n if (filtered.length === 0) {\r\n if (searchTerm.trim()) return <Empty text={t('noResults', { query: searchTerm.trim() })} />\r\n\r\n const empty = registration.emptyKey\r\n ? message(registration.pluginId, registration.emptyKey, registration.emptyKey)\r\n : t('empty')\r\n\r\n return <Empty text={empty} />\r\n }\r\n\r\n return (\r\n <div className=\"overflow-x-auto\">\r\n <table className=\"w-full text-sm\">\r\n <thead>\r\n <tr className=\"border-b text-left text-muted-foreground\">\r\n {registration.columns.map(column => (\r\n <th key={column.key} scope=\"col\" className=\"px-3 py-2 font-medium\">\r\n {message(registration.pluginId, column.labelKey, column.labelKey)}\r\n </th>\r\n ))}\r\n </tr>\r\n </thead>\r\n <tbody>\r\n {filtered.map((row, index) => (\r\n <tr\r\n key={rowKey(row, index)}\r\n className={onRowClick ? 'border-b hover:bg-accent/50 cursor-pointer' : 'border-b'}\r\n // Interactive only when the plugin gave it something to do.\r\n {...(onRowClick\r\n ? {\r\n role: 'button' as const,\r\n tabIndex: 0,\r\n onClick: () => onRowClick(row),\r\n onKeyDown: (event: React.KeyboardEvent) => {\r\n if (event.key !== 'Enter' && event.key !== ' ') return\r\n event.preventDefault()\r\n onRowClick(row)\r\n },\r\n }\r\n : {})}\r\n >\r\n {registration.columns.map(column => (\r\n <td key={column.key} className=\"px-3 py-2\">\r\n {column.render ? column.render(row) : formatCell(row[column.key])}\r\n </td>\r\n ))}\r\n </tr>\r\n ))}\r\n </tbody>\r\n </table>\r\n </div>\r\n )\r\n}\r\n\r\n/** A plugin's own `key` when it supplied one, so a re-render does not remount every row. */\r\nfunction rowKey(row: Row, index: number): string {\r\n return typeof row.key === 'string' ? row.key : String(index)\r\n}\r\n\r\n// Non-primitives render empty rather than \"[object Object]\"; use a column `render` instead.\r\nfunction formatCell(value: unknown): string {\r\n if (typeof value === 'string') return value\r\n if (typeof value === 'number' || typeof value === 'boolean') return String(value)\r\n return ''\r\n}\r\n\r\nfunction filterRows(rows: Row[], searchKeys: string[] | undefined, searchTerm: string): Row[] {\r\n const query = searchTerm.trim().toLowerCase()\r\n if (!query) return rows\r\n\r\n return rows.filter((row) => {\r\n const keys = searchKeys ?? Object.keys(row)\r\n return keys.some(key => formatCell(row[key]).toLowerCase().includes(query))\r\n })\r\n}\r\n\r\nfunction Empty({ text }: { text: string }) {\r\n return <p className=\"py-12 text-center text-sm text-muted-foreground\">{text}</p>\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6CS,cA4BG,YA5BH;AAxCT,SAAS,uBAAuB;AAChC,YAAY,WAAW;AAEvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa;AACtB,SAAS,8BAA8B;AAEvC,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AACrC,SAAS,kBAAkB,8BAA8B;AACzD,SAAS,2BAA2B;AAY7B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1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/core/plugins/host/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/core/plugins/host/context.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAEjB,MAAM,cAAc,CAAA;AAErB,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,gBAAgB,EAAE,CAAA;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,QAAQ,EAAE,cAAc,CAAA;CACzB;AAwBD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAsBhF"}
|
|
@@ -17,6 +17,21 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { ViewerNames } from "../sdk/types";
|
|
21
|
+
const TARGETABLE_VIEWERS = /* @__PURE__ */ new Set([
|
|
22
|
+
ViewerNames.map,
|
|
23
|
+
ViewerNames.bim,
|
|
24
|
+
ViewerNames.pointcloud
|
|
25
|
+
]);
|
|
26
|
+
function warnOnUnknownViewers(pluginId, key, item) {
|
|
27
|
+
const { viewers } = item;
|
|
28
|
+
if (!Array.isArray(viewers)) return;
|
|
29
|
+
const unknown = viewers.filter((viewer) => !TARGETABLE_VIEWERS.has(viewer));
|
|
30
|
+
if (unknown.length === 0) return;
|
|
31
|
+
console.warn(
|
|
32
|
+
`Plugin "${pluginId}" targets unknown viewer(s) ${unknown.map((v) => JSON.stringify(v)).join(", ")} in its "${key}" contribution, so it renders nowhere. Valid viewers: ${[...TARGETABLE_VIEWERS].join(", ")}.`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
20
35
|
function createPluginContext(options) {
|
|
21
36
|
const { pluginId, capabilities, config, registry } = options;
|
|
22
37
|
const declared = new Set(capabilities);
|
|
@@ -29,6 +44,7 @@ function createPluginContext(options) {
|
|
|
29
44
|
`Plugin "${pluginId}" did not declare capability "${key}" in its manifest`
|
|
30
45
|
);
|
|
31
46
|
}
|
|
47
|
+
warnOnUnknownViewers(pluginId, key, item);
|
|
32
48
|
registry.register(key, __spreadProps(__spreadValues({}, item), { pluginId }));
|
|
33
49
|
}
|
|
34
50
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/plugins/host/context.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/plugins/host/context.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport { ViewerNames } from '../sdk/types'\n\nimport type { PluginRegistry } from './registry'\nimport type {\n PluginContext,\n PluginCapability,\n CapabilityRegistry,\n} from '../sdk/types'\n\ninterface CreateContextOptions {\n pluginId: string\n capabilities: PluginCapability[]\n config: Record<string, unknown>\n registry: PluginRegistry\n}\n\n// `ViewerNames` also names routes like settings and users; only these three host contributions.\nconst TARGETABLE_VIEWERS = new Set<string>([\n ViewerNames.map,\n ViewerNames.bim,\n ViewerNames.pointcloud,\n])\n\n// A viewer name outside the three renders nowhere and throws nothing, so say so once here.\nfunction warnOnUnknownViewers(pluginId: string, key: string, item: unknown): void {\n const { viewers } = item as { viewers?: unknown }\n if (!Array.isArray(viewers)) return\n\n const unknown = viewers.filter(viewer => !TARGETABLE_VIEWERS.has(viewer as string))\n if (unknown.length === 0) return\n\n console.warn(\n `Plugin \"${pluginId}\" targets unknown viewer(s) ${unknown.map(v => JSON.stringify(v)).join(', ')} `\n + `in its \"${key}\" contribution, so it renders nowhere. Valid viewers: `\n + `${[...TARGETABLE_VIEWERS].join(', ')}.`,\n )\n}\n\nexport function createPluginContext(options: CreateContextOptions): PluginContext {\n const { pluginId, capabilities, config, registry } = options\n const declared = new Set<string>(capabilities)\n\n return {\n pluginId,\n config,\n register<K extends keyof CapabilityRegistry>(key: K, item: CapabilityRegistry[K]): void {\n if (!declared.has(key)) {\n throw new Error(\n `Plugin \"${pluginId}\" did not declare capability \"${key}\" in its manifest`,\n )\n }\n\n warnOnUnknownViewers(pluginId, key, item)\n\n // `pluginId` last, so a plugin cannot pass one and claim to be another. The\n // double cast is because the registration types have no index signature and\n // `RegistryEntry` needs one to store shapes keyed by capability.\n registry.register(key, { ...(item as unknown as Record<string, unknown>), pluginId })\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAGA,SAAS,mBAAmB;AAiB5B,MAAM,qBAAqB,oBAAI,IAAY;AAAA,EACzC,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,YAAY;AACd,CAAC;AAGD,SAAS,qBAAqB,UAAkB,KAAa,MAAqB;AAChF,QAAM,EAAE,QAAQ,IAAI;AACpB,MAAI,CAAC,MAAM,QAAQ,OAAO,EAAG;AAE7B,QAAM,UAAU,QAAQ,OAAO,YAAU,CAAC,mBAAmB,IAAI,MAAgB,CAAC;AAClF,MAAI,QAAQ,WAAW,EAAG;AAE1B,UAAQ;AAAA,IACN,WAAW,QAAQ,+BAA+B,QAAQ,IAAI,OAAK,KAAK,UAAU,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,YACnF,GAAG,yDACX,CAAC,GAAG,kBAAkB,EAAE,KAAK,IAAI,CAAC;AAAA,EACzC;AACF;AAEO,SAAS,oBAAoB,SAA8C;AAChF,QAAM,EAAE,UAAU,cAAc,QAAQ,SAAS,IAAI;AACrD,QAAM,WAAW,IAAI,IAAY,YAAY;AAE7C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,SAA6C,KAAQ,MAAmC;AACtF,UAAI,CAAC,SAAS,IAAI,GAAG,GAAG;AACtB,cAAM,IAAI;AAAA,UACR,WAAW,QAAQ,iCAAiC,GAAG;AAAA,QACzD;AAAA,MACF;AAEA,2BAAqB,UAAU,KAAK,IAAI;AAKxC,eAAS,SAAS,KAAK,iCAAM,OAAN,EAAmD,SAAS,EAAC;AAAA,IACtF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { LucideProps } from 'lucide-react';
|
|
2
|
+
import type * as React from 'react';
|
|
3
|
+
/** A plugin may pass a lucide component, or its name as a string — JSON manifests only carry the string. */
|
|
4
|
+
export declare function resolvePluginIcon(icon: string | React.ComponentType<LucideProps>): React.ComponentType<LucideProps>;
|
|
5
|
+
//# sourceMappingURL=pluginIcon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginIcon.d.ts","sourceRoot":"","sources":["../../../../src/core/plugins/host/pluginIcon.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAA;AAQnC,4GAA4G;AAC5G,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,GAC9C,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,CAKlC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as LR from "lucide-react";
|
|
2
|
+
const FALLBACK_ICON = LR.Puzzle;
|
|
3
|
+
function resolvePluginIcon(icon) {
|
|
4
|
+
if (typeof icon !== "string") return icon;
|
|
5
|
+
const candidate = LR[icon];
|
|
6
|
+
return isComponent(candidate) ? candidate : FALLBACK_ICON;
|
|
7
|
+
}
|
|
8
|
+
function isComponent(value) {
|
|
9
|
+
if (typeof value === "function") return true;
|
|
10
|
+
return typeof value === "object" && value !== null && "$$typeof" in value;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
resolvePluginIcon
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=pluginIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/plugins/host/pluginIcon.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport * as LR from 'lucide-react'\n\nimport type { LucideProps } from 'lucide-react'\nimport type * as React from 'react'\n\n// A leaf module on purpose: the Plugins page resolves an icon too, and importing a hook to\n// get this pulled the store barrel into a card that has no business with it.\n\n/** Shown when a plugin names an icon that does not exist, so the button still appears. */\nconst FALLBACK_ICON = LR.Puzzle\n\n/** A plugin may pass a lucide component, or its name as a string — JSON manifests only carry the string. */\nexport function resolvePluginIcon(\n icon: string | React.ComponentType<LucideProps>,\n): React.ComponentType<LucideProps> {\n if (typeof icon !== 'string') return icon\n\n const candidate = (LR as unknown as Record<string, unknown>)[icon]\n return isComponent(candidate) ? candidate : FALLBACK_ICON\n}\n\n// Lucide icons are `forwardRef` objects, so a bare `typeof === 'function'` check\n// rejects every real icon. Anything renderable is callable or carries `$$typeof`.\nfunction isComponent(value: unknown): value is React.ComponentType<LucideProps> {\n if (typeof value === 'function') return true\n return typeof value === 'object' && value !== null && '$$typeof' in value\n}\n"],"mappings":"AAGA,YAAY,QAAQ;AASpB,MAAM,gBAAgB,GAAG;AAGlB,SAAS,kBACd,MACkC;AAClC,MAAI,OAAO,SAAS,SAAU,QAAO;AAErC,QAAM,YAAa,GAA0C,IAAI;AACjE,SAAO,YAAY,SAAS,IAAI,YAAY;AAC9C;AAIA,SAAS,YAAY,OAA2D;AAC9E,MAAI,OAAO,UAAU,WAAY,QAAO;AACxC,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,cAAc;AACtE;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtimeShims.d.ts","sourceRoot":"","sources":["../../../../src/core/plugins/host/runtimeShims.ts"],"names":[],"mappings":"AAGA,2FAA2F;AAC3F,MAAM,WAAW,WAAW;IAC1B,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAA;IACd,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAA;IACjB,6EAA6E;IAC7E,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB;AAUD,eAAO,MAAM,oBAAoB,EAAE,SAAS,WAAW,
|
|
1
|
+
{"version":3,"file":"runtimeShims.d.ts","sourceRoot":"","sources":["../../../../src/core/plugins/host/runtimeShims.ts"],"names":[],"mappings":"AAGA,2FAA2F;AAC3F,MAAM,WAAW,WAAW;IAC1B,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAA;IACd,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAA;IACjB,6EAA6E;IAC7E,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB;AAUD,eAAO,MAAM,oBAAoB,EAAE,SAAS,WAAW,EAkGtD,CAAA;AAED,8EAA8E;AAC9E,eAAO,MAAM,gBAAgB,EAAE,SAAS,MAAM,EAE7C,CAAA"}
|
|
@@ -84,6 +84,44 @@ const PLUGIN_RUNTIME_SHIMS = [
|
|
|
84
84
|
specifier: "@collabdt/core/plugins-sdk/store",
|
|
85
85
|
exports: ["usePluginStore"]
|
|
86
86
|
},
|
|
87
|
+
{
|
|
88
|
+
file: "sdk-data.js",
|
|
89
|
+
bridge: "sdkData",
|
|
90
|
+
specifier: "@collabdt/core/plugins-sdk/data",
|
|
91
|
+
exports: [
|
|
92
|
+
"useBuildings",
|
|
93
|
+
"useBuilding",
|
|
94
|
+
"useBuildingsByOsm",
|
|
95
|
+
"useBuildingOsmIds",
|
|
96
|
+
"useSites",
|
|
97
|
+
"useSite",
|
|
98
|
+
"useInfrastructures",
|
|
99
|
+
"useInfrastructure",
|
|
100
|
+
"useOrganization",
|
|
101
|
+
"useOrganizationByName",
|
|
102
|
+
"useFiles",
|
|
103
|
+
"useFile",
|
|
104
|
+
"useFilesByBuildingId",
|
|
105
|
+
"useFilesBySiteId",
|
|
106
|
+
"useDownloadFile",
|
|
107
|
+
"useSensors",
|
|
108
|
+
"useSensor",
|
|
109
|
+
"useSensorsByBuilding",
|
|
110
|
+
"useSensorsByAuthor",
|
|
111
|
+
"useCreateSensor",
|
|
112
|
+
"useSensorTypes",
|
|
113
|
+
"useSensorType",
|
|
114
|
+
"useComments",
|
|
115
|
+
"useComment",
|
|
116
|
+
"useCommentsByBuilding",
|
|
117
|
+
"useCommentsByAuthor",
|
|
118
|
+
"useCreateComment",
|
|
119
|
+
"useDeleteComments",
|
|
120
|
+
// Re-exported by the module, so a plugin reaching for data finds both here too.
|
|
121
|
+
"usePluginConfig",
|
|
122
|
+
"usePluginPermissions"
|
|
123
|
+
]
|
|
124
|
+
},
|
|
87
125
|
{
|
|
88
126
|
file: "sdk-state.js",
|
|
89
127
|
bridge: "sdkState",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/plugins/host/runtimeShims.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/plugins/host/runtimeShims.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\n/** One bare specifier a runtime-loaded plugin may import, and the shim the host serves. */\nexport interface RuntimeShim {\n /** Filename served under `/plugin-runtime/`. */\n file: string\n /** Key on `globalThis.__CDT_RUNTIME__` that the host bridge populates. */\n bridge: string\n /** The bare specifier the plugin writes. */\n specifier: string\n /** Re-exported by name, because an import map cannot rewrite a namespace. */\n exports: string[]\n}\n\n// Part of the host contract, so it lives beside `PLUGIN_HOST_API` rather than in the\n// app. Three consumers derive from it — the app's shim generator, the published import\n// map, and `@collabdt/plugin-kit`'s build preset — and when they disagree a plugin\n// either bundles a second copy of a singleton or dies on an unmapped specifier.\n//\n// Absent on purpose: `@thatopen/components`, `three`, `maplibre-gl`, `lucide-react`. A\n// plugin gets viewer instances as props and names icons by string, so it never imports\n// those at runtime — which is what stops a second copy of three.js loading.\nexport const PLUGIN_RUNTIME_SHIMS: readonly RuntimeShim[] = [\n {\n file: 'react.js',\n bridge: 'react',\n specifier: 'react',\n exports: [\n 'Children', 'Component', 'Fragment', 'Profiler', 'PureComponent',\n 'StrictMode', 'Suspense', 'cloneElement', 'createContext',\n 'createElement', 'createRef', 'forwardRef', 'isValidElement', 'lazy',\n 'memo', 'startTransition', 'useCallback', 'useContext', 'useDebugValue',\n 'useDeferredValue', 'useEffect', 'useId', 'useImperativeHandle',\n 'useInsertionEffect', 'useLayoutEffect', 'useMemo', 'useReducer',\n 'useRef', 'useState', 'useSyncExternalStore', 'useTransition', 'version',\n ],\n },\n {\n file: 'react-dom.js',\n bridge: 'reactDom',\n specifier: 'react-dom',\n exports: ['createPortal', 'flushSync', 'version'],\n },\n {\n file: 'jsx-runtime.js',\n bridge: 'jsxRuntime',\n specifier: 'react/jsx-runtime',\n exports: ['Fragment', 'jsx', 'jsxs'],\n },\n {\n file: 'sdk.js',\n bridge: 'sdk',\n specifier: '@collabdt/core/plugins-sdk',\n exports: [\n 'VALID_CAPABILITIES', 'validateManifest', 'PLUGIN_HOST_API', 'resolvePluginEntry',\n // A value, not just a type: a `viewer.tabs` contribution names the viewers it belongs in.\n 'ViewerNames',\n // So a plugin colouring something on the map uses the platform's palette.\n 'MAP_COLOUR_PALETTE', 'stringToColour',\n ],\n },\n {\n file: 'sdk-config.js',\n bridge: 'sdkConfig',\n specifier: '@collabdt/core/plugins-sdk/config',\n exports: ['usePluginConfig', 'usePluginId'],\n },\n {\n file: 'sdk-messages.js',\n bridge: 'sdkMessages',\n specifier: '@collabdt/core/plugins-sdk/messages',\n exports: ['usePluginMessage', 'usePluginTranslations', 'useCoreTranslations'],\n },\n {\n file: 'sdk-store.js',\n bridge: 'sdkStore',\n specifier: '@collabdt/core/plugins-sdk/store',\n exports: ['usePluginStore'],\n },\n {\n file: 'sdk-data.js',\n bridge: 'sdkData',\n specifier: '@collabdt/core/plugins-sdk/data',\n exports: [\n 'useBuildings', 'useBuilding', 'useBuildingsByOsm', 'useBuildingOsmIds',\n 'useSites', 'useSite',\n 'useInfrastructures', 'useInfrastructure',\n 'useOrganization', 'useOrganizationByName',\n 'useFiles', 'useFile', 'useFilesByBuildingId', 'useFilesBySiteId', 'useDownloadFile',\n 'useSensors', 'useSensor', 'useSensorsByBuilding', 'useSensorsByAuthor', 'useCreateSensor',\n 'useSensorTypes', 'useSensorType',\n 'useComments', 'useComment', 'useCommentsByBuilding', 'useCommentsByAuthor',\n 'useCreateComment', 'useDeleteComments',\n // Re-exported by the module, so a plugin reaching for data finds both here too.\n 'usePluginConfig', 'usePluginPermissions',\n ],\n },\n {\n file: 'sdk-state.js',\n bridge: 'sdkState',\n specifier: '@collabdt/core/plugins-sdk/state',\n exports: ['usePluginState'],\n },\n {\n file: 'sdk-ui.js',\n bridge: 'sdkUi',\n specifier: '@collabdt/core/plugins-sdk/ui',\n exports: ['usePluginDialogs'],\n },\n {\n file: 'sdk-components.js',\n bridge: 'sdkComponents',\n specifier: '@collabdt/core/plugins-sdk/components',\n exports: [\n 'Badge', 'Button', 'Input', 'Separator',\n 'Card', 'CardContent', 'CardDescription', 'CardFooter', 'CardHeader', 'CardTitle',\n 'Dialog', 'DialogClose', 'DialogContent', 'DialogDescription',\n 'DialogFooter', 'DialogHeader', 'DialogTitle', 'DialogTrigger',\n ],\n },\n]\n\n/** Just the specifiers, which is what a bundler's `external` option wants. */\nexport const PLUGIN_EXTERNALS: readonly string[] = PLUGIN_RUNTIME_SHIMS.map(\n shim => shim.specifier,\n)\n"],"mappings":"AAuBO,MAAM,uBAA+C;AAAA,EAC1D;AAAA,IACE,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,SAAS;AAAA,MACP;AAAA,MAAY;AAAA,MAAa;AAAA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IACX,SAAS;AAAA,MACP;AAAA,MAAgB;AAAA,MAAe;AAAA,MAAqB;AAAA,MACpD;AAAA,MAAY;AAAA,MACZ;AAAA,MAAsB;AAAA,MACtB;AAAA,MAAmB;AAAA,MACnB;AAAA,MAAY;AAAA,MAAW;AAAA,MAAwB;AAAA,MAAoB;AAAA,MACnE;AAAA,MAAc;AAAA,MAAa;AAAA,MAAwB;AAAA,MAAsB;AAAA,MACzE;AAAA,MAAkB;AAAA,MAClB;AAAA,MAAe;AAAA,MAAc;AAAA,MAAyB;AAAA,MACtD;AAAA,MAAoB;AAAA;AAAA,MAEpB;AAAA,MAAmB;AAAA,IACrB;AAAA,EACF;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,SAAS,CAAC,gBAAgB;AAAA,EAC5B;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,SAAS,CAAC,kBAAkB;AAAA,EAC9B;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,SAAS;AAAA,MACP;AAAA,MAAS;AAAA,MAAU;AAAA,MAAS;AAAA,MAC5B;AAAA,MAAQ;AAAA,MAAe;AAAA,MAAmB;AAAA,MAAc;AAAA,MAAc;AAAA,MACtE;AAAA,MAAU;AAAA,MAAe;AAAA,MAAiB;AAAA,MAC1C;AAAA,MAAgB;AAAA,MAAgB;AAAA,MAAe;AAAA,IACjD;AAAA,EACF;AACF;AAGO,MAAM,mBAAsC,qBAAqB;AAAA,EACtE,UAAQ,KAAK;AACf;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { usePluginMessageLookup } from "../sdk/messages";
|
|
4
|
+
import { resolvePluginIcon } from "./pluginIcon";
|
|
4
5
|
import { pluginViewerKey } from "./pluginViewerKey";
|
|
5
6
|
import { usePluginContributions } from "./provider";
|
|
6
|
-
import { resolvePluginIcon } from "./usePluginToolbarTools";
|
|
7
7
|
function usePluginDataPages() {
|
|
8
8
|
const registrations = usePluginContributions("data.pages");
|
|
9
9
|
const message = usePluginMessageLookup();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/plugins/host/usePluginDataPages.ts"],"sourcesContent":["'use client'\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport * as React from 'react'\r\n\r\nimport { usePluginMessageLookup } from '../sdk/messages'\r\n\r\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/plugins/host/usePluginDataPages.ts"],"sourcesContent":["'use client'\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport * as React from 'react'\r\n\r\nimport { usePluginMessageLookup } from '../sdk/messages'\r\n\r\nimport { resolvePluginIcon } from './pluginIcon'\r\nimport { pluginViewerKey } from './pluginViewerKey'\r\nimport { usePluginContributions } from './provider'\r\n\r\nimport type { ViewerKey } from '../../types/dbTypes'\r\nimport type { LucideProps } from 'lucide-react'\r\n\r\nexport interface PluginNavItem {\r\n /** The `viewer` key this item switches to. */\r\n id: ViewerKey\r\n title: string\r\n icon: React.ComponentType<LucideProps>\r\n}\r\n\r\n/**\r\n * The `data.pages` contributions as nav items. They sit in Datasets beside Buildings, so a\r\n * contributed page reads as part of the platform.\r\n */\r\nexport function usePluginDataPages(): PluginNavItem[] {\r\n const registrations = usePluginContributions('data.pages')\r\n const message = usePluginMessageLookup()\r\n\r\n return React.useMemo(\r\n () => registrations.map(registration => ({\r\n id: pluginViewerKey(registration.pluginId, registration.id),\r\n title: message(registration.pluginId, registration.titleKey, registration.titleKey),\r\n icon: resolvePluginIcon(registration.icon),\r\n })),\r\n [registrations, message],\r\n )\r\n}\r\n"],"mappings":";AAKA,YAAY,WAAW;AAEvB,SAAS,8BAA8B;AAEvC,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAS,8BAA8B;AAgBhC,SAAS,qBAAsC;AACpD,QAAM,gBAAgB,uBAAuB,YAAY;AACzD,QAAM,UAAU,uBAAuB;AAEvC,SAAO,MAAM;AAAA,IACX,MAAM,cAAc,IAAI,mBAAiB;AAAA,MACvC,IAAI,gBAAgB,aAAa,UAAU,aAAa,EAAE;AAAA,MAC1D,OAAO,QAAQ,aAAa,UAAU,aAAa,UAAU,aAAa,QAAQ;AAAA,MAClF,MAAM,kBAAkB,aAAa,IAAI;AAAA,IAC3C,EAAE;AAAA,IACF,CAAC,eAAe,OAAO;AAAA,EACzB;AACF;","names":[]}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
import type { Tool } from '../../types/tools';
|
|
3
|
-
import type { ToolbarRegistration } from '../sdk/types';
|
|
4
|
-
import type { LucideProps } from 'lucide-react';
|
|
5
2
|
/** The three toolbar capabilities. All share `ToolbarRegistration`. */
|
|
6
3
|
export type ToolbarCapability = 'map.tools' | 'bim.tools' | 'pointcloud.tools';
|
|
7
|
-
/** A plugin may pass a lucide component, or its name as a string — JSON manifests only carry the string. */
|
|
8
|
-
export declare function resolvePluginIcon(icon: ToolbarRegistration['icon']): React.ComponentType<LucideProps>;
|
|
9
4
|
/**
|
|
10
5
|
* Plugin contributions for one toolbar, as `Tool` objects the toolbars already
|
|
11
6
|
* render: `[...coreTools, ...usePluginToolbarTools('bim.tools', viewerProps)]`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePluginToolbarTools.d.ts","sourceRoot":"","sources":["../../../../src/core/plugins/host/usePluginToolbarTools.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePluginToolbarTools.d.ts","sourceRoot":"","sources":["../../../../src/core/plugins/host/usePluginToolbarTools.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAK7C,uEAAuE;AACvE,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,WAAW,GAAG,kBAAkB,CAAA;AAK9E;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,iBAAiB,EAC7B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACnC,IAAI,EAAE,CAyCR"}
|
|
@@ -28,21 +28,11 @@ var __objRest = (source, exclude) => {
|
|
|
28
28
|
return target;
|
|
29
29
|
};
|
|
30
30
|
import { jsx } from "react/jsx-runtime";
|
|
31
|
-
import * as LR from "lucide-react";
|
|
32
31
|
import * as React from "react";
|
|
33
32
|
import { ToolbarSubmenu } from "../../components/ToolbarSubmenu";
|
|
33
|
+
import { resolvePluginIcon } from "./pluginIcon";
|
|
34
34
|
import { usePluginConfigs, usePluginContributions } from "./provider";
|
|
35
35
|
import { PluginScopeProvider } from "./scope";
|
|
36
|
-
const FALLBACK_ICON = LR.Puzzle;
|
|
37
|
-
function resolvePluginIcon(icon) {
|
|
38
|
-
if (typeof icon !== "string") return icon;
|
|
39
|
-
const candidate = LR[icon];
|
|
40
|
-
return isComponent(candidate) ? candidate : FALLBACK_ICON;
|
|
41
|
-
}
|
|
42
|
-
function isComponent(value) {
|
|
43
|
-
if (typeof value === "function") return true;
|
|
44
|
-
return typeof value === "object" && value !== null && "$$typeof" in value;
|
|
45
|
-
}
|
|
46
36
|
function usePluginToolbarTools(capability, extraProps) {
|
|
47
37
|
const contributions = usePluginContributions(capability);
|
|
48
38
|
const configs = usePluginConfigs();
|
|
@@ -87,7 +77,6 @@ function wrapPluginComponent(contribution, readConfig) {
|
|
|
87
77
|
return PluginToolboxItem;
|
|
88
78
|
}
|
|
89
79
|
export {
|
|
90
|
-
resolvePluginIcon,
|
|
91
80
|
usePluginToolbarTools
|
|
92
81
|
};
|
|
93
82
|
//# sourceMappingURL=usePluginToolbarTools.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/plugins/host/usePluginToolbarTools.tsx"],"sourcesContent":["'use client'\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport * as LR from 'lucide-react'\r\nimport * as React from 'react'\r\n\r\nimport { ToolbarSubmenu } from '../../components/ToolbarSubmenu'\r\n\r\nimport { usePluginConfigs, usePluginContributions, type PluginContribution } from './provider'\r\nimport { PluginScopeProvider } from './scope'\r\n\r\nimport type { CursorType } from '../../types/global'\r\nimport type { Tool } from '../../types/tools'\r\nimport type { ToolbarRegistration } from '../sdk/types'\r\nimport type { LucideProps } from 'lucide-react'\r\n\r\n/** The three toolbar capabilities. All share `ToolbarRegistration`. */\r\nexport type ToolbarCapability = 'map.tools' | 'bim.tools' | 'pointcloud.tools'\r\n\r\n/** What `ToolbarButton` renders for a tool that supplies its own component. */\r\ntype ToolComponent = NonNullable<Tool['component']>\r\n\r\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/plugins/host/usePluginToolbarTools.tsx"],"sourcesContent":["'use client'\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport * as LR from 'lucide-react'\r\nimport * as React from 'react'\r\n\r\nimport { ToolbarSubmenu } from '../../components/ToolbarSubmenu'\r\n\r\nimport { resolvePluginIcon } from './pluginIcon'\r\nimport { usePluginConfigs, usePluginContributions, type PluginContribution } from './provider'\r\nimport { PluginScopeProvider } from './scope'\r\n\r\nimport type { CursorType } from '../../types/global'\r\nimport type { Tool } from '../../types/tools'\r\nimport type { ToolbarRegistration } from '../sdk/types'\r\n\r\nimport type { LucideProps } from 'lucide-react'\r\n\r\n/** The three toolbar capabilities. All share `ToolbarRegistration`. */\r\nexport type ToolbarCapability = 'map.tools' | 'bim.tools' | 'pointcloud.tools'\r\n\r\n/** What `ToolbarButton` renders for a tool that supplies its own component. */\r\ntype ToolComponent = NonNullable<Tool['component']>\r\n\r\n/**\r\n * Plugin contributions for one toolbar, as `Tool` objects the toolbars already\r\n * render: `[...coreTools, ...usePluginToolbarTools('bim.tools', viewerProps)]`.\r\n *\r\n * `extraProps` is spread onto the plugin's component by `ToolbarButton` — how a BIM\r\n * tool gets its viewer handles. Each viewer passes its own, keeping this module free\r\n * of viewer-engine imports that would pull three into the map bundle.\r\n */\r\nexport function usePluginToolbarTools(\r\n capability: ToolbarCapability,\r\n extraProps?: Record<string, unknown>,\r\n): Tool[] {\r\n const contributions = usePluginContributions(capability)\r\n const configs = usePluginConfigs()\r\n\r\n // Cached by tool id to keep component identity stable. `extraProps` changes on\r\n // most renders (it carries live viewer handles), and rebuilding on each would\r\n // remount the plugin's panel and lose its state on every camera move.\r\n const wrapped = React.useRef(new Map<string, ToolComponent>())\r\n\r\n return React.useMemo(() => {\r\n const live = new Set<string>()\r\n\r\n const tools = contributions.map(contribution => {\r\n const id = pluginToolId(contribution)\r\n live.add(id)\r\n\r\n let Component = wrapped.current.get(id)\r\n if (!Component) {\r\n Component = wrapPluginComponent(contribution, () => configs[contribution.pluginId])\r\n wrapped.current.set(id, Component)\r\n }\r\n\r\n return {\r\n id,\r\n title: contribution.label,\r\n icon: resolvePluginIcon(contribution.icon),\r\n // An invented cursor is a CSS no-op, not a crash, so it goes unvalidated.\r\n cursor: contribution.cursor as CursorType | undefined,\r\n stayActive: contribution.stayActive,\r\n component: Component,\r\n extraProps,\r\n } satisfies Tool\r\n })\r\n\r\n // Drop cache entries for plugins that have since been disabled.\r\n for (const id of wrapped.current.keys()) {\r\n if (!live.has(id)) wrapped.current.delete(id)\r\n }\r\n\r\n return tools\r\n }, [contributions, extraProps])\r\n}\r\n\r\nfunction pluginToolId(contribution: PluginContribution<ToolbarCapability>) {\r\n return `plugin:${contribution.pluginId}:${contribution.id}` as const\r\n}\r\n\r\n/**\r\n * Wrap a plugin's component into a real toolbar entry.\r\n *\r\n * `ToolbarButton` renders `tool.component` *instead of* a button, so a plugin\r\n * returning a panel would render it inline and blow the strip out of the viewport.\r\n * `ToolbarSubmenu` gives it the same ghost button and dropdown every core tool has,\r\n * built from the `label` and `icon` it already declared. The wrapper also supplies\r\n * the plugin scope the scoped SDK hooks read.\r\n */\r\nfunction wrapPluginComponent(\r\n contribution: PluginContribution<ToolbarCapability>,\r\n // Lazily, because the component identity is cached: capturing the config by value\r\n // would freeze it at whatever it was on first render.\r\n readConfig: () => Record<string, unknown> | undefined,\r\n): ToolComponent {\r\n // Props are typed per capability at `ctx.register`. This wrapper forwards whatever\r\n // the hosting toolbar passed, so the shape is erased here on purpose.\r\n const Component = contribution.component as unknown as React.ComponentType<Record<string, unknown>>\r\n\r\n function PluginToolboxItem({ tool, ...rest }: React.ComponentProps<ToolComponent>) {\r\n return (\r\n <ToolbarSubmenu tool={tool}>\r\n <PluginScopeProvider pluginId={contribution.pluginId} config={readConfig()}>\r\n <Component tool={tool} {...rest} />\r\n </PluginScopeProvider>\r\n </ToolbarSubmenu>\r\n )\r\n }\r\n\r\n PluginToolboxItem.displayName = `PluginTool(${contribution.pluginId}/${contribution.id})`\r\n return PluginToolboxItem\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2GU;AArGV,YAAY,WAAW;AAEvB,SAAS,sBAAsB;AAE/B,SAAS,yBAAyB;AAClC,SAAS,kBAAkB,8BAAuD;AAClF,SAAS,2BAA2B;AAsB7B,SAAS,sBACd,YACA,YACQ;AACR,QAAM,gBAAgB,uBAAuB,UAAU;AACvD,QAAM,UAAU,iBAAiB;AAKjC,QAAM,UAAU,MAAM,OAAO,oBAAI,IAA2B,CAAC;AAE7D,SAAO,MAAM,QAAQ,MAAM;AACzB,UAAM,OAAO,oBAAI,IAAY;AAE7B,UAAM,QAAQ,cAAc,IAAI,kBAAgB;AAC9C,YAAM,KAAK,aAAa,YAAY;AACpC,WAAK,IAAI,EAAE;AAEX,UAAI,YAAY,QAAQ,QAAQ,IAAI,EAAE;AACtC,UAAI,CAAC,WAAW;AACd,oBAAY,oBAAoB,cAAc,MAAM,QAAQ,aAAa,QAAQ,CAAC;AAClF,gBAAQ,QAAQ,IAAI,IAAI,SAAS;AAAA,MACnC;AAEA,aAAO;AAAA,QACL;AAAA,QACA,OAAO,aAAa;AAAA,QACpB,MAAM,kBAAkB,aAAa,IAAI;AAAA;AAAA,QAEzC,QAAQ,aAAa;AAAA,QACrB,YAAY,aAAa;AAAA,QACzB,WAAW;AAAA,QACX;AAAA,MACF;AAAA,IACF,CAAC;AAGD,eAAW,MAAM,QAAQ,QAAQ,KAAK,GAAG;AACvC,UAAI,CAAC,KAAK,IAAI,EAAE,EAAG,SAAQ,QAAQ,OAAO,EAAE;AAAA,IAC9C;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,eAAe,UAAU,CAAC;AAChC;AAEA,SAAS,aAAa,cAAqD;AACzE,SAAO,UAAU,aAAa,QAAQ,IAAI,aAAa,EAAE;AAC3D;AAWA,SAAS,oBACP,cAGA,YACe;AAGf,QAAM,YAAY,aAAa;AAE/B,WAAS,kBAAkB,IAAwD;AAAxD,iBAAE,OAvG/B,IAuG6B,IAAW,iBAAX,IAAW,CAAT;AAC3B,WACE,oBAAC,kBAAe,MACd,8BAAC,uBAAoB,UAAU,aAAa,UAAU,QAAQ,WAAW,GACvE,8BAAC,4BAAU,QAAgB,KAAM,GACnC,GACF;AAAA,EAEJ;AAEA,oBAAkB,cAAc,cAAc,aAAa,QAAQ,IAAI,aAAa,EAAE;AACtF,SAAO;AACT;","names":[]}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { usePluginMessageLookup } from "../sdk/messages";
|
|
5
|
+
import { resolvePluginIcon } from "./pluginIcon";
|
|
5
6
|
import { usePluginConfigs, usePluginContributions } from "./provider";
|
|
6
7
|
import { PluginScopeProvider } from "./scope";
|
|
7
|
-
import { resolvePluginIcon } from "./usePluginToolbarTools";
|
|
8
8
|
function pluginTabId(pluginId, tabId) {
|
|
9
9
|
return `plugin:${pluginId}:${tabId}`;
|
|
10
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/plugins/host/usePluginViewerTabs.tsx"],"sourcesContent":["'use client'\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport * as React from 'react'\r\n\r\nimport { usePluginMessageLookup } from '../sdk/messages'\r\n\r\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/plugins/host/usePluginViewerTabs.tsx"],"sourcesContent":["'use client'\r\n\r\n// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\nimport * as React from 'react'\r\n\r\nimport { usePluginMessageLookup } from '../sdk/messages'\r\n\r\nimport { resolvePluginIcon } from './pluginIcon'\r\nimport { usePluginConfigs, usePluginContributions } from './provider'\r\nimport { PluginScopeProvider } from './scope'\r\n\r\nimport type { ViewerSidebarTab } from '../../components/ui/ViewerSidebar/sidebarTabs'\r\nimport type { SidebarTabKey } from '../../store/Menus/reducer'\r\nimport type { ViewerNames } from '../../types/dbTypes'\r\n\r\n/** Namespaced so a plugin tab can never collide with a built-in one, or with another plugin's. */\r\nexport function pluginTabId(pluginId: string, tabId: string): SidebarTabKey {\r\n return `plugin:${pluginId}:${tabId}`\r\n}\r\n\r\n/**\r\n * The `viewer.tabs` contributions for this viewer; no `viewers` means every viewer. The panel\r\n * is wrapped in the plugin scope, which is what lets the component inside reach the SDK hooks.\r\n */\r\nexport function usePluginViewerTabs(viewer: ViewerNames): ViewerSidebarTab[] {\r\n const registrations = usePluginContributions('viewer.tabs')\r\n const configs = usePluginConfigs()\r\n const message = usePluginMessageLookup()\r\n\r\n return React.useMemo(\r\n () => registrations\r\n .filter(registration => !registration.viewers || registration.viewers.includes(viewer))\r\n .map((registration) => {\r\n const Panel = registration.component\r\n\r\n return {\r\n id: pluginTabId(registration.pluginId, registration.id),\r\n meta: {\r\n icon: resolvePluginIcon(registration.icon),\r\n label: message(registration.pluginId, registration.labelKey, registration.labelKey),\r\n },\r\n content: (\r\n <PluginScopeProvider\r\n pluginId={registration.pluginId}\r\n config={configs[registration.pluginId]}\r\n >\r\n <Panel />\r\n </PluginScopeProvider>\r\n ),\r\n }\r\n }),\r\n [registrations, viewer, configs, message],\r\n )\r\n}\r\n"],"mappings":";AAgDc;AA3Cd,YAAY,WAAW;AAEvB,SAAS,8BAA8B;AAEvC,SAAS,yBAAyB;AAClC,SAAS,kBAAkB,8BAA8B;AACzD,SAAS,2BAA2B;AAO7B,SAAS,YAAY,UAAkB,OAA8B;AAC1E,SAAO,UAAU,QAAQ,IAAI,KAAK;AACpC;AAMO,SAAS,oBAAoB,QAAyC;AAC3E,QAAM,gBAAgB,uBAAuB,aAAa;AAC1D,QAAM,UAAU,iBAAiB;AACjC,QAAM,UAAU,uBAAuB;AAEvC,SAAO,MAAM;AAAA,IACX,MAAM,cACH,OAAO,kBAAgB,CAAC,aAAa,WAAW,aAAa,QAAQ,SAAS,MAAM,CAAC,EACrF,IAAI,CAAC,iBAAiB;AACrB,YAAM,QAAQ,aAAa;AAE3B,aAAO;AAAA,QACL,IAAI,YAAY,aAAa,UAAU,aAAa,EAAE;AAAA,QACtD,MAAM;AAAA,UACJ,MAAM,kBAAkB,aAAa,IAAI;AAAA,UACzC,OAAO,QAAQ,aAAa,UAAU,aAAa,UAAU,aAAa,QAAQ;AAAA,QACpF;AAAA,QACA,SACE;AAAA,UAAC;AAAA;AAAA,YACC,UAAU,aAAa;AAAA,YACvB,QAAQ,QAAQ,aAAa,QAAQ;AAAA,YAErC,8BAAC,SAAM;AAAA;AAAA,QACT;AAAA,MAEJ;AAAA,IACF,CAAC;AAAA,IACH,CAAC,eAAe,QAAQ,SAAS,OAAO;AAAA,EAC1C;AACF;","names":[]}
|
|
@@ -14,6 +14,8 @@ export interface PluginManifest {
|
|
|
14
14
|
hostApi?: number;
|
|
15
15
|
description?: string;
|
|
16
16
|
author?: string;
|
|
17
|
+
/** A lucide icon name shown beside the plugin's name. Unset or unknown shows a puzzle piece. */
|
|
18
|
+
icon?: string;
|
|
17
19
|
capabilities: PluginCapability[];
|
|
18
20
|
requiredPermissions?: string[];
|
|
19
21
|
configSchema?: Record<string, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/core/plugins/sdk/types.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAEjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAM/C,eAAO,MAAM,kBAAkB,oIASrB,CAAA;AAEV,MAAM,MAAM,gBAAgB,GAAG,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAA;AAIhE,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,kGAAkG;IAClG,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,gBAAgB,EAAE,CAAA;IAChC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACtC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE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B;AAED,sFAAsF;AACtF,MAAM,MAAM,YAAY,GAAG,YAAY,EAAE,GAAG,CAAC,MAAM,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/plugins/sdk/types.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\n// Type-only: keeps the viewer modules' runtime deps (@thatopen, three, maplibre)\r\n// out of the host's module graph.\r\nimport type { BimToolProps } from './bimViewer'\r\nimport type { MapToolProps } from './mapViewer'\r\nimport type { PointCloudToolProps } from './pointCloudViewer'\r\n// A value, not just a type: a `viewer.tabs` contribution names the viewers it belongs in.\r\nexport { ViewerNames } from '../../types/dbTypes'\r\n\r\nimport type { ViewerNames } from '../../types/dbTypes'\r\nimport type { LucideProps } from 'lucide-react'\r\n\r\n// --- Capability definitions ---\r\n\r\n// Only capabilities core actually renders. One with no consumer registers fine,\r\n// shows nothing, and leaves nothing to debug.\r\nexport const VALID_CAPABILITIES = [\r\n 'data.pages',\r\n 'viewer.tabs',\r\n 'ui.dialogs',\r\n 'map.tools',\r\n 'bim.tools',\r\n 'pointcloud.tools',\r\n 'viewer.legends',\r\n 'map.layers',\r\n] as const\r\n\r\nexport type PluginCapability = typeof VALID_CAPABILITIES[number]\r\n\r\n// --- Manifest ---\r\n\r\nexport interface PluginManifest {\r\n slug: string\r\n name: string\r\n version: string\r\n /** The `PLUGIN_HOST_API` this plugin was built against. Omitted is warned about, not rejected. */\r\n hostApi?: number\r\n description?: string\r\n author?: string\r\n capabilities: PluginCapability[]\r\n requiredPermissions?: string[]\r\n configSchema?: Record<string, unknown>\r\n /**\r\n * Strings keyed by locale then message key, e.g. `{ en: { title: 'Hello' } }`.\r\n * Core folds them under `plugins.<slug>`, so `t('title')` resolves and no plugin\r\n * can collide with another. Values may nest, addressed as `t('spaces.title')`.\r\n */\r\n messages?: Record<string, Record<string, unknown>>\r\n}\r\n\r\nexport function validateManifest(manifest: unknown): { valid: boolean; errors: string[] } {\r\n const errors: string[] = []\r\n\r\n if (typeof manifest !== 'object' || manifest === null) {\r\n return { valid: false, errors: ['manifest must be an object'] }\r\n }\r\n\r\n const m = manifest as Record<string, unknown>\r\n\r\n if (!m.slug || typeof m.slug !== 'string') errors.push('slug is required')\r\n if (!m.name || typeof m.name !== 'string') errors.push('name is required')\r\n if (!m.version || typeof m.version !== 'string') errors.push('version is required')\r\n\r\n if (m.hostApi !== undefined && !Number.isInteger(m.hostApi)) {\r\n errors.push('hostApi must be an integer when present')\r\n }\r\n\r\n if (!Array.isArray(m.capabilities) || m.capabilities.length === 0) {\r\n errors.push('at least one capability is required')\r\n } else {\r\n for (const cap of m.capabilities) {\r\n if (!VALID_CAPABILITIES.includes(cap as PluginCapability)) {\r\n errors.push(`invalid capability: \"${cap}\"`)\r\n }\r\n }\r\n }\r\n\r\n return { valid: errors.length === 0, errors }\r\n}\r\n\r\n// --- Registration shapes (one per capability) ---\r\n\r\nexport interface DataPageColumn<Row> {\r\n key: string\r\n /** Resolved in the plugin's own namespace, falling back to the literal string. */\r\n labelKey: string\r\n render?: (row: Row) => React.ReactNode\r\n}\r\n\r\n/**\r\n * A full page in the Datasets nav, rendered by core. The plugin declares rows and columns; a\r\n * row click opens one of its own `ui.dialogs` rather than a detail view of its own.\r\n */\r\nexport interface DataPageRows<Row> {\r\n rows: Row[]\r\n isLoading?: boolean\r\n /** From the hook, not the registration, so it can close over `usePluginDialogs`. */\r\n onRowClick?: (row: Row) => void\r\n}\r\n\r\nexport interface DataPageRegistration<Row = Record<string, unknown>> {\r\n id: string\r\n titleKey: string\r\n icon: string | React.ComponentType<LucideProps>\r\n useRows: () => DataPageRows<Row>\r\n columns: DataPageColumn<Row>[]\r\n /** Column keys the search box filters on. Omit to search every column. */\r\n searchKeys?: string[]\r\n emptyKey?: string\r\n}\r\n\r\n/** Every toolbar component receives the toolbar entry core built for it. */\r\nexport interface ToolbarToolProps {\r\n tool: unknown\r\n}\r\n\r\n/**\r\n * A toolbar contribution. `P` is the viewer surface the hosting toolbar passes as\r\n * props, bound per capability by `CapabilityRegistry` — so a BIM component\r\n * registered under `map.tools` is a compile error.\r\n */\r\nexport interface ToolbarRegistration<P = Record<string, unknown>> {\r\n id: string\r\n label: string\r\n icon: string | React.ComponentType<LucideProps>\r\n component: React.ComponentType<ToolbarToolProps & P>\r\n cursor?: string\r\n stayActive?: boolean\r\n}\r\n\r\nexport interface ViewerTabRegistration {\r\n id: string\r\n labelKey: string\r\n icon: string | React.ComponentType<LucideProps>\r\n component: React.ComponentType\r\n /** Which viewers this tab appears in. Omit for all of them. */\r\n viewers?: ViewerNames[]\r\n}\r\n\r\n/**\r\n * A modal core owns. Registered here, opened by id from any of the plugin's surfaces via\r\n * `usePluginDialogs()`, so it outlives whichever one opened it.\r\n */\r\nexport interface DialogRegistration<P = Record<string, unknown>> {\r\n id: string\r\n titleKey: string\r\n size?: 'sm' | 'md' | 'lg' | 'xl'\r\n component: React.ComponentType<P & { close: () => void }>\r\n}\r\n\r\n/**\r\n * Something drawn on the map, mounted for as long as the map. Separate from `map.tools`,\r\n * whose panel unmounts when its dropdown closes and would take the layer with it.\r\n */\r\nexport interface MapLayerRegistration {\r\n id: string\r\n component: React.ComponentType<MapToolProps>\r\n}\r\n\r\nexport interface LegendRow {\r\n label: string\r\n color: string\r\n count?: number\r\n}\r\n\r\nexport interface LegendRegistration {\r\n id: string\r\n title: string\r\n /** Which viewers this legend appears in. Omit for all of them. */\r\n viewers?: ViewerNames[]\r\n // Called by <MapLegendHost> on each render; active:false omits the section.\r\n useLegend: () => {\r\n active: boolean\r\n // Overrides registration.title when set, e.g. a city-scoped label.\r\n title?: string\r\n unavailable?: boolean\r\n rows: LegendRow[]\r\n }\r\n}\r\n\r\n// --- Capability → registration type map ---\r\n// A new contribution point needs one entry here, its type above, and a consumer\r\n// calling `registry.getAll('your.key')`. No host changes.\r\n\r\nexport interface CapabilityRegistry {\r\n 'data.pages': DataPageRegistration\r\n 'viewer.tabs': ViewerTabRegistration\r\n 'ui.dialogs': DialogRegistration\r\n 'map.tools': ToolbarRegistration<MapToolProps>\r\n 'bim.tools': ToolbarRegistration<BimToolProps>\r\n 'pointcloud.tools': ToolbarRegistration<PointCloudToolProps>\r\n 'viewer.legends': LegendRegistration\r\n 'map.layers': MapLayerRegistration\r\n}\r\n\r\n// Errors if VALID_CAPABILITIES and keyof CapabilityRegistry drift apart.\r\ntype _CapabilityParity =\r\n PluginCapability extends keyof CapabilityRegistry\r\n ? keyof CapabilityRegistry extends PluginCapability\r\n ? true\r\n : never\r\n : never\r\nconst _capabilityParity: _CapabilityParity = true\r\nvoid _capabilityParity\r\n\r\n// --- Plugin Context ---\r\n\r\nexport interface PluginContext {\r\n pluginId: string\r\n register<K extends keyof CapabilityRegistry>(key: K, item: CapabilityRegistry[K]): void\r\n config: Record<string, unknown>\r\n}\r\n\r\n// --- Plugin entry point type ---\r\n\r\nexport interface PluginEntry {\r\n activate(ctx: PluginContext): void | Promise<void>\r\n deactivate?(ctx: PluginContext): void | Promise<void>\r\n}\r\n\r\n/**\r\n * One loadable plugin: its manifest plus its module, or a thunk returning it.\r\n * Prefer the thunk when compiled in — a static import pulls the plugin's\r\n * components into every route that reaches `installed.ts`.\r\n */\r\nexport interface PluginSource {\r\n manifest: PluginManifest\r\n entry: PluginEntry | (() => Promise<PluginEntry>)\r\n}\r\n\r\n/** Resolves either form of `PluginSource.entry` to the module. */\r\nexport async function resolvePluginEntry(\r\n entry: PluginSource['entry'],\r\n): Promise<PluginEntry> {\r\n return typeof entry === 'function' ? entry() : entry\r\n}\r\n\r\n/** An array for compiled-in plugins; a thunk when the list itself must be fetched. */\r\nexport type PluginsInput = PluginSource[] | (() => Promise<PluginSource[]>)\r\n"],"mappings":"AASA,SAAS,mBAAmB;AASrB,MAAM,qBAAqB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/plugins/sdk/types.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\r\n// Copyright (C) 2025 Collab Digital Twins\r\n\r\n// Type-only: keeps the viewer modules' runtime deps (@thatopen, three, maplibre)\r\n// out of the host's module graph.\r\nimport type { BimToolProps } from './bimViewer'\r\nimport type { MapToolProps } from './mapViewer'\r\nimport type { PointCloudToolProps } from './pointCloudViewer'\r\n// A value, not just a type: a `viewer.tabs` contribution names the viewers it belongs in.\r\nexport { ViewerNames } from '../../types/dbTypes'\r\n\r\nimport type { ViewerNames } from '../../types/dbTypes'\r\nimport type { LucideProps } from 'lucide-react'\r\n\r\n// --- Capability definitions ---\r\n\r\n// Only capabilities core actually renders. One with no consumer registers fine,\r\n// shows nothing, and leaves nothing to debug.\r\nexport const VALID_CAPABILITIES = [\r\n 'data.pages',\r\n 'viewer.tabs',\r\n 'ui.dialogs',\r\n 'map.tools',\r\n 'bim.tools',\r\n 'pointcloud.tools',\r\n 'viewer.legends',\r\n 'map.layers',\r\n] as const\r\n\r\nexport type PluginCapability = typeof VALID_CAPABILITIES[number]\r\n\r\n// --- Manifest ---\r\n\r\nexport interface PluginManifest {\r\n slug: string\r\n name: string\r\n version: string\r\n /** The `PLUGIN_HOST_API` this plugin was built against. Omitted is warned about, not rejected. */\r\n hostApi?: number\r\n description?: string\r\n author?: string\r\n /** A lucide icon name shown beside the plugin's name. Unset or unknown shows a puzzle piece. */\r\n icon?: string\r\n capabilities: PluginCapability[]\r\n requiredPermissions?: string[]\r\n configSchema?: Record<string, unknown>\r\n /**\r\n * Strings keyed by locale then message key, e.g. `{ en: { title: 'Hello' } }`.\r\n * Core folds them under `plugins.<slug>`, so `t('title')` resolves and no plugin\r\n * can collide with another. Values may nest, addressed as `t('spaces.title')`.\r\n */\r\n messages?: Record<string, Record<string, unknown>>\r\n}\r\n\r\nexport function validateManifest(manifest: unknown): { valid: boolean; errors: string[] } {\r\n const errors: string[] = []\r\n\r\n if (typeof manifest !== 'object' || manifest === null) {\r\n return { valid: false, errors: ['manifest must be an object'] }\r\n }\r\n\r\n const m = manifest as Record<string, unknown>\r\n\r\n if (!m.slug || typeof m.slug !== 'string') errors.push('slug is required')\r\n if (!m.name || typeof m.name !== 'string') errors.push('name is required')\r\n if (!m.version || typeof m.version !== 'string') errors.push('version is required')\r\n\r\n if (m.hostApi !== undefined && !Number.isInteger(m.hostApi)) {\r\n errors.push('hostApi must be an integer when present')\r\n }\r\n\r\n if (!Array.isArray(m.capabilities) || m.capabilities.length === 0) {\r\n errors.push('at least one capability is required')\r\n } else {\r\n for (const cap of m.capabilities) {\r\n if (!VALID_CAPABILITIES.includes(cap as PluginCapability)) {\r\n errors.push(`invalid capability: \"${cap}\"`)\r\n }\r\n }\r\n }\r\n\r\n return { valid: errors.length === 0, errors }\r\n}\r\n\r\n// --- Registration shapes (one per capability) ---\r\n\r\nexport interface DataPageColumn<Row> {\r\n key: string\r\n /** Resolved in the plugin's own namespace, falling back to the literal string. */\r\n labelKey: string\r\n render?: (row: Row) => React.ReactNode\r\n}\r\n\r\n/**\r\n * A full page in the Datasets nav, rendered by core. The plugin declares rows and columns; a\r\n * row click opens one of its own `ui.dialogs` rather than a detail view of its own.\r\n */\r\nexport interface DataPageRows<Row> {\r\n rows: Row[]\r\n isLoading?: boolean\r\n /** From the hook, not the registration, so it can close over `usePluginDialogs`. */\r\n onRowClick?: (row: Row) => void\r\n}\r\n\r\nexport interface DataPageRegistration<Row = Record<string, unknown>> {\r\n id: string\r\n titleKey: string\r\n icon: string | React.ComponentType<LucideProps>\r\n useRows: () => DataPageRows<Row>\r\n columns: DataPageColumn<Row>[]\r\n /** Column keys the search box filters on. Omit to search every column. */\r\n searchKeys?: string[]\r\n emptyKey?: string\r\n}\r\n\r\n/** Every toolbar component receives the toolbar entry core built for it. */\r\nexport interface ToolbarToolProps {\r\n tool: unknown\r\n}\r\n\r\n/**\r\n * A toolbar contribution. `P` is the viewer surface the hosting toolbar passes as\r\n * props, bound per capability by `CapabilityRegistry` — so a BIM component\r\n * registered under `map.tools` is a compile error.\r\n */\r\nexport interface ToolbarRegistration<P = Record<string, unknown>> {\r\n id: string\r\n label: string\r\n icon: string | React.ComponentType<LucideProps>\r\n component: React.ComponentType<ToolbarToolProps & P>\r\n cursor?: string\r\n stayActive?: boolean\r\n}\r\n\r\nexport interface ViewerTabRegistration {\r\n id: string\r\n labelKey: string\r\n icon: string | React.ComponentType<LucideProps>\r\n component: React.ComponentType\r\n /** Which viewers this tab appears in. Omit for all of them. */\r\n viewers?: ViewerNames[]\r\n}\r\n\r\n/**\r\n * A modal core owns. Registered here, opened by id from any of the plugin's surfaces via\r\n * `usePluginDialogs()`, so it outlives whichever one opened it.\r\n */\r\nexport interface DialogRegistration<P = Record<string, unknown>> {\r\n id: string\r\n titleKey: string\r\n size?: 'sm' | 'md' | 'lg' | 'xl'\r\n component: React.ComponentType<P & { close: () => void }>\r\n}\r\n\r\n/**\r\n * Something drawn on the map, mounted for as long as the map. Separate from `map.tools`,\r\n * whose panel unmounts when its dropdown closes and would take the layer with it.\r\n */\r\nexport interface MapLayerRegistration {\r\n id: string\r\n component: React.ComponentType<MapToolProps>\r\n}\r\n\r\nexport interface LegendRow {\r\n label: string\r\n color: string\r\n count?: number\r\n}\r\n\r\nexport interface LegendRegistration {\r\n id: string\r\n title: string\r\n /** Which viewers this legend appears in. Omit for all of them. */\r\n viewers?: ViewerNames[]\r\n // Called by <MapLegendHost> on each render; active:false omits the section.\r\n useLegend: () => {\r\n active: boolean\r\n // Overrides registration.title when set, e.g. a city-scoped label.\r\n title?: string\r\n unavailable?: boolean\r\n rows: LegendRow[]\r\n }\r\n}\r\n\r\n// --- Capability → registration type map ---\r\n// A new contribution point needs one entry here, its type above, and a consumer\r\n// calling `registry.getAll('your.key')`. No host changes.\r\n\r\nexport interface CapabilityRegistry {\r\n 'data.pages': DataPageRegistration\r\n 'viewer.tabs': ViewerTabRegistration\r\n 'ui.dialogs': DialogRegistration\r\n 'map.tools': ToolbarRegistration<MapToolProps>\r\n 'bim.tools': ToolbarRegistration<BimToolProps>\r\n 'pointcloud.tools': ToolbarRegistration<PointCloudToolProps>\r\n 'viewer.legends': LegendRegistration\r\n 'map.layers': MapLayerRegistration\r\n}\r\n\r\n// Errors if VALID_CAPABILITIES and keyof CapabilityRegistry drift apart.\r\ntype _CapabilityParity =\r\n PluginCapability extends keyof CapabilityRegistry\r\n ? keyof CapabilityRegistry extends PluginCapability\r\n ? true\r\n : never\r\n : never\r\nconst _capabilityParity: _CapabilityParity = true\r\nvoid _capabilityParity\r\n\r\n// --- Plugin Context ---\r\n\r\nexport interface PluginContext {\r\n pluginId: string\r\n register<K extends keyof CapabilityRegistry>(key: K, item: CapabilityRegistry[K]): void\r\n config: Record<string, unknown>\r\n}\r\n\r\n// --- Plugin entry point type ---\r\n\r\nexport interface PluginEntry {\r\n activate(ctx: PluginContext): void | Promise<void>\r\n deactivate?(ctx: PluginContext): void | Promise<void>\r\n}\r\n\r\n/**\r\n * One loadable plugin: its manifest plus its module, or a thunk returning it.\r\n * Prefer the thunk when compiled in — a static import pulls the plugin's\r\n * components into every route that reaches `installed.ts`.\r\n */\r\nexport interface PluginSource {\r\n manifest: PluginManifest\r\n entry: PluginEntry | (() => Promise<PluginEntry>)\r\n}\r\n\r\n/** Resolves either form of `PluginSource.entry` to the module. */\r\nexport async function resolvePluginEntry(\r\n entry: PluginSource['entry'],\r\n): Promise<PluginEntry> {\r\n return typeof entry === 'function' ? entry() : entry\r\n}\r\n\r\n/** An array for compiled-in plugins; a thunk when the list itself must be fetched. */\r\nexport type PluginsInput = PluginSource[] | (() => Promise<PluginSource[]>)\r\n"],"mappings":"AASA,SAAS,mBAAmB;AASrB,MAAM,qBAAqB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AA2BO,SAAS,iBAAiB,UAAyD;AACxF,QAAM,SAAmB,CAAC;AAE1B,MAAI,OAAO,aAAa,YAAY,aAAa,MAAM;AACrD,WAAO,EAAE,OAAO,OAAO,QAAQ,CAAC,4BAA4B,EAAE;AAAA,EAChE;AAEA,QAAM,IAAI;AAEV,MAAI,CAAC,EAAE,QAAQ,OAAO,EAAE,SAAS,SAAU,QAAO,KAAK,kBAAkB;AACzE,MAAI,CAAC,EAAE,QAAQ,OAAO,EAAE,SAAS,SAAU,QAAO,KAAK,kBAAkB;AACzE,MAAI,CAAC,EAAE,WAAW,OAAO,EAAE,YAAY,SAAU,QAAO,KAAK,qBAAqB;AAElF,MAAI,EAAE,YAAY,UAAa,CAAC,OAAO,UAAU,EAAE,OAAO,GAAG;AAC3D,WAAO,KAAK,yCAAyC;AAAA,EACvD;AAEA,MAAI,CAAC,MAAM,QAAQ,EAAE,YAAY,KAAK,EAAE,aAAa,WAAW,GAAG;AACjE,WAAO,KAAK,qCAAqC;AAAA,EACnD,OAAO;AACL,eAAW,OAAO,EAAE,cAAc;AAChC,UAAI,CAAC,mBAAmB,SAAS,GAAuB,GAAG;AACzD,eAAO,KAAK,wBAAwB,GAAG,GAAG;AAAA,MAC5C;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,OAAO,OAAO,WAAW,GAAG,OAAO;AAC9C;AA4HA,MAAM,oBAAuC;AAC7C,KAAK;AA4BL,eAAsB,mBACpB,OACsB;AACtB,SAAO,OAAO,UAAU,aAAa,MAAM,IAAI;AACjD;","names":[]}
|