@wix/auto-patterns 1.23.0 → 1.25.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 (207) hide show
  1. package/dist/cjs/components/AutoPatternsEntityPage/AutoPatternsEntityPage.js +12 -323
  2. package/dist/cjs/components/AutoPatternsEntityPage/AutoPatternsEntityPage.js.map +1 -1
  3. package/dist/cjs/components/AutoPatternsEntityPage/EditModeEntityPage.js +172 -0
  4. package/dist/cjs/components/AutoPatternsEntityPage/EditModeEntityPage.js.map +1 -0
  5. package/dist/cjs/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutCard.js +78 -0
  6. package/dist/cjs/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutCard.js.map +1 -0
  7. package/dist/cjs/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutContent.js +119 -0
  8. package/dist/cjs/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutContent.js.map +1 -0
  9. package/dist/cjs/components/AutoPatternsEntityPage/RenderLayout/RenderViewField.js +79 -0
  10. package/dist/cjs/components/AutoPatternsEntityPage/RenderLayout/RenderViewField.js.map +1 -0
  11. package/dist/cjs/components/AutoPatternsEntityPage/RenderLayout/index.js +16 -0
  12. package/dist/cjs/components/AutoPatternsEntityPage/RenderLayout/index.js.map +1 -0
  13. package/dist/cjs/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutCard.js +77 -0
  14. package/dist/cjs/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutCard.js.map +1 -0
  15. package/dist/cjs/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutContent.js +109 -0
  16. package/dist/cjs/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutContent.js.map +1 -0
  17. package/dist/cjs/components/AutoPatternsEntityPage/ViewModeEntityPage.js +198 -0
  18. package/dist/cjs/components/AutoPatternsEntityPage/ViewModeEntityPage.js.map +1 -0
  19. package/dist/cjs/components/AutoPatternsEntityPage/index.js +12 -0
  20. package/dist/cjs/components/AutoPatternsEntityPage/index.js.map +1 -1
  21. package/dist/cjs/dataSourceAdapters/cms/cmsAdapter.js +2 -1
  22. package/dist/cjs/dataSourceAdapters/cms/cmsAdapter.js.map +1 -1
  23. package/dist/cjs/hooks/useActionCell.js +2 -1
  24. package/dist/cjs/hooks/useActionCell.js.map +1 -1
  25. package/dist/cjs/hooks/useBulkActionToolbar.js +2 -1
  26. package/dist/cjs/hooks/useBulkActionToolbar.js.map +1 -1
  27. package/dist/cjs/hooks/useCollectionPageActions.js +2 -1
  28. package/dist/cjs/hooks/useCollectionPageActions.js.map +1 -1
  29. package/dist/cjs/hooks/useEntityPageActions.js +106 -0
  30. package/dist/cjs/hooks/useEntityPageActions.js.map +1 -0
  31. package/dist/cjs/hooks/useEntityPageMoreActions.js +11 -1
  32. package/dist/cjs/hooks/useEntityPageMoreActions.js.map +1 -1
  33. package/dist/cjs/hooks/useNavigateEditEntityAction.js +50 -0
  34. package/dist/cjs/hooks/useNavigateEditEntityAction.js.map +1 -0
  35. package/dist/cjs/hooks/useNavigationUtils.js +12 -1
  36. package/dist/cjs/hooks/useNavigationUtils.js.map +1 -1
  37. package/dist/cjs/providers/ErrorContext.js +6 -3
  38. package/dist/cjs/providers/ErrorContext.js.map +1 -1
  39. package/dist/cjs/providers/PatternsWizardOverridesContext.js +1 -1
  40. package/dist/cjs/providers/PatternsWizardOverridesContext.js.map +1 -1
  41. package/dist/cjs/types/EntityPageConfig.js.map +1 -1
  42. package/dist/cjs/types/actions/actionCell.js.map +1 -1
  43. package/dist/cjs/types/actions/entityPageActions.js.map +1 -1
  44. package/dist/cjs/utils/actions/types.js.map +1 -1
  45. package/dist/docs/action_cell.md +11 -6
  46. package/dist/docs/app_config_structure.md +49 -4
  47. package/dist/docs/auto-patterns-guide.md +311 -43
  48. package/dist/docs/bulk_actions.md +7 -2
  49. package/dist/docs/collection_page_actions.md +14 -4
  50. package/dist/docs/entity_page.md +65 -1
  51. package/dist/docs/entity_page_actions.md +13 -11
  52. package/dist/docs/entity_page_view_actions.md +137 -0
  53. package/dist/docs/index.md +6 -2
  54. package/dist/docs/pages_configuration.md +1 -11
  55. package/dist/docs/sdk_utilities.md +11 -4
  56. package/dist/docs/wix_fqdn_custom_data_source.md +25 -5
  57. package/dist/esm/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.js +4 -3
  58. package/dist/esm/components/AutoPatternsCollectionComponent/AutoPatternsCollectionComponent.js.map +1 -1
  59. package/dist/esm/components/AutoPatternsCollectionPageContent/AutoPatternsCollectionPageContent.js +2 -1
  60. package/dist/esm/components/AutoPatternsCollectionPageContent/AutoPatternsCollectionPageContent.js.map +1 -1
  61. package/dist/esm/components/AutoPatternsEntityPage/AutoPatternsEntityPage.js +9 -196
  62. package/dist/esm/components/AutoPatternsEntityPage/AutoPatternsEntityPage.js.map +1 -1
  63. package/dist/esm/components/AutoPatternsEntityPage/EditModeEntityPage.js +115 -0
  64. package/dist/esm/components/AutoPatternsEntityPage/EditModeEntityPage.js.map +1 -0
  65. package/dist/esm/components/AutoPatternsEntityPage/Fields/DateInput.js +10 -6
  66. package/dist/esm/components/AutoPatternsEntityPage/Fields/DateInput.js.map +1 -1
  67. package/dist/esm/components/AutoPatternsEntityPage/Fields/DateTime.js +23 -16
  68. package/dist/esm/components/AutoPatternsEntityPage/Fields/DateTime.js.map +1 -1
  69. package/dist/esm/components/AutoPatternsEntityPage/Fields/FormFieldInput.js +3 -2
  70. package/dist/esm/components/AutoPatternsEntityPage/Fields/FormFieldInput.js.map +1 -1
  71. package/dist/esm/components/AutoPatternsEntityPage/Fields/ImageInput.js +9 -6
  72. package/dist/esm/components/AutoPatternsEntityPage/Fields/ImageInput.js.map +1 -1
  73. package/dist/esm/components/AutoPatternsEntityPage/Fields/LongText.js +8 -6
  74. package/dist/esm/components/AutoPatternsEntityPage/Fields/LongText.js.map +1 -1
  75. package/dist/esm/components/AutoPatternsEntityPage/Fields/Number.js +10 -8
  76. package/dist/esm/components/AutoPatternsEntityPage/Fields/Number.js.map +1 -1
  77. package/dist/esm/components/AutoPatternsEntityPage/Fields/ShortText.js +12 -10
  78. package/dist/esm/components/AutoPatternsEntityPage/Fields/ShortText.js.map +1 -1
  79. package/dist/esm/components/AutoPatternsEntityPage/Fields/Url.js +8 -6
  80. package/dist/esm/components/AutoPatternsEntityPage/Fields/Url.js.map +1 -1
  81. package/dist/esm/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutCard.js +33 -0
  82. package/dist/esm/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutCard.js.map +1 -0
  83. package/dist/esm/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutContent.js +70 -0
  84. package/dist/esm/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutContent.js.map +1 -0
  85. package/dist/esm/components/AutoPatternsEntityPage/RenderLayout/RenderViewField.js +48 -0
  86. package/dist/esm/components/AutoPatternsEntityPage/RenderLayout/RenderViewField.js.map +1 -0
  87. package/dist/esm/components/AutoPatternsEntityPage/RenderLayout/index.js +3 -0
  88. package/dist/esm/components/AutoPatternsEntityPage/RenderLayout/index.js.map +1 -0
  89. package/dist/esm/components/AutoPatternsEntityPage/SkeletonEntity.js +7 -4
  90. package/dist/esm/components/AutoPatternsEntityPage/SkeletonEntity.js.map +1 -1
  91. package/dist/esm/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutCard.js +31 -0
  92. package/dist/esm/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutCard.js.map +1 -0
  93. package/dist/esm/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutContent.js +66 -0
  94. package/dist/esm/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutContent.js.map +1 -0
  95. package/dist/esm/components/AutoPatternsEntityPage/ViewModeEntityPage.js +111 -0
  96. package/dist/esm/components/AutoPatternsEntityPage/ViewModeEntityPage.js.map +1 -0
  97. package/dist/esm/components/AutoPatternsEntityPage/index.js +2 -0
  98. package/dist/esm/components/AutoPatternsEntityPage/index.js.map +1 -1
  99. package/dist/esm/components/ModalRenderer.js +2 -1
  100. package/dist/esm/components/ModalRenderer.js.map +1 -1
  101. package/dist/esm/components/modals/actions/BulkDeleteModal.js +12 -7
  102. package/dist/esm/components/modals/actions/BulkDeleteModal.js.map +1 -1
  103. package/dist/esm/components/modals/actions/CreateModal.js +11 -6
  104. package/dist/esm/components/modals/actions/CreateModal.js.map +1 -1
  105. package/dist/esm/components/modals/actions/EditModal.js +11 -6
  106. package/dist/esm/components/modals/actions/EditModal.js.map +1 -1
  107. package/dist/esm/dataSourceAdapters/cms/cmsAdapter.js +6 -4
  108. package/dist/esm/dataSourceAdapters/cms/cmsAdapter.js.map +1 -1
  109. package/dist/esm/dataSourceAdapters/cms/filterUtils.js +2 -1
  110. package/dist/esm/dataSourceAdapters/cms/filterUtils.js.map +1 -1
  111. package/dist/esm/dataSourceAdapters/cms/sortUtils.js +2 -2
  112. package/dist/esm/dataSourceAdapters/cms/sortUtils.js.map +1 -1
  113. package/dist/esm/hooks/useActionCell.js +14 -9
  114. package/dist/esm/hooks/useActionCell.js.map +1 -1
  115. package/dist/esm/hooks/useBaseTableFeatures.js +2 -1
  116. package/dist/esm/hooks/useBaseTableFeatures.js.map +1 -1
  117. package/dist/esm/hooks/useBulkActionToolbar.js +4 -3
  118. package/dist/esm/hooks/useBulkActionToolbar.js.map +1 -1
  119. package/dist/esm/hooks/useCollectionPageActions.js +5 -4
  120. package/dist/esm/hooks/useCollectionPageActions.js.map +1 -1
  121. package/dist/esm/hooks/useCollectionPageOnRowClickActions.js +1 -1
  122. package/dist/esm/hooks/useCollectionPageOnRowClickActions.js.map +1 -1
  123. package/dist/esm/hooks/useColumns.js +12 -7
  124. package/dist/esm/hooks/useColumns.js.map +1 -1
  125. package/dist/esm/hooks/useCommonCollectionFeatures.js +8 -7
  126. package/dist/esm/hooks/useCommonCollectionFeatures.js.map +1 -1
  127. package/dist/esm/hooks/useEmptyStates.js +6 -5
  128. package/dist/esm/hooks/useEmptyStates.js.map +1 -1
  129. package/dist/esm/hooks/useEntityPageActions.js +83 -0
  130. package/dist/esm/hooks/useEntityPageActions.js.map +1 -0
  131. package/dist/esm/hooks/useEntityPageMoreActions.js +12 -2
  132. package/dist/esm/hooks/useEntityPageMoreActions.js.map +1 -1
  133. package/dist/esm/hooks/useFilters.js +7 -7
  134. package/dist/esm/hooks/useFilters.js.map +1 -1
  135. package/dist/esm/hooks/useNavigateEditEntityAction.js +46 -0
  136. package/dist/esm/hooks/useNavigateEditEntityAction.js.map +1 -0
  137. package/dist/esm/hooks/useNavigationUtils.js +15 -3
  138. package/dist/esm/hooks/useNavigationUtils.js.map +1 -1
  139. package/dist/esm/hooks/usePagePath.js +4 -3
  140. package/dist/esm/hooks/usePagePath.js.map +1 -1
  141. package/dist/esm/hooks/useTableFeatures.js +2 -1
  142. package/dist/esm/hooks/useTableFeatures.js.map +1 -1
  143. package/dist/esm/providers/ErrorContext.js +4 -1
  144. package/dist/esm/providers/ErrorContext.js.map +1 -1
  145. package/dist/esm/providers/PatternsWizardOverridesContext.js.map +1 -1
  146. package/dist/esm/providers/SchemaContext.js +3 -2
  147. package/dist/esm/providers/SchemaContext.js.map +1 -1
  148. package/dist/esm/providers/SchemaRegistryContext.js +1 -1
  149. package/dist/esm/providers/SchemaRegistryContext.js.map +1 -1
  150. package/dist/esm/types/EntityPageConfig.js.map +1 -1
  151. package/dist/esm/types/actions/actionCell.js.map +1 -1
  152. package/dist/esm/types/actions/entityPageActions.js.map +1 -1
  153. package/dist/esm/utils/actions/customAction.js +2 -1
  154. package/dist/esm/utils/actions/customAction.js.map +1 -1
  155. package/dist/esm/utils/actions/deleteAction.js +10 -5
  156. package/dist/esm/utils/actions/deleteAction.js.map +1 -1
  157. package/dist/esm/utils/actions/types.js.map +1 -1
  158. package/dist/esm/utils/filterCreators.js +11 -11
  159. package/dist/esm/utils/filterCreators.js.map +1 -1
  160. package/dist/types/components/AutoPatternsEntityPage/AutoPatternsEntityPage.d.ts.map +1 -1
  161. package/dist/types/components/AutoPatternsEntityPage/EditModeEntityPage.d.ts +6 -0
  162. package/dist/types/components/AutoPatternsEntityPage/EditModeEntityPage.d.ts.map +1 -0
  163. package/dist/types/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutCard.d.ts +11 -0
  164. package/dist/types/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutCard.d.ts.map +1 -0
  165. package/dist/types/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutContent.d.ts +13 -0
  166. package/dist/types/components/AutoPatternsEntityPage/RenderLayout/RenderLayoutContent.d.ts.map +1 -0
  167. package/dist/types/components/AutoPatternsEntityPage/RenderLayout/RenderViewField.d.ts +8 -0
  168. package/dist/types/components/AutoPatternsEntityPage/RenderLayout/RenderViewField.d.ts.map +1 -0
  169. package/dist/types/components/AutoPatternsEntityPage/RenderLayout/index.d.ts +3 -0
  170. package/dist/types/components/AutoPatternsEntityPage/RenderLayout/index.d.ts.map +1 -0
  171. package/dist/types/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutCard.d.ts +8 -0
  172. package/dist/types/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutCard.d.ts.map +1 -0
  173. package/dist/types/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutContent.d.ts +8 -0
  174. package/dist/types/components/AutoPatternsEntityPage/ViewEntityPage/RenderViewLayoutContent.d.ts.map +1 -0
  175. package/dist/types/components/AutoPatternsEntityPage/ViewModeEntityPage.d.ts +8 -0
  176. package/dist/types/components/AutoPatternsEntityPage/ViewModeEntityPage.d.ts.map +1 -0
  177. package/dist/types/components/AutoPatternsEntityPage/index.d.ts +2 -0
  178. package/dist/types/components/AutoPatternsEntityPage/index.d.ts.map +1 -1
  179. package/dist/types/dataSourceAdapters/cms/cmsAdapter.d.ts.map +1 -1
  180. package/dist/types/hooks/useActionCell.d.ts.map +1 -1
  181. package/dist/types/hooks/useEntityPageActions.d.ts +9 -0
  182. package/dist/types/hooks/useEntityPageActions.d.ts.map +1 -0
  183. package/dist/types/hooks/useEntityPageHeaderTexts.d.ts.map +1 -1
  184. package/dist/types/hooks/useEntityPageMoreActions.d.ts +2 -2
  185. package/dist/types/hooks/useEntityPageMoreActions.d.ts.map +1 -1
  186. package/dist/types/hooks/useNavigateEditEntityAction.d.ts +6 -0
  187. package/dist/types/hooks/useNavigateEditEntityAction.d.ts.map +1 -0
  188. package/dist/types/hooks/useNavigationUtils.d.ts +1 -0
  189. package/dist/types/hooks/useNavigationUtils.d.ts.map +1 -1
  190. package/dist/types/providers/ErrorContext.d.ts +7 -0
  191. package/dist/types/providers/ErrorContext.d.ts.map +1 -1
  192. package/dist/types/providers/PatternsWizardOverridesContext.d.ts +2 -2
  193. package/dist/types/providers/PatternsWizardOverridesContext.d.ts.map +1 -1
  194. package/dist/types/types/EntityPageConfig.d.ts +20 -4
  195. package/dist/types/types/EntityPageConfig.d.ts.map +1 -1
  196. package/dist/types/types/actions/actionCell.d.ts +7 -1
  197. package/dist/types/types/actions/actionCell.d.ts.map +1 -1
  198. package/dist/types/types/actions/entityPageActions.d.ts +24 -5
  199. package/dist/types/types/actions/entityPageActions.d.ts.map +1 -1
  200. package/dist/types/utils/actions/customAction.d.ts +1 -1
  201. package/dist/types/utils/actions/customAction.d.ts.map +1 -1
  202. package/dist/types/utils/actions/resolveAction.d.ts +1 -0
  203. package/dist/types/utils/actions/resolveAction.d.ts.map +1 -1
  204. package/dist/types/utils/actions/types.d.ts +2 -1
  205. package/dist/types/utils/actions/types.d.ts.map +1 -1
  206. package/package.json +16 -15
  207. package/dist/docs/config_schema.md +0 -184
