@pro6pp/infer-react 0.0.2-beta.12 → 0.0.2-beta.14

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/dist/index.cjs CHANGED
@@ -56,6 +56,7 @@ var INITIAL_STATE = {
56
56
  streets: [],
57
57
  suggestions: [],
58
58
  isValid: false,
59
+ value: null,
59
60
  isError: false,
60
61
  isLoading: false,
61
62
  hasMore: false,
@@ -111,6 +112,7 @@ var InferCore = class {
111
112
  this.updateState({
112
113
  query: value,
113
114
  isValid: false,
115
+ value: null,
114
116
  isLoading: !!value.trim(),
115
117
  selectedSuggestionIndex: -1,
116
118
  hasMore: false
@@ -228,6 +230,7 @@ var InferCore = class {
228
230
  cities: [],
229
231
  streets: [],
230
232
  isValid: true,
233
+ value: value || null,
231
234
  stage: "final",
232
235
  hasMore: false
233
236
  });
@@ -283,10 +286,12 @@ var InferCore = class {
283
286
  const currentSignal = this.abortController?.signal;
284
287
  const baseUrl = this.explicitApiUrl ? this.explicitApiUrl : `${DEFAULTS.API_URL}/infer/${this.country.toLowerCase()}`;
285
288
  const params = new URLSearchParams({
286
- country: this.country.toLowerCase(),
287
289
  query: text,
288
290
  limit: this.currentLimit.toString()
289
291
  });
292
+ if (this.explicitApiUrl) {
293
+ params.append("country", this.country.toLowerCase());
294
+ }
290
295
  if (this.authKey) {
291
296
  params.set("authKey", this.authKey);
292
297
  }
@@ -352,8 +357,16 @@ var InferCore = class {
352
357
  }
353
358
  }
354
359
  updateQueryAndFetch(nextQuery) {
355
- this.updateState({ query: nextQuery, suggestions: [], cities: [], streets: [] });
356
- this.updateState({ isLoading: true, isValid: false, hasMore: false });
360
+ this.updateState({
361
+ query: nextQuery,
362
+ suggestions: [],
363
+ cities: [],
364
+ streets: [],
365
+ isValid: false,
366
+ value: null,
367
+ isLoading: true,
368
+ hasMore: false
369
+ });
357
370
  this.debouncedFetch(nextQuery);
358
371
  }
359
372
  replaceLastSegment(fullText, newSegment) {
@@ -444,6 +457,12 @@ var DEFAULT_STYLES = `
444
457
  appearance: none;
445
458
  transition: border-color 0.2s, box-shadow 0.2s;
446
459
  }
460
+
461
+ .pro6pp-input::placeholder {
462
+ font-size: 16px;
463
+ color: #a3a3a3;
464
+ }
465
+
447
466
  .pro6pp-input:focus {
448
467
  outline: none;
449
468
  border-color: #3b82f6;
@@ -466,8 +485,8 @@ var DEFAULT_STYLES = `
466
485
  .pro6pp-clear-button {
467
486
  background: none;
468
487
  border: none;
469
- width: 40px;
470
- height: 40px;
488
+ width: 32px;
489
+ height: 32px;
471
490
  cursor: pointer;
472
491
  color: #a3a3a3;
473
492
  display: flex;
@@ -512,7 +531,7 @@ var DEFAULT_STYLES = `
512
531
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
513
532
  z-index: 9999;
514
533
  padding: 0;
515
- max-height: 260px;
534
+ max-height: 280px;
516
535
  overflow-y: auto;
517
536
  display: flex;
518
537
  flex-direction: column;
@@ -520,7 +539,7 @@ var DEFAULT_STYLES = `
520
539
 
521
540
  @media (max-height: 500px) {
522
541
  .pro6pp-dropdown {
523
- max-height: 140px;
542
+ max-height: 180px;
524
543
  }
525
544
  }
526
545
 
@@ -536,7 +555,8 @@ var DEFAULT_STYLES = `
536
555
  cursor: pointer;
537
556
  display: flex;
538
557
  align-items: center;
539
- font-size: 14px;
558
+ font-size: 15px;
559
+ line-height: 1.4;
540
560
  color: #374151;
541
561
  border-bottom: 1px solid #f3f4f6;
542
562
  transition: background-color 0.1s;
@@ -559,18 +579,24 @@ var DEFAULT_STYLES = `
559
579
 
560
580
  .pro6pp-item__label {
561
581
  font-weight: 500;
562
- flex-shrink: 0;
582
+ flex-shrink: 1;
583
+ overflow: hidden;
584
+ text-overflow: ellipsis;
585
+ white-space: nowrap;
563
586
  }
587
+
564
588
  .pro6pp-item__subtitle {
565
- font-size: 14px;
589
+ font-size: 13px;
566
590
  color: #6b7280;
567
- flex-grow: 1;
591
+ flex-shrink: 0;
568
592
  }
593
+
569
594
  .pro6pp-item__chevron {
570
595
  color: #d1d5db;
571
596
  display: flex;
572
597
  align-items: center;
573
598
  margin-left: auto;
599
+ padding-left: 8px;
574
600
  }
575
601
 
576
602
  .pro6pp-no-results {
@@ -594,6 +620,24 @@ var DEFAULT_STYLES = `
594
620
  touch-action: manipulation;
595
621
  }
596
622
 
623
+ @media (max-width: 640px) {
624
+ .pro6pp-input {
625
+ font-size: 16px;
626
+ padding: 10px 12px;
627
+ }
628
+ .pro6pp-item {
629
+ padding: 10px 12px;
630
+ font-size: 14px;
631
+ }
632
+ .pro6pp-item__subtitle {
633
+ font-size: 12px;
634
+ }
635
+ .pro6pp-load-more {
636
+ padding: 12px;
637
+ font-size: 13px;
638
+ }
639
+ }
640
+
597
641
  .pro6pp-load-more:active {
598
642
  background-color: #f3f4f6;
599
643
  }
@@ -611,7 +655,18 @@ var HighlightedText = ({ text, query }) => {
611
655
  ));
612
656
  };
613
657
  function useInfer(config) {
614
- const [state, setState] = (0, import_react.useState)(INITIAL_STATE);
658
+ const [state, setState] = (0, import_react.useState)(() => {
659
+ if (config.initialValue) {
660
+ return {
661
+ ...INITIAL_STATE,
662
+ value: config.initialValue,
663
+ query: `${config.initialValue.street} ${config.initialValue.street_number}, ${config.initialValue.city}`,
664
+ isValid: true,
665
+ stage: "final"
666
+ };
667
+ }
668
+ return INITIAL_STATE;
669
+ });
615
670
  const callbacksRef = (0, import_react.useRef)({
616
671
  onStateChange: config.onStateChange,
617
672
  onSelect: config.onSelect
@@ -623,7 +678,7 @@ function useInfer(config) {
623
678
  };
624
679
  }, [config.onStateChange, config.onSelect]);
625
680
  const core = (0, import_react.useMemo)(() => {
626
- return new InferCore({
681
+ const instance = new InferCore({
627
682
  ...config,
628
683
  onStateChange: (newState) => {
629
684
  setState({ ...newState });
@@ -633,6 +688,12 @@ function useInfer(config) {
633
688
  callbacksRef.current.onSelect?.(selection);
634
689
  }
635
690
  });
691
+ if (config.initialValue) {
692
+ const address = config.initialValue;
693
+ const label = `${address.street} ${address.street_number}, ${address.city}`;
694
+ instance.selectItem({ label, value: address });
695
+ }
696
+ return instance;
636
697
  }, [
637
698
  config.country,
638
699
  config.authKey,
@@ -640,10 +701,16 @@ function useInfer(config) {
640
701
  config.fetcher,
641
702
  config.limit,
642
703
  config.debounceMs,
643
- config.maxRetries
704
+ config.maxRetries,
705
+ config.initialValue
644
706
  ]);
707
+ const setValue = (address) => {
708
+ if (!address) return;
709
+ const label = `${address.street} ${address.street_number}, ${address.city}`;
710
+ core.selectItem({ label, value: address });
711
+ };
645
712
  return {
646
- /** The current UI state (suggestions, loading status, query, etc.). */
713
+ /** The current UI state (suggestions, loading status, query, value, etc.). */
647
714
  state,
648
715
  /** The raw InferCore instance for manual control. */
649
716
  core,
@@ -653,9 +720,11 @@ function useInfer(config) {
653
720
  onChange: (e) => core.handleInput(e.target.value),
654
721
  onKeyDown: (e) => core.handleKeyDown(e)
655
722
  },
656
- /** Function to manually select a specific suggestion. */
723
+ /** Manually select a specific suggestion. */
657
724
  selectItem: (item) => core.selectItem(item),
658
- /** Function to load more results. */
725
+ /** Programmatically set the address value. */
726
+ setValue,
727
+ /** Load more results. */
659
728
  loadMore: () => core.loadMore()
660
729
  };
661
730
  }
package/dist/index.d.cts CHANGED
@@ -1,14 +1,23 @@
1
1
  import React from 'react';
2
- import { InferConfig, InferState, InferCore, InferResult } from '@pro6pp/infer-core';
2
+ import { InferConfig, AddressValue, InferState, InferCore, InferResult } from '@pro6pp/infer-core';
3
3
  export { AddressValue, CountryCode, Fetcher, InferConfig, InferResult, InferState, Stage } from '@pro6pp/infer-core';
4
4
 
5
+ /**
6
+ * Extended configuration for the React hook.
7
+ */
8
+ interface UseInferConfig extends InferConfig {
9
+ /**
10
+ * Initial address value to pre-fill the state with.
11
+ */
12
+ initialValue?: AddressValue;
13
+ }
5
14
  /**
6
15
  * A headless React hook that provides the logic for address search using the Infer API.
7
16
  * @param config The engine configuration (authKey, country, etc.).
8
17
  * @returns An object containing the current state, the core instance, and pre-bound input props.
9
18
  */
10
- declare function useInfer(config: InferConfig): {
11
- /** The current UI state (suggestions, loading status, query, etc.). */
19
+ declare function useInfer(config: UseInferConfig): {
20
+ /** The current UI state (suggestions, loading status, query, value, etc.). */
12
21
  state: InferState;
13
22
  /** The raw InferCore instance for manual control. */
14
23
  core: InferCore;
@@ -18,15 +27,17 @@ declare function useInfer(config: InferConfig): {
18
27
  onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
19
28
  onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void;
20
29
  };
21
- /** Function to manually select a specific suggestion. */
30
+ /** Manually select a specific suggestion. */
22
31
  selectItem: (item: InferResult | string) => boolean;
23
- /** Function to load more results. */
32
+ /** Programmatically set the address value. */
33
+ setValue: (address: AddressValue) => void;
34
+ /** Load more results. */
24
35
  loadMore: () => void;
25
36
  };
26
37
  /**
27
38
  * Props for the Pro6PPInfer component.
28
39
  */
29
- interface Pro6PPInferProps extends InferConfig {
40
+ interface Pro6PPInferProps extends UseInferConfig {
30
41
  /** Optional CSS class for the wrapper div. */
31
42
  className?: string;
32
43
  /** Optional inline styles for the wrapper div. */
@@ -65,4 +76,4 @@ interface Pro6PPInferProps extends InferConfig {
65
76
  */
66
77
  declare const Pro6PPInfer: React.ForwardRefExoticComponent<Pro6PPInferProps & React.RefAttributes<HTMLInputElement>>;
67
78
 
68
- export { Pro6PPInfer, type Pro6PPInferProps, useInfer };
79
+ export { Pro6PPInfer, type Pro6PPInferProps, type UseInferConfig, useInfer };
package/dist/index.d.ts CHANGED
@@ -1,14 +1,23 @@
1
1
  import React from 'react';
2
- import { InferConfig, InferState, InferCore, InferResult } from '@pro6pp/infer-core';
2
+ import { InferConfig, AddressValue, InferState, InferCore, InferResult } from '@pro6pp/infer-core';
3
3
  export { AddressValue, CountryCode, Fetcher, InferConfig, InferResult, InferState, Stage } from '@pro6pp/infer-core';
4
4
 
5
+ /**
6
+ * Extended configuration for the React hook.
7
+ */
8
+ interface UseInferConfig extends InferConfig {
9
+ /**
10
+ * Initial address value to pre-fill the state with.
11
+ */
12
+ initialValue?: AddressValue;
13
+ }
5
14
  /**
6
15
  * A headless React hook that provides the logic for address search using the Infer API.
7
16
  * @param config The engine configuration (authKey, country, etc.).
8
17
  * @returns An object containing the current state, the core instance, and pre-bound input props.
9
18
  */
10
- declare function useInfer(config: InferConfig): {
11
- /** The current UI state (suggestions, loading status, query, etc.). */
19
+ declare function useInfer(config: UseInferConfig): {
20
+ /** The current UI state (suggestions, loading status, query, value, etc.). */
12
21
  state: InferState;
13
22
  /** The raw InferCore instance for manual control. */
14
23
  core: InferCore;
@@ -18,15 +27,17 @@ declare function useInfer(config: InferConfig): {
18
27
  onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
19
28
  onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void;
20
29
  };
21
- /** Function to manually select a specific suggestion. */
30
+ /** Manually select a specific suggestion. */
22
31
  selectItem: (item: InferResult | string) => boolean;
23
- /** Function to load more results. */
32
+ /** Programmatically set the address value. */
33
+ setValue: (address: AddressValue) => void;
34
+ /** Load more results. */
24
35
  loadMore: () => void;
25
36
  };
26
37
  /**
27
38
  * Props for the Pro6PPInfer component.
28
39
  */
29
- interface Pro6PPInferProps extends InferConfig {
40
+ interface Pro6PPInferProps extends UseInferConfig {
30
41
  /** Optional CSS class for the wrapper div. */
31
42
  className?: string;
32
43
  /** Optional inline styles for the wrapper div. */
@@ -65,4 +76,4 @@ interface Pro6PPInferProps extends InferConfig {
65
76
  */
66
77
  declare const Pro6PPInfer: React.ForwardRefExoticComponent<Pro6PPInferProps & React.RefAttributes<HTMLInputElement>>;
67
78
 
68
- export { Pro6PPInfer, type Pro6PPInferProps, useInfer };
79
+ export { Pro6PPInfer, type Pro6PPInferProps, type UseInferConfig, useInfer };
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ var INITIAL_STATE = {
30
30
  streets: [],
31
31
  suggestions: [],
32
32
  isValid: false,
33
+ value: null,
33
34
  isError: false,
34
35
  isLoading: false,
35
36
  hasMore: false,
@@ -85,6 +86,7 @@ var InferCore = class {
85
86
  this.updateState({
86
87
  query: value,
87
88
  isValid: false,
89
+ value: null,
88
90
  isLoading: !!value.trim(),
89
91
  selectedSuggestionIndex: -1,
90
92
  hasMore: false
@@ -202,6 +204,7 @@ var InferCore = class {
202
204
  cities: [],
203
205
  streets: [],
204
206
  isValid: true,
207
+ value: value || null,
205
208
  stage: "final",
206
209
  hasMore: false
207
210
  });
@@ -257,10 +260,12 @@ var InferCore = class {
257
260
  const currentSignal = this.abortController?.signal;
258
261
  const baseUrl = this.explicitApiUrl ? this.explicitApiUrl : `${DEFAULTS.API_URL}/infer/${this.country.toLowerCase()}`;
259
262
  const params = new URLSearchParams({
260
- country: this.country.toLowerCase(),
261
263
  query: text,
262
264
  limit: this.currentLimit.toString()
263
265
  });
266
+ if (this.explicitApiUrl) {
267
+ params.append("country", this.country.toLowerCase());
268
+ }
264
269
  if (this.authKey) {
265
270
  params.set("authKey", this.authKey);
266
271
  }
@@ -326,8 +331,16 @@ var InferCore = class {
326
331
  }
327
332
  }
328
333
  updateQueryAndFetch(nextQuery) {
329
- this.updateState({ query: nextQuery, suggestions: [], cities: [], streets: [] });
330
- this.updateState({ isLoading: true, isValid: false, hasMore: false });
334
+ this.updateState({
335
+ query: nextQuery,
336
+ suggestions: [],
337
+ cities: [],
338
+ streets: [],
339
+ isValid: false,
340
+ value: null,
341
+ isLoading: true,
342
+ hasMore: false
343
+ });
331
344
  this.debouncedFetch(nextQuery);
332
345
  }
333
346
  replaceLastSegment(fullText, newSegment) {
@@ -418,6 +431,12 @@ var DEFAULT_STYLES = `
418
431
  appearance: none;
419
432
  transition: border-color 0.2s, box-shadow 0.2s;
420
433
  }
434
+
435
+ .pro6pp-input::placeholder {
436
+ font-size: 16px;
437
+ color: #a3a3a3;
438
+ }
439
+
421
440
  .pro6pp-input:focus {
422
441
  outline: none;
423
442
  border-color: #3b82f6;
@@ -440,8 +459,8 @@ var DEFAULT_STYLES = `
440
459
  .pro6pp-clear-button {
441
460
  background: none;
442
461
  border: none;
443
- width: 40px;
444
- height: 40px;
462
+ width: 32px;
463
+ height: 32px;
445
464
  cursor: pointer;
446
465
  color: #a3a3a3;
447
466
  display: flex;
@@ -486,7 +505,7 @@ var DEFAULT_STYLES = `
486
505
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
487
506
  z-index: 9999;
488
507
  padding: 0;
489
- max-height: 260px;
508
+ max-height: 280px;
490
509
  overflow-y: auto;
491
510
  display: flex;
492
511
  flex-direction: column;
@@ -494,7 +513,7 @@ var DEFAULT_STYLES = `
494
513
 
495
514
  @media (max-height: 500px) {
496
515
  .pro6pp-dropdown {
497
- max-height: 140px;
516
+ max-height: 180px;
498
517
  }
499
518
  }
500
519
 
@@ -510,7 +529,8 @@ var DEFAULT_STYLES = `
510
529
  cursor: pointer;
511
530
  display: flex;
512
531
  align-items: center;
513
- font-size: 14px;
532
+ font-size: 15px;
533
+ line-height: 1.4;
514
534
  color: #374151;
515
535
  border-bottom: 1px solid #f3f4f6;
516
536
  transition: background-color 0.1s;
@@ -533,18 +553,24 @@ var DEFAULT_STYLES = `
533
553
 
534
554
  .pro6pp-item__label {
535
555
  font-weight: 500;
536
- flex-shrink: 0;
556
+ flex-shrink: 1;
557
+ overflow: hidden;
558
+ text-overflow: ellipsis;
559
+ white-space: nowrap;
537
560
  }
561
+
538
562
  .pro6pp-item__subtitle {
539
- font-size: 14px;
563
+ font-size: 13px;
540
564
  color: #6b7280;
541
- flex-grow: 1;
565
+ flex-shrink: 0;
542
566
  }
567
+
543
568
  .pro6pp-item__chevron {
544
569
  color: #d1d5db;
545
570
  display: flex;
546
571
  align-items: center;
547
572
  margin-left: auto;
573
+ padding-left: 8px;
548
574
  }
549
575
 
550
576
  .pro6pp-no-results {
@@ -568,6 +594,24 @@ var DEFAULT_STYLES = `
568
594
  touch-action: manipulation;
569
595
  }
570
596
 
597
+ @media (max-width: 640px) {
598
+ .pro6pp-input {
599
+ font-size: 16px;
600
+ padding: 10px 12px;
601
+ }
602
+ .pro6pp-item {
603
+ padding: 10px 12px;
604
+ font-size: 14px;
605
+ }
606
+ .pro6pp-item__subtitle {
607
+ font-size: 12px;
608
+ }
609
+ .pro6pp-load-more {
610
+ padding: 12px;
611
+ font-size: 13px;
612
+ }
613
+ }
614
+
571
615
  .pro6pp-load-more:active {
572
616
  background-color: #f3f4f6;
573
617
  }
@@ -585,7 +629,18 @@ var HighlightedText = ({ text, query }) => {
585
629
  ));
586
630
  };
587
631
  function useInfer(config) {
588
- const [state, setState] = useState(INITIAL_STATE);
632
+ const [state, setState] = useState(() => {
633
+ if (config.initialValue) {
634
+ return {
635
+ ...INITIAL_STATE,
636
+ value: config.initialValue,
637
+ query: `${config.initialValue.street} ${config.initialValue.street_number}, ${config.initialValue.city}`,
638
+ isValid: true,
639
+ stage: "final"
640
+ };
641
+ }
642
+ return INITIAL_STATE;
643
+ });
589
644
  const callbacksRef = useRef({
590
645
  onStateChange: config.onStateChange,
591
646
  onSelect: config.onSelect
@@ -597,7 +652,7 @@ function useInfer(config) {
597
652
  };
598
653
  }, [config.onStateChange, config.onSelect]);
599
654
  const core = useMemo(() => {
600
- return new InferCore({
655
+ const instance = new InferCore({
601
656
  ...config,
602
657
  onStateChange: (newState) => {
603
658
  setState({ ...newState });
@@ -607,6 +662,12 @@ function useInfer(config) {
607
662
  callbacksRef.current.onSelect?.(selection);
608
663
  }
609
664
  });
665
+ if (config.initialValue) {
666
+ const address = config.initialValue;
667
+ const label = `${address.street} ${address.street_number}, ${address.city}`;
668
+ instance.selectItem({ label, value: address });
669
+ }
670
+ return instance;
610
671
  }, [
611
672
  config.country,
612
673
  config.authKey,
@@ -614,10 +675,16 @@ function useInfer(config) {
614
675
  config.fetcher,
615
676
  config.limit,
616
677
  config.debounceMs,
617
- config.maxRetries
678
+ config.maxRetries,
679
+ config.initialValue
618
680
  ]);
681
+ const setValue = (address) => {
682
+ if (!address) return;
683
+ const label = `${address.street} ${address.street_number}, ${address.city}`;
684
+ core.selectItem({ label, value: address });
685
+ };
619
686
  return {
620
- /** The current UI state (suggestions, loading status, query, etc.). */
687
+ /** The current UI state (suggestions, loading status, query, value, etc.). */
621
688
  state,
622
689
  /** The raw InferCore instance for manual control. */
623
690
  core,
@@ -627,9 +694,11 @@ function useInfer(config) {
627
694
  onChange: (e) => core.handleInput(e.target.value),
628
695
  onKeyDown: (e) => core.handleKeyDown(e)
629
696
  },
630
- /** Function to manually select a specific suggestion. */
697
+ /** Manually select a specific suggestion. */
631
698
  selectItem: (item) => core.selectItem(item),
632
- /** Function to load more results. */
699
+ /** Programmatically set the address value. */
700
+ setValue,
701
+ /** Load more results. */
633
702
  loadMore: () => core.loadMore()
634
703
  };
635
704
  }
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "url": "https://github.com/pro6pp/infer-sdk/issues"
21
21
  },
22
22
  "sideEffects": false,
23
- "version": "0.0.2-beta.12",
23
+ "version": "0.0.2-beta.14",
24
24
  "main": "./dist/index.cjs",
25
25
  "module": "./dist/index.js",
26
26
  "types": "./dist/index.d.ts",
@@ -46,7 +46,7 @@
46
46
  "react": ">=16"
47
47
  },
48
48
  "dependencies": {
49
- "@pro6pp/infer-core": "0.0.2-beta.10"
49
+ "@pro6pp/infer-core": "0.0.2-beta.12"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@testing-library/dom": "^10.4.1",