Compare commits

...

97 Commits

Author SHA1 Message Date
Dan Ribbens
43cdb45620 fix: mongodb multiple error rollback transaction 2023-11-22 11:53:45 -05:00
Jessica Chowdhury
6364afb1dd docs: updates vite alias example and fixes broken link (#4224) 2023-11-21 14:34:18 -05:00
Radosław Kłos
56a4692662 fix: typo in polish translations (#4234) 2023-11-21 13:09:00 -05:00
Dan Ribbens
ef6b8e4235 test: graphql handle deleted relationships (#4229) 2023-11-21 13:07:13 -05:00
Elliot DeNolf
5f5290341a chore(plugin-cloud-storage): adjust prepublishOnly script 2023-11-21 10:28:35 -05:00
Elliot DeNolf
62403584ad chore(scripts): cleanup package details log 2023-11-21 10:28:17 -05:00
Jarrod Flesch
19fcfc27af fix: number field validation (#4233) 2023-11-21 10:12:26 -05:00
Elliot DeNolf
dcf14f5f71 chore(release): payload/2.2.1 [skip ci] 2023-11-21 10:08:07 -05:00
Elliot DeNolf
3a784a06cc fix: make outputSchema optional on richtext config (#4230) 2023-11-21 09:45:57 -05:00
Jessica Chowdhury
6eeae9d53b examples: updates blank template readme (#4216) 2023-11-21 08:40:01 -05:00
Jarrod Flesch
6044f810bd docs: correct PULL_REQUEST_TEMPLATE.md links 2023-11-21 08:37:57 -05:00
Elliot DeNolf
e68ca9363f fix(plugin-cloud-storage): adjust webpack aliasing for pnpm (#4228) 2023-11-20 16:53:30 -05:00
Elliot DeNolf
9963b8d945 chore(release): plugin-nested-docs/1.0.9 [skip ci] 2023-11-20 16:40:46 -05:00
Elliot DeNolf
9afb838182 chore(release): richtext-slate/1.2.0 [skip ci] 2023-11-20 16:39:38 -05:00
Elliot DeNolf
2dad129022 chore(release): richtext-lexical/0.2.0 [skip ci] 2023-11-20 16:39:20 -05:00
Elliot DeNolf
6af1c4d45d chore(release): payload/2.2.0 [skip ci] 2023-11-20 16:36:41 -05:00
Dan Ribbens
4e41dd1bf2 fix(plugin-nested-docs): await populate breadcrumbs on resaveChildren (#4226) 2023-11-20 16:32:02 -05:00
Dan Ribbens
de02490231 feat: hide publish button based on permissions (#4203)
Co-authored-by: James <james@trbl.design>
2023-11-20 16:26:49 -05:00
Take Weiland
1510baf46e fix: synchronous transaction errors (#4164)
Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
2023-11-20 12:20:42 -05:00
Alessio Gravili
c10db332cd docs(richtext-lexical): remove unnecessary await from createHeadlessEditor (#4213) 2023-11-19 14:40:09 +01:00
Alessio Gravili
0af9c4d398 fix(richtext-lexical): Blocks: Array row data is not removed (#4209)
* chore(richtext-lexical): Add failing test which reproduces issue

* fix(richtext-lexical): fix the actual issue
2023-11-18 14:01:57 +01:00
Alessio Gravili
fc137c0f53 Merge pull request #4210 from payloadcms/chore/upgrade-lexical
chore(richtext-lexical): Upgrade lexical from 0.12.2 to 0.12.4 and port some playground changes over
2023-11-18 12:59:24 +01:00
Alessio Gravili
a24f2be4a6 chore(richtext-lexical): backport setFloatingElemPositionForLinkEditor type change from playground 2023-11-18 12:54:40 +01:00
Alessio Gravili
57999adfe2 chore(richtext-lexical): backport autolink changes from lexical playground 2023-11-18 12:51:08 +01:00
Alessio Gravili
7857043d03 chore(richtext-lexical): Upgrade lexical packages 2023-11-18 12:37:28 +01:00
Alessio Gravili
3b93af734b Merge pull request #4207 from payloadcms/fix/lexical-validations-
fix(richtext-lexical): Blocks: fields without fulfilled condition are now skipped for validation
2023-11-18 11:55:41 +01:00
Alessio Gravili
50fab902bd fix(richtext-lexical): Blocks: fields without fulfilled condition are now skipped for validation 2023-11-18 11:52:30 +01:00
Alessio Gravili
724d80b7f4 Merge pull request #4196 from payloadcms/docs/lexical-editorconfig
docs(richtext-lexical): various documentation improvements
2023-11-17 18:39:11 +01:00
Alessio Gravili
b406e6afb9 docs(richtext-lexical): various documentation improvements 2023-11-17 18:38:09 +01:00
Alessio Gravili
3f46b21eb2 Merge pull request #4192 from payloadcms/feat/lexical-top
feat(richtext-lexical): Add new position: 'top' property for plugins
2023-11-17 18:20:29 +01:00
Alessio Gravili
eed4f4361c feat(richtext-lexical): Add new position: 'top' property for plugins 2023-11-17 18:18:54 +01:00
Jarrod Flesch
05f3169a75 fix: thread locale through to access routes from admin panel (#4183) 2023-11-17 10:15:12 -05:00
Alessio Gravili
94f1443ce4 Merge pull request #4176 from payloadcms/fix/missing-use-client
fix(richtext-lexical): add missing 'use client' to TestRecorder
2023-11-16 22:38:52 +01:00
Alessio Gravili
fc26275b7a fix(richtext-lexical): add missing 'use client' to TestRecorder feature plugin 2023-11-16 22:37:37 +01:00
Alessio Gravili
e57f5e2aa0 Merge pull request #4175 from payloadcms/fix/lexical-html-globals
fix(richtext-lexical): make lexicalHTML() function work for globals
2023-11-16 22:11:54 +01:00
Alessio Gravili
dbfc83520c fix(richtext-lexical): make lexicalHTML() function work for globals 2023-11-16 22:10:00 +01:00
Alessio Gravili
c068a8784e fix(richtext-lexical): Blocks: make sure fields are wrapped in a uniquely-named group, change block node data format, fix react key error (#3995)
* fix(richtext-lexical): make sure block fields are wrapped in a uniquely-named group

* chore: remove redundant hook

* chore(richtext-lexical): attempt to fix unnecessary unsaved changes warning regression

* cleanup everything

* chore: more cleanup

* debug

* looks like properly cloning the formdata for setting initial state fixes the issue where the old formdata is updated even if node.setFields is not called

* chore: fix e2e tests

* chore: fix e2e tests (a selector has changed)

* chore: fix int tests (due to new blocks data format)

* chore: fix incorrect insert block commands in drawer

* chore: add new e2e test

* chore: fail e2e tests when there are browser console errors

* fix(breaking): beforeInput and afterInput: fix missing key errors, consistent typing and cases in name
2023-11-16 22:01:04 +01:00
Alessio Gravili
989c10e0e0 feat: allow richtext adapters to control type generation, improve generated lexical types (#4036) 2023-11-16 11:36:20 -05:00
Alessio Gravili
3bf2b7a3fe Merge pull request #4171 from zakinadhif/main
fix(richtext-lexical): visual bug after rearranging blocks
2023-11-16 17:23:41 +01:00
Zaki Nadhif
a6b486007d fix(richtext-lexical): visual bug after rearranging blocks 2023-11-16 22:38:34 +07:00
Wilson
4e03ee7079 chore: adds doc blocks for field access properties (#3973) 2023-11-16 09:15:04 -05:00
Quentin Beauperin
b91711a74a fix: improves live preview breakpoints and zoom options in dark mode (#4090) 2023-11-16 09:10:33 -05:00
Jonathan Wu
191c13a409 chore(examples/form-builder): improve form input accessibility (#4166) 2023-11-16 08:02:15 -05:00
Alessio Gravili
b210af4696 fix(richtext-lexical): incorrect caret positioning when selecting second line of multi-line paragraph (#4165) 2023-11-15 22:22:42 +01:00
Taís Massaro
8cebd2ccce docs: correct useTableColumns react import path in example (#4150) 2023-11-15 08:20:42 -05:00
Take Weiland
195a952c43 fix: transactionID isolation for GraphQL (#4095) 2023-11-14 16:07:10 -05:00
Alessio Gravili
4bc5fa7086 chore(richtext-lexical): remove unused defaultValue prop in RichText component (#4146) 2023-11-14 18:31:04 +01:00
Alessio Gravili
2c8d34d2aa fix(richtext-lexical): remove optional chaining after this as transpilers are not handling it well (#4145) 2023-11-14 18:21:51 +01:00
Alessio Gravili
4ec5643dd7 chore: restricts character length in table cells (#4063) 2023-11-14 11:25:24 -05:00
Jessica Chowdhury
45e9a559bb fix: upload fit not accounted for when editing focal point or crop (#4142)
Co-authored-by: Jarrod Flesch <jarrodmflesch@gmail.com>
2023-11-14 11:19:23 -05:00
Jessica Chowdhury
d6233cbf42 templates: update fetch request in populateArchiveBlock hook (#4127) 2023-11-14 11:16:16 -05:00
Jessica Chowdhury
ad3e23b345 chore: updates translation key in dropzone component (#4135) 2023-11-14 11:09:09 -05:00
Radosław Kłos
782e118569 fix(i18n): polish translations (#4134) 2023-11-14 11:06:59 -05:00
Jessica Chowdhury
dbfe4af993 chore: corrects block name overflow in UI (#4138) 2023-11-14 10:56:35 -05:00
Alessio Gravili
859c2f4a6d fix(richtext-lexical): nested editor may lose focus when writing (#4139) 2023-11-14 15:42:30 +01:00
Elliot DeNolf
a34d0f8274 fix(templates): yarn v1 workaround (#4125) 2023-11-13 11:53:57 -05:00
Jessica Chowdhury
967eff1aab fix: rename tab button classname to prevent unintentional styling (#4121) 2023-11-13 08:39:16 -05:00
Alessio Gravili
b7041d6ab1 chore(richtext-lexical): New e2e test: should allow adding new blocks to a sub-blocks field, part of a parent lexical blocks field (#4114) 2023-11-12 23:48:13 +01:00
Alessio Gravili
78b7bd62cd Merge pull request #4113 from payloadcms/fix/4025
fix(richtext-lexical): Blocks: z-index and floating select menu button click issues
2023-11-12 23:17:53 +01:00
Alessio Gravili
7329b1babd chore(richtext-lexical): Remove unnecessary console.log 2023-11-12 23:17:33 +01:00
Alessio Gravili
c87969b7f9 chore(richtext-lexical): Add e2e test: 'ensure slash menu is not hidden behind other blocks' 2023-11-12 23:12:24 +01:00
Alessio Gravili
09f17f4450 fix(richtext-lexical): Blocks: z-index issue, e.g. select field dropdown in blocks hidden behind blocks below, or slash menu inside nested editor hidden behind blocks below 2023-11-12 22:28:05 +01:00
Alessio Gravili
615702b858 fix(richtext-lexical): Floating Select Toolbar: Buttons and Dropdown Buttons not clickable in nested editors
Fixes #4025
2023-11-12 22:09:36 +01:00
Alessio Gravili
f0642ce031 chore(richtext-lexical): add a bunch of e2e tests, including a failing one 2023-11-12 21:44:18 +01:00
Alessio Gravili
56db87d2ec Merge pull request #4104 from payloadcms/chore/console-log-remove
chore: remove unnecessary console.log
2023-11-11 12:58:54 +01:00
Alessio Gravili
45c42724a4 chore: remove unnecessary console.log 2023-11-11 12:57:22 +01:00
Alessio Gravili
a6d5f2e3de fix(richtext-lexical): HTMLConverter: cannot find nested lexical fields (#4103)
Fixes #4034
2023-11-11 12:54:33 +01:00
Elliot Lintz
73b8549ef5 chore: fix readme badge link styles (#4101) 2023-11-10 17:37:50 -05:00
Jarrod Flesch
e22b95bdf3 fix: fully define the define property for esbuild string replacement (#4099) 2023-11-10 13:47:14 -05:00
Jessica Chowdhury
56ddd2c388 chore: update date field schema (#4098) 2023-11-10 12:25:03 -05:00
Jessica Chowdhury
803a37eaa9 fix: simplifies block/array/hasMany-number field validations (#4052)
Co-authored-by: Jarrod Flesch <jarrodmflesch@gmail.com>
2023-11-10 12:06:21 -05:00
Elliot DeNolf
d308bb3421 chore(release): richtext-lexical/0.1.17 [skip ci] 2023-11-10 10:42:33 -05:00
Elliot DeNolf
cbc4752ecb chore(release): plugin-sentry/0.0.6 [skip ci] 2023-11-10 10:42:26 -05:00
Elliot DeNolf
c51f9d01cb chore(release): live-preview-react/0.1.6 [skip ci] 2023-11-10 10:42:18 -05:00
Elliot DeNolf
d19d8fd232 chore(release): live-preview/0.1.6 [skip ci] 2023-11-10 10:42:11 -05:00
Elliot DeNolf
5dbbd8f88b chore(release): db-mongodb/1.0.8 [skip ci] 2023-11-10 10:42:00 -05:00
Elliot DeNolf
47bd3894c4 chore(release): payload/2.1.1 [skip ci] 2023-11-10 10:40:45 -05:00
Elliot DeNolf
a57c68cd04 chore(plugin-sentry): set version to latest instead of beta for release notes 2023-11-10 10:38:12 -05:00
Take Weiland
acad2888cd fix: fixes creation of related documents within a transaction if filterOptions is used (#4087) 2023-11-10 10:37:58 -05:00
Alessio Gravili
db2da71357 Merge pull request #4097 from payloadcms/docs/disableIndexHints
docs: document disableIndexHints property
2023-11-10 16:31:05 +01:00
Alessio Gravili
cbb4ce2f51 docs: document disableIndexHints property 2023-11-10 16:23:21 +01:00
Dan Ribbens
47efd3b92e fix(plugin-nested-docs): sync write transaction errors (#4084) 2023-11-10 10:16:31 -05:00
Dan Ribbens
348a70cc33 fix: possible issue with access control not using req (#4086) 2023-11-10 10:15:07 -05:00
Alessio Gravili
9f873f8630 chore(db-mongodb): add option to disable index hint optimization, which breaks on AWS DocumentDB (#3997)
* chore: add option to disable pagination count index hinting optimization

* chore: rename hintPaginationCountIndex to disablePaginationCountIndexHint

* chore: fix logic

* chore: disablePaginationCountIndexHint => disableIndexHints
2023-11-10 16:08:14 +01:00
Jessica Chowdhury
949e265cd9 fix: disable editing option for svg image types (#4071)
Co-authored-by: Jarrod Flesch <jarrodmflesch@gmail.com>
2023-11-10 00:35:04 -05:00
Jessica Chowdhury
687f4850ac fix: hide empty image sizes from the preview drawer (#3946)
Co-authored-by: Jarrod Flesch <jarrodmflesch@gmail.com>
2023-11-09 22:34:50 -05:00
Jacob Fletcher
1f851f21b1 fix(live-preview): properly handles apiRoute (#4076) 2023-11-09 13:14:41 -05:00
Jarrod Flesch
dbc4ce71e6 chore: fixes test suites that use clearAndSeedEverything (#4080) 2023-11-09 12:30:19 -05:00
Patrik
cef4cbb0ee fix: conditionally hide dot menu in DocumentControls (#4075) 2023-11-09 12:01:58 -05:00
Jacob Fletcher
7059a71243 fix(live-preview): ensures field schema exists before traversing fields (#4074) 2023-11-09 10:08:10 -05:00
Jacob Fletcher
01559ef34b chore: prevents field validation from triggering unnecessary re-renders (#4066) 2023-11-09 09:46:35 -05:00
Jacob Fletcher
8488f7b8db docs: adds apiRoute to useLivePreview args (#4073) 2023-11-09 09:01:04 -05:00
Michał Korczak
a92a160a13 docs: fix link to public demo example config (#4007) 2023-11-09 00:23:58 -05:00
PatrikKozak
77a7c83251 chore: updates default type value for graphql playground type 2023-11-08 18:30:55 -05:00
Jacob Fletcher
2ad7340154 fix(live-preview): field recursion and relationship population (#4045) 2023-11-08 17:28:35 -05:00
Alessio Gravili
c462df38f6 fix(richtext-lexical): floating select toolbar caret not positioned correctly if first line is selected (#4062) 2023-11-08 22:13:38 +01:00
Alessio Gravili
fff377ad22 fix(richtext-lexical): Blocks: unnecessary saving node value when initially opening a document & new lexical tests (#4059)
* chore: new lexical int tests and working test structure

* chore: more int tests, and better lexical collection structure

* fix(richtext-lexical): Blocks: unnecessary saving node value when initially opening a document
2023-11-08 21:32:43 +01:00
265 changed files with 6918 additions and 3638 deletions

View File

@@ -12,8 +12,8 @@
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Change to the [templates](../templates/) directory (does not affect core functionality)
- [ ] Change to the [examples](../examples/) directory (does not affect core functionality)
- [ ] Change to the [templates](https://github.com/payloadcms/payload/tree/main/templates) directory (does not affect core functionality)
- [ ] Change to the [examples](https://github.com/payloadcms/payload/tree/main/examples) directory (does not affect core functionality)
- [ ] This change requires a documentation update
## Checklist:

7
.vscode/launch.json vendored
View File

@@ -64,6 +64,13 @@
"NODE_ENV": "production"
}
},
{
"command": "pnpm run test:int live-preview",
"cwd": "${workspaceFolder}",
"name": "Live Preview Integration",
"request": "launch",
"type": "node-terminal"
},
{
"command": "ts-node ./packages/payload/src/bin/index.ts build",
"env": {

View File

@@ -1,3 +1,62 @@
## [2.2.1](https://github.com/payloadcms/payload/compare/v2.2.0...v2.2.1) (2023-11-21)
### Bug Fixes
* make outputSchema optional on richtext config ([#4230](https://github.com/payloadcms/payload/issues/4230)) ([3a784a0](https://github.com/payloadcms/payload/commit/3a784a06cc6c42c96b8d6cf023d942e6661be7b5))
## [2.2.0](https://github.com/payloadcms/payload/compare/v2.1.1...v2.2.0) (2023-11-20)
### Features
* allow richtext adapters to control type generation, improve generated lexical types ([#4036](https://github.com/payloadcms/payload/issues/4036)) ([989c10e](https://github.com/payloadcms/payload/commit/989c10e0e0b36a8c34822263b19f5cb4b9ed6e72))
* hide publish button based on permissions ([#4203](https://github.com/payloadcms/payload/issues/4203)) ([de02490](https://github.com/payloadcms/payload/commit/de02490231fbc8936973c1b81ac87add39878d8b))
* **richtext-lexical:** Add new position: 'top' property for plugins ([eed4f43](https://github.com/payloadcms/payload/commit/eed4f4361cd012adf4e777820adbe7ad330ffef6))
### Bug Fixes
* fully define the define property for esbuild string replacement ([#4099](https://github.com/payloadcms/payload/issues/4099)) ([e22b95b](https://github.com/payloadcms/payload/commit/e22b95bdf3b2911ae67a07a76ec109c76416ea56))
* **i18n:** polish translations ([#4134](https://github.com/payloadcms/payload/issues/4134)) ([782e118](https://github.com/payloadcms/payload/commit/782e1185698abb2fff3556052fd16d2b725611b9))
* improves live preview breakpoints and zoom options in dark mode ([#4090](https://github.com/payloadcms/payload/issues/4090)) ([b91711a](https://github.com/payloadcms/payload/commit/b91711a74ad9379ed820b6675060209626b1c2d0))
* **plugin-nested-docs:** await populate breadcrumbs on resaveChildren ([#4226](https://github.com/payloadcms/payload/issues/4226)) ([4e41dd1](https://github.com/payloadcms/payload/commit/4e41dd1bf2706001fa03130adb1c69403795ac96))
* rename tab button classname to prevent unintentional styling ([#4121](https://github.com/payloadcms/payload/issues/4121)) ([967eff1](https://github.com/payloadcms/payload/commit/967eff1aabcc9ba7f29573fc2706538d691edfdd))
* **richtext-lexical:** add missing 'use client' to TestRecorder feature plugin ([fc26275](https://github.com/payloadcms/payload/commit/fc26275b7a85fd34f424f7693b8383ad4efe0121))
* **richtext-lexical:** Blocks: Array row data is not removed ([#4209](https://github.com/payloadcms/payload/issues/4209)) ([0af9c4d](https://github.com/payloadcms/payload/commit/0af9c4d3985a6c46a071ef5ac28c8359cb320571))
* **richtext-lexical:** Blocks: fields without fulfilled condition are now skipped for validation ([50fab90](https://github.com/payloadcms/payload/commit/50fab902bd7baa1702ae0d995b4f58c1f5fca374))
* **richtext-lexical:** Blocks: make sure fields are wrapped in a uniquely-named group, change block node data format, fix react key error ([#3995](https://github.com/payloadcms/payload/issues/3995)) ([c068a87](https://github.com/payloadcms/payload/commit/c068a8784ec5780dbdca5416b25ba654afd05458))
* **richtext-lexical:** Blocks: z-index issue, e.g. select field dropdown in blocks hidden behind blocks below, or slash menu inside nested editor hidden behind blocks below ([09f17f4](https://github.com/payloadcms/payload/commit/09f17f44508539cfcb8722f7f462ef40d9ed54fd))
* **richtext-lexical:** Floating Select Toolbar: Buttons and Dropdown Buttons not clickable in nested editors ([615702b](https://github.com/payloadcms/payload/commit/615702b858e76994a174159cb69f034ef811e016)), closes [#4025](https://github.com/payloadcms/payload/issues/4025)
* **richtext-lexical:** HTMLConverter: cannot find nested lexical fields ([#4103](https://github.com/payloadcms/payload/issues/4103)) ([a6d5f2e](https://github.com/payloadcms/payload/commit/a6d5f2e3dea178e1fbde90c0d6a5ce254a8db0d1)), closes [#4034](https://github.com/payloadcms/payload/issues/4034)
* **richtext-lexical:** incorrect caret positioning when selecting second line of multi-line paragraph ([#4165](https://github.com/payloadcms/payload/issues/4165)) ([b210af4](https://github.com/payloadcms/payload/commit/b210af46968b77d96ffd6ef60adc3b8d8bdc9376))
* **richtext-lexical:** make lexicalHTML() function work for globals ([dbfc835](https://github.com/payloadcms/payload/commit/dbfc83520ca8b5e55198a3c4b517ae3a80f9cac6))
* **richtext-lexical:** nested editor may lose focus when writing ([#4139](https://github.com/payloadcms/payload/issues/4139)) ([859c2f4](https://github.com/payloadcms/payload/commit/859c2f4a6d299a42e572133502b3841a74a11002))
* **richtext-lexical:** remove optional chaining after `this` as transpilers are not handling it well ([#4145](https://github.com/payloadcms/payload/issues/4145)) ([2c8d34d](https://github.com/payloadcms/payload/commit/2c8d34d2aadf2fcaf0655c0abef233f341d9945f))
* **richtext-lexical:** visual bug after rearranging blocks ([a6b4860](https://github.com/payloadcms/payload/commit/a6b486007dc26195adc5d576d937e35471c2868f))
* simplifies block/array/hasMany-number field validations ([#4052](https://github.com/payloadcms/payload/issues/4052)) ([803a37e](https://github.com/payloadcms/payload/commit/803a37eaa947397fa0a93b9f4f7d702c6b94ceaa))
* synchronous transaction errors ([#4164](https://github.com/payloadcms/payload/issues/4164)) ([1510baf](https://github.com/payloadcms/payload/commit/1510baf46e33540c72784f2d3f98330a8ff90923))
* thread locale through to access routes from admin panel ([#4183](https://github.com/payloadcms/payload/issues/4183)) ([05f3169](https://github.com/payloadcms/payload/commit/05f3169a75b3b62962e7fe7842fbb6df6699433d))
* transactionID isolation for GraphQL ([#4095](https://github.com/payloadcms/payload/issues/4095)) ([195a952](https://github.com/payloadcms/payload/commit/195a952c4314e0d53fd579517035373b49d6ccae))
* upload fit not accounted for when editing focal point or crop ([#4142](https://github.com/payloadcms/payload/issues/4142)) ([45e9a55](https://github.com/payloadcms/payload/commit/45e9a559bbb16b2171465c8a439044011cebf102))
## [2.1.1](https://github.com/payloadcms/payload/compare/v2.1.0...v2.1.1) (2023-11-10)
### Bug Fixes
* conditionally hide dot menu in DocumentControls ([#4075](https://github.com/payloadcms/payload/issues/4075)) ([cef4cbb](https://github.com/payloadcms/payload/commit/cef4cbb0ee59e1b0b806808d79b402dce114755f))
* disable editing option for svg image types ([#4071](https://github.com/payloadcms/payload/issues/4071)) ([949e265](https://github.com/payloadcms/payload/commit/949e265cd9c95b7d4063336dde86177008d54839))
* fixes creation of related documents within a transaction if filterOptions is used ([#4087](https://github.com/payloadcms/payload/issues/4087)) ([acad288](https://github.com/payloadcms/payload/commit/acad2888cd9a13d5fb9e4c686b2267ea69454eaf))
* hide empty image sizes from the preview drawer ([#3946](https://github.com/payloadcms/payload/issues/3946)) ([687f485](https://github.com/payloadcms/payload/commit/687f4850acf073df0a649ef6182bfc8387857173))
* **live-preview:** ensures field schema exists before traversing fields ([#4074](https://github.com/payloadcms/payload/issues/4074)) ([7059a71](https://github.com/payloadcms/payload/commit/7059a71243a8f98dcc89af0bfe502247db9e4123))
* **live-preview:** field recursion and relationship population ([#4045](https://github.com/payloadcms/payload/issues/4045)) ([2ad7340](https://github.com/payloadcms/payload/commit/2ad73401546ef6608fd67d1f00b537f149640d6a))
* **live-preview:** properly handles apiRoute ([#4076](https://github.com/payloadcms/payload/issues/4076)) ([1f851f2](https://github.com/payloadcms/payload/commit/1f851f21b18c9a5076d9afc9a31abc7a97fcb0df))
* **plugin-nested-docs:** sync write transaction errors ([#4084](https://github.com/payloadcms/payload/issues/4084)) ([47efd3b](https://github.com/payloadcms/payload/commit/47efd3b92e99594dd5b61f0017f4eb76e1d36eb7))
* possible issue with access control not using req ([#4086](https://github.com/payloadcms/payload/issues/4086)) ([348a70c](https://github.com/payloadcms/payload/commit/348a70cc33409b0b48aff3acd2b94c2df5d88f3b))
* **richtext-lexical:** Blocks: unnecessary saving node value when initially opening a document & new lexical tests ([#4059](https://github.com/payloadcms/payload/issues/4059)) ([fff377a](https://github.com/payloadcms/payload/commit/fff377ad22cce3b26142cde8f4125fcee95aa072))
* **richtext-lexical:** floating select toolbar caret not positioned correctly if first line is selected ([#4062](https://github.com/payloadcms/payload/issues/4062)) ([c462df3](https://github.com/payloadcms/payload/commit/c462df38f65b155e131e6a7b46b2bb16cd090e45))
## [2.1.0](https://github.com/payloadcms/payload/compare/v2.0.15...v2.1.0) (2023-11-08)

View File

@@ -1,24 +1,14 @@
<a href="https://payloadcms.com">
<img width="100%" src="https://github.com/payloadcms/payload/blob/main/packages/payload/src/admin/assets/images/github-banner-alt.jpg?raw=true" alt="Payload headless CMS Admin panel built with React" />
</a>
<a href="https://payloadcms.com"><img width="100%" src="https://github.com/payloadcms/payload/blob/main/packages/payload/src/admin/assets/images/github-banner-alt.jpg?raw=true" alt="Payload headless CMS Admin panel built with React" /></a>
<br />
<br />
<p align="left">
<a href="https://github.com/payloadcms/payload/actions">
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/payloadcms/payload/main.yml?style=flat-square">
</a>
<a href="https://github.com/payloadcms/payload/actions"><img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/payloadcms/payload/main.yml?style=flat-square"></a>
&nbsp;
<a href="https://discord.gg/payload">
<img alt="Discord" src="https://img.shields.io/discord/967097582721572934?label=Discord&color=7289da&style=flat-square" />
</a>
<a href="https://discord.gg/payload"><img alt="Discord" src="https://img.shields.io/discord/967097582721572934?label=Discord&color=7289da&style=flat-square" /></a>
&nbsp;
<a href="https://www.npmjs.com/package/payload">
<img alt="npm" src="https://img.shields.io/npm/v/payload?style=flat-square" />
</a>
<a href="https://www.npmjs.com/package/payload"><img alt="npm" src="https://img.shields.io/npm/v/payload?style=flat-square" /></a>
&nbsp;
<a href="https://twitter.com/payloadcms">
<img src="https://img.shields.io/badge/follow-payloadcms-1DA1F2?logo=twitter&style=flat-square" alt="Payload Twitter" />
</a>
<a href="https://twitter.com/payloadcms"><img src="https://img.shields.io/badge/follow-payloadcms-1DA1F2?logo=twitter&style=flat-square" alt="Payload Twitter" /></a>
</p>
<hr/>
<h4>

View File

@@ -432,14 +432,14 @@ All Payload fields support the ability to swap in your own React components. So,
| **`Cell`** | Used in the `List` view's table to represent a table-based preview of the data stored in the field. [More](#cell-component) |
| **`Field`** | Swap out the field itself within all `Edit` views. [More](#field-component) |
As an alternative to replacing the entire Field component, you may want to keep the majority of the default Field component and only swap components within. This allows you to replace the **`Label`** or **`Error`** within a field component or add additional components inside the field with **`BeforeInput`** or **`AfterInput`**. **`BeforeInput`** and **`AfterInput`** are allowed in any fields that don't contain other fields, except [UI](/docs/fields/ui) and [Rich Text](/docs/fields/rich-text).
As an alternative to replacing the entire Field component, you may want to keep the majority of the default Field component and only swap components within. This allows you to replace the **`Label`** or **`Error`** within a field component or add additional components inside the field with **`beforeInput`** or **`afterInput`**. **`beforeInput`** and **`afterInput`** are allowed in any fields that don't contain other fields, except [UI](/docs/fields/ui) and [Rich Text](/docs/fields/rich-text).
| Component | Description |
| ----------------- | --------------------------------------------------------------------------------------------------------------- |
| **`Label`** | Override the default Label in the Field Component. [More](#label-component) |
| **`Error`** | Override the default Label in the Field Component. [More](#error-component) |
| **`BeforeInput`** | An array of elements that will be added before `input`/`textarea` elements. [More](#afterinput-and-beforeinput) |
| **`AfterInput`** | An array of elements that will be added after `input`/`textarea` elements. [More](#afterinput-and-beforeinput) |
| **`beforeInput`** | An array of elements that will be added before `input`/`textarea` elements. [More](#afterinput-and-beforeinput) |
| **`afterInput`** | An array of elements that will be added after `input`/`textarea` elements. [More](#afterinput-and-beforeinput) |
## Cell Component
@@ -530,7 +530,7 @@ const CustomLabel: React.FC<Props> = (props) => {
{getTranslation(label, i18n)}
{required && <span className="required">*</span>}
</span>);
}
}
return null
}
@@ -564,7 +564,7 @@ const CustomError: React.FC<Props> = (props) => {
}
```
## AfterInput and BeforeInput
## afterInput and beforeInput
With these properties you can add multiple components before and after the input element. For example, you can add an absolutely positioned button to clear the current field value.
@@ -583,9 +583,7 @@ const fieldField: Field = {
type: 'text',
admin: {
components: {
AfterInput: [
<ClearButton />
]
afterInput: [ClearButton]
}
}
}

View File

@@ -172,20 +172,34 @@ export default buildConfig({
collections: [Subscriptions],
admin: {
bundler: viteBundler(),
vite: (config) => {
return {
...config,
resolve: {
...config.resolve,
// highlight-start
alias: {
...config.resolve.alias,
// remember, vite aliases are exact-match only
'./hooks/createStripeSubscription': mockModulePath,
},
// highlight-end
},
vite: (incomingViteConfig) => {
const existingAliases = incomingViteConfig?.resolve?.alias || {};
let aliasArray: { find: string | RegExp; replacement: string; }[] = [];
// Pass the existing Vite aliases
if (Array.isArray(existingAliases)) {
aliasArray = existingAliases;
} else {
aliasArray = Object.values(existingAliases);
}
// highlight-start
// Add your own aliases using the find and replacement keys
// remember, vite aliases are exact-match only
aliasArray.push({
find: '../server-only-module',
replacement: path.resolve(__dirname, './path/to/browser-safe-module.js')
});
// highlight-end
return {
...incomingViteConfig,
resolve: {
...(incomingViteConfig?.resolve || {}),
alias: aliasArray,
}
};
},
},
})

View File

@@ -764,7 +764,7 @@ Returns methods to set and get user preferences. More info can be found [here](h
Returns methods to manipulate table columns
```tsx
import { useTableColumns } from 'payload/components/utilities'
import { useTableColumns } from 'payload/components/hooks'
const MyComponent: React.FC = () => {
// highlight-start

View File

@@ -60,17 +60,33 @@ export const buildConfig({
collections: [],
admin: {
bundler: viteBundler(),
vite: (incomingViteConfig) => ({
...incomingViteConfig,
resolve: {
...(incomingViteConfig?.resolve || {}),
alias: {
...(incomingViteConfig?.resolve?.alias || {}),
'../server-only-module': path.resolve(__dirname, './path/to/browser-safe-module.js'),
'../../server-only-module': path.resolve(__dirname, './path/to/browser-safe-module.js'),
}
vite: (incomingViteConfig) => {
const existingAliases = incomingViteConfig?.resolve?.alias || {};
let aliasArray: { find: string | RegExp; replacement: string; }[] = [];
// Pass the existing Vite aliases
if (Array.isArray(existingAliases)) {
aliasArray = existingAliases;
} else {
aliasArray = Object.values(existingAliases);
}
})
// Add your own aliases using the find and replacement keys
aliasArray.push({
find: '../server-only-module',
replacement: path.resolve(__dirname, './path/to/browser-safe-module.js')
find: '../../server-only-module',
replacement: path.resolve(__dirname, './path/to/browser-safe-module.js')
});
return {
...incomingViteConfig,
resolve: {
...(incomingViteConfig?.resolve || {}),
alias: aliasArray,
}
};
},
}
})
```
@@ -90,7 +106,8 @@ That plugin should create an alias to support Vite as follows:
```ts
{
// aliases go here
'payload-plugin-cool': path.resolve(__dirname, './my-admin-plugin.js')
find: 'payload-plugin-cool',
replacement: path.resolve(__dirname, './my-admin-plugin.js')
}
```
@@ -108,22 +125,36 @@ export const buildConfig({
collections: [],
admin: {
bundler: viteBundler(),
vite: (incomingViteConfig) => ({
...incomingViteConfig,
resolve: {
...(incomingViteConfig?.resolve || {}),
alias: {
...(incomingViteConfig?.resolve?.alias || {}),
// custom aliases go here
'../server-only-module': path.resolve(__dirname, './path/to/browser-safe-module.js'),
}
vite: (incomingViteConfig) => {
const existingAliases = incomingViteConfig?.resolve?.alias || {};
let aliasArray: { find: string | RegExp; replacement: string; }[] = [];
// Pass the existing Vite aliases
if (Array.isArray(existingAliases)) {
aliasArray = existingAliases;
} else {
aliasArray = Object.values(existingAliases);
}
})
// Add your own aliases using the find and replacement keys
aliasArray.push({
find: '../server-only-module',
replacement: path.resolve(__dirname, './path/to/browser-safe-module.js')
});
return {
...incomingViteConfig,
resolve: {
...(incomingViteConfig?.resolve || {}),
alias: aliasArray,
}
};
},
}
})
```
Learn more about [aliasing server-only modules](http://localhost:3000/docs/admin/excluding-server-code#aliasing-server-only-modules).
Learn more about [aliasing server-only modules](https://payloadcms.com/docs/admin/excluding-server-code#aliasing-server-only-modules).
Even though there is a new property for Vite configs specifically, we have implemented some "compatibility" between Webpack and Vite out-of-the-box.

View File

@@ -108,7 +108,7 @@ export default buildConfig({
#### Full example config
You can see a full [example config](https://github.com/payloadcms/public-demo/blob/master/src/payload.config.ts) in the Public Demo source code on GitHub.
You can see a full [example config](https://github.com/payloadcms/public-demo/blob/master/src/payload/payload.config.ts) in the Public Demo source code on GitHub.
### Using environment variables in your config

View File

@@ -33,6 +33,7 @@ export default buildConfig({
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `autoPluralization` | Tell Mongoose to auto-pluralize any collection names if it encounters any singular words used as collection `slug`s. |
| `connectOptions` | Customize MongoDB connection options. Payload will connect to your MongoDB database using default options which you can override and extend to include all the [options](https://mongoosejs.com/docs/connections.html#options) available to mongoose. |
| `disableIndexHints` | Set to true to disable hinting to MongoDB to use 'id' as index. This is currently done when counting documents for pagination, as it increases the speed of the count function used in that query. Disabling this optimization might fix some problems with AWS DocumentDB. Defaults to false |
| `migrationDir` | Customize the directory that migrations are stored. |
### Access to Mongoose models
@@ -43,4 +44,4 @@ You can access Mongoose models as follows:
- Collection models - `payload.db.collections[myCollectionSlug]`
- Globals model - `payload.db.globals`
- Versions model (both collections and globals) - `payload.db.versions[myEntitySlug]`
- Versions model (both collections and globals) - `payload.db.versions[myEntitySlug]`

View File

@@ -55,6 +55,7 @@ In addition to the default [field admin config](/docs/fields/overview#admin-conf
| **`date.maxDate`** \* | Max date value to allow. |
| **`date.minTime`** \* | Min time value to allow. |
| **`date.maxTime`** \* | Max date value to allow. |
| **`date.overrides`** \* | Pass any valid props directly to the [react-datepicker](https://github.com/Hacker0x01/react-datepicker/blob/master/docs/datepicker.md) |
| **`date.timeIntervals`** \* | Time intervals to display. Defaults to 30 minutes. |
| **`date.timeFormat`** \* | Determines time format. Defaults to `'h:mm aa'`. |

View File

@@ -10,13 +10,14 @@ While using Live Preview, the Admin panel emits a new `window.postMessage` event
Wiring your front-end into Live Preview is easy. If your front-end application is built with React or Next.js, use the [`useLivePreview`](#react) React hook that Payload provides. In the future, all other major frameworks like Vue, Svelte, etc will be officially supported. If you are using any of these frameworks today, you can still integrate with Live Preview yourself using the underlying tooling that Payload provides. See [building your own hook](#building-your-own-hook) for more information.
By default, all hooks require the following args:
By default, all hooks accept the following args:
| Path | Description |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`serverURL`** \* | The URL of your Payload server. |
| **`initialData`** | The initial data of the document. The live data will be merged in as changes are made. |
| **`depth`** | The depth of the relationships to fetch. Defaults to `0`. |
| **`apiRoute`** | The path of your API route as defined in `routes.api`. Defaults to `/api`. |
_\* An asterisk denotes that a property is required._

View File

@@ -314,13 +314,31 @@ import {
const yourEditorConfig; // <= your editor config here
const headlessEditor = await createHeadlessEditor({
const headlessEditor = createHeadlessEditor({
nodes: getEnabledNodes({
editorConfig: sanitizeEditorConfig(yourEditorConfig),
}),
})
```
### Getting the editor config
As you can see, you need to provide an editor config in order to create a headless editor. This is because the editor config is used to determine which nodes & features are enabled, and which converters are used.
To get the editor config, simply import the default editor config and adjust it - just like you did inside of the `editor: lexicalEditor({})` property:
```ts
import { defaultEditorConfig, defaultEditorFeatures } from '@payloadcms/richtext-lexical' // <= make sure this package is installed
const yourEditorConfig = defaultEditorConfig
// If you made changes to the features of the field's editor config, you should also make those changes here:
yourEditorConfig.features = [
...defaultEditorFeatures,
// Add your custom features here
]
```
### HTML => Lexical
Once you have your headless editor instance, you can use it to convert HTML to Lexical:
@@ -328,13 +346,14 @@ Once you have your headless editor instance, you can use it to convert HTML to L
```ts
import { $generateNodesFromDOM } from '@lexical/html'
import { $getRoot,$getSelection } from 'lexical'
import JSDOM from 'jsdom'
headlessEditor.update(() => {
// In a headless environment you can use a package such as JSDom to parse the HTML string.
const dom = new JSDOM(htmlString)
// Once you have the DOM instance it's easy to generate LexicalNodes.
const nodes = $generateNodesFromDOM(editor, dom.window.document)
const nodes = $generateNodesFromDOM(headlessEditor, dom.window.document)
// Select the root
$getRoot().select()
@@ -348,6 +367,8 @@ headlessEditor.update(() => {
const editorJSON = headlessEditor.getEditorState().toJSON()
```
Functions prefixed with a `$` can only be run inside of an `editor.update()` or `editorState.read()` callback.
This has been taken from the [lexical serialization & deserialization docs](https://lexical.dev/docs/concepts/serialization#html---lexical).
<Banner type="success">
@@ -395,7 +416,6 @@ try {
headlessEditor.setEditorState(headlessEditor.parseEditorState(yourEditorState)) // This should commit the editor state immediately
} catch (e) {
logger.error({ err: e }, 'ERROR parsing editor state')
return ''
}
// Export to markdown
@@ -407,6 +427,35 @@ headlessEditor.getEditorState().read(() => {
The `.setEditorState()` function immediately updates your editor state. Thus, there's no need for the `discrete: true` flag when reading the state afterward.
### Lexical => Plain Text
Export content from the Lexical editor into plain text using these steps:
1. Import your current editor state into the headless editor.
2. Convert and fetch the resulting plain text string.
Here's the code for it:
```ts
import type { SerializedEditorState } from "lexical"
import { $getRoot } from "lexical"
const yourEditorState: SerializedEditorState // <= your current editor state here
// Import editor state into your headless editor
try {
headlessEditor.setEditorState(headlessEditor.parseEditorState(yourEditorState)) // This should commit the editor state immediately
} catch (e) {
logger.error({ err: e }, 'ERROR parsing editor state')
}
// Export to plain text
const plainTextContent = headlessEditor.getEditorState().read(() => {
return $getRoot().getTextContent()
}) || ''
```
## Migrating from Slate
While both Slate and Lexical save the editor state in JSON, the structure of the JSON is different.

View File

@@ -38,7 +38,7 @@ Every Payload Collection can opt-in to supporting Uploads by specifying the `upl
</strong> on that collection.
</Banner>
#### Collection Upload Options
### Collection Upload Options
| Option | Description |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -47,14 +47,14 @@ Every Payload Collection can opt-in to supporting Uploads by specifying the `upl
| **`adminThumbnail`** | Set the way that the Admin panel will display thumbnails for this Collection. [More](#admin-thumbnails) |
| **`crop`** | Set to `false` to disable the cropping tool in the Admin panel. Crop is enabled by default. [More](#crop-and-focal-point-selector) |
| **`disableLocalStorage`** | Completely disable uploading files to disk locally. [More](#disabling-local-upload-storage) |
| **`focalPoint`** | Set to `false` to disable the focal point selection tool in the Admin panel. The focal point selector is only available when `imageSizes` or `resizeOptions` are defined. [More](#crop-and-focal-point-selector) |
| **`focalPoint`** | Set to `false` to disable the focal point selection tool in the Admin panel. The focal point selector is only available when `imageSizes` or `resizeOptions` are defined. [More](#crop-and-focal-point-selector) |
| **`formatOptions`** | An object with `format` and `options` that are used with the Sharp image library to format the upload file. [More](https://sharp.pixelplumbing.com/api-output#toformat) |
| **`handlers`** | Array of Express request handlers to execute before the built-in Payload static middleware executes. |
| **`imageSizes`** | If specified, image uploads will be automatically resized in accordance to these image sizes. [More](#image-sizes) |
| **`mimeTypes`** | Restrict mimeTypes in the file picker. Array of valid mimetypes or mimetype wildcards [More](#mimetypes) |
| **`staticOptions`** | Set options for `express.static` to use while serving your static files. [More](http://expressjs.com/en/resources/middleware/serve-static.html) format) |
| **`resizeOptions`** | An object passed to the the Sharp image library to resize the uploaded file. [More](https://sharp.pixelplumbing.com/api-resize) |
| **`filesRequiredOnCreate`** | Mandate file data on creation, default is true. |
| **`staticOptions`** | Set options for `express.static` to use while serving your static files. [More](http://expressjs.com/en/resources/middleware/serve-static.html) |
| **`resizeOptions`** | An object passed to the the Sharp image library to resize the uploaded file. [More](https://sharp.pixelplumbing.com/api-resize) |
| **`filesRequiredOnCreate`** | Mandate file data on creation, default is true. |
_An asterisk denotes that a property above is required._
@@ -148,6 +148,23 @@ All auto-resized images are exposed to be re-used in hooks and similar via an ob
The object will have keys for each size generated, and each key will be set equal to a buffer containing the file data.
##### Handling Image Enlargement
When an uploaded image is smaller than the defined image size, we have 3 options:
`withoutEnlargement: undefined | false | true`
1.`undefined` [default]: uploading images with smaller width AND height than the image size will return null
2. `false`: always enlarge images to the image size
3. `true`: if the image is smaller than the image size, return the original image
<Banner type="error">
<strong>Note:</strong>
<br />
By default, the image size will return NULL when the uploaded image is smaller than the defined image size.
Use the `withoutEnlargement` prop to change this.
</Banner>
### Crop and Focal Point Selector
This feature is only available for image file types.

View File

@@ -21,7 +21,7 @@ export const Country: React.FC<
return (
<Width width={width}>
<div className={classes.select}>
<label htmlFor="name" className={classes.label}>
<label htmlFor={name} className={classes.label}>
{label}
</label>
<Controller
@@ -37,6 +37,7 @@ export const Country: React.FC<
onChange={val => onChange(val.value)}
className={classes.reactSelect}
classNamePrefix="rs"
inputId={name}
/>
)}
/>

View File

@@ -19,13 +19,14 @@ export const Email: React.FC<
return (
<Width width={width}>
<div className={classes.wrap}>
<label htmlFor="name" className={classes.label}>
<label htmlFor={name} className={classes.label}>
{label}
</label>
<input
type="text"
placeholder="Email"
className={classes.input}
id={name}
{...register(name, { required: requiredFromProps, pattern: /^\S+@\S+$/i })}
/>
{requiredFromProps && errors[name] && <Error />}

View File

@@ -19,12 +19,13 @@ export const Number: React.FC<
return (
<Width width={width}>
<div className={classes.wrap}>
<label htmlFor="name" className={classes.label}>
<label htmlFor={name} className={classes.label}>
{label}
</label>
<input
type="number"
className={classes.input}
id={name}
{...register(name, { required: requiredFromProps })}
/>
{requiredFromProps && errors[name] && <Error />}

View File

@@ -20,7 +20,7 @@ export const Select: React.FC<
return (
<Width width={width}>
<div className={classes.select}>
<label htmlFor="name" className={classes.label}>
<label htmlFor={name} className={classes.label}>
{label}
</label>
<Controller
@@ -36,6 +36,7 @@ export const Select: React.FC<
onChange={val => onChange(val.value)}
className={classes.reactSelect}
classNamePrefix="rs"
inputId={name}
/>
)}
/>

View File

@@ -21,7 +21,7 @@ export const State: React.FC<
return (
<Width width={width}>
<div className={classes.select}>
<label htmlFor="name" className={classes.label}>
<label htmlFor={name} className={classes.label}>
{label}
</label>
<Controller
@@ -37,6 +37,7 @@ export const State: React.FC<
onChange={val => onChange(val.value)}
className={classes.reactSelect}
classNamePrefix="rs"
id={name}
/>
)}
/>

View File

@@ -19,12 +19,13 @@ export const Text: React.FC<
return (
<Width width={width}>
<div className={classes.wrap}>
<label htmlFor="name" className={classes.label}>
<label htmlFor={name} className={classes.label}>
{label}
</label>
<input
type="text"
className={classes.input}
id={name}
{...register(name, { required: requiredFromProps })}
/>
{requiredFromProps && errors[name] && <Error />}

View File

@@ -20,12 +20,13 @@ export const Textarea: React.FC<
return (
<Width width={width}>
<div className={classes.wrap}>
<label htmlFor="name" className={classes.label}>
<label htmlFor={name} className={classes.label}>
{label}
</label>
<textarea
rows={rows}
className={classes.textarea}
id={name}
{...register(name, { required: requiredFromProps })}
/>
{requiredFromProps && errors[name] && <Error />}

View File

@@ -77,6 +77,7 @@
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"jwt-decode": "3.1.2",
"lexical": "0.12.2",
"lint-staged": "^14.0.1",
"minimist": "1.2.8",
"mongodb-memory-server": "8.12.2",

View File

@@ -69,6 +69,8 @@ export const getViteConfig = async (payloadConfig: SanitizedConfig): Promise<Inl
Object.entries(process.env).forEach(([key, val]) => {
if (key.indexOf('PAYLOAD_PUBLIC_') === 0) {
define[`process.env.${key}`] = `'${val}'`
} else {
define[`process.env.${key}`] = `''`
}
})

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/db-mongodb",
"version": "1.0.7",
"version": "1.0.8",
"description": "The officially supported MongoDB database adapter for Payload",
"repository": "https://github.com/payloadcms/payload",
"license": "MIT",

View File

@@ -55,7 +55,7 @@ export const find: Find = async function find(
useEstimatedCount,
}
if (!useEstimatedCount) {
if (!useEstimatedCount && this.disableIndexHints !== true) {
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding a hint.
paginationOptions.useCustomCountFn = () => {
return Promise.resolve(

View File

@@ -74,7 +74,7 @@ export const findGlobalVersions: FindGlobalVersions = async function findGlobalV
useEstimatedCount,
}
if (!useEstimatedCount) {
if (!useEstimatedCount && this.disableIndexHints !== true) {
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding a hint.
paginationOptions.useCustomCountFn = () => {
return Promise.resolve(

View File

@@ -71,7 +71,7 @@ export const findVersions: FindVersions = async function findVersions(
useEstimatedCount,
}
if (!useEstimatedCount) {
if (!useEstimatedCount && this.disableIndexHints !== true) {
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding a hint.
paginationOptions.useCustomCountFn = () => {
return Promise.resolve(

View File

@@ -46,6 +46,8 @@ export interface Args {
/** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */
useFacet?: boolean
}
/** Set to true to disable hinting to MongoDB to use 'id' as index. This is currently done when counting documents for pagination. Disabling this optimization might fix some problems with AWS DocumentDB. Defaults to false */
disableIndexHints?: boolean
migrationDir?: string
/** The URL to connect to MongoDB or false to start payload and prevent connecting */
url: false | string
@@ -87,6 +89,7 @@ declare module 'payload' {
export function mongooseAdapter({
autoPluralization = true,
connectOptions,
disableIndexHints = false,
migrationDir: migrationDirArg,
url,
}: Args): MongooseAdapterResult {
@@ -105,6 +108,7 @@ export function mongooseAdapter({
collections: {},
connectOptions: connectOptions || {},
connection: undefined,
disableIndexHints,
globals: undefined,
mongoMemoryServer: undefined,
sessions: {},

View File

@@ -58,7 +58,7 @@ export const queryDrafts: QueryDrafts = async function queryDrafts(
useEstimatedCount,
}
if (!useEstimatedCount) {
if (!useEstimatedCount && this.disableIndexHints !== true) {
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding a hint.
paginationOptions.useCustomCountFn = () => {
return Promise.resolve(

View File

@@ -1,23 +1,27 @@
import type { RollbackTransaction } from 'payload/database'
export const rollbackTransaction: RollbackTransaction = async function rollbackTransaction(
id = '',
) {
export const rollbackTransaction: RollbackTransaction = function rollbackTransaction(id = '') {
// if multiple operations are using the same transaction, the first will flow through and delete the session.
// subsequent calls should be ignored.
if (!this.sessions[id]) {
return
}
// when session exists but is not inTransaction something unexpected is happening to the session
// when session exists but inTransaction is false, it is no longer used and can be deleted
if (!this.sessions[id].inTransaction()) {
this.payload.logger.warn('rollbackTransaction called when no transaction exists')
delete this.sessions[id]
return
}
// the first call for rollback should be aborted and deleted causing any other operations with the same transaction to fail
await this.sessions[id].abortTransaction()
await this.sessions[id].endSession()
try {
// null coalesce needed when rollback is called multiple times with the same id synchronously
this.sessions?.[id].abortTransaction().then(() => {
// not supported by DocumentDB
this.sessions?.[id].endSession()
})
} catch (e) {
// no action needed
}
delete this.sessions[id]
}

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/live-preview-react",
"version": "0.1.5",
"version": "0.1.6",
"description": "The official live preview React SDK for Payload",
"repository": "https://github.com/payloadcms/payload",
"license": "MIT",

View File

@@ -7,6 +7,7 @@ import { useCallback, useEffect, useRef, useState } from 'react'
// you can conditionally render loading UI based on the `isLoading` state
export const useLivePreview = <T extends any>(props: {
apiRoute?: string
depth?: number
initialData: T
serverURL: string
@@ -14,7 +15,7 @@ export const useLivePreview = <T extends any>(props: {
data: T
isLoading: boolean
} => {
const { depth = 0, initialData, serverURL } = props
const { apiRoute, depth, initialData, serverURL } = props
const [data, setData] = useState<T>(initialData)
const [isLoading, setIsLoading] = useState<boolean>(true)
const hasSentReadyMessage = useRef<boolean>(false)
@@ -26,6 +27,7 @@ export const useLivePreview = <T extends any>(props: {
useEffect(() => {
const subscription = subscribe({
apiRoute,
callback: onChange,
depth,
initialData,
@@ -43,7 +45,7 @@ export const useLivePreview = <T extends any>(props: {
return () => {
unsubscribe(subscription)
}
}, [serverURL, onChange, depth, initialData])
}, [serverURL, onChange, depth, initialData, apiRoute])
return {
data,

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/live-preview",
"version": "0.1.5",
"version": "0.1.6",
"description": "The official live preview JavaScript SDK for Payload",
"repository": "https://github.com/payloadcms/payload",
"license": "MIT",

View File

@@ -7,12 +7,14 @@ import { mergeData } from '.'
let payloadLivePreviewFieldSchema = undefined // TODO: type this from `fieldSchemaToJSON` return type
export const handleMessage = async <T>(args: {
depth: number
apiRoute?: string
depth?: number
event: MessageEvent
initialData: T
serverURL: string
}): Promise<T> => {
const { depth, event, initialData, serverURL } = args
const { apiRoute, depth, event, initialData, serverURL } = args
if (event.origin === serverURL && event.data) {
const eventData = JSON.parse(event?.data)
@@ -21,7 +23,17 @@ export const handleMessage = async <T>(args: {
payloadLivePreviewFieldSchema = eventData.fieldSchemaJSON
}
if (!payloadLivePreviewFieldSchema) {
// eslint-disable-next-line no-console
console.warn(
'Payload Live Preview: No `fieldSchemaJSON` was received from the parent window. Unable to merge data.',
)
return initialData
}
const mergedData = await mergeData<T>({
apiRoute,
depth,
fieldSchema: payloadLivePreviewFieldSchema,
incomingData: eventData.data,

View File

@@ -2,23 +2,29 @@ import type { fieldSchemaToJSON } from 'payload/utilities'
import { traverseFields } from './traverseFields'
export type MergeLiveDataArgs<T> = {
export const mergeData = async <T>(args: {
apiRoute?: string
depth: number
depth?: number
fieldSchema: ReturnType<typeof fieldSchemaToJSON>
incomingData: Partial<T>
initialData: T
returnNumberOfRequests?: boolean
serverURL: string
}
}): Promise<
T & {
_numberOfRequests?: number
}
> => {
const {
apiRoute,
depth,
fieldSchema,
incomingData,
initialData,
returnNumberOfRequests,
serverURL,
} = args
export const mergeData = async <T>({
apiRoute,
depth,
fieldSchema,
incomingData,
initialData,
serverURL,
}: MergeLiveDataArgs<T>): Promise<T> => {
const result = { ...initialData }
const populationPromises: Promise<void>[] = []
@@ -35,5 +41,8 @@ export const mergeData = async <T>({
await Promise.all(populationPromises)
return result
return {
...result,
...(returnNumberOfRequests ? { _numberOfRequests: populationPromises.length } : {}),
}
}

View File

@@ -1,4 +1,4 @@
type Args = {
export const promise = async (args: {
accessor: number | string
apiRoute?: string
collection: string
@@ -6,20 +6,23 @@ type Args = {
id: number | string
ref: Record<string, unknown>
serverURL: string
}
}): Promise<void> => {
const { id, accessor, apiRoute, collection, depth, ref, serverURL } = args
export const promise = async ({
id,
accessor,
apiRoute,
collection,
depth,
ref,
serverURL,
}: Args): Promise<void> => {
const res: any = await fetch(
`${serverURL}${apiRoute || '/api'}/${collection}/${id}?depth=${depth}`,
).then((res) => res.json())
const url = `${serverURL}${apiRoute || '/api'}/${collection}/${id}?depth=${depth}`
let res: Record<string, unknown> | null | undefined = null
try {
res = await fetch(url, {
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
}).then((res) => res.json())
} catch (err) {
console.error(err) // eslint-disable-line no-console
}
ref[accessor] = res
}

View File

@@ -1,15 +1,16 @@
import { handleMessage } from '.'
export const subscribe = <T>(args: {
apiRoute?: string
callback: (data: T) => void
depth: number
depth?: number
initialData: T
serverURL: string
}): ((event: MessageEvent) => void) => {
const { callback, depth, initialData, serverURL } = args
const { apiRoute, callback, depth, initialData, serverURL } = args
const onMessage = async (event: MessageEvent) => {
const mergedData = await handleMessage<T>({ depth, event, initialData, serverURL })
const mergedData = await handleMessage<T>({ apiRoute, depth, event, initialData, serverURL })
callback(mergedData)
}

View File

@@ -2,51 +2,52 @@ import type { fieldSchemaToJSON } from 'payload/utilities'
import { promise } from './promise'
type Args<T> = {
export const traverseFields = <T>(args: {
apiRoute?: string
depth: number
depth?: number
fieldSchema: ReturnType<typeof fieldSchemaToJSON>
incomingData: T
populationPromises: Promise<void>[]
result: T
serverURL: string
}
}): void => {
const {
apiRoute,
depth,
fieldSchema: fieldSchemas,
incomingData,
populationPromises,
result,
serverURL,
} = args
export const traverseFields = <T>({
apiRoute,
depth,
fieldSchema,
incomingData,
populationPromises,
result,
serverURL,
}: Args<T>): void => {
fieldSchema.forEach((fieldJSON) => {
if ('name' in fieldJSON && typeof fieldJSON.name === 'string') {
const fieldName = fieldJSON.name
fieldSchemas.forEach((fieldSchema) => {
if ('name' in fieldSchema && typeof fieldSchema.name === 'string') {
const fieldName = fieldSchema.name
switch (fieldJSON.type) {
switch (fieldSchema.type) {
case 'array':
if (Array.isArray(incomingData[fieldName])) {
result[fieldName] = incomingData[fieldName].map((row, i) => {
const hasExistingRow =
Array.isArray(result[fieldName]) &&
typeof result[fieldName][i] === 'object' &&
result[fieldName][i] !== null
result[fieldName] = incomingData[fieldName].map((incomingRow, i) => {
if (!result[fieldName]) {
result[fieldName] = []
}
const newRow = hasExistingRow ? { ...result[fieldName][i] } : {}
if (!result[fieldName][i]) {
result[fieldName][i] = {}
}
traverseFields({
apiRoute,
depth,
fieldSchema: fieldJSON.fields,
incomingData: row,
fieldSchema: fieldSchema.fields,
incomingData: incomingRow,
populationPromises,
result: newRow,
result: result[fieldName][i],
serverURL,
})
return newRow
return result[fieldName][i]
})
}
break
@@ -54,18 +55,21 @@ export const traverseFields = <T>({
case 'blocks':
if (Array.isArray(incomingData[fieldName])) {
result[fieldName] = incomingData[fieldName].map((incomingBlock, i) => {
const incomingBlockJSON = fieldJSON.blocks[incomingBlock.blockType]
const incomingBlockJSON = fieldSchema.blocks[incomingBlock.blockType]
// Compare the index and id to determine if this block already exists in the result
// If so, we want to use the existing block as the base, otherwise take the incoming block
// Either way, we will traverse the fields of the block to populate relationships
const isExistingBlock =
Array.isArray(result[fieldName]) &&
typeof result[fieldName][i] === 'object' &&
result[fieldName][i] !== null &&
result[fieldName][i].id === incomingBlock.id
if (!result[fieldName]) {
result[fieldName] = []
}
const block = isExistingBlock ? result[fieldName][i] : incomingBlock
if (
!result[fieldName][i] ||
result[fieldName][i].id !== incomingBlock.id ||
result[fieldName][i].blockType !== incomingBlock.blockType
) {
result[fieldName][i] = {
blockType: incomingBlock.blockType,
}
}
traverseFields({
apiRoute,
@@ -73,11 +77,11 @@ export const traverseFields = <T>({
fieldSchema: incomingBlockJSON.fields,
incomingData: incomingBlock,
populationPromises,
result: block,
result: result[fieldName][i],
serverURL,
})
return block
return result[fieldName][i]
})
} else {
result[fieldName] = []
@@ -94,7 +98,7 @@ export const traverseFields = <T>({
traverseFields({
apiRoute,
depth,
fieldSchema: fieldJSON.fields,
fieldSchema: fieldSchema.fields,
incomingData: incomingData[fieldName] || {},
populationPromises,
result: result[fieldName],
@@ -105,31 +109,35 @@ export const traverseFields = <T>({
case 'upload':
case 'relationship':
if (fieldJSON.hasMany && Array.isArray(incomingData[fieldName])) {
const existingValue = Array.isArray(result[fieldName]) ? [...result[fieldName]] : []
result[fieldName] = Array.isArray(result[fieldName])
? [...result[fieldName]].slice(0, incomingData[fieldName].length)
: []
// Handle `hasMany` relationships
if (fieldSchema.hasMany && Array.isArray(incomingData[fieldName])) {
if (!result[fieldName]) {
result[fieldName] = []
}
incomingData[fieldName].forEach((relation, i) => {
incomingData[fieldName].forEach((incomingRelation, i) => {
// Handle `hasMany` polymorphic
if (Array.isArray(fieldJSON.relationTo)) {
const existingID = existingValue[i]?.value?.id
if (
existingID !== relation.value ||
existingValue[i]?.relationTo !== relation.relationTo
) {
if (Array.isArray(fieldSchema.relationTo)) {
// if the field doesn't exist on the result, create it
// the value will be populated later
if (!result[fieldName][i]) {
result[fieldName][i] = {
relationTo: relation.relationTo,
relationTo: incomingRelation.relationTo,
}
}
const oldID = result[fieldName][i]?.value?.id
const oldRelation = result[fieldName][i]?.relationTo
const newID = incomingRelation.value
const newRelation = incomingRelation.relationTo
if (oldID !== newID || oldRelation !== newRelation) {
populationPromises.push(
promise({
id: relation.value,
id: incomingRelation.value,
accessor: 'value',
apiRoute,
collection: relation.relationTo,
collection: newRelation,
depth,
ref: result[fieldName][i],
serverURL,
@@ -138,15 +146,13 @@ export const traverseFields = <T>({
}
} else {
// Handle `hasMany` monomorphic
const existingID = existingValue[i]?.id
if (existingID !== relation) {
if (result[fieldName][i]?.id !== incomingRelation) {
populationPromises.push(
promise({
id: relation,
id: incomingRelation,
accessor: i,
apiRoute,
collection: String(fieldJSON.relationTo),
collection: String(fieldSchema.relationTo),
depth,
ref: result[fieldName],
serverURL,
@@ -157,29 +163,49 @@ export const traverseFields = <T>({
})
} else {
// Handle `hasOne` polymorphic
if (Array.isArray(fieldJSON.relationTo)) {
if (Array.isArray(fieldSchema.relationTo)) {
// if the field doesn't exist on the result, create it
// the value will be populated later
if (!result[fieldName]) {
result[fieldName] = {
relationTo: incomingData[fieldName]?.relationTo,
}
}
const hasNewValue =
typeof incomingData[fieldName] === 'object' && incomingData[fieldName] !== null
incomingData[fieldName] &&
typeof incomingData[fieldName] === 'object' &&
incomingData[fieldName] !== null
const hasOldValue =
typeof result[fieldName] === 'object' && result[fieldName] !== null
result[fieldName] &&
typeof result[fieldName] === 'object' &&
result[fieldName] !== null
const newID = hasNewValue
? typeof incomingData[fieldName].value === 'object'
? incomingData[fieldName].value.id
: incomingData[fieldName].value
: ''
const oldID = hasOldValue
? typeof result[fieldName].value === 'object'
? result[fieldName].value.id
: result[fieldName].value
: ''
const newValue = hasNewValue ? incomingData[fieldName].value : ''
const newRelation = hasNewValue ? incomingData[fieldName].relationTo : ''
const oldValue = hasOldValue ? result[fieldName].value : ''
const oldRelation = hasOldValue ? result[fieldName].relationTo : ''
if (newValue !== oldValue || newRelation !== oldRelation) {
if (newValue) {
if (!result[fieldName]) {
result[fieldName] = {
relationTo: newRelation,
}
}
// if the new value/relation is different from the old value/relation
// populate the new value, otherwise leave it alone
if (newID !== oldID || newRelation !== oldRelation) {
// if the new value is not empty, populate it
// otherwise set the value to null
if (newID) {
populationPromises.push(
promise({
id: newValue,
id: newID,
accessor: 'value',
apiRoute,
collection: newRelation,
@@ -188,34 +214,36 @@ export const traverseFields = <T>({
serverURL,
}),
)
} else {
result[fieldName] = null
}
} else {
result[fieldName] = null
}
} else {
// Handle `hasOne` monomorphic
const newID: string =
(typeof incomingData[fieldName] === 'string' && incomingData[fieldName]) ||
(typeof incomingData[fieldName] === 'object' &&
incomingData[fieldName] !== null &&
const newID: number | string | undefined =
(incomingData[fieldName] &&
typeof incomingData[fieldName] === 'object' &&
incomingData[fieldName].id) ||
''
incomingData[fieldName]
const oldID: string =
(typeof result[fieldName] === 'string' && result[fieldName]) ||
(typeof result[fieldName] === 'object' &&
result[fieldName] !== null &&
const oldID: number | string | undefined =
(result[fieldName] &&
typeof result[fieldName] === 'object' &&
result[fieldName].id) ||
''
result[fieldName]
// if the new value is different from the old value
// populate the new value, otherwise leave it alone
if (newID !== oldID) {
// if the new value is not empty, populate it
// otherwise set the value to null
if (newID) {
populationPromises.push(
promise({
id: newID,
accessor: fieldName,
apiRoute,
collection: String(fieldJSON.relationTo),
collection: String(fieldSchema.relationTo),
depth,
ref: result as Record<string, unknown>,
serverURL,
@@ -235,6 +263,4 @@ export const traverseFields = <T>({
}
}
})
return null
}

View File

@@ -1,6 +1,6 @@
{
"name": "payload",
"version": "2.1.0",
"version": "2.2.1",
"description": "Node, React and MongoDB Headless CMS and Application Framework",
"license": "MIT",
"main": "./dist/index.js",

View File

@@ -56,7 +56,12 @@ export const DocumentControls: React.FC<{
const { i18n, t } = useTranslation('general')
const showDotMenu = Boolean(collection && id && !disableActions)
const hasCreatePermission = 'create' in permissions && permissions.create?.permission
const hasDeletePermission = 'delete' in permissions && permissions.delete?.permission
const showDotMenu = Boolean(
collection && id && !disableActions && (hasCreatePermission || hasDeletePermission),
)
return (
<Gutter className={baseClass}>
@@ -203,7 +208,7 @@ export const DocumentControls: React.FC<{
verticalAlign="bottom"
>
<PopupList.ButtonGroup>
{'create' in permissions && permissions?.create?.permission && (
{hasCreatePermission && (
<React.Fragment>
<PopupList.Button
id="action-create"
@@ -217,7 +222,7 @@ export const DocumentControls: React.FC<{
)}
</React.Fragment>
)}
{'delete' in permissions && permissions?.delete?.permission && id && (
{hasDeletePermission && (
<DeleteDocument buttonId="action-delete" collection={collection} id={id} />
)}
</PopupList.ButtonGroup>

View File

@@ -1,107 +1,109 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import Button from '../Button';
import React from 'react'
import { useTranslation } from 'react-i18next'
import Button from '../Button'
import './index.scss';
import './index.scss'
const handleDragOver = (e: DragEvent) => {
e.preventDefault();
e.stopPropagation();
};
e.preventDefault()
e.stopPropagation()
}
const baseClass = 'dropzone';
const baseClass = 'dropzone'
type Props = {
onChange: (e: FileList) => void;
className?: string;
mimeTypes?: string[];
onChange: (e: FileList) => void
className?: string
mimeTypes?: string[]
}
export const Dropzone: React.FC<Props> = ({ onChange, className, mimeTypes }) => {
const dropRef = React.useRef<HTMLDivElement>(null);
const [dragging, setDragging] = React.useState(false);
const inputRef = React.useRef(null);
const dropRef = React.useRef<HTMLDivElement>(null)
const [dragging, setDragging] = React.useState(false)
const inputRef = React.useRef(null)
const { t } = useTranslation(['upload', 'general']);
const { t } = useTranslation(['upload', 'general'])
const handlePaste = React.useCallback((e: ClipboardEvent) => {
e.preventDefault();
e.stopPropagation();
const handlePaste = React.useCallback(
(e: ClipboardEvent) => {
e.preventDefault()
e.stopPropagation()
if (e.clipboardData.files && e.clipboardData.files.length > 0) {
onChange(e.clipboardData.files);
}
}, [onChange]);
if (e.clipboardData.files && e.clipboardData.files.length > 0) {
onChange(e.clipboardData.files)
}
},
[onChange],
)
const handleDragEnter = React.useCallback((e: DragEvent) => {
e.preventDefault();
e.stopPropagation();
setDragging(true);
}, []);
e.preventDefault()
e.stopPropagation()
setDragging(true)
}, [])
const handleDragLeave = React.useCallback((e: DragEvent) => {
e.preventDefault();
e.stopPropagation();
setDragging(false);
}, []);
e.preventDefault()
e.stopPropagation()
setDragging(false)
}, [])
const handleDrop = React.useCallback((e: DragEvent) => {
e.preventDefault();
e.stopPropagation();
setDragging(false);
const handleDrop = React.useCallback(
(e: DragEvent) => {
e.preventDefault()
e.stopPropagation()
setDragging(false)
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
onChange(e.dataTransfer.files);
setDragging(false);
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
onChange(e.dataTransfer.files)
setDragging(false)
e.dataTransfer.clearData();
}
}, [onChange]);
e.dataTransfer.clearData()
}
},
[onChange],
)
const handleFileSelection = React.useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files && e.target.files.length > 0) {
onChange(e.target.files);
}
}, [onChange]);
const handleFileSelection = React.useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files && e.target.files.length > 0) {
onChange(e.target.files)
}
},
[onChange],
)
React.useEffect(() => {
const div = dropRef.current;
const div = dropRef.current
if (div) {
div.addEventListener('dragenter', handleDragEnter);
div.addEventListener('dragleave', handleDragLeave);
div.addEventListener('dragover', handleDragOver);
div.addEventListener('drop', handleDrop);
div.addEventListener('paste', handlePaste);
div.addEventListener('dragenter', handleDragEnter)
div.addEventListener('dragleave', handleDragLeave)
div.addEventListener('dragover', handleDragOver)
div.addEventListener('drop', handleDrop)
div.addEventListener('paste', handlePaste)
return () => {
div.removeEventListener('dragenter', handleDragEnter);
div.removeEventListener('dragleave', handleDragLeave);
div.removeEventListener('dragover', handleDragOver);
div.removeEventListener('drop', handleDrop);
div.removeEventListener('paste', handlePaste);
};
div.removeEventListener('dragenter', handleDragEnter)
div.removeEventListener('dragleave', handleDragLeave)
div.removeEventListener('dragover', handleDragOver)
div.removeEventListener('drop', handleDrop)
div.removeEventListener('paste', handlePaste)
}
}
return () => null;
}, [handleDragEnter, handleDragLeave, handleDrop, handlePaste]);
return () => null
}, [handleDragEnter, handleDragLeave, handleDrop, handlePaste])
const classes = [
baseClass,
className,
dragging ? 'dragging' : '',
].filter(Boolean).join(' ');
const classes = [baseClass, className, dragging ? 'dragging' : ''].filter(Boolean).join(' ')
return (
<div
ref={dropRef}
className={classes}
>
<div ref={dropRef} className={classes}>
<Button
size="small"
buttonStyle="secondary"
onClick={() => {
inputRef.current.click();
inputRef.current.click()
}}
className={`${baseClass}__file-button`}
>
@@ -117,10 +119,8 @@ export const Dropzone: React.FC<Props> = ({ onChange, className, mimeTypes }) =>
/>
<p className={`${baseClass}__label`}>
{t('or')}
{' '}
{t('dragAndDrop')}
{t('general:or')} {t('dragAndDrop')}
</p>
</div>
);
};
)
}

View File

@@ -70,6 +70,11 @@ $header-height: base(5);
}
}
&__draggable {
@include btn-reset;
position: absolute;
}
&__focalPoint {
position: absolute;
top: 50%;

View File

@@ -164,7 +164,15 @@ export const EditUpload: React.FC<{
/>
</ReactCrop>
) : (
<img alt={t('upload:setFocalPoint')} ref={imageRef} src={fileSrcToUse} />
<img
alt={t('upload:setFocalPoint')}
onLoad={(e) => {
setOriginalHeight(e.currentTarget.naturalHeight)
setOriginalWidth(e.currentTarget.naturalWidth)
}}
ref={imageRef}
src={fileSrcToUse}
/>
)}
{showFocalPoint && (
<DraggableElement
@@ -273,7 +281,7 @@ const DraggableElement = ({
}) => {
const [position, setPosition] = useState({ x: initialPosition.x, y: initialPosition.y })
const [isDragging, setIsDragging] = useState(false)
const dragRef = useRef<HTMLDivElement | undefined>()
const dragRef = useRef<HTMLButtonElement | undefined>()
const getCoordinates = React.useCallback(
(mouseXArg?: number, mouseYArg?: number, recenter?: boolean) => {
@@ -319,7 +327,7 @@ const DraggableElement = ({
return { x, y }
},
[],
[boundsRef, containerRef],
)
const handleMouseDown = (event) => {
@@ -349,7 +357,7 @@ const DraggableElement = ({
setCheckBounds(false)
return
}
}, [getCoordinates, isDragging, checkBounds, setCheckBounds, position.x, position.y])
}, [getCoordinates, isDragging, checkBounds, setCheckBounds, position.x, position.y, onDragEnd])
React.useEffect(() => {
setPosition({ x: initialPosition.x, y: initialPosition.y })
@@ -365,15 +373,16 @@ const DraggableElement = ({
.join(' ')}
onMouseMove={handleMouseMove}
>
<div
<button
className={[`${baseClass}__draggable`, className].filter(Boolean).join(' ')}
onMouseDown={handleMouseDown}
onMouseUp={onDrop}
ref={dragRef}
style={{ left: `${position.x}%`, position: 'absolute', top: `${position.y}%` }}
style={{ left: `${position.x}%`, top: `${position.y}%` }}
type="button"
>
{children}
</div>
</button>
<div />
</div>
)

View File

@@ -38,7 +38,7 @@ const FileDetails: React.FC<Props> = (props) => {
width={width as number}
/>
{isImage(mimeType as string) && (
{isImage(mimeType as string) && mimeType !== 'image/svg+xml' && (
<UploadActions canEdit={canEdit} showSizePreviews={hasImageSizes && doc.filename} />
)}
</div>

View File

@@ -77,7 +77,6 @@
&__sizeOption {
padding: base(0.5);
display: flex;
flex-direction: row;
gap: base(1);
cursor: pointer;
transition: background-color 0.2s ease-in-out;

View File

@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react'
import React, { useEffect, useMemo, useState } from 'react'
import type { SanitizedCollectionConfig } from '../../../../exports/types'
import type { FileSizes, Upload } from '../../../../uploads/types'
@@ -23,9 +23,49 @@ const sortSizes = (sizes: FileSizes, imageSizes: Upload['imageSizes']) => {
return orderedSizes
}
type PreviewSizeCardProps = {
active: boolean
baseURL: string
meta: FileSizes[0]
name: string
onClick?: () => void
previewSrc: string
}
const PreviewSizeCard: React.FC<PreviewSizeCardProps> = ({
name,
active,
baseURL,
meta,
onClick,
previewSrc,
}) => {
return (
<div
className={[`${baseClass}__sizeOption`, active && `${baseClass}--selected`]
.filter(Boolean)
.join(' ')}
onClick={typeof onClick === 'function' ? onClick : undefined}
onKeyDown={(e) => {
if (typeof onClick !== 'function') return
if (e.key === 'Enter') onClick()
}}
role="button"
tabIndex={0}
>
<div className={`${baseClass}__image`}>
<img alt={meta.filename} src={previewSrc} />
</div>
<div className={`${baseClass}__sizeMeta`}>
<div className={`${baseClass}__sizeName`}>{name}</div>
<Meta {...meta} staticURL={baseURL} />
</div>
</div>
)
}
const PreviewSizes: React.FC<{
collection: SanitizedCollectionConfig
doc?: Data & {
doc: Data & {
sizes?: FileSizes
}
imageCacheTag?: string
@@ -36,9 +76,7 @@ const PreviewSizes: React.FC<{
const { sizes } = doc
const [orderedSizes, setOrderedSizes] = useState<FileSizes>(() => sortSizes(sizes, imageSizes))
const [selectedSize, setSelectedSize] = useState<null | string>(
orderedSizes?.[imageSizes[0]?.name]?.filename ? imageSizes[0]?.name : null,
)
const [selectedSize, setSelectedSize] = useState<null | string>(null)
const generateImageUrl = (filename) => {
return `${staticURL}/${filename}${imageCacheTag ? `?${imageCacheTag}` : ''}`
@@ -47,47 +85,60 @@ const PreviewSizes: React.FC<{
setOrderedSizes(sortSizes(sizes, imageSizes))
}, [sizes, imageSizes, imageCacheTag])
const mainPreviewSrc = generateImageUrl(`${orderedSizes[selectedSize]?.filename}`)
const mainPreviewSrc = selectedSize
? generateImageUrl(`${orderedSizes[selectedSize]?.filename}`)
: generateImageUrl(doc.filename)
const originalImage = useMemo(
(): FileSizes[0] => ({
filename: doc.filename,
filesize: doc.filesize,
height: doc.height,
mimeType: doc.mimeType,
width: doc.width,
}),
[doc],
)
const originalFilename = 'Original'
return (
<div className={baseClass}>
<div className={`${baseClass}__imageWrap`}>
<div className={`${baseClass}__meta`}>
<div className={`${baseClass}__sizeName`}>{selectedSize}</div>
<Meta {...(selectedSize && orderedSizes[selectedSize])} staticURL={staticURL} />
<div className={`${baseClass}__sizeName`}>{selectedSize || originalFilename}</div>
<Meta
{...(selectedSize ? orderedSizes[selectedSize] : originalImage)}
staticURL={staticURL}
/>
</div>
<img alt={doc.filename} className={`${baseClass}__preview`} src={mainPreviewSrc} />
</div>
<div className={`${baseClass}__listWrap`}>
<div className={`${baseClass}__list`}>
<PreviewSizeCard
active={!selectedSize}
baseURL={staticURL}
meta={originalImage}
name={originalFilename}
onClick={() => setSelectedSize(null)}
previewSrc={generateImageUrl(doc.filename)}
/>
{Object.entries(orderedSizes).map(([key, val]) => {
const selected = selectedSize === key
const previewSrc = generateImageUrl(val.filename)
const previewSrc = val.filename ? generateImageUrl(val.filename) : undefined
if (previewSrc) {
return (
<div
className={[`${baseClass}__sizeOption`, selected && `${baseClass}--selected`]
.filter(Boolean)
.join(' ')}
<PreviewSizeCard
active={selected}
baseURL={staticURL}
key={key}
meta={val}
name={key}
onClick={() => setSelectedSize(key)}
onKeyDown={(e) => {
if (e.keyCode === 13) {
setSelectedSize(key)
}
}}
role="button"
tabIndex={0}
>
<div className={`${baseClass}__image`}>
<img alt={val.filename} src={previewSrc} />
</div>
<div className={`${baseClass}__sizeMeta`}>
<div className={`${baseClass}__sizeName`}>{key}</div>
<Meta {...val} staticURL={staticURL} />
</div>
</div>
previewSrc={previewSrc}
/>
)
}

View File

@@ -1,9 +1,12 @@
import qs from 'qs'
import React, { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import { useForm, useFormModified } from '../../forms/Form/context'
import FormSubmit from '../../forms/Submit'
import { useConfig } from '../../utilities/Config'
import { useDocumentInfo } from '../../utilities/DocumentInfo'
import { useLocale } from '../../utilities/Locale'
import RenderCustomComponent from '../../utilities/RenderCustomComponent'
export type CustomPublishButtonProps = React.ComponentType<
@@ -12,6 +15,7 @@ export type CustomPublishButtonProps = React.ComponentType<
}
>
export type DefaultPublishButtonProps = {
canPublish: boolean
disabled: boolean
id?: string
label: string
@@ -19,10 +23,13 @@ export type DefaultPublishButtonProps = {
}
const DefaultPublishButton: React.FC<DefaultPublishButtonProps> = ({
id,
canPublish,
disabled,
label,
publish,
}) => {
if (!canPublish) return null
return (
<FormSubmit buttonId={id} disabled={disabled} onClick={publish} size="small" type="button">
{label}
@@ -35,22 +42,68 @@ type Props = {
}
export const Publish: React.FC<Props> = ({ CustomComponent }) => {
const { publishedDoc, unpublishedVersions } = useDocumentInfo()
const { submit } = useForm()
const { code } = useLocale()
const { id, collection, global, publishedDoc, unpublishedVersions } = useDocumentInfo()
const [hasPublishPermission, setHasPublishPermission] = React.useState(false)
const { getData, submit } = useForm()
const modified = useFormModified()
const {
routes: { api },
serverURL,
} = useConfig()
const { t } = useTranslation('version')
const hasNewerVersions = unpublishedVersions?.totalDocs > 0
const canPublish = modified || hasNewerVersions || !publishedDoc
const publish = useCallback(() => {
submit({
void submit({
overrides: {
_status: 'published',
},
})
}, [submit])
React.useEffect(() => {
const fetchPublishAccess = async () => {
let docAccessURL: string
let operation = 'update'
const params = {
locale: code || undefined,
}
if (global) {
docAccessURL = `/globals/${global.slug}/access`
} else if (collection) {
if (!id) operation = 'create'
docAccessURL = `/${collection.slug}/access${id ? `/${id}` : ''}`
}
if (docAccessURL) {
const data = getData()
const res = await fetch(`${serverURL}${api}${docAccessURL}?${qs.stringify(params)}`, {
body: JSON.stringify({
...data,
_status: 'published',
}),
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
method: 'post',
})
const json = await res.json()
const result = Boolean(json?.[operation]?.permission)
setHasPublishPermission(result)
} else {
setHasPublishPermission(true)
}
}
void fetchPublishAccess()
}, [api, code, collection, getData, global, id, serverURL])
return (
<RenderCustomComponent
CustomComponent={CustomComponent}
@@ -58,6 +111,7 @@ export const Publish: React.FC<Props> = ({ CustomComponent }) => {
componentProps={{
id: 'action-save',
DefaultButton: DefaultPublishButton,
canPublish: hasPublishPermission,
disabled: !canPublish,
label: t('publishChanges'),
publish,

View File

@@ -2,6 +2,7 @@
.section-title {
position: relative;
min-width: 0;
&:after {
display: block;

View File

@@ -10,10 +10,10 @@ import './index.scss'
const baseClass = 'checkbox-input'
type CheckboxInputProps = {
AfterInput?: React.ReactElement<any>[]
BeforeInput?: React.ReactElement<any>[]
Label?: React.ComponentType<LabelProps>
afterInput?: React.ComponentType<any>[]
'aria-label'?: string
beforeInput?: React.ComponentType<any>[]
checked?: boolean
className?: string
id?: string
@@ -30,10 +30,10 @@ export const CheckboxInput: React.FC<CheckboxInputProps> = (props) => {
const {
id,
name,
AfterInput,
BeforeInput,
Label,
afterInput,
'aria-label': ariaLabel,
beforeInput,
checked,
className,
inputRef,
@@ -58,7 +58,7 @@ export const CheckboxInput: React.FC<CheckboxInputProps> = (props) => {
.join(' ')}
>
<div className={`${baseClass}__input`}>
{BeforeInput}
{Array.isArray(beforeInput) && beforeInput.map((Component, i) => <Component key={i} />)}
<input
aria-label={ariaLabel}
defaultChecked={Boolean(checked)}
@@ -69,7 +69,7 @@ export const CheckboxInput: React.FC<CheckboxInputProps> = (props) => {
ref={inputRef}
type="checkbox"
/>
{AfterInput}
{Array.isArray(afterInput) && afterInput.map((Component, i) => <Component key={i} />)}
<span className={`${baseClass}__icon ${!partialChecked ? 'check' : 'partial'}`}>
{!partialChecked && <Check />}
{partialChecked && <Line />}

View File

@@ -20,12 +20,12 @@ const Checkbox: React.FC<Props> = (props) => {
name,
admin: {
className,
components: { Error, Label, afterInput, beforeInput } = {},
condition,
description,
readOnly,
style,
width,
components: { Error, Label, BeforeInput, AfterInput } = {},
} = {},
disableFormData,
label,
@@ -85,15 +85,15 @@ const Checkbox: React.FC<Props> = (props) => {
<ErrorComp alignCaret="left" message={errorMessage} showError={showError} />
</div>
<CheckboxInput
Label={Label}
afterInput={afterInput}
beforeInput={beforeInput}
checked={Boolean(value)}
id={fieldID}
label={getTranslation(label || name, i18n)}
name={path}
onToggle={onToggle}
readOnly={readOnly}
Label={Label}
BeforeInput={BeforeInput}
AfterInput={AfterInput}
required={required}
/>
<FieldDescription description={description} value={value} />

View File

@@ -9,8 +9,8 @@ import FieldDescription from '../../FieldDescription'
import DefaultLabel from '../../Label'
import useField from '../../useField'
import withCondition from '../../withCondition'
import './index.scss'
import { fieldBaseClass } from '../shared'
import './index.scss'
const prismToMonacoLanguageMap = {
js: 'javascript',
@@ -24,6 +24,7 @@ const Code: React.FC<Props> = (props) => {
name,
admin: {
className,
components: { Error, Label } = {},
condition,
description,
editorOptions,
@@ -31,7 +32,6 @@ const Code: React.FC<Props> = (props) => {
readOnly,
style,
width,
components: { Error, Label } = {},
} = {},
label,
path: pathFromProps,

View File

@@ -17,10 +17,10 @@ const baseClass = 'date-time-field'
export type DateTimeInputProps = Omit<DateField, 'admin' | 'name' | 'type'> & {
className?: string
components: {
AfterInput?: React.ReactElement<any>[]
BeforeInput?: React.ReactElement<any>[]
Error?: React.ComponentType<any>
Label?: React.ComponentType<any>
afterInput?: React.ComponentType<any>[]
beforeInput?: React.ComponentType<any>[]
}
datePickerProps?: DateField['admin']['date']
description?: Description
@@ -39,7 +39,7 @@ export type DateTimeInputProps = Omit<DateField, 'admin' | 'name' | 'type'> & {
export const DateTimeInput: React.FC<DateTimeInputProps> = (props) => {
const {
className,
components: { AfterInput, BeforeInput, Error, Label } = {},
components: { Error, Label, afterInput, beforeInput } = {},
datePickerProps,
description,
errorMessage,
@@ -81,7 +81,7 @@ export const DateTimeInput: React.FC<DateTimeInputProps> = (props) => {
</div>
<LabelComp htmlFor={path} label={label} required={required} />
<div className={`${baseClass}__input-wrapper`} id={`field-${path.replace(/\./g, '__')}`}>
{BeforeInput}
{Array.isArray(beforeInput) && beforeInput.map((Component, i) => <Component key={i} />)}
<DatePicker
{...datePickerProps}
onChange={onChange}
@@ -89,7 +89,7 @@ export const DateTimeInput: React.FC<DateTimeInputProps> = (props) => {
readOnly={readOnly}
value={value}
/>
{AfterInput}
{Array.isArray(afterInput) && afterInput.map((Component, i) => <Component key={i} />)}
</div>
<FieldDescription description={description} value={value} />
</div>

View File

@@ -10,8 +10,8 @@ import FieldDescription from '../../FieldDescription'
import DefaultLabel from '../../Label'
import useField from '../../useField'
import withCondition from '../../withCondition'
import './index.scss'
import { fieldBaseClass } from '../shared'
import './index.scss'
const Email: React.FC<Props> = (props) => {
const {
@@ -19,13 +19,13 @@ const Email: React.FC<Props> = (props) => {
admin: {
autoComplete,
className,
components: { Error, Label, afterInput, beforeInput } = {},
condition,
description,
placeholder,
readOnly,
style,
width,
components: { Error, Label, BeforeInput, AfterInput } = {},
} = {},
label,
path: pathFromProps,
@@ -68,7 +68,7 @@ const Email: React.FC<Props> = (props) => {
<ErrorComp message={errorMessage} showError={showError} />
<LabelComp htmlFor={`field-${path.replace(/\./g, '__')}`} label={label} required={required} />
<div className="input-wrapper">
{BeforeInput}
{Array.isArray(beforeInput) && beforeInput.map((Component, i) => <Component key={i} />)}
<input
autoComplete={autoComplete}
disabled={Boolean(readOnly)}
@@ -79,7 +79,7 @@ const Email: React.FC<Props> = (props) => {
type="email"
value={(value as string) || ''}
/>
{AfterInput}
{Array.isArray(afterInput) && afterInput.map((Component, i) => <Component key={i} />)}
</div>
<FieldDescription description={description} value={value} />
</div>

View File

@@ -13,14 +13,15 @@ import FieldDescription from '../../FieldDescription'
import DefaultLabel from '../../Label'
import useField from '../../useField'
import withCondition from '../../withCondition'
import './index.scss'
import { fieldBaseClass } from '../shared'
import './index.scss'
const NumberField: React.FC<Props> = (props) => {
const {
name,
admin: {
className,
components: { Error, Label, afterInput, beforeInput } = {},
condition,
description,
placeholder,
@@ -28,7 +29,6 @@ const NumberField: React.FC<Props> = (props) => {
step,
style,
width,
components: { Error, Label, BeforeInput, AfterInput } = {},
} = {},
hasMany,
label,
@@ -162,7 +162,7 @@ const NumberField: React.FC<Props> = (props) => {
/>
) : (
<div className="input-wrapper">
{BeforeInput}
{Array.isArray(beforeInput) && beforeInput.map((Component, i) => <Component key={i} />)}
<input
disabled={readOnly}
id={`field-${path.replace(/\./g, '__')}`}
@@ -178,7 +178,7 @@ const NumberField: React.FC<Props> = (props) => {
type="number"
value={typeof value === 'number' ? value : ''}
/>
{AfterInput}
{Array.isArray(afterInput) && afterInput.map((Component, i) => <Component key={i} />)}
</div>
)}

View File

@@ -10,8 +10,8 @@ import FieldDescription from '../../FieldDescription'
import DefaultLabel from '../../Label'
import useField from '../../useField'
import withCondition from '../../withCondition'
import './index.scss'
import { fieldBaseClass } from '../shared'
import './index.scss'
const baseClass = 'point'
@@ -20,6 +20,7 @@ const PointField: React.FC<Props> = (props) => {
name,
admin: {
className,
components: { Error, Label, afterInput, beforeInput } = {},
condition,
description,
placeholder,
@@ -27,7 +28,6 @@ const PointField: React.FC<Props> = (props) => {
step,
style,
width,
components: { Error, Label, BeforeInput, AfterInput } = {},
} = {},
label,
path: pathFromProps,
@@ -98,7 +98,7 @@ const PointField: React.FC<Props> = (props) => {
required={required}
/>
<div className="input-wrapper">
{BeforeInput}
{Array.isArray(beforeInput) && beforeInput.map((Component, i) => <Component key={i} />)}
<input
disabled={readOnly}
id={`field-longitude-${path.replace(/\./g, '__')}`}
@@ -109,7 +109,7 @@ const PointField: React.FC<Props> = (props) => {
type="number"
value={value && typeof value[0] === 'number' ? value[0] : ''}
/>
{AfterInput}
{Array.isArray(afterInput) && afterInput.map((Component, i) => <Component key={i} />)}
</div>
</li>
<li>
@@ -119,7 +119,7 @@ const PointField: React.FC<Props> = (props) => {
required={required}
/>
<div className="input-wrapper">
{BeforeInput}
{Array.isArray(beforeInput) && beforeInput.map((Component, i) => <Component key={i} />)}
<input
disabled={readOnly}
id={`field-latitude-${path.replace(/\./g, '__')}`}
@@ -130,7 +130,7 @@ const PointField: React.FC<Props> = (props) => {
type="number"
value={value && typeof value[1] === 'number' ? value[1] : ''}
/>
{AfterInput}
{Array.isArray(afterInput) && afterInput.map((Component, i) => <Component key={i} />)}
</div>
</li>
</ul>

View File

@@ -1,3 +1,5 @@
import type { JSONSchema4 } from 'json-schema'
import type { PayloadRequest } from '../../../../../express/types'
import type { RichTextField, Validate } from '../../../../../fields/config/types'
import type { CellComponentProps } from '../../../views/collections/List/Cell/types'
@@ -29,6 +31,13 @@ export type RichTextAdapter<
siblingDoc: Record<string, unknown>
}) => Promise<void> | null
outputSchema?: ({
field,
isRequired,
}: {
field: RichTextField<Value, AdapterProps, ExtraFieldProperties>
isRequired: boolean
}) => JSONSchema4
populationPromise?: (data: {
currentDepth?: number
depth: number

View File

@@ -166,7 +166,9 @@ const TabsField: React.FC<Props> = (props) => {
className={[
`${baseClass}__tab`,
activeTabConfig.label &&
`${baseClass}__tab-${toKebabCase(getTranslation(activeTabConfig.label, i18n))}`,
`${baseClass}__tabConfigLabel-${toKebabCase(
getTranslation(activeTabConfig.label, i18n),
)}`,
]
.filter(Boolean)
.join(' ')}

View File

@@ -14,6 +14,10 @@ import { fieldBaseClass } from '../shared'
import './index.scss'
export type TextInputProps = Omit<TextField, 'type'> & {
Error?: React.ComponentType<any>
Label?: React.ComponentType<any>
afterInput?: React.ComponentType<any>[]
beforeInput?: React.ComponentType<any>[]
className?: string
description?: Description
errorMessage?: string
@@ -29,14 +33,14 @@ export type TextInputProps = Omit<TextField, 'type'> & {
style?: React.CSSProperties
value?: string
width?: string
Error?: React.ComponentType<any>
Label?: React.ComponentType<any>
BeforeInput?: React.ReactElement<any>[]
AfterInput?: React.ReactElement<any>[]
}
const TextInput: React.FC<TextInputProps> = (props) => {
const {
Error,
Label,
afterInput,
beforeInput,
className,
description,
errorMessage,
@@ -53,10 +57,6 @@ const TextInput: React.FC<TextInputProps> = (props) => {
style,
value,
width,
Error,
Label,
BeforeInput,
AfterInput,
} = props
const { i18n } = useTranslation()
@@ -77,7 +77,7 @@ const TextInput: React.FC<TextInputProps> = (props) => {
<ErrorComp message={errorMessage} showError={showError} />
<LabelComp htmlFor={`field-${path.replace(/\./g, '__')}`} label={label} required={required} />
<div className="input-wrapper">
{BeforeInput}
{Array.isArray(beforeInput) && beforeInput.map((Component, i) => <Component key={i} />)}
<input
data-rtl={rtl}
disabled={readOnly}
@@ -90,7 +90,7 @@ const TextInput: React.FC<TextInputProps> = (props) => {
type="text"
value={value || ''}
/>
{AfterInput}
{Array.isArray(afterInput) && afterInput.map((Component, i) => <Component key={i} />)}
</div>
<FieldDescription
className={`field-description-${path.replace(/\./g, '__')}`}

View File

@@ -15,6 +15,7 @@ const Text: React.FC<Props> = (props) => {
name,
admin: {
className,
components: { Error, Label, afterInput, beforeInput } = {},
condition,
description,
placeholder,
@@ -22,7 +23,6 @@ const Text: React.FC<Props> = (props) => {
rtl,
style,
width,
components: { Error, Label, BeforeInput, AfterInput } = {},
} = {},
inputRef,
label,
@@ -60,6 +60,10 @@ const Text: React.FC<Props> = (props) => {
return (
<TextInput
Error={Error}
Label={Label}
afterInput={afterInput}
beforeInput={beforeInput}
className={className}
description={description}
errorMessage={errorMessage}
@@ -78,10 +82,6 @@ const Text: React.FC<Props> = (props) => {
style={style}
value={value}
width={width}
Error={Error}
Label={Label}
BeforeInput={BeforeInput}
AfterInput={AfterInput}
/>
)
}

View File

@@ -10,10 +10,14 @@ import { getTranslation } from '../../../../../utilities/getTranslation'
import DefaultError from '../../Error'
import FieldDescription from '../../FieldDescription'
import DefaultLabel from '../../Label'
import './index.scss'
import { fieldBaseClass } from '../shared'
import './index.scss'
export type TextAreaInputProps = Omit<TextareaField, 'type'> & {
Error?: React.ComponentType<any>
Label?: React.ComponentType<any>
afterInput?: React.ComponentType<any>[]
beforeInput?: React.ComponentType<any>[]
className?: string
description?: Description
errorMessage?: string
@@ -28,14 +32,14 @@ export type TextAreaInputProps = Omit<TextareaField, 'type'> & {
style?: React.CSSProperties
value?: string
width?: string
Error?: React.ComponentType<any>
Label?: React.ComponentType<any>
BeforeInput?: React.ReactElement<any>[]
AfterInput?: React.ReactElement<any>[]
}
const TextareaInput: React.FC<TextAreaInputProps> = (props) => {
const {
Error,
Label,
afterInput,
beforeInput,
className,
description,
errorMessage,
@@ -51,10 +55,6 @@ const TextareaInput: React.FC<TextAreaInputProps> = (props) => {
style,
value,
width,
Error,
Label,
BeforeInput,
AfterInput,
} = props
const { i18n } = useTranslation()
@@ -83,7 +83,7 @@ const TextareaInput: React.FC<TextAreaInputProps> = (props) => {
<label className="textarea-outer" htmlFor={`field-${path.replace(/\./g, '__')}`}>
<div className="textarea-inner">
<div className="textarea-clone" data-value={value || placeholder || ''} />
{BeforeInput}
{Array.isArray(beforeInput) && beforeInput.map((Component, i) => <Component key={i} />)}
<textarea
className="textarea-element"
data-rtl={rtl}
@@ -95,7 +95,7 @@ const TextareaInput: React.FC<TextAreaInputProps> = (props) => {
rows={rows}
value={value || ''}
/>
{AfterInput}
{Array.isArray(afterInput) && afterInput.map((Component, i) => <Component key={i} />)}
</div>
</label>
<FieldDescription description={description} value={value} />

View File

@@ -18,6 +18,7 @@ const Textarea: React.FC<Props> = (props) => {
name,
admin: {
className,
components: { Error, Label, afterInput, beforeInput } = {},
condition,
description,
placeholder,
@@ -26,7 +27,6 @@ const Textarea: React.FC<Props> = (props) => {
rtl,
style,
width,
components: { Error, Label, BeforeInput, AfterInput } = {},
} = {},
label,
localized,
@@ -65,6 +65,10 @@ const Textarea: React.FC<Props> = (props) => {
return (
<TextareaInput
Error={Error}
Label={Label}
afterInput={afterInput}
beforeInput={beforeInput}
className={className}
description={description}
errorMessage={errorMessage}
@@ -83,10 +87,6 @@ const Textarea: React.FC<Props> = (props) => {
style={style}
value={value as string}
width={width}
Error={Error}
Label={Label}
BeforeInput={BeforeInput}
AfterInput={AfterInput}
/>
)
}

View File

@@ -1,7 +1,6 @@
import { useCallback, useMemo } from 'react'
import { useCallback, useMemo, useRef } from 'react'
import { useTranslation } from 'react-i18next'
import type { UPDATE } from '../Form/types'
import type { FieldType, Options } from './types'
import useThrottledEffect from '../../../hooks/useThrottledEffect'
@@ -36,6 +35,8 @@ const useField = <T,>(options: Options): FieldType<T> => {
const valid = typeof field?.valid === 'boolean' ? field.valid : true
const showError = valid === false && submitted
const prevValid = useRef(valid)
// Method to return from `useField`, used to
// update field values from field component(s)
const setValue = useCallback(
@@ -93,48 +94,55 @@ const useField = <T,>(options: Options): FieldType<T> => {
useThrottledEffect(
() => {
const validateField = async () => {
const action: UPDATE = {
condition,
disableFormData:
disableFormData || (hasRows ? typeof value === 'number' && value > 0 : false),
errorMessage: undefined,
path,
rows: field?.rows,
type: 'UPDATE',
valid: false,
validate,
value,
}
const validateOptions = {
id,
config,
data: getData(),
operation,
siblingData: getSiblingData(path),
t,
user,
}
let valueToValidate = value
if (field?.rows && Array.isArray(field.rows)) {
valueToValidate = getDataByPath(path)
}
let errorMessage: string | undefined
let valid: boolean | string = false
const validationResult =
typeof validate === 'function' ? await validate(valueToValidate, validateOptions) : true
typeof validate === 'function'
? await validate(valueToValidate, {
id,
config,
data: getData(),
operation,
siblingData: getSiblingData(path),
t,
user,
})
: true
if (typeof validationResult === 'string') {
action.errorMessage = validationResult
action.valid = false
errorMessage = validationResult
valid = false
} else {
action.valid = validationResult
action.errorMessage = undefined
valid = validationResult
errorMessage = undefined
}
if (typeof dispatchField === 'function') {
dispatchField(action)
// Only dispatch if the validation result has changed
// This will prevent unnecessary rerenders
if (valid !== prevValid.current) {
prevValid.current = valid
if (typeof dispatchField === 'function') {
dispatchField({
condition,
disableFormData:
disableFormData || (hasRows ? typeof value === 'number' && value > 0 : false),
errorMessage,
path,
rows: field?.rows,
type: 'UPDATE',
valid,
validate,
value,
})
}
}
}

View File

@@ -1,4 +1,5 @@
import { useModal } from '@faceless-ui/modal'
import qs from 'qs'
import React, { createContext, useCallback, useContext, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useHistory, useLocation } from 'react-router-dom'
@@ -10,6 +11,7 @@ import type { AuthContext } from './types'
import { requests } from '../../../api'
import useDebounce from '../../../hooks/useDebounce'
import { useConfig } from '../Config'
import { useLocale } from '../Locale'
const Context = createContext({} as AuthContext)
@@ -21,6 +23,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
const [tokenExpiration, setTokenExpiration] = useState<number>()
const { pathname } = useLocation()
const { push } = useHistory()
const { code } = useLocale()
const config = useConfig()
@@ -144,8 +147,11 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
}, [serverURL, api, userSlug, revokeTokenAndExpire])
const refreshPermissions = useCallback(async () => {
const params = {
locale: code,
}
try {
const request = await requests.get(`${serverURL}${api}/access`, {
const request = await requests.get(`${serverURL}${api}/access?${qs.stringify(params)}`, {
headers: {
'Accept-Language': i18n.language,
},
@@ -160,7 +166,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
} catch (e) {
toast.error(`Refreshing permissions failed: ${e.message}`)
}
}, [serverURL, api, i18n])
}, [serverURL, api, i18n, code])
const fetchFullUser = React.useCallback(async () => {
try {

View File

@@ -199,6 +199,9 @@ export const DocumentInfoProvider: React.FC<Props> = ({
const getDocPermissions = React.useCallback(async () => {
let docAccessURL: string
const params = {
locale: code || undefined,
}
if (pluralType === 'globals') {
docAccessURL = `/globals/${slug}/access`
} else if (pluralType === 'collections' && id) {
@@ -206,7 +209,7 @@ export const DocumentInfoProvider: React.FC<Props> = ({
}
if (docAccessURL) {
const res = await fetch(`${serverURL}${api}${docAccessURL}`, {
const res = await fetch(`${serverURL}${api}${docAccessURL}?${qs.stringify(params)}`, {
credentials: 'include',
headers: {
'Accept-Language': i18n.language,
@@ -219,7 +222,7 @@ export const DocumentInfoProvider: React.FC<Props> = ({
// (i.e. create has no id)
setDocPermissions(permissions[pluralType][slug])
}
}, [serverURL, api, pluralType, slug, id, permissions, i18n.language])
}, [serverURL, api, pluralType, slug, id, permissions, i18n.language, code])
const getDocPreferences = useCallback(async () => {
return getPreference<DocumentPreferences>(preferencesKey)

View File

@@ -1,5 +1,5 @@
import { DndContext } from '@dnd-kit/core'
import React, { useCallback, useEffect, useRef, useState } from 'react'
import React, { useCallback, useEffect, useState } from 'react'
import type { LivePreviewConfig } from '../../../../../exports/config'
import type { Field } from '../../../../../fields/config/types'

View File

@@ -51,4 +51,9 @@
justify-content: center;
padding: 6px 0;
}
.popup-button {
display: flex;
align-items: center;
}
}

View File

@@ -2,13 +2,19 @@ import React from 'react'
import type { EditViewProps } from '../../../types'
import { X } from '../../../..'
import { Chevron, Popup, X } from '../../../..'
import * as PopupList from '../../../../elements/Popup/PopupButtonList'
import { ExternalLinkIcon } from '../../../../graphics/ExternalLink'
import { useLivePreviewContext } from '../../Context/context'
import { PreviewFrameSizeInput } from '../SizeInput'
import './index.scss'
const baseClass = 'live-preview-toolbar-controls'
const zoomOptions = [50, 75, 100, 125, 150, 200]
const customOption = {
label: 'Custom', // TODO: Add i18n to this string
value: 'custom',
}
export const ToolbarControls: React.FC<EditViewProps> = () => {
const { breakpoint, breakpoints, setBreakpoint, setPreviewWindowType, setZoom, url, zoom } =
@@ -17,23 +23,51 @@ export const ToolbarControls: React.FC<EditViewProps> = () => {
return (
<div className={baseClass}>
{breakpoints?.length > 0 && (
<select
<Popup
className={`${baseClass}__breakpoint`}
name="live-preview-breakpoint"
onChange={(e) => setBreakpoint(e.target.value)}
value={breakpoint}
>
{breakpoints.map((bp) => (
<option key={bp.name} value={bp.name}>
{bp.label}
</option>
))}
{breakpoint === 'custom' && (
// Dynamically add this option so that it only appears when the width and height inputs are explicitly changed
// TODO: Translate this string
<option value="custom">Custom</option>
button={
<>
<span>
{breakpoints.find((bp) => bp.name == breakpoint)?.label ?? customOption.label}
</span>
&nbsp;
<Chevron className={`${baseClass}__chevron`} />
</>
}
render={({ close }) => (
<PopupList.ButtonGroup>
<React.Fragment>
{breakpoints.map((bp) => (
<PopupList.Button
key={bp.name}
active={bp.name == breakpoint}
onClick={() => {
setBreakpoint(bp.name)
close()
}}
>
{bp.label}
</PopupList.Button>
))}
{/* Dynamically add this option so that it only appears when the width and height inputs are explicitly changed */}
{breakpoint === 'custom' && (
<PopupList.Button
active={breakpoint == customOption.value}
onClick={() => {
setBreakpoint(customOption.value)
close()
}}
>
{customOption.label}
</PopupList.Button>
)}
</React.Fragment>
</PopupList.ButtonGroup>
)}
</select>
showScrollbar
verticalAlign="bottom"
horizontalAlign="right"
/>
)}
<div className={`${baseClass}__device-size`}>
<PreviewFrameSizeInput axis="x" />
@@ -42,18 +76,37 @@ export const ToolbarControls: React.FC<EditViewProps> = () => {
</span>
<PreviewFrameSizeInput axis="y" />
</div>
<select
<Popup
className={`${baseClass}__zoom`}
onChange={(e) => setZoom(Number(e.target.value) / 100)}
value={zoom * 100}
>
<option value={50}>50%</option>
<option value={75}>75%</option>
<option value={100}>100%</option>
<option value={125}>125%</option>
<option value={150}>150%</option>
<option value={200}>200%</option>
</select>
button={
<>
<span>{zoom * 100}%</span>
&nbsp;
<Chevron className={`${baseClass}__chevron`} />
</>
}
render={({ close }) => (
<PopupList.ButtonGroup>
<React.Fragment>
{zoomOptions.map((zoomValue) => (
<PopupList.Button
key={zoomValue}
active={zoom * 100 == zoomValue}
onClick={() => {
setZoom(zoomValue / 100)
close()
}}
>
{zoomValue}%
</PopupList.Button>
))}
</React.Fragment>
</PopupList.ButtonGroup>
)}
showScrollbar
verticalAlign="bottom"
horizontalAlign="right"
/>
<a
className={`${baseClass}__external`}
href={url}

View File

@@ -11,7 +11,6 @@ import type { EditViewProps } from '../types'
import { getTranslation } from '../../../../utilities/getTranslation'
import { DocumentControls } from '../../elements/DocumentControls'
import { DocumentFields } from '../../elements/DocumentFields'
import { Gutter } from '../../elements/Gutter'
import { LeaveWithoutSaving } from '../../modals/LeaveWithoutSaving'
import { useConfig } from '../../utilities/Config'
import { useDocumentInfo } from '../../utilities/DocumentInfo'

View File

@@ -161,7 +161,7 @@ export const Upload: React.FC<Props> = (props) => {
value={value.name}
/>
{isImage(value.type) && (
{isImage(value.type) && value.type !== 'image/svg+xml' && (
<UploadActions
canEdit={showCrop || showFocalPoint}
showSizePreviews={hasImageSizes && doc.filename && !replacingFile}

View File

@@ -2,9 +2,10 @@ import React from 'react'
import { useTranslation } from 'react-i18next'
import { Link } from 'react-router-dom'
import type { CodeField } from '../../../../../../fields/config/types'
import type { CellComponentProps, Props } from './types'
import { CodeField, fieldAffectsData } from '../../../../../../fields/config/types'
import { fieldAffectsData } from '../../../../../../fields/config/types'
import { getTranslation } from '../../../../../../utilities/getTranslation'
import { useConfig } from '../../../../utilities/Config'
import RenderCustomComponent from '../../../../utilities/RenderCustomComponent'
@@ -60,8 +61,8 @@ const DefaultCell: React.FC<Props> = (props) => {
collection={collection}
data={`ID: ${cellData}`}
field={field as CodeField}
rowData={rowData}
nowrap
rowData={rowData}
/>
</WrapElement>
)

View File

@@ -43,6 +43,15 @@
width: 100%;
overflow: auto;
[class^="cell"] > p, [class^="cell"] > span, [class^="cell"] > a {
line-clamp: 4;
-webkit-box-orient: vertical;
-webkit-line-clamp: 4;
overflow: hidden;
display: -webkit-box;
max-width: 100vw;
}
#heading-_select,
.cell-_select {
min-width: unset;

View File

@@ -1,7 +1,7 @@
import type { PayloadRequest } from '../../../express/types'
import type { Payload } from '../../../payload'
import formatName from '../../../graphql/utilities/formatName'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import access from '../../operations/access'
const formatConfigNames = (results, configs) => {
@@ -19,7 +19,7 @@ const formatConfigNames = (results, configs) => {
function accessResolver(payload: Payload) {
async function resolver(_, args, context) {
const options = {
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
}
const accessResults = await access(options)

View File

@@ -1,6 +1,6 @@
import type { Collection } from '../../../collections/config/types'
import type { PayloadRequest } from '../../../express/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import forgotPassword from '../../operations/forgotPassword'
function forgotPasswordResolver(collection: Collection): any {
@@ -12,7 +12,7 @@ function forgotPasswordResolver(collection: Collection): any {
},
disableEmail: args.disableEmail,
expiration: args.expiration,
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
}
await forgotPassword(options)

View File

@@ -1,12 +1,11 @@
import type { PayloadRequest } from '../../../express/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import init from '../../operations/init'
function initResolver(collection: string) {
async function resolver(_, args, context) {
const options = {
collection,
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
}
return init(options)

View File

@@ -1,6 +1,6 @@
import type { Collection } from '../../../collections/config/types'
import type { PayloadRequest } from '../../../express/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import login from '../../operations/login'
function loginResolver(collection: Collection) {
@@ -12,7 +12,7 @@ function loginResolver(collection: Collection) {
password: args.password,
},
depth: 0,
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
res: context.res,
}

View File

@@ -1,13 +1,13 @@
import type { Collection } from '../../../collections/config/types'
import type { PayloadRequest } from '../../../express/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import logout from '../../operations/logout'
function logoutResolver(collection: Collection): any {
async function resolver(_, args, context) {
const options = {
collection,
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
res: context.res,
}

View File

@@ -1,6 +1,6 @@
import type { Collection } from '../../../collections/config/types'
import type { PayloadRequest } from '../../../express/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import me from '../../operations/me'
function meResolver(collection: Collection): any {
@@ -8,7 +8,7 @@ function meResolver(collection: Collection): any {
const options = {
collection,
depth: 0,
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
}
return me(options)
}

View File

@@ -1,6 +1,6 @@
import type { Collection } from '../../../collections/config/types'
import type { PayloadRequest } from '../../../express/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import getExtractJWT from '../../getExtractJWT'
import refresh from '../../operations/refresh'
@@ -18,7 +18,7 @@ function refreshResolver(collection: Collection) {
const options = {
collection,
depth: 0,
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
res: context.res,
token,
}

View File

@@ -1,7 +1,7 @@
/* eslint-disable no-param-reassign */
import type { Collection } from '../../../collections/config/types'
import type { PayloadRequest } from '../../../express/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import resetPassword from '../../operations/resetPassword'
function resetPasswordResolver(collection: Collection) {
@@ -14,7 +14,7 @@ function resetPasswordResolver(collection: Collection) {
collection,
data: args,
depth: 0,
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
res: context.res,
}

View File

@@ -1,6 +1,6 @@
import type { Collection } from '../../../collections/config/types'
import type { PayloadRequest } from '../../../express/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import unlock from '../../operations/unlock'
function unlockResolver(collection: Collection) {
@@ -8,7 +8,7 @@ function unlockResolver(collection: Collection) {
const options = {
collection,
data: { email: args.email },
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
}
const result = await unlock(options)

View File

@@ -1,7 +1,7 @@
/* eslint-disable no-param-reassign */
import type { Collection } from '../../../collections/config/types'
import type { PayloadRequest } from '../../../express/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import verifyEmail from '../../operations/verifyEmail'
function verifyEmailResolver(collection: Collection) {
@@ -12,7 +12,7 @@ function verifyEmailResolver(collection: Collection) {
const options = {
api: 'GraphQL',
collection,
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
res: context.res,
token: args.token,
}

View File

@@ -2,7 +2,10 @@ import type { PayloadRequest } from '../../express/types'
import type { AllOperations } from '../../types'
import type { Permissions } from '../types'
import { commitTransaction } from '../../utilities/commitTransaction'
import { getEntityPolicies } from '../../utilities/getEntityPolicies'
import { initTransaction } from '../../utilities/initTransaction'
import { killTransaction } from '../../utilities/killTransaction'
import { adminInit as adminInitTelemetry } from '../../utilities/telemetry/events/adminInit'
const allOperations: AllOperations[] = ['create', 'read', 'update', 'delete']
@@ -38,57 +41,64 @@ async function accessOperation(args: Arguments): Promise<Permissions> {
results.canAccessAdmin = false
}
await Promise.all(
config.collections.map(async (collection) => {
const collectionOperations = [...allOperations]
try {
const shouldCommit = await initTransaction(req)
await Promise.all(
config.collections.map(async (collection) => {
const collectionOperations = [...allOperations]
if (
collection.auth &&
typeof collection.auth.maxLoginAttempts !== 'undefined' &&
collection.auth.maxLoginAttempts !== 0
) {
collectionOperations.push('unlock')
}
if (
collection.auth &&
typeof collection.auth.maxLoginAttempts !== 'undefined' &&
collection.auth.maxLoginAttempts !== 0
) {
collectionOperations.push('unlock')
}
if (collection.versions) {
collectionOperations.push('readVersions')
}
if (collection.versions) {
collectionOperations.push('readVersions')
}
const collectionPolicy = await getEntityPolicies({
entity: collection,
operations: collectionOperations,
req,
type: 'collection',
})
results.collections = {
...results.collections,
[collection.slug]: collectionPolicy,
}
}),
)
const collectionPolicy = await getEntityPolicies({
entity: collection,
operations: collectionOperations,
req,
type: 'collection',
})
results.collections = {
...results.collections,
[collection.slug]: collectionPolicy,
}
}),
)
await Promise.all(
config.globals.map(async (global) => {
const globalOperations: AllOperations[] = ['read', 'update']
await Promise.all(
config.globals.map(async (global) => {
const globalOperations: AllOperations[] = ['read', 'update']
if (global.versions) {
globalOperations.push('readVersions')
}
if (global.versions) {
globalOperations.push('readVersions')
}
const globalPolicy = await getEntityPolicies({
entity: global,
operations: globalOperations,
req,
type: 'global',
})
results.globals = {
...results.globals,
[global.slug]: globalPolicy,
}
}),
)
const globalPolicy = await getEntityPolicies({
entity: global,
operations: globalOperations,
req,
type: 'global',
})
results.globals = {
...results.globals,
[global.slug]: globalPolicy,
}
}),
)
return results
if (shouldCommit) await commitTransaction(req)
return results
} catch (e: unknown) {
await killTransaction(req)
throw e
}
}
export default accessOperation

View File

@@ -129,6 +129,16 @@ const buildEndpoints = (collection: SanitizedCollectionConfig): Endpoint[] => {
method: 'get',
path: '/access/:id',
},
{
handler: docAccessRequestHandler,
method: 'post',
path: '/access/:id',
},
{
handler: docAccessRequestHandler,
method: 'post',
path: '/access',
},
{
handler: deprecatedUpdate,
method: 'put',

View File

@@ -6,6 +6,7 @@ import type { GeneratedTypes } from '../../../'
import type { PayloadRequest } from '../../../express/types'
import type { Collection } from '../../config/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import create from '../../operations/create'
export type Resolver<TSlug extends keyof GeneratedTypes['collections']> = (
@@ -37,7 +38,7 @@ export default function createResolver<TSlug extends keyof GeneratedTypes['colle
data: args.data,
depth: 0,
draft: args.draft,
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
}
const result = await create(options)

View File

@@ -5,6 +5,7 @@ import type { GeneratedTypes } from '../../../'
import type { PayloadRequest } from '../../../express/types'
import type { Collection } from '../../config/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import deleteByID from '../../operations/deleteByID'
export type Resolver<TSlug extends keyof GeneratedTypes['collections']> = (
@@ -30,7 +31,7 @@ export default function getDeleteResolver<TSlug extends keyof GeneratedTypes['co
id: args.id,
collection,
depth: 0,
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
}
const result = await deleteByID(options)

View File

@@ -1,6 +1,7 @@
import type { CollectionPermission, GlobalPermission } from '../../../auth'
import type { PayloadRequest } from '../../../express/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import { docAccess } from '../../operations/docAccess'
export type Resolver = (
@@ -18,7 +19,7 @@ export function docAccessResolver(): Resolver {
async function resolver(_, args, context) {
return docAccess({
id: args.id,
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
})
}

View File

@@ -4,6 +4,7 @@ import type { PayloadRequest } from '../../../express/types'
import type { Where } from '../../../types'
import type { Collection } from '../../config/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import find from '../../operations/find'
export type Resolver = (
@@ -36,7 +37,7 @@ export default function findResolver(collection: Collection): Resolver {
draft: args.draft,
limit: args.limit,
page: args.page,
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
sort: args.sort,
where: args.where,
}

View File

@@ -2,6 +2,7 @@ import type { GeneratedTypes } from '../../../'
import type { PayloadRequest } from '../../../express/types'
import type { Collection } from '../../config/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import findByID from '../../operations/findByID'
export type Resolver<T> = (
@@ -31,7 +32,7 @@ export default function findByIDResolver<T extends keyof GeneratedTypes['collect
collection,
depth: 0,
draft: args.draft,
req,
req: isolateTransactionID(context.req),
}
const result = await findByID(options)

View File

@@ -5,6 +5,7 @@ import type { PayloadRequest } from '../../../express/types'
import type { TypeWithVersion } from '../../../versions/types'
import type { Collection, TypeWithID } from '../../config/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import findVersionByID from '../../operations/findVersionByID'
export type Resolver<T extends TypeWithID = any> = (
@@ -31,7 +32,7 @@ export default function findVersionByIDResolver(collection: Collection): Resolve
collection,
depth: 0,
draft: args.draft,
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
}
const result = await findVersionByID(options)

View File

@@ -7,6 +7,7 @@ import type { PayloadRequest } from '../../../express/types'
import type { Where } from '../../../types'
import type { Collection } from '../../config/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import findVersions from '../../operations/findVersions'
export type Resolver = (
@@ -35,7 +36,7 @@ export default function findVersionsResolver(collection: Collection): Resolver {
depth: 0,
limit: args.limit,
page: args.page,
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
sort: args.sort,
where: args.where,
}

View File

@@ -4,6 +4,7 @@ import type { Response } from 'express'
import type { PayloadRequest } from '../../../express/types'
import type { Collection } from '../../config/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import restoreVersion from '../../operations/restoreVersion'
export type Resolver = (
@@ -23,7 +24,7 @@ export default function restoreVersionResolver(collection: Collection): Resolver
id: args.id,
collection,
depth: 0,
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
}
const result = await restoreVersion(options)

View File

@@ -5,6 +5,7 @@ import type { GeneratedTypes } from '../../../'
import type { PayloadRequest } from '../../../express/types'
import type { Collection } from '../../config/types'
import isolateTransactionID from '../../../utilities/isolateTransactionID'
import updateByID from '../../operations/updateByID'
export type Resolver<TSlug extends keyof GeneratedTypes['collections']> = (
@@ -36,7 +37,7 @@ export default function updateResolver<TSlug extends keyof GeneratedTypes['colle
data: args.data,
depth: 0,
draft: args.draft,
req: { ...context.req } as PayloadRequest,
req: isolateTransactionID(context.req),
}
const result = await updateByID<TSlug>(options)

View File

@@ -2,7 +2,10 @@ import type { CollectionPermission } from '../../auth'
import type { PayloadRequest } from '../../express/types'
import type { AllOperations } from '../../types'
import { commitTransaction } from '../../utilities/commitTransaction'
import { getEntityPolicies } from '../../utilities/getEntityPolicies'
import { initTransaction } from '../../utilities/initTransaction'
import { killTransaction } from '../../utilities/killTransaction'
const allOperations: AllOperations[] = ['create', 'read', 'update', 'delete']
@@ -34,11 +37,22 @@ export async function docAccess(args: Arguments): Promise<CollectionPermission>
collectionOperations.push('readVersions')
}
return getEntityPolicies({
id,
entity: config,
operations: collectionOperations,
req,
type: 'collection',
})
try {
const shouldCommit = await initTransaction(req)
const result = await getEntityPolicies({
id,
entity: config,
operations: collectionOperations,
req,
type: 'collection',
})
if (shouldCommit) await commitTransaction(req)
return result
} catch (e: unknown) {
await killTransaction(req)
throw e
}
}

View File

@@ -97,6 +97,7 @@ export default joi.object({
CellComponent: component.required(),
FieldComponent: component.required(),
afterReadPromise: joi.func().optional(),
outputSchema: joi.func().optional(),
populationPromise: joi.func().optional(),
validate: joi.func().required(),
})

View File

@@ -288,7 +288,7 @@ export type Locale = {
* label of supported locale
* @example "English"
*/
label: string | Record<string, string>
label: Record<string, string> | string
/**
* if true, defaults textAligmnent on text fields to RTL
*/
@@ -663,7 +663,7 @@ export type Config = {
api?: string
/** @default "/graphql" */
graphQL?: string
/** @default "/playground" */
/** @default "/graphql-playground" */
graphQLPlayground?: string
}
/**

View File

@@ -151,7 +151,7 @@ export type BeginTransaction = (
options?: Record<string, unknown>,
) => Promise<null | number | string>
export type RollbackTransaction = (id: number | string) => Promise<void>
export type RollbackTransaction = (id: number | string) => Promise<void> | void
export type CommitTransaction = (id: number | string) => Promise<void>

View File

@@ -3,7 +3,11 @@ export { extractTranslations } from '../translations/extractTranslations'
export { i18nInit } from '../translations/init'
export { combineMerge } from '../utilities/combineMerge'
export { configToJSONSchema, entityToJSONSchema } from '../utilities/configToJSONSchema'
export {
configToJSONSchema,
entityToJSONSchema,
withNullableJSONSchemaType,
} from '../utilities/configToJSONSchema'
export { createArrayFromCommaDelineated } from '../utilities/createArrayFromCommaDelineated'
export { deepCopyObject } from '../utilities/deepCopyObject'

View File

@@ -59,6 +59,10 @@ export declare type PayloadRequest<U = any> = Request & {
* Identifier for the database transaction for interactions in a single, all-or-nothing operation.
*/
transactionID?: number | string
/**
* Used to ensure consistency when multiple operations try to create a transaction concurrently on the same request
*/
transactionIDPromise?: Promise<void>
/** The signed in user */
user: (U & User) | null
}

View File

@@ -71,16 +71,16 @@ export const text = baseField.keys({
name: joi.string().required(),
admin: baseAdminFields.keys({
autoComplete: joi.string(),
components: baseAdminComponentFields.keys({
Error: componentSchema,
Label: componentSchema,
afterInput: joi.array().items(componentSchema),
beforeInput: joi.array().items(componentSchema),
}),
placeholder: joi
.alternatives()
.try(joi.object().pattern(joi.string(), [joi.string()]), joi.string()),
rtl: joi.boolean(),
components: baseAdminComponentFields.keys({
Label: componentSchema,
Error: componentSchema,
BeforeInput: joi.array().items(componentSchema),
AfterInput: joi.array().items(componentSchema),
}),
}),
defaultValue: joi.alternatives().try(joi.string(), joi.func()),
maxLength: joi.number(),
@@ -92,20 +92,20 @@ export const number = baseField.keys({
name: joi.string().required(),
admin: baseAdminFields.keys({
autoComplete: joi.string(),
placeholder: joi.string(),
step: joi.number(),
components: baseAdminComponentFields.keys({
Label: componentSchema,
Error: componentSchema,
BeforeInput: joi
Label: componentSchema,
afterInput: joi
.array()
.items(componentSchema)
.when('hasMany', { not: true, otherwise: joi.forbidden() }),
AfterInput: joi
beforeInput: joi
.array()
.items(componentSchema)
.when('hasMany', { not: true, otherwise: joi.forbidden() }),
}),
placeholder: joi.string(),
step: joi.number(),
}),
defaultValue: joi.alternatives().try(joi.number(), joi.func()),
hasMany: joi.boolean().default(false),
@@ -119,15 +119,15 @@ export const number = baseField.keys({
export const textarea = baseField.keys({
name: joi.string().required(),
admin: baseAdminFields.keys({
components: baseAdminComponentFields.keys({
Error: componentSchema,
Label: componentSchema,
afterInput: joi.array().items(componentSchema),
beforeInput: joi.array().items(componentSchema),
}),
placeholder: joi.string(),
rows: joi.number(),
rtl: joi.boolean(),
components: baseAdminComponentFields.keys({
Label: componentSchema,
Error: componentSchema,
BeforeInput: joi.array().items(componentSchema),
AfterInput: joi.array().items(componentSchema),
}),
}),
defaultValue: joi.alternatives().try(joi.string(), joi.func()),
maxLength: joi.number(),
@@ -139,13 +139,13 @@ export const email = baseField.keys({
name: joi.string().required(),
admin: baseAdminFields.keys({
autoComplete: joi.string(),
placeholder: joi.string(),
components: baseAdminComponentFields.keys({
Label: componentSchema,
Error: componentSchema,
BeforeInput: joi.array().items(componentSchema),
AfterInput: joi.array().items(componentSchema),
Label: componentSchema,
afterInput: joi.array().items(componentSchema),
beforeInput: joi.array().items(componentSchema),
}),
placeholder: joi.string(),
}),
defaultValue: joi.alternatives().try(joi.string(), joi.func()),
maxLength: joi.number(),
@@ -156,12 +156,12 @@ export const email = baseField.keys({
export const code = baseField.keys({
name: joi.string().required(),
admin: baseAdminFields.keys({
components: baseAdminComponentFields.keys({
Error: componentSchema,
Label: componentSchema,
}),
editorOptions: joi.object().unknown(), // Editor['options'] @monaco-editor/react
language: joi.string(),
components: baseAdminComponentFields.keys({
Label: componentSchema,
Error: componentSchema,
}),
}),
defaultValue: joi.alternatives().try(joi.string(), joi.func()),
type: joi.string().valid('code').required(),
@@ -171,8 +171,8 @@ export const json = baseField.keys({
name: joi.string().required(),
admin: baseAdminFields.keys({
components: baseAdminComponentFields.keys({
Label: componentSchema,
Error: componentSchema,
Label: componentSchema,
}),
}),
defaultValue: joi.alternatives().try(joi.array(), joi.object()),
@@ -182,12 +182,12 @@ export const json = baseField.keys({
export const select = baseField.keys({
name: joi.string().required(),
admin: baseAdminFields.keys({
components: baseAdminComponentFields.keys({
Error: componentSchema,
Label: componentSchema,
}),
isClearable: joi.boolean().default(false),
isSortable: joi.boolean().default(false),
components: baseAdminComponentFields.keys({
Label: componentSchema,
Error: componentSchema,
}),
}),
defaultValue: joi
.alternatives()
@@ -214,11 +214,11 @@ export const select = baseField.keys({
export const radio = baseField.keys({
name: joi.string().required(),
admin: baseAdminFields.keys({
layout: joi.string().valid('vertical', 'horizontal'),
components: baseAdminComponentFields.keys({
Label: componentSchema,
Error: componentSchema,
Label: componentSchema,
}),
layout: joi.string().valid('vertical', 'horizontal'),
}),
defaultValue: joi.alternatives().try(joi.string().allow(''), joi.func()),
options: joi
@@ -318,8 +318,8 @@ export const upload = baseField.keys({
name: joi.string().required(),
admin: baseAdminFields.keys({
components: baseAdminComponentFields.keys({
Label: componentSchema,
Error: componentSchema,
Label: componentSchema,
}),
}),
defaultValue: joi.alternatives().try(joi.object(), joi.func()),
@@ -333,10 +333,10 @@ export const checkbox = baseField.keys({
name: joi.string().required(),
admin: baseAdminFields.keys({
components: baseAdminComponentFields.keys({
Label: componentSchema,
Error: componentSchema,
BeforeInput: joi.array().items(componentSchema),
AfterInput: joi.array().items(componentSchema),
Label: componentSchema,
afterInput: joi.array().items(componentSchema),
beforeInput: joi.array().items(componentSchema),
}),
}),
defaultValue: joi.alternatives().try(joi.boolean(), joi.func()),
@@ -347,10 +347,10 @@ export const point = baseField.keys({
name: joi.string().required(),
admin: baseAdminFields.keys({
components: baseAdminComponentFields.keys({
Label: componentSchema,
Error: componentSchema,
BeforeInput: joi.array().items(componentSchema),
AfterInput: joi.array().items(componentSchema),
Label: componentSchema,
afterInput: joi.array().items(componentSchema),
beforeInput: joi.array().items(componentSchema),
}),
}),
defaultValue: joi.alternatives().try(joi.array().items(joi.number()).max(2).min(2), joi.func()),
@@ -361,11 +361,11 @@ export const relationship = baseField.keys({
name: joi.string().required(),
admin: baseAdminFields.keys({
allowCreate: joi.boolean().default(true),
isSortable: joi.boolean().default(false),
components: baseAdminComponentFields.keys({
Label: componentSchema,
Error: componentSchema,
Label: componentSchema,
}),
isSortable: joi.boolean().default(false),
}),
defaultValue: joi.alternatives().try(joi.func()),
filterOptions: joi.alternatives().try(joi.object(), joi.func()),
@@ -434,6 +434,7 @@ export const richText = baseField.keys({
CellComponent: componentSchema.required(),
FieldComponent: componentSchema.required(),
afterReadPromise: joi.func().optional(),
outputSchema: joi.func().optional(),
populationPromise: joi.func().optional(),
validate: joi.func().required(),
})
@@ -444,6 +445,12 @@ export const richText = baseField.keys({
export const date = baseField.keys({
name: joi.string().required(),
admin: baseAdminFields.keys({
components: baseAdminComponentFields.keys({
Error: componentSchema,
Label: componentSchema,
afterInput: joi.array().items(componentSchema),
beforeInput: joi.array().items(componentSchema),
}),
date: joi.object({
displayFormat: joi.string(),
maxDate: joi.date(),
@@ -451,17 +458,12 @@ export const date = baseField.keys({
minDate: joi.date(),
minTime: joi.date(),
monthsToShow: joi.number(),
overrides: joi.object().unknown(),
pickerAppearance: joi.string(),
timeFormat: joi.string(),
timeIntervals: joi.number(),
}),
placeholder: joi.string(),
components: baseAdminComponentFields.keys({
Label: componentSchema,
Error: componentSchema,
BeforeInput: joi.array().items(componentSchema),
AfterInput: joi.array().items(componentSchema),
}),
}),
defaultValue: joi.alternatives().try(joi.string(), joi.func()),
type: joi.string().valid('date').required(),

Some files were not shown because too many files have changed in this diff Show More