@webiny/app-headless-cms 5.20.0 → 5.22.0-beta.1

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 (107) hide show
  1. package/HeadlessCMS.d.ts +12 -0
  2. package/HeadlessCMS.js +27 -0
  3. package/admin/components/ContentEntryForm/useContentEntryForm.js +101 -12
  4. package/admin/components/ContentModelEditor/Context.js +3 -1
  5. package/admin/components/ContentModelEditor/Editor.d.ts +1 -1
  6. package/admin/components/ContentModelEditor/Editor.js +1 -1
  7. package/admin/components/Draggable.d.ts +3 -2
  8. package/admin/components/Draggable.js +5 -3
  9. package/admin/components/Droppable.d.ts +3 -2
  10. package/admin/components/Droppable.js +5 -3
  11. package/admin/components/FieldEditor/EditFieldDialog/PredefinedValues.d.ts +10 -5
  12. package/admin/components/FieldEditor/EditFieldDialog/PredefinedValues.js +9 -5
  13. package/admin/components/FieldEditor/Field.js +4 -4
  14. package/admin/components/FieldEditor/FieldEditor.js +1 -1
  15. package/admin/components/FieldEditor/Styled.d.ts +2 -2
  16. package/admin/contexts/Cms/index.d.ts +1 -2
  17. package/admin/elements/ContentGroupMenuElement.js +2 -1
  18. package/admin/elements/ContentModelMenuElement.js +2 -1
  19. package/admin/elements/NothingToShowElement.js +1 -1
  20. package/admin/graphql/contentModels.d.ts +1 -1
  21. package/admin/graphql/contentModels.js +1 -1
  22. package/admin/hooks/usePermission.d.ts +2 -2
  23. package/admin/menus/CmsMenuLoader.d.ts +2 -0
  24. package/admin/menus/CmsMenuLoader.js +39 -0
  25. package/admin/menus/ContentGroupsMenuItems.d.ts +1 -0
  26. package/admin/menus/ContentGroupsMenuItems.js +88 -0
  27. package/admin/{plugins/menus → menus}/GlobalSearchPlugins.d.ts +0 -0
  28. package/admin/{plugins/menus → menus}/GlobalSearchPlugins.js +2 -2
  29. package/admin/menus/NothingToShowElement.d.ts +2 -0
  30. package/admin/menus/NothingToShowElement.js +42 -0
  31. package/admin/plugins/editor/defaultBar/BackButton.js +1 -1
  32. package/admin/plugins/editor/defaultBar/CreateContentButton.js +1 -1
  33. package/admin/plugins/editor/defaultBar/Divider.d.ts +1 -1
  34. package/admin/plugins/editor/defaultBar/FormSettings/FormSettingsButton.js +1 -1
  35. package/admin/plugins/editor/defaultBar/FormSettings/FormSettingsStyled.d.ts +2 -2
  36. package/admin/plugins/editor/defaultBar/Name/NameStyled.d.ts +3 -3
  37. package/admin/plugins/editor/formSettings/index.js +1 -1
  38. package/admin/plugins/fieldRenderers/DynamicSection.js +1 -1
  39. package/admin/plugins/fieldRenderers/checkboxes.js +18 -15
  40. package/admin/plugins/fieldRenderers/dateTime/DateOnly.d.ts +9 -0
  41. package/admin/plugins/fieldRenderers/dateTime/DateOnly.js +39 -0
  42. package/admin/plugins/fieldRenderers/dateTime/DateTimeWithTimezone.d.ts +2 -3
  43. package/admin/plugins/fieldRenderers/dateTime/DateTimeWithTimezone.js +61 -59
  44. package/admin/plugins/fieldRenderers/dateTime/DateTimeWithoutTimezone.d.ts +4 -4
  45. package/admin/plugins/fieldRenderers/dateTime/DateTimeWithoutTimezone.js +52 -51
  46. package/admin/plugins/fieldRenderers/dateTime/Input.d.ts +6 -7
  47. package/admin/plugins/fieldRenderers/dateTime/Input.js +2 -5
  48. package/admin/plugins/fieldRenderers/dateTime/Select.d.ts +10 -3
  49. package/admin/plugins/fieldRenderers/dateTime/Select.js +2 -5
  50. package/admin/plugins/fieldRenderers/dateTime/Time.d.ts +3 -3
  51. package/admin/plugins/fieldRenderers/dateTime/Time.js +33 -9
  52. package/admin/plugins/fieldRenderers/dateTime/dateTimeField.js +8 -13
  53. package/admin/plugins/fieldRenderers/dateTime/dateTimeFields.js +9 -13
  54. package/admin/plugins/fieldRenderers/dateTime/utils.d.ts +7 -6
  55. package/admin/plugins/fieldRenderers/dateTime/utils.js +51 -9
  56. package/admin/plugins/fieldRenderers/file/File.js +2 -2
  57. package/admin/plugins/fieldRenderers/file/utils.d.ts +1 -1
  58. package/admin/plugins/fieldRenderers/file/utils.js +2 -2
  59. package/admin/plugins/fieldRenderers/longText/longTexts.js +1 -1
  60. package/admin/plugins/fieldRenderers/number/numberInputs.js +1 -1
  61. package/admin/plugins/fieldRenderers/object/multipleObjects.js +1 -1
  62. package/admin/plugins/fieldRenderers/radioButtons.js +4 -3
  63. package/admin/plugins/fieldRenderers/richText/richTextInputs.js +1 -1
  64. package/admin/plugins/fieldRenderers/text/textInputs.js +1 -1
  65. package/admin/plugins/fieldValidators/date/createDateInputField.js +8 -13
  66. package/admin/plugins/fieldValidators/unique.d.ts +3 -0
  67. package/admin/plugins/fieldValidators/unique.js +12 -0
  68. package/admin/plugins/fields/PredefinedValuesDynamicFieldset.d.ts +7 -4
  69. package/admin/plugins/fields/PredefinedValuesDynamicFieldset.js +88 -53
  70. package/admin/plugins/fields/boolean.js +19 -2
  71. package/admin/plugins/fields/dateTime.js +17 -6
  72. package/admin/plugins/fields/file.js +1 -1
  73. package/admin/plugins/fields/longText.js +1 -1
  74. package/admin/plugins/fields/number.js +1 -1
  75. package/admin/plugins/fields/object.js +1 -1
  76. package/admin/plugins/fields/ref.js +1 -1
  77. package/admin/plugins/fields/richText.js +1 -1
  78. package/admin/plugins/fields/text.js +2 -2
  79. package/admin/plugins/index.d.ts +1 -7
  80. package/admin/plugins/index.js +1 -3
  81. package/admin/plugins/install.js +1 -1
  82. package/admin/plugins/permissionRenderer/components/StyledComponents.d.ts +1 -1
  83. package/admin/plugins/permissionRenderer/index.js +1 -1
  84. package/admin/plugins/transformers/dateTransformer.js +5 -7
  85. package/admin/plugins/validators/unique.d.ts +7 -0
  86. package/admin/plugins/validators/unique.js +38 -0
  87. package/admin/views/contentEntries/ContentEntriesList.js +2 -2
  88. package/admin/views/contentEntries/ContentEntry/RevisionListItem.js +9 -9
  89. package/admin/views/contentEntries/ContentEntry/header/contentFormOptionsMenu/ContentFormOptionsMenu.js +2 -2
  90. package/admin/views/contentEntries/ContentEntry/header/requestChanges/RequestChanges.js +1 -1
  91. package/admin/views/contentEntries/ContentEntry/header/requestReview/RequestReview.js +1 -1
  92. package/admin/views/contentEntries/ContentEntry/header/revisionSelector/RevisionSelector.js +1 -1
  93. package/admin/views/contentEntries/ContentEntry.js +1 -1
  94. package/admin/views/contentModelGroups/ContentModelGroupsDataList.js +2 -2
  95. package/admin/views/contentModelGroups/ContentModelGroupsForm.js +1 -1
  96. package/admin/views/contentModels/ContentModelEditor.js +2 -8
  97. package/admin/views/contentModels/ContentModelsDataList.js +4 -4
  98. package/index.d.ts +1 -0
  99. package/index.js +1 -0
  100. package/package.json +31 -37
  101. package/types.d.ts +4 -1
  102. package/admin/plugins/menus/CmsMenuLoader.d.ts +0 -7
  103. package/admin/plugins/menus/CmsMenuLoader.js +0 -76
  104. package/admin/plugins/menus/ContentGroupsMenuItems.d.ts +0 -6
  105. package/admin/plugins/menus/ContentGroupsMenuItems.js +0 -154
  106. package/admin/plugins/menus.d.ts +0 -4
  107. package/admin/plugins/menus.js +0 -19
