@kokimoki/kit 1.8.0 → 1.8.2
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/README.md +1 -1
- package/dist/api.js +6 -6
- package/dist/credentials.js +3 -4
- package/dist/dev-app.js +8 -9
- package/dist/dev-frame/render-dev-frame.js +1 -2
- package/dist/dev-i18n.js +4 -5
- package/dist/dev-overlays.js +3 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -2
- package/dist/kokimoki-kit-plugin.d.ts +1 -0
- package/dist/kokimoki-kit-plugin.js +21 -9
- package/dist/preprocess-style.js +11 -12
- package/dist/production-loading-screen.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/kokimoki-kit.instructions.md +102 -96
- package/package.json +6 -2
- package/dist/schema-builder.d.ts +0 -110
- package/dist/schema-builder.js +0 -183
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Add the plugin to your `vite.config.ts`:
|
|
|
15
15
|
```typescript
|
|
16
16
|
import { defineConfig } from "vite";
|
|
17
17
|
import { kokimokiKitPlugin } from "@kokimoki/kit";
|
|
18
|
-
import { z } from "@kokimoki/
|
|
18
|
+
import { z } from "@kokimoki/app";
|
|
19
19
|
|
|
20
20
|
export default defineConfig({
|
|
21
21
|
plugins: [
|
package/dist/api.js
CHANGED
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
* Shared between @kokimoki/cli and @kokimoki/kit
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.DEFAULT_ENDPOINT = void 0;
|
|
8
|
+
exports.createConcept = createConcept;
|
|
9
|
+
exports.getOrganization = getOrganization;
|
|
10
|
+
exports.getConceptOrganization = getConceptOrganization;
|
|
11
|
+
exports.createBuild = createBuild;
|
|
12
|
+
exports.getDeployUrl = getDeployUrl;
|
|
8
13
|
exports.DEFAULT_ENDPOINT = "https://api.kokimoki.com";
|
|
9
14
|
/**
|
|
10
15
|
* Make a request to the Kokimoki API
|
|
@@ -34,7 +39,6 @@ async function createConcept(options, request) {
|
|
|
34
39
|
body: JSON.stringify(request),
|
|
35
40
|
});
|
|
36
41
|
}
|
|
37
|
-
exports.createConcept = createConcept;
|
|
38
42
|
/**
|
|
39
43
|
* Get organization details via the Kokimoki API
|
|
40
44
|
* Used for authentication validation
|
|
@@ -42,7 +46,6 @@ exports.createConcept = createConcept;
|
|
|
42
46
|
async function getOrganization(endpoint, apiKey) {
|
|
43
47
|
return kokimokiApiRequest("/auth", { endpoint, apiKey }, { method: "GET" });
|
|
44
48
|
}
|
|
45
|
-
exports.getOrganization = getOrganization;
|
|
46
49
|
/**
|
|
47
50
|
* Get the organization that owns a concept (by concept ID)
|
|
48
51
|
*/
|
|
@@ -60,7 +63,6 @@ async function getConceptOrganization(endpoint, conceptId) {
|
|
|
60
63
|
}
|
|
61
64
|
return await res.json();
|
|
62
65
|
}
|
|
63
|
-
exports.getConceptOrganization = getConceptOrganization;
|
|
64
66
|
/**
|
|
65
67
|
* Create a new build via the Kokimoki API
|
|
66
68
|
*/
|
|
@@ -73,7 +75,6 @@ async function createBuild(options, request, cliVersion) {
|
|
|
73
75
|
body: JSON.stringify(request),
|
|
74
76
|
});
|
|
75
77
|
}
|
|
76
|
-
exports.createBuild = createBuild;
|
|
77
78
|
/**
|
|
78
79
|
* Get the deploy URL for a build
|
|
79
80
|
*/
|
|
@@ -92,4 +93,3 @@ async function getDeployUrl(endpoint, apiKey, buildId) {
|
|
|
92
93
|
}
|
|
93
94
|
return await res.json();
|
|
94
95
|
}
|
|
95
|
-
exports.getDeployUrl = getDeployUrl;
|
package/dist/credentials.js
CHANGED
|
@@ -7,7 +7,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7
7
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.
|
|
10
|
+
exports.getCredentialsPath = getCredentialsPath;
|
|
11
|
+
exports.readCredentials = readCredentials;
|
|
12
|
+
exports.writeCredentials = writeCredentials;
|
|
11
13
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
12
14
|
const os_1 = require("os");
|
|
13
15
|
const path_1 = __importDefault(require("path"));
|
|
@@ -17,7 +19,6 @@ const path_1 = __importDefault(require("path"));
|
|
|
17
19
|
function getCredentialsPath() {
|
|
18
20
|
return path_1.default.join((0, os_1.homedir)(), ".kokimoki");
|
|
19
21
|
}
|
|
20
|
-
exports.getCredentialsPath = getCredentialsPath;
|
|
21
22
|
/**
|
|
22
23
|
* Read credentials from the ~/.kokimoki file
|
|
23
24
|
*/
|
|
@@ -34,7 +35,6 @@ async function readCredentials() {
|
|
|
34
35
|
throw e;
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
|
-
exports.readCredentials = readCredentials;
|
|
38
38
|
/**
|
|
39
39
|
* Write credentials to the ~/.kokimoki file
|
|
40
40
|
*/
|
|
@@ -42,4 +42,3 @@ async function writeCredentials(credentials) {
|
|
|
42
42
|
const credentialsPath = getCredentialsPath();
|
|
43
43
|
await promises_1.default.writeFile(credentialsPath, JSON.stringify(credentials, null, 2));
|
|
44
44
|
}
|
|
45
|
-
exports.writeCredentials = writeCredentials;
|
package/dist/dev-app.js
CHANGED
|
@@ -3,9 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
|
|
6
|
+
exports.deleteAppId = deleteAppId;
|
|
7
|
+
exports.setDevAppI18n = setDevAppI18n;
|
|
8
|
+
exports.setDevAppTranslation = setDevAppTranslation;
|
|
9
|
+
exports.computeStoresHash = computeStoresHash;
|
|
10
|
+
exports.readStoresHash = readStoresHash;
|
|
11
|
+
exports.writeStoresHash = writeStoresHash;
|
|
12
|
+
exports.getOrCreateDevApp = getOrCreateDevApp;
|
|
8
13
|
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
14
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
9
15
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
10
16
|
const path_1 = __importDefault(require("path"));
|
|
11
17
|
const api_1 = require("./api");
|
|
@@ -102,7 +108,6 @@ async function deleteAppId() {
|
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
110
|
}
|
|
105
|
-
exports.deleteAppId = deleteAppId;
|
|
106
111
|
/**
|
|
107
112
|
* Set i18n metadata for a dev app
|
|
108
113
|
*/
|
|
@@ -121,7 +126,6 @@ async function setDevAppI18n(endpoint, apiKey, appId, i18nMeta) {
|
|
|
121
126
|
throw new Error(`Failed to set dev app i18n: ${res.status} ${errorText}`);
|
|
122
127
|
}
|
|
123
128
|
}
|
|
124
|
-
exports.setDevAppI18n = setDevAppI18n;
|
|
125
129
|
/**
|
|
126
130
|
* Set translations for a specific language and namespace in a dev app
|
|
127
131
|
*/
|
|
@@ -140,7 +144,6 @@ async function setDevAppTranslation(endpoint, apiKey, appId, lng, namespace, tra
|
|
|
140
144
|
throw new Error(`Failed to set dev app translation: ${res.status} ${errorText}`);
|
|
141
145
|
}
|
|
142
146
|
}
|
|
143
|
-
exports.setDevAppTranslation = setDevAppTranslation;
|
|
144
147
|
/**
|
|
145
148
|
* Compute a hash of the stores configuration
|
|
146
149
|
*/
|
|
@@ -148,7 +151,6 @@ function computeStoresHash(stores) {
|
|
|
148
151
|
const content = JSON.stringify(stores ?? []);
|
|
149
152
|
return crypto_1.default.createHash("sha256").update(content).digest("hex").slice(0, 16);
|
|
150
153
|
}
|
|
151
|
-
exports.computeStoresHash = computeStoresHash;
|
|
152
154
|
/**
|
|
153
155
|
* Read the stored stores hash from .kokimoki/stores-hash
|
|
154
156
|
*/
|
|
@@ -164,7 +166,6 @@ async function readStoresHash() {
|
|
|
164
166
|
throw e;
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
|
-
exports.readStoresHash = readStoresHash;
|
|
168
169
|
/**
|
|
169
170
|
* Write the stores hash to .kokimoki/stores-hash
|
|
170
171
|
*/
|
|
@@ -172,7 +173,6 @@ async function writeStoresHash(hash) {
|
|
|
172
173
|
await ensureKokimokiDir();
|
|
173
174
|
await promises_1.default.writeFile(path_1.default.join(KOKIMOKI_DIR, STORES_HASH_FILE), hash);
|
|
174
175
|
}
|
|
175
|
-
exports.writeStoresHash = writeStoresHash;
|
|
176
176
|
/**
|
|
177
177
|
* Get or create a dev app for local development.
|
|
178
178
|
*
|
|
@@ -269,4 +269,3 @@ async function getOrCreateDevApp(config) {
|
|
|
269
269
|
};
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
|
-
exports.getOrCreateDevApp = getOrCreateDevApp;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Renders the dev frame HTML page - a multi-window view for development
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.renderDevFrame =
|
|
6
|
+
exports.renderDevFrame = renderDevFrame;
|
|
7
7
|
const styles_1 = require("./styles");
|
|
8
8
|
/**
|
|
9
9
|
* Generate URL for a dev frame iframe
|
|
@@ -186,4 +186,3 @@ function renderDevFrame(config) {
|
|
|
186
186
|
</body>
|
|
187
187
|
</html>`;
|
|
188
188
|
}
|
|
189
|
-
exports.renderDevFrame = renderDevFrame;
|
package/dist/dev-i18n.js
CHANGED
|
@@ -3,7 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.loadI18nFromPath = loadI18nFromPath;
|
|
7
|
+
exports.getI18nMeta = getI18nMeta;
|
|
8
|
+
exports.syncAllI18nToDevApp = syncAllI18nToDevApp;
|
|
9
|
+
exports.syncI18nFile = syncI18nFile;
|
|
7
10
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
8
11
|
const path_1 = __importDefault(require("path"));
|
|
9
12
|
const dev_app_1 = require("./dev-app");
|
|
@@ -38,7 +41,6 @@ async function loadI18nFromPath(i18nPath) {
|
|
|
38
41
|
}
|
|
39
42
|
return resources;
|
|
40
43
|
}
|
|
41
|
-
exports.loadI18nFromPath = loadI18nFromPath;
|
|
42
44
|
/**
|
|
43
45
|
* Scan an i18n folder and return i18n metadata.
|
|
44
46
|
* Expected structure: `{i18nPath}/{lng}/{namespace}.json`
|
|
@@ -92,7 +94,6 @@ async function getI18nMeta(i18nPath, primaryLng = "en") {
|
|
|
92
94
|
languages,
|
|
93
95
|
};
|
|
94
96
|
}
|
|
95
|
-
exports.getI18nMeta = getI18nMeta;
|
|
96
97
|
/**
|
|
97
98
|
* Sync primary language i18n files to the dev app build directory (initial sync).
|
|
98
99
|
* Only uploads primaryLng since that's what AI translations use as source.
|
|
@@ -134,7 +135,6 @@ async function syncAllI18nToDevApp(devAppInfo, i18nResources, primaryLng = "en")
|
|
|
134
135
|
console.warn(`[kokimoki-kit] Synced i18n: ${syncedFiles.join(", ")}`);
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
|
-
exports.syncAllI18nToDevApp = syncAllI18nToDevApp;
|
|
138
138
|
/**
|
|
139
139
|
* Sync a single i18n file to the dev app build directory.
|
|
140
140
|
* Only syncs if the file is for the primary language.
|
|
@@ -162,4 +162,3 @@ async function syncI18nFile(devAppInfo, i18nPath, changedFilePath, primaryLng =
|
|
|
162
162
|
console.warn(`[kokimoki-kit] Failed to sync i18n ${lng}/${ns}:`, e instanceof Error ? e.message : e);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
-
exports.syncI18nFile = syncI18nFile;
|
package/dist/dev-overlays.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* Development overlay HTML templates for kokimoki-kit plugin
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.renderLoadingPage = renderLoadingPage;
|
|
7
|
+
exports.renderErrorPage = renderErrorPage;
|
|
8
|
+
exports.renderStoresChangedPage = renderStoresChangedPage;
|
|
7
9
|
const pageBaseStyles = `
|
|
8
10
|
color: white;
|
|
9
11
|
display: flex;
|
|
@@ -109,7 +111,6 @@ function renderLoadingPage() {
|
|
|
109
111
|
</body>
|
|
110
112
|
</html>`;
|
|
111
113
|
}
|
|
112
|
-
exports.renderLoadingPage = renderLoadingPage;
|
|
113
114
|
/**
|
|
114
115
|
* Generate error page HTML for dev app errors (full page)
|
|
115
116
|
*/
|
|
@@ -175,7 +176,6 @@ function renderErrorPage(error) {
|
|
|
175
176
|
</body>
|
|
176
177
|
</html>`;
|
|
177
178
|
}
|
|
178
|
-
exports.renderErrorPage = renderErrorPage;
|
|
179
179
|
/**
|
|
180
180
|
* Generate stores changed warning page HTML (full page, not overlay)
|
|
181
181
|
*/
|
|
@@ -298,4 +298,3 @@ function renderStoresChangedPage(canReset) {
|
|
|
298
298
|
</body>
|
|
299
299
|
</html>`;
|
|
300
300
|
}
|
|
301
|
-
exports.renderStoresChangedPage = renderStoresChangedPage;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -18,8 +18,6 @@ __exportStar(require("./dev-app"), exports);
|
|
|
18
18
|
__exportStar(require("./dev-frame"), exports);
|
|
19
19
|
__exportStar(require("./kokimoki-kit-plugin"), exports);
|
|
20
20
|
__exportStar(require("./preprocess-style"), exports);
|
|
21
|
-
// Re-export Zod utilities for schema definition
|
|
22
|
-
__exportStar(require("./zod"), exports);
|
|
23
21
|
// App Meta schema for built-in store
|
|
24
22
|
__exportStar(require("./schemas/app-meta-schema"), exports);
|
|
25
23
|
// Shared utilities (used by both kit and cli)
|
|
@@ -15,18 +15,29 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
39
|
+
exports.getI18nMeta = void 0;
|
|
40
|
+
exports.kokimokiKitPlugin = kokimokiKitPlugin;
|
|
30
41
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
31
42
|
const node_html_parser_1 = require("node-html-parser");
|
|
32
43
|
const path_1 = __importDefault(require("path"));
|
|
@@ -52,6 +63,7 @@ const BUILT_IN_APP_META_STORE = {
|
|
|
52
63
|
pattern: app_meta_schema_1.APP_META_STORE_NAME,
|
|
53
64
|
schema: app_meta_schema_1.appMetaStoreSchema,
|
|
54
65
|
local: false,
|
|
66
|
+
isTransferable: true,
|
|
55
67
|
};
|
|
56
68
|
function kokimokiKitPlugin(config) {
|
|
57
69
|
// Combine user stores with built-in stores
|
|
@@ -407,6 +419,7 @@ function kokimokiKitPlugin(config) {
|
|
|
407
419
|
pattern: store.pattern,
|
|
408
420
|
local: store.local,
|
|
409
421
|
schema: v4_1.z.toJSONSchema(store.schema),
|
|
422
|
+
isTransferable: store.isTransferable ?? false,
|
|
410
423
|
}));
|
|
411
424
|
this.emitFile({
|
|
412
425
|
type: "asset",
|
|
@@ -637,4 +650,3 @@ function kokimokiKitPlugin(config) {
|
|
|
637
650
|
},
|
|
638
651
|
};
|
|
639
652
|
}
|
|
640
|
-
exports.kokimokiKitPlugin = kokimokiKitPlugin;
|
package/dist/preprocess-style.js
CHANGED
|
@@ -3,7 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.hexToRgb = hexToRgb;
|
|
7
|
+
exports.rgbToHex = rgbToHex;
|
|
8
|
+
exports.revertReplaceForColorPickers = revertReplaceForColorPickers;
|
|
9
|
+
exports.hexToTailwindRgbString = hexToTailwindRgbString;
|
|
10
|
+
exports.getLuminance = getLuminance;
|
|
11
|
+
exports.calculateRatio = calculateRatio;
|
|
12
|
+
exports.handleStringColor = handleStringColor;
|
|
13
|
+
exports.destringRgb = destringRgb;
|
|
14
|
+
exports.generateA11yOnColor = generateA11yOnColor;
|
|
15
|
+
exports.generatePalette = generatePalette;
|
|
16
|
+
exports.preprocessStyle = preprocessStyle;
|
|
7
17
|
const colorjs_io_1 = __importDefault(require("colorjs.io"));
|
|
8
18
|
const colornames_1 = __importDefault(require("colornames"));
|
|
9
19
|
// List of rgb tuple variable names (possibly temporary system to support color picker for these variables)
|
|
@@ -103,12 +113,10 @@ function hexToRgb(hex) {
|
|
|
103
113
|
b: parseInt(b, 16),
|
|
104
114
|
};
|
|
105
115
|
}
|
|
106
|
-
exports.hexToRgb = hexToRgb;
|
|
107
116
|
function rgbToHex(r, g, b) {
|
|
108
117
|
const toHex = (c) => `0${c.toString(16)}`.slice(-2);
|
|
109
118
|
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
110
119
|
}
|
|
111
|
-
exports.rgbToHex = rgbToHex;
|
|
112
120
|
// export function replaceForColorPickers(code: string) {
|
|
113
121
|
// return code.replace(
|
|
114
122
|
// /--([a-z0-9-]+):\s*(\d+)\s+(\d+)\s+(\d+);/gi,
|
|
@@ -145,7 +153,6 @@ function revertReplaceForColorPickers(code) {
|
|
|
145
153
|
return match;
|
|
146
154
|
});
|
|
147
155
|
}
|
|
148
|
-
exports.revertReplaceForColorPickers = revertReplaceForColorPickers;
|
|
149
156
|
function lighten(hex, intensity) {
|
|
150
157
|
const color = hexToRgb(`#${hex}`);
|
|
151
158
|
if (!color)
|
|
@@ -172,7 +179,6 @@ function hexToTailwindRgbString(hex) {
|
|
|
172
179
|
const [, r, g, b] = colorParts;
|
|
173
180
|
return `${parseInt(r, 16)} ${parseInt(g, 16)} ${parseInt(b, 16)}`;
|
|
174
181
|
}
|
|
175
|
-
exports.hexToTailwindRgbString = hexToTailwindRgbString;
|
|
176
182
|
function getLuminance(r, g, b) {
|
|
177
183
|
const { _r, _g, _b } = typeof r === "object"
|
|
178
184
|
? { _r: r.r, _g: r.g, _b: r.b }
|
|
@@ -186,7 +192,6 @@ function getLuminance(r, g, b) {
|
|
|
186
192
|
});
|
|
187
193
|
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
|
|
188
194
|
}
|
|
189
|
-
exports.getLuminance = getLuminance;
|
|
190
195
|
function calculateRatio(luminance1, luminance2) {
|
|
191
196
|
const lum1 = typeof luminance1 === "string"
|
|
192
197
|
? getLuminance(handleStringColor(luminance1))
|
|
@@ -200,7 +205,6 @@ function calculateRatio(luminance1, luminance2) {
|
|
|
200
205
|
? (lum2 + 0.05) / (lum1 + 0.05)
|
|
201
206
|
: (lum1 + 0.05) / (lum2 + 0.05);
|
|
202
207
|
}
|
|
203
|
-
exports.calculateRatio = calculateRatio;
|
|
204
208
|
function handleStringColor(colorString, returnType = "rgb") {
|
|
205
209
|
// if it's a css variable
|
|
206
210
|
if (colorString.includes("--")) {
|
|
@@ -224,7 +228,6 @@ function handleStringColor(colorString, returnType = "rgb") {
|
|
|
224
228
|
}
|
|
225
229
|
return colorString;
|
|
226
230
|
}
|
|
227
|
-
exports.handleStringColor = handleStringColor;
|
|
228
231
|
function cssColorToHex(colorString) {
|
|
229
232
|
if (colorString.includes("#"))
|
|
230
233
|
return colorString;
|
|
@@ -251,13 +254,11 @@ function destringRgb(rgbString) {
|
|
|
251
254
|
b: parseInt(rgb[3], 10),
|
|
252
255
|
};
|
|
253
256
|
}
|
|
254
|
-
exports.destringRgb = destringRgb;
|
|
255
257
|
function generateA11yOnColor(hex) {
|
|
256
258
|
const black = calculateRatio(hex, "#000000");
|
|
257
259
|
const white = calculateRatio(hex, "#FFFFFF");
|
|
258
260
|
return black < white ? "0 0 0" : "255 255 255";
|
|
259
261
|
}
|
|
260
|
-
exports.generateA11yOnColor = generateA11yOnColor;
|
|
261
262
|
function generatePalette(baseColor) {
|
|
262
263
|
const hexValidation = new RegExp(/^#[0-9a-f]{6}$/i);
|
|
263
264
|
if (!hexValidation.test(baseColor))
|
|
@@ -299,7 +300,6 @@ function generatePalette(baseColor) {
|
|
|
299
300
|
});
|
|
300
301
|
return response;
|
|
301
302
|
}
|
|
302
|
-
exports.generatePalette = generatePalette;
|
|
303
303
|
function preprocessGfcThemeBlock(code) {
|
|
304
304
|
// Generate map of defined css variables
|
|
305
305
|
const cssVariableMap = {};
|
|
@@ -376,4 +376,3 @@ function preprocessStyle(code) {
|
|
|
376
376
|
}
|
|
377
377
|
});
|
|
378
378
|
}
|
|
379
|
-
exports.preprocessStyle = preprocessStyle;
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* This screen is injected into production builds and removed when km:ready is received.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.loadingScreenElement = exports.loadingScreenScript = exports.loadingScreenStyles = void 0;
|
|
8
|
+
exports.removeExistingLoadingScreen = removeExistingLoadingScreen;
|
|
8
9
|
/**
|
|
9
10
|
* Loading screen styles
|
|
10
11
|
*/
|
|
@@ -120,4 +121,3 @@ function removeExistingLoadingScreen(html) {
|
|
|
120
121
|
.replace(/<div[^>]*id=["']km-loading["'][^>]*>[\s\S]*?<\/div>/gi, "")
|
|
121
122
|
.replace(/<style[^>]*id=["']km-loading-style["'][^>]*>[\s\S]*?<\/style>/gi, "");
|
|
122
123
|
}
|
|
123
|
-
exports.removeExistingLoadingScreen = removeExistingLoadingScreen;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const KOKIMOKI_KIT_VERSION = "1.8.
|
|
1
|
+
export declare const KOKIMOKI_KIT_VERSION = "1.8.2";
|
package/dist/version.js
CHANGED
|
@@ -15,77 +15,94 @@ npm install @kokimoki/kit
|
|
|
15
15
|
|
|
16
16
|
## Plugin Configuration
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Create a `kokimoki.config.ts` file in your project root to define your Kokimoki Kit configuration:
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
import { z } from "@kokimoki/app";
|
|
22
|
+
|
|
23
|
+
export const kokimokiConfig: KokimokiKitConfig = {
|
|
24
|
+
// Required: Your concept ID from Kokimoki
|
|
25
|
+
conceptId: "your-concept-id",
|
|
26
|
+
|
|
27
|
+
// Required: Deploy configurations
|
|
28
|
+
deployCodes: [
|
|
29
|
+
{
|
|
30
|
+
name: "default",
|
|
31
|
+
description: "Default game mode",
|
|
32
|
+
clientContext: { mode: "standard" },
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "tournament",
|
|
36
|
+
description: "Tournament mode with stricter rules",
|
|
37
|
+
clientContext: { mode: "tournament", maxPlayers: 100 },
|
|
38
|
+
},
|
|
39
|
+
],
|
|
24
40
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Store schemas for validation
|
|
43
|
+
* marking stores as transferable allows their content to be used
|
|
44
|
+
* when creating new apps based on this one.
|
|
45
|
+
*
|
|
46
|
+
* For example, game configuration can contain content and settings
|
|
47
|
+
* that can be reused when setting up a new game instance. Dynamic
|
|
48
|
+
* game state, on the other hand, should not be transferable.
|
|
49
|
+
*/
|
|
50
|
+
stores: [
|
|
51
|
+
{
|
|
52
|
+
pattern: "config",
|
|
53
|
+
schema: z.object({
|
|
54
|
+
mode: z.enum(["standard", "tournament"]),
|
|
55
|
+
duration: z.number().min(1).describe("Game duration in minutes"),
|
|
56
|
+
}),
|
|
57
|
+
isTransferable: true, // This store content can be used to create a new app with the same content
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
pattern: "game",
|
|
61
|
+
schema: z.object({
|
|
62
|
+
status: z.enum(["waiting", "playing", "finished"]),
|
|
63
|
+
round: z.number(),
|
|
64
|
+
}),
|
|
65
|
+
isTransferable: false, // Dynamic game state should not be marked as transferable
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
pattern: "player-*",
|
|
46
69
|
schema: z.object({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
timeLimit: z.number().optional(),
|
|
70
|
+
name: z.string(),
|
|
71
|
+
score: z.number(),
|
|
50
72
|
}),
|
|
73
|
+
local: true, // Local store (per-client)
|
|
74
|
+
isTransferable: false, // Local stores cannot be transferable
|
|
75
|
+
},
|
|
76
|
+
],
|
|
51
77
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
local: true, // Local store (per-client)
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
|
|
71
|
-
// Optional: i18n configuration
|
|
72
|
-
i18nPath: "./src/i18n",
|
|
73
|
-
i18nPrimaryLng: "en", // Source language for AI translations
|
|
74
|
-
|
|
75
|
-
// Optional: Custom API endpoint
|
|
76
|
-
endpoint: "https://api.kokimoki.com",
|
|
77
|
-
host: "y-wss.kokimoki.com",
|
|
78
|
-
|
|
79
|
-
// Optional: Dev view layout (see Dev Frame section)
|
|
80
|
-
devView: [
|
|
81
|
-
[{ label: "host", clientContext: { mode: "host" } }],
|
|
82
|
-
[
|
|
83
|
-
{ label: "player1", clientContext: { mode: "player" } },
|
|
84
|
-
{ label: "player2", clientContext: { mode: "player" } },
|
|
85
|
-
],
|
|
86
|
-
],
|
|
87
|
-
}),
|
|
78
|
+
// Optional: i18n configuration
|
|
79
|
+
i18nPath: "./src/i18n",
|
|
80
|
+
i18nPrimaryLng: "en", // Source language for AI translations
|
|
81
|
+
|
|
82
|
+
// Optional: Custom API endpoint
|
|
83
|
+
endpoint: "https://api.kokimoki.com",
|
|
84
|
+
host: "y-wss.kokimoki.com",
|
|
85
|
+
|
|
86
|
+
// Optional: Dev view layout (see Dev Frame section)
|
|
87
|
+
devView: [
|
|
88
|
+
[{ label: "host", clientContext: { mode: "host" } }],
|
|
89
|
+
[
|
|
90
|
+
{ label: "player1", clientContext: { mode: "player" } },
|
|
91
|
+
{ label: "player2", clientContext: { mode: "player" } },
|
|
92
|
+
],
|
|
88
93
|
],
|
|
94
|
+
};
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Add the plugin to your `vite.config.ts`:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { defineConfig } from "vite";
|
|
101
|
+
import { kokimokiKitPlugin } from "@kokimoki/kit";
|
|
102
|
+
import { kokimokiConfig } from "./kokimoki.config";
|
|
103
|
+
|
|
104
|
+
export default defineConfig({
|
|
105
|
+
plugins: [kokimokiKitPlugin(kokimokiConfig)],
|
|
89
106
|
});
|
|
90
107
|
```
|
|
91
108
|
|
|
@@ -100,17 +117,17 @@ export default defineConfig({
|
|
|
100
117
|
|
|
101
118
|
### Optional Options
|
|
102
119
|
|
|
103
|
-
| Option
|
|
104
|
-
|
|
|
105
|
-
| `schema`
|
|
106
|
-
| `stores`
|
|
107
|
-
| `i18nPath`
|
|
108
|
-
| `i18nPrimaryLng`
|
|
109
|
-
| `endpoint`
|
|
110
|
-
| `host`
|
|
111
|
-
| `devView`
|
|
112
|
-
| `defaultAppMeta`
|
|
113
|
-
| `defaultProjectStylePath`
|
|
120
|
+
| Option | Type | Description |
|
|
121
|
+
| ------------------------- | ---------------- | -------------------------------------------------- |
|
|
122
|
+
| `schema` | `ZodType` | Zod schema for project configuration |
|
|
123
|
+
| `stores` | `array` | Store definitions with patterns and schemas |
|
|
124
|
+
| `i18nPath` | `string` | Path to i18n folder (e.g., `./src/i18n`) |
|
|
125
|
+
| `i18nPrimaryLng` | `string` | Source language code (default: `"en"`) |
|
|
126
|
+
| `endpoint` | `string` | API endpoint (default: `https://api.kokimoki.com`) |
|
|
127
|
+
| `host` | `string` | WebSocket host (default: `y-wss.kokimoki.com`) |
|
|
128
|
+
| `devView` | `array \| false` | Dev frame layout or `false` to disable |
|
|
129
|
+
| `defaultAppMeta` | `object` | Default meta tags for SEO and social sharing |
|
|
130
|
+
| `defaultProjectStylePath` | `string` | Path to default project style file |
|
|
114
131
|
|
|
115
132
|
## App Meta
|
|
116
133
|
|
|
@@ -135,15 +152,15 @@ kokimokiKitPlugin({
|
|
|
135
152
|
|
|
136
153
|
### Fields
|
|
137
154
|
|
|
138
|
-
| Field | Description
|
|
139
|
-
| --------------- |
|
|
140
|
-
| `lang` | HTML `lang` attribute (e.g., `"en"`, `"de"`)
|
|
141
|
-
| `title` | Document title (browser tab)
|
|
142
|
-
| `description` | Meta description for SEO
|
|
143
|
-
| `ogTitle` | Open Graph title (defaults to `title` if not set)
|
|
144
|
-
| `ogDescription` | Open Graph description (defaults to `description`)
|
|
155
|
+
| Field | Description |
|
|
156
|
+
| --------------- | ------------------------------------------------------------- |
|
|
157
|
+
| `lang` | HTML `lang` attribute (e.g., `"en"`, `"de"`) |
|
|
158
|
+
| `title` | Document title (browser tab) |
|
|
159
|
+
| `description` | Meta description for SEO |
|
|
160
|
+
| `ogTitle` | Open Graph title (defaults to `title` if not set) |
|
|
161
|
+
| `ogDescription` | Open Graph description (defaults to `description`) |
|
|
145
162
|
| `ogImage` | Open Graph image URL (use relative path like `/og-image.png`) |
|
|
146
|
-
| `favicon` | Favicon URL (use relative path like `/favicon.png`)
|
|
163
|
+
| `favicon` | Favicon URL (use relative path like `/favicon.png`) |
|
|
147
164
|
|
|
148
165
|
### Asset Path Resolution
|
|
149
166
|
|
|
@@ -218,6 +235,8 @@ kokimokiKitPlugin({
|
|
|
218
235
|
Define schemas to validate store state during development:
|
|
219
236
|
|
|
220
237
|
```typescript
|
|
238
|
+
import { z } from "@kokimoki/app";
|
|
239
|
+
|
|
221
240
|
stores: [
|
|
222
241
|
// Global store - shared across all clients
|
|
223
242
|
{
|
|
@@ -295,19 +314,6 @@ kokimokiKitPlugin({
|
|
|
295
314
|
- Changes are synced to the dev app in real-time
|
|
296
315
|
- No need to restart the dev server
|
|
297
316
|
|
|
298
|
-
## Zod Re-export
|
|
299
|
-
|
|
300
|
-
The kit re-exports Zod for convenience:
|
|
301
|
-
|
|
302
|
-
```typescript
|
|
303
|
-
import { z } from "@kokimoki/kit";
|
|
304
|
-
|
|
305
|
-
const mySchema = z.object({
|
|
306
|
-
name: z.string(),
|
|
307
|
-
count: z.number(),
|
|
308
|
-
});
|
|
309
|
-
```
|
|
310
|
-
|
|
311
317
|
## Project Files
|
|
312
318
|
|
|
313
319
|
### .kokimoki Directory
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kokimoki/kit",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,13 +12,17 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"test": "ts-mocha src/**/*.spec.ts --exit",
|
|
14
14
|
"prebuild": "node -p \"'export const KOKIMOKI_KIT_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
|
|
15
|
-
"build": "tsc"
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"lint": "eslint .",
|
|
17
|
+
"typecheck": "tsc --noEmit"
|
|
16
18
|
},
|
|
17
19
|
"author": "Loquiz OÜ",
|
|
18
20
|
"license": "Apache-2.0",
|
|
19
21
|
"devDependencies": {
|
|
22
|
+
"eslint-config": "*",
|
|
20
23
|
"@types/colornames": "^1.1.4",
|
|
21
24
|
"@types/expect": "^24.3.2",
|
|
25
|
+
"eslint": "^9.39.1",
|
|
22
26
|
"mocha": "^11.1.0",
|
|
23
27
|
"ts-mocha": "^10.0.0"
|
|
24
28
|
},
|
package/dist/schema-builder.d.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
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<
|
|
19
|
-
string extends T ? never : T
|
|
20
|
-
> {
|
|
21
|
-
value: string extends T ? never : T;
|
|
22
|
-
constructor(value: string extends T ? never : T, options?: FieldOptions);
|
|
23
|
-
get schema(): {
|
|
24
|
-
const: string extends T ? never : T;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
export declare class ImageField extends Field<string> {
|
|
28
|
-
value: string;
|
|
29
|
-
constructor(value: string, options?: FieldOptions);
|
|
30
|
-
get schema(): {
|
|
31
|
-
type: string;
|
|
32
|
-
default: string;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export declare class TextField extends Field<string> {
|
|
36
|
-
value: string;
|
|
37
|
-
constructor(value: string, options?: FieldOptions);
|
|
38
|
-
get schema(): {
|
|
39
|
-
type: string;
|
|
40
|
-
default: string;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
export declare class EnumField<T extends Record<string, string>> extends Field<
|
|
44
|
-
keyof T
|
|
45
|
-
> {
|
|
46
|
-
enumValues: T;
|
|
47
|
-
value: keyof T;
|
|
48
|
-
constructor(enumValues: T, value: keyof T, options?: FieldOptions);
|
|
49
|
-
get schema(): {
|
|
50
|
-
enum: string[];
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
export declare class IntegerField extends Field<number> {
|
|
54
|
-
value: number;
|
|
55
|
-
constructor(value: number, options?: FieldOptions);
|
|
56
|
-
get schema(): {
|
|
57
|
-
type: string;
|
|
58
|
-
default: number;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
export declare class FloatField extends Field<number> {
|
|
62
|
-
value: number;
|
|
63
|
-
constructor(value: number, options?: FieldOptions);
|
|
64
|
-
get schema(): {
|
|
65
|
-
type: string;
|
|
66
|
-
default: number;
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
export declare class FormGroup<
|
|
70
|
-
T extends Record<string, Field<any>>,
|
|
71
|
-
O extends Record<string, Field<any>>,
|
|
72
|
-
> extends Field<
|
|
73
|
-
{
|
|
74
|
-
[key in keyof T]: T[key]["value"];
|
|
75
|
-
} & Partial<{
|
|
76
|
-
[key in keyof O]: O[key]["value"];
|
|
77
|
-
}>
|
|
78
|
-
> {
|
|
79
|
-
requiredFields: T;
|
|
80
|
-
optionalFields: O;
|
|
81
|
-
constructor(requiredFields: T, optionalFields?: O, options?: FieldOptions);
|
|
82
|
-
get value(): {
|
|
83
|
-
[key in keyof T]: T[key]["value"];
|
|
84
|
-
} & Partial<{
|
|
85
|
-
[key in keyof O]: O[key]["value"];
|
|
86
|
-
}>;
|
|
87
|
-
get schema(): {
|
|
88
|
-
type: string;
|
|
89
|
-
properties: any;
|
|
90
|
-
required: string[];
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
export declare class FormArray<T> extends Field<T[]> {
|
|
94
|
-
private factory;
|
|
95
|
-
value: Field<T>["value"][];
|
|
96
|
-
constructor(
|
|
97
|
-
factory: () => Field<T>,
|
|
98
|
-
value: Field<T>["value"][],
|
|
99
|
-
options?: FieldOptions,
|
|
100
|
-
);
|
|
101
|
-
get schema(): {
|
|
102
|
-
type: string;
|
|
103
|
-
items: any;
|
|
104
|
-
default: T[];
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
export declare class Form<
|
|
108
|
-
R extends Record<string, Field<any>>,
|
|
109
|
-
O extends Record<string, Field<any>>,
|
|
110
|
-
> extends FormGroup<R, O> {}
|
package/dist/schema-builder.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Form =
|
|
4
|
-
exports.FormArray =
|
|
5
|
-
exports.FormGroup =
|
|
6
|
-
exports.FloatField =
|
|
7
|
-
exports.IntegerField =
|
|
8
|
-
exports.EnumField =
|
|
9
|
-
exports.TextField =
|
|
10
|
-
exports.ImageField =
|
|
11
|
-
exports.ConstField =
|
|
12
|
-
exports.BooleanField =
|
|
13
|
-
exports.Field =
|
|
14
|
-
void 0;
|
|
15
|
-
const defaultFieldOptions = {};
|
|
16
|
-
class Field {
|
|
17
|
-
options;
|
|
18
|
-
constructor(options) {
|
|
19
|
-
this.options = options;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.Field = Field;
|
|
23
|
-
class BooleanField extends Field {
|
|
24
|
-
value;
|
|
25
|
-
constructor(value, options = defaultFieldOptions) {
|
|
26
|
-
super(options);
|
|
27
|
-
this.value = value;
|
|
28
|
-
}
|
|
29
|
-
get schema() {
|
|
30
|
-
return {
|
|
31
|
-
type: "boolean",
|
|
32
|
-
default: this.value,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.BooleanField = BooleanField;
|
|
37
|
-
class ConstField extends Field {
|
|
38
|
-
value;
|
|
39
|
-
constructor(value, options = defaultFieldOptions) {
|
|
40
|
-
super(options);
|
|
41
|
-
this.value = value;
|
|
42
|
-
}
|
|
43
|
-
get schema() {
|
|
44
|
-
return {
|
|
45
|
-
const: this.value,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.ConstField = ConstField;
|
|
50
|
-
class ImageField extends Field {
|
|
51
|
-
value;
|
|
52
|
-
constructor(value, options = defaultFieldOptions) {
|
|
53
|
-
super(options);
|
|
54
|
-
this.value = value;
|
|
55
|
-
}
|
|
56
|
-
get schema() {
|
|
57
|
-
return {
|
|
58
|
-
type: "string",
|
|
59
|
-
default: this.value,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.ImageField = ImageField;
|
|
64
|
-
class TextField extends Field {
|
|
65
|
-
value;
|
|
66
|
-
constructor(value, options = defaultFieldOptions) {
|
|
67
|
-
super(options);
|
|
68
|
-
this.value = value;
|
|
69
|
-
}
|
|
70
|
-
get schema() {
|
|
71
|
-
return {
|
|
72
|
-
type: "string",
|
|
73
|
-
default: this.value,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.TextField = TextField;
|
|
78
|
-
class EnumField extends Field {
|
|
79
|
-
enumValues;
|
|
80
|
-
value;
|
|
81
|
-
constructor(enumValues, value, options = defaultFieldOptions) {
|
|
82
|
-
super(options);
|
|
83
|
-
this.enumValues = enumValues;
|
|
84
|
-
this.value = value;
|
|
85
|
-
}
|
|
86
|
-
get schema() {
|
|
87
|
-
return {
|
|
88
|
-
enum: Object.keys(this.enumValues),
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
exports.EnumField = EnumField;
|
|
93
|
-
class IntegerField extends Field {
|
|
94
|
-
value;
|
|
95
|
-
constructor(value, options = defaultFieldOptions) {
|
|
96
|
-
super(options);
|
|
97
|
-
this.value = value;
|
|
98
|
-
}
|
|
99
|
-
get schema() {
|
|
100
|
-
return {
|
|
101
|
-
type: "integer",
|
|
102
|
-
default: this.value,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
exports.IntegerField = IntegerField;
|
|
107
|
-
class FloatField extends Field {
|
|
108
|
-
value;
|
|
109
|
-
constructor(value, options = defaultFieldOptions) {
|
|
110
|
-
super(options);
|
|
111
|
-
this.value = value;
|
|
112
|
-
}
|
|
113
|
-
get schema() {
|
|
114
|
-
return {
|
|
115
|
-
type: "number",
|
|
116
|
-
default: this.value,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.FloatField = FloatField;
|
|
121
|
-
class FormGroup extends Field {
|
|
122
|
-
requiredFields;
|
|
123
|
-
optionalFields;
|
|
124
|
-
constructor(
|
|
125
|
-
requiredFields,
|
|
126
|
-
optionalFields = {},
|
|
127
|
-
options = defaultFieldOptions,
|
|
128
|
-
) {
|
|
129
|
-
super(options);
|
|
130
|
-
this.requiredFields = requiredFields;
|
|
131
|
-
this.optionalFields = optionalFields;
|
|
132
|
-
}
|
|
133
|
-
get value() {
|
|
134
|
-
const value = Object.entries(this.requiredFields).reduce(
|
|
135
|
-
(acc, [key, field]) => {
|
|
136
|
-
acc[key] = field.value;
|
|
137
|
-
return acc;
|
|
138
|
-
},
|
|
139
|
-
{},
|
|
140
|
-
);
|
|
141
|
-
Object.entries(this.optionalFields).forEach(([key, field]) => {
|
|
142
|
-
if (field.value !== undefined) {
|
|
143
|
-
value[key] = field.value;
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
return value;
|
|
147
|
-
}
|
|
148
|
-
get schema() {
|
|
149
|
-
const properties = {};
|
|
150
|
-
Object.entries(this.requiredFields).forEach(([key, field]) => {
|
|
151
|
-
properties[key] = field.schema;
|
|
152
|
-
});
|
|
153
|
-
Object.entries(this.optionalFields).forEach(([key, field]) => {
|
|
154
|
-
properties[key] = field.schema;
|
|
155
|
-
});
|
|
156
|
-
return {
|
|
157
|
-
type: "object",
|
|
158
|
-
properties,
|
|
159
|
-
required: Object.keys(this.requiredFields),
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
exports.FormGroup = FormGroup;
|
|
164
|
-
class FormArray extends Field {
|
|
165
|
-
factory;
|
|
166
|
-
value;
|
|
167
|
-
constructor(factory, value, options = defaultFieldOptions) {
|
|
168
|
-
super(options);
|
|
169
|
-
this.factory = factory;
|
|
170
|
-
this.value = value;
|
|
171
|
-
}
|
|
172
|
-
get schema() {
|
|
173
|
-
const field = this.factory();
|
|
174
|
-
return {
|
|
175
|
-
type: "array",
|
|
176
|
-
items: field.schema,
|
|
177
|
-
default: this.value,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
exports.FormArray = FormArray;
|
|
182
|
-
class Form extends FormGroup {}
|
|
183
|
-
exports.Form = Form;
|