@payloadcms/ui 4.0.0-canary.6 → 4.0.0-canary.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/elements/RelationshipTable/index.css +1 -2
  3. package/dist/elements/Table/index.css +7 -2
  4. package/dist/exports/client/index.d.ts +1 -0
  5. package/dist/exports/client/index.d.ts.map +1 -1
  6. package/dist/exports/client/index.js +13 -13
  7. package/dist/exports/client/index.js.map +4 -4
  8. package/dist/exports/rsc/index.d.ts +2 -0
  9. package/dist/exports/rsc/index.d.ts.map +1 -1
  10. package/dist/exports/rsc/index.js +2 -0
  11. package/dist/exports/rsc/index.js.map +1 -1
  12. package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts +1 -0
  13. package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts.map +1 -1
  14. package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js +9 -1
  15. package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js.map +1 -1
  16. package/dist/forms/fieldSchemasToFormState/index.d.ts +2 -1
  17. package/dist/forms/fieldSchemasToFormState/index.d.ts.map +1 -1
  18. package/dist/forms/fieldSchemasToFormState/index.js +2 -0
  19. package/dist/forms/fieldSchemasToFormState/index.js.map +1 -1
  20. package/dist/forms/fieldSchemasToFormState/iterateFields.d.ts +2 -1
  21. package/dist/forms/fieldSchemasToFormState/iterateFields.d.ts.map +1 -1
  22. package/dist/forms/fieldSchemasToFormState/iterateFields.js +2 -0
  23. package/dist/forms/fieldSchemasToFormState/iterateFields.js.map +1 -1
  24. package/dist/styles.css +1 -1
  25. package/dist/utilities/buildFormState.d.ts.map +1 -1
  26. package/dist/utilities/buildFormState.js +1 -0
  27. package/dist/utilities/buildFormState.js.map +1 -1
  28. package/dist/utilities/formatRelativeDate.d.ts +15 -0
  29. package/dist/utilities/formatRelativeDate.d.ts.map +1 -0
  30. package/dist/utilities/formatRelativeDate.js +62 -0
  31. package/dist/utilities/formatRelativeDate.js.map +1 -0
  32. package/dist/utilities/recentlyViewed.d.ts +16 -0
  33. package/dist/utilities/recentlyViewed.d.ts.map +1 -0
  34. package/dist/utilities/recentlyViewed.js +21 -0
  35. package/dist/utilities/recentlyViewed.js.map +1 -0
  36. package/dist/utilities/recentlyViewed.spec.js +92 -0
  37. package/dist/utilities/recentlyViewed.spec.js.map +1 -0
  38. package/dist/views/Document/index.d.ts.map +1 -1
  39. package/dist/views/Document/index.js +9 -0
  40. package/dist/views/Document/index.js.map +1 -1
  41. package/dist/views/Document/recordRecentlyViewed.d.ts +12 -0
  42. package/dist/views/Document/recordRecentlyViewed.d.ts.map +1 -0
  43. package/dist/views/Document/recordRecentlyViewed.js +40 -0
  44. package/dist/views/Document/recordRecentlyViewed.js.map +1 -0
  45. package/dist/widgets/CollectionQuery/index.css +10 -152
  46. package/dist/widgets/CollectionQuery/index.d.ts +0 -1
  47. package/dist/widgets/CollectionQuery/index.d.ts.map +1 -1
  48. package/dist/widgets/CollectionQuery/index.js +40 -111
  49. package/dist/widgets/CollectionQuery/index.js.map +1 -1
  50. package/dist/widgets/RecentlyViewed/CollectionsField/index.css +14 -0
  51. package/dist/widgets/RecentlyViewed/CollectionsField/index.d.ts +10 -0
  52. package/dist/widgets/RecentlyViewed/CollectionsField/index.d.ts.map +1 -0
  53. package/dist/widgets/RecentlyViewed/CollectionsField/index.js +76 -0
  54. package/dist/widgets/RecentlyViewed/CollectionsField/index.js.map +1 -0
  55. package/dist/widgets/RecentlyViewed/index.d.ts +10 -0
  56. package/dist/widgets/RecentlyViewed/index.d.ts.map +1 -0
  57. package/dist/widgets/RecentlyViewed/index.js +148 -0
  58. package/dist/widgets/RecentlyViewed/index.js.map +1 -0
  59. package/dist/widgets/WidgetCard/index.css +155 -0
  60. package/dist/widgets/WidgetCard/index.d.ts +19 -0
  61. package/dist/widgets/WidgetCard/index.d.ts.map +1 -0
  62. package/dist/widgets/WidgetCard/index.js +49 -0
  63. package/dist/widgets/WidgetCard/index.js.map +1 -0
  64. package/package.json +5 -5
