@cloud-ru/ds-markdown 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +201 -0
  3. package/README.md +273 -0
  4. package/dist/cjs/components/Markdown/CodeBlock.d.ts +9 -0
  5. package/dist/cjs/components/Markdown/CodeBlock.js +58 -0
  6. package/dist/cjs/components/Markdown/Markdown.d.ts +2 -0
  7. package/dist/cjs/components/Markdown/Markdown.js +25 -0
  8. package/dist/cjs/components/Markdown/index.d.ts +1 -0
  9. package/dist/cjs/components/Markdown/index.js +17 -0
  10. package/dist/cjs/components/Markdown/styles.module.css +205 -0
  11. package/dist/cjs/components/MarkdownEditor/MarkdownEditor.d.ts +2 -0
  12. package/dist/cjs/components/MarkdownEditor/MarkdownEditor.js +176 -0
  13. package/dist/cjs/components/MarkdownEditor/index.d.ts +1 -0
  14. package/dist/cjs/components/MarkdownEditor/index.js +17 -0
  15. package/dist/cjs/components/MarkdownEditor/styles.module.css +273 -0
  16. package/dist/cjs/components/Toolbar/Toolbar.d.ts +9 -0
  17. package/dist/cjs/components/Toolbar/Toolbar.js +173 -0
  18. package/dist/cjs/components/Toolbar/constants.d.ts +13 -0
  19. package/dist/cjs/components/Toolbar/constants.js +40 -0
  20. package/dist/cjs/components/Toolbar/hooks/index.d.ts +2 -0
  21. package/dist/cjs/components/Toolbar/hooks/index.js +18 -0
  22. package/dist/cjs/components/Toolbar/hooks/useToolbarHotkeys.d.ts +21 -0
  23. package/dist/cjs/components/Toolbar/hooks/useToolbarHotkeys.js +59 -0
  24. package/dist/cjs/components/Toolbar/hooks/useToolbarOverflow.d.ts +14 -0
  25. package/dist/cjs/components/Toolbar/hooks/useToolbarOverflow.js +87 -0
  26. package/dist/cjs/components/Toolbar/index.d.ts +2 -0
  27. package/dist/cjs/components/Toolbar/index.js +20 -0
  28. package/dist/cjs/components/Toolbar/styles.module.css +17 -0
  29. package/dist/cjs/components/index.d.ts +2 -0
  30. package/dist/cjs/components/index.js +20 -0
  31. package/dist/cjs/constants.d.ts +65 -0
  32. package/dist/cjs/constants.js +67 -0
  33. package/dist/cjs/helperComponents/ButtonHeading/ButtonHeading.d.ts +6 -0
  34. package/dist/cjs/helperComponents/ButtonHeading/ButtonHeading.js +61 -0
  35. package/dist/cjs/helperComponents/ButtonHeading/index.d.ts +1 -0
  36. package/dist/cjs/helperComponents/ButtonHeading/index.js +17 -0
  37. package/dist/cjs/helperComponents/ButtonHeading/styles.module.css +3 -0
  38. package/dist/cjs/helperComponents/Buttons/Buttons.d.ts +10 -0
  39. package/dist/cjs/helperComponents/Buttons/Buttons.js +21 -0
  40. package/dist/cjs/helperComponents/Buttons/index.d.ts +1 -0
  41. package/dist/cjs/helperComponents/Buttons/index.js +17 -0
  42. package/dist/cjs/helperComponents/Buttons/styles.module.css +17 -0
  43. package/dist/cjs/helperComponents/Modals/CustomizeTableModal.d.ts +8 -0
  44. package/dist/cjs/helperComponents/Modals/CustomizeTableModal.js +39 -0
  45. package/dist/cjs/helperComponents/Modals/ImageModal.d.ts +7 -0
  46. package/dist/cjs/helperComponents/Modals/ImageModal.js +44 -0
  47. package/dist/cjs/helperComponents/Modals/LinkModal.d.ts +13 -0
  48. package/dist/cjs/helperComponents/Modals/LinkModal.js +42 -0
  49. package/dist/cjs/helperComponents/Modals/index.d.ts +3 -0
  50. package/dist/cjs/helperComponents/Modals/index.js +19 -0
  51. package/dist/cjs/helperComponents/Modals/styles.module.css +17 -0
  52. package/dist/cjs/helperComponents/PrivateButton/PrivateButton.d.ts +17 -0
  53. package/dist/cjs/helperComponents/PrivateButton/PrivateButton.js +27 -0
  54. package/dist/cjs/helperComponents/PrivateButton/index.d.ts +1 -0
  55. package/dist/cjs/helperComponents/PrivateButton/index.js +17 -0
  56. package/dist/cjs/helperComponents/PrivateButton/styles.module.css +140 -0
  57. package/dist/cjs/helperComponents/TableSelectItem/TableSelectItem.d.ts +11 -0
  58. package/dist/cjs/helperComponents/TableSelectItem/TableSelectItem.js +12 -0
  59. package/dist/cjs/helperComponents/TableSelectItem/index.d.ts +1 -0
  60. package/dist/cjs/helperComponents/TableSelectItem/index.js +17 -0
  61. package/dist/cjs/helperComponents/TableSelectItem/styles.module.css +101 -0
  62. package/dist/cjs/helperComponents/TableSelectSettingsGrid/TableSelectSettingsGrid.d.ts +4 -0
  63. package/dist/cjs/helperComponents/TableSelectSettingsGrid/TableSelectSettingsGrid.js +27 -0
  64. package/dist/cjs/helperComponents/TableSelectSettingsGrid/index.d.ts +1 -0
  65. package/dist/cjs/helperComponents/TableSelectSettingsGrid/index.js +17 -0
  66. package/dist/cjs/helperComponents/TableSelectSettingsGrid/styles.module.css +54 -0
  67. package/dist/cjs/helperComponents/index.d.ts +6 -0
  68. package/dist/cjs/helperComponents/index.js +22 -0
  69. package/dist/cjs/index.d.ts +4 -0
  70. package/dist/cjs/index.js +20 -0
  71. package/dist/cjs/locale/index.d.ts +199 -0
  72. package/dist/cjs/locale/index.js +104 -0
  73. package/dist/cjs/lowlight.d.ts +14 -0
  74. package/dist/cjs/lowlight.js +35 -0
  75. package/dist/cjs/mixins.css +0 -0
  76. package/dist/cjs/package.json +3 -0
  77. package/dist/cjs/rawMarkdownCommands.d.ts +16 -0
  78. package/dist/cjs/rawMarkdownCommands.js +145 -0
  79. package/dist/cjs/style.css +875 -0
  80. package/dist/cjs/styles/syntax.module.css +47 -0
  81. package/dist/cjs/toolbarApi.d.ts +33 -0
  82. package/dist/cjs/toolbarApi.js +100 -0
  83. package/dist/cjs/types.d.ts +52 -0
  84. package/dist/cjs/types.js +2 -0
  85. package/dist/esm/components/Markdown/CodeBlock.d.ts +9 -0
  86. package/dist/esm/components/Markdown/CodeBlock.js +52 -0
  87. package/dist/esm/components/Markdown/Markdown.d.ts +2 -0
  88. package/dist/esm/components/Markdown/Markdown.js +19 -0
  89. package/dist/esm/components/Markdown/index.d.ts +1 -0
  90. package/dist/esm/components/Markdown/index.js +1 -0
  91. package/dist/esm/components/Markdown/styles.module.css +205 -0
  92. package/dist/esm/components/MarkdownEditor/MarkdownEditor.d.ts +2 -0
  93. package/dist/esm/components/MarkdownEditor/MarkdownEditor.js +170 -0
  94. package/dist/esm/components/MarkdownEditor/index.d.ts +1 -0
  95. package/dist/esm/components/MarkdownEditor/index.js +1 -0
  96. package/dist/esm/components/MarkdownEditor/styles.module.css +273 -0
  97. package/dist/esm/components/Toolbar/Toolbar.d.ts +9 -0
  98. package/dist/esm/components/Toolbar/Toolbar.js +167 -0
  99. package/dist/esm/components/Toolbar/constants.d.ts +13 -0
  100. package/dist/esm/components/Toolbar/constants.js +37 -0
  101. package/dist/esm/components/Toolbar/hooks/index.d.ts +2 -0
  102. package/dist/esm/components/Toolbar/hooks/index.js +2 -0
  103. package/dist/esm/components/Toolbar/hooks/useToolbarHotkeys.d.ts +21 -0
  104. package/dist/esm/components/Toolbar/hooks/useToolbarHotkeys.js +56 -0
  105. package/dist/esm/components/Toolbar/hooks/useToolbarOverflow.d.ts +14 -0
  106. package/dist/esm/components/Toolbar/hooks/useToolbarOverflow.js +84 -0
  107. package/dist/esm/components/Toolbar/index.d.ts +2 -0
  108. package/dist/esm/components/Toolbar/index.js +2 -0
  109. package/dist/esm/components/Toolbar/styles.module.css +17 -0
  110. package/dist/esm/components/index.d.ts +2 -0
  111. package/dist/esm/components/index.js +4 -0
  112. package/dist/esm/constants.d.ts +65 -0
  113. package/dist/esm/constants.js +61 -0
  114. package/dist/esm/helperComponents/ButtonHeading/ButtonHeading.d.ts +6 -0
  115. package/dist/esm/helperComponents/ButtonHeading/ButtonHeading.js +55 -0
  116. package/dist/esm/helperComponents/ButtonHeading/index.d.ts +1 -0
  117. package/dist/esm/helperComponents/ButtonHeading/index.js +1 -0
  118. package/dist/esm/helperComponents/ButtonHeading/styles.module.css +3 -0
  119. package/dist/esm/helperComponents/Buttons/Buttons.d.ts +10 -0
  120. package/dist/esm/helperComponents/Buttons/Buttons.js +13 -0
  121. package/dist/esm/helperComponents/Buttons/index.d.ts +1 -0
  122. package/dist/esm/helperComponents/Buttons/index.js +1 -0
  123. package/dist/esm/helperComponents/Buttons/styles.module.css +17 -0
  124. package/dist/esm/helperComponents/Modals/CustomizeTableModal.d.ts +8 -0
  125. package/dist/esm/helperComponents/Modals/CustomizeTableModal.js +33 -0
  126. package/dist/esm/helperComponents/Modals/ImageModal.d.ts +7 -0
  127. package/dist/esm/helperComponents/Modals/ImageModal.js +38 -0
  128. package/dist/esm/helperComponents/Modals/LinkModal.d.ts +13 -0
  129. package/dist/esm/helperComponents/Modals/LinkModal.js +36 -0
  130. package/dist/esm/helperComponents/Modals/index.d.ts +3 -0
  131. package/dist/esm/helperComponents/Modals/index.js +3 -0
  132. package/dist/esm/helperComponents/Modals/styles.module.css +17 -0
  133. package/dist/esm/helperComponents/PrivateButton/PrivateButton.d.ts +17 -0
  134. package/dist/esm/helperComponents/PrivateButton/PrivateButton.js +21 -0
  135. package/dist/esm/helperComponents/PrivateButton/index.d.ts +1 -0
  136. package/dist/esm/helperComponents/PrivateButton/index.js +1 -0
  137. package/dist/esm/helperComponents/PrivateButton/styles.module.css +140 -0
  138. package/dist/esm/helperComponents/TableSelectItem/TableSelectItem.d.ts +11 -0
  139. package/dist/esm/helperComponents/TableSelectItem/TableSelectItem.js +6 -0
  140. package/dist/esm/helperComponents/TableSelectItem/index.d.ts +1 -0
  141. package/dist/esm/helperComponents/TableSelectItem/index.js +1 -0
  142. package/dist/esm/helperComponents/TableSelectItem/styles.module.css +101 -0
  143. package/dist/esm/helperComponents/TableSelectSettingsGrid/TableSelectSettingsGrid.d.ts +4 -0
  144. package/dist/esm/helperComponents/TableSelectSettingsGrid/TableSelectSettingsGrid.js +21 -0
  145. package/dist/esm/helperComponents/TableSelectSettingsGrid/index.d.ts +1 -0
  146. package/dist/esm/helperComponents/TableSelectSettingsGrid/index.js +1 -0
  147. package/dist/esm/helperComponents/TableSelectSettingsGrid/styles.module.css +54 -0
  148. package/dist/esm/helperComponents/index.d.ts +6 -0
  149. package/dist/esm/helperComponents/index.js +6 -0
  150. package/dist/esm/index.d.ts +4 -0
  151. package/dist/esm/index.js +4 -0
  152. package/dist/esm/locale/index.d.ts +199 -0
  153. package/dist/esm/locale/index.js +101 -0
  154. package/dist/esm/lowlight.d.ts +14 -0
  155. package/dist/esm/lowlight.js +29 -0
  156. package/dist/esm/mixins.css +0 -0
  157. package/dist/esm/rawMarkdownCommands.d.ts +16 -0
  158. package/dist/esm/rawMarkdownCommands.js +135 -0
  159. package/dist/esm/style.css +875 -0
  160. package/dist/esm/styles/syntax.module.css +47 -0
  161. package/dist/esm/toolbarApi.d.ts +33 -0
  162. package/dist/esm/toolbarApi.js +96 -0
  163. package/dist/esm/types.d.ts +52 -0
  164. package/dist/esm/types.js +1 -0
  165. package/dist/tsconfig.cjs.tsbuildinfo +1 -0
  166. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  167. package/package.json +84 -0
  168. package/src/components/Markdown/CodeBlock.tsx +96 -0
  169. package/src/components/Markdown/Markdown.tsx +47 -0
  170. package/src/components/Markdown/index.ts +1 -0
  171. package/src/components/Markdown/styles.module.scss +105 -0
  172. package/src/components/MarkdownEditor/MarkdownEditor.tsx +322 -0
  173. package/src/components/MarkdownEditor/index.ts +1 -0
  174. package/src/components/MarkdownEditor/styles.module.scss +201 -0
  175. package/src/components/Toolbar/Toolbar.tsx +292 -0
  176. package/src/components/Toolbar/constants.tsx +63 -0
  177. package/src/components/Toolbar/hooks/index.ts +2 -0
  178. package/src/components/Toolbar/hooks/useToolbarHotkeys.ts +74 -0
  179. package/src/components/Toolbar/hooks/useToolbarOverflow.ts +102 -0
  180. package/src/components/Toolbar/index.ts +2 -0
  181. package/src/components/Toolbar/styles.module.scss +29 -0
  182. package/src/components/index.ts +4 -0
  183. package/src/constants.ts +67 -0
  184. package/src/helperComponents/ButtonHeading/ButtonHeading.tsx +100 -0
  185. package/src/helperComponents/ButtonHeading/index.ts +1 -0
  186. package/src/helperComponents/ButtonHeading/styles.module.scss +5 -0
  187. package/src/helperComponents/Buttons/Buttons.tsx +30 -0
  188. package/src/helperComponents/Buttons/index.ts +1 -0
  189. package/src/helperComponents/Buttons/styles.module.scss +26 -0
  190. package/src/helperComponents/Modals/CustomizeTableModal.tsx +82 -0
  191. package/src/helperComponents/Modals/ImageModal.tsx +84 -0
  192. package/src/helperComponents/Modals/LinkModal.tsx +92 -0
  193. package/src/helperComponents/Modals/index.ts +3 -0
  194. package/src/helperComponents/Modals/styles.module.scss +21 -0
  195. package/src/helperComponents/PrivateButton/PrivateButton.tsx +88 -0
  196. package/src/helperComponents/PrivateButton/index.ts +1 -0
  197. package/src/helperComponents/PrivateButton/styles.module.scss +77 -0
  198. package/src/helperComponents/TableSelectItem/TableSelectItem.tsx +43 -0
  199. package/src/helperComponents/TableSelectItem/index.ts +1 -0
  200. package/src/helperComponents/TableSelectItem/styles.module.scss +26 -0
  201. package/src/helperComponents/TableSelectSettingsGrid/TableSelectSettingsGrid.tsx +48 -0
  202. package/src/helperComponents/TableSelectSettingsGrid/index.ts +1 -0
  203. package/src/helperComponents/TableSelectSettingsGrid/styles.module.scss +65 -0
  204. package/src/helperComponents/index.ts +6 -0
  205. package/src/index.ts +4 -0
  206. package/src/locale/index.ts +105 -0
  207. package/src/lowlight.ts +30 -0
  208. package/src/mixins.scss +123 -0
  209. package/src/rawMarkdownCommands.ts +179 -0
  210. package/src/styles/syntax.module.scss +54 -0
  211. package/src/toolbarApi.ts +152 -0
  212. package/src/types.ts +56 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # 1.0.0 (2026-08-18)
