@quitecustard/payload 0.3.0 → 0.3.1
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 +2 -0
- package/dist/fields/link-field.d.ts +3 -1
- package/dist/fields/link-field.js +2 -1
- package/dist/fields/link-url.d.ts +14 -0
- package/dist/fields/link-url.js +15 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,6 +59,8 @@ objects in place, so two collections must not receive one.
|
|
|
59
59
|
- `owner-field` — a relationship auto-stamped to the creating user, refused on update by field-level
|
|
60
60
|
access rather than by `admin.readOnly`, which Payload never consults on a write
|
|
61
61
|
- `seo-tab` — over `@payloadcms/plugin-seo`'s field factories
|
|
62
|
+
- `link-url` — `validateLinkField`: the link protocol allowlist in the one-argument shape a
|
|
63
|
+
field's `validate` takes
|
|
62
64
|
- `social-url` — `normaliseSocialUrl` (bare host → `https://…`) plus `validateSocialUrl`
|
|
63
65
|
- `colour-picker-field`, `colour-options-field`, `phone-field`, `height-field`, `size-field`,
|
|
64
66
|
`spacing-select-field`, `layout-fields`, `media-content-fields`
|
|
@@ -13,7 +13,7 @@ type SelectOption = {
|
|
|
13
13
|
* linkField({ relationTo: ['pages', 'posts'], styleOptions: [{ label: 'Primary', value: 'primary' }] })
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
|
-
export declare const linkField: ({ relationTo, dropdown, staticOptions, phoneComponent, anchorComponent, styleOptions, disableLabel, localizedLabel, overrides, maxDepth, }: {
|
|
16
|
+
export declare const linkField: ({ relationTo, dropdown, staticOptions, phoneComponent, anchorComponent, anchorDescription, styleOptions, disableLabel, localizedLabel, overrides, maxDepth, }: {
|
|
17
17
|
/** Collections the "internal link" type may point to. */
|
|
18
18
|
relationTo: CollectionSlug[];
|
|
19
19
|
/** Collection slug for a "dropdown" link type (e.g. a menus collection). Omit to disable it. */
|
|
@@ -28,6 +28,8 @@ export declare const linkField: ({ relationTo, dropdown, staticOptions, phoneCom
|
|
|
28
28
|
* disable it.
|
|
29
29
|
*/
|
|
30
30
|
anchorComponent?: string;
|
|
31
|
+
/** Help text under the anchor picker, e.g. where its markers come from. */
|
|
32
|
+
anchorDescription?: string;
|
|
31
33
|
/** Style select options (e.g. primary/secondary/outline). Omit to skip the style field. */
|
|
32
34
|
styleOptions?: SelectOption[];
|
|
33
35
|
/** Whether the field also carries a "Label" text input alongside the link type. */
|
|
@@ -14,7 +14,7 @@ const withRowWidth = (field) => ({ ...field, admin: { ...field.admin, width: '50
|
|
|
14
14
|
* linkField({ relationTo: ['pages', 'posts'], styleOptions: [{ label: 'Primary', value: 'primary' }] })
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
-
export const linkField = ({ relationTo, dropdown, staticOptions, phoneComponent, anchorComponent, styleOptions, disableLabel = false, localizedLabel = false, overrides = {}, maxDepth = 1, }) => {
|
|
17
|
+
export const linkField = ({ relationTo, dropdown, staticOptions, phoneComponent, anchorComponent, anchorDescription, styleOptions, disableLabel = false, localizedLabel = false, overrides = {}, maxDepth = 1, }) => {
|
|
18
18
|
const typeOptions = [
|
|
19
19
|
{ label: 'Internal link', value: 'reference' },
|
|
20
20
|
{ label: 'Custom URL', value: 'custom' },
|
|
@@ -106,6 +106,7 @@ export const linkField = ({ relationTo, dropdown, staticOptions, phoneComponent,
|
|
|
106
106
|
type: 'text',
|
|
107
107
|
required: true,
|
|
108
108
|
admin: {
|
|
109
|
+
...(anchorDescription ? { description: anchorDescription } : {}),
|
|
109
110
|
condition: (_, siblingData) => siblingData?.type === 'anchor',
|
|
110
111
|
components: { Field: anchorComponent },
|
|
111
112
|
},
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The link protocol allowlist as a text field's `validate`: root-relative paths, in-page anchors,
|
|
3
|
+
* http(s), mailto: and tel:, never javascript:/data:. Empty values pass, so pair it with
|
|
4
|
+
* `required` where the field must be filled.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* { name: 'website', type: 'text', validate: validateLinkField }
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* Use this, not `validateLinkUrl` from `@quitecustard/core/url/link-protocol`, as the `validate`
|
|
11
|
+
* itself. Payload calls `validate(value, options)`, and `validateLinkUrl`'s second parameter is a
|
|
12
|
+
* protocol allowlist - the options object would land in that slot.
|
|
13
|
+
*/
|
|
14
|
+
export declare const validateLinkField: (value: string | null | undefined) => true | string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { validateLinkUrl } from '@quitecustard/core/url/link-protocol';
|
|
2
|
+
/**
|
|
3
|
+
* The link protocol allowlist as a text field's `validate`: root-relative paths, in-page anchors,
|
|
4
|
+
* http(s), mailto: and tel:, never javascript:/data:. Empty values pass, so pair it with
|
|
5
|
+
* `required` where the field must be filled.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* { name: 'website', type: 'text', validate: validateLinkField }
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Use this, not `validateLinkUrl` from `@quitecustard/core/url/link-protocol`, as the `validate`
|
|
12
|
+
* itself. Payload calls `validate(value, options)`, and `validateLinkUrl`'s second parameter is a
|
|
13
|
+
* protocol allowlist - the options object would land in that slot.
|
|
14
|
+
*/
|
|
15
|
+
export const validateLinkField = (value) => validateLinkUrl(value);
|
package/package.json
CHANGED