@knovator/pagecreator-admin 0.5.12 → 0.6.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.
package/index.cjs CHANGED
@@ -1674,6 +1674,11 @@ var CALLBACK_CODES;
1674
1674
  CALLBACK_CODES["IMAGE_REMOVE"] = "IMAGE_REMOVE";
1675
1675
  CALLBACK_CODES["INTERNAL"] = "INTERNAL";
1676
1676
  })(CALLBACK_CODES || (CALLBACK_CODES = {}));
1677
+ const CONSTANTS = {
1678
+ EMPTY_REGEX: / /g,
1679
+ SLUG_REGEX: /^[\da-z-]*$/,
1680
+ SLUG_REPLACE_REGEX: /[^\da-z-]/gi
1681
+ };
1677
1682
  const DEFAULT_PERMISSIONS = {
1678
1683
  list: true,
1679
1684
  add: true,
@@ -1764,6 +1769,9 @@ const TRANSLATION_PAIRS_PAGE = {
1764
1769
  'page.code': 'Code',
1765
1770
  'page.codePlaceholder': 'Enter code',
1766
1771
  'page.codeRequired': 'Code is required',
1772
+ 'page.slug': 'Slug',
1773
+ 'page.slugPlaceholder': 'Enter Slug',
1774
+ 'page.slugRequired': 'Slug is required',
1767
1775
  'page.addPageTitle': 'Add Page',
1768
1776
  'page.updatePageTitle': 'Update Page',
1769
1777
  'page.searchPages': 'Search Pages...',
@@ -2494,7 +2502,11 @@ const capitalizeFirstLetter = (string = '') => {
2494
2502
  };
2495
2503
  const changeToCode = (string = '') => {
2496
2504
  var _a, _b;
2497
- return (_b = (_a = string.replace(/[^\s\w]/gi, '')) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === null || _b === void 0 ? void 0 : _b.replace(/ /g, '_');
2505
+ return (_b = (_a = string.replace(/[^\s\w]/gi, '')) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === null || _b === void 0 ? void 0 : _b.replace(CONSTANTS.EMPTY_REGEX, '_');
2506
+ };
2507
+ const changeToSlug = (string = '') => {
2508
+ var _a;
2509
+ return (_a = string === null || string === void 0 ? void 0 : string.toLowerCase()) === null || _a === void 0 ? void 0 : _a.replace(CONSTANTS.EMPTY_REGEX, '-');
2498
2510
  };
2499
2511
  const isObject$3 = data => {
2500
2512
  var _a;
@@ -4035,6 +4047,16 @@ const PageForm = ({
4035
4047
  event.target.value = changeToCode(event.target.value);
4036
4048
  return event;
4037
4049
  }
4050
+ function handleSlug(event) {
4051
+ let slugValue = changeToSlug(event.target.value);
4052
+ if (!slugValue || !CONSTANTS.SLUG_REGEX.test(slugValue)) {
4053
+ slugValue = '';
4054
+ } else {
4055
+ slugValue = slugValue.replace(CONSTANTS.SLUG_REPLACE_REGEX, '');
4056
+ }
4057
+ event.target.value = slugValue;
4058
+ return event;
4059
+ }
4038
4060
  function loadOptions(value, callback) {
4039
4061
  getWidgets(widgetsData => {
4040
4062
  if (callback) callback(widgetsData);
@@ -4071,6 +4093,17 @@ const PageForm = ({
4071
4093
  validations: {
4072
4094
  required: t('page.codeRequired')
4073
4095
  }
4096
+ }, {
4097
+ label: `${t('page.slug')}`,
4098
+ accessor: 'slug',
4099
+ required: true,
4100
+ type: 'text',
4101
+ onInput: handleSlug,
4102
+ editable: false,
4103
+ placeholder: t('page.slugPlaceholder'),
4104
+ validations: {
4105
+ required: t('page.slugRequired')
4106
+ }
4074
4107
  }, {
4075
4108
  label: t('page.widgets'),
4076
4109
  accessor: 'widgets',
package/index.js CHANGED
@@ -1662,6 +1662,11 @@ var CALLBACK_CODES;
1662
1662
  CALLBACK_CODES["IMAGE_REMOVE"] = "IMAGE_REMOVE";
1663
1663
  CALLBACK_CODES["INTERNAL"] = "INTERNAL";
1664
1664
  })(CALLBACK_CODES || (CALLBACK_CODES = {}));
1665
+ const CONSTANTS = {
1666
+ EMPTY_REGEX: / /g,
1667
+ SLUG_REGEX: /^[\da-z-]*$/,
1668
+ SLUG_REPLACE_REGEX: /[^\da-z-]/gi
1669
+ };
1665
1670
  const DEFAULT_PERMISSIONS = {
1666
1671
  list: true,
1667
1672
  add: true,
@@ -1752,6 +1757,9 @@ const TRANSLATION_PAIRS_PAGE = {
1752
1757
  'page.code': 'Code',
1753
1758
  'page.codePlaceholder': 'Enter code',
1754
1759
  'page.codeRequired': 'Code is required',
1760
+ 'page.slug': 'Slug',
1761
+ 'page.slugPlaceholder': 'Enter Slug',
1762
+ 'page.slugRequired': 'Slug is required',
1755
1763
  'page.addPageTitle': 'Add Page',
1756
1764
  'page.updatePageTitle': 'Update Page',
1757
1765
  'page.searchPages': 'Search Pages...',
@@ -2482,7 +2490,11 @@ const capitalizeFirstLetter = (string = '') => {
2482
2490
  };
2483
2491
  const changeToCode = (string = '') => {
2484
2492
  var _a, _b;
2485
- return (_b = (_a = string.replace(/[^\s\w]/gi, '')) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === null || _b === void 0 ? void 0 : _b.replace(/ /g, '_');
2493
+ return (_b = (_a = string.replace(/[^\s\w]/gi, '')) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === null || _b === void 0 ? void 0 : _b.replace(CONSTANTS.EMPTY_REGEX, '_');
2494
+ };
2495
+ const changeToSlug = (string = '') => {
2496
+ var _a;
2497
+ return (_a = string === null || string === void 0 ? void 0 : string.toLowerCase()) === null || _a === void 0 ? void 0 : _a.replace(CONSTANTS.EMPTY_REGEX, '-');
2486
2498
  };
2487
2499
  const isObject$3 = data => {
2488
2500
  var _a;
@@ -4023,6 +4035,16 @@ const PageForm = ({
4023
4035
  event.target.value = changeToCode(event.target.value);
4024
4036
  return event;
4025
4037
  }
4038
+ function handleSlug(event) {
4039
+ let slugValue = changeToSlug(event.target.value);
4040
+ if (!slugValue || !CONSTANTS.SLUG_REGEX.test(slugValue)) {
4041
+ slugValue = '';
4042
+ } else {
4043
+ slugValue = slugValue.replace(CONSTANTS.SLUG_REPLACE_REGEX, '');
4044
+ }
4045
+ event.target.value = slugValue;
4046
+ return event;
4047
+ }
4026
4048
  function loadOptions(value, callback) {
4027
4049
  getWidgets(widgetsData => {
4028
4050
  if (callback) callback(widgetsData);
@@ -4059,6 +4081,17 @@ const PageForm = ({
4059
4081
  validations: {
4060
4082
  required: t('page.codeRequired')
4061
4083
  }
4084
+ }, {
4085
+ label: `${t('page.slug')}`,
4086
+ accessor: 'slug',
4087
+ required: true,
4088
+ type: 'text',
4089
+ onInput: handleSlug,
4090
+ editable: false,
4091
+ placeholder: t('page.slugPlaceholder'),
4092
+ validations: {
4093
+ required: t('page.slugRequired')
4094
+ }
4062
4095
  }, {
4063
4096
  label: t('page.widgets'),
4064
4097
  accessor: 'widgets',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knovator/pagecreator-admin",
3
- "version": "0.5.12",
3
+ "version": "0.6.0",
4
4
  "dependencies": {
5
5
  "classnames": "^2.3.1",
6
6
  "react-beautiful-dnd": "^13.1.0",
@@ -15,6 +15,11 @@ declare enum CALLBACK_CODES {
15
15
  'IMAGE_REMOVE' = "IMAGE_REMOVE",
16
16
  'INTERNAL' = "INTERNAL"
17
17
  }
18
+ declare const CONSTANTS: {
19
+ EMPTY_REGEX: RegExp;
20
+ SLUG_REGEX: RegExp;
21
+ SLUG_REPLACE_REGEX: RegExp;
22
+ };
18
23
  declare const DEFAULT_PERMISSIONS: {
19
24
  list: boolean;
20
25
  add: boolean;
@@ -105,6 +110,9 @@ declare const TRANSLATION_PAIRS_PAGE: {
105
110
  'page.code': string;
106
111
  'page.codePlaceholder': string;
107
112
  'page.codeRequired': string;
113
+ 'page.slug': string;
114
+ 'page.slugPlaceholder': string;
115
+ 'page.slugRequired': string;
108
116
  'page.addPageTitle': string;
109
117
  'page.updatePageTitle': string;
110
118
  'page.searchPages': string;
@@ -113,4 +121,4 @@ declare const TRANSLATION_PAIRS_PAGE: {
113
121
  'page.widgets': string;
114
122
  'page.actionsLabel': string;
115
123
  };
116
- export { CALLBACK_CODES, DECIMAL_REDIX, DEFAULT_CURRENT_PAGE, DEFAULT_OFFSET_PAYLOAD, INTERNAL_ERROR_CODE, DEFAULT_PERMISSIONS, TRANSLATION_PAIRS_COMMON, DEFAULT_LIMIT, PAGE_LIMITS, TRANSLATION_PAIRS_WIDGET, TRANSLATION_PAIRS_ITEM, TRANSLATION_PAIRS_PAGE, };
124
+ export { CONSTANTS, CALLBACK_CODES, DECIMAL_REDIX, DEFAULT_CURRENT_PAGE, DEFAULT_OFFSET_PAYLOAD, INTERNAL_ERROR_CODE, DEFAULT_PERMISSIONS, TRANSLATION_PAIRS_COMMON, DEFAULT_LIMIT, PAGE_LIMITS, TRANSLATION_PAIRS_WIDGET, TRANSLATION_PAIRS_ITEM, TRANSLATION_PAIRS_PAGE, };
@@ -3,6 +3,7 @@ export declare const paginationDataGatter: (data: any) => any;
3
3
  export declare const dataGatter: (data: any) => any;
4
4
  export declare const capitalizeFirstLetter: (string?: string) => string;
5
5
  export declare const changeToCode: (string?: string) => string;
6
+ export declare const changeToSlug: (string?: string) => string;
6
7
  export declare const isObject: (data: any) => boolean;
7
8
  export declare const isString: (data: any) => boolean;
8
9
  export declare const isArray: (data: any) => boolean;