@layers-app/editor 0.7.41 → 0.7.43

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 (219) hide show
  1. package/README.md +830 -830
  2. package/dist/index.cjs +2 -2
  3. package/dist/index.d.ts +12 -2
  4. package/dist/index.js +4 -4
  5. package/dist/{layers.BchVgarW.js → layers.-lgAuFI6.js} +1 -1
  6. package/dist/layers.0eQkKr_w.js +1 -0
  7. package/dist/{layers.DWNz8BXU.js → layers.0i9vKetd.js} +1 -1
  8. package/dist/{layers.C9HjG-Ke.js → layers.2NMr07wA.js} +1 -1
  9. package/dist/{layers.DllKoCC-.js → layers.2ik8_6l2.js} +4 -4
  10. package/dist/{layers.C4MUpR11.js → layers.3IgaNeJn.js} +1 -1
  11. package/dist/{layers.I73LaY9l.js → layers.57i-OqDF.js} +1 -1
  12. package/dist/{layers.N5R3r_JW.js → layers.5eDmsqRK.js} +4 -4
  13. package/dist/{layers.BjCo3vcH.js → layers.A6uZvsgq.js} +1 -1
  14. package/dist/{layers.DvL_TIFt.js → layers.AC0R909h.js} +1 -1
  15. package/dist/{layers.BMuFQo35.js → layers.B2tLYqpD.js} +1 -1
  16. package/dist/{layers.lOjBvW_z.js → layers.B3IZwax6.js} +1 -1
  17. package/dist/{layers.B_tHB3vp.js → layers.B46avS9z.js} +1 -1
  18. package/dist/{layers.BgZZ078S.js → layers.B4dYw--x.js} +1 -1
  19. package/dist/{layers.CNO_iJaQ.js → layers.B6rG2flg.js} +1 -1
  20. package/dist/{layers.CccO8sEt.js → layers.B8ET8FsD.js} +1 -1
  21. package/dist/{layers.DRubLgM4.js → layers.B92Cw5d0.js} +1 -1
  22. package/dist/{layers.CJBsg8gt.js → layers.BAOrIJw4.js} +1 -1
  23. package/dist/{layers.EYF5Mm7Z.js → layers.BAnNbsm5.js} +1 -1
  24. package/dist/{layers.D_1YoHD5.js → layers.BBBiB-Vr.js} +1 -1
  25. package/dist/{layers.kcjgNMat.js → layers.BBuesH9K.js} +1 -1
  26. package/dist/{layers.COJntDrB.js → layers.BC5VUDbx.js} +1 -1
  27. package/dist/{layers.CVf7lCUh.js → layers.BCH9A8C7.js} +5 -5
  28. package/dist/{layers.ChlqtWg7.js → layers.BCSgLmiZ.js} +1 -1
  29. package/dist/{layers.BNBPOImO.js → layers.BEFEVjt6.js} +3 -3
  30. package/dist/{layers.DHbAaa13.js → layers.BELdY7y0.js} +1 -1
  31. package/dist/{layers.jEjLBvNb.js → layers.BLvmw8Wj.js} +4 -4
  32. package/dist/{layers.D__w0kvk.js → layers.BLztyg73.js} +1 -1
  33. package/dist/{layers.C4SLJpNC.js → layers.BPBodejy.js} +4 -4
  34. package/dist/{layers.C6i4OtFS.js → layers.BQ1RGd3f.js} +1 -1
  35. package/dist/{layers.CnoFrdSf.js → layers.BQ8NZ5Il.js} +3 -3
  36. package/dist/{layers.DngWWT6U.js → layers.BQh2C0i_.js} +1 -1
  37. package/dist/{layers.cfgVLC3j.js → layers.BR7w64vi.js} +1 -1
  38. package/dist/{layers.DNFf0CIP.js → layers.BSJulJYA.js} +1 -1
  39. package/dist/{layers.BAs1gi7V.js → layers.BSwfQR19.js} +1 -1
  40. package/dist/layers.BT2zIc1V.js +8 -0
  41. package/dist/{layers.CzydOxOD.js → layers.BT6hqZGs.js} +1 -1
  42. package/dist/{layers.BVlOH3Nl.js → layers.BTWb_5s9.js} +1 -1
  43. package/dist/{layers.IaPxlBs9.js → layers.BUc-e9EX.js} +7 -7
  44. package/dist/{layers.DEY3oL8s.js → layers.BVaFLrsa.js} +1 -1
  45. package/dist/{layers.DwHwJaky.js → layers.BW06U9LZ.js} +1 -1
  46. package/dist/{layers.CIlIALMa.js → layers.BYpLdMwp.js} +1 -1
  47. package/dist/{layers.DBdQ1V7o.js → layers.BcQ82iV2.js} +1 -1
  48. package/dist/{layers.CwrbepKU.js → layers.Bck6NjQV.js} +1 -1
  49. package/dist/{layers.DudnLmlj.js → layers.Bdhwia0v.js} +8 -8
  50. package/dist/{layers.B7nSbTCE.js → layers.Bea-O4CR.js} +1 -1
  51. package/dist/{layers.D9SgYX_-.js → layers.Bew0m5rC.js} +1 -1
  52. package/dist/{layers.Cffd41PM.js → layers.BhChUFXy.js} +1 -1
  53. package/dist/{layers.DAZr6Xea.js → layers.Bib-xN3O.js} +1 -1
  54. package/dist/{layers.Bbfo-AVC.js → layers.Bjx2pakC.js} +1 -1
  55. package/dist/{layers.DkdmnYzo.js → layers.BkAtuLAv.js} +1 -1
  56. package/dist/{layers.DMOjUgDc.js → layers.BkAvTxFf.js} +1 -1
  57. package/dist/{layers.DQ6nDgfc.js → layers.BlGXLSr6.js} +7 -7
  58. package/dist/{layers.C-Uq_JnR.js → layers.Bn6wp3e-.js} +1 -1
  59. package/dist/{layers.B0n0s7E-.js → layers.BnL2kJDr.js} +3 -3
  60. package/dist/{layers.BfoUysXV.js → layers.BnkUnV4r.js} +1 -1
  61. package/dist/{layers.LtK9Fiio.js → layers.BpscNjFu.js} +1 -1
  62. package/dist/{layers.Cv2imAso.js → layers.Bq1lvVgw.js} +1 -1
  63. package/dist/{layers.DKSzEdGc.js → layers.Bqqd0svs.js} +1 -1
  64. package/dist/{layers.D7f0La4N.js → layers.BqyCilll.js} +1 -1
  65. package/dist/{layers.CGWU3X7o.js → layers.BvWYyyIH.js} +1 -1
  66. package/dist/{layers.zm6jLcmi.js → layers.BwKZ7SEE.js} +1 -1
  67. package/dist/{layers.BG9oeLpV.js → layers.BxeAspEX.js} +1 -1
  68. package/dist/{layers.Di2Jxvjf.js → layers.BzB4z4Zi.js} +25 -25
  69. package/dist/{layers.7YU7MHrr.js → layers.C2pxLbos.js} +1 -1
  70. package/dist/{layers.C9ggD_MX.js → layers.C38dZLLN.js} +1 -1
  71. package/dist/{layers.DnQlK70V.js → layers.C4V7oEqG.js} +1 -1
  72. package/dist/{layers.F9Bf26dg.js → layers.C6__hpri.js} +1 -1
  73. package/dist/{layers.qRieu5g0.js → layers.C7FbixU3.js} +1 -1
  74. package/dist/{layers.32sfaCUl.js → layers.C7Rys0zv.js} +2 -2
  75. package/dist/{layers.CVLD0ZDM.js → layers.C85Wk4Xu.js} +2 -2
  76. package/dist/{layers.BO4RdpPz.js → layers.C98A6Pk3.js} +1 -1
  77. package/dist/{layers.COUHJCMK.js → layers.C9ApzN6P.js} +4 -4
  78. package/dist/{layers.Y6OKUmle.js → layers.CCw9EckU.js} +4 -4
  79. package/dist/{layers.DU56eEUj.js → layers.CILzqg5B.js} +1 -1
  80. package/dist/{layers.BqsHgxbo.js → layers.CMPhz83-.js} +1 -1
  81. package/dist/layers.CNZ3C3z8.js +276 -0
  82. package/dist/{layers.C5AIfP3j.js → layers.CNk-RIr6.js} +1 -1
  83. package/dist/{layers.D30czbpI.js → layers.CO-4dR7L.js} +1 -1
  84. package/dist/{layers.Bn0rUGpF.js → layers.CQv460Zq.js} +1 -1
  85. package/dist/{layers.C0VuF8DM.js → layers.CSRRbBDC.js} +1 -1
  86. package/dist/{layers.DtnnIg1t.js → layers.CSZwIgFb.js} +1 -1
  87. package/dist/{layers.CaJkA5DB.js → layers.CV3uMdkK.js} +2 -2
  88. package/dist/{layers.DSv-v2De.js → layers.CV7X73-0.js} +3 -3
  89. package/dist/{layers.C7V3tYKb.js → layers.CVQdNUmq.js} +1 -1
  90. package/dist/{layers.DR7clma3.js → layers.CVzEzv6N.js} +1 -1
  91. package/dist/{layers.DgFs-GB2.js → layers.CYxBzqtY.js} +1 -1
  92. package/dist/{layers.DUAQX84x.js → layers.CaF8EYt3.js} +1 -1
  93. package/dist/{layers.BrS9VPcR.js → layers.CeBCW73U.js} +1 -1
  94. package/dist/{layers.Kt6HTpa4.js → layers.Cf22pyUO.js} +1 -1
  95. package/dist/{layers.D0dxYpgu.js → layers.CfSK31zY.js} +1 -1
  96. package/dist/{layers.C5BvrYPn.js → layers.Cfh_rUFc.js} +1 -1
  97. package/dist/{layers.Cbfu6xtI.js → layers.CgkPpXW_.js} +1 -1
  98. package/dist/{layers.0s890aWJ.js → layers.ChJbBMSR.js} +1 -1
  99. package/dist/{layers.Ca4oxgxo.js → layers.CiEOeAXK.js} +5 -5
  100. package/dist/{layers.BNNbARGZ.js → layers.CimxPbPT.js} +1 -1
  101. package/dist/layers.Cju97Vjl.js +6 -0
  102. package/dist/{layers.CxZyzwFF.js → layers.Cm3sLE1Z.js} +1 -1
  103. package/dist/{layers.D_sNxjxf.js → layers.Cm8LsPwk.js} +3 -3
  104. package/dist/{layers.CSUkAE0q.js → layers.Cq3dRtYC.js} +1 -1
  105. package/dist/{layers.B8gjlyiW.js → layers.CqlW2vwb.js} +1 -1
  106. package/dist/{layers.DZuIAyTe.js → layers.Ct8Ta7Q6.js} +1 -1
  107. package/dist/{layers.C9o9vDoa.js → layers.CumFtFgR.js} +1 -1
  108. package/dist/{layers.DClpKhxv.js → layers.Cv7K3AF4.js} +1 -1
  109. package/dist/{layers.B5e5X9Ym.js → layers.Cwc1z5ZE.js} +1 -1
  110. package/dist/{layers.U1NaH79o.js → layers.CwqGv21r.js} +1 -1
  111. package/dist/{layers.X3zac8jQ.js → layers.CwwZhxpz.js} +1 -1
  112. package/dist/{layers.D8AS2qma.js → layers.CxWhysSV.js} +1 -1
  113. package/dist/{layers.CF7JiCph.js → layers.CyGGIu23.js} +1 -1
  114. package/dist/{layers.GohLKb9o.js → layers.CyTrQX4y.js} +1 -1
  115. package/dist/{layers.izNODSur.js → layers.Cya0jfN8.js} +1 -1
  116. package/dist/layers.Cz6M1RAd.js +28300 -0
  117. package/dist/{layers.BcMMhKnD.js → layers.Czf1cJZ8.js} +3 -3
  118. package/dist/{layers.DgS-Co7K.js → layers.D04Y5q_U.js} +1 -1
  119. package/dist/{layers.DBVLnyVE.js → layers.D0l0EHI-.js} +1 -1
  120. package/dist/{layers.B1ZyqNRM.js → layers.D1cPOqnS.js} +1 -1
  121. package/dist/{layers.DomyWbef.js → layers.D2Oaivvt.js} +4 -4
  122. package/dist/{layers.7xY8zequ.js → layers.D2QnqgK2.js} +1 -1
  123. package/dist/{layers.DjrqjYKb.js → layers.D2rRC-ys.js} +1 -1
  124. package/dist/{layers.CsTC6xdu.js → layers.D5SkJMwa.js} +1 -1
  125. package/dist/{layers.DwzloX9Y.js → layers.D5b8Z5wy.js} +1 -1
  126. package/dist/{layers.veSWcio5.js → layers.DA1oZ2tY.js} +1 -1
  127. package/dist/{layers.CQwyCYuY.js → layers.DAhAGovh.js} +1 -1
  128. package/dist/{layers.NfVJM9V8.js → layers.DDd8M3Nr.js} +3 -3
  129. package/dist/{layers.CI-gTGNf.js → layers.DGKZ8xYk.js} +2 -2
  130. package/dist/{layers.CTdBLgBZ.js → layers.DIVBRmsy.js} +1 -1
  131. package/dist/{layers.z1t8pspX.js → layers.DIlz2Zcu.js} +1 -1
  132. package/dist/{layers.CC27VJVq.js → layers.DIt_yl-l.js} +1 -1
  133. package/dist/{layers.B8EmDWBp.js → layers.DJ2qTYKr.js} +1 -1
  134. package/dist/{layers.CJZRhFIz.js → layers.DKcXnJJV.js} +3 -3
  135. package/dist/{layers.TC2CgPLy.js → layers.DL25C7qT.js} +1 -1
  136. package/dist/{layers.o82vkF11.js → layers.DMPFv7Fz.js} +1 -1
  137. package/dist/layers.DMmHVnts.js +129 -0
  138. package/dist/{layers.x0dkQ1bt.js → layers.DNW2KScZ.js} +1 -1
  139. package/dist/{layers.CaEok_wY.js → layers.DP-rn0Uc.js} +1 -1
  140. package/dist/{layers.Bj1gWEXB.js → layers.DPQjdkry.js} +1 -1
  141. package/dist/{layers.BPYJayyl.js → layers.DPvhzY0F.js} +1 -1
  142. package/dist/{layers.Cfcfeu7c.js → layers.DQaoQnL_.js} +1 -1
  143. package/dist/{layers.DlfP_W1w.js → layers.DSLoDtB5.js} +6 -6
  144. package/dist/{layers.DymX_rzT.js → layers.DYNoKpHA.js} +1 -1
  145. package/dist/{layers.D1wQJCP6.js → layers.DagpSO6b.js} +1 -1
  146. package/dist/{layers.CKw6bqBo.js → layers.Dd0ulM7L.js} +1 -1
  147. package/dist/{layers.CVcK32bw.js → layers.Dd5BXNf9.js} +1 -1
  148. package/dist/{layers.D_nCC_Gk.js → layers.DdEKAPU6.js} +3 -3
  149. package/dist/{layers.C-S-OXIw.js → layers.Dj-tWMPT.js} +1 -1
  150. package/dist/{layers.DaIP2Oiu.js → layers.DjovsJgM.js} +1 -1
  151. package/dist/{layers.DBNEjpiE.js → layers.DjvwCzX1.js} +1 -1
  152. package/dist/{layers.CnjcVUt-.js → layers.DlGEEQo6.js} +1 -1
  153. package/dist/{layers.I3PiCI9B.js → layers.DmzeeiW6.js} +1 -1
  154. package/dist/{layers.BNBB2nhh.js → layers.DqhuPwie.js} +1 -1
  155. package/dist/{layers.TYt3RKP1.js → layers.DrbEas4c.js} +1 -1
  156. package/dist/{layers.BIpST2Nm.js → layers.Dt4ccLj9.js} +1 -1
  157. package/dist/{layers.BxjQNikW.js → layers.DubEHOZc.js} +1 -1
  158. package/dist/{layers.DKbmg4NI.js → layers.Dv0NTtiZ.js} +1 -1
  159. package/dist/{layers.Cdcj2p-u.js → layers.DvsDhmnx.js} +2 -2
  160. package/dist/{layers.CJ4y6VwK.js → layers.DwHDiVbc.js} +1 -1
  161. package/dist/{layers.BV39QvSF.js → layers.DxP8BLwm.js} +1 -1
  162. package/dist/{layers.BiOtIGEg.js → layers.DxwbhoAk.js} +1 -1
  163. package/dist/{layers.BOBEA042.js → layers.DypIGFji.js} +1 -1
  164. package/dist/{layers.C8ghCwyt.js → layers.Dz2o5CxF.js} +1 -1
  165. package/dist/{layers.CTGCrng0.js → layers.DzCckueA.js} +1 -1
  166. package/dist/{layers.xgFpsyVh.js → layers.DzNrHwjz.js} +1 -1
  167. package/dist/{layers.DzuUCbVg.js → layers.Dz_ylahe.js} +3 -3
  168. package/dist/{layers.Db7omJT6.js → layers.DzdPgRrM.js} +1 -1
  169. package/dist/{layers.DPbvdZcv.js → layers.EC_umiAq.js} +1 -1
  170. package/dist/{layers.k741r9El.js → layers.GmMUChw0.js} +1 -1
  171. package/dist/{layers.cXMANsAM.js → layers.GpR-ajNO.js} +3 -3
  172. package/dist/{layers.D54MS4JQ.js → layers.HuvCGno0.js} +4 -4
  173. package/dist/{layers.CvRpPQpf.js → layers.Hv5aSo_0.js} +1 -1
  174. package/dist/{layers.DTFAMOsh.js → layers.K-naCwh4.js} +1 -1
  175. package/dist/{layers.Bsw9cb6W.js → layers.K9W4tXVj.js} +1 -1
  176. package/dist/{layers.ChovUXZY.js → layers.KuBwBALX.js} +4 -4
  177. package/dist/{layers.B5cuX8TZ.js → layers.LkuruMKl.js} +1 -1
  178. package/dist/{layers.Bn3Kvs8N.js → layers.MX9lxQ6G.js} +1 -1
  179. package/dist/{layers.C-8utZaX.js → layers.Q0Xp1Q-P.js} +1 -1
  180. package/dist/{layers.CUBC0j_0.js → layers.QJ4-VO9_.js} +1 -1
  181. package/dist/{layers.DK7BeJ11.js → layers.QP6Cr2Nl.js} +1 -1
  182. package/dist/layers.R8mPlCA0.js +261 -0
  183. package/dist/{layers.Piz44sNs.js → layers.SSAR8euQ.js} +1 -1
  184. package/dist/{layers.BMl6pIJd.js → layers.TnFH8KYM.js} +1 -1
  185. package/dist/{layers.D0ZumZJT.js → layers.TxdNho-c.js} +4 -4
  186. package/dist/{layers.b8GNfwfM.js → layers.VPt1VCtx.js} +1 -1
  187. package/dist/{layers.DVFEGnDJ.js → layers.WJ7FT-_X.js} +1 -1
  188. package/dist/{layers.DmBZUQ5G.js → layers.XKMvbn0C.js} +1 -1
  189. package/dist/{layers.DW_xTQxO.js → layers.YNq9tvLz.js} +1 -1
  190. package/dist/{layers.CEds-Rt0.js → layers.YZlWxcrC.js} +1 -1
  191. package/dist/{layers.CQ5_GklQ.js → layers.ZWO2oaCs.js} +1 -1
  192. package/dist/{layers.CDT1UDt_.js → layers._OuJa7nT.js} +1 -1
  193. package/dist/layers.b9B2NY7n.js +11690 -0
  194. package/dist/{layers.DY_iZBDd.js → layers.bX48DvmK.js} +2 -2
  195. package/dist/{layers.B5l4HZ4C.js → layers.djaCdv2S.js} +2 -2
  196. package/dist/{layers.B4f4vul7.js → layers.f6YbpTJZ.js} +1 -1
  197. package/dist/{layers.BSFqxkS3.js → layers.fj4ECrmO.js} +1 -1
  198. package/dist/layers.g774TOP4.js +1 -0
  199. package/dist/{layers.DguDn0vP.js → layers.h-iodP5b.js} +1 -1
  200. package/dist/{layers.CPpVqPlD.js → layers.hyEKDEhn.js} +1 -1
  201. package/dist/{layers.B7OYbfhG.js → layers.jJFeQDnO.js} +1 -1
  202. package/dist/{layers.NQUbG1RG.js → layers.kSiuerJ9.js} +1 -1
  203. package/dist/{layers.CIKF0IB-.js → layers.krbJBCbv.js} +1 -1
  204. package/dist/{layers.lOryM08N.js → layers.kyX4tHs8.js} +1 -1
  205. package/dist/layers.l4nJXrV3.js +1 -0
  206. package/dist/{layers.UqlDgoDE.js → layers.pqYdKNCf.js} +1 -1
  207. package/dist/{layers.CHCyJMu3.js → layers.uDTUbBxv.js} +1 -1
  208. package/dist/{layers.JFUGrD3Y.js → layers.ujDhe2Ed.js} +1 -1
  209. package/dist/{layers.CWZiCOwS.js → layers.unOIW4mt.js} +1 -1
  210. package/dist/{layers.DpuRYukB.js → layers.vBNkCeKg.js} +1 -1
  211. package/dist/{layers.DsT8J6fH.js → layers.wYs9uUGI.js} +1 -1
  212. package/dist/{layers.CycmAced.js → layers.ywX6nW5o.js} +1 -1
  213. package/package.json +160 -160
  214. package/dist/layers.BpgxikTB.js +0 -389
  215. package/dist/layers.CFixCkfY.js +0 -1
  216. package/dist/layers.CWnQwM6Z.js +0 -1
  217. package/dist/layers.Cb00RMfQ.js +0 -8
  218. package/dist/layers.CtXlNsYA.js +0 -6
  219. package/dist/layers.diNdCuZw.js +0 -39424
