react-form-builder-more-flexibility 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.
- package/README.md +49 -2
- package/dist/845.app.js +1 -1
- package/dist/app.js +1 -1
- package/lib/form-elements/component-label.js +4 -0
- package/lib/form-elements/index.js +33 -0
- package/lib/form-elements-edit.js +32 -0
- package/lib/preview.js +51 -3
- package/package.json +38 -2
|
@@ -15,6 +15,10 @@ var ComponentLabel = function ComponentLabel(props) {
|
|
|
15
15
|
}
|
|
16
16
|
var hasPopUp = !!props.data.hasPopUp;
|
|
17
17
|
return /*#__PURE__*/_react["default"].createElement("label", {
|
|
18
|
+
// id so the paired input can name itself via aria-labelledby (H91/F68):
|
|
19
|
+
// the label's onClick opens the rules popup for hasPopUp items, so
|
|
20
|
+
// htmlFor would wrongly focus the field — name by reference instead.
|
|
21
|
+
id: props.data.field_name ? "".concat(props.data.field_name, "__label") : undefined,
|
|
18
22
|
onClick: hasPopUp ? props.passUpClick : undefined // Pass the function reference instead of invoking it
|
|
19
23
|
,
|
|
20
24
|
className: props.className || 'form-label',
|
|
@@ -29,6 +29,28 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
29
29
|
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) { (0, _defineProperty2["default"])(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; }
|
|
30
30
|
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
|
|
31
31
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /* eslint-disable quote-props */ // eslint-disable-next-line max-classes-per-file
|
|
32
|
+
// Accessible NAME for every input (WCAG H91 / F68). Operators often leave the
|
|
33
|
+
// label blank and rely on the placeholder, which axe tolerates but Pa11y
|
|
34
|
+
// rightly rejects (a placeholder vanishes on first keystroke). Name by the
|
|
35
|
+
// visible label when there is one (aria-labelledby → ComponentLabel's id),
|
|
36
|
+
// else fall back to a stable aria-label from the placeholder or a humanized
|
|
37
|
+
// custom_name. Mirrors the fan side's LightFormRenderer.nameProps.
|
|
38
|
+
var humanizeName = function humanizeName(s) {
|
|
39
|
+
return (s || '').replace(/_\d+$/, '').replace(/[_-]+/g, ' ').trim().replace(/\b\w/g, function (c) {
|
|
40
|
+
return c.toUpperCase();
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
var accessibleNameProps = function accessibleNameProps() {
|
|
44
|
+
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
45
|
+
var hasVisibleLabel = !!(data.label && String(data.label).trim());
|
|
46
|
+
if (hasVisibleLabel) return {
|
|
47
|
+
'aria-labelledby': "".concat(data.field_name, "__label")
|
|
48
|
+
};
|
|
49
|
+
var fallback = data.placeholder && String(data.placeholder).trim() || humanizeName(data.custom_name) || humanizeName(data.field_name);
|
|
50
|
+
return fallback ? {
|
|
51
|
+
'aria-label': fallback
|
|
52
|
+
} : {};
|
|
53
|
+
};
|
|
32
54
|
var FormElements = {};
|
|
33
55
|
var Header = /*#__PURE__*/function (_React$Component) {
|
|
34
56
|
function Header() {
|
|
@@ -164,6 +186,7 @@ var TextInput = /*#__PURE__*/function (_React$Component5) {
|
|
|
164
186
|
props.className = 'form-control';
|
|
165
187
|
props.name = this.props.data.field_name;
|
|
166
188
|
props.placeholder = this.props.data.placeholder;
|
|
189
|
+
Object.assign(props, accessibleNameProps(this.props.data));
|
|
167
190
|
if (this.props.mutable) {
|
|
168
191
|
props.defaultValue = this.props.defaultValue;
|
|
169
192
|
props.ref = this.inputField;
|
|
@@ -201,6 +224,7 @@ var EmailInput = /*#__PURE__*/function (_React$Component6) {
|
|
|
201
224
|
props.className = 'form-control';
|
|
202
225
|
props.name = this.props.data.field_name;
|
|
203
226
|
props.placeholder = this.props.data.placeholder;
|
|
227
|
+
Object.assign(props, accessibleNameProps(this.props.data));
|
|
204
228
|
if (this.props.mutable) {
|
|
205
229
|
props.defaultValue = this.props.defaultValue;
|
|
206
230
|
props.ref = this.inputField;
|
|
@@ -238,6 +262,7 @@ var PhoneNumber = /*#__PURE__*/function (_React$Component7) {
|
|
|
238
262
|
props.className = 'form-control';
|
|
239
263
|
props.name = this.props.data.field_name;
|
|
240
264
|
props.placeholder = this.props.data.placeholder;
|
|
265
|
+
Object.assign(props, accessibleNameProps(this.props.data));
|
|
241
266
|
if (this.props.mutable) {
|
|
242
267
|
props.defaultValue = this.props.defaultValue;
|
|
243
268
|
props.ref = this.inputField;
|
|
@@ -275,6 +300,7 @@ var NumberInput = /*#__PURE__*/function (_React$Component8) {
|
|
|
275
300
|
props.className = 'form-control';
|
|
276
301
|
props.name = this.props.data.field_name;
|
|
277
302
|
props.placeholder = this.props.data.placeholder;
|
|
303
|
+
Object.assign(props, accessibleNameProps(this.props.data));
|
|
278
304
|
if (this.props.mutable) {
|
|
279
305
|
props.defaultValue = this.props.defaultValue;
|
|
280
306
|
props.ref = this.inputField;
|
|
@@ -311,6 +337,7 @@ var TextArea = /*#__PURE__*/function (_React$Component9) {
|
|
|
311
337
|
props.className = 'form-control';
|
|
312
338
|
props.name = this.props.data.field_name;
|
|
313
339
|
props.placeholder = this.props.data.placeholder;
|
|
340
|
+
Object.assign(props, accessibleNameProps(this.props.data));
|
|
314
341
|
if (this.props.read_only) {
|
|
315
342
|
props.disabled = 'disabled';
|
|
316
343
|
}
|
|
@@ -626,7 +653,13 @@ var Checkbox = /*#__PURE__*/function (_React$Component12) {
|
|
|
626
653
|
}, /*#__PURE__*/_react["default"].createElement("input", (0, _extends2["default"])({
|
|
627
654
|
className: "form-check-input",
|
|
628
655
|
id: this.props.data.field_name
|
|
656
|
+
// Named by the box label via aria-labelledby, not htmlFor — the
|
|
657
|
+
// box label's onClick opens the rules popup and must not toggle
|
|
658
|
+
// the box (H91.InputCheckbox.Name).
|
|
659
|
+
,
|
|
660
|
+
"aria-labelledby": "".concat(this.props.data.field_name, "__boxlabel")
|
|
629
661
|
}, props)), /*#__PURE__*/_react["default"].createElement("label", {
|
|
662
|
+
id: "".concat(this.props.data.field_name, "__boxlabel"),
|
|
630
663
|
className: "form-check-label",
|
|
631
664
|
onClick: this.handleLabelClick,
|
|
632
665
|
dangerouslySetInnerHTML: {
|
|
@@ -223,6 +223,25 @@ var FormElementsEdit = exports["default"] = /*#__PURE__*/function (_React$Compon
|
|
|
223
223
|
_this.props.manualEditModeOff && _this.props.manualEditModeOff();
|
|
224
224
|
});
|
|
225
225
|
});
|
|
226
|
+
// A click outside the panel closes it the way Save does, never by discarding
|
|
227
|
+
// the draft. Returns false (and shows the errors) when the draft is invalid,
|
|
228
|
+
// so the panel stays open; true when it committed, or had nothing to commit.
|
|
229
|
+
// Preview closes the panel itself afterwards — no manualEditModeOff here.
|
|
230
|
+
(0, _defineProperty2["default"])(_this, "commitDraftOnOutsideClose", function () {
|
|
231
|
+
if (!_this.state.dirty) return true;
|
|
232
|
+
var errors = _this.validate();
|
|
233
|
+
if (Object.keys(errors).length > 0) {
|
|
234
|
+
_this.setState({
|
|
235
|
+
errors: errors
|
|
236
|
+
});
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
_this.props.updateElement.call(_this.props.preview, _this.state.draft);
|
|
240
|
+
_this.setState({
|
|
241
|
+
dirty: false
|
|
242
|
+
});
|
|
243
|
+
return true;
|
|
244
|
+
});
|
|
226
245
|
(0, _defineProperty2["default"])(_this, "cancel", function () {
|
|
227
246
|
// Discard local changes & close
|
|
228
247
|
_this.setState({
|
|
@@ -244,6 +263,19 @@ var FormElementsEdit = exports["default"] = /*#__PURE__*/function (_React$Compon
|
|
|
244
263
|
}
|
|
245
264
|
(0, _inherits2["default"])(FormElementsEdit, _React$Component);
|
|
246
265
|
return (0, _createClass2["default"])(FormElementsEdit, [{
|
|
266
|
+
key: "componentDidMount",
|
|
267
|
+
value: function componentDidMount() {
|
|
268
|
+
// Preview's outside-click close commits through this (see commitDraftOnOutsideClose).
|
|
269
|
+
if (typeof this.props.registerDraftCommitter === 'function') {
|
|
270
|
+
this.unregisterDraftCommitter = this.props.registerDraftCommitter(this.commitDraftOnOutsideClose);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}, {
|
|
274
|
+
key: "componentWillUnmount",
|
|
275
|
+
value: function componentWillUnmount() {
|
|
276
|
+
if (this.unregisterDraftCommitter) this.unregisterDraftCommitter();
|
|
277
|
+
}
|
|
278
|
+
}, {
|
|
247
279
|
key: "componentDidUpdate",
|
|
248
280
|
value: function componentDidUpdate(prevProps) {
|
|
249
281
|
var _prevProps$element, _this$props$element;
|
package/lib/preview.js
CHANGED
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports["default"] = void 0;
|
|
7
|
+
exports["default"] = exports.KEEP_EDIT_OPEN_SELECTOR = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
10
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
@@ -13,6 +13,7 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
|
|
|
13
13
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
14
14
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
15
|
var _react = _interopRequireDefault(require("react"));
|
|
16
|
+
var _reactDom = require("react-dom");
|
|
16
17
|
var _immutabilityHelper = _interopRequireDefault(require("immutability-helper"));
|
|
17
18
|
var _store = _interopRequireDefault(require("./stores/store"));
|
|
18
19
|
var _formDynamicEdit = _interopRequireDefault(require("./form-dynamic-edit"));
|
|
@@ -23,6 +24,20 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
23
24
|
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
|
|
24
25
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } //src/preview.jsx
|
|
25
26
|
var PlaceHolder = _sortableFormElements["default"].PlaceHolder;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A mousedown inside any of these is NOT an outside click for the element edit
|
|
30
|
+
* panel. SweetAlert2 mounts its dialogs on <body>, so a link dialog opened from
|
|
31
|
+
* a rich-text editor INSIDE the panel is outside the panel's DOM; before this,
|
|
32
|
+
* clicking into that dialog closed the panel and lost the operator's draft.
|
|
33
|
+
* Any other pop-up a host app opens from the panel (a portal, a modal, a
|
|
34
|
+
* popover) opts in by carrying `data-rfb-keep-edit-open` on its root — see
|
|
35
|
+
* the README.
|
|
36
|
+
*/
|
|
37
|
+
var KEEP_EDIT_OPEN_SELECTOR = exports.KEEP_EDIT_OPEN_SELECTOR = '.swal2-container, [data-rfb-keep-edit-open]';
|
|
38
|
+
var isKeepEditOpenTarget = function isKeepEditOpenTarget(target) {
|
|
39
|
+
return !!(target && typeof target.closest === 'function' && target.closest(KEEP_EDIT_OPEN_SELECTOR));
|
|
40
|
+
};
|
|
26
41
|
var Preview = exports["default"] = /*#__PURE__*/function (_React$Component) {
|
|
27
42
|
function Preview(props) {
|
|
28
43
|
var _this;
|
|
@@ -32,14 +47,46 @@ var Preview = exports["default"] = /*#__PURE__*/function (_React$Component) {
|
|
|
32
47
|
data: [],
|
|
33
48
|
answer_data: {}
|
|
34
49
|
});
|
|
50
|
+
// The edit form registers how to commit its draft; the outside-click close uses it.
|
|
51
|
+
(0, _defineProperty2["default"])(_this, "registerDraftCommitter", function (commit) {
|
|
52
|
+
_this.draftCommitter = commit;
|
|
53
|
+
return function () {
|
|
54
|
+
if (_this.draftCommitter === commit) _this.draftCommitter = null;
|
|
55
|
+
};
|
|
56
|
+
});
|
|
35
57
|
(0, _defineProperty2["default"])(_this, "editModeOff", function (e) {
|
|
36
|
-
|
|
58
|
+
var form = _this.editForm.current;
|
|
59
|
+
if (!form || form.contains(e.target)) return;
|
|
60
|
+
// A pop-up the panel opened (a link dialog, a colour picker, an upload error)
|
|
61
|
+
// is usually mounted on <body>, so it is outside the panel's DOM without
|
|
62
|
+
// being outside the interaction. Closing here used to take the draft with it.
|
|
63
|
+
if (isKeepEditOpenTarget(e.target)) return;
|
|
64
|
+
var commit = _this.draftCommitter;
|
|
65
|
+
if (!commit) {
|
|
37
66
|
_this.manualEditModeOff();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// An outside click closes the panel THE WAY SAVE DOES — it must never
|
|
70
|
+
// silently discard what the operator typed. A field that only reports its
|
|
71
|
+
// value on blur (an option row) is blurred first, synchronously, so the
|
|
72
|
+
// draft is complete before it is committed.
|
|
73
|
+
var active = document.activeElement;
|
|
74
|
+
if (active && active !== document.body && form.contains(active) && typeof active.blur === 'function') {
|
|
75
|
+
(0, _reactDom.flushSync)(function () {
|
|
76
|
+
return active.blur();
|
|
77
|
+
});
|
|
38
78
|
}
|
|
79
|
+
// false = the draft is invalid; the form is showing why, so stay open.
|
|
80
|
+
if (commit() === false) return;
|
|
81
|
+
_this.manualEditModeOff();
|
|
39
82
|
});
|
|
40
83
|
(0, _defineProperty2["default"])(_this, "manualEditModeOff", function () {
|
|
41
84
|
var editElement = _this.props.editElement;
|
|
42
|
-
|
|
85
|
+
// The legacy close path, for an edit form that edits the element in place.
|
|
86
|
+
// A draft-based form (the default one registers a committer) owns its
|
|
87
|
+
// commits: `editElement` is the STALE element it opened with, and re-posting
|
|
88
|
+
// it here overwrote the draft Save had just committed.
|
|
89
|
+
if (editElement && editElement.dirty && !_this.draftCommitter) {
|
|
43
90
|
editElement.dirty = false;
|
|
44
91
|
_this.updateElement(editElement);
|
|
45
92
|
}
|
|
@@ -339,6 +386,7 @@ var Preview = exports["default"] = /*#__PURE__*/function (_React$Component) {
|
|
|
339
386
|
showCorrectColumn: this.props.showCorrectColumn,
|
|
340
387
|
files: this.props.files,
|
|
341
388
|
manualEditModeOff: this.manualEditModeOff,
|
|
389
|
+
registerDraftCommitter: this.registerDraftCommitter,
|
|
342
390
|
preview: this,
|
|
343
391
|
element: this.props.editElement,
|
|
344
392
|
updateElement: handleUpdateElement
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-form-builder-more-flexibility",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.74",
|
|
4
4
|
"description": "A complete form builder for react.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
"@babel/runtime-corejs2": "^7.12.5",
|
|
68
68
|
"add": "^2.0.6",
|
|
69
69
|
"babel-eslint": "^10.1.0",
|
|
70
|
+
"babel-jest": "^29.7.0",
|
|
70
71
|
"babel-loader": "^8.2.2",
|
|
71
72
|
"copyfiles": "^2.4.1",
|
|
72
73
|
"css-loader": "^3.6.0",
|
|
@@ -77,6 +78,8 @@
|
|
|
77
78
|
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
78
79
|
"eslint-plugin-react": "^7.22.0",
|
|
79
80
|
"express": "^4.17.1",
|
|
81
|
+
"jest": "^29.7.0",
|
|
82
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
80
83
|
"multer": "^1.4.2",
|
|
81
84
|
"react": "^18.3.1",
|
|
82
85
|
"react-dom": "^18.3.1",
|
|
@@ -103,7 +106,8 @@
|
|
|
103
106
|
"start": "NODE_OPTIONS=--openssl-legacy-provider && webpack-dev-server --hot --mode development",
|
|
104
107
|
"serve:api": "node server/index.js",
|
|
105
108
|
"pretranspile": "rimraf lib",
|
|
106
|
-
"transpile": "babel --out-dir lib src --copy-files"
|
|
109
|
+
"transpile": "babel --out-dir lib src --copy-files",
|
|
110
|
+
"test": "jest"
|
|
107
111
|
},
|
|
108
112
|
"bugs": {
|
|
109
113
|
"url": "https://github.com/ljorgens/react-form-builder/issues"
|
|
@@ -112,5 +116,37 @@
|
|
|
112
116
|
"directories": {
|
|
113
117
|
"doc": "docs",
|
|
114
118
|
"example": "examples"
|
|
119
|
+
},
|
|
120
|
+
"jest": {
|
|
121
|
+
"testEnvironment": "jsdom",
|
|
122
|
+
"roots": [
|
|
123
|
+
"<rootDir>/test"
|
|
124
|
+
],
|
|
125
|
+
"moduleNameMapper": {
|
|
126
|
+
"\\.(css|scss)$": "<rootDir>/test/styleStub.js"
|
|
127
|
+
},
|
|
128
|
+
"transform": {
|
|
129
|
+
"/node_modules/.+\\.js$": [
|
|
130
|
+
"babel-jest",
|
|
131
|
+
{
|
|
132
|
+
"babelrc": false,
|
|
133
|
+
"configFile": false,
|
|
134
|
+
"presets": [
|
|
135
|
+
[
|
|
136
|
+
"@babel/preset-env",
|
|
137
|
+
{
|
|
138
|
+
"targets": {
|
|
139
|
+
"node": "current"
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
"\\.[jt]sx?$": "babel-jest"
|
|
147
|
+
},
|
|
148
|
+
"transformIgnorePatterns": [
|
|
149
|
+
"/node_modules/(?!(react-dnd|react-dnd-html5-backend|dnd-core|@react-dnd)/)"
|
|
150
|
+
]
|
|
115
151
|
}
|
|
116
152
|
}
|