@@ -1,14 +1,17 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- import React, { useState, useEffect } from "react";
4
- import Input from "./Input";
5
- import Select from "./Select";
3
+ import React, { useEffect } from "react";
4
+ import { Input } from "./Input";
5
+ import { Select } from "./Select";
6
6
  import { Grid, Cell } from "@webiny/ui/Grid";
7
- import { UTC_TIMEZONES, DEFAULT_TIME, DEFAULT_DATE, DEFAULT_TIMEZONE, RemoveFieldButton } from "./utils";
7
+ import { UTC_TIMEZONES, RemoveFieldButton, getDefaultFieldValue, DEFAULT_TIMEZONE, getCurrentDate, getCurrentLocalTime, getCurrentTimeZone } from "./utils";
8
8
 
9
9
  var parseDateTime = function parseDateTime(value) {
10
10
  if (!value || typeof value !== "string") {
11
- return {};
11
+ return {
12
+ date: "",
13
+ rest: ""
14
+ };
12
15
  }
13
16
 
14
17
  var _value$split = value.split("T"),
@@ -21,14 +24,17 @@ var parseDateTime = function parseDateTime(value) {
21
24
  }
22
25
 
23
26
  return {
24
- formattedDate: formattedDate,
27
+ date: formattedDate,
25
28
  rest: rest
26
29
  };
27
30
  };
