@pareto-engineering/design-system 4.2.0 → 4.2.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.
Files changed (63) hide show
  1. package/dist/cjs/a/XMLEditor/XMLEditor.js +3 -15
  2. package/dist/cjs/f/fields/EditorInput/EditorInput.js +6 -21
  3. package/dist/cjs/f/fields/EditorInput/common/StopPropagationPlugin.js +2 -7
  4. package/dist/cjs/f/fields/SelectInput/common/Menu/Menu.js +1 -1
  5. package/dist/cjs/f/fields/SelectInput/common/Multiple/Multiple.js +1 -1
  6. package/dist/cjs/f/fields/SelectInput/styles.scss +1 -1
  7. package/dist/cjs/g/FormBuilder/FormBuilder.js +38 -5
  8. package/dist/cjs/g/FormBuilder/common/Builder/Builder.js +62 -25
  9. package/dist/cjs/g/FormBuilder/common/Builder/common/ActionsContainer/ActionsContainer.js +80 -0
  10. package/dist/cjs/g/FormBuilder/common/Builder/common/ActionsContainer/index.js +13 -0
  11. package/dist/cjs/g/FormBuilder/common/Builder/common/ActionsContainer/styles.scss +59 -0
  12. package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +19 -45
  13. package/dist/cjs/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +0 -49
  14. package/dist/cjs/g/FormBuilder/common/Builder/common/Section/Section.js +14 -3
  15. package/dist/cjs/g/FormBuilder/common/Builder/common/Section/styles.scss +61 -0
  16. package/dist/cjs/g/FormBuilder/common/Builder/common/index.js +8 -1
  17. package/dist/cjs/g/FormBuilder/common/Builder/styles.scss +5 -48
  18. package/dist/cjs/g/FormBuilder/common/Renderer/Renderer.js +76 -33
  19. package/dist/cjs/g/FormBuilder/common/Renderer/common/Section/Section.js +8 -3
  20. package/dist/cjs/g/FormBuilder/common/Renderer/styles.scss +12 -1
  21. package/dist/es/a/XMLEditor/XMLEditor.js +3 -15
  22. package/dist/es/f/fields/EditorInput/EditorInput.js +7 -22
  23. package/dist/es/f/fields/EditorInput/common/StopPropagationPlugin.js +2 -6
  24. package/dist/es/f/fields/SelectInput/common/Menu/Menu.js +1 -1
  25. package/dist/es/f/fields/SelectInput/common/Multiple/Multiple.js +1 -1
  26. package/dist/es/f/fields/SelectInput/styles.scss +1 -1
  27. package/dist/es/g/FormBuilder/FormBuilder.js +38 -5
  28. package/dist/es/g/FormBuilder/common/Builder/Builder.js +56 -20
  29. package/dist/es/g/FormBuilder/common/Builder/common/ActionsContainer/ActionsContainer.js +70 -0
  30. package/dist/es/g/FormBuilder/common/Builder/common/ActionsContainer/index.js +2 -0
  31. package/dist/es/g/FormBuilder/common/Builder/common/ActionsContainer/styles.scss +59 -0
  32. package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.js +21 -47
  33. package/dist/es/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +0 -49
  34. package/dist/es/g/FormBuilder/common/Builder/common/Section/Section.js +14 -3
  35. package/dist/es/g/FormBuilder/common/Builder/common/Section/styles.scss +61 -0
  36. package/dist/es/g/FormBuilder/common/Builder/common/index.js +2 -1
  37. package/dist/es/g/FormBuilder/common/Builder/styles.scss +5 -48
  38. package/dist/es/g/FormBuilder/common/Renderer/Renderer.js +76 -34
  39. package/dist/es/g/FormBuilder/common/Renderer/common/Section/Section.js +8 -3
  40. package/dist/es/g/FormBuilder/common/Renderer/styles.scss +12 -1
  41. package/package.json +4 -4
  42. package/src/stories/g/FormBuilder.stories.jsx +116 -21
  43. package/src/ui/a/XMLEditor/XMLEditor.jsx +1 -15
  44. package/src/ui/f/fields/EditorInput/EditorInput.jsx +7 -23
  45. package/src/ui/f/fields/EditorInput/common/StopPropagationPlugin.jsx +2 -6
  46. package/src/ui/f/fields/SelectInput/common/Menu/Menu.jsx +1 -0
  47. package/src/ui/f/fields/SelectInput/common/Multiple/Multiple.jsx +1 -1
  48. package/src/ui/f/fields/SelectInput/styles.scss +1 -1
  49. package/src/ui/g/FormBuilder/FormBuilder.jsx +50 -3
  50. package/src/ui/g/FormBuilder/common/Builder/Builder.jsx +56 -18
  51. package/src/ui/g/FormBuilder/common/Builder/common/ActionsContainer/ActionsContainer.jsx +97 -0
  52. package/src/ui/g/FormBuilder/common/Builder/common/ActionsContainer/index.js +2 -0
  53. package/src/ui/g/FormBuilder/common/Builder/common/ActionsContainer/styles.scss +59 -0
  54. package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/InputBuilder.jsx +40 -60
  55. package/src/ui/g/FormBuilder/common/Builder/common/InputBuilder/styles.scss +0 -49
  56. package/src/ui/g/FormBuilder/common/Builder/common/Section/Section.jsx +26 -4
  57. package/src/ui/g/FormBuilder/common/Builder/common/Section/styles.scss +61 -0
  58. package/src/ui/g/FormBuilder/common/Builder/common/index.js +1 -0
  59. package/src/ui/g/FormBuilder/common/Builder/styles.scss +5 -48
  60. package/src/ui/g/FormBuilder/common/Renderer/Renderer.jsx +84 -33
  61. package/src/ui/g/FormBuilder/common/Renderer/common/Section/Section.jsx +3 -2
  62. package/src/ui/g/FormBuilder/common/Renderer/styles.scss +12 -1
  63. package/tests/__snapshots__/Storyshots.test.js.snap +395 -133