7
+
8
+ Initial stable release under the `@cloud-ru/ds-*` scope.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2023 Cloud technology Limited (Ltd.)
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,273 @@
1
+ # Markdown
2
+
3
+ `@cloud-ru/ds-markdown` — Просмотр и редактирование markdown — рендер GFM и WYSIWYG-редактор на TipTap.
4
+
5
+ Пакет `@cloud-ru/ds-markdown` даёт две независимые сущности:
6
+
7
+ - ****Markdown**** — рендер markdown-строки в безопасный HTML: GFM, таблицы, подсветка кода с копированием. Презентационный компонент только для чтения.
8
+ - ****MarkdownEditor**** — WYSIWYG-редактор на TipTap с тулбаром, preview-тоглом и загрузкой картинок. Работает в controlled и uncontrolled режимах.
9
+
10
+ ## Установка
11
+
12
+ ```bash
13
+ pnpm add @cloud-ru/ds-markdown
14
+ ```
15
+
16
+ ```ts
17
+ import { Markdown, MarkdownEditor, TOOLBAR_ITEM } from '@cloud-ru/ds-markdown'
18
+ ```
19
+
20
+ Редактор использует порталы (тултипы, выпадающие меню) — оборачивайте его в `PortalContextProvider` из `@cloud-ru/ds-portal-context`.
21
+
22
+ ## Markdown
23
+
24
+ Рендер markdown-строки в безопасный HTML — GFM, таблицы, зачёркивание, подсветка кода с кнопкой копирования.
25
+
26
+ Презентационный компонент: принимает `value` со строкой markdown и рендерит её в безопасный HTML. Поддерживает GitHub Flavored Markdown, подсветку кода и копирование code-блоков. Только для чтения — для ввода используйте **`MarkdownEditor`**.
27
+
28
+ ### Когда использовать
29
+
30
+ - Отображение пользовательского markdown: описания, комментарии, документация, release notes.
31
+ - Показ форматированного текста, сохранённого редактором, в публичной части интерфейса.
32
+
33
+ Когда **не** нужен:
34
+
35
+ - Для простого многострочного текста без форматирования:
36
+ - нативный `textarea` или поле ввода из `@cloud-ru/ds-fields`.
37
+ - Для подсветки изолированного фрагмента кода без markdown:
38
+ - отдельный code-viewer.
39
+
40
+ ### Анатомия
41
+
42
+ #### View — рендер
43
+
44
+ Принимает `value` со строкой markdown и рендерит:
45
+
46
+ - заголовки `h1–h5`, параграфы, списки (маркированные, нумерованные, вложенные);
47
+ - цитаты, горизонтальные разделители, ссылки;
48
+ - таблицы GFM, зачёркивание, инлайн-код;
49
+ - code-блоки с подсветкой синтаксиса, нумерацией строк и кнопкой копирования.
50
+
51
+ #### skipHtml (default `true`)
52
+
53
+ Контроль над сырым HTML внутри markdown:
54
+
55
+ - `true` (по умолчанию) — теги вырезаются, рендерится только markdown-разметка (безопасно для пользовательского ввода).
56
+ - `false` — сырой HTML пропускается в вывод. Включайте только для доверенного контента.
57
+
58
+ #### Расширение рендера
59
+
60
+ - `components` — override отдельных HTML-элементов своими React-компонентами.
61
+ - `remarkPlugins` / `rehypePlugins` — дополнительные плагины пайплайна `react-markdown`.
62
+ - `onCodeCopyClick` — колбэк кнопки Copy на code-блоке, получает сырой текст блока.
63
+
64
+ ### Примеры использования
65
+
66
+ #### Рендер markdown
67
+
68
+ GFM-таблица, зачёркивание и code-блок с копированием
69
+
70
+ ```tsx
71
+ import { Markdown } from '@cloud-ru/ds-markdown';
72
+
73
+ const SOURCE = `# Релиз 2.0
74
+
75
+ Поддерживается **GFM**: таблицы, ~~зачёркивание~~, списки задач и подсветка кода.
76
+
77
+ | Сервис | Статус |
78
+ |----------|----------|
79
+ | API | стабилен |
80
+ | Realtime | beta |
81
+
82
+ \`\`\`ts
83
+ export function greet(name: string) {
84
+ return \`Hello, \${name}!\`
85
+ }
86
+ \`\`\`
87
+ `;
88
+
89
+ export function Viewer() {
90
+ return <Markdown value={SOURCE} />;
91
+ }
92
+ ```
93
+
94
+ #### Копирование code-блока
95
+
96
+ onCodeCopyClick получает сырой текст блока
97
+
98
+ ```tsx
99
+ import { Markdown } from '@cloud-ru/ds-markdown';
100
+ import { useState } from 'react';
101
+
102
+ const SOURCE = `Нажмите Copy на блоке кода — \`onCodeCopyClick\` получит сырой текст.
103
+
104
+ \`\`\`bash
105
+ pnpm add @cloud-ru/ds-markdown
106
+ \`\`\`
107
+ `;
108
+
109
+ export function ViewerCodeCopy() {
110
+ const [copied, setCopied] = useState<string | null>(null);
111
+
112
+ return (
113
+ <div style={{ display: 'flex', gap: 12, flexWrap: 'wrap', alignItems: 'center' }}>
114
+ <Markdown value={SOURCE} onCodeCopyClick={setCopied} />
115
+ {copied !== null && <span>Скопировано: {copied}</span>}
116
+ </div>
117
+ );
118
+ }
119
+ ```
120
+
121
+ ### Props
122
+
123
+ **MarkdownProps**
124
+
125
+ | Prop | Type | Default | Description |
126
+ |------|------|---------|-------------|
127
+ | `className` | `string` | — | CSS-класс корневого элемента. |
128
+ | `components` | `Components` | — | Override рендера элементов |
129
+ | `data-test-id` | `string` | `markdown` | |
130
+ | `onCodeCopyClick` | `((code: string) => void)` | — | Колбэк кнопки Copy на code-блоке |
131
+ | `rehypePlugins` | `PluggableList` | — | Доп. rehype-плагины |
132
+ | `remarkPlugins` | `PluggableList` | — | Доп. remark-плагины |
133
+ | `skipHtml` | `boolean` | `true` | По умолчанию true — сырой HTML вырезается |
134
+ | `value` | `string` | — | Markdown-исходник |
135
+
136
+ ## MarkdownEditor
137
+
138
+ WYSIWYG-редактор markdown на TipTap — тулбар форматирования, preview-тогл, загрузка картинок, controlled и uncontrolled режимы.
139
+
140
+ WYSIWYG-редактор на TipTap с тулбаром форматирования и preview-тоглом. Работает в controlled (`value` / `onChange`) и uncontrolled (`defaultValue`) режимах. Готовый результат показывайте через **`Markdown`**.
141
+
142
+ ### Когда использовать
143
+
144
+ - Поле ввода форматированного текста с тулбаром и предпросмотром: описания, комментарии, заметки.
145
+ - Редактирование markdown, который потом сохраняется и рендерится в публичной части.
146
+
147
+ Когда **не** нужен:
148
+
149
+ - Для простого многострочного текста без форматирования:
150
+ - нативный `textarea` или поле ввода из `@cloud-ru/ds-fields`.
151
+ - Для показа готового markdown без редактирования:
152
+ - компонент **`Markdown`**.
153
+
154
+ ### Анатомия
155
+
156
+ Редактор состоит из:
157
+
158
+ - `header` — тогл `Preview` слева и подпись (`label`) справа.
159
+ - `toolbar` — кнопки форматирования, сгруппированные по смыслу; лишние сворачиваются в меню «Ещё».
160
+ - `content` — редактируемая область с кнопкой очистки.
161
+
162
+ #### Preview (default `false`)
163
+
164
+ Переключает форму редактирования (обе редактируемы, тулбар работает в обеих):
165
+
166
+ - `false` (по умолчанию) — редактирование «сырого» markdown-текста в textarea. Кнопки тулбара вставляют markdown-разметку (`**жирный**`, `# заголовок`, `- список`) в исходник.
167
+ - `true` — форматированный WYSIWYG-редактор; те же кнопки применяют форматирование к rich-узлам.
168
+
169
+ Управляется тоглом в шапке либо пропами `preview` / `defaultPreview` / `onPreviewChange`.
170
+
171
+ #### Toolbar (default — полный набор)
172
+
173
+ Какие кнопки показать:
174
+
175
+ - `toolbar={[...]}` — массив значений `TOOLBAR_ITEM` (показываются только перечисленные кнопки).
176
+ - `toolbar={false}` — без тулбара.
177
+ - не указан — полный набор кнопок.
178
+
179
+ #### Header (default — виден)
180
+
181
+ Шапка с тоглом Preview и подписью:
182
+
183
+ - `label` — подпись справа. `false` — без подписи.
184
+ - `previewLabel` — текст тогла Preview.
185
+ - `hideHeader` — скрыть шапку целиком.
186
+
187
+ #### Resizable (default `true`)
188
+
189
+ Может ли пользователь менять размеры поля перетаскиванием уголка.
190
+
191
+ ### Примеры использования
192
+
193
+ #### Редактор (uncontrolled)
194
+
195
+ defaultValue + onChange с дебаунсом
196
+
197
+ ```tsx
198
+ import { MarkdownEditor } from '@cloud-ru/ds-markdown';
199
+
200
+ const INITIAL = `# Заметка
201
+
202
+ Печатайте текст и форматируйте его через тулбар. Поддерживается **markdown**.
203
+ `;
204
+
205
+ export function EditorUncontrolled() {
206
+ return <MarkdownEditor defaultValue={INITIAL} placeholder='Начните писать…' />;
207
+ }
208
+ ```
209
+
210
+ #### Редактор (controlled) + Preview
211
+
212
+ value/onChange и preview/onPreviewChange во внешнем стейте
213
+
214
+ ```tsx
215
+ import { MarkdownEditor } from '@cloud-ru/ds-markdown';
216
+ import { useState } from 'react';
217
+
218
+ export function EditorControlled() {
219
+ const [value, setValue] = useState('# Controlled\n\nЗначение хранится во внешнем `useState`.');
220
+ const [preview, setPreview] = useState(false);
221
+
222
+ return (
223
+ <MarkdownEditor value={value} onChange={setValue} preview={preview} onPreviewChange={setPreview} label='Описание' />
224
+ );
225
+ }
226
+ ```
227
+
228
+ #### Свой набор кнопок тулбара
229
+
230
+ toolbar={[...]} оставляет только нужные действия
231
+
232
+ ```tsx
233
+ import { MarkdownEditor, TOOLBAR_ITEM } from '@cloud-ru/ds-markdown';
234
+
235
+ const INITIAL = `Оставьте в тулбаре только нужные кнопки через \`toolbar\`.
236
+ `;
237
+
238
+ export function EditorCustomToolbar() {
239
+ return (
240
+ <MarkdownEditor
241
+ defaultValue={INITIAL}
242
+ label='Комментарий'
243
+ toolbar={[TOOLBAR_ITEM.Bold, TOOLBAR_ITEM.Italic, TOOLBAR_ITEM.Link, TOOLBAR_ITEM.BulletList]}
244
+ />
245
+ );
246
+ }
247
+ ```
248
+
249
+ ### Props
250
+
251
+ **MarkdownEditorProps**
252
+
253
+ | Prop | Type | Default | Description |
254
+ |------|------|---------|-------------|
255
+ | `className` | `string` | — | CSS-класс корневого элемента. |
256
+ | `data-test-id` | `string` | `markdown-editor` | |
257
+ | `defaultPreview` | `boolean` | — | Uncontrolled |
258
+ | `defaultValue` | `string` | — | Uncontrolled |
259
+ | `hideHeader` | `boolean` | `false` | Скрыть шапку с тоглом Preview и подписью |
260
+ | `label` | `string \| false` | `Markdown field` | Подпись в шапке справа. По умолчанию — `Markdown field`. `false` — без подписи. |
261
+ | `onChange` | `((markdown: string) => void)` | — | Колбэк изменения markdown. Вызывается с дебаунсом `ON_CHANGE_DEBOUNCE_MS` после остановки ввода. |
262
+ | `onPreviewChange` | `((preview: boolean) => void)` | — | Колбэк переключения Preview-тогла в шапке |
263
+ | `placeholder` | `string` | — | Placeholder пустого редактора. |
264
+ | `preview` | `boolean` | — | Controlled preview-режим: показывает форматированный WYSIWYG с активным тулбаром. Выключен — редактирование «сырого» markdown-текста в textarea |
265
+ | `previewLabel` | `string` | `Preview` | Текст тогла Preview в шапке. По умолчанию `Preview`. |
266
+ | `resizable` | `boolean` | `true` | Может ли пользователь менять размеры поля перетаскиванием уголка. По умолчанию `true`. |
267
+ | `spellCheck` | `boolean` | `true` | Нативная проверка орфографии (`spellcheck`). По умолчанию `true`. |
268
+ | `toolbar` | `ToolbarItemId` | — | Какие кнопки тулбара показать. false — без тулбара |
269
+ | `value` | `string` | — | Controlled markdown |
270
+
271
+ ##### Related types
272
+
273
+ - `ToolbarItemId` = `"block-code"` \| `"block-quote"` \| `"bold"` \| `"bullet-list"` \| `"heading"` \| `"image"` \| `"inline-code"` \| `"italic"` \| `"link"` \| `"ordered-list"` \| `"strikethrough"` \| `"table"`
@@ -0,0 +1,9 @@
1
+ import { ReactNode } from 'react';
2
+ type CodeBlockProps = {
3
+ /** `<code>`-элемент с подсветкой, который react-markdown передаёт внутрь `pre`. */
4
+ children: ReactNode;
5
+ /** Колбэк на копирование. Получает сырой код блока. */
6
+ onCopyClick?(code: string): void;
7
+ };
8
+ export declare function CodeBlock({ children, onCopyClick }: CodeBlockProps): import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CodeBlock = CodeBlock;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const button_1 = require("@cloud-ru/ds-button");
9
+ const system_1 = require("@cloud-ru/ds-icons/interface/system");
10
+ const scroll_1 = require("@cloud-ru/ds-scroll");
11
+ const utils_1 = require("@cloud-ru/ds-utils");
12
+ const classnames_1 = __importDefault(require("classnames"));
13
+ const react_1 = require("react");
14
+ const constants_1 = require("../../constants");
15
+ const locale_1 = require("../../locale");
16
+ const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
17
+ const LANGUAGE_PATTERN = /language-([\w-]+)/;
18
+ const COPIED_RESET_MS = 1600;
19
+ /** Рекурсивно собирает текстовое содержимое узла — для копирования и подсчёта строк. */
20
+ function extractText(node) {
21
+ if (node === null || node === undefined || typeof node === 'boolean')
22
+ return '';
23
+ if (typeof node === 'string' || typeof node === 'number')
24
+ return String(node);
25
+ if (Array.isArray(node))
26
+ return node.map(extractText).join('');
27
+ if ((0, react_1.isValidElement)(node))
28
+ return extractText(node.props.children);
29
+ return '';
30
+ }
31
+ function CodeBlock({ children, onCopyClick }) {
32
+ const { t } = locale_1.markdownLocale.useTranslations();
33
+ const [copied, setCopied] = (0, react_1.useState)(false);
34
+ const resetTimer = (0, react_1.useRef)(null);
35
+ const codeElement = react_1.Children.toArray(children).find(child => (0, react_1.isValidElement)(child));
36
+ const codeProps = (0, react_1.isValidElement)(codeElement)
37
+ ? codeElement.props
38
+ : { className: '', children };
39
+ const className = codeProps.className ?? '';
40
+ const codeChildren = codeProps.children;
41
+ const language = LANGUAGE_PATTERN.exec(className)?.[1];
42
+ const raw = extractText(codeChildren).replace(/\n$/, '');
43
+ const lineCount = raw.length === 0 ? 1 : raw.split('\n').length;
44
+ const markCopied = () => {
45
+ setCopied(true);
46
+ if (resetTimer.current)
47
+ clearTimeout(resetTimer.current);
48
+ resetTimer.current = setTimeout(() => setCopied(false), COPIED_RESET_MS);
49
+ };
50
+ const handleCopy = () => {
51
+ onCopyClick?.(raw);
52
+ // `copyToClipboard` из @cloud-ru/ds-utils сам падает на execCommand, если Clipboard API недоступен
53
+ // (insecure-context). Ждать результат не нужно: галочка показывается по факту клика.
54
+ (0, utils_1.copyToClipboard)(raw);
55
+ markCopied();
56
+ };
57
+ return ((0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.codeBlock, children: [(0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.codeHeader, children: [(0, jsx_runtime_1.jsx)("span", { className: styles_module_scss_1.default.codeLang, children: language ?? 'text' }), (0, jsx_runtime_1.jsx)(button_1.Button, { view: 'function', appearance: 'neutral', size: 'm', icon: copied ? (0, jsx_runtime_1.jsx)(system_1.CheckSVG, {}) : (0, jsx_runtime_1.jsx)(system_1.CopySVG, {}), className: styles_module_scss_1.default.codeCopy, "data-test-id": constants_1.TEST_IDS.viewerCodeCopy, "data-copied": copied || undefined, "aria-label": copied ? t('copied') : t('copy'), onClick: handleCopy })] }), (0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.codeBody, children: [(0, jsx_runtime_1.jsx)("span", { className: styles_module_scss_1.default.codeGutter, "aria-hidden": 'true', children: Array.from({ length: lineCount }, (_, i) => ((0, jsx_runtime_1.jsx)("span", { className: styles_module_scss_1.default.codeLineNo, children: i + 1 }, i))) }), (0, jsx_runtime_1.jsx)(scroll_1.Scroll, { className: styles_module_scss_1.default.codeScroll, overflow: { y: 'hidden' }, children: (0, jsx_runtime_1.jsx)("pre", { className: styles_module_scss_1.default.codePre, children: (0, jsx_runtime_1.jsx)("code", { className: (0, classnames_1.default)(styles_module_scss_1.default.codeContent, className), children: codeChildren }) }) })] })] }));
58
+ }
@@ -0,0 +1,2 @@
1
+ import { MarkdownProps } from '../../types';
2
+ export declare function Markdown({ value, remarkPlugins, rehypePlugins, components, skipHtml, onCodeCopyClick, className, 'data-test-id': dataTestId, ...rest }: MarkdownProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Markdown = Markdown;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const utils_1 = require("@cloud-ru/ds-utils");
9
+ const classnames_1 = __importDefault(require("classnames"));
10
+ const react_1 = require("react");
11
+ const react_markdown_1 = __importDefault(require("react-markdown"));
12
+ const rehype_highlight_1 = __importDefault(require("rehype-highlight"));
13
+ const remark_gfm_1 = __importDefault(require("remark-gfm"));
14
+ const constants_1 = require("../../constants");
15
+ const syntax_module_scss_1 = __importDefault(require('../../styles/syntax.module.css'));
16
+ const CodeBlock_1 = require("./CodeBlock");
17
+ const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
18
+ function Markdown({ value, remarkPlugins, rehypePlugins, components, skipHtml = true, onCodeCopyClick, className, 'data-test-id': dataTestId = constants_1.TEST_IDS.viewer, ...rest }) {
19
+ const supportProps = (0, utils_1.extractSupportProps)(rest);
20
+ const mergedComponents = (0, react_1.useMemo)(() => ({
21
+ pre: ({ children }) => (0, jsx_runtime_1.jsx)(CodeBlock_1.CodeBlock, { onCopyClick: onCodeCopyClick, children: children }),
22
+ ...components,
23
+ }), [components, onCodeCopyClick]);
24
+ return ((0, jsx_runtime_1.jsx)("div", { ...supportProps, className: (0, classnames_1.default)(styles_module_scss_1.default.root, syntax_module_scss_1.default.syntax, className), "data-test-id": dataTestId, children: (0, jsx_runtime_1.jsx)(react_markdown_1.default, { remarkPlugins: [remark_gfm_1.default, ...(remarkPlugins ?? [])], rehypePlugins: [[rehype_highlight_1.default, { detect: true }], ...(rehypePlugins ?? [])], skipHtml: skipHtml, components: mergedComponents, children: value }) }));
25
+ }
@@ -0,0 +1 @@
1
+ export * from './Markdown';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Markdown"), exports);