@payloadcms/ui 3.0.0-beta.90 → 3.0.0-beta.92

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 (67) hide show
  1. package/dist/elements/AddNewRelation/index.d.ts.map +1 -1
  2. package/dist/elements/AddNewRelation/index.js +1 -1
  3. package/dist/elements/AddNewRelation/index.js.map +1 -1
  4. package/dist/elements/AddNewRelation/index.scss +14 -4
  5. package/dist/elements/AppHeader/index.js +41 -80
  6. package/dist/elements/AppHeader/index.js.map +1 -1
  7. package/dist/elements/Autosave/index.js +148 -231
  8. package/dist/elements/Autosave/index.js.map +1 -1
  9. package/dist/elements/Button/index.js +86 -218
  10. package/dist/elements/Button/index.js.map +1 -1
  11. package/dist/elements/Collapsible/index.js +44 -62
  12. package/dist/elements/Collapsible/index.js.map +1 -1
  13. package/dist/elements/Collapsible/index.scss +15 -28
  14. package/dist/elements/CopyToClipboard/index.js +20 -54
  15. package/dist/elements/CopyToClipboard/index.js.map +1 -1
  16. package/dist/elements/Dropzone/index.js +59 -119
  17. package/dist/elements/Dropzone/index.js.map +1 -1
  18. package/dist/elements/EditMany/index.js +124 -230
  19. package/dist/elements/EditMany/index.js.map +1 -1
  20. package/dist/elements/EditUpload/index.js +133 -206
  21. package/dist/elements/EditUpload/index.js.map +1 -1
  22. package/dist/elements/ListControls/index.js +82 -188
  23. package/dist/elements/ListControls/index.js.map +1 -1
  24. package/dist/elements/Nav/context.js +47 -83
  25. package/dist/elements/Nav/context.js.map +1 -1
  26. package/dist/elements/SaveButton/index.js +30 -81
  27. package/dist/elements/SaveButton/index.js.map +1 -1
  28. package/dist/elements/SaveDraftButton/index.js +54 -116
  29. package/dist/elements/SaveDraftButton/index.js.map +1 -1
  30. package/dist/elements/SearchFilter/index.js +21 -77
  31. package/dist/elements/SearchFilter/index.js.map +1 -1
  32. package/dist/elements/Upload/index.js +130 -280
  33. package/dist/elements/Upload/index.js.map +1 -1
  34. package/dist/exports/client/{CodeEditor-C4FLUUO7.js → CodeEditor-MTP455NO.js} +2 -2
  35. package/dist/exports/client/chunk-NJHSEGFB.js +14 -0
  36. package/dist/exports/client/{chunk-UGBVRIVY.js.map → chunk-NJHSEGFB.js.map} +2 -2
  37. package/dist/exports/client/index.d.ts +1 -1
  38. package/dist/exports/client/index.d.ts.map +1 -1
  39. package/dist/exports/client/index.js +19 -19
  40. package/dist/exports/client/index.js.map +3 -3
  41. package/dist/fields/Relationship/index.js +318 -504
  42. package/dist/fields/Relationship/index.js.map +1 -1
  43. package/dist/fields/Upload/HasMany/index.d.ts.map +1 -1
  44. package/dist/fields/Upload/HasMany/index.js +192 -422
  45. package/dist/fields/Upload/HasMany/index.js.map +1 -1
  46. package/dist/fields/Upload/HasMany/index.scss +19 -1
  47. package/dist/forms/Submit/index.js +12 -28
  48. package/dist/forms/Submit/index.js.map +1 -1
  49. package/dist/hooks/useDelay.js +15 -48
  50. package/dist/hooks/useDelay.js.map +1 -1
  51. package/dist/hooks/useDelayedRender.js +32 -71
  52. package/dist/hooks/useDelayedRender.js.map +1 -1
  53. package/dist/hooks/useIntersect.js +14 -20
  54. package/dist/hooks/useIntersect.js.map +1 -1
  55. package/dist/providers/Config/createClientConfig/collections.d.ts.map +1 -1
  56. package/dist/providers/Config/createClientConfig/collections.js +8 -6
  57. package/dist/providers/Config/createClientConfig/collections.js.map +1 -1
  58. package/dist/providers/Preferences/index.js +1 -3
  59. package/dist/providers/Preferences/index.js.map +1 -1
  60. package/dist/providers/Selection/index.js +102 -190
  61. package/dist/providers/Selection/index.js.map +1 -1
  62. package/dist/scss/app.scss +6 -6
  63. package/dist/scss/type.scss +4 -4
  64. package/dist/styles.css +1 -1
  65. package/package.json +9 -9
  66. package/dist/exports/client/chunk-UGBVRIVY.js +0 -14
  67. /package/dist/exports/client/{CodeEditor-C4FLUUO7.js.map → CodeEditor-MTP455NO.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"collections.js","names":["deepCopyObjectSimple","createClientFields","createClientCollectionConfig","DefaultEditView","DefaultListView","clientCollection","collection","createMappedComponent","i18n","importMap","payload","fields","clientFields","serverOnlyCollectionProperties","forEach","key","upload","handlers","adminThumbnail","externalFileHeaderFilter","withMetadata","imageSizes","length","map","size","sanitizedSize","generateImageName","auth","strategies","forgotPassword","verify","labels","Object","entries","labelType","collectionLabel","t","serverOnlyCollectionAdminProperties","admin","preview","_isPreviewEnabled","components","edit","PreviewButton","undefined","PublishButton","SaveButton","SaveDraftButton","Upload","beforeList","Component","beforeListTable","afterList","afterListTable","description","Description","clientProps","views","hasEditView","default","collectionSlug","slug","view","actions","hasListView","list","livePreview","url","createClientCollectionConfigs","clientCollections","collections","i"],"sources":["../../../../src/providers/Config/createClientConfig/collections.tsx"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n AdminViewProps,\n ClientCollectionConfig,\n CreateMappedComponent,\n EditViewConfig,\n EditViewProps,\n ImportMap,\n MappedView,\n Payload,\n SanitizedCollectionConfig,\n ServerOnlyCollectionAdminProperties,\n ServerOnlyCollectionProperties,\n} from 'payload'\nimport type React from 'react'\n\nimport { deepCopyObjectSimple } from 'payload'\n\nimport { createClientFields } from './fields.js'\n\nexport const createClientCollectionConfig = ({\n DefaultEditView,\n DefaultListView,\n clientCollection,\n collection,\n createMappedComponent,\n i18n,\n importMap,\n payload,\n}: {\n DefaultEditView: React.FC<EditViewProps>\n DefaultListView: React.FC<AdminViewProps>\n clientCollection: ClientCollectionConfig\n collection: SanitizedCollectionConfig\n createMappedComponent: CreateMappedComponent\n i18n: I18nClient\n importMap: ImportMap\n payload: Payload\n}): ClientCollectionConfig => {\n clientCollection.fields = createClientFields({\n clientFields: clientCollection.fields,\n createMappedComponent,\n fields: collection.fields,\n i18n,\n importMap,\n payload,\n })\n\n const serverOnlyCollectionProperties: Partial<ServerOnlyCollectionProperties>[] = [\n 'hooks',\n 'access',\n 'endpoints',\n 'custom',\n // `upload`\n // `admin`\n // are all handled separately\n ]\n\n serverOnlyCollectionProperties.forEach((key) => {\n if (key in clientCollection) {\n delete clientCollection[key]\n }\n })\n\n if ('upload' in clientCollection && typeof clientCollection.upload === 'object') {\n delete clientCollection.upload.handlers\n delete clientCollection.upload.adminThumbnail\n delete clientCollection.upload.externalFileHeaderFilter\n delete clientCollection.upload.withMetadata\n\n if ('imageSizes' in clientCollection.upload && clientCollection.upload.imageSizes.length) {\n clientCollection.upload.imageSizes = clientCollection.upload.imageSizes.map((size) => {\n const sanitizedSize = { ...size }\n if ('generateImageName' in sanitizedSize) delete sanitizedSize.generateImageName\n return sanitizedSize\n })\n }\n }\n\n if ('auth' in clientCollection && typeof clientCollection.auth === 'object') {\n delete clientCollection.auth.strategies\n delete clientCollection.auth.forgotPassword\n delete clientCollection.auth.verify\n }\n\n if (collection.labels) {\n Object.entries(collection.labels).forEach(([labelType, collectionLabel]) => {\n if (typeof collectionLabel === 'function') {\n clientCollection.labels[labelType] = collectionLabel({ t: i18n.t })\n }\n })\n }\n\n const serverOnlyCollectionAdminProperties: Partial<ServerOnlyCollectionAdminProperties>[] = [\n 'hidden',\n 'preview',\n // `livePreview` is handled separately\n ]\n\n serverOnlyCollectionAdminProperties.forEach((key) => {\n if (key in clientCollection.admin) {\n delete clientCollection.admin[key]\n }\n })\n\n if (collection.admin.preview) {\n clientCollection._isPreviewEnabled = true\n }\n\n clientCollection.admin.components = {} as ClientCollectionConfig['admin']['components']\n\n if (collection?.admin?.components) {\n if (collection.admin.components?.edit) {\n clientCollection.admin.components.edit =\n {} as ClientCollectionConfig['admin']['components']['edit']\n\n if (collection.admin.components.edit?.PreviewButton) {\n clientCollection.admin.components.edit.PreviewButton = createMappedComponent(\n collection.admin.components.edit.PreviewButton,\n undefined,\n undefined,\n 'collection.admin.components.edit.PreviewButton',\n )\n }\n\n if (collection.admin.components.edit?.PublishButton) {\n clientCollection.admin.components.edit.PublishButton = createMappedComponent(\n collection.admin.components.edit.PublishButton,\n undefined,\n undefined,\n 'collection.admin.components.edit.PublishButton',\n )\n }\n\n if (collection.admin.components.edit?.SaveButton) {\n clientCollection.admin.components.edit.SaveButton = createMappedComponent(\n collection.admin.components.edit.SaveButton,\n undefined,\n undefined,\n 'collection.admin.components.edit.SaveButton',\n )\n }\n\n if (collection.admin.components.edit?.SaveDraftButton) {\n clientCollection.admin.components.edit.SaveDraftButton = createMappedComponent(\n collection.admin.components.edit.SaveDraftButton,\n undefined,\n undefined,\n 'collection.admin.components.edit.SaveDraftButton',\n )\n }\n\n if (collection.admin.components.edit?.Upload) {\n clientCollection.admin.components.edit.Upload = createMappedComponent(\n collection.admin.components.edit.Upload,\n undefined,\n undefined,\n 'collection.admin.components.edit.Upload',\n )\n }\n }\n\n if (collection.admin.components?.beforeList) {\n clientCollection.admin.components.beforeList = collection.admin.components.beforeList.map(\n (Component) =>\n createMappedComponent(\n Component,\n undefined,\n undefined,\n 'collection.admin.components.beforeList',\n ),\n )\n }\n\n if (collection.admin.components?.beforeListTable) {\n clientCollection.admin.components.beforeListTable =\n collection.admin.components.beforeListTable.map((Component) =>\n createMappedComponent(\n Component,\n undefined,\n undefined,\n 'collection.admin.components.beforeListTable',\n ),\n )\n }\n\n if (collection.admin.components?.afterList) {\n clientCollection.admin.components.afterList = collection.admin.components.afterList.map(\n (Component) =>\n createMappedComponent(\n Component,\n undefined,\n undefined,\n 'collection.admin.components.afterList',\n ),\n )\n }\n\n if (collection.admin.components?.afterListTable) {\n clientCollection.admin.components.afterListTable =\n collection.admin.components.afterListTable.map((Component) =>\n createMappedComponent(\n Component,\n undefined,\n undefined,\n 'collection.admin.components.afterListTable',\n ),\n )\n }\n }\n\n let description = undefined\n\n if (collection.admin?.description) {\n if (\n typeof collection.admin?.description === 'string' ||\n typeof collection.admin?.description === 'object'\n ) {\n description = collection.admin.description\n } else if (typeof collection.admin?.description === 'function') {\n description = collection.admin?.description({ t: i18n.t })\n }\n }\n\n clientCollection.admin.description = description\n\n if (collection.admin.components?.Description) {\n clientCollection.admin.components.Description = createMappedComponent(\n collection.admin.components.Description,\n {\n clientProps: {\n description,\n },\n },\n undefined,\n 'collection.admin.components.Description',\n )\n }\n\n clientCollection.admin.components.views = (\n collection?.admin?.components?.views\n ? deepCopyObjectSimple(collection?.admin?.components?.views)\n : {}\n ) as ClientCollectionConfig['admin']['components']['views']\n\n const hasEditView =\n 'admin' in collection &&\n 'components' in collection.admin &&\n 'views' in collection.admin.components &&\n 'edit' in collection.admin.components.views &&\n 'default' in collection.admin.components.views.edit\n\n if (!clientCollection.admin.components.views.edit) {\n clientCollection.admin.components.views.edit =\n {} as ClientCollectionConfig['admin']['components']['views']['edit']\n }\n\n clientCollection.admin.components.views.edit.default = {\n Component: createMappedComponent(\n hasEditView &&\n 'Component' in collection.admin.components.views.edit.default &&\n collection.admin.components.views.edit.default.Component\n ? collection.admin.components.views.edit.default.Component\n : null,\n {\n clientProps: {\n collectionSlug: collection.slug,\n },\n },\n DefaultEditView,\n 'collection.admin.components.views.edit.default',\n ),\n }\n\n if (collection?.admin?.components?.views?.edit) {\n for (const key in collection.admin.components.views.edit) {\n const view: EditViewConfig = collection.admin.components.views.edit[key]\n\n if (!clientCollection.admin.components.views.edit[key]) {\n clientCollection.admin.components.views.edit[key] = {} as MappedView\n }\n\n if ('Component' in view && key !== 'default') {\n clientCollection.admin.components.views.edit[key].Component = createMappedComponent(\n view.Component,\n {\n clientProps: {\n collectionSlug: collection.slug,\n },\n },\n undefined,\n 'collection.admin.components.views.edit.key.Component',\n )\n }\n\n if ('actions' in view && view.actions?.length) {\n clientCollection.admin.components.views.edit[key].actions = view.actions.map((Component) =>\n createMappedComponent(\n Component,\n undefined,\n undefined,\n 'collection.admin.components.views.key.admin',\n ),\n )\n }\n }\n }\n\n const hasListView =\n 'admin' in collection &&\n 'components' in collection.admin &&\n 'views' in collection.admin.components &&\n 'list' in collection.admin.components.views\n\n if (!clientCollection.admin.components.views.list) {\n clientCollection.admin.components.views.list =\n {} as ClientCollectionConfig['admin']['components']['views']['list']\n }\n\n clientCollection.admin.components.views.list.Component = createMappedComponent(\n hasListView &&\n 'Component' in collection.admin.components.views.list &&\n collection.admin.components.views.list.Component\n ? collection.admin.components.views.list.Component\n : null,\n {\n clientProps: {\n collectionSlug: collection.slug,\n },\n },\n DefaultListView,\n 'collection.admin.components.views.list',\n )\n\n if (\n hasListView &&\n 'actions' in collection.admin.components.views.list &&\n collection.admin.components.views.list.actions\n ) {\n clientCollection.admin.components.views.list.actions =\n collection.admin.components.views.list.actions.map((Component) =>\n createMappedComponent(\n Component,\n undefined,\n undefined,\n 'collection.admin.components.views.list',\n ),\n )\n }\n\n if (\n 'livePreview' in clientCollection.admin &&\n clientCollection.admin.livePreview &&\n 'url' in clientCollection.admin.livePreview\n ) {\n delete clientCollection.admin.livePreview.url\n }\n\n return clientCollection\n}\n\nexport const createClientCollectionConfigs = ({\n DefaultEditView,\n DefaultListView,\n clientCollections,\n collections,\n createMappedComponent,\n i18n,\n importMap,\n payload,\n}: {\n DefaultEditView: React.FC<EditViewProps>\n DefaultListView: React.FC<AdminViewProps>\n clientCollections: ClientCollectionConfig[]\n collections: SanitizedCollectionConfig[]\n createMappedComponent: CreateMappedComponent\n i18n: I18nClient\n importMap: ImportMap\n payload: Payload\n}): ClientCollectionConfig[] => {\n for (let i = 0; i < collections.length; i++) {\n const collection = collections[i]\n const clientCollection = clientCollections[i]\n clientCollections[i] = createClientCollectionConfig({\n DefaultEditView,\n DefaultListView,\n clientCollection,\n collection,\n createMappedComponent,\n i18n,\n importMap,\n payload,\n })\n }\n\n return clientCollections\n}\n"],"mappings":"AAgBA,SAASA,oBAAoB,QAAQ;AAErC,SAASC,kBAAkB,QAAQ;AAEnC,OAAO,MAAMC,4BAAA,GAA+BA,CAAC;EAC3CC,eAAe;EACfC,eAAe;EACfC,gBAAgB;EAChBC,UAAU;EACVC,qBAAqB;EACrBC,IAAI;EACJC,SAAS;EACTC;AAAO,CAUR;EACCL,gBAAA,CAAiBM,MAAM,GAAGV,kBAAA,CAAmB;IAC3CW,YAAA,EA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AAA,EACAN,SAAA,EACAA,SAAA,EACA;EAGR;EAEA,IACE,iBAAiBvC,gBAAA,CAAiBiC,KAAK,IACvCjC,gBAAA,CAAiBiC,KAAK,CAAC4B,WAAW,IAClC,SAAS7D,gBAAA,CAAiBiC,KAAK,CAAC4B,WAAW,EAC3C;IACA,OAAO7D,gBAAA,CAAiBiC,KAAK,CAAC4B,WAAW,CAACC,GAAG;EAC/C;EAEA,OAAO9D,gBAAA;AACT;AAEA,OAAO,MAAM+D,6BAAA,GAAgCA,CAAC;EAC5CjE,eAAe;EACfC,eAAe;EACfiE,iBAAiB;EACjBC,WAAW;EACX/D,qBAAqB;EACrBC,IAAI;EACJC,SAAS;EACTC;AAAO,CAUR;EACC,KAAK,IAAI6D,CAAA,GAAI,GAAGA,CAAA,GAAID,WAAA,CAAYhD,MAAM,EAAEiD,CAAA,IAAK;IAC3C,MAAMjE,UAAA,GAAagE,WAAW,CAACC,CAAA,CAAE;IACjC,MAAMlE,gBAAA,GAAmBgE,iBAAiB,CAACE,CAAA,CAAE;IAC7CF,iBAAiB,CAACE,CAAA,CAAE,GAAGrE,4BAAA,CAA6B;MAClDC,eAAA;MACAC,eAAA;MACAC,gBAAA;MACAC,UAAA;MACAC,qBAAA;MACAC,IAAA;MACAC,SAAA;MACAC;IACF;EACF;EAEA,OAAO2D,iBAAA;AACT","ignoreList":[]}
1
+ {"version":3,"file":"collections.js","names":["deepCopyObjectSimple","createClientFields","serverOnlyCollectionProperties","serverOnlyUploadProperties","serverOnlyCollectionAdminProperties","createClientCollectionConfig","DefaultEditView","DefaultListView","clientCollection","collection","createMappedComponent","i18n","importMap","payload","fields","clientFields","forEach","key","upload","imageSizes","length","map","size","sanitizedSize","generateImageName","auth","strategies","forgotPassword","verify","labels","Object","entries","labelType","collectionLabel","t","admin","preview","_isPreviewEnabled","components","edit","PreviewButton","undefined","PublishButton","SaveButton","SaveDraftButton","Upload","beforeList","Component","beforeListTable","afterList","afterListTable","description","Description","clientProps","views","hasEditView","default","collectionSlug","slug","view","actions","hasListView","list","livePreview","url","createClientCollectionConfigs","clientCollections","collections","i"],"sources":["../../../../src/providers/Config/createClientConfig/collections.tsx"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n AdminViewProps,\n ClientCollectionConfig,\n CreateMappedComponent,\n EditViewConfig,\n EditViewProps,\n ImportMap,\n MappedView,\n Payload,\n SanitizedCollectionConfig,\n ServerOnlyCollectionAdminProperties,\n ServerOnlyCollectionProperties,\n ServerOnlyUploadProperties,\n} from 'payload'\nimport type React from 'react'\n\nimport { deepCopyObjectSimple } from 'payload'\n\nimport { createClientFields } from './fields.js'\n\nconst serverOnlyCollectionProperties: Partial<ServerOnlyCollectionProperties>[] = [\n 'hooks',\n 'access',\n 'endpoints',\n 'custom',\n // `upload`\n // `admin`\n // are all handled separately\n]\n\nconst serverOnlyUploadProperties: Partial<ServerOnlyUploadProperties>[] = [\n 'adminThumbnail',\n 'externalFileHeaderFilter',\n 'handlers',\n 'modifyResponseHeaders',\n 'withMetadata',\n]\n\nconst serverOnlyCollectionAdminProperties: Partial<ServerOnlyCollectionAdminProperties>[] = [\n 'hidden',\n 'preview',\n // `livePreview` is handled separately\n]\n\nexport const createClientCollectionConfig = ({\n DefaultEditView,\n DefaultListView,\n clientCollection,\n collection,\n createMappedComponent,\n i18n,\n importMap,\n payload,\n}: {\n DefaultEditView: React.FC<EditViewProps>\n DefaultListView: React.FC<AdminViewProps>\n clientCollection: ClientCollectionConfig\n collection: SanitizedCollectionConfig\n createMappedComponent: CreateMappedComponent\n i18n: I18nClient\n importMap: ImportMap\n payload: Payload\n}): ClientCollectionConfig => {\n clientCollection.fields = createClientFields({\n clientFields: clientCollection.fields,\n createMappedComponent,\n fields: collection.fields,\n i18n,\n importMap,\n payload,\n })\n\n serverOnlyCollectionProperties.forEach((key) => {\n if (key in clientCollection) {\n delete clientCollection[key]\n }\n })\n\n if ('upload' in clientCollection && typeof clientCollection.upload === 'object') {\n serverOnlyUploadProperties.forEach((key) => {\n if (key in clientCollection.upload) {\n delete clientCollection.upload[key]\n }\n })\n\n if ('imageSizes' in clientCollection.upload && clientCollection.upload.imageSizes.length) {\n clientCollection.upload.imageSizes = clientCollection.upload.imageSizes.map((size) => {\n const sanitizedSize = { ...size }\n if ('generateImageName' in sanitizedSize) delete sanitizedSize.generateImageName\n return sanitizedSize\n })\n }\n }\n\n if ('auth' in clientCollection && typeof clientCollection.auth === 'object') {\n delete clientCollection.auth.strategies\n delete clientCollection.auth.forgotPassword\n delete clientCollection.auth.verify\n }\n\n if (collection.labels) {\n Object.entries(collection.labels).forEach(([labelType, collectionLabel]) => {\n if (typeof collectionLabel === 'function') {\n clientCollection.labels[labelType] = collectionLabel({ t: i18n.t })\n }\n })\n }\n\n serverOnlyCollectionAdminProperties.forEach((key) => {\n if (key in clientCollection.admin) {\n delete clientCollection.admin[key]\n }\n })\n\n if (collection.admin.preview) {\n clientCollection._isPreviewEnabled = true\n }\n\n clientCollection.admin.components = {} as ClientCollectionConfig['admin']['components']\n\n if (collection?.admin?.components) {\n if (collection.admin.components?.edit) {\n clientCollection.admin.components.edit =\n {} as ClientCollectionConfig['admin']['components']['edit']\n\n if (collection.admin.components.edit?.PreviewButton) {\n clientCollection.admin.components.edit.PreviewButton = createMappedComponent(\n collection.admin.components.edit.PreviewButton,\n undefined,\n undefined,\n 'collection.admin.components.edit.PreviewButton',\n )\n }\n\n if (collection.admin.components.edit?.PublishButton) {\n clientCollection.admin.components.edit.PublishButton = createMappedComponent(\n collection.admin.components.edit.PublishButton,\n undefined,\n undefined,\n 'collection.admin.components.edit.PublishButton',\n )\n }\n\n if (collection.admin.components.edit?.SaveButton) {\n clientCollection.admin.components.edit.SaveButton = createMappedComponent(\n collection.admin.components.edit.SaveButton,\n undefined,\n undefined,\n 'collection.admin.components.edit.SaveButton',\n )\n }\n\n if (collection.admin.components.edit?.SaveDraftButton) {\n clientCollection.admin.components.edit.SaveDraftButton = createMappedComponent(\n collection.admin.components.edit.SaveDraftButton,\n undefined,\n undefined,\n 'collection.admin.components.edit.SaveDraftButton',\n )\n }\n\n if (collection.admin.components.edit?.Upload) {\n clientCollection.admin.components.edit.Upload = createMappedComponent(\n collection.admin.components.edit.Upload,\n undefined,\n undefined,\n 'collection.admin.components.edit.Upload',\n )\n }\n }\n\n if (collection.admin.components?.beforeList) {\n clientCollection.admin.components.beforeList = collection.admin.components.beforeList.map(\n (Component) =>\n createMappedComponent(\n Component,\n undefined,\n undefined,\n 'collection.admin.components.beforeList',\n ),\n )\n }\n\n if (collection.admin.components?.beforeListTable) {\n clientCollection.admin.components.beforeListTable =\n collection.admin.components.beforeListTable.map((Component) =>\n createMappedComponent(\n Component,\n undefined,\n undefined,\n 'collection.admin.components.beforeListTable',\n ),\n )\n }\n\n if (collection.admin.components?.afterList) {\n clientCollection.admin.components.afterList = collection.admin.components.afterList.map(\n (Component) =>\n createMappedComponent(\n Component,\n undefined,\n undefined,\n 'collection.admin.components.afterList',\n ),\n )\n }\n\n if (collection.admin.components?.afterListTable) {\n clientCollection.admin.components.afterListTable =\n collection.admin.components.afterListTable.map((Component) =>\n createMappedComponent(\n Component,\n undefined,\n undefined,\n 'collection.admin.components.afterListTable',\n ),\n )\n }\n }\n\n let description = undefined\n\n if (collection.admin?.description) {\n if (\n typeof collection.admin?.description === 'string' ||\n typeof collection.admin?.description === 'object'\n ) {\n description = collection.admin.description\n } else if (typeof collection.admin?.description === 'function') {\n description = collection.admin?.description({ t: i18n.t })\n }\n }\n\n clientCollection.admin.description = description\n\n if (collection.admin.components?.Description) {\n clientCollection.admin.components.Description = createMappedComponent(\n collection.admin.components.Description,\n {\n clientProps: {\n description,\n },\n },\n undefined,\n 'collection.admin.components.Description',\n )\n }\n\n clientCollection.admin.components.views = (\n collection?.admin?.components?.views\n ? deepCopyObjectSimple(collection?.admin?.components?.views)\n : {}\n ) as ClientCollectionConfig['admin']['components']['views']\n\n const hasEditView =\n 'admin' in collection &&\n 'components' in collection.admin &&\n 'views' in collection.admin.components &&\n 'edit' in collection.admin.components.views &&\n 'default' in collection.admin.components.views.edit\n\n if (!clientCollection.admin.components.views.edit) {\n clientCollection.admin.components.views.edit =\n {} as ClientCollectionConfig['admin']['components']['views']['edit']\n }\n\n clientCollection.admin.components.views.edit.default = {\n Component: createMappedComponent(\n hasEditView &&\n 'Component' in collection.admin.components.views.edit.default &&\n collection.admin.components.views.edit.default.Component\n ? collection.admin.components.views.edit.default.Component\n : null,\n {\n clientProps: {\n collectionSlug: collection.slug,\n },\n },\n DefaultEditView,\n 'collection.admin.components.views.edit.default',\n ),\n }\n\n if (collection?.admin?.components?.views?.edit) {\n for (const key in collection.admin.components.views.edit) {\n const view: EditViewConfig = collection.admin.components.views.edit[key]\n\n if (!clientCollection.admin.components.views.edit[key]) {\n clientCollection.admin.components.views.edit[key] = {} as MappedView\n }\n\n if ('Component' in view && key !== 'default') {\n clientCollection.admin.components.views.edit[key].Component = createMappedComponent(\n view.Component,\n {\n clientProps: {\n collectionSlug: collection.slug,\n },\n },\n undefined,\n 'collection.admin.components.views.edit.key.Component',\n )\n }\n\n if ('actions' in view && view.actions?.length) {\n clientCollection.admin.components.views.edit[key].actions = view.actions.map((Component) =>\n createMappedComponent(\n Component,\n undefined,\n undefined,\n 'collection.admin.components.views.key.admin',\n ),\n )\n }\n }\n }\n\n const hasListView =\n 'admin' in collection &&\n 'components' in collection.admin &&\n 'views' in collection.admin.components &&\n 'list' in collection.admin.components.views\n\n if (!clientCollection.admin.components.views.list) {\n clientCollection.admin.components.views.list =\n {} as ClientCollectionConfig['admin']['components']['views']['list']\n }\n\n clientCollection.admin.components.views.list.Component = createMappedComponent(\n hasListView &&\n 'Component' in collection.admin.components.views.list &&\n collection.admin.components.views.list.Component\n ? collection.admin.components.views.list.Component\n : null,\n {\n clientProps: {\n collectionSlug: collection.slug,\n },\n },\n DefaultListView,\n 'collection.admin.components.views.list',\n )\n\n if (\n hasListView &&\n 'actions' in collection.admin.components.views.list &&\n collection.admin.components.views.list.actions\n ) {\n clientCollection.admin.components.views.list.actions =\n collection.admin.components.views.list.actions.map((Component) =>\n createMappedComponent(\n Component,\n undefined,\n undefined,\n 'collection.admin.components.views.list',\n ),\n )\n }\n\n if (\n 'livePreview' in clientCollection.admin &&\n clientCollection.admin.livePreview &&\n 'url' in clientCollection.admin.livePreview\n ) {\n delete clientCollection.admin.livePreview.url\n }\n\n return clientCollection\n}\n\nexport const createClientCollectionConfigs = ({\n DefaultEditView,\n DefaultListView,\n clientCollections,\n collections,\n createMappedComponent,\n i18n,\n importMap,\n payload,\n}: {\n DefaultEditView: React.FC<EditViewProps>\n DefaultListView: React.FC<AdminViewProps>\n clientCollections: ClientCollectionConfig[]\n collections: SanitizedCollectionConfig[]\n createMappedComponent: CreateMappedComponent\n i18n: I18nClient\n importMap: ImportMap\n payload: Payload\n}): ClientCollectionConfig[] => {\n for (let i = 0; i < collections.length; i++) {\n const collection = collections[i]\n const clientCollection = clientCollections[i]\n clientCollections[i] = createClientCollectionConfig({\n DefaultEditView,\n DefaultListView,\n clientCollection,\n collection,\n createMappedComponent,\n i18n,\n importMap,\n payload,\n })\n }\n\n return clientCollections\n}\n"],"mappings":"AAiBA,SAASA,oBAAoB,QAAQ;AAErC,SAASC,kBAAkB,QAAQ;AAEnC,MAAMC,8BAAA,GAA4E,CAChF,SACA,UACA,aACA,SAID;AAED,MAAMC,0BAAA,GAAoE,CACxE,kBACA,4BACA,YACA,yBACA,eACD;AAED,MAAMC,mCAAA,GAAsF,CAC1F,UACA,UAED;AAED,OAAO,MAAMC,4BAAA,GAA+BA,CAAC;EAC3CC,eAAe;EACfC,eAAe;EACfC,gBAAgB;EAChBC,UAAU;EACVC,qBAAqB;EACrBC,IAAI;EACJC,SAAS;EACTC;AAAO,CAUR;EACCL,gBAAA,CAAiBM,MAAM,GAAGb,kBAAA,CAAmB;IAC3Cc,YAAA,EAAcP,gBAAA,CAAiBM,MAAM;IACrCJ,qBAAA;IACAI,MAAA,EAAQL,UAAA,CAAWK,MAAM;IACzB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CAAiB2B,KAAK,CAAC4B,WAAW,CAACC,GAAG;EAC/C;EAEA,OAAOxD,gBAAA;AACT;AAEA,OAAO,MAAMyD,6BAAA,GAAgCA,CAAC;EAC5C3D,eAAe;EACfC,eAAe;EACf2D,iBAAiB;EACjBC,WAAW;EACXzD,qBAAqB;EACrBC,IAAI;EACJC,SAAS;EACTC;AAAO,CAUR;EACC,KAAK,IAAIuD,CAAA,GAAI,GAAGA,CAAA,GAAID,WAAA,CAAY/C,MAAM,EAAEgD,CAAA,IAAK;IAC3C,MAAM3D,UAAA,GAAa0D,WAAW,CAACC,CAAA,CAAE;IACjC,MAAM5D,gBAAA,GAAmB0D,iBAAiB,CAACE,CAAA,CAAE;IAC7CF,iBAAiB,CAACE,CAAA,CAAE,GAAG/D,4BAAA,CAA6B;MAClDC,eAAA;MACAC,eAAA;MACAC,gBAAA;MACAC,UAAA;MACAC,qBAAA;MACAC,IAAA;MACAC,SAAA;MACAC;IACF;EACF;EAEA,OAAOqD,iBAAA;AACT","ignoreList":[]}
@@ -118,7 +118,5 @@ export const PreferencesProvider = ({
118
118
  children: children
119
119
  });
120
120
  };
121
- export const usePreferences = () => {
122
- return useContext(Context);
123
- };
121
+ export const usePreferences = () => useContext(Context);
124
122
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["dequal","React","createContext","useCallback","useContext","useEffect","useRef","useTranslation","requests","useAuth","useConfig","Context","requestOptions","value","language","body","JSON","stringify","headers","PreferencesProvider","children","contextRef","preferencesRef","pendingUpdate","config","user","i18n","routes","api","serverURL","current","getPreference","key","prefs","promise","Promise","resolve","request","get","status","preference","json","setPreference","merge","post","newValue","currentPreference","updatePreference","setTimeout","_jsx","Provider","usePreferences"],"sources":["../../../src/providers/Preferences/index.tsx"],"sourcesContent":["'use client'\nimport { dequal } from 'dequal/lite' // lite: no need for Map and Set support\nimport React, { createContext, useCallback, useContext, useEffect, useRef } from 'react'\n\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { requests } from '../../utilities/api.js'\nimport { useAuth } from '../Auth/index.js'\nimport { useConfig } from '../Config/index.js'\n\ntype PreferencesContext = {\n getPreference: <T = any>(key: string) => Promise<T>\n /**\n * @param key - a string identifier for the property being set\n * @param value - preference data to store\n * @param merge - when true will combine the existing preference object batch the change into one request for objects, default = false\n */\n setPreference: <T = any>(key: string, value: T, merge?: boolean) => Promise<void>\n}\n\nconst Context = createContext({} as PreferencesContext)\n\nconst requestOptions = (value, language) => ({\n body: JSON.stringify({ value }),\n headers: {\n 'Accept-Language': language,\n 'Content-Type': 'application/json',\n },\n})\n\nexport const PreferencesProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) => {\n const contextRef = useRef({} as PreferencesContext)\n const preferencesRef = useRef({})\n const pendingUpdate = useRef({})\n const { config } = useConfig()\n const { user } = useAuth()\n const { i18n } = useTranslation()\n\n const {\n routes: { api },\n serverURL,\n } = config\n\n useEffect(() => {\n if (!user) {\n // clear preferences between users\n preferencesRef.current = {}\n }\n }, [user])\n\n const getPreference = useCallback(\n async <T = any,>(key: string): Promise<T> => {\n const prefs = preferencesRef.current\n if (typeof prefs[key] !== 'undefined') return prefs[key]\n const promise = new Promise((resolve: (value: T) => void) => {\n void (async () => {\n const request = await requests.get(`${serverURL}${api}/payload-preferences/${key}`, {\n headers: {\n 'Accept-Language': i18n.language,\n },\n })\n let value = null\n if (request.status === 200) {\n const preference = await request.json()\n value = preference.value\n }\n preferencesRef.current[key] = value\n resolve(value)\n })()\n })\n prefs[key] = promise\n return promise\n },\n [i18n.language, api, preferencesRef, serverURL],\n )\n\n const setPreference = useCallback(\n async (key: string, value: unknown, merge = false): Promise<void> => {\n if (merge === false) {\n preferencesRef.current[key] = value\n\n await requests.post(\n `${serverURL}${api}/payload-preferences/${key}`,\n requestOptions(value, i18n.language),\n )\n\n return\n }\n\n let newValue = value\n const currentPreference = await getPreference(key)\n // handle value objects where multiple values can be set under one key\n if (\n typeof value === 'object' &&\n typeof currentPreference === 'object' &&\n typeof newValue === 'object'\n ) {\n // merge the value with any existing preference for the key\n newValue = { ...(currentPreference || {}), ...value }\n\n if (dequal(newValue, currentPreference)) {\n return\n }\n\n // add the requested changes to a pendingUpdate batch for the key\n pendingUpdate.current[key] = {\n ...pendingUpdate.current[key],\n ...(newValue as Record<string, unknown>),\n }\n } else {\n if (newValue === currentPreference) {\n return\n }\n pendingUpdate.current[key] = newValue\n }\n\n const updatePreference = async () => {\n // compare the value stored in context before sending to eliminate duplicate requests\n if (dequal(pendingUpdate.current[key], preferencesRef.current[key])) {\n return\n }\n\n // preference set in context here to prevent other updatePreference at the same time\n preferencesRef.current[key] = pendingUpdate.current[key]\n\n await requests.post(\n `${serverURL}${api}/payload-preferences/${key}`,\n requestOptions(preferencesRef.current[key], i18n.language),\n )\n\n // reset any changes for this key after sending the request\n delete pendingUpdate.current[key]\n }\n\n // use timeout to allow multiple changes of different values using the same key in one request\n setTimeout(() => {\n void updatePreference()\n })\n },\n [api, getPreference, i18n.language, pendingUpdate, serverURL],\n )\n\n contextRef.current.getPreference = getPreference\n contextRef.current.setPreference = setPreference\n\n return <Context.Provider value={contextRef.current}>{children}</Context.Provider>\n}\n\nexport const usePreferences = (): PreferencesContext => useContext(Context)\n"],"mappings":"AAAA;;;AACA,SAASA,MAAM,QAAQ,cAAa,CAAC;AACrC,OAAOC,KAAA,IAASC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,QAAQ;AAEjF,SAASC,cAAc,QAAQ;AAC/B,SAASC,QAAQ,QAAQ;AACzB,SAASC,OAAO,QAAQ;AACxB,SAASC,SAAS,QAAQ;AAY1B,MAAMC,OAAA,gBAAUT,aAAA,CAAc,CAAC;AAE/B,MAAMU,cAAA,GAAiBA,CAACC,KAAA,EAAOC,QAAA,MAAc;EAC3CC,IAAA,EAAMC,IAAA,CAAKC,SAAS,CAAC;IAAEJ;EAAM;EAC7BK,OAAA,EAAS;IACP,mBAAmBJ,QAAA;IACnB,g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E,KAAA,CAAI,EAAEV,cAAA,CAAeQ,OAAO,CAACE,KAAA,CAAI,GAAG;QACnE;MACF;MAEA;MACAV,cAAA,CAAeQ,OAAO,CAACE,KAAA,CAAI,GAAGT,aAAA,CAAcO,OAAO,CAACE,KAAA,CAAI;MAExD,MAAMxB,QAAA,CAASoC,IAAI,CACjB,GAAGf,SAAA,GAAYD,GAAA,wBAA2BI,KAAA,EAAK,EAC/CpB,cAAA,CAAeU,cAAA,CAAeQ,OAAO,CAACE,KAAA,CAAI,EAAEN,IAAA,CAAKZ,QAAQ;MAG3D;MACA,OAAOS,aAAA,CAAcO,OAAO,CAACE,KAAA,CAAI;IACnC;IAEA;IACAgB,UAAA,CAAW;MACT,KAAKD,gBAAA;IACP;EACF,GACA,CAACnB,GAAA,EAAKG,aAAA,EAAeL,IAAA,CAAKZ,QAAQ,EAAES,aAAA,EAAeM,SAAA,CAAU;EAG/DR,UAAA,CAAWS,OAAO,CAACC,aAAa,GAAGA,aAAA;EACnCV,UAAA,CAAWS,OAAO,CAACY,aAAa,GAAGA,aAAA;EAEnC,oBAAOO,IAAA,CAACtC,OAAA,CAAQuC,QAAQ;IAACrC,KAAA,EAAOQ,UAAA,CAAWS,OAAO;cAAGV;;AACvD;AAEA,OAAO,MAAM+B,cAAA,GAAiBA,CAAA;EAAA,OAA0B/C,UAAA,CAAAO,OAAW;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["dequal","React","createContext","useCallback","useContext","useEffect","useRef","useTranslation","requests","useAuth","useConfig","Context","requestOptions","value","language","body","JSON","stringify","headers","PreferencesProvider","children","contextRef","preferencesRef","pendingUpdate","config","user","i18n","routes","api","serverURL","current","getPreference","key","prefs","promise","Promise","resolve","request","get","status","preference","json","setPreference","merge","post","newValue","currentPreference","updatePreference","setTimeout","_jsx","Provider","usePreferences"],"sources":["../../../src/providers/Preferences/index.tsx"],"sourcesContent":["'use client'\nimport { dequal } from 'dequal/lite' // lite: no need for Map and Set support\nimport React, { createContext, useCallback, useContext, useEffect, useRef } from 'react'\n\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { requests } from '../../utilities/api.js'\nimport { useAuth } from '../Auth/index.js'\nimport { useConfig } from '../Config/index.js'\n\ntype PreferencesContext = {\n getPreference: <T = any>(key: string) => Promise<T>\n /**\n * @param key - a string identifier for the property being set\n * @param value - preference data to store\n * @param merge - when true will combine the existing preference object batch the change into one request for objects, default = false\n */\n setPreference: <T = any>(key: string, value: T, merge?: boolean) => Promise<void>\n}\n\nconst Context = createContext({} as PreferencesContext)\n\nconst requestOptions = (value, language) => ({\n body: JSON.stringify({ value }),\n headers: {\n 'Accept-Language': language,\n 'Content-Type': 'application/json',\n },\n})\n\nexport const PreferencesProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) => {\n const contextRef = useRef({} as PreferencesContext)\n const preferencesRef = useRef({})\n const pendingUpdate = useRef({})\n const { config } = useConfig()\n const { user } = useAuth()\n const { i18n } = useTranslation()\n\n const {\n routes: { api },\n serverURL,\n } = config\n\n useEffect(() => {\n if (!user) {\n // clear preferences between users\n preferencesRef.current = {}\n }\n }, [user])\n\n const getPreference = useCallback(\n async <T = any,>(key: string): Promise<T> => {\n const prefs = preferencesRef.current\n if (typeof prefs[key] !== 'undefined') return prefs[key]\n const promise = new Promise((resolve: (value: T) => void) => {\n void (async () => {\n const request = await requests.get(`${serverURL}${api}/payload-preferences/${key}`, {\n headers: {\n 'Accept-Language': i18n.language,\n },\n })\n let value = null\n if (request.status === 200) {\n const preference = await request.json()\n value = preference.value\n }\n preferencesRef.current[key] = value\n resolve(value)\n })()\n })\n prefs[key] = promise\n return promise\n },\n [i18n.language, api, preferencesRef, serverURL],\n )\n\n const setPreference = useCallback(\n async (key: string, value: unknown, merge = false): Promise<void> => {\n if (merge === false) {\n preferencesRef.current[key] = value\n\n await requests.post(\n `${serverURL}${api}/payload-preferences/${key}`,\n requestOptions(value, i18n.language),\n )\n\n return\n }\n\n let newValue = value\n const currentPreference = await getPreference(key)\n // handle value objects where multiple values can be set under one key\n if (\n typeof value === 'object' &&\n typeof currentPreference === 'object' &&\n typeof newValue === 'object'\n ) {\n // merge the value with any existing preference for the key\n newValue = { ...(currentPreference || {}), ...value }\n\n if (dequal(newValue, currentPreference)) {\n return\n }\n\n // add the requested changes to a pendingUpdate batch for the key\n pendingUpdate.current[key] = {\n ...pendingUpdate.current[key],\n ...(newValue as Record<string, unknown>),\n }\n } else {\n if (newValue === currentPreference) {\n return\n }\n pendingUpdate.current[key] = newValue\n }\n\n const updatePreference = async () => {\n // compare the value stored in context before sending to eliminate duplicate requests\n if (dequal(pendingUpdate.current[key], preferencesRef.current[key])) {\n return\n }\n\n // preference set in context here to prevent other updatePreference at the same time\n preferencesRef.current[key] = pendingUpdate.current[key]\n\n await requests.post(\n `${serverURL}${api}/payload-preferences/${key}`,\n requestOptions(preferencesRef.current[key], i18n.language),\n )\n\n // reset any changes for this key after sending the request\n delete pendingUpdate.current[key]\n }\n\n // use timeout to allow multiple changes of different values using the same key in one request\n setTimeout(() => {\n void updatePreference()\n })\n },\n [api, getPreference, i18n.language, pendingUpdate, serverURL],\n )\n\n contextRef.current.getPreference = getPreference\n contextRef.current.setPreference = setPreference\n\n return <Context.Provider value={contextRef.current}>{children}</Context.Provider>\n}\n\nexport const usePreferences = (): PreferencesContext => useContext(Context)\n"],"mappings":"AAAA;;;AACA,SAASA,MAAM,QAAQ,cAAa,CAAC;AACrC,OAAOC,KAAA,IAASC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,QAAQ;AAEjF,SAASC,cAAc,QAAQ;AAC/B,SAASC,QAAQ,QAAQ;AACzB,SAASC,OAAO,QAAQ;AACxB,SAASC,SAAS,QAAQ;AAY1B,MAAMC,OAAA,gBAAUT,aAAA,CAAc,CAAC;AAE/B,MAAMU,cAAA,GAAiBA,CAACC,KAAA,EAAOC,QAAA,MAAc;EAC3CC,IAAA,EAAMC,IAAA,CAAKC,SAAS,CAAC;IAAEJ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;MACvB;MACA,IAAI/C,MAAA,CAAOuB,aAAA,CAAcO,OAAO,CAACE,KAAA,CAAI,EAAEV,cAAA,CAAeQ,OAAO,CAACE,KAAA,CAAI,GAAG;QACnE;MACF;MAEA;MACAV,cAAA,CAAeQ,OAAO,CAACE,KAAA,CAAI,GAAGT,aAAA,CAAcO,OAAO,CAACE,KAAA,CAAI;MAExD,MAAMxB,QAAA,CAASoC,IAAI,CACjB,GAAGf,SAAA,GAAYD,GAAA,wBAA2BI,KAAA,EAAK,EAC/CpB,cAAA,CAAeU,cAAA,CAAeQ,OAAO,CAACE,KAAA,CAAI,EAAEN,IAAA,CAAKZ,QAAQ;MAG3D;MACA,OAAOS,aAAA,CAAcO,OAAO,CAACE,KAAA,CAAI;IACnC;IAEA;IACAgB,UAAA,CAAW;MACT,KAAKD,gBAAA;IACP;EACF,GACA,CAACnB,GAAA,EAAKG,aAAA,EAAeL,IAAA,CAAKZ,QAAQ,EAAES,aAAA,EAAeM,SAAA,CAAU;EAG/DR,UAAA,CAAWS,OAAO,CAACC,aAAa,GAAGA,aAAA;EACnCV,UAAA,CAAWS,OAAO,CAACY,aAAa,GAAGA,aAAA;EAEnC,oBAAOO,IAAA,CAACtC,OAAA,CAAQuC,QAAQ;IAACrC,KAAA,EAAOQ,UAAA,CAAWS,OAAO;cAAGV;;AACvD;AAEA,OAAO,MAAM+B,cAAA,GAAiBA,CAAA,KAA0B/C,UAAA,CAAWO,OAAA","ignoreList":[]}
@@ -1,6 +1,5 @@
1
1
  'use client';
2
2
 
3
- import { c as _c } from "react/compiler-runtime";
4
3
  import { jsx as _jsx } from "react/jsx-runtime";
5
4
  import * as qs from 'qs-esm';
6
5
  import React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';
@@ -14,202 +13,117 @@ export var SelectAllStatus;
14
13
  SelectAllStatus["Some"] = "some";
15
14
  })(SelectAllStatus || (SelectAllStatus = {}));
16
15
  const Context = /*#__PURE__*/createContext({});
17
- export const SelectionProvider = t0 => {
18
- const $ = _c(23);
19
- const {
20
- children,
21
- docs: t1,
22
- totalDocs
23
- } = t0;
24
- let t2;
25
- if ($[0] !== t1) {
26
- t2 = t1 === undefined ? [] : t1;
27
- $[0] = t1;
28
- $[1] = t2;
29
- } else {
30
- t2 = $[1];
31
- }
32
- const docs = t2;
16
+ export const SelectionProvider = ({
17
+ children,
18
+ docs = [],
19
+ totalDocs
20
+ }) => {
33
21
  const contextRef = useRef({});
34
22
  const {
35
23
  code: locale
36
24
  } = useLocale();
37
- let t3;
38
- if ($[2] !== docs) {
39
- t3 = () => {
40
- const rows = {};
41
- docs.forEach(t4 => {
42
- const {
43
- id
44
- } = t4;
45
- rows[id] = false;
46
- });
47
- return rows;
48
- };
49
- $[2] = docs;
50
- $[3] = t3;
51
- } else {
52
- t3 = $[3];
53
- }
54
- const [selected, setSelected] = useState(t3);
25
+ const [selected, setSelected] = useState(() => {
26
+ const rows = {};
27
+ docs.forEach(({
28
+ id
29
+ }) => {
30
+ rows[id] = false;
31
+ });
32
+ return rows;
33
+ });
55
34
  const [selectAll, setSelectAll] = useState("none");
56
35
  const [count, setCount] = useState(0);
57
36
  const {
58
37
  searchParams
59
38
  } = useSearchParams();
60
- let t4;
61
- if ($[4] !== docs || $[5] !== selectAll) {
62
- t4 = t5 => {
63
- const allAvailable = t5 === undefined ? false : t5;
64
- const rows_0 = {};
65
- if (allAvailable) {
66
- setSelectAll("allAvailable");
67
- docs.forEach(t6 => {
68
- const {
69
- id: id_0
70
- } = t6;
71
- rows_0[id_0] = true;
72
- });
73
- } else {
74
- if (selectAll === "allAvailable" || selectAll === "allInPage") {
75
- setSelectAll("none");
76
- docs.forEach(t7 => {
77
- const {
78
- id: id_1
79
- } = t7;
80
- rows_0[id_1] = false;
81
- });
82
- } else {
83
- docs.forEach(t8 => {
84
- const {
85
- id: id_2
86
- } = t8;
87
- rows_0[id_2] = selectAll !== "some";
88
- });
89
- }
90
- }
91
- setSelected(rows_0);
92
- };
93
- $[4] = docs;
94
- $[5] = selectAll;
95
- $[6] = t4;
96
- } else {
97
- t4 = $[6];
98
- }
99
- const toggleAll = t4;
100
- let t5;
101
- if ($[7] !== selected) {
102
- t5 = id_3 => {
103
- const isSelected = !selected[id_3];
104
- const newSelected = {
105
- ...selected,
106
- [id_3]: isSelected
107
- };
108
- if (!isSelected) {
109
- setSelectAll("some");
110
- }
111
- setSelected(newSelected);
112
- };
113
- $[7] = selected;
114
- $[8] = t5;
115
- } else {
116
- t5 = $[8];
117
- }
118
- const setSelection = t5;
119
- let t6;
120
- if ($[9] !== selectAll || $[10] !== searchParams || $[11] !== selected || $[12] !== locale) {
121
- t6 = additionalParams => {
122
- let where;
123
- if (selectAll === "allAvailable") {
124
- const params = searchParams?.where;
125
- where = params || {
126
- id: {
127
- not_equals: ""
128
- }
129
- };
130
- } else {
131
- where = {
132
- id: {
133
- in: Object.keys(selected).filter(id_4 => selected[id_4]).map(id_5 => id_5)
134
- }
135
- };
136
- }
137
- if (additionalParams) {
138
- where = {
139
- and: [{
140
- ...additionalParams
141
- }, where]
142
- };
143
- }
144
- return qs.stringify({
145
- locale,
146
- where
147
- }, {
148
- addQueryPrefix: true
39
+ const toggleAll = useCallback((allAvailable = false) => {
40
+ const rows_0 = {};
41
+ if (allAvailable) {
42
+ setSelectAll("allAvailable");
43
+ docs.forEach(({
44
+ id: id_0
45
+ }) => {
46
+ rows_0[id_0] = true;
149
47
  });
150
- };
151
- $[9] = selectAll;
152
- $[10] = searchParams;
153
- $[11] = selected;
154
- $[12] = locale;
155
- $[13] = t6;
156
- } else {
157
- t6 = $[13];
158
- }
159
- const getQueryParams = t6;
160
- let t7;
161
- let t8;
162
- if ($[14] !== selectAll || $[15] !== selected) {
163
- t7 = () => {
164
- if (selectAll === "allAvailable") {
165
- return;
166
- }
167
- let some;
168
- some = false;
169
- let all;
170
- all = true;
171
- Object.values(selected).forEach(val => {
172
- all = all && val;
173
- some = some || val;
48
+ } else if (selectAll === "allAvailable" || selectAll === "allInPage") {
49
+ setSelectAll("none");
50
+ docs.forEach(({
51
+ id: id_1
52
+ }) => {
53
+ rows_0[id_1] = false;
174
54
  });
175
- if (all) {
176
- setSelectAll("allInPage");
177
- } else {
178
- if (some) {
179
- setSelectAll("some");
180
- } else {
181
- setSelectAll("none");
182
- }
183
- }
184
- };
185
- t8 = [selectAll, selected];
186
- $[14] = selectAll;
187
- $[15] = selected;
188
- $[16] = t7;
189
- $[17] = t8;
190
- } else {
191
- t7 = $[16];
192
- t8 = $[17];
193
- }
194
- useEffect(t7, t8);
195
- let t9;
196
- let t10;
197
- if ($[18] !== selectAll || $[19] !== totalDocs || $[20] !== selected) {
198
- t9 = () => {
199
- const newCount = selectAll === "allAvailable" ? totalDocs : Object.keys(selected).filter(id_6 => selected[id_6]).length;
200
- setCount(newCount);
55
+ } else {
56
+ docs.forEach(({
57
+ id: id_2
58
+ }) => {
59
+ rows_0[id_2] = selectAll !== "some";
60
+ });
61
+ }
62
+ setSelected(rows_0);
63
+ }, [docs, selectAll]);
64
+ const setSelection = useCallback(id_3 => {
65
+ const isSelected = !selected[id_3];
66
+ const newSelected = {
67
+ ...selected,
68
+ [id_3]: isSelected
201
69
  };
202
- t10 = [selectAll, selected, totalDocs];
203
- $[18] = selectAll;
204
- $[19] = totalDocs;
205
- $[20] = selected;
206
- $[21] = t9;
207
- $[22] = t10;
208
- } else {
209
- t9 = $[21];
210
- t10 = $[22];
211
- }
212
- useEffect(t9, t10);
70
+ if (!isSelected) {
71
+ setSelectAll("some");
72
+ }
73
+ setSelected(newSelected);
74
+ }, [selected]);
75
+ const getQueryParams = useCallback(additionalParams => {
76
+ let where;
77
+ if (selectAll === "allAvailable") {
78
+ const params = searchParams?.where;
79
+ where = params || {
80
+ id: {
81
+ not_equals: ''
82
+ }
83
+ };
84
+ } else {
85
+ where = {
86
+ id: {
87
+ in: Object.keys(selected).filter(id_4 => selected[id_4]).map(id_5 => id_5)
88
+ }
89
+ };
90
+ }
91
+ if (additionalParams) {
92
+ where = {
93
+ and: [{
94
+ ...additionalParams
95
+ }, where]
96
+ };
97
+ }
98
+ return qs.stringify({
99
+ locale,
100
+ where
101
+ }, {
102
+ addQueryPrefix: true
103
+ });
104
+ }, [selectAll, selected, locale, searchParams]);
105
+ useEffect(() => {
106
+ if (selectAll === "allAvailable") {
107
+ return;
108
+ }
109
+ let some = false;
110
+ let all = true;
111
+ Object.values(selected).forEach(val => {
112
+ all = all && val;
113
+ some = some || val;
114
+ });
115
+ if (all) {
116
+ setSelectAll("allInPage");
117
+ } else if (some) {
118
+ setSelectAll("some");
119
+ } else {
120
+ setSelectAll("none");
121
+ }
122
+ }, [selectAll, selected]);
123
+ useEffect(() => {
124
+ const newCount = selectAll === "allAvailable" ? totalDocs : Object.keys(selected).filter(id_6 => selected[id_6]).length;
125
+ setCount(newCount);
126
+ }, [selectAll, selected, totalDocs]);
213
127
  contextRef.current = {
214
128
  count,
215
129
  getQueryParams,
@@ -219,12 +133,10 @@ export const SelectionProvider = t0 => {
219
133
  toggleAll,
220
134
  totalDocs
221
135
  };
222
- return _jsx(Context.Provider, {
136
+ return /*#__PURE__*/_jsx(Context.Provider, {
223
137
  value: contextRef.current,
224
- children
138
+ children: children
225
139
  });
226
140
  };
227
- export const useSelection = () => {
228
- return useContext(Context);
229
- };
141
+ export const useSelection = () => useContext(Context);
230
142
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","qs","React","createContext","useCallback","useContext","useEffect","useRef","useState","useLocale","useSearchParams","SelectAllStatus","Context","SelectionProvider","t0","$","children","docs","t1","totalDocs","t2","undefined","contextRef","code","locale","t3","rows","forEach","t4","id","selected","setSelected","selectAll","setSelectAll","count","setCount","searchParams","t5","allAvailable","rows_0","t6","id_0","t7","id_1","t8","id_2","toggleAll","id_3","isSelected","newSelected","setSelection","additionalParams","where","params","not_equals","filter","id_4","map","id_5","stringify","addQueryPrefix","getQueryParams","some","all","Object","values","val","t9","t10","newCount","keys","id_6","length","current","_jsx","Provider","value","useSelection"],"sources":["../../../src/providers/Selection/index.tsx"],"sourcesContent":["'use client'\nimport type { Where } from 'payload'\n\nimport * as qs from 'qs-esm'\nimport React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react'\n\nimport { useLocale } from '../Locale/index.js'\nimport { useSearchParams } from '../SearchParams/index.js'\n\nexport enum SelectAllStatus {\n AllAvailable = 'allAvailable',\n AllInPage = 'allInPage',\n None = 'none',\n Some = 'some',\n}\n\ntype SelectionContext = {\n count: number\n disableBulkDelete?: boolean\n disableBulkEdit?: boolean\n getQueryParams: (additionalParams?: Where) => string\n selectAll: SelectAllStatus\n selected: Record<number | string, boolean>\n setSelection: (id: number | string) => void\n toggleAll: (allAvailable?: boolean) => void\n totalDocs: number\n}\n\nconst Context = createContext({} as SelectionContext)\n\ntype Props = {\n readonly children: React.ReactNode\n readonly docs: any[]\n readonly totalDocs: number\n}\n\nexport const SelectionProvider: React.FC<Props> = ({ children, docs = [], totalDocs }) => {\n const contextRef = useRef({} as SelectionContext)\n\n const { code: locale } = useLocale()\n const [selected, setSelected] = useState<SelectionContext['selected']>(() => {\n const rows = {}\n docs.forEach(({ id }) => {\n rows[id] = false\n })\n return rows\n })\n const [selectAll, setSelectAll] = useState<SelectAllStatus>(SelectAllStatus.None)\n const [count, setCount] = useState(0)\n const { searchParams } = useSearchParams()\n\n const toggleAll = useCallback(\n (allAvailable = false) => {\n const rows = {}\n if (allAvailable) {\n setSelectAll(SelectAllStatus.AllAvailable)\n docs.forEach(({ id }) => {\n rows[id] = true\n })\n } else if (\n selectAll === SelectAllStatus.AllAvailable ||\n selectAll === SelectAllStatus.AllInPage\n ) {\n setSelectAll(SelectAllStatus.None)\n docs.forEach(({ id }) => {\n rows[id] = false\n })\n } else {\n docs.forEach(({ id }) => {\n rows[id] = selectAll !== SelectAllStatus.Some\n })\n }\n setSelected(rows)\n },\n [docs, selectAll],\n )\n\n const setSelection = useCallback(\n (id) => {\n const isSelected = !selected[id]\n const newSelected = {\n ...selected,\n [id]: isSelected,\n }\n if (!isSelected) {\n setSelectAll(SelectAllStatus.Some)\n }\n setSelected(newSelected)\n },\n [selected],\n )\n\n const getQueryParams = useCallback(\n (additionalParams?: Where): string => {\n let where: Where\n if (selectAll === SelectAllStatus.AllAvailable) {\n const params = searchParams?.where as Where\n where = params || {\n id: { not_equals: '' },\n }\n } else {\n where = {\n id: {\n in: Object.keys(selected)\n .filter((id) => selected[id])\n .map((id) => id),\n },\n }\n }\n if (additionalParams) {\n where = {\n and: [{ ...additionalParams }, where],\n }\n }\n return qs.stringify(\n {\n locale,\n where,\n },\n { addQueryPrefix: true },\n )\n },\n [selectAll, selected, locale, searchParams],\n )\n\n useEffect(() => {\n if (selectAll === SelectAllStatus.AllAvailable) {\n return\n }\n let some = false\n let all = true\n Object.values(selected).forEach((val) => {\n all = all && val\n some = some || val\n })\n\n if (all) {\n setSelectAll(SelectAllStatus.AllInPage)\n } else if (some) {\n setSelectAll(SelectAllStatus.Some)\n } else {\n setSelectAll(SelectAllStatus.None)\n }\n }, [selectAll, selected])\n\n useEffect(() => {\n const newCount =\n selectAll === SelectAllStatus.AllAvailable\n ? totalDocs\n : Object.keys(selected).filter((id) => selected[id]).length\n setCount(newCount)\n }, [selectAll, selected, totalDocs])\n\n contextRef.current = {\n count,\n getQueryParams,\n selectAll,\n selected,\n setSelection,\n toggleAll,\n totalDocs,\n }\n\n return <Context.Provider value={contextRef.current}>{children}</Context.Provider>\n}\n\nexport const useSelection = (): SelectionContext => useContext(Context)\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,YAAYC,EAAA,MAAQ;AACpB,OAAOC,KAAA,IAASC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAE3F,SAASC,SAAS,QAAQ;AAC1B,SAASC,eAAe,QAAQ;;WAEpBC,eAAA;;;;;GAAAA,eAAA,KAAAA,eAAA;AAmBZ,MAAMC,OAAA,g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AAmD,OAAA;IAAAzD;EAAA,C;CAClC;AAEA,OAAO,MAAM6D,YAAA,GAAeA,CAAA;EAAA,OAAwBxE,UAAA,CAAAO,OAAW;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["qs","React","createContext","useCallback","useContext","useEffect","useRef","useState","useLocale","useSearchParams","SelectAllStatus","Context","SelectionProvider","children","docs","totalDocs","contextRef","code","locale","selected","setSelected","rows","forEach","id","selectAll","setSelectAll","count","setCount","searchParams","toggleAll","allAvailable","setSelection","isSelected","newSelected","getQueryParams","additionalParams","where","params","not_equals","in","Object","keys","filter","map","and","stringify","addQueryPrefix","some","all","values","val","newCount","length","current","_jsx","Provider","value","useSelection"],"sources":["../../../src/providers/Selection/index.tsx"],"sourcesContent":["'use client'\nimport type { Where } from 'payload'\n\nimport * as qs from 'qs-esm'\nimport React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react'\n\nimport { useLocale } from '../Locale/index.js'\nimport { useSearchParams } from '../SearchParams/index.js'\n\nexport enum SelectAllStatus {\n AllAvailable = 'allAvailable',\n AllInPage = 'allInPage',\n None = 'none',\n Some = 'some',\n}\n\ntype SelectionContext = {\n count: number\n disableBulkDelete?: boolean\n disableBulkEdit?: boolean\n getQueryParams: (additionalParams?: Where) => string\n selectAll: SelectAllStatus\n selected: Record<number | string, boolean>\n setSelection: (id: number | string) => void\n toggleAll: (allAvailable?: boolean) => void\n totalDocs: number\n}\n\nconst Context = createContext({} as SelectionContext)\n\ntype Props = {\n readonly children: React.ReactNode\n readonly docs: any[]\n readonly totalDocs: number\n}\n\nexport const SelectionProvider: React.FC<Props> = ({ children, docs = [], totalDocs }) => {\n const contextRef = useRef({} as SelectionContext)\n\n const { code: locale } = useLocale()\n const [selected, setSelected] = useState<SelectionContext['selected']>(() => {\n const rows = {}\n docs.forEach(({ id }) => {\n rows[id] = false\n })\n return rows\n })\n const [selectAll, setSelectAll] = useState<SelectAllStatus>(SelectAllStatus.None)\n const [count, setCount] = useState(0)\n const { searchParams } = useSearchParams()\n\n const toggleAll = useCallback(\n (allAvailable = false) => {\n const rows = {}\n if (allAvailable) {\n setSelectAll(SelectAllStatus.AllAvailable)\n docs.forEach(({ id }) => {\n rows[id] = true\n })\n } else if (\n selectAll === SelectAllStatus.AllAvailable ||\n selectAll === SelectAllStatus.AllInPage\n ) {\n setSelectAll(SelectAllStatus.None)\n docs.forEach(({ id }) => {\n rows[id] = false\n })\n } else {\n docs.forEach(({ id }) => {\n rows[id] = selectAll !== SelectAllStatus.Some\n })\n }\n setSelected(rows)\n },\n [docs, selectAll],\n )\n\n const setSelection = useCallback(\n (id) => {\n const isSelected = !selected[id]\n const newSelected = {\n ...selected,\n [id]: isSelected,\n }\n if (!isSelected) {\n setSelectAll(SelectAllStatus.Some)\n }\n setSelected(newSelected)\n },\n [selected],\n )\n\n const getQueryParams = useCallback(\n (additionalParams?: Where): string => {\n let where: Where\n if (selectAll === SelectAllStatus.AllAvailable) {\n const params = searchParams?.where as Where\n where = params || {\n id: { not_equals: '' },\n }\n } else {\n where = {\n id: {\n in: Object.keys(selected)\n .filter((id) => selected[id])\n .map((id) => id),\n },\n }\n }\n if (additionalParams) {\n where = {\n and: [{ ...additionalParams }, where],\n }\n }\n return qs.stringify(\n {\n locale,\n where,\n },\n { addQueryPrefix: true },\n )\n },\n [selectAll, selected, locale, searchParams],\n )\n\n useEffect(() => {\n if (selectAll === SelectAllStatus.AllAvailable) {\n return\n }\n let some = false\n let all = true\n Object.values(selected).forEach((val) => {\n all = all && val\n some = some || val\n })\n\n if (all) {\n setSelectAll(SelectAllStatus.AllInPage)\n } else if (some) {\n setSelectAll(SelectAllStatus.Some)\n } else {\n setSelectAll(SelectAllStatus.None)\n }\n }, [selectAll, selected])\n\n useEffect(() => {\n const newCount =\n selectAll === SelectAllStatus.AllAvailable\n ? totalDocs\n : Object.keys(selected).filter((id) => selected[id]).length\n setCount(newCount)\n }, [selectAll, selected, totalDocs])\n\n contextRef.current = {\n count,\n getQueryParams,\n selectAll,\n selected,\n setSelection,\n toggleAll,\n totalDocs,\n }\n\n return <Context.Provider value={contextRef.current}>{children}</Context.Provider>\n}\n\nexport const useSelection = (): SelectionContext => useContext(Context)\n"],"mappings":"AAAA;;;AAGA,YAAYA,EAAA,MAAQ;AACpB,OAAOC,KAAA,IAASC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAE3F,SAASC,SAAS,QAAQ;AAC1B,SAASC,eAAe,QAAQ;;WAEpBC,eAAA;;;;;GAAAA,eAAA,KAAAA,eAAA;AAmBZ,MAAMC,OAAA,gBAAUT,aAAA,CAAc,CAAC;AAQ/B,OAAO,MAAMU,iBAAA,GAAqCA,CAAC;EAAEC,QAAQ;EAAEC,IAAA,GAAO,EAAE;EAAEC;AAAS,CAAE;EACnF,MAAMC,UAAA,GAAaV,MAAA,CAAO,CAAC;EAE3B,MAAM;IAAEW,IAAA,EAAMC;EAAM,CAAE,GAAGV,SAAA;EACzB,MAAM,CAACW,QAAA,EAAUC,WAAA,CAAY,GAAGb,QAAA,CAAuC;IACrE,MAAMc,IAAA,GAAO,CAAC;IACdP,IAAA,CAAKQ,OAAO,CAAC,CAAC;MAAEC;IAAE,CAAE;MAClBF,IAAI,CAACE,EAAA,CAAG,GAAG;IACb;IACA,OAAOF,IAAA;EACT;EACA,MAAM,CAACG,SAAA,EAAWC,YAAA,CAAa,GAAGlB,QAAA;EAClC,MAAM,CAACmB,KAAA,EAAOC,QAAA,CAAS,GAAGpB,QAAA,CAAS;EACnC,MAAM;IAAEqB;EAAY,CAAE,GAAGnB,eAAA;EAEzB,MAAMoB,SAAA,GAAY1B,WAAA,CAChB,CAAC2B,YAAA,GAAe,KAAK;IACnB,MAAMT,MAAA,GAAO,CAAC;IACd,IAAIS,YAAA,EAAc;MAChBL,YAAA;MACAX,IAAA,CAAKQ,OAAO,CAAC,CAAC;QAAEC,EAAE,EAAFA;MAAE,CAAE;QAClBF,MAAI,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
22
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
23
23
  sans-serif;
24
- --font-serif: Georgia, 'Bitstream Charter', 'Charis SIL', Utopia, 'URW Bookman L', serif;
25
- --font-mono: monospace;
24
+ --font-serif: 'Georgia', 'Bitstream Charter', 'Charis SIL', Utopia, 'URW Bookman L', serif;
25
+ --font-mono: 'SF Mono', Menlo, Consolas, Monaco, monospace;
26
26
 
27
27
  --style-radius-s: #{$style-radius-s};
28
28
  --style-radius-m: #{$style-radius-m};
@@ -45,8 +45,8 @@
45
45
 
46
46
  @include mid-break {
47
47
  --gutter-h: #{base(2)};
48
- --app-header-height: calc(var(--base) * 2.8);
49
- --doc-controls-height: calc(var(--base) * 2.5);
48
+ --app-header-height: calc(var(--base) * 2.4);
49
+ --doc-controls-height: calc(var(--base) * 2.4);
50
50
  }
51
51
 
52
52
  @include small-break {
@@ -146,13 +146,13 @@ h6 {
146
146
  }
147
147
 
148
148
  p {
149
- margin: 0 0 $baseline;
149
+ margin: 0;
150
150
  }
151
151
 
152
152
  ul,
153
153
  ol {
154
154
  padding-left: $baseline;
155
- margin: 0 0 $baseline;
155
+ margin: 0;
156
156
  }
157
157
 
158
158
  :focus-visible {
@@ -16,7 +16,7 @@
16
16
  }
17
17
 
18
18
  %h1 {
19
- margin: 0 0 base(1);
19
+ margin: 0;
20
20
  font-size: base(1.6);
21
21
  line-height: base(1.8);
22
22
 
@@ -27,7 +27,7 @@
27
27
  }
28
28
 
29
29
  %h2 {
30
- margin: 0 0 base(1);
30
+ margin: 0;
31
31
  font-size: base(1.3);
32
32
  line-height: base(1.6);
33
33
 
@@ -37,7 +37,7 @@
37
37
  }
38
38
 
39
39
  %h3 {
40
- margin: 0 0 base(1);
40
+ margin: 0;
41
41
  font-size: base(1);
42
42
  line-height: base(1.2);
43
43
 
@@ -48,7 +48,7 @@
48
48
  }
49
49
 
50
50
  %h4 {
51
- margin: 0 0 $baseline;
51
+ margin: 0;
52
52
  font-size: base(0.8);
53
53
  line-height: base(1);
54
54
  letter-spacing: -0.375px;