@@ -1,8 +1,8 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
  /* @pareto-engineering/generator-front 1.1.1-alpha.2 */
3
3
  import * as React from 'react';
4
+ import { useState, useEffect } from 'react';
4
5
  import { Formik, Form } from 'formik';
5
- import { useState } from 'react';
6
6
  import PropTypes from 'prop-types';
7
7
  import styleNames from '@pareto-engineering/bem/exports';
8
8
  import { Button } from "../../../../b";
@@ -13,6 +13,27 @@ import "./styles.scss";
13
13
  import { Section } from "./common";
14
14
  const baseClassName = styleNames.base;
15
15
  const componentClassName = 'renderer';
16
+ const reconstructFormDataWithValues = (formData, values) => {
17
+ const newData = {
18
+ ...formData
19
+ };
20
+ Object.keys(values).forEach(key => {
21
+ const [sectionIdx, inputIdx] = key.match(/\d+/g).map(Number);
22
+ newData.sections[sectionIdx].inputs[inputIdx].value = values[key];
23
+ });
24
+ return newData;
25
+ };
26
+ const validate = values => {
27
+ const errors = {};
28
+ const hasAtLeastOneValue = Object.keys(values).some(valueKey => {
29
+ const inputValue = values[valueKey];
30
+ return inputValue && inputValue !== '';
31
+ });
32
+ if (!hasAtLeastOneValue) {
33
+ errors.message = 'At least one input must have a value';
34
+ }
35
+ return errors;
36
+ };
16
37
 
