@dhis2/analytics 26.2.0-cumulative-values-alpha.1 → 26.2.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/package.json +1 -1
- package/build/cjs/api/analytics/__tests__/AnalyticsTrackedEntities.spec.js +0 -44
- package/build/cjs/api/analytics/__tests__/__snapshots__/AnalyticsTrackedEntities.spec.js.snap +0 -3
- package/build/cjs/components/RichText/Editor.bk/Editor.js +0 -40
- package/build/cjs/components/RichText/Editor.bk/__tests__/Editor.spec.js +0 -29
- package/build/cjs/components/RichText/Editor.bk/__tests__/convertCtrlKey.spec.js +0 -205
- package/build/cjs/components/RichText/Editor.bk/convertCtrlKey.js +0 -87
- package/build/cjs/components/RichText/Parser.bk/MdParser.js +0 -107
- package/build/cjs/components/RichText/Parser.bk/Parser.js +0 -34
- package/build/cjs/components/RichText/Parser.bk/__tests__/MdParser.spec.js +0 -34
- package/build/cjs/components/RichText/Parser.bk/__tests__/Parser.spec.js +0 -41
- package/build/cjs/visualizations/config/generators/dhis/singleValue.js.xp1 +0 -478
- package/build/es/api/analytics/__tests__/AnalyticsTrackedEntities.spec.js +0 -41
- package/build/es/api/analytics/__tests__/__snapshots__/AnalyticsTrackedEntities.spec.js.snap +0 -3
- package/build/es/components/RichText/Editor.bk/Editor.js +0 -30
- package/build/es/components/RichText/Editor.bk/__tests__/Editor.spec.js +0 -26
- package/build/es/components/RichText/Editor.bk/__tests__/convertCtrlKey.spec.js +0 -202
- package/build/es/components/RichText/Editor.bk/convertCtrlKey.js +0 -80
- package/build/es/components/RichText/Parser.bk/MdParser.js +0 -99
- package/build/es/components/RichText/Parser.bk/Parser.js +0 -24
- package/build/es/components/RichText/Parser.bk/__tests__/MdParser.spec.js +0 -31
- package/build/es/components/RichText/Parser.bk/__tests__/Parser.spec.js +0 -38
- package/build/es/visualizations/config/generators/dhis/singleValue.js.xp1 +0 -478
package/package.json
CHANGED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _fixtures = _interopRequireDefault(require("../../../__fixtures__/fixtures.js"));
|
|
4
|
-
var _DataEngine = _interopRequireDefault(require("../__mocks__/DataEngine.js"));
|
|
5
|
-
var _AnalyticsRequest = _interopRequireDefault(require("../AnalyticsRequest.js"));
|
|
6
|
-
var _AnalyticsTrackedEntities = _interopRequireDefault(require("../AnalyticsTrackedEntities.js"));
|
|
7
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
-
describe.skip('analytics.trackedEntity', () => {
|
|
9
|
-
let enrollments;
|
|
10
|
-
let request;
|
|
11
|
-
let dataEngineMock;
|
|
12
|
-
let fixture;
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
dataEngineMock = new _DataEngine.default();
|
|
15
|
-
_DataEngine.default.mockClear();
|
|
16
|
-
enrollments = new _AnalyticsTrackedEntities.default();
|
|
17
|
-
});
|
|
18
|
-
it('should not be allowed to be called without new', () => {
|
|
19
|
-
expect(() => (0, _AnalyticsTrackedEntities.default)()).toThrowErrorMatchingSnapshot();
|
|
20
|
-
});
|
|
21
|
-
it('should use the dataEngine object when it is passed', () => {
|
|
22
|
-
const dataEngineMockObject = {};
|
|
23
|
-
enrollments = new _AnalyticsTrackedEntities.default(dataEngineMockObject);
|
|
24
|
-
expect(enrollments.dataEngine).toBe(dataEngineMockObject);
|
|
25
|
-
});
|
|
26
|
-
describe('.getQuery()', () => {
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
enrollments = new _AnalyticsTrackedEntities.default(new _DataEngine.default());
|
|
29
|
-
request = new _AnalyticsRequest.default().addOrgUnitDimension('ImspTQPwCqd').addDimension('WZbXY0S00lP.de0FEHSIoxh').addDimension('WZbXY0S00lP.sWoqcoByYmD').addPeriodFilter('LAST_MONTH').withTrackedEntity('nEenWmSyUEp').withAsc('ENROLLMENTDATE').withOuMode('DESCENDANTS').withColumns('w75KJ2mc4zz').withPage(1).withPageSize(10);
|
|
30
|
-
fixture = _fixtures.default.get('/api/analytics/enrollments'); // XXX
|
|
31
|
-
|
|
32
|
-
dataEngineMock.query.mockReturnValue(Promise.resolve({
|
|
33
|
-
data: fixture
|
|
34
|
-
}));
|
|
35
|
-
});
|
|
36
|
-
it('should be a function', () => {
|
|
37
|
-
expect(enrollments.getQuery).toBeInstanceOf(Function);
|
|
38
|
-
});
|
|
39
|
-
it('should resolve a promise with data', () => enrollments.getQuery(request).then(data => {
|
|
40
|
-
expect(data.width).toEqual(fixture.width);
|
|
41
|
-
expect(data.height).toEqual(fixture.height);
|
|
42
|
-
}));
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
var _convertCtrlKey = _interopRequireDefault(require("./convertCtrlKey.js"));
|
|
10
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
15
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
16
|
-
class Editor extends _react.Component {
|
|
17
|
-
constructor() {
|
|
18
|
-
super(...arguments);
|
|
19
|
-
_defineProperty(this, "onKeyDown", event => {
|
|
20
|
-
(0, _convertCtrlKey.default)(event, this.props.onEdit);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
render() {
|
|
24
|
-
const {
|
|
25
|
-
children
|
|
26
|
-
} = this.props;
|
|
27
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
28
|
-
onKeyDown: this.onKeyDown
|
|
29
|
-
}, children);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
Editor.defaultProps = {
|
|
33
|
-
onEdit: null
|
|
34
|
-
};
|
|
35
|
-
Editor.propTypes = {
|
|
36
|
-
children: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.node), _propTypes.default.node]),
|
|
37
|
-
onEdit: _propTypes.default.func
|
|
38
|
-
};
|
|
39
|
-
var _default = Editor;
|
|
40
|
-
exports.default = _default;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _enzyme = require("enzyme");
|
|
4
|
-
var _react = _interopRequireDefault(require("react"));
|
|
5
|
-
var _convertCtrlKey = _interopRequireDefault(require("../convertCtrlKey.js"));
|
|
6
|
-
var _Editor = _interopRequireDefault(require("../Editor.js"));
|
|
7
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
-
jest.mock('../convertCtrlKey');
|
|
9
|
-
describe('RichText: Editor component', () => {
|
|
10
|
-
let richTextEditor;
|
|
11
|
-
const componentProps = {
|
|
12
|
-
onEdit: jest.fn()
|
|
13
|
-
};
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
_convertCtrlKey.default.mockClear();
|
|
16
|
-
});
|
|
17
|
-
const renderComponent = props => {
|
|
18
|
-
return (0, _enzyme.shallow)( /*#__PURE__*/_react.default.createElement(_Editor.default, props, /*#__PURE__*/_react.default.createElement("input", null)));
|
|
19
|
-
};
|
|
20
|
-
it('renders a result', () => {
|
|
21
|
-
richTextEditor = renderComponent(componentProps);
|
|
22
|
-
expect(richTextEditor).toHaveLength(1);
|
|
23
|
-
});
|
|
24
|
-
it('calls convertCtrlKey on keydown', () => {
|
|
25
|
-
richTextEditor = renderComponent(componentProps);
|
|
26
|
-
richTextEditor.simulate('keyDown');
|
|
27
|
-
expect(_convertCtrlKey.default).toHaveBeenCalled();
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _convertCtrlKey = _interopRequireDefault(require("../convertCtrlKey.js"));
|
|
4
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
-
describe('convertCtrlKey', () => {
|
|
6
|
-
it('does not trigger callback if no ctrl key', () => {
|
|
7
|
-
const cb = jest.fn();
|
|
8
|
-
const e = {
|
|
9
|
-
key: 'j',
|
|
10
|
-
preventDefault: () => {}
|
|
11
|
-
};
|
|
12
|
-
(0, _convertCtrlKey.default)(e, cb);
|
|
13
|
-
expect(cb).not.toHaveBeenCalled();
|
|
14
|
-
});
|
|
15
|
-
describe('when ctrl key + "b" pressed', () => {
|
|
16
|
-
it('triggers callback with open/close markers and caret pos in between', () => {
|
|
17
|
-
const cb = jest.fn();
|
|
18
|
-
const e = {
|
|
19
|
-
key: 'b',
|
|
20
|
-
ctrlKey: true,
|
|
21
|
-
target: {
|
|
22
|
-
selectionStart: 0,
|
|
23
|
-
selectionEnd: 0,
|
|
24
|
-
value: 'rainbow dash'
|
|
25
|
-
},
|
|
26
|
-
preventDefault: () => {}
|
|
27
|
-
};
|
|
28
|
-
(0, _convertCtrlKey.default)(e, cb);
|
|
29
|
-
expect(cb).toHaveBeenCalled();
|
|
30
|
-
expect(cb).toHaveBeenCalledWith('** rainbow dash', 1);
|
|
31
|
-
});
|
|
32
|
-
it('triggers callback with open/close markers and caret pos in between (end of text)', () => {
|
|
33
|
-
const cb = jest.fn();
|
|
34
|
-
const e = {
|
|
35
|
-
key: 'b',
|
|
36
|
-
ctrlKey: true,
|
|
37
|
-
target: {
|
|
38
|
-
selectionStart: 22,
|
|
39
|
-
selectionEnd: 22,
|
|
40
|
-
value: 'rainbow dash is purple'
|
|
41
|
-
},
|
|
42
|
-
preventDefault: () => {}
|
|
43
|
-
};
|
|
44
|
-
(0, _convertCtrlKey.default)(e, cb);
|
|
45
|
-
expect(cb).toHaveBeenCalled();
|
|
46
|
-
expect(cb).toHaveBeenCalledWith('rainbow dash is purple **', 24);
|
|
47
|
-
});
|
|
48
|
-
it('triggers callback with open/close markers mid-text with surrounding spaces (1)', () => {
|
|
49
|
-
const cb = jest.fn();
|
|
50
|
-
const e = {
|
|
51
|
-
key: 'b',
|
|
52
|
-
metaKey: true,
|
|
53
|
-
target: {
|
|
54
|
-
selectionStart: 4,
|
|
55
|
-
// caret located just before "quick"
|
|
56
|
-
selectionEnd: 4,
|
|
57
|
-
value: 'the quick brown fox'
|
|
58
|
-
},
|
|
59
|
-
preventDefault: () => {}
|
|
60
|
-
};
|
|
61
|
-
(0, _convertCtrlKey.default)(e, cb);
|
|
62
|
-
expect(cb).toHaveBeenCalled();
|
|
63
|
-
expect(cb).toHaveBeenCalledWith('the ** quick brown fox', 5);
|
|
64
|
-
});
|
|
65
|
-
it('triggers callback with open/close markers mid-text with surrounding spaces (2)', () => {
|
|
66
|
-
const cb = jest.fn();
|
|
67
|
-
const e = {
|
|
68
|
-
key: 'b',
|
|
69
|
-
metaKey: true,
|
|
70
|
-
target: {
|
|
71
|
-
selectionStart: 3,
|
|
72
|
-
// caret located just after "the"
|
|
73
|
-
selectionEnd: 3,
|
|
74
|
-
value: 'the quick brown fox'
|
|
75
|
-
},
|
|
76
|
-
preventDefault: () => {}
|
|
77
|
-
};
|
|
78
|
-
(0, _convertCtrlKey.default)(e, cb);
|
|
79
|
-
expect(cb).toHaveBeenCalled();
|
|
80
|
-
expect(cb).toHaveBeenCalledWith('the ** quick brown fox', 5);
|
|
81
|
-
});
|
|
82
|
-
it('triggers callback with correct double markers and padding', () => {
|
|
83
|
-
const cb = jest.fn();
|
|
84
|
-
const e = {
|
|
85
|
-
key: 'b',
|
|
86
|
-
metaKey: true,
|
|
87
|
-
target: {
|
|
88
|
-
selectionStart: 9,
|
|
89
|
-
// between the underscores
|
|
90
|
-
selectionEnd: 9,
|
|
91
|
-
value: 'rainbow __'
|
|
92
|
-
},
|
|
93
|
-
preventDefault: () => {}
|
|
94
|
-
};
|
|
95
|
-
(0, _convertCtrlKey.default)(e, cb);
|
|
96
|
-
expect(cb).toHaveBeenCalled();
|
|
97
|
-
expect(cb).toHaveBeenCalledWith('rainbow _**_', 10);
|
|
98
|
-
});
|
|
99
|
-
describe('selected text', () => {
|
|
100
|
-
it('triggers callback with open/close markers around text and caret pos after closing marker', () => {
|
|
101
|
-
const cb = jest.fn();
|
|
102
|
-
const e = {
|
|
103
|
-
key: 'b',
|
|
104
|
-
metaKey: true,
|
|
105
|
-
target: {
|
|
106
|
-
selectionStart: 5,
|
|
107
|
-
// "ow da" is selected
|
|
108
|
-
selectionEnd: 10,
|
|
109
|
-
value: 'rainbow dash is purple'
|
|
110
|
-
},
|
|
111
|
-
preventDefault: () => {}
|
|
112
|
-
};
|
|
113
|
-
(0, _convertCtrlKey.default)(e, cb);
|
|
114
|
-
expect(cb).toHaveBeenCalled();
|
|
115
|
-
expect(cb).toHaveBeenCalledWith('rainb *ow da* sh is purple', 13);
|
|
116
|
-
});
|
|
117
|
-
it('triggers callback with open/close markers around text when starting at beginning of line', () => {
|
|
118
|
-
const cb = jest.fn();
|
|
119
|
-
const e = {
|
|
120
|
-
key: 'b',
|
|
121
|
-
metaKey: true,
|
|
122
|
-
target: {
|
|
123
|
-
selectionStart: 0,
|
|
124
|
-
// "rainbow" is selected
|
|
125
|
-
selectionEnd: 7,
|
|
126
|
-
value: 'rainbow dash is purple'
|
|
127
|
-
},
|
|
128
|
-
preventDefault: () => {}
|
|
129
|
-
};
|
|
130
|
-
(0, _convertCtrlKey.default)(e, cb);
|
|
131
|
-
expect(cb).toHaveBeenCalled();
|
|
132
|
-
expect(cb).toHaveBeenCalledWith('*rainbow* dash is purple', 9);
|
|
133
|
-
});
|
|
134
|
-
it('triggers callback with open/close markers around text when ending at end of line', () => {
|
|
135
|
-
const cb = jest.fn();
|
|
136
|
-
const e = {
|
|
137
|
-
key: 'b',
|
|
138
|
-
metaKey: true,
|
|
139
|
-
target: {
|
|
140
|
-
selectionStart: 16,
|
|
141
|
-
// "purple" is selected
|
|
142
|
-
selectionEnd: 22,
|
|
143
|
-
value: 'rainbow dash is purple'
|
|
144
|
-
},
|
|
145
|
-
preventDefault: () => {}
|
|
146
|
-
};
|
|
147
|
-
(0, _convertCtrlKey.default)(e, cb);
|
|
148
|
-
expect(cb).toHaveBeenCalled();
|
|
149
|
-
expect(cb).toHaveBeenCalledWith('rainbow dash is *purple*', 24);
|
|
150
|
-
});
|
|
151
|
-
it('triggers callback with open/close markers around word', () => {
|
|
152
|
-
const cb = jest.fn();
|
|
153
|
-
const e = {
|
|
154
|
-
key: 'b',
|
|
155
|
-
metaKey: true,
|
|
156
|
-
target: {
|
|
157
|
-
selectionStart: 8,
|
|
158
|
-
// "dash" is selected
|
|
159
|
-
selectionEnd: 12,
|
|
160
|
-
value: 'rainbow dash is purple'
|
|
161
|
-
},
|
|
162
|
-
preventDefault: () => {}
|
|
163
|
-
};
|
|
164
|
-
(0, _convertCtrlKey.default)(e, cb);
|
|
165
|
-
expect(cb).toHaveBeenCalled();
|
|
166
|
-
expect(cb).toHaveBeenCalledWith('rainbow *dash* is purple', 14);
|
|
167
|
-
});
|
|
168
|
-
it('triggers callback with leading/trailing spaces trimmed from selection', () => {
|
|
169
|
-
const cb = jest.fn();
|
|
170
|
-
const e = {
|
|
171
|
-
key: 'b',
|
|
172
|
-
metaKey: true,
|
|
173
|
-
target: {
|
|
174
|
-
selectionStart: 8,
|
|
175
|
-
// " dash " is selected (note leading and trailing space)
|
|
176
|
-
selectionEnd: 13,
|
|
177
|
-
value: 'rainbow dash is purple'
|
|
178
|
-
},
|
|
179
|
-
preventDefault: () => {}
|
|
180
|
-
};
|
|
181
|
-
(0, _convertCtrlKey.default)(e, cb);
|
|
182
|
-
expect(cb).toHaveBeenCalled();
|
|
183
|
-
expect(cb).toHaveBeenCalledWith('rainbow *dash* is purple', 14);
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
describe('when ctrl key + "i" pressed', () => {
|
|
188
|
-
it('triggers callback with open/close italics markers and caret pos in between', () => {
|
|
189
|
-
const cb = jest.fn();
|
|
190
|
-
const e = {
|
|
191
|
-
key: 'i',
|
|
192
|
-
ctrlKey: true,
|
|
193
|
-
target: {
|
|
194
|
-
selectionStart: 0,
|
|
195
|
-
selectionEnd: 0,
|
|
196
|
-
value: ''
|
|
197
|
-
},
|
|
198
|
-
preventDefault: () => {}
|
|
199
|
-
};
|
|
200
|
-
(0, _convertCtrlKey.default)(e, cb);
|
|
201
|
-
expect(cb).toHaveBeenCalled();
|
|
202
|
-
expect(cb).toHaveBeenCalledWith('__', 1);
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
const state = {
|
|
8
|
-
boldMode: false,
|
|
9
|
-
italicMode: false,
|
|
10
|
-
element: null
|
|
11
|
-
};
|
|
12
|
-
const markerMap = {
|
|
13
|
-
italic: '_',
|
|
14
|
-
bold: '*'
|
|
15
|
-
};
|
|
16
|
-
const trim = str => {
|
|
17
|
-
const leftSpaces = /^\s+/;
|
|
18
|
-
const rightSpaces = /\s+$/;
|
|
19
|
-
return str.replace(leftSpaces, '').replace(rightSpaces, '');
|
|
20
|
-
};
|
|
21
|
-
const toggleMode = mode => {
|
|
22
|
-
const prop = `${mode}Mode`;
|
|
23
|
-
state[prop] = !state[prop];
|
|
24
|
-
};
|
|
25
|
-
const insertMarkers = (mode, cb) => {
|
|
26
|
-
const {
|
|
27
|
-
selectionStart: start,
|
|
28
|
-
selectionEnd: end,
|
|
29
|
-
value
|
|
30
|
-
} = state.element;
|
|
31
|
-
const marker = markerMap[mode] || null;
|
|
32
|
-
if (!marker || !cb || start < 0) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
toggleMode(mode);
|
|
36
|
-
let newValue;
|
|
37
|
-
let caretPos = end + 1;
|
|
38
|
-
const padMarkers = text => {
|
|
39
|
-
// is caret between two markers (i.e., "**" or "__")? Then do not add padding
|
|
40
|
-
if (start === end && value.length && start > 0) {
|
|
41
|
-
if (value[start - 1] === markerMap.bold && value[start] === markerMap.bold || value[start - 1] === markerMap.italic && value[start] === markerMap.italic) {
|
|
42
|
-
return text;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (value.length && start > 0 && value[start - 1] !== ' ') {
|
|
46
|
-
text = ` ${text}`;
|
|
47
|
-
++caretPos;
|
|
48
|
-
}
|
|
49
|
-
if (value.length && end !== value.length && value[end] !== ' ') {
|
|
50
|
-
text = `${text} `;
|
|
51
|
-
}
|
|
52
|
-
return text;
|
|
53
|
-
};
|
|
54
|
-
if (start === end) {
|
|
55
|
-
//no text
|
|
56
|
-
const valueArr = value.split('');
|
|
57
|
-
valueArr.splice(start, 0, padMarkers(`${marker}${marker}`));
|
|
58
|
-
newValue = valueArr.join('');
|
|
59
|
-
} else {
|
|
60
|
-
const text = value.slice(start, end);
|
|
61
|
-
const trimmedText = trim(text);
|
|
62
|
-
|
|
63
|
-
// adjust caretPos based on trimmed text selection
|
|
64
|
-
caretPos = caretPos - (text.length - trimmedText.length) + 1;
|
|
65
|
-
newValue = [value.slice(0, start), padMarkers(`${marker}${trimmedText}${marker}`), value.slice(end)].join('');
|
|
66
|
-
toggleMode(mode);
|
|
67
|
-
}
|
|
68
|
-
cb(newValue, caretPos);
|
|
69
|
-
};
|
|
70
|
-
const convertCtrlKey = (event, cb) => {
|
|
71
|
-
const {
|
|
72
|
-
key,
|
|
73
|
-
ctrlKey,
|
|
74
|
-
metaKey
|
|
75
|
-
} = event;
|
|
76
|
-
const element = event.target;
|
|
77
|
-
state.element = element;
|
|
78
|
-
if (key === 'b' && (ctrlKey || metaKey)) {
|
|
79
|
-
event.preventDefault();
|
|
80
|
-
insertMarkers('bold', cb);
|
|
81
|
-
} else if (key === 'i' && (ctrlKey || metaKey)) {
|
|
82
|
-
event.preventDefault();
|
|
83
|
-
insertMarkers('italic', cb);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
var _default = convertCtrlKey;
|
|
87
|
-
exports.default = _default;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _markdownIt = _interopRequireDefault(require("markdown-it"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
const emojiDb = {
|
|
10
|
-
':-)': '\u{1F642}',
|
|
11
|
-
':)': '\u{1F642}',
|
|
12
|
-
':-(': '\u{1F641}',
|
|
13
|
-
':(': '\u{1F641}',
|
|
14
|
-
':+1': '\u{1F44D}',
|
|
15
|
-
':-1': '\u{1F44E}'
|
|
16
|
-
};
|
|
17
|
-
const codes = {
|
|
18
|
-
bold: {
|
|
19
|
-
name: 'bold',
|
|
20
|
-
char: '*',
|
|
21
|
-
domEl: 'strong',
|
|
22
|
-
encodedChar: 0x2a,
|
|
23
|
-
// see https://regex101.com/r/evswdV/8 for explanation of regexp
|
|
24
|
-
regexString: '\\B\\*((?!\\s)[^*]+(?:\\b|[^*\\s]))\\*\\B',
|
|
25
|
-
contentFn: val => val
|
|
26
|
-
},
|
|
27
|
-
italic: {
|
|
28
|
-
name: 'italic',
|
|
29
|
-
char: '_',
|
|
30
|
-
domEl: 'em',
|
|
31
|
-
encodedChar: 0x5f,
|
|
32
|
-
// see https://regex101.com/r/p6LpjK/6 for explanation of regexp
|
|
33
|
-
regexString: '\\b_((?!\\s)[^_]+(?:\\B|[^_\\s]))_\\b',
|
|
34
|
-
contentFn: val => val
|
|
35
|
-
},
|
|
36
|
-
emoji: {
|
|
37
|
-
name: 'emoji',
|
|
38
|
-
char: ':',
|
|
39
|
-
domEl: 'span',
|
|
40
|
-
encodedChar: 0x3a,
|
|
41
|
-
regexString: '^(:-\\)|:\\)|:\\(|:-\\(|:\\+1|:-1)',
|
|
42
|
-
contentFn: val => emojiDb[val]
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
let md;
|
|
46
|
-
let linksInText;
|
|
47
|
-
const markerIsInLinkText = pos => linksInText.some(link => pos >= link.index && pos <= link.lastIndex);
|
|
48
|
-
const parse = code => (state, silent) => {
|
|
49
|
-
if (silent) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
const start = state.pos;
|
|
53
|
-
|
|
54
|
-
// skip parsing emphasis if marker is within a link
|
|
55
|
-
if (markerIsInLinkText(start)) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
const marker = state.src.charCodeAt(start);
|
|
59
|
-
|
|
60
|
-
// marker character: "_", "*", ":"
|
|
61
|
-
if (marker !== codes[code].encodedChar) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
const MARKER_REGEX = new RegExp(codes[code].regexString);
|
|
65
|
-
const token = state.src.slice(start);
|
|
66
|
-
if (MARKER_REGEX.test(token)) {
|
|
67
|
-
const markerMatch = token.match(MARKER_REGEX);
|
|
68
|
-
|
|
69
|
-
// skip parsing sections where the marker is not at the start of the token
|
|
70
|
-
if (markerMatch.index !== 0) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
const text = markerMatch[1];
|
|
74
|
-
state.push(`${codes[code].domEl}_open`, codes[code].domEl, 1);
|
|
75
|
-
const t = state.push('text', '', 0);
|
|
76
|
-
t.content = codes[code].contentFn(text);
|
|
77
|
-
state.push(`${codes.bold.domEl}_close`, codes[code].domEl, -1);
|
|
78
|
-
state.pos += markerMatch[0].length;
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
return false;
|
|
82
|
-
};
|
|
83
|
-
class MdParser {
|
|
84
|
-
constructor() {
|
|
85
|
-
// disable all rules, enable autolink for URLs and email addresses
|
|
86
|
-
md = new _markdownIt.default('zero', {
|
|
87
|
-
linkify: true
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// *bold* -> <strong>bold</strong>
|
|
91
|
-
md.inline.ruler.push('strong', parse(codes.bold.name));
|
|
92
|
-
|
|
93
|
-
// _italic_ -> <em>italic</em>
|
|
94
|
-
md.inline.ruler.push('italic', parse(codes.italic.name));
|
|
95
|
-
|
|
96
|
-
// :-) :) :-( :( :+1 :-1 -> <span>[unicode]</span>
|
|
97
|
-
md.inline.ruler.push('emoji', parse(codes.emoji.name));
|
|
98
|
-
md.enable(['link', 'linkify', 'strong', 'italic', 'emoji']);
|
|
99
|
-
return this;
|
|
100
|
-
}
|
|
101
|
-
render(text) {
|
|
102
|
-
linksInText = md.linkify.match(text) || [];
|
|
103
|
-
return md.renderInline(text);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
var _default = MdParser;
|
|
107
|
-
exports.default = _default;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
var _MdParser = _interopRequireDefault(require("./MdParser.js"));
|
|
10
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
const Parser = _ref => {
|
|
14
|
-
let {
|
|
15
|
-
children,
|
|
16
|
-
style
|
|
17
|
-
} = _ref;
|
|
18
|
-
const MdParser = (0, _react.useMemo)(() => new _MdParser.default(), []);
|
|
19
|
-
return children ? /*#__PURE__*/_react.default.createElement("p", {
|
|
20
|
-
style: style,
|
|
21
|
-
dangerouslySetInnerHTML: {
|
|
22
|
-
__html: MdParser.render(children)
|
|
23
|
-
}
|
|
24
|
-
}) : null;
|
|
25
|
-
};
|
|
26
|
-
Parser.defaultProps = {
|
|
27
|
-
style: null
|
|
28
|
-
};
|
|
29
|
-
Parser.propTypes = {
|
|
30
|
-
children: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.node), _propTypes.default.node]),
|
|
31
|
-
style: _propTypes.default.object
|
|
32
|
-
};
|
|
33
|
-
var _default = Parser;
|
|
34
|
-
exports.default = _default;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _MdParser = _interopRequireDefault(require("../MdParser.js"));
|
|
4
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
-
const Parser = new _MdParser.default();
|
|
6
|
-
describe('MdParser class', () => {
|
|
7
|
-
it('converts text into HTML', () => {
|
|
8
|
-
const tests = [['_italic_', '<em>italic</em>'], ['*bold*', '<strong>bold</strong>'], ['* not bold because there is a space *', '* not bold because there is a space *'], ['_ not italic because there is a space _', '_ not italic because there is a space _'], [':-)', '<span>\u{1F642}</span>'], [':)', '<span>\u{1F642}</span>'], [':-(', '<span>\u{1F641}</span>'], [':(', '<span>\u{1F641}</span>'], [':+1', '<span>\u{1F44D}</span>'], [':-1', '<span>\u{1F44E}</span>'], ['mixed _italic_ *bold* and :+1', 'mixed <em>italic</em> <strong>bold</strong> and <span>\u{1F44D}</span>'], ['_italic with * inside_', '<em>italic with * inside</em>'], ['*bold with _ inside*', '<strong>bold with _ inside</strong>'],
|
|
9
|
-
// italic marker followed by : should work
|
|
10
|
-
['_italic_:', '<em>italic</em>:'], ['_italic_: some text, *bold*: some other text', '<em>italic</em>: some text, <strong>bold</strong>: some other text'],
|
|
11
|
-
// bold marker followed by : should work
|
|
12
|
-
['*bold*:', '<strong>bold</strong>:'], ['*bold*: some text, _italic_: some other text', '<strong>bold</strong>: some text, <em>italic</em>: some other text'],
|
|
13
|
-
// italic marker inside an italic string not allowed
|
|
14
|
-
['_italic with _ inside_', '_italic with _ inside_'],
|
|
15
|
-
// bold marker inside a bold string not allowed
|
|
16
|
-
['*bold with * inside*', '*bold with * inside*'], ['_multiple_ italic in the _same line_', '<em>multiple</em> italic in the <em>same line</em>'],
|
|
17
|
-
// nested italic/bold combinations not allowed
|
|
18
|
-
['_italic with *bold* inside_', '<em>italic with *bold* inside</em>'], ['*bold with _italic_ inside*', '<strong>bold with _italic_ inside</strong>'], ['text with : and :)', 'text with : and <span>\u{1F642}</span>'], ['(parenthesis and :))', '(parenthesis and <span>\u{1F642}</span>)'], [':((parenthesis:))', '<span>\u{1F641}</span>(parenthesis<span>\u{1F642}</span>)'], [':+1+1', '<span>\u{1F44D}</span>+1'], ['-1:-1', '-1<span>\u{1F44E}</span>'],
|
|
19
|
-
// links
|
|
20
|
-
['example.com/path', '<a href="http://example.com/path">example.com/path</a>'],
|
|
21
|
-
// not recognized links with italic marker inside not converted
|
|
22
|
-
['example_with_underscore.com/path', 'example_with_underscore.com/path'], ['example_with_underscore.com/path_with_underscore', 'example_with_underscore.com/path_with_underscore'],
|
|
23
|
-
// markers around non-recognized links
|
|
24
|
-
['link example_with_underscore.com/path should _not_ be converted', 'link example_with_underscore.com/path should <em>not</em> be converted'], ['link example_with_underscore.com/path should *not* be converted', 'link example_with_underscore.com/path should <strong>not</strong> be converted'],
|
|
25
|
-
// italic marker inside links not converted
|
|
26
|
-
['example.com/path_with_underscore', '<a href="http://example.com/path_with_underscore">example.com/path_with_underscore</a>'], ['_italic_ and *bold* with a example.com/link_with_underscore', '<em>italic</em> and <strong>bold</strong> with a <a href="http://example.com/link_with_underscore">example.com/link_with_underscore</a>'], ['example.com/path with *bold* after :)', '<a href="http://example.com/path">example.com/path</a> with <strong>bold</strong> after <span>\u{1F642}</span>'], ['_before_ example.com/path_with_underscore *after* :)', '<em>before</em> <a href="http://example.com/path_with_underscore">example.com/path_with_underscore</a> <strong>after</strong> <span>\u{1F642}</span>'],
|
|
27
|
-
// italic/bold markers right after non-word characters
|
|
28
|
-
['_If % of ART retention rate after 12 months >90(%)_: Sustain the efforts.', '<em>If % of ART retention rate after 12 months >90(%)</em>: Sustain the efforts.'], ['*If % of ART retention rate after 12 months >90(%)*: Sustain the efforts.', '<strong>If % of ART retention rate after 12 months >90(%)</strong>: Sustain the efforts.']];
|
|
29
|
-
tests.forEach(test => {
|
|
30
|
-
const renderedText = Parser.render(test[0]);
|
|
31
|
-
expect(renderedText).toEqual(test[1]);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _enzyme = require("enzyme");
|
|
4
|
-
var _react = _interopRequireDefault(require("react"));
|
|
5
|
-
var _Parser = _interopRequireDefault(require("../Parser.js"));
|
|
6
|
-
require("../MdParser.js");
|
|
7
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
-
jest.mock('../MdParser', () => {
|
|
9
|
-
return jest.fn().mockImplementation(() => {
|
|
10
|
-
return {
|
|
11
|
-
render: () => 'converted text'
|
|
12
|
-
};
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
describe('RichText: Parser component', () => {
|
|
16
|
-
let richTextParser;
|
|
17
|
-
const defaultProps = {
|
|
18
|
-
style: {
|
|
19
|
-
color: 'blue'
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const renderComponent = (props, text) => {
|
|
23
|
-
return (0, _enzyme.shallow)( /*#__PURE__*/_react.default.createElement(_Parser.default, props, text));
|
|
24
|
-
};
|
|
25
|
-
it('should have rendered a result', () => {
|
|
26
|
-
richTextParser = renderComponent({}, 'test');
|
|
27
|
-
expect(richTextParser).toHaveLength(1);
|
|
28
|
-
});
|
|
29
|
-
it('should have rendered a result with the style prop', () => {
|
|
30
|
-
richTextParser = renderComponent(defaultProps, 'test prop');
|
|
31
|
-
expect(richTextParser.props().style).toEqual(defaultProps.style);
|
|
32
|
-
});
|
|
33
|
-
it('should have rendered content', () => {
|
|
34
|
-
richTextParser = renderComponent({}, 'plain text');
|
|
35
|
-
expect(richTextParser.html()).toEqual('<p>converted text</p>');
|
|
36
|
-
});
|
|
37
|
-
it('should return null if no children is passed', () => {
|
|
38
|
-
richTextParser = renderComponent({}, undefined);
|
|
39
|
-
expect(richTextParser.html()).toBe(null);
|
|
40
|
-
});
|
|
41
|
-
});
|