dn-react-router-toolkit 0.2.7 → 0.3.2

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 (279) hide show
  1. package/dist/api/create_handler.d.mts +13 -0
  2. package/dist/api/create_handler.d.ts +13 -0
  3. package/dist/api/create_handler.js +298 -0
  4. package/dist/api/create_handler.mjs +304 -0
  5. package/dist/api/index.d.mts +4 -0
  6. package/dist/api/index.d.ts +4 -0
  7. package/dist/api/index.js +298 -0
  8. package/dist/api/index.mjs +304 -0
  9. package/dist/auth/client/index.d.mts +3 -0
  10. package/dist/auth/client/index.d.ts +3 -0
  11. package/dist/{date.js → auth/client/index.js} +25 -32
  12. package/dist/auth/client/index.mjs +21 -0
  13. package/dist/auth/client/redirect_page.d.mts +1 -0
  14. package/dist/auth/client/redirect_page.d.ts +1 -0
  15. package/dist/auth/cookie_store.d.mts +13 -0
  16. package/dist/auth/cookie_store.d.ts +13 -0
  17. package/dist/{text_editor/plugins/keymap.js → auth/cookie_store.js} +24 -16
  18. package/dist/auth/cookie_store.mjs +23 -0
  19. package/dist/auth/index.d.mts +5 -0
  20. package/dist/auth/index.d.ts +5 -0
  21. package/dist/auth/index.js +139 -0
  22. package/dist/auth/index.mjs +111 -0
  23. package/dist/auth/server/index.d.mts +1 -0
  24. package/dist/auth/server/index.d.ts +1 -0
  25. package/dist/{slug.js → auth/server/index.js} +6 -14
  26. package/dist/auth/server/index.mjs +2 -0
  27. package/dist/auth/with_auth.d.mts +2 -6
  28. package/dist/auth/with_auth.d.ts +2 -6
  29. package/dist/auth/with_auth.js +3 -0
  30. package/dist/auth/with_auth.mjs +3 -0
  31. package/dist/{components → client}/client_env.d.mts +1 -1
  32. package/dist/{components → client}/client_env.d.ts +1 -1
  33. package/dist/{components → client}/client_env.js +6 -2
  34. package/dist/{components → client}/client_env.mjs +2 -2
  35. package/dist/client/index.d.mts +3 -0
  36. package/dist/client/index.d.ts +3 -0
  37. package/dist/{auth/client/google_login_button.js → client/index.js} +30 -33
  38. package/dist/client/index.mjs +31 -0
  39. package/dist/client/use_user_agent.d.mts +8 -0
  40. package/dist/client/use_user_agent.d.ts +8 -0
  41. package/dist/{file/client/format_size.js → client/use_user_agent.js} +14 -14
  42. package/dist/client/use_user_agent.mjs +13 -0
  43. package/dist/file/client/index.d.mts +1 -0
  44. package/dist/file/client/index.d.ts +1 -0
  45. package/dist/file/{cdn.js → client/index.js} +6 -16
  46. package/dist/file/client/index.mjs +2 -0
  47. package/dist/file/index.d.mts +1 -0
  48. package/dist/file/index.d.ts +1 -0
  49. package/dist/{cn.js → file/index.js} +6 -14
  50. package/dist/file/index.mjs +2 -0
  51. package/dist/file/server/index.d.mts +1 -0
  52. package/dist/file/server/index.d.ts +1 -0
  53. package/dist/file/server/index.js +24 -0
  54. package/dist/file/server/index.mjs +2 -0
  55. package/dist/http/index.d.mts +1 -1
  56. package/dist/http/index.d.ts +1 -1
  57. package/dist/http/index.js +3 -90
  58. package/dist/http/index.mjs +2 -68
  59. package/dist/index.d.mts +8 -6
  60. package/dist/index.d.ts +8 -6
  61. package/dist/index.js +3 -79
  62. package/dist/index.mjs +2 -58
  63. package/dist/modal/index.d.mts +1 -0
  64. package/dist/modal/index.d.ts +1 -0
  65. package/dist/{sleep.js → modal/index.js} +6 -14
  66. package/dist/modal/index.mjs +2 -0
  67. package/dist/seo/index.d.mts +4 -0
  68. package/dist/seo/index.d.ts +4 -0
  69. package/dist/seo/index.js +304 -0
  70. package/dist/seo/index.mjs +267 -0
  71. package/dist/text_editor/index.d.mts +1 -0
  72. package/dist/text_editor/index.d.ts +1 -0
  73. package/dist/text_editor/index.js +24 -0
  74. package/dist/text_editor/index.mjs +2 -0
  75. package/package.json +58 -32
  76. package/dist/auth/apple_auth.d.mts +0 -38
  77. package/dist/auth/apple_auth.d.ts +0 -38
  78. package/dist/auth/apple_auth.js +0 -88
  79. package/dist/auth/apple_auth.mjs +0 -63
  80. package/dist/auth/auth_repository.d.mts +0 -41
  81. package/dist/auth/auth_repository.d.ts +0 -41
  82. package/dist/auth/auth_repository.js +0 -18
  83. package/dist/auth/auth_repository.mjs +0 -0
  84. package/dist/auth/auth_service.d.mts +0 -63
  85. package/dist/auth/auth_service.d.ts +0 -63
  86. package/dist/auth/auth_service.js +0 -210
  87. package/dist/auth/auth_service.mjs +0 -171
  88. package/dist/auth/client/google_login_button.d.mts +0 -7
  89. package/dist/auth/client/google_login_button.d.ts +0 -7
  90. package/dist/auth/client/google_login_button.mjs +0 -37
  91. package/dist/auth/client/provider.d.mts +0 -24
  92. package/dist/auth/client/provider.d.ts +0 -24
  93. package/dist/auth/client/provider.js +0 -154
  94. package/dist/auth/client/provider.mjs +0 -118
  95. package/dist/auth/google_auth.d.mts +0 -33
  96. package/dist/auth/google_auth.d.ts +0 -33
  97. package/dist/auth/google_auth.js +0 -135
  98. package/dist/auth/google_auth.mjs +0 -108
  99. package/dist/auth/handlers/find_auth.d.mts +0 -13
  100. package/dist/auth/handlers/find_auth.d.ts +0 -13
  101. package/dist/auth/handlers/find_auth.js +0 -82
  102. package/dist/auth/handlers/find_auth.mjs +0 -55
  103. package/dist/auth/handlers/login.d.mts +0 -13
  104. package/dist/auth/handlers/login.d.ts +0 -13
  105. package/dist/auth/handlers/login.js +0 -107
  106. package/dist/auth/handlers/login.mjs +0 -80
  107. package/dist/auth/handlers/login_with_thirdparty.d.mts +0 -15
  108. package/dist/auth/handlers/login_with_thirdparty.d.ts +0 -15
  109. package/dist/auth/handlers/login_with_thirdparty.js +0 -98
  110. package/dist/auth/handlers/login_with_thirdparty.mjs +0 -71
  111. package/dist/auth/handlers/logout.d.mts +0 -13
  112. package/dist/auth/handlers/logout.d.ts +0 -13
  113. package/dist/auth/handlers/logout.js +0 -102
  114. package/dist/auth/handlers/logout.mjs +0 -75
  115. package/dist/auth/handlers/refresh.d.mts +0 -13
  116. package/dist/auth/handlers/refresh.d.ts +0 -13
  117. package/dist/auth/handlers/refresh.js +0 -92
  118. package/dist/auth/handlers/refresh.mjs +0 -65
  119. package/dist/auth/handlers/request_password_reset.d.mts +0 -10
  120. package/dist/auth/handlers/request_password_reset.d.ts +0 -10
  121. package/dist/auth/handlers/request_password_reset.js +0 -87
  122. package/dist/auth/handlers/request_password_reset.mjs +0 -60
  123. package/dist/auth/handlers/reset_password.d.mts +0 -10
  124. package/dist/auth/handlers/reset_password.d.ts +0 -10
  125. package/dist/auth/handlers/reset_password.js +0 -88
  126. package/dist/auth/handlers/reset_password.mjs +0 -61
  127. package/dist/auth/handlers/signup.d.mts +0 -15
  128. package/dist/auth/handlers/signup.d.ts +0 -15
  129. package/dist/auth/handlers/signup.js +0 -147
  130. package/dist/auth/handlers/signup.mjs +0 -112
  131. package/dist/auth/handlers/signup_with_thirdparty.d.mts +0 -17
  132. package/dist/auth/handlers/signup_with_thirdparty.d.ts +0 -17
  133. package/dist/auth/handlers/signup_with_thirdparty.js +0 -123
  134. package/dist/auth/handlers/signup_with_thirdparty.mjs +0 -98
  135. package/dist/auth/handlers/thirdparty_auth_callback.d.mts +0 -16
  136. package/dist/auth/handlers/thirdparty_auth_callback.d.ts +0 -16
  137. package/dist/auth/handlers/thirdparty_auth_callback.js +0 -129
  138. package/dist/auth/handlers/thirdparty_auth_callback.mjs +0 -102
  139. package/dist/auth/jwt_manager.d.mts +0 -38
  140. package/dist/auth/jwt_manager.d.ts +0 -38
  141. package/dist/auth/jwt_manager.js +0 -90
  142. package/dist/auth/jwt_manager.mjs +0 -65
  143. package/dist/auth/kakao_auth.d.mts +0 -27
  144. package/dist/auth/kakao_auth.d.ts +0 -27
  145. package/dist/auth/kakao_auth.js +0 -56
  146. package/dist/auth/kakao_auth.mjs +0 -31
  147. package/dist/auth/password_recovery.d.mts +0 -34
  148. package/dist/auth/password_recovery.d.ts +0 -34
  149. package/dist/auth/password_recovery.js +0 -169
  150. package/dist/auth/password_recovery.mjs +0 -134
  151. package/dist/auth/thirdparty_auth.d.mts +0 -41
  152. package/dist/auth/thirdparty_auth.d.ts +0 -41
  153. package/dist/auth/thirdparty_auth.js +0 -113
  154. package/dist/auth/thirdparty_auth.mjs +0 -86
  155. package/dist/cn.d.mts +0 -3
  156. package/dist/cn.d.ts +0 -3
  157. package/dist/cn.mjs +0 -7
  158. package/dist/components/index.d.mts +0 -5
  159. package/dist/components/index.d.ts +0 -5
  160. package/dist/components/index.js +0 -261
  161. package/dist/components/index.mjs +0 -219
  162. package/dist/components/modal/fullscreen_container.d.mts +0 -7
  163. package/dist/components/modal/fullscreen_container.d.ts +0 -7
  164. package/dist/components/modal/fullscreen_container.js +0 -102
  165. package/dist/components/modal/fullscreen_container.mjs +0 -68
  166. package/dist/components/modal/hooks.d.mts +0 -18
  167. package/dist/components/modal/hooks.d.ts +0 -18
  168. package/dist/components/modal/hooks.js +0 -236
  169. package/dist/components/modal/hooks.mjs +0 -204
  170. package/dist/components/modal/index.d.mts +0 -4
  171. package/dist/components/modal/index.d.ts +0 -4
  172. package/dist/components/modal/index.js +0 -238
  173. package/dist/components/modal/index.mjs +0 -203
  174. package/dist/components/modal/modal.d.mts +0 -13
  175. package/dist/components/modal/modal.d.ts +0 -13
  176. package/dist/components/modal/modal.js +0 -155
  177. package/dist/components/modal/modal.mjs +0 -130
  178. package/dist/components/styles.d.mts +0 -9
  179. package/dist/components/styles.d.ts +0 -9
  180. package/dist/components/styles.js +0 -48
  181. package/dist/components/styles.mjs +0 -17
  182. package/dist/date.d.mts +0 -5
  183. package/dist/date.d.ts +0 -5
  184. package/dist/date.mjs +0 -29
  185. package/dist/file/cdn.d.mts +0 -6
  186. package/dist/file/cdn.d.ts +0 -6
  187. package/dist/file/cdn.mjs +0 -9
  188. package/dist/file/client/drop_file_input.d.mts +0 -36
  189. package/dist/file/client/drop_file_input.d.ts +0 -36
  190. package/dist/file/client/drop_file_input.js +0 -323
  191. package/dist/file/client/drop_file_input.mjs +0 -294
  192. package/dist/file/client/file_upload_button.d.mts +0 -10
  193. package/dist/file/client/file_upload_button.d.ts +0 -10
  194. package/dist/file/client/file_upload_button.js +0 -89
  195. package/dist/file/client/file_upload_button.mjs +0 -58
  196. package/dist/file/client/file_uploader.d.mts +0 -13
  197. package/dist/file/client/file_uploader.d.ts +0 -13
  198. package/dist/file/client/file_uploader.js +0 -163
  199. package/dist/file/client/file_uploader.mjs +0 -136
  200. package/dist/file/client/format_size.d.mts +0 -3
  201. package/dist/file/client/format_size.d.ts +0 -3
  202. package/dist/file/client/format_size.mjs +0 -13
  203. package/dist/file/client/metadata.d.mts +0 -7
  204. package/dist/file/client/metadata.d.ts +0 -7
  205. package/dist/file/client/metadata.js +0 -85
  206. package/dist/file/client/metadata.mjs +0 -60
  207. package/dist/file/file_repository.d.mts +0 -16
  208. package/dist/file/file_repository.d.ts +0 -16
  209. package/dist/file/file_repository.js +0 -18
  210. package/dist/file/file_repository.mjs +0 -0
  211. package/dist/file/file_service.d.mts +0 -32
  212. package/dist/file/file_service.d.ts +0 -32
  213. package/dist/file/file_service.js +0 -66
  214. package/dist/file/file_service.mjs +0 -41
  215. package/dist/file/handlers/delete_file.d.mts +0 -17
  216. package/dist/file/handlers/delete_file.d.ts +0 -17
  217. package/dist/file/handlers/delete_file.js +0 -99
  218. package/dist/file/handlers/delete_file.mjs +0 -72
  219. package/dist/file/handlers/upload_file.d.mts +0 -16
  220. package/dist/file/handlers/upload_file.d.ts +0 -16
  221. package/dist/file/handlers/upload_file.js +0 -106
  222. package/dist/file/handlers/upload_file.mjs +0 -79
  223. package/dist/file/object_storage.d.mts +0 -20
  224. package/dist/file/object_storage.d.ts +0 -20
  225. package/dist/file/object_storage.js +0 -90
  226. package/dist/file/object_storage.mjs +0 -70
  227. package/dist/file/responsive_image.d.mts +0 -20
  228. package/dist/file/responsive_image.d.ts +0 -20
  229. package/dist/file/responsive_image.js +0 -132
  230. package/dist/file/responsive_image.mjs +0 -96
  231. package/dist/http/response.d.mts +0 -19
  232. package/dist/http/response.d.ts +0 -19
  233. package/dist/http/response.js +0 -109
  234. package/dist/http/response.mjs +0 -68
  235. package/dist/route/api.d.mts +0 -21
  236. package/dist/route/api.d.ts +0 -21
  237. package/dist/route/api.js +0 -584
  238. package/dist/route/api.mjs +0 -547
  239. package/dist/singleton.d.mts +0 -3
  240. package/dist/singleton.d.ts +0 -3
  241. package/dist/singleton.js +0 -37
  242. package/dist/singleton.mjs +0 -12
  243. package/dist/sleep.d.mts +0 -3
  244. package/dist/sleep.d.ts +0 -3
  245. package/dist/sleep.mjs +0 -7
  246. package/dist/slug.d.mts +0 -3
  247. package/dist/slug.d.ts +0 -3
  248. package/dist/slug.mjs +0 -7
  249. package/dist/text_editor/attach_media.d.mts +0 -16
  250. package/dist/text_editor/attach_media.d.ts +0 -16
  251. package/dist/text_editor/attach_media.js +0 -237
  252. package/dist/text_editor/attach_media.mjs +0 -210
  253. package/dist/text_editor/plugins/drag_and_drop.d.mts +0 -13
  254. package/dist/text_editor/plugins/drag_and_drop.d.ts +0 -13
  255. package/dist/text_editor/plugins/drag_and_drop.js +0 -59
  256. package/dist/text_editor/plugins/drag_and_drop.mjs +0 -34
  257. package/dist/text_editor/plugins/keymap.d.mts +0 -5
  258. package/dist/text_editor/plugins/keymap.d.ts +0 -5
  259. package/dist/text_editor/plugins/keymap.mjs +0 -15
  260. package/dist/text_editor/plugins/placehoder.d.mts +0 -5
  261. package/dist/text_editor/plugins/placehoder.d.ts +0 -5
  262. package/dist/text_editor/plugins/placehoder.js +0 -112
  263. package/dist/text_editor/plugins/placehoder.mjs +0 -87
  264. package/dist/text_editor/plugins/trailing_paragraph.d.mts +0 -5
  265. package/dist/text_editor/plugins/trailing_paragraph.d.ts +0 -5
  266. package/dist/text_editor/plugins/trailing_paragraph.js +0 -46
  267. package/dist/text_editor/plugins/trailing_paragraph.mjs +0 -21
  268. package/dist/text_editor/plugins/upload_placeholder.d.mts +0 -7
  269. package/dist/text_editor/plugins/upload_placeholder.d.ts +0 -7
  270. package/dist/text_editor/plugins/upload_placeholder.js +0 -94
  271. package/dist/text_editor/plugins/upload_placeholder.mjs +0 -68
  272. package/dist/text_editor/schema.d.mts +0 -9
  273. package/dist/text_editor/schema.d.ts +0 -9
  274. package/dist/text_editor/schema.js +0 -354
  275. package/dist/text_editor/schema.mjs +0 -319
  276. package/dist/text_editor/text_editor.d.mts +0 -45
  277. package/dist/text_editor/text_editor.d.ts +0 -45
  278. package/dist/text_editor/text_editor.js +0 -834
  279. package/dist/text_editor/text_editor.mjs +0 -806
