@wix/auto-patterns 1.22.0 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/cjs/hooks/useActionCell.js.map +1 -1
  2. package/dist/cjs/providers/PatternsWizardOverridesContext.js +1 -1
  3. package/dist/cjs/providers/PatternsWizardOverridesContext.js.map +1 -1
  4. package/dist/cjs/types/actions/base.js.map +1 -1
  5. package/dist/docs/app_config_structure.md +0 -3
  6. package/dist/docs/auto-patterns-guide.md +87 -22
  7. package/dist/docs/bulk_actions.md +1 -4
  8. package/dist/docs/custom_overrides.md +86 -15
  9. package/dist/esm/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.js +3 -4
  10. package/dist/esm/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.js.map +1 -1
  11. package/dist/esm/components/AutoPatternsCollectionPageContent/AutoPatternsCollectionPageContent.js +1 -2
  12. package/dist/esm/components/AutoPatternsCollectionPageContent/AutoPatternsCollectionPageContent.js.map +1 -1
  13. package/dist/esm/components/AutoPatternsEntityPage/AutoPatternsEntityPage.js +8 -13
  14. package/dist/esm/components/AutoPatternsEntityPage/AutoPatternsEntityPage.js.map +1 -1
  15. package/dist/esm/components/AutoPatternsEntityPage/Fields/DateInput.js +6 -10
  16. package/dist/esm/components/AutoPatternsEntityPage/Fields/DateInput.js.map +1 -1
  17. package/dist/esm/components/AutoPatternsEntityPage/Fields/DateTime.js +16 -23
  18. package/dist/esm/components/AutoPatternsEntityPage/Fields/DateTime.js.map +1 -1
  19. package/dist/esm/components/AutoPatternsEntityPage/Fields/FormFieldInput.js +2 -3
  20. package/dist/esm/components/AutoPatternsEntityPage/Fields/FormFieldInput.js.map +1 -1
  21. package/dist/esm/components/AutoPatternsEntityPage/Fields/ImageInput.js +6 -9
  22. package/dist/esm/components/AutoPatternsEntityPage/Fields/ImageInput.js.map +1 -1
  23. package/dist/esm/components/AutoPatternsEntityPage/Fields/LongText.js +6 -8
  24. package/dist/esm/components/AutoPatternsEntityPage/Fields/LongText.js.map +1 -1
  25. package/dist/esm/components/AutoPatternsEntityPage/Fields/Number.js +8 -10
  26. package/dist/esm/components/AutoPatternsEntityPage/Fields/Number.js.map +1 -1
  27. package/dist/esm/components/AutoPatternsEntityPage/Fields/ShortText.js +10 -12
  28. package/dist/esm/components/AutoPatternsEntityPage/Fields/ShortText.js.map +1 -1
  29. package/dist/esm/components/AutoPatternsEntityPage/Fields/Url.js +6 -8
  30. package/dist/esm/components/AutoPatternsEntityPage/Fields/Url.js.map +1 -1
  31. package/dist/esm/components/AutoPatternsEntityPage/SkeletonEntity.js +4 -7
  32. package/dist/esm/components/AutoPatternsEntityPage/SkeletonEntity.js.map +1 -1
  33. package/dist/esm/components/ModalRenderer.js +1 -2
  34. package/dist/esm/components/ModalRenderer.js.map +1 -1
  35. package/dist/esm/components/modals/actions/BulkDeleteModal.js +7 -12
  36. package/dist/esm/components/modals/actions/BulkDeleteModal.js.map +1 -1
  37. package/dist/esm/components/modals/actions/CreateModal.js +6 -11
  38. package/dist/esm/components/modals/actions/CreateModal.js.map +1 -1
  39. package/dist/esm/components/modals/actions/EditModal.js +6 -11
  40. package/dist/esm/components/modals/actions/EditModal.js.map +1 -1
  41. package/dist/esm/dataSourceAdapters/cms/cmsAdapter.js +3 -4
  42. package/dist/esm/dataSourceAdapters/cms/cmsAdapter.js.map +1 -1
  43. package/dist/esm/dataSourceAdapters/cms/filterUtils.js +1 -2
  44. package/dist/esm/dataSourceAdapters/cms/filterUtils.js.map +1 -1
  45. package/dist/esm/dataSourceAdapters/cms/sortUtils.js +2 -2
  46. package/dist/esm/dataSourceAdapters/cms/sortUtils.js.map +1 -1
  47. package/dist/esm/hooks/useActionCell.js +8 -12
  48. package/dist/esm/hooks/useActionCell.js.map +1 -1
  49. package/dist/esm/hooks/useBaseTableFeatures.js +1 -2
  50. package/dist/esm/hooks/useBaseTableFeatures.js.map +1 -1
  51. package/dist/esm/hooks/useBulkActionToolbar.js +2 -2
  52. package/dist/esm/hooks/useBulkActionToolbar.js.map +1 -1
  53. package/dist/esm/hooks/useCollectionPageActions.js +3 -3
  54. package/dist/esm/hooks/useCollectionPageActions.js.map +1 -1
  55. package/dist/esm/hooks/useCollectionPageOnRowClickActions.js +1 -1
  56. package/dist/esm/hooks/useCollectionPageOnRowClickActions.js.map +1 -1
  57. package/dist/esm/hooks/useColumns.js +7 -12
  58. package/dist/esm/hooks/useColumns.js.map +1 -1
  59. package/dist/esm/hooks/useCommonCollectionFeatures.js +7 -8
  60. package/dist/esm/hooks/useCommonCollectionFeatures.js.map +1 -1
  61. package/dist/esm/hooks/useEmptyStates.js +5 -6
  62. package/dist/esm/hooks/useEmptyStates.js.map +1 -1
  63. package/dist/esm/hooks/useFilters.js +7 -7
  64. package/dist/esm/hooks/useFilters.js.map +1 -1
  65. package/dist/esm/hooks/useNavigationUtils.js +2 -3
  66. package/dist/esm/hooks/useNavigationUtils.js.map +1 -1
  67. package/dist/esm/hooks/usePagePath.js +3 -4
  68. package/dist/esm/hooks/usePagePath.js.map +1 -1
  69. package/dist/esm/hooks/useTableFeatures.js +1 -2
  70. package/dist/esm/hooks/useTableFeatures.js.map +1 -1
  71. package/dist/esm/providers/PatternsWizardOverridesContext.js.map +1 -1
  72. package/dist/esm/providers/SchemaContext.js +2 -3
  73. package/dist/esm/providers/SchemaContext.js.map +1 -1
  74. package/dist/esm/providers/SchemaRegistryContext.js +1 -1
  75. package/dist/esm/providers/SchemaRegistryContext.js.map +1 -1
  76. package/dist/esm/types/actions/base.js.map +1 -1
  77. package/dist/esm/utils/actions/customAction.js +1 -2
  78. package/dist/esm/utils/actions/customAction.js.map +1 -1
  79. package/dist/esm/utils/actions/deleteAction.js +5 -10
  80. package/dist/esm/utils/actions/deleteAction.js.map +1 -1
  81. package/dist/esm/utils/filterCreators.js +11 -11
  82. package/dist/esm/utils/filterCreators.js.map +1 -1
  83. package/dist/types/providers/PatternsWizardOverridesContext.d.ts +2 -5
  84. package/dist/types/providers/PatternsWizardOverridesContext.d.ts.map +1 -1
  85. package/dist/types/types/actions/base.d.ts +0 -4
  86. package/dist/types/types/actions/base.d.ts.map +1 -1
  87. package/package.json +10 -10