@@ -1,145 +1,9 @@
1
1
  @layer payload-default {
2
- .collection-query-widget {
3
- --collection-query-widget-visible-rows: 5;
4
- --collection-query-widget-row-gap: var(--spacer-1);
5
- --collection-query-widget-row-height: 40px;
6
- --collection-query-widget-scrollbar-width: 6px;
7
- --collection-query-widget-rows-height: calc(
8
- (
9
- var(--collection-query-widget-row-height) + var(--collection-query-widget-row-gap)
10
- ) * var(--collection-query-widget-visible-rows) - var(--collection-query-widget-row-gap)
11
- );
12
-
13
- flex-direction: column;
14
- align-items: stretch;
15
- gap: var(--spacer-2-5);
16
- height: 100%;
17
- /* Border + padding + header + header/rows gap + the visible row viewport. */
18
- max-height: calc(
19
- (var(--stroke-width-small) * 2) + (var(--spacer-2-5) * 3) +
20
- var(--text-heading-small-line-height, 24px) +
21
- var(--collection-query-widget-rows-height)
22
- );
23
- overflow: hidden;
24
- padding: var(--spacer-2-5);
25
- }
26
-
27
- .collection-query-widget__title {
28
- margin: 0;
29
- color: var(--color-text);
30
- font-family: var(--text-heading-small-font-family, var(--text-body-large-strong-font-family));
31
- font-size: var(--text-heading-small-font-size, 20px);
32
- font-weight: var(--text-heading-small-font-weight, var(--text-body-large-strong-font-weight));
33
- line-height: var(--text-heading-small-line-height, 24px);
34
- }
35
-
36
- .collection-query-widget__header {
37
- display: flex;
38
- align-items: center;
39
- gap: var(--spacer-2);
40
- }
41
-
42
- .collection-query-widget__rows {
43
- display: flex;
44
- flex: 1 1 auto;
45
- flex-direction: column;
46
- gap: var(--collection-query-widget-row-gap);
47
- min-height: 0;
48
- overflow-y: auto;
49
- padding: 0;
50
- padding-inline-end: calc(
51
- var(--collection-query-widget-scrollbar-width) + var(--spacer-1)
52
- );
53
- margin: 0;
54
- list-style: none;
55
- scrollbar-color: GrayText transparent;
56
- scrollbar-width: thin;
57
-
58
- &::-webkit-scrollbar {
59
- width: var(--collection-query-widget-scrollbar-width);
60
- background: transparent;
61
- }
62
-
63
- &::-webkit-scrollbar-corner,
64
- &::-webkit-scrollbar-track,
65
- &::-webkit-scrollbar-track-piece {
66
- background: transparent;
67
- }
68
-
69
- &::-webkit-scrollbar-thumb {
70
- border-radius: var(--radius-small, 3px);
71
- background: GrayText;
72
- }
73
- }
74
-
75
- .collection-query-widget__row {
76
- margin: 0;
77
- }
78
-
79
- .collection-query-widget__row-link {
80
- display: flex;
81
- align-items: center;
82
- justify-content: space-between;
83
- gap: var(--spacer-2);
84
- min-height: var(--collection-query-widget-row-height);
85
- padding: var(--spacer-1) calc(var(--spacer-1) * 1.5);
86
- border: var(--stroke-width-small) solid var(--color-border);
87
- border-radius: var(--radius-small, 3px);
88
- background: var(--color-bg);
89
- color: var(--color-text);
90
- text-decoration: none;
91
-
92
- &:hover {
93
- background: var(--color-bg-secondary-hover);
94
- text-decoration: none;
95
- }
96
- }
97
-
98
- .collection-query-widget__row-main,
99
- .collection-query-widget__row-meta {
100
- display: inline-flex;
101
- align-items: center;
102
- min-width: 0;
103
- }
104
-
105
- .collection-query-widget__row-main {
106
- flex: 1 1 auto;
107
- gap: calc(var(--spacer-1) * 1.5);
108
- }
109
-
110
- .collection-query-widget__row-meta {
111
- flex: 0 0 auto;
112
- gap: var(--spacer-1);
113
- padding-left: calc(var(--spacer-1) * 1.5);
114
- color: var(--color-text-secondary);
115
- font-family: var(--text-body-small-font-family, var(--text-body-medium-font-family));
116
- font-size: var(--text-body-small-font-size, 13px);
117
- line-height: var(--text-body-small-line-height, 20px);
118
- white-space: nowrap;
119
- }
120
-
121
- .collection-query-widget__row-title {
122
- overflow: hidden;
123
- color: var(--color-text);
124
- font-family: var(
125
- --text-body-small-strong-font-family,
126
- var(--text-body-medium-strong-font-family)
127
- );
128
- font-size: var(--text-body-small-strong-font-size, 13px);
129
- font-weight: var(
130
- --text-body-small-strong-font-weight,
131
- var(--text-body-medium-strong-font-weight)
132
- );
133
- line-height: var(--text-body-small-strong-line-height, 24px);
134
- text-overflow: ellipsis;
135
- white-space: nowrap;
136
- }
137
-
138
2
  .collection-query-widget--error {
139
3
  border-color: var(--color-bg-danger);
140
4
  }
141
5
 
142
- .collection-query-widget--error .collection-query-widget__title {
6
+ .collection-query-widget--error .widget-card__title {
143
7
  color: var(--color-text-danger);
144
8
  }
145
9
 
@@ -152,9 +16,10 @@
152
16
  border-radius: var(--radius-small, 3px);
153
17
  background: var(--color-bg-danger-tertiary);
154
18
  color: var(--color-text-danger);
155
- font-family: var(--text-body-small-font-family, var(--text-body-medium-font-family));
156
- font-size: var(--text-body-small-font-size, 13px);
157
- line-height: var(--text-body-small-line-height, 20px);
19
+ font-family: var(--text-body-medium-font-family);
20
+ font-size: var(--text-body-medium-font-size);
21
+ line-height: var(--text-body-medium-line-height);
22
+ letter-spacing: var(--text-body-medium-letter-spacing);
158
23
  }
159
24
 
160
25
  .collection-query-widget__error-title {
@@ -165,13 +30,11 @@
165
30
  border-radius: var(--radius-small, 3px);
166
31
  background: var(--color-bg-danger);
167
32
  color: var(--color-text-ondanger);
168
- font-family: var(--text-body-small-strong-font-family, var(--text-body-medium-strong-font-family));
169
- font-size: var(--text-body-small-strong-font-size, 13px);
170
- font-weight: var(
171
- --text-body-small-strong-font-weight,
172
- var(--text-body-medium-strong-font-weight)
173
- );
174
- line-height: var(--text-body-small-strong-line-height, 20px);
33
+ font-family: var(--text-body-medium-strong-font-family);
34
+ font-size: var(--text-body-medium-strong-font-size);
35
+ font-weight: var(--text-body-medium-strong-font-weight);
36
+ line-height: var(--text-body-medium-strong-line-height);
37
+ letter-spacing: var(--text-body-medium-strong-letter-spacing);
175
38
  }
176
39
 
177
40
  .collection-query-widget__error-list {
@@ -198,9 +61,4 @@
198
61
  border-radius: 50%;
199
62
  background: currentColor;
200
63
  }
201
-
202
- .collection-query-widget__empty {
203
- margin: 0;
204
- color: var(--color-text-secondary);
205
- }
206
64
  }
@@ -1,6 +1,5 @@
1
1
  import type { CollectionSlug, Where, WidgetServerProps } from 'payload';
2
2
  import React from 'react';
3
- import '../../elements/Card/index.css';
4
3
  import './index.css';
