@acdh-oeaw/keystatic-lib 0.6.1 → 0.7.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/_virtual/rolldown_runtime.js +27 -0
- package/dist/config.d.ts +6 -5
- package/dist/config.js +1 -3
- package/dist/create-asset-options.d.ts +7 -7
- package/dist/create-asset-options.js +15 -2
- package/dist/create-asset-options.js.map +1 -1
- package/dist/create-component.d.ts +6 -5
- package/dist/create-component.js +9 -2
- package/dist/create-component.js.map +1 -1
- package/dist/create-content-field-options.d.ts +10 -10
- package/dist/create-content-field-options.js +19 -3
- package/dist/create-content-field-options.js.map +1 -1
- package/dist/create-label.d.ts +4 -2
- package/dist/create-label.js +7 -2
- package/dist/create-label.js.map +1 -1
- package/dist/index.d.ts +8 -9
- package/dist/index.js +8 -8
- package/dist/node_modules/.pnpm/react@19.1.1/node_modules/react/cjs/react.development.js +718 -0
- package/dist/node_modules/.pnpm/react@19.1.1/node_modules/react/cjs/react.development.js.map +1 -0
- package/dist/node_modules/.pnpm/react@19.1.1/node_modules/react/cjs/react.production.js +354 -0
- package/dist/node_modules/.pnpm/react@19.1.1/node_modules/react/cjs/react.production.js.map +1 -0
- package/dist/node_modules/.pnpm/react@19.1.1/node_modules/react/index.js +15 -0
- package/dist/node_modules/.pnpm/react@19.1.1/node_modules/react/index.js.map +1 -0
- package/dist/preview/index.d.ts +7 -5
- package/dist/preview/index.js +21 -20
- package/dist/preview/index.js.map +1 -1
- package/dist/reader.d.ts +41 -39
- package/dist/reader.js +85 -86
- package/dist/reader.js.map +1 -1
- package/dist/resources.d.ts +14 -12
- package/dist/resources.js +34 -2
- package/dist/resources.js.map +1 -1
- package/dist/with-i18n-prefix.d.ts +5 -3
- package/dist/with-i18n-prefix.js +7 -2
- package/dist/with-i18n-prefix.js.map +1 -1
- package/license +1 -1
- package/package.json +44 -33
- package/dist/chunk-CI4JBTGG.js +0 -8
- package/dist/chunk-CI4JBTGG.js.map +0 -1
- package/dist/chunk-EEB35F4L.js +0 -15
- package/dist/chunk-EEB35F4L.js.map +0 -1
- package/dist/chunk-ENT7N2ZS.js +0 -16
- package/dist/chunk-ENT7N2ZS.js.map +0 -1
- package/dist/chunk-M7J4ISS4.js +0 -8
- package/dist/chunk-M7J4ISS4.js.map +0 -1
- package/dist/chunk-ZN3LEWB6.js +0 -35
- package/dist/chunk-ZN3LEWB6.js.map +0 -1
- package/dist/chunk-ZWZCXCMD.js +0 -10
- package/dist/chunk-ZWZCXCMD.js.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/preview/index.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __toESM } from "../_virtual/rolldown_runtime.js";
|
|
2
|
+
import { require_react } from "../node_modules/.pnpm/react@19.1.1/node_modules/react/index.js";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
//#region src/preview/index.ts
|
|
5
|
+
var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
|
|
6
|
+
/** @see https://github.com/Thinkmill/keystatic/blob/main/packages/keystatic/src/form/fields/image/ui.tsx#L48-L63 */
|
|
4
7
|
function useObjectUrl(params) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}, [contentType, data]);
|
|
21
|
-
return url;
|
|
8
|
+
const data = params?.data;
|
|
9
|
+
const contentType = params?.extension === "svg" ? "image/svg+xml" : void 0;
|
|
10
|
+
const [url, setUrl] = (0, import_react.useState)(null);
|
|
11
|
+
(0, import_react.useEffect)(() => {
|
|
12
|
+
if (data == null) {
|
|
13
|
+
setUrl(null);
|
|
14
|
+
return void 0;
|
|
15
|
+
}
|
|
16
|
+
const url$1 = URL.createObjectURL(new Blob([data], contentType ? { type: contentType } : void 0));
|
|
17
|
+
setUrl(url$1);
|
|
18
|
+
return () => {
|
|
19
|
+
URL.revokeObjectURL(url$1);
|
|
20
|
+
};
|
|
21
|
+
}, [contentType, data]);
|
|
22
|
+
return url;
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
//#endregion
|
|
24
26
|
export { useObjectUrl };
|
|
25
|
-
//# sourceMappingURL=index.js.map
|
|
26
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["url"],"sources":["../../src/preview/index.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\n\nexport interface UseObjectUrlParams {\n\tdata: Uint8Array;\n\textension: string;\n\tfilename: string;\n}\n\n/** @see https://github.com/Thinkmill/keystatic/blob/main/packages/keystatic/src/form/fields/image/ui.tsx#L48-L63 */\nexport function useObjectUrl(params: UseObjectUrlParams | null) {\n\tconst data = params?.data;\n\tconst contentType = params?.extension === \"svg\" ? \"image/svg+xml\" : undefined;\n\n\tconst [url, setUrl] = useState<string | null>(null);\n\n\tuseEffect(() => {\n\t\tif (data == null) {\n\t\t\tsetUrl(null);\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst url = URL.createObjectURL(\n\t\t\tnew Blob([data as BlobPart], contentType ? { type: contentType } : undefined),\n\t\t);\n\t\tsetUrl(url);\n\n\t\treturn () => {\n\t\t\tURL.revokeObjectURL(url);\n\t\t};\n\t}, [contentType, data]);\n\n\treturn url;\n}\n"],"mappings":";;;;;;AASA,SAAgB,aAAa,QAAmC;CAC/D,MAAM,OAAO,QAAQ;CACrB,MAAM,cAAc,QAAQ,cAAc,QAAQ,kBAAkB;CAEpE,MAAM,CAAC,KAAK,qCAAkC;AAE9C,mCAAgB;AACf,MAAI,QAAQ,MAAM;AACjB,UAAO;AACP,UAAO;;EAGR,MAAMA,QAAM,IAAI,gBACf,IAAI,KAAK,CAAC,OAAmB,cAAc,EAAE,MAAM,gBAAgB;AAEpE,SAAOA;AAEP,eAAa;AACZ,OAAI,gBAAgBA;;IAEnB,CAAC,aAAa;AAEjB,QAAO"}
|
package/dist/reader.d.ts
CHANGED
|
@@ -1,44 +1,46 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
1
|
+
import { Locale } from "./config.js";
|
|
2
|
+
import { WithoutI18nPrefix } from "./with-i18n-prefix.js";
|
|
3
|
+
import * as _keystatic_core_reader_github0 from "@keystatic/core/reader/github";
|
|
4
|
+
import { createGitHubReader } from "@keystatic/core/reader/github";
|
|
5
|
+
import * as _keystatic_core0 from "@keystatic/core";
|
|
6
|
+
import { Collection, ComponentSchema, Config, Singleton } from "@keystatic/core";
|
|
7
|
+
import * as url0 from "url";
|
|
8
|
+
import { MDXModule } from "mdx/types";
|
|
9
9
|
|
|
10
|
+
//#region src/reader.d.ts
|
|
10
11
|
type GitHubReaderConfig = Parameters<typeof createGitHubReader>[1];
|
|
11
|
-
declare function createReader<TCollections extends Record<string, Collection<Record<string, ComponentSchema>, string>>, TSingletons extends Record<string, Singleton<Record<string, ComponentSchema>>>>(config: Config<TCollections, TSingletons>, getGitHubReaderConfig?: () => GitHubReaderConfig | null):
|
|
12
|
+
declare function createReader<TCollections extends Record<string, Collection<Record<string, ComponentSchema>, string>>, TSingletons extends Record<string, Singleton<Record<string, ComponentSchema>>>>(config: Config<TCollections, TSingletons>, getGitHubReaderConfig?: () => GitHubReaderConfig | null): _keystatic_core_reader_github0.Reader<TCollections, TSingletons>;
|
|
12
13
|
declare function createReaders<TCollections extends Record<string, Collection<Record<string, ComponentSchema>, string>>, TSingletons extends Record<string, Singleton<Record<string, ComponentSchema>>>, TLocale extends Locale, TMdxContent extends MDXModule>(config: Config<TCollections, TSingletons>, getMdxContent: (code: string, locale: TLocale, baseUrl: URL) => Promise<TMdxContent>): {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
14
|
+
createCollectionResource: <TKeys extends WithoutI18nPrefix<keyof TCollections & string, TLocale>>(name: TKeys, locale: TLocale) => {
|
|
15
|
+
all: () => Promise<{
|
|
16
|
+
collection: TKeys;
|
|
17
|
+
id: string;
|
|
18
|
+
md5: string;
|
|
19
|
+
data: TCollections[`${TLocale}:${TKeys}`]["schema"] extends infer T extends Record<string, ComponentSchema> ? { [Key in keyof T]: SlugField extends Key ? T[Key] extends _keystatic_core0.SlugFormField<any, any, any, infer SlugSerializedValue> ? SlugSerializedValue : (Opts[0] extends infer T_1 ? T_1 extends Opts[0] ? T_1 extends {} ? T_1["resolveLinkedFiles"] : undefined : never : never) extends infer T_2 ? T_2 extends (Opts[0] extends infer T_3 ? T_3 extends Opts[0] ? T_3 extends {} ? T_3["resolveLinkedFiles"] : undefined : never : never) ? T_2 extends true ? _keystatic_core0.ValueForReadingDeep<T[Key]> : _keystatic_core0.ValueForReading<T[Key]> : never : never : (Opts[0] extends infer T_4 ? T_4 extends Opts[0] ? T_4 extends {} ? T_4["resolveLinkedFiles"] : undefined : never : never) extends infer T_5 ? T_5 extends (Opts[0] extends infer T_6 ? T_6 extends Opts[0] ? T_6 extends {} ? T_6["resolveLinkedFiles"] : undefined : never : never) ? T_5 extends true ? _keystatic_core0.ValueForReadingDeep<T[Key]> : _keystatic_core0.ValueForReading<T[Key]> : never : never } : never;
|
|
20
|
+
compile(code: string): Promise<TMdxContent>;
|
|
21
|
+
}[]>;
|
|
22
|
+
baseUrl: (id: string) => url0.URL;
|
|
23
|
+
compile: (id: string, code: string) => Promise<TMdxContent>;
|
|
24
|
+
list: () => Promise<string[]>;
|
|
25
|
+
read: (id: string) => Promise<{
|
|
26
|
+
collection: TKeys;
|
|
27
|
+
id: string;
|
|
28
|
+
md5: string;
|
|
29
|
+
data: TCollections[`${TLocale}:${TKeys}`]["schema"] extends infer T extends Record<string, ComponentSchema> ? { [Key in keyof T]: SlugField extends Key ? T[Key] extends _keystatic_core0.SlugFormField<any, any, any, infer SlugSerializedValue> ? SlugSerializedValue : (Opts[0] extends infer T_1 ? T_1 extends Opts[0] ? T_1 extends {} ? T_1["resolveLinkedFiles"] : undefined : never : never) extends infer T_2 ? T_2 extends (Opts[0] extends infer T_3 ? T_3 extends Opts[0] ? T_3 extends {} ? T_3["resolveLinkedFiles"] : undefined : never : never) ? T_2 extends true ? _keystatic_core0.ValueForReadingDeep<T[Key]> : _keystatic_core0.ValueForReading<T[Key]> : never : never : (Opts[0] extends infer T_4 ? T_4 extends Opts[0] ? T_4 extends {} ? T_4["resolveLinkedFiles"] : undefined : never : never) extends infer T_5 ? T_5 extends (Opts[0] extends infer T_6 ? T_6 extends Opts[0] ? T_6 extends {} ? T_6["resolveLinkedFiles"] : undefined : never : never) ? T_5 extends true ? _keystatic_core0.ValueForReadingDeep<T[Key]> : _keystatic_core0.ValueForReading<T[Key]> : never : never } : never;
|
|
30
|
+
compile(code: string): Promise<TMdxContent>;
|
|
31
|
+
}>;
|
|
32
|
+
};
|
|
33
|
+
createSingletonResource: <TKeys extends WithoutI18nPrefix<keyof TSingletons & string, TLocale>>(name: TKeys, locale: TLocale) => {
|
|
34
|
+
baseUrl: () => url0.URL;
|
|
35
|
+
compile: (code: string) => Promise<TMdxContent>;
|
|
36
|
+
read: () => Promise<{
|
|
37
|
+
singleton: TKeys;
|
|
38
|
+
md5: string;
|
|
39
|
+
data: TSingletons[`${TLocale}:${TKeys}`]["schema"] extends infer T extends Record<string, ComponentSchema> ? { readonly [Key in keyof T]: _keystatic_core0.ValueForReadingDeep<T[Key]> } : never;
|
|
40
|
+
compile: (code: string) => Promise<TMdxContent>;
|
|
41
|
+
}>;
|
|
42
|
+
};
|
|
42
43
|
};
|
|
43
|
-
|
|
44
|
+
//#endregion
|
|
44
45
|
export { createReader, createReaders };
|
|
46
|
+
//# sourceMappingURL=reader.d.ts.map
|
package/dist/reader.js
CHANGED
|
@@ -1,94 +1,93 @@
|
|
|
1
|
-
import { withI18nPrefix } from
|
|
2
|
-
import assert from
|
|
3
|
-
import { createHash } from
|
|
4
|
-
import { join } from
|
|
5
|
-
import { pathToFileURL } from
|
|
6
|
-
import { serialize } from
|
|
7
|
-
import { createReader as createReader$1 } from
|
|
8
|
-
import { createGitHubReader } from
|
|
1
|
+
import { withI18nPrefix } from "./with-i18n-prefix.js";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { serialize } from "node:v8";
|
|
7
|
+
import { createReader as createReader$1 } from "@keystatic/core/reader";
|
|
8
|
+
import { createGitHubReader } from "@keystatic/core/reader/github";
|
|
9
9
|
|
|
10
|
+
//#region src/reader.ts
|
|
10
11
|
function createReader(config, getGitHubReaderConfig) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
return createReader$1(process.cwd(), config);
|
|
12
|
+
const gitHubConfig = getGitHubReaderConfig?.();
|
|
13
|
+
if (gitHubConfig != null) return createGitHubReader(config, gitHubConfig);
|
|
14
|
+
return createReader$1(process.cwd(), config);
|
|
16
15
|
}
|
|
17
16
|
function createReaders(config, getMdxContent) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
17
|
+
function createCollectionResource(name, locale) {
|
|
18
|
+
const reader = createReader(config);
|
|
19
|
+
const collectionName = withI18nPrefix(name, locale);
|
|
20
|
+
const collectionReader = reader.collections[collectionName];
|
|
21
|
+
const collectionConfig = reader.config.collections?.[collectionName];
|
|
22
|
+
assert(collectionConfig?.path);
|
|
23
|
+
function baseUrl(id) {
|
|
24
|
+
return pathToFileURL(join(process.cwd(), collectionConfig.path.replace(/\*+/, id)));
|
|
25
|
+
}
|
|
26
|
+
async function compile(id, code) {
|
|
27
|
+
return getMdxContent(code, locale, baseUrl(id));
|
|
28
|
+
}
|
|
29
|
+
function list() {
|
|
30
|
+
return collectionReader.list();
|
|
31
|
+
}
|
|
32
|
+
async function read(id) {
|
|
33
|
+
const data = await collectionReader.readOrThrow(id, { resolveLinkedFiles: true });
|
|
34
|
+
const md5 = createHash("md5").update(serialize(data)).digest("hex");
|
|
35
|
+
return {
|
|
36
|
+
collection: name,
|
|
37
|
+
id,
|
|
38
|
+
md5,
|
|
39
|
+
data,
|
|
40
|
+
compile(code) {
|
|
41
|
+
return compile(id, code);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async function all() {
|
|
46
|
+
const ids = await list();
|
|
47
|
+
return Promise.all(ids.map(read));
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
all,
|
|
51
|
+
baseUrl,
|
|
52
|
+
compile,
|
|
53
|
+
list,
|
|
54
|
+
read
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function createSingletonResource(name, locale) {
|
|
58
|
+
const reader = createReader(config);
|
|
59
|
+
const i18nName = withI18nPrefix(name, locale);
|
|
60
|
+
const singletonReader = reader.singletons[i18nName];
|
|
61
|
+
const singletonConfig = reader.config.singletons?.[i18nName];
|
|
62
|
+
assert(singletonConfig?.path);
|
|
63
|
+
function baseUrl() {
|
|
64
|
+
return pathToFileURL(join(process.cwd(), singletonConfig.path));
|
|
65
|
+
}
|
|
66
|
+
async function compile(code) {
|
|
67
|
+
return getMdxContent(code, locale, baseUrl());
|
|
68
|
+
}
|
|
69
|
+
async function read() {
|
|
70
|
+
const data = await singletonReader.readOrThrow({ resolveLinkedFiles: true });
|
|
71
|
+
const md5 = createHash("md5").update(serialize(data)).digest("hex");
|
|
72
|
+
return {
|
|
73
|
+
singleton: name,
|
|
74
|
+
md5,
|
|
75
|
+
data,
|
|
76
|
+
compile
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
baseUrl,
|
|
81
|
+
compile,
|
|
82
|
+
read
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
createCollectionResource,
|
|
87
|
+
createSingletonResource
|
|
88
|
+
};
|
|
90
89
|
}
|
|
91
90
|
|
|
91
|
+
//#endregion
|
|
92
92
|
export { createReader, createReaders };
|
|
93
|
-
//# sourceMappingURL=reader.js.map
|
|
94
93
|
//# sourceMappingURL=reader.js.map
|
package/dist/reader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"reader.js","names":["createLocalReader"],"sources":["../src/reader.ts"],"sourcesContent":["import assert from \"node:assert/strict\";\nimport { createHash } from \"node:crypto\";\nimport { join } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { serialize } from \"node:v8\";\n\nimport type { Collection, ComponentSchema, Config, Singleton } from \"@keystatic/core\";\nimport { createReader as createLocalReader } from \"@keystatic/core/reader\";\nimport { createGitHubReader } from \"@keystatic/core/reader/github\";\nimport type { MDXModule } from \"mdx/types\";\n\nimport type { Locale } from \"./config\";\nimport { withI18nPrefix, type WithoutI18nPrefix } from \"./with-i18n-prefix\";\n\ntype GitHubReaderConfig = Parameters<typeof createGitHubReader>[1];\n\nexport function createReader<\n\tTCollections extends Record<string, Collection<Record<string, ComponentSchema>, string>>,\n\tTSingletons extends Record<string, Singleton<Record<string, ComponentSchema>>>,\n>(\n\tconfig: Config<TCollections, TSingletons>,\n\tgetGitHubReaderConfig?: () => GitHubReaderConfig | null,\n) {\n\tconst gitHubConfig = getGitHubReaderConfig?.();\n\n\tif (gitHubConfig != null) {\n\t\treturn createGitHubReader(config, gitHubConfig);\n\t}\n\n\treturn createLocalReader(process.cwd(), config);\n}\n\nexport function createReaders<\n\tTCollections extends Record<string, Collection<Record<string, ComponentSchema>, string>>,\n\tTSingletons extends Record<string, Singleton<Record<string, ComponentSchema>>>,\n\tTLocale extends Locale,\n\tTMdxContent extends MDXModule,\n>(\n\tconfig: Config<TCollections, TSingletons>,\n\tgetMdxContent: (code: string, locale: TLocale, baseUrl: URL) => Promise<TMdxContent>,\n) {\n\tfunction createCollectionResource<\n\t\tTKeys extends WithoutI18nPrefix<keyof TCollections & string, TLocale>,\n\t>(name: TKeys, locale: TLocale) {\n\t\tconst reader = createReader(config);\n\t\tconst collectionName = withI18nPrefix(name, locale);\n\n\t\tconst collectionReader = reader.collections[collectionName];\n\t\tconst collectionConfig = reader.config.collections?.[collectionName];\n\n\t\tassert(collectionConfig?.path);\n\n\t\tfunction baseUrl(id: string) {\n\t\t\treturn pathToFileURL(join(process.cwd(), collectionConfig!.path!.replace(/\\*+/, id)));\n\t\t}\n\n\t\tasync function compile(id: string, code: string) {\n\t\t\treturn getMdxContent(code, locale, baseUrl(id));\n\t\t}\n\n\t\tfunction list() {\n\t\t\treturn collectionReader.list();\n\t\t}\n\n\t\tasync function read(id: string) {\n\t\t\tconst data = await collectionReader.readOrThrow(id, { resolveLinkedFiles: true });\n\t\t\tconst md5 = createHash(\"md5\").update(serialize(data)).digest(\"hex\");\n\n\t\t\treturn {\n\t\t\t\tcollection: name,\n\t\t\t\tid,\n\t\t\t\tmd5,\n\t\t\t\tdata,\n\t\t\t\tcompile(code: string) {\n\t\t\t\t\treturn compile(id, code);\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\tasync function all() {\n\t\t\tconst ids = await list();\n\n\t\t\treturn Promise.all(ids.map(read));\n\t\t}\n\n\t\treturn {\n\t\t\tall,\n\t\t\tbaseUrl,\n\t\t\tcompile,\n\t\t\tlist,\n\t\t\tread,\n\t\t};\n\t}\n\n\tfunction createSingletonResource<\n\t\tTKeys extends WithoutI18nPrefix<keyof TSingletons & string, TLocale>,\n\t>(name: TKeys, locale: TLocale) {\n\t\tconst reader = createReader(config);\n\t\tconst i18nName = withI18nPrefix(name, locale);\n\n\t\tconst singletonReader = reader.singletons[i18nName];\n\t\tconst singletonConfig = reader.config.singletons?.[i18nName];\n\n\t\tassert(singletonConfig?.path);\n\n\t\tfunction baseUrl() {\n\t\t\treturn pathToFileURL(join(process.cwd(), singletonConfig!.path!));\n\t\t}\n\n\t\tasync function compile(code: string) {\n\t\t\treturn getMdxContent(code, locale, baseUrl());\n\t\t}\n\n\t\tasync function read() {\n\t\t\tconst data = await singletonReader.readOrThrow({ resolveLinkedFiles: true });\n\t\t\tconst md5 = createHash(\"md5\").update(serialize(data)).digest(\"hex\");\n\n\t\t\treturn {\n\t\t\t\tsingleton: name,\n\t\t\t\tmd5,\n\t\t\t\tdata,\n\t\t\t\tcompile,\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tbaseUrl,\n\t\t\tcompile,\n\t\t\tread,\n\t\t};\n\t}\n\n\treturn {\n\t\tcreateCollectionResource,\n\t\tcreateSingletonResource,\n\t};\n}\n"],"mappings":";;;;;;;;;;AAgBA,SAAgB,aAIf,QACA,uBACC;CACD,MAAM,eAAe;AAErB,KAAI,gBAAgB,KACnB,QAAO,mBAAmB,QAAQ;AAGnC,QAAOA,eAAkB,QAAQ,OAAO;;AAGzC,SAAgB,cAMf,QACA,eACC;CACD,SAAS,yBAEP,MAAa,QAAiB;EAC/B,MAAM,SAAS,aAAa;EAC5B,MAAM,iBAAiB,eAAe,MAAM;EAE5C,MAAM,mBAAmB,OAAO,YAAY;EAC5C,MAAM,mBAAmB,OAAO,OAAO,cAAc;AAErD,SAAO,kBAAkB;EAEzB,SAAS,QAAQ,IAAY;AAC5B,UAAO,cAAc,KAAK,QAAQ,OAAO,iBAAkB,KAAM,QAAQ,OAAO;;EAGjF,eAAe,QAAQ,IAAY,MAAc;AAChD,UAAO,cAAc,MAAM,QAAQ,QAAQ;;EAG5C,SAAS,OAAO;AACf,UAAO,iBAAiB;;EAGzB,eAAe,KAAK,IAAY;GAC/B,MAAM,OAAO,MAAM,iBAAiB,YAAY,IAAI,EAAE,oBAAoB;GAC1E,MAAM,MAAM,WAAW,OAAO,OAAO,UAAU,OAAO,OAAO;AAE7D,UAAO;IACN,YAAY;IACZ;IACA;IACA;IACA,QAAQ,MAAc;AACrB,YAAO,QAAQ,IAAI;;;;EAKtB,eAAe,MAAM;GACpB,MAAM,MAAM,MAAM;AAElB,UAAO,QAAQ,IAAI,IAAI,IAAI;;AAG5B,SAAO;GACN;GACA;GACA;GACA;GACA;;;CAIF,SAAS,wBAEP,MAAa,QAAiB;EAC/B,MAAM,SAAS,aAAa;EAC5B,MAAM,WAAW,eAAe,MAAM;EAEtC,MAAM,kBAAkB,OAAO,WAAW;EAC1C,MAAM,kBAAkB,OAAO,OAAO,aAAa;AAEnD,SAAO,iBAAiB;EAExB,SAAS,UAAU;AAClB,UAAO,cAAc,KAAK,QAAQ,OAAO,gBAAiB;;EAG3D,eAAe,QAAQ,MAAc;AACpC,UAAO,cAAc,MAAM,QAAQ;;EAGpC,eAAe,OAAO;GACrB,MAAM,OAAO,MAAM,gBAAgB,YAAY,EAAE,oBAAoB;GACrE,MAAM,MAAM,WAAW,OAAO,OAAO,UAAU,OAAO,OAAO;AAE7D,UAAO;IACN,WAAW;IACX;IACA;IACA;;;AAIF,SAAO;GACN;GACA;GACA;;;AAIF,QAAO;EACN;EACA"}
|
package/dist/resources.d.ts
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Locale } from "./config.js";
|
|
2
|
+
import { Collection, ComponentSchema, Singleton } from "@keystatic/core";
|
|
3
3
|
|
|
4
|
+
//#region src/resources.d.ts
|
|
4
5
|
declare function createPaths<TPath extends `/${string}/`>(path: TPath, locale: Locale): {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
readonly assetPath: `/content/assets/${string}${TPath}`;
|
|
7
|
+
readonly downloadPath: `/content/downloads/${string}${TPath}`;
|
|
7
8
|
};
|
|
8
9
|
type Paths<TPath extends `/${string}/`> = ReturnType<typeof createPaths<TPath>>;
|
|
9
10
|
declare function createCollectionPaths<TPath extends `/${string}/`>(path: TPath, locale: Locale): {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
readonly contentPath: `./content/${string}${TPath}*/`;
|
|
12
|
+
readonly assetPath: `/content/assets/${string}${TPath}`;
|
|
13
|
+
readonly downloadPath: `/content/downloads/${string}${TPath}`;
|
|
13
14
|
};
|
|
14
15
|
declare function createSingletonPaths<TPath extends `/${string}/`>(path: TPath, locale: Locale): {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
readonly contentPath: `./content/${string}${TPath}`;
|
|
17
|
+
readonly assetPath: `/content/assets/${string}${TPath}`;
|
|
18
|
+
readonly downloadPath: `/content/downloads/${string}${TPath}`;
|
|
18
19
|
};
|
|
19
20
|
declare function createCollection<TPath extends `/${string}/`, TLocale extends Locale, TSchema extends Record<string, ComponentSchema>, TSlugField extends string>(path: TPath, createLocalisedCollectionFactory: (paths: ReturnType<typeof createCollectionPaths<TPath>>, locale: TLocale) => Collection<TSchema, TSlugField>): (locale: TLocale) => Collection<TSchema, TSlugField>;
|
|
20
21
|
declare function createSingleton<TPath extends `/${string}/`, TLocale extends Locale, TSchema extends Record<string, ComponentSchema>>(path: TPath, createLocalisedSingletonFactory: (paths: ReturnType<typeof createSingletonPaths<TPath>>, locale: TLocale) => Singleton<TSchema>): (locale: TLocale) => Singleton<TSchema>;
|
|
21
|
-
|
|
22
|
-
export {
|
|
22
|
+
//#endregion
|
|
23
|
+
export { Paths, createCollection, createCollectionPaths, createPaths, createSingleton, createSingletonPaths };
|
|
24
|
+
//# sourceMappingURL=resources.d.ts.map
|
package/dist/resources.js
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/resources.ts
|
|
2
|
+
function createPaths(path, locale) {
|
|
3
|
+
return {
|
|
4
|
+
assetPath: `/content/assets/${locale}${path}`,
|
|
5
|
+
downloadPath: `/content/downloads/${locale}${path}`
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
function createCollectionPaths(path, locale) {
|
|
9
|
+
return {
|
|
10
|
+
...createPaths(path, locale),
|
|
11
|
+
contentPath: `./content/${locale}${path}*/`
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function createSingletonPaths(path, locale) {
|
|
15
|
+
return {
|
|
16
|
+
...createPaths(path, locale),
|
|
17
|
+
contentPath: `./content/${locale}${path}`
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function createCollection(path, createLocalisedCollectionFactory) {
|
|
21
|
+
return function createLocalisedCollection(locale) {
|
|
22
|
+
const paths = createCollectionPaths(path, locale);
|
|
23
|
+
return createLocalisedCollectionFactory(paths, locale);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function createSingleton(path, createLocalisedSingletonFactory) {
|
|
27
|
+
return function createLocalisedSingleton(locale) {
|
|
28
|
+
const paths = createSingletonPaths(path, locale);
|
|
29
|
+
return createLocalisedSingletonFactory(paths, locale);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { createCollection, createCollectionPaths, createPaths, createSingleton, createSingletonPaths };
|
|
3
35
|
//# sourceMappingURL=resources.js.map
|
package/dist/resources.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"resources.js","names":[],"sources":["../src/resources.ts"],"sourcesContent":["import type { Collection, ComponentSchema, Singleton } from \"@keystatic/core\";\n\nimport type { Locale } from \"./config\";\n\nexport function createPaths<TPath extends `/${string}/`>(path: TPath, locale: Locale) {\n\treturn {\n\t\tassetPath: `/content/assets/${locale}${path}`,\n\t\tdownloadPath: `/content/downloads/${locale}${path}`,\n\t} as const;\n}\n\nexport type Paths<TPath extends `/${string}/`> = ReturnType<typeof createPaths<TPath>>;\n\nexport function createCollectionPaths<TPath extends `/${string}/`>(path: TPath, locale: Locale) {\n\treturn {\n\t\t...createPaths(path, locale),\n\t\tcontentPath: `./content/${locale}${path}*/`,\n\t} as const;\n}\n\nexport function createSingletonPaths<TPath extends `/${string}/`>(path: TPath, locale: Locale) {\n\treturn {\n\t\t...createPaths(path, locale),\n\t\tcontentPath: `./content/${locale}${path}`,\n\t} as const;\n}\n\nexport function createCollection<\n\tTPath extends `/${string}/`,\n\tTLocale extends Locale,\n\tTSchema extends Record<string, ComponentSchema>,\n\tTSlugField extends string,\n>(\n\tpath: TPath,\n\tcreateLocalisedCollectionFactory: (\n\t\tpaths: ReturnType<typeof createCollectionPaths<TPath>>,\n\t\tlocale: TLocale,\n\t) => Collection<TSchema, TSlugField>,\n) {\n\treturn function createLocalisedCollection(locale: TLocale) {\n\t\tconst paths = createCollectionPaths(path, locale);\n\t\treturn createLocalisedCollectionFactory(paths, locale);\n\t};\n}\n\nexport function createSingleton<\n\tTPath extends `/${string}/`,\n\tTLocale extends Locale,\n\tTSchema extends Record<string, ComponentSchema>,\n>(\n\tpath: TPath,\n\tcreateLocalisedSingletonFactory: (\n\t\tpaths: ReturnType<typeof createSingletonPaths<TPath>>,\n\t\tlocale: TLocale,\n\t) => Singleton<TSchema>,\n) {\n\treturn function createLocalisedSingleton(locale: TLocale) {\n\t\tconst paths = createSingletonPaths(path, locale);\n\t\treturn createLocalisedSingletonFactory(paths, locale);\n\t};\n}\n"],"mappings":";AAIA,SAAgB,YAAyC,MAAa,QAAgB;AACrF,QAAO;EACN,WAAW,mBAAmB,SAAS;EACvC,cAAc,sBAAsB,SAAS;;;AAM/C,SAAgB,sBAAmD,MAAa,QAAgB;AAC/F,QAAO;EACN,GAAG,YAAY,MAAM;EACrB,aAAa,aAAa,SAAS,KAAK;;;AAI1C,SAAgB,qBAAkD,MAAa,QAAgB;AAC9F,QAAO;EACN,GAAG,YAAY,MAAM;EACrB,aAAa,aAAa,SAAS;;;AAIrC,SAAgB,iBAMf,MACA,kCAIC;AACD,QAAO,SAAS,0BAA0B,QAAiB;EAC1D,MAAM,QAAQ,sBAAsB,MAAM;AAC1C,SAAO,iCAAiC,OAAO;;;AAIjD,SAAgB,gBAKf,MACA,iCAIC;AACD,QAAO,SAAS,yBAAyB,QAAiB;EACzD,MAAM,QAAQ,qBAAqB,MAAM;AACzC,SAAO,gCAAgC,OAAO"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { Locale } from
|
|
1
|
+
import { Locale } from "./config.js";
|
|
2
2
|
|
|
3
|
+
//#region src/with-i18n-prefix.d.ts
|
|
3
4
|
declare function withI18nPrefix<TLabel extends string, TLocale extends Locale>(label: TLabel, locale: TLocale): `${TLocale}:${TLabel}`;
|
|
4
5
|
type WithoutI18nPrefix<T extends string, TLocale extends Locale> = T extends `${TLocale}:${infer U}` ? U : T;
|
|
5
|
-
|
|
6
|
-
export {
|
|
6
|
+
//#endregion
|
|
7
|
+
export { WithoutI18nPrefix, withI18nPrefix };
|
|
8
|
+
//# sourceMappingURL=with-i18n-prefix.d.ts.map
|
package/dist/with-i18n-prefix.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/with-i18n-prefix.ts
|
|
2
|
+
function withI18nPrefix(label, locale) {
|
|
3
|
+
return `${locale}:${label}`;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
export { withI18nPrefix };
|
|
3
8
|
//# sourceMappingURL=with-i18n-prefix.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"with-i18n-prefix.js","names":[],"sources":["../src/with-i18n-prefix.ts"],"sourcesContent":["import type { Locale } from \"./config\";\n\nexport function withI18nPrefix<TLabel extends string, TLocale extends Locale>(\n\tlabel: TLabel,\n\tlocale: TLocale,\n) {\n\treturn `${locale}:${label}` as const;\n}\n\nexport type WithoutI18nPrefix<\n\tT extends string,\n\tTLocale extends Locale,\n> = T extends `${TLocale}:${infer U}` ? U : T;\n"],"mappings":";AAEA,SAAgB,eACf,OACA,QACC;AACD,QAAO,GAAG,OAAO,GAAG"}
|
package/license
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2024 Austrian Centre for Digital Humanities
|
|
3
|
+
Copyright (c) 2024-2025 Austrian Centre for Digital Humanities
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
6
6
|
associated documentation files (the "Software"), to deal in the Software without restriction,
|
package/package.json
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acdh-oeaw/keystatic-lib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": "22.x || 24.x"
|
|
8
|
+
},
|
|
9
|
+
"devEngines": {
|
|
10
|
+
"runtime": {
|
|
11
|
+
"name": "node",
|
|
12
|
+
"version": "22.x",
|
|
13
|
+
"onFail": "download"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
6
16
|
"exports": {
|
|
7
17
|
".": "./dist/index.js",
|
|
18
|
+
"./fields/*": "./dist/fields/*.js",
|
|
8
19
|
"./preview": "./dist/preview/index.js",
|
|
9
20
|
"./reader": "./dist/reader.js"
|
|
10
21
|
},
|
|
@@ -12,49 +23,49 @@
|
|
|
12
23
|
"dist"
|
|
13
24
|
],
|
|
14
25
|
"sideEffects": false,
|
|
15
|
-
"engines": {
|
|
16
|
-
"node": ">=22",
|
|
17
|
-
"pnpm": "9.x"
|
|
18
|
-
},
|
|
19
26
|
"dependencies": {
|
|
20
27
|
"@sindresorhus/slugify": "^2.2.1",
|
|
21
28
|
"@types/mdx": "^2.0.13"
|
|
22
29
|
},
|
|
23
30
|
"peerDependencies": {
|
|
31
|
+
"@keystar/ui": "0.x",
|
|
24
32
|
"@keystatic/core": "0.x"
|
|
25
33
|
},
|
|
26
34
|
"devDependencies": {
|
|
27
35
|
"@acdh-oeaw/commitlint-config": "^2.0.0",
|
|
28
|
-
"@acdh-oeaw/eslint-config": "^2.0.
|
|
29
|
-
"@acdh-oeaw/eslint-config-node": "^2.0.
|
|
30
|
-
"@acdh-oeaw/eslint-config-react": "^2.0.
|
|
31
|
-
"@acdh-oeaw/prettier-config": "^2.0.
|
|
32
|
-
"@acdh-oeaw/tsconfig-lib": "^1.
|
|
33
|
-
"@changesets/changelog-github": "^0.5.
|
|
34
|
-
"@changesets/cli": "^2.
|
|
35
|
-
"@commitlint/cli": "^19.
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"@types/
|
|
39
|
-
"
|
|
40
|
-
"eslint
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
36
|
+
"@acdh-oeaw/eslint-config": "^2.0.9",
|
|
37
|
+
"@acdh-oeaw/eslint-config-node": "^2.0.9",
|
|
38
|
+
"@acdh-oeaw/eslint-config-react": "^2.0.13",
|
|
39
|
+
"@acdh-oeaw/prettier-config": "^2.0.1",
|
|
40
|
+
"@acdh-oeaw/tsconfig-lib": "^1.3.0",
|
|
41
|
+
"@changesets/changelog-github": "^0.5.1",
|
|
42
|
+
"@changesets/cli": "^2.29.6",
|
|
43
|
+
"@commitlint/cli": "^19.8.1",
|
|
44
|
+
"@keystar/ui": "^0.7.19",
|
|
45
|
+
"@keystatic/core": "^0.5.48",
|
|
46
|
+
"@types/node": "^22.18.0",
|
|
47
|
+
"@types/react": "^19.1.11",
|
|
48
|
+
"eslint": "^9.34.0",
|
|
49
|
+
"eslint-config-flat-gitignore": "^2.1.0",
|
|
50
|
+
"globals": "^16.3.0",
|
|
51
|
+
"is-in-ci": "^2.0.0",
|
|
52
|
+
"lint-staged": "^16.1.5",
|
|
53
|
+
"npm-run-all2": "^8.0.4",
|
|
54
|
+
"prettier": "^3.6.2",
|
|
55
|
+
"react": "^19.1.1",
|
|
56
|
+
"simple-git-hooks": "^2.13.1",
|
|
57
|
+
"tsdown": "^0.14.2",
|
|
58
|
+
"tsx": "^4.20.5",
|
|
59
|
+
"typescript": "^5.9.2",
|
|
60
|
+
"typescript-eslint": "^8.41.0",
|
|
61
|
+
"node": "runtime:22.x"
|
|
51
62
|
},
|
|
52
63
|
"commitlint": {
|
|
53
64
|
"extends": "@acdh-oeaw/commitlint-config"
|
|
54
65
|
},
|
|
55
66
|
"lint-staged": {
|
|
56
67
|
"*.ts": [
|
|
57
|
-
"eslint --
|
|
68
|
+
"eslint --fix",
|
|
58
69
|
"prettier --cache --cache-location ./.prettiercache --write"
|
|
59
70
|
],
|
|
60
71
|
"*.!(ts)": "prettier --cache --cache-location ./.prettiercache --ignore-unknown --write"
|
|
@@ -66,18 +77,18 @@
|
|
|
66
77
|
"pre-push": "pnpm run validate"
|
|
67
78
|
},
|
|
68
79
|
"scripts": {
|
|
69
|
-
"build": "
|
|
80
|
+
"build": "tsdown",
|
|
70
81
|
"changeset:add": "changeset add",
|
|
71
82
|
"changeset:status": "changeset status --verbose",
|
|
72
83
|
"ci:release": "changeset publish",
|
|
73
84
|
"ci:version": "changeset version && prettier \"**/CHANGELOG.md\" --write",
|
|
74
85
|
"format:check": "prettier . --cache --cache-location ./.prettiercache --check --ignore-path ./.gitignore",
|
|
75
86
|
"format:fix": "pnpm run format:check --write",
|
|
76
|
-
"lint:check": "eslint .
|
|
87
|
+
"lint:check": "eslint .",
|
|
77
88
|
"lint:fix": "pnpm run lint:check --fix",
|
|
78
|
-
"setup": "is-ci || simple-git-hooks",
|
|
89
|
+
"setup": "is-in-ci || simple-git-hooks",
|
|
79
90
|
"test": "tsx --test --test-reporter spec",
|
|
80
91
|
"types:check": "tsc --noEmit",
|
|
81
|
-
"validate": "run-
|
|
92
|
+
"validate": "run-s format:check lint:check types:check test"
|
|
82
93
|
}
|
|
83
94
|
}
|