@pareto-engineering/design-system 4.0.0-alpha.61 → 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 (198) hide show
  1. package/dist/cjs/a/TextSteps/TextSteps.js +4 -4
  2. package/dist/cjs/a/TextSteps/styles.scss +1 -1
  3. package/dist/cjs/f/FormInput/FormInput.js +43 -13
  4. package/dist/cjs/f/common/V2/Description/Description.js +76 -0
  5. package/dist/cjs/f/common/V2/Description/index.js +13 -0
  6. package/dist/cjs/f/common/V2/Description/styles.scss +10 -0
  7. package/dist/cjs/f/common/V2/Label/Label.js +84 -0
  8. package/dist/cjs/f/common/V2/Label/index.js +13 -0
  9. package/dist/cjs/f/common/V2/Label/styles.scss +9 -0
  10. package/dist/cjs/f/common/V2/index.js +19 -0
  11. package/dist/cjs/f/common/index.js +12 -0
  12. package/dist/cjs/f/fields/V2/Checkbox/Checkbox.js +122 -0
  13. package/dist/cjs/f/fields/V2/Checkbox/index.js +13 -0
  14. package/dist/cjs/f/fields/V2/Checkbox/styles.scss +16 -0
  15. package/dist/cjs/f/fields/V2/ChoicesInput/ChoicesInput.js +154 -0
  16. package/dist/cjs/f/fields/V2/ChoicesInput/common/Choice/Choice.js +104 -0
  17. package/dist/cjs/f/fields/V2/ChoicesInput/common/Choice/index.js +13 -0
  18. package/dist/cjs/f/fields/V2/ChoicesInput/common/index.js +12 -0
  19. package/dist/cjs/f/fields/V2/ChoicesInput/index.js +13 -0
  20. package/dist/cjs/f/fields/V2/ChoicesInput/styles.scss +79 -0
  21. package/dist/cjs/f/fields/V2/EditorInput/EditorInput.js +197 -0
  22. package/dist/cjs/f/fields/V2/EditorInput/common/Toolbar.js +257 -0
  23. package/dist/cjs/f/fields/V2/EditorInput/common/TreeViewPlugin.js +18 -0
  24. package/dist/cjs/f/fields/V2/EditorInput/common/index.js +20 -0
  25. package/dist/cjs/f/fields/V2/EditorInput/index.js +13 -0
  26. package/dist/cjs/f/fields/V2/EditorInput/styles.scss +149 -0
  27. package/dist/cjs/f/fields/V2/LinkInput/LinkInput.js +156 -0
  28. package/dist/cjs/f/fields/V2/LinkInput/index.js +13 -0
  29. package/dist/cjs/f/fields/V2/LinkInput/styles.scss +90 -0
  30. package/dist/cjs/f/fields/V2/QueryChoices/QueryChoices.js +137 -0
  31. package/dist/cjs/f/fields/V2/QueryChoices/index.js +13 -0
  32. package/dist/cjs/f/fields/V2/QueryCombobox/QueryCombobox.js +229 -0
  33. package/dist/cjs/f/fields/V2/QueryCombobox/common/Combobox/Combobox.js +236 -0
  34. package/dist/cjs/f/fields/V2/QueryCombobox/common/Combobox/index.js +13 -0
  35. package/dist/cjs/f/fields/V2/QueryCombobox/common/Menu/Menu.js +83 -0
  36. package/dist/cjs/f/fields/V2/QueryCombobox/common/Menu/index.js +13 -0
  37. package/dist/cjs/f/fields/V2/QueryCombobox/common/MultipleCombobox/MultipleCombobox.js +300 -0
  38. package/dist/cjs/f/fields/V2/QueryCombobox/common/MultipleCombobox/index.js +13 -0
  39. package/dist/cjs/f/fields/V2/QueryCombobox/common/index.js +26 -0
  40. package/dist/cjs/f/fields/V2/QueryCombobox/index.js +13 -0
  41. package/dist/cjs/f/fields/V2/QueryCombobox/styles.scss +127 -0
  42. package/dist/cjs/f/fields/V2/QuerySelect/QuerySelect.js +198 -0
  43. package/dist/cjs/f/fields/V2/QuerySelect/index.js +13 -0
  44. package/dist/cjs/f/fields/V2/RatingsInput/RatingsInput.js +130 -0
  45. package/dist/cjs/f/fields/V2/RatingsInput/common/Rating/Rating.js +117 -0
  46. package/dist/cjs/f/fields/V2/RatingsInput/common/Rating/index.js +13 -0
  47. package/dist/cjs/f/fields/V2/RatingsInput/common/index.js +12 -0
  48. package/dist/cjs/f/fields/V2/RatingsInput/index.js +13 -0
  49. package/dist/cjs/f/fields/V2/RatingsInput/styles.scss +48 -0
  50. package/dist/cjs/f/fields/V2/SelectInput/SelectInput.js +154 -0
  51. package/dist/cjs/f/fields/V2/SelectInput/index.js +13 -0
  52. package/dist/cjs/f/fields/V2/SelectInput/styles.scss +87 -0
  53. package/dist/cjs/f/fields/V2/TextInput/TextInput.js +155 -0
  54. package/dist/cjs/f/fields/V2/TextInput/index.js +13 -0
  55. package/dist/cjs/f/fields/V2/TextInput/styles.scss +78 -0
  56. package/dist/cjs/f/fields/V2/TextareaInput/TextareaInput.js +152 -0
  57. package/dist/cjs/f/fields/V2/TextareaInput/index.js +13 -0
  58. package/dist/cjs/f/fields/V2/TextareaInput/styles.scss +53 -0
  59. package/dist/cjs/f/fields/V2/index.js +82 -0
  60. package/dist/cjs/f/fields/index.js +26 -1
  61. package/dist/es/a/TextSteps/TextSteps.js +4 -4
  62. package/dist/es/a/TextSteps/styles.scss +1 -1
  63. package/dist/es/f/FormInput/FormInput.js +33 -3
  64. package/dist/es/f/common/V2/Description/Description.js +68 -0
  65. package/dist/es/f/common/V2/Description/index.js +2 -0
  66. package/dist/es/f/common/V2/Description/styles.scss +10 -0
  67. package/dist/es/f/common/V2/Label/Label.js +76 -0
  68. package/dist/es/f/common/V2/Label/index.js +2 -0
  69. package/dist/es/f/common/V2/Label/styles.scss +9 -0
  70. package/dist/es/f/common/V2/index.js +2 -0
  71. package/dist/es/f/common/index.js +2 -1
  72. package/dist/es/f/fields/V2/Checkbox/Checkbox.js +114 -0
  73. package/dist/es/f/fields/V2/Checkbox/index.js +2 -0
  74. package/dist/es/f/fields/V2/Checkbox/styles.scss +16 -0
  75. package/dist/es/f/fields/V2/ChoicesInput/ChoicesInput.js +148 -0
  76. package/dist/es/f/fields/V2/ChoicesInput/common/Choice/Choice.js +97 -0
  77. package/dist/es/f/fields/V2/ChoicesInput/common/Choice/index.js +2 -0
  78. package/dist/es/f/fields/V2/ChoicesInput/common/index.js +1 -0
  79. package/dist/es/f/fields/V2/ChoicesInput/index.js +2 -0
  80. package/dist/es/f/fields/V2/ChoicesInput/styles.scss +79 -0
  81. package/dist/es/f/fields/V2/EditorInput/EditorInput.js +192 -0
  82. package/dist/es/f/fields/V2/EditorInput/common/Toolbar.js +246 -0
  83. package/dist/es/f/fields/V2/EditorInput/common/TreeViewPlugin.js +11 -0
  84. package/dist/es/f/fields/V2/EditorInput/common/index.js +2 -0
  85. package/dist/es/f/fields/V2/EditorInput/index.js +2 -0
  86. package/dist/es/f/fields/V2/EditorInput/styles.scss +149 -0
  87. package/dist/es/f/fields/V2/LinkInput/LinkInput.js +148 -0
  88. package/dist/es/f/fields/V2/LinkInput/index.js +2 -0
  89. package/dist/es/f/fields/V2/LinkInput/styles.scss +90 -0
  90. package/dist/es/f/fields/V2/QueryChoices/QueryChoices.js +126 -0
  91. package/dist/es/f/fields/V2/QueryChoices/index.js +2 -0
  92. package/dist/es/f/fields/V2/QueryCombobox/QueryCombobox.js +221 -0
  93. package/dist/es/f/fields/V2/QueryCombobox/common/Combobox/Combobox.js +229 -0
  94. package/dist/es/f/fields/V2/QueryCombobox/common/Combobox/index.js +2 -0
  95. package/dist/es/f/fields/V2/QueryCombobox/common/Menu/Menu.js +73 -0
  96. package/dist/es/f/fields/V2/QueryCombobox/common/Menu/index.js +2 -0
  97. package/dist/es/f/fields/V2/QueryCombobox/common/MultipleCombobox/MultipleCombobox.js +293 -0
  98. package/dist/es/f/fields/V2/QueryCombobox/common/MultipleCombobox/index.js +2 -0
  99. package/dist/es/f/fields/V2/QueryCombobox/common/index.js +3 -0
  100. package/dist/es/f/fields/V2/QueryCombobox/index.js +2 -0
  101. package/dist/es/f/fields/V2/QueryCombobox/styles.scss +127 -0
  102. package/dist/es/f/fields/V2/QuerySelect/QuerySelect.js +186 -0
  103. package/dist/es/f/fields/V2/QuerySelect/index.js +2 -0
  104. package/dist/es/f/fields/V2/RatingsInput/RatingsInput.js +124 -0
  105. package/dist/es/f/fields/V2/RatingsInput/common/Rating/Rating.js +109 -0
  106. package/dist/es/f/fields/V2/RatingsInput/common/Rating/index.js +2 -0
  107. package/dist/es/f/fields/V2/RatingsInput/common/index.js +1 -0
  108. package/dist/es/f/fields/V2/RatingsInput/index.js +2 -0
  109. package/dist/es/f/fields/V2/RatingsInput/styles.scss +48 -0
  110. package/dist/es/f/fields/V2/SelectInput/SelectInput.js +146 -0
  111. package/dist/es/f/fields/V2/SelectInput/index.js +2 -0
  112. package/dist/es/f/fields/V2/SelectInput/styles.scss +87 -0
  113. package/dist/es/f/fields/V2/TextInput/TextInput.js +147 -0
  114. package/dist/es/f/fields/V2/TextInput/index.js +2 -0
  115. package/dist/es/f/fields/V2/TextInput/styles.scss +78 -0
  116. package/dist/es/f/fields/V2/TextareaInput/TextareaInput.js +146 -0
  117. package/dist/es/f/fields/V2/TextareaInput/index.js +2 -0
  118. package/dist/es/f/fields/V2/TextareaInput/styles.scss +53 -0
  119. package/dist/es/f/fields/V2/index.js +11 -0
  120. package/dist/es/f/fields/index.js +2 -1
  121. package/package.json +3 -3
  122. package/src/stories/f/v2/Checkbox.stories.jsx +102 -0
  123. package/src/stories/f/v2/ChoicesInput.stories.jsx +139 -0
  124. package/src/stories/f/v2/EditorInput.stories.jsx +81 -0
  125. package/src/stories/f/v2/LinkInput.stories.jsx +93 -0
  126. package/src/stories/f/v2/QueryChoices.stories.jsx +144 -0
  127. package/src/stories/f/v2/QueryCombobox.stories.jsx +301 -0
  128. package/src/stories/f/v2/QuerySelect.stories.jsx +150 -0
  129. package/src/stories/f/v2/RatingsInput.stories.jsx +77 -0
  130. package/src/stories/f/v2/SelectInput.stories.jsx +95 -0
  131. package/src/stories/f/v2/TextInput.stories.jsx +120 -0
  132. package/src/stories/f/v2/TextareaInput.stories.jsx +107 -0
  133. package/src/stories/f/v2/__generated__/FormInputAllTaskStatusesQuery.graphql.js +122 -0
  134. package/src/stories/f/v2/__generated__/FormInputAllTeamsQuery.graphql.js +139 -0
  135. package/src/stories/f/v2/__generated__/QueryChoicesAllTaskStatusesQuery.graphql.js +122 -0
  136. package/src/stories/f/v2/__generated__/QueryComboboxAllTeamsQuery.graphql.js +139 -0
  137. package/src/stories/f/v2/__generated__/QuerySelectAllTaskStatusesQuery.graphql.js +122 -0
  138. package/src/ui/a/TextSteps/TextSteps.jsx +4 -4
  139. package/src/ui/a/TextSteps/styles.scss +1 -1
  140. package/src/ui/f/FormInput/FormInput.jsx +57 -12
  141. package/src/ui/f/common/V2/Description/Description.jsx +94 -0
  142. package/src/ui/f/common/V2/Description/index.js +2 -0
  143. package/src/ui/f/common/V2/Description/styles.scss +10 -0
  144. package/src/ui/f/common/V2/Label/Label.jsx +102 -0
  145. package/src/ui/f/common/V2/Label/index.js +2 -0
  146. package/src/ui/f/common/V2/Label/styles.scss +9 -0
  147. package/src/ui/f/common/V2/index.js +2 -0
  148. package/src/ui/f/common/index.js +1 -0
  149. package/src/ui/f/fields/V2/Checkbox/Checkbox.jsx +146 -0
  150. package/src/ui/f/fields/V2/Checkbox/index.js +2 -0
  151. package/src/ui/f/fields/V2/Checkbox/styles.scss +16 -0
  152. package/src/ui/f/fields/V2/ChoicesInput/ChoicesInput.jsx +183 -0
  153. package/src/ui/f/fields/V2/ChoicesInput/common/Choice/Choice.jsx +125 -0
  154. package/src/ui/f/fields/V2/ChoicesInput/common/Choice/index.js +2 -0
  155. package/src/ui/f/fields/V2/ChoicesInput/common/index.js +1 -0
  156. package/src/ui/f/fields/V2/ChoicesInput/index.js +2 -0
  157. package/src/ui/f/fields/V2/ChoicesInput/styles.scss +79 -0
  158. package/src/ui/f/fields/V2/EditorInput/EditorInput.jsx +244 -0
  159. package/src/ui/f/fields/V2/EditorInput/common/Toolbar.jsx +356 -0
  160. package/src/ui/f/fields/V2/EditorInput/common/TreeViewPlugin.jsx +16 -0
  161. package/src/ui/f/fields/V2/EditorInput/common/index.jsx +2 -0
  162. package/src/ui/f/fields/V2/EditorInput/index.js +2 -0
  163. package/src/ui/f/fields/V2/EditorInput/styles.scss +149 -0
  164. package/src/ui/f/fields/V2/LinkInput/LinkInput.jsx +187 -0
  165. package/src/ui/f/fields/V2/LinkInput/index.js +2 -0
  166. package/src/ui/f/fields/V2/LinkInput/styles.scss +90 -0
  167. package/src/ui/f/fields/V2/QueryChoices/QueryChoices.jsx +153 -0
  168. package/src/ui/f/fields/V2/QueryChoices/index.js +2 -0
  169. package/src/ui/f/fields/V2/QueryCombobox/QueryCombobox.jsx +254 -0
  170. package/src/ui/f/fields/V2/QueryCombobox/common/Combobox/Combobox.jsx +276 -0
  171. package/src/ui/f/fields/V2/QueryCombobox/common/Combobox/index.js +2 -0
  172. package/src/ui/f/fields/V2/QueryCombobox/common/Menu/Menu.jsx +103 -0
  173. package/src/ui/f/fields/V2/QueryCombobox/common/Menu/index.js +2 -0
  174. package/src/ui/f/fields/V2/QueryCombobox/common/MultipleCombobox/MultipleCombobox.jsx +362 -0
  175. package/src/ui/f/fields/V2/QueryCombobox/common/MultipleCombobox/index.js +2 -0
  176. package/src/ui/f/fields/V2/QueryCombobox/common/index.js +3 -0
  177. package/src/ui/f/fields/V2/QueryCombobox/index.js +2 -0
  178. package/src/ui/f/fields/V2/QueryCombobox/styles.scss +127 -0
  179. package/src/ui/f/fields/V2/QuerySelect/QuerySelect.jsx +220 -0
  180. package/src/ui/f/fields/V2/QuerySelect/index.js +2 -0
  181. package/src/ui/f/fields/V2/RatingsInput/RatingsInput.jsx +152 -0
  182. package/src/ui/f/fields/V2/RatingsInput/common/Rating/Rating.jsx +142 -0
  183. package/src/ui/f/fields/V2/RatingsInput/common/Rating/index.js +2 -0
  184. package/src/ui/f/fields/V2/RatingsInput/common/index.js +1 -0
  185. package/src/ui/f/fields/V2/RatingsInput/index.js +2 -0
  186. package/src/ui/f/fields/V2/RatingsInput/styles.scss +48 -0
  187. package/src/ui/f/fields/V2/SelectInput/SelectInput.jsx +187 -0
  188. package/src/ui/f/fields/V2/SelectInput/index.js +2 -0
  189. package/src/ui/f/fields/V2/SelectInput/styles.scss +87 -0
  190. package/src/ui/f/fields/V2/TextInput/TextInput.jsx +192 -0
  191. package/src/ui/f/fields/V2/TextInput/index.js +2 -0
  192. package/src/ui/f/fields/V2/TextInput/styles.scss +78 -0
  193. package/src/ui/f/fields/V2/TextareaInput/TextareaInput.jsx +180 -0
  194. package/src/ui/f/fields/V2/TextareaInput/index.js +2 -0
  195. package/src/ui/f/fields/V2/TextareaInput/styles.scss +53 -0
  196. package/src/ui/f/fields/V2/index.js +11 -0
  197. package/src/ui/f/fields/index.js +1 -0
  198. package/tests/__snapshots__/Storyshots.test.js.snap +5910 -1