@@ -1 +1 @@
1
- {"version":3,"names":["React","useMemo","useRef","EntityPage","useEntity","useEntityPage","useEntityPageContext","MoreActions","useForm","Card","Cell","Layout","useParams","useSchema","FormFieldInput","useEntityPageHeaderTexts","useNavigation","usePatternsWizardOverridesContext","useEntityPageMoreActions","useActionsSDK","RenderLayoutContent","_ref","_content$container$ch","_overrides$components","content","level","sectionId","cardIndex","contentIndex","setInputRef","schema","overrides","pageState","type","field","fieldId","fields","createElement","span","key","inputRef","ref","container","children","length","map","child","index","component","componentId","Component","components","form","entity","RenderLayoutCard","_ref2","_layout$card$subtitle","layout","minHeight","Header","title","card","text","subtitle","Divider","Content","AutoPatternsEntityPage","_ref3","_pageLayout$main","_pageLayout$sidebar","configuration","pageLayout","parentPageId","route","moreActions","collectionId","mode","params","entityId","id","isCreateMode","inputRefs","input","current","validate","invalidFieldId","Object","keys","find","_inputRefs$current$fi","invalid","_inputRefs$current$in","focus","Error","getParentPagePath","parentPath","state","onSave","formValues","getValues","baseEntity","updatedEntity","newEntity","actions","update","create","fetch","undefined","get","config","entityDisplayName","displayField","sdk","resolvedMoreActions","dataHook","items","MainContent","main","layoutIndex","sidebar","AdditionalContent"],"sources":["../../../../src/components/AutoPatternsEntityPage/AutoPatternsEntityPage.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport { CardLayout, EntityPageConfig, LayoutContent } from '../../types';\nimport {\n EntityPage,\n EntityPageState,\n useEntity,\n useEntityPage,\n useEntityPageContext,\n MoreActions,\n} from '@wix/patterns';\nimport { useForm } from '@wix/patterns/form';\nimport { Card, Cell, Layout } from '@wix/design-system';\nimport { useParams } from 'react-router-dom';\nimport { useSchema } from '../../providers/SchemaContext';\nimport { BaseInputRef } from './Fields/types';\nimport { FormFieldInput } from './Fields/FormFieldInput';\nimport { useEntityPageHeaderTexts, useNavigation } from '../../hooks';\nimport { usePatternsWizardOverridesContext } from '../../providers';\nimport { useEntityPageMoreActions } from '../../hooks/useEntityPageMoreActions';\nimport { useActionsSDK } from '../../hooks/useActionsSDK';\n\nconst RenderLayoutContent: React.FC<{\n content: LayoutContent;\n level: number;\n sectionId: string;\n cardIndex: number;\n contentIndex: number;\n setInputRef: (id: string, input: BaseInputRef) => void;\n}> = ({ content, level, sectionId, cardIndex, contentIndex, setInputRef }) => {\n const schema = useSchema();\n const overrides = usePatternsWizardOverridesContext();\n const pageState = useEntityPageContext();\n\n switch (content.type) {\n case 'field':\n if (!content.field.fieldId) {\n return null;\n }\n\n const field = schema.fields[content.field.fieldId];\n\n if (!field) {\n return null;\n }\n\n return (\n <Cell span={content.field.span}>\n <FormFieldInput\n key={content.field.fieldId}\n field={field}\n inputRef={(ref) => setInputRef(content.field.fieldId, ref)}\n />\n </Cell>\n );\n\n case 'container':\n if (!content.container.children?.length) {\n return null;\n }\n\n return (\n <Cell span={content.container.span}>\n <Layout>\n {content.container.children.map((child, index) => (\n <RenderLayoutContent\n key={`${sectionId}-card-${cardIndex}-content-${contentIndex}-level-${level}-child-${index}`}\n content={child}\n level={level + 1}\n sectionId={sectionId}\n cardIndex={cardIndex}\n contentIndex={index}\n setInputRef={setInputRef}\n />\n ))}\n </Layout>\n </Cell>\n );\n\n case 'component':\n if (!content.component.componentId) {\n return null;\n }\n\n const Component = overrides?.components?.[content.component.componentId];\n\n if (!Component) {\n return null;\n }\n\n return (\n <Cell span={content.component.span}>\n <Component\n form={pageState.form as any}\n entity={pageState.entity as any as Record<string, any>}\n />\n </Cell>\n );\n\n default:\n return null;\n }\n};\n\nconst RenderLayoutCard: React.FC<{\n layout: CardLayout;\n sectionId: string;\n cardIndex: number;\n setInputRef: (id: string, input: BaseInputRef) => void;\n}> = ({ layout, sectionId, cardIndex, setInputRef }) => {\n switch (layout.type) {\n case 'card':\n return (\n <EntityPage.Card minHeight=\"50px\">\n <Card.Header\n title={layout.card.title.text}\n subtitle={layout.card.subtitle?.text}\n />\n <Card.Divider />\n <Card.Content>\n <Layout>\n {layout.card.children.map((child, index: number) => (\n <RenderLayoutContent\n key={`${sectionId}-card-${cardIndex}-content-${index}`}\n content={child}\n level={0}\n sectionId={sectionId}\n cardIndex={cardIndex}\n contentIndex={index}\n setInputRef={setInputRef}\n />\n ))}\n </Layout>\n </Card.Content>\n </EntityPage.Card>\n );\n default:\n return null;\n }\n};\n\nexport interface AutoPatternsEntityPageProps {\n configuration: EntityPageConfig;\n}\n\nexport const AutoPatternsEntityPage: React.FC<AutoPatternsEntityPageProps> = ({\n configuration,\n}) => {\n const {\n layout: pageLayout,\n parentPageId,\n route,\n moreActions,\n collectionId,\n } = configuration;\n\n const form = useForm<any>({\n mode: 'onChange',\n });\n const params = useParams();\n const entityId = params[route.params.id];\n const schema = useSchema();\n const isCreateMode = !entityId;\n\n const inputRefs = useRef<{ [fieldId: string]: BaseInputRef }>({});\n\n const setInputRef = (id: string, input: BaseInputRef) => {\n inputRefs.current[id] = input;\n };\n\n const validate = () => {\n const invalidFieldId = Object.keys(inputRefs.current).find((fieldId) => {\n return inputRefs.current[fieldId]?.invalid;\n });\n\n if (invalidFieldId) {\n inputRefs.current[invalidFieldId]?.focus?.();\n throw new Error('Invalid form');\n }\n };\n const { getParentPagePath } = useNavigation();\n\n const parentPath = useMemo(\n () => getParentPagePath(parentPageId),\n [parentPageId, getParentPagePath],\n );\n\n const state: EntityPageState<any> = useEntityPage<any, any>({\n parentPath,\n form,\n onSave: async () => {\n validate();\n\n const formValues = form.getValues();\n const baseEntity = state.entity || {};\n const updatedEntity = {\n ...baseEntity,\n ...formValues,\n };\n\n const newEntity = entityId\n ? await schema.actions.update(updatedEntity)\n : await schema.actions.create(updatedEntity);\n\n return { updatedEntity: newEntity };\n },\n fetch: async () => {\n if (!entityId) {\n return { entity: undefined };\n }\n const entity = await schema.actions.get(entityId);\n return { entity };\n },\n });\n\n const entity = useEntity(state);\n\n const { title, subtitle } = useEntityPageHeaderTexts({\n config: configuration,\n isCreateMode,\n entityDisplayName: entity?.[schema.displayField],\n });\n\n const sdk = useActionsSDK({\n collectionId,\n });\n\n const resolvedMoreActions = useEntityPageMoreActions(\n moreActions,\n entity,\n sdk,\n form,\n );\n\n return (\n <EntityPage state={state} dataHook=\"auto-patterns-entity-page\">\n <EntityPage.Header\n title={title}\n subtitle={subtitle}\n moreActions={\n resolvedMoreActions.length > 0 ? (\n <MoreActions items={resolvedMoreActions} />\n ) : undefined\n }\n />\n <EntityPage.Content>\n <EntityPage.MainContent dataHook=\"entity-page-main-content\">\n {pageLayout?.main?.map((layout, layoutIndex) => (\n <RenderLayoutCard\n key={`main-section-card-${layoutIndex}`}\n layout={layout}\n sectionId=\"main\"\n cardIndex={layoutIndex}\n setInputRef={setInputRef}\n />\n ))}\n </EntityPage.MainContent>\n {pageLayout?.sidebar ? (\n <EntityPage.AdditionalContent>\n {pageLayout.sidebar?.map((layout, layoutIndex) => (\n <RenderLayoutCard\n key={`sidebar-section-card-${layoutIndex}`}\n layout={layout}\n sectionId=\"sidebar\"\n cardIndex={layoutIndex}\n setInputRef={setInputRef}\n />\n ))}\n </EntityPage.AdditionalContent>\n ) : null}\n </EntityPage.Content>\n </EntityPage>\n );\n};\n\n/*\n Key structure explanation:\n\n Main cards: main-section-card-{layoutIndex}\n Sidebar cards: sidebar-section-card-{layoutIndex}\n\n Layout content:\n {sectionId}-card-{cardIndex}-content-{contentIndex}\n\n Nested children:\n {sectionId}-card-{cardIndex}-content-{parentContentIndex}-level-{level}-child-{childIndex}\n\n This ensures uniqueness across all levels and sections.\n*/\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAE9C,SACEC,UAAU,EAEVC,SAAS,EACTC,aAAa,EACbC,oBAAoB,EACpBC,WAAW,QACN,eAAe;AACtB,SAASC,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,I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C,aAAA,CAACiB,gBAAgB;IACff,GAAG,EAAE,wBAAwB+E,WAAW,EAAG;IAC3C7D,MAAM,EAAEA,MAAO;IACf/B,SAAS,EAAC,SAAS;IACnBC,SAAS,EAAE2F,WAAY;IACvBzF,WAAW,EAAEA;EAAY,CAC1B,CACF,CAC2B,CAAC,GAC7B,IACc,CACV,CAAC;AAEjB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"names":["React","useMemo","useRef","EntityPage","useEntity","useEntityPage","useEntityPageContext","MoreActions","useForm","Card","Cell","Layout","useParams","useSchema","FormFieldInput","useEntityPageHeaderTexts","useNavigation","usePatternsWizardOverridesContext","useEntityPageMoreActions","useActionsSDK","RenderLayoutContent","_ref","content","level","sectionId","cardIndex","contentIndex","setInputRef","schema","overrides","pageState","type","field","fieldId","fields","createElement","span","key","inputRef","ref","container","children","length","map","child","index","component","componentId","Component","components","form","entity","RenderLayoutCard","_ref2","layout","minHeight","Header","title","card","text","subtitle","Divider","Content","AutoPatternsEntityPage","_ref3","configuration","pageLayout","parentPageId","route","moreActions","collectionId","mode","params","entityId","id","isCreateMode","inputRefs","input","current","validate","invalidFieldId","Object","keys","find","invalid","focus","Error","getParentPagePath","parentPath","state","onSave","formValues","getValues","baseEntity","updatedEntity","newEntity","actions","update","create","fetch","undefined","get","config","entityDisplayName","displayField","sdk","resolvedMoreActions","dataHook","items","MainContent","main","layoutIndex","sidebar","AdditionalContent"],"sources":["../../../../src/components/AutoPatternsEntityPage/AutoPatternsEntityPage.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport { CardLayout, EntityPageConfig, LayoutContent } from '../../types';\nimport {\n EntityPage,\n EntityPageState,\n useEntity,\n useEntityPage,\n useEntityPageContext,\n MoreActions,\n} from '@wix/patterns';\nimport { useForm } from '@wix/patterns/form';\nimport { Card, Cell, Layout } from '@wix/design-system';\nimport { useParams } from 'react-router-dom';\nimport { useSchema } from '../../providers/SchemaContext';\nimport { BaseInputRef } from './Fields/types';\nimport { FormFieldInput } from './Fields/FormFieldInput';\nimport { useEntityPageHeaderTexts, useNavigation } from '../../hooks';\nimport { usePatternsWizardOverridesContext } from '../../providers';\nimport { useEntityPageMoreActions } from '../../hooks/useEntityPageMoreActions';\nimport { useActionsSDK } from '../../hooks/useActionsSDK';\n\nconst RenderLayoutContent: React.FC<{\n content: LayoutContent;\n level: number;\n sectionId: string;\n cardIndex: number;\n contentIndex: number;\n setInputRef: (id: string, input: BaseInputRef) => void;\n}> = ({ content, level, sectionId, cardIndex, contentIndex, setInputRef }) => {\n const schema = useSchema();\n const overrides = usePatternsWizardOverridesContext();\n const pageState = useEntityPageContext();\n\n switch (content.type) {\n case 'field':\n if (!content.field.fieldId) {\n return null;\n }\n\n const field = schema.fields[content.field.fieldId];\n\n if (!field) {\n return null;\n }\n\n return (\n <Cell span={content.field.span}>\n <FormFieldInput\n key={content.field.fieldId}\n field={field}\n inputRef={(ref) => setInputRef(content.field.fieldId, ref)}\n />\n </Cell>\n );\n\n case 'container':\n if (!content.container.children?.length) {\n return null;\n }\n\n return (\n <Cell span={content.container.span}>\n <Layout>\n {content.container.children.map((child, index) => (\n <RenderLayoutContent\n key={`${sectionId}-card-${cardIndex}-content-${contentIndex}-level-${level}-child-${index}`}\n content={child}\n level={level + 1}\n sectionId={sectionId}\n cardIndex={cardIndex}\n contentIndex={index}\n setInputRef={setInputRef}\n />\n ))}\n </Layout>\n </Cell>\n );\n\n case 'component':\n if (!content.component.componentId) {\n return null;\n }\n\n const Component = overrides?.components?.[content.component.componentId];\n\n if (!Component) {\n return null;\n }\n\n return (\n <Cell span={content.component.span}>\n <Component\n form={pageState.form as any}\n entity={pageState.entity as any as Record<string, any>}\n />\n </Cell>\n );\n\n default:\n return null;\n }\n};\n\nconst RenderLayoutCard: React.FC<{\n layout: CardLayout;\n sectionId: string;\n cardIndex: number;\n setInputRef: (id: string, input: BaseInputRef) => void;\n}> = ({ layout, sectionId, cardIndex, setInputRef }) => {\n switch (layout.type) {\n case 'card':\n return (\n <EntityPage.Card minHeight=\"50px\">\n <Card.Header\n title={layout.card.title.text}\n subtitle={layout.card.subtitle?.text}\n />\n <Card.Divider />\n <Card.Content>\n <Layout>\n {layout.card.children.map((child, index: number) => (\n <RenderLayoutContent\n key={`${sectionId}-card-${cardIndex}-content-${index}`}\n content={child}\n level={0}\n sectionId={sectionId}\n cardIndex={cardIndex}\n contentIndex={index}\n setInputRef={setInputRef}\n />\n ))}\n </Layout>\n </Card.Content>\n </EntityPage.Card>\n );\n default:\n return null;\n }\n};\n\nexport interface AutoPatternsEntityPageProps {\n configuration: EntityPageConfig;\n}\n\nexport const AutoPatternsEntityPage: React.FC<AutoPatternsEntityPageProps> = ({\n configuration,\n}) => {\n const {\n layout: pageLayout,\n parentPageId,\n route,\n moreActions,\n collectionId,\n } = configuration;\n\n const form = useForm<any>({\n mode: 'onChange',\n });\n const params = useParams();\n const entityId = params[route.params.id];\n const schema = useSchema();\n const isCreateMode = !entityId;\n\n const inputRefs = useRef<{ [fieldId: string]: BaseInputRef }>({});\n\n const setInputRef = (id: string, input: BaseInputRef) => {\n inputRefs.current[id] = input;\n };\n\n const validate = () => {\n const invalidFieldId = Object.keys(inputRefs.current).find((fieldId) => {\n return inputRefs.current[fieldId]?.invalid;\n });\n\n if (invalidFieldId) {\n inputRefs.current[invalidFieldId]?.focus?.();\n throw new Error('Invalid form');\n }\n };\n const { getParentPagePath } = useNavigation();\n\n const parentPath = useMemo(\n () => getParentPagePath(parentPageId),\n [parentPageId, getParentPagePath],\n );\n\n const state: EntityPageState<any> = useEntityPage<any, any>({\n parentPath,\n form,\n onSave: async () => {\n validate();\n\n const formValues = form.getValues();\n const baseEntity = state.entity || {};\n const updatedEntity = {\n ...baseEntity,\n ...formValues,\n };\n\n const newEntity = entityId\n ? await schema.actions.update(updatedEntity)\n : await schema.actions.create(updatedEntity);\n\n return { updatedEntity: newEntity };\n },\n fetch: async () => {\n if (!entityId) {\n return { entity: undefined };\n }\n const entity = await schema.actions.get(entityId);\n return { entity };\n },\n });\n\n const entity = useEntity(state);\n\n const { title, subtitle } = useEntityPageHeaderTexts({\n config: configuration,\n isCreateMode,\n entityDisplayName: entity?.[schema.displayField],\n });\n\n const sdk = useActionsSDK({\n collectionId,\n });\n\n const resolvedMoreActions = useEntityPageMoreActions(\n moreActions,\n entity,\n sdk,\n form,\n );\n\n return (\n <EntityPage state={state} dataHook=\"auto-patterns-entity-page\">\n <EntityPage.Header\n title={title}\n subtitle={subtitle}\n moreActions={\n resolvedMoreActions.length > 0 ? (\n <MoreActions items={resolvedMoreActions} />\n ) : undefined\n }\n />\n <EntityPage.Content>\n <EntityPage.MainContent dataHook=\"entity-page-main-content\">\n {pageLayout?.main?.map((layout, layoutIndex) => (\n <RenderLayoutCard\n key={`main-section-card-${layoutIndex}`}\n layout={layout}\n sectionId=\"main\"\n cardIndex={layoutIndex}\n setInputRef={setInputRef}\n />\n ))}\n </EntityPage.MainContent>\n {pageLayout?.sidebar ? (\n <EntityPage.AdditionalContent>\n {pageLayout.sidebar?.map((layout, layoutIndex) => (\n <RenderLayoutCard\n key={`sidebar-section-card-${layoutIndex}`}\n layout={layout}\n sectionId=\"sidebar\"\n cardIndex={layoutIndex}\n setInputRef={setInputRef}\n />\n ))}\n </EntityPage.AdditionalContent>\n ) : null}\n </EntityPage.Content>\n </EntityPage>\n );\n};\n\n/*\n Key structure explanation:\n\n Main cards: main-section-card-{layoutIndex}\n Sidebar cards: sidebar-section-card-{layoutIndex}\n\n Layout content:\n {sectionId}-card-{cardIndex}-content-{contentIndex}\n\n Nested children:\n {sectionId}-card-{cardIndex}-content-{parentContentIndex}-level-{level}-child-{childIndex}\n\n This ensures uniqueness across all levels and sections.\n*/\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAE9C,SACEC,UAAU,EAEVC,SAAS,EACTC,aAAa,EACbC,o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,UAAU,CAACqD,MAAM;IAChBC,KAAK,EAAEA,KAAM;IACbG,QAAQ,EAAEA,QAAS;IACnBS,WAAW,EACTqC,mBAAmB,CAAChE,MAAM,GAAG,CAAC,gBAC5B1C,KAAA,CAAAmC,aAAA,CAAC5B,WAAW;MAACqG,KAAK,EAAEF;IAAoB,CAAE,CAAC,GACzCN;EACL,CACF,CAAC,eACFpG,KAAA,CAAAmC,aAAA,CAAChC,UAAU,CAAC2D,OAAO,qBACjB9D,KAAA,CAAAmC,aAAA,CAAChC,UAAU,CAAC0G,WAAW;IAACF,QAAQ,EAAC;EAA0B,GACxDzC,UAAU,EAAE4C,IAAI,EAAEnE,GAAG,CAAC,CAACW,MAAM,EAAEyD,WAAW,kBACzC/G,KAAA,CAAAmC,aAAA,CAACiB,gBAAgB;IACff,GAAG,EAAE,qBAAqB0E,WAAW,EAAG;IACxCzD,MAAM,EAAEA,MAAO;IACf9B,SAAS,EAAC,MAAM;IAChBC,SAAS,EAAEsF,WAAY;IACvBpF,WAAW,EAAEA;EAAY,CAC1B,CACF,CACqB,CAAC,EACxBuC,UAAU,EAAE8C,OAAO,gBAClBhH,KAAA,CAAAmC,aAAA,CAAChC,UAAU,CAAC8G,iBAAiB,QAC1B/C,UAAU,CAAC8C,OAAO,EAAErE,GAAG,CAAC,CAACW,MAAM,EAAEyD,WAAW,kBAC3C/G,KAAA,CAAAmC,aAAA,CAACiB,gBAAgB;IACff,GAAG,EAAE,wBAAwB0E,WAAW,EAAG;IAC3CzD,MAAM,EAAEA,MAAO;IACf9B,SAAS,EAAC,SAAS;IACnBC,SAAS,EAAEsF,WAAY;IACvBpF,WAAW,EAAEA;EAAY,CAC1B,CACF,CAC2B,CAAC,GAC7B,IACc,CACV,CAAC;AAEjB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -4,7 +4,7 @@ import { getDateWithoutTimezone, getISODateStringWithFixedTimezone } from './uti
4
4
  import { useSelector, useWixPatternsContainer, useEntityPageContext } from '@wix/patterns';
5
5
  import { useController } from '@wix/patterns/form';
6
6
  function validateDateField(value, validation, t, format, validationType) {
7
- if (validation != null && validation.required && (value === null || value === undefined || value === '')) {
7
+ if (validation?.required && (value === null || value === undefined || value === '')) {
8
8
  return t('cairo.fieldValidation.requiredField');
9
9
  } else if (validationType === 'formatError' && format) {
10
10
  return t('cairo.customFields.fieldType.date.invalid.value', {
@@ -14,7 +14,6 @@ function validateDateField(value, validation, t, format, validationType) {
14
14
  return '';
15
15
  }
16
16
  export const DateInput = props => {
17
- var _pageState$entity, _field$validation;
18
17
  const {
19
18
  field,
20
19
  dataHook,
@@ -27,9 +26,9 @@ export const DateInput = props => {
27
26
  useSelector(() => container.initTask.status);
28
27
  const pageState = useEntityPageContext();
29
28
  const controller = useController({
30
- name: (field == null ? void 0 : field.id) ?? '',
29
+ name: field?.id ?? '',
31
30
  control: pageState.form.control,
32
- defaultValue: (_pageState$entity = pageState.entity) == null ? void 0 : _pageState$entity[(field == null ? void 0 : field.id) ?? ''],
31
+ defaultValue: pageState.entity?.[field?.id ?? ''],
33
32
  rules: {
34
33
  validate: value => {
35
34
  const error = validateDateField(value, field.validation, t);
@@ -47,16 +46,13 @@ export const DateInput = props => {
47
46
  const [errorMessage, setErrorMessage] = useState('');
48
47
  return /*#__PURE__*/React.createElement(FormField, {
49
48
  label: field.displayName,
50
- required: (_field$validation = field.validation) == null ? void 0 : _field$validation.required,
49
+ required: field.validation?.required,
51
50
  dataHook: dataHook
52
51
  }, /*#__PURE__*/React.createElement(DatePicker, {
53
52
  ref: internalRef => {
54
- inputRef == null || inputRef(ref.current);
53
+ inputRef?.(ref.current);
55
54
  // @ts-expect-error: WSR internal API hack for focusing
56
- ref.current.focus = () => {
57
- var _internalRef$state;
58
- return internalRef == null || (_internalRef$state = internalRef.state) == null || (_internalRef$state = _internalRef$state.inputRef) == null || _internalRef$state.focus == null ? void 0 : _internalRef$state.focus();
59
- };
55
+ ref.current.focus = () => internalRef?.state?.inputRef?.focus?.();
60
56
  },
61
57
  dataHook: `date-${field.id}`,
62
58
  width: "100%",
@@ -1 +1 @@
1
- {"version":3,"names":["React","useState","useRef","FormField","DatePicker","getDateWithoutTimezone","getISODateStringWithFixedTimezone","useSelector","useWixPatternsContainer","useEntityPageContext","useController","validateDateField","value","validation","t","format","validationType","required","undefined","dateFormat","DateInput","props","_pageState$entity","_field$validation","field","dataHook","inputRef","translate","container","initTask","status","pageState","controller","name","id","control","form","defaultValue","entity","rules","validate","error","date","setDate","ref","errorMessage","setErrorMessage","createElement","label","displayName","internalRef","current","focus","_internalRef$state","state","width","onChange","newValue","formattedDate","split","onValidate","_ref","invalid","statusMessage"],"sources":["../../../../../src/components/AutoPatternsEntityPage/Fields/DateInput.tsx"],"sourcesContent":["import React, { useState, useRef } from 'react';\nimport { FormField, DatePicker } from '@wix/design-system';\nimport {\n getDateWithoutTimezone,\n getISODateStringWithFixedTimezone,\n} from './utils/dates';\nimport { BaseInputProps, BaseInputRef } from './types';\nimport {\n useSelector,\n useWixPatternsContainer,\n useEntityPageContext,\n} from '@wix/patterns';\nimport { useController } from '@wix/patterns/form';\nimport { Translate } from '@wix/patterns/core';\n\nexport interface DateProps extends BaseInputProps<string | null> {}\n\nfunction validateDateField(\n value: string | null | undefined,\n validation: DateProps['field']['validation'],\n t: Translate,\n format?: string,\n validationType?: 'outOfBoundsError' | 'formatError' | 'valid',\n) {\n if (\n validation?.required &&\n (value === null || value === undefined || value === '')\n ) {\n return t('cairo.fieldValidation.requiredField');\n } else if (validationType === 'formatError' && format) {\n return t('cairo.customFields.fieldType.date.invalid.value', {\n dateFormat: format,\n });\n }\n\n return '';\n}\n\nexport const DateInput = (props: DateProps) => {\n const { field, dataHook, inputRef } = props;\n const { translate: t, ...container } = useWixPatternsContainer();\n useSelector(() => container.initTask.status);\n const pageState = useEntityPageContext();\n\n const controller = useController({\n name: field?.id ?? '',\n control: pageState.form.control,\n defaultValue: (pageState.entity as any)?.[field?.id ?? ''],\n rules: {\n validate: (value) => {\n const error = validateDateField(value, field.validation, t);\n return error || true;\n },\n },\n });\n\n const [date, setDate] = useState<Date | undefined>(() => {\n if (controller.field.value) {\n return getDateWithoutTimezone(\n getISODateStringWithFixedTimezone(controller.field.value),\n );\n }\n return undefined;\n });\n\n const ref = useRef<BaseInputRef>({});\n const [errorMessage, setErrorMessage] = useState<string>('');\n\n return (\n <FormField\n label={field.displayName}\n required={field.validation?.required}\n dataHook={dataHook}\n >\n <DatePicker\n ref={(internalRef) => {\n inputRef?.(ref.current);\n // @ts-expect-error: WSR internal API hack for focusing\n ref.current.focus = () => internalRef?.state?.inputRef?.focus?.();\n }}\n dataHook={`date-${field.id}`}\n width=\"100%\"\n value={date}\n onChange={(newValue: Date) => {\n setDate(newValue);\n if (newValue) {\n const formattedDate = getISODateStringWithFixedTimezone(newValue);\n controller.field.onChange(formattedDate.split('T')[0]);\n } else {\n controller.field.onChange(null);\n }\n }}\n onValidate={({ validationType, value: newValue, format }) => {\n const error = validateDateField(\n newValue,\n field.validation,\n t,\n format,\n validationType,\n );\n setErrorMessage(error);\n ref.current.invalid = !!error;\n\n if (validationType === 'formatError' && newValue === '') {\n setDate(undefined);\n controller.field.onChange(null);\n }\n }}\n status={errorMessage ? 'error' : undefined}\n statusMessage={errorMessage}\n />\n </FormField>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,MAAM,QAAQ,OAAO;AAC/C,SAASC,SAAS,EAAEC,UAAU,QAAQ,oBAAoB;AAC1D,SACEC,sBAAsB,EACtBC,iCAAiC,QAC5B,eAAe;AAEtB,SACEC,WAAW,EACXC,uBAAuB,EACvBC,oBAAoB,QACf,eAAe;AACtB,SAASC,aAAa,QAAQ,oBAAoB;AAKlD,SAASC,iBAAiBA,CACxBC,KAAgC,EAChCC,UAA4C,EAC5CC,CAAY,EACZC,MAAe,EACfC,cAA6D,EAC7D;EACA,IACEH,UAAU,YAAVA,UA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AAU,CAACR,KAAK,CAACgC,QAAQ,CAACE,aAAa,CAACC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;MACxD,CAAC,MAAM;QACL3B,UAAU,CAACR,KAAK,CAACgC,QAAQ,CAAC,IAAI,CAAC;MACjC;IACF,CAAE;IACFI,UAAU,EAAEC,IAAA,IAAiD;MAAA,IAAhD;QAAE7C,cAAc;QAAEJ,KAAK,EAAE6C,QAAQ;QAAE1C;MAAO,CAAC,GAAA8C,IAAA;MACtD,MAAMpB,KAAK,GAAG9B,iBAAiB,CAC7B8C,QAAQ,EACRjC,KAAK,CAACX,UAAU,EAChBC,CAAC,EACDC,MAAM,EACNC,cACF,CAAC;MACD8B,eAAe,CAACL,KAAK,CAAC;MACtBG,GAAG,CAACO,OAAO,CAACW,OAAO,GAAG,CAAC,CAACrB,KAAK;MAE7B,IAAIzB,cAAc,KAAK,aAAa,IAAIyC,QAAQ,KAAK,EAAE,EAAE;QACvDd,OAAO,CAACzB,SAAS,CAAC;QAClBc,UAAU,CAACR,KAAK,CAACgC,QAAQ,CAAC,IAAI,CAAC;MACjC;IACF,CAAE;IACF1B,MAAM,EAAEe,YAAY,GAAG,OAAO,GAAG3B,SAAU;IAC3C6C,aAAa,EAAElB;EAAa,CAC7B,CACQ,CAAC;AAEhB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","useState","useRef","FormField","DatePicker","getDateWithoutTimezone","getISODateStringWithFixedTimezone","useSelector","useWixPatternsContainer","useEntityPageContext","useController","validateDateField","value","validation","t","format","validationType","required","undefined","dateFormat","DateInput","props","field","dataHook","inputRef","translate","container","initTask","status","pageState","controller","name","id","control","form","defaultValue","entity","rules","validate","error","date","setDate","ref","errorMessage","setErrorMessage","createElement","label","displayName","internalRef","current","focus","state","width","onChange","newValue","formattedDate","split","onValidate","_ref","invalid","statusMessage"],"sources":["../../../../../src/components/AutoPatternsEntityPage/Fields/DateInput.tsx"],"sourcesContent":["import React, { useState, useRef } from 'react';\nimport { FormField, DatePicker } from '@wix/design-system';\nimport {\n getDateWithoutTimezone,\n getISODateStringWithFixedTimezone,\n} from './utils/dates';\nimport { BaseInputProps, BaseInputRef } from './types';\nimport {\n useSelector,\n useWixPatternsContainer,\n useEntityPageContext,\n} from '@wix/patterns';\nimport { useController } from '@wix/patterns/form';\nimport { Translate } from '@wix/patterns/core';\n\nexport interface DateProps extends BaseInputProps<string | null> {}\n\nfunction validateDateField(\n value: string | null | undefined,\n validation: DateProps['field']['validation'],\n t: Translate,\n format?: string,\n validationType?: 'outOfBoundsError' | 'formatError' | 'valid',\n) {\n if (\n validation?.required &&\n (value === null || value === undefined || value === '')\n ) {\n return t('cairo.fieldValidation.requiredField');\n } else if (validationType === 'formatError' && format) {\n return t('cairo.customFields.fieldType.date.invalid.value', {\n dateFormat: format,\n });\n }\n\n return '';\n}\n\nexport const DateInput = (props: DateProps) => {\n const { field, dataHook, inputRef } = props;\n const { translate: t, ...container } = useWixPatternsContainer();\n useSelector(() => container.initTask.status);\n const pageState = useEntityPageContext();\n\n const controller = useController({\n name: field?.id ?? '',\n control: pageState.form.control,\n defaultValue: (pageState.entity as any)?.[field?.id ?? ''],\n rules: {\n validate: (value) => {\n const error = validateDateField(value, field.validation, t);\n return error || true;\n },\n },\n });\n\n const [date, setDate] = useState<Date | undefined>(() => {\n if (controller.field.value) {\n return getDateWithoutTimezone(\n getISODateStringWithFixedTimezone(controller.field.value),\n );\n }\n return undefined;\n });\n\n const ref = useRef<BaseInputRef>({});\n const [errorMessage, setErrorMessage] = useState<string>('');\n\n return (\n <FormField\n label={field.displayName}\n required={field.validation?.required}\n dataHook={dataHook}\n >\n <DatePicker\n ref={(internalRef) => {\n inputRef?.(ref.current);\n // @ts-expect-error: WSR internal API hack for focusing\n ref.current.focus = () => internalRef?.state?.inputRef?.focus?.();\n }}\n dataHook={`date-${field.id}`}\n width=\"100%\"\n value={date}\n onChange={(newValue: Date) => {\n setDate(newValue);\n if (newValue) {\n const formattedDate = getISODateStringWithFixedTimezone(newValue);\n controller.field.onChange(formattedDate.split('T')[0]);\n } else {\n controller.field.onChange(null);\n }\n }}\n onValidate={({ validationType, value: newValue, format }) => {\n const error = validateDateField(\n newValue,\n field.validation,\n t,\n format,\n validationType,\n );\n setErrorMessage(error);\n ref.current.invalid = !!error;\n\n if (validationType === 'formatError' && newValue === '') {\n setDate(undefined);\n controller.field.onChange(null);\n }\n }}\n status={errorMessage ? 'error' : undefined}\n statusMessage={errorMessage}\n />\n </FormField>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,MAAM,QAAQ,OAAO;AAC/C,SAASC,SAAS,EAAEC,UAAU,QAAQ,oBAAoB;AAC1D,SACEC,sBAAsB,EACtBC,iCAAiC,QAC5B,eAAe;AAEtB,SACEC,WAAW,EACXC,uBAAuB,EACvBC,oBAAoB,QACf,eAAe;AACtB,SAASC,aAAa,QAAQ,oBAAoB;AAKlD,SAASC,iBAAiBA,CACxBC,KAAgC,EAChCC,UAA4C,EAC5CC,CAAY,EACZC,MAAe,EACfC,cAA6D,EAC7D;EACA,IACEH,UAAU,EAAEI,QAAQ,KACnBL,KAAK,KAAK,IAAI,IAAIA,KAAK,KAAKM,SAAS,IAAIN,KAAK,KAAK,EAAE,CAAC,EACvD;IACA,OAAOE,CAAC,CAAC,qCAAqC,CAAC;EACjD,CAAC,MAAM,IAAIE,cAAc,KAAK,aAAa,IAAID,MAAM,EAAE;IACrD,OAAOD,CAAC,CAAC,iDAAiD,EAAE;MAC1DK,UAAU,EAAEJ;IACd,CAAC,CAAC;EACJ;EAEA,OAAO,EAAE;AACX;AAEA,OAAO,MAAMK,SAAS,GAAIC,KAAgB,IAAK;EAC7C,MAAM;IAAEC,KAAK;IAAEC,QAAQ;IAAEC;EAAS,CAAC,GAAGH,KAAK;EAC3C,MAAM;IAAEI,SAAS,EAAEX,CAAC;IAAE,GAAGY;EAAU,CAAC,GAAGlB,uBAAuB,CAAC,CAAC;EAChED,WAAW,CAA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3,6 @@ import { Cell, DatePicker, FormField, Layout, TimeInput } from '@wix/design-syst
3
3
  import { useWixPatternsContainer, useSelector, useEntityPageContext } from '@wix/patterns';
4
4
  import { useController } from '@wix/patterns/form';
5
5
  export const DateTime = props => {
6
- var _pageState$entity, _field$validation2;
7
6
  const {
8
7
  field,
9
8
  dataHook,
@@ -16,13 +15,12 @@ export const DateTime = props => {
16
15
  useSelector(() => container.initTask.status);
17
16
  const pageState = useEntityPageContext();
18
17
  const controller = useController({
19
- name: (field == null ? void 0 : field.id) ?? '',
18
+ name: field?.id ?? '',
20
19
  control: pageState.form.control,
21
- defaultValue: (_pageState$entity = pageState.entity) == null ? void 0 : _pageState$entity[(field == null ? void 0 : field.id) ?? ''],
20
+ defaultValue: pageState.entity?.[field?.id ?? ''],
22
21
  rules: {
23
22
  validate: v => {
24
- var _field$validation;
25
- if (field != null && (_field$validation = field.validation) != null && _field$validation.required && (v === null || v === undefined || v === '')) {
23
+ if (field?.validation?.required && (v === null || v === undefined || v === '')) {
26
24
  return t('cairo.fieldValidation.requiredField');
27
25
  }
28
26
  return true;
@@ -41,32 +39,29 @@ export const DateTime = props => {
41
39
  const ref = useRef({});
42
40
  const dateRef = useRef({});
43
41
  const timeRef = useRef({});
44
- const [dateValue, setDateValue] = useState(date == null ? void 0 : date.getDate());
45
- const [timeValue, setTimeValue] = useState(date == null ? void 0 : date.getTime());
42
+ const [dateValue, setDateValue] = useState(date?.getDate());
43
+ const [timeValue, setTimeValue] = useState(date?.getTime());
46
44
  useEffect(() => {
47
45
  ref.current.focus = () => {
48
46
  if (dateRef.current.invalid) {
49
- return dateRef.current.focus == null ? void 0 : dateRef.current.focus();
47
+ return dateRef.current.focus?.();
50
48
  }
51
- return timeRef.current.focus == null ? void 0 : timeRef.current.focus();
49
+ return timeRef.current.focus?.();
52
50
  };
53
- inputRef == null || inputRef(ref.current);
51
+ inputRef?.(ref.current);
54
52
  }, [inputRef]);
55
53
  return /*#__PURE__*/React.createElement(FormField, {
56
54
  label: field.displayName,
57
- required: (_field$validation2 = field.validation) == null ? void 0 : _field$validation2.required,
55
+ required: field.validation?.required,
58
56
  dataHook: dataHook
59
57
  }, /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Cell, {
60
58
  span: 6
61
59
  }, /*#__PURE__*/React.createElement(DatePicker, {
62
60
  ref: internalRef => {
63
- dateRef.current.focus = () => {
64
- var _internalRef$state;
65
- return (// TODO: PR to WSR needed to expose as public API
66
- // @ts-expect-error
67
- internalRef == null || (_internalRef$state = internalRef.state) == null || (_internalRef$state = _internalRef$state.inputRef) == null || _internalRef$state.focus == null ? void 0 : _internalRef$state.focus()
68
- );
69
- };
61
+ dateRef.current.focus = () =>
62
+ // TODO: PR to WSR needed to expose as public API
63
+ // @ts-expect-error
64
+ internalRef?.state?.inputRef?.focus?.();
70
65
  },
71
66
  width: "100%",
72
67
  value: date
@@ -90,8 +85,7 @@ export const DateTime = props => {
90
85
  setDateStatusMessage('');
91
86
  dateRef.current.invalid = false;
92
87
  } else if (validationType === 'formatError' && newValue === '') {
93
- var _field$validation3;
94
- if ((_field$validation3 = field.validation) != null && _field$validation3.required) {
88
+ if (field.validation?.required) {
95
89
  setDateStatusMessage(t('cairo.fieldValidation.requiredField'));
96
90
  dateRef.current.invalid = true;
97
91
  } else {
@@ -117,7 +111,7 @@ export const DateTime = props => {
117
111
  span: 6
118
112
  }, /*#__PURE__*/React.createElement(TimeInput, {
119
113
  ref: internalRef => {
120
- timeRef.current.focus = () => internalRef == null ? void 0 : internalRef.focus();
114
+ timeRef.current.focus = () => internalRef?.focus();
121
115
  },
122
116
  dataHook: `datetime-time-${field.id}`,
123
117
  value: date ?? null,
@@ -145,9 +139,8 @@ export const DateTime = props => {
145
139
  setDateStatusMessage('');
146
140
  } else {
147
141
  if (!newValue) {
148
- var _field$validation4;
149
142
  setTimeValue('');
150
- if ((_field$validation4 = field.validation) != null && _field$validation4.required) {
143
+ if (field.validation?.required) {
151
144
  setTimeStatusMessage(t('cairo.fieldValidation.requiredField'));
152
145
  timeRef.current.invalid = true;
153
146
  } else {
@@ -1 +1 @@
1
- {"version":3,"names":["React","useRef","useMemo","useState","useEffect","Cell","DatePicker","FormField","Layout","TimeInput","useWixPatternsContainer","useSelector","useEntityPageContext","useController","DateTime","props","_pageState$entity","_field$validation2","field","dataHook","inputRef","translate","t","container","initTask","status","pageState","controller","name","id","control","form","defaultValue","entity","rules","validate","v","_field$validation","validation","required","undefined","date","value","d","Date","isNaN","getTime","dateStatusMessage","setDateStatusMessage","timeStatusMessage","setTimeStatusMessage","ref","dateRef","timeRef","dateValue","setDateValue","getDate","timeValue","setTimeValue","current","focus","invalid","createElement","label","displayName","span","internalRef","_internalRef$state","state","width","onChange","onValidate","_ref","validationType","newValue","format","dateWithNewDate","_value","setFullYear","getFullYear","setMonth","getMonth","setDate","toISOString","_field$validation3","dateFormat","fieldState","error","statusMessage","onInvalid","_ref2","dateWithNewTime","setHours","getHours","setMinutes","getMinutes","setSeconds","getSeconds","setMilliseconds","getMilliseconds","_field$validation4"],"sources":["../../../../../src/components/AutoPatternsEntityPage/Fields/DateTime.tsx"],"sourcesContent":["import React, { useRef, useMemo, useState, useEffect } from 'react';\nimport {\n Cell,\n DatePicker,\n FormField,\n Layout,\n TimeInput,\n} from '@wix/design-system';\nimport { BaseInputProps, BaseInputRef } from './types';\nimport {\n useWixPatternsContainer,\n useSelector,\n useEntityPageContext,\n} from '@wix/patterns';\nimport { useController } from '@wix/patterns/form';\n\nexport interface DateTimeProps extends BaseInputProps<string | null> {}\n\nexport const DateTime = (props: DateTimeProps) => {\n const { field, dataHook, inputRef } = props;\n const { translate: t, ...container } = useWixPatternsContainer();\n useSelector(() => container.initTask.status);\n const pageState = useEntityPageContext();\n\n const controller = useController({\n name: field?.id ?? '',\n control: pageState.form.control,\n defaultValue: (pageState.entity as any)?.[field?.id ?? ''],\n rules: {\n validate: (v) => {\n if (\n field?.validation?.required &&\n (v === null || v === undefined || v === '')\n ) {\n return t('cairo.fieldValidation.requiredField');\n }\n return true;\n },\n },\n });\n\n const date = useMemo(() => {\n if (!controller.field.value) {\n return undefined;\n }\n const d = new Date(controller.field.value);\n return isNaN(d.getTime()) ? undefined : d;\n }, [controller.field.value]);\n\n const [dateStatusMessage, setDateStatusMessage] = useState('');\n const [timeStatusMessage, setTimeStatusMessage] = useState('');\n\n const ref = useRef<BaseInputRef>({});\n const dateRef = useRef<BaseInputRef>({});\n const timeRef = useRef<BaseInputRef>({});\n const [dateValue, setDateValue] = useState<number | string | undefined>(\n date?.getDate(),\n );\n const [timeValue, setTimeValue] = useState<number | string | undefined>(\n date?.getTime(),\n );\n\n useEffect(() => {\n ref.current.focus = () => {\n if (dateRef.current.invalid) {\n return dateRef.current.focus?.();\n }\n\n return timeRef.current.focus?.();\n };\n\n inputRef?.(ref.current);\n }, [inputRef]);\n\n return (\n <FormField\n label={field.displayName}\n required={field.validation?.required}\n dataHook={dataHook}\n >\n <Layout>\n <Cell span={6}>\n <DatePicker\n ref={(internalRef) => {\n dateRef.current.focus = () =>\n // TODO: PR to WSR needed to expose as public API\n // @ts-expect-error\n internalRef?.state?.inputRef?.focus?.();\n }}\n width=\"100%\"\n value={date}\n // onChange is triggered only when you have valid, non-empty value. and onValidate is triggered on every change so we use onValidate\n onChange={() => {}}\n onValidate={({ validationType, value: newValue, format }) => {\n if (validationType === 'valid') {\n const dateWithNewDate = date\n ? new Date(date)\n : new Date(newValue);\n const _value = new Date(newValue);\n dateWithNewDate.setFullYear(_value.getFullYear());\n dateWithNewDate.setMonth(_value.getMonth());\n dateWithNewDate.setDate(_value.getDate());\n controller.field.onChange(dateWithNewDate.toISOString());\n setDateValue(new Date(newValue).getDate());\n setDateStatusMessage('');\n dateRef.current.invalid = false;\n } else if (validationType === 'formatError' && newValue === '') {\n if (field.validation?.required) {\n setDateStatusMessage(\n t('cairo.fieldValidation.requiredField'),\n );\n dateRef.current.invalid = true;\n } else {\n setDateStatusMessage('');\n dateRef.current.invalid = false;\n }\n setDateValue(newValue);\n if (!timeValue) {\n controller.field.onChange(null);\n }\n } else {\n setDateStatusMessage(\n t('cairo.customFields.fieldType.date.invalid.value', {\n dateFormat: format ?? '',\n }),\n );\n dateRef.current.invalid = true;\n }\n\n ref.current.invalid =\n dateRef.current.invalid || timeRef.current.invalid;\n }}\n status={\n controller.fieldState.error || dateStatusMessage\n ? 'error'\n : undefined\n }\n statusMessage={controller.fieldState.error || dateStatusMessage}\n dataHook={`datetime-date-${field.id}`}\n />\n </Cell>\n <Cell span={6}>\n <TimeInput\n ref={(internalRef) => {\n timeRef.current.focus = () => internalRef?.focus();\n }}\n dataHook={`datetime-time-${field.id}`}\n value={date ?? null}\n status={\n controller.fieldState.error || timeStatusMessage\n ? 'error'\n : undefined\n }\n statusMessage={controller.fieldState.error || timeStatusMessage}\n onInvalid={() => {\n timeRef.current.invalid = true;\n setTimeStatusMessage(\n t('cairo.customFields.fieldType.dateAndTime.invalid.value'),\n );\n ref.current.invalid =\n dateRef.current.invalid || timeRef.current.invalid;\n }}\n onChange={({ date: newValue }) => {\n timeRef.current.invalid = false;\n ref.current.invalid =\n dateRef.current.invalid || timeRef.current.invalid;\n\n if (newValue) {\n const dateWithNewTime = date ? new Date(date) : newValue;\n dateWithNewTime.setHours(newValue.getHours());\n dateWithNewTime.setMinutes(newValue.getMinutes());\n dateWithNewTime.setSeconds(newValue.getSeconds());\n dateWithNewTime.setMilliseconds(newValue.getMilliseconds());\n controller.field.onChange(dateWithNewTime.toISOString());\n setTimeStatusMessage('');\n setDateStatusMessage('');\n } else {\n if (!newValue) {\n setTimeValue('');\n if (field.validation?.required) {\n setTimeStatusMessage(\n t('cairo.fieldValidation.requiredField'),\n );\n timeRef.current.invalid = true;\n } else {\n setTimeStatusMessage('');\n timeRef.current.invalid = false;\n }\n if (!ref.current.invalid) {\n if (!dateValue) {\n controller.field.onChange(null);\n }\n }\n }\n }\n }}\n />\n </Cell>\n </Layout>\n </FormField>\n );\n};\n"],"mappings":"AAAA,OAAOA,K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AACoD,QAAQ,CAAC,IAAI,CAAC;YACjC;UACF;QACF;MACF;IACF;EAAE,CACH,CACG,CACA,CACC,CAAC;AAEhB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","useRef","useMemo","useState","useEffect","Cell","DatePicker","FormField","Layout","TimeInput","useWixPatternsContainer","useSelector","useEntityPageContext","useController","DateTime","props","field","dataHook","inputRef","translate","t","container","initTask","status","pageState","controller","name","id","control","form","defaultValue","entity","rules","validate","v","validation","required","undefined","date","value","d","Date","isNaN","getTime","dateStatusMessage","setDateStatusMessage","timeStatusMessage","setTimeStatusMessage","ref","dateRef","timeRef","dateValue","setDateValue","getDate","timeValue","setTimeValue","current","focus","invalid","createElement","label","displayName","span","internalRef","state","width","onChange","onValidate","_ref","validationType","newValue","format","dateWithNewDate","_value","setFullYear","getFullYear","setMonth","getMonth","setDate","toISOString","dateFormat","fieldState","error","statusMessage","onInvalid","_ref2","dateWithNewTime","setHours","getHours","setMinutes","getMinutes","setSeconds","getSeconds","setMilliseconds","getMilliseconds"],"sources":["../../../../../src/components/AutoPatternsEntityPage/Fields/DateTime.tsx"],"sourcesContent":["import React, { useRef, useMemo, useState, useEffect } from 'react';\nimport {\n Cell,\n DatePicker,\n FormField,\n Layout,\n TimeInput,\n} from '@wix/design-system';\nimport { BaseInputProps, BaseInputRef } from './types';\nimport {\n useWixPatternsContainer,\n useSelector,\n useEntityPageContext,\n} from '@wix/patterns';\nimport { useController } from '@wix/patterns/form';\n\nexport interface DateTimeProps extends BaseInputProps<string | null> {}\n\nexport const DateTime = (props: DateTimeProps) => {\n const { field, dataHook, inputRef } = props;\n const { translate: t, ...container } = useWixPatternsContainer();\n useSelector(() => container.initTask.status);\n const pageState = useEntityPageContext();\n\n const controller = useController({\n name: field?.id ?? '',\n control: pageState.form.control,\n defaultValue: (pageState.entity as any)?.[field?.id ?? ''],\n rules: {\n validate: (v) => {\n if (\n field?.validation?.required &&\n (v === null || v === undefined || v === '')\n ) {\n return t('cairo.fieldValidation.requiredField');\n }\n return true;\n },\n },\n });\n\n const date = useMemo(() => {\n if (!controller.field.value) {\n return undefined;\n }\n const d = new Date(controller.field.value);\n return isNaN(d.getTime()) ? undefined : d;\n }, [controller.field.value]);\n\n const [dateStatusMessage, setDateStatusMessage] = useState('');\n const [timeStatusMessage, setTimeStatusMessage] = useState('');\n\n const ref = useRef<BaseInputRef>({});\n const dateRef = useRef<BaseInputRef>({});\n const timeRef = useRef<BaseInputRef>({});\n const [dateValue, setDateValue] = useState<number | string | undefined>(\n date?.getDate(),\n );\n const [timeValue, setTimeValue] = useState<number | string | undefined>(\n date?.getTime(),\n );\n\n useEffect(() => {\n ref.current.focus = () => {\n if (dateRef.current.invalid) {\n return dateRef.current.focus?.();\n }\n\n return timeRef.current.focus?.();\n };\n\n inputRef?.(ref.current);\n }, [inputRef]);\n\n return (\n <FormField\n label={field.displayName}\n required={field.validation?.required}\n dataHook={dataHook}\n >\n <Layout>\n <Cell span={6}>\n <DatePicker\n ref={(internalRef) => {\n dateRef.current.focus = () =>\n // TODO: PR to WSR needed to expose as public API\n // @ts-expect-error\n internalRef?.state?.inputRef?.focus?.();\n }}\n width=\"100%\"\n value={date}\n // onChange is triggered only when you have valid, non-empty value. and onValidate is triggered on every change so we use onValidate\n onChange={() => {}}\n onValidate={({ validationType, value: newValue, format }) => {\n if (validationType === 'valid') {\n const dateWithNewDate = date\n ? new Date(date)\n : new Date(newValue);\n const _value = new Date(newValue);\n dateWithNewDate.setFullYear(_value.getFullYear());\n dateWithNewDate.setMonth(_value.getMonth());\n dateWithNewDate.setDate(_value.getDate());\n controller.field.onChange(dateWithNewDate.toISOString());\n setDateValue(new Date(newValue).getDate());\n setDateStatusMessage('');\n dateRef.current.invalid = false;\n } else if (validationType === 'formatError' && newValue === '') {\n if (field.validation?.required) {\n setDateStatusMessage(\n t('cairo.fieldValidation.requiredField'),\n );\n dateRef.current.invalid = true;\n } else {\n setDateStatusMessage('');\n dateRef.current.invalid = false;\n }\n setDateValue(newValue);\n if (!timeValue) {\n controller.field.onChange(null);\n }\n } else {\n setDateStatusMessage(\n t('cairo.customFields.fieldType.date.invalid.value', {\n dateFormat: format ?? '',\n }),\n );\n dateRef.current.invalid = true;\n }\n\n ref.current.invalid =\n dateRef.current.invalid || timeRef.current.invalid;\n }}\n status={\n controller.fieldState.error || dateStatusMessage\n ? 'error'\n : undefined\n }\n statusMessage={controller.fieldState.error || dateStatusMessage}\n dataHook={`datetime-date-${field.id}`}\n />\n </Cell>\n <Cell span={6}>\n <TimeInput\n ref={(internalRef) => {\n timeRef.current.focus = () => internalRef?.focus();\n }}\n dataHook={`datetime-time-${field.id}`}\n value={date ?? null}\n status={\n controller.fieldState.error || timeStatusMessage\n ? 'error'\n : undefined\n }\n statusMessage={controller.fieldState.error || timeStatusMessage}\n onInvalid={() => {\n timeRef.current.invalid = true;\n setTimeStatusMessage(\n t('cairo.customFields.fieldType.dateAndTime.invalid.value'),\n );\n ref.current.invalid =\n dateRef.current.invalid || timeRef.current.invalid;\n }}\n onChange={({ date: newValue }) => {\n timeRef.current.invalid = false;\n ref.current.invalid =\n dateRef.current.invalid || timeRef.current.invalid;\n\n if (newValue) {\n const dateWithNewTime = date ? new Date(date) : newValue;\n dateWithNewTime.setHours(newValue.getHours());\n dateWithNewTime.setMinutes(newValue.getMinutes());\n dateWithNewTime.setSeconds(newValue.getSeconds());\n dateWithNewTime.setMilliseconds(newValue.getMilliseconds());\n controller.field.onChange(dateWithNewTime.toISOString());\n setTimeStatusMessage('');\n setDateStatusMessage('');\n } else {\n if (!newValue) {\n setTimeValue('');\n if (field.validation?.required) {\n setTimeStatusMessage(\n t('cairo.fieldValidation.requiredField'),\n );\n timeRef.current.invalid = true;\n } else {\n setTimeStatusMessage('');\n timeRef.current.invalid = false;\n }\n if (!ref.current.invalid) {\n if (!dateValue) {\n controller.field.onChange(null);\n }\n }\n }\n }\n }}\n />\n </Cell>\n </Layout>\n </FormField>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAA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,CAAC;QAC3DrE,UAAU,CAACT,KAAK,CAACkD,QAAQ,CAACoB,eAAe,CAACP,WAAW,CAAC,CAAC,CAAC;QACxDhC,oBAAoB,CAAC,EAAE,CAAC;QACxBF,oBAAoB,CAAC,EAAE,CAAC;MAC1B,CAAC,MAAM;QACL,IAAI,CAACyB,QAAQ,EAAE;UACbf,YAAY,CAAC,EAAE,CAAC;UAChB,IAAIvC,KAAK,CAACmB,UAAU,EAAEC,QAAQ,EAAE;YAC9BW,oBAAoB,CAClB3B,CAAC,CAAC,qCAAqC,CACzC,CAAC;YACD8B,OAAO,CAACM,OAAO,CAACE,OAAO,GAAG,IAAI;UAChC,CAAC,MAAM;YACLX,oBAAoB,CAAC,EAAE,CAAC;YACxBG,OAAO,CAACM,OAAO,CAACE,OAAO,GAAG,KAAK;UACjC;UACA,IAAI,CAACV,GAAG,CAACQ,OAAO,CAACE,OAAO,EAAE;YACxB,IAAI,CAACP,SAAS,EAAE;cACd1B,UAAU,CAACT,KAAK,CAACkD,QAAQ,CAAC,IAAI,CAAC;YACjC;UACF;QACF;MACF;IACF;EAAE,CACH,CACG,CACA,CACC,CAAC;AAEhB,CAAC","ignoreList":[]}
@@ -20,16 +20,15 @@ export const EDITABLE_INPUT_ELEMENTS = {
20
20
  IMAGE: ImageInput
21
21
  };
22
22
  export const FormFieldInput = props => {
23
- var _pageState$entity;
24
23
  const {
25
24
  field,
26
25
  inputRef
27
26
  } = props;
28
27
  const pageState = useEntityPageContext();
29
28
  const controller = useController({
30
- name: (field == null ? void 0 : field.id) ?? '',
29
+ name: field?.id ?? '',
31
30
  control: pageState.form.control,
32
- defaultValue: (_pageState$entity = pageState.entity) == null ? void 0 : _pageState$entity[(field == null ? void 0 : field.id) ?? '']
31
+ defaultValue: pageState.entity?.[field?.id ?? '']
33
32
  });
34
33
  if (!EDITABLE_INPUT_ELEMENTS.hasOwnProperty(field.type) || !pageState) {
35
34
  return null;
@@ -1 +1 @@
1
- {"version":3,"names":["React","ShortText","useEntityPageContext","useController","Checkbox","DateInput","DateTime","Number","LongText","Url","ImageInput","EDITABLE_INPUT_ELEMENTS","SHORT_TEXT","LONG_TEXT","BOOLEAN","DATE","DATETIME","NUMBER","URL","IMAGE","FormFieldInput","props","_pageState$entity","field","inputRef","pageState","controller","name","id","control","form","defaultValue","entity","hasOwnProperty","type","FieldInput","createElement","value","onChange","dataHook"],"sources":["../../../../../src/components/AutoPatternsEntityPage/Fields/FormFieldInput.tsx"],"sourcesContent":["import React from 'react';\nimport { ShortText } from './ShortText';\nimport { useEntityPageContext } from '@wix/patterns';\nimport { useController } from '@wix/patterns/form';\nimport { Field, PatternsFieldType } from '../../../types';\nimport { Checkbox } from './Checkbox';\nimport { DateInput } from './DateInput';\nimport { DateTime } from './DateTime';\nimport { Number } from './Number';\nimport { LongText } from './LongText';\nimport { Url } from './Url';\nimport { BaseInputProps } from './types';\nimport { ImageInput } from './ImageInput';\n\nexport const EDITABLE_INPUT_ELEMENTS: Partial<\n Record<PatternsFieldType, React.ComponentType<any>>\n> = {\n SHORT_TEXT: ShortText,\n LONG_TEXT: LongText,\n BOOLEAN: Checkbox,\n DATE: DateInput,\n DATETIME: DateTime,\n NUMBER: Number,\n URL: Url,\n IMAGE: ImageInput,\n};\n\nexport interface FormFieldInputProps {\n field: Field;\n inputRef?: BaseInputProps<any>['inputRef'];\n}\n\nexport const FormFieldInput = (props: FormFieldInputProps) => {\n const { field, inputRef } = props;\n\n const pageState = useEntityPageContext();\n\n const controller = useController({\n name: field?.id ?? '',\n control: pageState.form.control,\n defaultValue: (pageState.entity as any)?.[field?.id ?? ''],\n });\n\n if (!EDITABLE_INPUT_ELEMENTS.hasOwnProperty(field.type) || !pageState) {\n return null;\n }\n\n const FieldInput = EDITABLE_INPUT_ELEMENTS[field.type]!;\n\n return (\n <FieldInput\n field={field}\n value={controller.field.value}\n onChange={controller.field.onChange}\n dataHook={`form-field-${field.id}`}\n inputRef={inputRef}\n />\n );\n};\n"],"mappings":"AAAA,OAAOA,K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,CAACY,KAAK,CAACW,IAAI,CAAE;EAEvD,oBACElC,KAAA,CAAAoC,aAAA,CAACD,UAAU;IACTZ,KAAK,EAAEA,KAAM;IACbc,KAAK,EAAEX,UAAU,CAACH,KAAK,CAACc,KAAM;IAC9BC,QAAQ,EAAEZ,UAAU,CAACH,KAAK,CAACe,QAAS;IACpCC,QAAQ,EAAE,cAAchB,KAAK,CAACK,EAAE,EAAG;IACnCJ,QAAQ,EAAEA;EAAS,CACpB,CAAC;AAEN,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","ShortText","useEntityPageContext","useController","Checkbox","DateInput","DateTime","Number","LongText","Url","ImageInput","EDITABLE_INPUT_ELEMENTS","SHORT_TEXT","LONG_TEXT","BOOLEAN","DATE","DATETIME","NUMBER","URL","IMAGE","FormFieldInput","props","field","inputRef","pageState","controller","name","id","control","form","defaultValue","entity","hasOwnProperty","type","FieldInput","createElement","value","onChange","dataHook"],"sources":["../../../../../src/components/AutoPatternsEntityPage/Fields/FormFieldInput.tsx"],"sourcesContent":["import React from 'react';\nimport { ShortText } from './ShortText';\nimport { useEntityPageContext } from '@wix/patterns';\nimport { useController } from '@wix/patterns/form';\nimport { Field, PatternsFieldType } from '../../../types';\nimport { Checkbox } from './Checkbox';\nimport { DateInput } from './DateInput';\nimport { DateTime } from './DateTime';\nimport { Number } from './Number';\nimport { LongText } from './LongText';\nimport { Url } from './Url';\nimport { BaseInputProps } from './types';\nimport { ImageInput } from './ImageInput';\n\nexport const EDITABLE_INPUT_ELEMENTS: Partial<\n Record<PatternsFieldType, React.ComponentType<any>>\n> = {\n SHORT_TEXT: ShortText,\n LONG_TEXT: LongText,\n BOOLEAN: Checkbox,\n DATE: DateInput,\n DATETIME: DateTime,\n NUMBER: Number,\n URL: Url,\n IMAGE: ImageInput,\n};\n\nexport interface FormFieldInputProps {\n field: Field;\n inputRef?: BaseInputProps<any>['inputRef'];\n}\n\nexport const FormFieldInput = (props: FormFieldInputProps) => {\n const { field, inputRef } = props;\n\n const pageState = useEntityPageContext();\n\n const controller = useController({\n name: field?.id ?? '',\n control: pageState.form.control,\n defaultValue: (pageState.entity as any)?.[field?.id ?? ''],\n });\n\n if (!EDITABLE_INPUT_ELEMENTS.hasOwnProperty(field.type) || !pageState) {\n return null;\n }\n\n const FieldInput = EDITABLE_INPUT_ELEMENTS[field.type]!;\n\n return (\n <FieldInput\n field={field}\n value={controller.field.value}\n onChange={controller.field.onChange}\n dataHook={`form-field-${field.id}`}\n inputRef={inputRef}\n />\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,oBAAoB,QAAQ,eAAe;AACpD,SAASC,aAAa,QAAQ,oBAAoB;AAElD,SAASC,QAAQ,QAAQ,YAAY;AACrC,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,QAAQ,QAAQ,YAAY;AACrC,SAASC,MAAM,QAAQ,UAAU;AACjC,SAASC,QAAQ,QAAQ,YAAY;AACrC,SAASC,GAAG,QAAQ,OAAO;AAE3B,SAASC,UAAU,QAAQ,cAAc;AAEzC,OAAO,MAAMC,uBAEZ,GAAG;EACFC,UAAU,EAAEX,SAAS;EACrBY,SAAS,EAAEL,QAAQ;EACnBM,OAAO,EAAEV,QAAQ;EACjBW,IAAI,EAAEV,SAAS;EACfW,QAAQ,EAAEV,QAAQ;EAClBW,MAAM,EAAEV,MAAM;EACdW,GAAG,EAAET,GAAG;EACRU,KAAK,EAAET;AACT,CAAC;AAOD,OAAO,MAAMU,cAAc,GAAIC,KAA0B,IAAK;EAC5D,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAC,GAAGF,KAAK;EAEjC,MAAMG,SAAS,GAAGtB,oBAAoB,CAAC,CAAC;EAExC,MAAMuB,UAAU,GAAGtB,aAAa,CAAC;IAC/BuB,IAAI,EAAEJ,KAAK,EAAEK,EAAE,IAAI,EAAE;IACrBC,OAAO,EAAEJ,SAAS,CAACK,IAAI,CAACD,OAAO;IAC/BE,YAAY,EAAGN,SAAS,CAACO,MAAM,GAAWT,KAAK,EAAEK,EAAE,IAAI,EAAE;EAC3D,CAAC,CAAC;EAEF,IAAI,CAAChB,uBAAuB,CAACqB,cAAc,CAACV,KAAK,CAACW,IAAI,CAAC,IAAI,CAACT,SAAS,EAAE;IACrE,OAAO,IAAI;EACb;EAEA,MAAMU,UAAU,GAAGvB,uBAAuB,CAACW,KAAK,CAACW,IAAI,CAAE;EAEvD,oBACEjC,KAAA,CAAAmC,aAAA,CAACD,UAAU;IACTZ,KAAK,EAAEA,KAAM;IACbc,KAAK,EAAEX,UAAU,CAACH,KAAK,CAACc,KAAM;IAC9BC,QAAQ,EAAEZ,UAAU,CAACH,KAAK,CAACe,QAAS;IACpCC,QAAQ,EAAE,cAAchB,KAAK,CAACK,EAAE,EAAG;IACnCJ,QAAQ,EAAEA;EAAS,CACpB,CAAC;AAEN,CAAC","ignoreList":[]}
@@ -5,7 +5,6 @@ import { useController } from '@wix/patterns/form';
5
5
  import { getImageUrl } from '../../../utils/media/getImageUrl';
6
6
  import { dashboard } from '@wix/dashboard';
7
7
  export const ImageInput = props => {
8
- var _pageState$entity, _field$validation2, _controller$fieldStat;
9
8
  const {
10
9
  field,
11
10
  dataHook
@@ -19,25 +18,23 @@ export const ImageInput = props => {
19
18
  const pageState = useEntityPageContext();
20
19
  async function openMedia() {
21
20
  try {
22
- var _chosenMediaItems$ite;
23
21
  const chosenMediaItems = await dashboard.openMediaManager({
24
22
  multiSelect: false,
25
23
  category: 'IMAGE'
26
24
  });
27
- const newImage = chosenMediaItems == null || (_chosenMediaItems$ite = chosenMediaItems.items[0]) == null || (_chosenMediaItems$ite = _chosenMediaItems$ite.media) == null || (_chosenMediaItems$ite = _chosenMediaItems$ite.image) == null ? void 0 : _chosenMediaItems$ite.image;
25
+ const newImage = chosenMediaItems?.items[0]?.media?.image?.image;
28
26
  controller.field.onChange(newImage);
29
27
  } catch (error) {
30
28
  console.error('Error opening Media Manager or no files selected:', error);
31
29
  }
32
30
  }
33
31
  const controller = useController({
34
- name: (field == null ? void 0 : field.id) ?? '',
32
+ name: field?.id ?? '',
35
33
  control: pageState.form.control,
36
- defaultValue: (_pageState$entity = pageState.entity) == null ? void 0 : _pageState$entity[(field == null ? void 0 : field.id) ?? ''],
34
+ defaultValue: pageState.entity?.[field?.id ?? ''],
37
35
  rules: {
38
36
  validate: value => {
39
- var _field$validation;
40
- if ((_field$validation = field.validation) != null && _field$validation.required && (value === null || value === undefined || value === '')) {
37
+ if (field.validation?.required && (value === null || value === undefined || value === '')) {
41
38
  return t('cairo.fieldValidation.requiredField');
42
39
  }
43
40
  return true;
@@ -47,9 +44,9 @@ export const ImageInput = props => {
47
44
  const imageUrl = controller.field.value && getImageUrl(controller.field.value);
48
45
  return /*#__PURE__*/React.createElement(FormField, {
49
46
  label: field.displayName,
50
- required: (_field$validation2 = field.validation) == null ? void 0 : _field$validation2.required,
47
+ required: field.validation?.required,
51
48
  status: controller.fieldState.error ? 'error' : undefined,
52
- statusMessage: (_controller$fieldStat = controller.fieldState.error) == null ? void 0 : _controller$fieldStat.message,
49
+ statusMessage: controller.fieldState.error?.message,
53
50
  dataHook: dataHook
54
51
  }, /*#__PURE__*/React.createElement(ImageViewer, {
55
52
  imageUrl: imageUrl,
@@ -1 +1 @@
1
- {"version":3,"names":["React","FormField","ImageViewer","useEntityPageContext","useIsMobile","useSelector","useWixPatternsContainer","useController","getImageUrl","dashboard","ImageInput","props","_pageState$entity","_field$validation2","_controller$fieldStat","field","dataHook","translate","t","container","initTask","status","isMobile","pageState","openMedia","_chosenMediaItems$ite","chosenMediaItems","openMediaManager","multiSelect","category","newImage","items","media","image","controller","onChange","error","console","name","id","control","form","defaultValue","entity","rules","validate","value","_field$validation","validation","required","undefined","imageUrl","createElement","label","displayName","fieldState","statusMessage","message","onAddImage","onUpdateImage","updateImageInfo","removeImageInfo","addImageInfo","height","width","fit","onRemoveImage"],"sources":["../../../../../src/components/AutoPatternsEntityPage/Fields/ImageInput.tsx"],"sourcesContent":["import React from 'react';\nimport { FormField, ImageViewer } from '@wix/design-system';\nimport { BaseInputProps } from './types';\nimport {\n useEntityPageContext,\n useIsMobile,\n useSelector,\n useWixPatternsContainer,\n} from '@wix/patterns';\nimport { useController } from '@wix/patterns/form';\nimport { getImageUrl } from '../../../utils/media/getImageUrl';\nimport { dashboard } from '@wix/dashboard';\n\nexport interface ImageInputProps extends BaseInputProps<string> {}\n\nexport const ImageInput = (props: ImageInputProps) => {\n const { field, dataHook } = props;\n\n const { translate: t, ...container } = useWixPatternsContainer();\n useSelector(() => container.initTask.status);\n const isMobile = useIsMobile();\n const pageState = useEntityPageContext();\n\n async function openMedia() {\n try {\n const chosenMediaItems = await dashboard.openMediaManager({\n multiSelect: false,\n category: 'IMAGE',\n });\n\n const newImage = chosenMediaItems?.items[0]?.media?.image?.image;\n\n controller.field.onChange(newImage);\n } catch (error) {\n console.error('Error opening Media Manager or no files selected:', error);\n }\n }\n\n const controller = useController({\n name: field?.id ?? '',\n control: pageState.form.control,\n defaultValue: (pageState.entity as any)?.[field?.id ?? ''],\n rules: {\n validate: (value) => {\n if (\n field.validation?.required &&\n (value === null || value === undefined || value === '')\n ) {\n return t('cairo.fieldValidation.requiredField');\n }\n\n return true;\n },\n },\n });\n\n const imageUrl =\n controller.field.value && getImageUrl(controller.field.value);\n\n return (\n <FormField\n label={field.displayName}\n required={field.validation?.required}\n status={controller.fieldState.error ? 'error' : undefined}\n statusMessage={controller.fieldState.error?.message}\n dataHook={dataHook}\n >\n <ImageViewer\n imageUrl={imageUrl}\n dataHook={`image-${field.id}`}\n onAddImage={isMobile ? undefined : () => openMedia()}\n onUpdateImage={isMobile ? undefined : () => openMedia()}\n updateImageInfo={t('cairo.replace-image.tooltip')}\n removeImageInfo={t('cairo.remove-image.tooltip')}\n addImageInfo={t('cairo.add-image.tooltip')}\n height=\"120px\"\n width=\"25%\"\n fit=\"cover\"\n onRemoveImage={() => controller.field.onChange(null)}\n />\n </FormField>\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,WAAW;IACViD,QAAQ,EAAEA,QAAS;IACnBnC,QAAQ,EAAE,SAASD,KAAK,CAACwB,EAAE,EAAG;IAC9BmB,UAAU,EAAEpC,QAAQ,GAAG4B,SAAS,GAAG,MAAM1B,SAAS,CAAC,CAAE;IACrDmC,aAAa,EAAErC,QAAQ,GAAG4B,SAAS,GAAG,MAAM1B,SAAS,CAAC,CAAE;IACxDoC,eAAe,EAAE1C,CAAC,CAAC,6BAA6B,CAAE;IAClD2C,eAAe,EAAE3C,CAAC,CAAC,4BAA4B,CAAE;IACjD4C,YAAY,EAAE5C,CAAC,CAAC,yBAAyB,CAAE;IAC3C6C,MAAM,EAAC,OAAO;IACdC,KAAK,EAAC,KAAK;IACXC,GAAG,EAAC,OAAO;IACXC,aAAa,EAAEA,CAAA,KAAMhC,UAAU,CAACnB,KAAK,CAACoB,QAAQ,CAAC,IAAI;EAAE,CACtD,CACQ,CAAC;AAEhB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","FormField","ImageViewer","useEntityPageContext","useIsMobile","useSelector","useWixPatternsContainer","useController","getImageUrl","dashboard","ImageInput","props","field","dataHook","translate","t","container","initTask","status","isMobile","pageState","openMedia","chosenMediaItems","openMediaManager","multiSelect","category","newImage","items","media","image","controller","onChange","error","console","name","id","control","form","defaultValue","entity","rules","validate","value","validation","required","undefined","imageUrl","createElement","label","displayName","fieldState","statusMessage","message","onAddImage","onUpdateImage","updateImageInfo","removeImageInfo","addImageInfo","height","width","fit","onRemoveImage"],"sources":["../../../../../src/components/AutoPatternsEntityPage/Fields/ImageInput.tsx"],"sourcesContent":["import React from 'react';\nimport { FormField, ImageViewer } from '@wix/design-system';\nimport { BaseInputProps } from './types';\nimport {\n useEntityPageContext,\n useIsMobile,\n useSelector,\n useWixPatternsContainer,\n} from '@wix/patterns';\nimport { useController } from '@wix/patterns/form';\nimport { getImageUrl } from '../../../utils/media/getImageUrl';\nimport { dashboard } from '@wix/dashboard';\n\nexport interface ImageInputProps extends BaseInputProps<string> {}\n\nexport const ImageInput = (props: ImageInputProps) => {\n const { field, dataHook } = props;\n\n const { translate: t, ...container } = useWixPatternsContainer();\n useSelector(() => container.initTask.status);\n const isMobile = useIsMobile();\n const pageState = useEntityPageContext();\n\n async function openMedia() {\n try {\n const chosenMediaItems = await dashboard.openMediaManager({\n multiSelect: false,\n category: 'IMAGE',\n });\n\n const newImage = chosenMediaItems?.items[0]?.media?.image?.image;\n\n controller.field.onChange(newImage);\n } catch (error) {\n console.error('Error opening Media Manager or no files selected:', error);\n }\n }\n\n const controller = useController({\n name: field?.id ?? '',\n control: pageState.form.control,\n defaultValue: (pageState.entity as any)?.[field?.id ?? ''],\n rules: {\n validate: (value) => {\n if (\n field.validation?.required &&\n (value === null || value === undefined || value === '')\n ) {\n return t('cairo.fieldValidation.requiredField');\n }\n\n return true;\n },\n },\n });\n\n const imageUrl =\n controller.field.value && getImageUrl(controller.field.value);\n\n return (\n <FormField\n label={field.displayName}\n required={field.validation?.required}\n status={controller.fieldState.error ? 'error' : undefined}\n statusMessage={controller.fieldState.error?.message}\n dataHook={dataHook}\n >\n <ImageViewer\n imageUrl={imageUrl}\n dataHook={`image-${field.id}`}\n onAddImage={isMobile ? undefined : () => openMedia()}\n onUpdateImage={isMobile ? undefined : () => openMedia()}\n updateImageInfo={t('cairo.replace-image.tooltip')}\n removeImageInfo={t('cairo.remove-image.tooltip')}\n addImageInfo={t('cairo.add-image.tooltip')}\n height=\"120px\"\n width=\"25%\"\n fit=\"cover\"\n onRemoveImage={() => controller.field.onChange(null)}\n />\n </FormField>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,SAAS,EAAEC,WAAW,QAAQ,oBAAoB;AAE3D,SACEC,oBAAoB,EACpBC,WAAW,EACXC,WAAW,EACXC,uBAAuB,QAClB,eAAe;AACtB,SAASC,aAAa,QAAQ,oBAAoB;AAClD,SAASC,WAAW,QAAQ,kCAAkC;AAC9D,SAASC,SAAS,QAAQ,gBAA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ageContext, useSelector, useWixPatternsContainer } from '@wix/patterns';
4
4
  import { useController } from '@wix/patterns/form';
5
5
  export const LongText = props => {
6
- var _pageState$entity, _field$validation2, _controller$fieldStat;
7
6
  const {
8
7
  field,
9
8
  dataHook
@@ -15,13 +14,12 @@ export const LongText = props => {
15
14
  useSelector(() => container.initTask.status);
16
15
  const pageState = useEntityPageContext();
17
16
  const controller = useController({
18
- name: (field == null ? void 0 : field.id) ?? '',
17
+ name: field?.id ?? '',
19
18
  control: pageState.form.control,
20
- defaultValue: (_pageState$entity = pageState.entity) == null ? void 0 : _pageState$entity[(field == null ? void 0 : field.id) ?? ''],
19
+ defaultValue: pageState.entity?.[field?.id ?? ''],
21
20
  rules: {
22
21
  validate: value => {
23
- var _field$validation;
24
- if ((_field$validation = field.validation) != null && _field$validation.required && (value === null || value === undefined || value === '')) {
22
+ if (field.validation?.required && (value === null || value === undefined || value === '')) {
25
23
  return t('cairo.fieldValidation.requiredField');
26
24
  }
27
25
  return true;
@@ -30,13 +28,13 @@ export const LongText = props => {
30
28
  });
31
29
  return /*#__PURE__*/React.createElement(FormField, {
32
30
  label: field.displayName,
33
- required: (_field$validation2 = field.validation) == null ? void 0 : _field$validation2.required,
31
+ required: field.validation?.required,
34
32
  status: controller.fieldState.error ? 'error' : undefined,
35
- statusMessage: (_controller$fieldStat = controller.fieldState.error) == null ? void 0 : _controller$fieldStat.message,
33
+ statusMessage: controller.fieldState.error?.message,
36
34
  dataHook: dataHook
37
35
  }, /*#__PURE__*/React.createElement(InputArea, {
38
36
  value: controller.field.value,
39
- onChange: e => controller.field.onChange == null ? void 0 : controller.field.onChange(e.target.value),
37
+ onChange: e => controller.field.onChange?.(e.target.value),
40
38
  onBlur: controller.field.onBlur,
41
39
  ref: controller.field.ref,
42
40
  dataHook: `long-text-${field.id}`
@@ -1 +1 @@
1
- {"version":3,"names":["React","FormField","InputArea","useEntityPageContext","useSelector","useWixPatternsContainer","useController","LongText","props","_pageState$entity","_field$validation2","_controller$fieldStat","field","dataHook","translate","t","container","initTask","status","pageState","controller","name","id","control","form","defaultValue","entity","rules","validate","value","_field$validation","validation","required","undefined","createElement","label","displayName","fieldState","error","statusMessage","message","onChange","e","target","onBlur","ref"],"sources":["../../../../../src/components/AutoPatternsEntityPage/Fields/LongText.tsx"],"sourcesContent":["import React from 'react';\nimport { FormField, InputArea } from '@wix/design-system';\nimport { BaseInputProps } from './types';\nimport {\n useEntityPageContext,\n useSelector,\n useWixPatternsContainer,\n} from '@wix/patterns';\nimport { useController } from '@wix/patterns/form';\n\nexport interface LongTextProps extends BaseInputProps<string> {}\n\nexport const LongText = (props: LongTextProps) => {\n const { field, dataHook } = props;\n\n const { translate: t, ...container } = useWixPatternsContainer();\n useSelector(() => container.initTask.status);\n\n const pageState = useEntityPageContext();\n\n const controller = useController({\n name: field?.id ?? '',\n control: pageState.form.control,\n defaultValue: (pageState.entity as any)?.[field?.id ?? ''],\n rules: {\n validate: (value) => {\n if (\n field.validation?.required &&\n (value === null || value === undefined || value === '')\n ) {\n return t('cairo.fieldValidation.requiredField');\n }\n\n return true;\n },\n },\n });\n\n return (\n <FormField\n label={field.displayName}\n required={field.validation?.required}\n status={controller.fieldState.error ? 'error' : undefined}\n statusMessage={controller.fieldState.error?.message}\n dataHook={dataHook}\n >\n <InputArea\n value={controller.field.value}\n onChange={(e) => controller.field.onChange?.(e.target.value)}\n onBlur={controller.field.onBlur}\n ref={controller.field.ref}\n dataHook={`long-text-${field.id}`}\n />\n </FormField>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,SAAS,EAAEC,SAAS,QAAQ,oBAAoB;AAEzD,SACEC,oBAAoB,EACpBC,WAAW,EACXC,uBAAuB,QAClB,eAAe;AACtB,SAASC,aAAa,QAAQ,oBAAoB;AAIlD,OAAO,MAAMC,QAAQ,GAAIC,KAAoB,IAAK;EAAA,IAAAC,iBAAA,EAAAC,kBAAA,EAAAC,qBAAA;EAChD,MAAM;IAAEC,KAAK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Q;IACpD3B,QAAQ,EAAEA;EAAS,gBAEnBb,KAAA,CAAAkC,aAAA,CAAChC,SAAS;IACR2B,KAAK,EAAET,UAAU,CAACR,KAAK,CAACiB,KAAM;IAC9BY,QAAQ,EAAGC,CAAC,IAAKtB,UAAU,CAACR,KAAK,CAAC6B,QAAQ,oBAAzBrB,UAAU,CAACR,KAAK,CAAC6B,QAAQ,CAAGC,CAAC,CAACC,MAAM,CAACd,KAAK,CAAE;IAC7De,MAAM,EAAExB,UAAU,CAACR,KAAK,CAACgC,MAAO;IAChCC,GAAG,EAAEzB,UAAU,CAACR,KAAK,CAACiC,GAAI;IAC1BhC,QAAQ,EAAE,aAAaD,KAAK,CAACU,EAAE;EAAG,CACnC,CACQ,CAAC;AAEhB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","FormField","InputArea","useEntityPageContext","useSelector","useWixPatternsContainer","useController","LongText","props","field","dataHook","translate","t","container","initTask","status","pageState","controller","name","id","control","form","defaultValue","entity","rules","validate","value","validation","required","undefined","createElement","label","displayName","fieldState","error","statusMessage","message","onChange","e","target","onBlur","ref"],"sources":["../../../../../src/components/AutoPatternsEntityPage/Fields/LongText.tsx"],"sourcesContent":["import React from 'react';\nimport { FormField, InputArea } from '@wix/design-system';\nimport { BaseInputProps } from './types';\nimport {\n useEntityPageContext,\n useSelector,\n useWixPatternsContainer,\n} from '@wix/patterns';\nimport { useController } from '@wix/patterns/form';\n\nexport interface LongTextProps extends BaseInputProps<string> {}\n\nexport const LongText = (props: LongTextProps) => {\n const { field, dataHook } = props;\n\n const { translate: t, ...container } = useWixPatternsContainer();\n useSelector(() => container.initTask.status);\n\n const pageState = useEntityPageContext();\n\n const controller = useController({\n name: field?.id ?? '',\n control: pageState.form.control,\n defaultValue: (pageState.entity as any)?.[field?.id ?? ''],\n rules: {\n validate: (value) => {\n if (\n field.validation?.required &&\n (value === null || value === undefined || value === '')\n ) {\n return t('cairo.fieldValidation.requiredField');\n }\n\n return true;\n },\n },\n });\n\n return (\n <FormField\n label={field.displayName}\n required={field.validation?.required}\n status={controller.fieldState.error ? 'error' : undefined}\n statusMessage={controller.fieldState.error?.message}\n dataHook={dataHook}\n >\n <InputArea\n value={controller.field.value}\n onChange={(e) => controller.field.onChange?.(e.target.value)}\n onBlur={controller.field.onBlur}\n ref={controller.field.ref}\n dataHook={`long-text-${field.id}`}\n />\n </FormField>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,SAAS,EAAEC,SAAS,QAAQ,oBAAoB;AAEzD,SACEC,oBAAoB,EACpBC,WAAW,EACXC,uBAAuB,QAClB,eAAe;AACtB,SAASC,aAAa,QAAQ,oBAAoB;AAIlD,OAAO,MAAMC,QAAQ,GAAIC,KAAoB,IAAK;EAChD,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAC,GAAGF,KAAK;EAEjC,MAAM;IAAEG,SAAS,EAAEC,CAAC;IAAE,GAAGC;EAAU,CAAC,GAAGR,uBAAuB,CAAC,CAAC;EAChED,WAAW,CAAC,MAAMS,SAAS,CAACC,QAAQ,CAACC,MAAM,CAAC;EAE5C,MAAMC,SAAS,GAAGb,oBAAoB,CAAC,CAAC;EAExC,MAAMc,UAAU,GAAGX,aAAa,CAAC;IAC/BY,IAAI,EAAET,KAAK,EAAEU,EAAE,IAAI,EAAE;IACrBC,OAAO,EAAEJ,SAAS,CAACK,IAAI,CAACD,OAAO;IAC/BE,YAAY,EAAGN,SAAS,CAACO,MAAM,GAAWd,KAAK,EAAEU,EAAE,IAAI,EAAE,CAAC;IAC1DK,KAAK,EAAE;MACLC,QAAQ,EAAGC,KAAK,IAAK;QACnB,IACEjB,KAAK,CAACkB,UAAU,EAAEC,QAAQ,KACzBF,KAAK,KAAK,IAAI,IAAIA,KAAK,KAAKG,SAAS,IAAIH,KAAK,KAAK,EAAE,CAAC,EACvD;UACA,OAAOd,CAAC,CAAC,qCAAqC,CAAC;QACjD;QAEA,OAAO,IAAI;MACb;IACF;EACF,CAAC,CAAC;EAEF,oBACEZ,KAAA,CAAA8B,aAAA,CAAC7B,SAAS;IACR8B,KAAK,EAAEtB,KAAK,CAACuB,WAAY;IACzBJ,QAAQ,EAAEnB,KAAK,CAACkB,UAAU,EAAEC,QAAS;IACrCb,MAAM,EAAEE,UAAU,CAACgB,UAAU,CAACC,KAAK,GAAG,OAAO,GAAGL,SAAU;IAC1DM,aAAa,EAAElB,UAAU,CAACgB,UAAU,CAACC,KAAK,EAAEE,OAAQ;IACpD1B,QAAQ,EAAEA;EAAS,gBAEnBV,KAAA,CAAA8B,aAAA,CAAC5B,SAAS;IACRwB,KAAK,EAAET,UAAU,CAACR,KAAK,CAACiB,KAAM;IAC9BW,QAAQ,EAAGC,CAAC,IAAKrB,UAAU,CAACR,KAAK,CAAC4B,QAAQ,GAAGC,CAAC,CAACC,MAAM,CAACb,KAAK,CAAE;IAC7Dc,MAAM,EAAEvB,UAAU,CAACR,KAAK,CAAC+B,MAAO;IAChCC,GAAG,EAAExB,UAAU,CAACR,KAAK,CAACgC,GAAI;IAC1B/B,QAAQ,EAAE,aAAaD,KAAK,CAACU,EAAE;EAAG,CACnC,CACQ,CAAC;AAEhB,CAAC","ignoreList":[]}
@@ -3,7 +3,6 @@ import { FormField, NumberInput } from '@wix/design-system';
3
3
  import { useEntityPageContext, useSelector, useWixPatternsContainer } from '@wix/patterns';
4
4
  import { useController } from '@wix/patterns/form';
5
5
  export const Number = props => {
6
- var _field$validation, _pageState$entity, _field$validation3, _controller$fieldStat;
7
6
  const {
8
7
  field,
9
8
  dataHook
@@ -14,17 +13,16 @@ export const Number = props => {
14
13
  } = useWixPatternsContainer();
15
14
  useSelector(() => container.initTask.status);
16
15
  const pageState = useEntityPageContext();
17
- const numberRange = (_field$validation = field.validation) == null ? void 0 : _field$validation.numberRange;
18
- const min = numberRange == null ? void 0 : numberRange.min;
19
- const max = numberRange == null ? void 0 : numberRange.max;
16
+ const numberRange = field.validation?.numberRange;
17
+ const min = numberRange?.min;
18
+ const max = numberRange?.max;
20
19
  const controller = useController({
21
- name: (field == null ? void 0 : field.id) ?? '',
20
+ name: field?.id ?? '',
22
21
  control: pageState.form.control,
23
- defaultValue: (_pageState$entity = pageState.entity) == null ? void 0 : _pageState$entity[(field == null ? void 0 : field.id) ?? ''],
22
+ defaultValue: pageState.entity?.[field?.id ?? ''],
24
23
  rules: {
25
24
  validate: value => {
26
- var _field$validation2;
27
- if ((_field$validation2 = field.validation) != null && _field$validation2.required && (value === null || value === undefined || value === '')) {
25
+ if (field.validation?.required && (value === null || value === undefined || value === '')) {
28
26
  return t('cairo.fieldValidation.requiredField');
29
27
  }
30
28
  if (value !== null && value !== undefined) {
@@ -45,9 +43,9 @@ export const Number = props => {
45
43
  });
46
44
  return /*#__PURE__*/React.createElement(FormField, {
47
45
  label: field.displayName,
48
- required: (_field$validation3 = field.validation) == null ? void 0 : _field$validation3.required,
46
+ required: field.validation?.required,
49
47
  status: controller.fieldState.error ? 'error' : undefined,
50
- statusMessage: (_controller$fieldStat = controller.fieldState.error) == null ? void 0 : _controller$fieldStat.message,
48
+ statusMessage: controller.fieldState.error?.message,
51
49
  dataHook: dataHook
52
50
  }, /*#__PURE__*/React.createElement(NumberInput, {
53
51
  value: controller.field.value ?? undefined,