@cratis/scene.react 4.27.0 → 4.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/coreDescriptors.ts +28 -1
- package/dist/cjs/core/coreDescriptors.js +64 -0
- package/dist/cjs/core/coreDescriptors.js.map +1 -1
- package/dist/cjs/index.js +16 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/navigation/SceneNavigationHost.js +24 -13
- package/dist/cjs/navigation/SceneNavigationHost.js.map +1 -1
- package/dist/cjs/navigation/region/NavigationRegionClassNames.js +21 -0
- package/dist/cjs/navigation/region/NavigationRegionClassNames.js.map +1 -0
- package/dist/cjs/navigation/region/NavigationRegionView.js +283 -0
- package/dist/cjs/navigation/region/NavigationRegionView.js.map +1 -0
- package/dist/cjs/navigation/region/SceneNavigationModelContext.js +22 -0
- package/dist/cjs/navigation/region/SceneNavigationModelContext.js.map +1 -0
- package/dist/cjs/navigation/region/currentModuleOf.js +15 -0
- package/dist/cjs/navigation/region/currentModuleOf.js.map +1 -0
- package/dist/cjs/navigation/region/navigationDestinations.js +46 -0
- package/dist/cjs/navigation/region/navigationDestinations.js.map +1 -0
- package/dist/cjs/navigation/region/navigationItemActive.js +31 -0
- package/dist/cjs/navigation/region/navigationItemActive.js.map +1 -0
- package/dist/cjs/navigation/region/navigationItemDestination.js +34 -0
- package/dist/cjs/navigation/region/navigationItemDestination.js.map +1 -0
- package/dist/esm/core/coreDescriptors.d.ts.map +1 -1
- package/dist/esm/core/coreDescriptors.js +65 -1
- package/dist/esm/core/coreDescriptors.js.map +1 -1
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/navigation/SceneNavigationHost.d.ts +5 -1
- package/dist/esm/navigation/SceneNavigationHost.d.ts.map +1 -1
- package/dist/esm/navigation/SceneNavigationHost.js +25 -14
- package/dist/esm/navigation/SceneNavigationHost.js.map +1 -1
- package/dist/esm/navigation/index.d.ts +8 -0
- package/dist/esm/navigation/index.d.ts.map +1 -1
- package/dist/esm/navigation/index.js +8 -0
- package/dist/esm/navigation/index.js.map +1 -1
- package/dist/esm/navigation/region/NavigationRegionClassNames.d.ts +12 -0
- package/dist/esm/navigation/region/NavigationRegionClassNames.d.ts.map +1 -0
- package/dist/esm/navigation/region/NavigationRegionClassNames.js +19 -0
- package/dist/esm/navigation/region/NavigationRegionClassNames.js.map +1 -0
- package/dist/esm/navigation/region/NavigationRegionView.d.ts +20 -0
- package/dist/esm/navigation/region/NavigationRegionView.d.ts.map +1 -0
- package/dist/esm/navigation/region/NavigationRegionView.js +281 -0
- package/dist/esm/navigation/region/NavigationRegionView.js.map +1 -0
- package/dist/esm/navigation/region/SceneNavigationModel.d.ts +9 -0
- package/dist/esm/navigation/region/SceneNavigationModel.d.ts.map +1 -0
- package/dist/esm/navigation/region/SceneNavigationModel.js +2 -0
- package/dist/esm/navigation/region/SceneNavigationModel.js.map +1 -0
- package/dist/esm/navigation/region/SceneNavigationModelContext.d.ts +9 -0
- package/dist/esm/navigation/region/SceneNavigationModelContext.d.ts.map +1 -0
- package/dist/esm/navigation/region/SceneNavigationModelContext.js +19 -0
- package/dist/esm/navigation/region/SceneNavigationModelContext.js.map +1 -0
- package/dist/esm/navigation/region/currentModuleOf.d.ts +3 -0
- package/dist/esm/navigation/region/currentModuleOf.d.ts.map +1 -0
- package/dist/esm/navigation/region/currentModuleOf.js +13 -0
- package/dist/esm/navigation/region/currentModuleOf.js.map +1 -0
- package/dist/esm/navigation/region/navigationDestinations.d.ts +4 -0
- package/dist/esm/navigation/region/navigationDestinations.d.ts.map +1 -0
- package/dist/esm/navigation/region/navigationDestinations.js +44 -0
- package/dist/esm/navigation/region/navigationDestinations.js.map +1 -0
- package/dist/esm/navigation/region/navigationItemActive.d.ts +5 -0
- package/dist/esm/navigation/region/navigationItemActive.d.ts.map +1 -0
- package/dist/esm/navigation/region/navigationItemActive.js +29 -0
- package/dist/esm/navigation/region/navigationItemActive.js.map +1 -0
- package/dist/esm/navigation/region/navigationItemDestination.d.ts +5 -0
- package/dist/esm/navigation/region/navigationItemDestination.d.ts.map +1 -0
- package/dist/esm/navigation/region/navigationItemDestination.js +31 -0
- package/dist/esm/navigation/region/navigationItemDestination.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/navigation/SceneNavigationHost.tsx +27 -6
- package/navigation/index.ts +8 -0
- package/navigation/region/NavigationRegionClassNames.ts +46 -0
- package/navigation/region/NavigationRegionView.tsx +234 -0
- package/navigation/region/SceneNavigationModel.ts +29 -0
- package/navigation/region/SceneNavigationModelContext.tsx +25 -0
- package/navigation/region/currentModuleOf.ts +14 -0
- package/navigation/region/navigationDestinations.ts +41 -0
- package/navigation/region/navigationItemActive.ts +39 -0
- package/navigation/region/navigationItemDestination.ts +29 -0
- package/package.json +5 -5
package/core/coreDescriptors.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Cratis. All rights reserved.
|
|
2
2
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
3
|
|
|
4
|
-
import { ComponentDescriptor, PropertyValueType } from '@cratis/scene.model';
|
|
4
|
+
import { ComponentDescriptor, PropertyEditorKind, PropertyValueType, ToolbarEmphasis } from '@cratis/scene.model';
|
|
5
5
|
import { componentRegistryKey, describeComponents } from '../packages';
|
|
6
6
|
import { coreComponentMetadata } from './coreComponentMetadata';
|
|
7
7
|
|
|
@@ -46,6 +46,33 @@ const describedCore: ComponentDescriptor[] = [
|
|
|
46
46
|
},
|
|
47
47
|
],
|
|
48
48
|
},
|
|
49
|
+
{
|
|
50
|
+
component: key('toolbarItem'),
|
|
51
|
+
displayName: 'Toolbar button',
|
|
52
|
+
description: 'One toolbar button. An Action button invokes a state change slice and opens it as a task dialog over the page; a button with no slice is allowed while designing and is flagged.',
|
|
53
|
+
properties: [
|
|
54
|
+
{ path: 'label', label: 'Title', group: 'Content', valueType: PropertyValueType.String, default: 'Button' },
|
|
55
|
+
{
|
|
56
|
+
path: 'slice', label: 'Slice to invoke', group: 'Behavior', valueType: PropertyValueType.String,
|
|
57
|
+
editorKind: PropertyEditorKind.Slice, editorOptions: { kinds: ['StateChange'] },
|
|
58
|
+
description: 'Only State Change slices can be picked. State Views and Automations never take user input, so they are listed as unavailable.',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
path: 'emphasis', label: 'Emphasis', group: 'Appearance', valueType: PropertyValueType.Enum, default: ToolbarEmphasis.Secondary,
|
|
62
|
+
editorKind: PropertyEditorKind.Enum,
|
|
63
|
+
choices: [
|
|
64
|
+
{ value: ToolbarEmphasis.Primary, label: 'Primary' },
|
|
65
|
+
{ value: ToolbarEmphasis.Secondary, label: 'Secondary' },
|
|
66
|
+
{ value: ToolbarEmphasis.Quiet, label: 'Quiet' },
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
{ path: 'icon', label: 'Icon', group: 'Appearance', valueType: PropertyValueType.Icon, editorKind: 'iconPicker' },
|
|
70
|
+
{
|
|
71
|
+
path: 'target', label: 'Command (legacy)', group: 'Behavior', valueType: PropertyValueType.String, editorKind: 'stateChangeReference',
|
|
72
|
+
description: 'A hand-typed command for a button that has no slice. It is converted to the slice that accepts the command when exactly one does; prefer a slice.',
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
49
76
|
{
|
|
50
77
|
component: key('column'),
|
|
51
78
|
displayName: 'Table column',
|
|
@@ -89,6 +89,70 @@ const key = (name)=>ScenePackageBundle.componentRegistryKey('core', name);
|
|
|
89
89
|
}
|
|
90
90
|
]
|
|
91
91
|
},
|
|
92
|
+
{
|
|
93
|
+
component: key('toolbarItem'),
|
|
94
|
+
displayName: 'Toolbar button',
|
|
95
|
+
description: 'One toolbar button. An Action button invokes a state change slice and opens it as a task dialog over the page; a button with no slice is allowed while designing and is flagged.',
|
|
96
|
+
properties: [
|
|
97
|
+
{
|
|
98
|
+
path: 'label',
|
|
99
|
+
label: 'Title',
|
|
100
|
+
group: 'Content',
|
|
101
|
+
valueType: scene_model.PropertyValueType.String,
|
|
102
|
+
default: 'Button'
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
path: 'slice',
|
|
106
|
+
label: 'Slice to invoke',
|
|
107
|
+
group: 'Behavior',
|
|
108
|
+
valueType: scene_model.PropertyValueType.String,
|
|
109
|
+
editorKind: scene_model.PropertyEditorKind.Slice,
|
|
110
|
+
editorOptions: {
|
|
111
|
+
kinds: [
|
|
112
|
+
'StateChange'
|
|
113
|
+
]
|
|
114
|
+
},
|
|
115
|
+
description: 'Only State Change slices can be picked. State Views and Automations never take user input, so they are listed as unavailable.'
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
path: 'emphasis',
|
|
119
|
+
label: 'Emphasis',
|
|
120
|
+
group: 'Appearance',
|
|
121
|
+
valueType: scene_model.PropertyValueType.Enum,
|
|
122
|
+
default: scene_model.ToolbarEmphasis.Secondary,
|
|
123
|
+
editorKind: scene_model.PropertyEditorKind.Enum,
|
|
124
|
+
choices: [
|
|
125
|
+
{
|
|
126
|
+
value: scene_model.ToolbarEmphasis.Primary,
|
|
127
|
+
label: 'Primary'
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
value: scene_model.ToolbarEmphasis.Secondary,
|
|
131
|
+
label: 'Secondary'
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
value: scene_model.ToolbarEmphasis.Quiet,
|
|
135
|
+
label: 'Quiet'
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
path: 'icon',
|
|
141
|
+
label: 'Icon',
|
|
142
|
+
group: 'Appearance',
|
|
143
|
+
valueType: scene_model.PropertyValueType.Icon,
|
|
144
|
+
editorKind: 'iconPicker'
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
path: 'target',
|
|
148
|
+
label: 'Command (legacy)',
|
|
149
|
+
group: 'Behavior',
|
|
150
|
+
valueType: scene_model.PropertyValueType.String,
|
|
151
|
+
editorKind: 'stateChangeReference',
|
|
152
|
+
description: 'A hand-typed command for a button that has no slice. It is converted to the slice that accepts the command when exactly one does; prefer a slice.'
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
},
|
|
92
156
|
{
|
|
93
157
|
component: key('column'),
|
|
94
158
|
displayName: 'Table column',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coreDescriptors.js","sources":["../../../core/coreDescriptors.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ComponentDescriptor, PropertyValueType } from '@cratis/scene.model';\nimport { componentRegistryKey, describeComponents } from '../packages';\nimport { coreComponentMetadata } from './coreComponentMetadata';\n\nconst key = (name: string) => componentRegistryKey('core', name);\n\n/**\n * What can be edited on the `core` package's components.\n *\n * Only the components an author configures by hand are described: a button's label, an action's command and its\n * argument mapping, a column's heading, and the navigation bar. The Screenplay structural components - `data`,\n * `section`, `summary` - have nothing to edit that is not already a node in the tree.\n */\nconst describedCore: ComponentDescriptor[] = [\n {\n component: key('button'),\n displayName: 'Button',\n properties: [\n { path: 'label', label: 'Label', group: 'Content', valueType: PropertyValueType.String, default: '' },\n ],\n },\n {\n component: key('action'),\n displayName: 'Command action',\n description: 'Invokes a modeled command. The command and its argument mapping are stored on the element; the host that handles the command event reads them.',\n properties: [\n { path: 'label', label: 'Label', group: 'Content', valueType: PropertyValueType.String },\n {\n path: 'command', label: 'Command', group: 'Behavior', valueType: PropertyValueType.String,\n editorKind: 'stateChangeReference', constraints: { required: true },\n description: 'The state change this action submits.',\n },\n {\n path: 'arguments', label: 'Argument mapping', group: 'Behavior', valueType: PropertyValueType.Collection,\n description: 'Where each command argument comes from.',\n item: {\n label: 'Argument',\n properties: [\n { path: 'name', label: 'Argument', group: 'Behavior', valueType: PropertyValueType.String, constraints: { required: true } },\n { path: 'source', label: 'Source', group: 'Behavior', valueType: PropertyValueType.String, editorKind: 'bindingPath', constraints: { required: true } },\n ],\n },\n },\n ],\n },\n {\n component: key('column'),\n displayName: 'Table column',\n properties: [\n { path: 'property', label: 'Result field', group: 'Data', valueType: PropertyValueType.String, editorKind: 'resultField', constraints: { required: true } },\n { path: 'label', label: 'Heading', group: 'Content', valueType: PropertyValueType.String },\n ],\n },\n {\n component: key('outlet'),\n displayName: 'Outlet',\n description: 'A named region another screen opens into. Placing a screen here keeps this screen on the page, and the placed screen may declare outlets of its own.',\n properties: [{ path: 'name', label: 'Name', group: 'Navigation', valueType: PropertyValueType.String, constraints: { required: true } }],\n },\n {\n component: key('navigationBar'),\n displayName: 'Navigation bar',\n description: 'A list of navigation items. A template author fixes the first item (Home) and can expose the list so that screens add their own.',\n properties: [\n { path: 'title', label: 'Title', group: 'Content', valueType: PropertyValueType.String, default: 'Navigation' },\n {\n path: 'items', label: 'Items', group: 'Content', valueType: PropertyValueType.Collection, default: [],\n item: {\n label: 'Navigation item',\n properties: [\n { path: 'label', label: 'Label', group: 'Content', valueType: PropertyValueType.String, constraints: { required: true, minimumLength: 1 } },\n { path: 'icon', label: 'Icon', group: 'Content', valueType: PropertyValueType.Icon, editorKind: 'iconPicker' },\n { path: 'destination', label: 'Destination', group: 'Content', valueType: PropertyValueType.Destination, editorKind: 'screenPicker', constraints: { required: true } },\n ],\n },\n },\n ],\n },\n];\n\n/** The `core` package's descriptors: the hand-written ones above with every component's category, icon, keywords and design mode (CMP1). */\nexport const coreDescriptors: ComponentDescriptor[] = describeComponents('core', describedCore, coreComponentMetadata);"],"names":["key","name","componentRegistryKey","describedCore","component","displayName","properties","path","label","group","valueType","PropertyValueType","String","default","description","editorKind","constraints","required","Collection","item","minimumLength","Icon","Destination","coreDescriptors","describeComponents","coreComponentMetadata"],"mappings":";;;;;;;;;;;;;AAAA;AACA;AAMA,MAAMA,GAAAA,GAAM,CAACC,IAAAA,GAAiBC,uCAAAA,CAAqB,MAAA,EAAQD,IAAAA,CAAAA;AAE3D;;;;;;AAMC,IAC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AAA;;"}
|
|
1
|
+
{"version":3,"file":"coreDescriptors.js","sources":["../../../core/coreDescriptors.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ComponentDescriptor, PropertyEditorKind, PropertyValueType, ToolbarEmphasis } from '@cratis/scene.model';\nimport { componentRegistryKey, describeComponents } from '../packages';\nimport { coreComponentMetadata } from './coreComponentMetadata';\n\nconst key = (name: string) => componentRegistryKey('core', name);\n\n/**\n * What can be edited on the `core` package's components.\n *\n * Only the components an author configures by hand are described: a button's label, an action's command and its\n * argument mapping, a column's heading, and the navigation bar. The Screenplay structural components - `data`,\n * `section`, `summary` - have nothing to edit that is not already a node in the tree.\n */\nconst describedCore: ComponentDescriptor[] = [\n {\n component: key('button'),\n displayName: 'Button',\n properties: [\n { path: 'label', label: 'Label', group: 'Content', valueType: PropertyValueType.String, default: '' },\n ],\n },\n {\n component: key('action'),\n displayName: 'Command action',\n description: 'Invokes a modeled command. The command and its argument mapping are stored on the element; the host that handles the command event reads them.',\n properties: [\n { path: 'label', label: 'Label', group: 'Content', valueType: PropertyValueType.String },\n {\n path: 'command', label: 'Command', group: 'Behavior', valueType: PropertyValueType.String,\n editorKind: 'stateChangeReference', constraints: { required: true },\n description: 'The state change this action submits.',\n },\n {\n path: 'arguments', label: 'Argument mapping', group: 'Behavior', valueType: PropertyValueType.Collection,\n description: 'Where each command argument comes from.',\n item: {\n label: 'Argument',\n properties: [\n { path: 'name', label: 'Argument', group: 'Behavior', valueType: PropertyValueType.String, constraints: { required: true } },\n { path: 'source', label: 'Source', group: 'Behavior', valueType: PropertyValueType.String, editorKind: 'bindingPath', constraints: { required: true } },\n ],\n },\n },\n ],\n },\n {\n component: key('toolbarItem'),\n displayName: 'Toolbar button',\n description: 'One toolbar button. An Action button invokes a state change slice and opens it as a task dialog over the page; a button with no slice is allowed while designing and is flagged.',\n properties: [\n { path: 'label', label: 'Title', group: 'Content', valueType: PropertyValueType.String, default: 'Button' },\n {\n path: 'slice', label: 'Slice to invoke', group: 'Behavior', valueType: PropertyValueType.String,\n editorKind: PropertyEditorKind.Slice, editorOptions: { kinds: ['StateChange'] },\n description: 'Only State Change slices can be picked. State Views and Automations never take user input, so they are listed as unavailable.',\n },\n {\n path: 'emphasis', label: 'Emphasis', group: 'Appearance', valueType: PropertyValueType.Enum, default: ToolbarEmphasis.Secondary,\n editorKind: PropertyEditorKind.Enum,\n choices: [\n { value: ToolbarEmphasis.Primary, label: 'Primary' },\n { value: ToolbarEmphasis.Secondary, label: 'Secondary' },\n { value: ToolbarEmphasis.Quiet, label: 'Quiet' },\n ],\n },\n { path: 'icon', label: 'Icon', group: 'Appearance', valueType: PropertyValueType.Icon, editorKind: 'iconPicker' },\n {\n path: 'target', label: 'Command (legacy)', group: 'Behavior', valueType: PropertyValueType.String, editorKind: 'stateChangeReference',\n description: 'A hand-typed command for a button that has no slice. It is converted to the slice that accepts the command when exactly one does; prefer a slice.',\n },\n ],\n },\n {\n component: key('column'),\n displayName: 'Table column',\n properties: [\n { path: 'property', label: 'Result field', group: 'Data', valueType: PropertyValueType.String, editorKind: 'resultField', constraints: { required: true } },\n { path: 'label', label: 'Heading', group: 'Content', valueType: PropertyValueType.String },\n ],\n },\n {\n component: key('outlet'),\n displayName: 'Outlet',\n description: 'A named region another screen opens into. Placing a screen here keeps this screen on the page, and the placed screen may declare outlets of its own.',\n properties: [{ path: 'name', label: 'Name', group: 'Navigation', valueType: PropertyValueType.String, constraints: { required: true } }],\n },\n {\n component: key('navigationBar'),\n displayName: 'Navigation bar',\n description: 'A list of navigation items. A template author fixes the first item (Home) and can expose the list so that screens add their own.',\n properties: [\n { path: 'title', label: 'Title', group: 'Content', valueType: PropertyValueType.String, default: 'Navigation' },\n {\n path: 'items', label: 'Items', group: 'Content', valueType: PropertyValueType.Collection, default: [],\n item: {\n label: 'Navigation item',\n properties: [\n { path: 'label', label: 'Label', group: 'Content', valueType: PropertyValueType.String, constraints: { required: true, minimumLength: 1 } },\n { path: 'icon', label: 'Icon', group: 'Content', valueType: PropertyValueType.Icon, editorKind: 'iconPicker' },\n { path: 'destination', label: 'Destination', group: 'Content', valueType: PropertyValueType.Destination, editorKind: 'screenPicker', constraints: { required: true } },\n ],\n },\n },\n ],\n },\n];\n\n/** The `core` package's descriptors: the hand-written ones above with every component's category, icon, keywords and design mode (CMP1). */\nexport const coreDescriptors: ComponentDescriptor[] = describeComponents('core', describedCore, coreComponentMetadata);"],"names":["key","name","componentRegistryKey","describedCore","component","displayName","properties","path","label","group","valueType","PropertyValueType","String","default","description","editorKind","constraints","required","Collection","item","PropertyEditorKind","Slice","editorOptions","kinds","Enum","ToolbarEmphasis","Secondary","choices","value","Primary","Quiet","Icon","minimumLength","Destination","coreDescriptors","describeComponents","coreComponentMetadata"],"mappings":";;;;;;;;;;;;;AAAA;AACA;AAMA,MAAMA,GAAAA,GAAM,CAACC,IAAAA,GAAiBC,uCAAAA,CAAqB,MAAA,EAAQD,IAAAA,CAAAA;AAE3D;;;;;;AAMC,IACD,MAAME,aAAAA,GAAuC;AACzC,IAAA;AACIC,QAAAA,SAAAA,EAAWJ,GAAAA,CAAI,QAAA,CAAA;QACfK,WAAAA,EAAa,QAAA;QACbC,UAAAA,EAAY;AACR,YAAA;gBAAEC,IAAAA,EAAM,OAAA;gBAASC,KAAAA,EAAO,OAAA;gBAASC,KAAAA,EAAO,SAAA;AAAWC,gBAAAA,SAAAA,EAAWC,8BAAkBC,MAAM;gBAAEC,OAAAA,EAAS;AAAG;AACvG;AACL,KAAA;AACA,IAAA;AACIT,QAAAA,SAAAA,EAAWJ,GAAAA,CAAI,QAAA,CAAA;QACfK,WAAAA,EAAa,gBAAA;QACbS,WAAAA,EAAa,gJAAA;QACbR,UAAAA,EAAY;AACR,YAAA;gBAAEC,IAAAA,EAAM,OAAA;gBAASC,KAAAA,EAAO,OAAA;gBAASC,KAAAA,EAAO,SAAA;AAAWC,gBAAAA,SAAAA,EAAWC,8BAAkBC;A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AAA,EAAM,OAAA;gBAASC,KAAAA,EAAO,OAAA;gBAASC,KAAAA,EAAO,SAAA;AAAWC,gBAAAA,SAAAA,EAAWC,8BAAkBO,UAAU;AAAEL,gBAAAA,OAAAA,EAAS,EAAE;gBACrGM,IAAAA,EAAM;oBACFX,KAAAA,EAAO,iBAAA;oBACPF,UAAAA,EAAY;AACR,wBAAA;4BAAEC,IAAAA,EAAM,OAAA;4BAASC,KAAAA,EAAO,OAAA;4BAASC,KAAAA,EAAO,SAAA;AAAWC,4BAAAA,SAAAA,EAAWC,8BAAkBC,MAAM;4BAAEI,WAAAA,EAAa;gCAAEC,QAAAA,EAAU,IAAA;gCAAMe,aAAAA,EAAe;AAAE;AAAE,yBAAA;AAC1I,wBAAA;4BAAEzB,IAAAA,EAAM,MAAA;4BAAQC,KAAAA,EAAO,MAAA;4BAAQC,KAAAA,EAAO,SAAA;AAAWC,4BAAAA,SAAAA,EAAWC,8BAAkBoB,IAAI;4BAAEhB,UAAAA,EAAY;AAAa,yBAAA;AAC7G,wBAAA;4BAAER,IAAAA,EAAM,aAAA;4BAAeC,KAAAA,EAAO,aAAA;4BAAeC,KAAAA,EAAO,SAAA;AAAWC,4BAAAA,SAAAA,EAAWC,8BAAkBsB,WAAW;4BAAElB,UAAAA,EAAY,cAAA;4BAAgBC,WAAAA,EAAa;gCAAEC,QAAAA,EAAU;AAAK;AAAE;AACxK;AACL;AACJ;AACH;AACL;AACH,CAAA;AAED,6IACO,MAAMiB,kBAAyCC,qCAAAA,CAAmB,MAAA,EAAQhC,eAAeiC,2CAAAA;;"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -37,6 +37,13 @@ var CoreOutlet = require('./navigation/CoreOutlet.js');
|
|
|
37
37
|
var SceneOutletContext = require('./navigation/SceneOutletContext.js');
|
|
38
38
|
var collectOutletOwners = require('./navigation/collectOutletOwners.js');
|
|
39
39
|
var placeInOutlet = require('./navigation/placeInOutlet.js');
|
|
40
|
+
var SceneNavigationModelContext = require('./navigation/region/SceneNavigationModelContext.js');
|
|
41
|
+
var NavigationRegionClassNames = require('./navigation/region/NavigationRegionClassNames.js');
|
|
42
|
+
var NavigationRegionView = require('./navigation/region/NavigationRegionView.js');
|
|
43
|
+
var currentModuleOf = require('./navigation/region/currentModuleOf.js');
|
|
44
|
+
var navigationItemActive = require('./navigation/region/navigationItemActive.js');
|
|
45
|
+
var navigationItemDestination = require('./navigation/region/navigationItemDestination.js');
|
|
46
|
+
var navigationDestinations = require('./navigation/region/navigationDestinations.js');
|
|
40
47
|
var IconAdapterRegistry = require('./icons/IconAdapterRegistry.js');
|
|
41
48
|
var IconAdapterContext = require('./icons/IconAdapterContext.js');
|
|
42
49
|
var useIconGlyph = require('./icons/useIconGlyph.js');
|
|
@@ -134,6 +141,15 @@ exports.useSceneOutlets = SceneOutletContext.useSceneOutlets;
|
|
|
134
141
|
exports.collectOutletOwners = collectOutletOwners.collectOutletOwners;
|
|
135
142
|
exports.outletComponentName = collectOutletOwners.outletComponentName;
|
|
136
143
|
exports.placeInOutlet = placeInOutlet.placeInOutlet;
|
|
144
|
+
exports.SceneNavigationModelProvider = SceneNavigationModelContext.SceneNavigationModelProvider;
|
|
145
|
+
exports.useSceneNavigationModel = SceneNavigationModelContext.useSceneNavigationModel;
|
|
146
|
+
exports.defaultNavigationRegionClassNames = NavigationRegionClassNames.defaultNavigationRegionClassNames;
|
|
147
|
+
exports.NavigationRegionView = NavigationRegionView.NavigationRegionView;
|
|
148
|
+
exports.currentModuleOf = currentModuleOf.currentModuleOf;
|
|
149
|
+
exports.navigationItemActive = navigationItemActive.navigationItemActive;
|
|
150
|
+
exports.defaultScreenFor = navigationItemDestination.defaultScreenFor;
|
|
151
|
+
exports.navigationItemDestination = navigationItemDestination.navigationItemDestination;
|
|
152
|
+
exports.navigationDestinations = navigationDestinations.navigationDestinations;
|
|
137
153
|
exports.IconAdapterRegistry = IconAdapterRegistry.IconAdapterRegistry;
|
|
138
154
|
exports.createIconAdapterRegistry = IconAdapterRegistry.createIconAdapterRegistry;
|
|
139
155
|
exports.IconAdapterProvider = IconAdapterContext.IconAdapterProvider;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -9,6 +9,8 @@ var sceneRoutesFrom = require('./sceneRoutesFrom.js');
|
|
|
9
9
|
var collectOutletOwners = require('./collectOutletOwners.js');
|
|
10
10
|
var SceneOutletContext = require('./SceneOutletContext.js');
|
|
11
11
|
var useSceneHistoryNavigation = require('./useSceneHistoryNavigation.js');
|
|
12
|
+
var SceneNavigationModelContext = require('./region/SceneNavigationModelContext.js');
|
|
13
|
+
var navigationDestinations = require('./region/navigationDestinations.js');
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* Executes Scene destinations against an in-memory rendered hierarchy: a destination into a nested outlet -
|
|
@@ -16,7 +18,11 @@ var useSceneHistoryNavigation = require('./useSceneHistoryNavigation.js');
|
|
|
16
18
|
* depth; any other screen route replaces the primary region,
|
|
17
19
|
* dialog destinations render dialog content over the screen that opened them, and external destinations
|
|
18
20
|
* only report their resolved action. Every navigation is a history entry.
|
|
19
|
-
*/ function SceneNavigationHost({ screens, dialogs = {}, initialScreen, registry, bindingScope = {}, history, destinations, routes }) {
|
|
21
|
+
*/ function SceneNavigationHost({ screens, dialogs = {}, initialScreen, registry, bindingScope = {}, history, destinations: authoredDestinations, routes, navigationModel, frame }) {
|
|
22
|
+
const destinations = react.useMemo(()=>authoredDestinations ?? (navigationModel ? navigationDestinations.navigationDestinations(navigationModel.structure, navigationModel.navigation, navigationModel.screenFor) : undefined), [
|
|
23
|
+
authoredDestinations,
|
|
24
|
+
navigationModel
|
|
25
|
+
]);
|
|
20
26
|
const [memoryHistory] = react.useState(()=>createMemorySceneHistory.createMemorySceneHistory());
|
|
21
27
|
const routeTable = react.useMemo(()=>routes ?? sceneRoutesFrom.sceneRoutesFrom(Object.keys(screens), destinations), [
|
|
22
28
|
destinations,
|
|
@@ -36,22 +42,23 @@ var useSceneHistoryNavigation = require('./useSceneHistoryNavigation.js');
|
|
|
36
42
|
]);
|
|
37
43
|
const screen = screens[value.primaryScreen];
|
|
38
44
|
const dialog = value.currentDialog ? dialogs[value.currentDialog] : undefined;
|
|
39
|
-
|
|
45
|
+
const outlet = /*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
46
|
+
"data-scene-outlet": value.primaryScreen === value.currentScreen ? value.currentOutlet ?? 'primary' : 'primary',
|
|
47
|
+
"data-scene-url": value.currentUrl,
|
|
48
|
+
children: screen && /*#__PURE__*/ jsxRuntime.jsx(SceneElementView.SceneElementView, {
|
|
49
|
+
element: screen,
|
|
50
|
+
registry: registry,
|
|
51
|
+
dataContext: bindingScope.dataContext,
|
|
52
|
+
queryResults: bindingScope.queryResults,
|
|
53
|
+
componentOutputs: bindingScope.componentOutputs
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
const page = /*#__PURE__*/ jsxRuntime.jsx(SceneNavigationContext.SceneNavigationProvider, {
|
|
40
57
|
value: value,
|
|
41
58
|
children: /*#__PURE__*/ jsxRuntime.jsxs(SceneOutletContext.SceneOutletContext.Provider, {
|
|
42
59
|
value: outletContext,
|
|
43
60
|
children: [
|
|
44
|
-
|
|
45
|
-
"data-scene-outlet": value.primaryScreen === value.currentScreen ? value.currentOutlet ?? 'primary' : 'primary',
|
|
46
|
-
"data-scene-url": value.currentUrl,
|
|
47
|
-
children: screen && /*#__PURE__*/ jsxRuntime.jsx(SceneElementView.SceneElementView, {
|
|
48
|
-
element: screen,
|
|
49
|
-
registry: registry,
|
|
50
|
-
dataContext: bindingScope.dataContext,
|
|
51
|
-
queryResults: bindingScope.queryResults,
|
|
52
|
-
componentOutputs: bindingScope.componentOutputs
|
|
53
|
-
})
|
|
54
|
-
}),
|
|
61
|
+
frame ? frame(outlet) : outlet,
|
|
55
62
|
dialog && /*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
56
63
|
role: "dialog",
|
|
57
64
|
"aria-modal": "true",
|
|
@@ -68,6 +75,10 @@ var useSceneHistoryNavigation = require('./useSceneHistoryNavigation.js');
|
|
|
68
75
|
]
|
|
69
76
|
})
|
|
70
77
|
});
|
|
78
|
+
return navigationModel ? /*#__PURE__*/ jsxRuntime.jsx(SceneNavigationModelContext.SceneNavigationModelProvider, {
|
|
79
|
+
model: navigationModel,
|
|
80
|
+
children: page
|
|
81
|
+
}) : page;
|
|
71
82
|
}
|
|
72
83
|
|
|
73
84
|
exports.SceneNavigationHost = SceneNavigationHost;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SceneNavigationHost.js","sources":["../../../navigation/SceneNavigationHost.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { useMemo, useState } from 'react';\nimport { BindingScope } from '@cratis/scene.engine';\nimport { DestinationReference, SceneElement } from '@cratis/scene.model';\nimport { SceneElementView } from '../SceneElementView';\nimport { ComponentRegistry } from '../renderer';\nimport { createMemorySceneHistory } from './createMemorySceneHistory';\nimport { SceneHistory } from './SceneHistory';\nimport { SceneNavigationProvider } from './SceneNavigationContext';\nimport { SceneRoute } from './SceneRoute';\nimport { sceneRoutesFrom } from './sceneRoutesFrom';\nimport { collectOutletOwners } from './collectOutletOwners';\nimport { SceneOutletContext } from './SceneOutletContext';\nimport { useSceneHistoryNavigation } from './useSceneHistoryNavigation';\n\nexport interface SceneNavigationHostProps {\n screens: Record<string, SceneElement>;\n dialogs?: Record<string, SceneElement>;\n initialScreen: string;\n registry: ComponentRegistry;\n bindingScope?: BindingScope;\n\n /**\n * Where entries are recorded. `createBrowserSceneHistory()` drives the address bar, so deep links,\n * refresh and back/forward work; the default is an in-memory history for embedded hosts.\n */\n history?: SceneHistory;\n\n /** The destinations the application navigates to, so their route overrides can be deep linked. */\n destinations?: DestinationReference[];\n\n /** An explicit route table, used instead of the one derived from `screens` and `destinations`. */\n routes?: SceneRoute[];\n}\n\n/**\n * Executes Scene destinations against an in-memory rendered hierarchy: a destination into a nested outlet -\n * one a screen declares with `core:outlet` - places its screen there and keeps the screens above it, to any\n * depth; any other screen route replaces the primary region,\n * dialog destinations render dialog content over the screen that opened them, and external destinations\n * only report their resolved action. Every navigation is a history entry.\n */\nexport function SceneNavigationHost({ screens, dialogs = {}, initialScreen, registry, bindingScope = {}, history, destinations, routes }: SceneNavigationHostProps) {\n const [memoryHistory] = useState(() => createMemorySceneHistory());\n const routeTable = useMemo(() => routes ?? sceneRoutesFrom(Object.keys(screens), destinations), [destinations, routes, screens]);\n const outletOwners = useMemo(() => collectOutletOwners(screens), [screens]);\n const value = useSceneHistoryNavigation(history ?? memoryHistory, routeTable, initialScreen, bindingScope, outletOwners, destinations);\n const outletContext = useMemo(() => ({ screens, registry }), [registry, screens]);\n\n const screen = screens[value.primaryScreen];\n const dialog = value.currentDialog ? dialogs[value.currentDialog] : undefined;\n\n
|
|
1
|
+
{"version":3,"file":"SceneNavigationHost.js","sources":["../../../navigation/SceneNavigationHost.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ReactNode, useMemo, useState } from 'react';\nimport { BindingScope } from '@cratis/scene.engine';\nimport { DestinationReference, SceneElement } from '@cratis/scene.model';\nimport { SceneElementView } from '../SceneElementView';\nimport { ComponentRegistry } from '../renderer';\nimport { createMemorySceneHistory } from './createMemorySceneHistory';\nimport { SceneHistory } from './SceneHistory';\nimport { SceneNavigationProvider } from './SceneNavigationContext';\nimport { SceneRoute } from './SceneRoute';\nimport { sceneRoutesFrom } from './sceneRoutesFrom';\nimport { collectOutletOwners } from './collectOutletOwners';\nimport { SceneOutletContext } from './SceneOutletContext';\nimport { useSceneHistoryNavigation } from './useSceneHistoryNavigation';\nimport { SceneNavigationModel } from './region/SceneNavigationModel';\nimport { SceneNavigationModelProvider } from './region/SceneNavigationModelContext';\nimport { navigationDestinations } from './region/navigationDestinations';\n\nexport interface SceneNavigationHostProps {\n screens: Record<string, SceneElement>;\n dialogs?: Record<string, SceneElement>;\n initialScreen: string;\n registry: ComponentRegistry;\n bindingScope?: BindingScope;\n\n /**\n * Where entries are recorded. `createBrowserSceneHistory()` drives the address bar, so deep links,\n * refresh and back/forward work; the default is an in-memory history for embedded hosts.\n */\n history?: SceneHistory;\n\n /** The destinations the application navigates to, so their route overrides can be deep linked. */\n destinations?: DestinationReference[];\n\n /**\n * The application's structure and navigation. Navigation regions rendered inside the host (`NavigationRegionView`) read it,\n * and - when `destinations` is not given - the destinations of every navigation item become the deep-linkable ones.\n */\n navigationModel?: SceneNavigationModel;\n\n /**\n * Wraps the primary outlet in the application's chrome - a topbar, a sidebar, a toolbar. The chrome is part of the host,\n * so it stays mounted while the screens inside it change and navigation regions keep their state.\n */\n frame?(content: ReactNode): ReactNode;\n\n /** An explicit route table, used instead of the one derived from `screens` and `destinations`. */\n routes?: SceneRoute[];\n}\n\n/**\n * Executes Scene destinations against an in-memory rendered hierarchy: a destination into a nested outlet -\n * one a screen declares with `core:outlet` - places its screen there and keeps the screens above it, to any\n * depth; any other screen route replaces the primary region,\n * dialog destinations render dialog content over the screen that opened them, and external destinations\n * only report their resolved action. Every navigation is a history entry.\n */\nexport function SceneNavigationHost({ screens, dialogs = {}, initialScreen, registry, bindingScope = {}, history, destinations: authoredDestinations, routes, navigationModel, frame }: SceneNavigationHostProps) {\n const destinations = useMemo(\n () => authoredDestinations ?? (navigationModel ? navigationDestinations(navigationModel.structure, navigationModel.navigation, navigationModel.screenFor) : undefined),\n [authoredDestinations, navigationModel]);\n const [memoryHistory] = useState(() => createMemorySceneHistory());\n const routeTable = useMemo(() => routes ?? sceneRoutesFrom(Object.keys(screens), destinations), [destinations, routes, screens]);\n const outletOwners = useMemo(() => collectOutletOwners(screens), [screens]);\n const value = useSceneHistoryNavigation(history ?? memoryHistory, routeTable, initialScreen, bindingScope, outletOwners, destinations);\n const outletContext = useMemo(() => ({ screens, registry }), [registry, screens]);\n\n const screen = screens[value.primaryScreen];\n const dialog = value.currentDialog ? dialogs[value.currentDialog] : undefined;\n\n const outlet = <div data-scene-outlet={value.primaryScreen === value.currentScreen ? value.currentOutlet ?? 'primary' : 'primary'} data-scene-url={value.currentUrl}>\n {screen && <SceneElementView element={screen} registry={registry} dataContext={bindingScope.dataContext} queryResults={bindingScope.queryResults} componentOutputs={bindingScope.componentOutputs} />}\n </div>;\n const page = <SceneNavigationProvider value={value}><SceneOutletContext.Provider value={outletContext}>\n {frame ? frame(outlet) : outlet}\n {dialog && <div role='dialog' aria-modal='true' aria-label={value.currentDialog} data-scene-dialog={value.currentDialog}>\n <SceneElementView element={dialog} registry={registry} dataContext={bindingScope.dataContext} queryResults={bindingScope.queryResults} componentOutputs={bindingScope.componentOutputs} />\n </div>}\n </SceneOutletContext.Provider></SceneNavigationProvider>;\n\n return navigationModel ? <SceneNavigationModelProvider model={navigationModel}>{page}</SceneNavigationModelProvider> : page;\n}\n"],"names":["SceneNavigationHost","screens","dialogs","initialScreen","registry","bindingScope","history","destinations","authoredDestinations","routes","navigationModel","frame","useMemo","navigationDestinations","structure","navigation","screenFor","undefined","memoryHistory","useState","createMemorySceneHistory","routeTable","sceneRoutesFrom","Object","keys","outletOwners","collectOutletOwners","value","useSceneHistoryNavigation","outletContext","screen","primaryScreen","dialog","currentDialog","outlet","_jsx","div","data-scene-outlet","currentScreen","currentOutlet","data-scene-url","currentUrl","SceneElementView","element","dataContext","queryResults","componentOutputs","page","SceneNavigationProvider","_jsxs","SceneOutletContext","Provider","role","aria-modal","aria-label","data-scene-dialog","SceneNavigationModelProvider","model"],"mappings":";;;;;;;;;;;;;;AAoDA;;;;;;AAMC,IACM,SAASA,mBAAAA,CAAoB,EAAEC,OAAO,EAAEC,OAAAA,GAAU,EAAE,EAAEC,aAAa,EAAEC,QAAQ,EAAEC,YAAAA,GAAe,EAAE,EAAEC,OAAO,EAAEC,YAAAA,EAAcC,oBAAoB,EAAEC,MAAM,EAAEC,eAAe,EAAEC,KAAK,EAA4B,EAAA;AAC5M,IAAA,MAAMJ,eAAeK,aAAAA,CACjB,IAAMJ,oBAAAA,KAAyBE,kBAAkBG,6CAAAA,CAAuBH,eAAAA,CAAgBI,SAAS,EAAEJ,gBAAgBK,UAAU,EAAEL,gBAAgBM,SAAS,CAAA,GAAIC,SAAQ,CAAA,EACpK;AAACT,QAAAA,oBAAAA;AAAsBE,QAAAA;AAAgB,KAAA,CAAA;AAC3C,IAAA,MAAM,CAACQ,aAAAA,CAAc,GAAGC,cAAAA,CAAS,IAAMC,iDAAAA,EAAAA,CAAAA;IACvC,MAAMC,UAAAA,GAAaT,cAAQ,IAAMH,MAAAA,IAAUa,gCAAgBC,MAAAA,CAAOC,IAAI,CAACvB,OAAAA,CAAAA,EAAUM,YAAAA,CAAAA,EAAe;AAACA,QAAAA,YAAAA;AAAcE,QAAAA,MAAAA;AAAQR,QAAAA;AAAQ,KAAA,CAAA;AAC/H,IAAA,MAAMwB,YAAAA,GAAeb,aAAAA,CAAQ,IAAMc,uCAAAA,CAAoBzB,OAAAA,CAAAA,EAAU;AAACA,QAAAA;AAAQ,KAAA,CAAA;AAC1E,IAAA,MAAM0B,QAAQC,mDAAAA,CAA0BtB,OAAAA,IAAWY,eAAeG,UAAAA,EAAYlB,aAAAA,EAAeE,cAAcoB,YAAAA,EAAclB,YAAAA,CAAAA;IACzH,MAAMsB,aAAAA,GAAgBjB,aAAAA,CAAQ,KAAO;AAAEX,Y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BAAAE,cAAA,CAACO,iCAAAA,EAAAA;wBAAiBC,OAAAA,EAASX,MAAAA;wBAAQ5B,QAAAA,EAAUA,QAAAA;AAAUwC,wBAAAA,WAAAA,EAAavC,aAAauC,WAAW;AAAEC,wBAAAA,YAAAA,EAAcxC,aAAawC,YAAY;AAAEC,wBAAAA,gBAAAA,EAAkBzC,aAAayC;;;;;;AAI9K,IAAA,OAAOpC,gCAAkByB,cAAA,CAACqB,wDAAAA,EAAAA;QAA6BC,KAAAA,EAAO/C,eAAAA;AAAkBqC,QAAAA,QAAAA,EAAAA;AAAuCA,KAAAA,CAAAA,GAAAA,IAAAA;AAC3H;;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
4
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
5
|
+
/**
|
|
6
|
+
* The class names a {@link NavigationRegionView} puts on its nodes. The renderer carries no look of its own: a package
|
|
7
|
+
* gives the nodes its vocabulary (`blueprint.default` uses its `layout-menu` classes) and a stylesheet does the rest.
|
|
8
|
+
* State is always on data attributes as well - `data-active`, `data-expanded`, `data-read-only`, `data-origin`.
|
|
9
|
+
*/ /** The class names used when a host passes none. */ const defaultNavigationRegionClassNames = {
|
|
10
|
+
root: 'scene-nav',
|
|
11
|
+
list: 'scene-nav-list',
|
|
12
|
+
item: 'scene-nav-item',
|
|
13
|
+
link: 'scene-nav-link',
|
|
14
|
+
icon: 'scene-nav-icon',
|
|
15
|
+
label: 'scene-nav-label',
|
|
16
|
+
toggle: 'scene-nav-toggle',
|
|
17
|
+
submenu: 'scene-nav-submenu'
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.defaultNavigationRegionClassNames = defaultNavigationRegionClassNames;
|
|
21
|
+
//# sourceMappingURL=NavigationRegionClassNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NavigationRegionClassNames.js","sources":["../../../../navigation/region/NavigationRegionClassNames.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n\n/**\n * The class names a {@link NavigationRegionView} puts on its nodes. The renderer carries no look of its own: a package\n * gives the nodes its vocabulary (`blueprint.default` uses its `layout-menu` classes) and a stylesheet does the rest.\n * State is always on data attributes as well - `data-active`, `data-expanded`, `data-read-only`, `data-origin`.\n */\nexport interface NavigationRegionClassNames {\n /** The `nav` landmark. */\n root: string;\n\n /** Each list of items. */\n list: string;\n\n /** Each item's `li`. */\n item: string;\n\n /** The link of an item. */\n link: string;\n\n /** The icon of an item. */\n icon: string;\n\n /** The title of an item. */\n label: string;\n\n /** The button that expands or collapses an item's sub-items. */\n toggle: string;\n\n /** The list of an item's sub-items. */\n submenu: string;\n}\n\n/** The class names used when a host passes none. */\nexport const defaultNavigationRegionClassNames: NavigationRegionClassNames = {\n root: 'scene-nav',\n list: 'scene-nav-list',\n item: 'scene-nav-item',\n link: 'scene-nav-link',\n icon: 'scene-nav-icon',\n label: 'scene-nav-label',\n toggle: 'scene-nav-toggle',\n submenu: 'scene-nav-submenu',\n};\n"],"names":["defaultNavigationRegionClassNames","root","list","item","link","icon","label","toggle","submenu"],"mappings":";;AAAA;AACA;AAGA;;;;AAIC,yDA4BM,MAAMA,iCAAAA,GAAgE;IACzEC,IAAAA,EAAM,WAAA;IACNC,IAAAA,EAAM,gBAAA;IACNC,IAAAA,EAAM,gBAAA;IACNC,IAAAA,EAAM,gBAAA;IACNC,IAAAA,EAAM,gBAAA;IACNC,KAAAA,EAAO,iBAAA;IACPC,MAAAA,EAAQ,kBAAA;IACRC,OAAAA,EAAS;AACb;;"}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var scene_model = require('@cratis/scene.model');
|
|
6
|
+
var scene_engine = require('@cratis/scene.engine');
|
|
7
|
+
var SceneIcon = require('../../icons/SceneIcon.js');
|
|
8
|
+
var IconAdapterContext = require('../../icons/IconAdapterContext.js');
|
|
9
|
+
var resolveDestination = require('../resolveDestination.js');
|
|
10
|
+
var SceneNavigationContext = require('../SceneNavigationContext.js');
|
|
11
|
+
var NavigationRegionClassNames = require('./NavigationRegionClassNames.js');
|
|
12
|
+
var SceneNavigationModelContext = require('./SceneNavigationModelContext.js');
|
|
13
|
+
var currentModuleOf = require('./currentModuleOf.js');
|
|
14
|
+
var navigationItemActive = require('./navigationItemActive.js');
|
|
15
|
+
var navigationItemDestination = require('./navigationItemDestination.js');
|
|
16
|
+
|
|
17
|
+
function itemKey(path) {
|
|
18
|
+
return path.join('/');
|
|
19
|
+
}
|
|
20
|
+
function containsActive(item, isActive) {
|
|
21
|
+
return isActive(item) || (item.children ?? []).some((child)=>containsActive(child, isActive));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Renders the effective navigation of one region - a topbar or a sidebar - for the application or a module.
|
|
25
|
+
*
|
|
26
|
+
* - **Items** come from `effectiveNavigation`, so inherit/extend/override is already applied; nothing here re-implements
|
|
27
|
+
* it. A topbar is flat; a sidebar nests, collapses, and expands the parents of the active item.
|
|
28
|
+
* - **Active state** follows what the navigation host shows: an item is active (`aria-current`, `data-active`) when the
|
|
29
|
+
* screen it opens is the one in its slot, so items rendering into different slots are active at once.
|
|
30
|
+
* - **Activation** goes through the enclosing navigation host (`navigate`), which renders the target in the item's slot -
|
|
31
|
+
* the `outlet` of the destination; outside a host it announces `cratis.scene.navigate`.
|
|
32
|
+
* - **Authorization**: `isVisible` of the model hides items, it does not disable them.
|
|
33
|
+
* - **Keyboard**: arrows (left/right in a topbar, up/down in a sidebar), Home and End move between items; in a sidebar
|
|
34
|
+
* right expands and left collapses (or goes to the parent).
|
|
35
|
+
*
|
|
36
|
+
* Nothing here draws design chrome: items carry `data-read-only` and `data-origin` for a design layer to style.
|
|
37
|
+
*/ function NavigationRegionView({ region, module, application = false, model: modelProp, label, expand = 'active', classNames, renderIcon, renderAdornment, hrefFor, onActivate }) {
|
|
38
|
+
const contextModel = SceneNavigationModelContext.useSceneNavigationModel();
|
|
39
|
+
const model = modelProp ?? contextModel;
|
|
40
|
+
if (!model) throw new Error('NavigationRegionView needs a navigation model: pass `model` or render it inside a SceneNavigationModelProvider.');
|
|
41
|
+
const navigation = react.useContext(SceneNavigationContext.SceneNavigationContextInternal);
|
|
42
|
+
const adapters = IconAdapterContext.useIconAdapters();
|
|
43
|
+
const names = {
|
|
44
|
+
...NavigationRegionClassNames.defaultNavigationRegionClassNames,
|
|
45
|
+
...classNames
|
|
46
|
+
};
|
|
47
|
+
const index = react.useMemo(()=>model.structure instanceof scene_engine.ApplicationStructureIndex ? model.structure : new scene_engine.ApplicationStructureIndex(model.structure), [
|
|
48
|
+
model.structure
|
|
49
|
+
]);
|
|
50
|
+
const screenFor = model.screenFor ?? navigationItemDestination.defaultScreenFor;
|
|
51
|
+
const sidebar = region === scene_model.NavigationRegionKind.Sidebar;
|
|
52
|
+
const placement = react.useMemo(()=>({
|
|
53
|
+
primaryScreen: navigation?.primaryScreen,
|
|
54
|
+
outlets: navigation?.outlets ?? {}
|
|
55
|
+
}), [
|
|
56
|
+
navigation?.outlets,
|
|
57
|
+
navigation?.primaryScreen
|
|
58
|
+
]);
|
|
59
|
+
const scope = application ? undefined : module ?? currentModuleOf.currentModuleOf(index, placement.primaryScreen);
|
|
60
|
+
const resolved = react.useMemo(()=>scene_engine.effectiveNavigation(index, model.navigation, scope, region), [
|
|
61
|
+
index,
|
|
62
|
+
model.navigation,
|
|
63
|
+
scope,
|
|
64
|
+
region
|
|
65
|
+
]);
|
|
66
|
+
const isActive = (item)=>placement.primaryScreen !== undefined && navigationItemActive.navigationItemActive(item, {
|
|
67
|
+
primaryScreen: placement.primaryScreen,
|
|
68
|
+
outlets: placement.outlets
|
|
69
|
+
}, screenFor, !sidebar);
|
|
70
|
+
const isVisible = model.isVisible ?? (()=>true);
|
|
71
|
+
const visible = react.useMemo(()=>{
|
|
72
|
+
const keep = (items)=>items.filter(isVisible).map((item)=>item.children ? {
|
|
73
|
+
...item,
|
|
74
|
+
children: keep(item.children)
|
|
75
|
+
} : item);
|
|
76
|
+
return keep(resolved.items);
|
|
77
|
+
}, [
|
|
78
|
+
resolved,
|
|
79
|
+
model.isVisible
|
|
80
|
+
]);
|
|
81
|
+
const activeKey = JSON.stringify([
|
|
82
|
+
placement.primaryScreen,
|
|
83
|
+
placement.outlets,
|
|
84
|
+
scope
|
|
85
|
+
]);
|
|
86
|
+
const [toggled, setToggled] = react.useState({
|
|
87
|
+
key: activeKey,
|
|
88
|
+
state: {}
|
|
89
|
+
});
|
|
90
|
+
const overrides = toggled.key === activeKey ? toggled.state : {};
|
|
91
|
+
const [focused, setFocused] = react.useState();
|
|
92
|
+
const root = react.useRef(null);
|
|
93
|
+
const isExpanded = (item, key)=>overrides[key] ?? (expand === 'all' || containsActive(item, isActive));
|
|
94
|
+
const toggle = (key, expanded)=>setToggled({
|
|
95
|
+
key: activeKey,
|
|
96
|
+
state: {
|
|
97
|
+
...overrides,
|
|
98
|
+
[key]: expanded
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
const activate = (item)=>{
|
|
102
|
+
const destination = navigationItemDestination.navigationItemDestination(item, screenFor);
|
|
103
|
+
if (destination === undefined) return;
|
|
104
|
+
if (navigation) {
|
|
105
|
+
navigation.navigate(destination);
|
|
106
|
+
} else {
|
|
107
|
+
globalThis.dispatchEvent(new CustomEvent('cratis.scene.navigate', {
|
|
108
|
+
detail: {
|
|
109
|
+
targetScreen: destination.screen ?? '',
|
|
110
|
+
destination,
|
|
111
|
+
item
|
|
112
|
+
}
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
onActivate?.(item, destination);
|
|
116
|
+
};
|
|
117
|
+
const links = ()=>Array.from(root.current?.querySelectorAll('[data-scene-nav-link]') ?? []);
|
|
118
|
+
const focusLink = (element)=>{
|
|
119
|
+
if (!element) return;
|
|
120
|
+
setFocused(element.getAttribute('data-scene-nav-link') ?? undefined);
|
|
121
|
+
element.focus();
|
|
122
|
+
};
|
|
123
|
+
const onKeyDown = (event)=>{
|
|
124
|
+
const all = links();
|
|
125
|
+
const position = all.findIndex((link)=>link === document.activeElement);
|
|
126
|
+
if (position < 0) return;
|
|
127
|
+
const next = sidebar ? 'ArrowDown' : 'ArrowRight';
|
|
128
|
+
const previous = sidebar ? 'ArrowUp' : 'ArrowLeft';
|
|
129
|
+
const current = all[position];
|
|
130
|
+
const key = current.getAttribute('data-scene-nav-link');
|
|
131
|
+
const owner = current.closest('[data-scene-nav-item]');
|
|
132
|
+
const hasChildren = owner?.getAttribute('data-scene-nav-parent') === 'true';
|
|
133
|
+
const expanded = owner?.getAttribute('data-expanded') === 'true';
|
|
134
|
+
let target;
|
|
135
|
+
if (event.key === next) target = all[Math.min(position + 1, all.length - 1)];
|
|
136
|
+
else if (event.key === previous) target = all[Math.max(position - 1, 0)];
|
|
137
|
+
else if (event.key === 'Home') target = all[0];
|
|
138
|
+
else if (event.key === 'End') target = all[all.length - 1];
|
|
139
|
+
else if (sidebar && event.key === 'ArrowRight' && hasChildren) {
|
|
140
|
+
if (!expanded) toggle(key, true);
|
|
141
|
+
else target = all[position + 1];
|
|
142
|
+
} else if (sidebar && event.key === 'ArrowLeft') {
|
|
143
|
+
if (hasChildren && expanded) toggle(key, false);
|
|
144
|
+
else {
|
|
145
|
+
const parent = owner?.parentElement?.closest('[data-scene-nav-item]')?.querySelector(':scope > [data-scene-nav-link]');
|
|
146
|
+
if (parent) target = parent;
|
|
147
|
+
}
|
|
148
|
+
} else return;
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
focusLink(target);
|
|
151
|
+
};
|
|
152
|
+
const tabStop = focused ?? undefined;
|
|
153
|
+
const firstActive = (items, path)=>{
|
|
154
|
+
for (const item of items){
|
|
155
|
+
const key = itemKey([
|
|
156
|
+
...path,
|
|
157
|
+
item.id
|
|
158
|
+
]);
|
|
159
|
+
if (isActive(item)) return key;
|
|
160
|
+
const inner = firstActive(item.children ?? [], [
|
|
161
|
+
...path,
|
|
162
|
+
item.id
|
|
163
|
+
]);
|
|
164
|
+
if (inner !== undefined && isExpanded(item, key)) return inner;
|
|
165
|
+
}
|
|
166
|
+
return undefined;
|
|
167
|
+
};
|
|
168
|
+
const firstKey = visible.length > 0 ? itemKey([
|
|
169
|
+
visible[0].id
|
|
170
|
+
]) : undefined;
|
|
171
|
+
const stop = tabStop ?? firstActive(visible, []) ?? firstKey;
|
|
172
|
+
const icon = (item)=>{
|
|
173
|
+
if (item.icon === undefined) return null;
|
|
174
|
+
const drawn = renderIcon ? renderIcon(item.icon) : adapters ? (()=>{
|
|
175
|
+
const reference = scene_model.parseIconReference(item.icon);
|
|
176
|
+
return reference ? /*#__PURE__*/ jsxRuntime.jsx(SceneIcon.SceneIcon, {
|
|
177
|
+
reference: reference,
|
|
178
|
+
adapters: adapters
|
|
179
|
+
}) : null;
|
|
180
|
+
})() : null;
|
|
181
|
+
return drawn === null ? null : /*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
182
|
+
className: names.icon,
|
|
183
|
+
"aria-hidden": "true",
|
|
184
|
+
"data-scene-icon": item.icon,
|
|
185
|
+
children: drawn
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
const renderItems = (items, path, level)=>items.map((item)=>{
|
|
189
|
+
const key = itemKey([
|
|
190
|
+
...path,
|
|
191
|
+
item.id
|
|
192
|
+
]);
|
|
193
|
+
const destination = navigationItemDestination.navigationItemDestination(item, screenFor);
|
|
194
|
+
const active = isActive(item);
|
|
195
|
+
const children = item.children ?? [];
|
|
196
|
+
const parent = sidebar && children.length > 0;
|
|
197
|
+
const expanded = parent && isExpanded(item, key);
|
|
198
|
+
const url = destination ? resolveDestination.resolveDestination(destination).url : undefined;
|
|
199
|
+
const href = destination ? hrefFor ? hrefFor(destination, url) : url ? `#/${url}` : undefined : undefined;
|
|
200
|
+
const onClick = (event)=>{
|
|
201
|
+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.button !== 0) return;
|
|
202
|
+
event.preventDefault();
|
|
203
|
+
if (destination) activate(item);
|
|
204
|
+
else if (parent) toggle(key, !expanded);
|
|
205
|
+
};
|
|
206
|
+
const content = /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
207
|
+
children: [
|
|
208
|
+
icon(item),
|
|
209
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
210
|
+
className: names.label,
|
|
211
|
+
children: item.title
|
|
212
|
+
}),
|
|
213
|
+
renderAdornment?.(item)
|
|
214
|
+
]
|
|
215
|
+
});
|
|
216
|
+
return /*#__PURE__*/ jsxRuntime.jsxs("li", {
|
|
217
|
+
className: names.item,
|
|
218
|
+
"data-scene-nav-item": item.id,
|
|
219
|
+
"data-scene-nav-parent": parent ? 'true' : undefined,
|
|
220
|
+
"data-active": active,
|
|
221
|
+
"data-active-descendant": !active && parent && children.some((child)=>containsActive(child, isActive)) ? true : undefined,
|
|
222
|
+
"data-expanded": parent ? expanded : undefined,
|
|
223
|
+
"data-origin": item.origin,
|
|
224
|
+
"data-read-only": item.readOnly,
|
|
225
|
+
"data-slot": item.slot,
|
|
226
|
+
"data-level": level,
|
|
227
|
+
children: [
|
|
228
|
+
destination || parent ? /*#__PURE__*/ jsxRuntime.jsx("a", {
|
|
229
|
+
className: names.link,
|
|
230
|
+
href: href ?? '#',
|
|
231
|
+
"data-scene-nav-link": key,
|
|
232
|
+
"aria-current": active ? 'page' : undefined,
|
|
233
|
+
"aria-expanded": parent && !destination ? expanded : undefined,
|
|
234
|
+
tabIndex: key === stop ? 0 : -1,
|
|
235
|
+
onClick: onClick,
|
|
236
|
+
onFocus: ()=>setFocused(key),
|
|
237
|
+
children: content
|
|
238
|
+
}) : /*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
239
|
+
className: names.link,
|
|
240
|
+
"aria-disabled": "true",
|
|
241
|
+
"data-scene-nav-link": key,
|
|
242
|
+
tabIndex: -1,
|
|
243
|
+
children: content
|
|
244
|
+
}),
|
|
245
|
+
parent && /*#__PURE__*/ jsxRuntime.jsx("button", {
|
|
246
|
+
type: "button",
|
|
247
|
+
className: names.toggle,
|
|
248
|
+
tabIndex: -1,
|
|
249
|
+
"aria-expanded": expanded,
|
|
250
|
+
"aria-controls": `${key}-items`,
|
|
251
|
+
"aria-label": `${expanded ? 'Collapse' : 'Expand'} ${item.title}`,
|
|
252
|
+
onClick: ()=>toggle(key, !expanded)
|
|
253
|
+
}),
|
|
254
|
+
parent && expanded && /*#__PURE__*/ jsxRuntime.jsx("ul", {
|
|
255
|
+
id: `${key}-items`,
|
|
256
|
+
className: `${names.list} ${names.submenu}`,
|
|
257
|
+
children: renderItems(children, [
|
|
258
|
+
...path,
|
|
259
|
+
item.id
|
|
260
|
+
], level + 1)
|
|
261
|
+
})
|
|
262
|
+
]
|
|
263
|
+
}, item.id);
|
|
264
|
+
});
|
|
265
|
+
return /*#__PURE__*/ jsxRuntime.jsx("nav", {
|
|
266
|
+
ref: root,
|
|
267
|
+
className: names.root,
|
|
268
|
+
"aria-label": label ?? (sidebar ? 'Sidebar' : 'Topbar'),
|
|
269
|
+
"data-scene-nav-region": region,
|
|
270
|
+
"data-scene-nav-sources": resolved.sources.kind,
|
|
271
|
+
"data-scene-nav-sources-label": resolved.sources.label,
|
|
272
|
+
"data-scene-nav-module": scope,
|
|
273
|
+
"data-scene-nav-mode": resolved.mode,
|
|
274
|
+
onKeyDown: onKeyDown,
|
|
275
|
+
children: /*#__PURE__*/ jsxRuntime.jsx("ul", {
|
|
276
|
+
className: names.list,
|
|
277
|
+
children: renderItems(visible, [], 0)
|
|
278
|
+
})
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
exports.NavigationRegionView = NavigationRegionView;
|
|
283
|
+
//# sourceMappingURL=NavigationRegionView.js.map
|