@guardian/interactive-component-library 0.1.0-alpha.33 → 0.1.0-alpha.35
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.
|
@@ -485,7 +485,8 @@
|
|
|
485
485
|
},
|
|
486
486
|
onClick = () => {
|
|
487
487
|
},
|
|
488
|
-
styles: styles2
|
|
488
|
+
styles: styles2,
|
|
489
|
+
svgId
|
|
489
490
|
}) => {
|
|
490
491
|
const containerRef = hooks.useRef();
|
|
491
492
|
const containerSize = useContainerSize(containerRef);
|
|
@@ -502,6 +503,7 @@
|
|
|
502
503
|
children: containerSize && jsxRuntime.jsx("svg", {
|
|
503
504
|
viewBox: `0 0 ${width} ${height}`,
|
|
504
505
|
class: styles2.svg,
|
|
506
|
+
id: svgId,
|
|
505
507
|
children: jsxRuntime.jsx("g", {
|
|
506
508
|
children: units.map((unit2, j) => {
|
|
507
509
|
let attributes;
|
|
@@ -1464,6 +1466,7 @@
|
|
|
1464
1466
|
children: table2.columns.map((column, index) => {
|
|
1465
1467
|
var _a;
|
|
1466
1468
|
return jsxRuntime.jsx("th", {
|
|
1469
|
+
scope: "col",
|
|
1467
1470
|
className: mergeStyles(styles2.headerCell, (_a = column.styles) == null ? void 0 : _a.headerCell),
|
|
1468
1471
|
children: jsxRuntime.jsx(HeaderCell, {
|
|
1469
1472
|
styles: mergeStyles(styles2, column.styles),
|
|
@@ -1549,7 +1552,8 @@
|
|
|
1549
1552
|
right: 24,
|
|
1550
1553
|
top: 20,
|
|
1551
1554
|
bottom: 20
|
|
1552
|
-
}
|
|
1555
|
+
},
|
|
1556
|
+
svgId
|
|
1553
1557
|
}) => {
|
|
1554
1558
|
const wrapperRef = hooks.useRef(null);
|
|
1555
1559
|
const containerSize = useContainerSize(wrapperRef);
|
|
@@ -1580,6 +1584,7 @@
|
|
|
1580
1584
|
class: styles2.svg,
|
|
1581
1585
|
width,
|
|
1582
1586
|
height,
|
|
1587
|
+
id: svgId,
|
|
1583
1588
|
children: jsxRuntime.jsxs("g", {
|
|
1584
1589
|
transform: `translate(${padding.left} ${padding.top})`,
|
|
1585
1590
|
children: [jsxRuntime.jsxs("g", {
|
|
@@ -1944,11 +1949,11 @@
|
|
|
1944
1949
|
})]
|
|
1945
1950
|
});
|
|
1946
1951
|
});
|
|
1947
|
-
const borderTop = "
|
|
1948
|
-
const section = "
|
|
1949
|
-
const fullWidth = "
|
|
1950
|
-
const header = "
|
|
1951
|
-
const content = "
|
|
1952
|
+
const borderTop = "_borderTop_1yz7f_9";
|
|
1953
|
+
const section = "_section_1yz7f_14";
|
|
1954
|
+
const fullWidth = "_fullWidth_1yz7f_57";
|
|
1955
|
+
const header = "_header_1yz7f_96";
|
|
1956
|
+
const content = "_content_1yz7f_133";
|
|
1952
1957
|
const defaultStyles$9 = {
|
|
1953
1958
|
borderTop,
|
|
1954
1959
|
section,
|
|
@@ -2415,22 +2420,25 @@
|
|
|
2415
2420
|
return preact.cloneElement(t, { className: i });
|
|
2416
2421
|
});
|
|
2417
2422
|
};
|
|
2418
|
-
const transitionContainer = "
|
|
2419
|
-
const
|
|
2420
|
-
const
|
|
2421
|
-
const
|
|
2422
|
-
const
|
|
2423
|
-
const
|
|
2423
|
+
const transitionContainer = "_transitionContainer_1syip_1";
|
|
2424
|
+
const blur = "_blur_1syip_12";
|
|
2425
|
+
const modalBox = "_modalBox_1syip_17";
|
|
2426
|
+
const enter = "_enter_1syip_26";
|
|
2427
|
+
const exitDone = "_exitDone_1syip_27";
|
|
2428
|
+
const enterActive = "_enterActive_1syip_38";
|
|
2429
|
+
const exitActive = "_exitActive_1syip_49";
|
|
2424
2430
|
const styles$6 = {
|
|
2425
2431
|
transitionContainer,
|
|
2432
|
+
blur,
|
|
2426
2433
|
modalBox,
|
|
2427
2434
|
enter,
|
|
2428
2435
|
exitDone,
|
|
2429
2436
|
enterActive,
|
|
2430
|
-
|
|
2437
|
+
exitActive
|
|
2431
2438
|
};
|
|
2432
2439
|
function Modal({
|
|
2433
2440
|
visible = false,
|
|
2441
|
+
blurBackground = true,
|
|
2434
2442
|
children,
|
|
2435
2443
|
onClickOutside
|
|
2436
2444
|
}) {
|
|
@@ -2460,11 +2468,8 @@
|
|
|
2460
2468
|
duration: 300,
|
|
2461
2469
|
classNames: styles$6,
|
|
2462
2470
|
children: jsxRuntime.jsx("div", {
|
|
2463
|
-
|
|
2471
|
+
className: [styles$6.transitionContainer, blurBackground && styles$6.blur, visible && styles$6.visible].join(" "),
|
|
2464
2472
|
onClick,
|
|
2465
|
-
style: {
|
|
2466
|
-
pointerEvents: visible ? "auto" : "none"
|
|
2467
|
-
},
|
|
2468
2473
|
children: jsxRuntime.jsx("div", {
|
|
2469
2474
|
ref: modalBoxRef,
|
|
2470
2475
|
class: styles$6.modalBox,
|
|
@@ -3867,7 +3872,7 @@
|
|
|
3867
3872
|
const renderSVG = containerSize && !config.drawToCanvas;
|
|
3868
3873
|
const zoomControl2 = organisedChildren.controls["ZoomControl"];
|
|
3869
3874
|
const renderZoomControl = zoomControl2 && zoom.enabled;
|
|
3870
|
-
return jsxRuntime.jsxs("
|
|
3875
|
+
return jsxRuntime.jsxs("figure", {
|
|
3871
3876
|
ref: containerRef,
|
|
3872
3877
|
className: styles$4.container,
|
|
3873
3878
|
style: containerStyle,
|
|
@@ -4444,7 +4449,7 @@
|
|
|
4444
4449
|
constructor(map) {
|
|
4445
4450
|
this.map = map;
|
|
4446
4451
|
this._element = document.createElement("div");
|
|
4447
|
-
this._element.className = "gv-
|
|
4452
|
+
this._element.className = "gv-layer-container";
|
|
4448
4453
|
const style = this._element.style;
|
|
4449
4454
|
style.position = "absolute";
|
|
4450
4455
|
style.width = "100%";
|
|
@@ -5950,6 +5955,7 @@
|
|
|
5950
5955
|
this.layers = [];
|
|
5951
5956
|
this.dispatcher = new Dispatcher(this);
|
|
5952
5957
|
this._viewport = document.createElement("div");
|
|
5958
|
+
this._viewport.className = "gv-map";
|
|
5953
5959
|
this._viewport.style.position = "relative";
|
|
5954
5960
|
this._viewport.style.overflow = "hidden";
|
|
5955
5961
|
this._viewport.style.top = 0;
|
|
@@ -5963,13 +5969,19 @@
|
|
|
5963
5969
|
this.view.transform = d3Zoom.zoomIdentity;
|
|
5964
5970
|
this._zoomBypassKey = navigator.userAgent.indexOf("Mac") !== -1 ? "metaKey" : "ctrlKey";
|
|
5965
5971
|
this._zoomBehaviour = d3Zoom.zoom().scaleExtent(this.view.scaleExtent).filter((event) => {
|
|
5972
|
+
const filterEvent = (filter) => {
|
|
5973
|
+
this._filterEventCallback(filter);
|
|
5974
|
+
return !filter;
|
|
5975
|
+
};
|
|
5966
5976
|
if (event.type === "wheel" && !event[this._zoomBypassKey]) {
|
|
5967
|
-
|
|
5968
|
-
return false;
|
|
5977
|
+
return filterEvent(true);
|
|
5969
5978
|
}
|
|
5970
|
-
if ("targetTouches" in event
|
|
5971
|
-
|
|
5972
|
-
|
|
5979
|
+
if ("targetTouches" in event) {
|
|
5980
|
+
if (event.targetTouches.length < 2) {
|
|
5981
|
+
return false;
|
|
5982
|
+
}
|
|
5983
|
+
event.preventDefault();
|
|
5984
|
+
return filterEvent(false);
|
|
5973
5985
|
}
|
|
5974
5986
|
return (!event.ctrlKey || event.type === "wheel") && !event.button;
|
|
5975
5987
|
}).on("zoom", (event) => {
|
|
@@ -5980,6 +5992,15 @@
|
|
|
5980
5992
|
});
|
|
5981
5993
|
});
|
|
5982
5994
|
d3Selection.select(this._viewport).call(this._zoomBehaviour);
|
|
5995
|
+
this._viewport.addEventListener("touchmove", (event) => {
|
|
5996
|
+
if (event.targetTouches.length < 2) {
|
|
5997
|
+
this._filterEventCallback(true);
|
|
5998
|
+
}
|
|
5999
|
+
});
|
|
6000
|
+
}
|
|
6001
|
+
destroy() {
|
|
6002
|
+
this._resizeObserver.disconnect();
|
|
6003
|
+
this._viewport.remove();
|
|
5983
6004
|
}
|
|
5984
6005
|
/** PUBLIC GETTERS */
|
|
5985
6006
|
get size() {
|
|
@@ -5995,9 +6016,6 @@
|
|
|
5995
6016
|
onFilterEvent(callback) {
|
|
5996
6017
|
this._filterEventCallback = callback;
|
|
5997
6018
|
}
|
|
5998
|
-
onZoomEvent(callback) {
|
|
5999
|
-
this._onZoomEventCallback = callback;
|
|
6000
|
-
}
|
|
6001
6019
|
fitObject(geoJSON) {
|
|
6002
6020
|
this.view.fitObject(geoJSON);
|
|
6003
6021
|
this._requestRender();
|
|
@@ -6018,7 +6036,7 @@
|
|
|
6018
6036
|
if (layers === this.layers) {
|
|
6019
6037
|
return;
|
|
6020
6038
|
}
|
|
6021
|
-
|
|
6039
|
+
new Array(...this.layers).forEach((layer) => {
|
|
6022
6040
|
if (!layers.includes(layer)) {
|
|
6023
6041
|
this.removeLayer(layer);
|
|
6024
6042
|
}
|
|
@@ -6044,11 +6062,32 @@
|
|
|
6044
6062
|
}) {
|
|
6045
6063
|
return d3Selection.select(this._viewport).transition().duration(options.duration).call(this._zoomBehaviour.scaleTo, zoomLevel).end();
|
|
6046
6064
|
}
|
|
6047
|
-
zoomToFeature(feature, focalPoint
|
|
6065
|
+
zoomToFeature(feature, focalPoint, padding = {
|
|
6066
|
+
top: 40,
|
|
6067
|
+
right: 40,
|
|
6068
|
+
bottom: 40,
|
|
6069
|
+
left: 40
|
|
6070
|
+
}) {
|
|
6048
6071
|
const extent = feature.getExtent();
|
|
6049
|
-
const [[
|
|
6050
|
-
const
|
|
6051
|
-
const
|
|
6072
|
+
const [[featureX, featureY], [featureWidth, featureHeight]] = this.view.boundsForExtent(extent);
|
|
6073
|
+
const [viewPortWidth, viewPortHeight] = this.view.viewPortSize;
|
|
6074
|
+
const paddedViewPortWidth = viewPortWidth - padding.left - padding.right;
|
|
6075
|
+
const paddedViewPortHeight = viewPortHeight - padding.top - padding.bottom;
|
|
6076
|
+
const featureScale = Math.min(paddedViewPortWidth / featureWidth, paddedViewPortHeight / featureHeight);
|
|
6077
|
+
const zoomScale = Math.min(this.view.maxZoom, featureScale);
|
|
6078
|
+
const scaledPadding = {
|
|
6079
|
+
top: padding.top / zoomScale,
|
|
6080
|
+
right: padding.right / zoomScale,
|
|
6081
|
+
bottom: padding.bottom / zoomScale,
|
|
6082
|
+
left: padding.left / zoomScale
|
|
6083
|
+
};
|
|
6084
|
+
const paddedFeatureBounds = {
|
|
6085
|
+
x: featureX - scaledPadding.left,
|
|
6086
|
+
y: featureY - scaledPadding.top,
|
|
6087
|
+
width: featureWidth + scaledPadding.left + scaledPadding.right,
|
|
6088
|
+
height: featureHeight + scaledPadding.top + scaledPadding.bottom
|
|
6089
|
+
};
|
|
6090
|
+
const newTransform = d3Zoom.zoomIdentity.translate(viewPortWidth / 2, viewPortHeight / 2).scale(zoomScale).translate(-(paddedFeatureBounds.x + paddedFeatureBounds.width / 2), -(paddedFeatureBounds.y + paddedFeatureBounds.height / 2));
|
|
6052
6091
|
d3Selection.select(this._viewport).transition().duration(500).call(this._zoomBehaviour.transform, newTransform, focalPoint);
|
|
6053
6092
|
}
|
|
6054
6093
|
async resetZoom(options) {
|
|
@@ -6274,16 +6313,19 @@
|
|
|
6274
6313
|
};
|
|
6275
6314
|
}
|
|
6276
6315
|
}
|
|
6277
|
-
const mapContainer = "
|
|
6278
|
-
const helpTextContainer = "
|
|
6279
|
-
const helpText = "
|
|
6280
|
-
const
|
|
6316
|
+
const mapContainer = "_mapContainer_qlxau_9";
|
|
6317
|
+
const helpTextContainer = "_helpTextContainer_qlxau_15";
|
|
6318
|
+
const helpText = "_helpText_qlxau_15";
|
|
6319
|
+
const desktopHelpText = "_desktopHelpText_qlxau_40";
|
|
6320
|
+
const mobileHelpText$1 = "_mobileHelpText_qlxau_48";
|
|
6281
6321
|
const styles$3 = {
|
|
6282
6322
|
mapContainer,
|
|
6283
6323
|
helpTextContainer,
|
|
6284
6324
|
helpText,
|
|
6285
|
-
|
|
6325
|
+
desktopHelpText,
|
|
6326
|
+
mobileHelpText: mobileHelpText$1
|
|
6286
6327
|
};
|
|
6328
|
+
const mobileHelpText = "Use two fingers to zoom";
|
|
6287
6329
|
const Map$1 = compat.forwardRef(({
|
|
6288
6330
|
config,
|
|
6289
6331
|
onLoad,
|
|
@@ -6292,10 +6334,10 @@
|
|
|
6292
6334
|
const {
|
|
6293
6335
|
layers
|
|
6294
6336
|
} = children;
|
|
6337
|
+
const targetRef = hooks.useRef();
|
|
6295
6338
|
const [map, setMap] = hooks.useState();
|
|
6296
|
-
const [hideDefaultHelpText, setHideDefaultHelpText] = hooks.useState(false);
|
|
6297
6339
|
const [zoomHelpText, setZoomHelpText] = hooks.useState("");
|
|
6298
|
-
const [
|
|
6340
|
+
const [showHelpText, setShowHelpText] = hooks.useState(false);
|
|
6299
6341
|
hooks.useEffect(() => {
|
|
6300
6342
|
const map2 = new Map$2({
|
|
6301
6343
|
view: new View(config.view),
|
|
@@ -6309,6 +6351,7 @@
|
|
|
6309
6351
|
const zoomHelpText2 = navigator.userAgent.indexOf("Mac") !== -1 ? "Use ⌘ + scroll to zoom" : "Use Ctrl + scroll to zoom";
|
|
6310
6352
|
setZoomHelpText(zoomHelpText2);
|
|
6311
6353
|
return () => {
|
|
6354
|
+
map2.destroy();
|
|
6312
6355
|
if (ref)
|
|
6313
6356
|
ref.current = null;
|
|
6314
6357
|
setMap(null);
|
|
@@ -6318,16 +6361,15 @@
|
|
|
6318
6361
|
if (!map)
|
|
6319
6362
|
return;
|
|
6320
6363
|
let timeoutID;
|
|
6321
|
-
map.onFilterEvent(() => {
|
|
6364
|
+
map.onFilterEvent((showHelpText2) => {
|
|
6322
6365
|
if (timeoutID)
|
|
6323
6366
|
clearTimeout(timeoutID);
|
|
6324
|
-
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
setHideDefaultHelpText(zoomLevel > 1);
|
|
6367
|
+
setShowHelpText(showHelpText2);
|
|
6368
|
+
if (showHelpText2) {
|
|
6369
|
+
timeoutID = setTimeout(() => {
|
|
6370
|
+
setShowHelpText(false);
|
|
6371
|
+
}, 1e3);
|
|
6372
|
+
}
|
|
6331
6373
|
});
|
|
6332
6374
|
return () => {
|
|
6333
6375
|
if (timeoutID)
|
|
@@ -6339,22 +6381,22 @@
|
|
|
6339
6381
|
map.setLayers(layers);
|
|
6340
6382
|
}
|
|
6341
6383
|
}, [map, layers]);
|
|
6342
|
-
|
|
6343
|
-
const hideHelpText = hideDefaultHelpText && !highlightHelpText;
|
|
6344
|
-
const helpText2 = highlightHelpText ? zoomHelpText : config.defaultHelpText;
|
|
6345
|
-
return jsxRuntime.jsx("div", {
|
|
6384
|
+
return jsxRuntime.jsx("figure", {
|
|
6346
6385
|
ref: targetRef,
|
|
6347
6386
|
className: styles$3.mapContainer,
|
|
6348
|
-
children: jsxRuntime.
|
|
6387
|
+
children: jsxRuntime.jsxs("div", {
|
|
6349
6388
|
className: styles$3.helpTextContainer,
|
|
6350
6389
|
style: {
|
|
6351
|
-
opacity:
|
|
6390
|
+
opacity: showHelpText ? 1 : 0
|
|
6352
6391
|
},
|
|
6353
6392
|
"aria-hidden": true,
|
|
6354
|
-
children: jsxRuntime.jsx("p", {
|
|
6355
|
-
className: [styles$3.helpText,
|
|
6356
|
-
children:
|
|
6357
|
-
})
|
|
6393
|
+
children: [jsxRuntime.jsx("p", {
|
|
6394
|
+
className: [styles$3.helpText, styles$3.desktopHelpText].join(" "),
|
|
6395
|
+
children: zoomHelpText
|
|
6396
|
+
}), jsxRuntime.jsx("p", {
|
|
6397
|
+
className: [styles$3.helpText, styles$3.mobileHelpText].join(" "),
|
|
6398
|
+
children: mobileHelpText
|
|
6399
|
+
})]
|
|
6358
6400
|
})
|
|
6359
6401
|
});
|
|
6360
6402
|
});
|
|
@@ -6464,7 +6506,8 @@
|
|
|
6464
6506
|
render(frameState, feature, context) {
|
|
6465
6507
|
const {
|
|
6466
6508
|
projection,
|
|
6467
|
-
transform
|
|
6509
|
+
transform,
|
|
6510
|
+
pixelRatio
|
|
6468
6511
|
} = frameState.viewState;
|
|
6469
6512
|
this.drawingFunction.context(context);
|
|
6470
6513
|
context.beginPath();
|
|
@@ -6477,7 +6520,7 @@
|
|
|
6477
6520
|
fill
|
|
6478
6521
|
} = this.style;
|
|
6479
6522
|
if (stroke) {
|
|
6480
|
-
context.lineWidth = stroke.width / transform.k;
|
|
6523
|
+
context.lineWidth = stroke.width * pixelRatio / transform.k;
|
|
6481
6524
|
context.strokeStyle = stroke.color;
|
|
6482
6525
|
context.stroke();
|
|
6483
6526
|
}
|
|
@@ -6868,6 +6911,8 @@
|
|
|
6868
6911
|
this.featureRenderer = new FeatureRenderer();
|
|
6869
6912
|
}
|
|
6870
6913
|
renderFrame(frameState, targetElement) {
|
|
6914
|
+
if (this.layer.opacity === 0)
|
|
6915
|
+
return targetElement;
|
|
6871
6916
|
const {
|
|
6872
6917
|
projection,
|
|
6873
6918
|
sizeInPixels,
|
|
@@ -6885,14 +6930,14 @@
|
|
|
6885
6930
|
const source = this.layer.source;
|
|
6886
6931
|
const features = source.getFeaturesInExtent(visibleExtent);
|
|
6887
6932
|
for (const feature of features) {
|
|
6888
|
-
context.save();
|
|
6889
6933
|
const styleFunction2 = feature.getStyleFunction() || this.layer.getStyleFunction();
|
|
6890
6934
|
const featureStyle = styleFunction2(feature);
|
|
6891
|
-
if (
|
|
6892
|
-
|
|
6893
|
-
|
|
6894
|
-
|
|
6895
|
-
|
|
6935
|
+
if ((featureStyle == null ? void 0 : featureStyle.stroke) || (featureStyle == null ? void 0 : featureStyle.fill)) {
|
|
6936
|
+
context.save();
|
|
6937
|
+
this.featureRenderer.setStyle(featureStyle);
|
|
6938
|
+
this.featureRenderer.render(frameState, feature, context);
|
|
6939
|
+
context.restore();
|
|
6940
|
+
}
|
|
6896
6941
|
}
|
|
6897
6942
|
if (Object.prototype.hasOwnProperty.call(projection, "getCompositionBorders")) {
|
|
6898
6943
|
context.beginPath();
|
|
@@ -7420,7 +7465,7 @@
|
|
|
7420
7465
|
height: window.innerHeight
|
|
7421
7466
|
};
|
|
7422
7467
|
});
|
|
7423
|
-
hooks.
|
|
7468
|
+
hooks.useLayoutEffect(() => {
|
|
7424
7469
|
if (typeof window === "undefined")
|
|
7425
7470
|
return;
|
|
7426
7471
|
function handleResize() {
|
|
@@ -7511,7 +7556,7 @@
|
|
|
7511
7556
|
position: "relative",
|
|
7512
7557
|
zIndex: 2
|
|
7513
7558
|
},
|
|
7514
|
-
children: [jsxRuntime.jsx("
|
|
7559
|
+
children: [jsxRuntime.jsx("h3", {
|
|
7515
7560
|
className: styles2.title,
|
|
7516
7561
|
children: list.title
|
|
7517
7562
|
}), jsxRuntime.jsx("p", {
|