@panneau/fields 5.0.0-alpha.4 → 5.0.0-alpha.5
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 +33 -21
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/localized/LocalizedField.d.ts.map +1 -1
- package/dist/localized/LocalizedField.js +1 -0
- package/dist/localized/LocalizedField.js.map +1 -1
- package/dist/relation/RelationField.d.ts.map +1 -1
- package/dist/relation/RelationField.js +24 -24
- package/dist/relation/RelationField.js.map +1 -1
- package/dist/shared/DefinitionField.d.ts +3 -1
- package/dist/shared/DefinitionField.d.ts.map +1 -1
- package/dist/shared/DefinitionField.js +80 -72
- package/dist/shared/DefinitionField.js.map +1 -1
- package/dist/shared/check.d.ts +27 -0
- package/dist/shared/check.d.ts.map +1 -0
- package/dist/shared/check.js +18 -0
- package/dist/shared/check.js.map +1 -0
- package/dist/shared/context.d.ts +7 -2
- package/dist/shared/context.d.ts.map +1 -1
- package/dist/shared/context.js +22 -18
- package/dist/shared/context.js.map +1 -1
- package/dist/shared/types.d.ts +2 -0
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/slug/SlugField.css +18 -0
- package/dist/slug/SlugField.d.ts +31 -3
- package/dist/slug/SlugField.d.ts.map +1 -1
- package/dist/slug/SlugField.js +231 -159
- package/dist/slug/SlugField.js.map +1 -1
- package/dist/slug/SlugField.module.js +14 -0
- package/dist/slug/SlugField.module.js.map +1 -0
- package/dist/slug/index.d.ts +1 -1
- package/dist/slug/index.d.ts.map +1 -1
- package/dist/slug/index.js +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { FieldCheckRequest, FieldCheckResponse } from '@panneau/protocol';
|
|
2
|
+
/**
|
|
3
|
+
* Where fields with `check` check their value as it is typed: whether a slug is available, and
|
|
4
|
+
* its URL. The value's locale and the form's values come with each check.
|
|
5
|
+
*/
|
|
6
|
+
export interface FieldCheckSource {
|
|
7
|
+
check(field: string, request: {
|
|
8
|
+
value: string;
|
|
9
|
+
locale?: string;
|
|
10
|
+
values?: Record<string, unknown>;
|
|
11
|
+
}, options: {
|
|
12
|
+
signal: AbortSignal;
|
|
13
|
+
}): Promise<FieldCheckResponse>;
|
|
14
|
+
}
|
|
15
|
+
/** What `createFieldCheckSource()` needs from an adapter: the `checkField()` of `@panneau/data`. */
|
|
16
|
+
export interface FieldCheckAdapter {
|
|
17
|
+
checkField?(resource: string, field: string, request: FieldCheckRequest, options?: {
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
}): Promise<FieldCheckResponse>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The check source of a form of a resource, through an adapter (`POST
|
|
23
|
+
* /resources/{resource}/fields/{field}/check`): `id` is the item being edited, or null when
|
|
24
|
+
* creating one. Null when the adapter can't check.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createFieldCheckSource(adapter: FieldCheckAdapter, resource: string, id?: string | null): FieldCheckSource | null;
|
|
27
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/shared/check.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE/E;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC7B,KAAK,CACD,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,EAC7E,OAAO,EAAE;QAAE,MAAM,EAAE,WAAW,CAAA;KAAE,GACjC,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAClC;AAED,oGAAoG;AACpG,MAAM,WAAW,iBAAiB;IAC9B,UAAU,CAAC,CACP,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GACnC,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAClC;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAClC,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE,MAAM,EAChB,EAAE,GAAE,MAAM,GAAG,IAAW,GACzB,gBAAgB,GAAG,IAAI,CASzB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/shared/check.ts
|
|
2
|
+
/**
|
|
3
|
+
* The check source of a form of a resource, through an adapter (`POST
|
|
4
|
+
* /resources/{resource}/fields/{field}/check`): `id` is the item being edited, or null when
|
|
5
|
+
* creating one. Null when the adapter can't check.
|
|
6
|
+
*/
|
|
7
|
+
function createFieldCheckSource(adapter, resource, id = null) {
|
|
8
|
+
const { checkField } = adapter;
|
|
9
|
+
if (checkField === void 0) return null;
|
|
10
|
+
return { check: (field, request, { signal }) => checkField.call(adapter, resource, field, {
|
|
11
|
+
...request,
|
|
12
|
+
id
|
|
13
|
+
}, { signal }) };
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { createFieldCheckSource };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","names":[],"sources":["../../src/shared/check.ts"],"sourcesContent":["import type { FieldCheckRequest, FieldCheckResponse } from '@panneau/protocol';\n\n/**\n * Where fields with `check` check their value as it is typed: whether a slug is available, and\n * its URL. The value's locale and the form's values come with each check.\n */\nexport interface FieldCheckSource {\n check(\n field: string,\n request: { value: string; locale?: string; values?: Record<string, unknown> },\n options: { signal: AbortSignal },\n ): Promise<FieldCheckResponse>;\n}\n\n/** What `createFieldCheckSource()` needs from an adapter: the `checkField()` of `@panneau/data`. */\nexport interface FieldCheckAdapter {\n checkField?(\n resource: string,\n field: string,\n request: FieldCheckRequest,\n options?: { signal?: AbortSignal },\n ): Promise<FieldCheckResponse>;\n}\n\n/**\n * The check source of a form of a resource, through an adapter (`POST\n * /resources/{resource}/fields/{field}/check`): `id` is the item being edited, or null when\n * creating one. Null when the adapter can't check.\n */\nexport function createFieldCheckSource(\n adapter: FieldCheckAdapter,\n resource: string,\n id: string | null = null,\n): FieldCheckSource | null {\n const { checkField } = adapter;\n if (checkField === undefined) {\n return null;\n }\n return {\n check: (field, request, { signal }) =>\n checkField.call(adapter, resource, field, { ...request, id }, { signal }),\n };\n}\n"],"mappings":";;;;;;AA6BA,SAAgB,uBACZ,SACA,UACA,KAAoB,MACG;CACvB,MAAM,EAAE,eAAe;CACvB,IAAI,eAAe,KAAA,GACf,OAAO;CAEX,OAAO,EACH,QAAQ,OAAO,SAAS,EAAE,aACtB,WAAW,KAAK,SAAS,UAAU,OAAO;EAAE,GAAG;EAAS;CAAG,GAAG,EAAE,OAAO,CAAC,EAChF;AACJ"}
|
package/dist/shared/context.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ComponentType, type ReactNode } from 'react';
|
|
2
2
|
import type { Field } from '@panneau/protocol';
|
|
3
3
|
import type { UploadSource } from '../upload/types';
|
|
4
|
+
import type { FieldCheckSource } from './check';
|
|
4
5
|
import type { RelationSource } from './relation';
|
|
5
6
|
import type { FieldEntry } from './types';
|
|
6
7
|
/** What a binding gives a field: its value, handlers and errors at a path. */
|
|
@@ -38,6 +39,8 @@ export interface FieldsContextValue {
|
|
|
38
39
|
* files themselves.
|
|
39
40
|
*/
|
|
40
41
|
uploadSource: UploadSource | null;
|
|
42
|
+
/** Where fields with `check` check their value, such as a slug's availability. */
|
|
43
|
+
checkSource: FieldCheckSource | null;
|
|
41
44
|
binding: FieldBinding | null;
|
|
42
45
|
}
|
|
43
46
|
/** The fields context of the closest `FieldsProvider`. */
|
|
@@ -49,15 +52,17 @@ export interface FieldsProviderProps {
|
|
|
49
52
|
relationSource?: RelationSource | null;
|
|
50
53
|
/** Make it once, outside of render: fields make an uploader for each source they get. */
|
|
51
54
|
uploadSource?: UploadSource | null;
|
|
55
|
+
/** `createFieldCheckSource(adapter, resource, id)`, for the form of an item. */
|
|
56
|
+
checkSource?: FieldCheckSource | null;
|
|
52
57
|
binding?: FieldBinding | null;
|
|
53
58
|
children?: ReactNode;
|
|
54
59
|
}
|
|
55
60
|
/**
|
|
56
61
|
* Provides what fields rendered from a definition need: the components of each type, the locales
|
|
57
|
-
* of localized values, a relation source, an upload source and a binding. Values not given come from the parent
|
|
62
|
+
* of localized values, a relation source, an upload source, a check source and a binding. Values not given come from the parent
|
|
58
63
|
* provider.
|
|
59
64
|
*/
|
|
60
|
-
export declare function FieldsProvider({ components, locales, relationSource, uploadSource, binding, children, }: FieldsProviderProps): import("react").JSX.Element;
|
|
65
|
+
export declare function FieldsProvider({ components, locales, relationSource, uploadSource, checkSource, binding, children, }: FieldsProviderProps): import("react").JSX.Element;
|
|
61
66
|
/** The parent path of a path: `blocks.2` for `blocks.2.title`, `''` for `title`. */
|
|
62
67
|
export declare function getParentPath(path: string): string;
|
|
63
68
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/shared/context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAsB,MAAM,OAAO,CAAC;AAE/E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,8EAA8E;AAC9E,MAAM,WAAW,eAAe;I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;IAC5B,cAAc,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;IACvC,yFAAyF;IACzF,YAAY,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IACnC,gFAAgF;IAChF,WAAW,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACtC,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,EAC3B,UAAU,EACV,OAAO,EACP,cAAc,EACd,YAAY,EACZ,WAAW,EACX,OAAO,EACP,QAAQ,GACX,EAAE,mBAAmB,+BAYrB;AAED,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGlD"}
|
package/dist/shared/context.js
CHANGED
|
@@ -7,6 +7,7 @@ var FieldsContext = createContext({
|
|
|
7
7
|
locales: [],
|
|
8
8
|
relationSource: null,
|
|
9
9
|
uploadSource: null,
|
|
10
|
+
checkSource: null,
|
|
10
11
|
binding: null
|
|
11
12
|
});
|
|
12
13
|
/** The fields context of the closest `FieldsProvider`. */
|
|
@@ -15,12 +16,12 @@ function useFieldsContext() {
|
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* Provides what fields rendered from a definition need: the components of each type, the locales
|
|
18
|
-
* of localized values, a relation source, an upload source and a binding. Values not given come from the parent
|
|
19
|
+
* of localized values, a relation source, an upload source, a check source and a binding. Values not given come from the parent
|
|
19
20
|
* provider.
|
|
20
21
|
*/
|
|
21
22
|
function FieldsProvider(t0) {
|
|
22
|
-
const $ = c(
|
|
23
|
-
const { components, locales, relationSource, uploadSource, binding, children } = t0;
|
|
23
|
+
const $ = c(13);
|
|
24
|
+
const { components, locales, relationSource, uploadSource, checkSource, binding, children } = t0;
|
|
24
25
|
const parent = use(FieldsContext);
|
|
25
26
|
let t1;
|
|
26
27
|
if ($[0] !== components || $[1] !== parent.components) {
|
|
@@ -35,15 +36,17 @@ function FieldsProvider(t0) {
|
|
|
35
36
|
const t2 = locales ?? parent.locales;
|
|
36
37
|
const t3 = relationSource === void 0 ? parent.relationSource : relationSource;
|
|
37
38
|
const t4 = uploadSource === void 0 ? parent.uploadSource : uploadSource;
|
|
38
|
-
const t5 =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const t5 = checkSource === void 0 ? parent.checkSource : checkSource;
|
|
40
|
+
const t6 = binding === void 0 ? parent.binding : binding;
|
|
41
|
+
let t7;
|
|
42
|
+
if ($[3] !== t1 || $[4] !== t2 || $[5] !== t3 || $[6] !== t4 || $[7] !== t5 || $[8] !== t6) {
|
|
43
|
+
t7 = {
|
|
42
44
|
components: t1,
|
|
43
45
|
locales: t2,
|
|
44
46
|
relationSource: t3,
|
|
45
47
|
uploadSource: t4,
|
|
46
|
-
|
|
48
|
+
checkSource: t5,
|
|
49
|
+
binding: t6
|
|
47
50
|
};
|
|
48
51
|
$[3] = t1;
|
|
49
52
|
$[4] = t2;
|
|
@@ -51,19 +54,20 @@ function FieldsProvider(t0) {
|
|
|
51
54
|
$[6] = t4;
|
|
52
55
|
$[7] = t5;
|
|
53
56
|
$[8] = t6;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
$[9] = t7;
|
|
58
|
+
} else t7 = $[9];
|
|
59
|
+
const value = t7;
|
|
60
|
+
let t8;
|
|
61
|
+
if ($[10] !== children || $[11] !== value) {
|
|
62
|
+
t8 = /* @__PURE__ */ jsx(FieldsContext, {
|
|
59
63
|
value,
|
|
60
64
|
children
|
|
61
65
|
});
|
|
62
|
-
$[
|
|
63
|
-
$[
|
|
64
|
-
$[
|
|
65
|
-
} else
|
|
66
|
-
return
|
|
66
|
+
$[10] = children;
|
|
67
|
+
$[11] = value;
|
|
68
|
+
$[12] = t8;
|
|
69
|
+
} else t8 = $[12];
|
|
70
|
+
return t8;
|
|
67
71
|
}
|
|
68
72
|
/** The parent path of a path: `blocks.2` for `blocks.2.title`, `''` for `title`. */
|
|
69
73
|
function getParentPath(path) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":["value","children","_c"],"sources":["../../src/shared/context.tsx"],"sourcesContent":["import { type ComponentType, type ReactNode, createContext, use } from 'react';\n\nimport type { Field } from '@panneau/protocol';\n\nimport type { UploadSource } from '../upload/types';\nimport type { RelationSource } from './relation';\nimport type { FieldEntry } from './types';\n\n/** What a binding gives a field: its value, handlers and errors at a path. */\nexport interface BoundFieldProps {\n value: unknown;\n onChange: (value: unknown) => void;\n onBlur?: () => void;\n errors?: readonly string[];\n}\n\n/** Props of a binding: it decides whether a field shows, and where its value comes from. */\nexport interface FieldBindingProps {\n field: Field;\n /** Dot path of the field's value. */\n path: string;\n /** Dot path of the object the field belongs to: `''` at the top, `blocks.2` in a block. */\n parentPath: string;\n /** Renders the field with its bound value. */\n render: (bound: BoundFieldProps) => ReactNode;\n}\n\n/**\n * Binds nested fields (in groups, blocks and localized values) to a store by path, instead of the\n * value and `onChange` of their parent. `@panneau/forms` binds them to its form state, so that\n * every value is set, validated and shown in error by its own path.\n */\nexport type FieldBinding = ComponentType<FieldBindingProps>;\n\nexport interface FieldsContextValue {\n /** Registry entries, by field type, over the built-in ones. */\n components: Readonly<Record<string, FieldEntry>>;\n /** Locales of localized values, in order. */\n locales: readonly string[];\n /** Where relation fields search for items. */\n relationSource: RelationSource | null;\n /**\n * Where fields that take files upload them directly to storage. Without one, they give the\n * files themselves.\n */\n uploadSource: UploadSource | null;\n binding: FieldBinding | null;\n}\n\nconst FieldsContext = createContext<FieldsContextValue>({\n components: {},\n locales: [],\n relationSource: null,\n uploadSource: null,\n binding: null,\n});\n\n/** The fields context of the closest `FieldsProvider`. */\nexport function useFieldsContext(): FieldsContextValue {\n return use(FieldsContext);\n}\n\nexport interface FieldsProviderProps {\n /** Registry entries by type, added over those of a parent provider. */\n components?: Readonly<Record<string, FieldEntry>>;\n locales?: readonly string[];\n relationSource?: RelationSource | null;\n /** Make it once, outside of render: fields make an uploader for each source they get. */\n uploadSource?: UploadSource | null;\n binding?: FieldBinding | null;\n children?: ReactNode;\n}\n\n/**\n * Provides what fields rendered from a definition need: the components of each type, the locales\n * of localized values, a relation source, an upload source and a binding. Values not given come from the parent\n * provider.\n */\nexport function FieldsProvider({\n components,\n locales,\n relationSource,\n uploadSource,\n binding,\n children,\n}: FieldsProviderProps) {\n const parent = use(FieldsContext);\n const value: FieldsContextValue = {\n components:\n components !== undefined ? { ...parent.components, ...components } : parent.components,\n locales: locales ?? parent.locales,\n relationSource: relationSource === undefined ? parent.relationSource : relationSource,\n uploadSource: uploadSource === undefined ? parent.uploadSource : uploadSource,\n binding: binding === undefined ? parent.binding : binding,\n };\n return <FieldsContext value={value}>{children}</FieldsContext>;\n}\n\n/** The parent path of a path: `blocks.2` for `blocks.2.title`, `''` for `title`. */\nexport function getParentPath(path: string): string {\n const index = path.lastIndexOf('.');\n return index === -1 ? '' : path.slice(0, index);\n}\n"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"context.js","names":["value","children","_c"],"sources":["../../src/shared/context.tsx"],"sourcesContent":["import { type ComponentType, type ReactNode, createContext, use } from 'react';\n\nimport type { Field } from '@panneau/protocol';\n\nimport type { UploadSource } from '../upload/types';\nimport type { FieldCheckSource } from './check';\nimport type { RelationSource } from './relation';\nimport type { FieldEntry } from './types';\n\n/** What a binding gives a field: its value, handlers and errors at a path. */\nexport interface BoundFieldProps {\n value: unknown;\n onChange: (value: unknown) => void;\n onBlur?: () => void;\n errors?: readonly string[];\n}\n\n/** Props of a binding: it decides whether a field shows, and where its value comes from. */\nexport interface FieldBindingProps {\n field: Field;\n /** Dot path of the field's value. */\n path: string;\n /** Dot path of the object the field belongs to: `''` at the top, `blocks.2` in a block. */\n parentPath: string;\n /** Renders the field with its bound value. */\n render: (bound: BoundFieldProps) => ReactNode;\n}\n\n/**\n * Binds nested fields (in groups, blocks and localized values) to a store by path, instead of the\n * value and `onChange` of their parent. `@panneau/forms` binds them to its form state, so that\n * every value is set, validated and shown in error by its own path.\n */\nexport type FieldBinding = ComponentType<FieldBindingProps>;\n\nexport interface FieldsContextValue {\n /** Registry entries, by field type, over the built-in ones. */\n components: Readonly<Record<string, FieldEntry>>;\n /** Locales of localized values, in order. */\n locales: readonly string[];\n /** Where relation fields search for items. */\n relationSource: RelationSource | null;\n /**\n * Where fields that take files upload them directly to storage. Without one, they give the\n * files themselves.\n */\n uploadSource: UploadSource | null;\n /** Where fields with `check` check their value, such as a slug's availability. */\n checkSource: FieldCheckSource | null;\n binding: FieldBinding | null;\n}\n\nconst FieldsContext = createContext<FieldsContextValue>({\n components: {},\n locales: [],\n relationSource: null,\n uploadSource: null,\n checkSource: null,\n binding: null,\n});\n\n/** The fields context of the closest `FieldsProvider`. */\nexport function useFieldsContext(): FieldsContextValue {\n return use(FieldsContext);\n}\n\nexport interface FieldsProviderProps {\n /** Registry entries by type, added over those of a parent provider. */\n components?: Readonly<Record<string, FieldEntry>>;\n locales?: readonly string[];\n relationSource?: RelationSource | null;\n /** Make it once, outside of render: fields make an uploader for each source they get. */\n uploadSource?: UploadSource | null;\n /** `createFieldCheckSource(adapter, resource, id)`, for the form of an item. */\n checkSource?: FieldCheckSource | null;\n binding?: FieldBinding | null;\n children?: ReactNode;\n}\n\n/**\n * Provides what fields rendered from a definition need: the components of each type, the locales\n * of localized values, a relation source, an upload source, a check source and a binding. Values not given come from the parent\n * provider.\n */\nexport function FieldsProvider({\n components,\n locales,\n relationSource,\n uploadSource,\n checkSource,\n binding,\n children,\n}: FieldsProviderProps) {\n const parent = use(FieldsContext);\n const value: FieldsContextValue = {\n components:\n components !== undefined ? { ...parent.components, ...components } : parent.components,\n locales: locales ?? parent.locales,\n relationSource: relationSource === undefined ? parent.relationSource : relationSource,\n uploadSource: uploadSource === undefined ? parent.uploadSource : uploadSource,\n checkSource: checkSource === undefined ? parent.checkSource : checkSource,\n binding: binding === undefined ? parent.binding : binding,\n };\n return <FieldsContext value={value}>{children}</FieldsContext>;\n}\n\n/** The parent path of a path: `blocks.2` for `blocks.2.title`, `''` for `title`. */\nexport function getParentPath(path: string): string {\n const index = path.lastIndexOf('.');\n return index === -1 ? '' : path.slice(0, index);\n}\n"],"mappings":";;;;AAoDA,IAAM,gBAAgB,cAAkC;CACpD,YAAY,CAAC;CACb,SAAS,CAAA;CACT,gBAAgB;CAChB,cAAc;CACd,aAAa;CACb,SAAS;AACb,CAAC;;AAGD,SAAgB,mBAAuC;CACnD,OAAO,IAAI,aAAa;AAC5B;;;;;;AAoBA,SAAO,eAAA,IAAA;CAAA,MAAA,IAAAE,EAAA,EAAA;CAAwB,MAAA,EAAA,YAAA,SAAA,gBAAA,cAAA,aAAA,SAAA,aAAA;CAS3B,MAAA,SAAe,IAAI,aAAa;CAAE,IAAA;CAAA,IAAA,EAAA,OAAA,cAAA,EAAA,OAAA,OAAA,YAAA;EAG1B,KAAA,eAAe,KAAA,IAAf;GAAA,GAAgC,OAAM;GAAW,GAAK;EAA+B,IAAhB,OAAM;EAAW,EAAA,KAAA;EAAA,EAAA,KAAA,OAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CACjF,MAAA,KAAA,WAAW,OAAM;CACV,MAAA,KAAA,mBAAmB,KAAA,IAAY,OAAM,iBAArC;CACF,MAAA,KAAA,iBAAiB,KAAA,IAAY,OAAM,eAAnC;CACD,MAAA,KAAA,gBAAgB,KAAA,IAAY,OAAM,cAAlC;CACJ,MAAA,KAAA,YAAY,KAAA,IAAY,OAAM,UAA9B;CAAgD,IAAA;CAAA,IAAA,EAAA,OAAA,MAAA,EAAA,OAAA,MAAA,EAAA,OAAA,MAAA,EAAA,OAAA,MAAA,EAAA,OAAA,MAAA,EAAA,OAAA,IAAA;EAP3B,KAAA;GAAA,YAE1B;GAAsF,SACjF;GAAyB,gBAClB;GAAqE,cACvE;GAA+D,aAChE;GAA4D,SAChE;EACb;EAAC,EAAA,KAAA;EAAA,EAAA,KAAA;EAAA,EAAA,KAAA;EAAA,EAAA,KAAA;EAAA,EAAA,KAAA;EAAA,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CARD,MAAA,QAAkC;CAQhC,IAAA;CAAA,IAAA,EAAA,QAAA,YAAA,EAAA,QAAA,OAAA;EACK,KAAA,oBAAC,eAAD;GAAsB;GAAQ;EAAhB,CAAA;EAAyC,EAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;CAAA,OAAA,KAAA,EAAA;CAAA,OAAvD;AAAuD;;AAIlE,SAAgB,cAAc,MAAsB;CAChD,MAAM,QAAQ,KAAK,YAAY,GAAG;CAClC,OAAO,UAAU,KAAK,KAAK,KAAK,MAAM,GAAG,KAAK;AAClD"}
|
package/dist/shared/types.d.ts
CHANGED
|
@@ -43,6 +43,8 @@ export interface FieldEntryProps {
|
|
|
43
43
|
readOnly?: boolean;
|
|
44
44
|
/** The object the field belongs to: the form's values, or a group or a block. */
|
|
45
45
|
parentValue?: unknown;
|
|
46
|
+
/** The locale of the value: the input of a locale of a localized field. */
|
|
47
|
+
locale?: string;
|
|
46
48
|
className?: string;
|
|
47
49
|
}
|
|
48
50
|
/** A registry entry: renders the field of a type from its definition. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C;;;GAGG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC;IACzB,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IACjB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC;IACrC,oFAAoF;IACpF,MAAM,CAAC,EAAE,MAAM,IAAI,C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ACpB,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iFAAiF;IACjF,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,yEAAyE;AACzE,MAAM,MAAM,UAAU,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.panneau-slug-field-description {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: var(--panneau-space-1);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.panneau-slug-field-url {
|
|
8
|
+
overflow-wrap: anywhere;
|
|
9
|
+
color: var(--panneau-color-link);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.panneau-slug-field-taken {
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-wrap: wrap;
|
|
15
|
+
align-items: center;
|
|
16
|
+
gap: var(--panneau-space-2);
|
|
17
|
+
color: var(--panneau-color-warning);
|
|
18
|
+
}
|
package/dist/slug/SlugField.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FieldCheckResponse } from '@panneau/protocol';
|
|
1
2
|
import type { FieldEntryProps } from '../shared/types';
|
|
2
3
|
import { type TextFieldProps } from '../text/TextField';
|
|
3
4
|
/**
|
|
@@ -5,6 +6,10 @@ import { type TextFieldProps } from '../text/TextField';
|
|
|
5
6
|
* accents (`Été à Montréal` gives `ete-a-montreal`).
|
|
6
7
|
*/
|
|
7
8
|
export declare function slugify(text: string): string;
|
|
9
|
+
/** Checks a slug with the backend: whether it is available, and its URL. */
|
|
10
|
+
export type SlugCheck = (value: string, options: {
|
|
11
|
+
signal: AbortSignal;
|
|
12
|
+
}) => Promise<FieldCheckResponse>;
|
|
8
13
|
export interface SlugFieldProps extends Omit<TextFieldProps, 'type' | 'suffix'> {
|
|
9
14
|
/**
|
|
10
15
|
* The text the slug is made from (a title). While the slug is empty or still matches it, the
|
|
@@ -13,12 +18,35 @@ export interface SlugFieldProps extends Omit<TextFieldProps, 'type' | 'suffix'>
|
|
|
13
18
|
source?: string | null;
|
|
14
19
|
/** Name of the source, for the button that generates the slug from it. */
|
|
15
20
|
sourceLabel?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Checks the slug as it is typed, and once when the field shows: the field then shows the
|
|
23
|
+
* URL the backend gives, and says when the slug is taken, with a free one to use instead.
|
|
24
|
+
*/
|
|
25
|
+
onCheck?: SlugCheck | null;
|
|
26
|
+
/** How long typing must pause before a check, in milliseconds. Defaults to 300. */
|
|
27
|
+
checkDelay?: number;
|
|
28
|
+
/**
|
|
29
|
+
* What the check depends on besides the slug, such as the form's values: the slug is checked
|
|
30
|
+
* again when it changes. `onCheck` itself can change on every render.
|
|
31
|
+
*/
|
|
32
|
+
checkKey?: string;
|
|
16
33
|
}
|
|
17
34
|
/**
|
|
18
35
|
* A slug for URLs. Typed text is cleaned up on blur. With a `source`, the slug follows it until
|
|
19
|
-
* it is edited, and a button generates it again.
|
|
36
|
+
* it is edited, and a button generates it again. With `onCheck`, the backend says whether the
|
|
37
|
+
* slug is taken, and gives its URL.
|
|
38
|
+
*/
|
|
39
|
+
export declare function SlugField({ value, onChange, onBlur, source, sourceLabel, onCheck, checkDelay, checkKey, disabled, readOnly, prefix, errors, description, ...props }: SlugFieldProps): import("react").JSX.Element;
|
|
40
|
+
/**
|
|
41
|
+
* The text of a source value: the value itself, or for a localized value, its value in `locale`.
|
|
42
|
+
* Without a locale, the first locale that has a value.
|
|
43
|
+
*/
|
|
44
|
+
export declare function sourceText(value: unknown, locale?: string): string | null;
|
|
45
|
+
/**
|
|
46
|
+
* The `slug` type: `from` names the field it follows, in the slug's own locale, or in the default
|
|
47
|
+
* locale (the first of the fields context) for a slug that isn't localized. Setting `prefix`
|
|
48
|
+
* shows a URL prefix. With `check`, the fields context's check source checks the slug of a field
|
|
49
|
+
* at the top of the resource, with the form's values.
|
|
20
50
|
*/
|
|
21
|
-
export declare function SlugField({ value, onChange, onBlur, source, sourceLabel, disabled, readOnly, ...props }: SlugFieldProps): import("react").JSX.Element;
|
|
22
|
-
/** The `slug` type: `from` names the field it follows, and setting `prefix` shows a URL prefix. */
|
|
23
51
|
export declare function SlugFieldEntry(props: FieldEntryProps): import("react").JSX.Element;
|
|
24
52
|
//# sourceMappingURL=SlugField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SlugField.d.ts","sourceRoot":"","sources":["../../src/slug/SlugField.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SlugField.d.ts","sourceRoot":"","sources":["../../src/slug/SlugField.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAM5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnE;;;GAGG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO5C;AAED,4EAA4E;AAC5E,MAAM,MAAM,SAAS,GAAG,CACpB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,KAC/B,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAEjC,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC3E;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,0EAA0E;IAC1E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IAC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