@cohesivesystems/presentation-react 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +55 -0
- package/dist/collection-chrome-slot-renderer-registry.d.ts +12 -0
- package/dist/collection-chrome-slot-renderer-registry.d.ts.map +1 -0
- package/dist/collection-chrome-slot-renderer-registry.js +12 -0
- package/dist/collection-chrome-slot-renderer-registry.js.map +1 -0
- package/dist/collection-selection-state-context.d.ts +6 -0
- package/dist/collection-selection-state-context.d.ts.map +1 -0
- package/dist/collection-selection-state-context.js +25 -0
- package/dist/collection-selection-state-context.js.map +1 -0
- package/dist/collection-selection-state.d.ts +3 -0
- package/dist/collection-selection-state.d.ts.map +1 -0
- package/dist/collection-selection-state.js +52 -0
- package/dist/collection-selection-state.js.map +1 -0
- package/dist/document-workspace-runtime.d.ts +262 -0
- package/dist/document-workspace-runtime.d.ts.map +1 -0
- package/dist/document-workspace-runtime.js +699 -0
- package/dist/document-workspace-runtime.js.map +1 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/input-form-endpoint-runtime.d.ts +140 -0
- package/dist/input-form-endpoint-runtime.d.ts.map +1 -0
- package/dist/input-form-endpoint-runtime.js +280 -0
- package/dist/input-form-endpoint-runtime.js.map +1 -0
- package/dist/local-flow-state-data-source-projection.d.ts +21 -0
- package/dist/local-flow-state-data-source-projection.d.ts.map +1 -0
- package/dist/local-flow-state-data-source-projection.js +65 -0
- package/dist/local-flow-state-data-source-projection.js.map +1 -0
- package/dist/navigation-runtime-context.d.ts +22 -0
- package/dist/navigation-runtime-context.d.ts.map +1 -0
- package/dist/navigation-runtime-context.js +23 -0
- package/dist/navigation-runtime-context.js.map +1 -0
- package/dist/navigation-shell-frame-renderer-registry.d.ts +20 -0
- package/dist/navigation-shell-frame-renderer-registry.d.ts.map +1 -0
- package/dist/navigation-shell-frame-renderer-registry.js +9 -0
- package/dist/navigation-shell-frame-renderer-registry.js.map +1 -0
- package/dist/navigation-shell-region-component-registry.d.ts +50 -0
- package/dist/navigation-shell-region-component-registry.d.ts.map +1 -0
- package/dist/navigation-shell-region-component-registry.js +44 -0
- package/dist/navigation-shell-region-component-registry.js.map +1 -0
- package/dist/navigation-shell-slot-renderer-registry.d.ts +22 -0
- package/dist/navigation-shell-slot-renderer-registry.d.ts.map +1 -0
- package/dist/navigation-shell-slot-renderer-registry.js +9 -0
- package/dist/navigation-shell-slot-renderer-registry.js.map +1 -0
- package/dist/page-host-projection.d.ts +127 -0
- package/dist/page-host-projection.d.ts.map +1 -0
- package/dist/page-host-projection.js +59 -0
- package/dist/page-host-projection.js.map +1 -0
- package/dist/page-host-renderer-registry.d.ts +72 -0
- package/dist/page-host-renderer-registry.d.ts.map +1 -0
- package/dist/page-host-renderer-registry.js +63 -0
- package/dist/page-host-renderer-registry.js.map +1 -0
- package/dist/presentation-action-group-runtime-options.d.ts +36 -0
- package/dist/presentation-action-group-runtime-options.d.ts.map +1 -0
- package/dist/presentation-action-group-runtime-options.js +50 -0
- package/dist/presentation-action-group-runtime-options.js.map +1 -0
- package/dist/presentation-action-runtime.d.ts +52 -0
- package/dist/presentation-action-runtime.d.ts.map +1 -0
- package/dist/presentation-action-runtime.js +78 -0
- package/dist/presentation-action-runtime.js.map +1 -0
- package/dist/presentation-data-source-binding-runtime.d.ts +3 -0
- package/dist/presentation-data-source-binding-runtime.d.ts.map +1 -0
- package/dist/presentation-data-source-binding-runtime.js +65 -0
- package/dist/presentation-data-source-binding-runtime.js.map +1 -0
- package/dist/presentation-data-source-binding.d.ts +12 -0
- package/dist/presentation-data-source-binding.d.ts.map +1 -0
- package/dist/presentation-data-source-binding.js +13 -0
- package/dist/presentation-data-source-binding.js.map +1 -0
- package/dist/presentation-flow-runtime.d.ts +139 -0
- package/dist/presentation-flow-runtime.d.ts.map +1 -0
- package/dist/presentation-flow-runtime.js +514 -0
- package/dist/presentation-flow-runtime.js.map +1 -0
- package/dist/presentation-module-context.d.ts +4 -0
- package/dist/presentation-module-context.d.ts.map +1 -0
- package/dist/presentation-module-context.js +6 -0
- package/dist/presentation-module-context.js.map +1 -0
- package/dist/presentation-module-provider.d.ts +7 -0
- package/dist/presentation-module-provider.d.ts.map +1 -0
- package/dist/presentation-module-provider.js +7 -0
- package/dist/presentation-module-provider.js.map +1 -0
- package/dist/presentation-projection-diagnostics-context.d.ts +8 -0
- package/dist/presentation-projection-diagnostics-context.d.ts.map +1 -0
- package/dist/presentation-projection-diagnostics-context.js +3 -0
- package/dist/presentation-projection-diagnostics-context.js.map +1 -0
- package/dist/presentation-projection-diagnostics-hooks.d.ts +4 -0
- package/dist/presentation-projection-diagnostics-hooks.d.ts.map +1 -0
- package/dist/presentation-projection-diagnostics-hooks.js +17 -0
- package/dist/presentation-projection-diagnostics-hooks.js.map +1 -0
- package/dist/presentation-projection-diagnostics-runtime.d.ts +12 -0
- package/dist/presentation-projection-diagnostics-runtime.d.ts.map +1 -0
- package/dist/presentation-projection-diagnostics-runtime.js +54 -0
- package/dist/presentation-projection-diagnostics-runtime.js.map +1 -0
- package/dist/presentation-projection-trace.d.ts +27 -0
- package/dist/presentation-projection-trace.d.ts.map +1 -0
- package/dist/presentation-projection-trace.js +54 -0
- package/dist/presentation-projection-trace.js.map +1 -0
- package/dist/presentation-query-form-runtime.d.ts +30 -0
- package/dist/presentation-query-form-runtime.d.ts.map +1 -0
- package/dist/presentation-query-form-runtime.js +75 -0
- package/dist/presentation-query-form-runtime.js.map +1 -0
- package/dist/presentation-query-form-state-adapter-registry.d.ts +4 -0
- package/dist/presentation-query-form-state-adapter-registry.d.ts.map +1 -0
- package/dist/presentation-query-form-state-adapter-registry.js +13 -0
- package/dist/presentation-query-form-state-adapter-registry.js.map +1 -0
- package/dist/presentation-query-form-state-context.d.ts +20 -0
- package/dist/presentation-query-form-state-context.d.ts.map +1 -0
- package/dist/presentation-query-form-state-context.js +20 -0
- package/dist/presentation-query-form-state-context.js.map +1 -0
- package/dist/presentation-query-form-state.d.ts +29 -0
- package/dist/presentation-query-form-state.d.ts.map +1 -0
- package/dist/presentation-query-form-state.js +99 -0
- package/dist/presentation-query-form-state.js.map +1 -0
- package/dist/presentation-renderer-registry.d.ts +109 -0
- package/dist/presentation-renderer-registry.d.ts.map +1 -0
- package/dist/presentation-renderer-registry.js +25 -0
- package/dist/presentation-renderer-registry.js.map +1 -0
- package/dist/presentation-standards-context.d.ts +4 -0
- package/dist/presentation-standards-context.d.ts.map +1 -0
- package/dist/presentation-standards-context.js +12 -0
- package/dist/presentation-standards-context.js.map +1 -0
- package/dist/presentation-standards-provider.d.ts +14 -0
- package/dist/presentation-standards-provider.d.ts.map +1 -0
- package/dist/presentation-standards-provider.js +16 -0
- package/dist/presentation-standards-provider.js.map +1 -0
- package/dist/projected-document-action-runtime-bindings.d.ts +20 -0
- package/dist/projected-document-action-runtime-bindings.d.ts.map +1 -0
- package/dist/projected-document-action-runtime-bindings.js +88 -0
- package/dist/projected-document-action-runtime-bindings.js.map +1 -0
- package/dist/projected-document-action-runtime.d.ts +76 -0
- package/dist/projected-document-action-runtime.d.ts.map +1 -0
- package/dist/projected-document-action-runtime.js +224 -0
- package/dist/projected-document-action-runtime.js.map +1 -0
- package/dist/projected-document-process-preview-action-runtime-bindings.d.ts +26 -0
- package/dist/projected-document-process-preview-action-runtime-bindings.d.ts.map +1 -0
- package/dist/projected-document-process-preview-action-runtime-bindings.js +106 -0
- package/dist/projected-document-process-preview-action-runtime-bindings.js.map +1 -0
- package/dist/projected-document-process-preview-action-runtime.d.ts +321 -0
- package/dist/projected-document-process-preview-action-runtime.d.ts.map +1 -0
- package/dist/projected-document-process-preview-action-runtime.js +729 -0
- package/dist/projected-document-process-preview-action-runtime.js.map +1 -0
- package/dist/projected-document-process-preview-capability-runtime.d.ts +47 -0
- package/dist/projected-document-process-preview-capability-runtime.d.ts.map +1 -0
- package/dist/projected-document-process-preview-capability-runtime.js +49 -0
- package/dist/projected-document-process-preview-capability-runtime.js.map +1 -0
- package/dist/projected-document-workspace-action-runtime.d.ts +87 -0
- package/dist/projected-document-workspace-action-runtime.d.ts.map +1 -0
- package/dist/projected-document-workspace-action-runtime.js +150 -0
- package/dist/projected-document-workspace-action-runtime.js.map +1 -0
- package/dist/projected-document-workspace-projection-renderer-diagnostics.d.ts +18 -0
- package/dist/projected-document-workspace-projection-renderer-diagnostics.d.ts.map +1 -0
- package/dist/projected-document-workspace-projection-renderer-diagnostics.js +207 -0
- package/dist/projected-document-workspace-projection-renderer-diagnostics.js.map +1 -0
- package/dist/projected-document-workspace-runtime-binding-diagnostics.d.ts +19 -0
- package/dist/projected-document-workspace-runtime-binding-diagnostics.d.ts.map +1 -0
- package/dist/projected-document-workspace-runtime-binding-diagnostics.js +124 -0
- package/dist/projected-document-workspace-runtime-binding-diagnostics.js.map +1 -0
- package/dist/projected-navigation-provider.d.ts +16 -0
- package/dist/projected-navigation-provider.d.ts.map +1 -0
- package/dist/projected-navigation-provider.js +51 -0
- package/dist/projected-navigation-provider.js.map +1 -0
- package/dist/projected-presentation-flow-host.d.ts +16 -0
- package/dist/projected-presentation-flow-host.d.ts.map +1 -0
- package/dist/projected-presentation-flow-host.js +14 -0
- package/dist/projected-presentation-flow-host.js.map +1 -0
- package/dist/projected-query-form-state-adapter.d.ts +12 -0
- package/dist/projected-query-form-state-adapter.d.ts.map +1 -0
- package/dist/projected-query-form-state-adapter.js +361 -0
- package/dist/projected-query-form-state-adapter.js.map +1 -0
- package/dist/react-router-binding.d.ts +133 -0
- package/dist/react-router-binding.d.ts.map +1 -0
- package/dist/react-router-binding.js +76 -0
- package/dist/react-router-binding.js.map +1 -0
- package/dist/react-router-path.d.ts +4 -0
- package/dist/react-router-path.d.ts.map +1 -0
- package/dist/react-router-path.js +11 -0
- package/dist/react-router-path.js.map +1 -0
- package/dist/scope-selection-context.d.ts +28 -0
- package/dist/scope-selection-context.d.ts.map +1 -0
- package/dist/scope-selection-context.js +13 -0
- package/dist/scope-selection-context.js.map +1 -0
- package/dist/scope-selection-provider.d.ts +33 -0
- package/dist/scope-selection-provider.d.ts.map +1 -0
- package/dist/scope-selection-provider.js +162 -0
- package/dist/scope-selection-provider.js.map +1 -0
- package/dist/scope-selection-request.d.ts +6 -0
- package/dist/scope-selection-request.d.ts.map +1 -0
- package/dist/scope-selection-request.js +12 -0
- package/dist/scope-selection-request.js.map +1 -0
- package/dist/standard-navigation-shell-frame-renderers.d.ts +15 -0
- package/dist/standard-navigation-shell-frame-renderers.d.ts.map +1 -0
- package/dist/standard-navigation-shell-frame-renderers.js +22 -0
- package/dist/standard-navigation-shell-frame-renderers.js.map +1 -0
- package/dist/standard-navigation-shell-slot-renderers.d.ts +59 -0
- package/dist/standard-navigation-shell-slot-renderers.d.ts.map +1 -0
- package/dist/standard-navigation-shell-slot-renderers.js +67 -0
- package/dist/standard-navigation-shell-slot-renderers.js.map +1 -0
- package/dist/view-chrome-slot-renderer-registry.d.ts +12 -0
- package/dist/view-chrome-slot-renderer-registry.d.ts.map +1 -0
- package/dist/view-chrome-slot-renderer-registry.js +12 -0
- package/dist/view-chrome-slot-renderer-registry.js.map +1 -0
- package/package.json +60 -0
- package/src/collection-chrome-slot-renderer-registry.ts +66 -0
- package/src/collection-selection-state-context.ts +51 -0
- package/src/collection-selection-state.tsx +101 -0
- package/src/document-workspace-runtime.tsx +1505 -0
- package/src/index.ts +50 -0
- package/src/input-form-endpoint-runtime.ts +632 -0
- package/src/local-flow-state-data-source-projection.ts +133 -0
- package/src/navigation-runtime-context.ts +40 -0
- package/src/navigation-shell-frame-renderer-registry.ts +54 -0
- package/src/navigation-shell-region-component-registry.tsx +127 -0
- package/src/navigation-shell-slot-renderer-registry.ts +88 -0
- package/src/page-host-projection.ts +356 -0
- package/src/page-host-renderer-registry.tsx +353 -0
- package/src/presentation-action-group-runtime-options.ts +121 -0
- package/src/presentation-action-runtime.ts +190 -0
- package/src/presentation-data-source-binding-runtime.ts +109 -0
- package/src/presentation-data-source-binding.tsx +24 -0
- package/src/presentation-flow-runtime.tsx +835 -0
- package/src/presentation-module-context.ts +10 -0
- package/src/presentation-module-provider.tsx +19 -0
- package/src/presentation-projection-diagnostics-context.ts +17 -0
- package/src/presentation-projection-diagnostics-hooks.ts +29 -0
- package/src/presentation-projection-diagnostics-runtime.tsx +95 -0
- package/src/presentation-projection-trace.ts +117 -0
- package/src/presentation-query-form-runtime.ts +148 -0
- package/src/presentation-query-form-state-adapter-registry.ts +25 -0
- package/src/presentation-query-form-state-context.ts +56 -0
- package/src/presentation-query-form-state.tsx +250 -0
- package/src/presentation-renderer-registry.ts +214 -0
- package/src/presentation-standards-context.ts +21 -0
- package/src/presentation-standards-provider.tsx +44 -0
- package/src/projected-document-action-runtime-bindings.ts +132 -0
- package/src/projected-document-action-runtime.ts +414 -0
- package/src/projected-document-process-preview-action-runtime-bindings.ts +231 -0
- package/src/projected-document-process-preview-action-runtime.ts +1725 -0
- package/src/projected-document-process-preview-capability-runtime.ts +216 -0
- package/src/projected-document-workspace-action-runtime.ts +402 -0
- package/src/projected-document-workspace-projection-renderer-diagnostics.ts +342 -0
- package/src/projected-document-workspace-runtime-binding-diagnostics.ts +208 -0
- package/src/projected-navigation-provider.tsx +104 -0
- package/src/projected-presentation-flow-host.tsx +46 -0
- package/src/projected-query-form-state-adapter.ts +578 -0
- package/src/react-router-binding.tsx +417 -0
- package/src/react-router-path.ts +16 -0
- package/src/scope-selection-context.ts +58 -0
- package/src/scope-selection-provider.tsx +324 -0
- package/src/scope-selection-request.ts +21 -0
- package/src/standard-navigation-shell-frame-renderers.tsx +106 -0
- package/src/standard-navigation-shell-slot-renderers.tsx +289 -0
- package/src/view-chrome-slot-renderer-registry.ts +66 -0
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/* eslint-disable react-refresh/only-export-components */
|
|
3
|
+
import { createContext, useCallback, useContext, useMemo, useState, } from 'react';
|
|
4
|
+
import { findPresentationDocumentProfile, findPresentationView, findPresentationWorkspace, } from '@cohesivesystems/presentation-core';
|
|
5
|
+
import { usePresentationModule } from './presentation-module-context.js';
|
|
6
|
+
import { createPresentationEnumDiscriminator, findPresentationComponentBinding, matchesPresentationEnum, } from '@cohesivesystems/presentation-core';
|
|
7
|
+
import { coordinationActionKinds, coordinationTriggerKinds, presentationBindingKinds, presentationTargetKinds, projectionKindLabels, projectionSubjectKindLabels, semanticReferenceKindLabels, } from '@cohesivesystems/presentation-contracts';
|
|
8
|
+
const DocumentWorkspaceRuntimeContext = createContext(null);
|
|
9
|
+
/**
|
|
10
|
+
* Resolves the document workspace declared by the presentation IR and provides
|
|
11
|
+
* the active client-side runtime snapshot to projection renderers. This is the
|
|
12
|
+
* point where a route page becomes a semantic workspace instance.
|
|
13
|
+
*/
|
|
14
|
+
export function DocumentWorkspaceRuntime({ children, documentInstanceId, fallback = null, pageViewId, }) {
|
|
15
|
+
const module = usePresentationModule();
|
|
16
|
+
const resolution = useMemo(() => resolveDocumentWorkspace(module, pageViewId), [module, pageViewId]);
|
|
17
|
+
const documentProfile = resolution?.documentProfile ?? null;
|
|
18
|
+
const projections = useMemo(() => documentProfile?.Projections ?? [], [documentProfile]);
|
|
19
|
+
const initialProjectionIds = useMemo(() => resolveInitialProjectionIds(resolution?.workspaceRef ?? null, projections), [projections, resolution?.workspaceRef]);
|
|
20
|
+
const projectionViewIds = useMemo(() => initialProjectionIds
|
|
21
|
+
.map((projectionId) => projections.find((projection) => projection.Id === projectionId))
|
|
22
|
+
.map((projection) => projection?.ViewId ?? projection?.Id ?? null)
|
|
23
|
+
.filter((viewId) => Boolean(viewId)), [initialProjectionIds, projections]);
|
|
24
|
+
const defaultProjectionId = initialProjectionIds[0] ?? projections[0]?.Id ?? null;
|
|
25
|
+
// Scope runtime state to the semantic workspace/profile and the concrete
|
|
26
|
+
// document instance so navigating between documents does not leak state.
|
|
27
|
+
const instanceKey = [
|
|
28
|
+
resolution?.workspaceRef.WorkspaceId ?? pageViewId,
|
|
29
|
+
resolution?.documentProfile.Id ?? 'default',
|
|
30
|
+
documentInstanceId ?? 'transient',
|
|
31
|
+
].join(':');
|
|
32
|
+
const [activeProjectionState, setActiveProjectionState] = useState(() => ({ instanceKey, projectionId: defaultProjectionId }));
|
|
33
|
+
const [layoutState, setLayoutState] = useState(() => ({
|
|
34
|
+
instanceKey,
|
|
35
|
+
value: resolveDefaultLayout(resolution?.documentProfile.Layout ?? null),
|
|
36
|
+
}));
|
|
37
|
+
const [runtimeState, setRuntimeState] = useState(() => ({ instanceKey, value: createInitialRuntimeState() }));
|
|
38
|
+
const runtimeStateValue = runtimeState.instanceKey === instanceKey
|
|
39
|
+
? runtimeState.value
|
|
40
|
+
: createInitialRuntimeState();
|
|
41
|
+
const coordinationDefinitions = resolution?.documentProfile.Coordination;
|
|
42
|
+
const coordination = useMemo(() => coordinationDefinitions ?? [], [coordinationDefinitions]);
|
|
43
|
+
const setTreeExpandedItemIds = useCallback((projectionId, value) => {
|
|
44
|
+
setRuntimeState((current) => updateRuntimeTreeState(current, instanceKey, projectionId, (treeState) => ({
|
|
45
|
+
...treeState,
|
|
46
|
+
expandedItemIds: applySetStateAction(value, treeState.expandedItemIds),
|
|
47
|
+
})));
|
|
48
|
+
}, [instanceKey]);
|
|
49
|
+
const setTreeNavigationHistory = useCallback((projectionId, value) => {
|
|
50
|
+
setRuntimeState((current) => updateRuntimeTreeState(current, instanceKey, projectionId, (treeState) => ({
|
|
51
|
+
...treeState,
|
|
52
|
+
navigationHistory: applySetStateAction(value, treeState.navigationHistory),
|
|
53
|
+
})));
|
|
54
|
+
}, [instanceKey]);
|
|
55
|
+
const setTreeSearch = useCallback((projectionId, value) => {
|
|
56
|
+
setRuntimeState((current) => updateRuntimeTreeState(current, instanceKey, projectionId, (treeState) => ({
|
|
57
|
+
...treeState,
|
|
58
|
+
search: applySetStateAction(value, treeState.search),
|
|
59
|
+
})));
|
|
60
|
+
}, [instanceKey]);
|
|
61
|
+
const selectSemanticReference = useCallback((selection) => {
|
|
62
|
+
setRuntimeState((current) => {
|
|
63
|
+
const base = current.instanceKey === instanceKey
|
|
64
|
+
? current.value
|
|
65
|
+
: createInitialRuntimeState();
|
|
66
|
+
return {
|
|
67
|
+
instanceKey,
|
|
68
|
+
value: {
|
|
69
|
+
...base,
|
|
70
|
+
semanticSelections: createCoordinatedSemanticSelections(selection, coordination),
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
}, [coordination, instanceKey]);
|
|
75
|
+
const contextValue = useMemo(() => ({
|
|
76
|
+
coordination,
|
|
77
|
+
instanceKey,
|
|
78
|
+
selectSemanticReference,
|
|
79
|
+
setTreeExpandedItemIds,
|
|
80
|
+
setTreeNavigationHistory,
|
|
81
|
+
setTreeSearch,
|
|
82
|
+
state: runtimeStateValue,
|
|
83
|
+
}), [
|
|
84
|
+
coordination,
|
|
85
|
+
instanceKey,
|
|
86
|
+
runtimeStateValue,
|
|
87
|
+
selectSemanticReference,
|
|
88
|
+
setTreeExpandedItemIds,
|
|
89
|
+
setTreeNavigationHistory,
|
|
90
|
+
setTreeSearch,
|
|
91
|
+
]);
|
|
92
|
+
if (!resolution || !defaultProjectionId) {
|
|
93
|
+
return _jsx(_Fragment, { children: fallback });
|
|
94
|
+
}
|
|
95
|
+
const activeProjectionId = activeProjectionState.instanceKey === instanceKey &&
|
|
96
|
+
activeProjectionState.projectionId &&
|
|
97
|
+
initialProjectionIds.includes(activeProjectionState.projectionId)
|
|
98
|
+
? activeProjectionState.projectionId
|
|
99
|
+
: defaultProjectionId;
|
|
100
|
+
const activeProjection = projections.find((projection) => projection.Id === activeProjectionId) ?? null;
|
|
101
|
+
const activeViewId = activeProjection?.ViewId ?? activeProjection?.Id ?? null;
|
|
102
|
+
const layout = layoutState.instanceKey === instanceKey
|
|
103
|
+
? layoutState.value
|
|
104
|
+
: resolveDefaultLayout(resolution.documentProfile.Layout ?? null);
|
|
105
|
+
const activeLayoutModeId = resolveActiveLayoutModeId(layout, resolution.documentProfile.Layout ?? null);
|
|
106
|
+
function setActiveViewId(viewId) {
|
|
107
|
+
const projection = projections.find((candidate) => candidate.ViewId === viewId || candidate.Id === viewId);
|
|
108
|
+
if (!projection) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
setActiveProjectionState({ instanceKey, projectionId: projection.Id });
|
|
112
|
+
}
|
|
113
|
+
function setLayout(value) {
|
|
114
|
+
setLayoutState({ instanceKey, value });
|
|
115
|
+
}
|
|
116
|
+
const snapshot = {
|
|
117
|
+
activeLayoutModeId,
|
|
118
|
+
activeProjection,
|
|
119
|
+
activeProjectionId,
|
|
120
|
+
activeViewId,
|
|
121
|
+
documentProfile: resolution.documentProfile,
|
|
122
|
+
initialProjectionIds,
|
|
123
|
+
instanceKey,
|
|
124
|
+
layout,
|
|
125
|
+
pageView: resolution.pageView,
|
|
126
|
+
projectionViewIds,
|
|
127
|
+
projections,
|
|
128
|
+
setActiveViewId,
|
|
129
|
+
setLayout,
|
|
130
|
+
state: runtimeStateValue,
|
|
131
|
+
workspace: resolution.workspace,
|
|
132
|
+
workspaceRef: resolution.workspaceRef,
|
|
133
|
+
workspaceView: resolution.workspaceView,
|
|
134
|
+
};
|
|
135
|
+
return (_jsx(DocumentWorkspaceRuntimeContext.Provider, { value: contextValue, children: children(snapshot) }));
|
|
136
|
+
}
|
|
137
|
+
export function renderDocumentWorkspaceProjection(runtime, renderers, rendererContext, viewId, options) {
|
|
138
|
+
const resolution = resolveDocumentWorkspaceProjectionRenderer({
|
|
139
|
+
componentSet: options.componentSet,
|
|
140
|
+
module: options.module ?? null,
|
|
141
|
+
registry: renderers,
|
|
142
|
+
runtime,
|
|
143
|
+
viewId,
|
|
144
|
+
});
|
|
145
|
+
if (!resolution.projection || !resolution.renderer) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
return resolution.renderer({
|
|
149
|
+
componentSystem: options.componentSystem,
|
|
150
|
+
designSystem: options.designSystem,
|
|
151
|
+
extra: rendererContext,
|
|
152
|
+
projection: resolution.projection,
|
|
153
|
+
runtime,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
export function resolveDocumentWorkspaceProjectionRenderer({ componentSet, module, registry, runtime, viewId, }) {
|
|
157
|
+
// View ids are used by workspace chrome, while projection ids and renderer
|
|
158
|
+
// keys are semantic/runtime binding points. Accept either id at this boundary.
|
|
159
|
+
const projection = runtime.projections.find((candidate) => candidate.ViewId === viewId || candidate.Id === viewId);
|
|
160
|
+
if (!projection) {
|
|
161
|
+
return createDocumentProjectionRendererResolution(null);
|
|
162
|
+
}
|
|
163
|
+
const componentBinding = resolveDocumentWorkspaceProjectionComponentBinding(module ?? null, projection, componentSet);
|
|
164
|
+
const componentKey = componentBinding?.componentKey ?? null;
|
|
165
|
+
const componentRole = componentBinding?.componentRole ?? null;
|
|
166
|
+
const rendererKey = projection.RendererKey ?? null;
|
|
167
|
+
const componentRoleRenderer = componentRole
|
|
168
|
+
? registry.byComponentRole?.[componentRole]
|
|
169
|
+
: undefined;
|
|
170
|
+
if (componentRoleRenderer) {
|
|
171
|
+
return {
|
|
172
|
+
componentKey,
|
|
173
|
+
componentRole,
|
|
174
|
+
projection,
|
|
175
|
+
renderer: componentRoleRenderer,
|
|
176
|
+
rendererKey,
|
|
177
|
+
resolutionSource: 'component-role',
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const componentRenderer = componentKey
|
|
181
|
+
? registry.byComponentKey?.[componentKey]
|
|
182
|
+
: undefined;
|
|
183
|
+
if (componentRenderer) {
|
|
184
|
+
return {
|
|
185
|
+
componentKey,
|
|
186
|
+
componentRole,
|
|
187
|
+
projection,
|
|
188
|
+
renderer: componentRenderer,
|
|
189
|
+
rendererKey,
|
|
190
|
+
resolutionSource: 'component-key',
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
const semanticReferenceRenderer = findDiscriminatorRenderer(registry.bySemanticReferenceKind, projection.Coordinates?.SemanticReferenceKind, semanticReferenceKindLabels);
|
|
194
|
+
if (semanticReferenceRenderer) {
|
|
195
|
+
return {
|
|
196
|
+
componentKey,
|
|
197
|
+
componentRole,
|
|
198
|
+
projection,
|
|
199
|
+
renderer: semanticReferenceRenderer,
|
|
200
|
+
rendererKey,
|
|
201
|
+
resolutionSource: 'semantic-reference-kind',
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
const subjectKindRenderer = findDiscriminatorRenderer(registry.bySubjectKind, projection.Subject.Kind, projectionSubjectKindLabels);
|
|
205
|
+
if (subjectKindRenderer) {
|
|
206
|
+
return {
|
|
207
|
+
componentKey,
|
|
208
|
+
componentRole,
|
|
209
|
+
projection,
|
|
210
|
+
renderer: subjectKindRenderer,
|
|
211
|
+
rendererKey,
|
|
212
|
+
resolutionSource: 'subject-kind',
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const projectionKindRenderer = findDiscriminatorRenderer(registry.byProjectionKind, projection.Kind, projectionKindLabels);
|
|
216
|
+
if (projectionKindRenderer) {
|
|
217
|
+
return {
|
|
218
|
+
componentKey,
|
|
219
|
+
componentRole,
|
|
220
|
+
projection,
|
|
221
|
+
renderer: projectionKindRenderer,
|
|
222
|
+
rendererKey,
|
|
223
|
+
resolutionSource: 'projection-kind',
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const projectionIdRenderer = registry.byProjectionId?.[projection.Id];
|
|
227
|
+
if (projectionIdRenderer) {
|
|
228
|
+
return {
|
|
229
|
+
componentKey,
|
|
230
|
+
componentRole,
|
|
231
|
+
projection,
|
|
232
|
+
renderer: projectionIdRenderer,
|
|
233
|
+
rendererKey,
|
|
234
|
+
resolutionSource: 'projection-id',
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
const viewIdRenderer = projection.ViewId ? registry.byViewId?.[projection.ViewId] : undefined;
|
|
238
|
+
if (viewIdRenderer) {
|
|
239
|
+
return {
|
|
240
|
+
componentKey,
|
|
241
|
+
componentRole,
|
|
242
|
+
projection,
|
|
243
|
+
renderer: viewIdRenderer,
|
|
244
|
+
rendererKey,
|
|
245
|
+
resolutionSource: 'view-id',
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
if (registry.fallback) {
|
|
249
|
+
return {
|
|
250
|
+
componentKey,
|
|
251
|
+
componentRole,
|
|
252
|
+
projection,
|
|
253
|
+
renderer: registry.fallback,
|
|
254
|
+
rendererKey,
|
|
255
|
+
resolutionSource: 'fallback',
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
componentKey,
|
|
260
|
+
componentRole,
|
|
261
|
+
projection,
|
|
262
|
+
renderer: null,
|
|
263
|
+
rendererKey,
|
|
264
|
+
resolutionSource: null,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
export function resolveDocumentWorkspaceProjectionCapability({ capability, componentSet, module, projection, registry, }) {
|
|
268
|
+
const bindings = registry.capabilities?.[capability];
|
|
269
|
+
if (!bindings) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
const componentBinding = resolveDocumentWorkspaceProjectionComponentBinding(module ?? null, projection, componentSet);
|
|
273
|
+
const componentKey = componentBinding?.componentKey ?? null;
|
|
274
|
+
const componentRole = componentBinding?.componentRole ?? null;
|
|
275
|
+
if (componentRole && bindings.byComponentRole?.[componentRole]) {
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
if (componentKey && bindings.byComponentKey?.[componentKey]) {
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
if (findDiscriminatorRenderer(bindings.bySemanticReferenceKind, projection.Coordinates?.SemanticReferenceKind, semanticReferenceKindLabels)) {
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
if (findDiscriminatorRenderer(bindings.bySubjectKind, projection.Subject.Kind, projectionSubjectKindLabels)) {
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
if (findDiscriminatorRenderer(bindings.byProjectionKind, projection.Kind, projectionKindLabels)) {
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
return Boolean(bindings.byProjectionId?.[projection.Id] ||
|
|
291
|
+
(projection.ViewId ? bindings.byViewId?.[projection.ViewId] : false));
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Resolves the frontend renderer role and optional concrete component override
|
|
295
|
+
* declared by a presentation target binding for a document projection.
|
|
296
|
+
*/
|
|
297
|
+
function resolveDocumentWorkspaceProjectionComponentBinding(module, projection, componentSet) {
|
|
298
|
+
if (!module) {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
const binding = findPresentationComponentBinding(module, {
|
|
302
|
+
bindingKind: createPresentationEnumDiscriminator(presentationBindingKinds, 'projectionRenderer', 'ProjectionRenderer'),
|
|
303
|
+
componentSet,
|
|
304
|
+
id: projection.Id,
|
|
305
|
+
targetKind: createPresentationEnumDiscriminator(presentationTargetKinds, 'react', 'React'),
|
|
306
|
+
});
|
|
307
|
+
if (!binding) {
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
componentKey: binding.ComponentKey ?? null,
|
|
312
|
+
componentRole: binding.ComponentRole ?? null,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Shared tree-state hook for document projections. It uses workspace runtime
|
|
317
|
+
* state when mounted under DocumentWorkspaceRuntime, and falls back to local
|
|
318
|
+
* component state when a tree renderer is tested or rendered in isolation.
|
|
319
|
+
*/
|
|
320
|
+
export function useDocumentWorkspaceTreeState({ createSemanticSelection, initialExpandedItemIds, projectionId, semanticReferenceKind, }) {
|
|
321
|
+
const runtime = useContext(DocumentWorkspaceRuntimeContext);
|
|
322
|
+
const runtimeState = runtime?.state;
|
|
323
|
+
const selectSemanticReference = runtime?.selectSemanticReference;
|
|
324
|
+
const setRuntimeTreeExpandedItemIds = runtime?.setTreeExpandedItemIds;
|
|
325
|
+
const setRuntimeTreeNavigationHistory = runtime?.setTreeNavigationHistory;
|
|
326
|
+
const setRuntimeTreeSearch = runtime?.setTreeSearch;
|
|
327
|
+
const initialExpandedItemKey = initialExpandedItemIds.join('\u0000');
|
|
328
|
+
const [localExpandedItemState, setLocalExpandedItemState] = useState(() => ({
|
|
329
|
+
expandedItemIds: initialExpandedItemIds,
|
|
330
|
+
initialExpandedItemKey,
|
|
331
|
+
isUserControlled: false,
|
|
332
|
+
}));
|
|
333
|
+
const [localNavigationHistory, setLocalNavigationHistory] = useState(createInitialNavigationHistory);
|
|
334
|
+
const [localSearch, setLocalSearch] = useState(createInitialTreeSearchState);
|
|
335
|
+
const persistedTreeState = runtimeState && projectionId ? runtimeState.treeStates[projectionId] : undefined;
|
|
336
|
+
const treeState = persistedTreeState ??
|
|
337
|
+
(runtimeState && projectionId ? createInitialTreeState() : null);
|
|
338
|
+
const localExpandedItemIds = localExpandedItemState.isUserControlled ||
|
|
339
|
+
localExpandedItemState.initialExpandedItemKey === initialExpandedItemKey
|
|
340
|
+
? localExpandedItemState.expandedItemIds
|
|
341
|
+
: initialExpandedItemIds;
|
|
342
|
+
const expandedItemIds = persistedTreeState?.expandedItemIds ??
|
|
343
|
+
(runtimeState && projectionId
|
|
344
|
+
? initialExpandedItemIds
|
|
345
|
+
: localExpandedItemIds);
|
|
346
|
+
const navigationHistory = treeState?.navigationHistory ?? localNavigationHistory;
|
|
347
|
+
const search = treeState?.search ?? localSearch;
|
|
348
|
+
const setExpandedItemIds = useCallback((value) => {
|
|
349
|
+
if (setRuntimeTreeExpandedItemIds && projectionId) {
|
|
350
|
+
setRuntimeTreeExpandedItemIds(projectionId, value);
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
setLocalExpandedItemState((current) => ({
|
|
354
|
+
expandedItemIds: applySetStateAction(value, current.isUserControlled ||
|
|
355
|
+
current.initialExpandedItemKey === initialExpandedItemKey
|
|
356
|
+
? current.expandedItemIds
|
|
357
|
+
: initialExpandedItemIds),
|
|
358
|
+
initialExpandedItemKey,
|
|
359
|
+
isUserControlled: true,
|
|
360
|
+
}));
|
|
361
|
+
}
|
|
362
|
+
}, [
|
|
363
|
+
initialExpandedItemIds,
|
|
364
|
+
initialExpandedItemKey,
|
|
365
|
+
projectionId,
|
|
366
|
+
setRuntimeTreeExpandedItemIds,
|
|
367
|
+
]);
|
|
368
|
+
const setNavigationHistory = useCallback((value) => {
|
|
369
|
+
if (setRuntimeTreeNavigationHistory && projectionId) {
|
|
370
|
+
setRuntimeTreeNavigationHistory(projectionId, value);
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
setLocalNavigationHistory(value);
|
|
374
|
+
}
|
|
375
|
+
}, [projectionId, setRuntimeTreeNavigationHistory]);
|
|
376
|
+
const setSearch = useCallback((value) => {
|
|
377
|
+
if (setRuntimeTreeSearch && projectionId) {
|
|
378
|
+
setRuntimeTreeSearch(projectionId, value);
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
setLocalSearch(value);
|
|
382
|
+
}
|
|
383
|
+
}, [projectionId, setRuntimeTreeSearch]);
|
|
384
|
+
const publishSelectedItem = useCallback((itemId) => {
|
|
385
|
+
if (!selectSemanticReference || !projectionId || !itemId) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
selectSemanticReference(normalizeTreeSemanticSelection(createSemanticSelection?.(itemId) ??
|
|
389
|
+
createDefaultTreeSemanticSelection(itemId, projectionId, semanticReferenceKind), projectionId, semanticReferenceKind));
|
|
390
|
+
}, [createSemanticSelection, projectionId, selectSemanticReference, semanticReferenceKind]);
|
|
391
|
+
const semanticSelections = useMemo(() => filterSemanticSelectionsForProjection({
|
|
392
|
+
coordination: runtime?.coordination ?? [],
|
|
393
|
+
projectionId,
|
|
394
|
+
selections: runtimeState?.semanticSelections ?? [],
|
|
395
|
+
}), [projectionId, runtime?.coordination, runtimeState?.semanticSelections]);
|
|
396
|
+
return {
|
|
397
|
+
expandedItemIds,
|
|
398
|
+
navigationHistory,
|
|
399
|
+
onSelectedItemIdChange: publishSelectedItem,
|
|
400
|
+
search,
|
|
401
|
+
semanticSelections,
|
|
402
|
+
setExpandedItemIds,
|
|
403
|
+
setNavigationHistory,
|
|
404
|
+
setSearch,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
export function useDocumentWorkspaceSemanticSelections({ projectionId, }) {
|
|
408
|
+
const runtime = useContext(DocumentWorkspaceRuntimeContext);
|
|
409
|
+
const runtimeState = runtime?.state;
|
|
410
|
+
return useMemo(() => filterSemanticSelectionsForProjection({
|
|
411
|
+
coordination: runtime?.coordination ?? [],
|
|
412
|
+
projectionId,
|
|
413
|
+
selections: runtimeState?.semanticSelections ?? [],
|
|
414
|
+
}), [projectionId, runtime?.coordination, runtimeState?.semanticSelections]);
|
|
415
|
+
}
|
|
416
|
+
export function useDocumentWorkspaceSemanticSelectionPublisher({ projectionId, semanticReferenceKind, }) {
|
|
417
|
+
const runtime = useContext(DocumentWorkspaceRuntimeContext);
|
|
418
|
+
const selectSemanticReference = runtime?.selectSemanticReference;
|
|
419
|
+
return useCallback((selection) => {
|
|
420
|
+
if (!projectionId || !selectSemanticReference) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
selectSemanticReference(normalizeTreeSemanticSelection(selection, projectionId, semanticReferenceKind));
|
|
424
|
+
}, [projectionId, selectSemanticReference, semanticReferenceKind]);
|
|
425
|
+
}
|
|
426
|
+
export function createDocumentWorkspaceSemanticPath(segments) {
|
|
427
|
+
return { Segments: segments };
|
|
428
|
+
}
|
|
429
|
+
export function createDocumentWorkspaceSemanticReference({ id, kind, label, path, }) {
|
|
430
|
+
return {
|
|
431
|
+
Id: id,
|
|
432
|
+
Kind: kind,
|
|
433
|
+
Path: path ??
|
|
434
|
+
createDocumentWorkspaceSemanticPath([
|
|
435
|
+
{
|
|
436
|
+
Id: id,
|
|
437
|
+
Kind: kind,
|
|
438
|
+
Label: label ?? id,
|
|
439
|
+
},
|
|
440
|
+
]),
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
export function documentWorkspaceSemanticReferenceMatchesSelection(reference, selection) {
|
|
444
|
+
return (semanticReferencesMatch(reference, selection.Target) ||
|
|
445
|
+
semanticPathMatches(reference.Path ?? null, selection.SemanticPath ?? null) ||
|
|
446
|
+
semanticPathMatches(reference.Path ?? null, selection.Target.Path ?? null) ||
|
|
447
|
+
semanticPathContainsReference(selection.SemanticPath ?? null, reference) ||
|
|
448
|
+
semanticPathContainsReference(selection.Target.Path ?? null, reference));
|
|
449
|
+
}
|
|
450
|
+
export function findDocumentWorkspaceSemanticTreeItemId(selection, nodes) {
|
|
451
|
+
for (const node of nodes) {
|
|
452
|
+
const references = [
|
|
453
|
+
node.semanticReference,
|
|
454
|
+
...(node.relatedSemanticReferences ?? []),
|
|
455
|
+
];
|
|
456
|
+
if (references.some((reference) => documentWorkspaceSemanticReferenceMatchesSelection(reference, selection))) {
|
|
457
|
+
return node.itemId;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
function resolveDocumentWorkspace(module, pageViewId) {
|
|
463
|
+
// A route addresses a page view. The workspace may be the page itself or a
|
|
464
|
+
// hosted child surface within one of the page regions.
|
|
465
|
+
const pageView = findPresentationView(module, pageViewId);
|
|
466
|
+
if (!pageView) {
|
|
467
|
+
return null;
|
|
468
|
+
}
|
|
469
|
+
const workspaceView = findWorkspaceHostView(module, pageView);
|
|
470
|
+
const workspaceRef = workspaceView?.Workspace ?? null;
|
|
471
|
+
if (!workspaceView || !workspaceRef) {
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
474
|
+
const workspace = findPresentationWorkspace(module, workspaceRef.WorkspaceId);
|
|
475
|
+
if (!workspace) {
|
|
476
|
+
return null;
|
|
477
|
+
}
|
|
478
|
+
const documentProfileId = workspaceRef.DocumentProfileId ??
|
|
479
|
+
workspace.DefaultDocumentProfileId ??
|
|
480
|
+
workspace.DocumentProfiles?.[0]?.Id ??
|
|
481
|
+
null;
|
|
482
|
+
const documentProfile = documentProfileId
|
|
483
|
+
? findPresentationDocumentProfile(workspace, documentProfileId)
|
|
484
|
+
: null;
|
|
485
|
+
if (!documentProfile) {
|
|
486
|
+
return null;
|
|
487
|
+
}
|
|
488
|
+
return { documentProfile, pageView, workspace, workspaceRef, workspaceView };
|
|
489
|
+
}
|
|
490
|
+
function findWorkspaceHostView(module, pageView) {
|
|
491
|
+
if (pageView?.Workspace) {
|
|
492
|
+
return pageView;
|
|
493
|
+
}
|
|
494
|
+
for (const region of pageView?.Regions ?? []) {
|
|
495
|
+
for (const viewId of region.ViewIds ?? []) {
|
|
496
|
+
const view = findPresentationView(module, viewId);
|
|
497
|
+
if (view?.Workspace) {
|
|
498
|
+
return view;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return null;
|
|
503
|
+
}
|
|
504
|
+
function resolveInitialProjectionIds(workspaceRef, projections) {
|
|
505
|
+
// Workspace refs can narrow the active profile to a preferred projection set.
|
|
506
|
+
// If that declaration is absent or stale, expose every profile projection.
|
|
507
|
+
const projectionIds = new Set(projections.map((projection) => projection.Id));
|
|
508
|
+
const initialProjectionIds = (workspaceRef?.InitialProjectionIds ?? []).filter((projectionId) => projectionIds.has(projectionId));
|
|
509
|
+
return initialProjectionIds.length > 0
|
|
510
|
+
? initialProjectionIds
|
|
511
|
+
: projections.map((projection) => projection.Id);
|
|
512
|
+
}
|
|
513
|
+
function resolveDefaultLayout(layout) {
|
|
514
|
+
return layout?.DefaultModeId === 'split' ? 'split' : 'single';
|
|
515
|
+
}
|
|
516
|
+
function resolveActiveLayoutModeId(layout, layoutDefinition) {
|
|
517
|
+
if (layout === 'split') {
|
|
518
|
+
return layoutDefinition?.Modes?.find((mode) => mode.Id.toLocaleLowerCase() === 'split')?.Id ?? 'split';
|
|
519
|
+
}
|
|
520
|
+
return layoutDefinition?.DefaultModeId ?? layoutDefinition?.Modes?.[0]?.Id ?? 'single';
|
|
521
|
+
}
|
|
522
|
+
function createInitialRuntimeState() {
|
|
523
|
+
return {
|
|
524
|
+
semanticSelections: [],
|
|
525
|
+
treeStates: {},
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
function createInitialTreeState() {
|
|
529
|
+
return {
|
|
530
|
+
expandedItemIds: [],
|
|
531
|
+
navigationHistory: createInitialNavigationHistory(),
|
|
532
|
+
search: createInitialTreeSearchState(),
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
function createInitialNavigationHistory() {
|
|
536
|
+
return { entries: [], index: -1 };
|
|
537
|
+
}
|
|
538
|
+
function createInitialTreeSearchState() {
|
|
539
|
+
return { activeMatchIndex: 0, isOpen: false, query: '' };
|
|
540
|
+
}
|
|
541
|
+
function createDefaultTreeSemanticSelection(itemId, projectionId, semanticReferenceKind) {
|
|
542
|
+
const path = createDocumentWorkspaceSemanticPath([
|
|
543
|
+
{ Id: projectionId, Kind: semanticReferenceKind, Label: projectionId },
|
|
544
|
+
{ Id: itemId, Kind: semanticReferenceKind, Label: itemId },
|
|
545
|
+
]);
|
|
546
|
+
return {
|
|
547
|
+
SourceProjectionId: projectionId,
|
|
548
|
+
SemanticPath: path,
|
|
549
|
+
Target: {
|
|
550
|
+
Id: itemId,
|
|
551
|
+
Kind: semanticReferenceKind,
|
|
552
|
+
Path: path,
|
|
553
|
+
},
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
function normalizeTreeSemanticSelection(selection, projectionId, semanticReferenceKind) {
|
|
557
|
+
const targetPath = selection.Target.Path ??
|
|
558
|
+
selection.SemanticPath ??
|
|
559
|
+
createDocumentWorkspaceSemanticPath([
|
|
560
|
+
{
|
|
561
|
+
Id: selection.Target.Id,
|
|
562
|
+
Kind: selection.Target.Kind ?? semanticReferenceKind,
|
|
563
|
+
Label: selection.Target.Id,
|
|
564
|
+
},
|
|
565
|
+
]);
|
|
566
|
+
return {
|
|
567
|
+
SourceProjectionId: selection.SourceProjectionId ?? projectionId,
|
|
568
|
+
SemanticPath: selection.SemanticPath ?? targetPath,
|
|
569
|
+
Target: {
|
|
570
|
+
...selection.Target,
|
|
571
|
+
Kind: selection.Target.Kind ?? semanticReferenceKind,
|
|
572
|
+
Path: targetPath,
|
|
573
|
+
},
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
function createCoordinatedSemanticSelections(selection, coordination) {
|
|
577
|
+
if (!hasSemanticSelectionCoordination(coordination, selection.SourceProjectionId ?? null)) {
|
|
578
|
+
return [selection];
|
|
579
|
+
}
|
|
580
|
+
return [selection];
|
|
581
|
+
}
|
|
582
|
+
function filterSemanticSelectionsForProjection({ coordination, projectionId, selections, }) {
|
|
583
|
+
if (!projectionId) {
|
|
584
|
+
return selections;
|
|
585
|
+
}
|
|
586
|
+
return selections.filter((selection) => canRevealSemanticSelectionForProjection(coordination, projectionId, selection));
|
|
587
|
+
}
|
|
588
|
+
function hasSemanticSelectionCoordination(coordination, sourceProjectionId) {
|
|
589
|
+
return coordination.some((definition) => matchesCoordinationTrigger(definition, sourceProjectionId) &&
|
|
590
|
+
matchesPresentationEnum(definition.Action.Kind, setSemanticSelectionActionKind));
|
|
591
|
+
}
|
|
592
|
+
function canRevealSemanticSelectionForProjection(coordination, projectionId, selection) {
|
|
593
|
+
const revealDefinitions = coordination.filter((definition) => matchesCoordinationTrigger(definition, selection.SourceProjectionId ?? null) &&
|
|
594
|
+
matchesPresentationEnum(definition.Action.Kind, revealSemanticSelectionActionKind));
|
|
595
|
+
if (revealDefinitions.length === 0) {
|
|
596
|
+
return true;
|
|
597
|
+
}
|
|
598
|
+
return revealDefinitions.some((definition) => definition.Action.TargetProjectionIds.includes(projectionId));
|
|
599
|
+
}
|
|
600
|
+
function matchesCoordinationTrigger(definition, sourceProjectionId) {
|
|
601
|
+
return (matchesPresentationEnum(definition.Trigger.Kind, selectionChangedTriggerKind) &&
|
|
602
|
+
(!definition.Trigger.SourceProjectionId ||
|
|
603
|
+
definition.Trigger.SourceProjectionId === sourceProjectionId));
|
|
604
|
+
}
|
|
605
|
+
function semanticReferencesMatch(left, right) {
|
|
606
|
+
return (left.Id === right.Id &&
|
|
607
|
+
semanticReferenceKindsMatch(left.Kind ?? null, right.Kind ?? null));
|
|
608
|
+
}
|
|
609
|
+
function semanticPathMatches(left, right) {
|
|
610
|
+
if (!left || !right || left.Segments.length !== right.Segments.length) {
|
|
611
|
+
return false;
|
|
612
|
+
}
|
|
613
|
+
return left.Segments.every((leftSegment, index) => {
|
|
614
|
+
const rightSegment = right.Segments[index];
|
|
615
|
+
return (leftSegment.Id === rightSegment.Id &&
|
|
616
|
+
semanticReferenceKindsMatch(leftSegment.Kind ?? null, rightSegment.Kind ?? null));
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
function semanticPathContainsReference(path, reference) {
|
|
620
|
+
return (path?.Segments.some((segment) => segment.Id === reference.Id &&
|
|
621
|
+
semanticReferenceKindsMatch(segment.Kind ?? null, reference.Kind ?? null)) ?? false);
|
|
622
|
+
}
|
|
623
|
+
function semanticReferenceKindsMatch(left, right) {
|
|
624
|
+
if (left === null || right === null) {
|
|
625
|
+
return true;
|
|
626
|
+
}
|
|
627
|
+
const leftKeys = createDiscriminatorKeys(left, semanticReferenceKindLabels);
|
|
628
|
+
const rightKeys = createDiscriminatorKeys(right, semanticReferenceKindLabels);
|
|
629
|
+
for (const key of leftKeys) {
|
|
630
|
+
if (rightKeys.has(key)) {
|
|
631
|
+
return true;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
function createDocumentProjectionRendererResolution(projection) {
|
|
637
|
+
return {
|
|
638
|
+
componentKey: null,
|
|
639
|
+
componentRole: null,
|
|
640
|
+
projection,
|
|
641
|
+
renderer: null,
|
|
642
|
+
rendererKey: projection?.RendererKey ?? null,
|
|
643
|
+
resolutionSource: null,
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
const selectionChangedTriggerKind = createPresentationEnumDiscriminator(coordinationTriggerKinds, 'selectionChanged', 'SelectionChanged');
|
|
647
|
+
const setSemanticSelectionActionKind = createPresentationEnumDiscriminator(coordinationActionKinds, 'setSemanticSelection', 'SetSemanticSelection');
|
|
648
|
+
const revealSemanticSelectionActionKind = createPresentationEnumDiscriminator(coordinationActionKinds, 'revealSemanticSelection', 'RevealSemanticSelection');
|
|
649
|
+
function findDiscriminatorRenderer(renderers, value, labels) {
|
|
650
|
+
if (!renderers || value === null || value === undefined) {
|
|
651
|
+
return undefined;
|
|
652
|
+
}
|
|
653
|
+
for (const key of createDiscriminatorKeys(value, labels)) {
|
|
654
|
+
const renderer = renderers[key];
|
|
655
|
+
if (renderer) {
|
|
656
|
+
return renderer;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
return undefined;
|
|
660
|
+
}
|
|
661
|
+
function createDiscriminatorKeys(value, labels) {
|
|
662
|
+
const keys = new Set([String(value)]);
|
|
663
|
+
const directLabel = labels[value];
|
|
664
|
+
if (directLabel) {
|
|
665
|
+
keys.add(directLabel);
|
|
666
|
+
}
|
|
667
|
+
if (typeof value === 'string') {
|
|
668
|
+
const normalizedValue = value.toLocaleLowerCase();
|
|
669
|
+
for (const [enumValue, label] of Object.entries(labels)) {
|
|
670
|
+
if (label.toLocaleLowerCase() === normalizedValue) {
|
|
671
|
+
keys.add(enumValue);
|
|
672
|
+
keys.add(label);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
return keys;
|
|
677
|
+
}
|
|
678
|
+
function updateRuntimeTreeState(current, instanceKey, projectionId, update) {
|
|
679
|
+
// Treat an instance-key change as a new workspace session. This prevents tree
|
|
680
|
+
// state from one document/profile from being reused by another.
|
|
681
|
+
const base = current.instanceKey === instanceKey ? current.value : createInitialRuntimeState();
|
|
682
|
+
const currentTreeState = base.treeStates[projectionId] ?? createInitialTreeState();
|
|
683
|
+
return {
|
|
684
|
+
instanceKey,
|
|
685
|
+
value: {
|
|
686
|
+
...base,
|
|
687
|
+
treeStates: {
|
|
688
|
+
...base.treeStates,
|
|
689
|
+
[projectionId]: update(currentTreeState),
|
|
690
|
+
},
|
|
691
|
+
},
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
function applySetStateAction(action, current) {
|
|
695
|
+
return typeof action === 'function'
|
|
696
|
+
? action(current)
|
|
697
|
+
: action;
|
|
698
|
+
}
|
|
699
|
+
//# sourceMappingURL=document-workspace-runtime.js.map
|