@layers-app/editor 0.7.67 → 0.7.69

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 (214) hide show
  1. package/README.md +831 -831
  2. package/dist/index.cjs +2 -2
  3. package/dist/index.js +2 -2
  4. package/dist/{layers.DYFG46Tr.js → layers.-Ruj4Zo5.js} +7 -7
  5. package/dist/{layers.k5y85j83.js → layers.-rEnD-gW.js} +1 -1
  6. package/dist/{layers.Cmx49Y1r.js → layers.0DBGZAux.js} +1 -1
  7. package/dist/{layers.YPnmk6O3.js → layers.0Xr9gi8k.js} +1 -1
  8. package/dist/{layers.CCxJvhDA.js → layers.1h-C3twR.js} +1 -1
  9. package/dist/{layers.CheYGnCO.js → layers.27B-KQHO.js} +3 -3
  10. package/dist/{layers.vxjFabr5.js → layers.29-kZlSC.js} +1 -1
  11. package/dist/{layers.CZr22X_a.js → layers.2oQP3Kd1.js} +1 -1
  12. package/dist/{layers.S3H94rrd.js → layers.5QZeTM8q.js} +1 -1
  13. package/dist/{layers.CXwrOEhA.js → layers.5p0-huXu.js} +1 -1
  14. package/dist/{layers.COikqsOl.js → layers.6-rJJApG.js} +3 -3
  15. package/dist/{layers.DhiNgkiX.js → layers.6u9nN9kL.js} +1 -1
  16. package/dist/{layers.DNJKIVp-.js → layers.7Ceqy3dk.js} +1 -1
  17. package/dist/{layers.BShPUdDb.js → layers.7JPTj9nT.js} +1 -1
  18. package/dist/{layers.DxIVW_gu.js → layers.8mP8G0Aq.js} +1 -1
  19. package/dist/{layers.B8QLJoTK.js → layers.ABwl_epL.js} +1 -1
  20. package/dist/{layers.CrY7oVS3.js → layers.Apre-y7o.js} +24 -24
  21. package/dist/{layers.BKBq22K8.js → layers.B43YGj4m.js} +1 -1
  22. package/dist/{layers.B1weaFHT.js → layers.B5XR7a6d.js} +5 -5
  23. package/dist/layers.B6oRmypa.js +6 -0
  24. package/dist/{layers.DUiJr3Il.js → layers.B8owvN6x.js} +1 -1
  25. package/dist/{layers.DXxLXpLr.js → layers.B9UDpqLV.js} +2 -2
  26. package/dist/{layers.CYuU-K5D.js → layers.BACuuEQj.js} +1 -1
  27. package/dist/{layers.Dq1ww9aa.js → layers.BEBKNx1X.js} +1 -1
  28. package/dist/{layers.CeUIvx4k.js → layers.BEi-TBNF.js} +1 -1
  29. package/dist/{layers.C-iOi-oV.js → layers.BEzidhNG.js} +1 -1
  30. package/dist/{layers.DlKiE7Aa.js → layers.BFSFcjZf.js} +1 -1
  31. package/dist/{layers.CSOoHEpa.js → layers.BKFBrrT0.js} +1 -1
  32. package/dist/{layers.BSUonakO.js → layers.BKWjeNv0.js} +1 -1
  33. package/dist/{layers.BL4Fwha5.js → layers.BNtW40eC.js} +1 -1
  34. package/dist/{layers.BG-zA2JU.js → layers.BOo-MVTB.js} +1 -1
  35. package/dist/{layers.BCG8HyjM.js → layers.BPwGq1IZ.js} +1 -1
  36. package/dist/{layers.mP-gb41G.js → layers.BPxa1qKy.js} +6 -6
  37. package/dist/{layers.CXyGVR7D.js → layers.BQPUKPC6.js} +1 -1
  38. package/dist/{layers.CyshZKpL.js → layers.BQn-BoQ1.js} +1 -1
  39. package/dist/{layers.BNFljsg8.js → layers.BQt-6gJJ.js} +1 -1
  40. package/dist/{layers.ByOjr_px.js → layers.BRMYvE9z.js} +1 -1
  41. package/dist/{layers.Bajn-c5m.js → layers.BRlhY-vC.js} +1 -1
  42. package/dist/{layers.BSPRjhaj.js → layers.BRrmq6iF.js} +1 -1
  43. package/dist/layers.BSQ3Xt_h.js +1 -0
  44. package/dist/{layers.T2PNVGp2.js → layers.BT2p46yj.js} +1 -1
  45. package/dist/{layers.DjrVkP33.js → layers.BTHfw6Y3.js} +1 -1
  46. package/dist/layers.BUjjzt0_.js +8 -0
  47. package/dist/{layers.Bw5ssNYA.js → layers.BVazfLwg.js} +1 -1
  48. package/dist/{layers.C0YOw113.js → layers.BVixMLzr.js} +2 -2
  49. package/dist/{layers.BiH7AvZR.js → layers.BVqcl0kN.js} +1 -1
  50. package/dist/{layers.CtWut0NG.js → layers.BX73rpJr.js} +1 -1
  51. package/dist/{layers.CuZAknCW.js → layers.BXbpW1pa.js} +1 -1
  52. package/dist/{layers.Ck4rTM-7.js → layers.BXxEMH4b.js} +4 -4
  53. package/dist/{layers.DlwH9Z9x.js → layers.BYdLVl8c.js} +2 -2
  54. package/dist/{layers.q9DJ-rL8.js → layers.BazZH6QQ.js} +1 -1
  55. package/dist/{layers.D46738Eo.js → layers.Bdy9X7vh.js} +3 -3
  56. package/dist/{layers.BBv_ZF3c.js → layers.BeUtJKi2.js} +3 -3
  57. package/dist/{layers.uVjYtJ6Y.js → layers.Bf2vZuCE.js} +2 -2
  58. package/dist/{layers.BiGj0vc5.js → layers.BiFdoyLm.js} +1 -1
  59. package/dist/{layers.Dgzoa1kt.js → layers.BiTvj2e-.js} +1 -1
  60. package/dist/{layers.sV4JdJFZ.js → layers.Bikyk_e4.js} +1 -1
  61. package/dist/{layers.BJyksNmy.js → layers.Bj5LxhQF.js} +1 -1
  62. package/dist/{layers.CQf6or_z.js → layers.BjB-nIkz.js} +1 -1
  63. package/dist/{layers.BwJpbvpf.js → layers.BkL_wx9c.js} +1 -1
  64. package/dist/{layers.3Siqoo4I.js → layers.BkOoEzpy.js} +1 -1
  65. package/dist/{layers.vkgKotEx.js → layers.Bkg6bWRU.js} +1 -1
  66. package/dist/{layers.CwtnbUr1.js → layers.Bl49cA_q.js} +1 -1
  67. package/dist/{layers.DhuTIPXp.js → layers.BlDLjKDo.js} +6793 -6785
  68. package/dist/{layers.CKjdaZlk.js → layers.BlxHjIpu.js} +4 -4
  69. package/dist/{layers.BwRTsh3d.js → layers.BmFfrMCv.js} +1 -1
  70. package/dist/{layers.Cvch2giP.js → layers.BnRSfdCn.js} +1 -1
  71. package/dist/{layers.BRKX3PfY.js → layers.Bo0IyTdD.js} +5 -5
  72. package/dist/{layers.B1Nzfkft.js → layers.Bp002Gvn.js} +1 -1
  73. package/dist/{layers.CjqmJwzl.js → layers.BpLCIHmB.js} +1 -1
  74. package/dist/{layers.CvyQ6d-Z.js → layers.BsYppIUT.js} +1 -1
  75. package/dist/{layers.BAPwPDjT.js → layers.Bz-ApnNV.js} +4 -4
  76. package/dist/{layers.l-P06n7a.js → layers.BzvpI1hh.js} +1 -1
  77. package/dist/{layers.Dh7iDEfV.js → layers.C22aJlMR.js} +1 -1
  78. package/dist/{layers.gWeUL3aK.js → layers.C4OQU4VG.js} +1 -1
  79. package/dist/{layers.BCs9mJ8I.js → layers.C4yu73C7.js} +1 -1
  80. package/dist/{layers.DJwBmgHe.js → layers.C65VXHX0.js} +3 -3
  81. package/dist/{layers.Jqcxv6QN.js → layers.C6M4MqIv.js} +1 -1
  82. package/dist/{layers.DEqhh-hg.js → layers.C7ExfGAg.js} +1 -1
  83. package/dist/{layers.B5_CgG6g.js → layers.C8Uasx1W.js} +1 -1
  84. package/dist/{layers.CByOSJZG.js → layers.C8i5OjeA.js} +1 -1
  85. package/dist/{layers.CtoHNDXF.js → layers.C9aLQWLr.js} +1 -1
  86. package/dist/{layers.D6qPSUjk.js → layers.C9m_GsPX.js} +1 -1
  87. package/dist/{layers.e8NXQJQm.js → layers.CB008f5M.js} +1 -1
  88. package/dist/{layers.Mpjs6Fe4.js → layers.CBJ0MOlf.js} +1 -1
  89. package/dist/{layers.DgKb5bcf.js → layers.CCOUMNlV.js} +1 -1
  90. package/dist/{layers.C5TXFJ-N.js → layers.CEQVj5e3.js} +2 -2
  91. package/dist/{layers.C2iGgm96.js → layers.CFdxfEoL.js} +1 -1
  92. package/dist/{layers.tX3Ioek7.js → layers.CFfrUgu3.js} +4 -4
  93. package/dist/{layers.BKDglXbI.js → layers.CIJ4arAq.js} +1 -1
  94. package/dist/{layers.B1OFghlM.js → layers.CJXhO9Ve.js} +1 -1
  95. package/dist/{layers.BmJt8agO.js → layers.CKe87-Ob.js} +1 -1
  96. package/dist/{layers.DTosCorE.js → layers.CMhGAZ1F.js} +1 -1
  97. package/dist/{layers.DVQklNOP.js → layers.CMx7vO0L.js} +1 -1
  98. package/dist/{layers.2RUHqmtf.js → layers.CNP1oZdB.js} +1 -1
  99. package/dist/{layers.B01ypvmX.js → layers.CQz5mJxl.js} +1 -1
  100. package/dist/{layers.BVlHc346.js → layers.CScSVAbT.js} +1 -1
  101. package/dist/{layers.vtF-WeoD.js → layers.CTlCeLwn.js} +1 -1
  102. package/dist/{layers.VCVHBMUK.js → layers.CU1Xj7Xw.js} +1 -1
  103. package/dist/{layers.BOQqn2PA.js → layers.CVOG1MPi.js} +1 -1
  104. package/dist/{layers.FM6xZxio.js → layers.C_BVUEv9.js} +1 -1
  105. package/dist/{layers.BXrOL8gy.js → layers.C_GOAIwQ.js} +4 -4
  106. package/dist/{layers.D8nkEjhP.js → layers.CeAmhUfG.js} +1 -1
  107. package/dist/{layers.DSg6pyBA.js → layers.CeSuEnek.js} +1 -1
  108. package/dist/{layers.dXTUtzTQ.js → layers.Cg1xP3_y.js} +1 -1
  109. package/dist/{layers.5CsDINHO.js → layers.CgDGfwW5.js} +38 -38
  110. package/dist/{layers.9jyPDJ-n.js → layers.CgNnf8Hm.js} +1 -1
  111. package/dist/{layers.BDuKhc3d.js → layers.ChgBnn_C.js} +3 -3
  112. package/dist/{layers.CyMRDTs5.js → layers.CkkOx1Du.js} +1 -1
  113. package/dist/{layers.Dnkwmn9q.js → layers.CmP_wzmD.js} +1 -1
  114. package/dist/{layers.BwAfpdUe.js → layers.CoaCRc82.js} +1 -1
  115. package/dist/{layers.Cz_-Kmw4.js → layers.CouvMYZ_.js} +1 -1
  116. package/dist/{layers.m87Es6h2.js → layers.Cqc8FCdp.js} +4 -4
  117. package/dist/{layers.i6SZVJgZ.js → layers.CrfWp4fJ.js} +1 -1
  118. package/dist/{layers.C5aEOuz2.js → layers.Cu4n_10K.js} +1 -1
  119. package/dist/{layers.CD56zqZU.js → layers.CxG4X8gX.js} +1 -1
  120. package/dist/{layers.Cw8bKJBv.js → layers.Cy4keqhB.js} +1 -1
  121. package/dist/{layers.BaVjOgCV.js → layers.CztaGcF0.js} +1 -1
  122. package/dist/{layers.MloqT3eX.js → layers.D0EoHDuH.js} +1 -1
  123. package/dist/{layers.CNR0G7VK.js → layers.D1ndSKTI.js} +1 -1
  124. package/dist/{layers.Byw6M-0U.js → layers.D264prLn.js} +1 -1
  125. package/dist/{layers.CokDQ6mn.js → layers.D2Y8JbSm.js} +1 -1
  126. package/dist/{layers.Du2OkeaQ.js → layers.D33amGFS.js} +1 -1
  127. package/dist/{layers.aX3AXcWF.js → layers.D4JTY0h0.js} +3 -3
  128. package/dist/{layers.CXYiwz9q.js → layers.D6Zb3uyB.js} +1 -1
  129. package/dist/{layers.BAxXivki.js → layers.D7gubwRv.js} +1 -1
  130. package/dist/{layers.MTa--2B1.js → layers.D85fT96W.js} +4 -4
  131. package/dist/{layers.BAb9hDnX.js → layers.D86KUGFj.js} +1 -1
  132. package/dist/{layers.BqeWwbRi.js → layers.D8zgNYxg.js} +1 -1
  133. package/dist/{layers.B5cX0k6C.js → layers.D9v06W3U.js} +3 -3
  134. package/dist/{layers.DQPeCTce.js → layers.DBVgoS4g.js} +1 -1
  135. package/dist/{layers.Bd16r8QG.js → layers.DCF5TSK6.js} +3 -3
  136. package/dist/{layers.B8Ay8aqV.js → layers.DD3xo4Q7.js} +1 -1
  137. package/dist/{layers.CyWP3KW9.js → layers.DDCXCLxy.js} +1 -1
  138. package/dist/{layers.BWJk4sge.js → layers.DDcNIM5V.js} +1 -1
  139. package/dist/{layers.C8dakIy9.js → layers.DGQ_Ip2d.js} +8 -8
  140. package/dist/{layers.D0xAA1ud.js → layers.DJE4KoOw.js} +1 -1
  141. package/dist/{layers.CLKjBbUW.js → layers.DJhZTayX.js} +1 -1
  142. package/dist/{layers.BXgkzSb7.js → layers.DKf11IZ4.js} +1 -1
  143. package/dist/{layers.BlWgZCCD.js → layers.DLlZvhVA.js} +1 -1
  144. package/dist/{layers.DhgbBqzk.js → layers.DO14DAS1.js} +1 -1
  145. package/dist/{layers.CdoqcLfv.js → layers.DOUMVPFI.js} +1 -1
  146. package/dist/{layers.BWw-7_Ov.js → layers.DOrpTa-Z.js} +1 -1
  147. package/dist/{layers.BDFjv1wT.js → layers.DRqadjGU.js} +1 -1
  148. package/dist/{layers.C8jgYIiB.js → layers.DSFm0uZ6.js} +1 -1
  149. package/dist/{layers.sbMMmbT5.js → layers.DT1WT-jl.js} +1 -1
  150. package/dist/{layers.9MA7hRBy.js → layers.DThNATm6.js} +1 -1
  151. package/dist/{layers.pGiiPqk0.js → layers.DXcnRV7U.js} +1 -1
  152. package/dist/{layers.Bz_ULtvy.js → layers.DZZsW6JV.js} +1 -1
  153. package/dist/{layers.Hd9sKjAt.js → layers.D_dIsPyp.js} +1 -1
  154. package/dist/{layers.BgT_3mLC.js → layers.DaDiP12K.js} +1 -1
  155. package/dist/{layers.Dxh-kUOp.js → layers.Db05xOFS.js} +3 -3
  156. package/dist/{layers.CP5GvLOu.js → layers.Dbdv8-it.js} +1 -1
  157. package/dist/{layers.CBo2Alt6.js → layers.Ddbl4YKu.js} +1 -1
  158. package/dist/{layers.DONsTN3_.js → layers.DeG_vaHA.js} +1 -1
  159. package/dist/layers.Df431v9O.js +1 -0
  160. package/dist/{layers.CGQRH2oE.js → layers.DhtNmWhH.js} +1 -1
  161. package/dist/{layers.ByGHxGYo.js → layers.DlLc2eVa.js} +1 -1
  162. package/dist/{layers.CSkLVEJ4.js → layers.DoCKPdqw.js} +1 -1
  163. package/dist/{layers.YGQlRMs7.js → layers.Dps90Puu.js} +1 -1
  164. package/dist/{layers.D_rloV5d.js → layers.DsrGvHCq.js} +1 -1
  165. package/dist/{layers.eSyy94kL.js → layers.Dt8WcpHM.js} +1 -1
  166. package/dist/{layers.BAJlBx3w.js → layers.DtIUJOdD.js} +1 -1
  167. package/dist/{layers.CtcVjxJl.js → layers.DyOnTO36.js} +1 -1
  168. package/dist/{layers.Ws6We2at.js → layers.DzoWhdzh.js} +1 -1
  169. package/dist/{layers.B5CMCXYo.js → layers.GBoQfNMn.js} +1 -1
  170. package/dist/{layers.CIvGYQVa.js → layers.HKuQEi8d.js} +1 -1
  171. package/dist/{layers.CTFiJEXR.js → layers.JWOykHoL.js} +1 -1
  172. package/dist/{layers._aEgj9_3.js → layers.JvCTDQpj.js} +1 -1
  173. package/dist/{layers.DLVCPMeP.js → layers.LpxZivxv.js} +1 -1
  174. package/dist/{layers.uOcg9B9T.js → layers.MMnDRf0F.js} +1 -1
  175. package/dist/{layers.BjxQTy9m.js → layers.NSb01dZ8.js} +3 -3
  176. package/dist/{layers.DtRF5H6s.js → layers.O9aENdhz.js} +1 -1
  177. package/dist/{layers.BTUqi9dl.js → layers.OXr5r5tZ.js} +1 -1
  178. package/dist/{layers.ecg1JPTq.js → layers.OgHHJ7AJ.js} +1 -1
  179. package/dist/{layers.uE3U5tcq.js → layers.OjmLtSP1.js} +1 -1
  180. package/dist/{layers.-koEySTH.js → layers.P7yLojmH.js} +1 -1
  181. package/dist/{layers.B8SkTpY1.js → layers.PejndB2j.js} +1 -1
  182. package/dist/{layers.BsDzjs0V.js → layers.QcOQUP20.js} +1 -1
  183. package/dist/{layers.COYeAeZD.js → layers.SXC1p29H.js} +1 -1
  184. package/dist/{layers.Cy1FqVSa.js → layers.VG9nD_7m.js} +2 -2
  185. package/dist/{layers.CctuMNe2.js → layers.Yv4tqH51.js} +1 -1
  186. package/dist/{layers.mhTPvwbj.js → layers._rxomw_e.js} +1 -1
  187. package/dist/{layers.rIZ_HMhE.js → layers.d-J-pkkX.js} +1 -1
  188. package/dist/{layers.DoKXAeQh.js → layers.fvWum4-u.js} +1 -1
  189. package/dist/{layers.oJpVtc-Z.js → layers.gC3dy9DX.js} +1 -1
  190. package/dist/{layers.DW0FvG1g.js → layers.gaA-42fN.js} +1 -1
  191. package/dist/{layers.DBL9yB03.js → layers.hLDK8NtM.js} +1 -1
  192. package/dist/{layers.CeWRaT3a.js → layers.hhScrOOB.js} +1 -1
  193. package/dist/{layers.cAAna5Ye.js → layers.nLwIMr0A.js} +1 -1
  194. package/dist/{layers.DG4rwYgz.js → layers.nutPV8y6.js} +1 -1
  195. package/dist/{layers.CBCMt9a_.js → layers.nxzVbnZG.js} +1 -1
  196. package/dist/{layers.nCXZMUQI.js → layers.oDpU-Hra.js} +1 -1
  197. package/dist/{layers.BH6SiZz4.js → layers.ocb-ckJB.js} +1 -1
  198. package/dist/{layers.v9vQ156o.js → layers.pcuXD239.js} +1 -1
  199. package/dist/{layers.BpiMEou9.js → layers.pmVv821j.js} +1 -1
  200. package/dist/{layers.CklsVJ-8.js → layers.qJxUThUt.js} +1 -1
  201. package/dist/{layers.BRh4KNRZ.js → layers.qLig6Qrb.js} +4 -4
  202. package/dist/{layers.B8CKxXiL.js → layers.qh_bhSwF.js} +4 -4
  203. package/dist/{layers.D9uS1p65.js → layers.v33R5NY5.js} +1 -1
  204. package/dist/{layers.Dh4CniZb.js → layers.v8fikFVy.js} +3 -3
  205. package/dist/{layers.BIoj9NhZ.js → layers.xj7IEpC3.js} +1 -1
  206. package/dist/{layers.DYLApKxd.js → layers.yiF779cI.js} +1 -1
  207. package/dist/{layers.BOziEG1-.js → layers.yoJPKgxf.js} +1 -1
  208. package/dist/{layers.CtzNXxxc.js → layers.zBZCJFA4.js} +1 -1
  209. package/dist/{layers.D1rmyxa1.js → layers.zQ4PGkmU.js} +2 -2
  210. package/package.json +160 -160
  211. package/dist/layers.BLH0YOjh.js +0 -1
  212. package/dist/layers.BTHlMGt0.js +0 -8
  213. package/dist/layers.CdkMt7uk.js +0 -6
  214. package/dist/layers.Lr6XG1zP.js +0 -1
