react-survey-builder 1.0.72 → 1.0.74

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.
@@ -0,0 +1,139 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
12
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
+ import { isArrayLikeObject, isEmpty } from 'lodash';
14
+ export var isListNotEmpty = function isListNotEmpty(list) {
15
+ return isArrayLikeObject(list) && list !== undefined && list !== null && list.length > 0;
16
+ };
17
+ export var isObjectNotEmpty = function isObjectNotEmpty(obj) {
18
+ if (obj !== undefined && obj !== null && !isEmpty(obj)) {
19
+ return true;
20
+ }
21
+ return false;
22
+ };
23
+ export var updateObject = function updateObject(oldObject, updatedValues) {
24
+ return _objectSpread(_objectSpread({}, oldObject), updatedValues);
25
+ };
26
+ export var addObjectToTopOfArray = function addObjectToTopOfArray(oldObjects, newObject) {
27
+ return [newObject].concat(_toConsumableArray(oldObjects));
28
+ };
29
+ export var addObjectToBottomOfArray = function addObjectToBottomOfArray(oldObjects, newObject) {
30
+ return [].concat(_toConsumableArray(oldObjects), [newObject]);
31
+ };
32
+ export var addRecordToTop = function addRecordToTop(idFieldName, newRecord, oldList) {
33
+ // check to see if record already exists in the old list, update if so, insert if not
34
+ var existingList = isListNotEmpty(oldList) ? _toConsumableArray(oldList) : [];
35
+ var index = existingList.findIndex(function (obj) {
36
+ return obj[idFieldName] === newRecord[idFieldName];
37
+ });
38
+ var updatedRecords = [];
39
+ // only update if the record exists in the list
40
+ if (index !== -1) {
41
+ updatedRecords = [].concat(_toConsumableArray(existingList.slice(0, index)), [
42
+ // everything before current obj
43
+ newRecord], _toConsumableArray(existingList.slice(index + 1)));
44
+ } else {
45
+ updatedRecords = addObjectToTopOfArray(existingList, newRecord);
46
+ }
47
+ return updatedRecords;
48
+ };
49
+ export var addRecordToBottom = function addRecordToBottom(idFieldName, newRecord, oldList) {
50
+ // check to see if record already exists in the old list, update if so, insert if not
51
+ var existingList = isListNotEmpty(oldList) ? _toConsumableArray(oldList) : [];
52
+ var index = existingList.findIndex(function (obj) {
53
+ return obj[idFieldName] === newRecord[idFieldName];
54
+ });
55
+ var updatedRecords = [];
56
+ // only update if the record exists in the list
57
+ if (index !== -1) {
58
+ updatedRecords = [].concat(_toConsumableArray(existingList.slice(0, index)), [
59
+ // everything before current obj
60
+ newRecord], _toConsumableArray(existingList.slice(index + 1)));
61
+ } else {
62
+ updatedRecords = addObjectToBottomOfArray(existingList, newRecord);
63
+ }
64
+ return updatedRecords;
65
+ };
66
+ export var updateRecord = function updateRecord(idFieldName, updatedRecord, oldList) {
67
+ // check to see if record already exists in the old list, update if so, insert if not
68
+ var existingList = isListNotEmpty(oldList) ? _toConsumableArray(oldList) : [];
69
+ var index = existingList.findIndex(function (obj) {
70
+ return obj[idFieldName] === updatedRecord[idFieldName];
71
+ });
72
+ var updatedRecords = [];
73
+ // only update if the record exists in the list
74
+ if (index !== -1) {
75
+ updatedRecords = [].concat(_toConsumableArray(existingList.slice(0, index)), [
76
+ // everything before current obj
77
+ updatedRecord], _toConsumableArray(existingList.slice(index + 1)));
78
+ } else {
79
+ updatedRecords = addObjectToBottomOfArray(existingList, updatedRecord);
80
+ }
81
+ return updatedRecords;
82
+ };
83
+ export var updateRecordField = function updateRecordField(idFieldName, idFieldValue, updatedFieldName, updatedFieldValue, oldList) {
84
+ if (isListNotEmpty(oldList)) {
85
+ var existingList = _toConsumableArray(oldList);
86
+ var index = existingList.findIndex(function (obj) {
87
+ return obj[idFieldName] === idFieldValue;
88
+ });
89
+ var updatedRecords = [];
90
+ if (index !== -1) {
91
+ var existingRecord = existingList[index];
92
+ // only update if the record exists in the list
93
+ if (isObjectNotEmpty(existingRecord)) {
94
+ var updatedRecord = _objectSpread(_objectSpread({}, existingRecord), {}, _defineProperty({}, updatedFieldName, updatedFieldValue));
95
+ updatedRecords = [].concat(_toConsumableArray(existingList.slice(0, index)), [
96
+ // everything before current obj
97
+ updatedRecord], _toConsumableArray(existingList.slice(index + 1)));
98
+ return updatedRecords;
99
+ }
100
+ }
101
+ }
102
+ return oldList;
103
+ };
104
+ export var updateRecordFields = function updateRecordFields(idFieldName, idFieldValue, updatedFields, oldList) {
105
+ if (isListNotEmpty(oldList)) {
106
+ var existingList = _toConsumableArray(oldList);
107
+ var index = existingList.findIndex(function (obj) {
108
+ return obj[idFieldName] === idFieldValue;
109
+ });
110
+ var updatedRecords = [];
111
+ if (index !== -1) {
112
+ var existingRecord = existingList[index];
113
+ // only update if the record exists in the list
114
+ if (isObjectNotEmpty(existingRecord)) {
115
+ var updatedRecord = _objectSpread(_objectSpread({}, existingRecord), updatedFields);
116
+ updatedRecords = [].concat(_toConsumableArray(existingList.slice(0, index)), [
117
+ // everything before current obj
118
+ updatedRecord], _toConsumableArray(existingList.slice(index + 1)));
119
+ return updatedRecords;
120
+ }
121
+ }
122
+ }
123
+ return oldList;
124
+ };
125
+ export var removeRecord = function removeRecord(idFieldName, idToRemove, oldList) {
126
+ if (isListNotEmpty(oldList)) {
127
+ var existingList = _toConsumableArray(oldList);
128
+ var index = existingList.findIndex(function (obj) {
129
+ return obj[idFieldName] === idToRemove;
130
+ });
131
+ // only update if the record exists in the list
132
+ if (index !== -1) {
133
+ // returns the deleted items
134
+ existingList.splice(index, 1);
135
+ }
136
+ return existingList;
137
+ }
138
+ return oldList;
139
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-survey-builder",
3
- "version": "1.0.72",
3
+ "version": "1.0.74",
4
4
  "description": "A complete survey builder for react.",
5
5
  "main": "lib/index.js",
6
6
  "types": "types/index.d.ts",
@@ -37,6 +37,7 @@
37
37
  "immutability-helper": "^3.1.1",
38
38
  "isomorphic-fetch": "^3.0.0",
39
39
  "libphonenumber-js": "^1.10.61",
40
+ "lodash": "^4.17.21",
40
41
  "moment": "^2.30.1",
41
42
  "moment-timezone": "^0.5.44",
42
43
  "prop-types": "^15.7.2",
@@ -65,13 +66,13 @@
65
66
  "@babel/core": "^7.24.5",
66
67
  "@babel/preset-env": "^7.24.5",
67
68
  "@babel/preset-react": "^7.24.1",
68
- "css-loader": "^7.1.1",
69
- "sass-loader": "^14.2.1",
70
- "node-sass": "^9.0.0",
71
- "style-loader": "^4.0.0",
72
69
  "babel-loader": "^9.1.3",
73
70
  "copyfiles": "^2.4.1",
71
+ "css-loader": "^7.1.1",
72
+ "node-sass": "^9.0.0",
74
73
  "rimraf": "^3.0.2",
74
+ "sass-loader": "^14.2.1",
75
+ "style-loader": "^4.0.0",
75
76
  "webpack": "^5.91.0",
76
77
  "webpack-cli": "^5.1.4",
77
78
  "webpack-dev-server": "^4.15.1"
package/types/index.d.ts CHANGED
@@ -43,6 +43,9 @@ type BaseElement = {
43
43
  pageBreakBefore?: boolean;
44
44
  canPopulateFromApi: boolean;
45
45
  text: string;
46
+ conditional?: boolean;
47
+ conditionalFieldName?: string;
48
+ conditionalFieldValue?: string;
46
49
  };
47
50
  export type StaticElement = {
48
51
  bold: boolean;
@@ -176,6 +179,8 @@ export interface SurveyGeneratorProps {
176
179
  buttons?: JSX.Element;
177
180
  buttonClassName?: string;
178
181
  checkboxButtonClassName?: string;
182
+ headerClassName?: string;
183
+ labelClassName?: string;
179
184
  formId?: string;
180
185
  methods?: Record<any, any>;
181
186
  print?: boolean;