@open-pioneer/toc 0.1.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/CHANGELOG.md +16 -0
- package/LICENSE +202 -0
- package/LayerList.d.ts +11 -0
- package/LayerList.js +204 -0
- package/LayerList.js.map +1 -0
- package/README.md +52 -0
- package/Toc.d.ts +26 -0
- package/Toc.js +67 -0
- package/Toc.js.map +1 -0
- package/_virtual/_virtual-pioneer-module_react-hooks.js +7 -0
- package/_virtual/_virtual-pioneer-module_react-hooks.js.map +1 -0
- package/i18n/de.yaml +6 -0
- package/i18n/en.yaml +6 -0
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/index.js.map +1 -0
- package/package.json +38 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @open-pioneer/toc
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cafb66b: Initial release.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [bb2f27a]
|
|
12
|
+
- Updated dependencies [1e7545c]
|
|
13
|
+
- Updated dependencies [182da1c]
|
|
14
|
+
- @open-pioneer/map@0.1.0
|
|
15
|
+
- @open-pioneer/basemap-switcher@0.1.0
|
|
16
|
+
- @open-pioneer/react-utils@0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/LayerList.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { MapModel } from "@open-pioneer/map";
|
|
3
|
+
/**
|
|
4
|
+
* Lists the (top level) operational layers in the map.
|
|
5
|
+
*
|
|
6
|
+
* Layer Groups are skipped in the current implementation.
|
|
7
|
+
*/
|
|
8
|
+
export declare function LayerList(props: {
|
|
9
|
+
map: MapModel;
|
|
10
|
+
"aria-labelledby"?: string;
|
|
11
|
+
}): JSX.Element;
|
package/LayerList.js
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { Text, List, Box, Flex, Checkbox, Popover, PopoverTrigger, Button, Portal, PopoverContent, PopoverArrow, PopoverCloseButton, PopoverHeader, PopoverBody } from '@open-pioneer/chakra-integration';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import LayerGroup from 'ol/layer/Group';
|
|
5
|
+
import { useIntl } from './_virtual/_virtual-pioneer-module_react-hooks.js';
|
|
6
|
+
import { useCallback, useSyncExternalStore, useRef } from 'react';
|
|
7
|
+
import { FiMoreVertical } from 'react-icons/fi';
|
|
8
|
+
|
|
9
|
+
function LayerList(props) {
|
|
10
|
+
const { map, "aria-labelledby": ariaLabelledBy } = props;
|
|
11
|
+
const intl = useIntl();
|
|
12
|
+
const layers = useLayers(map);
|
|
13
|
+
if (!layers.length) {
|
|
14
|
+
return /* @__PURE__ */ jsx(Text, { className: "toc-missing-layers", "aria-labelledby": ariaLabelledBy, children: intl.formatMessage({ id: "missingLayers" }) });
|
|
15
|
+
}
|
|
16
|
+
return createList(layers, intl, {
|
|
17
|
+
"aria-labelledby": ariaLabelledBy
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function createList(layers, intl, listProps) {
|
|
21
|
+
const items = layers.map((layer) => /* @__PURE__ */ jsx(LayerItem, { layer, intl }, layer.id));
|
|
22
|
+
return /* @__PURE__ */ jsx(
|
|
23
|
+
List,
|
|
24
|
+
{
|
|
25
|
+
as: "ul",
|
|
26
|
+
className: "toc-layer-list",
|
|
27
|
+
listStyleType: "none",
|
|
28
|
+
...listProps,
|
|
29
|
+
children: items
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
function LayerItem(props) {
|
|
34
|
+
const { layer, intl } = props;
|
|
35
|
+
const title = useTitle(layer);
|
|
36
|
+
const { isVisible, setVisible } = useVisibility(layer);
|
|
37
|
+
const sublayers = useSublayers(layer);
|
|
38
|
+
let nestedChildren;
|
|
39
|
+
if (sublayers?.length) {
|
|
40
|
+
nestedChildren = createList(sublayers, intl, { ml: 4 });
|
|
41
|
+
}
|
|
42
|
+
return /* @__PURE__ */ jsxs(Box, { as: "li", className: classNames("toc-layer-item", `layer-${slug(layer.id)}`), children: [
|
|
43
|
+
/* @__PURE__ */ jsxs(
|
|
44
|
+
Flex,
|
|
45
|
+
{
|
|
46
|
+
className: "toc-layer-item-content",
|
|
47
|
+
width: "100%",
|
|
48
|
+
flexDirection: "row",
|
|
49
|
+
align: "center",
|
|
50
|
+
justifyContent: "space-between",
|
|
51
|
+
gap: 2,
|
|
52
|
+
minHeight: 10,
|
|
53
|
+
children: [
|
|
54
|
+
/* @__PURE__ */ jsx(
|
|
55
|
+
Checkbox,
|
|
56
|
+
{
|
|
57
|
+
isChecked: isVisible,
|
|
58
|
+
onChange: (event) => setVisible(event.target.checked),
|
|
59
|
+
children: title
|
|
60
|
+
}
|
|
61
|
+
),
|
|
62
|
+
layer.description && /* @__PURE__ */ jsx(LayerItemDescriptor, { layer, title, intl })
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
),
|
|
66
|
+
nestedChildren
|
|
67
|
+
] });
|
|
68
|
+
}
|
|
69
|
+
function LayerItemDescriptor(props) {
|
|
70
|
+
const { layer, title, intl } = props;
|
|
71
|
+
const buttonLabel = intl.formatMessage({ id: "descriptionLabel" });
|
|
72
|
+
const description = useLayerDescription(layer);
|
|
73
|
+
return /* @__PURE__ */ jsxs(Popover, { children: [
|
|
74
|
+
/* @__PURE__ */ jsx(PopoverTrigger, { children: /* @__PURE__ */ jsx(
|
|
75
|
+
Button,
|
|
76
|
+
{
|
|
77
|
+
className: "toc-layer-item-details-button",
|
|
78
|
+
"aria-label": buttonLabel,
|
|
79
|
+
borderRadius: "full",
|
|
80
|
+
iconSpacing: 0,
|
|
81
|
+
padding: 0,
|
|
82
|
+
variant: "ghost",
|
|
83
|
+
leftIcon: /* @__PURE__ */ jsx(FiMoreVertical, {})
|
|
84
|
+
}
|
|
85
|
+
) }),
|
|
86
|
+
/* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs(PopoverContent, { className: "toc-layer-item-details", overflowY: "auto", maxHeight: "400", children: [
|
|
87
|
+
/* @__PURE__ */ jsx(PopoverArrow, {}),
|
|
88
|
+
/* @__PURE__ */ jsx(PopoverCloseButton, {}),
|
|
89
|
+
/* @__PURE__ */ jsx(PopoverHeader, { children: title }),
|
|
90
|
+
/* @__PURE__ */ jsx(PopoverBody, { children: description })
|
|
91
|
+
] }) })
|
|
92
|
+
] });
|
|
93
|
+
}
|
|
94
|
+
function useLayerDescription(layer) {
|
|
95
|
+
const getSnapshot = useCallback(() => layer.description, [layer]);
|
|
96
|
+
const subscribe = useCallback(
|
|
97
|
+
(cb) => {
|
|
98
|
+
const resource = layer.on("changed:description", cb);
|
|
99
|
+
return () => resource.destroy();
|
|
100
|
+
},
|
|
101
|
+
[layer]
|
|
102
|
+
);
|
|
103
|
+
return useSyncExternalStore(subscribe, getSnapshot);
|
|
104
|
+
}
|
|
105
|
+
function useTitle(layer) {
|
|
106
|
+
const getSnapshot = useCallback(() => layer.title, [layer]);
|
|
107
|
+
const subscribe = useCallback(
|
|
108
|
+
(cb) => {
|
|
109
|
+
const resource = layer.on("changed:title", cb);
|
|
110
|
+
return () => resource.destroy();
|
|
111
|
+
},
|
|
112
|
+
[layer]
|
|
113
|
+
);
|
|
114
|
+
return useSyncExternalStore(subscribe, getSnapshot);
|
|
115
|
+
}
|
|
116
|
+
function useVisibility(layer) {
|
|
117
|
+
const getSnapshot = useCallback(() => layer.visible, [layer]);
|
|
118
|
+
const subscribe = useCallback(
|
|
119
|
+
(cb) => {
|
|
120
|
+
const resource = layer.on("changed:visible", cb);
|
|
121
|
+
return () => resource.destroy();
|
|
122
|
+
},
|
|
123
|
+
[layer]
|
|
124
|
+
);
|
|
125
|
+
const isVisible = useSyncExternalStore(subscribe, getSnapshot);
|
|
126
|
+
const setVisible = useCallback(
|
|
127
|
+
(visible) => {
|
|
128
|
+
layer.setVisible(visible);
|
|
129
|
+
},
|
|
130
|
+
[layer]
|
|
131
|
+
);
|
|
132
|
+
return {
|
|
133
|
+
isVisible,
|
|
134
|
+
setVisible
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function useLayers(map) {
|
|
138
|
+
const subscribe = useCallback(
|
|
139
|
+
(cb) => {
|
|
140
|
+
const resource = map.layers.on("changed", cb);
|
|
141
|
+
return () => resource.destroy();
|
|
142
|
+
},
|
|
143
|
+
[map]
|
|
144
|
+
);
|
|
145
|
+
const getValue = useCallback(() => {
|
|
146
|
+
let layers = map.layers.getOperationalLayers({ sortByDisplayOrder: true }) ?? [];
|
|
147
|
+
layers = layers.reverse().filter(canShowOperationalLayer);
|
|
148
|
+
return layers;
|
|
149
|
+
}, [map]);
|
|
150
|
+
return useCachedExternalStore(subscribe, getValue);
|
|
151
|
+
}
|
|
152
|
+
function useSublayers(layer) {
|
|
153
|
+
const subscribe = useCallback(
|
|
154
|
+
(cb) => {
|
|
155
|
+
const resource = layer.sublayers?.on("changed", cb);
|
|
156
|
+
return () => resource?.destroy();
|
|
157
|
+
},
|
|
158
|
+
[layer]
|
|
159
|
+
);
|
|
160
|
+
const getValue = useCallback(() => {
|
|
161
|
+
const sublayers = layer.sublayers;
|
|
162
|
+
if (!sublayers) {
|
|
163
|
+
return void 0;
|
|
164
|
+
}
|
|
165
|
+
let layers = layer.sublayers?.getSublayers({ sortByDisplayOrder: true });
|
|
166
|
+
layers = layers.reverse();
|
|
167
|
+
return layers;
|
|
168
|
+
}, [layer]);
|
|
169
|
+
return useCachedExternalStore(subscribe, getValue);
|
|
170
|
+
}
|
|
171
|
+
function useCachedExternalStore(subscribe, getValue) {
|
|
172
|
+
const cachedValue = useRef();
|
|
173
|
+
const cachedSubscribe = useCallback(
|
|
174
|
+
(cb) => {
|
|
175
|
+
const cleanup = subscribe(() => {
|
|
176
|
+
cachedValue.current = void 0;
|
|
177
|
+
cb();
|
|
178
|
+
});
|
|
179
|
+
return () => {
|
|
180
|
+
cachedValue.current = void 0;
|
|
181
|
+
cleanup();
|
|
182
|
+
};
|
|
183
|
+
},
|
|
184
|
+
[subscribe]
|
|
185
|
+
);
|
|
186
|
+
const cachedGetSnapshot = useCallback(() => {
|
|
187
|
+
if (cachedValue.current) {
|
|
188
|
+
return cachedValue.current.value;
|
|
189
|
+
}
|
|
190
|
+
const value = getValue();
|
|
191
|
+
cachedValue.current = { value };
|
|
192
|
+
return value;
|
|
193
|
+
}, [getValue]);
|
|
194
|
+
return useSyncExternalStore(cachedSubscribe, cachedGetSnapshot);
|
|
195
|
+
}
|
|
196
|
+
function canShowOperationalLayer(layer) {
|
|
197
|
+
return !(layer.olLayer instanceof LayerGroup);
|
|
198
|
+
}
|
|
199
|
+
function slug(id) {
|
|
200
|
+
return id.replace(/[^a-z0-9 -]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export { LayerList };
|
|
204
|
+
//# sourceMappingURL=LayerList.js.map
|
package/LayerList.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LayerList.js","sources":["LayerList.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n Box,\n Button,\n Checkbox,\n Flex,\n List,\n ListProps,\n Popover,\n PopoverArrow,\n PopoverBody,\n PopoverCloseButton,\n PopoverContent,\n PopoverHeader,\n PopoverTrigger,\n Portal,\n Text\n} from \"@open-pioneer/chakra-integration\";\nimport { Layer, LayerBase, MapModel, Sublayer } from \"@open-pioneer/map\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport classNames from \"classnames\";\nimport LayerGroup from \"ol/layer/Group\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { useCallback, useRef, useSyncExternalStore } from \"react\";\nimport { FiMoreVertical } from \"react-icons/fi\";\n\n/**\n * Lists the (top level) operational layers in the map.\n *\n * Layer Groups are skipped in the current implementation.\n */\nexport function LayerList(props: { map: MapModel; \"aria-labelledby\"?: string }): JSX.Element {\n const { map, \"aria-labelledby\": ariaLabelledBy } = props;\n const intl = useIntl();\n const layers = useLayers(map);\n if (!layers.length) {\n return (\n <Text className=\"toc-missing-layers\" aria-labelledby={ariaLabelledBy}>\n {intl.formatMessage({ id: \"missingLayers\" })}\n </Text>\n );\n }\n\n return createList(layers, intl, {\n \"aria-labelledby\": ariaLabelledBy\n });\n}\n\nfunction createList(layers: LayerBase[], intl: PackageIntl, listProps: ListProps) {\n const items = layers.map((layer) => <LayerItem key={layer.id} layer={layer} intl={intl} />);\n return (\n <List\n // Note: not using UnorderedList because it adds default margins\n as=\"ul\"\n className=\"toc-layer-list\"\n listStyleType=\"none\"\n {...listProps}\n >\n {items}\n </List>\n );\n}\n\n/**\n * Renders a single layer as a list item.\n *\n * The item may have further nested list items if there are sublayers present.\n */\nfunction LayerItem(props: { layer: LayerBase; intl: PackageIntl }): JSX.Element {\n const { layer, intl } = props;\n const title = useTitle(layer);\n const { isVisible, setVisible } = useVisibility(layer);\n const sublayers = useSublayers(layer);\n\n let nestedChildren;\n if (sublayers?.length) {\n nestedChildren = createList(sublayers, intl, { ml: 4 });\n }\n\n return (\n <Box as=\"li\" className={classNames(\"toc-layer-item\", `layer-${slug(layer.id)}`)}>\n <Flex\n className=\"toc-layer-item-content\"\n width=\"100%\"\n flexDirection=\"row\"\n align=\"center\"\n justifyContent=\"space-between\"\n /** Gap to prevent bleeding of the buttons hover style into the layer title */\n gap={2}\n /** Aligned to the size of the (potential) menu button in LayerItemDescriptor */\n minHeight={10}\n >\n <Checkbox\n isChecked={isVisible}\n onChange={(event) => setVisible(event.target.checked)}\n >\n {title}\n </Checkbox>\n {layer.description && (\n <LayerItemDescriptor layer={layer} title={title} intl={intl} />\n )}\n </Flex>\n {nestedChildren}\n </Box>\n );\n}\n\nfunction LayerItemDescriptor(props: {\n layer: LayerBase;\n title: string;\n intl: PackageIntl;\n}): JSX.Element {\n const { layer, title, intl } = props;\n const buttonLabel = intl.formatMessage({ id: \"descriptionLabel\" });\n const description = useLayerDescription(layer);\n\n return (\n <Popover>\n <PopoverTrigger>\n <Button\n className=\"toc-layer-item-details-button\"\n aria-label={buttonLabel}\n borderRadius=\"full\"\n iconSpacing={0}\n padding={0}\n variant=\"ghost\"\n leftIcon={<FiMoreVertical />}\n />\n </PopoverTrigger>\n <Portal>\n <PopoverContent className=\"toc-layer-item-details\" overflowY=\"auto\" maxHeight=\"400\">\n <PopoverArrow />\n <PopoverCloseButton />\n <PopoverHeader>{title}</PopoverHeader>\n <PopoverBody>{description}</PopoverBody>\n </PopoverContent>\n </Portal>\n </Popover>\n );\n}\n\nfunction useLayerDescription(layer: LayerBase): string {\n const getSnapshot = useCallback(() => layer.description, [layer]);\n const subscribe = useCallback(\n (cb: () => void) => {\n const resource = layer.on(\"changed:description\", cb);\n return () => resource.destroy();\n },\n [layer]\n );\n return useSyncExternalStore(subscribe, getSnapshot);\n}\n\n/** Returns the layers current title. */\nfunction useTitle(layer: LayerBase): string {\n const getSnapshot = useCallback(() => layer.title, [layer]);\n const subscribe = useCallback(\n (cb: () => void) => {\n const resource = layer.on(\"changed:title\", cb);\n return () => resource.destroy();\n },\n [layer]\n );\n\n return useSyncExternalStore(subscribe, getSnapshot);\n}\n\n/** Returns the layer's current visibility and a function to change it. */\nfunction useVisibility(layer: LayerBase): {\n isVisible: boolean;\n setVisible(visible: boolean): void;\n} {\n const getSnapshot = useCallback(() => layer.visible, [layer]);\n const subscribe = useCallback(\n (cb: () => void) => {\n const resource = layer.on(\"changed:visible\", cb);\n return () => resource.destroy();\n },\n [layer]\n );\n const isVisible = useSyncExternalStore(subscribe, getSnapshot);\n const setVisible = useCallback(\n (visible: boolean) => {\n layer.setVisible(visible);\n },\n [layer]\n );\n\n return {\n isVisible,\n setVisible\n };\n}\n\n/** Returns the top level operation layers (without LayerGroups). */\nfunction useLayers(map: MapModel): LayerBase[] {\n const subscribe = useCallback(\n (cb: () => void) => {\n const resource = map.layers.on(\"changed\", cb);\n return () => resource.destroy();\n },\n [map]\n );\n const getValue = useCallback(() => {\n let layers = map.layers.getOperationalLayers({ sortByDisplayOrder: true }) ?? [];\n layers = layers.reverse().filter(canShowOperationalLayer);\n return layers;\n }, [map]);\n return useCachedExternalStore(subscribe, getValue);\n}\n\n/** Returns the sublayers of the given layer (or undefined, if the sublayer cannot have any). */\nfunction useSublayers(layer: LayerBase): Sublayer[] | undefined {\n const subscribe = useCallback(\n (cb: () => void) => {\n const resource = layer.sublayers?.on(\"changed\", cb);\n return () => resource?.destroy();\n },\n [layer]\n );\n const getValue = useCallback((): Sublayer[] | undefined => {\n const sublayers = layer.sublayers;\n if (!sublayers) {\n return undefined;\n }\n\n let layers = layer.sublayers?.getSublayers({ sortByDisplayOrder: true });\n layers = layers.reverse();\n return layers;\n }, [layer]);\n return useCachedExternalStore(subscribe, getValue);\n}\n\n/**\n * This hooks wraps an external store that does not cache its own values, i.e.\n * it may return a different value each time from `getValue()`.\n *\n * The results returned from `getValue()` are cached locally; the cache\n * is only invalidated on re-subscription or if a change event has been observed.\n */\nfunction useCachedExternalStore<T>(\n subscribe: (onStoreChanged: () => void) => () => void,\n getValue: () => T\n): T {\n const cachedValue = useRef<{ value: T } | undefined>();\n\n const cachedSubscribe = useCallback(\n (cb: () => void) => {\n const cleanup = subscribe(() => {\n // Reset cache on change\n cachedValue.current = undefined;\n cb();\n });\n return () => {\n // Reset cache when (re-) subscribing\n cachedValue.current = undefined;\n cleanup();\n };\n },\n [subscribe]\n );\n const cachedGetSnapshot = useCallback(() => {\n // Return cached values if still up to date (see resets above).\n if (cachedValue.current) {\n return cachedValue.current.value;\n }\n\n // Compute values and cache the result.\n const value = getValue();\n cachedValue.current = { value };\n return value;\n }, [getValue]);\n return useSyncExternalStore(cachedSubscribe, cachedGetSnapshot);\n}\n\nfunction canShowOperationalLayer(layer: Layer) {\n return !(layer.olLayer instanceof LayerGroup);\n}\n\nfunction slug(id: string) {\n return id\n .replace(/[^a-z0-9 -]/g, \"\")\n .replace(/\\s+/g, \"-\")\n .replace(/-+/g, \"-\");\n}\n"],"names":[],"mappings":";;;;;;;;AAgCO,SAAS,UAAU,KAAmE,EAAA;AACzF,EAAA,MAAM,EAAE,GAAA,EAAK,iBAAmB,EAAA,cAAA,EAAmB,GAAA,KAAA,CAAA;AACnD,EAAA,MAAM,OAAO,OAAQ,EAAA,CAAA;AACrB,EAAM,MAAA,MAAA,GAAS,UAAU,GAAG,CAAA,CAAA;AAC5B,EAAI,IAAA,CAAC,OAAO,MAAQ,EAAA;AAChB,IAAA,uBACK,GAAA,CAAA,IAAA,EAAA,EAAK,SAAU,EAAA,oBAAA,EAAqB,iBAAiB,EAAA,cAAA,EACjD,QAAK,EAAA,IAAA,CAAA,aAAA,CAAc,EAAE,EAAA,EAAI,eAAgB,EAAC,CAC/C,EAAA,CAAA,CAAA;AAAA,GAER;AAEA,EAAO,OAAA,UAAA,CAAW,QAAQ,IAAM,EAAA;AAAA,IAC5B,iBAAmB,EAAA,cAAA;AAAA,GACtB,CAAA,CAAA;AACL,CAAA;AAEA,SAAS,UAAA,CAAW,MAAqB,EAAA,IAAA,EAAmB,SAAsB,EAAA;AAC9E,EAAM,MAAA,KAAA,GAAQ,MAAO,CAAA,GAAA,CAAI,CAAC,KAAA,qBAAW,GAAA,CAAA,SAAA,EAAA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AU,GAAA,KAAA,CAAA,CAAA;AACtB,QAAQ,OAAA,EAAA,CAAA;AAAA,OACZ,CAAA;AAAA,KACJ;AAAA,IACA,CAAC,SAAS,CAAA;AAAA,GACd,CAAA;AACA,EAAM,MAAA,iBAAA,GAAoB,YAAY,MAAM;AAExC,IAAA,IAAI,YAAY,OAAS,EAAA;AACrB,MAAA,OAAO,YAAY,OAAQ,CAAA,KAAA,CAAA;AAAA,KAC/B;AAGA,IAAA,MAAM,QAAQ,QAAS,EAAA,CAAA;AACvB,IAAY,WAAA,CAAA,OAAA,GAAU,EAAE,KAAM,EAAA,CAAA;AAC9B,IAAO,OAAA,KAAA,CAAA;AAAA,GACX,EAAG,CAAC,QAAQ,CAAC,CAAA,CAAA;AACb,EAAO,OAAA,oBAAA,CAAqB,iBAAiB,iBAAiB,CAAA,CAAA;AAClE,CAAA;AAEA,SAAS,wBAAwB,KAAc,EAAA;AAC3C,EAAO,OAAA,EAAE,MAAM,OAAmB,YAAA,UAAA,CAAA,CAAA;AACtC,CAAA;AAEA,SAAS,KAAK,EAAY,EAAA;AACtB,EAAO,OAAA,EAAA,CACF,OAAQ,CAAA,cAAA,EAAgB,EAAE,CAAA,CAC1B,OAAQ,CAAA,MAAA,EAAQ,GAAG,CAAA,CACnB,OAAQ,CAAA,KAAA,EAAO,GAAG,CAAA,CAAA;AAC3B;;;;"}
|
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# @open-pioneer/toc
|
|
2
|
+
|
|
3
|
+
This package provides a UI component that displays the map content to the user and allows them to control it.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
To integrate the TOC (table of contents) in your app, insert the following snippet and reference a map ID:
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
<Toc mapId="map_id" />
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Basemaps
|
|
14
|
+
|
|
15
|
+
By default, the TOC shows the basemap switcher as an embedded element.
|
|
16
|
+
|
|
17
|
+
To hide the basemap switcher, set the `showBasemapSwitcher` property to `false`:
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
<Toc mapId="map_id" showBasemapSwitcher={false} />
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
To configure the embedded basemap switcher, use the `basemapSwitcherProps` property:
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
<Toc
|
|
27
|
+
mapId="map_id"
|
|
28
|
+
basemapSwitcherProps={{
|
|
29
|
+
allowSelectingEmptyBasemap: true
|
|
30
|
+
}}
|
|
31
|
+
/>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Layer IDs as CSS classes on list items
|
|
35
|
+
|
|
36
|
+
List items for individual operational layers receive the layer's `id` as an additional CSS class (`layer-${id}`).
|
|
37
|
+
|
|
38
|
+
For example, given a layer with the ID `test-geojson`, the TOC's list item for that layer is rendered as:
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<li class="toc-layer-item layer-test-geojson ...">
|
|
42
|
+
<!-- -->
|
|
43
|
+
</li>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
> NOTE: Non-alphanumeric characters present in the layer's ID are removed from the class name. Whitespace is replaced with a single `-`.
|
|
47
|
+
|
|
48
|
+
> NOTE: List items are not guaranteed to be rendered as `li`. Only the CSS class name is guaranteed.
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
Apache-2.0 (see `LICENSE` file)
|
package/Toc.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BasemapSwitcherProps } from "@open-pioneer/basemap-switcher";
|
|
2
|
+
import { CommonComponentProps } from "@open-pioneer/react-utils";
|
|
3
|
+
import { FC } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* Props supported by the {@link Toc} component.
|
|
6
|
+
*/
|
|
7
|
+
export interface TocProps extends CommonComponentProps {
|
|
8
|
+
/**
|
|
9
|
+
* The id of the map.
|
|
10
|
+
*/
|
|
11
|
+
mapId: string;
|
|
12
|
+
/**
|
|
13
|
+
* Defines whether the basemap switcher is shown in the toc.
|
|
14
|
+
* Defaults to true.
|
|
15
|
+
*/
|
|
16
|
+
showBasemapSwitcher?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Properties for the embedded basemap switcher.
|
|
19
|
+
* Property "mapId" is not applied.
|
|
20
|
+
*/
|
|
21
|
+
basemapSwitcherProps?: Omit<BasemapSwitcherProps, "mapId">;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Displays the layers of the configured map.
|
|
25
|
+
*/
|
|
26
|
+
export declare const Toc: FC<TocProps>;
|
package/Toc.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { BasemapSwitcher } from '@open-pioneer/basemap-switcher';
|
|
3
|
+
import { Box, Text, Flex } from '@open-pioneer/chakra-integration';
|
|
4
|
+
import { useMapModel } from '@open-pioneer/map';
|
|
5
|
+
import { useCommonComponentProps, TitledSection, SectionHeading } from '@open-pioneer/react-utils';
|
|
6
|
+
import { useIntl } from './_virtual/_virtual-pioneer-module_react-hooks.js';
|
|
7
|
+
import { useId } from 'react';
|
|
8
|
+
import { LayerList } from './LayerList.js';
|
|
9
|
+
|
|
10
|
+
const PADDING = 2;
|
|
11
|
+
const Toc = (props) => {
|
|
12
|
+
const intl = useIntl();
|
|
13
|
+
const { mapId, showBasemapSwitcher = true, basemapSwitcherProps } = props;
|
|
14
|
+
const { containerProps } = useCommonComponentProps("toc", props);
|
|
15
|
+
const basemapsHeadingId = useId();
|
|
16
|
+
const operationalLayersHeadingId = useId();
|
|
17
|
+
const state = useMapModel(mapId);
|
|
18
|
+
let content;
|
|
19
|
+
switch (state.kind) {
|
|
20
|
+
case "loading":
|
|
21
|
+
content = null;
|
|
22
|
+
break;
|
|
23
|
+
case "rejected":
|
|
24
|
+
content = /* @__PURE__ */ jsx(Text, { className: "toc-error", children: intl.formatMessage({ id: "error" }) });
|
|
25
|
+
break;
|
|
26
|
+
case "resolved": {
|
|
27
|
+
const basemapSwitcher = showBasemapSwitcher && /* @__PURE__ */ jsx(Box, { className: "toc-basemap-switcher", children: /* @__PURE__ */ jsx(
|
|
28
|
+
TitledSection,
|
|
29
|
+
{
|
|
30
|
+
title: /* @__PURE__ */ jsx(SectionHeading, { id: basemapsHeadingId, size: "sm", mb: PADDING, children: intl.formatMessage({ id: "basemapsLabel" }) }),
|
|
31
|
+
children: /* @__PURE__ */ jsx(
|
|
32
|
+
BasemapSwitcher,
|
|
33
|
+
{
|
|
34
|
+
mapId,
|
|
35
|
+
"aria-labelledby": basemapsHeadingId,
|
|
36
|
+
...basemapSwitcherProps
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
) });
|
|
41
|
+
const layerList = /* @__PURE__ */ jsx(Box, { className: "toc-operational-layers", children: /* @__PURE__ */ jsx(
|
|
42
|
+
TitledSection,
|
|
43
|
+
{
|
|
44
|
+
title: /* @__PURE__ */ jsx(
|
|
45
|
+
SectionHeading,
|
|
46
|
+
{
|
|
47
|
+
id: operationalLayersHeadingId,
|
|
48
|
+
size: "sm",
|
|
49
|
+
mb: PADDING,
|
|
50
|
+
children: intl.formatMessage({ id: "operationalLayerLabel" })
|
|
51
|
+
}
|
|
52
|
+
),
|
|
53
|
+
children: /* @__PURE__ */ jsx(LayerList, { map: state.map, "aria-labelledby": operationalLayersHeadingId })
|
|
54
|
+
}
|
|
55
|
+
) });
|
|
56
|
+
content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
57
|
+
basemapSwitcher,
|
|
58
|
+
layerList
|
|
59
|
+
] });
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return /* @__PURE__ */ jsx(Flex, { ...containerProps, direction: "column", gap: PADDING, children: content });
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export { Toc };
|
|
67
|
+
//# sourceMappingURL=Toc.js.map
|
package/Toc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toc.js","sources":["Toc.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { BasemapSwitcher, BasemapSwitcherProps } from \"@open-pioneer/basemap-switcher\";\nimport { Box, Flex, Text } from \"@open-pioneer/chakra-integration\";\nimport { useMapModel } from \"@open-pioneer/map\";\nimport {\n CommonComponentProps,\n SectionHeading,\n TitledSection,\n useCommonComponentProps\n} from \"@open-pioneer/react-utils\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { FC, useId } from \"react\";\nimport { LayerList } from \"./LayerList\";\n\n/**\n * Props supported by the {@link Toc} component.\n */\nexport interface TocProps extends CommonComponentProps {\n /**\n * The id of the map.\n */\n mapId: string;\n\n /**\n * Defines whether the basemap switcher is shown in the toc.\n * Defaults to true.\n */\n showBasemapSwitcher?: boolean;\n\n /**\n * Properties for the embedded basemap switcher.\n * Property \"mapId\" is not applied.\n */\n basemapSwitcherProps?: Omit<BasemapSwitcherProps, \"mapId\">;\n}\n\nconst PADDING = 2;\n\n/**\n * Displays the layers of the configured map.\n */\nexport const Toc: FC<TocProps> = (props: TocProps) => {\n const intl = useIntl();\n\n const { mapId, showBasemapSwitcher = true, basemapSwitcherProps } = props;\n const { containerProps } = useCommonComponentProps(\"toc\", props);\n const basemapsHeadingId = useId();\n const operationalLayersHeadingId = useId();\n const state = useMapModel(mapId);\n\n let content: JSX.Element | null;\n switch (state.kind) {\n case \"loading\":\n content = null;\n break;\n case \"rejected\":\n content = <Text className=\"toc-error\">{intl.formatMessage({ id: \"error\" })}</Text>;\n break;\n case \"resolved\": {\n const basemapSwitcher = showBasemapSwitcher && (\n <Box className=\"toc-basemap-switcher\">\n <TitledSection\n title={\n <SectionHeading id={basemapsHeadingId} size={\"sm\"} mb={PADDING}>\n {intl.formatMessage({ id: \"basemapsLabel\" })}\n </SectionHeading>\n }\n >\n <BasemapSwitcher\n mapId={mapId}\n aria-labelledby={basemapsHeadingId}\n {...basemapSwitcherProps}\n />\n </TitledSection>\n </Box>\n );\n const layerList = (\n <Box className=\"toc-operational-layers\">\n <TitledSection\n title={\n <SectionHeading\n id={operationalLayersHeadingId}\n size={\"sm\"}\n mb={PADDING}\n >\n {intl.formatMessage({ id: \"operationalLayerLabel\" })}\n </SectionHeading>\n }\n >\n <LayerList map={state.map!} aria-labelledby={operationalLayersHeadingId} />\n </TitledSection>\n </Box>\n );\n\n content = (\n <>\n {basemapSwitcher}\n {layerList}\n </>\n );\n break;\n }\n }\n\n return (\n <Flex {...containerProps} direction=\"column\" gap={PADDING}>\n {content}\n </Flex>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;AAqCA,MAAM,OAAU,GAAA,CAAA,CAAA;AAKH,MAAA,GAAA,GAAoB,CAAC,KAAoB,KAAA;AAClD,EAAA,MAAM,OAAO,OAAQ,EAAA,CAAA;AAErB,EAAA,MAAM,EAAE,KAAA,EAAO,mBAAsB,GAAA,IAAA,EAAM,sBAAyB,GAAA,KAAA,CAAA;AACpE,EAAA,MAAM,EAAE,cAAA,EAAmB,GAAA,uBAAA,CAAwB,OAAO,KAAK,CAAA,CAAA;AAC/D,EAAA,MAAM,oBAAoB,KAAM,EAAA,CAAA;AAChC,EAAA,MAAM,6BAA6B,KAAM,EAAA,CAAA;AACzC,EAAM,MAAA,KAAA,GAAQ,YAAY,KAAK,CAAA,CAAA;AAE/B,EAAI,IAAA,OAAA,CAAA;AACJ,EAAA,QAAQ,MAAM,IAAM;AAAA,IAChB,KAAK,SAAA;AACD,MAAU,OAAA,GAAA,IAAA,CAAA;AACV,MAAA,MAAA;AAAA,IACJ,KAAK,UAAA;AACD,MAAU,OAAA,mBAAA,GAAA,CAAC,IAAK,EAAA,EAAA,SAAA,EAAU,WAAa,EAAA,QAAA,EAAA,IAAA,CAAK,cAAc,EAAE,EAAA,EAAI,OA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AAA;AAAA,QACA,SAAA;AAAA,OACL,EAAA,CAAA,CAAA;AAEJ,MAAA,MAAA;AAAA,KACJ;AAAA,GACJ;AAEA,EACI,uBAAA,GAAA,CAAC,QAAM,GAAG,cAAA,EAAgB,WAAU,QAAS,EAAA,GAAA,EAAK,SAC7C,QACL,EAAA,OAAA,EAAA,CAAA,CAAA;AAER;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useIntlInternal } from '@open-pioneer/runtime/react-integration';
|
|
2
|
+
|
|
3
|
+
const PACKAGE_NAME = "@open-pioneer/toc";
|
|
4
|
+
const useIntl = /*@__PURE__*/ useIntlInternal.bind(undefined, PACKAGE_NAME);
|
|
5
|
+
|
|
6
|
+
export { useIntl };
|
|
7
|
+
//# sourceMappingURL=_virtual-pioneer-module_react-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_virtual-pioneer-module_react-hooks.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
package/i18n/de.yaml
ADDED
package/i18n/en.yaml
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Toc, type TocProps } from "./Toc";
|
package/index.js
ADDED
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "@open-pioneer/toc",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"peerDependencies": {
|
|
7
|
+
"@open-pioneer/chakra-integration": "^1.1.0",
|
|
8
|
+
"@open-pioneer/runtime": "^1.1.0",
|
|
9
|
+
"ol": "^8.2.0",
|
|
10
|
+
"react": "^18.2.0",
|
|
11
|
+
"classnames": "^2.3.2",
|
|
12
|
+
"react-icons": "^4.11.0",
|
|
13
|
+
"@open-pioneer/map": "^0.1.0",
|
|
14
|
+
"@open-pioneer/basemap-switcher": "^0.1.0",
|
|
15
|
+
"@open-pioneer/react-utils": "^0.1.0"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
"./package.json": "./package.json",
|
|
19
|
+
".": {
|
|
20
|
+
"import": "./index.js",
|
|
21
|
+
"types": "./index.d.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"openPioneerFramework": {
|
|
25
|
+
"services": [],
|
|
26
|
+
"i18n": {
|
|
27
|
+
"languages": [
|
|
28
|
+
"en",
|
|
29
|
+
"de"
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
"ui": {
|
|
33
|
+
"references": []
|
|
34
|
+
},
|
|
35
|
+
"properties": [],
|
|
36
|
+
"packageFormatVersion": "1.0.0"
|
|
37
|
+
}
|
|
38
|
+
}
|