@@ -1,202 +1,15 @@
1
- import React, { useMemo, useRef } from 'react';
2
- import { EntityPage, useEntity, useEntityPage, useEntityPageContext, MoreActions } from '@wix/patterns';
3
- import { useForm } from '@wix/patterns/form';
4
- import { Card, Cell, Layout } from '@wix/design-system';
5
- import { useParams } from 'react-router-dom';
6
- import { useSchema } from '../../providers/SchemaContext';
7
- import { FormFieldInput } from './Fields/FormFieldInput';
8
- import { useEntityPageHeaderTexts, useNavigation } from '../../hooks';
9
- import { usePatternsWizardOverridesContext } from '../../providers';
10
- import { useEntityPageMoreActions } from '../../hooks/useEntityPageMoreActions';
11
- import { useActionsSDK } from '../../hooks/useActionsSDK';
12
- const RenderLayoutContent = _ref => {
13
- let {
14
- content,
15
- level,
16
- sectionId,
17
- cardIndex,
18
- contentIndex,
19
- setInputRef
20
- } = _ref;
21
- const schema = useSchema();
22
- const overrides = usePatternsWizardOverridesContext();
23
- const pageState = useEntityPageContext();
24
- switch (content.type) {
25
- case 'field':
26
- if (!content.field.fieldId) {
27
- return null;
28
- }
29
- const field = schema.fields[content.field.fieldId];
30
- if (!field) {
31
- return null;
32
- }
33
- return /*#__PURE__*/React.createElement(Cell, {
34
- span: content.field.span
35
- }, /*#__PURE__*/React.createElement(FormFieldInput, {
36
- key: content.field.fieldId,
37
- field: field,
38
- inputRef: ref => setInputRef(content.field.fieldId, ref)
39
- }));
40
- case 'container':
41
- if (!content.container.children?.length) {
42
- return null;
43
- }
44
- return /*#__PURE__*/React.createElement(Cell, {
45
- span: content.container.span
46
- }, /*#__PURE__*/React.createElement(Layout, null, content.container.children.map((child, index) => /*#__PURE__*/React.createElement(RenderLayoutContent, {
47
- key: `${sectionId}-card-${cardIndex}-content-${contentIndex}-level-${level}-child-${index}`,
48
- content: child,
49
- level: level + 1,
50
- sectionId: sectionId,
51
- cardIndex: cardIndex,
52
- contentIndex: index,
53
- setInputRef: setInputRef
54
- }))));
55
- case 'component':
56
- if (!content.component.componentId) {
57
- return null;
58
- }
59
- const Component = overrides?.components?.[content.component.componentId];
60
- if (!Component) {
61
- return null;
62
- }
63
- return /*#__PURE__*/React.createElement(Cell, {
64
- span: content.component.span
65
- }, /*#__PURE__*/React.createElement(Component, {
66
- form: pageState.form,
67
- entity: pageState.entity
68
- }));
69
- default:
70
- return null;
71
- }
72
- };
73
- const RenderLayoutCard = _ref2 => {
74
- let {
75
- layout,
76
- sectionId,
77
- cardIndex,
78
- setInputRef
79
- } = _ref2;
80
- switch (layout.type) {
81
- case 'card':
82
- return /*#__PURE__*/React.createElement(EntityPage.Card, {
83
- minHeight: "50px"
84
- }, /*#__PURE__*/React.createElement(Card.Header, {
85
- title: layout.card.title.text,
86
- subtitle: layout.card.subtitle?.text
87
- }), /*#__PURE__*/React.createElement(Card.Divider, null), /*#__PURE__*/React.createElement(Card.Content, null, /*#__PURE__*/React.createElement(Layout, null, layout.card.children.map((child, index) => /*#__PURE__*/React.createElement(RenderLayoutContent, {
88
- key: `${sectionId}-card-${cardIndex}-content-${index}`,
89
- content: child,
90
- level: 0,
91
- sectionId: sectionId,
92
- cardIndex: cardIndex,
93
- contentIndex: index,
94
- setInputRef: setInputRef
95
- })))));
96
- default:
97
- return null;
98
- }
99
- };
100
- export const AutoPatternsEntityPage = _ref3 => {
1
+ import React from 'react';
2
+ import { ViewModeEntityPage } from './ViewModeEntityPage';
3
+ import { EditModeEntityPage } from './EditModeEntityPage';
4
+ export const AutoPatternsEntityPage = _ref => {
101
5
  let {
102
6
  configuration
103
- } = _ref3;
104
- const {
105
- layout: pageLayout,
106
- parentPageId,
107
- route,
108
- moreActions,
109
- collectionId
110
- } = configuration;
111
- const form = useForm({
112
- mode: 'onChange'
113
- });
114
- const params = useParams();
115
- const entityId = params[route.params.id];
116
- const schema = useSchema();
117
- const isCreateMode = !entityId;
118
- const inputRefs = useRef({});
119
- const setInputRef = (id, input) => {
120
- inputRefs.current[id] = input;
121
- };
122
- const validate = () => {
123
- const invalidFieldId = Object.keys(inputRefs.current).find(fieldId => {
124
- return inputRefs.current[fieldId]?.invalid;
125
- });
126
- if (invalidFieldId) {
127
- inputRefs.current[invalidFieldId]?.focus?.();
128
- throw new Error('Invalid form');
129
- }
130
- };
131
- const {
132
- getParentPagePath
133
- } = useNavigation();
134
- const parentPath = useMemo(() => getParentPagePath(parentPageId), [parentPageId, getParentPagePath]);
135
- const state = useEntityPage({
136
- parentPath,
137
- form,
138
- onSave: async () => {
139
- validate();
140
- const formValues = form.getValues();
141
- const baseEntity = state.entity || {};
142
- const updatedEntity = {
143
- ...baseEntity,
144
- ...formValues
145
- };
146
- const newEntity = entityId ? await schema.actions.update(updatedEntity) : await schema.actions.create(updatedEntity);
147
- return {
148
- updatedEntity: newEntity
149
- };
150
- },
151
- fetch: async () => {
152
- if (!entityId) {
153
- return {
154
- entity: undefined
155
- };
156
- }
157
- const entity = await schema.actions.get(entityId);
158
- return {
159
- entity
160
- };
161
- }
162
- });
163
- const entity = useEntity(state);
164
- const {
165
- title,
166
- subtitle
167
- } = useEntityPageHeaderTexts({
168
- config: configuration,
169
- isCreateMode,
170
- entityDisplayName: entity?.[schema.displayField]
171
- });
172
- const sdk = useActionsSDK({
173
- collectionId
7
+ } = _ref;
8
+ return configuration.mode === 'view' ? /*#__PURE__*/React.createElement(ViewModeEntityPage, {
9
+ configuration: configuration
10
+ }) : /*#__PURE__*/React.createElement(EditModeEntityPage, {
11
+ configuration: configuration
174
12
  });
175
- const resolvedMoreActions = useEntityPageMoreActions(moreActions, entity, sdk, form);
176
- return /*#__PURE__*/React.createElement(EntityPage, {
177
- state: state,
178
- dataHook: "auto-patterns-entity-page"
179
- }, /*#__PURE__*/React.createElement(EntityPage.Header, {
180
- title: title,
181
- subtitle: subtitle,
182
- moreActions: resolvedMoreActions.length > 0 ? /*#__PURE__*/React.createElement(MoreActions, {
183
- items: resolvedMoreActions
184
- }) : undefined
185
- }), /*#__PURE__*/React.createElement(EntityPage.Content, null, /*#__PURE__*/React.createElement(EntityPage.MainContent, {
186
- dataHook: "entity-page-main-content"
187
- }, pageLayout?.main?.map((layout, layoutIndex) => /*#__PURE__*/React.createElement(RenderLayoutCard, {
188
- key: `main-section-card-${layoutIndex}`,
189
- layout: layout,
190
- sectionId: "main",
191
- cardIndex: layoutIndex,
192
- setInputRef: setInputRef
193
- }))), pageLayout?.sidebar ? /*#__PURE__*/React.createElement(EntityPage.AdditionalContent, null, pageLayout.sidebar?.map((layout, layoutIndex) => /*#__PURE__*/React.createElement(RenderLayoutCard, {
194
- key: `sidebar-section-card-${layoutIndex}`,
195
- layout: layout,
196
- sectionId: "sidebar",
197
- cardIndex: layoutIndex,
198
- setInputRef: setInputRef
199
- }))) : null));
200
13
  };
201
14
 
202
15
  /*
@@ -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","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,oBAAoB,EACpBC,WAAW,QACN,eAAe;AACtB,SAASC,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,IAAI,EAAEC,IAAI,EAAEC,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AChE,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":[]}
1
+ {"version":3,"names":["React","ViewModeEntityPage","EditModeEntityPage","AutoPatternsEntityPage","_ref","configuration","mode","createElement"],"sources":["../../../../src/components/AutoPatternsEntityPage/AutoPatternsEntityPage.tsx"],"sourcesContent":["import React from 'react';\nimport { EntityPageConfig } from '../../types';\nimport { ViewModeEntityPage } from './ViewModeEntityPage';\nimport { EditModeEntityPage } from './EditModeEntityPage';\n\nexport interface AutoPatternsEntityPageProps {\n configuration: EntityPageConfig;\n}\n\nexport const AutoPatternsEntityPage: React.FC<AutoPatternsEntityPageProps> = ({\n configuration,\n}) => {\n return configuration.mode === 'view' ? (\n <ViewModeEntityPage configuration={configuration} />\n ) : (\n <EditModeEntityPage configuration={configuration} />\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,MAAM,OAAO;AAEzB,SAASC,kBAAkB,QAAQ,sBAAsB;AACzD,SAASC,kBAAkB,QAAQ,sBAAsB;AAMzD,OAAO,MAAMC,sBAA6D,GAAGC,IAAA,IAEvE;EAAA,IAFwE;IAC5EC;EACF,CAAC,GAAAD,IAAA;EACC,OAAOC,aAAa,CAACC,IAAI,KAAK,MAAM,gBAClCN,KAAA,CAAAO,aAAA,CAACN,kBAAkB;IAACI,aAAa,EAAEA;EAAc,CAAE,CAAC,gBAEpDL,KAAA,CAAAO,aAAA,CAACL,kBAAkB;IAACG,aAAa,EAAEA;EAAc,CAAE,CACpD;AACH,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -0,0 +1,115 @@
1
+ import React, { useMemo, useRef } from 'react';
2
+ import { EntityPage, useEntity, useEntityPage, MoreActions } from '@wix/patterns';
3
+ import { useForm } from '@wix/patterns/form';
4
+ import { useParams } from 'react-router-dom';
5
+ import { useSchema } from '../../providers/SchemaContext';
6
+ import { useEntityPageHeaderTexts, useNavigation } from '../../hooks';
7
+ import { useEntityPageMoreActions } from '../../hooks/useEntityPageMoreActions';
8
+ import { useActionsSDK } from '../../hooks/useActionsSDK';
9
+ import { RenderLayoutCard } from './RenderLayout';
10
+ export const EditModeEntityPage = _ref => {
11
+ var _pageLayout$main, _pageLayout$sidebar;
12
+ let {
13
+ configuration
14
+ } = _ref;
15
+ const {
16
+ layout: pageLayout,
17
+ parentPageId,
18
+ route,
19
+ actions,
20
+ collectionId
21
+ } = configuration;
22
+ const moreActions = actions == null ? void 0 : actions.moreActions;
23
+ const form = useForm({
24
+ mode: 'onChange'
25
+ });
26
+ const params = useParams();
27
+ const entityId = params[route.params.id];
28
+ const schema = useSchema();
29
+ const isCreateMode = !entityId;
30
+ const inputRefs = useRef({});
31
+ const setInputRef = (id, input) => {
32
+ inputRefs.current[id] = input;
33
+ };
34
+ const validate = () => {
35
+ const invalidFieldId = Object.keys(inputRefs.current).find(fieldId => {
36
+ var _inputRefs$current$fi;
37
+ return (_inputRefs$current$fi = inputRefs.current[fieldId]) == null ? void 0 : _inputRefs$current$fi.invalid;
38
+ });
39
+ if (invalidFieldId) {
40
+ var _inputRefs$current$in;
41
+ (_inputRefs$current$in = inputRefs.current[invalidFieldId]) == null || _inputRefs$current$in.focus == null || _inputRefs$current$in.focus();
42
+ throw new Error('Invalid form');
43
+ }
44
+ };
45
+ const {
46
+ getParentPagePath
47
+ } = useNavigation();
48
+ const parentPath = useMemo(() => getParentPagePath(parentPageId), [parentPageId, getParentPagePath]);
49
+ const state = useEntityPage({
50
+ parentPath,
51
+ form,
52
+ onSave: async () => {
53
+ validate();
54
+ const formValues = form.getValues();
55
+ const baseEntity = state.entity || {};
56
+ const updatedEntity = {
57
+ ...baseEntity,
58
+ ...formValues
59
+ };
60
+ const newEntity = entityId ? await schema.actions.update(updatedEntity) : await schema.actions.create(updatedEntity);
61
+ return {
62
+ updatedEntity: newEntity
63
+ };
64
+ },
65
+ fetch: async () => {
66
+ if (!entityId) {
67
+ return {
68
+ entity: undefined
69
+ };
70
+ }
71
+ const entity = await schema.actions.get(entityId);
72
+ return {
73
+ entity
74
+ };
75
+ }
76
+ });
77
+ const entity = useEntity(state);
78
+ const {
79
+ title,
80
+ subtitle
81
+ } = useEntityPageHeaderTexts({
82
+ config: configuration,
83
+ isCreateMode,
84
+ entityDisplayName: entity == null ? void 0 : entity[schema.displayField]
85
+ });
86
+ const sdk = useActionsSDK({
87
+ collectionId
88
+ });
89
+ const resolvedMoreActions = useEntityPageMoreActions(moreActions, entity, sdk, form);
90
+ return /*#__PURE__*/React.createElement(EntityPage, {
91
+ state: state,
92
+ dataHook: "auto-patterns-entity-page"
93
+ }, /*#__PURE__*/React.createElement(EntityPage.Header, {
94
+ title: title,
95
+ subtitle: subtitle,
96
+ moreActions: resolvedMoreActions.length > 0 ? /*#__PURE__*/React.createElement(MoreActions, {
97
+ items: resolvedMoreActions
98
+ }) : undefined
99
+ }), /*#__PURE__*/React.createElement(EntityPage.Content, null, /*#__PURE__*/React.createElement(EntityPage.MainContent, {
100
+ dataHook: "entity-page-main-content"
101
+ }, pageLayout == null || (_pageLayout$main = pageLayout.main) == null ? void 0 : _pageLayout$main.map((layout, layoutIndex) => /*#__PURE__*/React.createElement(RenderLayoutCard, {
102
+ key: `main-section-card-${layoutIndex}`,
103
+ layout: layout,
104
+ sectionId: "main",
105
+ cardIndex: layoutIndex,
106
+ setInputRef: setInputRef
107
+ }))), pageLayout != null && pageLayout.sidebar ? /*#__PURE__*/React.createElement(EntityPage.AdditionalContent, null, (_pageLayout$sidebar = pageLayout.sidebar) == null ? void 0 : _pageLayout$sidebar.map((layout, layoutIndex) => /*#__PURE__*/React.createElement(RenderLayoutCard, {
108
+ key: `sidebar-section-card-${layoutIndex}`,
109
+ layout: layout,
110
+ sectionId: "sidebar",
111
+ cardIndex: layoutIndex,
112
+ setInputRef: setInputRef
113
+ }))) : null));
114
+ };
115
+ //# sourceMappingURL=EditModeEntityPage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useMemo","useRef","EntityPage","useEntity","useEntityPage","MoreActions","useForm","useParams","useSchema","useEntityPageHeaderTexts","useNavigation","useEntityPageMoreActions","useActionsSDK","RenderLayoutCard","EditModeEntityPage","_ref","_pageLayout$main","_pageLayout$sidebar","configuration","layout","pageLayout","parentPageId","route","actions","collectionId","moreActions","form","mode","params","entityId","id","schema","isCreateMode","inputRefs","setInputRef","input","current","validate","invalidFieldId","Object","keys","find","fieldId","_inputRefs$current$fi","invalid","_inputRefs$current$in","focus","Error","getParentPagePath","parentPath","state","onSave","formValues","getValues","baseEntity","entity","updatedEntity","newEntity","update","create","fetch","undefined","get","title","subtitle","config","entityDisplayName","displayField","sdk","resolvedMoreActions","createElement","dataHook","Header","length","items","Content","MainContent","main","map","layoutIndex","key","sectionId","cardIndex","sidebar","AdditionalContent"],"sources":["../../../../src/components/AutoPatternsEntityPage/EditModeEntityPage.tsx"],"sourcesContent":["import React, { useMemo, useRef } from 'react';\nimport {\n EntityPage,\n EntityPageState,\n useEntity,\n useEntityPage,\n MoreActions,\n} from '@wix/patterns';\nimport { useForm } from '@wix/patterns/form';\nimport { useParams } from 'react-router-dom';\nimport { useSchema } from '../../providers/SchemaContext';\nimport { BaseInputRef } from './Fields/types';\nimport { useEntityPageHeaderTexts, useNavigation } from '../../hooks';\nimport { useEntityPageMoreActions } from '../../hooks/useEntityPageMoreActions';\nimport { useActionsSDK } from '../../hooks/useActionsSDK';\nimport { RenderLayoutCard } from './RenderLayout';\nimport { EditEntityPageConfig } from '../../types';\n\nexport const EditModeEntityPage: React.FC<{\n configuration: EditEntityPageConfig;\n}> = ({ configuration }) => {\n const {\n layout: pageLayout,\n parentPageId,\n route,\n actions,\n collectionId,\n } = configuration;\n\n const moreActions = actions?.moreActions;\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"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAC9C,SACEC,UAAU,EAEVC,SAAS,EACTC,aAAa,EACbC,WAAW,QACN,eAAe;AACtB,SAASC,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,SAAS,QAAQ,+BAA+B;AAEzD,SAASC,wBAAwB,EAAEC,aAAa,QAAQ,aAAa;AACrE,SAASC,wBAAwB,QAAQ,sCAAsC;AAC/E,SAASC,aAAa,QAAQ,2BAA2B;AACzD,SAASC,gBAAgB,QAAQ,gBAAgB;AAGjD,OAAO,MAAMC,kBAEX,GAAGC,IAAA,IAAuB;EAAA,IAAAC,gBAAA,EAAAC,mBAAA;EAAA,IAAtB;IAAEC;EAAc,CAAC,GAAAH,IAAA;EACrB,MAAM;IACJI,MAAM,EAAEC,UAAU;IAClBC,YAAY;IACZC,KAAK;IACLC,OAAO;IACPC;EACF,CAAC,GAAGN,aAAa;EAEjB,MAAMO,WAAW,GAAGF,OAAO,oBAAPA,OAAO,CAAEE,WAAW;EAExC,MAAMC,IAAI,GAAGpB,OAAO,CAAM;IACxBqB,IAAI,EAAE;EACR,CAAC,CAAC;EACF,MAAMC,MAAM,GAAGrB,SAAS,CAAC,CAAC;EAC1B,MAAMsB,QAAQ,GAAGD,MAAM,CAACN,KAAK,CAACM,MAAM,CAACE,EAAE,CAAC;EACxC,MAAMC,MAAM,GAAGvB,SAAS,CAAC,CAAC;EAC1B,MAAMwB,YAAY,GAAG,CAACH,QAAQ;EAE9B,MAAMI,SAAS,GAAGhC,MAAM,CAAsC,CAAC,CAAC,CAAC;EAEjE,MAAMiC,WAAW,GAAGA,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AAA,CAAAuE,aAAA,CAACpE,UAAU,CAAC0E,WAAW;IAACL,QAAQ,EAAC;EAA0B,GACxDnD,UAAU,aAAAJ,gBAAA,GAAVI,UAAU,CAAEyD,IAAI,qBAAhB7D,gBAAA,CAAkB8D,GAAG,CAAC,CAAC3D,MAAM,EAAE4D,WAAW,kBACzChF,KAAA,CAAAuE,aAAA,CAACzD,gBAAgB;IACfmE,GAAG,EAAE,qBAAqBD,WAAW,EAAG;IACxC5D,MAAM,EAAEA,MAAO;IACf8D,SAAS,EAAC,MAAM;IAChBC,SAAS,EAAEH,WAAY;IACvB7C,WAAW,EAAEA;EAAY,CAC1B,CACF,CACqB,CAAC,EACxBd,UAAU,YAAVA,UAAU,CAAE+D,OAAO,gBAClBpF,KAAA,CAAAuE,aAAA,CAACpE,UAAU,CAACkF,iBAAiB,SAAAnE,mBAAA,GAC1BG,UAAU,CAAC+D,OAAO,qBAAlBlE,mBAAA,CAAoB6D,GAAG,CAAC,CAAC3D,MAAM,EAAE4D,WAAW,kBAC3ChF,KAAA,CAAAuE,aAAA,CAACzD,gBAAgB;IACfmE,GAAG,EAAE,wBAAwBD,WAAW,EAAG;IAC3C5D,MAAM,EAAEA,MAAO;IACf8D,SAAS,EAAC,SAAS;IACnBC,SAAS,EAAEH,WAAY;IACvB7C,WAAW,EAAEA;EAAY,CAC1B,CACF,CAC2B,CAAC,GAC7B,IACc,CACV,CAAC;AAEjB,CAAC","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?.required && (value === null || value === undefined || value === '')) {
7
+ if (validation != null && 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,6 +14,7 @@ function validateDateField(value, validation, t, format, validationType) {
14
14
  return '';
15
15
  }
16
16
  export const DateInput = props => {
17
+ var _pageState$entity, _field$validation;
17
18
  const {
18
19
  field,
19
20
  dataHook,
@@ -26,9 +27,9 @@ export const DateInput = props => {
26
27
  useSelector(() => container.initTask.status);
27
28
  const pageState = useEntityPageContext();
28
29
  const controller = useController({
29
- name: field?.id ?? '',
30
+ name: (field == null ? void 0 : field.id) ?? '',
30
31
  control: pageState.form.control,
31
- defaultValue: pageState.entity?.[field?.id ?? ''],
32
+ defaultValue: (_pageState$entity = pageState.entity) == null ? void 0 : _pageState$entity[(field == null ? void 0 : field.id) ?? ''],
32
33
  rules: {
33
34
  validate: value => {
34
35
  const error = validateDateField(value, field.validation, t);
@@ -46,13 +47,16 @@ export const DateInput = props => {
46
47
  const [errorMessage, setErrorMessage] = useState('');
47
48
  return /*#__PURE__*/React.createElement(FormField, {
48
49
  label: field.displayName,
49
- required: field.validation?.required,
50
+ required: (_field$validation = field.validation) == null ? void 0 : _field$validation.required,
50
51
  dataHook: dataHook
51
52
  }, /*#__PURE__*/React.createElement(DatePicker, {
52
53
  ref: internalRef => {
53
- inputRef?.(ref.current);
54
+ inputRef == null || inputRef(ref.current);
54
55
  // @ts-expect-error: WSR internal API hack for focusing
55
- ref.current.focus = () => internalRef?.state?.inputRef?.focus?.();
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
+ };
56
60
  },
57
61
  dataHook: `date-${field.id}`,
58
62
  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","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,EAA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O,CAACvB,SAAS,CAAC;QAClBY,UAAU,CAACR,KAAK,CAAC+B,QAAQ,CAAC,IAAI,CAAC;MACjC;IACF,CAAE;IACFzB,MAAM,EAAEe,YAAY,GAAG,OAAO,GAAGzB,SAAU;IAC3C0C,aAAa,EAAEjB;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","_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;AAK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bd,OAAO,CAACc,QAAQ,CAAC;MACjB,IAAIA,QAAQ,EAAE;QACZ,MAAMC,aAAa,GAAGpD,iCAAiC,CAACmD,QAAQ,CAAC;QACjEzB,UAAU,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":[]}
@@ -3,6 +3,7 @@ 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;
6
7
  const {
7
8
  field,
8
9
  dataHook,
@@ -15,12 +16,13 @@ export const DateTime = props => {
15
16
  useSelector(() => container.initTask.status);
16
17
  const pageState = useEntityPageContext();
17
18
  const controller = useController({
18
- name: field?.id ?? '',
19
+ name: (field == null ? void 0 : field.id) ?? '',
19
20
  control: pageState.form.control,
20
- defaultValue: pageState.entity?.[field?.id ?? ''],
21
+ defaultValue: (_pageState$entity = pageState.entity) == null ? void 0 : _pageState$entity[(field == null ? void 0 : field.id) ?? ''],
21
22
  rules: {
22
23
  validate: v => {
23
- if (field?.validation?.required && (v === null || v === undefined || v === '')) {
24
+ var _field$validation;
25
+ if (field != null && (_field$validation = field.validation) != null && _field$validation.required && (v === null || v === undefined || v === '')) {
24
26
  return t('cairo.fieldValidation.requiredField');
25
27
  }
26
28
  return true;
@@ -39,29 +41,32 @@ export const DateTime = props => {
39
41
  const ref = useRef({});
40
42
  const dateRef = useRef({});
41
43
  const timeRef = useRef({});
42
- const [dateValue, setDateValue] = useState(date?.getDate());
43
- const [timeValue, setTimeValue] = useState(date?.getTime());
44
+ const [dateValue, setDateValue] = useState(date == null ? void 0 : date.getDate());
45
+ const [timeValue, setTimeValue] = useState(date == null ? void 0 : date.getTime());
44
46
  useEffect(() => {
45
47
  ref.current.focus = () => {
46
48
  if (dateRef.current.invalid) {
47
- return dateRef.current.focus?.();
49
+ return dateRef.current.focus == null ? void 0 : dateRef.current.focus();
48
50
  }
49
- return timeRef.current.focus?.();
51
+ return timeRef.current.focus == null ? void 0 : timeRef.current.focus();
50
52
  };
51
- inputRef?.(ref.current);
53
+ inputRef == null || inputRef(ref.current);
52
54
  }, [inputRef]);
53
55
  return /*#__PURE__*/React.createElement(FormField, {
54
56
  label: field.displayName,
55
- required: field.validation?.required,
57
+ required: (_field$validation2 = field.validation) == null ? void 0 : _field$validation2.required,
56
58
  dataHook: dataHook
57
59
  }, /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Cell, {
58
60
  span: 6
59
61
  }, /*#__PURE__*/React.createElement(DatePicker, {
60
62
  ref: internalRef => {
61
- dateRef.current.focus = () =>
62
- // TODO: PR to WSR needed to expose as public API
63
- // @ts-expect-error
64
- internalRef?.state?.inputRef?.focus?.();
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
+ };
65
70
  },
66
71
  width: "100%",
67
72
  value: date
@@ -85,7 +90,8 @@ export const DateTime = props => {
85
90
  setDateStatusMessage('');
86
91
  dateRef.current.invalid = false;
87
92
  } else if (validationType === 'formatError' && newValue === '') {
88
- if (field.validation?.required) {
93
+ var _field$validation3;
94
+ if ((_field$validation3 = field.validation) != null && _field$validation3.required) {
89
95
  setDateStatusMessage(t('cairo.fieldValidation.requiredField'));
90
96
  dateRef.current.invalid = true;
91
97
  } else {
@@ -111,7 +117,7 @@ export const DateTime = props => {
111
117
  span: 6
112
118
  }, /*#__PURE__*/React.createElement(TimeInput, {
113
119
  ref: internalRef => {
114
- timeRef.current.focus = () => internalRef?.focus();
120
+ timeRef.current.focus = () => internalRef == null ? void 0 : internalRef.focus();
115
121
  },
116
122
  dataHook: `datetime-time-${field.id}`,
117
123
  value: date ?? null,
@@ -139,8 +145,9 @@ export const DateTime = props => {
139
145
  setDateStatusMessage('');
140
146
  } else {
141
147
  if (!newValue) {
148
+ var _field$validation4;
142
149
  setTimeValue('');
143
- if (field.validation?.required) {
150
+ if ((_field$validation4 = field.validation) != null && _field$validation4.required) {
144
151
  setTimeStatusMessage(t('cairo.fieldValidation.requiredField'));
145
152
  timeRef.current.invalid = true;
146
153
  } else {