5
4
  type CollectionQueryWidgetData = {
6
5
  limit?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/widgets/CollectionQuery/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAIvE,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,OAAO,+BAA+B,CAAA;AACtC,OAAO,aAAa,CAAA;AAGpB,KAAK,yBAAyB,GAAG;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,iBAAiB,CAAC,EAAE,cAAc,CAAA;IAClC,aAAa,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAiBD,wBAAsB,qBAAqB,CAAC,EAC1C,GAAG,EACH,UAAU,GACX,EAAE,iBAAiB,CAAC;IAAE,IAAI,CAAC,EAAE,yBAAyB,CAAA;CAAE,CAAC,8BAmHzD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/widgets/CollectionQuery/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAIvE,OAAO,KAAK,MAAM,OAAO,CAAA;AAOzB,OAAO,aAAa,CAAA;AAGpB,KAAK,yBAAyB,GAAG;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,iBAAiB,CAAC,EAAE,cAAc,CAAA;IAClC,aAAa,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAiBD,wBAAsB,qBAAqB,CAAC,EAC1C,GAAG,EACH,UAAU,GACX,EAAE,iBAAiB,CAAC;IAAE,IAAI,CAAC,EAAE,yBAAyB,CAAA;CAAE,CAAC,8BA+FzD"}
@@ -2,7 +2,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { getTranslation } from '@payloadcms/translations';
3
3
  import { formatAdminURL } from 'payload/shared';
4
4
  import React from 'react';
5
- import '../../elements/Card/index.css';
5
+ import { formatRelativeDate, getRelativeTimeFormat } from '../../utilities/formatRelativeDate.js';
6
+ import { WidgetCard, WidgetList } from '../WidgetCard/index.js';
6
7
  import './index.css';
7
8
  import { getCollectionFieldPaths } from './getCollectionFieldPaths.js';
8
9
  const minLimit = 1;
@@ -74,55 +75,40 @@ export async function CollectionQueryWidget({
74
75
  }
75
76
  const documentLabelPath = getCollectionDocumentLabelPath(collectionConfig.admin);
76
77
  const relativeTimeFormat = getRelativeTimeFormat(i18n.language);
77
- return /*#__PURE__*/_jsxs("div", {
78
- className: "card collection-query-widget",
79
- children: [/*#__PURE__*/_jsx("div", {
80
- className: "collection-query-widget__header",
81
- children: /*#__PURE__*/_jsx("h3", {
82
- className: "collection-query-widget__title",
83
- children: title
84
- })
85
- }), docs.length > 0 ? /*#__PURE__*/_jsx("ul", {
86
- className: "collection-query-widget__rows",
87
- children: docs.map(doc => {
88
- const sortMeta = getDocSortMeta({
78
+ const items = docs.map(doc => {
79
+ const sortMeta = getDocSortMeta({
80
+ doc,
81
+ i18n,
82
+ relativeTimeFormat,
83
+ sortField
84
+ });
85
+ return {
86
+ href: getDocumentHref({
87
+ id: doc.id,
88
+ adminRoute,
89
+ collectionSlug: relatedCollection
90
+ }),
91
+ key: String(doc.id),
92
+ main: /*#__PURE__*/_jsx("span", {
93
+ className: "widget-card__row-title",
94
+ children: getDocLabel({
89
95
  doc,
90
- i18n,
91
- relativeTimeFormat,
92
- sortField
93
- });
94
- return /*#__PURE__*/_jsx("li", {
95
- className: "collection-query-widget__row",
96
- children: /*#__PURE__*/_jsxs("a", {
97
- className: "collection-query-widget__row-link",
98
- href: getDocumentHref({
99
- id: doc.id,
100
- adminRoute,
101
- collectionSlug: relatedCollection
102
- }),
103
- children: [/*#__PURE__*/_jsx("span", {
104
- className: "collection-query-widget__row-main",
105
- children: /*#__PURE__*/_jsx("span", {
106
- className: "collection-query-widget__row-title",
107
- children: getDocLabel({
108
- doc,
109
- documentLabelPath
110
- })
111
- })
112
- }), /*#__PURE__*/_jsx("span", {
113
- className: "collection-query-widget__row-meta",
114
- children: sortMeta ? sortMeta.dateTime ? /*#__PURE__*/_jsx("time", {
115
- dateTime: sortMeta.dateTime,
116
- children: sortMeta.label
117
- }) : sortMeta.label : null
118
- })]
119
- })
120
- }, doc.id);
121
- })
122
- }) : /*#__PURE__*/_jsx("p", {
123
- className: "collection-query-widget__empty",
124
- children: i18n.t('general:noResultsFound')
125
- })]
96
+ documentLabelPath
97
+ })
98
+ }),
99
+ meta: sortMeta ? sortMeta.dateTime ? /*#__PURE__*/_jsx("time", {
100
+ dateTime: sortMeta.dateTime,
101
+ children: sortMeta.label
102
+ }) : sortMeta.label : null
103
+ };
104
+ });
105
+ return /*#__PURE__*/_jsx(WidgetCard, {
106
+ className: "collection-query-widget",
107
+ title: title,
108
+ children: /*#__PURE__*/_jsx(WidgetList, {
109
+ emptyMessage: i18n.t('general:noResultsFound'),
110
+ items: items
111
+ })
126
112
  });
127
113
  }
128
114
  function CollectionQueryError({
@@ -130,15 +116,10 @@ function CollectionQueryError({
130
116
  i18n,
131
117
  title
132
118
  }) {
133
- return /*#__PURE__*/_jsxs("div", {
134
- className: "card collection-query-widget collection-query-widget--error",
135
- children: [/*#__PURE__*/_jsx("div", {
136
- className: "collection-query-widget__header",
137
- children: /*#__PURE__*/_jsx("h3", {
138
- className: "collection-query-widget__title",
139
- children: title
140
- })
141
- }), /*#__PURE__*/_jsxs("div", {
119
+ return /*#__PURE__*/_jsx(WidgetCard, {
120
+ className: "collection-query-widget collection-query-widget--error",
121
+ title: title,
122
+ children: /*#__PURE__*/_jsxs("div", {
142
123
  className: "collection-query-widget__error",
143
124
  children: [/*#__PURE__*/_jsx("p", {
144
125
  className: "collection-query-widget__error-title",
@@ -149,7 +130,7 @@ function CollectionQueryError({
149
130
  children: error
150
131
  }, error))
151
132
  })]
152
- })]
133
+ })
153
134
  });
154
135
  }
155
136
  function clampLimit(limit) {
@@ -341,58 +322,6 @@ function getValueByPath({
341
322
  return value[segment];
342
323
  }, object);
343
324
  }
344
- function getRelativeTimeFormat(language) {
345
- try {
346
- return new Intl.RelativeTimeFormat(language, {
347
- numeric: 'auto',
348
- style: 'narrow'
349
- });
350
- } catch {
351
- return new Intl.RelativeTimeFormat('en', {
352
- numeric: 'auto',
353
- style: 'narrow'
354
- });
355
- }
356
- }
357
- const relativeTimeDivisions = [{
358
- amount: 60,
359
- unit: 'seconds'
360
- }, {
361
- amount: 60,
362
- unit: 'minutes'
363
- }, {
364
- amount: 24,
365
- unit: 'hours'
366
- }, {
367
- amount: 7,
368
- unit: 'days'
369
- }, {
370
- amount: 4.34524,
371
- unit: 'weeks'
372
- }, {
373
- amount: 12,
374
- unit: 'months'
375
- }, {
376
- amount: Number.POSITIVE_INFINITY,
377
- unit: 'years'
378
- }];
379
- function formatRelativeDate({
380
- relativeTimeFormat,
381
- value
382
- }) {
383
- const date = new Date(value);
384
- if (Number.isNaN(date.getTime())) {
385
- return value;
386
- }
387
- let duration = (date.getTime() - Date.now()) / 1000;
388
- for (const division of relativeTimeDivisions) {
389
- if (Math.abs(duration) < division.amount) {
390
- return relativeTimeFormat.format(Math.round(duration), division.unit);
391
- }
392
- duration /= division.amount;
393
- }
394
- return relativeTimeFormat.format(Math.round(duration), 'years');
395
- }
396
325
  function isDateString(value) {
397
326
  return /^\d{4}-\d{2}-\d{2}/.test(value) && !Number.isNaN(new Date(value).getTime());
398
327
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["getTranslation","formatAdminURL","React","getCollectionFieldPaths","minLimit","maxLimit","emptyFieldPaths","filterableFieldPaths","Set","relationshipFieldPaths","sortableFieldPaths","CollectionQueryWidget","req","widgetData","i18n","payload","user","relatedCollection","sortDirection","sortField","title","titleFromData","where","limit","clampLimit","collectionConfig","collections","config","undefined","labels","plural","t","fieldPaths","fields","validationErrors","getValidationErrors","length","_jsx","CollectionQueryError","errors","sort","adminRoute","routes","admin","docs","result","find","collection","depth","overrideAccess","err","logger","error","msg","documentLabelPath","getCollectionDocumentLabelPath","relativeTimeFormat","getRelativeTimeFormat","language","_jsxs","className","map","doc","sortMeta","getDocSortMeta","href","getDocumentHref","id","collectionSlug","getDocLabel","dateTime","label","Number","isNaN","Math","min","max","floor","adminConfig","useAsTitle","value","getValueByPath","object","path","updatedAt","createdAt","Date","toISOString","formatRelativeDate","isDateString","toLocaleString","String","push","has","field","fieldPath","getWhereFieldPaths","hasRelationshipAncestor","segments","split","prefix","segment","collectWhereFieldPaths","Array","isArray","item","key","childValue","Object","entries","add","reduce","Intl","RelativeTimeFormat","numeric","style","relativeTimeDivisions","amount","unit","POSITIVE_INFINITY","date","getTime","duration","now","division","abs","format","round","test"],"sources":["../../../src/widgets/CollectionQuery/index.tsx"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type { CollectionSlug, Where, WidgetServerProps } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { formatAdminURL } from 'payload/shared'\nimport React from 'react'\n\nimport type { CollectionFieldPaths } from './getCollectionFieldPaths.js'\n\nimport '../../elements/Card/index.css'\nimport './index.css'\nimport { getCollectionFieldPaths } from './getCollectionFieldPaths.js'\n\ntype CollectionQueryWidgetData = {\n limit?: number\n relatedCollection?: CollectionSlug\n sortDirection?: 'asc' | 'desc'\n sortField?: string\n title?: string\n where?: Where\n}\n\ntype QueryDoc = {\n createdAt?: string\n id: number | string\n updatedAt?: string\n} & Record<string, unknown>\n\nconst minLimit = 1\nconst maxLimit = 25\n\nconst emptyFieldPaths: CollectionFieldPaths = {\n filterableFieldPaths: new Set<string>(),\n relationshipFieldPaths: new Set<string>(),\n sortableFieldPaths: new Set<string>(),\n}\n\nexport async function CollectionQueryWidget({\n req,\n widgetData,\n}: WidgetServerProps<{ data?: CollectionQueryWidgetData }>) {\n const { i18n, payload, user } = req\n const {\n relatedCollection,\n sortDirection = 'desc',\n sortField,\n title: titleFromData,\n where,\n } = widgetData ?? {}\n const limit = clampLimit(widgetData?.limit)\n const collectionConfig = relatedCollection\n ? payload.collections[relatedCollection]?.config\n : undefined\n\n const title =\n titleFromData ||\n (collectionConfig\n ? getTranslation(collectionConfig.labels.plural, i18n)\n : i18n.t('dashboard:widgetTitleFallback'))\n\n const fieldPaths = collectionConfig\n ? getCollectionFieldPaths(collectionConfig.fields)\n : emptyFieldPaths\n const validationErrors = getValidationErrors({\n collectionConfig,\n fieldPaths,\n i18n,\n relatedCollection,\n sortField,\n where,\n })\n\n if (validationErrors.length > 0 || !relatedCollection || !collectionConfig) {\n return <CollectionQueryError errors={validationErrors} i18n={i18n} title={title} />\n }\n\n const sort = sortField ? `${sortDirection === 'desc' ? '-' : ''}${sortField}` : undefined\n const adminRoute = payload.config.routes.admin\n\n let docs: QueryDoc[]\n\n try {\n const result = await payload.find({\n collection: relatedCollection,\n depth: 0,\n limit,\n overrideAccess: false,\n sort,\n user,\n where,\n })\n\n docs = result.docs as QueryDoc[]\n } catch (err) {\n payload.logger.error({\n err,\n msg: `CollectionQueryWidget: failed to query collection \"${relatedCollection}\"`,\n })\n\n return (\n <CollectionQueryError\n errors={[i18n.t('dashboard:widgetQueryError')]}\n i18n={i18n}\n title={title}\n />\n )\n }\n\n const documentLabelPath = getCollectionDocumentLabelPath(collectionConfig.admin)\n const relativeTimeFormat = getRelativeTimeFormat(i18n.language)\n\n return (\n <div className=\"card collection-query-widget\">\n <div className=\"collection-query-widget__header\">\n <h3 className=\"collection-query-widget__title\">{title}</h3>\n </div>\n {docs.length > 0 ? (\n <ul className=\"collection-query-widget__rows\">\n {docs.map((doc) => {\n const sortMeta = getDocSortMeta({ doc, i18n, relativeTimeFormat, sortField })\n\n return (\n <li className=\"collection-query-widget__row\" key={doc.id}>\n <a\n className=\"collection-query-widget__row-link\"\n href={getDocumentHref({\n id: doc.id,\n adminRoute,\n collectionSlug: relatedCollection,\n })}\n >\n <span className=\"collection-query-widget__row-main\">\n <span className=\"collection-query-widget__row-title\">\n {getDocLabel({ doc, documentLabelPath })}\n </span>\n </span>\n <span className=\"collection-query-widget__row-meta\">\n {sortMeta ? (\n sortMeta.dateTime ? (\n <time dateTime={sortMeta.dateTime}>{sortMeta.label}</time>\n ) : (\n sortMeta.label\n )\n ) : null}\n </span>\n </a>\n </li>\n )\n })}\n </ul>\n ) : (\n <p className=\"collection-query-widget__empty\">{i18n.t('general:noResultsFound')}</p>\n )}\n </div>\n )\n}\n\nfunction CollectionQueryError({\n errors,\n i18n,\n title,\n}: {\n errors: string[]\n i18n: I18n\n title: string\n}) {\n return (\n <div className=\"card collection-query-widget collection-query-widget--error\">\n <div className=\"collection-query-widget__header\">\n <h3 className=\"collection-query-widget__title\">{title}</h3>\n </div>\n <div className=\"collection-query-widget__error\">\n <p className=\"collection-query-widget__error-title\">\n {i18n.t('dashboard:widgetConfigurationError')}\n </p>\n <ul className=\"collection-query-widget__error-list\">\n {errors.map((error) => (\n <li key={error}>{error}</li>\n ))}\n </ul>\n </div>\n </div>\n )\n}\n\nfunction clampLimit(limit: number | undefined) {\n if (typeof limit !== 'number' || Number.isNaN(limit)) {\n return 5\n }\n\n return Math.min(Math.max(Math.floor(limit), minLimit), maxLimit)\n}\n\nfunction getCollectionDocumentLabelPath(adminConfig: { useAsTitle?: string }) {\n return adminConfig.useAsTitle || 'id'\n}\n\nfunction getDocSortMeta({\n doc,\n i18n,\n relativeTimeFormat,\n sortField,\n}: {\n doc: QueryDoc\n i18n: I18n\n relativeTimeFormat: Intl.RelativeTimeFormat\n sortField?: string\n}) {\n const value = sortField\n ? getValueByPath({ object: doc, path: sortField })\n : doc.updatedAt || doc.createdAt\n\n if (value === null || typeof value === 'undefined' || value === '') {\n return null\n }\n\n if (value instanceof Date) {\n const dateTime = value.toISOString()\n\n return {\n dateTime,\n label: formatRelativeDate({ relativeTimeFormat, value: dateTime }),\n }\n }\n\n if (typeof value === 'string') {\n if (isDateString(value)) {\n return {\n dateTime: value,\n label: formatRelativeDate({ relativeTimeFormat, value }),\n }\n }\n\n return { label: value }\n }\n\n if (typeof value === 'number') {\n return { label: value.toLocaleString(i18n.language) }\n }\n\n if (typeof value === 'boolean') {\n return { label: value ? i18n.t('general:true') : i18n.t('general:false') }\n }\n\n return null\n}\n\nfunction getDocLabel({ doc, documentLabelPath }: { doc: QueryDoc; documentLabelPath: string }) {\n const title = getValueByPath({ object: doc, path: documentLabelPath })\n\n return typeof title === 'string' && title ? title : String(doc.id)\n}\n\nfunction getValidationErrors({\n collectionConfig,\n fieldPaths,\n i18n,\n relatedCollection,\n sortField,\n where,\n}: {\n collectionConfig: unknown\n fieldPaths: CollectionFieldPaths\n i18n: I18n\n relatedCollection?: CollectionSlug\n sortField?: string\n where?: Where\n}) {\n const errors: string[] = []\n\n if (!relatedCollection) {\n errors.push(i18n.t('dashboard:widgetCollectionRequired'))\n\n return errors\n }\n\n if (!collectionConfig) {\n errors.push(i18n.t('dashboard:widgetInvalidCollection', { collection: relatedCollection }))\n\n return errors\n }\n\n if (sortField) {\n if (!fieldPaths.filterableFieldPaths.has(sortField)) {\n errors.push(\n i18n.t('dashboard:widgetInvalidSortField', {\n collection: relatedCollection,\n field: sortField,\n }),\n )\n } else if (!fieldPaths.sortableFieldPaths.has(sortField)) {\n errors.push(\n i18n.t('dashboard:widgetNonSortableSortField', {\n collection: relatedCollection,\n field: sortField,\n }),\n )\n }\n }\n\n for (const fieldPath of getWhereFieldPaths(where)) {\n if (\n fieldPaths.filterableFieldPaths.has(fieldPath) ||\n hasRelationshipAncestor({\n path: fieldPath,\n relationshipFieldPaths: fieldPaths.relationshipFieldPaths,\n })\n ) {\n continue\n }\n\n errors.push(\n i18n.t('dashboard:widgetInvalidFilterField', {\n collection: relatedCollection,\n field: fieldPath,\n }),\n )\n }\n\n return errors\n}\n\n/**\n * A `where` path that traverses into a relationship (e.g. `category.name`) cannot be validated\n * against this collection's fields because it targets another collection, so accept it when any\n * ancestor segment is a relationship.\n */\nfunction hasRelationshipAncestor({\n path,\n relationshipFieldPaths,\n}: {\n path: string\n relationshipFieldPaths: Set<string>\n}) {\n const segments = path.split('.')\n let prefix = ''\n\n for (const segment of segments) {\n prefix = prefix ? `${prefix}.${segment}` : segment\n\n if (relationshipFieldPaths.has(prefix)) {\n return true\n }\n }\n\n return false\n}\n\nfunction getWhereFieldPaths(where: undefined | Where) {\n const fieldPaths = new Set<string>()\n\n collectWhereFieldPaths({ fieldPaths, value: where })\n\n return fieldPaths\n}\n\nfunction collectWhereFieldPaths({\n fieldPaths,\n value,\n}: {\n fieldPaths: Set<string>\n value: unknown\n}) {\n if (!value || typeof value !== 'object') {\n return\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n collectWhereFieldPaths({ fieldPaths, value: item })\n }\n\n return\n }\n\n for (const [key, childValue] of Object.entries(value)) {\n if (key === 'and' || key === 'or') {\n collectWhereFieldPaths({ fieldPaths, value: childValue })\n\n continue\n }\n\n fieldPaths.add(key)\n }\n}\n\nfunction getDocumentHref({\n id,\n adminRoute,\n collectionSlug,\n}: {\n adminRoute: string\n collectionSlug: CollectionSlug\n id: number | string\n}) {\n return formatAdminURL({\n adminRoute,\n path: `/collections/${collectionSlug}/${id}`,\n })\n}\n\nfunction getValueByPath({ object, path }: { object: Record<string, unknown>; path: string }) {\n return path.split('.').reduce<unknown>((value, segment) => {\n if (!value || typeof value !== 'object') {\n return undefined\n }\n\n return (value as Record<string, unknown>)[segment]\n }, object)\n}\n\nfunction getRelativeTimeFormat(language: string) {\n try {\n return new Intl.RelativeTimeFormat(language, { numeric: 'auto', style: 'narrow' })\n } catch {\n return new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'narrow' })\n }\n}\n\nconst relativeTimeDivisions: { amount: number; unit: Intl.RelativeTimeFormatUnit }[] = [\n { amount: 60, unit: 'seconds' },\n { amount: 60, unit: 'minutes' },\n { amount: 24, unit: 'hours' },\n { amount: 7, unit: 'days' },\n { amount: 4.34524, unit: 'weeks' },\n { amount: 12, unit: 'months' },\n { amount: Number.POSITIVE_INFINITY, unit: 'years' },\n]\n\nfunction formatRelativeDate({\n relativeTimeFormat,\n value,\n}: {\n relativeTimeFormat: Intl.RelativeTimeFormat\n value: string\n}) {\n const date = new Date(value)\n\n if (Number.isNaN(date.getTime())) {\n return value\n }\n\n let duration = (date.getTime() - Date.now()) / 1000\n\n for (const division of relativeTimeDivisions) {\n if (Math.abs(duration) < division.amount) {\n return relativeTimeFormat.format(Math.round(duration), division.unit)\n }\n\n duration /= division.amount\n }\n\n return relativeTimeFormat.format(Math.round(duration), 'years')\n}\n\nfunction isDateString(value: string) {\n return /^\\d{4}-\\d{2}-\\d{2}/.test(value) && !Number.isNaN(new Date(value).getTime())\n}\n"],"mappings":";AAGA,SAASA,cAAc,QAAQ;AAC/B,SAASC,cAAc,QAAQ;AAC/B,OAAOC,KAAA,MAAW;AAIlB,OAAO;AACP,OAAO;AACP,SAASC,uBAAuB,QAAQ;AAiBxC,MAAMC,QAAA,GAAW;AACjB,MAAMC,QAAA,GAAW;AAEjB,MAAMC,eAAA,GAAwC;EAC5CC,oBAAA,EAAsB,IAAIC,GAAA;EAC1BC,sBAAA,EAAwB,IAAID,GAAA;EAC5BE,kBAAA,EAAoB,IAAIF,GAAA;AAC1B;AAEA,OAAO,eAAeG,sBAAsB;EAC1CC,GAAG;EACHC;AAAU,CAC8C;EACxD,MAAM;IAAEC,IAAI;IAAEC,OAAO;IAAEC;EAAI,CAAE,GAAGJ,GAAA;EAChC,MAAM;IACJK,iBAAiB;IACjBC,aAAA,GAAgB,MAAM;IACtBC,SAAS;IACTC,KAAA,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,GAAW,CAACF,IAAA,CAAKC,OAAO,KAAKnC,IAAA,CAAKqC,GAAG,EAAC,IAAK;EAE/C,KAAK,MAAMC,QAAA,IAAYR,qBAAA,EAAuB;IAC5C,IAAI1C,IAAA,CAAKmD,GAAG,CAACH,QAAA,IAAYE,QAAA,CAASP,MAAM,EAAE;MACxC,OAAO7D,kBAAA,CAAmBsE,MAAM,CAACpD,IAAA,CAAKqD,KAAK,CAACL,QAAA,GAAWE,QAAA,CAASN,IAAI;IACtE;IAEAI,QAAA,IAAYE,QAAA,CAASP,MAAM;EAC7B;EAEA,OAAO7D,kBAAA,CAAmBsE,MAAM,CAACpD,IAAA,CAAKqD,KAAK,CAACL,QAAA,GAAW;AACzD;AAEA,SAASjC,aAAaT,KAAa;EACjC,OAAO,qBAAqBgD,IAAI,CAAChD,KAAA,KAAU,CAACR,MAAA,CAAOC,KAAK,CAAC,IAAIa,IAAA,CAAKN,KAAA,EAAOyC,OAAO;AAClF","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["getTranslation","formatAdminURL","React","formatRelativeDate","getRelativeTimeFormat","WidgetCard","WidgetList","getCollectionFieldPaths","minLimit","maxLimit","emptyFieldPaths","filterableFieldPaths","Set","relationshipFieldPaths","sortableFieldPaths","CollectionQueryWidget","req","widgetData","i18n","payload","user","relatedCollection","sortDirection","sortField","title","titleFromData","where","limit","clampLimit","collectionConfig","collections","config","undefined","labels","plural","t","fieldPaths","fields","validationErrors","getValidationErrors","length","_jsx","CollectionQueryError","errors","sort","adminRoute","routes","admin","docs","result","find","collection","depth","overrideAccess","err","logger","error","msg","documentLabelPath","getCollectionDocumentLabelPath","relativeTimeFormat","language","items","map","doc","sortMeta","getDocSortMeta","href","getDocumentHref","id","collectionSlug","key","String","main","className","getDocLabel","meta","dateTime","label","emptyMessage","_jsxs","Number","isNaN","Math","min","max","floor","adminConfig","useAsTitle","value","getValueByPath","object","path","updatedAt","createdAt","Date","toISOString","isDateString","toLocaleString","push","has","field","fieldPath","getWhereFieldPaths","hasRelationshipAncestor","segments","split","prefix","segment","collectWhereFieldPaths","Array","isArray","item","childValue","Object","entries","add","reduce","test","getTime"],"sources":["../../../src/widgets/CollectionQuery/index.tsx"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type { CollectionSlug, Where, WidgetServerProps } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { formatAdminURL } from 'payload/shared'\nimport React from 'react'\n\nimport type { WidgetListItem } from '../WidgetCard/index.js'\nimport type { CollectionFieldPaths } from './getCollectionFieldPaths.js'\n\nimport { formatRelativeDate, getRelativeTimeFormat } from '../../utilities/formatRelativeDate.js'\nimport { WidgetCard, WidgetList } from '../WidgetCard/index.js'\nimport './index.css'\nimport { getCollectionFieldPaths } from './getCollectionFieldPaths.js'\n\ntype CollectionQueryWidgetData = {\n limit?: number\n relatedCollection?: CollectionSlug\n sortDirection?: 'asc' | 'desc'\n sortField?: string\n title?: string\n where?: Where\n}\n\ntype QueryDoc = {\n createdAt?: string\n id: number | string\n updatedAt?: string\n} & Record<string, unknown>\n\nconst minLimit = 1\nconst maxLimit = 25\n\nconst emptyFieldPaths: CollectionFieldPaths = {\n filterableFieldPaths: new Set<string>(),\n relationshipFieldPaths: new Set<string>(),\n sortableFieldPaths: new Set<string>(),\n}\n\nexport async function CollectionQueryWidget({\n req,\n widgetData,\n}: WidgetServerProps<{ data?: CollectionQueryWidgetData }>) {\n const { i18n, payload, user } = req\n const {\n relatedCollection,\n sortDirection = 'desc',\n sortField,\n title: titleFromData,\n where,\n } = widgetData ?? {}\n const limit = clampLimit(widgetData?.limit)\n const collectionConfig = relatedCollection\n ? payload.collections[relatedCollection]?.config\n : undefined\n\n const title =\n titleFromData ||\n (collectionConfig\n ? getTranslation(collectionConfig.labels.plural, i18n)\n : i18n.t('dashboard:widgetTitleFallback'))\n\n const fieldPaths = collectionConfig\n ? getCollectionFieldPaths(collectionConfig.fields)\n : emptyFieldPaths\n const validationErrors = getValidationErrors({\n collectionConfig,\n fieldPaths,\n i18n,\n relatedCollection,\n sortField,\n where,\n })\n\n if (validationErrors.length > 0 || !relatedCollection || !collectionConfig) {\n return <CollectionQueryError errors={validationErrors} i18n={i18n} title={title} />\n }\n\n const sort = sortField ? `${sortDirection === 'desc' ? '-' : ''}${sortField}` : undefined\n const adminRoute = payload.config.routes.admin\n\n let docs: QueryDoc[]\n\n try {\n const result = await payload.find({\n collection: relatedCollection,\n depth: 0,\n limit,\n overrideAccess: false,\n sort,\n user,\n where,\n })\n\n docs = result.docs as QueryDoc[]\n } catch (err) {\n payload.logger.error({\n err,\n msg: `CollectionQueryWidget: failed to query collection \"${relatedCollection}\"`,\n })\n\n return (\n <CollectionQueryError\n errors={[i18n.t('dashboard:widgetQueryError')]}\n i18n={i18n}\n title={title}\n />\n )\n }\n\n const documentLabelPath = getCollectionDocumentLabelPath(collectionConfig.admin)\n const relativeTimeFormat = getRelativeTimeFormat(i18n.language)\n\n const items: WidgetListItem[] = docs.map((doc) => {\n const sortMeta = getDocSortMeta({ doc, i18n, relativeTimeFormat, sortField })\n\n return {\n href: getDocumentHref({ id: doc.id, adminRoute, collectionSlug: relatedCollection }),\n key: String(doc.id),\n main: (\n <span className=\"widget-card__row-title\">{getDocLabel({ doc, documentLabelPath })}</span>\n ),\n meta: sortMeta ? (\n sortMeta.dateTime ? (\n <time dateTime={sortMeta.dateTime}>{sortMeta.label}</time>\n ) : (\n sortMeta.label\n )\n ) : null,\n }\n })\n\n return (\n <WidgetCard className=\"collection-query-widget\" title={title}>\n <WidgetList emptyMessage={i18n.t('general:noResultsFound')} items={items} />\n </WidgetCard>\n )\n}\n\nfunction CollectionQueryError({\n errors,\n i18n,\n title,\n}: {\n errors: string[]\n i18n: I18n\n title: string\n}) {\n return (\n <WidgetCard className=\"collection-query-widget collection-query-widget--error\" title={title}>\n <div className=\"collection-query-widget__error\">\n <p className=\"collection-query-widget__error-title\">\n {i18n.t('dashboard:widgetConfigurationError')}\n </p>\n <ul className=\"collection-query-widget__error-list\">\n {errors.map((error) => (\n <li key={error}>{error}</li>\n ))}\n </ul>\n </div>\n </WidgetCard>\n )\n}\n\nfunction clampLimit(limit: number | undefined) {\n if (typeof limit !== 'number' || Number.isNaN(limit)) {\n return 5\n }\n\n return Math.min(Math.max(Math.floor(limit), minLimit), maxLimit)\n}\n\nfunction getCollectionDocumentLabelPath(adminConfig: { useAsTitle?: string }) {\n return adminConfig.useAsTitle || 'id'\n}\n\nfunction getDocSortMeta({\n doc,\n i18n,\n relativeTimeFormat,\n sortField,\n}: {\n doc: QueryDoc\n i18n: I18n\n relativeTimeFormat: Intl.RelativeTimeFormat\n sortField?: string\n}) {\n const value = sortField\n ? getValueByPath({ object: doc, path: sortField })\n : doc.updatedAt || doc.createdAt\n\n if (value === null || typeof value === 'undefined' || value === '') {\n return null\n }\n\n if (value instanceof Date) {\n const dateTime = value.toISOString()\n\n return {\n dateTime,\n label: formatRelativeDate({ relativeTimeFormat, value: dateTime }),\n }\n }\n\n if (typeof value === 'string') {\n if (isDateString(value)) {\n return {\n dateTime: value,\n label: formatRelativeDate({ relativeTimeFormat, value }),\n }\n }\n\n return { label: value }\n }\n\n if (typeof value === 'number') {\n return { label: value.toLocaleString(i18n.language) }\n }\n\n if (typeof value === 'boolean') {\n return { label: value ? i18n.t('general:true') : i18n.t('general:false') }\n }\n\n return null\n}\n\nfunction getDocLabel({ doc, documentLabelPath }: { doc: QueryDoc; documentLabelPath: string }) {\n const title = getValueByPath({ object: doc, path: documentLabelPath })\n\n return typeof title === 'string' && title ? title : String(doc.id)\n}\n\nfunction getValidationErrors({\n collectionConfig,\n fieldPaths,\n i18n,\n relatedCollection,\n sortField,\n where,\n}: {\n collectionConfig: unknown\n fieldPaths: CollectionFieldPaths\n i18n: I18n\n relatedCollection?: CollectionSlug\n sortField?: string\n where?: Where\n}) {\n const errors: string[] = []\n\n if (!relatedCollection) {\n errors.push(i18n.t('dashboard:widgetCollectionRequired'))\n\n return errors\n }\n\n if (!collectionConfig) {\n errors.push(i18n.t('dashboard:widgetInvalidCollection', { collection: relatedCollection }))\n\n return errors\n }\n\n if (sortField) {\n if (!fieldPaths.filterableFieldPaths.has(sortField)) {\n errors.push(\n i18n.t('dashboard:widgetInvalidSortField', {\n collection: relatedCollection,\n field: sortField,\n }),\n )\n } else if (!fieldPaths.sortableFieldPaths.has(sortField)) {\n errors.push(\n i18n.t('dashboard:widgetNonSortableSortField', {\n collection: relatedCollection,\n field: sortField,\n }),\n )\n }\n }\n\n for (const fieldPath of getWhereFieldPaths(where)) {\n if (\n fieldPaths.filterableFieldPaths.has(fieldPath) ||\n hasRelationshipAncestor({\n path: fieldPath,\n relationshipFieldPaths: fieldPaths.relationshipFieldPaths,\n })\n ) {\n continue\n }\n\n errors.push(\n i18n.t('dashboard:widgetInvalidFilterField', {\n collection: relatedCollection,\n field: fieldPath,\n }),\n )\n }\n\n return errors\n}\n\n/**\n * A `where` path that traverses into a relationship (e.g. `category.name`) cannot be validated\n * against this collection's fields because it targets another collection, so accept it when any\n * ancestor segment is a relationship.\n */\nfunction hasRelationshipAncestor({\n path,\n relationshipFieldPaths,\n}: {\n path: string\n relationshipFieldPaths: Set<string>\n}) {\n const segments = path.split('.')\n let prefix = ''\n\n for (const segment of segments) {\n prefix = prefix ? `${prefix}.${segment}` : segment\n\n if (relationshipFieldPaths.has(prefix)) {\n return true\n }\n }\n\n return false\n}\n\nfunction getWhereFieldPaths(where: undefined | Where) {\n const fieldPaths = new Set<string>()\n\n collectWhereFieldPaths({ fieldPaths, value: where })\n\n return fieldPaths\n}\n\nfunction collectWhereFieldPaths({\n fieldPaths,\n value,\n}: {\n fieldPaths: Set<string>\n value: unknown\n}) {\n if (!value || typeof value !== 'object') {\n return\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n collectWhereFieldPaths({ fieldPaths, value: item })\n }\n\n return\n }\n\n for (const [key, childValue] of Object.entries(value)) {\n if (key === 'and' || key === 'or') {\n collectWhereFieldPaths({ fieldPaths, value: childValue })\n\n continue\n }\n\n fieldPaths.add(key)\n }\n}\n\nfunction getDocumentHref({\n id,\n adminRoute,\n collectionSlug,\n}: {\n adminRoute: string\n collectionSlug: CollectionSlug\n id: number | string\n}) {\n return formatAdminURL({\n adminRoute,\n path: `/collections/${collectionSlug}/${id}`,\n })\n}\n\nfunction getValueByPath({ object, path }: { object: Record<string, unknown>; path: string }) {\n return path.split('.').reduce<unknown>((value, segment) => {\n if (!value || typeof value !== 'object') {\n return undefined\n }\n\n return (value as Record<string, unknown>)[segment]\n }, object)\n}\n\nfunction isDateString(value: string) {\n return /^\\d{4}-\\d{2}-\\d{2}/.test(value) && !Number.isNaN(new Date(value).getTime())\n}\n"],"mappings":";AAGA,SAASA,cAAc,QAAQ;AAC/B,SAASC,cAAc,QAAQ;AAC/B,OAAOC,KAAA,MAAW;AAKlB,SAASC,kBAAkB,EAAEC,qBAAqB,QAAQ;AAC1D,SAASC,UAAU,EAAEC,UAAU,QAAQ;AACvC,OAAO;AACP,SAASC,uBAAuB,QAAQ;AAiBxC,MAAMC,QAAA,GAAW;AACjB,MAAMC,QAAA,GAAW;AAEjB,MAAMC,eAAA,GAAwC;EAC5CC,oBAAA,EAAsB,IAAIC,GAAA;EAC1BC,sBAAA,EAAwB,IAAID,GAAA;EAC5BE,kBAAA,EAAoB,IAAIF,GAAA;AAC1B;AAEA,OAAO,eAAeG,sBAAsB;EAC1CC,GAAG;EACHC;AAAU,CAC8C;EACxD,MAAM;IAAEC,IAAI;IAAEC,OAAO;IAAEC;EAAI,CAAE,GAAGJ,GAAA;EAChC,MAAM;IACJK,iBAAiB;IACjBC,aAAA,GAAgB,MAAM;IACtBC,SAAS;IACTC,KAAA,EAAOC,aAAa;IACpBC;EAAK,CACN,GAAGT,UAAA,IAAc,CAAC;EACnB,MAAMU,KAAA,GAAQC,UAAA,CAAWX,UAAA,EAAYU,KAAA;EACrC,MAAME,gBAAA,GAAmBR,iBAAA,GACrBF,OAAA,CAAQW,WAAW,CAACT,iBAAA,CAAkB,EAAEU,MA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","ignoreList":[]}
@@ -0,0 +1,14 @@
1
+ @layer payload-default {
2
+ .recently-viewed-collections-field__list {
3
+ display: flex;
4
+ flex-direction: column;
5
+ gap: var(--spacer-1);
6
+ padding: 0;
7
+ margin: var(--spacer-1) 0 0;
8
+ list-style: none;
9
+ }
10
+
11
+ .recently-viewed-collections-field__option {
12
+ margin: 0;
13
+ }
14
+ }
@@ -0,0 +1,10 @@
1
+ import type { SelectFieldClientComponent } from 'payload';
2
+ import './index.css';
3
+ /**
4
+ * Widget config field for the activity widget. The value is stored as an exclusion list
5
+ * (`excludedCollections`), but the user sees an inclusion filter: every collection is checked by
6
+ * default and unchecking one adds it to the stored exclusions. Storing exclusions means collections
7
+ * added later are visible by default.
8
+ */
9
+ export declare const RecentlyViewedCollectionsField: SelectFieldClientComponent;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/widgets/RecentlyViewed/CollectionsField/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAwB,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAS/E,OAAO,aAAa,CAAA;AAOpB;;;;;GAKG;AACH,eAAO,MAAM,8BAA8B,EAAE,0BAmD5C,CAAA"}
@@ -0,0 +1,76 @@
1
+ 'use client';
2
+
3
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
+ import { getTranslation } from '@payloadcms/translations';
5
+ import React, { useCallback, useMemo } from 'react';
6
+ import { CheckboxInput } from '../../../fields/Checkbox/Input.js';
7
+ import { FieldLabel } from '../../../fields/FieldLabel/index.js';
8
+ import { useField } from '../../../forms/useField/index.js';
9
+ import { useTranslation } from '../../../providers/Translation/index.js';
10
+ import './index.css';
11
+ const baseClass = 'recently-viewed-collections-field';
12
+ const normalizeOption = option => typeof option === 'string' ? {
13
+ label: option,
14
+ value: option
15
+ } : option;
16
+ /**
17
+ * Widget config field for the activity widget. The value is stored as an exclusion list
18
+ * (`excludedCollections`), but the user sees an inclusion filter: every collection is checked by
19
+ * default and unchecking one adds it to the stored exclusions. Storing exclusions means collections
20
+ * added later are visible by default.
21
+ */
22
+ export const RecentlyViewedCollectionsField = ({
23
+ field,
24
+ path: pathFromProps,
25
+ readOnly
26
+ }) => {
27
+ const {
28
+ label
29
+ } = field;
30
+ const {
31
+ path,
32
+ setValue,
33
+ value
34
+ } = useField({
35
+ potentiallyStalePath: pathFromProps
36
+ });
37
+ const {
38
+ i18n
39
+ } = useTranslation();
40
+ const excludedSlugs = useMemo(() => new Set(Array.isArray(value) ? value : []), [value]);
41
+ const options = useMemo(() => (field.options ?? []).map(normalizeOption), [field.options]);
42
+ const toggleCollection = useCallback((slug, isIncluded) => {
43
+ const nextExcluded = new Set(excludedSlugs);
44
+ if (isIncluded) {
45
+ nextExcluded.delete(slug);
46
+ } else {
47
+ nextExcluded.add(slug);
48
+ }
49
+ setValue(Array.from(nextExcluded));
50
+ }, [excludedSlugs, setValue]);
51
+ return /*#__PURE__*/_jsxs("div", {
52
+ className: baseClass,
53
+ children: [/*#__PURE__*/_jsx(FieldLabel, {
54
+ as: "span",
55
+ label: label,
56
+ path: path
57
+ }), /*#__PURE__*/_jsx("ul", {
58
+ className: `${baseClass}__list`,
59
+ children: options.map(option => {
60
+ const isIncluded_0 = !excludedSlugs.has(option.value);
61
+ const resolvedLabel = getTranslation(option.label, i18n);
62
+ return /*#__PURE__*/_jsx("li", {
63
+ className: `${baseClass}__option`,
64
+ children: /*#__PURE__*/_jsx(CheckboxInput, {
65
+ checked: isIncluded_0,
66
+ label: typeof resolvedLabel === 'string' ? resolvedLabel : option.value,
67
+ name: `${path}__${option.value}`,
68
+ onToggle: event => toggleCollection(option.value, event.target.checked),
69
+ readOnly: readOnly
70
+ })
71
+ }, option.value);
72
+ })
73
+ })]
74
+ });
75
+ };
76
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["getTranslation","React","useCallback","useMemo","CheckboxInput","FieldLabel","useField","useTranslation","baseClass","normalizeOption","option","label","value","RecentlyViewedCollectionsField","field","path","pathFromProps","readOnly","setValue","potentiallyStalePath","i18n","excludedSlugs","Set","Array","isArray","options","map","toggleCollection","slug","isIncluded","nextExcluded","delete","add","from","_jsxs","className","_jsx","as","has","resolvedLabel","checked","name","onToggle","event","target"],"sources":["../../../../src/widgets/RecentlyViewed/CollectionsField/index.tsx"],"sourcesContent":["'use client'\nimport type { Option, OptionObject, SelectFieldClientComponent } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useCallback, useMemo } from 'react'\n\nimport { CheckboxInput } from '../../../fields/Checkbox/Input.js'\nimport { FieldLabel } from '../../../fields/FieldLabel/index.js'\nimport { useField } from '../../../forms/useField/index.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\nimport './index.css'\n\nconst baseClass = 'recently-viewed-collections-field'\n\nconst normalizeOption = (option: Option): OptionObject =>\n typeof option === 'string' ? { label: option, value: option } : option\n\n/**\n * Widget config field for the activity widget. The value is stored as an exclusion list\n * (`excludedCollections`), but the user sees an inclusion filter: every collection is checked by\n * default and unchecking one adds it to the stored exclusions. Storing exclusions means collections\n * added later are visible by default.\n */\nexport const RecentlyViewedCollectionsField: SelectFieldClientComponent = ({\n field,\n path: pathFromProps,\n readOnly,\n}) => {\n const { label } = field\n const { path, setValue, value } = useField<string[]>({ potentiallyStalePath: pathFromProps })\n const { i18n } = useTranslation()\n\n const excludedSlugs = useMemo(() => new Set<string>(Array.isArray(value) ? value : []), [value])\n\n const options = useMemo(() => (field.options ?? []).map(normalizeOption), [field.options])\n\n const toggleCollection = useCallback(\n (slug: string, isIncluded: boolean) => {\n const nextExcluded = new Set(excludedSlugs)\n\n if (isIncluded) {\n nextExcluded.delete(slug)\n } else {\n nextExcluded.add(slug)\n }\n\n setValue(Array.from(nextExcluded))\n },\n [excludedSlugs, setValue],\n )\n\n return (\n <div className={baseClass}>\n <FieldLabel as=\"span\" label={label} path={path} />\n <ul className={`${baseClass}__list`}>\n {options.map((option) => {\n const isIncluded = !excludedSlugs.has(option.value)\n const resolvedLabel = getTranslation(option.label, i18n)\n\n return (\n <li className={`${baseClass}__option`} key={option.value}>\n <CheckboxInput\n checked={isIncluded}\n label={typeof resolvedLabel === 'string' ? resolvedLabel : option.value}\n name={`${path}__${option.value}`}\n onToggle={(event) => toggleCollection(option.value, event.target.checked)}\n readOnly={readOnly}\n />\n </li>\n )\n })}\n </ul>\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,cAAc,QAAQ;AAC/B,OAAOC,KAAA,IAASC,WAAW,EAAEC,OAAO,QAAQ;AAE5C,SAASC,aAAa,QAAQ;AAC9B,SAASC,UAAU,QAAQ;AAC3B,SAASC,QAAQ,QAAQ;AACzB,SAASC,cAAc,QAAQ;AAC/B,OAAO;AAEP,MAAMC,SAAA,GAAY;AAElB,MAAMC,eAAA,GAAmBC,MAAA,IACvB,OAAOA,MAAA,KAAW,WAAW;EAAEC,KAAA,EAAOD,MAAA;EAAQE,KAAA,EAAOF;AAAO,IAAIA,MAAA;AAElE;;;;;;AAMA,OAAO,MAAMG,8BAAA,GAA6DA,CAAC;EACzEC,KAAK;EACLC,IAAA,EAAMC,aAAa;EACnBC;AAAQ,CACT;EACC,MAAM;IAAEN;EAAK,CAAE,GAAGG,KAAA;EAClB,MAAM;IAAEC,IAAI;IAAEG,QAAQ;IAAEN;EAAK,CAAE,GAAGN,QAAA,CAAmB;IAAEa,oBAAA,EAAsBH;EAAc;EAC3F,MAAM;IAAEI;EAAI,CAAE,GAAGb,cAAA;EAEjB,MAAMc,aAAA,GAAgBlB,OAAA,CAAQ,MAAM,IAAImB,GAAA,CAAYC,KAAA,CAAMC,OAAO,CAACZ,KAAA,IAASA,KAAA,GAAQ,EAAE,GAAG,CAACA,KAAA,CAAM;EAE/F,MAAMa,OAAA,GAAUtB,OAAA,CAAQ,MAAM,CAACW,KAAA,CAAMW,OAAO,IAAI,EAAE,EAAEC,GAA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AOE,KAAK;MAU5D;;;AAIR","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ import type { WidgetServerProps } from 'payload';
2
+ import React from 'react';
3
+ type RecentlyViewedWidgetData = {
4
+ excludedCollections?: string[];
5
+ };
6
+ export declare function RecentlyViewedWidget({ req, widgetData, }: WidgetServerProps<{
7
+ data?: RecentlyViewedWidgetData;
8
+ }>): Promise<React.JSX.Element>;
9
+ export {};
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/widgets/RecentlyViewed/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA6B,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAI3E,OAAO,KAAK,MAAM,OAAO,CAAA;AAQzB,KAAK,wBAAwB,GAAG;IAC9B,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC/B,CAAA;AAmBD,wBAAsB,oBAAoB,CAAC,EACzC,GAAG,EACH,UAAU,GACX,EAAE,iBAAiB,CAAC;IAAE,IAAI,CAAC,EAAE,wBAAwB,CAAA;CAAE,CAAC,8BAgCxD"}