17
38
  /**
18
39
  * This is the component description.
@@ -22,28 +43,36 @@ const Renderer = ({
22
43
  className: userClassName,
23
44
  style,
24
45
  formData,
25
- onSave
46
+ readOnly,
47
+ onSave,
48
+ onError,
49
+ shouldSubmit
26
50
  // ...otherProps
27
51
  }) => {
28
52
  const [currentSectionIndex, setCurrentSectionIndex] = useState(0);
29
53
  const [sectionHistory, setSectionHistory] = useState([]);
30
- const initialValues = formData.sections.reduce((acc, section) => {
31
- section.inputs.forEach(input => {
32
- acc[input.name] = '';
54
+ const [updatedFormData, setUpdatedFormData] = useState(formData);
55
+ useEffect(() => {
56
+ setUpdatedFormData(formData);
57
+ }, [formData]);
58
+ const initialValues = formData.sections.reduce((acc, section, sectionIndex) => {
59
+ section.inputs.forEach((input, inputIndex) => {
60
+ const inputName = `section_${sectionIndex}_input_${inputIndex}`;
61
+ acc[inputName] = input.value || '';
33
62
  });
34
63
  return acc;
35
64
  }, {});
36
65
  const handleSubmit = values => {
37
- const currentSection = formData.sections[currentSectionIndex];
66
+ const currentSection = updatedFormData.sections[currentSectionIndex];
38
67
  // by default, 'next' section is the immediate section after the current one
39
68
  let nextSectionIndex = currentSectionIndex + 1;
40
69
 
41
70
  // Any other value is either submit or an index to a section
42
71
  if (currentSection.navigation.nextSection !== 'next') {
43
- nextSectionIndex = currentSection.navigation.nextSection === 'submit' ? formData.sections.length // submit
72
+ nextSectionIndex = currentSection.navigation.nextSection === 'submit' ? updatedFormData.sections.length // submit
44
73
  : parseInt(currentSection.navigation.nextSection, 10); // go to specific section
45
74
  }
46
- if (nextSectionIndex >= formData.sections.length) {
75
+ if (nextSectionIndex >= updatedFormData.sections.length) {
47
76
  // submit
48
77
  onSave(values);
49
78
  } else {
@@ -62,28 +91,49 @@ const Renderer = ({
62
91
  setSectionHistory([...sectionHistory]);
63
92
  }
64
93
  };
94
+ const isSubmit = currentSectionIndex === updatedFormData.sections.length - 1 || updatedFormData.sections[currentSectionIndex].navigation.nextSection === 'submit';
65
95
  return /*#__PURE__*/React.createElement("div", {
66
96
  id: id,
67
97
  className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
68
98
  style: style
69
99
  }, /*#__PURE__*/React.createElement(Formik, {
70
100
  initialValues: initialValues,
71
- onSubmit: handleSubmit
72
- }, /*#__PURE__*/React.createElement(Form, null, formData.sections.map((section, sectionIndex) => sectionIndex === currentSectionIndex && /*#__PURE__*/React.createElement(Section, _extends({
73
- key: `${section.title}`
74
- }, section))), /*#__PURE__*/React.createElement("div", {
75
- className: "navigator-container"
76
- }, /*#__PURE__*/React.createElement(Button, {
77
- color: "interactive",
78
- isGradient: true,
79
- isGhost: true,
80
- onClick: handlePrevious,
81
- disabled: sectionHistory.length === 0
82
- }, "Previous"), /*#__PURE__*/React.createElement(Button, {
83
- color: "interactive",
84
- isGradient: true,
85
- type: "submit"
86
- }, formData.sections[currentSectionIndex].navigation.nextSection === 'submit' ? 'Submit' : 'Next')))));
101
+ onSubmit: handleSubmit,
102
+ validate: validate
103
+ }, ({
104
+ values,
105
+ errors
106
+ }) => {
107
+ useEffect(() => {
108
+ const formDataWithValues = reconstructFormDataWithValues(updatedFormData, values);
109
+ setUpdatedFormData(formDataWithValues);
110
+ onSave?.(formDataWithValues);
111
+ }, [values]);
112
+ useEffect(() => {
113
+ onError?.({
114
+ errors,
115
+ values
116
+ });
117
+ }, [errors, values]);
118
+ return /*#__PURE__*/React.createElement(Form, null, updatedFormData.sections.map((section, sectionIndex) => sectionIndex === currentSectionIndex && /*#__PURE__*/React.createElement(Section, _extends({
119
+ key: `${section.title}`
120
+ }, section, {
121
+ readOnly: readOnly
122
+ }))), /*#__PURE__*/React.createElement("div", {
123
+ className: "navigator-container"
124
+ }, /*#__PURE__*/React.createElement(Button, {
125
+ color: "interactive",
126
+ isGradient: true,
127
+ isCompact: true,
128
+ isGhost: true,
129
+ onClick: handlePrevious,
130
+ disabled: sectionHistory.length === 0
131
+ }, "Previous"), (!isSubmit || shouldSubmit) && /*#__PURE__*/React.createElement(Button, {
132
+ color: "interactive",
133
+ isGradient: true,
134
+ type: "submit"
135
+ }, isSubmit ? 'Submit' : 'Next')));
136
+ }));
87
137
  };
