@dative-gpi/foundation-shared-components 1.0.139-reportV1 → 1.0.139-widgetextensions

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.
@@ -5,6 +5,9 @@
5
5
  :toggleSet="false"
6
6
  :multiple="false"
7
7
  :items="items"
8
+ :customFilter="(_label: string, _query: string, item: any) => {
9
+ return item.value !== $props.modelValue?.placeId;
10
+ }"
8
11
  :modelValue="$props.modelValue?.placeId"
9
12
  @update:modelValue="onUpdate"
10
13
  v-model:search="search"
@@ -501,11 +501,11 @@ export default defineComponent({
501
501
  return;
502
502
  }
503
503
  const editorModelValue = JSON.stringify(editorState.toJSON());
504
- if(editorModelValue === emptyLexicalState) {
504
+ if(editorModelValue === emptyLexicalState && props.modelValue !== null) {
505
505
  emit("update:modelValue", null);
506
506
  return;
507
507
  }
508
- if(editorModelValue !== props.modelValue) {
508
+ if(editorModelValue !== emptyLexicalState && editorModelValue !== props.modelValue) {
509
509
  emit("update:modelValue", editorModelValue);
510
510
  }
511
511
  });
@@ -674,21 +674,16 @@ export default defineComponent({
674
674
  return;
675
675
  }
676
676
  if (props.modelValue != null) {
677
- editor.update(() => {
678
- if (typeof props.modelValue === "string") {
679
- if (props.modelValue !== "") {
680
- editor.setEditorState(editor.parseEditorState(props.modelValue!));
681
- }
682
- }
683
- else {
684
- editor.setEditorState(editor.parseEditorState(JSON.stringify(props.modelValue)));
685
- }
686
- });
687
- return;
677
+ if (typeof props.modelValue === "string" && props.modelValue !== "") {
678
+ editor.setEditorState(editor.parseEditorState(props.modelValue!));
679
+ return;
680
+ }
681
+ if (typeof props.modelValue === "object") {
682
+ editor.setEditorState(editor.parseEditorState(JSON.stringify(props.modelValue)));
683
+ return;
684
+ }
688
685
  }
689
- editor.update(() => {
690
- editor.setEditorState(editor.parseEditorState(emptyLexicalState));
691
- });
686
+ editor.setEditorState(editor.parseEditorState(emptyLexicalState));
692
687
  }
693
688
 
694
689
  watch(() => props.modelValue, () => {
@@ -1,20 +1,25 @@
1
+ /// <reference types="@types/google.maps" />
1
2
  import _ from "lodash";
2
3
 
3
4
  import { Address, type Place } from "@dative-gpi/foundation-shared-domain/models";
5
+ import { useAppLanguageCode } from '@dative-gpi/foundation-shared-services/composables';
4
6
 
5
7
  export const useAddress = () => {
6
8
  const enabled = true;
9
+ const { languageCode } = useAppLanguageCode();
10
+
7
11
  let initialized = false;
12
+ let userLocation: google.maps.LatLngLiteral | null;
8
13
  let searchService: google.maps.places.AutocompleteService;
9
14
  let placeService: google.maps.places.PlacesService;
10
15
  let sessionId: google.maps.places.AutocompleteSessionToken;
11
-
12
16
 
13
17
  const init = async () => {
14
18
  await window.initMap;
19
+ userLocation = await getCurrentLocation();
15
20
  searchService = new google.maps.places.AutocompleteService();
16
21
  placeService = new google.maps.places.PlacesService(
17
- document.getElementById("places") as HTMLDivElement
22
+ document.createElement("div")
18
23
  );
19
24
  sessionId = new google.maps.places.AutocompleteSessionToken();
20
25
  initialized = true;
@@ -25,11 +30,12 @@ export const useAddress = () => {
25
30
  await init();
26
31
  }
27
32
 
28
- return _search(search).then(result => {
29
- return _.map(result, r => ({ id: r.place_id, label: r.description }));
30
- }).catch(() => {
31
- return [];
32
- });
33
+ const mapsResults = await _search(search);
34
+
35
+ return mapsResults.map((result) => ({
36
+ id: result.place_id,
37
+ label: result.description
38
+ }));
33
39
  }
34
40
 
35
41
  const get = async (place: Place): Promise<Address> => {
@@ -78,16 +84,42 @@ export const useAddress = () => {
78
84
  });
79
85
  }
80
86
 
87
+ const getCurrentLocation = async (): Promise<google.maps.LatLngLiteral | null> => {
88
+ if (!navigator.geolocation) {
89
+ return null;
90
+ }
91
+
92
+ return new Promise((resolve) => {
93
+ navigator.geolocation.getCurrentPosition(
94
+ (position) => {
95
+ resolve({
96
+ lat: position.coords.latitude,
97
+ lng: position.coords.longitude
98
+ });
99
+ },
100
+ () => resolve(null)
101
+ );
102
+ });
103
+ };
104
+
81
105
  const _search = (search: string) => {
82
106
  if (!enabled) {
83
107
  throw new Error("offline mode, do not call this method");
84
108
  }
85
109
  return new Promise<google.maps.places.AutocompletePrediction[]>(
86
110
  (resolve, reject) => {
111
+ /**
112
+ * ISO 3166 language code
113
+ */
114
+ const isoLanguageCode = languageCode.value?.split("-")[0];
115
+
87
116
  searchService!.getPlacePredictions(
88
117
  {
89
118
  input: search,
90
- sessionToken: sessionId!
119
+ region: isoLanguageCode,
120
+ language: isoLanguageCode,
121
+ sessionToken: sessionId,
122
+ locationBias: userLocation,
91
123
  },
92
124
  function (result, status) {
93
125
  if (status != google.maps.places.PlacesServiceStatus.OK || !result) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dative-gpi/foundation-shared-components",
3
3
  "sideEffects": false,
4
- "version": "1.0.139-reportV1",
4
+ "version": "1.0.139-widgetextensions",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -10,8 +10,8 @@
10
10
  "author": "",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
- "@dative-gpi/foundation-shared-domain": "1.0.139-reportV1",
14
- "@dative-gpi/foundation-shared-services": "1.0.139-reportV1"
13
+ "@dative-gpi/foundation-shared-domain": "1.0.139-widgetextensions",
14
+ "@dative-gpi/foundation-shared-services": "1.0.139-widgetextensions"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "@dative-gpi/bones-ui": "^1.0.0",
@@ -35,5 +35,5 @@
35
35
  "sass": "1.71.1",
36
36
  "sass-loader": "13.3.2"
37
37
  },
38
- "gitHead": "dc53795b0a04d981780fa23fab46baad9c22f17c"
38
+ "gitHead": "940ca3219ce7b2be17e5977c2e539131d353380e"
39
39
  }