@collabdt/core 0.13.2 → 0.13.3

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.
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+ import type { Dataset } from '../../types/datasetTypes';
3
+ export type PluginDatasetLookup = (pluginId: string, id: string) => Dataset | undefined;
4
+ /** How the SDK finds a plugin's own dataset without importing the host, which would close a cycle through `installed.ts`. */
5
+ export declare const PluginDatasetLookupContext: React.Context<PluginDatasetLookup>;
6
+ //# sourceMappingURL=pluginDatasetLookup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pluginDatasetLookup.d.ts","sourceRoot":"","sources":["../../../../src/core/plugins/host/pluginDatasetLookup.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAEvD,MAAM,MAAM,mBAAmB,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,GAAG,SAAS,CAAA;AAEvF,6HAA6H;AAC7H,eAAO,MAAM,0BAA0B,oCAA4D,CAAA"}
@@ -0,0 +1,9 @@
1
+ 'use client'
2
+
3
+ "use client";
4
+ import * as React from "react";
5
+ const PluginDatasetLookupContext = React.createContext(() => void 0);
6
+ export {
7
+ PluginDatasetLookupContext
8
+ };
9
+ //# sourceMappingURL=pluginDatasetLookup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/core/plugins/host/pluginDatasetLookup.ts"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport * as React from 'react'\n\nimport type { Dataset } from '../../types/datasetTypes'\n\nexport type PluginDatasetLookup = (pluginId: string, id: string) => Dataset | undefined\n\n/** How the SDK finds a plugin's own dataset without importing the host, which would close a cycle through `installed.ts`. */\nexport const PluginDatasetLookupContext = React.createContext<PluginDatasetLookup>(() => undefined)\n"],"mappings":";AAKA,YAAY,WAAW;AAOhB,MAAM,6BAA6B,MAAM,cAAmC,MAAM,MAAS;","names":[]}
@@ -1,12 +1,4 @@
1
- import type { PluginContribution } from './provider';
2
1
  import type { Dataset } from '../../types/datasetTypes';
3
- type DatasetContribution = PluginContribution<'map.datasets'>;
4
- /**
5
- * A `map.datasets` contribution as the Datasets menu lists it. A live one goes under Live
6
- * Data; any other is organizational, stamped with the viewer's own organization.
7
- */
8
- export declare function toPluginDataset(registration: DatasetContribution, organization?: number): Dataset;
9
2
  /** Every enabled plugin's datasets, for the lists in the Datasets menu and the Layers tab. */
10
3
  export declare function usePluginDatasets(organization?: number): Dataset[];
11
- export {};
12
4
  //# sourceMappingURL=pluginDatasets.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pluginDatasets.d.ts","sourceRoot":"","sources":["../../../../src/core/plugins/host/pluginDatasets.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAMvD,KAAK,mBAAmB,GAAG,kBAAkB,CAAC,cAAc,CAAC,CAAA;AA8B7D;;;GAGG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,mBAAmB,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAoBjG;AAED,8FAA8F;AAC9F,wBAAgB,iBAAiB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,EAAE,CAOlE"}
1
+ {"version":3,"file":"pluginDatasets.d.ts","sourceRoot":"","sources":["../../../../src/core/plugins/host/pluginDatasets.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAEvD,8FAA8F;AAC9F,wBAAgB,iBAAiB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,EAAE,CAOlE"}
@@ -1,72 +1,9 @@
1
1
  'use client'
2
2
 
3
3
  "use client";
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __spreadValues = (a, b) => {
10
- for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
13
- if (__getOwnPropSymbols)
14
- for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- }
18
- return a;
19
- };
20
4
  import * as React from "react";
21
- import { buildWmsTileUrl } from "../../components/viewers/map/datasets/src/urlSources";
22
- import { layerColorByName } from "../../components/viewers/map/utils/stringToColour";
23
- import { DatasetGroup } from "../../types/dbTypes";
24
- import { pluginDatasetId } from "./pluginDatasetId";
25
5
  import { usePluginContributions } from "./provider";
