@guardian/interactive-component-library 0.4.5 → 0.5.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.
@@ -7,7 +7,10 @@ function MapProvider({ map, children }) {
7
7
  const registerLayer = (layer, comp) => {
8
8
  if (!layers.includes(layer)) {
9
9
  const position = getCompTreePosition(comp, children);
10
- if (position === null) return;
10
+ if (position === null) {
11
+ console.warn(`failed to find target component in component tree`, comp);
12
+ return;
13
+ }
11
14
  setLayers((prevLayers) => {
12
15
  const newLayers = [...prevLayers];
13
16
  newLayers.splice(position, 0, layer);
@@ -26,27 +29,42 @@ function MapProvider({ map, children }) {
26
29
  }, [map, layers]);
27
30
  return /* @__PURE__ */ jsx(MapContext.Provider, { value: { registerLayer, unregisterLayer }, children });
28
31
  }
29
- function getCompTreePosition(targetComponent, children) {
32
+ function getCompTreePosition(targetComponent, children, debug = false) {
30
33
  let index = 0;
34
+ let debugComponentPath = [];
31
35
  function traverse(nodes) {
32
- var _a, _b;
36
+ var _a, _b, _c, _d;
33
37
  for (const node of nodes) {
34
- const childNodes = (_b = (_a = node == null ? void 0 : node.__c) == null ? void 0 : _a.__v) == null ? void 0 : _b.__k;
35
- if (childNodes && childNodes.length > 1 && childNodes[0] !== null) {
36
- const result = traverse(childNodes);
37
- if (result !== null) {
38
- return result;
38
+ if (!node) continue;
39
+ const childNodes = (_b = (_a = node.__c) == null ? void 0 : _a.__v) == null ? void 0 : _b.__k;
40
+ if (debug) {
41
+ let name = ((_c = node.__c) == null ? void 0 : _c.constructor.displayName) || ((_d = node.__c) == null ? void 0 : _d.constructor.name);
42
+ if (name === "m") {
43
+ name = "";
39
44
  }
40
- } else {
41
- if ((node == null ? void 0 : node.__c) === targetComponent) {
42
- return index;
45
+ debugComponentPath.push(name);
46
+ }
47
+ if (childNodes && childNodes.length > 0) {
48
+ const result2 = traverse(childNodes);
49
+ if (result2 !== null) {
50
+ return result2;
43
51
  }
44
- index++;
45
52
  }
53
+ if ((node == null ? void 0 : node.__c) === targetComponent) {
54
+ return index;
55
+ }
56
+ if (debug) {
57
+ debugComponentPath.pop();
58
+ }
59
+ index++;
46
60
  }
47
61
  return null;
48
62
  }
49
- return traverse(Array.isArray(children) ? children : [children]);
63
+ const result = traverse(Array.isArray(children) ? children : [children]);
64
+ if (debug && result) {
65
+ console.log(`<${debugComponentPath.join("/> → <")}/>`);
66
+ }
67
+ return result;
50
68
  }
51
69
  export {
52
70
  MapContext,
@@ -5,8 +5,6 @@ import { Dispatcher } from '../events/Dispatcher';
5
5
  /** @typedef {Omit<ConstructorParameters<typeof TextLayer>[0], "source">} TextLayerOptions */
6
6
  /** @typedef {TextLayerOptions & { features: import("../Feature").Feature[] | import("../FeatureCollection").FeatureCollection }} TextLayerComponentProps */
7
7
  export class TextLayer {
8
- /** @param {TextLayerComponentProps} props */
9
- static Component({ features: featureCollection, style, minZoom, opacity, declutter, drawCollisionBoxes, }: TextLayerComponentProps): boolean;
10
8
  /**
11
9
  * @param {import("../Feature").Feature[]} features
12
10
  * @param {TextLayerOptions} options
@@ -46,6 +44,13 @@ export class TextLayer {
46
44
  getStyleFunction(): () => Style;
47
45
  renderFrame(frameState: any, targetElement: any): any;
48
46
  }
47
+ export namespace TextLayer {
48
+ /** @param {TextLayerComponentProps} props */
49
+ function Component({ features: featureCollection, style, minZoom, opacity, declutter, drawCollisionBoxes, }: TextLayerComponentProps): boolean;
50
+ namespace Component {
51
+ let displayName: string;
52
+ }
53
+ }
49
54
  export type TextLayerOptions = Omit<ConstructorParameters<typeof TextLayer>[0], "source">;
50
55
  export type TextLayerComponentProps = TextLayerOptions & {
51
56
  features: import('../Feature').Feature[] | import('../FeatureCollection').FeatureCollection;
@@ -118,6 +118,7 @@ class TextLayer {
118
118
  return this.renderer.renderFrame(frameState, targetElement);
119
119
  }
120
120
  }
121
+ TextLayer.Component.displayName = "TextLayer";
121
122
  export {
122
123
  TextLayer
123
124
  };
@@ -5,8 +5,6 @@ import { VectorSource } from '../sources/VectorSource';
5
5
  /** @typedef {Omit<ConstructorParameters<typeof VectorLayer>[0], "source">} VectorLayerOptions */
6
6
  /** @typedef {VectorLayerOptions & { features: import("../Feature").Feature[] | import("../FeatureCollection").FeatureCollection }} VectorLayerComponentProps */
7
7
  export class VectorLayer {
8
- /** @param {VectorLayerComponentProps} props */
9
- static Component({ features: featureCollection, style, minZoom, opacity, hitDetectionEnabled, }: VectorLayerComponentProps): boolean;
10
8
  /**
11
9
  * @param {import("../Feature").Feature[]} features
12
10
  * @param {VectorLayerOptions} options
@@ -51,6 +49,13 @@ export class VectorLayer {
51
49
  findFeatures(coordinate: any): any;
52
50
  renderFrame(frameState: any, targetElement: any): any;
53
51
  }
52
+ export namespace VectorLayer {
53
+ /** @param {VectorLayerComponentProps} props */
54
+ function Component({ features: featureCollection, style, minZoom, opacity, hitDetectionEnabled, }: VectorLayerComponentProps): boolean;
55
+ namespace Component {
56
+ let displayName: string;
57
+ }
58
+ }
54
59
  export type VectorLayerOptions = Omit<ConstructorParameters<typeof VectorLayer>[0], "source">;
55
60
  export type VectorLayerComponentProps = VectorLayerOptions & {
56
61
  features: import('../Feature').Feature[] | import('../FeatureCollection').FeatureCollection;
@@ -136,6 +136,7 @@ class VectorLayer {
136
136
  return this.renderer.renderFrame(frameState, targetElement);
137
137
  }
138
138
  }
139
+ VectorLayer.Component.displayName = "VectorLayer";
139
140
  export {
140
141
  VectorLayer
141
142
  };
@@ -18,7 +18,7 @@ class FeatureRenderer {
18
18
  }
19
19
  const feature = this.feature;
20
20
  const { projection, transform, pixelRatio } = frameState.viewState;
21
- const { stroke, fill } = this.style;
21
+ const { stroke, fill, pointRadius } = this.style;
22
22
  const geometries = feature.getProjectedGeometries(projection);
23
23
  if (frameState.debug) {
24
24
  try {
@@ -31,6 +31,11 @@ class FeatureRenderer {
31
31
  );
32
32
  }
33
33
  }
34
+ if (pointRadius) {
35
+ this.drawingFunction.pointRadius(
36
+ projection.scale() * pointRadius / transform.k
37
+ );
38
+ }
34
39
  this.drawPath(geometries, context);
35
40
  if (fill) {
36
41
  fill.drawInContext(context, transform.k);
@@ -10,12 +10,14 @@
10
10
  * @property {Object} properties.stroke - The stroke color of the style
11
11
  * @property {Fill} properties.fill - The fill color of the style
12
12
  * @property {Object} properties.text - The text color of the style
13
+ * @property {number} properties.pointRadius - Radius of drawn "Point"-type geometries, if present
13
14
  */
14
15
  export class Style {
15
16
  constructor(properties: any);
16
17
  stroke: any;
17
18
  fill: any;
18
19
  text: any;
20
+ pointRadius: any;
19
21
  clone(): Style;
20
22
  }
21
23
  /**
@@ -3,12 +3,14 @@ class Style {
3
3
  this.stroke = properties == null ? void 0 : properties.stroke;
4
4
  this.fill = properties == null ? void 0 : properties.fill;
5
5
  this.text = properties == null ? void 0 : properties.text;
6
+ this.pointRadius = properties == null ? void 0 : properties.pointRadius;
6
7
  }
7
8
  clone() {
8
9
  return new Style({
9
10
  stroke: this.stroke,
10
11
  fill: this.fill,
11
- text: this.text
12
+ text: this.text,
13
+ pointRadius: this.pointRadius
12
14
  });
13
15
  }
14
16
  }
@@ -15,10 +15,10 @@ import "../svg-map/index.js";
15
15
  import "../canvas-map/lib/Map.js";
16
16
  import "d3-polygon";
17
17
  import "../canvas-map/lib/projection/index.js";
18
- import "d3-geo";
18
+ import "../canvas-map/lib/layers/TextLayer.js";
19
+ import "../canvas-map/lib/layers/VectorLayer.js";
19
20
  import "rbush";
20
21
  import "rbush-knn";
21
- import "../canvas-map/context/MapContext.js";
22
22
  import "../canvas-map/Map.js";
23
23
  function ResultSummary({
24
24
  previous,
@@ -1,15 +1,15 @@
1
- const tickerVertical = "_tickerVertical_ozku7_9";
2
- const ticker = "_ticker_ozku7_9";
3
- const tickerItems = "_tickerItems_ozku7_27";
4
- const tickerScrollVertical = "_tickerScrollVertical_ozku7_32";
5
- const tickerScroll = "_tickerScroll_ozku7_32";
6
- const tickerItem = "_tickerItem_ozku7_27";
7
- const controls = "_controls_ozku7_75";
8
- const gradient = "_gradient_ozku7_90";
9
- const gradientHorizontal = "_gradientHorizontal_ozku7_102";
10
- const buttons = "_buttons_ozku7_116";
11
- const button = "_button_ozku7_116";
12
- const buttonInner = "_buttonInner_ozku7_142";
1
+ const tickerVertical = "_tickerVertical_1at7j_9";
2
+ const ticker = "_ticker_1at7j_9";
3
+ const tickerItems = "_tickerItems_1at7j_28";
4
+ const tickerScrollVertical = "_tickerScrollVertical_1at7j_33";
5
+ const tickerScroll = "_tickerScroll_1at7j_33";
6
+ const tickerItem = "_tickerItem_1at7j_28";
7
+ const controls = "_controls_1at7j_76";
8
+ const gradient = "_gradient_1at7j_91";
9
+ const gradientHorizontal = "_gradientHorizontal_1at7j_103";
10
+ const buttons = "_buttons_1at7j_118";
11
+ const button = "_button_1at7j_118";
12
+ const buttonInner = "_buttonInner_1at7j_144";
13
13
  const styles = {
14
14
  tickerVertical,
15
15
  ticker,
@@ -2,7 +2,7 @@ import { jsx } from "preact/jsx-runtime";
2
2
  import defaultStyles from "./style.module.css.js";
3
3
  import { mergeStyles } from "../../../styles/helpers/mergeStyles.js";
4
4
  import dayjs from "dayjs";
5
- import relativeTime from "dayjs/plugin/relativeTime";
5
+ import relativeTime from "dayjs/plugin/relativeTime.js";
6
6
  dayjs.extend(relativeTime);
7
7
  const RelativeTimeSentence = ({ timeStamp, styles }) => {
8
8
  styles = mergeStyles({ ...defaultStyles }, styles);
package/dist/style.css CHANGED
@@ -3200,30 +3200,31 @@ body.android {
3200
3200
  --top-inset: 58px;
3201
3201
  }
3202
3202
 
3203
- ._tickerVertical_ozku7_9 {
3203
+ ._tickerVertical_1at7j_9 {
3204
3204
  position: relative;
3205
3205
  padding-bottom: 44px;
3206
3206
  --ticker-item-width: 100%;
3207
3207
  }
3208
3208
  @media (min-width: 30em) {
3209
- ._tickerVertical_ozku7_9 {
3209
+ ._tickerVertical_1at7j_9 {
3210
3210
  --ticker-item-width: auto;
3211
3211
  padding: 0;
3212
3212
  }
3213
3213
  }
3214
3214
 
3215
- ._ticker_ozku7_9 {
3215
+ ._ticker_1at7j_9 {
3216
3216
  position: relative;
3217
3217
  --ticker-item-width: 200px;
3218
3218
  padding: 0;
3219
+ cursor: default;
3219
3220
  }
3220
3221
 
3221
- ._tickerItems_ozku7_27 {
3222
+ ._tickerItems_1at7j_28 {
3222
3223
  width: 100%;
3223
3224
  overflow: clip;
3224
3225
  }
3225
3226
 
3226
- ._tickerScrollVertical_ozku7_32 {
3227
+ ._tickerScrollVertical_1at7j_33 {
3227
3228
  display: flex;
3228
3229
  flex-direction: column;
3229
3230
  row-gap: var(--space-2);
@@ -3232,7 +3233,7 @@ body.android {
3232
3233
  overflow: visible;
3233
3234
  }
3234
3235
  @media (min-width: 30em) {
3235
- ._tickerScrollVertical_ozku7_32 {
3236
+ ._tickerScrollVertical_1at7j_33 {
3236
3237
  flex-direction: row;
3237
3238
  column-gap: var(--space-2);
3238
3239
  transform: translateX(var(--ticker-offset));
@@ -3240,7 +3241,7 @@ body.android {
3240
3241
  }
3241
3242
  }
3242
3243
 
3243
- ._tickerScroll_ozku7_32 {
3244
+ ._tickerScroll_1at7j_33 {
3244
3245
  display: flex;
3245
3246
  flex-direction: row;
3246
3247
  flex-wrap: nowrap;
@@ -3252,28 +3253,28 @@ body.android {
3252
3253
  width: auto;
3253
3254
  padding-right: 50px;
3254
3255
  }
3255
- ._tickerScroll_ozku7_32:-webkit-scrollbar {
3256
+ ._tickerScroll_1at7j_33:-webkit-scrollbar {
3256
3257
  display: none; /* for Chrome, Safari, and Opera */
3257
3258
  }
3258
3259
  @media (min-width: 30em) {
3259
- ._tickerScroll_ozku7_32 {
3260
+ ._tickerScroll_1at7j_33 {
3260
3261
  width: fit-content;
3261
3262
  }
3262
3263
  }
3263
3264
 
3264
- ._tickerItem_ozku7_27 {
3265
+ ._tickerItem_1at7j_28 {
3265
3266
  width: var(--ticker-item-width);
3266
3267
  flex-shrink: 0;
3267
3268
  }
3268
3269
 
3269
- ._controls_ozku7_75 {
3270
+ ._controls_1at7j_76 {
3270
3271
  position: absolute;
3271
3272
  bottom: 0;
3272
3273
  width: 100%;
3273
3274
  height: 130px;
3274
3275
  }
3275
3276
  @media (min-width: 30em) {
3276
- ._controls_ozku7_75 {
3277
+ ._controls_1at7j_76 {
3277
3278
  top: 0;
3278
3279
  right: 0;
3279
3280
  width: 86px;
@@ -3281,19 +3282,20 @@ body.android {
3281
3282
  }
3282
3283
  }
3283
3284
 
3284
- ._gradient_ozku7_90 {
3285
+ ._gradient_1at7j_91 {
3285
3286
  width: 100%;
3286
3287
  height: 86px;
3287
3288
  }
3288
3289
  @media (min-width: 30em) {
3289
- ._gradient_ozku7_90 {
3290
+ ._gradient_1at7j_91 {
3290
3291
  width: auto;
3291
3292
  height: 100%;
3292
3293
  right: 0;
3293
3294
  }
3294
3295
  }
3295
3296
 
3296
- ._gradientHorizontal_ozku7_102 {
3297
+ ._gradientHorizontal_1at7j_103 {
3298
+ pointer-events: none;
3297
3299
  width: 60px;
3298
3300
  height: 100%;
3299
3301
  right: 0;
@@ -3302,16 +3304,16 @@ body.android {
3302
3304
  background: linear-gradient(to right, transparent 0%, var(--tertiary-bg-color) 80%, var(--tertiary-bg-color));
3303
3305
  }
3304
3306
  @media (min-width: 30em) {
3305
- ._gradientHorizontal_ozku7_102 {
3307
+ ._gradientHorizontal_1at7j_103 {
3306
3308
  width: auto;
3307
3309
  }
3308
3310
  }
3309
3311
 
3310
- ._buttons_ozku7_116 {
3312
+ ._buttons_1at7j_118 {
3311
3313
  display: none;
3312
3314
  }
3313
3315
  @media (min-width: 30em) {
3314
- ._buttons_ozku7_116 {
3316
+ ._buttons_1at7j_118 {
3315
3317
  position: absolute;
3316
3318
  top: 0;
3317
3319
  right: var(--space-5);
@@ -3322,36 +3324,36 @@ body.android {
3322
3324
  }
3323
3325
  }
3324
3326
 
3325
- ._button_ozku7_116 {
3327
+ ._button_1at7j_118 {
3326
3328
  min-height: 40px;
3327
3329
  background-color: var(--tertiary-bg-color);
3328
3330
  padding-bottom: 20px;
3329
3331
  }
3330
3332
  @media (min-width: 30em) {
3331
- ._button_ozku7_116 {
3333
+ ._button_1at7j_118 {
3332
3334
  display: none;
3333
3335
  }
3334
3336
  }
3335
3337
 
3336
- ._buttonInner_ozku7_142 {
3338
+ ._buttonInner_1at7j_144 {
3337
3339
  background-color: var(--tertiary-bg-color);
3338
3340
  }
3339
3341
 
3340
- ._tickerVertical_ozku7_9[data-expanded=true] {
3342
+ ._tickerVertical_1at7j_9[data-expanded=true] {
3341
3343
  padding-bottom: 0;
3342
3344
  }
3343
3345
 
3344
- ._tickerVertical_ozku7_9[data-expanded=true] ._tickerScrollVertical_ozku7_32 {
3346
+ ._tickerVertical_1at7j_9[data-expanded=true] ._tickerScrollVertical_1at7j_33 {
3345
3347
  max-height: fit-content;
3346
3348
  margin-bottom: -40px;
3347
3349
  }
3348
3350
 
3349
- ._tickerVertical_ozku7_9[data-expanded=true] ._controls_ozku7_75 {
3351
+ ._tickerVertical_1at7j_9[data-expanded=true] ._controls_1at7j_76 {
3350
3352
  position: sticky;
3351
3353
  margin-top: -40px;
3352
3354
  }
3353
3355
 
3354
- ._tickerVertical_ozku7_9[data-expanded=true] ._button_ozku7_116 {
3356
+ ._tickerVertical_1at7j_9[data-expanded=true] ._button_1at7j_118 {
3355
3357
  position: absolute;
3356
3358
  width: 100%;
3357
3359
  left: 0;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@guardian/interactive-component-library",
3
3
  "private": false,
4
- "version": "0.4.5",
4
+ "version": "0.5.0",
5
5
  "packageManager": "pnpm@8.4.0",
6
6
  "repository": {
7
7
  "type": "git",