@lowdefy/blocks-google-maps 6.1.0 → 7.0.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.
- package/dist/blocks/GoogleMapsHeatmap/gallery.yaml +1 -1
- package/dist/blocks/PlacesAutocomplete/PlacesAutocomplete.js +286 -0
- package/dist/blocks/PlacesAutocomplete/e2e.js +39 -0
- package/dist/blocks/PlacesAutocomplete/gallery.yaml +228 -0
- package/dist/blocks/PlacesAutocomplete/getLoadedPlacesLibrary.js +21 -0
- package/dist/blocks/PlacesAutocomplete/getNotFoundContent.js +23 -0
- package/dist/blocks/PlacesAutocomplete/getPlaceKeys.js +36 -0
- package/dist/blocks/PlacesAutocomplete/mapPlaceResult.js +26 -0
- package/dist/blocks/PlacesAutocomplete/meta.js +305 -0
- package/dist/blocks/PlacesAutocomplete/removePlaceKeys.js +53 -0
- package/dist/blocks/PlacesAutocomplete/style.css +28 -0
- package/dist/blocks/PlacesAutocomplete/useAutocompleteSuggestions.js +83 -0
- package/dist/blocks/PlacesAutocomplete/usePlacesLibrary.js +40 -0
- package/dist/blocks.js +1 -0
- package/dist/e2e.js +1 -0
- package/dist/metas.js +1 -0
- package/package.json +10 -4
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import React, { useRef, useState } from 'react';
|
|
16
|
+
import { AutoComplete } from 'antd';
|
|
17
|
+
import { withBlockDefaults } from '@lowdefy/block-utils';
|
|
18
|
+
import { get, mergeObjects, set, type } from '@lowdefy/helpers';
|
|
19
|
+
import getDisabled from '@lowdefy/blocks-antd/getDisabled.js';
|
|
20
|
+
import Label from '@lowdefy/blocks-antd/blocks/Label/Label.js';
|
|
21
|
+
import withTheme from '@lowdefy/blocks-antd/blocks/withTheme.js';
|
|
22
|
+
import getNotFoundContent from './getNotFoundContent.js';
|
|
23
|
+
import getPlaceKeys from './getPlaceKeys.js';
|
|
24
|
+
import mapPlaceResult from './mapPlaceResult.js';
|
|
25
|
+
import removePlaceKeys from './removePlaceKeys.js';
|
|
26
|
+
import useAutocompleteSuggestions from './useAutocompleteSuggestions.js';
|
|
27
|
+
import usePlacesLibrary from './usePlacesLibrary.js';
|
|
28
|
+
import './style.css';
|
|
29
|
+
// Address input backed by the Places Autocomplete Data API. The block value is an
|
|
30
|
+
// object: picking a suggestion writes the fetched place fields into it, and typing
|
|
31
|
+
// writes the free text to the label field, so a form holds a usable address whether
|
|
32
|
+
// or not a suggestion is ever picked. Typing, picking and clearing each first remove
|
|
33
|
+
// the keys the previous place wrote (see getPlaceKeys), so a typed address never
|
|
34
|
+
// carries another place's coordinates. Sibling keys written into the same value
|
|
35
|
+
// object by other blocks are preserved, and the value is null once none remain.
|
|
36
|
+
const PlacesAutocomplete = ({ blockId, classNames = {}, components, events, loading, methods, properties, required, styles = {}, validation, value })=>{
|
|
37
|
+
const placesLibrary = usePlacesLibrary();
|
|
38
|
+
const [input, setInput] = useState('');
|
|
39
|
+
// Handlers that run after an await, or twice in one tick (antd calls onClear and
|
|
40
|
+
// then onSearch('')), read the value they last wrote rather than a stale prop.
|
|
41
|
+
const valueRef = useRef(value);
|
|
42
|
+
valueRef.current = value;
|
|
43
|
+
// Counts user edits, so a place that resolves after the user typed again or
|
|
44
|
+
// picked another suggestion is dropped instead of overwriting the newer input.
|
|
45
|
+
const editRef = useRef(0);
|
|
46
|
+
const labelField = properties.labelField ?? 'formattedAddress';
|
|
47
|
+
const inputKey = properties.resultMapping?.input ?? 'input';
|
|
48
|
+
const placeKeys = getPlaceKeys({
|
|
49
|
+
fetchFields: properties.fetchFields,
|
|
50
|
+
labelField,
|
|
51
|
+
resultMapping: properties.resultMapping
|
|
52
|
+
});
|
|
53
|
+
function triggerError(error) {
|
|
54
|
+
methods.triggerEvent({
|
|
55
|
+
name: 'onError',
|
|
56
|
+
event: {
|
|
57
|
+
message: error.message
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const { isLoading, predictions, resetSession } = useAutocompleteSuggestions({
|
|
62
|
+
debounce: properties.debounce ?? 250,
|
|
63
|
+
input,
|
|
64
|
+
onError: triggerError,
|
|
65
|
+
placesLibrary,
|
|
66
|
+
requestOptions: properties.requestOptions
|
|
67
|
+
});
|
|
68
|
+
function commitValue(nextValue) {
|
|
69
|
+
valueRef.current = nextValue;
|
|
70
|
+
methods.setValue(nextValue);
|
|
71
|
+
methods.triggerEvent({
|
|
72
|
+
name: 'onChange',
|
|
73
|
+
event: {
|
|
74
|
+
value: nextValue
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function clearPlace() {
|
|
79
|
+
const { removed, value: remaining } = removePlaceKeys({
|
|
80
|
+
placeKeys,
|
|
81
|
+
value: valueRef.current
|
|
82
|
+
});
|
|
83
|
+
if (removed) {
|
|
84
|
+
commitValue(remaining);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function handleSearch(text) {
|
|
88
|
+
editRef.current += 1;
|
|
89
|
+
setInput(text);
|
|
90
|
+
if (text === '') {
|
|
91
|
+
clearPlace();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const { value: remaining } = removePlaceKeys({
|
|
95
|
+
placeKeys,
|
|
96
|
+
value: valueRef.current
|
|
97
|
+
});
|
|
98
|
+
const typed = mapPlaceResult({
|
|
99
|
+
mapping: properties.resultMapping,
|
|
100
|
+
result: {
|
|
101
|
+
input: text
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
set(typed, labelField, text);
|
|
105
|
+
commitValue(mergeObjects([
|
|
106
|
+
remaining,
|
|
107
|
+
typed
|
|
108
|
+
]));
|
|
109
|
+
}
|
|
110
|
+
async function handleSelect(optionValue) {
|
|
111
|
+
const prediction = predictions.find((item)=>item.text.text === optionValue);
|
|
112
|
+
editRef.current += 1;
|
|
113
|
+
const edit = editRef.current;
|
|
114
|
+
// The prediction carries the session token into toPlace, and fetchFields ends
|
|
115
|
+
// that session, so the next search needs a new token.
|
|
116
|
+
const place = prediction.toPlace();
|
|
117
|
+
setInput('');
|
|
118
|
+
resetSession();
|
|
119
|
+
try {
|
|
120
|
+
await place.fetchFields({
|
|
121
|
+
fields: [
|
|
122
|
+
...properties.fetchFields ?? [],
|
|
123
|
+
'formattedAddress'
|
|
124
|
+
]
|
|
125
|
+
});
|
|
126
|
+
} catch (error) {
|
|
127
|
+
// The typed text stays in the value, so the form still holds what the user entered.
|
|
128
|
+
if (edit === editRef.current) {
|
|
129
|
+
triggerError(error);
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (edit !== editRef.current) return;
|
|
134
|
+
const mapped = mapPlaceResult({
|
|
135
|
+
mapping: properties.resultMapping,
|
|
136
|
+
result: {
|
|
137
|
+
input: place.formattedAddress,
|
|
138
|
+
...place.toJSON()
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
const { value: remaining } = removePlaceKeys({
|
|
142
|
+
placeKeys,
|
|
143
|
+
value: valueRef.current
|
|
144
|
+
});
|
|
145
|
+
const nextValue = mergeObjects([
|
|
146
|
+
remaining,
|
|
147
|
+
mapped
|
|
148
|
+
]);
|
|
149
|
+
commitValue(nextValue);
|
|
150
|
+
methods.triggerEvent({
|
|
151
|
+
name: 'onPlaceChanged',
|
|
152
|
+
event: {
|
|
153
|
+
place: mapped,
|
|
154
|
+
value: nextValue
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
let displayValue;
|
|
159
|
+
if (type.isObject(value)) {
|
|
160
|
+
displayValue = get(value, labelField, {
|
|
161
|
+
default: get(value, inputKey)
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
let variant = properties.variant;
|
|
165
|
+
if (type.isNone(variant) && properties.bordered === false) {
|
|
166
|
+
variant = 'borderless';
|
|
167
|
+
}
|
|
168
|
+
return /*#__PURE__*/ React.createElement(Label, {
|
|
169
|
+
blockId: blockId,
|
|
170
|
+
classNames: classNames,
|
|
171
|
+
components: components,
|
|
172
|
+
events: events,
|
|
173
|
+
methods: methods,
|
|
174
|
+
properties: {
|
|
175
|
+
title: properties.title,
|
|
176
|
+
size: properties.size,
|
|
177
|
+
...properties.label
|
|
178
|
+
},
|
|
179
|
+
required: required,
|
|
180
|
+
styles: styles,
|
|
181
|
+
validation: validation,
|
|
182
|
+
content: {
|
|
183
|
+
content: ()=>/*#__PURE__*/ React.createElement(AutoComplete, {
|
|
184
|
+
id: `${blockId}_input`,
|
|
185
|
+
className: classNames.element,
|
|
186
|
+
classNames: {
|
|
187
|
+
content: classNames.selector,
|
|
188
|
+
popup: {
|
|
189
|
+
root: classNames.popup
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
style: {
|
|
193
|
+
width: '100%',
|
|
194
|
+
...styles.element
|
|
195
|
+
},
|
|
196
|
+
styles: {
|
|
197
|
+
content: styles.selector,
|
|
198
|
+
popup: {
|
|
199
|
+
root: styles.popup
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
allowClear: properties.allowClear !== false && {
|
|
203
|
+
clearIcon: /*#__PURE__*/ React.createElement(components.Icon, {
|
|
204
|
+
blockId: `${blockId}_clearIcon`,
|
|
205
|
+
properties: {
|
|
206
|
+
name: 'clear',
|
|
207
|
+
title: ''
|
|
208
|
+
}
|
|
209
|
+
})
|
|
210
|
+
},
|
|
211
|
+
autoFocus: properties.autoFocus,
|
|
212
|
+
backfill: properties.backfill,
|
|
213
|
+
defaultOpen: properties.defaultOpen,
|
|
214
|
+
disabled: getDisabled({
|
|
215
|
+
loading,
|
|
216
|
+
properties
|
|
217
|
+
}),
|
|
218
|
+
filterOption: ()=>true,
|
|
219
|
+
notFoundContent: getNotFoundContent({
|
|
220
|
+
input,
|
|
221
|
+
isLoading,
|
|
222
|
+
placesReady: !type.isNone(placesLibrary),
|
|
223
|
+
properties
|
|
224
|
+
}),
|
|
225
|
+
placeholder: properties.placeholder ?? 'Start typing to search',
|
|
226
|
+
popupRender: (menu)=>/*#__PURE__*/ React.createElement(React.Fragment, null, menu, predictions.length > 0 && /*#__PURE__*/ React.createElement("div", {
|
|
227
|
+
className: "lowdefy-places-autocomplete-attribution"
|
|
228
|
+
}, "Powered by Google")),
|
|
229
|
+
size: properties.size,
|
|
230
|
+
status: validation.status,
|
|
231
|
+
value: displayValue,
|
|
232
|
+
variant: variant,
|
|
233
|
+
options: predictions.map((prediction, i)=>({
|
|
234
|
+
key: prediction.placeId,
|
|
235
|
+
// The prediction text is the option value, so backfill shows the address.
|
|
236
|
+
value: prediction.text.text,
|
|
237
|
+
className: classNames.options,
|
|
238
|
+
style: styles.options,
|
|
239
|
+
label: /*#__PURE__*/ React.createElement("span", {
|
|
240
|
+
id: `${blockId}_${i}`
|
|
241
|
+
}, /*#__PURE__*/ React.createElement(components.Icon, {
|
|
242
|
+
blockId: `${blockId}_${i}_optionsIcon`,
|
|
243
|
+
events: events,
|
|
244
|
+
properties: properties.optionsIcon ?? {
|
|
245
|
+
name: 'location',
|
|
246
|
+
title: ''
|
|
247
|
+
}
|
|
248
|
+
}), ' ', prediction.text.text)
|
|
249
|
+
})),
|
|
250
|
+
onBlur: ()=>{
|
|
251
|
+
// Leaving the input without picking a suggestion abandons the search.
|
|
252
|
+
setInput('');
|
|
253
|
+
resetSession();
|
|
254
|
+
methods.triggerEvent({
|
|
255
|
+
name: 'onBlur'
|
|
256
|
+
});
|
|
257
|
+
},
|
|
258
|
+
onClear: ()=>{
|
|
259
|
+
editRef.current += 1;
|
|
260
|
+
setInput('');
|
|
261
|
+
resetSession();
|
|
262
|
+
clearPlace();
|
|
263
|
+
methods.triggerEvent({
|
|
264
|
+
name: 'onClear'
|
|
265
|
+
});
|
|
266
|
+
},
|
|
267
|
+
onFocus: ()=>{
|
|
268
|
+
methods.triggerEvent({
|
|
269
|
+
name: 'onFocus'
|
|
270
|
+
});
|
|
271
|
+
},
|
|
272
|
+
onSearch: (text)=>{
|
|
273
|
+
handleSearch(text);
|
|
274
|
+
methods.triggerEvent({
|
|
275
|
+
name: 'onSearch',
|
|
276
|
+
event: {
|
|
277
|
+
value: text
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
},
|
|
281
|
+
onSelect: handleSelect
|
|
282
|
+
})
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
export default withTheme('Select', withBlockDefaults(PlacesAutocomplete));
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { createBlockHelper, escapeId } from '@lowdefy/e2e-utils';
|
|
16
|
+
import { expect } from '@playwright/test';
|
|
17
|
+
const locator = (page, blockId)=>page.locator(`.ant-select:has(#${escapeId(blockId)}_input)`);
|
|
18
|
+
const input = (page, blockId)=>page.locator(`#${escapeId(blockId)}_input`);
|
|
19
|
+
const suggestions = (page)=>page.locator('.ant-select-dropdown:not(.ant-select-dropdown-hidden) .ant-select-item-option-content');
|
|
20
|
+
export default createBlockHelper({
|
|
21
|
+
locator,
|
|
22
|
+
do: {
|
|
23
|
+
fill: (page, blockId, val)=>input(page, blockId).fill(val),
|
|
24
|
+
select: async (page, blockId, val)=>{
|
|
25
|
+
await suggestions(page).filter({
|
|
26
|
+
hasText: val
|
|
27
|
+
}).first().click();
|
|
28
|
+
},
|
|
29
|
+
clear: async (page, blockId)=>{
|
|
30
|
+
await locator(page, blockId).hover();
|
|
31
|
+
await locator(page, blockId).locator('.ant-select-clear').click();
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
expect: {
|
|
35
|
+
value: (page, blockId, val)=>expect(input(page, blockId)).toHaveValue(val),
|
|
36
|
+
placeholder: (page, blockId, text)=>expect(locator(page, blockId).locator('.ant-select-selection-placeholder')).toHaveText(text),
|
|
37
|
+
suggestionCount: (page, blockId, count)=>expect(suggestions(page)).toHaveCount(count)
|
|
38
|
+
}
|
|
39
|
+
});
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# Copyright 2020-2026 Lowdefy, Inc
|
|
2
|
+
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
# Note: All examples on this page are wrapped in a single GoogleMapsScript block
|
|
16
|
+
# loading the places library via the docs page template. Individual examples do
|
|
17
|
+
# not need their own script.
|
|
18
|
+
|
|
19
|
+
- title: Default
|
|
20
|
+
blocks:
|
|
21
|
+
- id: pa_default
|
|
22
|
+
type: PlacesAutocomplete
|
|
23
|
+
|
|
24
|
+
- title: Title and Placeholder
|
|
25
|
+
blocks:
|
|
26
|
+
- id: pa_title
|
|
27
|
+
type: PlacesAutocomplete
|
|
28
|
+
properties:
|
|
29
|
+
title: Delivery address
|
|
30
|
+
placeholder: Search for an address
|
|
31
|
+
- id: pa_label_extra
|
|
32
|
+
type: PlacesAutocomplete
|
|
33
|
+
properties:
|
|
34
|
+
title: Site address
|
|
35
|
+
label:
|
|
36
|
+
extra: Start typing, then pick a suggestion to capture the full address.
|
|
37
|
+
tooltip: Addresses are verified against Google Places.
|
|
38
|
+
|
|
39
|
+
- title: Fetch Place Fields
|
|
40
|
+
blocks:
|
|
41
|
+
- id: pa_fetch_fields
|
|
42
|
+
type: PlacesAutocomplete
|
|
43
|
+
properties:
|
|
44
|
+
title: Address
|
|
45
|
+
fetchFields:
|
|
46
|
+
- addressComponents
|
|
47
|
+
- location
|
|
48
|
+
- id
|
|
49
|
+
- displayName
|
|
50
|
+
|
|
51
|
+
- title: Result Mapping
|
|
52
|
+
blocks:
|
|
53
|
+
- id: pa_result_mapping
|
|
54
|
+
type: PlacesAutocomplete
|
|
55
|
+
properties:
|
|
56
|
+
title: Address
|
|
57
|
+
fetchFields:
|
|
58
|
+
- location
|
|
59
|
+
- addressComponents
|
|
60
|
+
resultMapping:
|
|
61
|
+
formattedAddress: address.line1
|
|
62
|
+
location: address.coordinates
|
|
63
|
+
addressComponents: address.components
|
|
64
|
+
labelField: address.line1
|
|
65
|
+
|
|
66
|
+
- title: Restrict and Bias Suggestions
|
|
67
|
+
blocks:
|
|
68
|
+
- id: pa_region_codes
|
|
69
|
+
type: PlacesAutocomplete
|
|
70
|
+
properties:
|
|
71
|
+
title: Address in the United Kingdom
|
|
72
|
+
requestOptions:
|
|
73
|
+
includedRegionCodes:
|
|
74
|
+
- gb
|
|
75
|
+
- id: pa_location_bias
|
|
76
|
+
type: PlacesAutocomplete
|
|
77
|
+
properties:
|
|
78
|
+
title: Near central London
|
|
79
|
+
requestOptions:
|
|
80
|
+
includedPrimaryTypes:
|
|
81
|
+
- street_address
|
|
82
|
+
locationBias:
|
|
83
|
+
center:
|
|
84
|
+
lat: 51.5074
|
|
85
|
+
lng: -0.1278
|
|
86
|
+
radius: 20000
|
|
87
|
+
|
|
88
|
+
- title: Sizes
|
|
89
|
+
blocks:
|
|
90
|
+
- id: pa_size_small
|
|
91
|
+
type: PlacesAutocomplete
|
|
92
|
+
properties:
|
|
93
|
+
title: Small
|
|
94
|
+
size: small
|
|
95
|
+
- id: pa_size_middle
|
|
96
|
+
type: PlacesAutocomplete
|
|
97
|
+
properties:
|
|
98
|
+
title: Middle
|
|
99
|
+
size: middle
|
|
100
|
+
- id: pa_size_large
|
|
101
|
+
type: PlacesAutocomplete
|
|
102
|
+
properties:
|
|
103
|
+
title: Large
|
|
104
|
+
size: large
|
|
105
|
+
|
|
106
|
+
- title: Variants
|
|
107
|
+
blocks:
|
|
108
|
+
- id: pa_variant_filled
|
|
109
|
+
type: PlacesAutocomplete
|
|
110
|
+
properties:
|
|
111
|
+
title: Filled
|
|
112
|
+
variant: filled
|
|
113
|
+
- id: pa_variant_borderless
|
|
114
|
+
type: PlacesAutocomplete
|
|
115
|
+
properties:
|
|
116
|
+
title: Borderless
|
|
117
|
+
variant: borderless
|
|
118
|
+
- id: pa_variant_underlined
|
|
119
|
+
type: PlacesAutocomplete
|
|
120
|
+
properties:
|
|
121
|
+
title: Underlined
|
|
122
|
+
variant: underlined
|
|
123
|
+
|
|
124
|
+
- title: Disabled and No Clear
|
|
125
|
+
blocks:
|
|
126
|
+
- id: pa_disabled
|
|
127
|
+
type: PlacesAutocomplete
|
|
128
|
+
properties:
|
|
129
|
+
title: Disabled
|
|
130
|
+
disabled: true
|
|
131
|
+
- id: pa_no_clear
|
|
132
|
+
type: PlacesAutocomplete
|
|
133
|
+
properties:
|
|
134
|
+
title: Clear button hidden
|
|
135
|
+
allowClear: false
|
|
136
|
+
|
|
137
|
+
- title: Custom Suggestion Icon and Dropdown Text
|
|
138
|
+
blocks:
|
|
139
|
+
- id: pa_custom_icon
|
|
140
|
+
type: PlacesAutocomplete
|
|
141
|
+
properties:
|
|
142
|
+
title: Address
|
|
143
|
+
optionsIcon:
|
|
144
|
+
name: home
|
|
145
|
+
color: '#1890ff'
|
|
146
|
+
loadingPlaceholder: Searching addresses...
|
|
147
|
+
notFoundContent: No matching address
|
|
148
|
+
|
|
149
|
+
- title: Required with Validation
|
|
150
|
+
blocks:
|
|
151
|
+
- id: pa_required
|
|
152
|
+
type: PlacesAutocomplete
|
|
153
|
+
required: true
|
|
154
|
+
properties:
|
|
155
|
+
title: Address
|
|
156
|
+
validate:
|
|
157
|
+
- message: An address must be selected.
|
|
158
|
+
status: error
|
|
159
|
+
pass:
|
|
160
|
+
_if_none:
|
|
161
|
+
- _state: pa_required.formattedAddress
|
|
162
|
+
- false
|
|
163
|
+
|
|
164
|
+
- title: Event Actions
|
|
165
|
+
blocks:
|
|
166
|
+
- id: pa_events
|
|
167
|
+
type: PlacesAutocomplete
|
|
168
|
+
properties:
|
|
169
|
+
title: Address
|
|
170
|
+
fetchFields:
|
|
171
|
+
- location
|
|
172
|
+
events:
|
|
173
|
+
onPlaceChanged:
|
|
174
|
+
- id: pa_place_changed_message
|
|
175
|
+
type: DisplayMessage
|
|
176
|
+
params:
|
|
177
|
+
content:
|
|
178
|
+
_string.concat:
|
|
179
|
+
- 'Selected: '
|
|
180
|
+
- _event: place.formattedAddress
|
|
181
|
+
duration: 2
|
|
182
|
+
onError:
|
|
183
|
+
- id: pa_error_message
|
|
184
|
+
type: DisplayMessage
|
|
185
|
+
params:
|
|
186
|
+
status: error
|
|
187
|
+
content:
|
|
188
|
+
_event: message
|
|
189
|
+
onSearch:
|
|
190
|
+
- id: pa_search_state
|
|
191
|
+
type: SetState
|
|
192
|
+
params:
|
|
193
|
+
pa_last_search:
|
|
194
|
+
_event: value
|
|
195
|
+
onClear:
|
|
196
|
+
- id: pa_clear_state
|
|
197
|
+
type: SetState
|
|
198
|
+
params:
|
|
199
|
+
pa_last_search: null
|
|
200
|
+
|
|
201
|
+
- title: PlacesAutocomplete in an Address Form
|
|
202
|
+
fullWidth: true
|
|
203
|
+
blocks:
|
|
204
|
+
- id: pa_form_title
|
|
205
|
+
type: Title
|
|
206
|
+
properties:
|
|
207
|
+
content: Delivery details
|
|
208
|
+
level: 4
|
|
209
|
+
- id: pa_form_address
|
|
210
|
+
type: PlacesAutocomplete
|
|
211
|
+
properties:
|
|
212
|
+
title: Street address
|
|
213
|
+
placeholder: Search for a delivery address
|
|
214
|
+
fetchFields:
|
|
215
|
+
- addressComponents
|
|
216
|
+
- location
|
|
217
|
+
label:
|
|
218
|
+
extra: Pick a suggestion to capture the coordinates for the driver.
|
|
219
|
+
- id: pa_form_instructions
|
|
220
|
+
type: TextArea
|
|
221
|
+
properties:
|
|
222
|
+
title: Delivery instructions
|
|
223
|
+
placeholder: Gate code, buzzer, where to leave the parcel
|
|
224
|
+
- id: pa_form_submit
|
|
225
|
+
type: Button
|
|
226
|
+
properties:
|
|
227
|
+
title: Save address
|
|
228
|
+
icon: save
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ // GoogleMapsScript only renders its children once the Google Maps JavaScript API
|
|
16
|
+
// has loaded, so when the script was configured with `libraries: [places]` the
|
|
17
|
+
// places library is already on the window on the first render.
|
|
18
|
+
function getLoadedPlacesLibrary() {
|
|
19
|
+
return window.google?.maps?.places ?? null;
|
|
20
|
+
}
|
|
21
|
+
export default getLoadedPlacesLibrary;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ // Returning null keeps the dropdown closed. Without the places library there is
|
|
16
|
+
// nothing to search, and before the first keystroke there is nothing to report.
|
|
17
|
+
function getNotFoundContent({ input, isLoading, placesReady, properties }) {
|
|
18
|
+
if (!placesReady) return null;
|
|
19
|
+
if (isLoading) return properties.loadingPlaceholder ?? 'Loading...';
|
|
20
|
+
if (input === '') return null;
|
|
21
|
+
return properties.notFoundContent ?? 'No results found';
|
|
22
|
+
}
|
|
23
|
+
export default getNotFoundContent;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
// The block value keys a place selection writes: the typed input, the place id,
|
|
17
|
+
// the formatted address and every fetched field, each renamed through
|
|
18
|
+
// resultMapping, plus the label field. These are the keys a new search or a new
|
|
19
|
+
// selection replaces, so a previous place never leaks into the next one.
|
|
20
|
+
function getPlaceKeys({ fetchFields, labelField, resultMapping }) {
|
|
21
|
+
const mapping = resultMapping ?? {};
|
|
22
|
+
const fields = [
|
|
23
|
+
'input',
|
|
24
|
+
'id',
|
|
25
|
+
'formattedAddress',
|
|
26
|
+
...fetchFields ?? []
|
|
27
|
+
];
|
|
28
|
+
const keys = fields.map((field)=>mapping[field] ?? field);
|
|
29
|
+
if (type.isString(labelField)) {
|
|
30
|
+
keys.push(labelField);
|
|
31
|
+
}
|
|
32
|
+
return [
|
|
33
|
+
...new Set(keys)
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
export default getPlaceKeys;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { set, type } from '@lowdefy/helpers';
|
|
16
|
+
// Place fields come back camelCased, mapping renames them onto the keys the app
|
|
17
|
+
// stores. A mapped key may be a dotted path, which nests the value.
|
|
18
|
+
function mapPlaceResult({ mapping, result }) {
|
|
19
|
+
if (type.isNone(mapping)) return result;
|
|
20
|
+
const mapped = {};
|
|
21
|
+
Object.entries(result).forEach(([key, value])=>{
|
|
22
|
+
set(mapped, mapping[key] ?? key, value);
|
|
23
|
+
});
|
|
24
|
+
return mapped;
|
|
25
|
+
}
|
|
26
|
+
export default mapPlaceResult;
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import AutoCompleteMeta from '@lowdefy/blocks-antd/blocks/AutoComplete/meta.js';
|
|
16
|
+
export default {
|
|
17
|
+
category: 'input',
|
|
18
|
+
icons: [
|
|
19
|
+
'error',
|
|
20
|
+
'success',
|
|
21
|
+
'loading',
|
|
22
|
+
'warning',
|
|
23
|
+
'help',
|
|
24
|
+
'location',
|
|
25
|
+
'clear'
|
|
26
|
+
],
|
|
27
|
+
valueType: 'object',
|
|
28
|
+
cssKeys: {
|
|
29
|
+
element: 'The PlacesAutocomplete input element.',
|
|
30
|
+
selector: 'The inner value container of the input (antd `content` semantic slot).',
|
|
31
|
+
label: 'The PlacesAutocomplete label.',
|
|
32
|
+
extra: 'The PlacesAutocomplete extra content.',
|
|
33
|
+
feedback: 'The PlacesAutocomplete validation feedback.',
|
|
34
|
+
options: 'Each suggestion in the dropdown.',
|
|
35
|
+
popup: 'The suggestions dropdown.'
|
|
36
|
+
},
|
|
37
|
+
events: {
|
|
38
|
+
onBlur: 'Trigger actions when the input loses focus.',
|
|
39
|
+
onChange: {
|
|
40
|
+
description: 'Trigger actions after the block value changes, by typing, by selecting a suggestion or by clearing the input.',
|
|
41
|
+
event: {
|
|
42
|
+
value: 'The new block value.'
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
onClear: 'Trigger actions when the input is cleared.',
|
|
46
|
+
onError: {
|
|
47
|
+
description: 'Trigger actions when fetching suggestions or place fields fails, for example when the Places API is not enabled on the API key. When fetching place fields fails, the typed text stays in the block value and onPlaceChanged is not triggered.',
|
|
48
|
+
event: {
|
|
49
|
+
message: 'The error message.'
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
onFocus: 'Trigger actions when the input gains focus.',
|
|
53
|
+
onPlaceChanged: {
|
|
54
|
+
description: 'Trigger actions after a suggestion is selected and its place fields have been fetched and written to the block value.',
|
|
55
|
+
event: {
|
|
56
|
+
place: 'The fetched place fields, after `resultMapping` is applied.',
|
|
57
|
+
value: 'The new block value.'
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
onSearch: {
|
|
61
|
+
description: 'Trigger actions when the search text changes.',
|
|
62
|
+
event: {
|
|
63
|
+
value: 'The search input text.'
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
onTooltipClick: 'Trigger actions when the tooltip icon is clicked.'
|
|
67
|
+
},
|
|
68
|
+
properties: {
|
|
69
|
+
type: 'object',
|
|
70
|
+
additionalProperties: false,
|
|
71
|
+
properties: {
|
|
72
|
+
allowClear: {
|
|
73
|
+
type: 'boolean',
|
|
74
|
+
default: true,
|
|
75
|
+
description: 'Allow the user to clear the input. Clearing removes the place keys from the block value, and sets the value to null when no sibling keys remain.'
|
|
76
|
+
},
|
|
77
|
+
autoFocus: {
|
|
78
|
+
type: 'boolean',
|
|
79
|
+
default: false,
|
|
80
|
+
description: 'Autofocus to the block on page load.'
|
|
81
|
+
},
|
|
82
|
+
backfill: {
|
|
83
|
+
type: 'boolean',
|
|
84
|
+
default: false,
|
|
85
|
+
description: 'Backfill the highlighted suggestion into the input when using the keyboard.'
|
|
86
|
+
},
|
|
87
|
+
bordered: {
|
|
88
|
+
type: 'boolean',
|
|
89
|
+
default: true,
|
|
90
|
+
description: 'Whether or not the input has a border style. Deprecated, use variant instead.'
|
|
91
|
+
},
|
|
92
|
+
debounce: {
|
|
93
|
+
type: 'number',
|
|
94
|
+
default: 250,
|
|
95
|
+
description: 'Milliseconds to wait after the last keystroke before requesting suggestions from the Places API.'
|
|
96
|
+
},
|
|
97
|
+
defaultOpen: {
|
|
98
|
+
type: 'boolean',
|
|
99
|
+
default: false,
|
|
100
|
+
description: 'Initial open state of the suggestions dropdown.'
|
|
101
|
+
},
|
|
102
|
+
disabled: {
|
|
103
|
+
type: 'boolean',
|
|
104
|
+
default: false,
|
|
105
|
+
description: 'Disable the block if true.'
|
|
106
|
+
},
|
|
107
|
+
fetchFields: {
|
|
108
|
+
type: 'array',
|
|
109
|
+
description: 'Place fields to fetch when a suggestion is selected, in camelCase, for example `addressComponents`, `location` or `viewport`. `formattedAddress` is always fetched. See <a href="https://developers.google.com/maps/documentation/javascript/reference/place#Place">Place fields</a>.',
|
|
110
|
+
items: {
|
|
111
|
+
type: 'string'
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
label: {
|
|
115
|
+
type: 'object',
|
|
116
|
+
description: 'Label properties.',
|
|
117
|
+
additionalProperties: false,
|
|
118
|
+
properties: {
|
|
119
|
+
align: {
|
|
120
|
+
type: 'string',
|
|
121
|
+
enum: [
|
|
122
|
+
'left',
|
|
123
|
+
'right'
|
|
124
|
+
],
|
|
125
|
+
default: 'left',
|
|
126
|
+
description: 'Align label left or right when inline.'
|
|
127
|
+
},
|
|
128
|
+
colon: {
|
|
129
|
+
type: 'boolean',
|
|
130
|
+
default: true,
|
|
131
|
+
description: 'Append label with colon.'
|
|
132
|
+
},
|
|
133
|
+
disabled: {
|
|
134
|
+
type: 'boolean',
|
|
135
|
+
default: false,
|
|
136
|
+
description: 'Hide input label.'
|
|
137
|
+
},
|
|
138
|
+
extra: {
|
|
139
|
+
type: 'string',
|
|
140
|
+
description: 'Extra text to display beneath the content - supports html.'
|
|
141
|
+
},
|
|
142
|
+
hasFeedback: {
|
|
143
|
+
type: 'boolean',
|
|
144
|
+
default: true,
|
|
145
|
+
description: 'Display feedback extra from validation, this does not disable validation.'
|
|
146
|
+
},
|
|
147
|
+
inline: {
|
|
148
|
+
type: 'boolean',
|
|
149
|
+
default: false,
|
|
150
|
+
description: 'Render input and label inline.'
|
|
151
|
+
},
|
|
152
|
+
span: {
|
|
153
|
+
type: 'number',
|
|
154
|
+
description: 'Label inline span.'
|
|
155
|
+
},
|
|
156
|
+
title: {
|
|
157
|
+
type: 'string',
|
|
158
|
+
description: 'Label title - supports html.'
|
|
159
|
+
},
|
|
160
|
+
tooltip: {
|
|
161
|
+
description: "Help tooltip shown via an icon beside the label. A string sets the tooltip text (supports html), or an object to also customize the icon and color. Use the block's onTooltipClick event to respond to clicks on the icon.",
|
|
162
|
+
oneOf: [
|
|
163
|
+
{
|
|
164
|
+
type: 'string'
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
type: 'object',
|
|
168
|
+
additionalProperties: false,
|
|
169
|
+
properties: {
|
|
170
|
+
title: {
|
|
171
|
+
type: 'string',
|
|
172
|
+
description: 'Tooltip text shown on hover - supports html.'
|
|
173
|
+
},
|
|
174
|
+
icon: {
|
|
175
|
+
type: 'string',
|
|
176
|
+
default: 'help',
|
|
177
|
+
description: 'Icon name to show beside the label: a semantic name like `help`, a Lucide icon name like `CircleQuestionMark`, or a set-qualified name like `tabler:HelpCircle`.'
|
|
178
|
+
},
|
|
179
|
+
color: {
|
|
180
|
+
type: 'string',
|
|
181
|
+
description: 'Color of the tooltip icon.',
|
|
182
|
+
docs: {
|
|
183
|
+
displayType: 'color'
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
labelField: {
|
|
193
|
+
type: 'string',
|
|
194
|
+
default: 'formattedAddress',
|
|
195
|
+
description: "The key in the block value, after `resultMapping` is applied, that is displayed in the input and written when the user types free text. Typing removes the keys the previous place wrote (the mapped `input`, `id`, `formattedAddress` and `fetchFields` keys), so typed text never carries another place's fields."
|
|
196
|
+
},
|
|
197
|
+
loadingPlaceholder: {
|
|
198
|
+
type: 'string',
|
|
199
|
+
default: 'Loading...',
|
|
200
|
+
description: 'Text displayed in the dropdown while suggestions are being fetched.'
|
|
201
|
+
},
|
|
202
|
+
notFoundContent: {
|
|
203
|
+
type: 'string',
|
|
204
|
+
default: 'No results found',
|
|
205
|
+
description: 'Text displayed in the dropdown when the search returns no suggestions.'
|
|
206
|
+
},
|
|
207
|
+
optionsIcon: {
|
|
208
|
+
type: [
|
|
209
|
+
'string',
|
|
210
|
+
'object'
|
|
211
|
+
],
|
|
212
|
+
default: 'location',
|
|
213
|
+
description: 'Icon displayed before each suggestion in the dropdown: a semantic name like `location`, a Lucide icon name like `MapPin`, or a set-qualified name like `tabler:MapPin`, or properties of an Icon block.',
|
|
214
|
+
docs: {
|
|
215
|
+
displayType: 'icon'
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
placeholder: {
|
|
219
|
+
type: 'string',
|
|
220
|
+
default: 'Start typing to search',
|
|
221
|
+
description: 'Placeholder text inside the block before the user types input.'
|
|
222
|
+
},
|
|
223
|
+
requestOptions: {
|
|
224
|
+
type: 'object',
|
|
225
|
+
description: 'Additional options passed to the autocomplete request. See <a href="https://developers.google.com/maps/documentation/javascript/reference/autocomplete-data#AutocompleteRequest">AutocompleteRequest</a>.',
|
|
226
|
+
properties: {
|
|
227
|
+
includedPrimaryTypes: {
|
|
228
|
+
type: 'array',
|
|
229
|
+
description: 'Restrict suggestions to these place types, for example `street_address` or `locality`.',
|
|
230
|
+
items: {
|
|
231
|
+
type: 'string'
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
includedRegionCodes: {
|
|
235
|
+
type: 'array',
|
|
236
|
+
description: 'Restrict suggestions to these regions, as up to 15 CLDR two character region codes, for example `["us", "gb"]`.',
|
|
237
|
+
items: {
|
|
238
|
+
type: 'string'
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
language: {
|
|
242
|
+
type: 'string',
|
|
243
|
+
description: 'The language in which to return the suggestions.'
|
|
244
|
+
},
|
|
245
|
+
locationBias: {
|
|
246
|
+
type: 'object',
|
|
247
|
+
description: 'Bias suggestions towards an area, as a circle or a rectangle. Cannot be used with locationRestriction.'
|
|
248
|
+
},
|
|
249
|
+
locationRestriction: {
|
|
250
|
+
type: 'object',
|
|
251
|
+
description: 'Restrict suggestions to an area, as a circle or a rectangle. Cannot be used with locationBias.'
|
|
252
|
+
},
|
|
253
|
+
origin: {
|
|
254
|
+
type: 'object',
|
|
255
|
+
description: 'The origin from which the distance to a suggestion is calculated, as a lat and lng object.',
|
|
256
|
+
properties: {
|
|
257
|
+
lat: {
|
|
258
|
+
type: 'number',
|
|
259
|
+
description: 'Lateral coordinate.'
|
|
260
|
+
},
|
|
261
|
+
lng: {
|
|
262
|
+
type: 'number',
|
|
263
|
+
description: 'Longitudinal coordinate.'
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
region: {
|
|
268
|
+
type: 'string',
|
|
269
|
+
description: 'The region code used to format the suggestions.'
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
resultMapping: {
|
|
274
|
+
type: 'object',
|
|
275
|
+
description: 'Rename the fetched place fields before they are written to the block value. Dotted target paths are nested, for example `{ formattedAddress: address.line1, location: geometry.location }`.'
|
|
276
|
+
},
|
|
277
|
+
size: {
|
|
278
|
+
type: 'string',
|
|
279
|
+
enum: [
|
|
280
|
+
'small',
|
|
281
|
+
'middle',
|
|
282
|
+
'large'
|
|
283
|
+
],
|
|
284
|
+
default: 'middle',
|
|
285
|
+
description: 'Size of the block.'
|
|
286
|
+
},
|
|
287
|
+
theme: AutoCompleteMeta.properties.properties.theme,
|
|
288
|
+
title: {
|
|
289
|
+
type: 'string',
|
|
290
|
+
description: 'Title to describe the input component, if no title is specified the block id is displayed - supports html.'
|
|
291
|
+
},
|
|
292
|
+
variant: {
|
|
293
|
+
type: 'string',
|
|
294
|
+
enum: [
|
|
295
|
+
'outlined',
|
|
296
|
+
'filled',
|
|
297
|
+
'borderless',
|
|
298
|
+
'underlined'
|
|
299
|
+
],
|
|
300
|
+
default: 'outlined',
|
|
301
|
+
description: 'Input visual variant. When set, takes precedence over bordered.'
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { get, serializer, type, unset } from '@lowdefy/helpers';
|
|
16
|
+
// Removes the keys a place selection wrote from the block value, keeping any
|
|
17
|
+
// sibling keys written into the same value object by other blocks. Returns null
|
|
18
|
+
// when nothing else is left, so an empty address reads as no value.
|
|
19
|
+
function removePlaceKeys({ placeKeys, value }) {
|
|
20
|
+
if (!type.isObject(value)) {
|
|
21
|
+
return {
|
|
22
|
+
removed: !type.isNone(value),
|
|
23
|
+
value: null
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const remaining = serializer.copy(value);
|
|
27
|
+
let removed = false;
|
|
28
|
+
placeKeys.forEach((key)=>{
|
|
29
|
+
if (type.isUndefined(get(remaining, key))) return;
|
|
30
|
+
unset(remaining, key);
|
|
31
|
+
removed = true;
|
|
32
|
+
// A dotted resultMapping target nests the field, so drop any parent object
|
|
33
|
+
// the removal left empty.
|
|
34
|
+
const segments = key.split('.');
|
|
35
|
+
for(let depth = segments.length - 1; depth > 0; depth -= 1){
|
|
36
|
+
const parentKey = segments.slice(0, depth).join('.');
|
|
37
|
+
const parent = get(remaining, parentKey);
|
|
38
|
+
if (!type.isObject(parent) || Object.keys(parent).length > 0) break;
|
|
39
|
+
unset(remaining, parentKey);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
if (Object.keys(remaining).length === 0) {
|
|
43
|
+
return {
|
|
44
|
+
removed,
|
|
45
|
+
value: null
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
removed,
|
|
50
|
+
value: remaining
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export default removePlaceKeys;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
The Places API terms require the Google attribution to be displayed when
|
|
19
|
+
predictions are shown outside of a Google map.
|
|
20
|
+
*/
|
|
21
|
+
.lowdefy-places-autocomplete-attribution {
|
|
22
|
+
color: #5f6368;
|
|
23
|
+
font-size: 12px;
|
|
24
|
+
letter-spacing: 0.0575em;
|
|
25
|
+
line-height: 16px;
|
|
26
|
+
padding: 8px 12px;
|
|
27
|
+
text-align: end;
|
|
28
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { useCallback, useEffect, useRef, useState } from 'react';
|
|
16
|
+
import { type } from '@lowdefy/helpers';
|
|
17
|
+
// Fetches place predictions from the Places Autocomplete Data API, waiting for
|
|
18
|
+
// `debounce` milliseconds after the last keystroke. A session token groups the
|
|
19
|
+
// keystrokes of one search with the fetchFields call that follows it into a single
|
|
20
|
+
// billed session. resetSession drops the token once the search ends - a place was
|
|
21
|
+
// picked, the input was cleared or the user left the input - so the next search
|
|
22
|
+
// starts a new session.
|
|
23
|
+
// See https://developers.google.com/maps/documentation/javascript/place-autocomplete-data
|
|
24
|
+
function useAutocompleteSuggestions({ debounce, input, onError, placesLibrary, requestOptions }) {
|
|
25
|
+
const sessionTokenRef = useRef(null);
|
|
26
|
+
// Only the latest request may write results, so a slow response to an earlier
|
|
27
|
+
// keystroke never replaces the suggestions for the current input.
|
|
28
|
+
const requestIdRef = useRef(0);
|
|
29
|
+
const [predictions, setPredictions] = useState([]);
|
|
30
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
31
|
+
// requestOptions is rebuilt by the operator parser on every render, so it is
|
|
32
|
+
// read but not tracked - only a new input string starts a new request.
|
|
33
|
+
useEffect(()=>{
|
|
34
|
+
if (type.isNone(placesLibrary)) return undefined;
|
|
35
|
+
requestIdRef.current += 1;
|
|
36
|
+
const requestId = requestIdRef.current;
|
|
37
|
+
if (input === '') {
|
|
38
|
+
setPredictions((current)=>current.length === 0 ? current : []);
|
|
39
|
+
setIsLoading(false);
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
setIsLoading(true);
|
|
43
|
+
const timeout = setTimeout(()=>{
|
|
44
|
+
const { AutocompleteSessionToken, AutocompleteSuggestion } = placesLibrary;
|
|
45
|
+
if (type.isNone(sessionTokenRef.current)) {
|
|
46
|
+
sessionTokenRef.current = new AutocompleteSessionToken();
|
|
47
|
+
}
|
|
48
|
+
AutocompleteSuggestion.fetchAutocompleteSuggestions({
|
|
49
|
+
...requestOptions,
|
|
50
|
+
input,
|
|
51
|
+
sessionToken: sessionTokenRef.current
|
|
52
|
+
}).then((response)=>{
|
|
53
|
+
if (requestId !== requestIdRef.current) return;
|
|
54
|
+
setPredictions(response.suggestions.map((suggestion)=>suggestion.placePrediction).filter((prediction)=>!type.isNone(prediction)));
|
|
55
|
+
setIsLoading(false);
|
|
56
|
+
}).catch((error)=>{
|
|
57
|
+
if (requestId !== requestIdRef.current) return;
|
|
58
|
+
setPredictions([]);
|
|
59
|
+
setIsLoading(false);
|
|
60
|
+
onError(error);
|
|
61
|
+
});
|
|
62
|
+
}, debounce);
|
|
63
|
+
return ()=>{
|
|
64
|
+
clearTimeout(timeout);
|
|
65
|
+
};
|
|
66
|
+
}, [
|
|
67
|
+
debounce,
|
|
68
|
+
input,
|
|
69
|
+
placesLibrary
|
|
70
|
+
]);
|
|
71
|
+
const resetSession = useCallback(()=>{
|
|
72
|
+
requestIdRef.current += 1;
|
|
73
|
+
sessionTokenRef.current = null;
|
|
74
|
+
setPredictions([]);
|
|
75
|
+
setIsLoading(false);
|
|
76
|
+
}, []);
|
|
77
|
+
return {
|
|
78
|
+
isLoading,
|
|
79
|
+
predictions,
|
|
80
|
+
resetSession
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export default useAutocompleteSuggestions;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { useEffect, useState } from 'react';
|
|
16
|
+
import { type } from '@lowdefy/helpers';
|
|
17
|
+
import getLoadedPlacesLibrary from './getLoadedPlacesLibrary.js';
|
|
18
|
+
// Uses the places library the GoogleMapsScript loaded. When the script omitted it,
|
|
19
|
+
// the library is imported on demand through google.maps.importLibrary. Outside a
|
|
20
|
+
// GoogleMapsScript, or when the import fails (for example the Places API is not
|
|
21
|
+
// enabled on the key), there is no library and the block stays a plain text input.
|
|
22
|
+
function usePlacesLibrary() {
|
|
23
|
+
const [placesLibrary, setPlacesLibrary] = useState(getLoadedPlacesLibrary);
|
|
24
|
+
useEffect(()=>{
|
|
25
|
+
if (!type.isNone(placesLibrary)) return undefined;
|
|
26
|
+
if (!type.isFunction(window.google?.maps?.importLibrary)) return undefined;
|
|
27
|
+
let cancelled = false;
|
|
28
|
+
window.google.maps.importLibrary('places').then((library)=>{
|
|
29
|
+
if (cancelled) return;
|
|
30
|
+
setPlacesLibrary(library);
|
|
31
|
+
}).catch(()=>null);
|
|
32
|
+
return ()=>{
|
|
33
|
+
cancelled = true;
|
|
34
|
+
};
|
|
35
|
+
}, [
|
|
36
|
+
placesLibrary
|
|
37
|
+
]);
|
|
38
|
+
return placesLibrary;
|
|
39
|
+
}
|
|
40
|
+
export default usePlacesLibrary;
|
package/dist/blocks.js
CHANGED
|
@@ -15,3 +15,4 @@
|
|
|
15
15
|
*/ export { default as GoogleMaps } from './blocks/GoogleMaps/GoogleMaps.js';
|
|
16
16
|
export { default as GoogleMapsHeatmap } from './blocks/GoogleMapsHeatmap/GoogleMapsHeatmap.js';
|
|
17
17
|
export { default as GoogleMapsScript } from './blocks/GoogleMapsScript/GoogleMapsScript.js';
|
|
18
|
+
export { default as PlacesAutocomplete } from './blocks/PlacesAutocomplete/PlacesAutocomplete.js';
|
package/dist/e2e.js
CHANGED
|
@@ -13,3 +13,4 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ export { default as GoogleMapsScript } from './blocks/GoogleMapsScript/e2e.js';
|
|
16
|
+
export { default as PlacesAutocomplete } from './blocks/PlacesAutocomplete/e2e.js';
|
package/dist/metas.js
CHANGED
|
@@ -15,3 +15,4 @@
|
|
|
15
15
|
*/ export { default as GoogleMaps } from './blocks/GoogleMaps/meta.js';
|
|
16
16
|
export { default as GoogleMapsHeatmap } from './blocks/GoogleMapsHeatmap/meta.js';
|
|
17
17
|
export { default as GoogleMapsScript } from './blocks/GoogleMapsScript/meta.js';
|
|
18
|
+
export { default as PlacesAutocomplete } from './blocks/PlacesAutocomplete/meta.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/blocks-google-maps",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Google Maps Blocks for Lowdefy.",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -25,6 +25,9 @@
|
|
|
25
25
|
"url": "https://github.com/lowdefy/lowdefy.git"
|
|
26
26
|
},
|
|
27
27
|
"type": "module",
|
|
28
|
+
"sideEffects": [
|
|
29
|
+
"**/*.css"
|
|
30
|
+
],
|
|
28
31
|
"exports": {
|
|
29
32
|
"./*": "./dist/*",
|
|
30
33
|
"./blocks": "./dist/blocks.js",
|
|
@@ -35,16 +38,19 @@
|
|
|
35
38
|
"dist/*"
|
|
36
39
|
],
|
|
37
40
|
"dependencies": {
|
|
38
|
-
"@lowdefy/block-utils": "
|
|
41
|
+
"@lowdefy/block-utils": "7.0.0",
|
|
42
|
+
"@lowdefy/blocks-antd": "7.0.0",
|
|
43
|
+
"@lowdefy/helpers": "7.0.0",
|
|
39
44
|
"@react-google-maps/api": "2.20.8"
|
|
40
45
|
},
|
|
41
46
|
"peerDependencies": {
|
|
47
|
+
"antd": ">=6",
|
|
42
48
|
"react": ">=18",
|
|
43
49
|
"react-dom": ">=18"
|
|
44
50
|
},
|
|
45
51
|
"devDependencies": {
|
|
46
|
-
"@lowdefy/block-dev-e2e": "
|
|
47
|
-
"@lowdefy/e2e-utils": "
|
|
52
|
+
"@lowdefy/block-dev-e2e": "7.0.0",
|
|
53
|
+
"@lowdefy/e2e-utils": "7.0.0",
|
|
48
54
|
"@playwright/test": "1.59.1",
|
|
49
55
|
"@swc/cli": "0.8.1",
|
|
50
56
|
"@swc/core": "1.15.32",
|