package/README.md CHANGED
@@ -1,831 +1,831 @@
1
- # LayersTextEditor
2
-
3
- LayersTextEditor is a text editor for web applications written in JavaScript, with a focus on reliability, accessibility, and performance.
4
-
5
- <details>
6
- <summary>
7
- 🚀 Quick Start
8
- </summary>
9
-
10
- ## Installation
11
-
12
- To install the package, run one of the following commands:
13
-
14
- ### Use npm:
15
-
16
- ```bash
17
- npm install @layers-app/editor
18
- ```
19
-
20
- > If you plan to use the Swagger node, install the additional package: `npm install swagger-ui-react`.
21
-
22
- ### Use yarn:
23
-
24
- ```bash
25
- yarn add @layers-app/editor
26
- ```
27
-
28
- ### Initializing the text editor
29
-
30
- ```
31
- import { Editor } from '@layers-app/editor';
32
- ```
33
-
34
- By default, LayersTextEditor works with an object and can return either an object or HTML.
35
-
36
- Example with an object:
37
-
38
- ```js
39
- const text = 'Hello world';
40
-
41
- const json = {
42
- root: {
43
- children: [
44
- {
45
- children: [
46
- {
47
- detail: 0,
48
- format: 0,
49
- mode: 'normal',
50
- style: '',
51
- text: text,
52
- type: 'text',
53
- version: 1,
54
- },
55
- ],
56
- direction: 'ltr',
57
- format: '',
58
- indent: 0,
59
- type: 'paragraph',
60
- version: 1,
61
- },
62
- ],
63
- direction: 'ltr',
64
- format: '',
65
- indent: 0,
66
- type: 'root',
67
- version: 1,
68
- },
69
- };
70
-
71
- const onChange = (
72
- data, // json
73
- ) => <Editor initialContent={json} onChange={onChange} />;
74
- ```
75
-
76
- You can also pass an HTML string to the editor.
77
-
78
- Example with HTML:
79
-
80
- ```
81
- const html = `
82
- <h2 dir="ltr" style="text-align: left;">
83
- <span style="background-color: rgb(248, 231, 28); font-family: &quot;Trebuchet MS&quot;; white-space: pre-wrap;">Hello</span>
84
- </h2>
85
- <h2 dir="ltr">
86
- <br>
87
- </h2>
88
- <p dir="ltr">
89
- <br>
90
- </p>
91
- <p dir="ltr">
92
- <span style="font-size: 21px; white-space: pre-wrap;">world</span>
93
- </p>
94
- `
95
-
96
- const onChange = (data) => // json
97
-
98
- <Editor initialContent={html} onChange={onChange} />
99
- ```
100
-
101
- The output of the data in the `onChange` function is controlled by the **outputFormat** property. **outputFormat** can be either "html" or "json". Example with **outputFormat**:
102
-
103
- ```
104
- const html = `
105
- <h2 dir="ltr" style="text-align: left;">
106
- <span style="background-color: rgb(248, 231, 28); font-family: &quot;Trebuchet MS&quot;; white-space: pre-wrap;">Hello</span>
107
- </h2>
108
- <h2 dir="ltr">
109
- <br>
110
- </h2>
111
- <p dir="ltr">
112
- <br>
113
- </p>
114
- <p dir="ltr">
115
- <span style="font-size: 21px; white-space: pre-wrap;">world</span>
116
- </p>
117
- `
118
-
119
- const onChange = (data: string, text?: string) => {
120
- // data - html from editor
121
- // text - text from editor
122
- }
123
-
124
-
125
- <Editor initialContent={html} outputFormat="html" onChange={onChange} />
126
- ```
127
-
128
- </details>
129
-
130
- <details>
131
- <summary>
132
- 🎨 StylesProvider
133
- </summary>
134
-
135
- Use **StylesProvider** to add styling to your HTML content.
136
-
137
- ```
138
- <StylesProvider>
139
- <div
140
- dangerouslySetInnerHTML={{ __html: '<p>Your html here</p>' }}
141
- />
142
- </StylesProvider>
143
- ```
144
-
145
- </details>
146
-
147
- <details>
148
- <summary>
149
- 🖼️ File upload
150
- </summary>
151
-
152
- ## Image upload
153
-
154
- To start working with image uploads, use the **fetchUploadMedia** function, which takes three parameters: **file**, **success**, and **error**. After successfully uploading the image to your service, you should call the **success** function and pass two required arguments: the **URL** of the image and its **ID**.
155
- Optional: You can also pass two optional parameters: **signal** and **onProgress**. The **signal** allows you to cancel an ongoing upload using an AbortController, and **onProgress** provides the current upload progress in percent — useful for displaying a progress bar or loading state.
156
-
157
- ```
158
- const fetchUploadMedia = async (
159
- file: File,
160
- success: (url: string, id: string) => void,
161
- error?: (error?: Error) => void
162
- ) => {
163
- const formData = new FormData();
164
- formData.append('File', file);
165
- formData.append('FileAccessModifier', '0');
166
-
167
- try {
168
- const response = await fetch('/api/v1/Files/Upload', {
169
- method: 'POST',
170
- body: formData,
171
- credentials: 'include'
172
- });
173
-
174
- if (!response.ok) {
175
- throw new Error('File upload failed');
176
- }
177
-
178
- const data = await response.json();
179
- const { Id, Url } = data;
180
-
181
- success(Url, Id);
182
- } catch (err) {
183
- if (error) {
184
- if (err instanceof Error) {
185
- error(err);
186
- } else {
187
- error(new Error('An unknown error occurred'));
188
- }
189
- }
190
- }
191
- };
192
-
193
- const fetchUploadMedia = async (
194
- file: File,
195
- success: (url: string, id: string, data: any) => void,
196
- error?: (err: Error) => void,
197
- signal?: AbortSignal,
198
- onProgress?: (percent: number) => void,
199
- ) => {
200
- const formData = new FormData();
201
- formData.append('File', file);
202
- formData.append('FileAccessModifier', '0');
203
-
204
- const xhr = new XMLHttpRequest();
205
- xhr.open('POST', '/api/v1/Files/Upload');
206
- xhr.withCredentials = true;
207
-
208
- if (signal) signal.addEventListener('abort', () => xhr.abort());
209
- if (onProgress) {
210
- xhr.upload.onprogress = (e) => {
211
- if (e.lengthComputable) onProgress(Math.round((e.loaded / e.total) * 100));
212
- };
213
- }
214
-
215
- xhr.onload = () => {
216
- try {
217
- const data = JSON.parse(xhr.responseText);
218
- success(`/v1/attachments/${data.id}`, data.id, data);
219
- } catch {
220
- error?.(new Error('Invalid response'));
221
- }
222
- };
223
-
224
- xhr.onerror = () => error?.(new Error('Upload error')));
225
- xhr.send(formData);
226
- };
227
-
228
-
229
- <Editor
230
- ...props
231
- fetchUploadMedia={fetchUploadMedia}
232
- />
233
- ```
234
-
235
- ## Image Deletion
236
-
237
- To have greater control over image deletion, pass an optional function **fetchDeleteMedia** to the editor, which accepts three parameters: **id**, **success**, and **error**. After successfully deleting the image from your service, the **success** function should be called.
238
-
239
- ```
240
- const fetchDeleteMedia = async (
241
- id: string,
242
- success: () => void,
243
- error?: (error?: Error) => void
244
- ) => {
245
- const body = { Ids: [id] };
246
-
247
- try {
248
- const response = await fetch('/api/v1/Documents/Delete', {
249
- method: 'POST',
250
- headers: {
251
- 'Content-Type': 'application/json'
252
- },
253
- body: JSON.stringify(body),
254
- credentials: 'include'
255
- });
256
-
257
- await response.json();
258
- success();
259
- } catch (err) {
260
- if (error) {
261
- if (err instanceof Error) {
262
- error(err);
263
- } else {
264
- error(new Error('An unknown error occurred'));
265
- }
266
- }
267
- }
268
- };
269
-
270
- <Editor
271
- ...props
272
- fetchUploadMedia={fetchUploadMedia}
273
- fetchDeleteMedia={fetchUploadMedia}
274
- />
275
- ```
276
-
277
- ## Additional options for working with image uploads.
278
-
279
- ```
280
- import { Editor, Dropzone } from "@sinups/editor-dsd";
281
-
282
- const Content = () => (
283
- <Group justify="center" gap="xl" mih={220} style={{ pointerEvents: 'none' }}>
284
- {/*
285
- The components Dropzone.Accept, Dropzone.Reject, and Dropzone.Idle are visible only when the user performs specific actions:
286
-
287
- Dropzone.Accept is visible only when the user drags a file that can be accepted into the drop zone.
288
- Dropzone.Reject is visible only when the user drags a file that cannot be accepted into the drop zone.
289
- Dropzone.Idle is visible when the user is not dragging any file into the drop zone.
290
- */}
291
- <Dropzone.Accept>
292
- <IconUpload
293
- style={{ width: rem(52), height: rem(52), color: 'var(--mantine-color-blue-6)' }}
294
- stroke={1.5}
295
- />
296
- </Dropzone.Accept>
297
- <Dropzone.Reject>
298
- <IconX
299
- style={{ width: rem(52), height: rem(52), color: 'var(--mantine-color-red-6)' }}
300
- stroke={1.5}
301
- />
302
- </Dropzone.Reject>
303
- <Dropzone.Idle>
304
- <IconPhoto
305
- style={{ width: rem(52), height: rem(52), color: 'var(--mantine-color-dimmed)' }}
306
- stroke={1.5}
307
- />
308
- </Dropzone.Idle>
309
-
310
- <div>
311
- <Text size="xl" inline>
312
- Drag images here or click to select files
313
- </Text>
314
- <Text size="sm" c="dimmed" inline mt={7}>
315
- Attach as many files as you want, each file must not exceed{' '} {maxFileSize} МБ.
316
- </Text>
317
- </div>
318
- </Group>
319
- );
320
-
321
- <Editor
322
- ...props
323
- fetchUploadMedia={fetchUploadMedia}
324
- contentModalUploadImage={Content}
325
- maxFileSize={5}
326
- maxImageSizeError={() => {}}
327
- />
328
- ```
329
-
330
- ## File upload
331
-
332
- For uploading a file or audio, you might need the third parameter "data".
333
-
334
- ```
335
- const fetchUploadMedia = async (
336
- file: File,
337
- success: (url: string, id: string, data?: {
338
- contentType: string;
339
- fileSize: string;
340
- originalFileName: string;
341
- }) => void,
342
- error?: (error?: Error) => void
343
- ) => {
344
- const formData = new FormData();
345
- formData.append('File', file);
346
- formData.append('FileAccessModifier', '0');
347
-
348
- try {
349
- const response = await fetch('/api/v1/Files/Upload', {
350
- method: 'POST',
351
- body: formData,
352
- credentials: 'include'
353
- });
354
-
355
- if (!response.ok) {
356
- throw new Error('File upload failed');
357
- }
358
-
359
- const data = await response.json();
360
- const { Id, Url } = data;
361
-
362
- success(Url, Id, data);
363
- } catch (err) {
364
- if (error) {
365
- if (err instanceof Error) {
366
- error(err);
367
- } else {
368
- error(new Error('An unknown error occurred'));
369
- }
370
- }
371
- }
372
- };
373
- ```
374
-
375
- </details>
376
-
377
- <details>
378
- <summary>
379
- 🤖 AI
380
- </summary>
381
-
382
- ## Connect AI
383
-
384
- ```
385
- const fetchPromptResult = async (
386
- prompt: string,
387
- success: (data: string) => void,
388
- error?: () => void,
389
- ) => {
390
- try {
391
- const response = await fetch(
392
- 'https://domain/api/v1/openai/call-any-prompt',
393
- {
394
- method: 'POST',
395
- headers: {
396
- 'Content-Type': 'application/json',
397
-
398
- Authorization: 'token',
399
- },
400
- body: JSON.stringify({ prompt }),
401
- },
402
- );
403
-
404
- if (!response.ok) {
405
- const errText = await response.text();
406
- console.error('server error', errText);
407
- throw new Error('API failed');
408
- }
409
-
410
- const data = await response.json();
411
-
412
- success(data.content);
413
- } catch (err) {
414
- if (error) {
415
- error();
416
- console.error('Error');
417
- }
418
- }
419
- };
420
-
421
- <Editor
422
- ...props
423
- fetchPromptResult={fetchPromptResult}
424
- />
425
- ```
426
-
427
- </details>
428
-
429
- <details>
430
- <summary>
431
- 📊 Analytics (onTrack)
432
- </summary>
433
-
434
- ## Event Tracking
435
-
436
- The editor can track user actions via the `onTrack` callback. This allows the host application to send analytics events to any provider (Yandex.Metrika, Google Analytics, Mixpanel, etc.) without the editor depending on any specific analytics SDK.
437
-
438
- ### Basic Usage
439
-
440
- ```tsx
441
- import { trackGoal } from '@layers/hooks/useAnalytics';
442
-
443
- <Editor {...props} onTrack={trackGoal} />;
444
- ```
445
-
446
- ### Custom Handler
447
-
448
- ```tsx
449
- const handleTrack = (event: string, params?: Record<string, unknown>) => {
450
- console.log('Editor event:', event, params);
451
-
452
- // Send to your analytics provider
453
- myAnalytics.track(event, params);
454
- };
455
-
456
- <Editor {...props} onTrack={handleTrack} />;
457
- ```
458
-
459
- ### Type Signature
460
-
461
- ```ts
462
- type EditorTrackFn = (event: string, params?: Record<string, unknown>) => void;
463
- ```
464
-
465
- ### Tracked Events
466
-
467
- | Event | Trigger | Plugin |
468
- | --------------------------- | ---------------------------------- | --------------------- |
469
- | `block_table_created` | User inserts a table | BlockFormatDropDown |
470
- | `block_image_added` | User inserts an image | BlockFormatDropDown |
471
- | `block_code_created` | User inserts a code block | BlockFormatDropDown |
472
- | `block_layout_used` | User inserts a grid/layout | BlockFormatDropDown |
473
- | `block_collapse_created` | User inserts a toggle/collapsible | BlockFormatDropDown |
474
- | `block_link_inserted` | User inserts a link | ToolbarPlugin |
475
- | `block_comment_added` | User adds an inline comment | ToolbarPlugin |
476
- | `ai_menu_opened` | User clicks the AI toolbar button | ToolbarPlugin/AI |
477
- | `block_heading_created` | User creates a heading (h1-h4) | BlockFormatDropDown |
478
- | `list_bullet_created` | User creates a bullet list | BlockFormatDropDown |
479
- | `list_number_created` | User creates a numbered list | BlockFormatDropDown |
480
- | `list_check_created` | User creates a checklist | BlockFormatDropDown |
481
- | `block_quote_created` | User creates a quote block | BlockFormatDropDown |
482
- | `block_divider_inserted` | User inserts a horizontal rule | BlockFormatDropDown |
483
- | `block_child_docs_inserted` | User inserts child documents block | BlockFormatDropDown |
484
- | `block_embed_added` | User adds an embed/integration | BlockFormatDropDown |
485
- | `media_audio_added` | User adds an audio block | BlockFormatDropDown |
486
- | `media_file_added` | User adds a file block | BlockFormatDropDown |
487
- | `table_row_added` | User inserts a table row | TableActionMenuPlugin |
488
- | `table_column_added` | User inserts a table column | TableActionMenuPlugin |
489
- | `table_row_deleted` | User deletes a table row | TableActionMenuPlugin |
490
- | `table_column_deleted` | User deletes a table column | TableActionMenuPlugin |
491
- | `block_duplicated` | User duplicates a block | DraggableBlockPlugin |
492
- | `block_deleted` | User deletes a block | DraggableBlockPlugin |
493
- | `text_code_toggled` | User toggles inline code format | ToolbarPlugin |
494
- | `text_formatting_cleared` | User clears all text formatting | ToolbarPlugin |
495
-
496
- > Events fire from both the toolbar dropdown menu and the slash command menu (`/`).
497
-
498
- ### What Happens Without onTrack?
499
-
500
- If `onTrack` is not provided, **nothing happens** — all tracking calls use optional chaining (`onTrack?.('event')`) and are silently skipped. The editor works exactly the same with or without analytics. There is no error, no console warning, and no performance impact.
501
-
502
- This means:
503
-
504
- - **No analytics SDK required** — the editor is a standalone package with zero analytics dependencies
505
- - **Safe to omit** — if you don't need tracking, simply don't pass the prop
506
- - **No counter needed** — the editor itself never calls `ym()`, `gtag()`, or any external API directly
507
-
508
- ### How It Works Internally
509
-
510
- 1. `onTrack` is passed as a prop to `<Editor>` and stored in React Context
511
- 2. Plugins access it via `useContext(Context)` and call `onTrack?.('event_name')`
512
- 3. The host app decides what to do with the event (send to Metrika, log, ignore)
513
-
514
- ```
515
- Host App Editor Package
516
- ───────── ──────────────
517
- trackGoal() ──→ onTrack prop ──→ Context.onTrack
518
- │ │
519
- │ Plugins call:
520
- │ onTrack?.('block_table_created')
521
- │ │
522
- ◄────────────────────────────────┘
523
-
524
- ym(ID, 'reachGoal', 'block_table_created')
525
- dataLayer.push({ event: 'block_table_created' })
526
- ```
527
-
528
- </details>
529
-
530
- <details>
531
- <summary>
532
- 👥 Collaboration
533
- </summary>
534
-
535
- ```jsx
536
- <Editor
537
- {...props}
538
- ws={{
539
- url: 'https://wss.dudoc.io/', // WebSocket URL
540
- id: '322323', // Unique document ID
541
- user: userProfile, // Current user
542
- getActiveUsers: (users) => {
543
- // Returns active users editing the document
544
- setActiveUsers(users);
545
- },
546
- }}
547
- />
548
- ```
549
-
550
- </details>
551
-
552
- <details>
553
- <summary>
554
- 📝 Additional options
555
- </summary>
556
-
557
- ## Reset editor content
558
-
559
- ```
560
-
561
- import { CLEAR_EDITOR_COMMAND } from './EditorLexical';
562
-
563
- <>
564
- <button
565
- onClick={() => {
566
- if (editorRef.current) {
567
- editorRef.current.update(() => {
568
- editorRef.current?.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined);
569
- });
570
- }
571
- }}
572
- >
573
- Reset
574
- </button>
575
- <Editor
576
- ...props
577
- editorRef={editorRef}
578
- />
579
- <>
580
- ```
581
-
582
- </details>
583
-
584
- <details>
585
- <summary>
586
- 🧪 Testing
587
- </summary>
588
-
589
- ## Testing Overview
590
-
591
- This project includes comprehensive testing with both **unit tests** (Vitest) and **end-to-end tests** (Playwright). The testing setup ensures reliability across different browsers and environments.
592
-
593
- ### Prerequisites
594
-
595
- Before running tests, make sure you have installed all dependencies:
596
-
597
- ```bash
598
- npm install
599
- ```
600
-
601
- ## Unit Tests (Vitest)
602
-
603
- Unit tests are written with **Vitest** and **jsdom** for testing individual components and utilities.
604
-
605
- ### Run Unit Tests
606
-
607
- ```bash
608
- # Run all unit tests
609
- npm run test-unit
610
-
611
- # Run unit tests in watch mode (auto-rerun on changes)
612
- npm run test-unit-watch
613
- ```
614
-
615
- ### Unit Test Files Location
616
-
617
- - `__tests__/unit/` - Unit test files
618
- - Test files follow the pattern: `*.test.ts` or `*.test.tsx`
619
-
620
- ## End-to-End Tests (Playwright)
621
-
622
- E2E tests use **Playwright** to test the complete application flow in real browsers.
623
-
624
- ### Run E2E Tests
625
-
626
- ```bash
627
- # Run all E2E tests (WebKit only for CI optimization)
628
- npm run test:e2e
629
-
630
- # Run E2E tests with UI mode (interactive)
631
- npm run test:e2e:ui
632
-
633
- # Run E2E tests in debug mode
634
- npm run test:e2e:debug
635
-
636
- # Run E2E tests in headed mode (visible browser)
637
- npm run test:e2e:headed
638
- ```
639
-
640
- ### E2E Test Files Location
641
-
642
- - `__tests__/e2e/` - End-to-end test files
643
- - `__tests__/regression/` - Regression test files
644
- - Test files follow the pattern: `*.spec.js`, `*.spec.mjs`, or `*.spec.ts`
645
-
646
- ### Browser Support
647
-
648
- - **WebKit** (Safari) - Primary browser for CI/CD
649
- - **Chromium** and **Firefox** - Available for local testing
650
-
651
- ## Test Server
652
-
653
- The test server automatically starts when running E2E tests:
654
-
655
- ```bash
656
- # Manual test server start (if needed)
657
- npm run start-test-server
658
- ```
659
-
660
- - **URL**: `http://localhost:3000`
661
- - **Mode**: Full editor mode with all features enabled
662
- - **Environment**: `VITE_LAYERS=true`
663
-
664
- ## Test Configuration
665
-
666
- ### Playwright Configuration
667
-
668
- - **Config file**: `playwright.config.js`
669
- - **Test directory**: `./__tests__/e2e/`
670
- - **Browser**: WebKit (optimized for CI)
671
- - **Base URL**: `http://localhost:3000`
672
- - **Timeout**: 90 seconds per test
673
- - **Retries**: 2 retries in CI, 0 locally
674
-
675
- ### Vitest Configuration
676
-
677
- - **Config file**: `vitest.config.mts`
678
- - **Environment**: jsdom
679
- - **Setup file**: `vitest.setup.mts`
680
- - **Coverage**: V8 provider
681
-
682
- ## CI/CD Testing
683
-
684
- Tests run automatically on:
685
-
686
- - **Push** to `main` or `dev` branches
687
- - **Pull requests** to `main` or `dev` branches
688
- - **Manual trigger** via GitHub Actions
689
-
690
- ### GitHub Actions Workflow
691
-
692
- - **File**: `.github/workflows/tests.yml`
693
- - **Runner**: Ubuntu Latest
694
- - **Node.js**: Version 20
695
- - **Browser caching**: Playwright browsers cached for faster runs
696
- - **Artifacts**: Test reports and traces uploaded on completion
697
-
698
- ## Test Examples
699
-
700
- ### Basic E2E Test Structure
701
-
702
- ```javascript
703
- // __tests__/e2e/example.spec.mjs
704
- import { expect, test } from '@playwright/test';
705
-
706
- import { focusEditor } from '../utils/index.mjs';
707
-
708
- test('Can type text in editor', async ({ page }) => {
709
- await page.goto('/');
710
- await focusEditor(page);
711
-
712
- const editor = page.locator('[contenteditable="true"]').first();
713
- await editor.type('Hello World');
714
-
715
- await expect(editor).toContainText('Hello World');
716
- });
717
- ```
718
-
719
- ### Unit Test Structure
720
-
721
- ```typescript
722
- // __tests__/unit/example.test.ts
723
- import { describe, it, expect } from 'vitest';
724
- import { render } from '@testing-library/react';
725
- import { Editor } from '../src/Editor';
726
-
727
- describe('Editor Component', () => {
728
- it('renders without crashing', () => {
729
- const { container } = render(<Editor />);
730
- expect(container).toBeTruthy();
731
- });
732
- });
733
- ```
734
-
735
- ## Debugging Tests
736
-
737
- ### Debug E2E Tests
738
-
739
- ```bash
740
- # Run with Playwright Inspector
741
- npm run test:e2e:debug
742
-
743
- # Run specific test file
744
- npx playwright test __tests__/e2e/TextEntry.spec.mjs --debug
745
-
746
- # Run with headed browser
747
- npm run test:e2e:headed
748
- ```
749
-
750
- ### View Test Reports
751
-
752
- ```bash
753
- # Open HTML report (after running tests)
754
- npx playwright show-report
755
-
756
- # View test traces (for failed tests)
757
- npx playwright show-trace test-results/[test-name]/trace.zip
758
- ```
759
-
760
- ## Test Utilities
761
-
762
- Common test utilities are available in `__tests__/utils/index.mjs`:
763
-
764
- - `focusEditor(page)` - Focus the main editor
765
- - `selectAll(page)` - Select all text in editor
766
- - `moveLeft(page, count)` - Move cursor left
767
- - `selectCharacters(page, count)` - Select specific number of characters
768
- - `waitForSelector(page, selector)` - Wait for element to appear
769
-
770
- ## Performance
771
-
772
- ### Test Execution Times
773
-
774
- - **Unit Tests**: ~10-30 seconds
775
- - **E2E Tests (first run)**: ~3-4 minutes (includes browser installation)
776
- - **E2E Tests (cached)**: ~1-2 minutes (uses cached browsers)
777
-
778
- ### Optimization Features
779
-
780
- - **Browser Caching**: Playwright browsers cached in CI
781
- - **Single Worker**: Prevents race conditions in CI
782
- - **WebKit Only**: Faster than multi-browser matrix
783
- - **Smart Retries**: Auto-retry flaky tests
784
-
785
- ## Troubleshooting
786
-
787
- ### Common Issues
788
-
789
- 1. **Port conflicts**: Ensure port 3000 is available
790
- 2. **Browser installation**: Run `npx playwright install` if needed
791
- 3. **Test timeouts**: Check if test server is running properly
792
- 4. **Certificate errors**: Tests use HTTP to avoid HTTPS certificate issues
793
-
794
- ### Reset Test Environment
795
-
796
- ```bash
797
- # Clear Playwright cache
798
- npx playwright install --force
799
-
800
- # Reset node_modules
801
- rm -rf node_modules package-lock.json
802
- npm install
803
- ```
804
-
805
- </details>
806
-
807
- <details>
808
- <summary>
809
- ⚙️ Properties
810
- </summary>
811
-
812
- ```
813
- onChange: (value: string | object) => undefined - A function that triggers every time the editor content changes and returns an HTML string or an object depending on the outputFormat property.
814
- debounce?: number - Defines how often the onChange function is called, in milliseconds.
815
- onBlur: (value: string | object) => undefined - A function that triggers when the editor loses focus and returns an HTML string or an object depending on the outputFormat property.
816
- outputFormat?: 'html' | 'json' - The outputFormat property defines whether we want to output an HTML string or a JSON object. The default is JSON.
817
- initialContent: string | object - The initial content for the editor.
818
- maxHeight?: number - Sets the height of the editor. The default is 100%.
819
- mode?: 'simple' | 'default' | 'full' | 'editor' - The editor mode. Depending on the chosen mode, functionality may be restricted or extended. The default is default.
820
- fetchUploadMedia?: (file: File, success: (url: string, id: string, error?: (error?: Error) => void) => void) - Function to upload an image to your service.
821
- fetchDeleteMedia?: (id: string, success: () => void, error?: (error?: Error) => void) - Helper function to delete an image.
822
- maxFileSize?: number - The maximum image size in megabytes.
823
- contentModalUploadImage?: React.FunctionComponent - A React component to replace content in DropZone.
824
- maxImageSizeError?: () => void - A function that is called if the image exceeds the maxFileSize.
825
- disable?: boolean - Toggles the editor into read-only mode.
826
- ws?: { url: string, id: string, user: { color: string, name: string }, getActiveUsers: (users) => void } - WebSocket settings: URL, document ID, current user details, and function to return active users editing the document.
827
- editorRef?: { current: EditorType | null } - Reference to the editor.
828
- onTrack?: (event: string, params?: Record<string, unknown>) => void - Optional callback for analytics event tracking. Called when the user performs tracked actions (insert table, add image, open AI menu, etc.). If not provided, tracking is silently skipped. See the "Analytics (onTrack)" section for the full list of events.
829
- ```
830
-
831
- </details>
1
+ # LayersTextEditor
2
+
3
+ LayersTextEditor is a text editor for web applications written in JavaScript, with a focus on reliability, accessibility, and performance.
4
+
5
+ <details>
6
+ <summary>
7
+ 🚀 Quick Start
8
+ </summary>
9
+
10
+ ## Installation
11
+
12
+ To install the package, run one of the following commands:
13
+
14
+ ### Use npm:
15
+
16
+ ```bash
17
+ npm install @layers-app/editor
18
+ ```
19
+
20
+ > If you plan to use the Swagger node, install the additional package: `npm install swagger-ui-react`.
21
+
22
+ ### Use yarn:
23
+
24
+ ```bash
25
+ yarn add @layers-app/editor
26
+ ```
27
+
28
+ ### Initializing the text editor
29
+
30
+ ```
31
+ import { Editor } from '@layers-app/editor';
32
+ ```
33
+
34
+ By default, LayersTextEditor works with an object and can return either an object or HTML.
35
+
36
+ Example with an object:
37
+
38
+ ```js
39
+ const text = 'Hello world';
40
+
41
+ const json = {
42
+ root: {
43
+ children: [
44
+ {
45
+ children: [
46
+ {
47
+ detail: 0,
48
+ format: 0,
49
+ mode: 'normal',
50
+ style: '',
51
+ text: text,
52
+ type: 'text',
53
+ version: 1,
54
+ },
55
+ ],
56
+ direction: 'ltr',
57
+ format: '',
58
+ indent: 0,
59
+ type: 'paragraph',
60
+ version: 1,
61
+ },
62
+ ],
63
+ direction: 'ltr',
64
+ format: '',
65
+ indent: 0,
66
+ type: 'root',
67
+ version: 1,
68
+ },
69
+ };
70
+
71
+ const onChange = (
72
+ data, // json
73
+ ) => <Editor initialContent={json} onChange={onChange} />;
74
+ ```
75
+
76
+ You can also pass an HTML string to the editor.
77
+
78
+ Example with HTML:
79
+
80
+ ```
81
+ const html = `
82
+ <h2 dir="ltr" style="text-align: left;">
83
+ <span style="background-color: rgb(248, 231, 28); font-family: &quot;Trebuchet MS&quot;; white-space: pre-wrap;">Hello</span>
84
+ </h2>
85
+ <h2 dir="ltr">
86
+ <br>
87
+ </h2>
88
+ <p dir="ltr">
89
+ <br>
90
+ </p>
91
+ <p dir="ltr">
92
+ <span style="font-size: 21px; white-space: pre-wrap;">world</span>
93
+ </p>
94
+ `
95
+
96
+ const onChange = (data) => // json
97
+
98
+ <Editor initialContent={html} onChange={onChange} />
99
+ ```
100
+
101
+ The output of the data in the `onChange` function is controlled by the **outputFormat** property. **outputFormat** can be either "html" or "json". Example with **outputFormat**:
102
+
103
+ ```
104
+ const html = `
105
+ <h2 dir="ltr" style="text-align: left;">
106
+ <span style="background-color: rgb(248, 231, 28); font-family: &quot;Trebuchet MS&quot;; white-space: pre-wrap;">Hello</span>
107
+ </h2>
108
+ <h2 dir="ltr">
109
+ <br>
110
+ </h2>
111
+ <p dir="ltr">
112
+ <br>
113
+ </p>
114
+ <p dir="ltr">
115
+ <span style="font-size: 21px; white-space: pre-wrap;">world</span>
116
+ </p>
117
+ `
118
+
119
+ const onChange = (data: string, text?: string) => {
120
+ // data - html from editor
121
+ // text - text from editor
122
+ }
123
+
124
+
125
+ <Editor initialContent={html} outputFormat="html" onChange={onChange} />
126
+ ```
127
+
128
+ </details>
129
+
130
+ <details>
131
+ <summary>
132
+ 🎨 StylesProvider
133
+ </summary>
134
+
135
+ Use **StylesProvider** to add styling to your HTML content.
136
+
137
+ ```
138
+ <StylesProvider>
139
+ <div
140
+ dangerouslySetInnerHTML={{ __html: '<p>Your html here</p>' }}
141
+ />
142
+ </StylesProvider>
143
+ ```
144
+
145
+ </details>
146
+
147
+ <details>
148
+ <summary>
149
+ 🖼️ File upload
150
+ </summary>
151
+
152
+ ## Image upload
153
+
154
+ To start working with image uploads, use the **fetchUploadMedia** function, which takes three parameters: **file**, **success**, and **error**. After successfully uploading the image to your service, you should call the **success** function and pass two required arguments: the **URL** of the image and its **ID**.
155
+ Optional: You can also pass two optional parameters: **signal** and **onProgress**. The **signal** allows you to cancel an ongoing upload using an AbortController, and **onProgress** provides the current upload progress in percent — useful for displaying a progress bar or loading state.
156
+
157
+ ```
158
+ const fetchUploadMedia = async (
159
+ file: File,
160
+ success: (url: string, id: string) => void,
161
+ error?: (error?: Error) => void
162
+ ) => {
163
+ const formData = new FormData();
164
+ formData.append('File', file);
165
+ formData.append('FileAccessModifier', '0');
166
+
167
+ try {
168
+ const response = await fetch('/api/v1/Files/Upload', {
169
+ method: 'POST',
170
+ body: formData,
171
+ credentials: 'include'
172
+ });
173
+
174
+ if (!response.ok) {
175
+ throw new Error('File upload failed');
176
+ }
177
+
178
+ const data = await response.json();
179
+ const { Id, Url } = data;
180
+
181
+ success(Url, Id);
182
+ } catch (err) {
183
+ if (error) {
184
+ if (err instanceof Error) {
185
+ error(err);
186
+ } else {
187
+ error(new Error('An unknown error occurred'));
188
+ }
189
+ }
190
+ }
191
+ };
192
+
193
+ const fetchUploadMedia = async (
194
+ file: File,
195
+ success: (url: string, id: string, data: any) => void,
196
+ error?: (err: Error) => void,
197
+ signal?: AbortSignal,
198
+ onProgress?: (percent: number) => void,
199
+ ) => {
200
+ const formData = new FormData();
201
+ formData.append('File', file);
202
+ formData.append('FileAccessModifier', '0');
203
+
204
+ const xhr = new XMLHttpRequest();
205
+ xhr.open('POST', '/api/v1/Files/Upload');
206
+ xhr.withCredentials = true;
207
+
208
+ if (signal) signal.addEventListener('abort', () => xhr.abort());
209
+ if (onProgress) {
210
+ xhr.upload.onprogress = (e) => {
211
+ if (e.lengthComputable) onProgress(Math.round((e.loaded / e.total) * 100));
212
+ };
213
+ }
214
+
215
+ xhr.onload = () => {
216
+ try {
217
+ const data = JSON.parse(xhr.responseText);
218
+ success(`/v1/attachments/${data.id}`, data.id, data);
219
+ } catch {
220
+ error?.(new Error('Invalid response'));
221
+ }
222
+ };
223
+
224
+ xhr.onerror = () => error?.(new Error('Upload error')));
225
+ xhr.send(formData);
226
+ };
227
+
228
+
229
+ <Editor
230
+ ...props
231
+ fetchUploadMedia={fetchUploadMedia}
232
+ />
233
+ ```
234
+
235
+ ## Image Deletion
236
+
237
+ To have greater control over image deletion, pass an optional function **fetchDeleteMedia** to the editor, which accepts three parameters: **id**, **success**, and **error**. After successfully deleting the image from your service, the **success** function should be called.
238
+
239
+ ```
240
+ const fetchDeleteMedia = async (
241
+ id: string,
242
+ success: () => void,
243
+ error?: (error?: Error) => void
244
+ ) => {
245
+ const body = { Ids: [id] };
246
+
247
+ try {
248
+ const response = await fetch('/api/v1/Documents/Delete', {
249
+ method: 'POST',
250
+ headers: {
251
+ 'Content-Type': 'application/json'
252
+ },
253
+ body: JSON.stringify(body),
254
+ credentials: 'include'
255
+ });
256
+
257
+ await response.json();
258
+ success();
259
+ } catch (err) {
260
+ if (error) {
261
+ if (err instanceof Error) {
262
+ error(err);
263
+ } else {
264
+ error(new Error('An unknown error occurred'));
265
+ }
266
+ }
267
+ }
268
+ };
269
+
270
+ <Editor
271
+ ...props
272
+ fetchUploadMedia={fetchUploadMedia}
273
+ fetchDeleteMedia={fetchUploadMedia}
274
+ />
275
+ ```
276
+
277
+ ## Additional options for working with image uploads.
278
+
279
+ ```
280
+ import { Editor, Dropzone } from "@sinups/editor-dsd";
281
+
282
+ const Content = () => (
283
+ <Group justify="center" gap="xl" mih={220} style={{ pointerEvents: 'none' }}>
284
+ {/*
285
+ The components Dropzone.Accept, Dropzone.Reject, and Dropzone.Idle are visible only when the user performs specific actions:
286
+
287
+ Dropzone.Accept is visible only when the user drags a file that can be accepted into the drop zone.
288
+ Dropzone.Reject is visible only when the user drags a file that cannot be accepted into the drop zone.
289
+ Dropzone.Idle is visible when the user is not dragging any file into the drop zone.
290
+ */}
291
+ <Dropzone.Accept>
292
+ <IconUpload
293
+ style={{ width: rem(52), height: rem(52), color: 'var(--mantine-color-blue-6)' }}
294
+ stroke={1.5}
295
+ />
296
+ </Dropzone.Accept>
297
+ <Dropzone.Reject>
298
+ <IconX
299
+ style={{ width: rem(52), height: rem(52), color: 'var(--mantine-color-red-6)' }}
300
+ stroke={1.5}
301
+ />
302
+ </Dropzone.Reject>
303
+ <Dropzone.Idle>
304
+ <IconPhoto
305
+ style={{ width: rem(52), height: rem(52), color: 'var(--mantine-color-dimmed)' }}
306
+ stroke={1.5}
307
+ />
308
+ </Dropzone.Idle>
309
+
310
+ <div>
311
+ <Text size="xl" inline>
312
+ Drag images here or click to select files
313
+ </Text>
314
+ <Text size="sm" c="dimmed" inline mt={7}>
315
+ Attach as many files as you want, each file must not exceed{' '} {maxFileSize} МБ.
316
+ </Text>
317
+ </div>
318
+ </Group>
319
+ );
320
+
321
+ <Editor
322
+ ...props
323
+ fetchUploadMedia={fetchUploadMedia}
324
+ contentModalUploadImage={Content}
325
+ maxFileSize={5}
326
+ maxImageSizeError={() => {}}
327
+ />
328
+ ```
329
+
330
+ ## File upload
331
+
332
+ For uploading a file or audio, you might need the third parameter "data".
333
+
334
+ ```
335
+ const fetchUploadMedia = async (
336
+ file: File,
337
+ success: (url: string, id: string, data?: {
338
+ contentType: string;
339
+ fileSize: string;
340
+ originalFileName: string;
341
+ }) => void,
342
+ error?: (error?: Error) => void
343
+ ) => {
344
+ const formData = new FormData();
345
+ formData.append('File', file);
346
+ formData.append('FileAccessModifier', '0');
347
+
348
+ try {
349
+ const response = await fetch('/api/v1/Files/Upload', {
350
+ method: 'POST',
351
+ body: formData,
352
+ credentials: 'include'
353
+ });
354
+
355
+ if (!response.ok) {
356
+ throw new Error('File upload failed');
357
+ }
358
+
359
+ const data = await response.json();
360
+ const { Id, Url } = data;
361
+
362
+ success(Url, Id, data);
363
+ } catch (err) {
364
+ if (error) {
365
+ if (err instanceof Error) {
366
+ error(err);
367
+ } else {
368
+ error(new Error('An unknown error occurred'));
369
+ }
370
+ }
371
+ }
372
+ };
373
+ ```
374
+
375
+ </details>
376
+
377
+ <details>
378
+ <summary>
379
+ 🤖 AI
380
+ </summary>
381
+
382
+ ## Connect AI
383
+
384
+ ```
385
+ const fetchPromptResult = async (
386
+ prompt: string,
387
+ success: (data: string) => void,
388
+ error?: () => void,
389
+ ) => {
390
+ try {
391
+ const response = await fetch(
392
+ 'https://domain/api/v1/openai/call-any-prompt',
393
+ {
394
+ method: 'POST',
395
+ headers: {
396
+ 'Content-Type': 'application/json',
397
+
398
+ Authorization: 'token',
399
+ },
400
+ body: JSON.stringify({ prompt }),
401
+ },
402
+ );
403
+
404
+ if (!response.ok) {
405
+ const errText = await response.text();
406
+ console.error('server error', errText);
407
+ throw new Error('API failed');
408
+ }
409
+
410
+ const data = await response.json();
411
+
412
+ success(data.content);
413
+ } catch (err) {
414
+ if (error) {
415
+ error();
416
+ console.error('Error');
417
+ }
418
+ }
419
+ };
420
+
421
+ <Editor
422
+ ...props
423
+ fetchPromptResult={fetchPromptResult}
424
+ />
425
+ ```
426
+
427
+ </details>
428
+
429
+ <details>
430
+ <summary>
431
+ 📊 Analytics (onTrack)
432
+ </summary>
433
+
434
+ ## Event Tracking
435
+
436
+ The editor can track user actions via the `onTrack` callback. This allows the host application to send analytics events to any provider (Yandex.Metrika, Google Analytics, Mixpanel, etc.) without the editor depending on any specific analytics SDK.
437
+
438
+ ### Basic Usage
439
+
440
+ ```tsx
441
+ import { trackGoal } from '@layers/hooks/useAnalytics';
442
+
443
+ <Editor {...props} onTrack={trackGoal} />;
444
+ ```
445
+
446
+ ### Custom Handler
447
+
448
+ ```tsx
449
+ const handleTrack = (event: string, params?: Record<string, unknown>) => {
450
+ console.log('Editor event:', event, params);
451
+
452
+ // Send to your analytics provider
453
+ myAnalytics.track(event, params);
454
+ };
455
+
456
+ <Editor {...props} onTrack={handleTrack} />;
457
+ ```
458
+
459
+ ### Type Signature
460
+
461
+ ```ts
462
+ type EditorTrackFn = (event: string, params?: Record<string, unknown>) => void;
463
+ ```
464
+
465
+ ### Tracked Events
466
+
467
+ | Event | Trigger | Plugin |
468
+ | --------------------------- | ---------------------------------- | --------------------- |
469
+ | `block_table_created` | User inserts a table | BlockFormatDropDown |
470
+ | `block_image_added` | User inserts an image | BlockFormatDropDown |
471
+ | `block_code_created` | User inserts a code block | BlockFormatDropDown |
472
+ | `block_layout_used` | User inserts a grid/layout | BlockFormatDropDown |
473
+ | `block_collapse_created` | User inserts a toggle/collapsible | BlockFormatDropDown |
474
+ | `block_link_inserted` | User inserts a link | ToolbarPlugin |
475
+ | `block_comment_added` | User adds an inline comment | ToolbarPlugin |
476
+ | `ai_menu_opened` | User clicks the AI toolbar button | ToolbarPlugin/AI |
477
+ | `block_heading_created` | User creates a heading (h1-h4) | BlockFormatDropDown |
478
+ | `list_bullet_created` | User creates a bullet list | BlockFormatDropDown |
479
+ | `list_number_created` | User creates a numbered list | BlockFormatDropDown |
480
+ | `list_check_created` | User creates a checklist | BlockFormatDropDown |
481
+ | `block_quote_created` | User creates a quote block | BlockFormatDropDown |
482
+ | `block_divider_inserted` | User inserts a horizontal rule | BlockFormatDropDown |
483
+ | `block_child_docs_inserted` | User inserts child documents block | BlockFormatDropDown |
484
+ | `block_embed_added` | User adds an embed/integration | BlockFormatDropDown |
485
+ | `media_audio_added` | User adds an audio block | BlockFormatDropDown |
486
+ | `media_file_added` | User adds a file block | BlockFormatDropDown |
487
+ | `table_row_added` | User inserts a table row | TableActionMenuPlugin |
488
+ | `table_column_added` | User inserts a table column | TableActionMenuPlugin |
489
+ | `table_row_deleted` | User deletes a table row | TableActionMenuPlugin |
490
+ | `table_column_deleted` | User deletes a table column | TableActionMenuPlugin |
491
+ | `block_duplicated` | User duplicates a block | DraggableBlockPlugin |
492
+ | `block_deleted` | User deletes a block | DraggableBlockPlugin |
493
+ | `text_code_toggled` | User toggles inline code format | ToolbarPlugin |
494
+ | `text_formatting_cleared` | User clears all text formatting | ToolbarPlugin |
495
+
496
+ > Events fire from both the toolbar dropdown menu and the slash command menu (`/`).
497
+
498
+ ### What Happens Without onTrack?
499
+
500
+ If `onTrack` is not provided, **nothing happens** — all tracking calls use optional chaining (`onTrack?.('event')`) and are silently skipped. The editor works exactly the same with or without analytics. There is no error, no console warning, and no performance impact.
501
+
502
+ This means:
503
+
504
+ - **No analytics SDK required** — the editor is a standalone package with zero analytics dependencies
505
+ - **Safe to omit** — if you don't need tracking, simply don't pass the prop
506
+ - **No counter needed** — the editor itself never calls `ym()`, `gtag()`, or any external API directly
507
+
508
+ ### How It Works Internally
509
+
510
+ 1. `onTrack` is passed as a prop to `<Editor>` and stored in React Context
511
+ 2. Plugins access it via `useContext(Context)` and call `onTrack?.('event_name')`
512
+ 3. The host app decides what to do with the event (send to Metrika, log, ignore)
513
+
514
+ ```
515
+ Host App Editor Package
516
+ ───────── ──────────────
517
+ trackGoal() ──→ onTrack prop ──→ Context.onTrack
518
+ │ │
519
+ │ Plugins call:
520
+ │ onTrack?.('block_table_created')
521
+ │ │
522
+ ◄────────────────────────────────┘
523
+
524
+ ym(ID, 'reachGoal', 'block_table_created')
525
+ dataLayer.push({ event: 'block_table_created' })
526
+ ```
527
+
528
+ </details>
529
+
530
+ <details>
531
+ <summary>
532
+ 👥 Collaboration
533
+ </summary>
534
+
535
+ ```jsx
536
+ <Editor
537
+ {...props}
538
+ ws={{
539
+ url: 'https://wss.dudoc.io/', // WebSocket URL
540
+ id: '322323', // Unique document ID
541
+ user: userProfile, // Current user
542
+ getActiveUsers: (users) => {
543
+ // Returns active users editing the document
544
+ setActiveUsers(users);
545
+ },
546
+ }}
547
+ />
548
+ ```
549
+
550
+ </details>
551
+
552
+ <details>
553
+ <summary>
554
+ 📝 Additional options
555
+ </summary>
556
+
557
+ ## Reset editor content
558
+
559
+ ```
560
+
561
+ import { CLEAR_EDITOR_COMMAND } from './EditorLexical';
562
+
563
+ <>
564
+ <button
565
+ onClick={() => {
566
+ if (editorRef.current) {
567
+ editorRef.current.update(() => {
568
+ editorRef.current?.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined);
569
+ });
570
+ }
571
+ }}
572
+ >
573
+ Reset
574
+ </button>
575
+ <Editor
576
+ ...props
577
+ editorRef={editorRef}
578
+ />
579
+ <>
580
+ ```
581
+
582
+ </details>
583
+
584
+ <details>
585
+ <summary>
586
+ 🧪 Testing
587
+ </summary>
588
+
589
+ ## Testing Overview
590
+
591
+ This project includes comprehensive testing with both **unit tests** (Vitest) and **end-to-end tests** (Playwright). The testing setup ensures reliability across different browsers and environments.
592
+
593
+ ### Prerequisites
594
+
595
+ Before running tests, make sure you have installed all dependencies:
596
+
597
+ ```bash
598
+ npm install
599
+ ```
600
+
601
+ ## Unit Tests (Vitest)
602
+
603
+ Unit tests are written with **Vitest** and **jsdom** for testing individual components and utilities.
604
+
605
+ ### Run Unit Tests
606
+
607
+ ```bash
608
+ # Run all unit tests
609
+ npm run test-unit
610
+
611
+ # Run unit tests in watch mode (auto-rerun on changes)
612
+ npm run test-unit-watch
613
+ ```
614
+
615
+ ### Unit Test Files Location
616
+
617
+ - `__tests__/unit/` - Unit test files
618
+ - Test files follow the pattern: `*.test.ts` or `*.test.tsx`
619
+
620
+ ## End-to-End Tests (Playwright)
621
+
622
+ E2E tests use **Playwright** to test the complete application flow in real browsers.
623
+
624
+ ### Run E2E Tests
625
+
626
+ ```bash
627
+ # Run all E2E tests (WebKit only for CI optimization)
628
+ npm run test:e2e
629
+
630
+ # Run E2E tests with UI mode (interactive)
631
+ npm run test:e2e:ui
632
+
633
+ # Run E2E tests in debug mode
634
+ npm run test:e2e:debug
635
+
636
+ # Run E2E tests in headed mode (visible browser)
637
+ npm run test:e2e:headed
638
+ ```
639
+
640
+ ### E2E Test Files Location
641
+
642
+ - `__tests__/e2e/` - End-to-end test files
643
+ - `__tests__/regression/` - Regression test files
644
+ - Test files follow the pattern: `*.spec.js`, `*.spec.mjs`, or `*.spec.ts`
645
+
646
+ ### Browser Support
647
+
648
+ - **WebKit** (Safari) - Primary browser for CI/CD
649
+ - **Chromium** and **Firefox** - Available for local testing
650
+
651
+ ## Test Server
652
+
653
+ The test server automatically starts when running E2E tests:
654
+
655
+ ```bash
656
+ # Manual test server start (if needed)
657
+ npm run start-test-server
658
+ ```
659
+
660
+ - **URL**: `http://localhost:3000`
661
+ - **Mode**: Full editor mode with all features enabled
662
+ - **Environment**: `VITE_LAYERS=true`
663
+
664
+ ## Test Configuration
665
+
666
+ ### Playwright Configuration
667
+
668
+ - **Config file**: `playwright.config.js`
669
+ - **Test directory**: `./__tests__/e2e/`
670
+ - **Browser**: WebKit (optimized for CI)
671
+ - **Base URL**: `http://localhost:3000`
672
+ - **Timeout**: 90 seconds per test
673
+ - **Retries**: 2 retries in CI, 0 locally
674
+
675
+ ### Vitest Configuration
676
+
677
+ - **Config file**: `vitest.config.mts`
678
+ - **Environment**: jsdom
679
+ - **Setup file**: `vitest.setup.mts`
680
+ - **Coverage**: V8 provider
681
+
682
+ ## CI/CD Testing
683
+
684
+ Tests run automatically on:
685
+
686
+ - **Push** to `main` or `dev` branches
687
+ - **Pull requests** to `main` or `dev` branches
688
+ - **Manual trigger** via GitHub Actions
689
+
690
+ ### GitHub Actions Workflow
691
+
692
+ - **File**: `.github/workflows/tests.yml`
693
+ - **Runner**: Ubuntu Latest
694
+ - **Node.js**: Version 20
695
+ - **Browser caching**: Playwright browsers cached for faster runs
696
+ - **Artifacts**: Test reports and traces uploaded on completion
697
+
698
+ ## Test Examples
699
+
700
+ ### Basic E2E Test Structure
701
+
702
+ ```javascript
703
+ // __tests__/e2e/example.spec.mjs
704
+ import { expect, test } from '@playwright/test';
705
+
706
+ import { focusEditor } from '../utils/index.mjs';
707
+
708
+ test('Can type text in editor', async ({ page }) => {
709
+ await page.goto('/');
710
+ await focusEditor(page);
711
+
712
+ const editor = page.locator('[contenteditable="true"]').first();
713
+ await editor.type('Hello World');
714
+
715
+ await expect(editor).toContainText('Hello World');
716
+ });
717
+ ```
718
+
719
+ ### Unit Test Structure
720
+
721
+ ```typescript
722
+ // __tests__/unit/example.test.ts
723
+ import { describe, it, expect } from 'vitest';
724
+ import { render } from '@testing-library/react';
725
+ import { Editor } from '../src/Editor';
726
+
727
+ describe('Editor Component', () => {
728
+ it('renders without crashing', () => {
729
+ const { container } = render(<Editor />);
730
+ expect(container).toBeTruthy();
731
+ });
732
+ });
733
+ ```
734
+
735
+ ## Debugging Tests
736
+
737
+ ### Debug E2E Tests
738
+
739
+ ```bash
740
+ # Run with Playwright Inspector
741
+ npm run test:e2e:debug
742
+
743
+ # Run specific test file
744
+ npx playwright test __tests__/e2e/TextEntry.spec.mjs --debug
745
+
746
+ # Run with headed browser
747
+ npm run test:e2e:headed
748
+ ```
749
+
750
+ ### View Test Reports
751
+
752
+ ```bash
753
+ # Open HTML report (after running tests)
754
+ npx playwright show-report
755
+
756
+ # View test traces (for failed tests)
757
+ npx playwright show-trace test-results/[test-name]/trace.zip
758
+ ```
759
+
760
+ ## Test Utilities
761
+
762
+ Common test utilities are available in `__tests__/utils/index.mjs`:
763
+
764
+ - `focusEditor(page)` - Focus the main editor
765
+ - `selectAll(page)` - Select all text in editor
766
+ - `moveLeft(page, count)` - Move cursor left
767
+ - `selectCharacters(page, count)` - Select specific number of characters
768
+ - `waitForSelector(page, selector)` - Wait for element to appear
769
+
770
+ ## Performance
771
+
772
+ ### Test Execution Times
773
+
774
+ - **Unit Tests**: ~10-30 seconds
775
+ - **E2E Tests (first run)**: ~3-4 minutes (includes browser installation)
776
+ - **E2E Tests (cached)**: ~1-2 minutes (uses cached browsers)
777
+
778
+ ### Optimization Features
779
+
780
+ - **Browser Caching**: Playwright browsers cached in CI
781
+ - **Single Worker**: Prevents race conditions in CI
782
+ - **WebKit Only**: Faster than multi-browser matrix
783
+ - **Smart Retries**: Auto-retry flaky tests
784
+
785
+ ## Troubleshooting
786
+
787
+ ### Common Issues
788
+
789
+ 1. **Port conflicts**: Ensure port 3000 is available
790
+ 2. **Browser installation**: Run `npx playwright install` if needed
791
+ 3. **Test timeouts**: Check if test server is running properly
792
+ 4. **Certificate errors**: Tests use HTTP to avoid HTTPS certificate issues
793
+
794
+ ### Reset Test Environment
795
+
796
+ ```bash
797
+ # Clear Playwright cache
798
+ npx playwright install --force
799
+
800
+ # Reset node_modules
801
+ rm -rf node_modules package-lock.json
802
+ npm install
803
+ ```
804
+
805
+ </details>
806
+
807
+ <details>
808
+ <summary>
809
+ ⚙️ Properties
810
+ </summary>
811
+
812
+ ```
813
+ onChange: (value: string | object) => undefined - A function that triggers every time the editor content changes and returns an HTML string or an object depending on the outputFormat property.
814
+ debounce?: number - Defines how often the onChange function is called, in milliseconds.
815
+ onBlur: (value: string | object) => undefined - A function that triggers when the editor loses focus and returns an HTML string or an object depending on the outputFormat property.
816
+ outputFormat?: 'html' | 'json' - The outputFormat property defines whether we want to output an HTML string or a JSON object. The default is JSON.
817
+ initialContent: string | object - The initial content for the editor.
818
+ maxHeight?: number - Sets the height of the editor. The default is 100%.
819
+ mode?: 'simple' | 'default' | 'full' | 'editor' - The editor mode. Depending on the chosen mode, functionality may be restricted or extended. The default is default.
820
+ fetchUploadMedia?: (file: File, success: (url: string, id: string, error?: (error?: Error) => void) => void) - Function to upload an image to your service.
821
+ fetchDeleteMedia?: (id: string, success: () => void, error?: (error?: Error) => void) - Helper function to delete an image.
822
+ maxFileSize?: number - The maximum image size in megabytes.
823
+ contentModalUploadImage?: React.FunctionComponent - A React component to replace content in DropZone.
824
+ maxImageSizeError?: () => void - A function that is called if the image exceeds the maxFileSize.
825
+ disable?: boolean - Toggles the editor into read-only mode.
826
+ ws?: { url: string, id: string, user: { color: string, name: string }, getActiveUsers: (users) => void } - WebSocket settings: URL, document ID, current user details, and function to return active users editing the document.
827
+ editorRef?: { current: EditorType | null } - Reference to the editor.
828
+ onTrack?: (event: string, params?: Record<string, unknown>) => void - Optional callback for analytics event tracking. Called when the user performs tracked actions (insert table, add image, open AI menu, etc.). If not provided, tracking is silently skipped. See the "Analytics (onTrack)" section for the full list of events.
829
+ ```
830
+
831
+ </details>