@inseefr/lunatic 2.6.0 → 2.6.2-rc.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.
@@ -7,6 +7,7 @@ exports["default"] = void 0;
7
7
  var _reactMarkdown = _interopRequireDefault(require("react-markdown"));
8
8
  var _link = _interopRequireDefault(require("./link"));
9
9
  var _function = require("../../../../utils/function");
10
+ var _react = require("react");
10
11
  var _jsxRuntime = require("react/jsx-runtime");
11
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
13
  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); }
@@ -15,18 +16,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
15
16
  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; }
16
17
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
17
18
  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); }
18
- var renderers = function renderers(otherProps) {
19
- return {
20
- p: function p(props) {
21
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
22
- children: props.children
23
- });
24
- },
25
- a: function a(props) {
26
- return (0, _link["default"])(_objectSpread(_objectSpread({}, otherProps), props));
27
- }
28
- };
29
- };
30
19
  var DEFAULT_LOG_FUNCTION = _function.voidFunction;
31
20
  var MdLabel = function MdLabel(_ref) {
32
21
  var expression = _ref.expression,
@@ -34,10 +23,25 @@ var MdLabel = function MdLabel(_ref) {
34
23
  logFunction = _ref$logFunction === void 0 ? DEFAULT_LOG_FUNCTION : _ref$logFunction;
35
24
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactMarkdown["default"], {
36
25
  children: expression,
37
- components: renderers({
26
+ components: renderComponentsFor(expression, {
38
27
  logFunction: logFunction
39
28
  })
40
29
  });
41
30
  };
31
+ var renderComponentsFor = function renderComponentsFor(expression, extraProps) {
32
+ var components = {
33
+ p: _react.Fragment,
34
+ br: 'br',
35
+ a: function a(props) {
36
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_link["default"], _objectSpread({}, _objectSpread(_objectSpread({}, extraProps), props)));
37
+ }
38
+ };
39
+ if (/\n\n/.test(expression)) {
40
+ return _objectSpread(_objectSpread({}, components), {}, {
41
+ p: 'p'
42
+ });
43
+ }
44
+ return components;
45
+ };
42
46
  var _default = MdLabel;
43
47
  exports["default"] = _default;
@@ -6,10 +6,22 @@ var _mdLabel = _interopRequireDefault(require("./md-label"));
6
6
  var _jsxRuntime = require("react/jsx-runtime");
7
7
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
8
8
  (0, _vitest.describe)('md-label', function () {
9
- (0, _vitest.it)('should handle emoticon', function () {
9
+ (0, _vitest.it)('should handle simple text', function () {
10
10
  var obj = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_mdLabel["default"], {
11
- expression: "**Demo** of a"
11
+ expression: "This **is** a simple test"
12
12
  }));
13
- return (0, _vitest.expect)(obj.container.firstChild).toMatchInlineSnapshot("\n <p>\n <strong>\n Demo\n </strong>\n of a\n </p>\n ");
13
+ return (0, _vitest.expect)(obj.container).toMatchInlineSnapshot("\n\t\t\t<div>\n\t\t\t This \n\t\t\t <strong>\n\t\t\t is\n\t\t\t </strong>\n\t\t\t a simple test\n\t\t\t</div>\n\t\t");
14
+ });
15
+ (0, _vitest.it)('should handle line break', function () {
16
+ var obj = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_mdLabel["default"], {
17
+ expression: 'This **is** a simple test\non multiple line'
18
+ }));
19
+ return (0, _vitest.expect)(obj.container).toMatchInlineSnapshot("\n\t\t\t<div>\n\t\t\t This \n\t\t\t <strong>\n\t\t\t is\n\t\t\t </strong>\n\t\t\t a simple test\n\t\t\ton multiple line\n\t\t\t</div>\n\t\t");
20
+ });
21
+ (0, _vitest.it)('should handle paragraphs break', function () {
22
+ var obj = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_mdLabel["default"], {
23
+ expression: 'This **is** a simple test\n\nwith multiple paragraphs'
24
+ }));
25
+ return (0, _vitest.expect)(obj.container).toMatchInlineSnapshot("\n\t\t\t<div>\n\t\t\t <p>\n\t\t\t This \n\t\t\t <strong>\n\t\t\t is\n\t\t\t </strong>\n\t\t\t a simple test\n\t\t\t </p>\n\t\t\t \n\n\t\t\t <p>\n\t\t\t with multiple paragraphs\n\t\t\t </p>\n\t\t\t</div>\n\t\t");
14
26
  });
15
27
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inseefr/lunatic",
3
- "version": "2.6.0",
3
+ "version": "2.6.2-rc.1",
4
4
  "workersVersion": "0.2.5-experimental",
5
5
  "description": "Library of questionnaire components",
6
6
  "repository": {
@@ -57,7 +57,7 @@
57
57
  "library"
58
58
  ],
59
59
  "dependencies": {
60
- "@inseefr/trevas": "^0.1.19",
60
+ "@inseefr/trevas": "^0.1.20",
61
61
  "@inseefr/vtl-2.0-antlr-tools": "^0.1.0-bundle",
62
62
  "antlr4": "4.11.0",
63
63
  "classnames": "^2.3.1",