@pareto-engineering/design-system 4.0.0-alpha.62 → 4.0.0-alpha.63

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 (192) hide show
  1. package/dist/cjs/f/FormInput/FormInput.js +43 -13
  2. package/dist/cjs/f/common/V2/Description/Description.js +76 -0
  3. package/dist/cjs/f/common/V2/Description/index.js +13 -0
  4. package/dist/cjs/f/common/V2/Description/styles.scss +10 -0
  5. package/dist/cjs/f/common/V2/Label/Label.js +84 -0
  6. package/dist/cjs/f/common/V2/Label/index.js +13 -0
  7. package/dist/cjs/f/common/V2/Label/styles.scss +9 -0
  8. package/dist/cjs/f/common/V2/index.js +19 -0
  9. package/dist/cjs/f/common/index.js +12 -0
  10. package/dist/cjs/f/fields/V2/Checkbox/Checkbox.js +122 -0
  11. package/dist/cjs/f/fields/V2/Checkbox/index.js +13 -0
  12. package/dist/cjs/f/fields/V2/Checkbox/styles.scss +16 -0
  13. package/dist/cjs/f/fields/V2/ChoicesInput/ChoicesInput.js +154 -0
  14. package/dist/cjs/f/fields/V2/ChoicesInput/common/Choice/Choice.js +104 -0
  15. package/dist/cjs/f/fields/V2/ChoicesInput/common/Choice/index.js +13 -0
  16. package/dist/cjs/f/fields/V2/ChoicesInput/common/index.js +12 -0
  17. package/dist/cjs/f/fields/V2/ChoicesInput/index.js +13 -0
  18. package/dist/cjs/f/fields/V2/ChoicesInput/styles.scss +79 -0
  19. package/dist/cjs/f/fields/V2/EditorInput/EditorInput.js +197 -0
  20. package/dist/cjs/f/fields/V2/EditorInput/common/Toolbar.js +257 -0
  21. package/dist/cjs/f/fields/V2/EditorInput/common/TreeViewPlugin.js +18 -0
  22. package/dist/cjs/f/fields/V2/EditorInput/common/index.js +20 -0
  23. package/dist/cjs/f/fields/V2/EditorInput/index.js +13 -0
  24. package/dist/cjs/f/fields/V2/EditorInput/styles.scss +149 -0
  25. package/dist/cjs/f/fields/V2/LinkInput/LinkInput.js +156 -0
  26. package/dist/cjs/f/fields/V2/LinkInput/index.js +13 -0
  27. package/dist/cjs/f/fields/V2/LinkInput/styles.scss +90 -0
  28. package/dist/cjs/f/fields/V2/QueryChoices/QueryChoices.js +137 -0
  29. package/dist/cjs/f/fields/V2/QueryChoices/index.js +13 -0
  30. package/dist/cjs/f/fields/V2/QueryCombobox/QueryCombobox.js +229 -0
  31. package/dist/cjs/f/fields/V2/QueryCombobox/common/Combobox/Combobox.js +236 -0
  32. package/dist/cjs/f/fields/V2/QueryCombobox/common/Combobox/index.js +13 -0
  33. package/dist/cjs/f/fields/V2/QueryCombobox/common/Menu/Menu.js +83 -0
  34. package/dist/cjs/f/fields/V2/QueryCombobox/common/Menu/index.js +13 -0
  35. package/dist/cjs/f/fields/V2/QueryCombobox/common/MultipleCombobox/MultipleCombobox.js +300 -0
  36. package/dist/cjs/f/fields/V2/QueryCombobox/common/MultipleCombobox/index.js +13 -0
  37. package/dist/cjs/f/fields/V2/QueryCombobox/common/index.js +26 -0
  38. package/dist/cjs/f/fields/V2/QueryCombobox/index.js +13 -0
  39. package/dist/cjs/f/fields/V2/QueryCombobox/styles.scss +127 -0
  40. package/dist/cjs/f/fields/V2/QuerySelect/QuerySelect.js +198 -0
  41. package/dist/cjs/f/fields/V2/QuerySelect/index.js +13 -0
  42. package/dist/cjs/f/fields/V2/RatingsInput/RatingsInput.js +130 -0
  43. package/dist/cjs/f/fields/V2/RatingsInput/common/Rating/Rating.js +117 -0
  44. package/dist/cjs/f/fields/V2/RatingsInput/common/Rating/index.js +13 -0
  45. package/dist/cjs/f/fields/V2/RatingsInput/common/index.js +12 -0
  46. package/dist/cjs/f/fields/V2/RatingsInput/index.js +13 -0
  47. package/dist/cjs/f/fields/V2/RatingsInput/styles.scss +48 -0
  48. package/dist/cjs/f/fields/V2/SelectInput/SelectInput.js +154 -0
  49. package/dist/cjs/f/fields/V2/SelectInput/index.js +13 -0
  50. package/dist/cjs/f/fields/V2/SelectInput/styles.scss +87 -0
  51. package/dist/cjs/f/fields/V2/TextInput/TextInput.js +155 -0
  52. package/dist/cjs/f/fields/V2/TextInput/index.js +13 -0
  53. package/dist/cjs/f/fields/V2/TextInput/styles.scss +78 -0
  54. package/dist/cjs/f/fields/V2/TextareaInput/TextareaInput.js +152 -0
  55. package/dist/cjs/f/fields/V2/TextareaInput/index.js +13 -0
  56. package/dist/cjs/f/fields/V2/TextareaInput/styles.scss +53 -0
  57. package/dist/cjs/f/fields/V2/index.js +82 -0
  58. package/dist/cjs/f/fields/index.js +26 -1
  59. package/dist/es/f/FormInput/FormInput.js +33 -3
  60. package/dist/es/f/common/V2/Description/Description.js +68 -0
  61. package/dist/es/f/common/V2/Description/index.js +2 -0
  62. package/dist/es/f/common/V2/Description/styles.scss +10 -0
  63. package/dist/es/f/common/V2/Label/Label.js +76 -0
  64. package/dist/es/f/common/V2/Label/index.js +2 -0
  65. package/dist/es/f/common/V2/Label/styles.scss +9 -0
  66. package/dist/es/f/common/V2/index.js +2 -0
  67. package/dist/es/f/common/index.js +2 -1
  68. package/dist/es/f/fields/V2/Checkbox/Checkbox.js +114 -0
  69. package/dist/es/f/fields/V2/Checkbox/index.js +2 -0
  70. package/dist/es/f/fields/V2/Checkbox/styles.scss +16 -0
  71. package/dist/es/f/fields/V2/ChoicesInput/ChoicesInput.js +148 -0
  72. package/dist/es/f/fields/V2/ChoicesInput/common/Choice/Choice.js +97 -0
  73. package/dist/es/f/fields/V2/ChoicesInput/common/Choice/index.js +2 -0
  74. package/dist/es/f/fields/V2/ChoicesInput/common/index.js +1 -0
  75. package/dist/es/f/fields/V2/ChoicesInput/index.js +2 -0
  76. package/dist/es/f/fields/V2/ChoicesInput/styles.scss +79 -0
  77. package/dist/es/f/fields/V2/EditorInput/EditorInput.js +192 -0
  78. package/dist/es/f/fields/V2/EditorInput/common/Toolbar.js +246 -0
  79. package/dist/es/f/fields/V2/EditorInput/common/TreeViewPlugin.js +11 -0
  80. package/dist/es/f/fields/V2/EditorInput/common/index.js +2 -0
  81. package/dist/es/f/fields/V2/EditorInput/index.js +2 -0
  82. package/dist/es/f/fields/V2/EditorInput/styles.scss +149 -0
  83. package/dist/es/f/fields/V2/LinkInput/LinkInput.js +148 -0
  84. package/dist/es/f/fields/V2/LinkInput/index.js +2 -0
  85. package/dist/es/f/fields/V2/LinkInput/styles.scss +90 -0
  86. package/dist/es/f/fields/V2/QueryChoices/QueryChoices.js +126 -0
  87. package/dist/es/f/fields/V2/QueryChoices/index.js +2 -0
  88. package/dist/es/f/fields/V2/QueryCombobox/QueryCombobox.js +221 -0
  89. package/dist/es/f/fields/V2/QueryCombobox/common/Combobox/Combobox.js +229 -0
  90. package/dist/es/f/fields/V2/QueryCombobox/common/Combobox/index.js +2 -0
  91. package/dist/es/f/fields/V2/QueryCombobox/common/Menu/Menu.js +73 -0
  92. package/dist/es/f/fields/V2/QueryCombobox/common/Menu/index.js +2 -0
  93. package/dist/es/f/fields/V2/QueryCombobox/common/MultipleCombobox/MultipleCombobox.js +293 -0
  94. package/dist/es/f/fields/V2/QueryCombobox/common/MultipleCombobox/index.js +2 -0
  95. package/dist/es/f/fields/V2/QueryCombobox/common/index.js +3 -0
  96. package/dist/es/f/fields/V2/QueryCombobox/index.js +2 -0
  97. package/dist/es/f/fields/V2/QueryCombobox/styles.scss +127 -0
  98. package/dist/es/f/fields/V2/QuerySelect/QuerySelect.js +186 -0
  99. package/dist/es/f/fields/V2/QuerySelect/index.js +2 -0
  100. package/dist/es/f/fields/V2/RatingsInput/RatingsInput.js +124 -0
  101. package/dist/es/f/fields/V2/RatingsInput/common/Rating/Rating.js +109 -0
  102. package/dist/es/f/fields/V2/RatingsInput/common/Rating/index.js +2 -0
  103. package/dist/es/f/fields/V2/RatingsInput/common/index.js +1 -0
  104. package/dist/es/f/fields/V2/RatingsInput/index.js +2 -0
  105. package/dist/es/f/fields/V2/RatingsInput/styles.scss +48 -0
  106. package/dist/es/f/fields/V2/SelectInput/SelectInput.js +146 -0
  107. package/dist/es/f/fields/V2/SelectInput/index.js +2 -0
  108. package/dist/es/f/fields/V2/SelectInput/styles.scss +87 -0
  109. package/dist/es/f/fields/V2/TextInput/TextInput.js +147 -0
  110. package/dist/es/f/fields/V2/TextInput/index.js +2 -0
  111. package/dist/es/f/fields/V2/TextInput/styles.scss +78 -0
  112. package/dist/es/f/fields/V2/TextareaInput/TextareaInput.js +146 -0
  113. package/dist/es/f/fields/V2/TextareaInput/index.js +2 -0
  114. package/dist/es/f/fields/V2/TextareaInput/styles.scss +53 -0
  115. package/dist/es/f/fields/V2/index.js +11 -0
  116. package/dist/es/f/fields/index.js +2 -1
  117. package/package.json +3 -3
  118. package/src/stories/f/v2/Checkbox.stories.jsx +102 -0
  119. package/src/stories/f/v2/ChoicesInput.stories.jsx +139 -0
  120. package/src/stories/f/v2/EditorInput.stories.jsx +81 -0
  121. package/src/stories/f/v2/LinkInput.stories.jsx +93 -0
  122. package/src/stories/f/v2/QueryChoices.stories.jsx +144 -0
  123. package/src/stories/f/v2/QueryCombobox.stories.jsx +301 -0
  124. package/src/stories/f/v2/QuerySelect.stories.jsx +150 -0
  125. package/src/stories/f/v2/RatingsInput.stories.jsx +77 -0
  126. package/src/stories/f/v2/SelectInput.stories.jsx +95 -0
  127. package/src/stories/f/v2/TextInput.stories.jsx +120 -0
  128. package/src/stories/f/v2/TextareaInput.stories.jsx +107 -0
  129. package/src/stories/f/v2/__generated__/FormInputAllTaskStatusesQuery.graphql.js +122 -0
  130. package/src/stories/f/v2/__generated__/FormInputAllTeamsQuery.graphql.js +139 -0
  131. package/src/stories/f/v2/__generated__/QueryChoicesAllTaskStatusesQuery.graphql.js +122 -0
  132. package/src/stories/f/v2/__generated__/QueryComboboxAllTeamsQuery.graphql.js +139 -0
  133. package/src/stories/f/v2/__generated__/QuerySelectAllTaskStatusesQuery.graphql.js +122 -0
  134. package/src/ui/f/FormInput/FormInput.jsx +57 -12
  135. package/src/ui/f/common/V2/Description/Description.jsx +94 -0
  136. package/src/ui/f/common/V2/Description/index.js +2 -0
  137. package/src/ui/f/common/V2/Description/styles.scss +10 -0
  138. package/src/ui/f/common/V2/Label/Label.jsx +102 -0
  139. package/src/ui/f/common/V2/Label/index.js +2 -0
  140. package/src/ui/f/common/V2/Label/styles.scss +9 -0
  141. package/src/ui/f/common/V2/index.js +2 -0
  142. package/src/ui/f/common/index.js +1 -0
  143. package/src/ui/f/fields/V2/Checkbox/Checkbox.jsx +146 -0
  144. package/src/ui/f/fields/V2/Checkbox/index.js +2 -0
  145. package/src/ui/f/fields/V2/Checkbox/styles.scss +16 -0
  146. package/src/ui/f/fields/V2/ChoicesInput/ChoicesInput.jsx +183 -0
  147. package/src/ui/f/fields/V2/ChoicesInput/common/Choice/Choice.jsx +125 -0
  148. package/src/ui/f/fields/V2/ChoicesInput/common/Choice/index.js +2 -0
  149. package/src/ui/f/fields/V2/ChoicesInput/common/index.js +1 -0
  150. package/src/ui/f/fields/V2/ChoicesInput/index.js +2 -0
  151. package/src/ui/f/fields/V2/ChoicesInput/styles.scss +79 -0
  152. package/src/ui/f/fields/V2/EditorInput/EditorInput.jsx +244 -0
  153. package/src/ui/f/fields/V2/EditorInput/common/Toolbar.jsx +356 -0
  154. package/src/ui/f/fields/V2/EditorInput/common/TreeViewPlugin.jsx +16 -0
  155. package/src/ui/f/fields/V2/EditorInput/common/index.jsx +2 -0
  156. package/src/ui/f/fields/V2/EditorInput/index.js +2 -0
  157. package/src/ui/f/fields/V2/EditorInput/styles.scss +149 -0
  158. package/src/ui/f/fields/V2/LinkInput/LinkInput.jsx +187 -0
  159. package/src/ui/f/fields/V2/LinkInput/index.js +2 -0
  160. package/src/ui/f/fields/V2/LinkInput/styles.scss +90 -0
  161. package/src/ui/f/fields/V2/QueryChoices/QueryChoices.jsx +153 -0
  162. package/src/ui/f/fields/V2/QueryChoices/index.js +2 -0
  163. package/src/ui/f/fields/V2/QueryCombobox/QueryCombobox.jsx +254 -0
  164. package/src/ui/f/fields/V2/QueryCombobox/common/Combobox/Combobox.jsx +276 -0
  165. package/src/ui/f/fields/V2/QueryCombobox/common/Combobox/index.js +2 -0
  166. package/src/ui/f/fields/V2/QueryCombobox/common/Menu/Menu.jsx +103 -0
  167. package/src/ui/f/fields/V2/QueryCombobox/common/Menu/index.js +2 -0
  168. package/src/ui/f/fields/V2/QueryCombobox/common/MultipleCombobox/MultipleCombobox.jsx +362 -0
  169. package/src/ui/f/fields/V2/QueryCombobox/common/MultipleCombobox/index.js +2 -0
  170. package/src/ui/f/fields/V2/QueryCombobox/common/index.js +3 -0
  171. package/src/ui/f/fields/V2/QueryCombobox/index.js +2 -0
  172. package/src/ui/f/fields/V2/QueryCombobox/styles.scss +127 -0
  173. package/src/ui/f/fields/V2/QuerySelect/QuerySelect.jsx +220 -0
  174. package/src/ui/f/fields/V2/QuerySelect/index.js +2 -0
  175. package/src/ui/f/fields/V2/RatingsInput/RatingsInput.jsx +152 -0
  176. package/src/ui/f/fields/V2/RatingsInput/common/Rating/Rating.jsx +142 -0
  177. package/src/ui/f/fields/V2/RatingsInput/common/Rating/index.js +2 -0
  178. package/src/ui/f/fields/V2/RatingsInput/common/index.js +1 -0
  179. package/src/ui/f/fields/V2/RatingsInput/index.js +2 -0
  180. package/src/ui/f/fields/V2/RatingsInput/styles.scss +48 -0
  181. package/src/ui/f/fields/V2/SelectInput/SelectInput.jsx +187 -0
  182. package/src/ui/f/fields/V2/SelectInput/index.js +2 -0
  183. package/src/ui/f/fields/V2/SelectInput/styles.scss +87 -0
  184. package/src/ui/f/fields/V2/TextInput/TextInput.jsx +192 -0
  185. package/src/ui/f/fields/V2/TextInput/index.js +2 -0
  186. package/src/ui/f/fields/V2/TextInput/styles.scss +78 -0
  187. package/src/ui/f/fields/V2/TextareaInput/TextareaInput.jsx +180 -0
  188. package/src/ui/f/fields/V2/TextareaInput/index.js +2 -0
  189. package/src/ui/f/fields/V2/TextareaInput/styles.scss +53 -0
  190. package/src/ui/f/fields/V2/index.js +11 -0
  191. package/src/ui/f/fields/index.js +1 -0
  192. package/tests/__snapshots__/Storyshots.test.js.snap +5909 -0
