@kokimoki/kit 1.0.2 → 1.2.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/index.d.ts +1 -0
- package/dist/index.js +19 -2
- package/dist/kokimoki-kit-plugin.d.ts +11 -1
- package/dist/kokimoki-kit-plugin.js +35 -10
- package/dist/preprocess-style.js +33 -16
- package/dist/schema-builder.d.ts +95 -0
- package/dist/schema-builder.js +166 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +4 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -1,2 +1,19 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./kokimoki-kit-plugin"), exports);
|
18
|
+
__exportStar(require("./preprocess-style"), exports);
|
19
|
+
__exportStar(require("./schema-builder"), exports);
|
@@ -1,2 +1,12 @@
|
|
1
1
|
import type { Plugin } from "vite";
|
2
|
-
|
2
|
+
import type { Form } from "./schema-builder";
|
3
|
+
export interface KokimokiKitConfig {
|
4
|
+
conceptId: string;
|
5
|
+
form: Form<any, any>;
|
6
|
+
deployCodes: {
|
7
|
+
name: string;
|
8
|
+
description: string;
|
9
|
+
clientContext: any;
|
10
|
+
}[];
|
11
|
+
}
|
12
|
+
export declare function kokimokiKitPlugin(config: KokimokiKitConfig): Plugin;
|
@@ -1,12 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.kokimokiKitPlugin = void 0;
|
7
|
+
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
8
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
9
|
+
const preprocess_style_1 = require("./preprocess-style");
|
10
|
+
const version_1 = require("./version");
|
11
|
+
function kokimokiKitPlugin(config) {
|
5
12
|
return {
|
6
13
|
name: "kokimoki-kit",
|
7
14
|
async transform(code, id) {
|
8
15
|
if (id.endsWith("kokimoki.style.css")) {
|
9
|
-
return preprocessStyle(code);
|
16
|
+
return (0, preprocess_style_1.preprocessStyle)(code);
|
10
17
|
}
|
11
18
|
return code;
|
12
19
|
},
|
@@ -42,7 +49,7 @@ export const kokimokiKitPlugin = () => {
|
|
42
49
|
}
|
43
50
|
// Ensure .kokimoki directory exists
|
44
51
|
try {
|
45
|
-
await
|
52
|
+
await promises_1.default.mkdir(".kokimoki");
|
46
53
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
47
54
|
}
|
48
55
|
catch (e) {
|
@@ -53,7 +60,7 @@ export const kokimokiKitPlugin = () => {
|
|
53
60
|
// Try to read the app id from the .kokimoki/app-id file
|
54
61
|
let appId;
|
55
62
|
try {
|
56
|
-
appId = await
|
63
|
+
appId = await promises_1.default.readFile(".kokimoki/app-id", "utf8");
|
57
64
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
58
65
|
}
|
59
66
|
catch (e) {
|
@@ -63,8 +70,8 @@ export const kokimokiKitPlugin = () => {
|
|
63
70
|
}
|
64
71
|
// If the app id doesn't exist, generate a new one
|
65
72
|
if (!appId) {
|
66
|
-
appId = new
|
67
|
-
await
|
73
|
+
appId = new bson_objectid_1.default().toHexString();
|
74
|
+
await promises_1.default.writeFile(".kokimoki/app-id", appId);
|
68
75
|
}
|
69
76
|
// Inject the app id into the index.html
|
70
77
|
html = html.replace("<head>", `<head>
|
@@ -74,11 +81,29 @@ export const kokimokiKitPlugin = () => {
|
|
74
81
|
"test": true,
|
75
82
|
"host": "y-wss.kokimoki.com",
|
76
83
|
"appId": "${appId}",
|
84
|
+
"configObject": ${JSON.stringify(config.form.value)},
|
77
85
|
"base": "/",
|
78
86
|
"assets": "/"
|
79
87
|
}
|
80
88
|
</script>`);
|
81
89
|
return html;
|
82
90
|
},
|
91
|
+
// write kokimoki metadata to .kokimoki directory
|
92
|
+
async generateBundle(_, _bundle) {
|
93
|
+
// write config
|
94
|
+
await promises_1.default.writeFile(".kokimoki/config.json", JSON.stringify({
|
95
|
+
kokimokiKitVersion: version_1.KOKIMOKI_KIT_VERSION,
|
96
|
+
conceptId: config.conceptId,
|
97
|
+
deployCodes: config.deployCodes,
|
98
|
+
build: "dist",
|
99
|
+
}, null, 2));
|
100
|
+
// write schema
|
101
|
+
const schema = JSON.stringify(config.form.schema, null, 2);
|
102
|
+
await promises_1.default.writeFile(".kokimoki/schema.json", schema);
|
103
|
+
// write scheme defaults
|
104
|
+
const defaultValue = JSON.stringify(config.form.value, null, 2);
|
105
|
+
await promises_1.default.writeFile(".kokimoki/schema-defaults.json", defaultValue);
|
106
|
+
},
|
83
107
|
};
|
84
|
-
}
|
108
|
+
}
|
109
|
+
exports.kokimokiKitPlugin = kokimokiKitPlugin;
|
package/dist/preprocess-style.js
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.preprocessStyle = exports.generatePalette = exports.generateA11yOnColor = exports.destringRgb = exports.handleStringColor = exports.calculateRatio = exports.getLuminance = exports.hexToTailwindRgbString = exports.revertReplaceForColorPickers = exports.rgbToHex = exports.hexToRgb = void 0;
|
7
|
+
const colornames_1 = __importDefault(require("colornames"));
|
8
|
+
const colorjs_io_1 = __importDefault(require("colorjs.io"));
|
3
9
|
// List of rgb tuple variable names (possibly temporary system to support color picker for these variables)
|
4
10
|
const rgbTupleVariableNames = [
|
5
11
|
"theme-font-color-base",
|
@@ -85,7 +91,7 @@ const rgbTupleVariableNames = [
|
|
85
91
|
"color-surface-800",
|
86
92
|
"color-surface-900",
|
87
93
|
];
|
88
|
-
|
94
|
+
function hexToRgb(hex) {
|
89
95
|
const sanitizedHex = hex.replace(/##/g, "#");
|
90
96
|
const colorParts = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(sanitizedHex);
|
91
97
|
if (!colorParts)
|
@@ -97,10 +103,12 @@ export function hexToRgb(hex) {
|
|
97
103
|
b: parseInt(b, 16),
|
98
104
|
};
|
99
105
|
}
|
100
|
-
|
106
|
+
exports.hexToRgb = hexToRgb;
|
107
|
+
function rgbToHex(r, g, b) {
|
101
108
|
const toHex = (c) => `0${c.toString(16)}`.slice(-2);
|
102
109
|
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
103
110
|
}
|
111
|
+
exports.rgbToHex = rgbToHex;
|
104
112
|
// export function replaceForColorPickers(code: string) {
|
105
113
|
// return code.replace(
|
106
114
|
// /--([a-z0-9-]+):\s*(\d+)\s+(\d+)\s+(\d+);/gi,
|
@@ -110,7 +118,7 @@ export function rgbToHex(r, g, b) {
|
|
110
118
|
// }
|
111
119
|
// );
|
112
120
|
// }
|
113
|
-
|
121
|
+
function revertReplaceForColorPickers(code) {
|
114
122
|
return code.replace(/--([a-z0-9-]+):(.*?);/gi, (match, name, value) => {
|
115
123
|
if (!rgbTupleVariableNames.includes(name))
|
116
124
|
return match;
|
@@ -128,7 +136,7 @@ export function revertReplaceForColorPickers(code) {
|
|
128
136
|
.map((x) => x.trim());
|
129
137
|
return `--${name}: ${r} ${g} ${b};`;
|
130
138
|
}
|
131
|
-
const hex =
|
139
|
+
const hex = (0, colornames_1.default)(value);
|
132
140
|
if (hex) {
|
133
141
|
const rgb = hexToRgb(hex);
|
134
142
|
if (rgb)
|
@@ -137,6 +145,7 @@ export function revertReplaceForColorPickers(code) {
|
|
137
145
|
return match;
|
138
146
|
});
|
139
147
|
}
|
148
|
+
exports.revertReplaceForColorPickers = revertReplaceForColorPickers;
|
140
149
|
function lighten(hex, intensity) {
|
141
150
|
const color = hexToRgb(`#${hex}`);
|
142
151
|
if (!color)
|
@@ -155,7 +164,7 @@ function darken(hex, intensity) {
|
|
155
164
|
const b = Math.round(color.b * intensity);
|
156
165
|
return rgbToHex(r, g, b);
|
157
166
|
}
|
158
|
-
|
167
|
+
function hexToTailwindRgbString(hex) {
|
159
168
|
const sanitizedHex = hex.replace(/##/g, "#");
|
160
169
|
const colorParts = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(sanitizedHex);
|
161
170
|
if (!colorParts)
|
@@ -163,7 +172,8 @@ export function hexToTailwindRgbString(hex) {
|
|
163
172
|
const [, r, g, b] = colorParts;
|
164
173
|
return `${parseInt(r, 16)} ${parseInt(g, 16)} ${parseInt(b, 16)}`;
|
165
174
|
}
|
166
|
-
|
175
|
+
exports.hexToTailwindRgbString = hexToTailwindRgbString;
|
176
|
+
function getLuminance(r, g, b) {
|
167
177
|
const { _r, _g, _b } = typeof r === "object"
|
168
178
|
? { _r: r.r, _g: r.g, _b: r.b }
|
169
179
|
: { _r: r, _g: g, _b: b }; // I'm not really happy with this ternary, but it works
|
@@ -176,7 +186,8 @@ export function getLuminance(r, g, b) {
|
|
176
186
|
});
|
177
187
|
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
|
178
188
|
}
|
179
|
-
|
189
|
+
exports.getLuminance = getLuminance;
|
190
|
+
function calculateRatio(luminance1, luminance2) {
|
180
191
|
const lum1 = typeof luminance1 === "string"
|
181
192
|
? getLuminance(handleStringColor(luminance1))
|
182
193
|
: luminance1;
|
@@ -189,7 +200,8 @@ export function calculateRatio(luminance1, luminance2) {
|
|
189
200
|
? (lum2 + 0.05) / (lum1 + 0.05)
|
190
201
|
: (lum1 + 0.05) / (lum2 + 0.05);
|
191
202
|
}
|
192
|
-
|
203
|
+
exports.calculateRatio = calculateRatio;
|
204
|
+
function handleStringColor(colorString, returnType = "rgb") {
|
193
205
|
// if it's a css variable
|
194
206
|
if (colorString.includes("--")) {
|
195
207
|
colorString = colorString.replace(/var\(|\)/g, ""); // grab just the variable name
|
@@ -212,6 +224,7 @@ export function handleStringColor(colorString, returnType = "rgb") {
|
|
212
224
|
}
|
213
225
|
return colorString;
|
214
226
|
}
|
227
|
+
exports.handleStringColor = handleStringColor;
|
215
228
|
function cssColorToHex(colorString) {
|
216
229
|
if (colorString.includes("#"))
|
217
230
|
return colorString;
|
@@ -223,12 +236,12 @@ function cssColorToHex(colorString) {
|
|
223
236
|
.map((x) => x.trim());
|
224
237
|
return rgbToHex(Number(r), Number(g), Number(b));
|
225
238
|
}
|
226
|
-
const hex =
|
239
|
+
const hex = (0, colornames_1.default)(colorString);
|
227
240
|
if (hex)
|
228
241
|
return hex;
|
229
242
|
return "#000000";
|
230
243
|
}
|
231
|
-
|
244
|
+
function destringRgb(rgbString) {
|
232
245
|
const rgb = rgbString.match(/(\d+),?\s*(\d+),?\s*(\d+)/); // matches "255, 255, 255" and "255 255 255"
|
233
246
|
if (!rgb)
|
234
247
|
throw new Error("Invalid RGB string!");
|
@@ -238,12 +251,14 @@ export function destringRgb(rgbString) {
|
|
238
251
|
b: parseInt(rgb[3], 10),
|
239
252
|
};
|
240
253
|
}
|
241
|
-
|
254
|
+
exports.destringRgb = destringRgb;
|
255
|
+
function generateA11yOnColor(hex) {
|
242
256
|
const black = calculateRatio(hex, "#000000");
|
243
257
|
const white = calculateRatio(hex, "#FFFFFF");
|
244
258
|
return black < white ? "0 0 0" : "255 255 255";
|
245
259
|
}
|
246
|
-
|
260
|
+
exports.generateA11yOnColor = generateA11yOnColor;
|
261
|
+
function generatePalette(baseColor) {
|
247
262
|
const hexValidation = new RegExp(/^#[0-9a-f]{6}$/i);
|
248
263
|
if (!hexValidation.test(baseColor))
|
249
264
|
baseColor = "#CCCCCC";
|
@@ -284,6 +299,7 @@ export function generatePalette(baseColor) {
|
|
284
299
|
});
|
285
300
|
return response;
|
286
301
|
}
|
302
|
+
exports.generatePalette = generatePalette;
|
287
303
|
function preprocessGfcThemeBlock(code) {
|
288
304
|
// Generate map of defined css variables
|
289
305
|
const cssVariableMap = {};
|
@@ -330,7 +346,7 @@ function preprocessDaisyThemeBlock(code) {
|
|
330
346
|
const variableRegex = /--(p|pc|b1|bc|b2|er|erc|su|suc|s|sc|a|ac):\s*(.*?);/gi;
|
331
347
|
return code.replace(variableRegex, (_, name, value) => {
|
332
348
|
try {
|
333
|
-
const oklch = new
|
349
|
+
const oklch = new colorjs_io_1.default(value).to("oklch");
|
334
350
|
const [l, c, h] = oklch.coords;
|
335
351
|
const lStr = (l * 100).toFixed(1);
|
336
352
|
const cStr = c.toFixed(3);
|
@@ -343,7 +359,7 @@ function preprocessDaisyThemeBlock(code) {
|
|
343
359
|
}
|
344
360
|
});
|
345
361
|
}
|
346
|
-
|
362
|
+
function preprocessStyle(code) {
|
347
363
|
// Find and replace [data-theme] block contents
|
348
364
|
const themeBlockRegex = /\[data-theme=(?:"|')?(gfc|gfc-theme|mac-theme|consensus-theme|daisy-light|daisy-dark)(?:"|')?\]\s*{([\s\S]*?)}/gi;
|
349
365
|
return code.replace(themeBlockRegex, (_, theme, block) => {
|
@@ -360,3 +376,4 @@ export function preprocessStyle(code) {
|
|
360
376
|
}
|
361
377
|
});
|
362
378
|
}
|
379
|
+
exports.preprocessStyle = preprocessStyle;
|
@@ -0,0 +1,95 @@
|
|
1
|
+
export interface FieldOptions {
|
2
|
+
label?: string;
|
3
|
+
}
|
4
|
+
export declare abstract class Field<T> {
|
5
|
+
readonly options: FieldOptions;
|
6
|
+
constructor(options: FieldOptions);
|
7
|
+
abstract get value(): T;
|
8
|
+
abstract get schema(): any;
|
9
|
+
}
|
10
|
+
export declare class BooleanField extends Field<boolean> {
|
11
|
+
value: boolean;
|
12
|
+
constructor(value: boolean, options?: FieldOptions);
|
13
|
+
get schema(): {
|
14
|
+
type: string;
|
15
|
+
default: boolean;
|
16
|
+
};
|
17
|
+
}
|
18
|
+
export declare class ConstField<T extends string> extends Field<string extends T ? never : T> {
|
19
|
+
value: string extends T ? never : T;
|
20
|
+
constructor(value: string extends T ? never : T, options?: FieldOptions);
|
21
|
+
get schema(): {
|
22
|
+
const: string extends T ? never : T;
|
23
|
+
};
|
24
|
+
}
|
25
|
+
export declare class ImageField extends Field<string> {
|
26
|
+
value: string;
|
27
|
+
constructor(value: string, options?: FieldOptions);
|
28
|
+
get schema(): {
|
29
|
+
type: string;
|
30
|
+
default: string;
|
31
|
+
};
|
32
|
+
}
|
33
|
+
export declare class TextField extends Field<string> {
|
34
|
+
value: string;
|
35
|
+
constructor(value: string, options?: FieldOptions);
|
36
|
+
get schema(): {
|
37
|
+
type: string;
|
38
|
+
default: string;
|
39
|
+
};
|
40
|
+
}
|
41
|
+
export declare class EnumField<T extends Record<string, string>> extends Field<keyof T> {
|
42
|
+
enumValues: T;
|
43
|
+
value: keyof T;
|
44
|
+
constructor(enumValues: T, value: keyof T, options?: FieldOptions);
|
45
|
+
get schema(): {
|
46
|
+
enum: string[];
|
47
|
+
};
|
48
|
+
}
|
49
|
+
export declare class IntegerField extends Field<number> {
|
50
|
+
value: number;
|
51
|
+
constructor(value: number, options?: FieldOptions);
|
52
|
+
get schema(): {
|
53
|
+
type: string;
|
54
|
+
default: number;
|
55
|
+
};
|
56
|
+
}
|
57
|
+
export declare class FloatField extends Field<number> {
|
58
|
+
value: number;
|
59
|
+
constructor(value: number, options?: FieldOptions);
|
60
|
+
get schema(): {
|
61
|
+
type: string;
|
62
|
+
default: number;
|
63
|
+
};
|
64
|
+
}
|
65
|
+
export declare class FormGroup<T extends Record<string, Field<any>>, O extends Record<string, Field<any>>> extends Field<{
|
66
|
+
[key in keyof T]: T[key]["value"];
|
67
|
+
} & Partial<{
|
68
|
+
[key in keyof O]: O[key]["value"];
|
69
|
+
}>> {
|
70
|
+
requiredFields: T;
|
71
|
+
optionalFields: O;
|
72
|
+
constructor(requiredFields: T, optionalFields?: O, options?: FieldOptions);
|
73
|
+
get value(): {
|
74
|
+
[key in keyof T]: T[key]["value"];
|
75
|
+
} & Partial<{
|
76
|
+
[key in keyof O]: O[key]["value"];
|
77
|
+
}>;
|
78
|
+
get schema(): {
|
79
|
+
type: string;
|
80
|
+
properties: any;
|
81
|
+
required: string[];
|
82
|
+
};
|
83
|
+
}
|
84
|
+
export declare class FormArray<T> extends Field<T[]> {
|
85
|
+
private factory;
|
86
|
+
value: Field<T>["value"][];
|
87
|
+
constructor(factory: () => Field<T>, value: Field<T>["value"][], options?: FieldOptions);
|
88
|
+
get schema(): {
|
89
|
+
type: string;
|
90
|
+
items: any;
|
91
|
+
default: T[];
|
92
|
+
};
|
93
|
+
}
|
94
|
+
export declare class Form<R extends Record<string, Field<any>>, O extends Record<string, Field<any>>> extends FormGroup<R, O> {
|
95
|
+
}
|
@@ -0,0 +1,166 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Form = exports.FormArray = exports.FormGroup = exports.FloatField = exports.IntegerField = exports.EnumField = exports.TextField = exports.ImageField = exports.ConstField = exports.BooleanField = exports.Field = void 0;
|
4
|
+
const defaultFieldOptions = {};
|
5
|
+
class Field {
|
6
|
+
options;
|
7
|
+
constructor(options) {
|
8
|
+
this.options = options;
|
9
|
+
}
|
10
|
+
}
|
11
|
+
exports.Field = Field;
|
12
|
+
class BooleanField extends Field {
|
13
|
+
value;
|
14
|
+
constructor(value, options = defaultFieldOptions) {
|
15
|
+
super(options);
|
16
|
+
this.value = value;
|
17
|
+
}
|
18
|
+
get schema() {
|
19
|
+
return {
|
20
|
+
type: "boolean",
|
21
|
+
default: this.value,
|
22
|
+
};
|
23
|
+
}
|
24
|
+
}
|
25
|
+
exports.BooleanField = BooleanField;
|
26
|
+
class ConstField extends Field {
|
27
|
+
value;
|
28
|
+
constructor(value, options = defaultFieldOptions) {
|
29
|
+
super(options);
|
30
|
+
this.value = value;
|
31
|
+
}
|
32
|
+
get schema() {
|
33
|
+
return {
|
34
|
+
const: this.value,
|
35
|
+
};
|
36
|
+
}
|
37
|
+
}
|
38
|
+
exports.ConstField = ConstField;
|
39
|
+
class ImageField extends Field {
|
40
|
+
value;
|
41
|
+
constructor(value, options = defaultFieldOptions) {
|
42
|
+
super(options);
|
43
|
+
this.value = value;
|
44
|
+
}
|
45
|
+
get schema() {
|
46
|
+
return {
|
47
|
+
type: "string",
|
48
|
+
default: this.value,
|
49
|
+
};
|
50
|
+
}
|
51
|
+
}
|
52
|
+
exports.ImageField = ImageField;
|
53
|
+
class TextField extends Field {
|
54
|
+
value;
|
55
|
+
constructor(value, options = defaultFieldOptions) {
|
56
|
+
super(options);
|
57
|
+
this.value = value;
|
58
|
+
}
|
59
|
+
get schema() {
|
60
|
+
return {
|
61
|
+
type: "string",
|
62
|
+
default: this.value,
|
63
|
+
};
|
64
|
+
}
|
65
|
+
}
|
66
|
+
exports.TextField = TextField;
|
67
|
+
class EnumField extends Field {
|
68
|
+
enumValues;
|
69
|
+
value;
|
70
|
+
constructor(enumValues, value, options = defaultFieldOptions) {
|
71
|
+
super(options);
|
72
|
+
this.enumValues = enumValues;
|
73
|
+
this.value = value;
|
74
|
+
}
|
75
|
+
get schema() {
|
76
|
+
return {
|
77
|
+
enum: Object.keys(this.enumValues),
|
78
|
+
};
|
79
|
+
}
|
80
|
+
}
|
81
|
+
exports.EnumField = EnumField;
|
82
|
+
class IntegerField extends Field {
|
83
|
+
value;
|
84
|
+
constructor(value, options = defaultFieldOptions) {
|
85
|
+
super(options);
|
86
|
+
this.value = value;
|
87
|
+
}
|
88
|
+
get schema() {
|
89
|
+
return {
|
90
|
+
type: "integer",
|
91
|
+
default: this.value,
|
92
|
+
};
|
93
|
+
}
|
94
|
+
}
|
95
|
+
exports.IntegerField = IntegerField;
|
96
|
+
class FloatField extends Field {
|
97
|
+
value;
|
98
|
+
constructor(value, options = defaultFieldOptions) {
|
99
|
+
super(options);
|
100
|
+
this.value = value;
|
101
|
+
}
|
102
|
+
get schema() {
|
103
|
+
return {
|
104
|
+
type: "number",
|
105
|
+
default: this.value,
|
106
|
+
};
|
107
|
+
}
|
108
|
+
}
|
109
|
+
exports.FloatField = FloatField;
|
110
|
+
class FormGroup extends Field {
|
111
|
+
requiredFields;
|
112
|
+
optionalFields;
|
113
|
+
constructor(requiredFields, optionalFields = {}, options = defaultFieldOptions) {
|
114
|
+
super(options);
|
115
|
+
this.requiredFields = requiredFields;
|
116
|
+
this.optionalFields = optionalFields;
|
117
|
+
}
|
118
|
+
get value() {
|
119
|
+
const value = Object.entries(this.requiredFields).reduce((acc, [key, field]) => {
|
120
|
+
acc[key] = field.value;
|
121
|
+
return acc;
|
122
|
+
}, {});
|
123
|
+
Object.entries(this.optionalFields).forEach(([key, field]) => {
|
124
|
+
if (field.value !== undefined) {
|
125
|
+
value[key] = field.value;
|
126
|
+
}
|
127
|
+
});
|
128
|
+
return value;
|
129
|
+
}
|
130
|
+
get schema() {
|
131
|
+
const properties = {};
|
132
|
+
Object.entries(this.requiredFields).forEach(([key, field]) => {
|
133
|
+
properties[key] = field.schema;
|
134
|
+
});
|
135
|
+
Object.entries(this.optionalFields).forEach(([key, field]) => {
|
136
|
+
properties[key] = field.schema;
|
137
|
+
});
|
138
|
+
return {
|
139
|
+
type: "object",
|
140
|
+
properties,
|
141
|
+
required: Object.keys(this.requiredFields),
|
142
|
+
};
|
143
|
+
}
|
144
|
+
}
|
145
|
+
exports.FormGroup = FormGroup;
|
146
|
+
class FormArray extends Field {
|
147
|
+
factory;
|
148
|
+
value;
|
149
|
+
constructor(factory, value, options = defaultFieldOptions) {
|
150
|
+
super(options);
|
151
|
+
this.factory = factory;
|
152
|
+
this.value = value;
|
153
|
+
}
|
154
|
+
get schema() {
|
155
|
+
const field = this.factory();
|
156
|
+
return {
|
157
|
+
type: "array",
|
158
|
+
items: field.schema,
|
159
|
+
default: this.value,
|
160
|
+
};
|
161
|
+
}
|
162
|
+
}
|
163
|
+
exports.FormArray = FormArray;
|
164
|
+
class Form extends FormGroup {
|
165
|
+
}
|
166
|
+
exports.Form = Form;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const KOKIMOKI_KIT_VERSION = "1.2.0";
|
package/dist/version.js
ADDED
package/package.json
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@kokimoki/kit",
|
3
|
-
"version": "1.0
|
3
|
+
"version": "1.2.0",
|
4
4
|
"description": "",
|
5
|
-
"type": "module",
|
6
5
|
"main": "dist/index.js",
|
7
6
|
"types": "dist/index.d.ts",
|
8
7
|
"files": [
|
@@ -10,6 +9,7 @@
|
|
10
9
|
],
|
11
10
|
"scripts": {
|
12
11
|
"test": "echo \"Error: no test specified\" && exit 1",
|
12
|
+
"prebuild": "node -p \"'export const KOKIMOKI_KIT_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
|
13
13
|
"build": "tsc"
|
14
14
|
},
|
15
15
|
"author": "Loquiz OÜ",
|