Commit Graph

12556 Commits

Author SHA1 Message Date
Elliot DeNolf
d265c26049 chore(release): v3.16.0 [skip ci] 2025-01-10 14:12:06 -05:00
Sasha
e46ad67c3b chore: update year in licenses (#10463)
Happy New Year!
2025-01-10 14:05:37 -05:00
Jacob Fletcher
f4596fc82b fix(ui): disables form during locale change (#8705)
Editing fields during a locale change on slow networks can lead to
changes being reset when the new form state is returned. This is because
the fields receive new values from context when the new locale loads in,
which may have occurred _after_ changes were made to the fields. The fix
is to subscribe to a new `localeIsLoading` context which is set
immediately after changing locales, and then reset once the new locale
loads in. This also removes the misleading `@deprecated` flag from the
`useLocale` hook itself.
2025-01-10 14:03:36 -05:00
Alessio Gravili
4fc6956617 fix(richtext-lexical): respect defaultValue config of link feature url and linkType fields (#10498)
Fixes https://github.com/payloadcms/payload/issues/10444
2025-01-10 18:08:28 +00:00
Alessio Gravili
e0df0d67ca fix(richtext-lexical): properly handle error if blocks or inline blocks are not found (#10497)
Fixes https://github.com/payloadcms/payload/issues/10445

Previously, if a block or inline block was part of the editor data that
did not exist in the config, an error would be thrown that rendered the
entire editor unusable.

Now, the error is handled gracefully and displayed within the block,
allowing users to remove the block in order to fix the issue.

![CleanShot 2025-01-10 at 10 17
14@2x](https://github.com/user-attachments/assets/7d1c97bc-8c7b-451d-a6dc-e46d39dfb0f5)
2025-01-10 17:46:19 +00:00
Sepiolina
8d5d2d1d37 fix(richtext-lexical): update Thai translations for blockquote and horizontal rule (#10469)
**Description:**

- [x] Replaces the [SKIPPED] entry with the correct translation for
"Blockquote".
- [x] I have read and understand the CONTRIBUTING.md document in this
repository.

**Type of Change:**

- [x] Bug fix (non-breaking change which fixes an issue).


**Fixes:**  

1. fix the translation issue by replacing the [SKIPPED] entry with the
correct Thai translation for "Blockquote". Which I choose
"ข้อความอ้างอิง" However one might prefer other form of translation like
"คำอ้างอิง" or "กล่องข้อความอ้างอิง" which represent the 'block' with in
the 'Blockquote'
2. corrects the Thai translation for "Horizontal Rule." The translation
has been changed from "กฎแนวนอน," which was a mistranslation, to
"เส้นขอบแนวนอน" to better reflect the meaning of "Horizontal Rule" as a
visual divider or border.
2025-01-10 08:21:51 +00:00
Steve Kuznetsov
21eec876c4 docs: update beforeValidate documentation (#10367)
docs: update beforeValidate documentation

These hooks operate similarly across the different contexts they can be
registered in, but were not sufficiently documented as such.

Signed-off-by: Steve Kuznetsov <stekuznetsov@microsoft.com>
2025-01-10 08:15:44 +00:00
Steve Kuznetsov
a8d6f3f543 docs: update draft doc for formatting (#10393)
I think some automatic formatter added the `{' '}` styling, it doesn't
render correctly. Update the formatting for this banner to remove it and
correctly refer to the `_status` field.

---------

Signed-off-by: Steve Kuznetsov <stekuznetsov@microsoft.com>
2025-01-10 08:14:29 +00:00
Adrian Maj
83bd0e2e4c docs: removed unnecessary visible <br/> tag in fields/blocks (#10456)
There was a `<br/>` tag, which was visible on the docs page. Also, I
removed spacing from the second tip box, to keep in consistent with tips
in other places in docs.
2025-01-10 08:10:31 +00:00
Alessio Gravili
4c96028e87 fix(richtext-lexical): allow external state mutation of block node from outside the form (#10486)
Previously, updates of the node fields from outside the form using
setFields did not trigger re-fetching the initial state, and thus
providing updated values to the form. This is to avoid unnecessary
re-renders of the form and unnecessary requests when setFields is
triggered from within the form.

This PR resets the initial state, thus triggering a re-render and
re-fetch of the initial state, if node.setFields is called from outside
the form. This preserves the performance optimization
2025-01-10 01:03:51 -07:00
Sasha
225c24da99 fix: collection access endpoint optional ID and use 404 for not found response (#10487)
The collection access endpoint, apparently, can be used without an ID as
well and the correct status code in `notFoundResponse` was missing.
Huge thanks to @akhrarovsaid
2025-01-10 07:35:24 +00:00
Alessio Gravili
d8f4f06b58 fix: do not autorun jobs during next build process (#10483)
This PR auto-runs jobs only when an admin route is visited. This
solution is only temporary, as it will not work for deployments without
the admin panel that should run jobs
2025-01-09 17:38:30 -07:00
Germán Jabloñski
bdb96ddbcc fix(richtext-lexical): inline Block drawers opened when document mounts (#10480)
Fixes #10439
2025-01-09 20:54:09 +00:00
Sasha
686e48d171 feat: consolidates REST API handling, decouple from next.js (#10466)
This PR improves how we handle REST API.
Problems before:
* `packages/next/src/routes/rest/*` had a huge amount of code that
didn't depend on next.js at all.
* `packages/next/src/routes/rest/index.ts` itself was not only huge but
also really hard to follow. Every method (`GET`, `POST` etc. was almost
full copy of another).
* `packages/next/src/utilities` had some utilities like
`headersWithCors` or `createPayloadRequest` that again, weren't depend
on next.js and potentially can be used outside of next.js.

Now:
All the logic that's not related to next.js now is inside
`packages/payload`, `packages/next/src/routes/rest/index.ts` now is only
_40_ lines instead of 900+
Functions like `headersWithCors` are now implemented and exported in
`payload`. To keep bc, we re-export them from the same path but marked
as `@deprecated`.

You can attach Payload REST API to any backend framework that uses Fetch
API (like Remix / SolidStart / Bun / Hono) if you don't need the admin
panel in your server instance, but you still want to have REST API. The
main function [`handleEndpoints`

](https://github.com/payloadcms/payload/pull/10466/files#diff-82e97630068f9fc40256f3f46e06226215ab150d16012281810586b51b0cfd51R28)
accepts `Request` and returns `Response`.
It's also doable with Express, but you'd have to convert node.js'
req/res to fetch.
2025-01-09 15:34:03 -05:00
Jacob Fletcher
ae1542be26 feat: exports ListPreferences from payload (#10474)
The `ListPreferences` and `ColumnPreferences` types were defined
multiple times in different places, making it difficult to make changes
across the board. Now, the `ListPreferences` type is exported directly
from `payload` alongside the other preferences types, and
`ColumnPreferences` has been merged directly into this type to simplify
usage as this is not a standalone preference.
2025-01-09 12:36:23 -05:00
Alessio Gravili
34a0d006cf fix(payload-cloud): infinite recursion on init (#10467) 2025-01-09 08:34:31 -07:00
Jacob Fletcher
a78bc6c65e fix(next): properly instantiates locale context (#10451)
Currently, unless a locale is present in the URL search params, the
locale context is instantiated using the default locale until prefs load
in client-side. This causes the locale selector to briefly render in
with the incorrect (default) locale before being replaced by the proper
locale of the request. For example, if the default locale is `en`, and
the page is requested in `es`, the locale selector will flash with
English before changing to the correct locale, even though the page data
itself is properly loaded in Spanish. This is especially evident within
slow networks.

The fix is to query the user's locale preference server-side and thread
it into the locale provider to initialize state. Because search params
are not available within server layouts, we cannot pass the locale param
in the same way, so we rely on the provider itself to read them from the
`useSearchParams` hook. If present, this takes precedence over the
user's preference if it exists.

Since the root page also queries the user's locale preference to
determine the proper locale across navigation, we use React's cache
function to dedupe these function calls and ensure only a single query
is made to the db for each request.
2025-01-08 23:57:42 -05:00
Germán Jabloñski
36e50dd6a6 feat(payload-cloud): set up cron jobs on init (#10106)
If the user has tasks configured, we set up cron jobs on init.
We also make sure to only run on one instance using a instance
identifier stored in a global.

This adds a new property to the payloadCloudPlugin: `jobs`.
2025-01-08 23:30:32 -05:00
Jacob Fletcher
6a262ab809 fix: properly validates preferences json (#10465)
It is currently possible to set all types of valid JSON within the
`payload-preferences` collection via the REST API, but not the Local
API. For example, locales are currently saved as plain strings to the
`value` field, something that is only possible through REST. This is
because there is a custom POST handler that submits the data directly to
the db using the update operation itself, bypassing typical `json` field
validation. However, when using the Local API, it does not behave in the
same way, and throws a validation error instead. The fix is to add a
custom `validate` function to this field that attempts to parse the
value, and if it succeeds, returns true. This way both APIs behave the
same.
2025-01-08 23:19:50 -05:00
Dan Ribbens
3349a4c5e5 fix: schedule publish allowed before saving draft (#10461)
### What?

In the scheduled publish feature, it is possible to open the modal to
schedule publishing a document even before you have saved a draft. This
change removes the option to open the drawer to even attempt this.
This also fixes an issue if you do not have permission to publish, you
cannot schedule publish either.

### Why?

There were numerous problems:
1. The schedule publish events would show all other publish events for
the collection without an ID in the query
2. Scheduling a publish would not work without an ID for a document to
publish

### How?
Removes the Schedule Publish menu item and drawer if you are on a
collection without an ID or you do not have permission to publish.

Without an ID:
![Screenshot 2025-01-08
162850](https://github.com/user-attachments/assets/fae0b8d4-6dac-45d7-a565-63fede7aa372)

With an ID:
![Screenshot 2025-01-08
162918](https://github.com/user-attachments/assets/c1f4d4f5-1321-43c1-991d-29747db1685d)

Perviously, you would always have the option to Schedule Publish.
2025-01-08 23:18:25 -05:00
Dan Ribbens
81c1e47747 feat: export the default JWTAuthentication strategy (#10430)
### What?
Export the default Payload JWTAuthentication strategy function for
extending and using in your own custom auth strategies that need to rely
on JWT.

### Why?
This makes it more simple to implement your own custom auth strategy.
All you need to do is set a valid JWT token as a cookie and then import
the default auth strategy so that the user will be recognized.

### How?
Exports the function and makes it reusable by adding a to the args a
strategyName prop. In the `executeAuthStrategies` function we assign the
strategyName from the configured `auth.strategies` own `name` property.
2025-01-08 23:18:07 -05:00
Paul
5318d24601 chore(templates): generate new migrations for vercel (#10458) 2025-01-08 20:40:52 +00:00
Paul
d9ff2e08dc templates: adjusted the cron job schedule so its compatible with hobby tiers as well (#10457) 2025-01-08 20:14:56 +00:00
Germán Jabloñski
c0dc0cca37 feat: autoRun jobs (#10401)
This pull request introduces the ability to configure cron jobs for
automatically running tasks in the job queue.
2025-01-08 14:51:26 -05:00
Paul
7321f9f3d5 templates: add support for scheduled publish to the website template [no lint] (#10455)
Adds configuration for vercel cron jobs and scheduled publish/unpublish
in website templates
2025-01-08 13:43:47 -06:00
Jarrod Flesch
17e7ee2315 fix(ui): stale doc status when publishing, reverting and unpublishing (#10405)
### What?
The status indicator was not updating properly when users were clicking
"unpublish" and "revert changes"

### Why?
hasPublishedDoc, unpublishedVersionCount and
mostRecentVersionIsAutosaved states were not being updated properly.

### How?
This PR updates the variables when interacting with the status actions
and sets mostRecentVersionIsAutosaved to false when the publish button
is clicked.

Fixes https://github.com/payloadcms/payload/issues/9531
2025-01-08 10:10:48 -05:00
Patrik
9701fc6970 fix(ui): removes edit drawer button from uploads collection edit view (#10426)
### What?

Previously, the `uploads` collection edit view contained an unnecessary
button in the file details which allowed opening the same document in a
drawer.

### Why?

This button was left over from `v2` when it was originally built to
allow editing of uploads from different collection edit views that had
`upload` type fields (relationship) within them.

This edit drawer button is now a separate button on the Upload
relationship component
[here](4d7587d26a/packages/ui/src/fields/Upload/RelationshipContent/index.tsx (L109)).

### How?

Removes edit drawer button from the FileDetails component.

#### Before:
![Screenshot 2025-01-07 at 1 49
18 PM](https://github.com/user-attachments/assets/50b2e789-69e7-47a5-99b8-ddbe1bf42f03)

#### After:
![Screenshot 2025-01-07 at 1 47
51 PM](https://github.com/user-attachments/assets/31a56aac-cb96-4fda-bad5-00759820da02)
2025-01-08 09:06:50 -05:00
Jarrod Flesch
ac97bfdc47 chore: import copy icon from nested folder (#9223)
Corrects imports in templates to go directly to
`@payloadcms/ui/path-to-file` instead of using the barrel export.
2025-01-08 08:37:29 -05:00
Elliot DeNolf
81188fc8bb chore(release): v3.15.1 [skip ci] 2025-01-07 21:49:22 -05:00
Elliot DeNolf
7a21b44bbf fix: vercel upload adapter warning false positive (#10434)
Adjust logic for warning message.
2025-01-07 21:47:49 -05:00
Jacob Fletcher
b09275419a fix: deprecates admin.disable property (#10429)
Fixes #10284. The `admin.disable` property is no longer supported as of
v3. Instead, to opt-out of serving the Admin Panel, REST API, or GraphQL
API, you must delete their corresponding directories within your Next.js
app. For example, to opt-out of everything, delete the `/app/(payload)`
directory entirely. Or to remove specifically the Admin Panel or API
routes, delete the `/app/(payload)/admin` or `/app/(payload)/api`
directories, respectively. Note: if you've modified the default paths
for these routes via `admin.routes`, delete those directories instead.
2025-01-07 20:28:05 +00:00
Germán Jabloñski
4d7587d26a fix(richtext-lexical): fix default arg in normalizeMarkdown (#10424)
Fix https://github.com/payloadcms/payload/issues/10387

The default argument was true and then in the nested function false.
2025-01-07 13:26:19 -05:00
Elliot DeNolf
a5443a1c6c chore(release): v3.15.0 [skip ci] 2025-01-07 12:46:11 -05:00
Alessio Gravili
08fb159943 feat: allow running sub-tasks from tasks (#10373)
Task handlers now receive `inlineTask` as an arg, which can be used to
run inline sub-tasks. In the task log, those inline tasks will have a
`parent` property that points to the parent task.

Example:

```ts
{
        slug: 'subTask',
        inputSchema: [
          {
            name: 'message',
            type: 'text',
            required: true,
          },
        ],
        handler: async ({ job, inlineTask }) => {
          await inlineTask('create two docs', {
            task: async ({ input, inlineTask }) => {
            
              const { newSimple } = await inlineTask('create doc 1', {
                task: async ({ req }) => {
                  const newSimple = await req.payload.create({
                    collection: 'simple',
                    req,
                    data: {
                      title: input.message,
                    },
                  })
                  return {
                    output: {
                      newSimple,
                    },
                  }
                },
              })

              const { newSimple2 } = await inlineTask('create doc 2', {
                task: async ({ req }) => {
                  const newSimple2 = await req.payload.create({
                    collection: 'simple',
                    req,
                    data: {
                      title: input.message,
                    },
                  })
                  return {
                    output: {
                      newSimple2,
                    },
                  }
                },
              })
              return {
                output: {
                  simpleID1: newSimple.id,
                  simpleID2: newSimple2.id,
                },
              }
            },
            input: {
              message: job.input.message,
            },
          })
        },
      } as WorkflowConfig<'subTask'>
```

Job log example:

```ts
[
  {
    executedAt: '2025-01-06T03:55:44.682Z',
    completedAt: '2025-01-06T03:55:44.684Z',
    taskSlug: 'inline',
    taskID: 'create doc 1',
    output: { newSimple: [Object] },
    parent: { taskSlug: 'inline', taskID: 'create two docs' }, // <= New
    state: 'succeeded',
    id: '677b5440ba35d345d1214d1b'
  },
  {
    executedAt: '2025-01-06T03:55:44.690Z',
    completedAt: '2025-01-06T03:55:44.692Z',
    taskSlug: 'inline',
    taskID: 'create doc 2',
    output: { newSimple2: [Object] },
    parent: { taskSlug: 'inline', taskID: 'create two docs' }, // <= New
    state: 'succeeded',
    id: '677b5440ba35d345d1214d1c'
  },
  {
    executedAt: '2025-01-06T03:55:44.681Z',
    completedAt: '2025-01-06T03:55:44.697Z',
    taskSlug: 'inline',
    taskID: 'create two docs',
    input: { message: 'hello!' },
    output: {
      simpleID1: '677b54401e34772cc63c8693',
      simpleID2: '677b54401e34772cc63c8697'
    },
    parent: {},
    state: 'succeeded',
    id: '677b5440ba35d345d1214d1d'
  }
]
```
2025-01-07 17:24:00 +00:00
Paul
ab53ababc8 fix(ui): drawer component missing closing bracket in style calc (#10411) 2025-01-07 16:25:32 +00:00
Alessio Gravili
b774f557be docs: minor lexical docs improvements (#10414) 2025-01-07 16:22:40 +00:00
Boyan Bratvanov
7fc6227310 fix(richtext-lexical): make div container optional (#10383)
Makes the wrapper container `<div class='payload-richtext'>` optional.
This is useful when importing and re-using the `<RichText/>` component
as part of another custom component already providing a container.
2025-01-07 09:55:50 -06:00
Alessio Gravili
827c75a3d2 fix(richtext-lexical): formatted inline code resulted in incorrect markdown export (#10413)
If the following markdown:

```md
**`text`**
```

was imported and then re-exported, the result was

```md
`**text**`
```

Which would have been rendered as

```html
<code>**text**</code>
```

Instead of

```html
<strong><code>text</code></strong>
```
2025-01-07 06:13:00 +00:00
Jacob Fletcher
5991a2e60f test: fixes flaky localization e2e once and for all (#10406)
The localization e2e test is notorious for flaking, consuming a lot of
time and resources continually retrying. This was because the test was
attempting to click DOM elements using selectors that never resolve, or
attempting to click inaccessible DOM nodes such as those behind a modal.
The fix is to ensure that the dot nav, for example, is disabled while
form state loads, and that modals are properly closed prior to executing
subsequent tests, etc. Tests also needed to explicitly check for
_enabled_ states before performing click actions, rather than simply
awaiting their visibility.
2025-01-07 04:45:38 +00:00
Alessio Gravili
ef7191b39a fix(next): live preview tab did not display custom edit view components (#10412)
This PR passes them through the same way it's done in the default edit
view tab
2025-01-07 03:13:38 +00:00
Paul
c7f21fc2e2 fix(email-resend): add reply_to to the API when sending emails (#10407)
Fixes https://github.com/payloadcms/payload/issues/10361

Adds reply_to to the resend mapping
2025-01-06 23:54:32 +00:00
Jacob Fletcher
a83a430a3a fix(ui): sort resets columns (#10402)
Fixes #10018. When toggling columns, then sorting them, the table is
reset to the collection's default columns instead of the user's
preferred columns. This is because when sorting columns, a stale
client-side cache of the user's preferences is used to update their sort
preference. This is because when column state is constructed
server-side, it completely bypasses the client-side cache. To fix this,
sort preferences are now also set on the server right alongside column
preferences, which performs an upsert-like operation to ensure that no
existing preferences are lost.
2025-01-06 16:57:19 -05:00
Amir Aryan
df827c0fdd chore(examples): set HTML dir attribute for RTL locales #10344 (#10345)
fix [#10344](https://github.com/payloadcms/payload/issues/10344)

The template was missing defining direction.

direction property is necessary because HTML direction will be LTR for
RTL languages by default.
2025-01-06 14:40:22 -06:00
Paul
398b6096f2 templates: fix nested docs url generation for categories (#10403)
Fixes https://github.com/payloadcms/payload/issues/10374
2025-01-06 14:18:54 -06:00
Patrik
eadce5ea57 fix: extends type all to the locale type definition in req (#10399)
### What?

If you query with all locales using the `'all'` value for locales, the
`req.locale` value is `'all'` but the type definition only contains the
available locales.

### Why?

The `CustomPayloadRequestProperties.locale` property was only being
typed as `TypedLocale` and was not extending `'all'.`

### How?

Extends type all to the locale type definition in req

Fixes #10244
2025-01-06 15:18:08 -05:00
Elliot DeNolf
f629709797 fix: increase safety of findConfig (#10400)
If `@payload-config` is not set in tsconfig, findConfig could fail when
performing a `path.extname` on an undefined value.

Example error in this scenario:
```
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined.
```
2025-01-06 14:11:11 -05:00
Germán Jabloñski
d772b2b7eb fix(richtext-lexical): modify JSXConvertersFunction type to support block types in strict mode (#10398)
Reproduction steps:
1. Set `strict: true` in `templates/website/tsconfig.json`
2. You will find a ts error in
`templates/website/src/components/RichText/index.tsx`.

This is because the blockType property of blocks is generated by Payload
as a literal (e.g. "mediaBlock") and cannot be assigned to a string.

To test this PR, you can make the change to `JSXConvertersFunction` in
node_modules of the website template
2025-01-06 18:01:38 +00:00
Elliot DeNolf
22c4dee5a0 feat: warn if deploying to vercel and any upload collection missing storage adapter (#10391)
A large number of users have been confused why their upload collection
doesn't work as expected when deploying to Vercel. This is because by
default, Payload uses local disk storage for file uploads - which will
not function properly in that environment.

This adds a warning if a user is deploying on Vercel, and they have any
upload collection missing an adapter - aka, writing to disk.
2025-01-06 16:21:07 +00:00
Sasha
c1abd16a7f templates: use cross-env in the plugin template to achieve compatibility with Windows (#10390)
### What?
Uses `cross-env` for the `dev:payload` script in the plugin template.

### Why?
To achieve compatibility with Windows. 

### How?
Adds `cross-env` as a dev dependency and modifies the `dev:payload`
script.
2025-01-06 18:00:12 +02:00
bakaptr
d2127335b9 fix: handle withoutEnlargement for undefined height or width (#10078)
<!--

Thank you for the PR! Please go through the checklist below and make
sure you've completed all the steps.

Please review the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository if you haven't already.

The following items will ensure that your PR is handled as smoothly as
possible:

- PR Title must follow conventional commits format. For example, `feat:
my new feature`, `fix(plugin-seo): my fix`.
- Minimal description explained as if explained to someone not
immediately familiar with the code.
- Provide before/after screenshots or code diffs if applicable.
- Link any related issues/discussions from GitHub or Discord.
- Add review comments if necessary to explain to the reviewer the logic
behind a change

-->

### What?

This patch implements the functionality in `imageResizer` to omit the
generation of the image when either width or height is undefined and
`withoutEnlargement` is set to `undefined`

### Why?

#9986: `withoutEnlargement` doesn't work when `height` is undefined in
`upload.imageSizes`

### How?

This code checks if `withoutEnlargement` is undefined and either
`targetWidth` or `targetHeight` is missing. If so, it further checks
whether the target dimensions (if provided) are larger than the original
image dimensions. If the target would enlarge the image, it returns
'omit', skipping the resizing to prevent enlargement

Fixes #9986

---------

Co-authored-by: Patrik Kozak <patrik@payloadcms.com>
2025-01-06 10:50:44 -05:00