26
- const noFeatures = async () => ({ type: "FeatureCollection", features: [] });
27
- function drawnBy(registration) {
28
- const { source, pluginId } = registration;
29
- if ((source == null ? void 0 : source.type) === "wms") {
30
- const { baseUrl, layers, timeEnabled } = source;
31
- return {
32
- datasetType: "WMS",
33
- type: "WMS",
34
- url: buildWmsTileUrl(baseUrl, layers),
35
- timeEnabled,
36
- wms: { baseUrl, layers },
37
- clickable: false,
38
- getFeatures: noFeatures
39
- };
40
- }
41
- if ((source == null ? void 0 : source.type) === "geojson") {
42
- return {
43
- datasetType: "GeoJSON",
44
- type: "GeoJSON",
45
- clickable: true,
46
- getFeatures: async () => await source.getFeatures()
47
- };
48
- }
49
- return { datasetType: "GeoJSON", type: "Plugin", clickable: false, drawnByPlugin: pluginId, getFeatures: noFeatures };
50
- }
51
- function toPluginDataset(registration, organization) {
52
- const { pluginId, id, name, description, publisher, information, live = false } = registration;
53
- const group = live ? DatasetGroup.National : DatasetGroup.Organizational;
54
- return __spreadValues({
55
- id: pluginDatasetId(pluginId, id),
56
- name,
57
- description,
58
- publisher,
59
- information,
60
- organization: live ? void 0 : organization,
61
- dataManagementSystem: "other",
62
- countrySubdivision: "",
63
- municipality: "",
64
- group,
65
- layerColor: layerColorByName(name),
66
- portal: { id: -1, name: publisher != null ? publisher : name, group, dataManagementSystem: "Other", live },
67
- getFields: async () => []
68
- }, drawnBy(registration));
69
- }
6
+ import { toPluginDataset } from "./toPluginDataset";
70
7
  function usePluginDatasets(organization) {
71
8
  const registrations = usePluginContributions("map.datasets");
72
9
  return React.useMemo(
@@ -75,7 +12,6 @@ function usePluginDatasets(organization) {
75
12
  );
76
13
  }
77
14
  export {
78
- toPluginDataset,
79
15
  usePluginDatasets
80
16
  };
81
17
  //# sourceMappingURL=pluginDatasets.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/core/plugins/host/pluginDatasets.ts"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport * as React from 'react'\n\nimport { buildWmsTileUrl } from '../../components/viewers/map/datasets/src/urlSources'\nimport { layerColorByName } from '../../components/viewers/map/utils/stringToColour'\nimport { DatasetGroup } from '../../types/dbTypes'\n\nimport { pluginDatasetId } from './pluginDatasetId'\nimport { usePluginContributions } from './provider'\n\nimport type { PluginContribution } from './provider'\nimport type { Dataset } from '../../types/datasetTypes'\nimport type { AllGeoJSON } from '@turf/turf'\n\nconst noFeatures = async (): Promise<AllGeoJSON> =>\n ({ type: 'FeatureCollection', features: [] }) as AllGeoJSON\n\ntype DatasetContribution = PluginContribution<'map.datasets'>\n\nfunction drawnBy(registration: DatasetContribution): Pick<Dataset, 'datasetType' | 'type' | 'url' | 'timeEnabled' | 'wms' | 'getFeatures' | 'drawnByPlugin' | 'clickable'> {\n const { source, pluginId } = registration\n\n if (source?.type === 'wms') {\n const { baseUrl, layers, timeEnabled } = source\n return {\n datasetType: 'WMS',\n type: 'WMS',\n url: buildWmsTileUrl(baseUrl, layers),\n timeEnabled,\n wms: { baseUrl, layers },\n clickable: false,\n getFeatures: noFeatures,\n }\n }\n\n if (source?.type === 'geojson') {\n return {\n datasetType: 'GeoJSON',\n type: 'GeoJSON',\n clickable: true,\n getFeatures: async () => (await source.getFeatures()) as AllGeoJSON,\n }\n }\n\n return { datasetType: 'GeoJSON', type: 'Plugin', clickable: false, drawnByPlugin: pluginId, getFeatures: noFeatures }\n}\n\n/**\n * A `map.datasets` contribution as the Datasets menu lists it. A live one goes under Live\n * Data; any other is organizational, stamped with the viewer's own organization.\n */\nexport function toPluginDataset(registration: DatasetContribution, organization?: number): Dataset {\n const { pluginId, id, name, description, publisher, information, live = false } = registration\n const group = live ? DatasetGroup.National : DatasetGroup.Organizational\n\n return {\n id: pluginDatasetId(pluginId, id),\n name,\n description,\n publisher,\n information,\n organization: live ? undefined : organization,\n dataManagementSystem: 'other',\n countrySubdivision: '',\n municipality: '',\n group,\n layerColor: layerColorByName(name),\n portal: { id: -1, name: publisher ?? name, group, dataManagementSystem: 'Other', live },\n getFields: async () => [],\n ...drawnBy(registration),\n }\n}\n\n/** Every enabled plugin's datasets, for the lists in the Datasets menu and the Layers tab. */\nexport function usePluginDatasets(organization?: number): Dataset[] {\n const registrations = usePluginContributions('map.datasets')\n\n return React.useMemo(\n () => registrations.map(registration => toPluginDataset(registration, organization)),\n [registrations, organization],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAKA,YAAY,WAAW;AAEvB,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAE7B,SAAS,uBAAuB;AAChC,SAAS,8BAA8B;AAMvC,MAAM,aAAa,aAChB,EAAE,MAAM,qBAAqB,UAAU,CAAC,EAAE;AAI7C,SAAS,QAAQ,cAA0J;AACzK,QAAM,EAAE,QAAQ,SAAS,IAAI;AAE7B,OAA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,"sources":["../../../../src/core/plugins/host/pluginDatasets.ts"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport * as React from 'react'\n\nimport { usePluginContributions } from './provider'\nimport { toPluginDataset } from './toPluginDataset'\n\nimport type { Dataset } from '../../types/datasetTypes'\n\n/** Every enabled plugin's datasets, for the lists in the Datasets menu and the Layers tab. */\nexport function usePluginDatasets(organization?: number): Dataset[] {\n const registrations = usePluginContributions('map.datasets')\n\n return React.useMemo(\n () => registrations.map(registration => toPluginDataset(registration, organization)),\n [registrations, organization],\n )\n}\n"],"mappings":";AAKA,YAAY,WAAW;AAEvB,SAAS,8BAA8B;AACvC,SAAS,uBAAuB;AAKzB,SAAS,kBAAkB,cAAkC;AAClE,QAAM,gBAAgB,uBAAuB,cAAc;AAE3D,SAAO,MAAM;AAAA,IACX,MAAM,cAAc,IAAI,kBAAgB,gBAAgB,cAAc,YAAY,CAAC;AAAA,IACnF,CAAC,eAAe,YAAY;AAAA,EAC9B;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../../src/core/plugins/host/provider.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAO9B,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAG3C,OAAO,KAAK,EAAE,kBAAkB,EAAgB,YAAY,EAAE,MAAM,cAAc,CAAA;AAWlF,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB;;;;OAIG;IACH,OAAO,CAAC,EAAE,YAAY,CAAA;IACtB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,E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C,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;CAClD;AAED,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,OAA2B,EAC3B,YAAY,EACZ,OAAO,GACR,EAAE,uBAAuB,qBAiHzB;AAED,wBAAgB,iBAAiB,IAAI,cAAc,CAMlD;AAED,wBAAgB,eAAe,IAAI,OAAO,CAGzC;AAED,sFAAsF;AACtF,wBAAgB,aAAa,IAAI,UAAU,GAAG,IAAI,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAE1E;AAID,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,kBAAkB,IAC/D,kBAAkB,CAAC,CAAC,CAAC,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAA;AAE9C;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,kBAAkB,EACvE,GAAG,EAAE,CAAC,GACL,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAgBzB"}
@@ -7,7 +7,9 @@ import { INSTALLED_PLUGINS } from "../installed";
7
7
  import { resolvePluginEntry } from "../sdk/types";
8
8
  import { PluginDialogProvider } from "./dialogs";
9
9
  import { PluginHost } from "./host";
10
+ import { PluginDatasetLookupContext } from "./pluginDatasetLookup";
10
11
  import { PluginRegistry } from "./registry";
12
+ import { toPluginDataset } from "./toPluginDataset";
11
13
  const PluginHostContext = React.createContext(null);
12
14
  function PluginHostProvider({
13
15
  children,
@@ -84,7 +86,11 @@ function PluginHostProvider({
84
86
  () => ({ registry, host, ready, configs: resolvedConfigs }),
85
87
  [registry, host, ready, resolvedConfigs]
86
88
  );
87
- return /* @__PURE__ */ jsx(PluginHostContext.Provider, { value, children: /* @__PURE__ */ jsx(PluginDialogProvider, { children }) });
89
+ const findDataset = React.useCallback((pluginId, id) => {
90
+ const registration = registry.getAll("map.datasets").find((candidate) => candidate.pluginId === pluginId && candidate.id === id);
91
+ return registration && toPluginDataset(registration);
92
+ }, [registry]);
93
+ return /* @__PURE__ */ jsx(PluginHostContext.Provider, { value, children: /* @__PURE__ */ jsx(PluginDatasetLookupContext.Provider, { value: findDataset, children: /* @__PURE__ */ jsx(PluginDialogProvider, { children }) }) });
88
94
  }
89
95
  function usePluginRegistry() {
90
96
  const context = React.useContext(PluginHostContext);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/core/plugins/host/provider.tsx"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport * as React from 'react'\n\nimport { INSTALLED_PLUGINS } from '../installed'\n\nimport { resolvePluginEntry } from '../sdk/types'\n\nimport { PluginDialogProvider } from './dialogs'\nimport { PluginHost } from './host'\nimport { PluginRegistry } from './registry'\n\n\nimport type { CapabilityRegistry, PluginSource, PluginsInput } from '../sdk/types'\n\ninterface PluginHostContextValue {\n registry: PluginRegistry\n host: PluginHost\n ready: boolean\n configs: Record<string, Record<string, unknown>>\n}\n\nconst PluginHostContext = React.createContext<PluginHostContextValue | null>(null)\n\nexport interface PluginHostProviderProps {\n children: React.ReactNode\n /**\n * The plugins to load. Defaults to the set compiled into core. Pass a stable\n * reference — a module-scope array or a `useCallback` thunk — since a fresh\n * literal re-resolves the list on every render.\n */\n plugins?: PluginsInput\n /**\n * Slugs to activate. `undefined` activates everything, for consumers that do not\n * manage enablement. An array is authoritative: anything unlisted stays inactive,\n * and removing a slug deactivates that plugin in place, without a reload.\n */\n enabledSlugs?: string[]\n /** Per-plugin configuration, keyed by slug. Reaches the plugin as `ctx.config`. */\n configs?: Record<string, Record<string, unknown>>\n}\n\nexport function PluginHostProvider({\n children,\n plugins = INSTALLED_PLUGINS,\n enabledSlugs,\n configs,\n}: PluginHostProviderProps) {\n const registry = React.useMemo(() => new PluginRegistry(), [])\n const host = React.useMemo(() => new PluginHost(registry), [registry])\n\n const [sources, setSources] = React.useState<PluginSource[] | null>(null)\n const [ready, setReady] = React.useState(false)\n\n // Both normalized to an identity derived from their content: the props arrive as\n // fresh literals from a fetch, and using them as effect deps directly would reload\n // every plugin on every render. The JSON round-trip also drops anything\n // non-serializable, which is correct — config originates as JSON.\n const enabledKey = React.useMemo(\n () => (enabledSlugs ? [...enabledSlugs].sort().join('\\u0000') : null),\n [enabledSlugs],\n )\n const enabled = React.useMemo(\n () => (enabledKey === null ? null : new Set(enabledKey.split('\\u0000'))),\n [enabledKey],\n )\n\n const configsKey = React.useMemo(() => (configs ? JSON.stringify(configs) : ''), [configs])\n const resolvedConfigs = React.useMemo<Record<string, Record<string, unknown>>>(\n () => (configsKey ? JSON.parse(configsKey) : {}),\n [configsKey],\n )\n\n // Resolve the list first: for runtime-loaded plugins that is a fetch plus a\n // dynamic import per bundle, so it cannot happen during render.\n React.useEffect(() => {\n let cancelled = false\n\n async function resolve() {\n try {\n const resolved = typeof plugins === 'function' ? await plugins() : plugins\n if (!cancelled) setSources(resolved)\n } catch (err) {\n // A plugin source that cannot be resolved must not take down the app.\n console.error('Failed to resolve the plugin list:', err)\n if (!cancelled) setSources([])\n }\n }\n\n void resolve()\n return () => {\n cancelled = true\n }\n }, [plugins])\n\n // Reconcile: activate what should be running, deactivate what should not.\n // Runs again whenever enablement or config changes, so the plugins page can\n // toggle a plugin without a page reload.\n React.useEffect(() => {\n if (!sources) return\n let cancelled = false\n\n async function sync() {\n for (const { manifest, entry } of sources ?? []) {\n if (cancelled) return\n\n const slug = manifest?.slug\n if (typeof slug !== 'string' || !slug) {\n // Let the host reject it, so the failure is recorded. The entry is never\n // resolved: no point fetching a chunk for a plugin that cannot activate.\n await host.loadPlugin(manifest, { activate: () => {} }, {})\n continue\n }\n\n const shouldRun = enabled === null || enabled.has(slug)\n const isRunning = host.getStatus(slug) === 'active'\n\n if (shouldRun && !isRunning) {\n // Resolving the entry is what downloads a compiled-in plugin's chunk, so it\n // happens here rather than at module scope.\n try {\n await host.loadPlugin(manifest, await resolvePluginEntry(entry), resolvedConfigs[slug] ?? {})\n } catch (error) {\n // A chunk that fails to load must not stop the plugins after it.\n console.error(`Failed to load plugin \"${slug}\":`, error)\n }\n } else if (!shouldRun && isRunning) {\n await host.unloadPlugin(slug)\n }\n }\n\n if (!cancelled) setReady(true)\n }\n\n void sync()\n return () => {\n cancelled = true\n }\n }, [sources, host, enabled, resolvedConfigs])\n\n const value = React.useMemo(\n () => ({ registry, host, ready, configs: resolvedConfigs }),\n [registry, host, ready, resolvedConfigs],\n )\n\n return (\n <PluginHostContext.Provider value={value}>\n <PluginDialogProvider>\n {children}\n </PluginDialogProvider>\n </PluginHostContext.Provider>\n )\n}\n\nexport function usePluginRegistry(): PluginRegistry {\n const context = React.useContext(PluginHostContext)\n if (!context) {\n throw new Error('usePluginRegistry must be used within PluginHostProvider')\n }\n return context.registry\n}\n\nexport function usePluginsReady(): boolean {\n const context = React.useContext(PluginHostContext)\n return context?.ready ?? false\n}\n\n/** The host itself. Only the plugins page needs this; capability consumers do not. */\nexport function usePluginHost(): PluginHost | null {\n return React.useContext(PluginHostContext)?.host ?? null\n}\n\n/**\n * Every plugin's configuration, keyed by slug, for capability hosts to pass into\n * `PluginScopeProvider`. Plugins use `usePluginConfig()` from the SDK instead — a plugin\n * component importing this module puts `installed.ts` and the host in a cycle.\n */\nexport function usePluginConfigs(): Record<string, Record<string, unknown>> {\n return React.useContext(PluginHostContext)?.configs ?? EMPTY_CONFIGS\n}\n\nconst EMPTY_CONFIGS: Record<string, Record<string, unknown>> = {}\n\nexport type PluginContribution<K extends keyof CapabilityRegistry> =\n CapabilityRegistry[K] & { pluginId: string }\n\n/**\n * Read a capability's contributions and re-render when they change — the one way a host\n * component should consume the registry. `registry.getAll()` during render only works\n * when plugins load before first paint; a runtime-loaded plugin registers after the\n * consumer rendered, with nothing to tell it to look again.\n */\nexport function usePluginContributions<K extends keyof CapabilityRegistry>(\n key: K,\n): PluginContribution<K>[] {\n const registry = usePluginRegistry()\n\n const subscribe = React.useCallback(\n (onStoreChange: () => void) => registry.subscribe(onStoreChange),\n [registry],\n )\n\n // Copy-on-write in the registry makes this a stable reference between changes, which is\n // what lets useSyncExternalStore skip consumers of untouched capabilities.\n const getSnapshot = React.useCallback(\n () => registry.getAll(key) as unknown as PluginContribution<K>[],\n [registry, key],\n )\n\n return React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot)\n}\n"],"mappings":";AAsJM;AAjJN,YAAY,WAAW;AAEvB,SAAS,yBAAyB;AAElC,SAAS,0BAA0B;AAEnC,SAAS,4BAA4B;AACrC,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAY/B,MAAM,oBAAoB,MAAM,cAA6C,IAAI;AAoB1E,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA,UAAU;AAAA,EACV;AAAA,EACA;AACF,GAA4B;AAC1B,QAAM,WAAW,MAAM,QAAQ,MAAM,IAAI,eAAe,GAAG,CAAC,CAAC;AAC7D,QAAM,OAAO,MAAM,QAAQ,MAAM,IAAI,WAAW,QAAQ,GAAG,CAAC,QAAQ,CAAC;AAErE,QAAM,CAAC,SAAS,UAAU,IAAI,MAAM,SAAgC,IAAI;AACxE,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,KAAK;AAM9C,QAAM,aAAa,MAAM;AAAA,IACvB,MAAO,eAAe,CAAC,GAAG,YAAY,EAAE,KAAK,EAAE,KAAK,IAAQ,IAAI;AAAA,IAChE,CAAC,YAAY;AAAA,EACf;AACA,QAAM,UAAU,MAAM;AAAA,IACpB,MAAO,eAAe,OAAO,OAAO,IAAI,IAAI,WAAW,MAAM,IAAQ,CAAC;AAAA,IACtE,CAAC,UAAU;AAAA,EACb;AAEA,QAAM,aAAa,MAAM,QAAQ,MAAO,UAAU,KAAK,UAAU,OAAO,IAAI,IAAK,CAAC,OAAO,CAAC;AAC1F,QAAM,kBAAkB,MAAM;AAAA,IAC5B,MAAO,aAAa,KAAK,MAAM,UAAU,IAAI,C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A,SAAK,KAAK;AACV,WAAO,MAAM;AACX,kBAAY;AAAA,IACd;AAAA,EACF,GAAG,CAAC,SAAS,MAAM,SAAS,eAAe,CAAC;AAE5C,QAAM,QAAQ,MAAM;AAAA,IAClB,OAAO,EAAE,UAAU,MAAM,OAAO,SAAS,gBAAgB;AAAA,IACzD,CAAC,UAAU,MAAM,OAAO,eAAe;AAAA,EACzC;AAEA,SACE,oBAAC,kBAAkB,UAAlB,EAA2B,OAC1B,8BAAC,wBACE,UACH,GACF;AAEJ;AAEO,SAAS,oBAAoC;AAClD,QAAM,UAAU,MAAM,WAAW,iBAAiB;AAClD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC5E;AACA,SAAO,QAAQ;AACjB;AAEO,SAAS,kBAA2B;AArK3C;AAsKE,QAAM,UAAU,MAAM,WAAW,iBAAiB;AAClD,UAAO,wCAAS,UAAT,YAAkB;AAC3B;AAGO,SAAS,gBAAmC;AA3KnD;AA4KE,UAAO,iBAAM,WAAW,iBAAiB,MAAlC,mBAAqC,SAArC,YAA6C;AACtD;AAOO,SAAS,mBAA4D;AApL5E;AAqLE,UAAO,iBAAM,WAAW,iBAAiB,MAAlC,mBAAqC,YAArC,YAAgD;AACzD;AAEA,MAAM,gBAAyD,CAAC;AAWzD,SAAS,uBACd,KACyB;AACzB,QAAM,WAAW,kBAAkB;AAEnC,QAAM,YAAY,MAAM;AAAA,IACtB,CAAC,kBAA8B,SAAS,UAAU,aAAa;AAAA,IAC/D,CAAC,QAAQ;AAAA,EACX;AAIA,QAAM,cAAc,MAAM;AAAA,IACxB,MAAM,SAAS,OAAO,GAAG;AAAA,IACzB,CAAC,UAAU,GAAG;AAAA,EAChB;AAEA,SAAO,MAAM,qBAAqB,WAAW,aAAa,WAAW;AACvE;","names":[]}
1
+ {"version":3,"sources":["../../../../src/core/plugins/host/provider.tsx"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport * as React from 'react'\n\nimport { INSTALLED_PLUGINS } from '../installed'\n\nimport { resolvePluginEntry } from '../sdk/types'\n\nimport { PluginDialogProvider } from './dialogs'\nimport { PluginHost } from './host'\nimport { PluginDatasetLookupContext, type PluginDatasetLookup } from './pluginDatasetLookup'\nimport { PluginRegistry } from './registry'\nimport { toPluginDataset } from './toPluginDataset'\n\n\nimport type { CapabilityRegistry, PluginSource, PluginsInput } from '../sdk/types'\n\ninterface PluginHostContextValue {\n registry: PluginRegistry\n host: PluginHost\n ready: boolean\n configs: Record<string, Record<string, unknown>>\n}\n\nconst PluginHostContext = React.createContext<PluginHostContextValue | null>(null)\n\nexport interface PluginHostProviderProps {\n children: React.ReactNode\n /**\n * The plugins to load. Defaults to the set compiled into core. Pass a stable\n * reference — a module-scope array or a `useCallback` thunk — since a fresh\n * literal re-resolves the list on every render.\n */\n plugins?: PluginsInput\n /**\n * Slugs to activate. `undefined` activates everything, for consumers that do not\n * manage enablement. An array is authoritative: anything unlisted stays inactive,\n * and removing a slug deactivates that plugin in place, without a reload.\n */\n enabledSlugs?: string[]\n /** Per-plugin configuration, keyed by slug. Reaches the plugin as `ctx.config`. */\n configs?: Record<string, Record<string, unknown>>\n}\n\nexport function PluginHostProvider({\n children,\n plugins = INSTALLED_PLUGINS,\n enabledSlugs,\n configs,\n}: PluginHostProviderProps) {\n const registry = React.useMemo(() => new PluginRegistry(), [])\n const host = React.useMemo(() => new PluginHost(registry), [registry])\n\n const [sources, setSources] = React.useState<PluginSource[] | null>(null)\n const [ready, setReady] = React.useState(false)\n\n // Both normalized to an identity derived from their content: the props arrive as\n // fresh literals from a fetch, and using them as effect deps directly would reload\n // every plugin on every render. The JSON round-trip also drops anything\n // non-serializable, which is correct — config originates as JSON.\n const enabledKey = React.useMemo(\n () => (enabledSlugs ? [...enabledSlugs].sort().join('\\u0000') : null),\n [enabledSlugs],\n )\n const enabled = React.useMemo(\n () => (enabledKey === null ? null : new Set(enabledKey.split('\\u0000'))),\n [enabledKey],\n )\n\n const configsKey = React.useMemo(() => (configs ? JSON.stringify(configs) : ''), [configs])\n const resolvedConfigs = React.useMemo<Record<string, Record<string, unknown>>>(\n () => (configsKey ? JSON.parse(configsKey) : {}),\n [configsKey],\n )\n\n // Resolve the list first: for runtime-loaded plugins that is a fetch plus a\n // dynamic import per bundle, so it cannot happen during render.\n React.useEffect(() => {\n let cancelled = false\n\n async function resolve() {\n try {\n const resolved = typeof plugins === 'function' ? await plugins() : plugins\n if (!cancelled) setSources(resolved)\n } catch (err) {\n // A plugin source that cannot be resolved must not take down the app.\n console.error('Failed to resolve the plugin list:', err)\n if (!cancelled) setSources([])\n }\n }\n\n void resolve()\n return () => {\n cancelled = true\n }\n }, [plugins])\n\n // Reconcile: activate what should be running, deactivate what should not.\n // Runs again whenever enablement or config changes, so the plugins page can\n // toggle a plugin without a page reload.\n React.useEffect(() => {\n if (!sources) return\n let cancelled = false\n\n async function sync() {\n for (const { manifest, entry } of sources ?? []) {\n if (cancelled) return\n\n const slug = manifest?.slug\n if (typeof slug !== 'string' || !slug) {\n // Let the host reject it, so the failure is recorded. The entry is never\n // resolved: no point fetching a chunk for a plugin that cannot activate.\n await host.loadPlugin(manifest, { activate: () => {} }, {})\n continue\n }\n\n const shouldRun = enabled === null || enabled.has(slug)\n const isRunning = host.getStatus(slug) === 'active'\n\n if (shouldRun && !isRunning) {\n // Resolving the entry is what downloads a compiled-in plugin's chunk, so it\n // happens here rather than at module scope.\n try {\n await host.loadPlugin(manifest, await resolvePluginEntry(entry), resolvedConfigs[slug] ?? {})\n } catch (error) {\n // A chunk that fails to load must not stop the plugins after it.\n console.error(`Failed to load plugin \"${slug}\":`, error)\n }\n } else if (!shouldRun && isRunning) {\n await host.unloadPlugin(slug)\n }\n }\n\n if (!cancelled) setReady(true)\n }\n\n void sync()\n return () => {\n cancelled = true\n }\n }, [sources, host, enabled, resolvedConfigs])\n\n const value = React.useMemo(\n () => ({ registry, host, ready, configs: resolvedConfigs }),\n [registry, host, ready, resolvedConfigs],\n )\n\n const findDataset = React.useCallback<PluginDatasetLookup>((pluginId, id) => {\n const registration = (registry.getAll('map.datasets') as unknown as PluginContribution<'map.datasets'>[])\n .find(candidate => candidate.pluginId === pluginId && candidate.id === id)\n return registration && toPluginDataset(registration)\n }, [registry])\n\n return (\n <PluginHostContext.Provider value={value}>\n <PluginDatasetLookupContext.Provider value={findDataset}>\n <PluginDialogProvider>\n {children}\n </PluginDialogProvider>\n </PluginDatasetLookupContext.Provider>\n </PluginHostContext.Provider>\n )\n}\n\nexport function usePluginRegistry(): PluginRegistry {\n const context = React.useContext(PluginHostContext)\n if (!context) {\n throw new Error('usePluginRegistry must be used within PluginHostProvider')\n }\n return context.registry\n}\n\nexport function usePluginsReady(): boolean {\n const context = React.useContext(PluginHostContext)\n return context?.ready ?? false\n}\n\n/** The host itself. Only the plugins page needs this; capability consumers do not. */\nexport function usePluginHost(): PluginHost | null {\n return React.useContext(PluginHostContext)?.host ?? null\n}\n\n/**\n * Every plugin's configuration, keyed by slug, for capability hosts to pass into\n * `PluginScopeProvider`. Plugins use `usePluginConfig()` from the SDK instead — a plugin\n * component importing this module puts `installed.ts` and the host in a cycle.\n */\nexport function usePluginConfigs(): Record<string, Record<string, unknown>> {\n return React.useContext(PluginHostContext)?.configs ?? EMPTY_CONFIGS\n}\n\nconst EMPTY_CONFIGS: Record<string, Record<string, unknown>> = {}\n\nexport type PluginContribution<K extends keyof CapabilityRegistry> =\n CapabilityRegistry[K] & { pluginId: string }\n\n/**\n * Read a capability's contributions and re-render when they change — the one way a host\n * component should consume the registry. `registry.getAll()` during render only works\n * when plugins load before first paint; a runtime-loaded plugin registers after the\n * consumer rendered, with nothing to tell it to look again.\n */\nexport function usePluginContributions<K extends keyof CapabilityRegistry>(\n key: K,\n): PluginContribution<K>[] {\n const registry = usePluginRegistry()\n\n const subscribe = React.useCallback(\n (onStoreChange: () => void) => registry.subscribe(onStoreChange),\n [registry],\n )\n\n // Copy-on-write in the registry makes this a stable reference between changes, which is\n // what lets useSyncExternalStore skip consumers of untouched capabilities.\n const getSnapshot = React.useCallback(\n () => registry.getAll(key) as unknown as PluginContribution<K>[],\n [registry, key],\n )\n\n return React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot)\n}\n"],"mappings":";AA+JQ;AA1JR,YAAY,WAAW;AAEvB,SAAS,yBAAyB;AAElC,SAAS,0BAA0B;AAEnC,SAAS,4BAA4B;AACrC,SAAS,kBAAkB;AAC3B,SAAS,kCAA4D;AACrE,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAYhC,MAAM,oBAAoB,MAAM,cAA6C,IAAI;AAoB1E,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA,UAAU;AAAA,EACV;AAAA,EACA;AACF,GAA4B;AAC1B,QAAM,WAAW,MAAM,QAAQ,MAAM,IAAI,eAAe,GAAG,CAAC,CAAC;AAC7D,QAAM,OAAO,MAAM,QAAQ,MAAM,IAAI,WAAW,QAAQ,GAAG,CAAC,QAAQ,CAAC;AAErE,QAAM,CAAC,SAAS,UAAU,IAAI,MAAM,SAAgC,IAAI;AACxE,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,KAAK;AAM9C,QAAM,aAAa,MAAM;AAAA,IACvB,MAAO,eAAe,CAAC,GAAG,YAAY,EAAE,KAAK,EAAE,KAAK,IAAQ,IAAI;AAAA,IAChE,CAAC,YAAY;AAAA,EACf;AACA,QAAM,UAAU,MAAM;AAAA,IACpB,MAAO,eAAe,OAAO,OAAO,IAAI,IAAI,WAAW,MAAM,IAAQ,CAAC;AAAA,IACtE,CAAC,UAAU;AAAA,EACb;AAEA,QAAM,aAAa,MAAM,QAAQ,MAAO,UAAU,KAAK,UAAU,OAAO,IAAI,IAAK,CAAC,OAAO,CAAC;AAC1F,QAAM,kBAAkB,MAAM;AAAA,IAC5B,MAAO,aAAa,KAAK,MAAM,UAAU,IAAI,CAAC;AAAA,IAC9C,CAAC,UAAU;AAAA,EACb;AA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,OAAO,GAAG;AAAA,IACzB,CAAC,UAAU,GAAG;AAAA,EAChB;AAEA,SAAO,MAAM,qBAAqB,WAAW,aAAa,WAAW;AACvE;","names":[]}
@@ -0,0 +1,10 @@
1
+ import type { PluginContribution } from './provider';
2
+ import type { Dataset } from '../../types/datasetTypes';
3
+ type DatasetContribution = PluginContribution<'map.datasets'>;
4
+ /**
5
+ * A `map.datasets` contribution as the Datasets menu lists it. A live one goes under Live
6
+ * Data; any other is organizational, stamped with the viewer's own organization.
7
+ */
8
+ export declare function toPluginDataset(registration: DatasetContribution, organization?: number): Dataset;
9
+ export {};
10
+ //# sourceMappingURL=toPluginDataset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toPluginDataset.d.ts","sourceRoot":"","sources":["../../../../src/core/plugins/host/toPluginDataset.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAMvD,KAAK,mBAAmB,GAAG,kBAAkB,CAAC,cAAc,CAAC,CAAA;AA8B7D;;;GAGG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,mBAAmB,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAoBjG"}
@@ -0,0 +1,68 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ import { buildWmsTileUrl } from "../../components/viewers/map/datasets/src/urlSources";
18
+ import { layerColorByName } from "../../components/viewers/map/utils/stringToColour";
19
+ import { DatasetGroup } from "../../types/dbTypes";
20
+ import { pluginDatasetId } from "./pluginDatasetId";
21
+ const noFeatures = async () => ({ type: "FeatureCollection", features: [] });
22
+ function drawnBy(registration) {
23
+ const { source, pluginId } = registration;
24
+ if ((source == null ? void 0 : source.type) === "wms") {
25
+ const { baseUrl, layers, timeEnabled } = source;
26
+ return {
27
+ datasetType: "WMS",
28
+ type: "WMS",
29
+ url: buildWmsTileUrl(baseUrl, layers),
30
+ timeEnabled,
31
+ wms: { baseUrl, layers },
32
+ clickable: false,
33
+ getFeatures: noFeatures
34
+ };
35
+ }
36
+ if ((source == null ? void 0 : source.type) === "geojson") {
37
+ return {
38
+ datasetType: "GeoJSON",
39
+ type: "GeoJSON",
40
+ clickable: true,
41
+ getFeatures: async () => await source.getFeatures()
42
+ };
43
+ }
44
+ return { datasetType: "GeoJSON", type: "Plugin", clickable: false, drawnByPlugin: pluginId, getFeatures: noFeatures };
45
+ }
46
+ function toPluginDataset(registration, organization) {
47
+ const { pluginId, id, name, description, publisher, information, live = false } = registration;
48
+ const group = live ? DatasetGroup.National : DatasetGroup.Organizational;
49
+ return __spreadValues({
50
+ id: pluginDatasetId(pluginId, id),
51
+ name,
52
+ description,
53
+ publisher,
54
+ information,
55
+ organization: live ? void 0 : organization,
56
+ dataManagementSystem: "other",
57
+ countrySubdivision: "",
58
+ municipality: "",
59
+ group,
60
+ layerColor: layerColorByName(name),
61
+ portal: { id: -1, name: publisher != null ? publisher : name, group, dataManagementSystem: "Other", live },
62
+ getFields: async () => []
63
+ }, drawnBy(registration));
64
+ }
65
+ export {
66
+ toPluginDataset
67
+ };
68
+ //# sourceMappingURL=toPluginDataset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/core/plugins/host/toPluginDataset.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport { buildWmsTileUrl } from '../../components/viewers/map/datasets/src/urlSources'\nimport { layerColorByName } from '../../components/viewers/map/utils/stringToColour'\nimport { DatasetGroup } from '../../types/dbTypes'\n\nimport { pluginDatasetId } from './pluginDatasetId'\n\nimport type { PluginContribution } from './provider'\nimport type { Dataset } from '../../types/datasetTypes'\nimport type { AllGeoJSON } from '@turf/turf'\n\nconst noFeatures = async (): Promise<AllGeoJSON> =>\n ({ type: 'FeatureCollection', features: [] }) as AllGeoJSON\n\ntype DatasetContribution = PluginContribution<'map.datasets'>\n\nfunction drawnBy(registration: DatasetContribution): Pick<Dataset, 'datasetType' | 'type' | 'url' | 'timeEnabled' | 'wms' | 'getFeatures' | 'drawnByPlugin' | 'clickable'> {\n const { source, pluginId } = registration\n\n if (source?.type === 'wms') {\n const { baseUrl, layers, timeEnabled } = source\n return {\n datasetType: 'WMS',\n type: 'WMS',\n url: buildWmsTileUrl(baseUrl, layers),\n timeEnabled,\n wms: { baseUrl, layers },\n clickable: false,\n getFeatures: noFeatures,\n }\n }\n\n if (source?.type === 'geojson') {\n return {\n datasetType: 'GeoJSON',\n type: 'GeoJSON',\n clickable: true,\n getFeatures: async () => (await source.getFeatures()) as AllGeoJSON,\n }\n }\n\n return { datasetType: 'GeoJSON', type: 'Plugin', clickable: false, drawnByPlugin: pluginId, getFeatures: noFeatures }\n}\n\n/**\n * A `map.datasets` contribution as the Datasets menu lists it. A live one goes under Live\n * Data; any other is organizational, stamped with the viewer's own organization.\n */\nexport function toPluginDataset(registration: DatasetContribution, organization?: number): Dataset {\n const { pluginId, id, name, description, publisher, information, live = false } = registration\n const group = live ? DatasetGroup.National : DatasetGroup.Organizational\n\n return {\n id: pluginDatasetId(pluginId, id),\n name,\n description,\n publisher,\n information,\n organization: live ? undefined : organization,\n dataManagementSystem: 'other',\n countrySubdivision: '',\n municipality: '',\n group,\n layerColor: layerColorByName(name),\n portal: { id: -1, name: publisher ?? name, group, dataManagementSystem: 'Other', live },\n getFields: async () => [],\n ...drawnBy(registration),\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAGA,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAE7B,SAAS,uBAAuB;AAMhC,MAAM,aAAa,aAChB,EAAE,MAAM,qBAAqB,UAAU,CAAC,EAAE;AAI7C,SAAS,QAAQ,cAA0J;AACzK,QAAM,EAAE,QAAQ,SAAS,IAAI;AAE7B,OAAI,iCAAQ,UAAS,OAAO;AAC1B,UAAM,EAAE,SAAS,QAAQ,YAAY,IAAI;AACzC,WAAO;AAAA,MACL,aAAa;AAAA,MACb,MAAM;AAAA,MACN,KAAK,gBAAgB,SAAS,MAAM;AAAA,MACpC;AAAA,MACA,KAAK,EAAE,SAAS,OAAO;AAAA,MACvB,WAAW;AAAA,MACX,aAAa;AAAA,IACf;AAAA,EACF;AAEA,OAAI,iCAAQ,UAAS,WAAW;AAC9B,WAAO;AAAA,MACL,aAAa;AAAA,MACb,MAAM;AAAA,MACN,WAAW;AAAA,MACX,aAAa,YAAa,MAAM,OAAO,YAAY;AAAA,IACrD;AAAA,EACF;AAEA,SAAO,EAAE,aAAa,WAAW,MAAM,UAAU,WAAW,OAAO,eAAe,UAAU,aAAa,WAAW;AACtH;AAMO,SAAS,gBAAgB,cAAmC,cAAgC;AACjG,QAAM,EAAE,UAAU,IAAI,MAAM,aAAa,WAAW,aAAa,OAAO,MAAM,IAAI;AAClF,QAAM,QAAQ,OAAO,aAAa,WAAW,aAAa;AAE1D,SAAO;AAAA,IACL,IAAI,gBAAgB,UAAU,EAAE;AAAA,IAChC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,OAAO,SAAY;AAAA,IACjC,sBAAsB;AAAA,IACtB,oBAAoB;AAAA,IACpB,cAAc;AAAA,IACd;AAAA,IACA,YAAY,iBAAiB,IAAI;AAAA,IACjC,QAAQ,EAAE,IAAI,IAAI,MAAM,gCAAa,MAAM,OAAO,sBAAsB,SAAS,KAAK;AAAA,IACtF,WAAW,YAAY,CAAC;AAAA,KACrB,QAAQ,YAAY;AAE3B;","names":[]}
@@ -3,10 +3,14 @@ export interface PluginDatasetState {
3
3
  applied: boolean;
4
4
  /** Applied and not hidden with its eye toggle: draw it only when this is true. */
5
5
  visible: boolean;
6
+ /** What ticking it in the Datasets menu does: adds it to the map, or shows it again if hidden. */
7
+ apply: () => void;
8
+ /** What unticking it in the Datasets menu does: takes it off the map. */
9
+ remove: () => void;
6
10
  }
7
11
  /**
8
- * Whether one of this plugin's `map.datasets` is on the map, so the `map.layers` and
9
- * `viewer.legends` that draw it know when to. `id` is the registration's own id.
12
+ * Whether one of this plugin's `map.datasets` is on the map, with the Datasets menu's own
13
+ * actions for it so a plugin's controls and the menu never disagree. `id` is the registration's.
10
14
  */
11
15
  export declare function usePluginDataset(id: string): PluginDatasetState;
12
16
  //# sourceMappingURL=datasets.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"datasets.d.ts","sourceRoot":"","sources":["../../../../src/core/plugins/sdk/datasets.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,kBAAkB;IACjC,gDAAgD;IAChD,OAAO,EAAE,OAAO,CAAA;IAChB,kFAAkF;IAClF,OAAO,EAAE,OAAO,CAAA;CACjB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,kBAAkB,CAS/D"}
1
+ {"version":3,"file":"datasets.d.ts","sourceRoot":"","sources":["../../../../src/core/plugins/sdk/datasets.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,kBAAkB;IACjC,gDAAgD;IAChD,OAAO,EAAE,OAAO,CAAA;IAChB,kFAAkF;IAClF,OAAO,EAAE,OAAO,CAAA;IAChB,kGAAkG;IAClG,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB,yEAAyE;IACzE,MAAM,EAAE,MAAM,IAAI,CAAA;CACnB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,kBAAkB,CAuB/D"}
@@ -4,15 +4,28 @@
4
4
  import * as React from "react";
5
5
  import { DatasetsContext } from "../../store/Datasets/context";
6
6
  import { pluginDatasetId } from "../host/pluginDatasetId";
7
+ import { PluginDatasetLookupContext } from "../host/pluginDatasetLookup";
7
8
  import { usePluginId } from "../host/scope";
8
9
  function usePluginDataset(id) {
9
10
  const pluginId = usePluginId();
10
- const { state } = React.useContext(DatasetsContext);
11
+ const { state, dispatch } = React.useContext(DatasetsContext);
12
+ const findDataset = React.useContext(PluginDatasetLookupContext);
11
13
  const datasetId = pluginDatasetId(pluginId, id);
12
14
  const added = state.datasets.addedDatasets.find((dataset) => dataset.id === datasetId);
13
15
  const applied = added !== void 0;
14
16
  const visible = applied && added.visible !== false;
15
- return React.useMemo(() => ({ applied, visible }), [applied, visible]);
17
+ const apply = React.useCallback(() => {
18
+ if (applied) {
19
+ if (!visible) dispatch({ type: "TOGGLE_DATASET_VISIBILITY", payload: { datasetId } });
20
+ return;
21
+ }
22
+ const dataset = findDataset(pluginId, id);
23
+ if (dataset) dispatch({ type: "ADD_DATASET_TO_MAP", payload: { dataset } });
24
+ }, [applied, visible, findDataset, pluginId, id, datasetId, dispatch]);
25
+ const remove = React.useCallback(() => {
26
+ if (applied) dispatch({ type: "REMOVE_DATASET_FROM_MAP", payload: { datasetId } });
27
+ }, [applied, datasetId, dispatch]);
28
+ return React.useMemo(() => ({ applied, visible, apply, remove }), [applied, visible, apply, remove]);
16
29
  }
17
30
  export {
18
31
  usePluginDataset
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/core/plugins/sdk/datasets.ts"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport * as React from 'react'\n\nimport { DatasetsContext } from '../../store/Datasets/context'\nimport { pluginDatasetId } from '../host/pluginDatasetId'\nimport { usePluginId } from '../host/scope'\n\nexport interface PluginDatasetState {\n /** The user added it from the Datasets menu. */\n applied: boolean\n /** Applied and not hidden with its eye toggle: draw it only when this is true. */\n visible: boolean\n}\n\n/**\n * Whether one of this plugin's `map.datasets` is on the map, so the `map.layers` and\n * `viewer.legends` that draw it know when to. `id` is the registration's own id.\n */\nexport function usePluginDataset(id: string): PluginDatasetState {\n const pluginId = usePluginId()\n const { state } = React.useContext(DatasetsContext)\n const datasetId = pluginDatasetId(pluginId, id)\n const added = state.datasets.addedDatasets.find(dataset => dataset.id === datasetId)\n const applied = added !== undefined\n const visible = applied && added.visible !== false\n\n return React.useMemo(() => ({ applied, visible }), [applied, visible])\n}\n"],"mappings":";AAKA,YAAY,WAAW;AAEvB,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAarB,SAAS,iBAAiB,IAAgC;AAC/D,QAAM,WAAW,YAAY;AAC7B,QAAM,EAAE,MAAM,IAAI,MAAM,WAAW,eAAe;AAClD,QAAM,YAAY,gBAAgB,UAAU,EAAE;AAC9C,QAAM,QAAQ,MAAM,SAAS,cAAc,KAAK,aAAW,QAAQ,OAAO,SAAS;AACnF,QAAM,UAAU,UAAU;AAC1B,QAAM,UAAU,WAAW,MAAM,YAAY;AAE7C,SAAO,MAAM,QAAQ,OAAO,EAAE,SAAS,QAAQ,IAAI,CAAC,SAAS,OAAO,CAAC;AACvE;","names":[]}
1
+ {"version":3,"sources":["../../../../src/core/plugins/sdk/datasets.ts"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport * as React from 'react'\n\nimport { DatasetsContext } from '../../store/Datasets/context'\nimport { pluginDatasetId } from '../host/pluginDatasetId'\nimport { PluginDatasetLookupContext } from '../host/pluginDatasetLookup'\nimport { usePluginId } from '../host/scope'\n\nexport interface PluginDatasetState {\n /** The user added it from the Datasets menu. */\n applied: boolean\n /** Applied and not hidden with its eye toggle: draw it only when this is true. */\n visible: boolean\n /** What ticking it in the Datasets menu does: adds it to the map, or shows it again if hidden. */\n apply: () => void\n /** What unticking it in the Datasets menu does: takes it off the map. */\n remove: () => void\n}\n\n/**\n * Whether one of this plugin's `map.datasets` is on the map, with the Datasets menu's own\n * actions for it so a plugin's controls and the menu never disagree. `id` is the registration's.\n */\nexport function usePluginDataset(id: string): PluginDatasetState {\n const pluginId = usePluginId()\n const { state, dispatch } = React.useContext(DatasetsContext)\n const findDataset = React.useContext(PluginDatasetLookupContext)\n const datasetId = pluginDatasetId(pluginId, id)\n const added = state.datasets.addedDatasets.find(dataset => dataset.id === datasetId)\n const applied = added !== undefined\n const visible = applied && added.visible !== false\n\n const apply = React.useCallback(() => {\n if (applied) {\n if (!visible) dispatch({ type: 'TOGGLE_DATASET_VISIBILITY', payload: { datasetId } })\n return\n }\n const dataset = findDataset(pluginId, id)\n if (dataset) dispatch({ type: 'ADD_DATASET_TO_MAP', payload: { dataset } })\n }, [applied, visible, findDataset, pluginId, id, datasetId, dispatch])\n\n const remove = React.useCallback(() => {\n if (applied) dispatch({ type: 'REMOVE_DATASET_FROM_MAP', payload: { datasetId } })\n }, [applied, datasetId, dispatch])\n\n return React.useMemo(() => ({ applied, visible, apply, remove }), [applied, visible, apply, remove])\n}\n"],"mappings":";AAKA,YAAY,WAAW;AAEvB,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C,SAAS,mBAAmB;AAiBrB,SAAS,iBAAiB,IAAgC;AAC/D,QAAM,WAAW,YAAY;AAC7B,QAAM,EAAE,OAAO,SAAS,IAAI,MAAM,WAAW,eAAe;AAC5D,QAAM,cAAc,MAAM,WAAW,0BAA0B;AAC/D,QAAM,YAAY,gBAAgB,UAAU,EAAE;AAC9C,QAAM,QAAQ,MAAM,SAAS,cAAc,KAAK,aAAW,QAAQ,OAAO,SAAS;AACnF,QAAM,UAAU,UAAU;AAC1B,QAAM,UAAU,WAAW,MAAM,YAAY;AAE7C,QAAM,QAAQ,MAAM,YAAY,MAAM;AACpC,QAAI,SAAS;AACX,UAAI,CAAC,QAAS,UAAS,EAAE,MAAM,6BAA6B,SAAS,EAAE,UAAU,EAAE,CAAC;AACpF;AAAA,IACF;AACA,UAAM,UAAU,YAAY,UAAU,EAAE;AACxC,QAAI,QAAS,UAAS,EAAE,MAAM,sBAAsB,SAAS,EAAE,QAAQ,EAAE,CAAC;AAAA,EAC5E,GAAG,CAAC,SAAS,SAAS,aAAa,UAAU,IAAI,WAAW,QAAQ,CAAC;AAErE,QAAM,SAAS,MAAM,YAAY,MAAM;AACrC,QAAI,QAAS,UAAS,EAAE,MAAM,2BAA2B,SAAS,EAAE,UAAU,EAAE,CAAC;AAAA,EACnF,GAAG,CAAC,SAAS,WAAW,QAAQ,CAAC;AAEjC,SAAO,MAAM,QAAQ,OAAO,EAAE,SAAS,SAAS,OAAO,OAAO,IAAI,CAAC,SAAS,SAAS,OAAO,MAAM,CAAC;AACrG;","names":[]}
@@ -131,7 +131,7 @@ export type PluginDatasetSource = {
131
131
  };
132
132
  /**
133
133
  * A dataset listed in the Datasets menu: under Live Data when `live`, otherwise under
134
- * Organizational. Applying it is the user's choice; `usePluginDataset(id)` reports it.
134
+ * Organizational. `usePluginDataset(id)` reports whether it is applied and can apply or remove it.
135
135
  */
136
136
  export interface DatasetRegistration {
137
137
  id: string;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/core/plugins/sdk/types.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\n// Type-only: keeps the viewer modules' runtime deps (@thatopen, three, maplibre)\n// out of the host's module graph.\nimport type { BimToolProps } from './bimViewer'\nimport type { MapToolProps } from './mapViewer'\n// A value, not just a type: a `viewer.tabs` contribution names the viewers it belongs in.\nexport { ViewerNames } from '../../types/dbTypes'\n\nimport type { ViewerNames } from '../../types/dbTypes'\n\n/**\n * The viewers that can host a tab or a legend, spelled as plain strings. Derived from\n * `ViewerNames` so the two cannot drift, and the form `@collabdt/plugin-kit` publishes.\n */\nexport type PluginViewerTarget = `${ViewerNames.map | ViewerNames.bim}`\nimport type { LucideProps } from 'lucide-react'\n\n// --- Capability definitions ---\n\n// Only capabilities core actually renders. One with no consumer registers fine,\n// shows nothing, and leaves nothing to debug.\nexport const VALID_CAPABILITIES = [\n 'data.pages',\n 'viewer.tabs',\n 'ui.dialogs',\n 'map.tools',\n 'bim.tools',\n 'viewer.legends',\n 'map.layers',\n 'map.datasets',\n] as const\n\nexport type PluginCapability = typeof VALID_CAPABILITIES[number]\n\n// --- Manifest ---\n\nexport interface PluginManifest {\n slug: string\n name: string\n version: string\n /** The `PLUGIN_HOST_API` this plugin was built against. Omitted is warned about, not rejected. */\n hostApi?: number\n description?: string\n author?: string\n /** A lucide icon name shown beside the plugin's name. Unset or unknown shows a puzzle piece. */\n icon?: string\n capabilities: PluginCapability[]\n requiredPermissions?: string[]\n configSchema?: Record<string, unknown>\n /**\n * Strings keyed by locale then message key, e.g. `{ en: { title: 'Hello' } }`.\n * Core folds them under `plugins.<slug>`, so `t('title')` resolves and no plugin\n * can collide with another. Values may nest, addressed as `t('spaces.title')`.\n */\n messages?: Record<string, Record<string, unknown>>\n}\n\nexport function validateManifest(manifest: unknown): { valid: boolean; errors: string[] } {\n const errors: string[] = []\n\n if (typeof manifest !== 'object' || manifest === null) {\n return { valid: false, errors: ['manifest must be an object'] }\n }\n\n const m = manifest as Record<string, unknown>\n\n if (!m.slug || typeof m.slug !== 'string') errors.push('slug is required')\n if (!m.name || typeof m.name !== 'string') errors.push('name is required')\n if (!m.version || typeof m.version !== 'string') errors.push('version is required')\n\n if (m.hostApi !== undefined && !Number.isInteger(m.hostApi)) {\n errors.push('hostApi must be an integer when present')\n }\n\n if (!Array.isArray(m.capabilities) || m.capabilities.length === 0) {\n errors.push('at least one capability is required')\n } else {\n for (const cap of m.capabilities) {\n if (!VALID_CAPABILITIES.includes(cap as PluginCapability)) {\n errors.push(`invalid capability: \"${cap}\"`)\n }\n }\n }\n\n return { valid: errors.length === 0, errors }\n}\n\n// --- Registration shapes (one per capability) ---\n\nexport interface DataPageColumn<Row> {\n key: string\n /** Resolved in the plugin's own namespace, falling back to the literal string. */\n labelKey: string\n render?: (row: Row) => React.ReactNode\n}\n\n/**\n * A full page in the Datasets nav, rendered by core. The plugin declares rows and columns; a\n * row click opens one of its own `ui.dialogs` rather than a detail view of its own.\n */\nexport interface DataPageRows<Row> {\n rows: Row[]\n isLoading?: boolean\n /** From the hook, not the registration, so it can close over `usePluginDialogs`. */\n onRowClick?: (row: Row) => void\n}\n\nexport interface DataPageRegistration<Row = Record<string, unknown>> {\n id: string\n titleKey: string\n icon: string | React.ComponentType<LucideProps>\n useRows: () => DataPageRows<Row>\n columns: DataPageColumn<Row>[]\n /** Column keys the search box filters on. Omit to search every column. */\n searchKeys?: string[]\n emptyKey?: string\n}\n\n/** Every toolbar component receives the toolbar entry core built for it. */\nexport interface ToolbarToolProps {\n tool: unknown\n}\n\n/**\n * A toolbar contribution. `P` is the viewer surface the hosting toolbar passes as\n * props, bound per capability by `CapabilityRegistry` — so a BIM component\n * registered under `map.tools` is a compile error.\n */\nexport interface ToolbarRegistration<P = Record<string, unknown>> {\n id: string\n label: string\n icon: string | React.ComponentType<LucideProps>\n component: React.ComponentType<ToolbarToolProps & P>\n cursor?: string\n stayActive?: boolean\n}\n\nexport interface ViewerTabRegistration {\n id: string\n labelKey: string\n icon: string | React.ComponentType<LucideProps>\n component: React.ComponentType\n /** Which viewers this tab appears in. Omit for all of them. */\n viewers?: Array<PluginViewerTarget | ViewerNames>\n}\n\n/**\n * A modal core owns. Registered here, opened by id from any of the plugin's surfaces via\n * `usePluginDialogs()`, so it outlives whichever one opened it.\n */\nexport interface DialogRegistration<P = Record<string, unknown>> {\n id: string\n titleKey: string\n size?: 'sm' | 'md' | 'lg' | 'xl'\n component: React.ComponentType<P & { close: () => void }>\n}\n\n/**\n * Something drawn on the map, mounted for as long as the map. Separate from `map.tools`,\n * whose panel unmounts when its dropdown closes and would take the layer with it.\n */\nexport interface MapLayerRegistration {\n id: string\n component: React.ComponentType<MapToolProps>\n}\n\n/** The least of a GeoJSON FeatureCollection core needs, so a typed `geojson` one satisfies it. */\nexport interface PluginFeatureCollection {\n type: 'FeatureCollection'\n features: Array<{\n type: 'Feature'\n id?: string | number\n geometry: { type: string; coordinates?: unknown; geometries?: unknown } | null\n properties: Record<string, unknown> | null\n }>\n}\n\n/** How core draws a plugin dataset. Absent, the plugin draws it from its own `map.layers`. */\nexport type PluginDatasetSource =\n | { type: 'wms'; baseUrl: string; layers: string; timeEnabled?: boolean }\n | { type: 'geojson'; getFeatures: () => Promise<PluginFeatureCollection> }\n\n/**\n * A dataset listed in the Datasets menu: under Live Data when `live`, otherwise under\n * Organizational. Applying it is the user's choice; `usePluginDataset(id)` reports it.\n */\nexport interface DatasetRegistration {\n id: string\n name: string\n description?: string\n publisher?: string\n /** A link to the dataset's documentation, shown in its details. */\n information?: string\n live?: boolean\n source?: PluginDatasetSource\n}\n\nexport interface LegendRow {\n label: string\n color: string\n count?: number\n /** With `onVisibleChange`, the row gets a switch; false dims it. */\n visible?: boolean\n onVisibleChange?: (visible: boolean) => void\n}\n\nexport interface LegendRegistration {\n id: string\n title: string\n /** Which viewers this legend appears in. Omit for all of them. */\n viewers?: Array<PluginViewerTarget | ViewerNames>\n /** A `map.datasets` id of the same plugin: the map nests this legend under that applied dataset. */\n dataset?: string\n // Called by the legend host on each render; active:false omits the section.\n useLegend: () => {\n active: boolean\n // Overrides registration.title when set, e.g. a city-scoped label.\n title?: string\n unavailable?: boolean\n rows: LegendRow[]\n /** The plugin's own inputs under the rows, such as a date slider filtering what is drawn. */\n controls?: React.ReactNode\n }\n}\n\n// --- Capability → registration type map ---\n// A new contribution point needs one entry here, its type above, and a consumer\n// calling `registry.getAll('your.key')`. No host changes.\n\nexport interface CapabilityRegistry {\n 'data.pages': DataPageRegistration\n 'viewer.tabs': ViewerTabRegistration\n 'ui.dialogs': DialogRegistration\n 'map.tools': ToolbarRegistration<MapToolProps>\n 'bim.tools': ToolbarRegistration<BimToolProps>\n 'viewer.legends': LegendRegistration\n 'map.layers': MapLayerRegistration\n 'map.datasets': DatasetRegistration\n}\n\n// Errors if VALID_CAPABILITIES and keyof CapabilityRegistry drift apart.\ntype _CapabilityParity =\n PluginCapability extends keyof CapabilityRegistry\n ? keyof CapabilityRegistry extends PluginCapability\n ? true\n : never\n : never\nconst _capabilityParity: _CapabilityParity = true\nvoid _capabilityParity\n\n// --- Plugin Context ---\n\nexport interface PluginContext {\n pluginId: string\n register<K extends keyof CapabilityRegistry>(key: K, item: CapabilityRegistry[K]): void\n config: Record<string, unknown>\n}\n\n// --- Plugin entry point type ---\n\nexport interface PluginEntry {\n // `any`: each plugin binds only the slots it uses, so no one context type fits them all.\n activate(ctx: any): void | Promise<void>\n deactivate?(ctx: any): void | Promise<void>\n}\n\n/**\n * One loadable plugin: its manifest plus its module, or a thunk returning it.\n * Prefer the thunk when compiled in — a static import pulls the plugin's\n * components into every route that reaches `installed.ts`.\n */\nexport interface PluginSource {\n manifest: PluginManifest\n entry: PluginEntry | (() => Promise<PluginEntry>)\n}\n\n/** Resolves either form of `PluginSource.entry` to the module. */\nexport async function resolvePluginEntry(\n entry: PluginSource['entry'],\n): Promise<PluginEntry> {\n return typeof entry === 'function' ? entry() : entry\n}\n\n/** An array for compiled-in plugins; a thunk when the list itself must be fetched. */\nexport type PluginsInput = PluginSource[] | (() => Promise<PluginSource[]>)\n"],"mappings":"AAQA,SAAS,mBAAmB;AAerB,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;AAkKA,MAAM,oBAAuC;AAC7C,KAAK;AA6BL,eAAsB,mBACpB,OACsB;AACtB,SAAO,OAAO,UAAU,aAAa,MAAM,IAAI;AACjD;","names":[]}
1
+ {"version":3,"sources":["../../../../src/core/plugins/sdk/types.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\n// Type-only: keeps the viewer modules' runtime deps (@thatopen, three, maplibre)\n// out of the host's module graph.\nimport type { BimToolProps } from './bimViewer'\nimport type { MapToolProps } from './mapViewer'\n// A value, not just a type: a `viewer.tabs` contribution names the viewers it belongs in.\nexport { ViewerNames } from '../../types/dbTypes'\n\nimport type { ViewerNames } from '../../types/dbTypes'\n\n/**\n * The viewers that can host a tab or a legend, spelled as plain strings. Derived from\n * `ViewerNames` so the two cannot drift, and the form `@collabdt/plugin-kit` publishes.\n */\nexport type PluginViewerTarget = `${ViewerNames.map | ViewerNames.bim}`\nimport type { LucideProps } from 'lucide-react'\n\n// --- Capability definitions ---\n\n// Only capabilities core actually renders. One with no consumer registers fine,\n// shows nothing, and leaves nothing to debug.\nexport const VALID_CAPABILITIES = [\n 'data.pages',\n 'viewer.tabs',\n 'ui.dialogs',\n 'map.tools',\n 'bim.tools',\n 'viewer.legends',\n 'map.layers',\n 'map.datasets',\n] as const\n\nexport type PluginCapability = typeof VALID_CAPABILITIES[number]\n\n// --- Manifest ---\n\nexport interface PluginManifest {\n slug: string\n name: string\n version: string\n /** The `PLUGIN_HOST_API` this plugin was built against. Omitted is warned about, not rejected. */\n hostApi?: number\n description?: string\n author?: string\n /** A lucide icon name shown beside the plugin's name. Unset or unknown shows a puzzle piece. */\n icon?: string\n capabilities: PluginCapability[]\n requiredPermissions?: string[]\n configSchema?: Record<string, unknown>\n /**\n * Strings keyed by locale then message key, e.g. `{ en: { title: 'Hello' } }`.\n * Core folds them under `plugins.<slug>`, so `t('title')` resolves and no plugin\n * can collide with another. Values may nest, addressed as `t('spaces.title')`.\n */\n messages?: Record<string, Record<string, unknown>>\n}\n\nexport function validateManifest(manifest: unknown): { valid: boolean; errors: string[] } {\n const errors: string[] = []\n\n if (typeof manifest !== 'object' || manifest === null) {\n return { valid: false, errors: ['manifest must be an object'] }\n }\n\n const m = manifest as Record<string, unknown>\n\n if (!m.slug || typeof m.slug !== 'string') errors.push('slug is required')\n if (!m.name || typeof m.name !== 'string') errors.push('name is required')\n if (!m.version || typeof m.version !== 'string') errors.push('version is required')\n\n if (m.hostApi !== undefined && !Number.isInteger(m.hostApi)) {\n errors.push('hostApi must be an integer when present')\n }\n\n if (!Array.isArray(m.capabilities) || m.capabilities.length === 0) {\n errors.push('at least one capability is required')\n } else {\n for (const cap of m.capabilities) {\n if (!VALID_CAPABILITIES.includes(cap as PluginCapability)) {\n errors.push(`invalid capability: \"${cap}\"`)\n }\n }\n }\n\n return { valid: errors.length === 0, errors }\n}\n\n// --- Registration shapes (one per capability) ---\n\nexport interface DataPageColumn<Row> {\n key: string\n /** Resolved in the plugin's own namespace, falling back to the literal string. */\n labelKey: string\n render?: (row: Row) => React.ReactNode\n}\n\n/**\n * A full page in the Datasets nav, rendered by core. The plugin declares rows and columns; a\n * row click opens one of its own `ui.dialogs` rather than a detail view of its own.\n */\nexport interface DataPageRows<Row> {\n rows: Row[]\n isLoading?: boolean\n /** From the hook, not the registration, so it can close over `usePluginDialogs`. */\n onRowClick?: (row: Row) => void\n}\n\nexport interface DataPageRegistration<Row = Record<string, unknown>> {\n id: string\n titleKey: string\n icon: string | React.ComponentType<LucideProps>\n useRows: () => DataPageRows<Row>\n columns: DataPageColumn<Row>[]\n /** Column keys the search box filters on. Omit to search every column. */\n searchKeys?: string[]\n emptyKey?: string\n}\n\n/** Every toolbar component receives the toolbar entry core built for it. */\nexport interface ToolbarToolProps {\n tool: unknown\n}\n\n/**\n * A toolbar contribution. `P` is the viewer surface the hosting toolbar passes as\n * props, bound per capability by `CapabilityRegistry` — so a BIM component\n * registered under `map.tools` is a compile error.\n */\nexport interface ToolbarRegistration<P = Record<string, unknown>> {\n id: string\n label: string\n icon: string | React.ComponentType<LucideProps>\n component: React.ComponentType<ToolbarToolProps & P>\n cursor?: string\n stayActive?: boolean\n}\n\nexport interface ViewerTabRegistration {\n id: string\n labelKey: string\n icon: string | React.ComponentType<LucideProps>\n component: React.ComponentType\n /** Which viewers this tab appears in. Omit for all of them. */\n viewers?: Array<PluginViewerTarget | ViewerNames>\n}\n\n/**\n * A modal core owns. Registered here, opened by id from any of the plugin's surfaces via\n * `usePluginDialogs()`, so it outlives whichever one opened it.\n */\nexport interface DialogRegistration<P = Record<string, unknown>> {\n id: string\n titleKey: string\n size?: 'sm' | 'md' | 'lg' | 'xl'\n component: React.ComponentType<P & { close: () => void }>\n}\n\n/**\n * Something drawn on the map, mounted for as long as the map. Separate from `map.tools`,\n * whose panel unmounts when its dropdown closes and would take the layer with it.\n */\nexport interface MapLayerRegistration {\n id: string\n component: React.ComponentType<MapToolProps>\n}\n\n/** The least of a GeoJSON FeatureCollection core needs, so a typed `geojson` one satisfies it. */\nexport interface PluginFeatureCollection {\n type: 'FeatureCollection'\n features: Array<{\n type: 'Feature'\n id?: string | number\n geometry: { type: string; coordinates?: unknown; geometries?: unknown } | null\n properties: Record<string, unknown> | null\n }>\n}\n\n/** How core draws a plugin dataset. Absent, the plugin draws it from its own `map.layers`. */\nexport type PluginDatasetSource =\n | { type: 'wms'; baseUrl: string; layers: string; timeEnabled?: boolean }\n | { type: 'geojson'; getFeatures: () => Promise<PluginFeatureCollection> }\n\n/**\n * A dataset listed in the Datasets menu: under Live Data when `live`, otherwise under\n * Organizational. `usePluginDataset(id)` reports whether it is applied and can apply or remove it.\n */\nexport interface DatasetRegistration {\n id: string\n name: string\n description?: string\n publisher?: string\n /** A link to the dataset's documentation, shown in its details. */\n information?: string\n live?: boolean\n source?: PluginDatasetSource\n}\n\nexport interface LegendRow {\n label: string\n color: string\n count?: number\n /** With `onVisibleChange`, the row gets a switch; false dims it. */\n visible?: boolean\n onVisibleChange?: (visible: boolean) => void\n}\n\nexport interface LegendRegistration {\n id: string\n title: string\n /** Which viewers this legend appears in. Omit for all of them. */\n viewers?: Array<PluginViewerTarget | ViewerNames>\n /** A `map.datasets` id of the same plugin: the map nests this legend under that applied dataset. */\n dataset?: string\n // Called by the legend host on each render; active:false omits the section.\n useLegend: () => {\n active: boolean\n // Overrides registration.title when set, e.g. a city-scoped label.\n title?: string\n unavailable?: boolean\n rows: LegendRow[]\n /** The plugin's own inputs under the rows, such as a date slider filtering what is drawn. */\n controls?: React.ReactNode\n }\n}\n\n// --- Capability → registration type map ---\n// A new contribution point needs one entry here, its type above, and a consumer\n// calling `registry.getAll('your.key')`. No host changes.\n\nexport interface CapabilityRegistry {\n 'data.pages': DataPageRegistration\n 'viewer.tabs': ViewerTabRegistration\n 'ui.dialogs': DialogRegistration\n 'map.tools': ToolbarRegistration<MapToolProps>\n 'bim.tools': ToolbarRegistration<BimToolProps>\n 'viewer.legends': LegendRegistration\n 'map.layers': MapLayerRegistration\n 'map.datasets': DatasetRegistration\n}\n\n// Errors if VALID_CAPABILITIES and keyof CapabilityRegistry drift apart.\ntype _CapabilityParity =\n PluginCapability extends keyof CapabilityRegistry\n ? keyof CapabilityRegistry extends PluginCapability\n ? true\n : never\n : never\nconst _capabilityParity: _CapabilityParity = true\nvoid _capabilityParity\n\n// --- Plugin Context ---\n\nexport interface PluginContext {\n pluginId: string\n register<K extends keyof CapabilityRegistry>(key: K, item: CapabilityRegistry[K]): void\n config: Record<string, unknown>\n}\n\n// --- Plugin entry point type ---\n\nexport interface PluginEntry {\n // `any`: each plugin binds only the slots it uses, so no one context type fits them all.\n activate(ctx: any): void | Promise<void>\n deactivate?(ctx: any): void | Promise<void>\n}\n\n/**\n * One loadable plugin: its manifest plus its module, or a thunk returning it.\n * Prefer the thunk when compiled in — a static import pulls the plugin's\n * components into every route that reaches `installed.ts`.\n */\nexport interface PluginSource {\n manifest: PluginManifest\n entry: PluginEntry | (() => Promise<PluginEntry>)\n}\n\n/** Resolves either form of `PluginSource.entry` to the module. */\nexport async function resolvePluginEntry(\n entry: PluginSource['entry'],\n): Promise<PluginEntry> {\n return typeof entry === 'function' ? entry() : entry\n}\n\n/** An array for compiled-in plugins; a thunk when the list itself must be fetched. */\nexport type PluginsInput = PluginSource[] | (() => Promise<PluginSource[]>)\n"],"mappings":"AAQA,SAAS,mBAAmB;AAerB,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;AAkKA,MAAM,oBAAuC;AAC7C,KAAK;AA6BL,eAAsB,mBACpB,OACsB;AACtB,SAAO,OAAO,UAAU,aAAa,MAAM,IAAI;AACjD;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@collabdt/core",
3
- "version": "0.13.2",
3
+ "version": "0.13.3",
4
4
  "description": "CDT Core contains all the core technology for your CDT platform",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",