package/README.md CHANGED
@@ -1,830 +1,830 @@
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
- const fetchUploadMedia = async (
158
- file: File,
159
- success: (url: string, id: string) => void,
160
- error?: (error?: Error) => void
161
- ) => {
162
- const formData = new FormData();
163
- formData.append('File', file);
164
- formData.append('FileAccessModifier', '0');
165
-
166
- try {
167
- const response = await fetch('/api/v1/Files/Upload', {
168
- method: 'POST',
169
- body: formData,
170
- credentials: 'include'
171
- });
172
-
173
- if (!response.ok) {
174
- throw new Error('File upload failed');
175
- }
176
-
177
- const data = await response.json();
178
- const { Id, Url } = data;
179
-
180
- success(Url, Id);
181
- } catch (err) {
182
- if (error) {
183
- if (err instanceof Error) {
184
- error(err);
185
- } else {
186
- error(new Error('An unknown error occurred'));
187
- }
188
- }
189
- }
190
- };
191
-
192
- const fetchUploadMedia = async (
193
- file: File,
194
- success: (url: string, id: string, data: any) => void,
195
- error?: (err: Error) => void,
196
- signal?: AbortSignal,
197
- onProgress?: (percent: number) => void,
198
- ) => {
199
- const formData = new FormData();
200
- formData.append('File', file);
201
- formData.append('FileAccessModifier', '0');
202
-
203
- const xhr = new XMLHttpRequest();
204
- xhr.open('POST', '/api/v1/Files/Upload');
205
- xhr.withCredentials = true;
206
-
207
- if (signal) signal.addEventListener('abort', () => xhr.abort());
208
- if (onProgress) {
209
- xhr.upload.onprogress = (e) => {
210
- if (e.lengthComputable) onProgress(Math.round((e.loaded / e.total) * 100));
211
- };
212
- }
213
-
214
- xhr.onload = () => {
215
- try {
216
- const data = JSON.parse(xhr.responseText);
217
- success(`/v1/attachments/${data.id}`, data.id, data);
218
- } catch {
219
- error?.(new Error('Invalid response'));
220
- }
221
- };
222
-
223
- xhr.onerror = () => error?.(new Error('Upload error')));
224
- xhr.send(formData);
225
- };
226
-
227
-
228
- <Editor
229
- ...props
230
- fetchUploadMedia={fetchUploadMedia}
231
- />
232
- ```
233
-
234
- ## Image Deletion
235
-
236
- 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.
237
-
238
- ```
239
- const fetchDeleteMedia = async (
240
- id: string,
241
- success: () => void,
242
- error?: (error?: Error) => void
243
- ) => {
244
- const body = { Ids: [id] };
245
-
246
- try {
247
- const response = await fetch('/api/v1/Documents/Delete', {
248
- method: 'POST',
249
- headers: {
250
- 'Content-Type': 'application/json'
251
- },
252
- body: JSON.stringify(body),
253
- credentials: 'include'
254
- });
255
-
256
- await response.json();
257
- success();
258
- } catch (err) {
259
- if (error) {
260
- if (err instanceof Error) {
261
- error(err);
262
- } else {
263
- error(new Error('An unknown error occurred'));
264
- }
265
- }
266
- }
267
- };
268
-
269
- <Editor
270
- ...props
271
- fetchUploadMedia={fetchUploadMedia}
272
- fetchDeleteMedia={fetchUploadMedia}
273
- />
274
- ```
275
-
276
- ## Additional options for working with image uploads.
277
-
278
- ```
279
- import { Editor, Dropzone } from "@sinups/editor-dsd";
280
-
281
- const Content = () => (
282
- <Group justify="center" gap="xl" mih={220} style={{ pointerEvents: 'none' }}>
283
- {/*
284
- The components Dropzone.Accept, Dropzone.Reject, and Dropzone.Idle are visible only when the user performs specific actions:
285
-
286
- Dropzone.Accept is visible only when the user drags a file that can be accepted into the drop zone.
287
- Dropzone.Reject is visible only when the user drags a file that cannot be accepted into the drop zone.
288
- Dropzone.Idle is visible when the user is not dragging any file into the drop zone.
289
- */}
290
- <Dropzone.Accept>
291
- <IconUpload
292
- style={{ width: rem(52), height: rem(52), color: 'var(--mantine-color-blue-6)' }}
293
- stroke={1.5}
294
- />
295
- </Dropzone.Accept>
296
- <Dropzone.Reject>
297
- <IconX
298
- style={{ width: rem(52), height: rem(52), color: 'var(--mantine-color-red-6)' }}
299
- stroke={1.5}
300
- />
301
- </Dropzone.Reject>
302
- <Dropzone.Idle>
303
- <IconPhoto
304
- style={{ width: rem(52), height: rem(52), color: 'var(--mantine-color-dimmed)' }}
305
- stroke={1.5}
306
- />
307
- </Dropzone.Idle>
308
-
309
- <div>
310
- <Text size="xl" inline>
311
- Drag images here or click to select files
312
- </Text>
313
- <Text size="sm" c="dimmed" inline mt={7}>
314
- Attach as many files as you want, each file must not exceed{' '} {maxFileSize} МБ.
315
- </Text>
316
- </div>
317
- </Group>
318
- );
319
-
320
- <Editor
321
- ...props
322
- fetchUploadMedia={fetchUploadMedia}
323
- contentModalUploadImage={Content}
324
- maxFileSize={5}
325
- maxImageSizeError={() => {}}
326
- />
327
- ```
328
-
329
- ## File upload
330
-
331
- For uploading a file or audio, you might need the third parameter "data".
332
-
333
- ```
334
- const fetchUploadMedia = async (
335
- file: File,
336
- success: (url: string, id: string, data?: {
337
- contentType: string;
338
- fileSize: string;
339
- originalFileName: string;
340
- }) => void,
341
- error?: (error?: Error) => void
342
- ) => {
343
- const formData = new FormData();
344
- formData.append('File', file);
345
- formData.append('FileAccessModifier', '0');
346
-
347
- try {
348
- const response = await fetch('/api/v1/Files/Upload', {
349
- method: 'POST',
350
- body: formData,
351
- credentials: 'include'
352
- });
353
-
354
- if (!response.ok) {
355
- throw new Error('File upload failed');
356
- }
357
-
358
- const data = await response.json();
359
- const { Id, Url } = data;
360
-
361
- success(Url, Id, data);
362
- } catch (err) {
363
- if (error) {
364
- if (err instanceof Error) {
365
- error(err);
366
- } else {
367
- error(new Error('An unknown error occurred'));
368
- }
369
- }
370
- }
371
- };
372
- ```
373
- </details>
374
-
375
-
376
- <details>
377
- <summary>
378
- 🤖 AI
379
- </summary>
380
-
381
- ## Connect AI
382
-
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
- </details>
427
-
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
444
- {...props}
445
- onTrack={trackGoal}
446
- />
447
- ```
448
-
449
- ### Custom Handler
450
-
451
- ```tsx
452
- const handleTrack = (event: string, params?: Record<string, unknown>) => {
453
- console.log('Editor event:', event, params);
454
-
455
- // Send to your analytics provider
456
- myAnalytics.track(event, params);
457
- };
458
-
459
- <Editor
460
- {...props}
461
- onTrack={handleTrack}
462
- />
463
- ```
464
-
465
- ### Type Signature
466
-
467
- ```ts
468
- type EditorTrackFn = (
469
- event: string,
470
- params?: Record<string, unknown>,
471
- ) => void;
472
- ```
473
-
474
- ### Tracked Events
475
-
476
- | Event | Trigger | Plugin |
477
- |-------|---------|--------|
478
- | `block_table_created` | User inserts a table | BlockFormatDropDown |
479
- | `block_image_added` | User inserts an image | BlockFormatDropDown |
480
- | `block_code_created` | User inserts a code block | BlockFormatDropDown |
481
- | `block_layout_used` | User inserts a grid/layout | BlockFormatDropDown |
482
- | `block_collapse_created` | User inserts a toggle/collapsible | BlockFormatDropDown |
483
- | `block_link_inserted` | User inserts a link | ToolbarPlugin |
484
- | `block_comment_added` | User adds an inline comment | ToolbarPlugin |
485
- | `ai_menu_opened` | User clicks the AI toolbar button | ToolbarPlugin/AI |
486
- | `block_heading_created` | User creates a heading (h1-h4) | BlockFormatDropDown |
487
- | `list_bullet_created` | User creates a bullet list | BlockFormatDropDown |
488
- | `list_number_created` | User creates a numbered list | BlockFormatDropDown |
489
- | `list_check_created` | User creates a checklist | BlockFormatDropDown |
490
- | `block_quote_created` | User creates a quote block | BlockFormatDropDown |
491
- | `block_divider_inserted` | User inserts a horizontal rule | BlockFormatDropDown |
492
- | `block_child_docs_inserted` | User inserts child documents block | BlockFormatDropDown |
493
- | `block_embed_added` | User adds an embed/integration | BlockFormatDropDown |
494
- | `media_audio_added` | User adds an audio block | BlockFormatDropDown |
495
- | `media_file_added` | User adds a file block | BlockFormatDropDown |
496
- | `table_row_added` | User inserts a table row | TableActionMenuPlugin |
497
- | `table_column_added` | User inserts a table column | TableActionMenuPlugin |
498
- | `table_row_deleted` | User deletes a table row | TableActionMenuPlugin |
499
- | `table_column_deleted` | User deletes a table column | TableActionMenuPlugin |
500
- | `block_duplicated` | User duplicates a block | DraggableBlockPlugin |
501
- | `block_deleted` | User deletes a block | DraggableBlockPlugin |
502
- | `text_code_toggled` | User toggles inline code format | ToolbarPlugin |
503
- | `text_formatting_cleared` | User clears all text formatting | ToolbarPlugin |
504
-
505
- > Events fire from both the toolbar dropdown menu and the slash command menu (`/`).
506
-
507
- ### What Happens Without onTrack?
508
-
509
- 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.
510
-
511
- This means:
512
- - **No analytics SDK required** — the editor is a standalone package with zero analytics dependencies
513
- - **Safe to omit** — if you don't need tracking, simply don't pass the prop
514
- - **No counter needed** — the editor itself never calls `ym()`, `gtag()`, or any external API directly
515
-
516
- ### How It Works Internally
517
-
518
- 1. `onTrack` is passed as a prop to `<Editor>` and stored in React Context
519
- 2. Plugins access it via `useContext(Context)` and call `onTrack?.('event_name')`
520
- 3. The host app decides what to do with the event (send to Metrika, log, ignore)
521
-
522
- ```
523
- Host App Editor Package
524
- ───────── ──────────────
525
- trackGoal() ──→ onTrack prop ──→ Context.onTrack
526
- │ │
527
- │ Plugins call:
528
- │ onTrack?.('block_table_created')
529
- │ │
530
- ◄────────────────────────────────┘
531
-
532
- ym(ID, 'reachGoal', 'block_table_created')
533
- dataLayer.push({ event: 'block_table_created' })
534
- ```
535
-
536
- </details>
537
-
538
-
539
- <details>
540
- <summary>
541
- 👥 Collaboration
542
- </summary>
543
-
544
- ```jsx
545
- <Editor
546
- {...props}
547
- ws={{
548
- url: 'https://wss.dudoc.io/', // WebSocket URL
549
- id: '322323', // Unique document ID
550
- user: userProfile, // Current user
551
- getActiveUsers: (users) => {
552
- // Returns active users editing the document
553
- setActiveUsers(users);
554
- },
555
- }}
556
- />
557
- ```
558
-
559
- </details>
560
-
561
- <details>
562
- <summary>
563
- 📝 Additional options
564
- </summary>
565
-
566
- ## Reset editor content
567
-
568
- ```
569
-
570
- import { CLEAR_EDITOR_COMMAND } from './EditorLexical';
571
-
572
- <>
573
- <button
574
- onClick={() => {
575
- if (editorRef.current) {
576
- editorRef.current.update(() => {
577
- editorRef.current?.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined);
578
- });
579
- }
580
- }}
581
- >
582
- Reset
583
- </button>
584
- <Editor
585
- ...props
586
- editorRef={editorRef}
587
- />
588
- <>
589
- ```
590
-
591
- </details>
592
-
593
- <details>
594
- <summary>
595
- 🧪 Testing
596
- </summary>
597
-
598
- ## Testing Overview
599
-
600
- 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.
601
-
602
- ### Prerequisites
603
-
604
- Before running tests, make sure you have installed all dependencies:
605
-
606
- ```bash
607
- npm install
608
- ```
609
-
610
- ## Unit Tests (Vitest)
611
-
612
- Unit tests are written with **Vitest** and **jsdom** for testing individual components and utilities.
613
-
614
- ### Run Unit Tests
615
-
616
- ```bash
617
- # Run all unit tests
618
- npm run test-unit
619
-
620
- # Run unit tests in watch mode (auto-rerun on changes)
621
- npm run test-unit-watch
622
- ```
623
-
624
- ### Unit Test Files Location
625
- - `__tests__/unit/` - Unit test files
626
- - Test files follow the pattern: `*.test.ts` or `*.test.tsx`
627
-
628
- ## End-to-End Tests (Playwright)
629
-
630
- E2E tests use **Playwright** to test the complete application flow in real browsers.
631
-
632
- ### Run E2E Tests
633
-
634
- ```bash
635
- # Run all E2E tests (WebKit only for CI optimization)
636
- npm run test:e2e
637
-
638
- # Run E2E tests with UI mode (interactive)
639
- npm run test:e2e:ui
640
-
641
- # Run E2E tests in debug mode
642
- npm run test:e2e:debug
643
-
644
- # Run E2E tests in headed mode (visible browser)
645
- npm run test:e2e:headed
646
- ```
647
-
648
- ### E2E Test Files Location
649
- - `__tests__/e2e/` - End-to-end test files
650
- - `__tests__/regression/` - Regression test files
651
- - Test files follow the pattern: `*.spec.js`, `*.spec.mjs`, or `*.spec.ts`
652
-
653
- ### Browser Support
654
- - **WebKit** (Safari) - Primary browser for CI/CD
655
- - **Chromium** and **Firefox** - Available for local testing
656
-
657
- ## Test Server
658
-
659
- The test server automatically starts when running E2E tests:
660
-
661
- ```bash
662
- # Manual test server start (if needed)
663
- npm run start-test-server
664
- ```
665
-
666
- - **URL**: `http://localhost:3000`
667
- - **Mode**: Full editor mode with all features enabled
668
- - **Environment**: `VITE_LAYERS=true`
669
-
670
- ## Test Configuration
671
-
672
- ### Playwright Configuration
673
- - **Config file**: `playwright.config.js`
674
- - **Test directory**: `./__tests__/e2e/`
675
- - **Browser**: WebKit (optimized for CI)
676
- - **Base URL**: `http://localhost:3000`
677
- - **Timeout**: 90 seconds per test
678
- - **Retries**: 2 retries in CI, 0 locally
679
-
680
- ### Vitest Configuration
681
- - **Config file**: `vitest.config.mts`
682
- - **Environment**: jsdom
683
- - **Setup file**: `vitest.setup.mts`
684
- - **Coverage**: V8 provider
685
-
686
- ## CI/CD Testing
687
-
688
- Tests run automatically on:
689
- - **Push** to `main` or `dev` branches
690
- - **Pull requests** to `main` or `dev` branches
691
- - **Manual trigger** via GitHub Actions
692
-
693
- ### GitHub Actions Workflow
694
- - **File**: `.github/workflows/tests.yml`
695
- - **Runner**: Ubuntu Latest
696
- - **Node.js**: Version 20
697
- - **Browser caching**: Playwright browsers cached for faster runs
698
- - **Artifacts**: Test reports and traces uploaded on completion
699
-
700
- ## Test Examples
701
-
702
- ### Basic E2E Test Structure
703
-
704
- ```javascript
705
- // __tests__/e2e/example.spec.mjs
706
- import { test, expect } from '@playwright/test';
707
- import { focusEditor } from '../utils/index.mjs';
708
-
709
- test('Can type text in editor', async ({ page }) => {
710
- await page.goto('/');
711
- await focusEditor(page);
712
-
713
- const editor = page.locator('[contenteditable="true"]').first();
714
- await editor.type('Hello World');
715
-
716
- await expect(editor).toContainText('Hello World');
717
- });
718
- ```
719
-
720
- ### Unit Test Structure
721
-
722
- ```typescript
723
- // __tests__/unit/example.test.ts
724
- import { describe, it, expect } from 'vitest';
725
- import { render } from '@testing-library/react';
726
- import { Editor } from '../src/Editor';
727
-
728
- describe('Editor Component', () => {
729
- it('renders without crashing', () => {
730
- const { container } = render(<Editor />);
731
- expect(container).toBeTruthy();
732
- });
733
- });
734
- ```
735
-
736
- ## Debugging Tests
737
-
738
- ### Debug E2E Tests
739
-
740
- ```bash
741
- # Run with Playwright Inspector
742
- npm run test:e2e:debug
743
-
744
- # Run specific test file
745
- npx playwright test __tests__/e2e/TextEntry.spec.mjs --debug
746
-
747
- # Run with headed browser
748
- npm run test:e2e:headed
749
- ```
750
-
751
- ### View Test Reports
752
-
753
- ```bash
754
- # Open HTML report (after running tests)
755
- npx playwright show-report
756
-
757
- # View test traces (for failed tests)
758
- npx playwright show-trace test-results/[test-name]/trace.zip
759
- ```
760
-
761
- ## Test Utilities
762
-
763
- Common test utilities are available in `__tests__/utils/index.mjs`:
764
-
765
- - `focusEditor(page)` - Focus the main editor
766
- - `selectAll(page)` - Select all text in editor
767
- - `moveLeft(page, count)` - Move cursor left
768
- - `selectCharacters(page, count)` - Select specific number of characters
769
- - `waitForSelector(page, selector)` - Wait for element to appear
770
-
771
- ## Performance
772
-
773
- ### Test Execution Times
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
- - **Browser Caching**: Playwright browsers cached in CI
780
- - **Single Worker**: Prevents race conditions in CI
781
- - **WebKit Only**: Faster than multi-browser matrix
782
- - **Smart Retries**: Auto-retry flaky tests
783
-
784
- ## Troubleshooting
785
-
786
- ### Common Issues
787
-
788
- 1. **Port conflicts**: Ensure port 3000 is available
789
- 2. **Browser installation**: Run `npx playwright install` if needed
790
- 3. **Test timeouts**: Check if test server is running properly
791
- 4. **Certificate errors**: Tests use HTTP to avoid HTTPS certificate issues
792
-
793
- ### Reset Test Environment
794
-
795
- ```bash
796
- # Clear Playwright cache
797
- npx playwright install --force
798
-
799
- # Reset node_modules
800
- rm -rf node_modules package-lock.json
801
- npm install
802
- ```
803
-
804
- </details>
805
-
806
- <details>
807
- <summary>
808
- ⚙️ Properties
809
- </summary>
810
-
811
- ```
812
- 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.
813
- debounce?: number - Defines how often the onChange function is called, in milliseconds.
814
- 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.
815
- outputFormat?: 'html' | 'json' - The outputFormat property defines whether we want to output an HTML string or a JSON object. The default is JSON.
816
- initialContent: string | object - The initial content for the editor.
817
- maxHeight?: number - Sets the height of the editor. The default is 100%.
818
- mode?: 'simple' | 'default' | 'full' | 'editor' - The editor mode. Depending on the chosen mode, functionality may be restricted or extended. The default is default.
819
- fetchUploadMedia?: (file: File, success: (url: string, id: string, error?: (error?: Error) => void) => void) - Function to upload an image to your service.
820
- fetchDeleteMedia?: (id: string, success: () => void, error?: (error?: Error) => void) - Helper function to delete an image.
821
- maxFileSize?: number - The maximum image size in megabytes.
822
- contentModalUploadImage?: React.FunctionComponent - A React component to replace content in DropZone.
823
- maxImageSizeError?: () => void - A function that is called if the image exceeds the maxFileSize.
824
- disable?: boolean - Toggles the editor into read-only mode.
825
- 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.
826
- editorRef?: { current: EditorType | null } - Reference to the editor.
827
- 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.
828
- ```
829
-
830
- </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
+ const fetchUploadMedia = async (
158
+ file: File,
159
+ success: (url: string, id: string) => void,
160
+ error?: (error?: Error) => void
161
+ ) => {
162
+ const formData = new FormData();
163
+ formData.append('File', file);
164
+ formData.append('FileAccessModifier', '0');
165
+
166
+ try {
167
+ const response = await fetch('/api/v1/Files/Upload', {
168
+ method: 'POST',
169
+ body: formData,
170
+ credentials: 'include'
171
+ });
172
+
173
+ if (!response.ok) {
174
+ throw new Error('File upload failed');
175
+ }
176
+
177
+ const data = await response.json();
178
+ const { Id, Url } = data;
179
+
180
+ success(Url, Id);
181
+ } catch (err) {
182
+ if (error) {
183
+ if (err instanceof Error) {
184
+ error(err);
185
+ } else {
186
+ error(new Error('An unknown error occurred'));
187
+ }
188
+ }
189
+ }
190
+ };
191
+
192
+ const fetchUploadMedia = async (
193
+ file: File,
194
+ success: (url: string, id: string, data: any) => void,
195
+ error?: (err: Error) => void,
196
+ signal?: AbortSignal,
197
+ onProgress?: (percent: number) => void,
198
+ ) => {
199
+ const formData = new FormData();
200
+ formData.append('File', file);
201
+ formData.append('FileAccessModifier', '0');
202
+
203
+ const xhr = new XMLHttpRequest();
204
+ xhr.open('POST', '/api/v1/Files/Upload');
205
+ xhr.withCredentials = true;
206
+
207
+ if (signal) signal.addEventListener('abort', () => xhr.abort());
208
+ if (onProgress) {
209
+ xhr.upload.onprogress = (e) => {
210
+ if (e.lengthComputable) onProgress(Math.round((e.loaded / e.total) * 100));
211
+ };
212
+ }
213
+
214
+ xhr.onload = () => {
215
+ try {
216
+ const data = JSON.parse(xhr.responseText);
217
+ success(`/v1/attachments/${data.id}`, data.id, data);
218
+ } catch {
219
+ error?.(new Error('Invalid response'));
220
+ }
221
+ };
222
+
223
+ xhr.onerror = () => error?.(new Error('Upload error')));
224
+ xhr.send(formData);
225
+ };
226
+
227
+
228
+ <Editor
229
+ ...props
230
+ fetchUploadMedia={fetchUploadMedia}
231
+ />
232
+ ```
233
+
234
+ ## Image Deletion
235
+
236
+ 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.
237
+
238
+ ```
239
+ const fetchDeleteMedia = async (
240
+ id: string,
241
+ success: () => void,
242
+ error?: (error?: Error) => void
243
+ ) => {
244
+ const body = { Ids: [id] };
245
+
246
+ try {
247
+ const response = await fetch('/api/v1/Documents/Delete', {
248
+ method: 'POST',
249
+ headers: {
250
+ 'Content-Type': 'application/json'
251
+ },
252
+ body: JSON.stringify(body),
253
+ credentials: 'include'
254
+ });
255
+
256
+ await response.json();
257
+ success();
258
+ } catch (err) {
259
+ if (error) {
260
+ if (err instanceof Error) {
261
+ error(err);
262
+ } else {
263
+ error(new Error('An unknown error occurred'));
264
+ }
265
+ }
266
+ }
267
+ };
268
+
269
+ <Editor
270
+ ...props
271
+ fetchUploadMedia={fetchUploadMedia}
272
+ fetchDeleteMedia={fetchUploadMedia}
273
+ />
274
+ ```
275
+
276
+ ## Additional options for working with image uploads.
277
+
278
+ ```
279
+ import { Editor, Dropzone } from "@sinups/editor-dsd";
280
+
281
+ const Content = () => (
282
+ <Group justify="center" gap="xl" mih={220} style={{ pointerEvents: 'none' }}>
283
+ {/*
284
+ The components Dropzone.Accept, Dropzone.Reject, and Dropzone.Idle are visible only when the user performs specific actions:
285
+
286
+ Dropzone.Accept is visible only when the user drags a file that can be accepted into the drop zone.
287
+ Dropzone.Reject is visible only when the user drags a file that cannot be accepted into the drop zone.
288
+ Dropzone.Idle is visible when the user is not dragging any file into the drop zone.
289
+ */}
290
+ <Dropzone.Accept>
291
+ <IconUpload
292
+ style={{ width: rem(52), height: rem(52), color: 'var(--mantine-color-blue-6)' }}
293
+ stroke={1.5}
294
+ />
295
+ </Dropzone.Accept>
296
+ <Dropzone.Reject>
297
+ <IconX
298
+ style={{ width: rem(52), height: rem(52), color: 'var(--mantine-color-red-6)' }}
299
+ stroke={1.5}
300
+ />
301
+ </Dropzone.Reject>
302
+ <Dropzone.Idle>
303
+ <IconPhoto
304
+ style={{ width: rem(52), height: rem(52), color: 'var(--mantine-color-dimmed)' }}
305
+ stroke={1.5}
306
+ />
307
+ </Dropzone.Idle>
308
+
309
+ <div>
310
+ <Text size="xl" inline>
311
+ Drag images here or click to select files
312
+ </Text>
313
+ <Text size="sm" c="dimmed" inline mt={7}>
314
+ Attach as many files as you want, each file must not exceed{' '} {maxFileSize} МБ.
315
+ </Text>
316
+ </div>
317
+ </Group>
318
+ );
319
+
320
+ <Editor
321
+ ...props
322
+ fetchUploadMedia={fetchUploadMedia}
323
+ contentModalUploadImage={Content}
324
+ maxFileSize={5}
325
+ maxImageSizeError={() => {}}
326
+ />
327
+ ```
328
+
329
+ ## File upload
330
+
331
+ For uploading a file or audio, you might need the third parameter "data".
332
+
333
+ ```
334
+ const fetchUploadMedia = async (
335
+ file: File,
336
+ success: (url: string, id: string, data?: {
337
+ contentType: string;
338
+ fileSize: string;
339
+ originalFileName: string;
340
+ }) => void,
341
+ error?: (error?: Error) => void
342
+ ) => {
343
+ const formData = new FormData();
344
+ formData.append('File', file);
345
+ formData.append('FileAccessModifier', '0');
346
+
347
+ try {
348
+ const response = await fetch('/api/v1/Files/Upload', {
349
+ method: 'POST',
350
+ body: formData,
351
+ credentials: 'include'
352
+ });
353
+
354
+ if (!response.ok) {
355
+ throw new Error('File upload failed');
356
+ }
357
+
358
+ const data = await response.json();
359
+ const { Id, Url } = data;
360
+
361
+ success(Url, Id, data);
362
+ } catch (err) {
363
+ if (error) {
364
+ if (err instanceof Error) {
365
+ error(err);
366
+ } else {
367
+ error(new Error('An unknown error occurred'));
368
+ }
369
+ }
370
+ }
371
+ };
372
+ ```
373
+ </details>
374
+
375
+
376
+ <details>
377
+ <summary>
378
+ 🤖 AI
379
+ </summary>
380
+
381
+ ## Connect AI
382
+
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
+ </details>
427
+
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
444
+ {...props}
445
+ onTrack={trackGoal}
446
+ />
447
+ ```
448
+
449
+ ### Custom Handler
450
+
451
+ ```tsx
452
+ const handleTrack = (event: string, params?: Record<string, unknown>) => {
453
+ console.log('Editor event:', event, params);
454
+
455
+ // Send to your analytics provider
456
+ myAnalytics.track(event, params);
457
+ };
458
+
459
+ <Editor
460
+ {...props}
461
+ onTrack={handleTrack}
462
+ />
463
+ ```
464
+
465
+ ### Type Signature
466
+
467
+ ```ts
468
+ type EditorTrackFn = (
469
+ event: string,
470
+ params?: Record<string, unknown>,
471
+ ) => void;
472
+ ```
473
+
474
+ ### Tracked Events
475
+
476
+ | Event | Trigger | Plugin |
477
+ |-------|---------|--------|
478
+ | `block_table_created` | User inserts a table | BlockFormatDropDown |
479
+ | `block_image_added` | User inserts an image | BlockFormatDropDown |
480
+ | `block_code_created` | User inserts a code block | BlockFormatDropDown |
481
+ | `block_layout_used` | User inserts a grid/layout | BlockFormatDropDown |
482
+ | `block_collapse_created` | User inserts a toggle/collapsible | BlockFormatDropDown |
483
+ | `block_link_inserted` | User inserts a link | ToolbarPlugin |
484
+ | `block_comment_added` | User adds an inline comment | ToolbarPlugin |
485
+ | `ai_menu_opened` | User clicks the AI toolbar button | ToolbarPlugin/AI |
486
+ | `block_heading_created` | User creates a heading (h1-h4) | BlockFormatDropDown |
487
+ | `list_bullet_created` | User creates a bullet list | BlockFormatDropDown |
488
+ | `list_number_created` | User creates a numbered list | BlockFormatDropDown |
489
+ | `list_check_created` | User creates a checklist | BlockFormatDropDown |
490
+ | `block_quote_created` | User creates a quote block | BlockFormatDropDown |
491
+ | `block_divider_inserted` | User inserts a horizontal rule | BlockFormatDropDown |
492
+ | `block_child_docs_inserted` | User inserts child documents block | BlockFormatDropDown |
493
+ | `block_embed_added` | User adds an embed/integration | BlockFormatDropDown |
494
+ | `media_audio_added` | User adds an audio block | BlockFormatDropDown |
495
+ | `media_file_added` | User adds a file block | BlockFormatDropDown |
496
+ | `table_row_added` | User inserts a table row | TableActionMenuPlugin |
497
+ | `table_column_added` | User inserts a table column | TableActionMenuPlugin |
498
+ | `table_row_deleted` | User deletes a table row | TableActionMenuPlugin |
499
+ | `table_column_deleted` | User deletes a table column | TableActionMenuPlugin |
500
+ | `block_duplicated` | User duplicates a block | DraggableBlockPlugin |
501
+ | `block_deleted` | User deletes a block | DraggableBlockPlugin |
502
+ | `text_code_toggled` | User toggles inline code format | ToolbarPlugin |
503
+ | `text_formatting_cleared` | User clears all text formatting | ToolbarPlugin |
504
+
505
+ > Events fire from both the toolbar dropdown menu and the slash command menu (`/`).
506
+
507
+ ### What Happens Without onTrack?
508
+
509
+ 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.
510
+
511
+ This means:
512
+ - **No analytics SDK required** — the editor is a standalone package with zero analytics dependencies
513
+ - **Safe to omit** — if you don't need tracking, simply don't pass the prop
514
+ - **No counter needed** — the editor itself never calls `ym()`, `gtag()`, or any external API directly
515
+
516
+ ### How It Works Internally
517
+
518
+ 1. `onTrack` is passed as a prop to `<Editor>` and stored in React Context
519
+ 2. Plugins access it via `useContext(Context)` and call `onTrack?.('event_name')`
520
+ 3. The host app decides what to do with the event (send to Metrika, log, ignore)
521
+
522
+ ```
523
+ Host App Editor Package
524
+ ───────── ──────────────
525
+ trackGoal() ──→ onTrack prop ──→ Context.onTrack
526
+ │ │
527
+ │ Plugins call:
528
+ │ onTrack?.('block_table_created')
529
+ │ │
530
+ ◄────────────────────────────────┘
531
+
532
+ ym(ID, 'reachGoal', 'block_table_created')
533
+ dataLayer.push({ event: 'block_table_created' })
534
+ ```
535
+
536
+ </details>
537
+
538
+
539
+ <details>
540
+ <summary>
541
+ 👥 Collaboration
542
+ </summary>
543
+
544
+ ```jsx
545
+ <Editor
546
+ {...props}
547
+ ws={{
548
+ url: 'https://wss.dudoc.io/', // WebSocket URL
549
+ id: '322323', // Unique document ID
550
+ user: userProfile, // Current user
551
+ getActiveUsers: (users) => {
552
+ // Returns active users editing the document
553
+ setActiveUsers(users);
554
+ },
555
+ }}
556
+ />
557
+ ```
558
+
559
+ </details>
560
+
561
+ <details>
562
+ <summary>
563
+ 📝 Additional options
564
+ </summary>
565
+
566
+ ## Reset editor content
567
+
568
+ ```
569
+
570
+ import { CLEAR_EDITOR_COMMAND } from './EditorLexical';
571
+
572
+ <>
573
+ <button
574
+ onClick={() => {
575
+ if (editorRef.current) {
576
+ editorRef.current.update(() => {
577
+ editorRef.current?.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined);
578
+ });
579
+ }
580
+ }}
581
+ >
582
+ Reset
583
+ </button>
584
+ <Editor
585
+ ...props
586
+ editorRef={editorRef}
587
+ />
588
+ <>
589
+ ```
590
+
591
+ </details>
592
+
593
+ <details>
594
+ <summary>
595
+ 🧪 Testing
596
+ </summary>
597
+
598
+ ## Testing Overview
599
+
600
+ 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.
601
+
602
+ ### Prerequisites
603
+
604
+ Before running tests, make sure you have installed all dependencies:
605
+
606
+ ```bash
607
+ npm install
608
+ ```
609
+
610
+ ## Unit Tests (Vitest)
611
+
612
+ Unit tests are written with **Vitest** and **jsdom** for testing individual components and utilities.
613
+
614
+ ### Run Unit Tests
615
+
616
+ ```bash
617
+ # Run all unit tests
618
+ npm run test-unit
619
+
620
+ # Run unit tests in watch mode (auto-rerun on changes)
621
+ npm run test-unit-watch
622
+ ```
623
+
624
+ ### Unit Test Files Location
625
+ - `__tests__/unit/` - Unit test files
626
+ - Test files follow the pattern: `*.test.ts` or `*.test.tsx`
627
+
628
+ ## End-to-End Tests (Playwright)
629
+
630
+ E2E tests use **Playwright** to test the complete application flow in real browsers.
631
+
632
+ ### Run E2E Tests
633
+
634
+ ```bash
635
+ # Run all E2E tests (WebKit only for CI optimization)
636
+ npm run test:e2e
637
+
638
+ # Run E2E tests with UI mode (interactive)
639
+ npm run test:e2e:ui
640
+
641
+ # Run E2E tests in debug mode
642
+ npm run test:e2e:debug
643
+
644
+ # Run E2E tests in headed mode (visible browser)
645
+ npm run test:e2e:headed
646
+ ```
647
+
648
+ ### E2E Test Files Location
649
+ - `__tests__/e2e/` - End-to-end test files
650
+ - `__tests__/regression/` - Regression test files
651
+ - Test files follow the pattern: `*.spec.js`, `*.spec.mjs`, or `*.spec.ts`
652
+
653
+ ### Browser Support
654
+ - **WebKit** (Safari) - Primary browser for CI/CD
655
+ - **Chromium** and **Firefox** - Available for local testing
656
+
657
+ ## Test Server
658
+
659
+ The test server automatically starts when running E2E tests:
660
+
661
+ ```bash
662
+ # Manual test server start (if needed)
663
+ npm run start-test-server
664
+ ```
665
+
666
+ - **URL**: `http://localhost:3000`
667
+ - **Mode**: Full editor mode with all features enabled
668
+ - **Environment**: `VITE_LAYERS=true`
669
+
670
+ ## Test Configuration
671
+
672
+ ### Playwright Configuration
673
+ - **Config file**: `playwright.config.js`
674
+ - **Test directory**: `./__tests__/e2e/`
675
+ - **Browser**: WebKit (optimized for CI)
676
+ - **Base URL**: `http://localhost:3000`
677
+ - **Timeout**: 90 seconds per test
678
+ - **Retries**: 2 retries in CI, 0 locally
679
+
680
+ ### Vitest Configuration
681
+ - **Config file**: `vitest.config.mts`
682
+ - **Environment**: jsdom
683
+ - **Setup file**: `vitest.setup.mts`
684
+ - **Coverage**: V8 provider
685
+
686
+ ## CI/CD Testing
687
+
688
+ Tests run automatically on:
689
+ - **Push** to `main` or `dev` branches
690
+ - **Pull requests** to `main` or `dev` branches
691
+ - **Manual trigger** via GitHub Actions
692
+
693
+ ### GitHub Actions Workflow
694
+ - **File**: `.github/workflows/tests.yml`
695
+ - **Runner**: Ubuntu Latest
696
+ - **Node.js**: Version 20
697
+ - **Browser caching**: Playwright browsers cached for faster runs
698
+ - **Artifacts**: Test reports and traces uploaded on completion
699
+
700
+ ## Test Examples
701
+
702
+ ### Basic E2E Test Structure
703
+
704
+ ```javascript
705
+ // __tests__/e2e/example.spec.mjs
706
+ import { test, expect } from '@playwright/test';
707
+ import { focusEditor } from '../utils/index.mjs';
708
+
709
+ test('Can type text in editor', async ({ page }) => {
710
+ await page.goto('/');
711
+ await focusEditor(page);
712
+
713
+ const editor = page.locator('[contenteditable="true"]').first();
714
+ await editor.type('Hello World');
715
+
716
+ await expect(editor).toContainText('Hello World');
717
+ });
718
+ ```
719
+
720
+ ### Unit Test Structure
721
+
722
+ ```typescript
723
+ // __tests__/unit/example.test.ts
724
+ import { describe, it, expect } from 'vitest';
725
+ import { render } from '@testing-library/react';
726
+ import { Editor } from '../src/Editor';
727
+
728
+ describe('Editor Component', () => {
729
+ it('renders without crashing', () => {
730
+ const { container } = render(<Editor />);
731
+ expect(container).toBeTruthy();
732
+ });
733
+ });
734
+ ```
735
+
736
+ ## Debugging Tests
737
+
738
+ ### Debug E2E Tests
739
+
740
+ ```bash
741
+ # Run with Playwright Inspector
742
+ npm run test:e2e:debug
743
+
744
+ # Run specific test file
745
+ npx playwright test __tests__/e2e/TextEntry.spec.mjs --debug
746
+
747
+ # Run with headed browser
748
+ npm run test:e2e:headed
749
+ ```
750
+
751
+ ### View Test Reports
752
+
753
+ ```bash
754
+ # Open HTML report (after running tests)
755
+ npx playwright show-report
756
+
757
+ # View test traces (for failed tests)
758
+ npx playwright show-trace test-results/[test-name]/trace.zip
759
+ ```
760
+
761
+ ## Test Utilities
762
+
763
+ Common test utilities are available in `__tests__/utils/index.mjs`:
764
+
765
+ - `focusEditor(page)` - Focus the main editor
766
+ - `selectAll(page)` - Select all text in editor
767
+ - `moveLeft(page, count)` - Move cursor left
768
+ - `selectCharacters(page, count)` - Select specific number of characters
769
+ - `waitForSelector(page, selector)` - Wait for element to appear
770
+
771
+ ## Performance
772
+
773
+ ### Test Execution Times
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
+ - **Browser Caching**: Playwright browsers cached in CI
780
+ - **Single Worker**: Prevents race conditions in CI
781
+ - **WebKit Only**: Faster than multi-browser matrix
782
+ - **Smart Retries**: Auto-retry flaky tests
783
+
784
+ ## Troubleshooting
785
+
786
+ ### Common Issues
787
+
788
+ 1. **Port conflicts**: Ensure port 3000 is available
789
+ 2. **Browser installation**: Run `npx playwright install` if needed
790
+ 3. **Test timeouts**: Check if test server is running properly
791
+ 4. **Certificate errors**: Tests use HTTP to avoid HTTPS certificate issues
792
+
793
+ ### Reset Test Environment
794
+
795
+ ```bash
796
+ # Clear Playwright cache
797
+ npx playwright install --force
798
+
799
+ # Reset node_modules
800
+ rm -rf node_modules package-lock.json
801
+ npm install
802
+ ```
803
+
804
+ </details>
805
+
806
+ <details>
807
+ <summary>
808
+ ⚙️ Properties
809
+ </summary>
810
+
811
+ ```
812
+ 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.
813
+ debounce?: number - Defines how often the onChange function is called, in milliseconds.
814
+ 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.
815
+ outputFormat?: 'html' | 'json' - The outputFormat property defines whether we want to output an HTML string or a JSON object. The default is JSON.
816
+ initialContent: string | object - The initial content for the editor.
817
+ maxHeight?: number - Sets the height of the editor. The default is 100%.
818
+ mode?: 'simple' | 'default' | 'full' | 'editor' - The editor mode. Depending on the chosen mode, functionality may be restricted or extended. The default is default.
819
+ fetchUploadMedia?: (file: File, success: (url: string, id: string, error?: (error?: Error) => void) => void) - Function to upload an image to your service.
820
+ fetchDeleteMedia?: (id: string, success: () => void, error?: (error?: Error) => void) - Helper function to delete an image.
821
+ maxFileSize?: number - The maximum image size in megabytes.
822
+ contentModalUploadImage?: React.FunctionComponent - A React component to replace content in DropZone.
823
+ maxImageSizeError?: () => void - A function that is called if the image exceeds the maxFileSize.
824
+ disable?: boolean - Toggles the editor into read-only mode.
825
+ 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.
826
+ editorRef?: { current: EditorType | null } - Reference to the editor.
827
+ 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.
828
+ ```
829
+
830
+ </details>