react-survey-builder 1.0.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.
- package/LICENSE +7 -0
- package/README.md +236 -0
- package/dist/967.index.js +1 -0
- package/dist/app.css +1 -0
- package/dist/app.css.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.LICENSE.txt +46 -0
- package/lib/ItemTypes.js +10 -0
- package/lib/UUID.js +65 -0
- package/lib/dynamic-option-list.js +188 -0
- package/lib/fieldset/FieldSet.js +118 -0
- package/lib/fieldset/index.js +13 -0
- package/lib/form.js +604 -0
- package/lib/functions/index.js +45 -0
- package/lib/index.js +139 -0
- package/lib/language-provider/IntlMessages.js +15 -0
- package/lib/language-provider/entries/en-us.js +16 -0
- package/lib/language-provider/entries/it-it.js +16 -0
- package/lib/language-provider/entries/vi-vn.js +16 -0
- package/lib/language-provider/index.js +32 -0
- package/lib/language-provider/locales/en-us.json +97 -0
- package/lib/language-provider/locales/it-it.json +92 -0
- package/lib/language-provider/locales/vi-vn.json +82 -0
- package/lib/multi-column/MultiColumnRow.js +134 -0
- package/lib/multi-column/dustbin.js +152 -0
- package/lib/multi-column/grip.js +51 -0
- package/lib/multi-column/index.js +24 -0
- package/lib/preview.js +388 -0
- package/lib/sortable-element.js +177 -0
- package/lib/sortable-form-elements.js +67 -0
- package/lib/stores/registry.js +42 -0
- package/lib/stores/requests.js +31 -0
- package/lib/stores/store.js +138 -0
- package/lib/survey-dynamic-edit.js +54 -0
- package/lib/survey-elements/component-drag-handle.js +90 -0
- package/lib/survey-elements/component-drag-layer.js +68 -0
- package/lib/survey-elements/component-drag-preview.js +57 -0
- package/lib/survey-elements/component-header.js +29 -0
- package/lib/survey-elements/component-label.js +26 -0
- package/lib/survey-elements/custom-element.js +70 -0
- package/lib/survey-elements/date-picker.js +278 -0
- package/lib/survey-elements/header-bar.js +54 -0
- package/lib/survey-elements/index.js +1196 -0
- package/lib/survey-elements/myxss.js +29 -0
- package/lib/survey-elements/star-rating.js +335 -0
- package/lib/survey-elements-edit.js +613 -0
- package/lib/survey-place-holder.js +51 -0
- package/lib/survey-validator.js +103 -0
- package/lib/toolbar-draggable-item.js +59 -0
- package/lib/toolbar-group-item.js +39 -0
- package/lib/toolbar.js +680 -0
- package/lib/utils/custom-date-picker.js +93 -0
- package/package.json +114 -0
- package/types/index.d.ts +180 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports["default"] = void 0;
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
9
|
+
var _reactDatepicker = _interopRequireDefault(require("react-datepicker"));
|
10
|
+
var _lodash = require("lodash");
|
11
|
+
function DatePickerComponent(props) {
|
12
|
+
var showTimeInput = props.showTimeInput,
|
13
|
+
dateFormat = props.dateFormat,
|
14
|
+
selected = props.selected,
|
15
|
+
_onChange = props.onChange,
|
16
|
+
isClearable = props.isClearable,
|
17
|
+
portalId = props.portalId;
|
18
|
+
var ButtonDatePicker = function ButtonDatePicker(_ref) {
|
19
|
+
var value = _ref.value,
|
20
|
+
onClick = _ref.onClick;
|
21
|
+
return /*#__PURE__*/_react["default"].createElement("button", {
|
22
|
+
type: "button",
|
23
|
+
className: "form-control",
|
24
|
+
style: {
|
25
|
+
minWidth: 140,
|
26
|
+
textAlign: 'left'
|
27
|
+
},
|
28
|
+
onClick: onClick
|
29
|
+
}, value || 'mm/dd/yyyy');
|
30
|
+
};
|
31
|
+
var years = (0, _lodash.range)(2010, new Date().getFullYear() + 10, 1);
|
32
|
+
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
33
|
+
return /*#__PURE__*/_react["default"].createElement(_reactDatepicker["default"], {
|
34
|
+
name: props.name,
|
35
|
+
ref: props.ref,
|
36
|
+
selected: selected,
|
37
|
+
onChange: function onChange(date) {
|
38
|
+
return _onChange(date);
|
39
|
+
},
|
40
|
+
todayButton: 'Today',
|
41
|
+
className: "form-control",
|
42
|
+
showTimeSelect: props.showTimeSelect,
|
43
|
+
showTimeSelectOnly: props.showTimeSelectOnly,
|
44
|
+
showTimeInput: showTimeInput,
|
45
|
+
autoComplete: "off",
|
46
|
+
placeholderText: props.placeholderText,
|
47
|
+
portalId: portalId,
|
48
|
+
dateFormat: dateFormat,
|
49
|
+
isClearable: isClearable,
|
50
|
+
customInput: /*#__PURE__*/_react["default"].createElement(ButtonDatePicker, null),
|
51
|
+
renderCustomHeader: function renderCustomHeader(_ref2) {
|
52
|
+
var date = _ref2.date,
|
53
|
+
changeYear = _ref2.changeYear,
|
54
|
+
changeMonth = _ref2.changeMonth,
|
55
|
+
decreaseMonth = _ref2.decreaseMonth,
|
56
|
+
increaseMonth = _ref2.increaseMonth,
|
57
|
+
prevMonthButtonDisabled = _ref2.prevMonthButtonDisabled,
|
58
|
+
nextMonthButtonDisabled = _ref2.nextMonthButtonDisabled;
|
59
|
+
return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("button", {
|
60
|
+
onClick: decreaseMonth,
|
61
|
+
disabled: prevMonthButtonDisabled,
|
62
|
+
type: "button"
|
63
|
+
}, '<'), /*#__PURE__*/_react["default"].createElement("select", {
|
64
|
+
value: date.getFullYear(),
|
65
|
+
onChange: function onChange(_ref3) {
|
66
|
+
var value = _ref3.target.value;
|
67
|
+
return changeYear(value);
|
68
|
+
}
|
69
|
+
}, years.map(function (option) {
|
70
|
+
return /*#__PURE__*/_react["default"].createElement("option", {
|
71
|
+
key: option,
|
72
|
+
value: option
|
73
|
+
}, option);
|
74
|
+
})), /*#__PURE__*/_react["default"].createElement("select", {
|
75
|
+
value: months[date.getMonth()],
|
76
|
+
onChange: function onChange(_ref4) {
|
77
|
+
var value = _ref4.target.value;
|
78
|
+
return changeMonth(months.indexOf(value));
|
79
|
+
}
|
80
|
+
}, months.map(function (option) {
|
81
|
+
return /*#__PURE__*/_react["default"].createElement("option", {
|
82
|
+
key: option,
|
83
|
+
value: option
|
84
|
+
}, option);
|
85
|
+
})), /*#__PURE__*/_react["default"].createElement("button", {
|
86
|
+
onClick: increaseMonth,
|
87
|
+
disabled: nextMonthButtonDisabled,
|
88
|
+
type: "button"
|
89
|
+
}, '>'));
|
90
|
+
}
|
91
|
+
});
|
92
|
+
}
|
93
|
+
var _default = exports["default"] = DatePickerComponent;
|
package/package.json
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
{
|
2
|
+
"name": "react-survey-builder",
|
3
|
+
"version": "1.0.1",
|
4
|
+
"description": "A complete survey builder for react.",
|
5
|
+
"main": "lib/index.js",
|
6
|
+
"types": "types/index.d.ts",
|
7
|
+
"license": "MIT",
|
8
|
+
"repository": {
|
9
|
+
"type": "git",
|
10
|
+
"url": "git+https://github.com/garrettlang/react-survey-builder.git"
|
11
|
+
},
|
12
|
+
"files": [
|
13
|
+
"lib",
|
14
|
+
"dist",
|
15
|
+
"types"
|
16
|
+
],
|
17
|
+
"keywords": [
|
18
|
+
"react",
|
19
|
+
"react-component",
|
20
|
+
"form",
|
21
|
+
"builder",
|
22
|
+
"ui",
|
23
|
+
"drag",
|
24
|
+
"drop"
|
25
|
+
],
|
26
|
+
"engines": {
|
27
|
+
"node": ">=18.7.0"
|
28
|
+
},
|
29
|
+
"author": "Garrett Lang",
|
30
|
+
"dependencies": {
|
31
|
+
"@fortawesome/react-fontawesome": "^0.2.0",
|
32
|
+
"beedle": "^0.8.1",
|
33
|
+
"classnames": "^2.2.6",
|
34
|
+
"date-fns": "^2.16.1",
|
35
|
+
"draft-js": "^0.11.7",
|
36
|
+
"draftjs-to-html": "^0.9.1",
|
37
|
+
"es6-promise": "^4.2.8",
|
38
|
+
"fbemitter": "^3.0.0",
|
39
|
+
"file-saver": "^2.0.5",
|
40
|
+
"immutability-helper": "^3.1.1",
|
41
|
+
"isomorphic-fetch": "^3.0.0",
|
42
|
+
"lodash": "^4.17.21",
|
43
|
+
"prop-types": "^15.7.2",
|
44
|
+
"react-bootstrap": "^2.9.2",
|
45
|
+
"react-bootstrap-range-slider": "^3.0.8",
|
46
|
+
"react-dnd": "^11.1.3",
|
47
|
+
"react-dnd-html5-backend": "^11.1.3",
|
48
|
+
"react-draft-wysiwyg": "^1.15.0",
|
49
|
+
"react-icons": "^5.0.1",
|
50
|
+
"react-intl": "^5.24.3",
|
51
|
+
"react-select": "^5.8.0",
|
52
|
+
"react-signature-canvas": "^1.0.3",
|
53
|
+
"react-textarea-autosize": "^8.5.3",
|
54
|
+
"xss": "^1.0.8"
|
55
|
+
},
|
56
|
+
"peerDependencies": {
|
57
|
+
"react": ">=18.2.0",
|
58
|
+
"react-dom": ">=18.2.0"
|
59
|
+
},
|
60
|
+
"devDependencies": {
|
61
|
+
"@babel/cli": "^7.12.10",
|
62
|
+
"@babel/core": "^7.12.10",
|
63
|
+
"@babel/plugin-proposal-class-properties": "^7.12.1",
|
64
|
+
"@babel/plugin-proposal-json-strings": "^7.12.1",
|
65
|
+
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
66
|
+
"@babel/plugin-syntax-import-meta": "^7.10.4",
|
67
|
+
"@babel/plugin-transform-runtime": "^7.17.10",
|
68
|
+
"@babel/preset-env": "^7.12.11",
|
69
|
+
"@babel/preset-react": "^7.14.5",
|
70
|
+
"@babel/runtime-corejs2": "^7.12.5",
|
71
|
+
"add": "^2.0.6",
|
72
|
+
"babel-eslint": "^10.1.0",
|
73
|
+
"babel-loader": "^8.2.2",
|
74
|
+
"copyfiles": "^2.4.1",
|
75
|
+
"css-loader": "^6.9.0",
|
76
|
+
"ejs": "^3.1.9",
|
77
|
+
"eslint": "^6.8.0",
|
78
|
+
"eslint-config-airbnb": "^18.2.1",
|
79
|
+
"eslint-plugin-import": "^2.22.1",
|
80
|
+
"eslint-plugin-jsx-a11y": "^6.4.1",
|
81
|
+
"eslint-plugin-react": "^7.22.0",
|
82
|
+
"express": "^4.17.1",
|
83
|
+
"multer": "^1.4.2",
|
84
|
+
"react": "^18.2.0",
|
85
|
+
"react-dom": "^18.2.0",
|
86
|
+
"rimraf": "^3.0.2",
|
87
|
+
"sass": "^1.69.7",
|
88
|
+
"sass-loader": "^14.0.0",
|
89
|
+
"style-loader": "^3.3.4",
|
90
|
+
"webpack": "^5.89.0",
|
91
|
+
"webpack-cli": "^5.1.4",
|
92
|
+
"webpack-dev-server": "^4.15.1"
|
93
|
+
},
|
94
|
+
"scripts": {
|
95
|
+
"build": "webpack --mode production --config webpack.production.config.js",
|
96
|
+
"build:dev": "webpack --mode development",
|
97
|
+
"build:umd": "webpack --mode development --config webpack.production.config.js",
|
98
|
+
"build:style": "sass ./scss/application.scss dist/app.css --style compressed",
|
99
|
+
"build:lib": "npm run transpile && npm run build:style",
|
100
|
+
"build:dist": "npm run build && npm run copy:dist",
|
101
|
+
"clean": "rimraf dist",
|
102
|
+
"copy:dist": "copyfiles -f \"./dist/*\" \"./public/dist\"",
|
103
|
+
"prepublishOnly": "npm run clean && npm run build:lib && npm run build",
|
104
|
+
"watch": "webpack --watch",
|
105
|
+
"start": "webpack-dev-server --hot --mode development",
|
106
|
+
"serve:api": "node server/index.js",
|
107
|
+
"pretranspile": "rimraf lib",
|
108
|
+
"transpile": "babel --out-dir lib src --copy-files"
|
109
|
+
},
|
110
|
+
"bugs": {
|
111
|
+
"url": "https://github.com/garrettlang/react-survey-builder/issues"
|
112
|
+
},
|
113
|
+
"homepage": "https://github.com/garrettlang/react-survey-builder#readme"
|
114
|
+
}
|
package/types/index.d.ts
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
/* eslint-disable max-classes-per-file */
|
2
|
+
import * as React from 'react';
|
3
|
+
|
4
|
+
type BaseElement = {
|
5
|
+
id: string;
|
6
|
+
element:
|
7
|
+
| "Header Text"
|
8
|
+
| "Label"
|
9
|
+
| "Paragraph"
|
10
|
+
| "Line Break"
|
11
|
+
| "Dropdown"
|
12
|
+
| "Tags"
|
13
|
+
| "Checkboxes"
|
14
|
+
| "Multiple Choice"
|
15
|
+
| "Text Input"
|
16
|
+
| "Number Input"
|
17
|
+
| "Multi-line Input"
|
18
|
+
| "Two Column Row"
|
19
|
+
| "Three Column Row"
|
20
|
+
| "Multi Column Row"
|
21
|
+
| "Image"
|
22
|
+
| "Rating"
|
23
|
+
| "Date"
|
24
|
+
| "Signature"
|
25
|
+
| "Web site"
|
26
|
+
| "Fieldset"
|
27
|
+
| "File Attachment"
|
28
|
+
| "Range"
|
29
|
+
| "Camera";
|
30
|
+
showDescription?: boolean;
|
31
|
+
required: boolean;
|
32
|
+
canHaveAlternateForm: boolean;
|
33
|
+
canHaveDisplayHorizontal: boolean;
|
34
|
+
canHaveOptionCorrect: boolean;
|
35
|
+
canHaveOptionValue: boolean;
|
36
|
+
canHavePageBreakBefore: boolean;
|
37
|
+
canPopulateFromApi: boolean;
|
38
|
+
text: string;
|
39
|
+
};
|
40
|
+
export type StaticElement = {
|
41
|
+
bold: boolean;
|
42
|
+
content: string;
|
43
|
+
inline?: boolean;
|
44
|
+
italic: boolean;
|
45
|
+
static: true;
|
46
|
+
};
|
47
|
+
export type SurveyBuilderInput = {
|
48
|
+
canHaveAnswer?: true;
|
49
|
+
field_name: string;
|
50
|
+
label: string;
|
51
|
+
};
|
52
|
+
export type Option = {
|
53
|
+
key: string;
|
54
|
+
label?: string;
|
55
|
+
text: string;
|
56
|
+
value: string;
|
57
|
+
};
|
58
|
+
export type SelectableElement = {
|
59
|
+
options: Option[];
|
60
|
+
} & SurveyBuilderInput;
|
61
|
+
export type ImageElement = {
|
62
|
+
field_name: string;
|
63
|
+
src: string;
|
64
|
+
};
|
65
|
+
export type DateElement = {
|
66
|
+
dateFormat: string;
|
67
|
+
defaultToday: boolean;
|
68
|
+
readOnly: boolean;
|
69
|
+
showTimeSelect: boolean;
|
70
|
+
showTimeSelectOnly: boolean;
|
71
|
+
showTimeInput: boolean;
|
72
|
+
timeFormat: string;
|
73
|
+
} & SurveyBuilderInput;
|
74
|
+
export type RangeElement = {
|
75
|
+
max_label: string;
|
76
|
+
max_value: number;
|
77
|
+
min_label: string;
|
78
|
+
min_value: number;
|
79
|
+
} & SurveyBuilderInput;
|
80
|
+
export type FileElement = {
|
81
|
+
_href: string;
|
82
|
+
file_path: string;
|
83
|
+
field_name: string;
|
84
|
+
} & StaticElement;
|
85
|
+
export type WebsiteElement = {
|
86
|
+
href: string;
|
87
|
+
} & StaticElement;
|
88
|
+
export type SignatureElement = {
|
89
|
+
readOnly: boolean;
|
90
|
+
} & SurveyBuilderInput;
|
91
|
+
export type TaskData = BaseElement &
|
92
|
+
(| StaticElement
|
93
|
+
| SurveyBuilderInput
|
94
|
+
| SelectableElement
|
95
|
+
| ImageElement
|
96
|
+
| DateElement
|
97
|
+
| RangeElement
|
98
|
+
| WebsiteElement
|
99
|
+
| FileElement
|
100
|
+
| SignatureElement
|
101
|
+
// eslint-disable-next-line no-use-before-define
|
102
|
+
| SurveyBuilderLayout
|
103
|
+
);
|
104
|
+
export type SurveyBuilderLayout = {
|
105
|
+
isContainer: true;
|
106
|
+
childItems: TaskData[];
|
107
|
+
field_name: string;
|
108
|
+
};
|
109
|
+
export type SurveyBuilderPostData = {
|
110
|
+
task_data: TaskData[];
|
111
|
+
};
|
112
|
+
|
113
|
+
export type ToolbarItem = {
|
114
|
+
key: string;
|
115
|
+
name: string;
|
116
|
+
static: boolean;
|
117
|
+
icon: string;
|
118
|
+
content: string;
|
119
|
+
};
|
120
|
+
|
121
|
+
export interface SurveyBuilderProps {
|
122
|
+
toolbarItems?: ToolbarItem[];
|
123
|
+
files?: any[];
|
124
|
+
url?: string;
|
125
|
+
showCorrectColumn?: boolean;
|
126
|
+
show_description?: boolean;
|
127
|
+
onLoad?: () => Promise<SurveyBuilderPostData>;
|
128
|
+
onPost?: (data: SurveyBuilderPostData) => void;
|
129
|
+
saveUrl?: string;
|
130
|
+
saveAlways?: boolean;
|
131
|
+
editMode?: boolean;
|
132
|
+
renderEditForm?: (props: BaseElement) => React.ReactNode;
|
133
|
+
}
|
134
|
+
|
135
|
+
export class ReactSurveyBuilder extends React.Component<SurveyBuilderProps> {}
|
136
|
+
|
137
|
+
export interface SurveyGeneratorOnSubmitParams {
|
138
|
+
id: number;
|
139
|
+
name: string;
|
140
|
+
custom_name: string;
|
141
|
+
value: string | string[];
|
142
|
+
}
|
143
|
+
|
144
|
+
export interface SurveyGeneratorProps {
|
145
|
+
form_action: string;
|
146
|
+
form_method: string;
|
147
|
+
action_name?: string;
|
148
|
+
onBlur?: (info: SurveyGeneratorOnSubmitParams[]) => void;
|
149
|
+
onSubmit?: (info: SurveyGeneratorOnSubmitParams[]) => void;
|
150
|
+
onChange?: (info: SurveyGeneratorOnSubmitParams[]) => void;
|
151
|
+
data: any[];
|
152
|
+
back_action?: string;
|
153
|
+
back_name?: string;
|
154
|
+
task_id?: number;
|
155
|
+
answer_data?: any[];
|
156
|
+
authenticity_token?: string;
|
157
|
+
hide_actions?: boolean;
|
158
|
+
skip_validations?: boolean;
|
159
|
+
display_short?: boolean;
|
160
|
+
read_only?: boolean;
|
161
|
+
// eslint-disable-next-line no-undef
|
162
|
+
variables?: Record<any, any>;
|
163
|
+
submitButton?: JSX.Element;
|
164
|
+
}
|
165
|
+
|
166
|
+
export class ReactSurveyGenerator extends React.Component<SurveyGeneratorProps> {}
|
167
|
+
|
168
|
+
export type ActionType = "load" | "updateOrder" | "delete";
|
169
|
+
|
170
|
+
export class ElementStore {
|
171
|
+
static dispatch: (type: ActionType, data: any) => void;
|
172
|
+
}
|
173
|
+
|
174
|
+
export class Registry {
|
175
|
+
static register: (name: string, component: React.ReactNode) => void;
|
176
|
+
|
177
|
+
static list: () => string[];
|
178
|
+
|
179
|
+
static get: (name: string) => React.ReactNode;
|
180
|
+
}
|