@@ -0,0 +1,192 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ /* eslint-disable import/no-extraneous-dependencies -- required here */
3
+ import * as React from 'react';
4
+ import { useInsertionEffect, memo } from 'react';
5
+ import { useFormikContext } from 'formik';
6
+ import { LexicalComposer } from '@lexical/react/LexicalComposer';
7
+ import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
8
+ import { ContentEditable } from '@lexical/react/LexicalContentEditable';
9
+ import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
10
+ import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
11
+ import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin';
12
+ import { ListPlugin } from '@lexical/react/LexicalListPlugin';
13
+ import { TabIndentationPlugin } from '@lexical/react/LexicalTabIndentationPlugin';
14
+ import { AutoLinkNode, LinkNode } from '@lexical/link';
15
+ import { ListItemNode, ListNode } from '@lexical/list';
16
+ import PropTypes from 'prop-types';
17
+ import styleNames from '@pareto-engineering/bem/exports';
18
+
19
+ // Local Definitions
20
+
21
+ import { FormLabelV2, FormDescriptionV2 } from "../../../common";
22
+ import { Toolbar, TreeViewPlugin } from "./common";
23
+ const baseClassName = styleNames.base;
24
+ const componentClassName = 'editor-input';
25
+
26
+ /**
27
+ * This is the component description.
28
+ */
29
+ const EditorInput = ({
30
+ id,
31
+ className: userClassName,
32
+ style,
33
+ name,
34
+ label,
35
+ // validate,
36
+ resize,
37
+ color,
38
+ rows,
39
+ optional,
40
+ labelColor,
41
+ description,
42
+ disabled,
43
+ showDebugger
44
+ // ...otherProps
45
+ }) => {
46
+ useInsertionEffect(() => {
47
+ import("./styles.scss");
48
+ }, []);
49
+ const formik = useFormikContext();
50
+ const setInitialValue = () => {
51
+ const value = formik.values[name];
52
+ try {
53
+ JSON.parse(value);
54
+ return value;
55
+ } catch {
56
+ const defaultValue = {
57
+ root: {
58
+ children: [{
59
+ children: [{
60
+ detail: 0,
61
+ format: 0,
62
+ mode: 'normal',
63
+ style: '',
64
+ text: '',
65
+ type: 'text',
66
+ version: 1
67
+ }],
68
+ direction: 'ltr',
69
+ format: '',
70
+ indent: 0,
71
+ type: 'paragraph',
72
+ version: 1
73
+ }],
74
+ direction: 'ltr',
75
+ format: '',
76
+ indent: 0,
77
+ type: 'root',
78
+ version: 1
79
+ }
80
+ };
81
+ defaultValue.root.children[0].children[0].text = value;
82
+ return JSON.stringify(defaultValue);
83
+ }
84
+ };
85
+ const onChange = state => {
86
+ formik.setValues({
87
+ ...formik.values,
88
+ [name]: JSON.stringify(state)
89
+ });
90
+ };
91
+ const initialConfig = {
92
+ nameSpace: name,
93
+ editable: !disabled,
94
+ editorState: setInitialValue(),
95
+ theme: {
96
+ text: {
97
+ italic: 'italic',
98
+ strikethrough: 'strikethrough',
99
+ underline: 'underlined'
100
+ }
101
+ },
102
+ nodes: [AutoLinkNode, LinkNode, ListNode, ListItemNode]
103
+ };
104
+ return /*#__PURE__*/React.createElement(LexicalComposer, {
105
+ initialConfig: initialConfig
106
+ }, /*#__PURE__*/React.createElement("div", {
107
+ id: id,
108
+ className: [baseClassName, componentClassName, userClassName, `y-${color}`, disabled && 'disabled'].filter(e => e).join(' '),
109
+ style: {
110
+ ...style,
111
+ '--resize': resize,
112
+ '--rows': `${rows}em`
113
+ }
114
+ }, /*#__PURE__*/React.createElement(FormLabelV2, {
115
+ name: name,
116
+ color: labelColor,
117
+ optional: optional
118
+ }, label), !disabled && /*#__PURE__*/React.createElement(Toolbar, null), /*#__PURE__*/React.createElement(RichTextPlugin, {
119
+ contentEditable: /*#__PURE__*/React.createElement(ContentEditable, {
120
+ id: name,
121
+ className: "content-editable"
122
+ })
123
+ }), /*#__PURE__*/React.createElement(OnChangePlugin, {
124
+ onChange: onChange
125
+ }), /*#__PURE__*/React.createElement(LinkPlugin, null), /*#__PURE__*/React.createElement(ListPlugin, null), /*#__PURE__*/React.createElement(TabIndentationPlugin, null), /*#__PURE__*/React.createElement(HistoryPlugin, null), /*#__PURE__*/React.createElement(FormDescriptionV2, {
126
+ className: "s-1",
127
+ description: description,
128
+ name: name
129
+ }), showDebugger && /*#__PURE__*/React.createElement(TreeViewPlugin, null)));
130
+ };
131
+ EditorInput.propTypes = {
132
+ /**
133
+ * The HTML id for this element
134
+ */
135
+ id: PropTypes.string,
136
+ /**
137
+ * The HTML class names for this element
138
+ */
139
+ className: PropTypes.string,
140
+ /**
141
+ * The React-written, css properties for this element.
142
+ */
143
+ style: PropTypes.objectOf(PropTypes.string),
144
+ /**
145
+ * The input name (html - and Formik state)
146
+ */
147
+ name: PropTypes.string.isRequired,
148
+ /**
149
+ * The input label
150
+ */
151
+ label: PropTypes.string.isRequired,
152
+ /**
153
+ * The input value validator function
154
+ */
155
+ // validate:PropTypes.func,
156
+
157
+ /**
158
+ * The number of rows int the text area
159
+ */
160
+ rows: PropTypes.number,
161
+ /**
162
+ * Color of the text
163
+ */
164
+ color: PropTypes.string,
165
+ /**
166
+ * Label base color
167
+ */
168
+ labelColor: PropTypes.string,
169
+ /**
170
+ * Text area description
171
+ */
172
+ description: PropTypes.string,
173
+ /**
174
+ * Whether the text area should be disabled
175
+ */
176
+ disabled: PropTypes.bool,
177
+ /**
178
+ * Whether the input is optional or not
179
+ */
180
+ optional: PropTypes.bool,
181
+ /**
182
+ * The resize property of the text area
183
+ */
184
+ resize: PropTypes.oneOf(['none', 'both', 'horizontal', 'vertical'])
185
+ };
186
+ EditorInput.defaultProps = {
187
+ rows: 10,
188
+ disabled: false,
189
+ color: 'paragraph',
190
+ resize: 'vertical'
191
+ };
192
+ export default /*#__PURE__*/memo(EditorInput);
@@ -0,0 +1,246 @@
1
+ /* eslint-disable import/no-extraneous-dependencies -- required here */
2
+ import * as React from 'react';
3
+ import { useEffect, useState, useCallback, useRef } from 'react';
4
+ import { $getSelection, $isRangeSelection, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, UNDO_COMMAND, REDO_COMMAND, COMMAND_PRIORITY_NORMAL, createCommand } from 'lexical';
5
+ import { INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND, $isListNode, ListNode } from '@lexical/list';
6
+ import { $isAtNodeEnd } from '@lexical/selection';
7
+ import { $isLinkNode, TOGGLE_LINK_COMMAND } from '@lexical/link';
8
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
9
+ import { mergeRegister, $getNearestNodeOfType } from '@lexical/utils';
10
+ import { Popover } from "../../../../..";
11
+ import styleNames from '@pareto-engineering/bem/exports';
12
+ const baseClassName = styleNames.base;
13
+ const componentClassName = 'toolbar';
14
+ const getSelectedNode = selection => {
15
+ const {
16
+ anchor,
17
+ focus
18
+ } = selection;
19
+ const anchorNode = selection.anchor.getNode();
20
+ const focusNode = selection.focus.getNode();
21
+ if (anchorNode === focusNode) {
22
+ return anchorNode;
23
+ }
24
+ const isBackward = selection.isBackward();
25
+ if (isBackward) {
26
+ return $isAtNodeEnd(focus) ? anchorNode : focusNode;
27
+ }
28
+ return $isAtNodeEnd(anchor) ? focusNode : anchorNode;
29
+ };
30
+ const defaultColor = 'var(--paragraph)';
31
+ const colorOptions = ['red', 'blue', 'green', 'yellow', 'orange', 'purple', 'pink', 'brown'];
32
+ const Toolbar = () => {
33
+ const [editor] = useLexicalComposerContext();
34
+ const [isBold, setIsBold] = useState(false);
35
+ const [isItalic, setIsItalic] = useState(false);
36
+ const [isStrikethrough, setIsStrikethrough] = useState(false);
37
+ const [blockType, setBlockType] = useState('paragraph');
38
+ const [isLink, setIsLink] = useState(false);
39
+ const [isUnderline, setIsUnderline] = useState(false);
40
+ const [color, setColor] = useState(defaultColor);
41
+ const colorMenuRef = useRef(false);
42
+ const formatBulletList = () => {
43
+ if (blockType !== 'ul') {
44
+ editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND);
45
+ } else {
46
+ editor.dispatchCommand(REMOVE_LIST_COMMAND);
47
+ }
48
+ };
49
+ const formatNumberedList = () => {
50
+ if (blockType !== 'ol') {
51
+ editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND);
52
+ } else {
53
+ editor.dispatchCommand(REMOVE_LIST_COMMAND);
54
+ }
55
+ };
56
+ const formatLink = useCallback(() => {
57
+ if (!isLink) {
58
+ // eslint-disable-next-line no-alert
59
+ const path = prompt('Enter the full URL. Ex: https://www.example.com');
60
+ editor.dispatchCommand(TOGGLE_LINK_COMMAND, path);
61
+ } else {
62
+ editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
63
+ }
64
+ }, [editor, isLink]);
65
+ const updateToolbar = useCallback(() => {
66
+ const selection = $getSelection();
67
+
68
+ // Check list selection
69
+ if ($isRangeSelection(selection)) {
70
+ const anchorNode = selection.anchor.getNode();
71
+ const element = anchorNode.getKey() === 'root' ? anchorNode : anchorNode.getTopLevelElementOrThrow();
72
+ if ($isListNode(element)) {
73
+ const parentList = $getNearestNodeOfType(anchorNode, ListNode);
74
+ const type = parentList ? parentList.getTag() : element.getTag();
75
+ setBlockType(type);
76
+ } else {
77
+ setBlockType(element);
78
+ }
79
+
80
+ // Check nodes for color
81
+ const nodes = selection.getNodes().filter(node => node.getType() === 'text');
82
+ nodes.forEach(node => {
83
+ const style = node.getStyle();
84
+ const colorProperty = style.match(/color: ([^;]+)/);
85
+ if (colorProperty) {
86
+ setColor(colorProperty[1]);
87
+ return;
88
+ }
89
+ setColor(false);
90
+ });
91
+
92
+ // Check selection text styles
93
+ setIsBold(selection.hasFormat('bold'));
94
+ setIsItalic(selection.hasFormat('italic'));
95
+ setIsStrikethrough(selection.hasFormat('strikethrough'));
96
+ setIsUnderline(selection.hasFormat('underline'));
97
+ setIsLink(selection.hasFormat('link'));
98
+
99
+ // Check links
100
+ const node = getSelectedNode(selection);
101
+ const parent = node.getParent();
102
+ if ($isLinkNode(parent) || $isLinkNode(node)) {
103
+ setIsLink(true);
104
+ } else {
105
+ setIsLink(false);
106
+ }
107
+ }
108
+ }, [editor]);
109
+ const UPDATE_COLOR_COMMAND = createCommand();
110
+ editor.registerCommand(UPDATE_COLOR_COMMAND, payload => {
111
+ const selection = $getSelection();
112
+ const nodes = selection?.extract().filter(node => node.getType() === 'text');
113
+ nodes?.forEach(node => {
114
+ const style = node.getStyle();
115
+ const colorProperty = style?.match(/color: ([^;]+)/);
116
+ if (colorProperty && color !== payload) {
117
+ node.setStyle(style.replace(colorProperty[0], `color: ${payload}`));
118
+ } else if (colorProperty) {
119
+ node.setStyle(`color: ${defaultColor}`);
120
+ } else {
121
+ node.setStyle(`color: ${payload}`);
122
+ }
123
+ });
124
+ }, COMMAND_PRIORITY_NORMAL);
125
+ useEffect(() => mergeRegister(editor.registerUpdateListener(({
126
+ editorState
127
+ }) => {
128
+ editorState.read(() => {
129
+ updateToolbar();
130
+ });
131
+ })), [updateToolbar, editor]);
132
+ const dispatchUpdateColor = useCallback((e, payload) => {
133
+ e.stopPropagation();
134
+ editor.dispatchCommand(UPDATE_COLOR_COMMAND, payload);
135
+ }, [editor]);
136
+ return /*#__PURE__*/React.createElement("div", {
137
+ className: `${baseClassName} ${componentClassName}`
138
+ }, /*#__PURE__*/React.createElement("div", {
139
+ className: "group"
140
+ }, /*#__PURE__*/React.createElement("button", {
141
+ type: "button",
142
+ className: isBold ? 'active' : undefined,
143
+ onClick: () => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold')
144
+ }, /*#__PURE__*/React.createElement("span", {
145
+ className: "icon"
146
+ }, "|")), /*#__PURE__*/React.createElement("button", {
147
+ type: "button",
148
+ className: isItalic ? 'active' : undefined,
149
+ onClick: () => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'italic')
150
+ }, /*#__PURE__*/React.createElement("span", {
151
+ className: "icon"
152
+ }, "}")), /*#__PURE__*/React.createElement("button", {
153
+ type: "button",
154
+ className: isUnderline ? 'active' : undefined,
155
+ onClick: () => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'underline')
156
+ }, /*#__PURE__*/React.createElement("span", {
157
+ className: "icon"
158
+ }, "~")), /*#__PURE__*/React.createElement("button", {
159
+ type: "button",
160
+ className: isStrikethrough ? 'active' : undefined,
161
+ onClick: () => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'strikethrough')
162
+ }, /*#__PURE__*/React.createElement("span", {
163
+ className: "icon"
164
+ }, "?")), /*#__PURE__*/React.createElement("button", {
165
+ type: "button",
166
+ className: color && color !== defaultColor ? 'active color-menu-button' : 'color-menu-button',
167
+ onClick: () => editor.dispatchCommand(UPDATE_COLOR_COMMAND, color !== defaultColor ? defaultColor : color),
168
+ ref: colorMenuRef,
169
+ style: {
170
+ position: 'relative'
171
+ }
172
+ }, /*#__PURE__*/React.createElement("span", {
173
+ className: "icon",
174
+ style: {
175
+ color
176
+ }
177
+ }, "Q"), /*#__PURE__*/React.createElement(Popover, {
178
+ parentRef: colorMenuRef
179
+ }, /*#__PURE__*/React.createElement("div", {
180
+ className: "color-menu"
181
+ }, colorOptions.map(option => /*#__PURE__*/React.createElement("span", {
182
+ role: "button",
183
+ className: "icon color-option",
184
+ style: {
185
+ color: option
186
+ },
187
+ onClick: e => dispatchUpdateColor(e, option),
188
+ onKeyDown: e => dispatchUpdateColor(e, option),
189
+ tabIndex: 0,
190
+ key: option
191
+ }, "o"))))), /*#__PURE__*/React.createElement("button", {
192
+ type: "button",
193
+ className: isLink ? 'active' : undefined,
194
+ onClick: () => formatLink()
195
+ }, /*#__PURE__*/React.createElement("span", {
196
+ className: "icon"
197
+ }, "]")), /*#__PURE__*/React.createElement("button", {
198
+ type: "button",
199
+ className: blockType === 'ul' ? 'active' : undefined,
200
+ onClick: () => formatBulletList()
201
+ }, /*#__PURE__*/React.createElement("span", {
202
+ className: "icon"
203
+ }, ".")), /*#__PURE__*/React.createElement("button", {
204
+ type: "button",
205
+ className: blockType === 'ol' ? 'active' : undefined,
206
+ onClick: () => formatNumberedList()
207
+ }, /*#__PURE__*/React.createElement("span", {
208
+ className: "icon"
209
+ }, "-"))), /*#__PURE__*/React.createElement("div", {
210
+ className: "group"
211
+ }, /*#__PURE__*/React.createElement("button", {
212
+ type: "button",
213
+ onClick: () => editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'left')
214
+ }, /*#__PURE__*/React.createElement("span", {
215
+ className: "icon"
216
+ }, "^")), /*#__PURE__*/React.createElement("button", {
217
+ type: "button",
218
+ onClick: () => editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'center')
219
+ }, /*#__PURE__*/React.createElement("span", {
220
+ className: "icon"
221
+ }, "_")), /*#__PURE__*/React.createElement("button", {
222
+ type: "button",
223
+ onClick: () => editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'right')
224
+ }, /*#__PURE__*/React.createElement("span", {
225
+ className: "icon"
226
+ }, "`")), /*#__PURE__*/React.createElement("button", {
227
+ type: "button",
228
+ onClick: () => editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'justify')
229
+ }, /*#__PURE__*/React.createElement("span", {
230
+ className: "icon"
231
+ }, "{"))), /*#__PURE__*/React.createElement("div", {
232
+ className: "group"
233
+ }, /*#__PURE__*/React.createElement("button", {
234
+ type: "button",
235
+ onClick: () => editor.dispatchCommand(UNDO_COMMAND)
236
+ }, /*#__PURE__*/React.createElement("span", {
237
+ className: "icon"
238
+ }, "\\")), /*#__PURE__*/React.createElement("button", {
239
+ type: "button",
240
+ className: "flip",
241
+ onClick: () => editor.dispatchCommand(REDO_COMMAND)
242
+ }, /*#__PURE__*/React.createElement("span", {
243
+ className: "icon"
244
+ }, "\\"))));
245
+ };
246
+ export default Toolbar;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
3
+ import { TreeView } from '@lexical/react/LexicalTreeView';
4
+ const TreeViewPlugin = () => {
5
+ const [editor] = useLexicalComposerContext();
6
+ return /*#__PURE__*/React.createElement(TreeView, {
7
+ viewClassName: "tree-view-output",
8
+ editor: editor
9
+ });
10
+ };
11
+ export default TreeViewPlugin;
@@ -0,0 +1,2 @@
1
+ export { default as Toolbar } from "./Toolbar";
2
+ export { default as TreeViewPlugin } from "./TreeViewPlugin";
@@ -0,0 +1,2 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ export { default as EditorInput } from "./EditorInput";
@@ -0,0 +1,149 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+
3
+ @use "@pareto-engineering/bem";
4
+ @use "@pareto-engineering/styles/src/mixins";
5
+ @use "@pareto-engineering/styles/src/globals" as *;
6
+
7
+ $default-gap: calc(var(--gap) / 2);
8
+ $default-padding: .55em .75em;
9
+ $default-border: 1px solid var(--outline-inputs);
10
+ $default-input-border-radius: var(--theme-default-input-border-radius);
11
+ $default-border: var(--theme-default-input-border);
12
+ $focus-border: var(--theme-focus-input-border);
13
+ $active-background: var(--hard-background-inputs);
14
+ $default-background: var(--background-inputs);
15
+ $default-icon-color: var(--on-background-inputs);
16
+ $disabled-background: var(--background-inputs-30);
17
+ $default-color-menu-padding: .5em .25em;
18
+
19
+ .#{bem.$base}.editor-input {
20
+ display: flex;
21
+ flex-direction: column;
22
+
23
+ > .#{bem.$base}.form-label {
24
+ margin-bottom: var(--gap);
25
+ }
26
+
27
+ > .#{bem.$base}.toolbar {
28
+ display: flex;
29
+ gap: $default-gap;
30
+ margin-bottom: .25em;
31
+
32
+ > .group {
33
+ > button {
34
+ background: $default-background;
35
+ border: $default-border;
36
+ color: $default-icon-color;
37
+ padding: $default-padding;
38
+
39
+ &.active {
40
+ background-color: $active-background;
41
+ }
42
+ }
43
+ }
44
+
45
+ .flip {
46
+ transform: scaleX(-1);
47
+ }
48
+ }
49
+
50
+ &:not(.disabled) {
51
+ &:hover,
52
+ &:focus,
53
+ &:active {
54
+ > .textarea {
55
+ border: $focus-border;
56
+ }
57
+ }
58
+ }
59
+
60
+ &.disabled {
61
+ > .textarea {
62
+ background: $disabled-background;
63
+ color: var(--metadata);
64
+ cursor: not-allowed;
65
+ }
66
+ }
67
+
68
+ .color-menu-button {
69
+ &:hover {
70
+ > .#{bem.$base}.popover {
71
+ display: block;
72
+ }
73
+ }
74
+
75
+ > .#{bem.$base}.popover {
76
+ padding: $default-color-menu-padding;
77
+
78
+ .color-menu {
79
+ display: flex;
80
+ flex-wrap: wrap;
81
+ gap: calc($default-gap / 2);
82
+ justify-content: center;
83
+ max-width: 10em;
84
+ min-width: 5em;
85
+ }
86
+
87
+ .color-option:hover {
88
+ opacity: .5;
89
+ }
90
+ }
91
+ }
92
+
93
+ > .content-editable {
94
+ background: $default-background;
95
+ border: $default-border;
96
+ border-radius: $default-input-border-radius;
97
+ color: var(--y);
98
+ height: var(--rows);
99
+ outline: none;
100
+ overflow: auto;
101
+ padding: $default-padding;
102
+ resize: var(--resize);
103
+ width: 100%;
104
+
105
+ li:has(ol, ul) {
106
+ list-style-type: none;
107
+ }
108
+
109
+ p,
110
+ span,
111
+ strong,
112
+ em,
113
+ li {
114
+ &.underlined {
115
+ text-decoration: underline;
116
+
117
+ &.strikethrough {
118
+ text-decoration: underline line-through;
119
+ }
120
+ }
121
+
122
+ &.strikethrough {
123
+ text-decoration: line-through;
124
+ }
125
+
126
+ &.italic {
127
+ font-style: italic;
128
+ }
129
+ }
130
+
131
+ :first-child {
132
+ margin-top: 0;
133
+ }
134
+
135
+ &::placeholder {
136
+ color: var(--metadata);
137
+ }
138
+ }
139
+
140
+
141
+ > .tree-view-output {
142
+ background: $default-background;
143
+ border: $default-border;
144
+ border-radius: $default-input-border-radius;
145
+ max-height: 20em;
146
+ overflow: auto;
147
+ padding: $default-padding;
148
+ }
149
+ }