28
31
 
29
32
  var parseTime = function parseTime(value) {
30
33
  if (!value) {
31
- return {};
34
+ return {
35
+ time: "",
36
+ timezone: ""
37
+ };
32
38
  }
33
39
 
34
40
  var sign = value.includes("+") ? "+" : "-";
@@ -39,50 +45,39 @@ var parseTime = function parseTime(value) {
39
45
  zone = _value$split4[1];
40
46
 
41
47
  return {
42
- formattedTime: fullTime,
43
- formattedTimezone: sign + zone
48
+ time: fullTime,
49
+ timezone: sign + zone
44
50
  };
45
51
  };
46
52
 
47
- var DateTimeWithTimezone = function DateTimeWithTimezone(_ref) {
53
+ export var DateTimeWithTimezone = function DateTimeWithTimezone(_ref) {
48
54
  var bind = _ref.bind,
49
55
  trailingIcon = _ref.trailingIcon,
50
56
  field = _ref.field;
57
+ var defaultTimeZone = getCurrentTimeZone() || DEFAULT_TIMEZONE; // "2020-05-18T09:00+10:00"
51
58
 
52
- // "2020-05-18T09:00+10:00"
53
- var _parseDateTime = parseDateTime(bind.value),
54
- formattedDate = _parseDateTime.formattedDate,
59
+ var initialValue = getDefaultFieldValue(field, bind, function () {
60
+ var date = new Date();
61
+ return "".concat(getCurrentDate(date), "T").concat(getCurrentLocalTime(date)).concat(defaultTimeZone);
62
+ });
63
+
64
+ var _parseDateTime = parseDateTime(initialValue),
65
+ date = _parseDateTime.date,
55
66
  rest = _parseDateTime.rest;
56
67
 
57
68
  var _parseTime = parseTime(rest),
58
- formattedTime = _parseTime.formattedTime,
59
- formattedTimezone = _parseTime.formattedTimezone;
60
-
61
- var _useState = useState({
62
- date: formattedDate || DEFAULT_DATE,
63
- time: formattedTime || DEFAULT_TIME,
64
- timezone: formattedTimezone || DEFAULT_TIMEZONE
65
- }),
66
- _useState2 = _slicedToArray(_useState, 2),
67
- state = _useState2[0],
68
- setState = _useState2[1];
69
-
70
- var date = state.date,
71
- time = state.time,
72
- timezone = state.timezone;
69
+ time = _parseTime.time,
70
+ _parseTime$timezone = _parseTime.timezone,
71
+ timezone = _parseTime$timezone === void 0 ? defaultTimeZone : _parseTime$timezone;
72
+
73
+ var bindValue = bind.value || "";
73
74
  useEffect(function () {
74
- if (!formattedDate || !formattedTime || !formattedTimezone) {
75
+ if (!date || !time || !timezone || bindValue === initialValue) {
75
76
  return;
76
77
  }
77
78
 
78
- setState(function () {
79
- return {
80
- date: formattedDate,
81
- time: formattedTime,
82
- timezone: formattedTimezone
83
- };
84
- });
85
- }, [formattedDate, formattedTime, formattedTimezone]);
79
+ bind.onChange(initialValue);
80
+ }, [bindValue]);
86
81
  var cellSize = trailingIcon ? 3 : 4;
87
82
  return /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Cell, {
88
83
  span: 4
@@ -90,12 +85,15 @@ var DateTimeWithTimezone = function DateTimeWithTimezone(_ref) {
90
85
  bind: _objectSpread(_objectSpread({}, bind), {}, {
91
86
  value: date,
92
87
  onChange: function onChange(value) {
93
- setState(function (prev) {
94
- return _objectSpread(_objectSpread({}, prev), {}, {
95
- date: value
96
- });
97
- });
98
- return bind.onChange("".concat(value, "T").concat(time).concat(timezone));
88
+ if (!value) {
89
+ if (!bind.value) {
90
+ return;
91
+ }
92
+
93
+ return bind.onChange("");
94
+ }
95
+
96
+ return bind.onChange("".concat(value, "T").concat(time || getCurrentLocalTime()).concat(timezone || defaultTimeZone));
99
97
  }
100
98
  }),
101
99
  field: _objectSpread(_objectSpread({}, field), {}, {
@@ -108,12 +106,15 @@ var DateTimeWithTimezone = function DateTimeWithTimezone(_ref) {
108
106
  bind: _objectSpread(_objectSpread({}, bind), {}, {
109
107
  value: time,
110
108
  onChange: function onChange(value) {
111
- setState(function (prev) {
112
- return _objectSpread(_objectSpread({}, prev), {}, {
113
- time: value
114
- });
115
- });
116
- return bind.onChange("".concat(date, "T").concat(value).concat(timezone));
109
+ if (!value) {
110
+ if (!bind.value) {
111
+ return;
112
+ }
113
+
114
+ return bind.onChange("");
115
+ }
116
+
117
+ return bind.onChange("".concat(date || getCurrentDate(), "T").concat(value).concat(timezone || defaultTimeZone));
117
118
  }
118
119
  }),
119
120
  field: _objectSpread(_objectSpread({}, field), {}, {
@@ -125,14 +126,17 @@ var DateTimeWithTimezone = function DateTimeWithTimezone(_ref) {
125
126
  span: cellSize
126
127
  }, /*#__PURE__*/React.createElement(Select, {
127
128
  label: "Timezone",
128
- value: timezone,
129
+ value: timezone || defaultTimeZone,
129
130
  onChange: function onChange(value) {
130
- setState(function (prev) {
131
- return _objectSpread(_objectSpread({}, prev), {}, {
132
- timezone: value
133
- });
134
- });
135
- return bind.onChange("".concat(date, "T").concat(time).concat(value));
131
+ if (!value) {
132
+ if (!bind.value) {
133
+ return;
134
+ }
135
+
136
+ return bind.onChange("");
137
+ }
138
+
139
+ return bind.onChange("".concat(date || getCurrentDate(), "T").concat(time || getCurrentLocalTime()).concat(value));
136
140
  },
137
141
  options: UTC_TIMEZONES.map(function (t) {
138
142
  return {
@@ -143,6 +147,4 @@ var DateTimeWithTimezone = function DateTimeWithTimezone(_ref) {
143
147
  })), /*#__PURE__*/React.createElement(RemoveFieldButton, {
144
148
  trailingIcon: trailingIcon
145
149
  }));
146
- };
147
-
148
- export default DateTimeWithTimezone;
150
+ };
@@ -1,8 +1,8 @@
1
1
  import React from "react";
2
- interface DateTimeWithoutTimezoneProps {
2
+ import { CmsEditorField } from "../../../../types";
3
+ export interface Props {
3
4
  bind: any;
4
5
  trailingIcon?: any;
5
- field: any;
6
+ field: CmsEditorField;
6
7
  }
7
- declare const DateTimeWithoutTimezone: React.FunctionComponent<DateTimeWithoutTimezoneProps>;
8
- export default DateTimeWithoutTimezone;
8
+ export declare const DateTimeWithoutTimezone: React.FunctionComponent<Props>;
@@ -1,74 +1,71 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- import React, { useEffect, useState } from "react";
3
+ import React, { useEffect } from "react";
4
4
  import { Grid, Cell } from "@webiny/ui/Grid";
5
- import { DEFAULT_DATE, DEFAULT_TIME, RemoveFieldButton } from "./utils";
6
- import Input from "./Input";
5
+ import { getCurrentDate, getCurrentLocalTime, getDefaultFieldValue, RemoveFieldButton } from "./utils";
6
+ import { Input } from "./Input";
7
7
 
8
8
  var parseDateTime = function parseDateTime(value) {
9
9
  if (!value) {
10
- return {};
10
+ return {
11
+ date: "",
12
+ time: ""
13
+ };
11
14
  }
12
15
 
13
16
  if (value.includes("T")) {
14
17
  var _value$split$0$split = value.split(".")[0].split("T"),
15
18
  _value$split$0$split2 = _slicedToArray(_value$split$0$split, 2),
16
- _formattedDate = _value$split$0$split2[0],
17
- _formattedTime = _value$split$0$split2[1];
19
+ _date = _value$split$0$split2[0],
20
+ _time = _value$split$0$split2[1];
18
21
 
19
22
  return {
20
- formattedDate: _formattedDate,
21
- formattedTime: _formattedTime
23
+ date: _date,
24
+ time: _time
22
25
  };
23
26
  }
24
27
 
25
28
  var _value$split = value.split(" "),
26
29
  _value$split2 = _slicedToArray(_value$split, 2),
27
- formattedDate = _value$split2[0],
28
- formattedTime = _value$split2[1];
30
+ date = _value$split2[0],
31
+ time = _value$split2[1];
29
32
 
30
- if (!formattedDate || !formattedTime) {
31
- throw new Error("Could not extract date and time from \"".concat(value, "\"."));
33
+ if (!date || !time) {
34
+ console.error("Could not extract date and time from \"".concat(value, "\"."));
35
+ return {
36
+ date: "",
37
+ time: ""
38
+ };
32
39
  }
33
40
 
34
41
  return {
35
- formattedDate: formattedDate,
36
- formattedTime: formattedTime
42
+ date: date,
43
+ time: time
37
44
  };
38
45
  };
39
46
 
40
- var DateTimeWithoutTimezone = function DateTimeWithoutTimezone(_ref) {
47
+ export var DateTimeWithoutTimezone = function DateTimeWithoutTimezone(_ref) {
41
48
  var field = _ref.field,
42
49
  bind = _ref.bind,
43
50
  trailingIcon = _ref.trailingIcon;
44
-
45
51
  // "2020-05-18 09:00:00"
46
- var _parseDateTime = parseDateTime(bind.value),
47
- formattedDate = _parseDateTime.formattedDate,
48
- formattedTime = _parseDateTime.formattedTime;
52
+ var initialValue = getDefaultFieldValue(field, bind, function () {
53
+ var date = new Date();
54
+ return "".concat(getCurrentDate(date), " ").concat(getCurrentLocalTime(date));
55
+ });
49
56
 
50
- var _useState = useState({
51
- date: formattedDate || DEFAULT_DATE,
52
- time: formattedTime || DEFAULT_TIME
53
- }),
54
- _useState2 = _slicedToArray(_useState, 2),
55
- state = _useState2[0],
56
- setState = _useState2[1];
57
+ var _parseDateTime = parseDateTime(initialValue),
58
+ date = _parseDateTime.date,
59
+ time = _parseDateTime.time;
57
60
 
58
- var date = state.date,
59
- time = state.time;
61
+ var bindValue = bind.value || "";
60
62
  useEffect(function () {
61
- if (!formattedDate || !formattedTime) {
63
+ if (!date || !time || bindValue === initialValue) {
62
64
  return;
63
65
  }
64
66
 
65
- setState(function () {
66
- return {
67
- date: formattedDate,
68
- time: formattedTime
69
- };
70
- });
71
- }, [formattedDate, formattedTime]);
67
+ bind.onChange(initialValue);
68
+ }, [bindValue]);
72
69
  var cellSize = trailingIcon ? 5 : 6;
73
70
  return /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Cell, {
74
71
  span: 6
@@ -76,12 +73,15 @@ var DateTimeWithoutTimezone = function DateTimeWithoutTimezone(_ref) {
76
73
  bind: _objectSpread(_objectSpread({}, bind), {}, {
77
74
  value: date,
78
75
  onChange: function onChange(value) {
79
- setState(function (prev) {
80
- return _objectSpread(_objectSpread({}, prev), {}, {
81
- date: value
82
- });
83
- });
84
- return bind.onChange("".concat(value, " ").concat(time));
76
+ if (!value) {
77
+ if (!bind.value) {
78
+ return;
79
+ }
80
+
81
+ return bind.onChange("");
82
+ }
83
+
84
+ return bind.onChange("".concat(value, " ").concat(time || getCurrentLocalTime()));
85
85
  }
86
86
  }),
87
87
  field: _objectSpread(_objectSpread({}, field), {}, {
@@ -94,12 +94,15 @@ var DateTimeWithoutTimezone = function DateTimeWithoutTimezone(_ref) {
94
94
  bind: _objectSpread(_objectSpread({}, bind), {}, {
95
95
  value: time,
96
96
  onChange: function onChange(value) {
97
- setState(function (prev) {
98
- return _objectSpread(_objectSpread({}, prev), {}, {
99
- time: value
100
- });
101
- });
102
- return bind.onChange("".concat(date, " ").concat(value));
97
+ if (!value) {
98
+ if (!bind.value) {
99
+ return;
100
+ }
101
+
102
+ return bind.onChange("");
103
+ }
104
+
105
+ return bind.onChange("".concat(date || getCurrentDate(), " ").concat(value));
103
106
  }
104
107
  }),
105
108
  field: _objectSpread(_objectSpread({}, field), {}, {
@@ -110,6 +113,4 @@ var DateTimeWithoutTimezone = function DateTimeWithoutTimezone(_ref) {
110
113
  })), /*#__PURE__*/React.createElement(RemoveFieldButton, {
111
114
  trailingIcon: trailingIcon
112
115
  }));
113
- };
114
-
115
- export default DateTimeWithoutTimezone;
116
+ };
@@ -1,16 +1,15 @@
1
1
  import * as React from "react";
2
2
  import { CmsEditorField } from "../../../../types";
3
3
  import { BindComponentRenderProp } from "@webiny/form";
4
- declare type TrailingIconType = {
4
+ export interface TrailingIcon {
5
5
  icon: React.ReactNode;
6
6
  onClick: any;
7
- };
8
- declare type Props = {
7
+ }
8
+ export interface Props {
9
9
  step?: number;
10
10
  type?: string;
11
11
  bind: BindComponentRenderProp;
12
12
  field: CmsEditorField;
13
- trailingIcon?: TrailingIconType;
14
- };
15
- declare const Input: ({ bind, ...props }: Props) => JSX.Element;
16
- export default Input;
13
+ trailingIcon?: TrailingIcon;
14
+ }
15
+ export declare const Input: React.FC<Props>;
@@ -2,8 +2,7 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProper
2
2
  var _excluded = ["bind"];
3
3
  import * as React from "react";
4
4
  import { Input as UiInput } from "@webiny/ui/Input";
5
-
6
- var Input = function Input(_ref) {
5
+ export var Input = function Input(_ref) {
7
6
  var bind = _ref.bind,
8
7
  props = _objectWithoutProperties(_ref, _excluded);
9
8
 
@@ -21,6 +20,4 @@ var Input = function Input(_ref) {
21
20
  type: props.type,
22
21
  trailingIcon: props.trailingIcon
23
22
  }));
24
- };
25
-
26
- export default Input;
23
+ };
@@ -1,3 +1,10 @@
1
- /// <reference types="react" />
2
- declare const Select: (props: any) => JSX.Element;
3
- export default Select;
1
+ import * as React from "react";
2
+ import { SelectProps } from "@webiny/ui/Select";
3
+ export interface Option {
4
+ value: string;
5
+ label: string;
6
+ }
7
+ export interface Props extends SelectProps {
8
+ options: Option[];
9
+ }
10
+ export declare const Select: React.FC<Props>;
@@ -1,13 +1,10 @@
1
1
  import * as React from "react";
2
2
  import { Select as UiSelect } from "@webiny/ui/Select";
3
-
4
- var Select = function Select(props) {
3
+ export var Select = function Select(props) {
5
4
  return /*#__PURE__*/React.createElement(UiSelect, props, props.options.map(function (t) {
6
5
  return /*#__PURE__*/React.createElement("option", {
7
6
  key: t.value,
8
7
  value: t.value
9
8
  }, t.label);
10
9
  }));
11
- };
12
-
13
- export default Select;
10
+ };
@@ -1,3 +1,3 @@
1
- /// <reference types="react" />
2
- declare const Time: (props: any) => JSX.Element;
3
- export default Time;
1
+ import React from "react";
2
+ import { Props } from "./Input";
3
+ export declare const Time: React.FC<Props>;
@@ -1,13 +1,37 @@
1
- import React from "react";
2
- import Input from "./Input";
1
+ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
+ import React, { useEffect } from "react";
3
+ import { Input } from "./Input";
4
+ import { getCurrentLocalTime, getDefaultFieldValue } from "./utils";
5
+ export var Time = function Time(props) {
6
+ var field = props.field,
7
+ bind = props.bind;
8
+ var time = getDefaultFieldValue(field, bind, function () {
9
+ return getCurrentLocalTime(new Date());
10
+ });
11
+ var bindValue = bind.value || "";
12
+ useEffect(function () {
13
+ if (!time || bindValue === time) {
14
+ return;
15
+ }
3
16
 
4
- var Time = function Time(props) {
5
- // "09:00:00"
17
+ bind.onChange(time);
18
+ }, [bindValue]);
6
19
  return /*#__PURE__*/React.createElement(Input, Object.assign({}, props, {
20
+ bind: _objectSpread(_objectSpread({}, bind), {}, {
21
+ value: time,
22
+ onChange: function onChange(value) {
23
+ if (!value) {
24
+ if (bind.value) {
25
+ return;
26
+ }
27
+
28
+ return bind.onChange("");
29
+ }
30
+
31
+ return bind.onChange(value);
32
+ }
33
+ }),
7
34
  type: "time",
8
- step: 5,
9
- trailingIcon: props.trailingIcon
35
+ step: 5
10
36
  }));
11
- };
12
-
13
- export default Time;
37
+ };
@@ -5,10 +5,10 @@ var _templateObject, _templateObject2;
5
5
  import React from "react";
6
6
  import get from "lodash/get";
7
7
  import { i18n } from "@webiny/app/i18n";
8
- import DateTimeWithoutTimezone from "./DateTimeWithoutTimezone";
9
- import DateTimeWithTimezone from "./DateTimeWithTimezone";
10
- import Time from "./Time";
11
- import Input from "./Input";
8
+ import { DateOnly } from "./DateOnly";
9
+ import { DateTimeWithoutTimezone } from "./DateTimeWithoutTimezone";
10
+ import { DateTimeWithTimezone } from "./DateTimeWithTimezone";
11
+ import { Time } from "./Time";
12
12
  var t = i18n.ns("app-headless-cms/admin/fields/date-time");
13
13
  var plugin = {
14
14
  type: "cms-editor-field-renderer",
@@ -31,26 +31,21 @@ var plugin = {
31
31
  field: field,
32
32
  bind: bind
33
33
  });
34
- }
35
-
36
- if (field.settings.type === "dateTimeWithTimezone") {
34
+ } else if (field.settings.type === "dateTimeWithTimezone") {
37
35
  return /*#__PURE__*/React.createElement(DateTimeWithTimezone, {
38
36
  field: field,
39
37
  bind: bind
40
38
  });
41
- }
42
-
43
- if (field.settings.type === "time") {
39
+ } else if (field.settings.type === "time") {
44
40
  return /*#__PURE__*/React.createElement(Time, {
45
41
  field: field,
46
42
  bind: bind
47
43
  });
48
44
  }
49
45
 
50
- return /*#__PURE__*/React.createElement(Input, {
46
+ return /*#__PURE__*/React.createElement(DateOnly, {
51
47
  bind: bind,
52
- field: field,
53
- type: field.settings.type
48
+ field: field
54
49
  });
55
50
  });
56
51
  }
@@ -1,17 +1,17 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
2
  import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
3
3
 
4
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
4
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4;
5
5
 
6
6
  import React from "react";
7
7
  import get from "lodash/get";
8
- import { i18n } from "@webiny/app/i18n";
9
- import { ReactComponent as DeleteIcon } from "@svgr/webpack!../../../icons/close.svg";
10
8
  import DynamicSection from "../DynamicSection";
11
- import DateTimeWithoutTimezone from "./DateTimeWithoutTimezone";
12
- import DateTimeWithTimezone from "./DateTimeWithTimezone";
13
- import Time from "./Time";
14
- import Input from "./Input";
9
+ import { i18n } from "@webiny/app/i18n";
10
+ import { ReactComponent as DeleteIcon } from "../../../icons/close.svg";
11
+ import { DateTimeWithoutTimezone } from "./DateTimeWithoutTimezone";
12
+ import { DateTimeWithTimezone } from "./DateTimeWithTimezone";
13
+ import { DateOnly } from "./DateOnly";
14
+ import { Time } from "./Time";
15
15
  var t = i18n.ns("app-headless-cms/admin/fields/date-time");
16
16
  var plugin = {
17
17
  type: "cms-editor-field-renderer",
@@ -60,21 +60,17 @@ var plugin = {
60
60
  })
61
61
  }),
62
62
  bind: bind.index,
63
- label: t(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["Value {number}"])))({
64
- number: index + 1
65
- }),
66
63
  trailingIcon: trailingIcon
67
64
  });
68
65
  }
69
66
 
70
- return /*#__PURE__*/React.createElement(Input, {
67
+ return /*#__PURE__*/React.createElement(DateOnly, {
71
68
  bind: bind.index,
72
69
  field: _objectSpread(_objectSpread({}, props.field), {}, {
73
- label: props.field.label + t(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral([" Value {number}"])))({
70
+ label: props.field.label + t(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral([" Value {number}"])))({
74
71
  number: index + 1
75
72
  })
76
73
  }),
77
- type: field.settings.type,
78
74
  trailingIcon: trailingIcon
79
75
  });
80
76
  });
@@ -1,15 +1,16 @@
1
1
  /// <reference types="react" />
2
+ import { CmsEditorField } from "../../../../types";
2
3
  export declare const UTC_TIMEZONES: {
3
4
  value: string;
4
5
  label: string;
5
6
  }[];
6
- /**
7
- * @returns Current date string in format `YYYY-MM-DD`
8
- */
9
- export declare const getCurrentDateString: () => string;
10
- export declare const DEFAULT_TIME = "00:00:00";
11
- export declare const DEFAULT_DATE: string;
12
7
  export declare const DEFAULT_TIMEZONE = "+01:00";
8
+ export declare const getDefaultFieldValue: (field: CmsEditorField, bind: {
9
+ value: string | null | undefined;
10
+ }, getCurrent: () => string) => string;
11
+ export declare const getCurrentTimeZone: (date?: Date) => string;
12
+ export declare const getCurrentLocalTime: (date?: Date) => string;
13
+ export declare const getCurrentDate: (date?: Date) => string;
13
14
  export declare const RemoveFieldButton: ({ trailingIcon }: {
14
15
  trailingIcon: any;
15
16
  }) => JSX.Element;