@nixxie-cms/fields-location 1.0.1
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/LICENSE +23 -0
- package/README.md +12 -0
- package/dist/declarations/src/index.d.ts +17 -0
- package/dist/declarations/src/index.d.ts.map +1 -0
- package/dist/nixxie-cms-fields-location.cjs.d.ts +2 -0
- package/dist/nixxie-cms-fields-location.cjs.js +47 -0
- package/dist/nixxie-cms-fields-location.esm.js +43 -0
- package/package.json +33 -0
- package/src/index.ts +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nixxie International DMCC
|
|
4
|
+
Portions Copyright (c) 2023 Thinkmill Labs Pty Ltd and contributors
|
|
5
|
+
(this software is derived from the KeystoneJS project, https://keystonejs.com)
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @nixxie-cms/fields-location
|
|
2
|
+
|
|
3
|
+
A geolocation field for Nixxie CMS. Stores `{ lat, lng, label? }` as JSON and validates coordinate
|
|
4
|
+
ranges.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { location } from '@nixxie-cms/fields-location'
|
|
8
|
+
|
|
9
|
+
fields: {
|
|
10
|
+
position: location({ validation: { isRequired: true } }),
|
|
11
|
+
}
|
|
12
|
+
```
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { JsonFieldConfig } from '@nixxie-cms/core/fields';
|
|
2
|
+
import type { BaseListTypeInfo, FieldTypeFunc } from '@nixxie-cms/core/types';
|
|
3
|
+
export type LatLng = {
|
|
4
|
+
lat: number;
|
|
5
|
+
lng: number;
|
|
6
|
+
label?: string;
|
|
7
|
+
};
|
|
8
|
+
export type LocationFieldConfig<ListTypeInfo extends BaseListTypeInfo> = Omit<JsonFieldConfig<ListTypeInfo>, 'defaultValue'> & {
|
|
9
|
+
validation?: {
|
|
10
|
+
isRequired?: boolean;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A geolocation field storing `{ lat, lng, label? }` as JSON. Validates latitude/longitude ranges.
|
|
15
|
+
*/
|
|
16
|
+
export declare function location<ListTypeInfo extends BaseListTypeInfo>(config?: LocationFieldConfig<ListTypeInfo>): FieldTypeFunc<ListTypeInfo>;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAE7E,MAAM,MAAM,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAEjE,MAAM,MAAM,mBAAmB,CAAC,YAAY,SAAS,gBAAgB,IAAI,IAAI,CAC3E,eAAe,CAAC,YAAY,CAAC,EAC7B,cAAc,CACf,GAAG;IACF,UAAU,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CACtC,CAAA;AAeD;;GAEG;AACH,wBAAgB,QAAQ,CAAC,YAAY,SAAS,gBAAgB,EAC5D,MAAM,GAAE,mBAAmB,CAAC,YAAY,CAAM,GAC7C,aAAa,CAAC,YAAY,CAAC,CAuB7B"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export * from "./declarations/src/index.js";
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibml4eGllLWNtcy1maWVsZHMtbG9jYXRpb24uY2pzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuL2RlY2xhcmF0aW9ucy9zcmMvaW5kZXguZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var fields = require('@nixxie-cms/core/fields');
|
|
6
|
+
|
|
7
|
+
function isValidLatLng(v) {
|
|
8
|
+
return v && typeof v === 'object' && typeof v.lat === 'number' && typeof v.lng === 'number' && v.lat >= -90 && v.lat <= 90 && v.lng >= -180 && v.lng <= 180;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A geolocation field storing `{ lat, lng, label? }` as JSON. Validates latitude/longitude ranges.
|
|
13
|
+
*/
|
|
14
|
+
function location(config = {}) {
|
|
15
|
+
const {
|
|
16
|
+
validation,
|
|
17
|
+
hooks,
|
|
18
|
+
...rest
|
|
19
|
+
} = config;
|
|
20
|
+
return fields.json({
|
|
21
|
+
...rest,
|
|
22
|
+
defaultValue: null,
|
|
23
|
+
hooks: {
|
|
24
|
+
...hooks,
|
|
25
|
+
validate: args => {
|
|
26
|
+
const {
|
|
27
|
+
resolvedData,
|
|
28
|
+
fieldKey,
|
|
29
|
+
addValidationError,
|
|
30
|
+
operation
|
|
31
|
+
} = args;
|
|
32
|
+
if (operation === 'delete') return;
|
|
33
|
+
const value = resolvedData[fieldKey];
|
|
34
|
+
if (value === undefined) return;
|
|
35
|
+
if (value === null) {
|
|
36
|
+
if (validation !== null && validation !== void 0 && validation.isRequired) addValidationError(`${fieldKey} is required`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (!isValidLatLng(value)) {
|
|
40
|
+
addValidationError(`${fieldKey} must be { lat, lng } with valid coordinates`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
exports.location = location;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { json } from '@nixxie-cms/core/fields';
|
|
2
|
+
|
|
3
|
+
function isValidLatLng(v) {
|
|
4
|
+
return v && typeof v === 'object' && typeof v.lat === 'number' && typeof v.lng === 'number' && v.lat >= -90 && v.lat <= 90 && v.lng >= -180 && v.lng <= 180;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A geolocation field storing `{ lat, lng, label? }` as JSON. Validates latitude/longitude ranges.
|
|
9
|
+
*/
|
|
10
|
+
function location(config = {}) {
|
|
11
|
+
const {
|
|
12
|
+
validation,
|
|
13
|
+
hooks,
|
|
14
|
+
...rest
|
|
15
|
+
} = config;
|
|
16
|
+
return json({
|
|
17
|
+
...rest,
|
|
18
|
+
defaultValue: null,
|
|
19
|
+
hooks: {
|
|
20
|
+
...hooks,
|
|
21
|
+
validate: args => {
|
|
22
|
+
const {
|
|
23
|
+
resolvedData,
|
|
24
|
+
fieldKey,
|
|
25
|
+
addValidationError,
|
|
26
|
+
operation
|
|
27
|
+
} = args;
|
|
28
|
+
if (operation === 'delete') return;
|
|
29
|
+
const value = resolvedData[fieldKey];
|
|
30
|
+
if (value === undefined) return;
|
|
31
|
+
if (value === null) {
|
|
32
|
+
if (validation !== null && validation !== void 0 && validation.isRequired) addValidationError(`${fieldKey} is required`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!isValidLatLng(value)) {
|
|
36
|
+
addValidationError(`${fieldKey} must be { lat, lng } with valid coordinates`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { location };
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nixxie-cms/fields-location",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "dist/nixxie-cms-fields-location.cjs.js",
|
|
6
|
+
"module": "dist/nixxie-cms-fields-location.esm.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/nixxie-cms-fields-location.cjs.js",
|
|
10
|
+
"module": "./dist/nixxie-cms-fields-location.esm.js",
|
|
11
|
+
"default": "./dist/nixxie-cms-fields-location.cjs.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@babel/runtime": "^7.24.7"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@nixxie-cms/core": "^1.0.1"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@nixxie-cms/core": "^1.0.1"
|
|
23
|
+
},
|
|
24
|
+
"preconstruct": {
|
|
25
|
+
"entrypoints": [
|
|
26
|
+
"index.ts"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/nixxiecms/nixxie/tree/main/packages/fields-location"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { json } from '@nixxie-cms/core/fields'
|
|
2
|
+
import type { JsonFieldConfig } from '@nixxie-cms/core/fields'
|
|
3
|
+
import type { BaseListTypeInfo, FieldTypeFunc } from '@nixxie-cms/core/types'
|
|
4
|
+
|
|
5
|
+
export type LatLng = { lat: number; lng: number; label?: string }
|
|
6
|
+
|
|
7
|
+
export type LocationFieldConfig<ListTypeInfo extends BaseListTypeInfo> = Omit<
|
|
8
|
+
JsonFieldConfig<ListTypeInfo>,
|
|
9
|
+
'defaultValue'
|
|
10
|
+
> & {
|
|
11
|
+
validation?: { isRequired?: boolean }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function isValidLatLng(v: any): v is LatLng {
|
|
15
|
+
return (
|
|
16
|
+
v &&
|
|
17
|
+
typeof v === 'object' &&
|
|
18
|
+
typeof v.lat === 'number' &&
|
|
19
|
+
typeof v.lng === 'number' &&
|
|
20
|
+
v.lat >= -90 &&
|
|
21
|
+
v.lat <= 90 &&
|
|
22
|
+
v.lng >= -180 &&
|
|
23
|
+
v.lng <= 180
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A geolocation field storing `{ lat, lng, label? }` as JSON. Validates latitude/longitude ranges.
|
|
29
|
+
*/
|
|
30
|
+
export function location<ListTypeInfo extends BaseListTypeInfo>(
|
|
31
|
+
config: LocationFieldConfig<ListTypeInfo> = {}
|
|
32
|
+
): FieldTypeFunc<ListTypeInfo> {
|
|
33
|
+
const { validation, hooks, ...rest } = config
|
|
34
|
+
|
|
35
|
+
return json<ListTypeInfo>({
|
|
36
|
+
...(rest as JsonFieldConfig<ListTypeInfo>),
|
|
37
|
+
defaultValue: null,
|
|
38
|
+
hooks: {
|
|
39
|
+
...hooks,
|
|
40
|
+
validate: (args: any) => {
|
|
41
|
+
const { resolvedData, fieldKey, addValidationError, operation } = args
|
|
42
|
+
if (operation === 'delete') return
|
|
43
|
+
const value = resolvedData[fieldKey]
|
|
44
|
+
if (value === undefined) return
|
|
45
|
+
if (value === null) {
|
|
46
|
+
if (validation?.isRequired) addValidationError(`${fieldKey} is required`)
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
if (!isValidLatLng(value)) {
|
|
50
|
+
addValidationError(`${fieldKey} must be { lat, lng } with valid coordinates`)
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
}
|