hadron-document 7.6.0 → 7.9.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/.depcheckrc +0 -2
- package/index.d.ts +192 -0
- package/lib/document.js +122 -55
- package/lib/editor/date.js +151 -0
- package/lib/editor/decimal128.js +88 -0
- package/lib/editor/double.js +113 -0
- package/lib/editor/index.js +50 -0
- package/lib/editor/int32.js +68 -0
- package/lib/editor/int64.js +88 -0
- package/lib/editor/null.js +81 -0
- package/lib/editor/objectid.js +98 -0
- package/lib/editor/standard.js +108 -0
- package/lib/editor/string.js +48 -0
- package/lib/editor/undefined.js +81 -0
- package/lib/element-events.js +15 -0
- package/lib/element.js +156 -85
- package/lib/index.js +4 -1
- package/lib/object-generator.js +1 -1
- package/lib/utils.js +10 -0
- package/package.json +4 -5
- package/src/document.js +44 -3
- package/src/editor/date.js +95 -0
- package/src/editor/decimal128.js +46 -0
- package/src/editor/double.js +70 -0
- package/src/editor/index.js +40 -0
- package/src/editor/int32.js +29 -0
- package/src/editor/int64.js +46 -0
- package/src/editor/null.js +42 -0
- package/src/editor/objectid.js +54 -0
- package/src/editor/standard.js +78 -0
- package/src/editor/string.js +20 -0
- package/src/editor/undefined.js +42 -0
- package/src/element-events.js +14 -0
- package/src/element.js +90 -39
- package/src/index.js +3 -0
- package/src/utils.js +6 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
|
+
|
|
7
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
8
|
+
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
|
|
11
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
12
|
+
|
|
13
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
14
|
+
|
|
15
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
16
|
+
|
|
17
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
18
|
+
|
|
19
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
20
|
+
|
|
21
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
22
|
+
|
|
23
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
24
|
+
|
|
25
|
+
var TypeChecker = require('hadron-type-checker');
|
|
26
|
+
|
|
27
|
+
var Events = require('../element-events');
|
|
28
|
+
|
|
29
|
+
var _require = require('../utils'),
|
|
30
|
+
fieldStringLen = _require.fieldStringLen;
|
|
31
|
+
|
|
32
|
+
var StandardEditor = require('./standard');
|
|
33
|
+
/**
|
|
34
|
+
* CRUD editor for date values.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
var DateEditor = /*#__PURE__*/function (_StandardEditor) {
|
|
39
|
+
_inherits(DateEditor, _StandardEditor);
|
|
40
|
+
|
|
41
|
+
var _super = _createSuper(DateEditor);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Create the editor with the element.
|
|
45
|
+
*
|
|
46
|
+
* @param {Element} element - The hadron document element.
|
|
47
|
+
*/
|
|
48
|
+
function DateEditor(element) {
|
|
49
|
+
_classCallCheck(this, DateEditor);
|
|
50
|
+
|
|
51
|
+
return _super.call(this, element);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Complete the date edit by converting the valid string to a date
|
|
55
|
+
* object or leaving as invalid.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
_createClass(DateEditor, [{
|
|
60
|
+
key: "complete",
|
|
61
|
+
value: function complete() {
|
|
62
|
+
if (this.element.isCurrentTypeValid()) {
|
|
63
|
+
this.element.edit(TypeChecker.cast(this._formattedValue(), 'Date'));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Edit the element with the provided value.
|
|
68
|
+
*
|
|
69
|
+
* @param {Object} value - The new value.
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
}, {
|
|
73
|
+
key: "edit",
|
|
74
|
+
value: function edit(value) {
|
|
75
|
+
try {
|
|
76
|
+
var date = TypeChecker.cast(value, 'Date');
|
|
77
|
+
|
|
78
|
+
if (date.toString() === 'Invalid Date') {
|
|
79
|
+
this.element.setInvalid(value, 'Date', "".concat(value, " is not in a valid date format"));
|
|
80
|
+
} else {
|
|
81
|
+
this.element.currentValue = value;
|
|
82
|
+
this.element.setValid();
|
|
83
|
+
|
|
84
|
+
this.element._bubbleUp(Events.Edited, this.element);
|
|
85
|
+
}
|
|
86
|
+
} catch (e) {
|
|
87
|
+
this.element.setInvalid(value, this.element.currentType, e.message);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the number of characters the value should display.
|
|
92
|
+
*
|
|
93
|
+
* @param {Boolean} editMode - If the element is being edited.
|
|
94
|
+
*
|
|
95
|
+
* @returns {Number} The number of characters.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
}, {
|
|
99
|
+
key: "size",
|
|
100
|
+
value: function size(editMode) {
|
|
101
|
+
var value = this.element.currentValue;
|
|
102
|
+
|
|
103
|
+
if (editMode) {
|
|
104
|
+
return fieldStringLen(value);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return this.element.isCurrentTypeValid() ? fieldStringLen(this._formattedValue()) : fieldStringLen(value);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Start the date edit.
|
|
111
|
+
*
|
|
112
|
+
* @param {Object} value - The value in the field.
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
}, {
|
|
116
|
+
key: "start",
|
|
117
|
+
value: function start() {
|
|
118
|
+
if (this.element.isCurrentTypeValid()) {
|
|
119
|
+
this.edit(this._formattedValue());
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get the value being edited.
|
|
124
|
+
*
|
|
125
|
+
* @param {Boolean} editMode - If the UI is in edit mode.
|
|
126
|
+
*
|
|
127
|
+
* @returns {String} The value.
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
}, {
|
|
131
|
+
key: "value",
|
|
132
|
+
value: function value(editMode) {
|
|
133
|
+
var value = this.element.currentValue;
|
|
134
|
+
|
|
135
|
+
if (!editMode && this.element.isCurrentTypeValid()) {
|
|
136
|
+
return this._formattedValue();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return value;
|
|
140
|
+
}
|
|
141
|
+
}, {
|
|
142
|
+
key: "_formattedValue",
|
|
143
|
+
value: function _formattedValue() {
|
|
144
|
+
return new Date(this.element.currentValue).toISOString().replace('Z', '+00:00');
|
|
145
|
+
}
|
|
146
|
+
}]);
|
|
147
|
+
|
|
148
|
+
return DateEditor;
|
|
149
|
+
}(StandardEditor);
|
|
150
|
+
|
|
151
|
+
module.exports = DateEditor;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
|
+
|
|
7
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
8
|
+
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
|
|
11
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
12
|
+
|
|
13
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
14
|
+
|
|
15
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
16
|
+
|
|
17
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
18
|
+
|
|
19
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
20
|
+
|
|
21
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
22
|
+
|
|
23
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
24
|
+
|
|
25
|
+
var TypeChecker = require('hadron-type-checker');
|
|
26
|
+
|
|
27
|
+
var Events = require('../element-events');
|
|
28
|
+
|
|
29
|
+
var StandardEditor = require('./standard');
|
|
30
|
+
/**
|
|
31
|
+
* CRUD editor for decimal128 values.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
var Decimal128Editor = /*#__PURE__*/function (_StandardEditor) {
|
|
36
|
+
_inherits(Decimal128Editor, _StandardEditor);
|
|
37
|
+
|
|
38
|
+
var _super = _createSuper(Decimal128Editor);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Create the editor with the element.
|
|
42
|
+
*
|
|
43
|
+
* @param {Element} element - The hadron document element.
|
|
44
|
+
*/
|
|
45
|
+
function Decimal128Editor(element) {
|
|
46
|
+
_classCallCheck(this, Decimal128Editor);
|
|
47
|
+
|
|
48
|
+
return _super.call(this, element);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Complete the decimal128 edit by converting the valid string to a decimal128
|
|
52
|
+
* value or leaving as invalid.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
_createClass(Decimal128Editor, [{
|
|
57
|
+
key: "complete",
|
|
58
|
+
value: function complete() {
|
|
59
|
+
if (this.element.isCurrentTypeValid()) {
|
|
60
|
+
this.element.edit(TypeChecker.cast(this.element.currentValue, 'Decimal128'));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Edit Decimal128 element. Check if the value is a Decimal128 before setting typed
|
|
65
|
+
* up value.
|
|
66
|
+
*
|
|
67
|
+
* @param {Object} value - The new value.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
}, {
|
|
71
|
+
key: "edit",
|
|
72
|
+
value: function edit(value) {
|
|
73
|
+
try {
|
|
74
|
+
TypeChecker.cast(value, 'Decimal128');
|
|
75
|
+
this.element.currentValue = value;
|
|
76
|
+
this.element.setValid();
|
|
77
|
+
|
|
78
|
+
this.element._bubbleUp(Events.Edited, this.element);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
this.element.setInvalid(value, this.element.currentType, error.message);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}]);
|
|
84
|
+
|
|
85
|
+
return Decimal128Editor;
|
|
86
|
+
}(StandardEditor);
|
|
87
|
+
|
|
88
|
+
module.exports = Decimal128Editor;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
|
+
|
|
7
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
8
|
+
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
|
|
11
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
12
|
+
|
|
13
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
14
|
+
|
|
15
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
16
|
+
|
|
17
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
18
|
+
|
|
19
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
20
|
+
|
|
21
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
22
|
+
|
|
23
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
24
|
+
|
|
25
|
+
var TypeChecker = require('hadron-type-checker');
|
|
26
|
+
|
|
27
|
+
var Events = require('../element-events');
|
|
28
|
+
|
|
29
|
+
var _require = require('../utils'),
|
|
30
|
+
fieldStringLen = _require.fieldStringLen;
|
|
31
|
+
|
|
32
|
+
var StandardEditor = require('./standard');
|
|
33
|
+
/**
|
|
34
|
+
* CRUD editor for double values.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
var DoubleEditor = /*#__PURE__*/function (_StandardEditor) {
|
|
39
|
+
_inherits(DoubleEditor, _StandardEditor);
|
|
40
|
+
|
|
41
|
+
var _super = _createSuper(DoubleEditor);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Create the editor with the element.
|
|
45
|
+
*
|
|
46
|
+
* @param {Element} element - The hadron document element.
|
|
47
|
+
*/
|
|
48
|
+
function DoubleEditor(element) {
|
|
49
|
+
_classCallCheck(this, DoubleEditor);
|
|
50
|
+
|
|
51
|
+
return _super.call(this, element);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Complete the double edit by converting the valid string to a double
|
|
55
|
+
* value or leaving as invalid.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
_createClass(DoubleEditor, [{
|
|
60
|
+
key: "complete",
|
|
61
|
+
value: function complete() {
|
|
62
|
+
if (this.element.isCurrentTypeValid()) {
|
|
63
|
+
this.element.edit(TypeChecker.cast(this.element.currentValue, 'Double'));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Edit Double element. Check if the value is a Double before setting tped
|
|
68
|
+
* up value.
|
|
69
|
+
*
|
|
70
|
+
* @param {Object} value - The new value.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
}, {
|
|
74
|
+
key: "edit",
|
|
75
|
+
value: function edit(value) {
|
|
76
|
+
try {
|
|
77
|
+
var _double = TypeChecker.cast(value, 'Double');
|
|
78
|
+
|
|
79
|
+
if (isNaN(_double.value)) {
|
|
80
|
+
this.element.setInvalid(value, 'Double', "".concat(value, " is not a valid double format"));
|
|
81
|
+
} else {
|
|
82
|
+
this.element.currentValue = value;
|
|
83
|
+
this.element.setValid();
|
|
84
|
+
|
|
85
|
+
this.element._bubbleUp(Events.Edited, this.element);
|
|
86
|
+
}
|
|
87
|
+
} catch (error) {
|
|
88
|
+
this.element.setInvalid(value, this.element.currentType, error.message);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get the number of characters the value should display.
|
|
93
|
+
*
|
|
94
|
+
* @param {Boolean} editMode - If the element is being edited.
|
|
95
|
+
*
|
|
96
|
+
* @returns {Number} The number of characters.
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
}, {
|
|
100
|
+
key: "size",
|
|
101
|
+
value: function size() {
|
|
102
|
+
var currentValue = this.element.currentValue;
|
|
103
|
+
return fieldStringLen( // Not all values that will be checked here are bson types with a `value`
|
|
104
|
+
// property, using valueOf is a more resilient way of getting the "native"
|
|
105
|
+
// value from `currentValue`
|
|
106
|
+
typeof currentValue.valueOf === 'function' ? currentValue.valueOf() : currentValue);
|
|
107
|
+
}
|
|
108
|
+
}]);
|
|
109
|
+
|
|
110
|
+
return DoubleEditor;
|
|
111
|
+
}(StandardEditor);
|
|
112
|
+
|
|
113
|
+
module.exports = DoubleEditor;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var StandardEditor = require('./standard');
|
|
4
|
+
|
|
5
|
+
var StringEditor = require('./string');
|
|
6
|
+
|
|
7
|
+
var Decimal128Editor = require('./decimal128');
|
|
8
|
+
|
|
9
|
+
var Int32Editor = require('./int32');
|
|
10
|
+
|
|
11
|
+
var Int64Editor = require('./int64');
|
|
12
|
+
|
|
13
|
+
var DoubleEditor = require('./double');
|
|
14
|
+
|
|
15
|
+
var DateEditor = require('./date');
|
|
16
|
+
|
|
17
|
+
var NullEditor = require('./null');
|
|
18
|
+
|
|
19
|
+
var UndefinedEditor = require('./undefined');
|
|
20
|
+
|
|
21
|
+
var ObjectIdEditor = require('./objectid');
|
|
22
|
+
|
|
23
|
+
var init = function init(element) {
|
|
24
|
+
return {
|
|
25
|
+
Standard: new StandardEditor(element),
|
|
26
|
+
String: new StringEditor(element),
|
|
27
|
+
Decimal128: new Decimal128Editor(element),
|
|
28
|
+
Date: new DateEditor(element),
|
|
29
|
+
Double: new DoubleEditor(element),
|
|
30
|
+
Int32: new Int32Editor(element),
|
|
31
|
+
Int64: new Int64Editor(element),
|
|
32
|
+
Null: new NullEditor(element),
|
|
33
|
+
Undefined: new UndefinedEditor(element),
|
|
34
|
+
ObjectId: new ObjectIdEditor(element)
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
Object.assign(init, {
|
|
39
|
+
DateEditor: DateEditor,
|
|
40
|
+
StandardEditor: StandardEditor,
|
|
41
|
+
StringEditor: StringEditor,
|
|
42
|
+
Decimal128Editor: Decimal128Editor,
|
|
43
|
+
DoubleEditor: DoubleEditor,
|
|
44
|
+
Int32Editor: Int32Editor,
|
|
45
|
+
Int64Editor: Int64Editor,
|
|
46
|
+
NullEditor: NullEditor,
|
|
47
|
+
UndefinedEditor: UndefinedEditor,
|
|
48
|
+
ObjectIdEditor: ObjectIdEditor
|
|
49
|
+
});
|
|
50
|
+
module.exports = init;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
|
+
|
|
7
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
8
|
+
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
|
|
11
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
12
|
+
|
|
13
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
14
|
+
|
|
15
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
16
|
+
|
|
17
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
18
|
+
|
|
19
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
20
|
+
|
|
21
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
22
|
+
|
|
23
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
24
|
+
|
|
25
|
+
var _require = require('../utils'),
|
|
26
|
+
fieldStringLen = _require.fieldStringLen;
|
|
27
|
+
|
|
28
|
+
var StandardEditor = require('./standard');
|
|
29
|
+
/**
|
|
30
|
+
* CRUD editor for int32 values.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
var Int32Editor = /*#__PURE__*/function (_StandardEditor) {
|
|
35
|
+
_inherits(Int32Editor, _StandardEditor);
|
|
36
|
+
|
|
37
|
+
var _super = _createSuper(Int32Editor);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Create the editor with the element.
|
|
41
|
+
*
|
|
42
|
+
* @param {Element} element - The hadron document element.
|
|
43
|
+
*/
|
|
44
|
+
function Int32Editor(element) {
|
|
45
|
+
_classCallCheck(this, Int32Editor);
|
|
46
|
+
|
|
47
|
+
return _super.call(this, element);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get the number of characters the value should display.
|
|
51
|
+
*
|
|
52
|
+
* @param {Boolean} editMode - If the element is being edited.
|
|
53
|
+
*
|
|
54
|
+
* @returns {Number} The number of characters.
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
_createClass(Int32Editor, [{
|
|
59
|
+
key: "size",
|
|
60
|
+
value: function size() {
|
|
61
|
+
return fieldStringLen(this.element.currentValue.valueOf());
|
|
62
|
+
}
|
|
63
|
+
}]);
|
|
64
|
+
|
|
65
|
+
return Int32Editor;
|
|
66
|
+
}(StandardEditor);
|
|
67
|
+
|
|
68
|
+
module.exports = Int32Editor;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
|
+
|
|
7
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
8
|
+
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
|
|
11
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
12
|
+
|
|
13
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
14
|
+
|
|
15
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
16
|
+
|
|
17
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
18
|
+
|
|
19
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
20
|
+
|
|
21
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
22
|
+
|
|
23
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
24
|
+
|
|
25
|
+
var TypeChecker = require('hadron-type-checker');
|
|
26
|
+
|
|
27
|
+
var Events = require('../element-events');
|
|
28
|
+
|
|
29
|
+
var StandardEditor = require('./standard');
|
|
30
|
+
/**
|
|
31
|
+
* CRUD editor for int32 values.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
var Int64Editor = /*#__PURE__*/function (_StandardEditor) {
|
|
36
|
+
_inherits(Int64Editor, _StandardEditor);
|
|
37
|
+
|
|
38
|
+
var _super = _createSuper(Int64Editor);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Create the editor with the element.
|
|
42
|
+
*
|
|
43
|
+
* @param {Element} element - The hadron document element.
|
|
44
|
+
*/
|
|
45
|
+
function Int64Editor(element) {
|
|
46
|
+
_classCallCheck(this, Int64Editor);
|
|
47
|
+
|
|
48
|
+
return _super.call(this, element);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Complete the int64 edit by converting the valid string to a int64
|
|
52
|
+
* value or leaving as invalid.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
_createClass(Int64Editor, [{
|
|
57
|
+
key: "complete",
|
|
58
|
+
value: function complete() {
|
|
59
|
+
if (this.element.isCurrentTypeValid()) {
|
|
60
|
+
this.element.edit(TypeChecker.cast(this.element.currentValue, 'Int64'));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Edit Int64 element. Check if the value is a Int64 before setting typed
|
|
65
|
+
* up value.
|
|
66
|
+
*
|
|
67
|
+
* @param {Object} value - The new value.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
}, {
|
|
71
|
+
key: "edit",
|
|
72
|
+
value: function edit(value) {
|
|
73
|
+
try {
|
|
74
|
+
TypeChecker.cast(value, 'Int64');
|
|
75
|
+
this.element.currentValue = value;
|
|
76
|
+
this.element.setValid();
|
|
77
|
+
|
|
78
|
+
this.element._bubbleUp(Events.Edited, this.element);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
this.element.setInvalid(value, this.element.currentType, error.message);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}]);
|
|
84
|
+
|
|
85
|
+
return Int64Editor;
|
|
86
|
+
}(StandardEditor);
|
|
87
|
+
|
|
88
|
+
module.exports = Int64Editor;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
|
+
|
|
7
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
8
|
+
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
|
|
11
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
12
|
+
|
|
13
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
14
|
+
|
|
15
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
16
|
+
|
|
17
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
18
|
+
|
|
19
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
20
|
+
|
|
21
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
22
|
+
|
|
23
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
24
|
+
|
|
25
|
+
var StandardEditor = require('./standard');
|
|
26
|
+
/**
|
|
27
|
+
* Null is always 'null'
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
var VALUE = 'null';
|
|
32
|
+
/**
|
|
33
|
+
* CRUD editor for null values.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
var NullEditor = /*#__PURE__*/function (_StandardEditor) {
|
|
37
|
+
_inherits(NullEditor, _StandardEditor);
|
|
38
|
+
|
|
39
|
+
var _super = _createSuper(NullEditor);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Create the editor with the element.
|
|
43
|
+
*
|
|
44
|
+
* @param {Element} element - The hadron document element.
|
|
45
|
+
*/
|
|
46
|
+
function NullEditor(element) {
|
|
47
|
+
_classCallCheck(this, NullEditor);
|
|
48
|
+
|
|
49
|
+
return _super.call(this, element);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the number of characters the value should display.
|
|
53
|
+
*
|
|
54
|
+
* @param {Boolean} editMode - If the element is being edited.
|
|
55
|
+
*
|
|
56
|
+
* @returns {Number} The number of characters.
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
_createClass(NullEditor, [{
|
|
61
|
+
key: "size",
|
|
62
|
+
value: function size() {
|
|
63
|
+
return 4;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get the value being edited.
|
|
67
|
+
*
|
|
68
|
+
* @returns {Object} The value.
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
}, {
|
|
72
|
+
key: "value",
|
|
73
|
+
value: function value() {
|
|
74
|
+
return VALUE;
|
|
75
|
+
}
|
|
76
|
+
}]);
|
|
77
|
+
|
|
78
|
+
return NullEditor;
|
|
79
|
+
}(StandardEditor);
|
|
80
|
+
|
|
81
|
+
module.exports = NullEditor;
|