react-form-builder-more-flexibility 1.0.77 → 2.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.
@@ -1,21 +1,9 @@
1
- /*
2
- object-assign
3
- (c) Sindre Sorhus
4
- @license MIT
5
- */
6
-
7
1
  /*!
8
2
  Copyright (c) 2018 Jed Watson.
9
3
  Licensed under the MIT License (MIT), see
10
4
  http://jedwatson.github.io/classnames
11
5
  */
12
6
 
13
- /*!
14
- Copyright (c) 2017 Jed Watson.
15
- Licensed under the MIT License (MIT), see
16
- http://jedwatson.github.io/classnames
17
- */
18
-
19
7
  /*!
20
8
  * Signature Pad v2.3.2
21
9
  * https://github.com/szimek/signature_pad
@@ -40,31 +28,6 @@ object-assign
40
28
 
41
29
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
42
30
 
43
- /**
44
- * @license
45
- * MIT License
46
- *
47
- * Copyright (c) 2014-present, Lee Byron and other contributors.
48
- *
49
- * Permission is hereby granted, free of charge, to any person obtaining a copy
50
- * of this software and associated documentation files (the "Software"), to deal
51
- * in the Software without restriction, including without limitation the rights
52
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
53
- * copies of the Software, and to permit persons to whom the Software is
54
- * furnished to do so, subject to the following conditions:
55
- *
56
- * The above copyright notice and this permission notice shall be included in all
57
- * copies or substantial portions of the Software.
58
- *
59
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
63
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
64
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
65
- * SOFTWARE.
66
- */
67
-
68
31
  /**
69
32
  * @license React
70
33
  * react-jsx-runtime.production.min.js
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports["default"] = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _myxss = _interopRequireDefault(require("./myxss"));
10
+ var _contrastBacking = require("../utils/contrast-backing");
10
11
  var ComponentLabel = function ComponentLabel(props) {
11
12
  var hasRequiredLabel = props.data.hasOwnProperty('required') && props.data.required === true && !props.read_only;
12
13
  var labelText = _myxss["default"].process(props.data.label);
@@ -27,7 +28,7 @@ var ComponentLabel = function ComponentLabel(props) {
27
28
  }
28
29
  }, /*#__PURE__*/_react["default"].createElement("span", {
29
30
  dangerouslySetInnerHTML: {
30
- __html: labelText
31
+ __html: (0, _contrastBacking.canvasHtml)(props, labelText)
31
32
  }
32
33
  }), hasRequiredLabel && !props.hide_required_alert && /*#__PURE__*/_react["default"].createElement("span", {
33
34
  className: "label-required badge badge-danger"
@@ -25,6 +25,7 @@ var _datePicker = _interopRequireDefault(require("./date-picker"));
25
25
  var _componentHeader = _interopRequireDefault(require("./component-header"));
26
26
  var _componentLabel = _interopRequireDefault(require("./component-label"));
27
27
  var _myxss = _interopRequireDefault(require("./myxss"));
28
+ var _contrastBacking = require("../utils/contrast-backing");
28
29
  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; }
29
30
  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
31
  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)); }
@@ -79,7 +80,7 @@ var Header = /*#__PURE__*/function (_React$Component) {
79
80
  }, /*#__PURE__*/_react["default"].createElement(_componentHeader["default"], this.props), /*#__PURE__*/_react["default"].createElement("h3", {
80
81
  className: classNames,
81
82
  dangerouslySetInnerHTML: {
82
- __html: _myxss["default"].process(this.props.data.content)
83
+ __html: (0, _contrastBacking.canvasHtml)(this.props, _myxss["default"].process(this.props.data.content))
83
84
  }
84
85
  }));
85
86
  }
@@ -111,7 +112,7 @@ var Paragraph = /*#__PURE__*/function (_React$Component2) {
111
112
  }, /*#__PURE__*/_react["default"].createElement(_componentHeader["default"], this.props), /*#__PURE__*/_react["default"].createElement("p", {
112
113
  className: classNames,
113
114
  dangerouslySetInnerHTML: {
114
- __html: _myxss["default"].process(this.props.data.content)
115
+ __html: (0, _contrastBacking.canvasHtml)(this.props, _myxss["default"].process(this.props.data.content))
115
116
  }
116
117
  }));
117
118
  }
@@ -143,7 +144,7 @@ var Label = /*#__PURE__*/function (_React$Component3) {
143
144
  }, /*#__PURE__*/_react["default"].createElement(_componentHeader["default"], this.props), /*#__PURE__*/_react["default"].createElement("label", {
144
145
  className: "".concat(classNames, " form-label"),
145
146
  dangerouslySetInnerHTML: {
146
- __html: _myxss["default"].process(this.props.data.content)
147
+ __html: (0, _contrastBacking.canvasHtml)(this.props, _myxss["default"].process(this.props.data.content))
147
148
  }
148
149
  }));