@@ -0,0 +1,244 @@
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
+
17
+ import PropTypes from 'prop-types'
18
+ import styleNames from '@pareto-engineering/bem/exports'
19
+
20
+ // Local Definitions
21
+
22
+ import { FormLabelV2, FormDescriptionV2 } from '../../../common'
23
+ import { Toolbar, TreeViewPlugin } from './common'
24
+
25
+ const baseClassName = styleNames.base
26
+ const componentClassName = 'editor-input'
27
+
28
+ /**
29
+ * This is the component description.
30
+ */
31
+ const EditorInput = ({
32
+ id,
33
+ className:userClassName,
34
+ style,
35
+ name,
36
+ label,
37
+ // validate,
38
+ resize,
39
+ color,
40
+ rows,
41
+ optional,
42
+ labelColor,
43
+ description,
44
+ disabled,
45
+ showDebugger,
46
+ // ...otherProps
47
+ }) => {
48
+ useInsertionEffect(() => {
49
+ import('./styles.scss')
50
+ }, [])
51
+
52
+ const formik = useFormikContext()
53
+
54
+ const setInitialValue = () => {
55
+ const value = formik.values[name]
56
+ try {
57
+ JSON.parse(value)
58
+ return value
59
+ } catch {
60
+ const defaultValue = {
61
+ root:{
62
+ children:[
63
+ {
64
+ children:[
65
+ {
66
+ detail :0,
67
+ format :0,
68
+ mode :'normal',
69
+ style :'',
70
+ text :'',
71
+ type :'text',
72
+ version:1,
73
+ },
74
+ ],
75
+ direction:'ltr',
76
+ format :'',
77
+ indent :0,
78
+ type :'paragraph',
79
+ version :1,
80
+ },
81
+ ],
82
+ direction:'ltr',
83
+ format :'',
84
+ indent :0,
85
+ type :'root',
86
+ version :1,
87
+ },
88
+ }
89
+ defaultValue.root.children[0].children[0].text = value
90
+ return JSON.stringify(defaultValue)
91
+ }
92
+ }
93
+
94
+ const onChange = (state) => {
95
+ formik.setValues({
96
+ ...formik.values,
97
+ [name]:JSON.stringify(state),
98
+ })
99
+ }
100
+
101
+ const initialConfig = {
102
+ nameSpace :name,
103
+ editable :!disabled,
104
+ editorState:setInitialValue(),
105
+ theme :{
106
+ text:{
107
+ italic :'italic',
108
+ strikethrough:'strikethrough',
109
+ underline :'underlined',
110
+ },
111
+ },
112
+ nodes:[
113
+ AutoLinkNode,
114
+ LinkNode,
115
+ ListNode,
116
+ ListItemNode,
117
+ ],
118
+ }
119
+
120
+ return (
121
+ <LexicalComposer
122
+ initialConfig={initialConfig}
123
+ >
124
+ <div
125
+ id={id}
126
+ className={[
127
+ baseClassName,
128
+ componentClassName,
129
+ userClassName,
130
+ `y-${color}`,
131
+ disabled && 'disabled',
132
+ ]
133
+ .filter((e) => e)
134
+ .join(' ')}
135
+ style={{
136
+ ...style,
137
+ '--resize':resize,
138
+ '--rows' :`${rows}em`,
139
+ }}
140
+ >
141
+ <FormLabelV2
142
+ name={name}
143
+ color={labelColor}
144
+ optional={optional}
145
+ >
146
+ {label}
147
+ </FormLabelV2>
148
+
149
+ { !disabled && <Toolbar /> }
150
+ <RichTextPlugin
151
+ contentEditable={(
152
+ <ContentEditable
153
+ id={name}
154
+ className="content-editable"
155
+ />
156
+ )}
157
+ />
158
+ <OnChangePlugin onChange={onChange} />
159
+ <LinkPlugin />
160
+ <ListPlugin />
161
+ <TabIndentationPlugin />
162
+ <HistoryPlugin />
163
+ <FormDescriptionV2 className="s-1" description={description} name={name} />
164
+ { showDebugger && <TreeViewPlugin />}
165
+ </div>
166
+ </LexicalComposer>
167
+ )
168
+ }
169
+
170
+ EditorInput.propTypes = {
171
+ /**
172
+ * The HTML id for this element
173
+ */
174
+ id:PropTypes.string,
175
+
176
+ /**
177
+ * The HTML class names for this element
178
+ */
179
+ className:PropTypes.string,
180
+
181
+ /**
182
+ * The React-written, css properties for this element.
183
+ */
184
+ style:PropTypes.objectOf(PropTypes.string),
185
+
186
+ /**
187
+ * The input name (html - and Formik state)
188
+ */
189
+ name:PropTypes.string.isRequired,
190
+
191
+ /**
192
+ * The input label
193
+ */
194
+ label:PropTypes.string.isRequired,
195
+
196
+ /**
197
+ * The input value validator function
198
+ */
199
+ // validate:PropTypes.func,
200
+
201
+ /**
202
+ * The number of rows int the text area
203
+ */
204
+ rows:PropTypes.number,
205
+
206
+ /**
207
+ * Color of the text
208
+ */
209
+ color:PropTypes.string,
210
+
211
+ /**
212
+ * Label base color
213
+ */
214
+ labelColor:PropTypes.string,
215
+
216
+ /**
217
+ * Text area description
218
+ */
219
+ description:PropTypes.string,
220
+
221
+ /**
222
+ * Whether the text area should be disabled
223
+ */
224
+ disabled:PropTypes.bool,
225
+
226
+ /**
227
+ * Whether the input is optional or not
228
+ */
229
+ optional:PropTypes.bool,
230
+
231
+ /**
232
+ * The resize property of the text area
233
+ */
234
+ resize:PropTypes.oneOf(['none', 'both', 'horizontal', 'vertical']),
235
+ }
236
+
237
+ EditorInput.defaultProps = {
238
+ rows :10,
239
+ disabled:false,
240
+ color :'paragraph',
241
+ resize :'vertical',
242
+ }
243
+
244
+ export default memo(EditorInput)
@@ -0,0 +1,356 @@
1
+ /* eslint-disable import/no-extraneous-dependencies -- required here */
2
+ import * as React from 'react'
3
+
4
+ import {
5
+ useEffect,
6
+ useState,
7
+ useCallback,
8
+ useRef,
9
+ } from 'react'
10
+
11
+ import {
12
+ $getSelection,
13
+ $isRangeSelection,
14
+ FORMAT_TEXT_COMMAND,
15
+ FORMAT_ELEMENT_COMMAND,
16
+ UNDO_COMMAND,
17
+ REDO_COMMAND,
18
+ COMMAND_PRIORITY_NORMAL,
19
+ createCommand,
20
+ } from 'lexical'
21
+ import {
22
+ INSERT_ORDERED_LIST_COMMAND,
23
+ INSERT_UNORDERED_LIST_COMMAND,
24
+ REMOVE_LIST_COMMAND,
25
+ $isListNode,
26
+ ListNode,
27
+ } from '@lexical/list'
28
+ import {
29
+ $isAtNodeEnd,
30
+ } from '@lexical/selection'
31
+ import {
32
+ $isLinkNode,
33
+ TOGGLE_LINK_COMMAND,
34
+ } from '@lexical/link'
35
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
36
+ import { mergeRegister, $getNearestNodeOfType } from '@lexical/utils'
37
+
38
+ import { Popover } from 'ui'
39
+
40
+ import styleNames from '@pareto-engineering/bem/exports'
41
+
42
+ const baseClassName = styleNames.base
43
+
44
+ const componentClassName = 'toolbar'
45
+
46
+ const getSelectedNode = (selection) => {
47
+ const { anchor, focus } = selection
48
+ const anchorNode = selection.anchor.getNode()
49
+ const focusNode = selection.focus.getNode()
50
+ if (anchorNode === focusNode) {
51
+ return anchorNode
52
+ }
53
+ const isBackward = selection.isBackward()
54
+ if (isBackward) {
55
+ return $isAtNodeEnd(focus) ? anchorNode : focusNode
56
+ }
57
+ return $isAtNodeEnd(anchor) ? focusNode : anchorNode
58
+ }
59
+
60
+ const defaultColor = 'var(--paragraph)'
61
+
62
+ const colorOptions = [
63
+ 'red',
64
+ 'blue',
65
+ 'green',
66
+ 'yellow',
67
+ 'orange',
68
+ 'purple',
69
+ 'pink',
70
+ 'brown',
71
+ ]
72
+
73
+ const Toolbar = () => {
74
+ const [editor] = useLexicalComposerContext()
75
+ const [isBold, setIsBold] = useState(false)
76
+ const [isItalic, setIsItalic] = useState(false)
77
+ const [isStrikethrough, setIsStrikethrough] = useState(false)
78
+ const [blockType, setBlockType] = useState('paragraph')
79
+ const [isLink, setIsLink] = useState(false)
80
+ const [isUnderline, setIsUnderline] = useState(false)
81
+ const [color, setColor] = useState(defaultColor)
82
+
83
+ const colorMenuRef = useRef(false)
84
+
85
+ const formatBulletList = () => {
86
+ if (blockType !== 'ul') {
87
+ editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND)
88
+ } else {
89
+ editor.dispatchCommand(REMOVE_LIST_COMMAND)
90
+ }
91
+ }
92
+
93
+ const formatNumberedList = () => {
94
+ if (blockType !== 'ol') {
95
+ editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND)
96
+ } else {
97
+ editor.dispatchCommand(REMOVE_LIST_COMMAND)
98
+ }
99
+ }
100
+
101
+ const formatLink = useCallback(() => {
102
+ if (!isLink) {
103
+ // eslint-disable-next-line no-alert
104
+ const path = prompt('Enter the full URL. Ex: https://www.example.com')
105
+ editor.dispatchCommand(TOGGLE_LINK_COMMAND, path)
106
+ } else {
107
+ editor.dispatchCommand(TOGGLE_LINK_COMMAND, null)
108
+ }
109
+ }, [editor, isLink])
110
+
111
+ const updateToolbar = useCallback(() => {
112
+ const selection = $getSelection()
113
+
114
+ // Check list selection
115
+ if ($isRangeSelection(selection)) {
116
+ const anchorNode = selection.anchor.getNode()
117
+ const element = anchorNode.getKey() === 'root'
118
+ ? anchorNode
119
+ : anchorNode.getTopLevelElementOrThrow()
120
+ if ($isListNode(element)) {
121
+ const parentList = $getNearestNodeOfType(anchorNode, ListNode)
122
+ const type = parentList ? parentList.getTag() : element.getTag()
123
+ setBlockType(type)
124
+ } else {
125
+ setBlockType(element)
126
+ }
127
+
128
+ // Check nodes for color
129
+ const nodes = selection.getNodes().filter((node) => node.getType() === 'text')
130
+ nodes.forEach((node) => {
131
+ const style = node.getStyle()
132
+ const colorProperty = style.match(/color: ([^;]+)/)
133
+ if (colorProperty) {
134
+ setColor(colorProperty[1])
135
+ return
136
+ }
137
+ setColor(false)
138
+ })
139
+
140
+ // Check selection text styles
141
+ setIsBold(selection.hasFormat('bold'))
142
+ setIsItalic(selection.hasFormat('italic'))
143
+ setIsStrikethrough(selection.hasFormat('strikethrough'))
144
+ setIsUnderline(selection.hasFormat('underline'))
145
+ setIsLink(selection.hasFormat('link'))
146
+
147
+ // Check links
148
+ const node = getSelectedNode(selection)
149
+ const parent = node.getParent()
150
+ if ($isLinkNode(parent) || $isLinkNode(node)) {
151
+ setIsLink(true)
152
+ } else {
153
+ setIsLink(false)
154
+ }
155
+ }
156
+ }, [editor])
157
+
158
+ const UPDATE_COLOR_COMMAND = createCommand()
159
+
160
+ editor.registerCommand(UPDATE_COLOR_COMMAND, (payload) => {
161
+ const selection = $getSelection()
162
+ const nodes = selection?.extract().filter((node) => node.getType() === 'text')
163
+ nodes?.forEach((node) => {
164
+ const style = node.getStyle()
165
+ const colorProperty = style?.match(/color: ([^;]+)/)
166
+ if (colorProperty && color !== payload) {
167
+ node.setStyle(style.replace(colorProperty[0], `color: ${payload}`))
168
+ } else if (colorProperty) {
169
+ node.setStyle(`color: ${defaultColor}`)
170
+ } else {
171
+ node.setStyle(`color: ${payload}`)
172
+ }
173
+ })
174
+ }, COMMAND_PRIORITY_NORMAL)
175
+
176
+ useEffect(() => mergeRegister(
177
+ editor.registerUpdateListener(({ editorState }) => {
178
+ editorState.read(() => {
179
+ updateToolbar()
180
+ })
181
+ }),
182
+ ), [updateToolbar, editor])
183
+
184
+ const dispatchUpdateColor = useCallback((e, payload) => {
185
+ e.stopPropagation()
186
+ editor.dispatchCommand(UPDATE_COLOR_COMMAND, payload)
187
+ }, [editor])
188
+
189
+ return (
190
+ <div className={`${baseClassName} ${componentClassName}`}>
191
+ <div className="group">
192
+ <button
193
+ type="button"
194
+ className={isBold ? 'active' : undefined}
195
+ onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold')}
196
+ >
197
+ <span className="icon">
198
+ |
199
+ </span>
200
+ </button>
201
+ <button
202
+ type="button"
203
+ className={isItalic ? 'active' : undefined}
204
+ onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'italic')}
205
+ >
206
+ <span className="icon">
207
+ &#125;
208
+ </span>
209
+ </button>
210
+ <button
211
+ type="button"
212
+ className={isUnderline ? 'active' : undefined}
213
+ onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'underline')}
214
+ >
215
+ <span className="icon">
216
+ ~
217
+ </span>
218
+ </button>
219
+ <button
220
+ type="button"
221
+ className={isStrikethrough ? 'active' : undefined}
222
+ onClick={() => editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'strikethrough')}
223
+ >
224
+ <span className="icon">
225
+ ?
226
+ </span>
227
+ </button>
228
+ <button
229
+ type="button"
230
+ className={color && color !== defaultColor ? 'active color-menu-button' : 'color-menu-button'}
231
+ onClick={() => editor.dispatchCommand(UPDATE_COLOR_COMMAND,
232
+ color !== defaultColor ? defaultColor : color)}
233
+ ref={colorMenuRef}
234
+ style={{ position: 'relative' }}
235
+ >
236
+ <span
237
+ className="icon"
238
+ style={{
239
+ color,
240
+ }}
241
+ >
242
+ Q
243
+ </span>
244
+ <Popover
245
+ parentRef={colorMenuRef}
246
+ >
247
+ <div className="color-menu">
248
+ {
249
+ colorOptions.map((option) => (
250
+ <span
251
+ role="button"
252
+ className="icon color-option"
253
+ style={{
254
+ color:option,
255
+ }}
256
+ onClick={(e) => dispatchUpdateColor(e, option)}
257
+ onKeyDown={(e) => dispatchUpdateColor(e, option)}
258
+ tabIndex={0}
259
+ key={option}
260
+ >
261
+ o
262
+ </span>
263
+ ))
264
+ }
265
+ </div>
266
+ </Popover>
267
+ </button>
268
+
269
+ <button
270
+ type="button"
271
+ className={isLink ? 'active' : undefined}
272
+ onClick={() => formatLink()}
273
+ >
274
+ <span className="icon">
275
+ &#93;
276
+ </span>
277
+ </button>
278
+ <button
279
+ type="button"
280
+ className={blockType === 'ul' ? 'active' : undefined}
281
+ onClick={() => formatBulletList()}
282
+ >
283
+ <span className="icon">
284
+ .
285
+ </span>
286
+ </button>
287
+ <button
288
+ type="button"
289
+ className={blockType === 'ol' ? 'active' : undefined}
290
+ onClick={() => formatNumberedList()}
291
+ >
292
+ <span className="icon">
293
+ -
294
+ </span>
295
+ </button>
296
+ </div>
297
+
298
+ <div className="group">
299
+ <button
300
+ type="button"
301
+ onClick={() => editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'left')}
302
+ >
303
+ <span className="icon">
304
+ ^
305
+ </span>
306
+ </button>
307
+ <button
308
+ type="button"
309
+ onClick={() => editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'center')}
310
+ >
311
+ <span className="icon">
312
+ _
313
+ </span>
314
+ </button>
315
+ <button
316
+ type="button"
317
+ onClick={() => editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'right')}
318
+ >
319
+ <span className="icon">
320
+ `
321
+ </span>
322
+ </button>
323
+ <button
324
+ type="button"
325
+ onClick={() => editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'justify')}
326
+ >
327
+ <span className="icon">
328
+ &#123;
329
+ </span>
330
+ </button>
331
+ </div>
332
+
333
+ <div className="group">
334
+ <button
335
+ type="button"
336
+ onClick={() => editor.dispatchCommand(UNDO_COMMAND)}
337
+ >
338
+ <span className="icon">
339
+ \
340
+ </span>
341
+ </button>
342
+ <button
343
+ type="button"
344
+ className="flip"
345
+ onClick={() => editor.dispatchCommand(REDO_COMMAND)}
346
+ >
347
+ <span className="icon">
348
+ \
349
+ </span>
350
+ </button>
351
+ </div>
352
+ </div>
353
+ )
354
+ }
355
+
356
+ export default Toolbar
@@ -0,0 +1,16 @@
1
+ import React from 'react'
2
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
3
+ import { TreeView } from '@lexical/react/LexicalTreeView'
4
+
5
+ const TreeViewPlugin = () => {
6
+ const [editor] = useLexicalComposerContext()
7
+
8
+ return (
9
+ <TreeView
10
+ viewClassName="tree-view-output"
11
+ editor={editor}
12
+ />
13
+ )
14
+ }
15
+
16
+ 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'