@@ -1,806 +0,0 @@
1
- // src/text_editor/text_editor.tsx
2
- import React2 from "react";
3
- import { EditorState as EditorState2 } from "prosemirror-state";
4
- import { EditorView } from "prosemirror-view";
5
- import { useCallback, useEffect, useMemo, useRef } from "react";
6
- import { baseKeymap, setBlockType, toggleMark } from "prosemirror-commands";
7
- import { keymap } from "prosemirror-keymap";
8
-
9
- // src/text_editor/plugins/drag_and_drop.tsx
10
- import { Plugin } from "prosemirror-state";
11
- function dragAndDropPlugin({
12
- attachMedia
13
- }) {
14
- return new Plugin({
15
- props: {
16
- handleDOMEvents: {
17
- drop(view, event) {
18
- const files = event.dataTransfer?.files;
19
- if (!files || files.length === 0) {
20
- return;
21
- }
22
- event.preventDefault();
23
- const pos = view.state.selection.$from.pos || view.posAtCoords({
24
- left: event.clientX,
25
- top: event.clientY
26
- })?.pos || null;
27
- if (pos === null) {
28
- return;
29
- }
30
- const medias = Array.from(files).filter(
31
- (file) => file.type.startsWith("image/") || file.type.startsWith("video/")
32
- );
33
- attachMedia(view, medias);
34
- return true;
35
- }
36
- }
37
- }
38
- });
39
- }
40
-
41
- // src/text_editor/plugins/upload_placeholder.tsx
42
- import { Plugin as Plugin2 } from "prosemirror-state";
43
- import { Decoration, DecorationSet } from "prosemirror-view";
44
- var uploadPlaceholderPlugin = new Plugin2({
45
- state: {
46
- init() {
47
- return DecorationSet.empty;
48
- },
49
- apply(tr, set) {
50
- set = set.map(tr.mapping, tr.doc);
51
- const action = tr.getMeta(this);
52
- if (action && action.add) {
53
- const { type, width, height } = action.add;
54
- const widget = document.createElement("div");
55
- widget.className = "upload-placeholder";
56
- widget.style.width = `100%`;
57
- if (type.startsWith("image/") || type.startsWith("video/")) {
58
- widget.style.aspectRatio = `${width} / ${height}`;
59
- widget.style.maxWidth = `${width}px`;
60
- } else {
61
- widget.style.height = "80px";
62
- }
63
- const progress = document.createElement("div");
64
- progress.className = "upload-progress";
65
- widget.appendChild(progress);
66
- const deco = Decoration.widget(action.add.pos, widget, {
67
- id: action.add.id
68
- });
69
- set = set.add(tr.doc, [deco]);
70
- } else if (action && action.progress) {
71
- const found = set.find(
72
- void 0,
73
- void 0,
74
- (spec) => spec.id === action.progress.id
75
- );
76
- if (found.length) {
77
- const widget = found[0].type.toDOM;
78
- const progress = widget.querySelector(".upload-progress");
79
- if (progress) {
80
- progress.innerHTML = `${Math.round(action.progress.progress)}%`;
81
- }
82
- }
83
- } else if (action && action.remove) {
84
- set = set.remove(
85
- set.find(void 0, void 0, (spec) => spec.id === action.remove.id)
86
- );
87
- }
88
- return set;
89
- }
90
- },
91
- props: {
92
- decorations(state) {
93
- return this.getState(state);
94
- }
95
- }
96
- });
97
- var findPlaceholder = (state, id) => {
98
- const decos = uploadPlaceholderPlugin.getState(state);
99
- if (!decos) {
100
- return null;
101
- }
102
- const found = decos.find(void 0, void 0, (spec) => spec.id === id);
103
- return found.length ? found[0].from : null;
104
- };
105
-
106
- // src/file/client/metadata.ts
107
- function generateMetadata(blob, {
108
- uploadBlob
109
- } = {}) {
110
- return new Promise((resolve) => {
111
- if (blob.type.startsWith("image/")) {
112
- const img = new Image();
113
- img.src = URL.createObjectURL(blob);
114
- img.onload = () => {
115
- resolve({
116
- width: img.width,
117
- height: img.height
118
- });
119
- };
120
- img.onerror = () => resolve({});
121
- return;
122
- }
123
- if (blob.type.startsWith("video/")) {
124
- const video = document.createElement("video");
125
- video.onloadeddata = () => {
126
- const canvas = document.createElement("canvas");
127
- canvas.width = video.videoWidth;
128
- canvas.height = video.videoHeight;
129
- const context = canvas.getContext("2d");
130
- if (!context || !uploadBlob) {
131
- return resolve({
132
- width: video.videoWidth,
133
- height: video.videoHeight
134
- });
135
- }
136
- video.addEventListener("seeked", () => {
137
- context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
138
- canvas.toBlob((blob2) => {
139
- if (!blob2) {
140
- return resolve({
141
- width: video.videoWidth,
142
- height: video.videoHeight
143
- });
144
- }
145
- uploadBlob(blob2, "poster").then(({ url }) => {
146
- resolve({
147
- width: video.videoWidth,
148
- height: video.videoHeight,
149
- poster: url
150
- });
151
- });
152
- }, "image/jpeg");
153
- });
154
- video.currentTime = 0;
155
- };
156
- video.onerror = () => resolve({});
157
- video.src = URL.createObjectURL(blob);
158
- return;
159
- }
160
- resolve({});
161
- });
162
- }
163
-
164
- // src/file/cdn.ts
165
- var createCDN = (origin) => {
166
- return (key, { width } = {}) => {
167
- return key ? `${origin}/${key}${width ? `?w=${width}` : ""}` : void 0;
168
- };
169
- };
170
-
171
- // src/text_editor/attach_media.tsx
172
- function createAttachMedia({
173
- schema,
174
- cdnOrigin,
175
- fileUploader
176
- }) {
177
- const cdn = createCDN(cdnOrigin);
178
- const attachEachMedia = async (view, file, pos) => {
179
- const metadata = await generateMetadata(file, {
180
- uploadBlob: (blob, type) => fileUploader.uploadBlob(blob, type).then(({ key }) => ({
181
- url: cdn(key)
182
- }))
183
- });
184
- const id = {};
185
- view.focus();
186
- const tr = view.state.tr;
187
- if (!tr.selection.empty) {
188
- tr.deleteSelection();
189
- }
190
- tr.setMeta(uploadPlaceholderPlugin, {
191
- add: {
192
- id,
193
- pos: pos ?? tr.selection.from,
194
- type: file.type,
195
- ...metadata
196
- }
197
- });
198
- view.dispatch(tr);
199
- const $pos = findPlaceholder(view.state, id);
200
- if (!$pos) {
201
- return;
202
- }
203
- try {
204
- const { name, key } = await fileUploader.uploadFile(file);
205
- const src = cdn(key);
206
- const tr2 = view.state.tr.setMeta(uploadPlaceholderPlugin, {
207
- remove: { id }
208
- });
209
- const media = (() => {
210
- if (file.type.startsWith("image/")) {
211
- return schema.nodes.image.create({
212
- src,
213
- alt: name,
214
- width: metadata.width,
215
- height: metadata.height
216
- });
217
- }
218
- if (file.type.startsWith("video/")) {
219
- return schema.nodes.video.create({
220
- src,
221
- width: metadata.width,
222
- height: metadata.height,
223
- poster: metadata.poster
224
- });
225
- }
226
- })();
227
- if (!media) {
228
- return;
229
- }
230
- view.dispatch(tr2.replaceWith($pos, $pos, media));
231
- return media;
232
- } catch (e) {
233
- view.dispatch(tr.setMeta(uploadPlaceholderPlugin, { remove: { id } }));
234
- }
235
- };
236
- return async (view, medias, pos) => {
237
- const result = [];
238
- for (let i = 0; i < medias.length; i++) {
239
- const file = medias[i];
240
- const item = await attachEachMedia(view, file, pos);
241
- if (item) {
242
- result.push(item);
243
- }
244
- }
245
- return result;
246
- };
247
- }
248
-
249
- // src/text_editor/plugins/placehoder.tsx
250
- import { Plugin as Plugin3 } from "prosemirror-state";
251
- var getFirstChildDescendants = (view) => {
252
- const nodes = [];
253
- view.state.doc?.descendants((n) => {
254
- nodes.push(n);
255
- });
256
- return nodes;
257
- };
258
- function placeholderPlugin(text) {
259
- const update = (view) => {
260
- const decos = uploadPlaceholderPlugin.getState(view.state);
261
- if (decos && decos.find().length > 0 || view.state.doc.content.content.some((e) => e.type.name !== "paragraph") || view.state.doc.childCount > 1 || getFirstChildDescendants(view).length > 1 || view.state.doc.textContent) {
262
- view.dom.removeAttribute("data-placeholder");
263
- } else {
264
- view.dom.setAttribute("data-placeholder", text);
265
- }
266
- };
267
- return new Plugin3({
268
- view(view) {
269
- update(view);
270
- return { update };
271
- }
272
- });
273
- }
274
-
275
- // src/text_editor/text_editor.tsx
276
- import {
277
- DOMSerializer,
278
- DOMParser
279
- } from "prosemirror-model";
280
- import { history } from "prosemirror-history";
281
-
282
- // src/text_editor/plugins/keymap.tsx
283
- import { undo, redo } from "prosemirror-history";
284
- function buildKeymap() {
285
- const keys = {};
286
- function bind(key, cmd) {
287
- keys[key] = cmd;
288
- }
289
- bind("Mod-z", undo);
290
- bind("Shift-Mod-z", redo);
291
- bind("Mod-y", redo);
292
- return keys;
293
- }
294
-
295
- // src/text_editor/schema.tsx
296
- import { Schema } from "prosemirror-model";
297
- import { addListNodes } from "prosemirror-schema-list";
298
-
299
- // src/file/responsive_image.tsx
300
- import React from "react";
301
- var sizes = [
302
- 64,
303
- 128,
304
- 256,
305
- 320,
306
- 480,
307
- 640,
308
- 768,
309
- 1080,
310
- 1200,
311
- 1536,
312
- 1920,
313
- 2560,
314
- 3840
315
- ];
316
- var generateSrc = (cdnOrigin, src, width, height, ratio, image = {}) => {
317
- const searchParams = new URLSearchParams();
318
- if (image.width) {
319
- searchParams.set("w", image.width.toString());
320
- }
321
- if (width) {
322
- searchParams.set("w", width.toString());
323
- if (ratio) {
324
- searchParams.set("h", Math.round(width / ratio).toString());
325
- }
326
- }
327
- if (image.height) {
328
- searchParams.set("h", image.height.toString());
329
- }
330
- if (height) {
331
- searchParams.set("h", height.toString());
332
- }
333
- const search = searchParams.toString() ? `?${searchParams.toString()}` : "";
334
- if (!src.includes(cdnOrigin)) {
335
- return src;
336
- }
337
- return `${encodeURI(decodeURI(src))}${search}`;
338
- };
339
- function generateSrcSet(cdnOrigin, image, ratio, props = {}) {
340
- const src = typeof image === "string" ? image : image.src;
341
- const isGif = src.endsWith(".gif");
342
- if (isGif) {
343
- return void 0;
344
- }
345
- if (props.width) {
346
- return [1, 2, 3].map((scale) => {
347
- const genWidth = Number(props.width) * scale;
348
- return `${generateSrc(
349
- cdnOrigin,
350
- src,
351
- genWidth,
352
- props.height ? Number(props.height) * scale : ratio ? Math.round(genWidth / ratio) : void 0
353
- )} ${scale}x`;
354
- }).join(", ");
355
- }
356
- return sizes.map(
357
- (size) => `${generateSrc(cdnOrigin, src, size, void 0, ratio, props)} ${size}w`
358
- ).join(", ");
359
- }
360
-
361
- // src/text_editor/schema.tsx
362
- function createSchema({ cdnOrigin }) {
363
- const customSchema = new Schema({
364
- nodes: {
365
- doc: { content: "block+" },
366
- paragraph: {
367
- attrs: { align: { default: null } },
368
- content: "inline*",
369
- group: "block",
370
- parseDOM: [
371
- {
372
- tag: "p",
373
- getAttrs(dom) {
374
- return {
375
- align: dom.style.textAlign || null
376
- };
377
- }
378
- }
379
- ],
380
- toDOM(node) {
381
- return [
382
- "p",
383
- {
384
- style: node.attrs.align ? `text-align: ${node.attrs.align}` : null
385
- },
386
- 0
387
- ];
388
- }
389
- },
390
- text: {
391
- group: "inline"
392
- },
393
- hard_break: {
394
- inline: true,
395
- group: "inline",
396
- selectable: false,
397
- parseDOM: [{ tag: "br" }],
398
- toDOM() {
399
- return ["br"];
400
- }
401
- },
402
- heading: {
403
- attrs: { level: { default: 1 }, align: { default: null } },
404
- content: "inline*",
405
- group: "block",
406
- defining: true,
407
- parseDOM: [
408
- {
409
- tag: "h1",
410
- getAttrs(node) {
411
- return {
412
- level: 1,
413
- algin: node.style.textAlign || null
414
- };
415
- }
416
- },
417
- {
418
- tag: "h2",
419
- getAttrs(node) {
420
- return {
421
- level: 2,
422
- algin: node.style.textAlign || null
423
- };
424
- }
425
- },
426
- {
427
- tag: "h3",
428
- getAttrs(node) {
429
- return {
430
- level: 3,
431
- algin: node.style.textAlign || null
432
- };
433
- }
434
- },
435
- {
436
- tag: "h4",
437
- getAttrs(node) {
438
- return {
439
- level: 4,
440
- algin: node.style.textAlign || null
441
- };
442
- }
443
- },
444
- {
445
- tag: "h5",
446
- getAttrs(node) {
447
- return {
448
- level: 5,
449
- algin: node.style.textAlign || null
450
- };
451
- }
452
- },
453
- {
454
- tag: "h6",
455
- getAttrs(node) {
456
- return {
457
- level: 6,
458
- algin: node.style.textAlign || null
459
- };
460
- }
461
- }
462
- ],
463
- toDOM(node) {
464
- return [
465
- "h" + node.attrs.level,
466
- {
467
- id: node.textContent.toLowerCase().replace(/\s+/g, "-"),
468
- style: node.attrs.align ? `text-align: ${node.attrs.align};` : null
469
- },
470
- 0
471
- ];
472
- }
473
- },
474
- horizontal_rule: {
475
- group: "block",
476
- parseDOM: [{ tag: "hr" }],
477
- toDOM() {
478
- return ["hr"];
479
- }
480
- },
481
- image: {
482
- attrs: {
483
- src: { validate: "string" },
484
- alt: { default: null, validate: "string|null" },
485
- title: {
486
- default: null,
487
- validate: "string|null"
488
- },
489
- width: {
490
- default: null,
491
- validate: "number|null"
492
- },
493
- height: {
494
- default: null,
495
- validate: "number|null"
496
- }
497
- },
498
- inline: true,
499
- group: "inline",
500
- draggable: true,
501
- parseDOM: [
502
- {
503
- tag: "img",
504
- getAttrs(dom) {
505
- return {
506
- src: dom.getAttribute("src"),
507
- title: dom.getAttribute("title"),
508
- alt: dom.getAttribute("alt"),
509
- width: dom.getAttribute("width"),
510
- height: dom.getAttribute("height")
511
- };
512
- }
513
- }
514
- ],
515
- toDOM(node) {
516
- const { src, alt, title, width, height } = node.attrs;
517
- return [
518
- "img",
519
- {
520
- src,
521
- alt,
522
- title,
523
- width,
524
- height,
525
- srcSet: cdnOrigin ? generateSrcSet(cdnOrigin, src) : void 0,
526
- sizes: cdnOrigin ? "(max-width: 768px) 100vw, 768px" : void 0
527
- }
528
- ];
529
- }
530
- }
531
- },
532
- marks: {
533
- link: {
534
- attrs: {
535
- href: { default: "" },
536
- title: { default: null }
537
- },
538
- inclusive: false,
539
- parseDOM: [
540
- {
541
- tag: "a[href]",
542
- getAttrs(dom) {
543
- return {
544
- href: dom.getAttribute("href"),
545
- title: dom.getAttribute("title")
546
- };
547
- }
548
- }
549
- ],
550
- toDOM(node) {
551
- const { href, title } = node.attrs;
552
- const target = "_blank";
553
- const rel = "noopener noreferrer";
554
- return ["a", { href, title: title || href, target, rel }, 0];
555
- }
556
- },
557
- bold: {
558
- parseDOM: [
559
- { tag: "strong" },
560
- {
561
- tag: "b",
562
- getAttrs: (node) => node.style.fontWeight != "normal" && null
563
- },
564
- {
565
- style: "font-weight=400",
566
- clearMark: (m) => m.type.name == "strong"
567
- },
568
- {
569
- style: "font-weight",
570
- getAttrs: (value) => /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null
571
- }
572
- ],
573
- toDOM() {
574
- return ["strong", 0];
575
- }
576
- },
577
- italic: {
578
- parseDOM: [
579
- { tag: "em" },
580
- { tag: "i" },
581
- { style: "font-style=italic" },
582
- {
583
- style: "font-style=normal",
584
- clearMark: (m) => m.type.name == "em"
585
- }
586
- ],
587
- toDOM() {
588
- return ["em", 0];
589
- }
590
- },
591
- underline: {
592
- parseDOM: [
593
- { tag: "u" },
594
- {
595
- style: "text-decoration",
596
- getAttrs: (value) => value === "underline" && null
597
- }
598
- ],
599
- toDOM() {
600
- return ["u", 0];
601
- }
602
- }
603
- }
604
- });
605
- const prosemirrorSchema = new Schema({
606
- nodes: addListNodes(customSchema.spec.nodes, "paragraph block*", "block"),
607
- marks: customSchema.spec.marks
608
- });
609
- return prosemirrorSchema;
610
- }
611
-
612
- // src/cn.ts
613
- function cn(...classes) {
614
- return classes.filter(Boolean).join(" ").trim();
615
- }
616
-
617
- // src/text_editor/text_editor.tsx
618
- function createTextEditor({
619
- fileUploader,
620
- cdnOrigin
621
- } = {}) {
622
- const schema = createSchema({ cdnOrigin });
623
- const prosemirrorParser = DOMParser.fromSchema(schema);
624
- const prosemirrorSerializer = DOMSerializer.fromSchema(schema);
625
- const attachMediaComponent = cdnOrigin && fileUploader ? createAttachMedia({
626
- schema,
627
- cdnOrigin,
628
- fileUploader
629
- }) : null;
630
- function useTextEditor() {
631
- const view = useRef(null);
632
- const observers = useMemo(() => [], []);
633
- const Component = useCallback(
634
- function Component2({
635
- autofocus,
636
- name,
637
- placeholder,
638
- className,
639
- defaultValue,
640
- onClick,
641
- onHTMLChanged,
642
- editor,
643
- state,
644
- ...props
645
- }) {
646
- const ref = useRef(null);
647
- useEffect(() => {
648
- const container = ref.current;
649
- if (!container) {
650
- return;
651
- }
652
- const wrapper = document.createElement("div");
653
- wrapper.innerHTML = defaultValue || "";
654
- const editorView = new EditorView(container, {
655
- ...editor,
656
- attributes: (state2) => {
657
- const propsAttributes = (() => {
658
- if (typeof editor?.attributes === "function") {
659
- return editor.attributes(state2);
660
- }
661
- return editor?.attributes;
662
- })();
663
- return {
664
- ...propsAttributes,
665
- class: cn(propsAttributes?.class, "outline-none"),
666
- spellcheck: propsAttributes?.spellcheck || "false"
667
- };
668
- },
669
- state: EditorState2.create({
670
- schema: state?.schema || schema,
671
- doc: state?.doc || prosemirrorParser.parse(wrapper),
672
- plugins: [
673
- ...state?.plugins || [],
674
- history(),
675
- keymap(baseKeymap),
676
- keymap(buildKeymap()),
677
- uploadPlaceholderPlugin,
678
- attachMediaComponent ? dragAndDropPlugin({ attachMedia: attachMediaComponent }) : null,
679
- placeholder && placeholderPlugin(placeholder)
680
- ].filter((e) => !!e)
681
- }),
682
- dispatchTransaction(tr) {
683
- let result;
684
- if (editor?.dispatchTransaction) {
685
- result = editor.dispatchTransaction(tr);
686
- } else {
687
- editorView.updateState(editorView.state.apply(tr));
688
- }
689
- observers.forEach((observer) => {
690
- observer(editorView);
691
- });
692
- if (tr.docChanged) {
693
- const html = serialize();
694
- onHTMLChanged?.(html);
695
- if (inputRef.current) {
696
- inputRef.current.value = html;
697
- }
698
- }
699
- return result;
700
- }
701
- });
702
- view.current = editorView;
703
- if (autofocus) {
704
- editorView.focus();
705
- }
706
- return () => {
707
- view.current = null;
708
- editorView.destroy();
709
- container.innerHTML = "";
710
- };
711
- }, [editor, state, defaultValue, placeholder, onHTMLChanged]);
712
- const inputRef = useRef(null);
713
- return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
714
- "div",
715
- {
716
- ref,
717
- className: cn("cursor-text", className),
718
- onClick: (e) => {
719
- e.stopPropagation();
720
- view?.current?.focus();
721
- onClick?.(e);
722
- },
723
- ...props
724
- }
725
- ), name && /* @__PURE__ */ React2.createElement("input", { ref: inputRef, type: "hidden", name }));
726
- },
727
- [observers]
728
- );
729
- const commands = {
730
- async attachMedia(files) {
731
- if (view.current && attachMediaComponent) {
732
- return attachMediaComponent(view.current, files);
733
- }
734
- },
735
- toggleMark(type, attrs, options) {
736
- const markType = schema.marks[type];
737
- if (view.current && markType) {
738
- const command = toggleMark(markType, attrs, options);
739
- command(view.current.state, view.current.dispatch);
740
- }
741
- },
742
- setBlockType(type, attrs) {
743
- const blockType = schema.nodes[type];
744
- if (view.current && blockType) {
745
- const command = setBlockType(blockType, attrs);
746
- command(view.current.state, view.current.dispatch);
747
- }
748
- },
749
- insertNode(type, attrs, content, marks) {
750
- const nodeType = schema.nodes[type];
751
- if (view.current && nodeType) {
752
- const node = nodeType.create(attrs, content, marks);
753
- view.current.dispatch(
754
- view.current.state.tr.replaceSelectionWith(node)
755
- );
756
- }
757
- },
758
- setHTML(html) {
759
- if (!view.current) {
760
- return;
761
- }
762
- const wrap = document.createElement("div");
763
- wrap.innerHTML = html;
764
- const doc = prosemirrorParser.parse(wrap);
765
- const tr = view.current.state.tr.replaceWith(
766
- 0,
767
- view.current.state.doc.content.size,
768
- doc.content
769
- );
770
- view.current.dispatch(tr);
771
- }
772
- };
773
- const serialize = () => {
774
- if (!view.current) {
775
- return "";
776
- }
777
- const fragment = prosemirrorSerializer.serializeFragment(
778
- view.current.state.doc.content
779
- );
780
- const container = document.createElement("div");
781
- container.appendChild(fragment);
782
- return container.innerHTML;
783
- };
784
- const getTextContent = () => {
785
- if (!view.current) {
786
- return "";
787
- }
788
- return view.current.state.doc.textContent;
789
- };
790
- return {
791
- schema,
792
- view,
793
- commands,
794
- Component,
795
- serialize,
796
- getTextContent
797
- };
798
- }
799
- return {
800
- schema,
801
- useTextEditor
802
- };
803
- }
804
- export {
805
- createTextEditor as default
806
- };