149
150
  }
@@ -663,7 +664,7 @@ var Checkbox = /*#__PURE__*/function (_React$Component12) {
663
664
  className: "form-check-label",
664
665
  onClick: this.handleLabelClick,
665
666
  dangerouslySetInnerHTML: {
666
- __html: this.props.data.boxLabel
667
+ __html: (0, _contrastBacking.canvasHtml)(this.props, this.props.data.boxLabel)
667
668
  }
668
669
  }))));
669
670
  }
@@ -814,7 +815,7 @@ var HyperLink = /*#__PURE__*/function (_React$Component16) {
814
815
  target: "_blank",
815
816
  href: this.props.data.href,
816
817
  dangerouslySetInnerHTML: {
817
- __html: _myxss["default"].process(this.props.data.content)
818
+ __html: (0, _contrastBacking.canvasHtml)(this.props, _myxss["default"].process(this.props.data.content))
818
819
  }
819
820
  }))));
820
821
  }
@@ -15,12 +15,8 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
15
15
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
16
16
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
17
17
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
18
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
19
18
  var _react = _interopRequireDefault(require("react"));
20
19
  var _reactTextareaAutosize = _interopRequireDefault(require("react-textarea-autosize"));
21
- var _draftJs = require("draft-js");
22
- var _draftjsToHtml = _interopRequireDefault(require("draftjs-to-html"));
23
- var _reactDraftWysiwyg = require("react-draft-wysiwyg");
24
20
  var _dynamicOptionList = _interopRequireDefault(require("./dynamic-option-list"));
25
21
  var _requests = require("./stores/requests");
26
22
  var _UUID = _interopRequireDefault(require("./UUID"));
@@ -29,54 +25,28 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
29
25
  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
26
  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