88
138
  Renderer.propTypes = {
89
139
  /**
@@ -97,17 +147,9 @@ Renderer.propTypes = {
97
147
  /**
98
148
  * The React-written, css properties for this element.
99
149
  */
100
- style: PropTypes.objectOf(PropTypes.string),
101
- /**
102
- * The children JSX
103
- */
104
- formData: PropTypes.shape({
105
- formTitle: PropTypes.string.isRequired,
106
- formDescription: PropTypes.string.isRequired,
107
- sections: PropTypes.arrayOf(PropTypes.objectOf(PropTypes.any))
108
- })
150
+ style: PropTypes.objectOf(PropTypes.string)
109
151
  };
110
152
  Renderer.defaultProps = {
111
- // someProp:false
153
+ // someProp: false,
112
154
  };
113
155
  export default Renderer;
@@ -20,18 +20,23 @@ const Section = ({
20
20
  style,
21
21
  title,
22
22
  description,
23
- inputs
23
+ inputs,
24
+ readOnly
24
25
  // ...otherProps
25
26
  }) => /*#__PURE__*/React.createElement("div", {
26
27
  id: id,
27
28
  className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
28
29
  style: style
29
- }, /*#__PURE__*/React.createElement("h3", null, title), /*#__PURE__*/React.createElement(ExpandableLexicalPreview, {
30
+ }, /*#__PURE__*/React.createElement("p", {
31
+ className: "h3"
32
+ }, title), /*#__PURE__*/React.createElement(ExpandableLexicalPreview, {
30
33
  nodes: description,
31
34
  name: "instructions"
32
35
  }), inputs.map(input => /*#__PURE__*/React.createElement(FormInput, _extends({
33
36
  key: input.name
34
- }, input))));
37
+ }, input, {
38
+ disabled: readOnly
39
+ }))));
35
40
  Section.propTypes = {
36
41
  /**
37
42
  * The HTML id for this element
@@ -6,10 +6,21 @@ $default-margin: 1rem;
6
6
 
7
7
  .#{bem.$base}.renderer {
8
8
  > form {
9
+ > .#{bem.$base}.section {
10
+ margin-bottom: calc($default-margin * 2);
11
+
12
+ > p {
13
+ margin: 0;
14
+ }
15
+ > .#{bem.$base}.expandable-lexical-preview {
16
+ margin-bottom: $default-margin;
17
+ }
18
+ }
19
+
9
20
  > .navigator-container {
10
21
  display: flex;
11
22
  gap: var(--gap);
12
- margin-top: $default-margin;
23
+ justify-content: space-between;
13
24
  }
14
25
  }
15
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pareto-engineering/design-system",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/es/index.js",
@@ -59,8 +59,8 @@
59
59
  "@lexical/selection": "0.12.2",
60
60
  "@lexical/table": "0.12.2",
61
61
  "@lexical/utils": "0.12.2",
62
- "@pareto-engineering/assets": "^4.1.0",
63
- "@pareto-engineering/bem": "^4.0.0",
62
+ "@pareto-engineering/assets": "^4.2.1",
63
+ "@pareto-engineering/bem": "^4.2.1",
64
64
  "@pareto-engineering/styles": "^4.2.0",
65
65
  "@pareto-engineering/utils": "^4.0.0",
66
66
  "codemirror": "^6.0.1",
@@ -82,5 +82,5 @@
82
82
  "relay-test-utils": "^15.0.0"
83
83
  },
84
84
  "browserslist": "> 2%",
85
- "gitHead": "7b24b23f9f4b091e2046d21bc0984cf7b7e6c0da"
85
+ "gitHead": "9dc4c06f6e3f8efe94eb0fa4f301ca6f046c5075"
86
86
  }
@@ -44,38 +44,82 @@ export const Builder = {
44
44
  const sampleFormData = {
45
45
  sections:[
46
46
  {
47
- title :'titlel',
48
- description:'{"root":{"children":[{"children":[{"detail":0,"format":0,"mode":"normal","style":"background-color: #a37575;","text":"asdvczvcsdvjksadvkl sdvasdvn mdvaskldvnsdavkjc,mndsvb asdvsdvsadv","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1}],"direction":"ltr","format":"","indent":0,"type":"root","version":1}}',
49
- key :'section-title',
47
+ title :'This is a survey of some of the best LLM models out there',
48
+ description:'{"root":{"children":[{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Best LLM models for software developers","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"heading","version":1,"tag":"h3"},{"children":[{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Chat GPT","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"listitem","version":1,"value":1},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Perplexity","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"listitem","version":1,"value":2},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Gemini","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"listitem","version":1,"value":3},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Claude","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"listitem","version":1,"value":4}],"direction":"ltr","format":"","indent":0,"type":"list","version":1,"listType":"bullet","start":1,"tag":"ul"},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Please add more exciting models that we might missed","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"quote","version":1},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"You can make them ","type":"text","version":1},{"detail":0,"format":1,"mode":"normal","style":"","text":"bold","type":"text","version":1},{"detail":0,"format":0,"mode":"normal","style":"","text":" or ","type":"text","version":1},{"detail":0,"format":2,"mode":"normal","style":"","text":"Italic or ","type":"text","version":1},{"detail":0,"format":10,"mode":"normal","style":"","text":"underlined","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1},{"children":[{"detail":0,"format":4,"mode":"normal","style":"color: #110b53;","text":"You can also color them and strike through them!","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1}],"direction":"ltr","format":"","indent":0,"type":"root","version":1}}',
49
+ key :'section-0',
50
50
  inputs :[
51
51
  {
52
- name :'section_0_input_0',
53
- label :'Names',
54
- type :'multiple',
55
- required:false,
56
- options :[
52
+ name :'section_0_input_0',
53
+ label :'Name the Model',
54
+ type :'text',
55
+ required :true,
56
+ options :[],
57
+ conditionalLogic:null,
58
+ description :'',
59
+ },
60
+ {
61
+ name :'section_0_input_1',
62
+ label :'Describe the Model in detail',
63
+ type :'textarea',
64
+ required :false,
65
+ options :[],
66
+ conditionalLogic:null,
67
+ description :'brief model description',
68
+ },
69
+ ],
70
+ orderedInputDragIds:[],
71
+ navigation :{
72
+ nextSection:'next',
73
+ },
74
+ },
75
+ {
76
+ title :'Rate the Models',
77
+ description:'{"root":{"children":[{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Best LLM models for software developers","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1},{"children":[{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Chat GPT","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"listitem","version":1,"value":1},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Perplexity","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"listitem","version":1,"value":2},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Gemini","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"listitem","version":1,"value":3},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Claude","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"listitem","version":1,"value":4}],"direction":"ltr","format":"","indent":0,"type":"list","version":1,"listType":"bullet","start":1,"tag":"ul"},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Please add more exciting models that we might missed","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"quote","version":1},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"You can make them ","type":"text","version":1},{"detail":0,"format":1,"mode":"normal","style":"","text":"bold","type":"text","version":1},{"detail":0,"format":0,"mode":"normal","style":"","text":" or ","type":"text","version":1},{"detail":0,"format":2,"mode":"normal","style":"","text":"Italic or ","type":"text","version":1},{"detail":0,"format":10,"mode":"normal","style":"","text":"underlined","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1},{"children":[{"detail":0,"format":4,"mode":"normal","style":"","text":"You can also color them and strike through them!","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1}],"direction":"ltr","format":"","indent":0,"type":"root","version":1}}',
78
+ key :'section-1',
79
+ inputs :[
80
+ {
81
+ type :'choices',
82
+ options:[
57
83
  {
58
- key :'sections-0-inputs-0-options--1',
59
- value :'James',
60
- label :'James',
84
+ key :'sections-1-inputs-0-options--1',
85
+ value :'Chat GPT',
86
+ label :'Chat GPT',
61
87
  nextSection:'',
62
88
  },
63
89
  {
64
- key :'sections-0-inputs-0-options-0',
65
- value :'Coigo',
66
- label :'Coigo',
90
+ key :'sections-1-inputs-0-options-0',
91
+ value :'Gemini',
92
+ label :'Gemini',
93
+ nextSection:'',
94
+ },
95
+ ],
96
+ required :true,
97
+ description:'',
98
+ name :'section_1_input_0',
99
+ label :'Which is better between the 2?',
100
+ },
101
+ {
102
+ name :'section_1_input_1',
103
+ label :'Choose the worst of them ',
104
+ type :'multiple',
105
+ required:false,
106
+ options :[
107
+ {
108
+ key :'sections-1-inputs-1-options--1',
109
+ value :'Chat GPT',
110
+ label :'Chat GPT',
67
111
  nextSection:'',
68
112
  },
69
113
  {
70
- key :'sections-0-inputs-0-options-1',
71
- value :'Nyanjui',
72
- label :'Nyanjui',
114
+ key :'sections-1-inputs-1-options-0',
115
+ value :'Gemini',
116
+ label :'Gemini',
73
117
  nextSection:'',
74
118
  },
75
119
  {
76
- key :'sections-0-inputs-0-options-2',
77
- value :'Masalia',
78
- label :'Masalia',
120
+ key :'sections-1-inputs-1-options-1',
121
+ value :'Claude',
122
+ label :'Claude',
79
123
  nextSection:'',
80
124
  },
81
125
  ],
@@ -83,15 +127,66 @@ const sampleFormData = {
83
127
  description :'',
84
128
  },
85
129
  ],
86
- navigation:{
130
+ orderedInputDragIds:[],
131
+ navigation :{
132
+ nextSection:'next',
133
+ },
134
+ },
135
+ {
136
+ title :'General sentiments',
137
+ description:'{"root":{"children":[{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Best LLM models for software developers","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"heading","version":1,"tag":"h3"},{"children":[{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Chat GPT","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"listitem","version":1,"value":1},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Perplexity","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"listitem","version":1,"value":2},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Gemini","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"listitem","version":1,"value":3},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Claude","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"listitem","version":1,"value":4}],"direction":"ltr","format":"","indent":0,"type":"list","version":1,"listType":"bullet","start":1,"tag":"ul"},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"Please add more exciting models that we might missed","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"quote","version":1},{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":"You can make them ","type":"text","version":1},{"detail":0,"format":1,"mode":"normal","style":"","text":"bold","type":"text","version":1},{"detail":0,"format":0,"mode":"normal","style":"","text":" or ","type":"text","version":1},{"detail":0,"format":2,"mode":"normal","style":"","text":"Italic or ","type":"text","version":1},{"detail":0,"format":10,"mode":"normal","style":"","text":"underlined","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1},{"children":[{"detail":0,"format":4,"mode":"normal","style":"","text":"You can also color them and strike through them!","type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1}],"direction":"ltr","format":"","indent":0,"type":"root","version":1}}',
138
+ key :'section-2',
139
+ inputs :[
140
+ {
141
+ type :'textarea',
142
+ options :[],
143
+ required :true,
144
+ description:'',
145
+ name :'section_2_input_0',
146
+ label :'Give a final brief description of your findings',
147
+ },
148
+ ],
149
+ orderedInputDragIds:[],
150
+ navigation :{
87
151
  nextSection:'next',
88
152
  },
89
153
  },
90
154
  ],
91
155
  }
156
+
92
157
  export const Renderer = {
93
158
  args:{
94
159
  mode :'render',
95
160
  formData:sampleFormData,
96
161
  },
162
+ render:(args) => {
163
+ const [values, setValues] = useState({})
164
+
165
+ const handleFormDataUpdateWithValues = (argsValues) => {
166
+ setValues(argsValues)
167
+ }
168
+
169
+ return (
170
+ <>
171
+ <FormBuilder {...args} onRendererFormSave={handleFormDataUpdateWithValues} />
172
+ <pre>{JSON.stringify(values, null, 2)}</pre>
173
+ </>
174
+ )
175
+ },
176
+ }
177
+
178
+ export const RendererWithSubmit = {
179
+ ...Renderer,
180
+ args:{
181
+ ...Renderer.args,
182
+ shouldSubmit:true,
183
+ },
184
+ }
185
+
186
+ export const RendererWithDisabled = {
187
+ ...Renderer,
188
+ args:{
189
+ ...Renderer.args,
190
+ readOnly:true,
191
+ },
97
192
  }
@@ -58,8 +58,6 @@ const XMLEditor = ({
58
58
  config,
59
59
  onChange,
60
60
  onBlur,
61
- stopAllPropagation,
62
- stopPropagationKeys,
63
61
  }) => {
64
62
  const editorRef = useRef()
65
63
 
@@ -93,9 +91,7 @@ const XMLEditor = ({
93
91
  }),
94
92
  EditorView.domEventHandlers({
95
93
  keydown(e) {
96
- if (stopPropagationKeys?.includes(e.key) || stopAllPropagation) {
97
- e.stopPropagation()
98
- }
94
+ e.stopPropagation()
99
95
  },
100
96
  }),
101
97
  ],
@@ -172,20 +168,10 @@ XMLEditor.propTypes = {
172
168
  */
173
169
  gutterWidth:PropTypes.string,
174
170
 
175
- /**
176
- * The keys to stop propagation on.
177
- */
178
- stopPropagationKeys:PropTypes.arrayOf(PropTypes.string),
179
-
180
171
  /**
181
172
  * The callback for when the editor loses focus.
182
173
  */
183
174
  onBlur:PropTypes.func,
184
-
185
- /**
186
- * Whether to stop all propagation of keys to keep focus on the editor.
187
- */
188
- stopAllPropagation:PropTypes.bool,
189
175
  }
