@dative-gpi/foundation-shared-components 1.0.138 → 1.0.139-auth-token

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"
@@ -0,0 +1,83 @@
1
+ <template>
2
+ <FSSearchField
3
+ :modelValue="$props.modelValue"
4
+ :appendInnerIcon="$props.closable ? $props.appendInnerIcon : null"
5
+ :clearable="false"
6
+ @click:appendInner="onCloseClicked"
7
+ @update:modelValue="$emit('update:modelValue', $event)"
8
+ v-bind="$attrs"
9
+ >
10
+ <template
11
+ v-for="(_, name) in $slots"
12
+ v-slot:[name]="slotData"
13
+ >
14
+ <slot
15
+ :name="name"
16
+ v-bind="slotData"
17
+ />
18
+ </template>
19
+ </FSSearchField>
20
+ </template>
21
+
22
+ <script lang="ts">
23
+ import { defineComponent, type PropType } from "vue";
24
+
25
+ import FSSearchField from "./FSSearchField.vue";
26
+
27
+ export default defineComponent({
28
+ name: "FSClosableSearchField",
29
+ components: {
30
+ FSSearchField
31
+ },
32
+ props: {
33
+ closable: {
34
+ type: Boolean as PropType<boolean>,
35
+ required: false,
36
+ default: true
37
+ },
38
+ unfocusOnClose: {
39
+ type: Boolean as PropType<boolean>,
40
+ required: false,
41
+ default: true
42
+ },
43
+ clearOnClose: {
44
+ type: Boolean as PropType<boolean>,
45
+ required: false,
46
+ default: true
47
+ },
48
+ modelValue: {
49
+ type: String as PropType<string | null>,
50
+ required: false,
51
+ default: null
52
+ },
53
+ appendInnerIcon: {
54
+ type: String as PropType<string | undefined>,
55
+ required: false,
56
+ default: 'mdi-close'
57
+ }
58
+ },
59
+ emits: ["update:modelValue", "close"],
60
+ setup(props, { emit }) {
61
+ const onCloseClicked = ($event: MouseEvent) => {
62
+ if(!props.closable) {
63
+ return;
64
+ }
65
+
66
+ if (props.unfocusOnClose) {
67
+ $event.preventDefault();
68
+ $event.stopPropagation();
69
+ (document.activeElement as HTMLElement)?.blur();
70
+ }
71
+ if (props.clearOnClose) {
72
+ emit('update:modelValue', null);
73
+ }
74
+
75
+ emit('close');
76
+ };
77
+
78
+ return {
79
+ onCloseClicked
80
+ };
81
+ }
82
+ });
83
+ </script>
@@ -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, () => {
@@ -2,6 +2,7 @@
2
2
  <FSTile
3
3
  :width="['275px','336px']"
4
4
  :height="['124px','156px']"
5
+ :editable="$props.editable"
5
6
  borderRadius="8px"
6
7
  v-bind="$attrs"
7
8
  >
@@ -99,6 +100,11 @@ export default defineComponent({
99
100
  type: Number as PropType<ChartType>,
100
101
  required: false,
101
102
  default: ChartType.None
103
+ },
104
+ editable: {
105
+ type: Boolean,
106
+ required: false,
107
+ default: true
102
108
  }
103
109
  },
104
110
  setup() {
@@ -4,58 +4,54 @@
4
4
  :height="$props.height"
5
5
  :width="$props.width"
6
6
  >
7
- <template
8
- v-if="$props.editable"
7
+ <FSClickable
8
+ v-if="$props.editable && $props.singleSelect"
9
+ padding="12px"
10
+ :variant="variant"
11
+ :color="color"
12
+ :style="style"
13
+ :to="$props.to"
14
+ :href="$props.href"
15
+ width="100%"
16
+ height="100%"
17
+ @click="() => $emit('update:modelValue', !$props.modelValue)"
18
+ v-bind="$attrs"
9
19
  >
10
- <FSClickable
11
- v-if="$props.singleSelect"
12
- padding="12px"
13
- :variant="variant"
14
- :color="color"
15
- :style="style"
16
- width="100%"
17
- height="100%"
18
- @click="() => $emit('update:modelValue', !$props.modelValue)"
19
- v-bind="$attrs"
20
- >
21
- <slot />
22
- </FSClickable>
23
- <FSClickable
24
- v-else-if="$props.href || $props.to || $attrs.onClick"
25
- variant="background"
26
- class="fs-tile"
27
- padding="12px"
28
- :color="ColorEnum.Background"
29
- :href="$props.href"
30
- width="100%"
31
- height="100%"
32
- :to="$props.to"
33
- :style="style"
34
- v-bind="$attrs"
20
+ <slot />
21
+ </FSClickable>
22
+
23
+
24
+ <FSClickable
25
+ v-else-if="$props.editable && ($props.href || $props.to || $attrs.onClick)"
26
+ variant="background"
27
+ class="fs-tile"
28
+ padding="12px"
29
+ :href="$props.href"
30
+ width="100%"
31
+ height="100%"
32
+ :to="$props.to"
33
+ :style="style"
34
+ v-bind="$attrs"
35
+ >
36
+ <slot />
37
+ <FSCard
38
+ class="fs-tile-checkbox"
39
+ :height="['40px', '32px']"
40
+ :width="['40px', '32px']"
41
+ :border="false"
35
42
  >
36
- <slot />
37
- <FSCard
38
- v-if="$props.editable"
39
- class="fs-tile-checkbox"
40
- variant="background"
41
- :height="['40px', '32px']"
42
- :width="['40px', '32px']"
43
- :border="false"
44
- v-bind="$attrs"
45
- >
46
- <FSCheckbox
47
- :modelValue="$props.modelValue"
48
- @update:modelValue="() => $emit('update:modelValue', !$props.modelValue)"
49
- />
50
- </FSCard>
51
- </FSClickable>
52
- </template>
43
+ <FSCheckbox
44
+ :modelValue="$props.modelValue"
45
+ @update:modelValue="() => $emit('update:modelValue', !$props.modelValue)"
46
+ />
47
+ </FSCard>
48
+ </FSClickable>
49
+
53
50
  <FSCard
54
51
  v-else
55
52
  variant="background"
56
53
  class="fs-tile"
57
54
  padding="12px"
58
- :color="color"
59
55
  :style="style"
60
56
  width="100%"
61
57
  height="100%"
@@ -69,7 +65,6 @@
69
65
  :height="['40px', '32px']"
70
66
  :width="['40px', '32px']"
71
67
  :border="false"
72
- v-bind="$attrs"
73
68
  >
74
69
  <FSCheckbox
75
70
  :modelValue="$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.138",
4
+ "version": "1.0.139-auth-token",
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.138",
14
- "@dative-gpi/foundation-shared-services": "1.0.138"
13
+ "@dative-gpi/foundation-shared-domain": "1.0.139-auth-token",
14
+ "@dative-gpi/foundation-shared-services": "1.0.139-auth-token"
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": "ec1370eef99afdec2bd4425c7010c1012c23563e"
38
+ "gitHead": "af9d894b3fa209b796f8466b8545bb1ecc46a399"
39
39
  }