@panneau/fields 5.0.0-alpha.2 → 5.0.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +186 -20
- package/dist/address/AddressField.css +44 -0
- package/dist/address/AddressField.d.ts +37 -0
- package/dist/address/AddressField.d.ts.map +1 -0
- package/dist/address/AddressField.js +411 -0
- package/dist/address/AddressField.js.map +1 -0
- package/dist/address/AddressField.module.js +22 -0
- package/dist/address/AddressField.module.js.map +1 -0
- package/dist/address/address.d.ts +23 -0
- package/dist/address/address.d.ts.map +1 -0
- package/dist/address/address.js +58 -0
- package/dist/address/address.js.map +1 -0
- package/dist/address/index.d.ts +3 -0
- package/dist/address/index.d.ts.map +1 -0
- package/dist/address/index.js +3 -0
- package/dist/boolean/BooleanField.d.ts +1 -1
- package/dist/boolean/BooleanField.js +78 -17
- package/dist/boolean/BooleanField.js.map +1 -1
- package/dist/boolean/index.d.ts +1 -1
- package/dist/color/ColorField.css +9 -0
- package/dist/color/ColorField.d.ts +12 -5
- package/dist/color/ColorField.d.ts.map +1 -1
- package/dist/color/ColorField.js +341 -81
- package/dist/color/ColorField.js.map +1 -1
- package/dist/color/ColorField.module.js +4 -2
- package/dist/color/ColorField.module.js.map +1 -1
- package/dist/color/index.d.ts +2 -1
- package/dist/color/index.d.ts.map +1 -1
- package/dist/color/index.js +3 -1
- package/dist/color/palette.d.ts +23 -0
- package/dist/color/palette.d.ts.map +1 -0
- package/dist/color/palette.js +34 -0
- package/dist/color/palette.js.map +1 -0
- package/dist/compound/Compound.css +26 -0
- package/dist/compound/Compound.module.js +16 -0
- package/dist/compound/Compound.module.js.map +1 -0
- package/dist/compound/compound.d.ts +56 -0
- package/dist/compound/compound.d.ts.map +1 -0
- package/dist/compound/compound.js +186 -0
- package/dist/compound/compound.js.map +1 -0
- package/dist/country/CountryField.css +42 -0
- package/dist/country/CountryField.d.ts +32 -0
- package/dist/country/CountryField.d.ts.map +1 -0
- package/dist/country/CountryField.js +424 -0
- package/dist/country/CountryField.js.map +1 -0
- package/dist/country/CountryField.module.js +20 -0
- package/dist/country/CountryField.module.js.map +1 -0
- package/dist/country/codes.d.ts +6 -0
- package/dist/country/codes.d.ts.map +1 -0
- package/dist/country/codes.js +261 -0
- package/dist/country/codes.js.map +1 -0
- package/dist/country/countries.d.ts +32 -0
- package/dist/country/countries.d.ts.map +1 -0
- package/dist/country/countries.js +60 -0
- package/dist/country/countries.js.map +1 -0
- package/dist/country/index.d.ts +3 -0
- package/dist/country/index.d.ts.map +1 -0
- package/dist/country/index.js +4 -0
- package/dist/credits/CreditsField.d.ts +15 -0
- package/dist/credits/CreditsField.d.ts.map +1 -0
- package/dist/credits/CreditsField.js +58 -0
- package/dist/credits/CreditsField.js.map +1 -0
- package/dist/credits/credits.d.ts +18 -0
- package/dist/credits/credits.d.ts.map +1 -0
- package/dist/credits/credits.js +33 -0
- package/dist/credits/credits.js.map +1 -0
- package/dist/credits/index.d.ts +5 -0
- package/dist/credits/index.d.ts.map +1 -0
- package/dist/credits/index.js +3 -0
- package/dist/date/DateField.d.ts +1 -1
- package/dist/date/DateField.js.map +1 -1
- package/dist/date/index.d.ts +1 -1
- package/dist/daterange/DateRangeField.css +9 -0
- package/dist/daterange/DateRangeField.d.ts +31 -0
- package/dist/daterange/DateRangeField.d.ts.map +1 -0
- package/dist/daterange/DateRangeField.js +372 -0
- package/dist/daterange/DateRangeField.js.map +1 -0
- package/dist/daterange/DateRangeField.module.js +12 -0
- package/dist/daterange/DateRangeField.module.js.map +1 -0
- package/dist/daterange/index.d.ts +3 -0
- package/dist/daterange/index.d.ts.map +1 -0
- package/dist/daterange/index.js +3 -0
- package/dist/daterange/range.d.ts +61 -0
- package/dist/daterange/range.d.ts.map +1 -0
- package/dist/daterange/range.js +119 -0
- package/dist/daterange/range.js.map +1 -0
- package/dist/datetime/DateTimeField.d.ts +1 -1
- package/dist/datetime/DateTimeField.js +107 -20
- package/dist/datetime/DateTimeField.js.map +1 -1
- package/dist/datetime/index.d.ts +1 -1
- package/dist/duration/DurationField.css +11 -0
- package/dist/duration/DurationField.d.ts +67 -0
- package/dist/duration/DurationField.d.ts.map +1 -0
- package/dist/duration/DurationField.js +260 -0
- package/dist/duration/DurationField.js.map +1 -0
- package/dist/duration/DurationField.module.js +12 -0
- package/dist/duration/DurationField.module.js.map +1 -0
- package/dist/duration/index.d.ts +2 -0
- package/dist/duration/index.d.ts.map +1 -0
- package/dist/duration/index.js +1 -0
- package/dist/email/EmailField.d.ts +2 -2
- package/dist/email/EmailField.js.map +1 -1
- package/dist/email/index.d.ts +1 -1
- package/dist/embed/EmbedField.css +60 -0
- package/dist/embed/EmbedField.d.ts +29 -0
- package/dist/embed/EmbedField.d.ts.map +1 -0
- package/dist/embed/EmbedField.js +309 -0
- package/dist/embed/EmbedField.js.map +1 -0
- package/dist/embed/EmbedField.module.js +22 -0
- package/dist/embed/EmbedField.module.js.map +1 -0
- package/dist/embed/index.d.ts +3 -0
- package/dist/embed/index.d.ts.map +1 -0
- package/dist/embed/index.js +3 -0
- package/dist/file/FileField.css +54 -0
- package/dist/file/FileField.d.ts +50 -0
- package/dist/file/FileField.d.ts.map +1 -0
- package/dist/file/FileField.js +288 -0
- package/dist/file/FileField.js.map +1 -0
- package/dist/file/FileField.module.js +22 -0
- package/dist/file/FileField.module.js.map +1 -0
- package/dist/file/index.d.ts +3 -0
- package/dist/file/index.d.ts.map +1 -0
- package/dist/file/index.js +1 -0
- package/dist/group/GroupField.css +20 -3
- package/dist/group/GroupField.d.ts +10 -4
- package/dist/group/GroupField.d.ts.map +1 -1
- package/dist/group/GroupField.js +71 -66
- package/dist/group/GroupField.js.map +1 -1
- package/dist/group/GroupField.module.js +10 -2
- package/dist/group/GroupField.module.js.map +1 -1
- package/dist/group/index.d.ts +1 -1
- package/dist/index.d.ts +21 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -2
- package/dist/json/JsonField.css +7 -0
- package/dist/json/JsonField.d.ts +22 -0
- package/dist/json/JsonField.d.ts.map +1 -0
- package/dist/json/JsonField.js +207 -0
- package/dist/json/JsonField.js.map +1 -0
- package/dist/json/JsonField.module.js +8 -0
- package/dist/json/JsonField.module.js.map +1 -0
- package/dist/json/index.d.ts +2 -0
- package/dist/json/index.d.ts.map +1 -0
- package/dist/json/index.js +1 -0
- package/dist/link/LinkField.css +12 -0
- package/dist/link/LinkField.d.ts +38 -0
- package/dist/link/LinkField.d.ts.map +1 -0
- package/dist/link/LinkField.js +742 -0
- package/dist/link/LinkField.js.map +1 -0
- package/dist/link/LinkField.module.js +8 -0
- package/dist/link/LinkField.module.js.map +1 -0
- package/dist/link/index.d.ts +3 -0
- package/dist/link/index.d.ts.map +1 -0
- package/dist/link/index.js +3 -0
- package/dist/link/link.d.ts +30 -0
- package/dist/link/link.d.ts.map +1 -0
- package/dist/link/link.js +63 -0
- package/dist/link/link.js.map +1 -0
- package/dist/link/pages.d.ts +17 -0
- package/dist/link/pages.d.ts.map +1 -0
- package/dist/link/pages.js +104 -0
- package/dist/link/pages.js.map +1 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/localized/LocalizedField.css +27 -6
- package/dist/localized/LocalizedField.d.ts +19 -8
- package/dist/localized/LocalizedField.d.ts.map +1 -1
- package/dist/localized/LocalizedField.js +238 -105
- package/dist/localized/LocalizedField.js.map +1 -1
- package/dist/localized/LocalizedField.module.js +10 -4
- package/dist/localized/LocalizedField.module.js.map +1 -1
- package/dist/localized/index.d.ts +1 -1
- package/dist/location/LocationField.css +54 -0
- package/dist/location/LocationField.d.ts +31 -0
- package/dist/location/LocationField.d.ts.map +1 -0
- package/dist/location/LocationField.js +487 -0
- package/dist/location/LocationField.js.map +1 -0
- package/dist/location/LocationField.module.js +22 -0
- package/dist/location/LocationField.module.js.map +1 -0
- package/dist/location/LocationMap.d.ts +25 -0
- package/dist/location/LocationMap.d.ts.map +1 -0
- package/dist/location/LocationMap.js +205 -0
- package/dist/location/LocationMap.js.map +1 -0
- package/dist/location/index.d.ts +5 -0
- package/dist/location/index.d.ts.map +1 -0
- package/dist/location/index.js +4 -0
- package/dist/location/leafletCss.d.ts +2 -0
- package/dist/location/leafletCss.d.ts.map +1 -0
- package/dist/location/leafletCss.js +6 -0
- package/dist/location/leafletCss.js.map +1 -0
- package/dist/location/nominatim.d.ts +23 -0
- package/dist/location/nominatim.d.ts.map +1 -0
- package/dist/location/nominatim.js +79 -0
- package/dist/location/nominatim.js.map +1 -0
- package/dist/location/search.d.ts +10 -0
- package/dist/location/search.d.ts.map +1 -0
- package/dist/location/search.js +83 -0
- package/dist/location/search.js.map +1 -0
- package/dist/location/types.d.ts +46 -0
- package/dist/location/types.d.ts.map +1 -0
- package/dist/missing/MissingField.d.ts +4 -3
- package/dist/missing/MissingField.d.ts.map +1 -1
- package/dist/missing/MissingField.js +3 -2
- package/dist/missing/MissingField.js.map +1 -1
- package/dist/money/MoneyField.d.ts +28 -0
- package/dist/money/MoneyField.d.ts.map +1 -0
- package/dist/money/MoneyField.js +269 -0
- package/dist/money/MoneyField.js.map +1 -0
- package/dist/money/index.d.ts +3 -0
- package/dist/money/index.d.ts.map +1 -0
- package/dist/money/index.js +3 -0
- package/dist/money/money.d.ts +27 -0
- package/dist/money/money.d.ts.map +1 -0
- package/dist/money/money.js +56 -0
- package/dist/money/money.js.map +1 -0
- package/dist/number/NumberField.d.ts +1 -1
- package/dist/number/NumberField.js.map +1 -1
- package/dist/number/index.d.ts +1 -1
- package/dist/range/RangeField.d.ts +22 -0
- package/dist/range/RangeField.d.ts.map +1 -0
- package/dist/range/RangeField.js +203 -0
- package/dist/range/RangeField.js.map +1 -0
- package/dist/range/index.d.ts +2 -0
- package/dist/range/index.d.ts.map +1 -0
- package/dist/range/index.js +1 -0
- package/dist/region/RegionField.d.ts +23 -0
- package/dist/region/RegionField.d.ts.map +1 -0
- package/dist/region/RegionField.js +174 -0
- package/dist/region/RegionField.js.map +1 -0
- package/dist/region/RegionFlag.css +9 -0
- package/dist/region/RegionFlag.d.ts +20 -0
- package/dist/region/RegionFlag.d.ts.map +1 -0
- package/dist/region/RegionFlag.js +61 -0
- package/dist/region/RegionFlag.js.map +1 -0
- package/dist/region/RegionFlag.module.js +8 -0
- package/dist/region/RegionFlag.module.js.map +1 -0
- package/dist/region/data.d.ts +5 -0
- package/dist/region/data.d.ts.map +1 -0
- package/dist/region/data.js +513 -0
- package/dist/region/data.js.map +1 -0
- package/dist/region/flags/CA.d.ts +4 -0
- package/dist/region/flags/CA.d.ts.map +1 -0
- package/dist/region/flags/CA.js +21 -0
- package/dist/region/flags/CA.js.map +1 -0
- package/dist/region/flags/US.d.ts +4 -0
- package/dist/region/flags/US.d.ts.map +1 -0
- package/dist/region/flags/US.js +65 -0
- package/dist/region/flags/US.js.map +1 -0
- package/dist/region/flags.d.ts +17 -0
- package/dist/region/flags.d.ts.map +1 -0
- package/dist/region/flags.js +84 -0
- package/dist/region/flags.js.map +1 -0
- package/dist/region/index.d.ts +5 -0
- package/dist/region/index.d.ts.map +1 -0
- package/dist/region/index.js +5 -0
- package/dist/region/regions.d.ts +15 -0
- package/dist/region/regions.d.ts.map +1 -0
- package/dist/region/regions.js +29 -0
- package/dist/region/regions.js.map +1 -0
- package/dist/relation/RelationField.d.ts +2 -2
- package/dist/relation/RelationField.d.ts.map +1 -1
- package/dist/relation/RelationField.js +511 -171
- package/dist/relation/RelationField.js.map +1 -1
- package/dist/relation/index.d.ts +2 -2
- package/dist/repeater/RepeaterField.d.ts +13 -2
- package/dist/repeater/RepeaterField.d.ts.map +1 -1
- package/dist/repeater/RepeaterField.js +138 -50
- package/dist/repeater/RepeaterField.js.map +1 -1
- package/dist/repeater/index.d.ts +1 -1
- package/dist/select/SelectField.d.ts +1 -1
- package/dist/select/SelectField.js.map +1 -1
- package/dist/select/index.d.ts +1 -1
- package/dist/sessions/SessionsField.d.ts +15 -0
- package/dist/sessions/SessionsField.d.ts.map +1 -0
- package/dist/sessions/SessionsField.js +49 -0
- package/dist/sessions/SessionsField.js.map +1 -0
- package/dist/sessions/index.d.ts +4 -0
- package/dist/sessions/index.d.ts.map +1 -0
- package/dist/sessions/index.js +1 -0
- package/dist/shared/CodeComboBox.d.ts +21 -0
- package/dist/shared/CodeComboBox.d.ts.map +1 -0
- package/dist/shared/CodeComboBox.js +238 -0
- package/dist/shared/CodeComboBox.js.map +1 -0
- package/dist/shared/DefinitionField.d.ts +9 -4
- package/dist/shared/DefinitionField.d.ts.map +1 -1
- package/dist/shared/DefinitionField.js +98 -78
- package/dist/shared/DefinitionField.js.map +1 -1
- package/dist/shared/builtIn.d.ts +7 -3
- package/dist/shared/builtIn.d.ts.map +1 -1
- package/dist/shared/builtIn.js +39 -7
- package/dist/shared/builtIn.js.map +1 -1
- package/dist/shared/check.d.ts +27 -0
- package/dist/shared/check.d.ts.map +1 -0
- package/dist/shared/check.js +18 -0
- package/dist/shared/check.js.map +1 -0
- package/dist/shared/context.d.ts +33 -5
- package/dist/shared/context.d.ts.map +1 -1
- package/dist/shared/context.js +36 -20
- package/dist/shared/context.js.map +1 -1
- package/dist/shared/cx.js.map +1 -1
- package/dist/shared/dates.js +2 -2
- package/dist/shared/dates.js.map +1 -1
- package/dist/shared/embed.d.ts +19 -0
- package/dist/shared/embed.d.ts.map +1 -0
- package/dist/shared/embed.js +14 -0
- package/dist/shared/embed.js.map +1 -0
- package/dist/shared/entry.d.ts +13 -4
- package/dist/shared/entry.d.ts.map +1 -1
- package/dist/shared/entry.js +24 -7
- package/dist/shared/entry.js.map +1 -1
- package/dist/shared/flow.d.ts +8 -0
- package/dist/shared/flow.d.ts.map +1 -0
- package/dist/shared/flow.js +38 -0
- package/dist/shared/flow.js.map +1 -0
- package/dist/shared/part.d.ts +26 -0
- package/dist/shared/part.d.ts.map +1 -0
- package/dist/shared/part.js +64 -0
- package/dist/shared/part.js.map +1 -0
- package/dist/shared/relation.js.map +1 -1
- package/dist/shared/reveal.d.ts +16 -0
- package/dist/shared/reveal.d.ts.map +1 -0
- package/dist/shared/reveal.js +46 -0
- package/dist/shared/reveal.js.map +1 -0
- package/dist/shared/types.d.ts +12 -0
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/slug/SlugField.css +18 -0
- package/dist/slug/SlugField.d.ts +33 -5
- package/dist/slug/SlugField.d.ts.map +1 -1
- package/dist/slug/SlugField.js +346 -126
- package/dist/slug/SlugField.js.map +1 -1
- package/dist/slug/SlugField.module.js +14 -0
- package/dist/slug/SlugField.module.js.map +1 -0
- package/dist/slug/index.d.ts +1 -1
- package/dist/slug/index.d.ts.map +1 -1
- package/dist/slug/index.js +1 -1
- package/dist/tags/TagsField.d.ts +17 -0
- package/dist/tags/TagsField.d.ts.map +1 -0
- package/dist/tags/TagsField.js +120 -0
- package/dist/tags/TagsField.js.map +1 -0
- package/dist/tags/index.d.ts +2 -0
- package/dist/tags/index.d.ts.map +1 -0
- package/dist/tags/index.js +1 -0
- package/dist/tel/TelField.css +25 -0
- package/dist/tel/TelField.d.ts +34 -0
- package/dist/tel/TelField.d.ts.map +1 -0
- package/dist/tel/TelField.js +390 -0
- package/dist/tel/TelField.js.map +1 -0
- package/dist/tel/TelField.module.js +12 -0
- package/dist/tel/TelField.module.js.map +1 -0
- package/dist/tel/index.d.ts +3 -0
- package/dist/tel/index.d.ts.map +1 -0
- package/dist/tel/index.js +3 -0
- package/dist/tel/phone.d.ts +59 -0
- package/dist/tel/phone.d.ts.map +1 -0
- package/dist/tel/phone.js +107 -0
- package/dist/tel/phone.js.map +1 -0
- package/dist/text/TextField.d.ts +12 -4
- package/dist/text/TextField.d.ts.map +1 -1
- package/dist/text/TextField.js +104 -60
- package/dist/text/TextField.js.map +1 -1
- package/dist/text/index.d.ts +1 -1
- package/dist/textarea/TextAreaField.d.ts +1 -1
- package/dist/textarea/TextAreaField.js.map +1 -1
- package/dist/textarea/index.d.ts +1 -1
- package/dist/time/TimeField.d.ts +1 -1
- package/dist/time/TimeField.js +64 -10
- package/dist/time/TimeField.js.map +1 -1
- package/dist/time/index.d.ts +1 -1
- package/dist/upload/FilePicker.css +24 -0
- package/dist/upload/FilePicker.d.ts +14 -0
- package/dist/upload/FilePicker.d.ts.map +1 -0
- package/dist/upload/FilePicker.js +130 -0
- package/dist/upload/FilePicker.js.map +1 -0
- package/dist/upload/FilePicker.module.js +12 -0
- package/dist/upload/FilePicker.module.js.map +1 -0
- package/dist/upload/UploadList.css +93 -0
- package/dist/upload/UploadList.d.ts +18 -0
- package/dist/upload/UploadList.d.ts.map +1 -0
- package/dist/upload/UploadList.js +144 -0
- package/dist/upload/UploadList.js.map +1 -0
- package/dist/upload/UploadList.module.js +32 -0
- package/dist/upload/UploadList.module.js.map +1 -0
- package/dist/upload/files.d.ts +5 -0
- package/dist/upload/files.d.ts.map +1 -0
- package/dist/upload/files.js +26 -0
- package/dist/upload/files.js.map +1 -0
- package/dist/upload/types.d.ts +58 -0
- package/dist/upload/types.d.ts.map +1 -0
- package/dist/upload/useRejectionMessage.d.ts +4 -0
- package/dist/upload/useRejectionMessage.d.ts.map +1 -0
- package/dist/upload/useRejectionMessage.js +25 -0
- package/dist/upload/useRejectionMessage.js.map +1 -0
- package/dist/upload/useUploads.d.ts +30 -0
- package/dist/upload/useUploads.d.ts.map +1 -0
- package/dist/upload/useUploads.js +115 -0
- package/dist/upload/useUploads.js.map +1 -0
- package/dist/uppy/index.d.ts +3 -0
- package/dist/uppy/index.d.ts.map +1 -0
- package/dist/uppy/index.js +1 -0
- package/dist/uppy/uploader.d.ts +44 -0
- package/dist/uppy/uploader.d.ts.map +1 -0
- package/dist/uppy/uploader.js +139 -0
- package/dist/uppy/uploader.js.map +1 -0
- package/dist/url/UrlField.d.ts +2 -2
- package/dist/url/UrlField.d.ts.map +1 -1
- package/dist/url/UrlField.js +69 -14
- package/dist/url/UrlField.js.map +1 -1
- package/dist/url/index.d.ts +1 -1
- package/package.json +110 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","names":["value","children","_c"],"sources":["../../src/shared/context.tsx"],"sourcesContent":["import { type ComponentType, type ReactNode, createContext, use } from 'react';\n\nimport type { Field } from '@panneau/protocol';\n\nimport type { RelationSource } from './relation';\nimport type { FieldEntry } from './types';\n\n/** What a binding gives a field: its value, handlers and errors at a path. */\nexport interface BoundFieldProps {\n value: unknown;\n onChange: (value: unknown) => void;\n onBlur?: () => void;\n errors?: readonly string[];\n}\n\n/** Props of a binding: it decides whether a field shows, and where its value comes from. */\nexport interface FieldBindingProps {\n field: Field;\n /** Dot path of the field's value. */\n path: string;\n /** Dot path of the object the field belongs to: `''` at the top, `blocks.2` in a block. */\n parentPath: string;\n /** Renders the field with its bound value. */\n render: (bound: BoundFieldProps) => ReactNode;\n}\n\n/**\n * Binds nested fields (in groups, blocks and localized values) to a store by path, instead of the\n * value and `onChange` of their parent. `@panneau/forms` binds them to its form state, so that\n * every value is set, validated and shown in error by its own path.\n */\nexport type FieldBinding = ComponentType<FieldBindingProps>;\n\nexport interface FieldsContextValue {\n /** Registry entries, by field type, over the built-in ones. */\n components: Readonly<Record<string, FieldEntry>>;\n /** Locales of localized values, in order. */\n locales: readonly string[];\n /** Where relation fields search for items. */\n relationSource: RelationSource | null;\n binding: FieldBinding | null;\n}\n\nconst FieldsContext = createContext<FieldsContextValue>({\n components: {},\n locales: [],\n relationSource: null,\n binding: null,\n});\n\n/** The fields context of the closest `FieldsProvider`. */\nexport function useFieldsContext(): FieldsContextValue {\n return use(FieldsContext);\n}\n\nexport interface FieldsProviderProps {\n /** Registry entries by type, added over those of a parent provider. */\n components?: Readonly<Record<string, FieldEntry>>;\n locales?: readonly string[];\n relationSource?: RelationSource | null;\n binding?: FieldBinding | null;\n children?: ReactNode;\n}\n\n/**\n * Provides what fields rendered from a definition need: the components of each type, the locales\n * of localized values,
|
|
1
|
+
{"version":3,"file":"context.js","names":["ComponentType","ReactNode","createContext","use","Field","MapsConfig","UploadSource","FieldCheckSource","EmbedSource","RelationSource","FieldEntry","BoundFieldProps","value","onChange","onBlur","errors","invalidPaths","FieldBindingProps","field","path","parentPath","render","bound","FieldBinding","FieldsContextValue","components","Readonly","Record","locales","relationSource","uploadSource","checkSource","embedSource","maps","binding","FieldsContext","useFieldsContext","FieldsProviderProps","children","FieldsProvider","t0","$","_c","parent","t1","undefined","t2","t3","t4","t5","t6","t7","t8","t9","t10","getParentPath","index","lastIndexOf","slice","_c"],"sources":["../../src/shared/context.tsx"],"sourcesContent":["import { type ComponentType, type ReactNode, createContext, use } from 'react';\n\nimport type { Field } from '@panneau/protocol';\n\nimport type { MapsConfig } from '../location/types';\nimport type { UploadSource } from '../upload/types';\nimport type { FieldCheckSource } from './check';\nimport type { EmbedSource } from './embed';\nimport type { RelationSource } from './relation';\nimport type { FieldEntry } from './types';\n\n/** What a binding gives a field: its value, handlers and errors at a path. */\nexport interface BoundFieldProps {\n value: unknown;\n onChange: (value: unknown) => void;\n onBlur?: () => void;\n errors?: readonly string[];\n /**\n * Paths inside the field that have errors (`title.en`), for fields that show their nested\n * fields themselves: a localized field marks its locales in error.\n */\n invalidPaths?: readonly string[];\n}\n\n/** Props of a binding: it decides whether a field shows, and where its value comes from. */\nexport interface FieldBindingProps {\n field: Field;\n /** Dot path of the field's value. */\n path: string;\n /** Dot path of the object the field belongs to: `''` at the top, `blocks.2` in a block. */\n parentPath: string;\n /** Renders the field with its bound value. */\n render: (bound: BoundFieldProps) => ReactNode;\n}\n\n/**\n * Binds nested fields (in groups, blocks and localized values) to a store by path, instead of the\n * value and `onChange` of their parent. `@panneau/forms` binds them to its form state, so that\n * every value is set, validated and shown in error by its own path.\n */\nexport type FieldBinding = ComponentType<FieldBindingProps>;\n\nexport interface FieldsContextValue {\n /** Registry entries, by field type, over the built-in ones. */\n components: Readonly<Record<string, FieldEntry>>;\n /** Locales of localized values, in order. */\n locales: readonly string[];\n /** Where relation fields search for items. */\n relationSource: RelationSource | null;\n /**\n * Where fields that take files upload them directly to storage. Without one, they give the\n * files themselves.\n */\n uploadSource: UploadSource | null;\n /** Where fields with `check` check their value, such as a slug's availability. */\n checkSource: FieldCheckSource | null;\n /** Where `embed` fields get what a URL embeds. Without one, they keep the URL alone. */\n embedSource: EmbedSource | null;\n /** The tiles and the address search of `location` fields. */\n maps: MapsConfig | null;\n binding: FieldBinding | null;\n}\n\nconst FieldsContext = createContext<FieldsContextValue>({\n components: {},\n locales: [],\n relationSource: null,\n uploadSource: null,\n checkSource: null,\n embedSource: null,\n maps: null,\n binding: null,\n});\n\n/** The fields context of the closest `FieldsProvider`. */\nexport function useFieldsContext(): FieldsContextValue {\n return use(FieldsContext);\n}\n\nexport interface FieldsProviderProps {\n /** Registry entries by type, added over those of a parent provider. */\n components?: Readonly<Record<string, FieldEntry>>;\n locales?: readonly string[];\n relationSource?: RelationSource | null;\n /** Make it once, outside of render: fields make an uploader for each source they get. */\n uploadSource?: UploadSource | null;\n /** `createFieldCheckSource(adapter, resource, id)`, for the form of an item. */\n checkSource?: FieldCheckSource | null;\n /** `createEmbedSource(adapter)`. */\n embedSource?: EmbedSource | null;\n /** The tiles and the address search of `location` fields. */\n maps?: MapsConfig | null;\n binding?: FieldBinding | null;\n children?: ReactNode;\n}\n\n/**\n * Provides what fields rendered from a definition need: the components of each type, the locales\n * of localized values, the sources of relations, uploads, checks and embeds, the maps of\n * locations, and a binding. Values not given come from the parent provider.\n */\nexport function FieldsProvider({\n components,\n locales,\n relationSource,\n uploadSource,\n checkSource,\n embedSource,\n maps,\n binding,\n children,\n}: FieldsProviderProps) {\n const parent = use(FieldsContext);\n const value: FieldsContextValue = {\n components:\n components !== undefined ? { ...parent.components, ...components } : parent.components,\n locales: locales ?? parent.locales,\n relationSource: relationSource === undefined ? parent.relationSource : relationSource,\n uploadSource: uploadSource === undefined ? parent.uploadSource : uploadSource,\n checkSource: checkSource === undefined ? parent.checkSource : checkSource,\n embedSource: embedSource === undefined ? parent.embedSource : embedSource,\n maps: maps === undefined ? parent.maps : maps,\n binding: binding === undefined ? parent.binding : binding,\n };\n return <FieldsContext value={value}>{children}</FieldsContext>;\n}\n\n/** The parent path of a path: `blocks.2` for `blocks.2.title`, `''` for `title`. */\nexport function getParentPath(path: string): string {\n const index = path.lastIndexOf('.');\n return index === -1 ? '' : path.slice(0, index);\n}\n"],"mappings":";;;;AA+DA,IAAMmC,gBAAgBjC,cAAkC;CACpDuB,YAAY,CAAC;CACbG,SAAS,CAAA;CACTC,gBAAgB;CAChBC,cAAc;CACdC,aAAa;CACbC,aAAa;CACbC,MAAM;CACNC,SAAS;AACb,CAAC;;AAGD,SAAgBE,mBAAuC;CACnD,OAAOjC,IAAIgC,aAAa;AAC5B;;;;;;AAwBA,SAAOI,eAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAwB,MAAA,EAAAjB,YAAAG,SAAAC,gBAAAC,cAAAC,aAAAC,aAAAC,MAAAC,SAAAI,aAAAE;CAW3B,MAAAG,SAAexC,IAAIgC,aAAa;CAAE,IAAAS;CAAA,IAAAH,EAAA,OAAAhB,cAAAgB,EAAA,OAAAE,OAAAlB,YAAA;EAG1BmB,KAAAnB,eAAeoB,KAAAA,IAAf;GAAA,GAAgCF,OAAMlB;GAAW,GAAKA;EAA+B,IAAhBkB,OAAMlB;EAAWgB,EAAA,KAAAhB;EAAAgB,EAAA,KAAAE,OAAAlB;EAAAgB,EAAA,KAAAG;CAAA,OAAAA,KAAAH,EAAA;CACjF,MAAAK,KAAAlB,WAAWe,OAAMf;CACV,MAAAmB,KAAAlB,mBAAmBgB,KAAAA,IAAYF,OAAMd,iBAArCA;CACF,MAAAmB,KAAAlB,iBAAiBe,KAAAA,IAAYF,OAAMb,eAAnCA;CACD,MAAAmB,KAAAlB,gBAAgBc,KAAAA,IAAYF,OAAMZ,cAAlCA;CACA,MAAAmB,KAAAlB,gBAAgBa,KAAAA,IAAYF,OAAMX,cAAlCA;CACP,MAAAmB,KAAAlB,SAASY,KAAAA,IAAYF,OAAMV,OAA3BA;CACG,MAAAmB,KAAAlB,YAAYW,KAAAA,IAAYF,OAAMT,UAA9BA;CAAgD,IAAAmB;CAAA,IAAAZ,EAAA,OAAAG,MAAAH,EAAA,OAAAK,MAAAL,EAAA,OAAAM,MAAAN,EAAA,OAAAO,MAAAP,EAAA,OAAAQ,MAAAR,EAAA,OAAAS,MAAAT,EAAA,OAAAU,MAAAV,EAAA,QAAAW,IAAA;EAT3BC,KAAA;GAAA5B,YAE1BmB;GAAsFhB,SACjFkB;GAAyBjB,gBAClBkB;GAAqEjB,cACvEkB;GAA+DjB,aAChEkB;GAA4DjB,aAC5DkB;GAA4DjB,MACnEkB;GAAuCjB,SACpCkB;EACb;EAACX,EAAA,KAAAG;EAAAH,EAAA,KAAAK;EAAAL,EAAA,KAAAM;EAAAN,EAAA,KAAAO;EAAAP,EAAA,KAAAQ;EAAAR,EAAA,KAAAS;EAAAT,EAAA,KAAAU;EAAAV,EAAA,MAAAW;EAAAX,EAAA,MAAAY;CAAA,OAAAA,KAAAZ,EAAA;CAVD,MAAA7B,QAAkCyC;CAUhC,IAAAC;CAAA,IAAAb,EAAA,QAAAH,YAAAG,EAAA,QAAA7B,OAAA;EACK0C,MAAA,oBAAC,eAAD;GAAsB1C;GAAQ0B;EAAhB,CAAA;EAAyCG,EAAA,MAAAH;EAAAG,EAAA,MAAA7B;EAAA6B,EAAA,MAAAa;CAAA,OAAAA,MAAAb,EAAA;CAAA,OAAvDa;AAAuD;;AAIlE,SAAgBC,cAAcpC,MAAsB;CAChD,MAAMqC,QAAQrC,KAAKsC,YAAY,GAAG;CAClC,OAAOD,UAAU,KAAK,KAAKrC,KAAKuC,MAAM,GAAGF,KAAK;AAClD"}
|
package/dist/shared/cx.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cx.js","names":[],"sources":["../../src/shared/cx.ts"],"sourcesContent":["/** Joins class names, skipping empty ones. */\nexport function cx(...classNames: (string | false | null | undefined)[]): string {\n return classNames.filter(Boolean).join(' ');\n}\n"],"mappings":";;AACA,
|
|
1
|
+
{"version":3,"file":"cx.js","names":["cx","classNames","filter","Boolean","join"],"sources":["../../src/shared/cx.ts"],"sourcesContent":["/** Joins class names, skipping empty ones. */\nexport function cx(...classNames: (string | false | null | undefined)[]): string {\n return classNames.filter(Boolean).join(' ');\n}\n"],"mappings":";;AACA,SAAgBA,GAAG,GAAGC,YAA2D;CAC7E,OAAOA,WAAWC,OAAOC,OAAO,CAAC,CAACC,KAAK,GAAG;AAC9C"}
|
package/dist/shared/dates.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getLocalTimeZone, parseAbsolute, parseDate, parseDateTime, parseTime } from "@internationalized/date";
|
|
2
2
|
//#region src/shared/dates.ts
|
|
3
3
|
/** `2026-10-15`, or the date of a date-time. */
|
|
4
|
-
function toCalendarDate(value) {
|
|
4
|
+
function toCalendarDate$1(value) {
|
|
5
5
|
const match = value?.match(/^(\d{4}-\d{2}-\d{2})/);
|
|
6
6
|
if (match?.[1] === void 0) return null;
|
|
7
7
|
try {
|
|
@@ -44,6 +44,6 @@ function fromTime(value, withSeconds = false) {
|
|
|
44
44
|
return withSeconds ? `${time}:${pad(value.second)}` : time;
|
|
45
45
|
}
|
|
46
46
|
//#endregion
|
|
47
|
-
export { fromDateTime, fromTime, toCalendarDate, toDateTime, toTime };
|
|
47
|
+
export { fromDateTime, fromTime, toCalendarDate$1 as toCalendarDate, toDateTime, toTime };
|
|
48
48
|
|
|
49
49
|
//# sourceMappingURL=dates.js.map
|
package/dist/shared/dates.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dates.js","names":[],"sources":["../../src/shared/dates.ts"],"sourcesContent":["import {\n type CalendarDate,\n type CalendarDateTime,\n type Time,\n type ZonedDateTime,\n getLocalTimeZone,\n parseAbsolute,\n parseDate,\n parseDateTime,\n parseTime,\n} from '@internationalized/date';\n\n/** `2026-10-15`, or the date of a date-time. */\nexport function toCalendarDate(value: string | null | undefined): CalendarDate | null {\n const match = value?.match(/^(\\d{4}-\\d{2}-\\d{2})/);\n if (match?.[1] === undefined) {\n return null;\n }\n try {\n return parseDate(match[1]);\n } catch {\n return null;\n }\n}\n\nconst OFFSET = /(?:Z|[+-]\\d{2}:?\\d{2})$/i;\n\n/**\n * A date-time: with an offset or `Z` (`2026-10-15T13:30:00Z`), in the given time zone; without one\n * (`2026-10-15 09:30:00`), as is.\n */\nexport function toDateTime(\n value: string | null | undefined,\n timeZone: string = getLocalTimeZone(),\n): ZonedDateTime | CalendarDateTime | null {\n if (value === null || value === undefined || value.trim() === '') {\n return null;\n }\n const iso = value.trim().replace(' ', 'T');\n try {\n return OFFSET.test(iso) ? parseAbsolute(iso, timeZone) : parseDateTime(iso);\n } catch {\n return null;\n }\n}\n\n/** Writes a date-time: in UTC (`…Z`) when it has a time zone, without an offset otherwise. */\nexport function fromDateTime(value: ZonedDateTime | CalendarDateTime): string {\n return 'timeZone' in value\n ? value.toAbsoluteString().replace(/\\.000Z$/, 'Z')\n : value.toString();\n}\n\n/** `09:30` or `09:30:15`. */\nexport function toTime(value: string | null | undefined): Time | null {\n if (value === null || value === undefined || !/^\\d{1,2}:\\d{2}(:\\d{2})?/.test(value)) {\n return null;\n }\n try {\n return parseTime(value.length < 5 ? `0${value}` : value);\n } catch {\n return null;\n }\n}\n\n/** Writes a time as `HH:mm`, or `HH:mm:ss` with seconds. */\nexport function fromTime(\n value: Pick<Time, 'hour' | 'minute' | 'second'>,\n withSeconds = false,\n): string {\n const pad = (part: number) => String(part).padStart(2, '0');\n const time = `${pad(value.hour)}:${pad(value.minute)}`;\n return withSeconds ? `${time}:${pad(value.second)}` : time;\n}\n"],"mappings":";;;AAaA,
|
|
1
|
+
{"version":3,"file":"dates.js","names":["CalendarDate","CalendarDateTime","Time","ZonedDateTime","getLocalTimeZone","parseAbsolute","parseDate","parseDateTime","parseTime","toCalendarDate","value","match","undefined","OFFSET","toDateTime","timeZone","trim","iso","replace","test","fromDateTime","toAbsoluteString","toString","toTime","length","fromTime","Pick","withSeconds","pad","part","String","padStart","time","hour","minute","second","toCalendarDate"],"sources":["../../src/shared/dates.ts"],"sourcesContent":["import {\n type CalendarDate,\n type CalendarDateTime,\n type Time,\n type ZonedDateTime,\n getLocalTimeZone,\n parseAbsolute,\n parseDate,\n parseDateTime,\n parseTime,\n} from '@internationalized/date';\n\n/** `2026-10-15`, or the date of a date-time. */\nexport function toCalendarDate(value: string | null | undefined): CalendarDate | null {\n const match = value?.match(/^(\\d{4}-\\d{2}-\\d{2})/);\n if (match?.[1] === undefined) {\n return null;\n }\n try {\n return parseDate(match[1]);\n } catch {\n return null;\n }\n}\n\nconst OFFSET = /(?:Z|[+-]\\d{2}:?\\d{2})$/i;\n\n/**\n * A date-time: with an offset or `Z` (`2026-10-15T13:30:00Z`), in the given time zone; without one\n * (`2026-10-15 09:30:00`), as is.\n */\nexport function toDateTime(\n value: string | null | undefined,\n timeZone: string = getLocalTimeZone(),\n): ZonedDateTime | CalendarDateTime | null {\n if (value === null || value === undefined || value.trim() === '') {\n return null;\n }\n const iso = value.trim().replace(' ', 'T');\n try {\n return OFFSET.test(iso) ? parseAbsolute(iso, timeZone) : parseDateTime(iso);\n } catch {\n return null;\n }\n}\n\n/** Writes a date-time: in UTC (`…Z`) when it has a time zone, without an offset otherwise. */\nexport function fromDateTime(value: ZonedDateTime | CalendarDateTime): string {\n return 'timeZone' in value\n ? value.toAbsoluteString().replace(/\\.000Z$/, 'Z')\n : value.toString();\n}\n\n/** `09:30` or `09:30:15`. */\nexport function toTime(value: string | null | undefined): Time | null {\n if (value === null || value === undefined || !/^\\d{1,2}:\\d{2}(:\\d{2})?/.test(value)) {\n return null;\n }\n try {\n return parseTime(value.length < 5 ? `0${value}` : value);\n } catch {\n return null;\n }\n}\n\n/** Writes a time as `HH:mm`, or `HH:mm:ss` with seconds. */\nexport function fromTime(\n value: Pick<Time, 'hour' | 'minute' | 'second'>,\n withSeconds = false,\n): string {\n const pad = (part: number) => String(part).padStart(2, '0');\n const time = `${pad(value.hour)}:${pad(value.minute)}`;\n return withSeconds ? `${time}:${pad(value.second)}` : time;\n}\n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+
import type { EmbedValue } from '@panneau/protocol';
|
|
2
|
+
/** Where `embed` fields get what a URL embeds: the backend, from the provider's oEmbed. */
|
|
3
|
+
export interface EmbedSource {
|
|
4
|
+
resolve(url: string, options: {
|
|
5
|
+
signal: AbortSignal;
|
|
6
|
+
}): Promise<EmbedValue>;
|
|
7
|
+
}
|
|
8
|
+
/** What `createEmbedSource()` needs from an adapter: the `resolveEmbed()` of `@panneau/data`. */
|
|
9
|
+
export interface EmbedAdapter {
|
|
10
|
+
resolveEmbed?(url: string, options?: {
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}): Promise<EmbedValue>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The embed source of an adapter (`GET /embeds?url=`). Null when the adapter can't resolve
|
|
16
|
+
* embeds: `embed` fields then keep the URL alone.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createEmbedSource(adapter: EmbedAdapter): EmbedSource | null;
|
|
19
|
+
//# sourceMappingURL=embed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../../src/shared/embed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,2FAA2F;AAC3F,MAAM,WAAW,WAAW;IACxB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC/E;AAED,iGAAiG;AACjG,MAAM,WAAW,YAAY;IACzB,YAAY,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACvF;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,YAAY,GAAG,WAAW,GAAG,IAAI,CAM3E"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/shared/embed.ts
|
|
2
|
+
/**
|
|
3
|
+
* The embed source of an adapter (`GET /embeds?url=`). Null when the adapter can't resolve
|
|
4
|
+
* embeds: `embed` fields then keep the URL alone.
|
|
5
|
+
*/
|
|
6
|
+
function createEmbedSource(adapter) {
|
|
7
|
+
const { resolveEmbed } = adapter;
|
|
8
|
+
if (resolveEmbed === void 0) return null;
|
|
9
|
+
return { resolve: (url, { signal }) => resolveEmbed.call(adapter, url, { signal }) };
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { createEmbedSource };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=embed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.js","names":["EmbedValue","EmbedSource","resolve","url","options","signal","AbortSignal","Promise","EmbedAdapter","resolveEmbed","createEmbedSource","adapter","undefined","call"],"sources":["../../src/shared/embed.ts"],"sourcesContent":["import type { EmbedValue } from '@panneau/protocol';\n\n/** Where `embed` fields get what a URL embeds: the backend, from the provider's oEmbed. */\nexport interface EmbedSource {\n resolve(url: string, options: { signal: AbortSignal }): Promise<EmbedValue>;\n}\n\n/** What `createEmbedSource()` needs from an adapter: the `resolveEmbed()` of `@panneau/data`. */\nexport interface EmbedAdapter {\n resolveEmbed?(url: string, options?: { signal?: AbortSignal }): Promise<EmbedValue>;\n}\n\n/**\n * The embed source of an adapter (`GET /embeds?url=`). Null when the adapter can't resolve\n * embeds: `embed` fields then keep the URL alone.\n */\nexport function createEmbedSource(adapter: EmbedAdapter): EmbedSource | null {\n const { resolveEmbed } = adapter;\n if (resolveEmbed === undefined) {\n return null;\n }\n return { resolve: (url, { signal }) => resolveEmbed.call(adapter, url, { signal }) };\n}\n"],"mappings":";;;;;AAgBA,SAAgBU,kBAAkBC,SAA2C;CACzE,MAAM,EAAEF,iBAAiBE;CACzB,IAAIF,iBAAiBG,KAAAA,GACjB,OAAO;CAEX,OAAO,EAAEV,UAAUC,KAAK,EAAEE,aAAaI,aAAaI,KAAKF,SAASR,KAAK,EAAEE,OAAO,CAAC,EAAE;AACvF"}
|
package/dist/shared/entry.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { Field, Rule } from '@panneau/protocol';
|
|
2
|
-
import type { FieldEntryProps, FieldProps } from './types';
|
|
3
|
-
/**
|
|
2
|
+
import type { FieldEntryProps, FieldProps } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The rule of a field with this name, if any. A rule limited to a mode (`"mode": "create"`)
|
|
5
|
+
* doesn't count: forms keep it, without its `mode`, in that mode only (`resolveFields()` of
|
|
6
|
+
* `@panneau/core`).
|
|
7
|
+
*/
|
|
4
8
|
export declare function findRule(field: Field, rule: Rule['rule']): Rule | undefined;
|
|
5
9
|
/** The number of a `min` or `max` rule of a field, if any. */
|
|
6
10
|
export declare function getRuleNumber(field: Field, rule: 'min' | 'max'): number | undefined;
|
|
@@ -9,15 +13,20 @@ export declare function isRequired(field: Field): boolean;
|
|
|
9
13
|
/** A setting of a field (`settings.<name>`), when it has the expected type. */
|
|
10
14
|
export declare function getSetting<T>(field: Field, name: string, guard: (value: unknown) => value is T): T | undefined;
|
|
11
15
|
export declare const isString: (value: unknown) => value is string;
|
|
16
|
+
export declare const isBoolean: (value: unknown) => value is boolean;
|
|
12
17
|
export declare const isNumber: (value: unknown) => value is number;
|
|
13
18
|
/**
|
|
14
19
|
* The props that every field takes, from a registry entry's props: label (the field's name
|
|
15
|
-
* without one), help, required mark, read-only, errors and
|
|
16
|
-
* own entries.
|
|
20
|
+
* without one, or `aria-label` with `hideLabel`), help, required mark, read-only, errors and
|
|
21
|
+
* handlers. Plugins use it to write their own entries.
|
|
17
22
|
*/
|
|
18
23
|
export declare function getFieldProps(props: FieldEntryProps): Omit<FieldProps<never>, 'value' | 'onChange'> & {
|
|
19
24
|
placeholder?: string;
|
|
20
25
|
};
|
|
21
26
|
/** The value as a string, or `null`. */
|
|
22
27
|
export declare function asString(value: unknown): string | null;
|
|
28
|
+
/** The accepted MIME types of a field that takes files: its `accept`, or its `accept` rule. */
|
|
29
|
+
export declare function getAccept(field: Field): string[] | null;
|
|
30
|
+
/** The largest file of a field, in bytes: its `maxSize` rule. */
|
|
31
|
+
export declare function getMaxSize(field: Field): number | null;
|
|
23
32
|
//# sourceMappingURL=entry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../src/shared/entry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE3D
|
|
1
|
+
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../src/shared/entry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,CAI3E;AAED,8DAA8D;AAC9D,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,CAKnF;AAED,+CAA+C;AAC/C,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEhD;AAED,+EAA+E;AAC/E,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,iBAG9F;AAED,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAAmC,CAAC;AACvF,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,OAAqC,CAAC;AAC1F,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MACE,CAAC;AAEtD;;;;GAIG;AACH,wBAAgB,aAAa,CACzB,KAAK,EAAE,eAAe,GACvB,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAkB1E;AAED,wCAAwC;AACxC,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAEtD;AAED,+FAA+F;AAC/F,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,GAAG,IAAI,CAQvD;AAED,iEAAiE;AACjE,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,IAAI,CAGtD"}
|
package/dist/shared/entry.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
//#region src/shared/entry.ts
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* The rule of a field with this name, if any. A rule limited to a mode (`"mode": "create"`)
|
|
4
|
+
* doesn't count: forms keep it, without its `mode`, in that mode only (`resolveFields()` of
|
|
5
|
+
* `@panneau/core`).
|
|
6
|
+
*/
|
|
3
7
|
function findRule(field, rule) {
|
|
4
|
-
return field.rules?.find((candidate) => candidate.rule === rule);
|
|
8
|
+
return field.rules?.find((candidate) => candidate.rule === rule && candidate.mode === void 0);
|
|
5
9
|
}
|
|
6
10
|
/** The number of a `min` or `max` rule of a field, if any. */
|
|
7
11
|
function getRuleNumber(field, rule) {
|
|
@@ -18,28 +22,41 @@ function getSetting(field, name, guard) {
|
|
|
18
22
|
return guard(value) ? value : void 0;
|
|
19
23
|
}
|
|
20
24
|
var isString = (value) => typeof value === "string";
|
|
25
|
+
var isBoolean = (value) => typeof value === "boolean";
|
|
21
26
|
var isNumber = (value) => typeof value === "number" && !Number.isNaN(value);
|
|
22
27
|
/**
|
|
23
28
|
* The props that every field takes, from a registry entry's props: label (the field's name
|
|
24
|
-
* without one), help, required mark, read-only, errors and
|
|
25
|
-
* own entries.
|
|
29
|
+
* without one, or `aria-label` with `hideLabel`), help, required mark, read-only, errors and
|
|
30
|
+
* handlers. Plugins use it to write their own entries.
|
|
26
31
|
*/
|
|
27
32
|
function getFieldProps(props) {
|
|
28
33
|
const { field } = props;
|
|
34
|
+
const label = field.label ?? field.name;
|
|
29
35
|
return {
|
|
30
36
|
name: props.path,
|
|
31
|
-
label:
|
|
37
|
+
...props.hideLabel === true ? { "aria-label": label } : { label },
|
|
32
38
|
description: field.help,
|
|
33
39
|
...field.placeholder !== void 0 ? { placeholder: field.placeholder } : {},
|
|
34
40
|
required: isRequired(field),
|
|
35
|
-
readOnly: props.readOnly === true || field.readOnly === true,
|
|
41
|
+
readOnly: props.readOnly === true || field.readOnly === true || field.abilities?.update === false,
|
|
36
42
|
disabled: props.disabled === true,
|
|
37
43
|
errors: props.errors ?? [],
|
|
38
44
|
...props.onBlur !== void 0 ? { onBlur: props.onBlur } : {},
|
|
39
45
|
...props.className !== void 0 ? { className: props.className } : {}
|
|
40
46
|
};
|
|
41
47
|
}
|
|
48
|
+
/** The accepted MIME types of a field that takes files: its `accept`, or its `accept` rule. */
|
|
49
|
+
function getAccept(field) {
|
|
50
|
+
if (field.accept !== void 0 && field.accept.length > 0) return field.accept;
|
|
51
|
+
const rule = findRule(field, "accept");
|
|
52
|
+
return rule !== void 0 && "value" in rule && Array.isArray(rule.value) ? rule.value.filter(isString) : null;
|
|
53
|
+
}
|
|
54
|
+
/** The largest file of a field, in bytes: its `maxSize` rule. */
|
|
55
|
+
function getMaxSize(field) {
|
|
56
|
+
const rule = findRule(field, "maxSize");
|
|
57
|
+
return rule !== void 0 && "value" in rule && isNumber(rule.value) ? rule.value : null;
|
|
58
|
+
}
|
|
42
59
|
//#endregion
|
|
43
|
-
export { findRule, getFieldProps, getRuleNumber, getSetting, isNumber, isRequired, isString };
|
|
60
|
+
export { findRule, getAccept, getFieldProps, getMaxSize, getRuleNumber, getSetting, isBoolean, isNumber, isRequired, isString };
|
|
44
61
|
|
|
45
62
|
//# sourceMappingURL=entry.js.map
|
package/dist/shared/entry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.js","names":[],"sources":["../../src/shared/entry.ts"],"sourcesContent":["import type { Field, Rule } from '@panneau/protocol';\n\nimport type { FieldEntryProps, FieldProps } from './types';\n\n
|
|
1
|
+
{"version":3,"file":"entry.js","names":["Field","Rule","FieldEntryProps","FieldProps","findRule","field","rule","rules","find","candidate","mode","undefined","getRuleNumber","found","value","isRequired","getSetting","name","guard","T","settings","isString","isBoolean","isNumber","Number","isNaN","getFieldProps","props","Omit","placeholder","label","path","hideLabel","description","help","required","readOnly","abilities","update","disabled","errors","onBlur","className","asString","getAccept","accept","length","Array","isArray","filter","getMaxSize"],"sources":["../../src/shared/entry.ts"],"sourcesContent":["import type { Field, Rule } from '@panneau/protocol';\n\nimport type { FieldEntryProps, FieldProps } from './types';\n\n/**\n * The rule of a field with this name, if any. A rule limited to a mode (`\"mode\": \"create\"`)\n * doesn't count: forms keep it, without its `mode`, in that mode only (`resolveFields()` of\n * `@panneau/core`).\n */\nexport function findRule(field: Field, rule: Rule['rule']): Rule | undefined {\n return field.rules?.find(\n (candidate) => candidate.rule === rule && candidate.mode === undefined,\n );\n}\n\n/** The number of a `min` or `max` rule of a field, if any. */\nexport function getRuleNumber(field: Field, rule: 'min' | 'max'): number | undefined {\n const found = findRule(field, rule);\n return found !== undefined && 'value' in found && typeof found.value === 'number'\n ? found.value\n : undefined;\n}\n\n/** Whether a field has the `required` rule. */\nexport function isRequired(field: Field): boolean {\n return findRule(field, 'required') !== undefined;\n}\n\n/** A setting of a field (`settings.<name>`), when it has the expected type. */\nexport function getSetting<T>(field: Field, name: string, guard: (value: unknown) => value is T) {\n const value = field.settings?.[name];\n return guard(value) ? value : undefined;\n}\n\nexport const isString = (value: unknown): value is string => typeof value === 'string';\nexport const isBoolean = (value: unknown): value is boolean => typeof value === 'boolean';\nexport const isNumber = (value: unknown): value is number =>\n typeof value === 'number' && !Number.isNaN(value);\n\n/**\n * The props that every field takes, from a registry entry's props: label (the field's name\n * without one, or `aria-label` with `hideLabel`), help, required mark, read-only, errors and\n * handlers. Plugins use it to write their own entries.\n */\nexport function getFieldProps(\n props: FieldEntryProps,\n): Omit<FieldProps<never>, 'value' | 'onChange'> & { placeholder?: string } {\n const { field } = props;\n // A field always has a label: its name when the definition gives none.\n const label = field.label ?? field.name;\n return {\n name: props.path,\n ...(props.hideLabel === true ? { 'aria-label': label } : { label }),\n description: field.help,\n ...(field.placeholder !== undefined ? { placeholder: field.placeholder } : {}),\n required: isRequired(field),\n // A field the user can't edit is read-only (`abilities.update: false`, decision 0046)\n readOnly:\n props.readOnly === true || field.readOnly === true || field.abilities?.update === false,\n disabled: props.disabled === true,\n errors: props.errors ?? [],\n ...(props.onBlur !== undefined ? { onBlur: props.onBlur } : {}),\n ...(props.className !== undefined ? { className: props.className } : {}),\n };\n}\n\n/** The value as a string, or `null`. */\nexport function asString(value: unknown): string | null {\n return typeof value === 'string' ? value : null;\n}\n\n/** The accepted MIME types of a field that takes files: its `accept`, or its `accept` rule. */\nexport function getAccept(field: Field): string[] | null {\n if (field.accept !== undefined && field.accept.length > 0) {\n return field.accept;\n }\n const rule = findRule(field, 'accept');\n return rule !== undefined && 'value' in rule && Array.isArray(rule.value)\n ? rule.value.filter(isString)\n : null;\n}\n\n/** The largest file of a field, in bytes: its `maxSize` rule. */\nexport function getMaxSize(field: Field): number | null {\n const rule = findRule(field, 'maxSize');\n return rule !== undefined && 'value' in rule && isNumber(rule.value) ? rule.value : null;\n}\n"],"mappings":";;;;;;AASA,SAAgBI,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AMc,OAAO,IAAI,CAAC;EAC7D,GAAId,MAAMe,cAAc/B,KAAAA,IAAY,EAAE+B,WAAWf,MAAMe,UAAU,IAAI,CAAC;CAC1E;AACJ;;AAQA,SAAgBE,UAAUvC,OAA+B;CACrD,IAAIA,MAAMwC,WAAWlC,KAAAA,KAAaN,MAAMwC,OAAOC,SAAS,GACpD,OAAOzC,MAAMwC;CAEjB,MAAMvC,OAAOF,SAASC,OAAO,QAAQ;CACrC,OAAOC,SAASK,KAAAA,KAAa,WAAWL,QAAQyC,MAAMC,QAAQ1C,KAAKQ,KAAK,IAClER,KAAKQ,MAAMmC,OAAO5B,QAAQ,IAC1B;AACV;;AAGA,SAAgB6B,WAAW7C,OAA6B;CACpD,MAAMC,OAAOF,SAASC,OAAO,SAAS;CACtC,OAAOC,SAASK,KAAAA,KAAa,WAAWL,QAAQiB,SAASjB,KAAKQ,KAAK,IAAIR,KAAKQ,QAAQ;AACxF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Field } from '@panneau/protocol';
|
|
2
|
+
/**
|
|
3
|
+
* Whether a field takes a whole row where fields flow in columns, such as in a form without a
|
|
4
|
+
* layout or in a group: long inputs (a text area, rich text, blocks), several values, a value per
|
|
5
|
+
* locale, and the types of plugins. Short inputs share a row.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isWideField(field: Field): boolean;
|
|
8
|
+
//# sourceMappingURL=flow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../src/shared/flow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AA0B/C;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CASjD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getSetting, isString } from "./entry.js";
|
|
2
|
+
//#region src/shared/flow.ts
|
|
3
|
+
/** Types whose input is short: they share a row with others in a flow of fields. */
|
|
4
|
+
var COMPACT_TYPES = /* @__PURE__ */ new Set([
|
|
5
|
+
"text",
|
|
6
|
+
"email",
|
|
7
|
+
"url",
|
|
8
|
+
"tel",
|
|
9
|
+
"country",
|
|
10
|
+
"region",
|
|
11
|
+
"money",
|
|
12
|
+
"number",
|
|
13
|
+
"date",
|
|
14
|
+
"datetime",
|
|
15
|
+
"time",
|
|
16
|
+
"duration",
|
|
17
|
+
"color",
|
|
18
|
+
"select",
|
|
19
|
+
"boolean",
|
|
20
|
+
"range",
|
|
21
|
+
"slug",
|
|
22
|
+
"relation"
|
|
23
|
+
]);
|
|
24
|
+
/**
|
|
25
|
+
* Whether a field takes a whole row where fields flow in columns, such as in a form without a
|
|
26
|
+
* layout or in a group: long inputs (a text area, rich text, blocks), several values, a value per
|
|
27
|
+
* locale, and the types of plugins. Short inputs share a row.
|
|
28
|
+
*/
|
|
29
|
+
function isWideField(field) {
|
|
30
|
+
if (field.localized === true || field.multiple === true) return true;
|
|
31
|
+
const widget = getSetting(field, "widget", isString);
|
|
32
|
+
if (field.type === "select" && widget !== void 0 && widget !== "dropdown") return true;
|
|
33
|
+
return !COMPACT_TYPES.has(field.type);
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { isWideField };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=flow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow.js","names":["Field","getSetting","isString","COMPACT_TYPES","Set","isWideField","field","localized","multiple","widget","type","undefined","has"],"sources":["../../src/shared/flow.ts"],"sourcesContent":["import type { Field } from '@panneau/protocol';\n\nimport { getSetting, isString } from './entry';\n\n/** Types whose input is short: they share a row with others in a flow of fields. */\nconst COMPACT_TYPES = new Set([\n 'text',\n 'email',\n 'url',\n 'tel',\n 'country',\n 'region',\n 'money',\n 'number',\n 'date',\n 'datetime',\n 'time',\n 'duration',\n 'color',\n 'select',\n 'boolean',\n 'range',\n 'slug',\n 'relation',\n]);\n\n/**\n * Whether a field takes a whole row where fields flow in columns, such as in a form without a\n * layout or in a group: long inputs (a text area, rich text, blocks), several values, a value per\n * locale, and the types of plugins. Short inputs share a row.\n */\nexport function isWideField(field: Field): boolean {\n if (field.localized === true || field.multiple === true) {\n return true;\n }\n const widget = getSetting(field, 'widget', isString);\n if (field.type === 'select' && widget !== undefined && widget !== 'dropdown') {\n return true;\n }\n return !COMPACT_TYPES.has(field.type);\n}\n"],"mappings":";;;AAKA,IAAMG,gCAAgB,IAAIC,IAAI;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAAU,CACb;;;;;;AAOD,SAAgBC,YAAYC,OAAuB;CAC/C,IAAIA,MAAMC,cAAc,QAAQD,MAAME,aAAa,MAC/C,OAAO;CAEX,MAAMC,SAASR,WAAWK,OAAO,UAAUJ,QAAQ;CACnD,IAAII,MAAMI,SAAS,YAAYD,WAAWE,KAAAA,KAAaF,WAAW,YAC9D,OAAO;CAEX,OAAO,CAACN,cAAcS,IAAIN,MAAMI,IAAI;AACxC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { Field } from '@panneau/protocol';
|
|
3
|
+
/** What a part of a value gets from the binding of the fields context: its errors and its blur. */
|
|
4
|
+
export interface BoundPartProps {
|
|
5
|
+
errors?: readonly string[];
|
|
6
|
+
onBlur?: () => void;
|
|
7
|
+
}
|
|
8
|
+
export interface PartBindingProps {
|
|
9
|
+
/** The part, as a field of the definition: the binding reads its errors by its path. */
|
|
10
|
+
field: Field;
|
|
11
|
+
/** Dot path of the part (`address.postalCode`). */
|
|
12
|
+
path: string;
|
|
13
|
+
/** Errors of the part without a binding. */
|
|
14
|
+
errors?: readonly string[];
|
|
15
|
+
/** Blur of the part without a binding. */
|
|
16
|
+
onBlur?: () => void;
|
|
17
|
+
render: (bound: BoundPartProps) => ReactNode;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A part of a value that a field edits itself (the postal code of an address, the URL of a link):
|
|
21
|
+
* the field keeps its whole value, and the binding of the fields context gives each part the
|
|
22
|
+
* errors of its own path, and marks it touched when it loses focus. Without a binding, the part
|
|
23
|
+
* gets `errors` and `onBlur`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function BoundPart({ field, path, errors, onBlur, render }: PartBindingProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null | undefined;
|
|
26
|
+
//# sourceMappingURL=part.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"part.d.ts","sourceRoot":"","sources":["../../src/shared/part.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAI/C,mGAAmG;AACnG,MAAM,WAAW,cAAc;IAC3B,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAC7B,wFAAwF;IACxF,KAAK,EAAE,KAAK,CAAC;IACb,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,SAAS,CAAC;CAChD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,gBAAgB,+TAqBlF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { getParentPath, useFieldsContext } from "./context.js";
|
|
2
|
+
import { c } from "react/compiler-runtime";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/shared/part.tsx
|
|
5
|
+
/**
|
|
6
|
+
* A part of a value that a field edits itself (the postal code of an address, the URL of a link):
|
|
7
|
+
* the field keeps its whole value, and the binding of the fields context gives each part the
|
|
8
|
+
* errors of its own path, and marks it touched when it loses focus. Without a binding, the part
|
|
9
|
+
* gets `errors` and `onBlur`.
|
|
10
|
+
*/
|
|
11
|
+
function BoundPart(t0) {
|
|
12
|
+
const $ = c(14);
|
|
13
|
+
const { field, path, errors, onBlur, render } = t0;
|
|
14
|
+
const { binding: Binding } = useFieldsContext();
|
|
15
|
+
if (Binding === null) {
|
|
16
|
+
let t1;
|
|
17
|
+
if ($[0] !== errors || $[1] !== onBlur || $[2] !== render) {
|
|
18
|
+
t1 = render({
|
|
19
|
+
...errors !== void 0 ? { errors } : {},
|
|
20
|
+
...onBlur !== void 0 ? { onBlur } : {}
|
|
21
|
+
});
|
|
22
|
+
$[0] = errors;
|
|
23
|
+
$[1] = onBlur;
|
|
24
|
+
$[2] = render;
|
|
25
|
+
$[3] = t1;
|
|
26
|
+
} else t1 = $[3];
|
|
27
|
+
return t1;
|
|
28
|
+
}
|
|
29
|
+
let t1;
|
|
30
|
+
if ($[4] !== path) {
|
|
31
|
+
t1 = getParentPath(path);
|
|
32
|
+
$[4] = path;
|
|
33
|
+
$[5] = t1;
|
|
34
|
+
} else t1 = $[5];
|
|
35
|
+
let t2;
|
|
36
|
+
if ($[6] !== render) {
|
|
37
|
+
t2 = (bound) => render({
|
|
38
|
+
...bound.errors !== void 0 ? { errors: bound.errors } : {},
|
|
39
|
+
...bound.onBlur !== void 0 ? { onBlur: bound.onBlur } : {}
|
|
40
|
+
});
|
|
41
|
+
$[6] = render;
|
|
42
|
+
$[7] = t2;
|
|
43
|
+
} else t2 = $[7];
|
|
44
|
+
let t3;
|
|
45
|
+
if ($[8] !== Binding || $[9] !== field || $[10] !== path || $[11] !== t1 || $[12] !== t2) {
|
|
46
|
+
t3 = /* @__PURE__ */ jsx(Binding, {
|
|
47
|
+
field,
|
|
48
|
+
path,
|
|
49
|
+
parentPath: t1,
|
|
50
|
+
render: t2
|
|
51
|
+
});
|
|
52
|
+
$[8] = Binding;
|
|
53
|
+
$[9] = field;
|
|
54
|
+
$[10] = path;
|
|
55
|
+
$[11] = t1;
|
|
56
|
+
$[12] = t2;
|
|
57
|
+
$[13] = t3;
|
|
58
|
+
} else t3 = $[13];
|
|
59
|
+
return t3;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { BoundPart };
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=part.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"part.js","names":["ReactNode","Field","getParentPath","useFieldsContext","BoundPartProps","errors","onBlur","PartBindingProps","field","path","render","bound","BoundPart","t0","$","_c","binding","Binding","t1","undefined","t2","t3","_c"],"sources":["../../src/shared/part.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport type { Field } from '@panneau/protocol';\n\nimport { getParentPath, useFieldsContext } from './context';\n\n/** What a part of a value gets from the binding of the fields context: its errors and its blur. */\nexport interface BoundPartProps {\n errors?: readonly string[];\n onBlur?: () => void;\n}\n\nexport interface PartBindingProps {\n /** The part, as a field of the definition: the binding reads its errors by its path. */\n field: Field;\n /** Dot path of the part (`address.postalCode`). */\n path: string;\n /** Errors of the part without a binding. */\n errors?: readonly string[];\n /** Blur of the part without a binding. */\n onBlur?: () => void;\n render: (bound: BoundPartProps) => ReactNode;\n}\n\n/**\n * A part of a value that a field edits itself (the postal code of an address, the URL of a link):\n * the field keeps its whole value, and the binding of the fields context gives each part the\n * errors of its own path, and marks it touched when it loses focus. Without a binding, the part\n * gets `errors` and `onBlur`.\n */\nexport function BoundPart({ field, path, errors, onBlur, render }: PartBindingProps) {\n const { binding: Binding } = useFieldsContext();\n if (Binding === null) {\n return render({\n ...(errors !== undefined ? { errors } : {}),\n ...(onBlur !== undefined ? { onBlur } : {}),\n });\n }\n return (\n <Binding\n field={field}\n path={path}\n parentPath={getParentPath(path)}\n render={(bound) =>\n render({\n ...(bound.errors !== undefined ? { errors: bound.errors } : {}),\n ...(bound.onBlur !== undefined ? { onBlur: bound.onBlur } : {}),\n })\n }\n />\n );\n}\n"],"mappings":";;;;;;;;;;AA8BA,SAAOY,UAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAmB,MAAA,EAAAP,OAAAC,MAAAJ,QAAAC,QAAAI,WAAAG;CACtB,MAAA,EAAAG,SAAAC,YAA6Bd,iBAAiB;CAC9C,IAAIc,YAAY,MAAI;EAAA,IAAAC;EAAA,IAAAJ,EAAA,OAAAT,UAAAS,EAAA,OAAAR,UAAAQ,EAAA,OAAAJ,QAAA;GACTQ,KAAAR,OAAO;IAAA,GACNL,WAAWc,KAAAA,IAAX,EAAAd,OAAqC,IAArC,CAAqC;IAAC,GACtCC,WAAWa,KAAAA,IAAX,EAAAb,OAAqC,IAArC,CAAqC;GAC7C,CAAC;GAACQ,EAAA,KAAAT;GAAAS,EAAA,KAAAR;GAAAQ,EAAA,KAAAJ;GAAAI,EAAA,KAAAI;EAAA,OAAAA,KAAAJ,EAAA;EAAA,OAHKI;CAGL;CACL,IAAAA;CAAA,IAAAJ,EAAA,OAAAL,MAAA;EAKmBS,KAAAhB,cAAcO,IAAI;EAACK,EAAA,KAAAL;EAAAK,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAAA,IAAAM;CAAA,IAAAN,EAAA,OAAAJ,QAAA;EACvBU,MAAAT,UACJD,OAAO;GAAA,GACCC,MAAKN,WAAYc,KAAAA,IAAjB,EAAAd,QAAuCM,MAAKN,OAAa,IAAzD,CAAyD;GAAC,GAC1DM,MAAKL,WAAYa,KAAAA,IAAjB,EAAAb,QAAuCK,MAAKL,OAAa,IAAzD,CAAyD;EACjE,CAAC;EAACQ,EAAA,KAAAJ;EAAAI,EAAA,KAAAM;CAAA,OAAAA,KAAAN,EAAA;CAAA,IAAAO;CAAA,IAAAP,EAAA,OAAAG,WAAAH,EAAA,OAAAN,SAAAM,EAAA,QAAAL,QAAAK,EAAA,QAAAI,MAAAJ,EAAA,QAAAM,IAAA;EARVC,KAAA,oBAAC,SAAD;GACWb;GACDC;GACM,YAAAS;GACJ,QAAAE;EAIF,CAAA;EAERN,EAAA,KAAAG;EAAAH,EAAA,KAAAN;EAAAM,EAAA,MAAAL;EAAAK,EAAA,MAAAI;EAAAJ,EAAA,MAAAM;EAAAN,EAAA,MAAAO;CAAA,OAAAA,KAAAP,EAAA;CAAA,OAVFO;AAUE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relation.js","names":["id","active","reference","_c"],"sources":["../../src/shared/relation.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { Definition, Item, ListQuery } from '@panneau/protocol';\n\n/** A related item: its id, and a label to show it. The value of a relation field. */\nexport interface RelationReference {\n id: string;\n label: string;\n}\n\n/** Where relation fields search for items. */\nexport interface RelationSource {\n /** Items of a resource that match a text, for the picker. */\n search(\n resource: string,\n query: string,\n options: { signal: AbortSignal },\n ): Promise<RelationReference[]>;\n /**\n * The references of items by id, for values that are only ids (`\"12\"`, `[\"12\", \"13\"]`), as a\n * product's own API gives them. In any order; ids it doesn't find are left out, and keep their\n * id as label. Without it, fields show the ids.\n */\n resolve?(\n resource: string,\n ids: readonly string[],\n options: { signal: AbortSignal },\n ): Promise<RelationReference[]>;\n /**\n * Creates an item from the text typed in the picker, which offers \"Create “…”\" when this\n * method exists. It can open a dialog, and resolves with the reference of the new item, or with\n * `null` when nothing was created.\n */\n create?(resource: string, text: string): Promise<RelationReference | null>;\n /** Whether `create()` can create items of a resource. Defaults to true. */\n canCreate?(resource: string): boolean;\n}\n\n/** What `createRelationSource()` needs from an adapter: the `list()`, `get()` and `create()` of `@panneau/data`. */\nexport interface RelationListAdapter {\n list(\n resource: string,\n query?: ListQuery,\n options?: { signal?: AbortSignal },\n ): Promise<{ data: Item[] }>;\n /** One item, for `resolve()`. Without it, the source doesn't resolve ids. */\n get?(resource: string, id: string, options?: { signal?: AbortSignal }): Promise<Item>;\n /** Creates an item, for `create()`. */\n create?(resource: string, values: Record<string, unknown>): Promise<Item>;\n}\n\nexport interface RelationSourceOptions {\n /** The definition, for the field that titles the items of each resource (`itemTitle`). */\n definition?: (Pick<Definition, 'resources'> & Partial<Pick<Definition, 'locales'>>) | null;\n /** Items per search. Defaults to 20. */\n perPage?: number;\n /** The label of an item, when `itemTitle` isn't enough. */\n getLabel?: (item: Item, resource: string) => string;\n /**\n * Lets the picker create items, with the adapter's `create()`. `true` sets the typed text as the\n * value of the resource's `itemTitle` field (in every locale of the definition when it is\n * localized), on the resources that allow `create`. A function gives the values of the new item\n * instead, or `null` for a resource where items can't be created.\n */\n create?: boolean | ((text: string, resource: string) => Record<string, unknown> | null);\n}\n\nfunction labelOf(value: unknown, locale?: string): string | null {\n if (typeof value === 'string' || typeof value === 'number') {\n return String(value);\n }\n if (value !== null && typeof value === 'object') {\n const localized = value as Record<string, unknown>;\n const first =\n (locale !== undefined ? localized[locale] : undefined) ?? Object.values(localized)[0];\n return typeof first === 'string' ? first : null;\n }\n return null;\n}\n\n/**\n * A relation source over an adapter, such as the `DataAdapter` of `@panneau/data`: a search is a\n * list query with `q`, ids are resolved with `get()`, and, with the `create` option, items are\n * created with `create()`. Labels come from the resource's `itemTitle`.\n */\nexport function createRelationSource(\n adapter: RelationListAdapter,\n { definition = null, perPage = 20, getLabel, create }: RelationSourceOptions = {},\n): RelationSource {\n const resourceOf = (resource: string) =>\n definition?.resources.find((candidate) => candidate.id === resource);\n const toReference = (item: Item, resource: string): RelationReference => {\n const titleField = resourceOf(resource)?.itemTitle;\n return {\n id: item.id,\n label:\n getLabel?.(item, resource) ??\n (titleField !== undefined ? labelOf(item[titleField]) : null) ??\n item.id,\n };\n };\n const valuesOf = (text: string, resource: string): Record<string, unknown> | null => {\n if (typeof create === 'function') {\n return create(text, resource);\n }\n const definitionResource = resourceOf(resource);\n const titleField = definitionResource?.itemTitle;\n if (definitionResource === undefined || titleField === undefined) {\n return null;\n }\n const field = definitionResource.fields.find((candidate) => candidate.name === titleField);\n const locales = definition?.locales ?? [];\n return {\n [titleField]:\n field?.localized === true && locales.length > 0\n ? Object.fromEntries(locales.map((locale) => [locale, text]))\n : text,\n };\n };\n const source: RelationSource = {\n async search(resource, query, { signal }) {\n const response = await adapter.list(\n resource,\n { page: 1, perPage, ...(query !== '' ? { q: query } : {}) },\n { signal },\n );\n return response.data.map((item) => toReference(item, resource));\n },\n };\n const { get, create: createItem } = adapter;\n if (get !== undefined) {\n source.resolve = async (resource, ids, { signal }) => {\n const results = await Promise.allSettled(\n ids.map((id) => get.call(adapter, resource, id, { signal })),\n );\n return results.flatMap((result) =>\n result.status === 'fulfilled' ? [toReference(result.value, resource)] : [],\n );\n };\n }\n if (create !== undefined && create !== false && createItem !== undefined) {\n source.canCreate = (resource) =>\n resourceOf(resource)?.abilities?.create !== false && valuesOf('', resource) !== null;\n source.create = async (resource, text) => {\n const values = valuesOf(text, resource);\n if (values === null) {\n return null;\n }\n return toReference(await createItem.call(adapter, resource, values), resource);\n };\n }\n return source;\n}\n\n/** Reads relation values: references, ids, or lists of them. */\nexport function toReferences(value: unknown): RelationReference[] {\n const list = Array.isArray(value)\n ? value\n : value === null || value === undefined\n ? []\n : [value];\n return list.flatMap((entry: unknown) => {\n if (typeof entry === 'string' || typeof entry === 'number') {\n return [{ id: String(entry), label: String(entry) }];\n }\n if (entry !== null && typeof entry === 'object' && 'id' in entry) {\n const { id, label } = entry as { id: unknown; label?: unknown };\n if (typeof id === 'string' || typeof id === 'number') {\n return [{ id: String(id), label: typeof label === 'string' ? label : String(id) }];\n }\n }\n return [];\n });\n}\n\ninterface ResolvedLabels {\n /** Labels by resource and id: `null` for ids that the source didn't find. */\n labels: Map<string, string | null>;\n /** Requests in flight, so that fields with the same ids share one. */\n pending: Map<string, Promise<void>>;\n}\n\nconst resolved = new WeakMap<RelationSource, ResolvedLabels>();\n\nfunction resolvedOf(source: RelationSource): ResolvedLabels {\n let entry = resolved.get(source);\n if (entry === undefined) {\n entry = { labels: new Map(), pending: new Map() };\n resolved.set(source, entry);\n }\n return entry;\n}\n\nconst keyOf = (resource: string, id: string) => `${resource}\\u0000${id}`;\n\n/** Resolves the ids that no request has resolved or is resolving yet, and waits for all of them. */\nfunction resolveIds(source: RelationSource, resource: string, ids: readonly string[]) {\n const { labels, pending } = resolvedOf(source);\n const fresh = ids.filter((id) => !pending.has(keyOf(resource, id)));\n if (fresh.length > 0 && source.resolve !== undefined) {\n // Shared by every field that asks for these ids: it isn't aborted when one unmounts.\n const request = source\n .resolve(resource, fresh, { signal: new AbortController().signal })\n .then(\n (found) => {\n fresh.forEach((id) =>\n labels.set(\n keyOf(resource, id),\n found.find((candidate) => candidate.id === id)?.label ?? null,\n ),\n );\n },\n () => {\n // Tried again the next time a field shows these ids.\n fresh.forEach((id) => pending.delete(keyOf(resource, id)));\n },\n );\n fresh.forEach((id) => pending.set(keyOf(resource, id), request));\n }\n return Promise.all(ids.map((id) => pending.get(keyOf(resource, id))));\n}\n\n/**\n * Relation references with the labels of plain ids: references whose label is their id (from\n * `\"12\"`) are resolved with the source's `resolve()`, once per source, resource and id. They keep\n * their id as label until then, or when the source doesn't find them.\n */\nexport function useRelationReferences(\n source: RelationSource | null,\n resource: string,\n references: readonly RelationReference[],\n): RelationReference[] {\n const cache = source !== null ? resolvedOf(source).labels : null;\n const [labels, setLabels] = useState<Readonly<Record<string, string>>>({});\n const label = (id: string): string | undefined =>\n labels[keyOf(resource, id)] ?? cache?.get(keyOf(resource, id)) ?? undefined;\n const missing =\n source?.resolve !== undefined && cache !== null\n ? references\n .filter((reference) => reference.label === reference.id)\n .map((reference) => reference.id)\n .filter((id) => !cache.has(keyOf(resource, id)))\n : [];\n const missingKey = missing.join('\\u0000');\n\n useEffect(() => {\n const ids = missingKey === '' ? [] : missingKey.split('\\u0000');\n if (source === null || cache === null || ids.length === 0) {\n return undefined;\n }\n let active = true;\n void resolveIds(source, resource, ids).then(() => {\n if (!active) {\n return;\n }\n const next: Record<string, string> = {};\n ids.forEach((id) => {\n const found = cache.get(keyOf(resource, id));\n if (typeof found === 'string') {\n next[keyOf(resource, id)] = found;\n }\n });\n setLabels((current) => ({ ...current, ...next }));\n });\n return () => {\n active = false;\n };\n }, [source, cache, resource, missingKey]);\n\n return references.map((reference) =>\n reference.label === reference.id\n ? { id: reference.id, label: label(reference.id) ?? reference.id }\n : reference,\n );\n}\n"],"mappings":";;;AAmEA,SAAS,QAAQ,OAAgB,QAAgC;CAC7D,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,UAC9C,OAAO,OAAO,KAAK;CAEvB,IAAI,UAAU,QAAQ,OAAO,UAAU,UAAU;EAC7C,MAAM,YAAY;EAClB,MAAM,SACD,WAAW,KAAA,IAAY,UAAU,UAAU,KAAA,MAAc,OAAO,OAAO,SAAS,CAAC,CAAC;EACvF,OAAO,OAAO,UAAU,WAAW,QAAQ;CAC/C;CACA,OAAO;AACX;;;;;;AAOA,SAAgB,qBACZ,SACA,EAAE,aAAa,MAAM,UAAU,IAAI,UAAU,WAAkC,CAAC,GAClE;CACd,MAAM,cAAc,aAChB,YAAY,UAAU,MAAM,cAAc,UAAU,OAAO,QAAQ;CACvE,MAAM,eAAe,MAAY,aAAwC;EACrE,MAAM,aAAa,WAAW,QAAQ,CAAC,EAAE;EACzC,OAAO;GACH,IAAI,KAAK;GACT,OACI,WAAW,MAAM,QAAQ,MACxB,eAAe,KAAA,IAAY,QAAQ,KAAK,WAAW,IAAI,SACxD,KAAK;EACb;CACJ;CACA,MAAM,YAAY,MAAc,aAAqD;EACjF,IAAI,OAAO,WAAW,YAClB,OAAO,OAAO,MAAM,QAAQ;EAEhC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M;GACxC,IAAI,CAAC,QAAM;GAGX,MAAA,OAAqC,CAAC;GACtC,IAAG,SAAS,SAAA;IACR,MAAA,QAAc,MAAK,IAAK,MAAM,UAAUA,IAAE,CAAC;IAC3C,IAAI,OAAO,UAAU,UACjB,KAAK,MAAM,UAAUA,IAAE,KAAK;GAC/B,CACJ;GACD,WAAU,aAAc;IAAA,GAAK;IAAO,GAAK;GAAK,EAAE;EAAC,CACpD;EAAC,aACK;GACH,SAASC;EAAH;CACT,GACF;EAAC;EAAQ;EAAO;EAAU;CAAU,CAAC;CAAC,OAElC,WAAU,KAAK,gBAClBC,YAAS,UAAWA,YAAS,KAA7B;EAAA,IACYA,YAAS;EAAG,OAAS,MAAMA,YAAS,EAAmB,KAAXA,YAAS;CACnD,IAFd,WAGJ;AAAC;AA9CE,SAAA,OAAA,aAAA;CAAA,OAa+BA,YAAS;AAAG;AAb3C,SAAA,MAAA,WAAA;CAAA,OAYkC,UAAS,UAAW,UAAS;AAAG"}
|
|
1
|
+
{"version":3,"file":"relation.js","names":["useEffect","useState","Definition","Item","ListQuery","RelationReference","id","label","RelationSource","search","resource","query","options","signal","AbortSignal","Promise","resolve","ids","create","text","canCreate","RelationListAdapter","list","data","get","values","Record","RelationSourceOptions","definition","Pick","Partial","perPage","getLabel","item","labelOf","value","locale","String","localized","first","undefined","Object","createRelationSource","adapter","resourceOf","resources","find","candidate","toReference","titleField","itemTitle","valuesOf","definitionResource","field","fields","name","locales","length","fromEntries","map","source","response","page","q","createItem","results","allSettled","call","flatMap","result","status","abilities","toReferences","Array","isArray","entry","ResolvedLabels","labels","Map","pending","resolved","WeakMap","resolvedOf","set","keyOf","resolveIds","fresh","filter","has","request","AbortController","then","found","forEach","delete","all","useRelationReferences","references","$","_c","cache","t0","Symbol","for","setLabels","missing","_temp","_temp2","id_0","missingKey","join","split","active","next","id_1","current","reference_1","reference","reference_0","_c"],"sources":["../../src/shared/relation.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { Definition, Item, ListQuery } from '@panneau/protocol';\n\n/** A related item: its id, and a label to show it. The value of a relation field. */\nexport interface RelationReference {\n id: string;\n label: string;\n}\n\n/** Where relation fields search for items. */\nexport interface RelationSource {\n /** Items of a resource that match a text, for the picker. */\n search(\n resource: string,\n query: string,\n options: { signal: AbortSignal },\n ): Promise<RelationReference[]>;\n /**\n * The references of items by id, for values that are only ids (`\"12\"`, `[\"12\", \"13\"]`), as a\n * product's own API gives them. In any order; ids it doesn't find are left out, and keep their\n * id as label. Without it, fields show the ids.\n */\n resolve?(\n resource: string,\n ids: readonly string[],\n options: { signal: AbortSignal },\n ): Promise<RelationReference[]>;\n /**\n * Creates an item from the text typed in the picker, which offers \"Create “…”\" when this\n * method exists. It can open a dialog, and resolves with the reference of the new item, or with\n * `null` when nothing was created.\n */\n create?(resource: string, text: string): Promise<RelationReference | null>;\n /** Whether `create()` can create items of a resource. Defaults to true. */\n canCreate?(resource: string): boolean;\n}\n\n/** What `createRelationSource()` needs from an adapter: the `list()`, `get()` and `create()` of `@panneau/data`. */\nexport interface RelationListAdapter {\n list(\n resource: string,\n query?: ListQuery,\n options?: { signal?: AbortSignal },\n ): Promise<{ data: Item[] }>;\n /** One item, for `resolve()`. Without it, the source doesn't resolve ids. */\n get?(resource: string, id: string, options?: { signal?: AbortSignal }): Promise<Item>;\n /** Creates an item, for `create()`. */\n create?(resource: string, values: Record<string, unknown>): Promise<Item>;\n}\n\nexport interface RelationSourceOptions {\n /** The definition, for the field that titles the items of each resource (`itemTitle`). */\n definition?: (Pick<Definition, 'resources'> & Partial<Pick<Definition, 'locales'>>) | null;\n /** Items per search. Defaults to 20. */\n perPage?: number;\n /** The label of an item, when `itemTitle` isn't enough. */\n getLabel?: (item: Item, resource: string) => string;\n /**\n * Lets the picker create items, with the adapter's `create()`. `true` sets the typed text as the\n * value of the resource's `itemTitle` field (in every locale of the definition when it is\n * localized), on the resources that allow `create`. A function gives the values of the new item\n * instead, or `null` for a resource where items can't be created.\n */\n create?: boolean | ((text: string, resource: string) => Record<string, unknown> | null);\n}\n\nfunction labelOf(value: unknown, locale?: string): string | null {\n if (typeof value === 'string' || typeof value === 'number') {\n return String(value);\n }\n if (value !== null && typeof value === 'object') {\n const localized = value as Record<string, unknown>;\n const first =\n (locale !== undefined ? localized[locale] : undefined) ?? Object.values(localized)[0];\n return typeof first === 'string' ? first : null;\n }\n return null;\n}\n\n/**\n * A relation source over an adapter, such as the `DataAdapter` of `@panneau/data`: a search is a\n * list query with `q`, ids are resolved with `get()`, and, with the `create` option, items are\n * created with `create()`. Labels come from the resource's `itemTitle`.\n */\nexport function createRelationSource(\n adapter: RelationListAdapter,\n { definition = null, perPage = 20, getLabel, create }: RelationSourceOptions = {},\n): RelationSource {\n const resourceOf = (resource: string) =>\n definition?.resources.find((candidate) => candidate.id === resource);\n const toReference = (item: Item, resource: string): RelationReference => {\n const titleField = resourceOf(resource)?.itemTitle;\n return {\n id: item.id,\n label:\n getLabel?.(item, resource) ??\n (titleField !== undefined ? labelOf(item[titleField]) : null) ??\n item.id,\n };\n };\n const valuesOf = (text: string, resource: string): Record<string, unknown> | null => {\n if (typeof create === 'function') {\n return create(text, resource);\n }\n const definitionResource = resourceOf(resource);\n const titleField = definitionResource?.itemTitle;\n if (definitionResource === undefined || titleField === undefined) {\n return null;\n }\n const field = definitionResource.fields.find((candidate) => candidate.name === titleField);\n const locales = definition?.locales ?? [];\n return {\n [titleField]:\n field?.localized === true && locales.length > 0\n ? Object.fromEntries(locales.map((locale) => [locale, text]))\n : text,\n };\n };\n const source: RelationSource = {\n async search(resource, query, { signal }) {\n const response = await adapter.list(\n resource,\n { page: 1, perPage, ...(query !== '' ? { q: query } : {}) },\n { signal },\n );\n return response.data.map((item) => toReference(item, resource));\n },\n };\n const { get, create: createItem } = adapter;\n if (get !== undefined) {\n source.resolve = async (resource, ids, { signal }) => {\n const results = await Promise.allSettled(\n ids.map((id) => get.call(adapter, resource, id, { signal })),\n );\n return results.flatMap((result) =>\n result.status === 'fulfilled' ? [toReference(result.value, resource)] : [],\n );\n };\n }\n if (create !== undefined && create !== false && createItem !== undefined) {\n source.canCreate = (resource) =>\n resourceOf(resource)?.abilities?.create !== false && valuesOf('', resource) !== null;\n source.create = async (resource, text) => {\n const values = valuesOf(text, resource);\n if (values === null) {\n return null;\n }\n return toReference(await createItem.call(adapter, resource, values), resource);\n };\n }\n return source;\n}\n\n/** Reads relation values: references, ids, or lists of them. */\nexport function toReferences(value: unknown): RelationReference[] {\n const list = Array.isArray(value)\n ? value\n : value === null || value === undefined\n ? []\n : [value];\n return list.flatMap((entry: unknown) => {\n if (typeof entry === 'string' || typeof entry === 'number') {\n return [{ id: String(entry), label: String(entry) }];\n }\n if (entry !== null && typeof entry === 'object' && 'id' in entry) {\n const { id, label } = entry as { id: unknown; label?: unknown };\n if (typeof id === 'string' || typeof id === 'number') {\n return [{ id: String(id), label: typeof label === 'string' ? label : String(id) }];\n }\n }\n return [];\n });\n}\n\ninterface ResolvedLabels {\n /** Labels by resource and id: `null` for ids that the source didn't find. */\n labels: Map<string, string | null>;\n /** Requests in flight, so that fields with the same ids share one. */\n pending: Map<string, Promise<void>>;\n}\n\nconst resolved = new WeakMap<RelationSource, ResolvedLabels>();\n\nfunction resolvedOf(source: RelationSource): ResolvedLabels {\n let entry = resolved.get(source);\n if (entry === undefined) {\n entry = { labels: new Map(), pending: new Map() };\n resolved.set(source, entry);\n }\n return entry;\n}\n\nconst keyOf = (resource: string, id: string) => `${resource}\\u0000${id}`;\n\n/** Resolves the ids that no request has resolved or is resolving yet, and waits for all of them. */\nfunction resolveIds(source: RelationSource, resource: string, ids: readonly string[]) {\n const { labels, pending } = resolvedOf(source);\n const fresh = ids.filter((id) => !pending.has(keyOf(resource, id)));\n if (fresh.length > 0 && source.resolve !== undefined) {\n // Shared by every field that asks for these ids: it isn't aborted when one unmounts.\n const request = source\n .resolve(resource, fresh, { signal: new AbortController().signal })\n .then(\n (found) => {\n fresh.forEach((id) =>\n labels.set(\n keyOf(resource, id),\n found.find((candidate) => candidate.id === id)?.label ?? null,\n ),\n );\n },\n () => {\n // Tried again the next time a field shows these ids.\n fresh.forEach((id) => pending.delete(keyOf(resource, id)));\n },\n );\n fresh.forEach((id) => pending.set(keyOf(resource, id), request));\n }\n return Promise.all(ids.map((id) => pending.get(keyOf(resource, id))));\n}\n\n/**\n * Relation references with the labels of plain ids: references whose label is their id (from\n * `\"12\"`) are resolved with the source's `resolve()`, once per source, resource and id. They keep\n * their id as label until then, or when the source doesn't find them.\n */\nexport function useRelationReferences(\n source: RelationSource | null,\n resource: string,\n references: readonly RelationReference[],\n): RelationReference[] {\n const cache = source !== null ? resolvedOf(source).labels : null;\n const [labels, setLabels] = useState<Readonly<Record<string, string>>>({});\n const label = (id: string): string | undefined =>\n labels[keyOf(resource, id)] ?? cache?.get(keyOf(resource, id)) ?? undefined;\n const missing =\n source?.resolve !== undefined && cache !== null\n ? references\n .filter((reference) => reference.label === reference.id)\n .map((reference) => reference.id)\n .filter((id) => !cache.has(keyOf(resource, id)))\n : [];\n const missingKey = missing.join('\\u0000');\n\n useEffect(() => {\n const ids = missingKey === '' ? [] : missingKey.split('\\u0000');\n if (source === null || cache === null || ids.length === 0) {\n return undefined;\n }\n let active = true;\n void resolveIds(source, resource, ids).then(() => {\n if (!active) {\n return;\n }\n const next: Record<string, string> = {};\n ids.forEach((id) => {\n const found = cache.get(keyOf(resource, id));\n if (typeof found === 'string') {\n next[keyOf(resource, id)] = found;\n }\n });\n setLabels((current) => ({ ...current, ...next }));\n });\n return () => {\n active = false;\n };\n }, [source, cache, resource, missingKey]);\n\n return references.map((reference) =>\n reference.label === reference.id\n ? { id: reference.id, label: label(reference.id) ?? reference.id }\n : reference,\n );\n}\n"],"mappings":";;;AAmEA,SAASkC,QAAQC,OAAgBC,QAAgC;CAC7D,IAAI,OAAOD,UAAU,YAAY,OAAOA,UAAU,UAC9C,OAAOE,OAAOF,KAAK;CAEvB,IAAIA,UAAU,QAAQ,OAAOA,UAAU,UAAU;EAC7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QlD,UAAUO,GAAG,CAAC,CAAA0E,WAAM;GACxC,IAAI,CAACqB,QAAM;GAGX,MAAAC,OAAqC,CAAC;GACtChG,IAAG4E,SAASqB,SAAA;IACR,MAAAtB,QAAcQ,MAAK5E,IAAK4D,MAAM1E,UAAUJ,IAAE,CAAC;IAC3C,IAAI,OAAOsF,UAAU,UACjBqB,KAAK7B,MAAM1E,UAAUJ,IAAE,KAAKsF;GAC/B,CACJ;GACDY,WAAUW,aAAc;IAAA,GAAKA;IAAO,GAAKF;GAAK,EAAE;EAAC,CACpD;EAAC,aACK;GACHD,SAASA;EAAH;CACT,GACF;EAACpD;EAAQwC;EAAO1F;EAAUmG;CAAU,CAAC;CAAC,OAElCZ,WAAUtC,KAAKyD,gBAClBC,YAAS9G,UAAW8G,YAAS/G,KAA7B;EAAAA,IACY+G,YAAS/G;EAAGC,OAASA,MAAM8G,YAAS/G,EAAmB,KAAX+G,YAAS/G;CACnD,IAFd8G,WAGJ;AAAC;AA9CE,SAAAT,OAAAW,aAAA;CAAA,OAa+BD,YAAS/G;AAAG;AAb3C,SAAAoG,MAAAW,WAAA;CAAA,OAYkCA,UAAS9G,UAAW8G,UAAS/G;AAAG"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Shows what holds a path, such as its tab or its locale, so that its field can be reached. */
|
|
2
|
+
export type Revealer = (path: string) => void;
|
|
3
|
+
/** Where a form asks the containers of its fields to show a path, before it focuses its field. */
|
|
4
|
+
export interface RevealRegistry {
|
|
5
|
+
add(revealer: Revealer): () => void;
|
|
6
|
+
reveal(path: string): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function createRevealRegistry(): RevealRegistry;
|
|
9
|
+
/**
|
|
10
|
+
* The reveal registry of the closest form. Containers that hide fields (tabs, sections, the
|
|
11
|
+
* locales of a localized field) add a revealer to it.
|
|
12
|
+
*/
|
|
13
|
+
export declare const RevealContext: import("react").Context<RevealRegistry>;
|
|
14
|
+
/** Calls the revealer when the form reveals a path, for as long as the component is mounted. */
|
|
15
|
+
export declare function useRevealer(revealer: Revealer): void;
|
|
16
|
+
//# sourceMappingURL=reveal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reveal.d.ts","sourceRoot":"","sources":["../../src/shared/reveal.ts"],"names":[],"mappings":"AAEA,gGAAgG;AAChG,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;AAE9C,kGAAkG;AAClG,MAAM,WAAW,cAAc;IAC3B,GAAG,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI,CAAC;IACpC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,wBAAgB,oBAAoB,IAAI,cAAc,CAarD;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,yCAAwD,CAAC;AAEnF,gGAAgG;AAChG,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAIpD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { c } from "react/compiler-runtime";
|
|
2
|
+
import { createContext, use, useEffect, useEffectEvent } from "react";
|
|
3
|
+
//#region src/shared/reveal.ts
|
|
4
|
+
function createRevealRegistry() {
|
|
5
|
+
const revealers = /* @__PURE__ */ new Set();
|
|
6
|
+
return {
|
|
7
|
+
add(revealer) {
|
|
8
|
+
revealers.add(revealer);
|
|
9
|
+
return () => {
|
|
10
|
+
revealers.delete(revealer);
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
reveal(path) {
|
|
14
|
+
revealers.forEach((revealer) => revealer(path));
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The reveal registry of the closest form. Containers that hide fields (tabs, sections, the
|
|
20
|
+
* locales of a localized field) add a revealer to it.
|
|
21
|
+
*/
|
|
22
|
+
var RevealContext = createContext(createRevealRegistry());
|
|
23
|
+
/** Calls the revealer when the form reveals a path, for as long as the component is mounted. */
|
|
24
|
+
function useRevealer(revealer) {
|
|
25
|
+
const $ = c(5);
|
|
26
|
+
const registry = use(RevealContext);
|
|
27
|
+
const onReveal = useEffectEvent(revealer);
|
|
28
|
+
let t0;
|
|
29
|
+
if ($[0] !== onReveal || $[1] !== registry) {
|
|
30
|
+
t0 = () => registry.add((path) => onReveal(path));
|
|
31
|
+
$[0] = onReveal;
|
|
32
|
+
$[1] = registry;
|
|
33
|
+
$[2] = t0;
|
|
34
|
+
} else t0 = $[2];
|
|
35
|
+
let t1;
|
|
36
|
+
if ($[3] !== registry) {
|
|
37
|
+
t1 = [registry];
|
|
38
|
+
$[3] = registry;
|
|
39
|
+
$[4] = t1;
|
|
40
|
+
} else t1 = $[4];
|
|
41
|
+
useEffect(t0, t1);
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { RevealContext, createRevealRegistry, useRevealer };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=reveal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reveal.js","names":["createContext","use","useEffect","useEffectEvent","Revealer","path","RevealRegistry","add","revealer","reveal","createRevealRegistry","revealers","Set","delete","forEach","RevealContext","useRevealer","$","_c","registry","onReveal","t0","t1","_c"],"sources":["../../src/shared/reveal.ts"],"sourcesContent":["import { createContext, use, useEffect, useEffectEvent } from 'react';\n\n/** Shows what holds a path, such as its tab or its locale, so that its field can be reached. */\nexport type Revealer = (path: string) => void;\n\n/** Where a form asks the containers of its fields to show a path, before it focuses its field. */\nexport interface RevealRegistry {\n add(revealer: Revealer): () => void;\n reveal(path: string): void;\n}\n\nexport function createRevealRegistry(): RevealRegistry {\n const revealers = new Set<Revealer>();\n return {\n add(revealer) {\n revealers.add(revealer);\n return () => {\n revealers.delete(revealer);\n };\n },\n reveal(path) {\n revealers.forEach((revealer) => revealer(path));\n },\n };\n}\n\n/**\n * The reveal registry of the closest form. Containers that hide fields (tabs, sections, the\n * locales of a localized field) add a revealer to it.\n */\nexport const RevealContext = createContext<RevealRegistry>(createRevealRegistry());\n\n/** Calls the revealer when the form reveals a path, for as long as the component is mounted. */\nexport function useRevealer(revealer: Revealer): void {\n const registry = use(RevealContext);\n const onReveal = useEffectEvent(revealer);\n useEffect(() => registry.add((path) => onReveal(path)), [registry]);\n}\n"],"mappings":";;;AAWA,SAAgBU,uBAAuC;CACnD,MAAMC,4BAAY,IAAIC,IAAc;CACpC,OAAO;EACHL,IAAIC,UAAU;GACVG,UAAUJ,IAAIC,QAAQ;GACtB,aAAa;IACTG,UAAUE,OAAOL,QAAQ;GAC7B;EACJ;EACAC,OAAOJ,MAAM;GACTM,UAAUG,SAASN,aAAaA,SAASH,IAAI,CAAC;EAClD;CACJ;AACJ;;;;;AAMA,IAAaU,gBAAgBf,cAA8BU,qBAAqB,CAAC;;AAGjF,SAAOM,YAAAR,UAAA;CAAA,MAAAS,IAAAC,EAAA,CAAA;CACH,MAAAC,WAAiBlB,IAAIc,aAAa;CAClC,MAAAK,WAAiBjB,eAAeK,QAAQ;CAAE,IAAAa;CAAA,IAAAJ,EAAA,OAAAG,YAAAH,EAAA,OAAAE,UAAA;EAChCE,WAAMF,SAAQZ,KAAKF,SAAUe,SAASf,IAAI,CAAC;EAACY,EAAA,KAAAG;EAAAH,EAAA,KAAAE;EAAAF,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAAA,IAAAK;CAAA,IAAAL,EAAA,OAAAE,UAAA;EAAEG,KAAA,CAACH,QAAQ;EAACF,EAAA,KAAAE;EAAAF,EAAA,KAAAK;CAAA,OAAAA,KAAAL,EAAA;CAAlEf,UAAUmB,IAA8CC,EAAU;AAAC"}
|