@nixxie-cms/fields-rating 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 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-rating
2
+
3
+ A rating field for Nixxie CMS (e.g. 0–5 stars). Built on the core `integer` field with a
4
+ constrained range.
5
+
6
+ ```ts
7
+ import { rating } from '@nixxie-cms/fields-rating'
8
+
9
+ fields: {
10
+ score: rating({ max: 5 }),
11
+ }
12
+ ```
@@ -0,0 +1,17 @@
1
+ import type { IntegerFieldConfig } from '@nixxie-cms/core/fields';
2
+ import type { BaseListTypeInfo, FieldTypeFunc } from '@nixxie-cms/core/types';
3
+ export type RatingFieldConfig<ListTypeInfo extends BaseListTypeInfo> = Omit<IntegerFieldConfig<ListTypeInfo>, 'validation' | 'defaultValue'> & {
4
+ /** Highest allowed rating. Default: 5 */
5
+ max?: number;
6
+ /** Lowest allowed rating. Default: 0 */
7
+ min?: number;
8
+ defaultValue?: number | null;
9
+ validation?: {
10
+ isRequired?: boolean;
11
+ };
12
+ };
13
+ /**
14
+ * A rating field (e.g. 0–5 stars). Built on the core `integer` field with a constrained range.
15
+ */
16
+ export declare function rating<ListTypeInfo extends BaseListTypeInfo>(config?: RatingFieldConfig<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,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAE7E,MAAM,MAAM,iBAAiB,CAAC,YAAY,SAAS,gBAAgB,IAAI,IAAI,CACzE,kBAAkB,CAAC,YAAY,CAAC,EAChC,YAAY,GAAG,cAAc,CAC9B,GAAG;IACF,yCAAyC;IACzC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,wCAAwC;IACxC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,UAAU,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CACtC,CAAA;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,YAAY,SAAS,gBAAgB,EAC1D,MAAM,GAAE,iBAAiB,CAAC,YAAY,CAAM,GAC3C,aAAa,CAAC,YAAY,CAAC,CAS7B"}
@@ -0,0 +1,2 @@
1
+ export * from "./declarations/src/index.js";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibml4eGllLWNtcy1maWVsZHMtcmF0aW5nLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi9kZWNsYXJhdGlvbnMvc3JjL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var fields = require('@nixxie-cms/core/fields');
6
+
7
+ /**
8
+ * A rating field (e.g. 0–5 stars). Built on the core `integer` field with a constrained range.
9
+ */
10
+ function rating(config = {}) {
11
+ const {
12
+ max = 5,
13
+ min = 0,
14
+ defaultValue,
15
+ validation,
16
+ ...rest
17
+ } = config;
18
+ return fields.integer({
19
+ ...rest,
20
+ defaultValue: defaultValue !== null && defaultValue !== void 0 ? defaultValue : null,
21
+ validation: {
22
+ isRequired: validation === null || validation === void 0 ? void 0 : validation.isRequired,
23
+ min,
24
+ max
25
+ },
26
+ ui: {
27
+ description: `A rating from ${min} to ${max}`,
28
+ ...rest.ui
29
+ }
30
+ });
31
+ }
32
+
33
+ exports.rating = rating;
@@ -0,0 +1,29 @@
1
+ import { integer } from '@nixxie-cms/core/fields';
2
+
3
+ /**
4
+ * A rating field (e.g. 0–5 stars). Built on the core `integer` field with a constrained range.
5
+ */
6
+ function rating(config = {}) {
7
+ const {
8
+ max = 5,
9
+ min = 0,
10
+ defaultValue,
11
+ validation,
12
+ ...rest
13
+ } = config;
14
+ return integer({
15
+ ...rest,
16
+ defaultValue: defaultValue !== null && defaultValue !== void 0 ? defaultValue : null,
17
+ validation: {
18
+ isRequired: validation === null || validation === void 0 ? void 0 : validation.isRequired,
19
+ min,
20
+ max
21
+ },
22
+ ui: {
23
+ description: `A rating from ${min} to ${max}`,
24
+ ...rest.ui
25
+ }
26
+ });
27
+ }
28
+
29
+ export { rating };
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@nixxie-cms/fields-rating",
3
+ "version": "1.0.1",
4
+ "license": "MIT",
5
+ "main": "dist/nixxie-cms-fields-rating.cjs.js",
6
+ "module": "dist/nixxie-cms-fields-rating.esm.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/nixxie-cms-fields-rating.cjs.js",
10
+ "module": "./dist/nixxie-cms-fields-rating.esm.js",
11
+ "default": "./dist/nixxie-cms-fields-rating.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-rating"
32
+ }
33
+ }
package/src/index.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { integer } from '@nixxie-cms/core/fields'
2
+ import type { IntegerFieldConfig } from '@nixxie-cms/core/fields'
3
+ import type { BaseListTypeInfo, FieldTypeFunc } from '@nixxie-cms/core/types'
4
+
5
+ export type RatingFieldConfig<ListTypeInfo extends BaseListTypeInfo> = Omit<
6
+ IntegerFieldConfig<ListTypeInfo>,
7
+ 'validation' | 'defaultValue'
8
+ > & {
9
+ /** Highest allowed rating. Default: 5 */
10
+ max?: number
11
+ /** Lowest allowed rating. Default: 0 */
12
+ min?: number
13
+ defaultValue?: number | null
14
+ validation?: { isRequired?: boolean }
15
+ }
16
+
17
+ /**
18
+ * A rating field (e.g. 0–5 stars). Built on the core `integer` field with a constrained range.
19
+ */
20
+ export function rating<ListTypeInfo extends BaseListTypeInfo>(
21
+ config: RatingFieldConfig<ListTypeInfo> = {}
22
+ ): FieldTypeFunc<ListTypeInfo> {
23
+ const { max = 5, min = 0, defaultValue, validation, ...rest } = config
24
+
25
+ return integer<ListTypeInfo>({
26
+ ...(rest as IntegerFieldConfig<ListTypeInfo>),
27
+ defaultValue: defaultValue ?? null,
28
+ validation: { isRequired: validation?.isRequired, min, max },
29
+ ui: { description: `A rating from ${min} to ${max}`, ...rest.ui },
30
+ })
31
+ }