190
176
 
191
177
  XMLEditor.defaultProps = {
@@ -2,7 +2,7 @@
2
2
  /* eslint-disable import/no-extraneous-dependencies -- required here */
3
3
  import * as React from 'react'
4
4
  import { memo, useEffect } from 'react'
5
- import { useFormikContext } from 'formik'
5
+ import { useField, useFormikContext } from 'formik'
6
6
  import { LexicalComposer } from '@lexical/react/LexicalComposer'
7
7
  import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin'
8
8
  import { ContentEditable } from '@lexical/react/LexicalContentEditable'
@@ -51,7 +51,6 @@ const EditorInput = ({
51
51
  style,
52
52
  name,
53
53
  label,
54
- // validate,
55
54
  resize,
56
55
  color,
57
56
  rows,
@@ -60,19 +59,16 @@ const EditorInput = ({
60
59
  description,
61
60
  disabled,
62
61
  showDebugger,
63
- stopPropagationKeys,
64
62
  setEditorState,
65
- // handleOnChange,
66
63
  // ...otherProps
67
64
  }) => {
68
- const { values, setFieldValue } = useFormikContext()
65
+ const [field, ,] = useField(name)
66
+ const { setFieldValue } = useFormikContext()
69
67
 
70
68
  const setInitialValue = () => {
71
- const value = values[name]
72
-
73
69
  try {
74
- JSON.parse(value)
75
- return value
70
+ JSON.parse(field.value)
71
+ return field.value
76
72
  } catch {
77
73
  const defaultValue = {
78
74
  root:{
@@ -103,7 +99,7 @@ const EditorInput = ({
103
99
  version :1,
104
100
  },
105
101
  }
106
- defaultValue.root.children[0].children[0].text = value
102
+ defaultValue.root.children[0].children[0].text = field.value
107
103
  return JSON.stringify(defaultValue)
108
104
  }
109
105
  }
@@ -188,9 +184,7 @@ const EditorInput = ({
188
184
  <TabIndentationPlugin />
189
185
  {setEditorState && <ExposeEditorStatePlugin setEditorState={setEditorState} />}
190
186
  <HistoryPlugin />
191
- { stopPropagationKeys && (
192
- <StopPropagationPlugin stopPropagationKeys={stopPropagationKeys} />
193
- )}
187
+ <StopPropagationPlugin />
194
188
  <FormDescription className="s-1" description={description} name={name} />
195
189
  { showDebugger && <TreeViewPlugin /> }
196
190
  </div>
@@ -224,11 +218,6 @@ EditorInput.propTypes = {
224
218
  */
225
219
  label:PropTypes.string.isRequired,
226
220
 
227
- /**
228
- * The input value validator function
229
- */
230
- // validate:PropTypes.func,
231
-
232
221
  /**
233
222
  * The number of rows int the text area
234
223
  */
@@ -268,11 +257,6 @@ EditorInput.propTypes = {
268
257
  * Whether to show the debugger or not
269
258
  */
270
259
  showDebugger:PropTypes.bool,
271
-
272
- /**
273
- * Map to stop propagation of the given keys
274
- */
275
- stopPropagationKeys:PropTypes.arrayOf(PropTypes.string),
276
260
  }
277
261
 
278
262
  EditorInput.defaultProps = {
@@ -1,16 +1,12 @@
1
1
  import { useInsertionEffect } from 'react'
2
2
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
3
3
 
4
- const StopPropagationPlugin = ({
5
- stopPropagationKeys,
6
- }) => {
4
+ const StopPropagationPlugin = () => {
7
5
  const [editor] = useLexicalComposerContext()
8
6
 
9
7
  useInsertionEffect(() => {
10
8
  const onKeyDown = (e) => {
11
- if (stopPropagationKeys?.includes(e.key)) {
12
- e.stopPropagation()
13
- }
9
+ e.stopPropagation()
14
10
  }
15
11
 
16
12
  return editor.registerRootListener(
@@ -45,6 +45,7 @@ const Menu = React.forwardRef(({
45
45
  {...getItemProps({ item, index })}
46
46
  className={[
47
47
  'item',
48
+ item.disabled && styleNames.modifierDisabled,
48
49
  highlightedIndex === index && styleNames.modifierActive,
49
50
  ].filter(Boolean)
50
51
  .join(' ')}
@@ -133,7 +133,7 @@ const Multiple = ({
133
133
  case useCombobox.stateChangeTypes.InputKeyDownEnter:
134
134
  case useCombobox.stateChangeTypes.ItemClick:
135
135
  case useCombobox.stateChangeTypes.InputBlur:
136
- if (selectedItem) {
136
+ if (selectedItem && !selectedItem?.disabled) {
137
137
  setSearchInputValue('')
138
138
  addSelectedItem(selectedItem)
139
139
  }
@@ -122,7 +122,7 @@ $default-gap: var(--gap);
122
122
  margin: 0;
123
123
  }
124
124
 
125
- &.#{bem.$modifier-active} {
125
+ &.#{bem.$modifier-active}:not(.disabled) {
126
126
  background-color: var(--y);
127
127
 
128
128
  > p {