@acdh-oeaw/keystatic-lib 0.1.2 → 0.3.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/{chunk-FVPLAXGT.js → chunk-X5LBXMLP.js} +2 -2
- package/dist/chunk-X5LBXMLP.js.map +1 -0
- package/dist/create-component.d.ts +1 -1
- package/dist/create-component.js +1 -1
- package/dist/index.js +1 -1
- package/dist/preview/index.d.ts +4 -0
- package/dist/preview/index.js +24 -0
- package/dist/preview/index.js.map +1 -0
- package/dist/reader.d.ts +3 -6
- package/dist/reader.js.map +1 -1
- package/package.json +10 -6
- package/dist/chunk-FVPLAXGT.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/create-component.ts"],"names":["createComponent"],"mappings":";AAIO,SAAS,gBAId,sBAA4E,EAAA;AAC7E,EAAO,OAAA,SAASA,gBAAgB,CAAA,SAAA,EAAkB,MAAiB,EAAA;AAClE,IAAO,OAAA,sBAAA,CAAuB,WAAW,MAAM,CAAA,CAAA;AAAA,GAChD,CAAA;AACD","file":"chunk-X5LBXMLP.js","sourcesContent":["import type { ContentComponent } from \"@keystatic/core/content-components\";\n\nimport type { Locale } from \"./config\";\n\nexport function createComponent<\n\tTPath extends `/${string}/`,\n\tTLocale extends Locale,\n\tTComponents extends Record<string, ContentComponent>,\n>(createComponentFactory: (assetPath: TPath, locale: TLocale) => TComponents) {\n\treturn function createComponent(assetPath: TPath, locale: TLocale) {\n\t\treturn createComponentFactory(assetPath, locale);\n\t};\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ContentComponent } from '@keystatic/core/content-components';
|
|
2
2
|
import { Locale } from './config.js';
|
|
3
3
|
|
|
4
|
-
declare function createComponent<TPath extends `/${string}/`, TLocale extends Locale,
|
|
4
|
+
declare function createComponent<TPath extends `/${string}/`, TLocale extends Locale, TComponents extends Record<string, ContentComponent>>(createComponentFactory: (assetPath: TPath, locale: TLocale) => TComponents): (assetPath: TPath, locale: TLocale) => TComponents;
|
|
5
5
|
|
|
6
6
|
export { createComponent };
|
package/dist/create-component.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createComponent } from './chunk-
|
|
1
|
+
export { createComponent } from './chunk-X5LBXMLP.js';
|
|
2
2
|
export { createContentFieldOptions } from './chunk-EAFZLNV4.js';
|
|
3
3
|
export { createAssetOptions } from './chunk-5ZKY25OZ.js';
|
|
4
4
|
export { createLabel } from './chunk-CI4JBTGG.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
// src/preview/index.ts
|
|
4
|
+
function useObjectUrl(data, contentType) {
|
|
5
|
+
const [url, setUrl] = useState(null);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (data == null) {
|
|
8
|
+
setUrl(null);
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
const url2 = URL.createObjectURL(
|
|
12
|
+
new Blob([data], contentType ? { type: contentType } : void 0)
|
|
13
|
+
);
|
|
14
|
+
setUrl(url2);
|
|
15
|
+
return () => {
|
|
16
|
+
URL.revokeObjectURL(url2);
|
|
17
|
+
};
|
|
18
|
+
}, [contentType, data]);
|
|
19
|
+
return url;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { useObjectUrl };
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/preview/index.ts"],"names":["url"],"mappings":";;;AAGO,SAAS,YAAA,CAAa,MAAyB,WAAiC,EAAA;AACtF,EAAA,MAAM,CAAC,GAAA,EAAK,MAAM,CAAA,GAAI,SAAwB,IAAI,CAAA,CAAA;AAElD,EAAA,SAAA,CAAU,MAAM;AACf,IAAA,IAAI,QAAQ,IAAM,EAAA;AACjB,MAAA,MAAA,CAAO,IAAI,CAAA,CAAA;AACX,MAAO,OAAA,KAAA,CAAA,CAAA;AAAA,KACR;AAEA,IAAA,MAAMA,OAAM,GAAI,CAAA,eAAA;AAAA,MACf,IAAI,IAAK,CAAA,CAAC,IAAI,CAAA,EAAG,cAAc,EAAE,IAAA,EAAM,WAAY,EAAA,GAAI,KAAS,CAAA,CAAA;AAAA,KACjE,CAAA;AACA,IAAA,MAAA,CAAOA,IAAG,CAAA,CAAA;AAEV,IAAA,OAAO,MAAM;AACZ,MAAA,GAAA,CAAI,gBAAgBA,IAAG,CAAA,CAAA;AAAA,KACxB,CAAA;AAAA,GACE,EAAA,CAAC,WAAa,EAAA,IAAI,CAAC,CAAA,CAAA;AAEtB,EAAO,OAAA,GAAA,CAAA;AACR","file":"index.js","sourcesContent":["import { useEffect, useState } from \"react\";\n\n/** @see https://github.com/Thinkmill/keystatic/blob/main/packages/keystatic/src/form/fields/image/ui.tsx#L48-L63 */\nexport function useObjectUrl(data: Uint8Array | null, contentType: string | undefined) {\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], 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"]}
|
package/dist/reader.d.ts
CHANGED
|
@@ -2,16 +2,13 @@ import * as url from 'url';
|
|
|
2
2
|
import * as _keystatic_core from '@keystatic/core';
|
|
3
3
|
import { Collection, ComponentSchema, Singleton, Config } from '@keystatic/core';
|
|
4
4
|
import * as _keystatic_core_reader_github from '@keystatic/core/reader/github';
|
|
5
|
+
import { createGitHubReader } from '@keystatic/core/reader/github';
|
|
5
6
|
import { MDXModule } from 'mdx/types';
|
|
6
7
|
import { Locale } from './config.js';
|
|
7
8
|
import { WithoutI18nPrefix } from './with-i18n-prefix.js';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
pathPrefix?: string;
|
|
12
|
-
ref?: string;
|
|
13
|
-
token?: string;
|
|
14
|
-
} | null): _keystatic_core_reader_github.Reader<TCollections, TSingletons>;
|
|
10
|
+
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): _keystatic_core_reader_github.Reader<TCollections, TSingletons>;
|
|
15
12
|
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>): {
|
|
16
13
|
createCollectionResource: <TKeys extends WithoutI18nPrefix<keyof TCollections & string, TLocale>>(name: TKeys, locale: TLocale) => {
|
|
17
14
|
all: () => Promise<{
|
package/dist/reader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/reader.ts"],"names":["createLocalReader"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"sources":["../src/reader.ts"],"names":["createLocalReader"],"mappings":";;;;;;;AAcO,SAAS,YAAA,CAIf,QACA,qBACC,EAAA;AACD,EAAA,MAAM,eAAe,qBAAwB,IAAA,CAAA;AAE7C,EAAA,IAAI,gBAAgB,IAAM,EAAA;AACzB,IAAO,OAAA,kBAAA,CAAmB,QAAQ,YAAY,CAAA,CAAA;AAAA,GAC/C;AAEA,EAAA,OAAOA,cAAkB,CAAA,OAAA,CAAQ,GAAI,EAAA,EAAG,MAAM,CAAA,CAAA;AAC/C,CAAA;AAEO,SA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OAAA;AAAA,MACA,OAAA;AAAA,MACA,IAAA;AAAA,KACD,CAAA;AAAA,GACD;AAEA,EAAO,OAAA;AAAA,IACN,wBAAA;AAAA,IACA,uBAAA;AAAA,GACD,CAAA;AACD","file":"reader.js","sourcesContent":["import assert from \"node:assert/strict\";\nimport { join } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\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\n\t\t\treturn {\n\t\t\t\tcollection: name,\n\t\t\t\tid,\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\n\t\t\treturn {\n\t\t\t\tsingleton: name,\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"]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acdh-oeaw/keystatic-lib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./dist/index.js",
|
|
8
|
+
"./preview": "./dist/preview/index.js",
|
|
8
9
|
"./reader": "./dist/reader.js"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
@@ -23,16 +24,18 @@
|
|
|
23
24
|
"@keystatic/core": "0.x"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"@acdh-oeaw/commitlint-config": "^
|
|
27
|
+
"@acdh-oeaw/commitlint-config": "^2.0.0",
|
|
27
28
|
"@acdh-oeaw/eslint-config": "^2.0.1",
|
|
28
29
|
"@acdh-oeaw/eslint-config-node": "^2.0.1",
|
|
30
|
+
"@acdh-oeaw/eslint-config-react": "^2.0.2",
|
|
29
31
|
"@acdh-oeaw/prettier-config": "^2.0.0",
|
|
30
|
-
"@acdh-oeaw/tsconfig-lib": "^1.1.
|
|
32
|
+
"@acdh-oeaw/tsconfig-lib": "^1.1.1",
|
|
31
33
|
"@changesets/changelog-github": "^0.5.0",
|
|
32
34
|
"@changesets/cli": "^2.27.8",
|
|
33
|
-
"@commitlint/cli": "^
|
|
34
|
-
"@keystatic/core": "^0.5.
|
|
35
|
+
"@commitlint/cli": "^19.5.0",
|
|
36
|
+
"@keystatic/core": "^0.5.35",
|
|
35
37
|
"@types/node": "^22.5.4",
|
|
38
|
+
"@types/react": "^18.3.5",
|
|
36
39
|
"eslint": "^9.10.0",
|
|
37
40
|
"eslint-config-flat-gitignore": "^0.3.0",
|
|
38
41
|
"globals": "^15.9.0",
|
|
@@ -40,9 +43,10 @@
|
|
|
40
43
|
"lint-staged": "^15.2.10",
|
|
41
44
|
"npm-run-all2": "^6.2.2",
|
|
42
45
|
"prettier": "^3.3.3",
|
|
46
|
+
"react": "^18.3.1",
|
|
43
47
|
"simple-git-hooks": "^2.11.1",
|
|
44
48
|
"tsup": "^8.2.4",
|
|
45
|
-
"tsx": "^4.19.
|
|
49
|
+
"tsx": "^4.19.1",
|
|
46
50
|
"typescript": "^5.6.2"
|
|
47
51
|
},
|
|
48
52
|
"commitlint": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/create-component.ts"],"names":["createComponent"],"mappings":";AAIO,SAAS,gBAId,sBAA2E,EAAA;AAC5E,EAAO,OAAA,SAASA,gBAAgB,CAAA,SAAA,EAAkB,MAAiB,EAAA;AAClE,IAAO,OAAA,sBAAA,CAAuB,WAAW,MAAM,CAAA,CAAA;AAAA,GAChD,CAAA;AACD","file":"chunk-FVPLAXGT.js","sourcesContent":["import type { ContentComponent } from \"@keystatic/core/content-components\";\n\nimport type { Locale } from \"./config\";\n\nexport function createComponent<\n\tTPath extends `/${string}/`,\n\tTLocale extends Locale,\n\tTComponent extends ContentComponent,\n>(createComponentFactory: (assetPath: TPath, locale: TLocale) => TComponent) {\n\treturn function createComponent(assetPath: TPath, locale: TLocale) {\n\t\treturn createComponentFactory(assetPath, locale);\n\t};\n}\n"]}
|