@knovator/pagecreator-admin 1.6.9 → 1.7.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 (3) hide show
  1. package/index.cjs +36 -9
  2. package/index.js +36 -9
  3. package/package.json +1 -1
package/index.cjs CHANGED
@@ -3370,13 +3370,25 @@ const Input$1 = ({
3370
3370
  onChange,
3371
3371
  wrapperClassName
3372
3372
  }) => {
3373
+ const isTextarea = type === 'textarea';
3373
3374
  return /*#__PURE__*/React__default["default"].createElement("div", {
3374
3375
  className: classNames__default["default"]('khb_input-wrapper', wrapperClassName)
3375
3376
  }, label && (/*#__PURE__*/React__default["default"].createElement("label", {
3376
3377
  className: "khb_input-label"
3377
3378
  }, label, required ? (/*#__PURE__*/React__default["default"].createElement("span", {
3378
3379
  className: "khb_input-label-required"
3379
- }, "*")) : null)), /*#__PURE__*/React__default["default"].createElement("input", Object.assign({
3380
+ }, "*")) : null)), isTextarea ? (/*#__PURE__*/React__default["default"].createElement("textarea", Object.assign({
3381
+ className: classNames__default["default"]('khb_input', `khb_input-${_size}`, className),
3382
+ placeholder: placeholder,
3383
+ disabled: disabled,
3384
+ id: id,
3385
+ value: value,
3386
+ onChange: onChange,
3387
+ rows: 10
3388
+ }, rest, {
3389
+ onInput: onInput,
3390
+ onBlur: onBlur
3391
+ }))) : (/*#__PURE__*/React__default["default"].createElement("input", Object.assign({
3380
3392
  className: classNames__default["default"]('khb_input', `khb_input-${_size}`, className),
3381
3393
  type: type,
3382
3394
  placeholder: placeholder,
@@ -3387,7 +3399,7 @@ const Input$1 = ({
3387
3399
  }, rest, {
3388
3400
  onInput: onInput,
3389
3401
  onBlur: onBlur
3390
- })), error && /*#__PURE__*/React__default["default"].createElement("p", {
3402
+ }))), error && /*#__PURE__*/React__default["default"].createElement("p", {
3391
3403
  className: "khb_input-error "
3392
3404
  }, error), info && /*#__PURE__*/React__default["default"].createElement("p", {
3393
3405
  className: "khb_input-info"
@@ -7197,10 +7209,11 @@ const WidgetForm = ({
7197
7209
  const [collectionItemsUpdated, setCollectionItemsUpdated] = React.useState(false);
7198
7210
  const [tabCollectionItemsUpdated, setTabCollectionItemsUpdated] = React.useState([]);
7199
7211
  const [blogCategory, setBlogCategory] = React.useState(null);
7200
- const [blogLimit, setBlogLimit] = React.useState(10);
7212
+ const [blogLimit, setBlogLimit] = React.useState(undefined);
7201
7213
  const [blogCategories, setBlogCategories] = React.useState([]);
7202
7214
  const [blogCategoriesLoading, setBlogCategoriesLoading] = React.useState(false);
7203
7215
  const pagesLoadedRef = React.useRef(false);
7216
+ const blogCategoryInitialized = React.useRef(false);
7204
7217
  React.useEffect(() => {
7205
7218
  if (data && formState === 'UPDATE') {
7206
7219
  const widgetType = widgetTypes.find(type => type.value === (data === null || data === void 0 ? void 0 : data.widgetType));
@@ -7265,24 +7278,25 @@ const WidgetForm = ({
7265
7278
  }, [currentItemsType, baseUrl, token, widgetRoutesPrefix, blogCategories.length]);
7266
7279
  // Set blog category and limit when editing a widget
7267
7280
  React.useEffect(() => {
7268
- if (formState === 'UPDATE' && data && currentItemsType === 'blog' && blogCategories.length > 0) {
7281
+ if (formState === 'UPDATE' && data && currentItemsType === 'blog' && blogCategories.length > 0 && !blogCategoryInitialized.current) {
7269
7282
  // Set blog category if it exists in the data
7270
- if (data.blogCategory && !blogCategory) {
7283
+ if (data.blogCategory) {
7271
7284
  const savedCategory = blogCategories.find(cat => cat.value === data.blogCategory);
7272
7285
  if (savedCategory) {
7273
7286
  setBlogCategory(savedCategory);
7287
+ blogCategoryInitialized.current = true;
7274
7288
  }
7275
7289
  }
7276
7290
  // Set blog limit if it exists in the data
7277
- if (data.blogLimit && blogLimit === 10) {
7291
+ if (data.blogLimit) {
7278
7292
  setBlogLimit(data.blogLimit);
7279
7293
  }
7280
7294
  }
7281
- }, [formState, data, currentItemsType, blogCategories, blogCategory, blogLimit]);
7295
+ }, [formState, data, currentItemsType, blogCategories]);
7282
7296
  // Clear collectionItems when using blog category/limit (server will handle fetching latest blogs)
7283
7297
  React.useEffect(() => {
7284
7298
  if (currentItemsType === 'blog') {
7285
- if (blogCategory || blogLimit > 0) {
7299
+ if (blogCategory || blogLimit && blogLimit > 0) {
7286
7300
  // Clear selected collection items since server will fetch latest blogs based on category/limit
7287
7301
  setSelectedCollectionItems([]);
7288
7302
  setCollectionItemsUpdated(true);
@@ -7293,10 +7307,15 @@ const WidgetForm = ({
7293
7307
  React.useEffect(() => {
7294
7308
  if (currentItemsType !== 'blog') {
7295
7309
  setBlogCategory(null);
7296
- setBlogLimit(10);
7310
+ setBlogLimit(undefined);
7297
7311
  setBlogCategories([]);
7312
+ blogCategoryInitialized.current = false;
7298
7313
  }
7299
7314
  }, [currentItemsType]);
7315
+ // Reset initialization flag when opening a different widget or changing form state
7316
+ React.useEffect(() => {
7317
+ blogCategoryInitialized.current = false;
7318
+ }, [data === null || data === void 0 ? void 0 : data._id, formState]);
7300
7319
  // Watch blogLimit form value and update state
7301
7320
  const watchedBlogLimit = watch('blogLimit');
7302
7321
  React.useEffect(() => {
@@ -7506,6 +7525,13 @@ const WidgetForm = ({
7506
7525
  }
7507
7526
  return item;
7508
7527
  });
7528
+ // Clean up fields based on widget type
7529
+ if (formData['widgetType'] !== constants.htmlWidgetTypeValue) {
7530
+ delete formData['htmlContent'];
7531
+ }
7532
+ if (formData['widgetType'] !== constants.textWidgetTypeValue) {
7533
+ delete formData['textContent'];
7534
+ }
7509
7535
  const submitPayload = Object.assign(Object.assign(Object.assign(Object.assign({}, formData), {
7510
7536
  items
7511
7537
  }), blogCategory && {
@@ -7632,6 +7658,7 @@ const WidgetForm = ({
7632
7658
  required: widgetTranslations.htmlContentRequired
7633
7659
  },
7634
7660
  show: (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.htmlWidgetTypeValue,
7661
+ wrapperClassName: 'khb_html-content-field',
7635
7662
  Input: customInputs && customInputs['htmlContent'] ? customInputs['htmlContent'] : undefined
7636
7663
  }, {
7637
7664
  label: widgetTranslations.itemsType,
package/index.js CHANGED
@@ -3358,13 +3358,25 @@ const Input$1 = ({
3358
3358
  onChange,
3359
3359
  wrapperClassName
3360
3360
  }) => {
3361
+ const isTextarea = type === 'textarea';
3361
3362
  return /*#__PURE__*/React.createElement("div", {
3362
3363
  className: classNames('khb_input-wrapper', wrapperClassName)
3363
3364
  }, label && (/*#__PURE__*/React.createElement("label", {
3364
3365
  className: "khb_input-label"
3365
3366
  }, label, required ? (/*#__PURE__*/React.createElement("span", {
3366
3367
  className: "khb_input-label-required"
3367
- }, "*")) : null)), /*#__PURE__*/React.createElement("input", Object.assign({
3368
+ }, "*")) : null)), isTextarea ? (/*#__PURE__*/React.createElement("textarea", Object.assign({
3369
+ className: classNames('khb_input', `khb_input-${_size}`, className),
3370
+ placeholder: placeholder,
3371
+ disabled: disabled,
3372
+ id: id,
3373
+ value: value,
3374
+ onChange: onChange,
3375
+ rows: 10
3376
+ }, rest, {
3377
+ onInput: onInput,
3378
+ onBlur: onBlur
3379
+ }))) : (/*#__PURE__*/React.createElement("input", Object.assign({
3368
3380
  className: classNames('khb_input', `khb_input-${_size}`, className),
3369
3381
  type: type,
3370
3382
  placeholder: placeholder,
@@ -3375,7 +3387,7 @@ const Input$1 = ({
3375
3387
  }, rest, {
3376
3388
  onInput: onInput,
3377
3389
  onBlur: onBlur
3378
- })), error && /*#__PURE__*/React.createElement("p", {
3390
+ }))), error && /*#__PURE__*/React.createElement("p", {
3379
3391
  className: "khb_input-error "
3380
3392
  }, error), info && /*#__PURE__*/React.createElement("p", {
3381
3393
  className: "khb_input-info"
@@ -7185,10 +7197,11 @@ const WidgetForm = ({
7185
7197
  const [collectionItemsUpdated, setCollectionItemsUpdated] = useState(false);
7186
7198
  const [tabCollectionItemsUpdated, setTabCollectionItemsUpdated] = useState([]);
7187
7199
  const [blogCategory, setBlogCategory] = useState(null);
7188
- const [blogLimit, setBlogLimit] = useState(10);
7200
+ const [blogLimit, setBlogLimit] = useState(undefined);
7189
7201
  const [blogCategories, setBlogCategories] = useState([]);
7190
7202
  const [blogCategoriesLoading, setBlogCategoriesLoading] = useState(false);
7191
7203
  const pagesLoadedRef = useRef(false);
7204
+ const blogCategoryInitialized = useRef(false);
7192
7205
  useEffect(() => {
7193
7206
  if (data && formState === 'UPDATE') {
7194
7207
  const widgetType = widgetTypes.find(type => type.value === (data === null || data === void 0 ? void 0 : data.widgetType));
@@ -7253,24 +7266,25 @@ const WidgetForm = ({
7253
7266
  }, [currentItemsType, baseUrl, token, widgetRoutesPrefix, blogCategories.length]);
7254
7267
  // Set blog category and limit when editing a widget
7255
7268
  useEffect(() => {
7256
- if (formState === 'UPDATE' && data && currentItemsType === 'blog' && blogCategories.length > 0) {
7269
+ if (formState === 'UPDATE' && data && currentItemsType === 'blog' && blogCategories.length > 0 && !blogCategoryInitialized.current) {
7257
7270
  // Set blog category if it exists in the data
7258
- if (data.blogCategory && !blogCategory) {
7271
+ if (data.blogCategory) {
7259
7272
  const savedCategory = blogCategories.find(cat => cat.value === data.blogCategory);
7260
7273
  if (savedCategory) {
7261
7274
  setBlogCategory(savedCategory);
7275
+ blogCategoryInitialized.current = true;
7262
7276
  }
7263
7277
  }
7264
7278
  // Set blog limit if it exists in the data
7265
- if (data.blogLimit && blogLimit === 10) {
7279
+ if (data.blogLimit) {
7266
7280
  setBlogLimit(data.blogLimit);
7267
7281
  }
7268
7282
  }
7269
- }, [formState, data, currentItemsType, blogCategories, blogCategory, blogLimit]);
7283
+ }, [formState, data, currentItemsType, blogCategories]);
7270
7284
  // Clear collectionItems when using blog category/limit (server will handle fetching latest blogs)
7271
7285
  useEffect(() => {
7272
7286
  if (currentItemsType === 'blog') {
7273
- if (blogCategory || blogLimit > 0) {
7287
+ if (blogCategory || blogLimit && blogLimit > 0) {
7274
7288
  // Clear selected collection items since server will fetch latest blogs based on category/limit
7275
7289
  setSelectedCollectionItems([]);
7276
7290
  setCollectionItemsUpdated(true);
@@ -7281,10 +7295,15 @@ const WidgetForm = ({
7281
7295
  useEffect(() => {
7282
7296
  if (currentItemsType !== 'blog') {
7283
7297
  setBlogCategory(null);
7284
- setBlogLimit(10);
7298
+ setBlogLimit(undefined);
7285
7299
  setBlogCategories([]);
7300
+ blogCategoryInitialized.current = false;
7286
7301
  }
7287
7302
  }, [currentItemsType]);
7303
+ // Reset initialization flag when opening a different widget or changing form state
7304
+ useEffect(() => {
7305
+ blogCategoryInitialized.current = false;
7306
+ }, [data === null || data === void 0 ? void 0 : data._id, formState]);
7288
7307
  // Watch blogLimit form value and update state
7289
7308
  const watchedBlogLimit = watch('blogLimit');
7290
7309
  useEffect(() => {
@@ -7494,6 +7513,13 @@ const WidgetForm = ({
7494
7513
  }
7495
7514
  return item;
7496
7515
  });
7516
+ // Clean up fields based on widget type
7517
+ if (formData['widgetType'] !== constants.htmlWidgetTypeValue) {
7518
+ delete formData['htmlContent'];
7519
+ }
7520
+ if (formData['widgetType'] !== constants.textWidgetTypeValue) {
7521
+ delete formData['textContent'];
7522
+ }
7497
7523
  const submitPayload = Object.assign(Object.assign(Object.assign(Object.assign({}, formData), {
7498
7524
  items
7499
7525
  }), blogCategory && {
@@ -7620,6 +7646,7 @@ const WidgetForm = ({
7620
7646
  required: widgetTranslations.htmlContentRequired
7621
7647
  },
7622
7648
  show: (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.htmlWidgetTypeValue,
7649
+ wrapperClassName: 'khb_html-content-field',
7623
7650
  Input: customInputs && customInputs['htmlContent'] ? customInputs['htmlContent'] : undefined
7624
7651
  }, {
7625
7652
  label: widgetTranslations.itemsType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knovator/pagecreator-admin",
3
- "version": "1.6.9",
3
+ "version": "1.7.0",
4
4
  "dependencies": {
5
5
  "classnames": "^2.3.1",
6
6
  "react-beautiful-dnd": "^13.1.0",