27
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } //src/form-elements-edit.jsx
32
- // ---------- Default RTE (DraftJS) adapter: HTML in/out ----------
28
+ // ---------- Default RTE: a plain textarea, HTML string in / HTML string out ----------
29
+ // The same adapter contract as `renderRichTextEditor` (value, onChange(html), placeholder, disabled, className).
30
+ // A host that wants rich editing passes its own editor (the SQWAD tenant admin passes a Tiptap adapter). This was a
31
+ // draft-js / react-draft-wysiwyg editor until 2.0.0; it was dropped because it pulled immutable 3.x and linkify-it 2.x
32
+ // (unfixable HIGH advisories) into every consumer's bundle — test/defaultRichTextEditor.test.jsx pins the absence.
33
33
  var DefaultRTE = function DefaultRTE(_ref) {
34
34
  var _ref$value = _ref.value,
35
35
  value = _ref$value === void 0 ? '' : _ref$value,
36
- onChange = _ref.onChange,
36
+ _onChange = _ref.onChange,
37
37
  placeholder = _ref.placeholder,
38
38
  disabled = _ref.disabled,
39
39
  className = _ref.className;
40
- var _React$useState = _react["default"].useState(function () {
41
- var parsed = (0, _draftJs.convertFromHTML)(value || '');
42
- if (!parsed.contentBlocks || !parsed.contentBlocks.length) return _draftJs.EditorState.createEmpty();
43
- var contentState = _draftJs.ContentState.createFromBlockArray(parsed);
44
- return _draftJs.EditorState.createWithContent(contentState);
45
- }),
46
- _React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2),
47
- state = _React$useState2[0],
48
- setState = _React$useState2[1];
49
- _react["default"].useEffect(function () {
50
- var parsed = (0, _draftJs.convertFromHTML)(value || '');
51
- if (!parsed.contentBlocks || !parsed.contentBlocks.length) {
52
- setState(_draftJs.EditorState.createEmpty());
53
- return;
40
+ return /*#__PURE__*/_react["default"].createElement(_reactTextareaAutosize["default"], {
41
+ "data-rfb-default-rte": "",
42
+ className: className,
43
+ value: value || '',
44
+ placeholder: placeholder,
45
+ disabled: !!disabled,
46
+ minRows: 2,
47
+ onChange: function onChange(e) {
48
+ return _onChange === null || _onChange === void 0 ? void 0 : _onChange(e.target.value);
54
49
  }
55
- var contentState = _draftJs.ContentState.createFromBlockArray(parsed);
56
- setState(_draftJs.EditorState.createWithContent(contentState));
57
- }, [value]);
58
- var toHtml = function toHtml(editorState) {
59
- return (0, _draftjsToHtml["default"])((0, _draftJs.convertToRaw)(editorState.getCurrentContent())).replace(/<p>/g, '').replace(/<\/p>/g, '').replace(/&nbsp;/g, ' ').replace(/(?:\r\n|\r|\n)/g, ' ');
60
- };
61
- var handleChange = function handleChange(st) {
62
- setState(st);
63
- onChange === null || onChange === void 0 || onChange(toHtml(st));
64
- };
65
- var toolbar = {
66
- options: ['inline', 'list', 'textAlign', 'fontSize', 'link', 'history'],
67
- inline: {
68
- inDropdown: false,
69
- options: ['bold', 'italic', 'underline', 'superscript', 'subscript']
70
- }
71
- };
72
- return /*#__PURE__*/_react["default"].createElement(_reactDraftWysiwyg.Editor, {
73
- toolbar: toolbar,
74
- editorState: state,
75
- onEditorStateChange: handleChange,
76
- stripPastedStyles: true,
77
- readOnly: !!disabled,
78
- editorClassName: className,
79
- placeholder: placeholder
80
50
  });
81
51
  };
82
52
  var FormElementsEdit = exports["default"] = /*#__PURE__*/function (_React$Component) {
@@ -5,22 +5,10 @@ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.DraftJs = void 0;
9
- Object.defineProperty(exports, "Editor", {
10
- enumerable: true,
11
- get: function get() {
12
- return _reactDraftWysiwyg.Editor;
13
- }
14
- });
15
- exports.generateUUID = exports.draftToHtml = exports.TextAreaAutosize = void 0;
8
+ exports.generateUUID = exports.TextAreaAutosize = void 0;
16
9
  exports.groupBy = groupBy;
17
10
  var _react = _interopRequireDefault(require("react"));
18
11
  var PkgTextAreaAutosize = _interopRequireWildcard(require("react-textarea-autosize"));
19
- var DraftJs = _interopRequireWildcard(require("draft-js"));
20
- exports.DraftJs = DraftJs;
21
- var draftToHtml = _interopRequireWildcard(require("draftjs-to-html"));
22
- exports.draftToHtml = draftToHtml;
23
- var _reactDraftWysiwyg = require("react-draft-wysiwyg");
24
12
  var _UUID = _interopRequireDefault(require("../UUID"));
25
13
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
26
14
  var generateUUID = exports.generateUUID = function generateUUID() {
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.MIN_READABLE_CONTRAST = exports.CANVAS_BACKGROUND = exports.BACKING_COLOR = void 0;
8
+ exports.backHardToReadText = backHardToReadText;
9
+ exports.canvasHtml = canvasHtml;
10
+ exports.contrastRatio = contrastRatio;
11
+ exports.parseCssColorToRgb = parseCssColorToRgb;
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
14
+ // A LABEL THE OPERATOR COLOURED WHITE MUST STILL BE READABLE ON THE BUILDER CANVAS (2.0.1).
15
+ //
16
+ // The canvas draws every field's saved label / header / paragraph on a white card, so text the
17
+ // operator coloured white (for a dark page) is a blank row in the builder. `canvasHtml` draws
18
+ // such text on a dark backing — ON THE CANVAS ONLY.
19
+ //
20
+ // "Only" is the load-bearing word. The same element classes render the GENERATED form
21
+ // (ReactFormGenerator), which hosts show to their own users on their own background; a backing
22
+ // there would be a dark chip on every user's form. The canvas renders elements with
23
+ // `mutable={false}`, the generator with `mutable={true}`: the backing is applied on a literal
24
+ // `false`, so any other caller gets its HTML back untouched.
25
+ //
26
+ // The backing is added to the HTML handed to React for display. It is never written to the
27
+ // element's data, so it is never saved.
28
+ //
29
+ // The three numbers below match the SQWAD tenant admin's rich-text editor
30
+ // (src/components/utils/lightTextColor.js there), so a label looks the same in the editor and on
31
+ // the canvas. Nothing breaks if they drift; the two would only stop matching.
32
+
33
+ var CANVAS_BACKGROUND = exports.CANVAS_BACKGROUND = '#ffffff';
34
+ var BACKING_COLOR = exports.BACKING_COLOR = '#2a2a2a';
35
+ var MIN_READABLE_CONTRAST = exports.MIN_READABLE_CONTRAST = 3;
36
+ var BACKING_ATTRIBUTE = 'data-rfb-contrast-backing';
37
+ var BACKING_TITLE = 'Shown on a dark backing so you can read it here. Your form shows this text on its own background.';
38
+ var WHITE = [255, 255, 255];
39
+ var NAMED = {
40
+ black: [0, 0, 0],
41
+ white: WHITE,
42
+ snow: WHITE,
43
+ ivory: WHITE,
44
+ ghostwhite: WHITE,
45
+ whitesmoke: WHITE,
46
+ floralwhite: WHITE,
47
+ mintcream: WHITE,
48
+ azure: WHITE,
49
+ aliceblue: WHITE,
50
+ seashell: WHITE,
51
+ honeydew: WHITE,
52
+ lightyellow: WHITE,
53
+ lightcyan: WHITE,
54
+ lavenderblush: WHITE,
55
+ oldlace: WHITE,
56
+ linen: WHITE,
57
+ cornsilk: WHITE,
58
+ beige: WHITE
59
+ };
60
+ var channel = function channel(token) {
61
+ var n = parseFloat(token);
62
+ if (!Number.isFinite(n)) return null;
63
+ return token.trim().endsWith('%') ? n / 100 * 255 : n;
64
+ };
65
+ var hslToRgb = function hslToRgb(h, s, l) {
66
+ var hue = (h % 360 + 360) % 360 / 360;
67
+ if (s === 0) return [l, l, l].map(function (v) {
68
+ return Math.round(v * 255);
69
+ });
70
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
71
+ var p = 2 * l - q;
72
+ var part = function part(t) {
73
+ var x = t;
74
+ if (x < 0) x += 1;
75
+ if (x > 1) x -= 1;
76
+ if (x < 1 / 6) return p + (q - p) * 6 * x;
77
+ if (x < 1 / 2) return q;
78
+ if (x < 2 / 3) return p + (q - p) * (2 / 3 - x) * 6;
79
+ return p;
80
+ };
81
+ return [part(hue + 1 / 3), part(hue), part(hue - 1 / 3)].map(function (v) {
82
+ return Math.round(v * 255);
83
+ });
84
+ };
85
+ function parseCssColorToRgb(value) {
86
+ if (typeof value !== 'string') return null;
87
+ var v = value.trim().toLowerCase();
88
+ if (!v) return null;
89
+ if (NAMED[v]) return (0, _toConsumableArray2["default"])(NAMED[v]);
90
+ var hex = /^#([0-9a-f]{3,8})$/.exec(v);
91
+ if (hex) {
92
+ var h = hex[1];
93
+ if (h.length === 3 || h.length === 4) return [0, 1, 2].map(function (i) {
94
+ return parseInt(h[i] + h[i], 16);
95
+ });
96
+ if (h.length === 6 || h.length === 8) return [0, 2, 4].map(function (i) {
97
+ return parseInt(h.slice(i, i + 2), 16);
98
+ });
99
+ return null;
100
+ }
101
+ var rgb = /^rgba?\(([^)]*)\)$/.exec(v);
102
+ if (rgb) {
103
+ var parts = rgb[1].split(/[\s,/]+/).filter(Boolean);
104
+ if (parts.length < 3) return null;
105
+ var channels = parts.slice(0, 3).map(channel);
106
+ return channels.some(function (c) {
107
+ return c === null;
108
+ }) ? null : channels;
109
+ }
110
+ var hsl = /^hsla?\(([^)]*)\)$/.exec(v);
111
+ if (hsl) {
112
+ var _parts = hsl[1].split(/[\s,/]+/).filter(Boolean);
113
+ if (_parts.length < 3) return null;
114
+ var _h = parseFloat(_parts[0]);
115
+ var s = parseFloat(_parts[1]);
116
+ var l = parseFloat(_parts[2]);
117
+ if (![_h, s, l].every(Number.isFinite)) return null;
118
+ return hslToRgb(_h, Math.min(100, Math.max(0, s)) / 100, Math.min(100, Math.max(0, l)) / 100);
119
+ }
120
+ return null;
121
+ }
122
+ var relativeLuminance = function relativeLuminance(rgb) {
123
+ var _rgb$map = rgb.map(function (c) {
124
+ var x = Math.min(255, Math.max(0, c)) / 255;
125
+ return x <= 0.03928 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
126
+ }),
127
+ _rgb$map2 = (0, _slicedToArray2["default"])(_rgb$map, 3),
128
+ r = _rgb$map2[0],
129
+ g = _rgb$map2[1],
130
+ b = _rgb$map2[2];
131
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
132
+ };
133
+
134
+ // WCAG contrast ratio of two CSS colours, 1–21. null when either cannot be read.
135
+ function contrastRatio(a, b) {
136
+ var ra = parseCssColorToRgb(a);
137
+ var rb = parseCssColorToRgb(b);
138
+ if (!ra || !rb) return null;
139
+ var la = relativeLuminance(ra);
140
+ var lb = relativeLuminance(rb);
141
+ return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
142
+ }
143
+
144
+ // The colour an inline `style` attribute sets, as written. Read from the attribute text rather
145
+ // than `element.style`, which not every DOM implementation fills for every colour form.
146
+ var inlineDeclaration = function inlineDeclaration(el, property) {
147
+ var style = el.getAttribute && el.getAttribute('style');
148
+ if (!style) return null;
149
+ var found = null;
150
+ style.split(';').forEach(function (declaration) {
151
+ var at = declaration.indexOf(':');
152
+ if (at === -1) return;
153
+ if (declaration.slice(0, at).trim().toLowerCase() === property) found = declaration.slice(at + 1).trim();
154
+ });
155
+ return found;
156
+ };
157
+ var hasOwnBackground = function hasOwnBackground(el) {
158
+ return !!(inlineDeclaration(el, 'background-color') || inlineDeclaration(el, 'background'));
159
+ };
160
+
161
+ // Returns `html` with a dark backing on every element whose own inline text colour is hard to
162
+ // read on the white canvas. Returns the SAME string when nothing needs one (the ordinary case),
163
+ // and whenever it cannot parse — it never throws and never drops content.
164
+ function backHardToReadText(html) {
165
+ if (typeof html !== 'string' || !html || html.indexOf('color') === -1) return html;
166
+ // No DOM (a server render): nothing to draw on, and the canvas never renders there.
167
+ if (typeof window === 'undefined' || typeof window.DOMParser === 'undefined') return html;
168
+ var body;
169
+ try {
170
+ // An inert document: nothing in it loads or runs.
171
+ body = new window.DOMParser().parseFromString("<!doctype html><body>".concat(html), 'text/html').body;
172
+ } catch (e) {
173
+ return html;
174
+ }
175
+ if (!body) return html;
176
+ var changed = false;
177
+ body.querySelectorAll('[style]').forEach(function (el) {
178
+ var color = inlineDeclaration(el, 'color');
179
+ if (!color) return;
180
+ var ratio = contrastRatio(color, CANVAS_BACKGROUND);
181
+ // A colour we cannot read is left alone: a backing drawn on a guess is noise.
182
+ if (ratio === null || ratio >= MIN_READABLE_CONTRAST) return;
183
+ // Text that already carries a background — its own or an ancestor's — is the operator's design.
184
+ for (var node = el; node && node !== body; node = node.parentElement) {
185
+ if (hasOwnBackground(node)) return;
186
+ }
187
+ var style = (el.getAttribute('style') || '').trim().replace(/;$/, '');
188
+ el.setAttribute('style', "".concat(style, "; background-color: ").concat(BACKING_COLOR, "; border-radius: 3px; box-shadow: 0 0 0 2px ").concat(BACKING_COLOR, ";"));
189
+ el.setAttribute(BACKING_ATTRIBUTE, 'dark');
190
+ el.setAttribute('title', BACKING_TITLE);
191
+ changed = true;
192
+ });
193
+ return changed ? body.innerHTML : html;
194
+ }
195
+
196
+ // What an element draws for a piece of saved HTML: backed on the builder canvas
197
+ // (`mutable === false`), untouched everywhere else.
198
+ function canvasHtml(props, html) {
199
+ return props && props.mutable === false ? backHardToReadText(html) : html;
200
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-form-builder-more-flexibility",
3
- "version": "1.0.77",
3
+ "version": "2.0.1",
4
4
  "description": "A complete form builder for react.",
5
5
  "main": "lib/index.js",
6
6
  "types": "types/index.d.ts",
@@ -31,8 +31,6 @@
31
31
  "beedle": "^0.8.1",
32
32
  "classnames": "^2.2.6",
33
33
  "date-fns": "^2.16.1",
34
- "draft-js": "^0.11.7",
35
- "draftjs-to-html": "^0.9.1",
36
34
  "es6-promise": "^4.2.8",
37
35
  "fbemitter": "^3.0.0",
38
36
  "file-saver": "^2.0.5",
@@ -43,7 +41,6 @@
43
41
  "react-bootstrap-slider": "^3.0.0",
44
42
  "react-dnd": "^16.0.1",
45
43
  "react-dnd-html5-backend": "^16.0.1",
46
- "react-draft-wysiwyg": "^1.15.0",
47
44
  "react-intl": "^7.1.11",
48
45
  "react-select": "^5.10.1",
49
46
  "react-signature-canvas": "^1.1.0-alpha.2",