@pega/cosmos-react-core 8.21.5 → 8.21.7
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/lib/components/Location/LocationInput.d.ts.map +1 -1
- package/lib/components/Location/LocationInput.js +76 -49
- package/lib/components/Location/LocationInput.js.map +1 -1
- package/lib/components/Location/LocationView.d.ts +2 -0
- package/lib/components/Location/LocationView.d.ts.map +1 -1
- package/lib/components/Location/LocationView.js +3 -3
- package/lib/components/Location/LocationView.js.map +1 -1
- package/lib/components/Location/utils.d.ts +2 -3
- package/lib/components/Location/utils.d.ts.map +1 -1
- package/lib/components/Location/utils.js +49 -49
- package/lib/components/Location/utils.js.map +1 -1
- package/lib/components/TextArea/TextArea.d.ts.map +1 -1
- package/lib/components/TextArea/TextArea.js +16 -4
- package/lib/components/TextArea/TextArea.js.map +1 -1
- package/lib/hooks/useI18n.d.ts +1 -0
- package/lib/hooks/useI18n.d.ts.map +1 -1
- package/lib/i18n/default.d.ts +1 -0
- package/lib/i18n/default.d.ts.map +1 -1
- package/lib/i18n/default.js +1 -0
- package/lib/i18n/default.js.map +1 -1
- package/lib/i18n/i18n.d.ts +1 -0
- package/lib/i18n/i18n.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -222,7 +222,7 @@ export function toGoogleLatLng(coords) {
|
|
|
222
222
|
/** Returns an array of place prediction objects ('place' can be an establishment, geographic location, or prominent point of interest)
|
|
223
223
|
* and session token (valid for multiple queries, followed by one place selection).
|
|
224
224
|
*/
|
|
225
|
-
export async function getPlacePredictions(location, bias = {}) {
|
|
225
|
+
export async function getPlacePredictions(location, bias = {}, sessionToken) {
|
|
226
226
|
const autocompleteService = new google.maps.places.AutocompleteService();
|
|
227
227
|
const optionalParams = {};
|
|
228
228
|
if (bias?.location) {
|
|
@@ -245,39 +245,19 @@ export async function getPlacePredictions(location, bias = {}) {
|
|
|
245
245
|
optionalParams.bounds = new google.maps.LatLngBounds(toGoogleLatLng(sw), toGoogleLatLng(ne));
|
|
246
246
|
}
|
|
247
247
|
return new Promise((resolve, reject) => {
|
|
248
|
-
const token = new google.maps.places.AutocompleteSessionToken();
|
|
248
|
+
const token = sessionToken ?? new google.maps.places.AutocompleteSessionToken();
|
|
249
249
|
autocompleteService.getPlacePredictions({
|
|
250
250
|
input: location,
|
|
251
251
|
types: QUERY_TYPES,
|
|
252
252
|
sessionToken: token,
|
|
253
253
|
...optionalParams
|
|
254
254
|
}, (placePredictions, status) => {
|
|
255
|
-
if (status === google.maps.places.PlacesServiceStatus.OK
|
|
255
|
+
if (status === google.maps.places.PlacesServiceStatus.OK ||
|
|
256
|
+
status === google.maps.places.PlacesServiceStatus.ZERO_RESULTS) {
|
|
256
257
|
resolve({ placePredictions: placePredictions ?? [], token });
|
|
257
258
|
}
|
|
258
259
|
else {
|
|
259
|
-
reject(new Error(LocationNotFoundError));
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
export async function getPlace(location, mapElement = document.createElement('div')) {
|
|
265
|
-
const placesService = new google.maps.places.PlacesService(mapElement);
|
|
266
|
-
const { placePredictions, token } = await getPlacePredictions(location);
|
|
267
|
-
return new Promise((resolve, reject) => {
|
|
268
|
-
placesService.getDetails({
|
|
269
|
-
placeId: placePredictions[0]?.place_id,
|
|
270
|
-
fields: QUERY_FIELDS,
|
|
271
|
-
sessionToken: token
|
|
272
|
-
}, (place, pStatus) => {
|
|
273
|
-
if (pStatus === google.maps.places.PlacesServiceStatus.OK) {
|
|
274
|
-
resolve({
|
|
275
|
-
latitude: place?.geometry?.location?.lat() ?? NaN,
|
|
276
|
-
longitude: place?.geometry?.location?.lng() ?? NaN
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
reject(new Error(LocationNotFoundError));
|
|
260
|
+
reject(new Error(`${LocationNotFoundError}: ${status}`));
|
|
281
261
|
}
|
|
282
262
|
});
|
|
283
263
|
});
|
|
@@ -285,61 +265,81 @@ export async function getPlace(location, mapElement = document.createElement('di
|
|
|
285
265
|
export async function getPlaceById(placeId, sessionToken = new google.maps.places.AutocompleteSessionToken(), mapElement = document.createElement('div')) {
|
|
286
266
|
const placesService = new google.maps.places.PlacesService(mapElement);
|
|
287
267
|
return new Promise((resolve, reject) => {
|
|
288
|
-
placesService.getDetails({ placeId, fields: QUERY_FIELDS, sessionToken }, (place,
|
|
289
|
-
if (
|
|
268
|
+
placesService.getDetails({ placeId, fields: QUERY_FIELDS, sessionToken }, (place, status) => {
|
|
269
|
+
if (status === google.maps.places.PlacesServiceStatus.OK) {
|
|
290
270
|
resolve({
|
|
291
271
|
name: place?.name,
|
|
292
272
|
address: place?.formatted_address,
|
|
293
|
-
latitude: place?.geometry?.location?.lat(),
|
|
294
|
-
longitude: place?.geometry?.location?.lng()
|
|
273
|
+
latitude: place?.geometry?.location?.lat() ?? NaN,
|
|
274
|
+
longitude: place?.geometry?.location?.lng() ?? NaN
|
|
295
275
|
});
|
|
296
276
|
}
|
|
297
277
|
else {
|
|
298
|
-
reject(new Error(LocationNotFoundError));
|
|
278
|
+
reject(new Error(`${LocationNotFoundError}: ${status}`));
|
|
299
279
|
}
|
|
300
280
|
});
|
|
301
281
|
});
|
|
302
282
|
}
|
|
303
283
|
/** Returns coordinations for given input: either coords, address or current position. */
|
|
304
|
-
export async function getCoords(
|
|
305
|
-
if (
|
|
284
|
+
export async function getCoords(location) {
|
|
285
|
+
if (location === '' || location === undefined)
|
|
306
286
|
throw new Error();
|
|
307
|
-
if (
|
|
287
|
+
if (location === 'current')
|
|
308
288
|
return getNavigatorPosition();
|
|
309
|
-
let
|
|
310
|
-
if (typeof
|
|
289
|
+
let coords;
|
|
290
|
+
if (typeof location === 'string') {
|
|
311
291
|
let latLng = [];
|
|
312
|
-
if (isValueDMSCoordinate(
|
|
313
|
-
isValueDMCoordinate(
|
|
314
|
-
isValueDegreeFormatCoordinate(
|
|
315
|
-
latLng = parseDMS(
|
|
292
|
+
if (isValueDMSCoordinate(location) ||
|
|
293
|
+
isValueDMCoordinate(location) ||
|
|
294
|
+
isValueDegreeFormatCoordinate(location)) {
|
|
295
|
+
latLng = parseDMS(location);
|
|
316
296
|
}
|
|
317
297
|
else {
|
|
318
298
|
let splitter;
|
|
319
|
-
if (
|
|
299
|
+
if (location.includes(', ')) {
|
|
320
300
|
splitter = ', ';
|
|
321
301
|
}
|
|
322
|
-
else if (
|
|
302
|
+
else if (location.includes(',')) {
|
|
323
303
|
splitter = ',';
|
|
324
304
|
}
|
|
325
|
-
else if (
|
|
305
|
+
else if (location.includes(' ')) {
|
|
326
306
|
splitter = ' ';
|
|
327
307
|
}
|
|
328
308
|
else {
|
|
329
309
|
splitter = ', ';
|
|
330
310
|
}
|
|
331
|
-
latLng =
|
|
311
|
+
latLng = location.split(splitter).map(Number);
|
|
332
312
|
}
|
|
333
313
|
const [lat, lng] = latLng;
|
|
334
|
-
if (Number.isNaN(lat) || Number.isNaN(lng) || lat === undefined || lng === undefined)
|
|
335
|
-
|
|
336
|
-
|
|
314
|
+
if (Number.isNaN(lat) || Number.isNaN(lng) || lat === undefined || lng === undefined) {
|
|
315
|
+
const geocoder = new google.maps.Geocoder();
|
|
316
|
+
return new Promise((resolve, reject) => {
|
|
317
|
+
geocoder.geocode({ address: location }, (results, status) => {
|
|
318
|
+
if (status === 'OK') {
|
|
319
|
+
const [result] = results ?? [];
|
|
320
|
+
if (result?.geometry?.location) {
|
|
321
|
+
resolve({
|
|
322
|
+
latitude: result.geometry.location.lat(),
|
|
323
|
+
longitude: result.geometry.location.lng()
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
resolve({ latitude: NaN, longitude: NaN });
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
reject(new Error(`${GeocoderFailedError}: ${status}`));
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
coords = { latitude: lat, longitude: lng };
|
|
337
337
|
}
|
|
338
338
|
else {
|
|
339
|
-
|
|
339
|
+
coords = location;
|
|
340
340
|
}
|
|
341
|
-
if (Number.isFinite(
|
|
342
|
-
return
|
|
341
|
+
if (Number.isFinite(coords.latitude) && Number.isFinite(coords.longitude))
|
|
342
|
+
return coords;
|
|
343
343
|
throw new Error(CoordsCannotBeParsedError);
|
|
344
344
|
}
|
|
345
345
|
export async function getAddress(coords) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/Location/utils.ts"],"names":[],"mappings":"AAAA,qDAAqD;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAEnD,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,2BAA2B,EAC3B,0BAA0B,EAC1B,kBAAkB,EAClB,qBAAqB,EACrB,yBAAyB,EACzB,YAAY,EACZ,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAG1B,MAAM,iBAAiB,GAAG;IACxB,QAAQ;IACR,mBAAmB;IACnB,gCAAgC;IAChC,KAAK;IACL,qBAAqB;IACrB,QAAQ;IACR,2CAA2C;IAC3C,YAAY;IACZ,OAAO;IACP,oBAAoB;IACpB,6CAA6C;IAC7C,KAAK;IACL,sBAAsB;IACtB,SAAS;CACV,CAAC;AAEF,MAAM,uBAAuB,GAAG,IAAI,MAAM,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AAE1F,MAAM,aAAa,GAAG;IACpB,QAAQ;IACR,mBAAmB;IACnB,wBAAwB;IACxB,KAAK;IACL,mBAAmB;IACnB,iCAAiC;IACjC,KAAK;IACL,qBAAqB;IACrB,QAAQ;IACR,2CAA2C;IAC3C,YAAY;IACZ,OAAO;IACP,oBAAoB;IACpB,qCAAqC;IACrC,KAAK;IACL,oBAAoB;IACpB,iCAA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,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IAElD,OAAO,GAAG,CAAC,IAAI,CAAC;AAClB,CAAC,CAAC","sourcesContent":["/// <reference types=\"google.maps\" preserve=\"true\" />\n\nimport { Loader } from '@googlemaps/js-api-loader';\n\nimport {\n CoordsCannotBeParsedError,\n GeocoderFailedError,\n GeolocationUnsupportedError,\n GoogleMapsAPINotFoundError,\n IsNotAnObjectError,\n LocationNotFoundError,\n ProviderNotSupportedError,\n QUERY_FIELDS,\n QUERY_TYPES\n} from './Location.types';\nimport type { Bias, LatLng, MapsProvider, ProviderOpts, Location } from './Location.types';\n\nconst DegreeRegexChunks = [\n /^[-+]?/,\n // latitude degrees\n /([0-9]|[1-8][0-9]|90)(\\.\\d+)?°/,\n /\\s?/,\n // latitude direction\n /(N|S)?/,\n // sepeartor between latitude and longitude\n /(,|,\\s|\\s)/,\n /[-+]?/,\n // longitude degrees\n /([0-9]|[1-9][0-9]|1[0-7][0-9]|180)(\\.\\d+)?°/,\n /\\s?/,\n // longitude direction\n /(W|E)?$/\n];\n\nconst DegreeRegularExpression = new RegExp(DegreeRegexChunks.map(c => c.source).join(''));\n\nconst DMRegexChunks = [\n /^[-+]?/,\n // latitude degrees\n /([0-9]|[1-8][0-9]|90)°/,\n /\\s?/,\n // latitude minutes\n /([0-9]|[0-5][0-9])(\\.\\d+)?('|’)/,\n /\\s?/,\n // latitude direction\n /(N|S)?/,\n // sepeartor between latitude and longitude\n /(,|,\\s|\\s)/,\n /[-+]?/,\n // longitude degrees\n /([0-9]|[1-9][0-9]|1[0-7][0-9]|180)°/,\n /\\s?/,\n // longitude minutes\n /([0-9]|[0-5][0-9])(\\.\\d+)?('|’)/,\n /\\s?/,\n // longitude direction\n /(W|E)?$/\n];\n\nconst DMRegularExpression = new RegExp(DMRegexChunks.map(c => c.source).join(''));\nconst DMSRegexChunks = [\n /^[-+]?/,\n // latitude degrees\n /([0-9]|[1-8][0-9]|90)°/,\n /\\s?/,\n // latitude minutes\n /([0-9]|[0-5][0-9])('|’)/,\n /\\s?/,\n // latitude seconds\n /([0-9]|[0-5][0-9])(\\.\\d+)?(\"|″)/,\n /\\s?/,\n // latitude direction\n /(N|S)?/,\n // sepeartor between latitude and longitude\n /(,|,\\s|\\s)/,\n /[-+]?/,\n // longitude degrees\n /([0-9]|[1-9][0-9]|1[0-7][0-9]|180)°/,\n /\\s?/,\n // longitude minutes\n /([0-9]|[0-5][0-9])('|’)/,\n /\\s?/,\n // longitude seconds\n /([0-9]|[0-5][0-9])(\\.\\d+)?(\"|″)/,\n /\\s?/,\n // longitude direction\n /(W|E)?$/\n];\n\nconst DMSRegularExpression = new RegExp(DMSRegexChunks.map(c => c.source).join(''));\n\nconst decimalRegexChunks = [\n /^[-+]?/,\n /([0-9]|[1-8][0-9]|90)/,\n /(\\.\\d+)?/,\n /(,|\\s|,\\s)/,\n /[-+]?/,\n /([0-9]|[1-9][0-9]|1[0-7][0-9]|180)/,\n /(\\.\\d+)?$/\n];\n\nconst decimalFormatCoordinatesRegularExpression = new RegExp(\n decimalRegexChunks.map(c => c.source).join('')\n);\n\nconst providers: {\n [key: string]: MapsProvider;\n} = {\n google: {\n name: 'Google',\n loadedPromise: null,\n loadedApiKey: '',\n loadAPI(opts) {\n const loader = new Loader({\n version: 'quarterly',\n apiKey: opts.apiKey ?? '',\n region: opts.region,\n language: opts.language,\n libraries: ['places', 'marker']\n });\n\n return loader.load().then(\n () => {},\n () => {\n throw new Error(GoogleMapsAPINotFoundError);\n }\n );\n }\n },\n undefined: {\n name: 'undefined',\n loadedPromise: null,\n loadedApiKey: '',\n loadAPI: data => Promise.reject(new Error(`${ProviderNotSupportedError}: ${data.name}`))\n }\n};\n\nexport async function loadMapsAPI(name: string = '', opts?: ProviderOpts): Promise<void> {\n if (typeof opts !== 'object' || !opts) {\n throw new Error(IsNotAnObjectError);\n }\n\n const provider = providers[name] ?? providers.undefined;\n\n if (!provider.loadedPromise) {\n provider.loadedPromise = provider\n .loadAPI(opts)\n .then(() => {\n provider.loadedApiKey = opts?.apiKey ?? '';\n })\n .catch(() => {\n provider.loadedPromise = null;\n });\n }\n return provider.loadedPromise;\n}\n\n/**\n * Identifies coordinates in degree format\n * eg. 45.78°N 9.11°E\n */\nexport function isValueDegreeFormatCoordinate(value: string): boolean {\n return DegreeRegularExpression.test(value);\n}\n\n/**\n * Identifies coordinates in degree, minute format\n * eg. 45°45.4’N 9°23’E\n */\nexport function isValueDMCoordinate(value: string): boolean {\n return DMRegularExpression.test(value);\n}\n\n/**\n * Identifies coordinates in degree, minute, second format\n * eg. 45°45’32.4″N 9°23’39.9″E\n */\nexport function isValueDMSCoordinate(value: string): boolean {\n return DMSRegularExpression.test(value);\n}\n\n/**\n * Identifies coordinates in decimal format\n * eg. 14.678, -38.765\n */\nexport function isValueACoordinate(value: string): boolean {\n return (\n decimalFormatCoordinatesRegularExpression.test(value) ||\n isValueDMSCoordinate(value) ||\n isValueDMCoordinate(value) ||\n isValueDegreeFormatCoordinate(value)\n );\n}\n\ninterface DMSParts {\n degrees: number;\n minutes?: number;\n seconds?: number;\n}\n\n/**\n * Converts DMS (degree, minute, second) format latitude/longitude into decimal format.\n */\nfunction convertDMSToDD({ degrees, minutes, seconds }: DMSParts, direction?: string): number {\n let dd = degrees;\n if (minutes) {\n if (degrees > 0) dd += minutes / 60;\n if (degrees < 0) dd -= minutes / 60;\n }\n if (seconds) {\n if (degrees > 0) dd += seconds / (60 * 60);\n if (degrees < 0) dd -= seconds / (60 * 60);\n }\n\n if (degrees > 0 && (direction === 'S' || direction === 'W')) {\n dd *= -1;\n }\n\n return dd;\n}\n\n/**\n * Parses DMS (degree, minute, second) format string into decimal format coordinates.\n */\nexport function parseDMS(input: string): number[] {\n if (isValueDMSCoordinate(input)) {\n const parts = input.split(/'|’|\"\\s?|″\\s?|°|,?\\s|,\\s?/);\n\n const lat = convertDMSToDD(\n {\n degrees: Number(parts[0]),\n minutes: Number(parts[1]),\n seconds: Number(parts[2])\n },\n parts[3]\n );\n const lng = convertDMSToDD(\n {\n degrees: Number(parts[4]),\n minutes: Number(parts[5]),\n seconds: Number(parts[6])\n },\n parts[7]\n );\n return [lat, lng];\n }\n if (isValueDMCoordinate(input)) {\n const parts = input.split(/'\\s?|’\\s?|°|,?\\s|,\\s?/);\n\n const lat = convertDMSToDD({ degrees: Number(parts[0]), minutes: Number(parts[1]) }, parts[2]);\n const lng = convertDMSToDD({ degrees: Number(parts[3]), minutes: Number(parts[4]) }, parts[5]);\n return [lat, lng];\n }\n\n const parts = input.split(/°\\s?|,?\\s|,\\s?/);\n\n const lat = convertDMSToDD({ degrees: Number(parts[0]) }, parts[1]);\n const lng = convertDMSToDD({ degrees: Number(parts[2]) }, parts[3]);\n return [lat, lng];\n}\n\nexport async function getNavigatorPosition(): Promise<LatLng> {\n if (!navigator.geolocation) throw new Error(GeolocationUnsupportedError);\n\n return new Promise((resolve, reject) => {\n navigator.geolocation.getCurrentPosition(\n currentLocation => {\n resolve({\n latitude: currentLocation.coords.latitude,\n longitude: currentLocation.coords.longitude\n });\n },\n error => reject(new Error(error.message))\n );\n });\n}\n\nexport function toGoogleLatLng(coords: LatLng): google.maps.LatLng {\n return new google.maps.LatLng(coords.latitude, coords.longitude);\n}\n\n/** Returns an array of place prediction objects ('place' can be an establishment, geographic location, or prominent point of interest)\n * and session token (valid for multiple queries, followed by one place selection).\n */\nexport async function getPlacePredictions(\n location: string,\n bias: Bias = {}\n): Promise<{\n placePredictions: google.maps.places.AutocompletePrediction[];\n token: google.maps.places.AutocompleteSessionToken;\n}> {\n const autocompleteService = new google.maps.places.AutocompleteService();\n const optionalParams: Partial<google.maps.places.AutocompletionRequest> = {};\n if (bias?.location) {\n if (bias?.location.center === 'current') {\n await getNavigatorPosition()\n .then(coords => {\n optionalParams.location = toGoogleLatLng(coords);\n optionalParams.radius = bias.location!.radius;\n })\n // no-op user didn't allow location\n .catch(() => {});\n } else {\n optionalParams.location = toGoogleLatLng(bias.location.center);\n optionalParams.radius = bias.location.radius;\n }\n }\n\n if (bias?.bounds) {\n const [sw, ne] = bias.bounds;\n optionalParams.bounds = new google.maps.LatLngBounds(toGoogleLatLng(sw), toGoogleLatLng(ne));\n }\n return new Promise((resolve, reject) => {\n const token = new google.maps.places.AutocompleteSessionToken();\n autocompleteService.getPlacePredictions(\n {\n input: location,\n types: QUERY_TYPES,\n sessionToken: token,\n ...optionalParams\n },\n (placePredictions, status) => {\n if (status === google.maps.places.PlacesServiceStatus.OK) {\n resolve({ placePredictions: placePredictions ?? [], token });\n } else {\n reject(new Error(LocationNotFoundError));\n }\n }\n );\n });\n}\n\nexport async function getPlace(\n location: string,\n mapElement: HTMLDivElement = document.createElement('div')\n): Promise<LatLng> {\n const placesService = new google.maps.places.PlacesService(mapElement);\n const { placePredictions, token } = await getPlacePredictions(location);\n return new Promise((resolve, reject) => {\n placesService.getDetails(\n {\n placeId: placePredictions[0]?.place_id,\n fields: QUERY_FIELDS,\n sessionToken: token\n },\n (place, pStatus) => {\n if (pStatus === google.maps.places.PlacesServiceStatus.OK) {\n resolve({\n latitude: place?.geometry?.location?.lat() ?? NaN,\n longitude: place?.geometry?.location?.lng() ?? NaN\n });\n } else {\n reject(new Error(LocationNotFoundError));\n }\n }\n );\n });\n}\n\nexport async function getPlaceById(\n placeId: string,\n sessionToken: google.maps.places.AutocompleteSessionToken = new google.maps.places.AutocompleteSessionToken(),\n mapElement: HTMLDivElement = document.createElement('div')\n): Promise<Location> {\n const placesService = new google.maps.places.PlacesService(mapElement);\n return new Promise((resolve, reject) => {\n placesService.getDetails({ placeId, fields: QUERY_FIELDS, sessionToken }, (place, pStatus) => {\n if (pStatus === google.maps.places.PlacesServiceStatus.OK) {\n resolve({\n name: place?.name,\n address: place?.formatted_address,\n latitude: place?.geometry?.location?.lat(),\n longitude: place?.geometry?.location?.lng()\n });\n } else {\n reject(new Error(LocationNotFoundError));\n }\n });\n });\n}\n\n/** Returns coordinations for given input: either coords, address or current position. */\nexport async function getCoords(\n coords: string | 'current' | LatLng,\n mapElement?: HTMLDivElement\n): Promise<LatLng> {\n if (coords === '' || coords === undefined) throw new Error();\n if (coords === 'current') return getNavigatorPosition();\n\n let location: LatLng;\n if (typeof coords === 'string') {\n let latLng: number[] = [];\n if (\n isValueDMSCoordinate(coords) ||\n isValueDMCoordinate(coords) ||\n isValueDegreeFormatCoordinate(coords)\n ) {\n latLng = parseDMS(coords);\n } else {\n let splitter;\n if (coords.includes(', ')) {\n splitter = ', ';\n } else if (coords.includes(',')) {\n splitter = ',';\n } else if (coords.includes(' ')) {\n splitter = ' ';\n } else {\n splitter = ', ';\n }\n\n latLng = coords.split(splitter).map(Number);\n }\n\n const [lat, lng] = latLng;\n if (Number.isNaN(lat) || Number.isNaN(lng) || lat === undefined || lng === undefined)\n return getPlace(coords, mapElement);\n location = { latitude: lat, longitude: lng };\n } else {\n location = coords;\n }\n\n if (Number.isFinite(location.latitude) && Number.isFinite(location.longitude)) return location;\n\n throw new Error(CoordsCannotBeParsedError);\n}\n\nexport async function getAddress(coords: LatLng): Promise<{\n name: string;\n address?: string;\n latitude: number;\n longitude: number;\n}> {\n const location = {\n lat: coords.latitude,\n lng: coords.longitude\n };\n const geocoder = new google.maps.Geocoder();\n return new Promise((resolve, reject) => {\n geocoder.geocode(\n { location },\n (results: google.maps.GeocoderResult[] | null, status: google.maps.GeocoderStatus) => {\n if (status === 'OK') {\n const [result] = results ?? [];\n if (result) {\n resolve({\n name: result.formatted_address,\n address: result.formatted_address,\n ...(result.geometry && {\n latitude: result.geometry.location.lat(),\n longitude: result.geometry.location.lng()\n })\n });\n } else {\n resolve({\n name: `${coords.latitude}, ${coords.longitude}`,\n latitude: coords.latitude,\n longitude: coords.longitude\n });\n }\n } else {\n reject(new Error(`${GeocoderFailedError}: ${status}`));\n }\n }\n );\n });\n}\n\nexport const isLatLngObject = (obj: unknown): obj is google.maps.LatLng => {\n return (\n !!obj &&\n typeof obj === 'object' &&\n 'lat' in obj &&\n typeof obj.lat === 'function' &&\n 'lng' in obj &&\n typeof obj.lng === 'function'\n );\n};\n\nexport const getGoogleMapsDirHref = (\n destination: string,\n waypoints: string[],\n travelMode: string = 'driving'\n) => {\n const url = new URL('https://www.google.com/maps/dir/?api=1');\n\n url.searchParams.append('destination', destination);\n url.searchParams.append('waypoints', waypoints.join('|'));\n url.searchParams.append('travelmode', travelMode);\n\n return url.href;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/Location/utils.ts"],"names":[],"mappings":"AAAA,qDAAqD;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAEnD,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,2BAA2B,EAC3B,0BAA0B,EAC1B,kBAAkB,EAClB,qBAAqB,EACrB,yBAAyB,EACzB,YAAY,EACZ,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAG1B,MAAM,iBAAiB,GAAG;IACxB,QAAQ;IACR,mBAAmB;IACnB,gCAAgC;IAChC,KAAK;IACL,qBAAqB;IACrB,QAAQ;IACR,2CAA2C;IAC3C,YAAY;IACZ,OAAO;IACP,oBAAoB;IACpB,6CAA6C;IAC7C,KAAK;IACL,sBAAsB;IACtB,SAAS;CACV,CAAC;AAEF,MAAM,uBAAuB,GAAG,IAAI,MAAM,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AAE1F,MAAM,aAAa,GAAG;IACpB,QAAQ;IACR,mBAAmB;IACnB,wBAAwB;IACxB,KAAK;IACL,mBAAmB;IACnB,iCAAiC;IACjC,KAAK;IACL,qBAAqB;IACrB,QAAQ;IACR,2CAA2C;IAC3C,YAAY;IACZ,OAAO;IACP,oBAAoB;IACpB,qCAAqC;IACrC,KAAK;IACL,oBAAoB;IACpB,iCAAiC;IACjC,KAAK;IACL,sBAAsB;IACtB,SAAS;CACV,CAAC;AAEF,MA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U,CAAC,CAAC;IAElD,OAAO,GAAG,CAAC,IAAI,CAAC;AAClB,CAAC,CAAC","sourcesContent":["/// <reference types=\"google.maps\" preserve=\"true\" />\n\nimport { Loader } from '@googlemaps/js-api-loader';\n\nimport {\n CoordsCannotBeParsedError,\n GeocoderFailedError,\n GeolocationUnsupportedError,\n GoogleMapsAPINotFoundError,\n IsNotAnObjectError,\n LocationNotFoundError,\n ProviderNotSupportedError,\n QUERY_FIELDS,\n QUERY_TYPES\n} from './Location.types';\nimport type { Bias, LatLng, MapsProvider, ProviderOpts, Location } from './Location.types';\n\nconst DegreeRegexChunks = [\n /^[-+]?/,\n // latitude degrees\n /([0-9]|[1-8][0-9]|90)(\\.\\d+)?°/,\n /\\s?/,\n // latitude direction\n /(N|S)?/,\n // sepeartor between latitude and longitude\n /(,|,\\s|\\s)/,\n /[-+]?/,\n // longitude degrees\n /([0-9]|[1-9][0-9]|1[0-7][0-9]|180)(\\.\\d+)?°/,\n /\\s?/,\n // longitude direction\n /(W|E)?$/\n];\n\nconst DegreeRegularExpression = new RegExp(DegreeRegexChunks.map(c => c.source).join(''));\n\nconst DMRegexChunks = [\n /^[-+]?/,\n // latitude degrees\n /([0-9]|[1-8][0-9]|90)°/,\n /\\s?/,\n // latitude minutes\n /([0-9]|[0-5][0-9])(\\.\\d+)?('|’)/,\n /\\s?/,\n // latitude direction\n /(N|S)?/,\n // sepeartor between latitude and longitude\n /(,|,\\s|\\s)/,\n /[-+]?/,\n // longitude degrees\n /([0-9]|[1-9][0-9]|1[0-7][0-9]|180)°/,\n /\\s?/,\n // longitude minutes\n /([0-9]|[0-5][0-9])(\\.\\d+)?('|’)/,\n /\\s?/,\n // longitude direction\n /(W|E)?$/\n];\n\nconst DMRegularExpression = new RegExp(DMRegexChunks.map(c => c.source).join(''));\nconst DMSRegexChunks = [\n /^[-+]?/,\n // latitude degrees\n /([0-9]|[1-8][0-9]|90)°/,\n /\\s?/,\n // latitude minutes\n /([0-9]|[0-5][0-9])('|’)/,\n /\\s?/,\n // latitude seconds\n /([0-9]|[0-5][0-9])(\\.\\d+)?(\"|″)/,\n /\\s?/,\n // latitude direction\n /(N|S)?/,\n // sepeartor between latitude and longitude\n /(,|,\\s|\\s)/,\n /[-+]?/,\n // longitude degrees\n /([0-9]|[1-9][0-9]|1[0-7][0-9]|180)°/,\n /\\s?/,\n // longitude minutes\n /([0-9]|[0-5][0-9])('|’)/,\n /\\s?/,\n // longitude seconds\n /([0-9]|[0-5][0-9])(\\.\\d+)?(\"|″)/,\n /\\s?/,\n // longitude direction\n /(W|E)?$/\n];\n\nconst DMSRegularExpression = new RegExp(DMSRegexChunks.map(c => c.source).join(''));\n\nconst decimalRegexChunks = [\n /^[-+]?/,\n /([0-9]|[1-8][0-9]|90)/,\n /(\\.\\d+)?/,\n /(,|\\s|,\\s)/,\n /[-+]?/,\n /([0-9]|[1-9][0-9]|1[0-7][0-9]|180)/,\n /(\\.\\d+)?$/\n];\n\nconst decimalFormatCoordinatesRegularExpression = new RegExp(\n decimalRegexChunks.map(c => c.source).join('')\n);\n\nconst providers: {\n [key: string]: MapsProvider;\n} = {\n google: {\n name: 'Google',\n loadedPromise: null,\n loadedApiKey: '',\n loadAPI(opts) {\n const loader = new Loader({\n version: 'quarterly',\n apiKey: opts.apiKey ?? '',\n region: opts.region,\n language: opts.language,\n libraries: ['places', 'marker']\n });\n\n return loader.load().then(\n () => {},\n () => {\n throw new Error(GoogleMapsAPINotFoundError);\n }\n );\n }\n },\n undefined: {\n name: 'undefined',\n loadedPromise: null,\n loadedApiKey: '',\n loadAPI: data => Promise.reject(new Error(`${ProviderNotSupportedError}: ${data.name}`))\n }\n};\n\nexport async function loadMapsAPI(name: string = '', opts?: ProviderOpts): Promise<void> {\n if (typeof opts !== 'object' || !opts) {\n throw new Error(IsNotAnObjectError);\n }\n\n const provider = providers[name] ?? providers.undefined;\n\n if (!provider.loadedPromise) {\n provider.loadedPromise = provider\n .loadAPI(opts)\n .then(() => {\n provider.loadedApiKey = opts?.apiKey ?? '';\n })\n .catch(() => {\n provider.loadedPromise = null;\n });\n }\n return provider.loadedPromise;\n}\n\n/**\n * Identifies coordinates in degree format\n * eg. 45.78°N 9.11°E\n */\nexport function isValueDegreeFormatCoordinate(value: string): boolean {\n return DegreeRegularExpression.test(value);\n}\n\n/**\n * Identifies coordinates in degree, minute format\n * eg. 45°45.4’N 9°23’E\n */\nexport function isValueDMCoordinate(value: string): boolean {\n return DMRegularExpression.test(value);\n}\n\n/**\n * Identifies coordinates in degree, minute, second format\n * eg. 45°45’32.4″N 9°23’39.9″E\n */\nexport function isValueDMSCoordinate(value: string): boolean {\n return DMSRegularExpression.test(value);\n}\n\n/**\n * Identifies coordinates in decimal format\n * eg. 14.678, -38.765\n */\nexport function isValueACoordinate(value: string): boolean {\n return (\n decimalFormatCoordinatesRegularExpression.test(value) ||\n isValueDMSCoordinate(value) ||\n isValueDMCoordinate(value) ||\n isValueDegreeFormatCoordinate(value)\n );\n}\n\ninterface DMSParts {\n degrees: number;\n minutes?: number;\n seconds?: number;\n}\n\n/**\n * Converts DMS (degree, minute, second) format latitude/longitude into decimal format.\n */\nfunction convertDMSToDD({ degrees, minutes, seconds }: DMSParts, direction?: string): number {\n let dd = degrees;\n if (minutes) {\n if (degrees > 0) dd += minutes / 60;\n if (degrees < 0) dd -= minutes / 60;\n }\n if (seconds) {\n if (degrees > 0) dd += seconds / (60 * 60);\n if (degrees < 0) dd -= seconds / (60 * 60);\n }\n\n if (degrees > 0 && (direction === 'S' || direction === 'W')) {\n dd *= -1;\n }\n\n return dd;\n}\n\n/**\n * Parses DMS (degree, minute, second) format string into decimal format coordinates.\n */\nexport function parseDMS(input: string): number[] {\n if (isValueDMSCoordinate(input)) {\n const parts = input.split(/'|’|\"\\s?|″\\s?|°|,?\\s|,\\s?/);\n\n const lat = convertDMSToDD(\n {\n degrees: Number(parts[0]),\n minutes: Number(parts[1]),\n seconds: Number(parts[2])\n },\n parts[3]\n );\n const lng = convertDMSToDD(\n {\n degrees: Number(parts[4]),\n minutes: Number(parts[5]),\n seconds: Number(parts[6])\n },\n parts[7]\n );\n return [lat, lng];\n }\n if (isValueDMCoordinate(input)) {\n const parts = input.split(/'\\s?|’\\s?|°|,?\\s|,\\s?/);\n\n const lat = convertDMSToDD({ degrees: Number(parts[0]), minutes: Number(parts[1]) }, parts[2]);\n const lng = convertDMSToDD({ degrees: Number(parts[3]), minutes: Number(parts[4]) }, parts[5]);\n return [lat, lng];\n }\n\n const parts = input.split(/°\\s?|,?\\s|,\\s?/);\n\n const lat = convertDMSToDD({ degrees: Number(parts[0]) }, parts[1]);\n const lng = convertDMSToDD({ degrees: Number(parts[2]) }, parts[3]);\n return [lat, lng];\n}\n\nexport async function getNavigatorPosition(): Promise<LatLng> {\n if (!navigator.geolocation) throw new Error(GeolocationUnsupportedError);\n\n return new Promise((resolve, reject) => {\n navigator.geolocation.getCurrentPosition(\n currentLocation => {\n resolve({\n latitude: currentLocation.coords.latitude,\n longitude: currentLocation.coords.longitude\n });\n },\n error => reject(new Error(error.message))\n );\n });\n}\n\nexport function toGoogleLatLng(coords: LatLng): google.maps.LatLng {\n return new google.maps.LatLng(coords.latitude, coords.longitude);\n}\n\n/** Returns an array of place prediction objects ('place' can be an establishment, geographic location, or prominent point of interest)\n * and session token (valid for multiple queries, followed by one place selection).\n */\nexport async function getPlacePredictions(\n location: string,\n bias: Bias = {},\n sessionToken?: google.maps.places.AutocompleteSessionToken\n): Promise<{\n placePredictions: google.maps.places.AutocompletePrediction[];\n token: google.maps.places.AutocompleteSessionToken;\n}> {\n const autocompleteService = new google.maps.places.AutocompleteService();\n const optionalParams: Partial<google.maps.places.AutocompletionRequest> = {};\n if (bias?.location) {\n if (bias?.location.center === 'current') {\n await getNavigatorPosition()\n .then(coords => {\n optionalParams.location = toGoogleLatLng(coords);\n optionalParams.radius = bias.location!.radius;\n })\n // no-op user didn't allow location\n .catch(() => {});\n } else {\n optionalParams.location = toGoogleLatLng(bias.location.center);\n optionalParams.radius = bias.location.radius;\n }\n }\n\n if (bias?.bounds) {\n const [sw, ne] = bias.bounds;\n optionalParams.bounds = new google.maps.LatLngBounds(toGoogleLatLng(sw), toGoogleLatLng(ne));\n }\n return new Promise((resolve, reject) => {\n const token = sessionToken ?? new google.maps.places.AutocompleteSessionToken();\n autocompleteService.getPlacePredictions(\n {\n input: location,\n types: QUERY_TYPES,\n sessionToken: token,\n ...optionalParams\n },\n (placePredictions, status) => {\n if (\n status === google.maps.places.PlacesServiceStatus.OK ||\n status === google.maps.places.PlacesServiceStatus.ZERO_RESULTS\n ) {\n resolve({ placePredictions: placePredictions ?? [], token });\n } else {\n reject(new Error(`${LocationNotFoundError}: ${status}`));\n }\n }\n );\n });\n}\n\nexport async function getPlaceById(\n placeId: string,\n sessionToken: google.maps.places.AutocompleteSessionToken = new google.maps.places.AutocompleteSessionToken(),\n mapElement: HTMLDivElement = document.createElement('div')\n): Promise<Location> {\n const placesService = new google.maps.places.PlacesService(mapElement);\n return new Promise((resolve, reject) => {\n placesService.getDetails({ placeId, fields: QUERY_FIELDS, sessionToken }, (place, status) => {\n if (status === google.maps.places.PlacesServiceStatus.OK) {\n resolve({\n name: place?.name,\n address: place?.formatted_address,\n latitude: place?.geometry?.location?.lat() ?? NaN,\n longitude: place?.geometry?.location?.lng() ?? NaN\n });\n } else {\n reject(new Error(`${LocationNotFoundError}: ${status}`));\n }\n });\n });\n}\n\n/** Returns coordinations for given input: either coords, address or current position. */\nexport async function getCoords(location: string | 'current' | LatLng): Promise<LatLng> {\n if (location === '' || location === undefined) throw new Error();\n if (location === 'current') return getNavigatorPosition();\n\n let coords: LatLng;\n if (typeof location === 'string') {\n let latLng: number[] = [];\n if (\n isValueDMSCoordinate(location) ||\n isValueDMCoordinate(location) ||\n isValueDegreeFormatCoordinate(location)\n ) {\n latLng = parseDMS(location);\n } else {\n let splitter;\n if (location.includes(', ')) {\n splitter = ', ';\n } else if (location.includes(',')) {\n splitter = ',';\n } else if (location.includes(' ')) {\n splitter = ' ';\n } else {\n splitter = ', ';\n }\n\n latLng = location.split(splitter).map(Number);\n }\n\n const [lat, lng] = latLng;\n if (Number.isNaN(lat) || Number.isNaN(lng) || lat === undefined || lng === undefined) {\n const geocoder = new google.maps.Geocoder();\n return new Promise((resolve, reject) => {\n geocoder.geocode({ address: location }, (results, status) => {\n if (status === 'OK') {\n const [result] = results ?? [];\n if (result?.geometry?.location) {\n resolve({\n latitude: result.geometry.location.lat(),\n longitude: result.geometry.location.lng()\n });\n } else {\n resolve({ latitude: NaN, longitude: NaN });\n }\n } else {\n reject(new Error(`${GeocoderFailedError}: ${status}`));\n }\n });\n });\n }\n coords = { latitude: lat, longitude: lng };\n } else {\n coords = location;\n }\n\n if (Number.isFinite(coords.latitude) && Number.isFinite(coords.longitude)) return coords;\n\n throw new Error(CoordsCannotBeParsedError);\n}\n\nexport async function getAddress(coords: LatLng): Promise<{\n name: string;\n address?: string;\n latitude: number;\n longitude: number;\n}> {\n const location = {\n lat: coords.latitude,\n lng: coords.longitude\n };\n const geocoder = new google.maps.Geocoder();\n return new Promise((resolve, reject) => {\n geocoder.geocode({ location }, (results, status) => {\n if (status === 'OK') {\n const [result] = results ?? [];\n if (result) {\n resolve({\n name: result.formatted_address,\n address: result.formatted_address,\n ...(result.geometry && {\n latitude: result.geometry.location.lat(),\n longitude: result.geometry.location.lng()\n })\n });\n } else {\n resolve({\n name: `${coords.latitude}, ${coords.longitude}`,\n latitude: coords.latitude,\n longitude: coords.longitude\n });\n }\n } else {\n reject(new Error(`${GeocoderFailedError}: ${status}`));\n }\n });\n });\n}\n\nexport const isLatLngObject = (obj: unknown): obj is google.maps.LatLng => {\n return (\n !!obj &&\n typeof obj === 'object' &&\n 'lat' in obj &&\n typeof obj.lat === 'function' &&\n 'lng' in obj &&\n typeof obj.lng === 'function'\n );\n};\n\nexport const getGoogleMapsDirHref = (\n destination: string,\n waypoints: string[],\n travelMode: string = 'driving'\n) => {\n const url = new URL('https://www.google.com/maps/dir/?api=1');\n\n url.searchParams.append('destination', destination);\n url.searchParams.append('waypoints', waypoints.join('|'));\n url.searchParams.append('travelmode', travelMode);\n\n return url.href;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextArea.d.ts","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,EAAE,EAIF,kBAAkB,EAElB,iBAAiB,EAClB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGvF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAgBvD,MAAM,WAAW,aAAc,SAAQ,gBAAgB,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU;IAC5F,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,QAAQ,CAAC,EAAE,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;IACnD,OAAO,CAAC,EAAE,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;IACjD,MAAM,CAAC,EAAE,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;CACjD;;;;
|
|
1
|
+
{"version":3,"file":"TextArea.d.ts","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,EAAE,EAIF,kBAAkB,EAElB,iBAAiB,EAClB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGvF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAgBvD,MAAM,WAAW,aAAc,SAAQ,gBAAgB,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU;IAC5F,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,QAAQ,CAAC,EAAE,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;IACnD,OAAO,CAAC,EAAE,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;IACjD,MAAM,CAAC,EAAE,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;CACjD;;;;AAwMD,wBAAyD"}
|
|
@@ -8,6 +8,7 @@ import Text from '../Text';
|
|
|
8
8
|
import VisuallyHiddenText from '../VisuallyHiddenText';
|
|
9
9
|
import StyledTextArea from './TextArea.styles';
|
|
10
10
|
import { getTextAreaTestIds } from './TextArea.test-ids';
|
|
11
|
+
const warnCharCount = 30;
|
|
11
12
|
const TextArea = forwardRef(function TextArea(props, ref) {
|
|
12
13
|
const uid = useUID();
|
|
13
14
|
const { testId, additionalInfo, id = uid, value, defaultValue, required = false, disabled = false, readOnly = false, label, labelHidden, info, status, resizable = false, autoResize = true, maxLength, displayCharCount = false, hardStop = true, onChange: onChangeProp, onResolveSuggestion, ...restProps } = props;
|
|
@@ -29,15 +30,26 @@ const TextArea = forwardRef(function TextArea(props, ref) {
|
|
|
29
30
|
controlProp.defaultValue = defaultValue ?? '';
|
|
30
31
|
}
|
|
31
32
|
const onChange = useCallback((e) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
if (maxLength !== undefined) {
|
|
34
|
+
if (e.target.value.length >= maxLength) {
|
|
35
|
+
announceAssertive({ message: t('text_area_character_limit'), type: 'warning' });
|
|
36
|
+
}
|
|
37
|
+
else if (maxLength > warnCharCount) {
|
|
38
|
+
const prevCharsRemaining = maxLength - charCount;
|
|
39
|
+
const charsRemaining = maxLength - e.target.value.length;
|
|
40
|
+
if (charsRemaining < warnCharCount && prevCharsRemaining >= warnCharCount) {
|
|
41
|
+
announceAssertive({
|
|
42
|
+
message: t('text_area_characters_remaining', [`${warnCharCount}`]),
|
|
43
|
+
type: 'warning'
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
35
47
|
}
|
|
36
48
|
if (!hardStop || maxLength === undefined || e.target.value.length <= maxLength) {
|
|
37
49
|
onChangeProp?.(e);
|
|
38
50
|
setCharCount(e.target.value.length);
|
|
39
51
|
}
|
|
40
|
-
}, [onChangeProp, hardStop, maxLength, announceAssertive, t]);
|
|
52
|
+
}, [onChangeProp, charCount, hardStop, maxLength, announceAssertive, t]);
|
|
41
53
|
const recalculateHeight = useCallback(() => {
|
|
42
54
|
if (!textAreaRef.current)
|
|
43
55
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextArea.js","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAY7E,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EACL,kBAAkB,EAClB,UAAU,EACV,OAAO,EACP,UAAU,EACV,UAAU,EACV,MAAM,EACP,MAAM,aAAa,CA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useEffect, useRef } from 'react';\nimport type {\n FC,\n Ref,\n PropsWithoutRef,\n ChangeEvent,\n ChangeEventHandler,\n FocusEvent,\n FocusEventHandler\n} from 'react';\n\nimport type { BaseProps, ForwardProps, NoChildrenProp, TestIdProp } from '../../types';\nimport FormField from '../FormField';\nimport { StyledFormControl } from '../FormControl';\nimport type { FormControlProps } from '../FormControl';\nimport { hasProp, withTestIds } from '../../utils';\nimport {\n useConsolidatedRef,\n useElement,\n useI18n,\n useLiveLog,\n useTestIds,\n useUID\n} from '../../hooks';\nimport Text from '../Text';\nimport VisuallyHiddenText from '../VisuallyHiddenText';\n\nimport StyledTextArea from './TextArea.styles';\nimport { getTextAreaTestIds } from './TextArea.test-ids';\n\nexport interface TextAreaProps extends FormControlProps, BaseProps, NoChildrenProp, TestIdProp {\n /** Minimum length of characters that can be input. */\n minLength?: number;\n /** Maximum length of characters that can be input. */\n maxLength?: number;\n /**\n * Allows the user to resize the Text Area. This prop is ignored if autoResize is true.\n * @default false\n */\n resizable?: boolean;\n /**\n * Enables the Text Area to resize itself automatically.\n * @default true\n */\n autoResize?: boolean;\n /**\n * Display a live character count in relation to the maxLength.\n * @default false\n */\n displayCharCount?: boolean;\n /**\n * Allow or disallow a value beyond the maxLength.\n * @default true\n */\n hardStop?: boolean;\n\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n onFocus?: FocusEventHandler<HTMLTextAreaElement>;\n onBlur?: FocusEventHandler<HTMLTextAreaElement>;\n}\n\nconst TextArea: FC<TextAreaProps & ForwardProps> = forwardRef(function TextArea(\n props: PropsWithoutRef<TextAreaProps>,\n ref: Ref<HTMLTextAreaElement>\n) {\n const uid = useUID();\n const {\n testId,\n additionalInfo,\n id = uid,\n value,\n defaultValue,\n required = false,\n disabled = false,\n readOnly = false,\n label,\n labelHidden,\n info,\n status,\n resizable = false,\n autoResize = true,\n maxLength,\n displayCharCount = false,\n hardStop = true,\n onChange: onChangeProp,\n onResolveSuggestion,\n ...restProps\n } = props;\n const t = useI18n();\n\n const testIds = useTestIds(testId, getTextAreaTestIds);\n const [charCount, setCharCount] = useState(value?.length ?? defaultValue?.length ?? 0);\n const [focused, setFocused] = useState(false);\n const [textAreaEl, setTextAreaEl] = useElement<HTMLTextAreaElement>();\n const textAreaRef = useConsolidatedRef(ref, setTextAreaEl);\n const prevHeightRef = useRef(0);\n const focusTimeoutRef = useRef(NaN);\n const { announceAssertive } = useLiveLog();\n\n const controlProp: {\n value?: string;\n defaultValue?: string;\n } = {};\n\n // Conditionally render component as controlled/uncontrolled\n if (hasProp(props, 'value')) {\n controlProp.value = value ?? '';\n } else if (hasProp(props, 'defaultValue')) {\n controlProp.defaultValue = defaultValue ?? '';\n }\n\n const onChange = useCallback(\n (e: ChangeEvent<HTMLTextAreaElement>) => {\n // Announce every change event when the limit is reached or exceeded.\n if (maxLength !== undefined && e.target.value.length >= maxLength) {\n announceAssertive({ message: t('text_area_character_limit'), type: 'warning' });\n }\n\n if (!hardStop || maxLength === undefined || e.target.value.length <= maxLength) {\n onChangeProp?.(e);\n setCharCount(e.target.value.length);\n }\n },\n [onChangeProp, hardStop, maxLength, announceAssertive, t]\n );\n\n const recalculateHeight = useCallback(() => {\n if (!textAreaRef.current) return;\n\n textAreaRef.current.style.setProperty('--textarea-height', 'auto');\n\n // Remove scrollbar width to avoid interference with calculation.\n textAreaRef.current.style.setProperty('scrollbar-width', 'none');\n\n const scrollHeight = textAreaRef.current.scrollHeight;\n const borderWidth = textAreaRef.current.offsetHeight - textAreaRef.current.clientHeight;\n // Set height to auto then scrollHeight + borderWidth to resize TextArea to content\n textAreaRef.current.style.setProperty('--textarea-height', `${scrollHeight + borderWidth}px`);\n\n textAreaRef.current.style.removeProperty('scrollbar-width');\n }, []);\n\n useEffect(() => {\n if (!textAreaRef.current) return;\n\n if (autoResize) {\n recalculateHeight();\n } else {\n textAreaRef.current.style.removeProperty('--textarea-height');\n }\n }, [value, autoResize, recalculateHeight]);\n\n // Recalculate height when the element becomes visible after being displayed none.\n useEffect(() => {\n if (!textAreaEl || !autoResize) return;\n\n prevHeightRef.current = textAreaEl.offsetHeight;\n\n const observer = new ResizeObserver(entries => {\n const currentHeight = entries[0].contentRect.height;\n if (prevHeightRef.current === 0 && currentHeight > 0) {\n recalculateHeight();\n }\n prevHeightRef.current = currentHeight;\n });\n\n observer.observe(textAreaEl);\n return () => observer.disconnect();\n }, [autoResize, recalculateHeight, textAreaEl]);\n\n useEffect(\n () => () => {\n clearTimeout(focusTimeoutRef.current);\n },\n []\n );\n\n const TextAreaControl = (\n <StyledFormControl\n data-testid={testIds.control}\n ref={textAreaRef}\n id={id}\n aria-describedby={\n // Remove when focused to prevent each change in character count from being announced.\n !focused && displayCharCount && typeof maxLength === 'number'\n ? `${id}-charCount`\n : undefined\n }\n required={required}\n disabled={disabled}\n status={status}\n readOnly={readOnly}\n autoResize={autoResize}\n resizable={autoResize ? false : resizable}\n maxLength={hardStop ? maxLength : undefined}\n hasSuggestion={status === 'pending' && !!onResolveSuggestion}\n {...controlProp}\n {...restProps}\n onChange={onChange}\n onFocus={(e: FocusEvent<HTMLTextAreaElement>) => {\n // Need to delay so screen readers will include the character count in announcement on initial focus.\n // Shorter delays did not seem to work.\n focusTimeoutRef.current = window.setTimeout(() => {\n setFocused(true);\n }, 250);\n\n restProps.onFocus?.(e);\n }}\n onBlur={(e: FocusEvent<HTMLTextAreaElement>) => {\n clearTimeout(focusTimeoutRef.current);\n setFocused(false);\n restProps.onBlur?.(e);\n }}\n as={StyledTextArea}\n />\n );\n\n return label || displayCharCount ? (\n <FormField\n testId={testIds}\n additionalInfo={additionalInfo}\n label={label}\n labelHidden={labelHidden}\n id={id}\n readOnly={readOnly}\n info={info}\n status={status}\n charLimitDisplay={\n displayCharCount && typeof maxLength === 'number' ? (\n <Text id={`${id}-charCount`} readOnly={readOnly} variant='secondary'>\n {maxLength >= 0 ? t('x_of_y', [charCount || '0', maxLength]) : charCount}{' '}\n <VisuallyHiddenText>{t('characters_typed')}</VisuallyHiddenText>\n </Text>\n ) : undefined\n }\n required={required}\n disabled={disabled}\n onResolveSuggestion={onResolveSuggestion}\n >\n {TextAreaControl}\n </FormField>\n ) : (\n TextAreaControl\n );\n});\n\nexport default withTestIds(TextArea, getTextAreaTestIds);\n"]}
|
|
1
|
+
{"version":3,"file":"TextArea.js","sourceRoot":"","sources":["../../../src/components/TextArea/TextArea.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAY7E,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EACL,kBAAkB,EAClB,UAAU,EACV,OAAO,EACP,UAAU,EACV,UAAU,EACV,MAAM,EACP,MAAM,aAAa,CAAC;AACrB,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AAEvD,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAiCzD,MAAM,aAAa,GAAG,EAAE,CAAC;AAEzB,MAAM,QAAQ,GAAqC,UAAU,CAAC,SAAS,QAAQ,CAC7E,KAAqC,EACrC,GAA6B;IAE7B,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;IACrB,MAAM,EACJ,MAAM,EACN,cAAc,EACd,EAAE,GAAG,GAAG,EACR,KAAK,EACL,YAAY,EACZ,QAAQ,GAAG,KAAK,EAChB,QAAQ,GAAG,KAAK,EAChB,QAAQ,GAAG,KAAK,EAChB,KAAK,EACL,WAAW,EACX,IAAI,EACJ,MAAM,EACN,SAAS,GAAG,KAAK,EACjB,UAAU,GAAG,IAAI,EACjB,SAAS,EACT,gBAAgB,GAAG,KAAK,EACxB,QAAQ,GA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UAAU,CAAC,KAAK,CAAC,CAAC;YAClB,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC,EACD,EAAE,EAAE,cAAc,GAClB,CACH,CAAC;IAEF,OAAO,KAAK,IAAI,gBAAgB,CAAC,CAAC,CAAC,CACjC,KAAC,SAAS,IACR,MAAM,EAAE,OAAO,EACf,cAAc,EAAE,cAAc,EAC9B,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,EAAE,EAAE,EAAE,EACN,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,EACd,gBAAgB,EACd,gBAAgB,IAAI,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,CAClD,MAAC,IAAI,IAAC,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAC,WAAW,aACjE,SAAS,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,SAAS,IAAI,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,GAAG,EAC7E,KAAC,kBAAkB,cAAE,CAAC,CAAC,kBAAkB,CAAC,GAAsB,IAC3D,CACR,CAAC,CAAC,CAAC,SAAS,EAEf,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,mBAAmB,EAAE,mBAAmB,YAEvC,eAAe,GACN,CACb,CAAC,CAAC,CAAC,CACF,eAAe,CAChB,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC","sourcesContent":["import { forwardRef, useCallback, useState, useEffect, useRef } from 'react';\nimport type {\n FC,\n Ref,\n PropsWithoutRef,\n ChangeEvent,\n ChangeEventHandler,\n FocusEvent,\n FocusEventHandler\n} from 'react';\n\nimport type { BaseProps, ForwardProps, NoChildrenProp, TestIdProp } from '../../types';\nimport FormField from '../FormField';\nimport { StyledFormControl } from '../FormControl';\nimport type { FormControlProps } from '../FormControl';\nimport { hasProp, withTestIds } from '../../utils';\nimport {\n useConsolidatedRef,\n useElement,\n useI18n,\n useLiveLog,\n useTestIds,\n useUID\n} from '../../hooks';\nimport Text from '../Text';\nimport VisuallyHiddenText from '../VisuallyHiddenText';\n\nimport StyledTextArea from './TextArea.styles';\nimport { getTextAreaTestIds } from './TextArea.test-ids';\n\nexport interface TextAreaProps extends FormControlProps, BaseProps, NoChildrenProp, TestIdProp {\n /** Minimum length of characters that can be input. */\n minLength?: number;\n /** Maximum length of characters that can be input. */\n maxLength?: number;\n /**\n * Allows the user to resize the Text Area. This prop is ignored if autoResize is true.\n * @default false\n */\n resizable?: boolean;\n /**\n * Enables the Text Area to resize itself automatically.\n * @default true\n */\n autoResize?: boolean;\n /**\n * Display a live character count in relation to the maxLength.\n * @default false\n */\n displayCharCount?: boolean;\n /**\n * Allow or disallow a value beyond the maxLength.\n * @default true\n */\n hardStop?: boolean;\n\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n onFocus?: FocusEventHandler<HTMLTextAreaElement>;\n onBlur?: FocusEventHandler<HTMLTextAreaElement>;\n}\n\nconst warnCharCount = 30;\n\nconst TextArea: FC<TextAreaProps & ForwardProps> = forwardRef(function TextArea(\n props: PropsWithoutRef<TextAreaProps>,\n ref: Ref<HTMLTextAreaElement>\n) {\n const uid = useUID();\n const {\n testId,\n additionalInfo,\n id = uid,\n value,\n defaultValue,\n required = false,\n disabled = false,\n readOnly = false,\n label,\n labelHidden,\n info,\n status,\n resizable = false,\n autoResize = true,\n maxLength,\n displayCharCount = false,\n hardStop = true,\n onChange: onChangeProp,\n onResolveSuggestion,\n ...restProps\n } = props;\n const t = useI18n();\n\n const testIds = useTestIds(testId, getTextAreaTestIds);\n const [charCount, setCharCount] = useState(value?.length ?? defaultValue?.length ?? 0);\n const [focused, setFocused] = useState(false);\n const [textAreaEl, setTextAreaEl] = useElement<HTMLTextAreaElement>();\n const textAreaRef = useConsolidatedRef(ref, setTextAreaEl);\n const prevHeightRef = useRef(0);\n const focusTimeoutRef = useRef(NaN);\n const { announceAssertive } = useLiveLog();\n\n const controlProp: {\n value?: string;\n defaultValue?: string;\n } = {};\n\n // Conditionally render component as controlled/uncontrolled\n if (hasProp(props, 'value')) {\n controlProp.value = value ?? '';\n } else if (hasProp(props, 'defaultValue')) {\n controlProp.defaultValue = defaultValue ?? '';\n }\n\n const onChange = useCallback(\n (e: ChangeEvent<HTMLTextAreaElement>) => {\n if (maxLength !== undefined) {\n if (e.target.value.length >= maxLength) {\n announceAssertive({ message: t('text_area_character_limit'), type: 'warning' });\n } else if (maxLength > warnCharCount) {\n const prevCharsRemaining = maxLength - charCount;\n const charsRemaining = maxLength - e.target.value.length;\n\n if (charsRemaining < warnCharCount && prevCharsRemaining >= warnCharCount) {\n announceAssertive({\n message: t('text_area_characters_remaining', [`${warnCharCount}`]),\n type: 'warning'\n });\n }\n }\n }\n\n if (!hardStop || maxLength === undefined || e.target.value.length <= maxLength) {\n onChangeProp?.(e);\n setCharCount(e.target.value.length);\n }\n },\n [onChangeProp, charCount, hardStop, maxLength, announceAssertive, t]\n );\n\n const recalculateHeight = useCallback(() => {\n if (!textAreaRef.current) return;\n\n textAreaRef.current.style.setProperty('--textarea-height', 'auto');\n\n // Remove scrollbar width to avoid interference with calculation.\n textAreaRef.current.style.setProperty('scrollbar-width', 'none');\n\n const scrollHeight = textAreaRef.current.scrollHeight;\n const borderWidth = textAreaRef.current.offsetHeight - textAreaRef.current.clientHeight;\n // Set height to auto then scrollHeight + borderWidth to resize TextArea to content\n textAreaRef.current.style.setProperty('--textarea-height', `${scrollHeight + borderWidth}px`);\n\n textAreaRef.current.style.removeProperty('scrollbar-width');\n }, []);\n\n useEffect(() => {\n if (!textAreaRef.current) return;\n\n if (autoResize) {\n recalculateHeight();\n } else {\n textAreaRef.current.style.removeProperty('--textarea-height');\n }\n }, [value, autoResize, recalculateHeight]);\n\n // Recalculate height when the element becomes visible after being displayed none.\n useEffect(() => {\n if (!textAreaEl || !autoResize) return;\n\n prevHeightRef.current = textAreaEl.offsetHeight;\n\n const observer = new ResizeObserver(entries => {\n const currentHeight = entries[0].contentRect.height;\n if (prevHeightRef.current === 0 && currentHeight > 0) {\n recalculateHeight();\n }\n prevHeightRef.current = currentHeight;\n });\n\n observer.observe(textAreaEl);\n return () => observer.disconnect();\n }, [autoResize, recalculateHeight, textAreaEl]);\n\n useEffect(\n () => () => {\n clearTimeout(focusTimeoutRef.current);\n },\n []\n );\n\n const TextAreaControl = (\n <StyledFormControl\n data-testid={testIds.control}\n ref={textAreaRef}\n id={id}\n aria-describedby={\n // Remove when focused to prevent each change in character count from being announced.\n !focused && displayCharCount && typeof maxLength === 'number'\n ? `${id}-charCount`\n : undefined\n }\n required={required}\n disabled={disabled}\n status={status}\n readOnly={readOnly}\n autoResize={autoResize}\n resizable={autoResize ? false : resizable}\n maxLength={hardStop ? maxLength : undefined}\n hasSuggestion={status === 'pending' && !!onResolveSuggestion}\n {...controlProp}\n {...restProps}\n onChange={onChange}\n onFocus={(e: FocusEvent<HTMLTextAreaElement>) => {\n // Need to delay so screen readers will include the character count in announcement on initial focus.\n // Shorter delays did not seem to work.\n focusTimeoutRef.current = window.setTimeout(() => {\n setFocused(true);\n }, 250);\n\n restProps.onFocus?.(e);\n }}\n onBlur={(e: FocusEvent<HTMLTextAreaElement>) => {\n clearTimeout(focusTimeoutRef.current);\n setFocused(false);\n restProps.onBlur?.(e);\n }}\n as={StyledTextArea}\n />\n );\n\n return label || displayCharCount ? (\n <FormField\n testId={testIds}\n additionalInfo={additionalInfo}\n label={label}\n labelHidden={labelHidden}\n id={id}\n readOnly={readOnly}\n info={info}\n status={status}\n charLimitDisplay={\n displayCharCount && typeof maxLength === 'number' ? (\n <Text id={`${id}-charCount`} readOnly={readOnly} variant='secondary'>\n {maxLength >= 0 ? t('x_of_y', [charCount || '0', maxLength]) : charCount}{' '}\n <VisuallyHiddenText>{t('characters_typed')}</VisuallyHiddenText>\n </Text>\n ) : undefined\n }\n required={required}\n disabled={disabled}\n onResolveSuggestion={onResolveSuggestion}\n >\n {TextAreaControl}\n </FormField>\n ) : (\n TextAreaControl\n );\n});\n\nexport default withTestIds(TextArea, getTextAreaTestIds);\n"]}
|
package/lib/hooks/useI18n.d.ts
CHANGED
|
@@ -255,6 +255,7 @@ declare const useI18n: () => import("../i18n/translate").TranslationFunction<Rea
|
|
|
255
255
|
x_of_y: string;
|
|
256
256
|
n_more: string;
|
|
257
257
|
keypress_instruction: string;
|
|
258
|
+
text_area_characters_remaining: string;
|
|
258
259
|
text_area_character_limit: string;
|
|
259
260
|
preview_link_instruction: string;
|
|
260
261
|
polite_announcements: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useI18n.d.ts","sourceRoot":"","sources":["../../src/hooks/useI18n.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,QAAA,MAAM,OAAO
|
|
1
|
+
{"version":3,"file":"useI18n.d.ts","sourceRoot":"","sources":["../../src/hooks/useI18n.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,QAAA,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAGZ,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
package/lib/i18n/default.d.ts
CHANGED
|
@@ -251,6 +251,7 @@ declare const _default: {
|
|
|
251
251
|
x_of_y: string;
|
|
252
252
|
n_more: string;
|
|
253
253
|
keypress_instruction: string;
|
|
254
|
+
text_area_characters_remaining: string;
|
|
254
255
|
text_area_character_limit: string;
|
|
255
256
|
preview_link_instruction: string;
|
|
256
257
|
polite_announcements: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/i18n/default.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/i18n/default.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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ED
|
@@ -269,6 +269,7 @@ export default {
|
|
|
269
269
|
// {pkg}:{ComponentDir} entries
|
|
270
270
|
// -----------------------------------------------------------------------------
|
|
271
271
|
/* core:TextArea */
|
|
272
|
+
text_area_characters_remaining: 'Less than {0} characters remaining.',
|
|
272
273
|
text_area_character_limit: 'Maximum character limit reached.',
|
|
273
274
|
/* core:Link */
|
|
274
275
|
preview_link_instruction: 'Press {0} and p to open this link in a preview.',
|