@pie-lib/editable-html-tip-tap 2.2.0-beta.8 → 3.0.0-next.35

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 (282) hide show
  1. package/dist/components/CharacterPicker.d.ts +31 -0
  2. package/dist/components/CharacterPicker.js +141 -0
  3. package/dist/components/EditableHtml.d.ts +11 -0
  4. package/dist/components/EditableHtml.js +330 -0
  5. package/dist/components/MenuBar.d.ts +11 -0
  6. package/dist/components/MenuBar.js +528 -0
  7. package/dist/components/TiptapContainer.d.ts +11 -0
  8. package/dist/components/TiptapContainer.js +167 -0
  9. package/dist/components/characters/characterUtils.d.ts +35 -0
  10. package/dist/components/characters/characterUtils.js +465 -0
  11. package/dist/components/characters/custom-popper.d.ts +14 -0
  12. package/dist/components/characters/custom-popper.js +32 -0
  13. package/dist/components/common/done-button.d.ts +30 -0
  14. package/dist/components/common/done-button.js +26 -0
  15. package/dist/components/common/toolbar-buttons.d.ts +38 -0
  16. package/dist/components/common/toolbar-buttons.js +96 -0
  17. package/dist/components/icons/CssIcon.d.ts +11 -0
  18. package/dist/components/icons/CssIcon.js +14 -0
  19. package/dist/components/icons/RespArea.d.ts +26 -0
  20. package/dist/components/icons/RespArea.js +42 -0
  21. package/dist/components/icons/TableIcons.d.ts +14 -0
  22. package/dist/components/icons/TableIcons.js +34 -0
  23. package/dist/components/icons/TextAlign.d.ts +18 -0
  24. package/dist/components/icons/TextAlign.js +143 -0
  25. package/dist/components/image/AltDialog.d.ts +22 -0
  26. package/dist/components/image/AltDialog.js +61 -0
  27. package/dist/components/image/ImageToolbar.d.ts +24 -0
  28. package/dist/components/image/ImageToolbar.js +80 -0
  29. package/dist/components/image/InsertImageHandler.d.ts +32 -0
  30. package/dist/components/image/InsertImageHandler.js +53 -0
  31. package/dist/components/media/MediaDialog.d.ts +43 -0
  32. package/dist/components/media/MediaDialog.js +389 -0
  33. package/dist/components/media/MediaToolbar.d.ts +19 -0
  34. package/dist/components/media/MediaToolbar.js +41 -0
  35. package/dist/components/media/MediaWrapper.d.ts +19 -0
  36. package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts +23 -0
  37. package/dist/components/respArea/DragInTheBlank/DragInTheBlank.js +58 -0
  38. package/dist/components/respArea/DragInTheBlank/choice.d.ts +56 -0
  39. package/dist/components/respArea/DragInTheBlank/choice.js +157 -0
  40. package/dist/components/respArea/ExplicitConstructedResponse.d.ts +20 -0
  41. package/dist/components/respArea/ExplicitConstructedResponse.js +84 -0
  42. package/dist/components/respArea/InlineDropdown.d.ts +18 -0
  43. package/dist/components/respArea/InlineDropdown.js +126 -0
  44. package/dist/components/respArea/MathTemplated.d.ts +19 -0
  45. package/dist/components/respArea/MathTemplated.js +98 -0
  46. package/dist/components/respArea/ToolbarIcon.d.ts +14 -0
  47. package/dist/components/respArea/ToolbarIcon.js +17 -0
  48. package/dist/components/respArea/inlineDropdownUtils.d.ts +15 -0
  49. package/dist/components/respArea/inlineDropdownUtils.js +15 -0
  50. package/dist/constants.d.ts +13 -0
  51. package/dist/constants.js +4 -0
  52. package/dist/extensions/css.d.ts +11 -0
  53. package/dist/extensions/css.js +120 -0
  54. package/dist/extensions/custom-toolbar-wrapper.d.ts +11 -0
  55. package/dist/extensions/custom-toolbar-wrapper.js +61 -0
  56. package/dist/extensions/div-node.d.ts +10 -0
  57. package/dist/extensions/div-node.js +42 -0
  58. package/dist/extensions/ensure-empty-root-div.d.ts +14 -0
  59. package/dist/extensions/ensure-empty-root-div.js +24 -0
  60. package/dist/extensions/ensure-list-item-content-is-div.d.ts +15 -0
  61. package/dist/extensions/ensure-list-item-content-is-div.js +31 -0
  62. package/dist/extensions/extended-list-item.d.ts +13 -0
  63. package/dist/extensions/extended-list-item.js +5 -0
  64. package/dist/extensions/extended-table-cell.d.ts +10 -0
  65. package/dist/extensions/extended-table-cell.js +6 -0
  66. package/dist/extensions/extended-table.d.ts +17 -0
  67. package/dist/extensions/extended-table.js +34 -0
  68. package/dist/extensions/heading-paragraph.d.ts +17 -0
  69. package/dist/extensions/heading-paragraph.js +30 -0
  70. package/dist/extensions/image-component.d.ts +22 -0
  71. package/dist/extensions/image-component.js +225 -0
  72. package/dist/extensions/image.d.ts +10 -0
  73. package/dist/extensions/image.js +68 -0
  74. package/dist/extensions/index.d.ts +16 -0
  75. package/dist/extensions/index.js +64 -0
  76. package/dist/extensions/math.d.ts +15 -0
  77. package/dist/extensions/math.js +213 -0
  78. package/dist/extensions/media.d.ts +19 -0
  79. package/dist/extensions/media.js +149 -0
  80. package/dist/extensions/responseArea.d.ts +27 -0
  81. package/dist/extensions/responseArea.js +255 -0
  82. package/dist/index.d.ts +13 -0
  83. package/dist/index.js +7 -0
  84. package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
  85. package/dist/styles/editorContainerStyles.d.ts +134 -0
  86. package/dist/theme.d.ts +9 -0
  87. package/dist/utils/helper.d.ts +9 -0
  88. package/dist/utils/helper.js +27 -0
  89. package/dist/utils/size.d.ts +9 -0
  90. package/dist/utils/size.js +14 -0
  91. package/dist/utils/toolbar.d.ts +10 -0
  92. package/dist/utils/toolbar.js +7 -0
  93. package/package.json +43 -29
  94. package/CHANGELOG.json +0 -32
  95. package/CHANGELOG.md +0 -2532
  96. package/lib/components/CharacterPicker.js +0 -226
  97. package/lib/components/CharacterPicker.js.map +0 -1
  98. package/lib/components/EditableHtml.js +0 -388
  99. package/lib/components/EditableHtml.js.map +0 -1
  100. package/lib/components/MenuBar.js +0 -702
  101. package/lib/components/MenuBar.js.map +0 -1
  102. package/lib/components/TiptapContainer.js +0 -242
  103. package/lib/components/TiptapContainer.js.map +0 -1
  104. package/lib/components/characters/characterUtils.js +0 -378
  105. package/lib/components/characters/characterUtils.js.map +0 -1
  106. package/lib/components/characters/custom-popper.js +0 -44
  107. package/lib/components/characters/custom-popper.js.map +0 -1
  108. package/lib/components/common/done-button.js +0 -34
  109. package/lib/components/common/done-button.js.map +0 -1
  110. package/lib/components/common/toolbar-buttons.js +0 -149
  111. package/lib/components/common/toolbar-buttons.js.map +0 -1
  112. package/lib/components/icons/CssIcon.js +0 -25
  113. package/lib/components/icons/CssIcon.js.map +0 -1
  114. package/lib/components/icons/RespArea.js +0 -72
  115. package/lib/components/icons/RespArea.js.map +0 -1
  116. package/lib/components/icons/TableIcons.js +0 -53
  117. package/lib/components/icons/TableIcons.js.map +0 -1
  118. package/lib/components/icons/TextAlign.js +0 -157
  119. package/lib/components/icons/TextAlign.js.map +0 -1
  120. package/lib/components/image/AltDialog.js +0 -98
  121. package/lib/components/image/AltDialog.js.map +0 -1
  122. package/lib/components/image/ImageToolbar.js +0 -137
  123. package/lib/components/image/ImageToolbar.js.map +0 -1
  124. package/lib/components/image/InsertImageHandler.js +0 -135
  125. package/lib/components/image/InsertImageHandler.js.map +0 -1
  126. package/lib/components/media/MediaDialog.js +0 -594
  127. package/lib/components/media/MediaDialog.js.map +0 -1
  128. package/lib/components/media/MediaToolbar.js +0 -74
  129. package/lib/components/media/MediaToolbar.js.map +0 -1
  130. package/lib/components/media/MediaWrapper.js +0 -67
  131. package/lib/components/media/MediaWrapper.js.map +0 -1
  132. package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js +0 -84
  133. package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js.map +0 -1
  134. package/lib/components/respArea/DragInTheBlank/choice.js +0 -253
  135. package/lib/components/respArea/DragInTheBlank/choice.js.map +0 -1
  136. package/lib/components/respArea/ExplicitConstructedResponse.js +0 -137
  137. package/lib/components/respArea/ExplicitConstructedResponse.js.map +0 -1
  138. package/lib/components/respArea/InlineDropdown.js +0 -223
  139. package/lib/components/respArea/InlineDropdown.js.map +0 -1
  140. package/lib/components/respArea/MathTemplated.js +0 -130
  141. package/lib/components/respArea/MathTemplated.js.map +0 -1
  142. package/lib/components/respArea/ToolbarIcon.js +0 -81
  143. package/lib/components/respArea/ToolbarIcon.js.map +0 -1
  144. package/lib/components/respArea/inlineDropdownUtils.js +0 -67
  145. package/lib/components/respArea/inlineDropdownUtils.js.map +0 -1
  146. package/lib/constants.js +0 -11
  147. package/lib/constants.js.map +0 -1
  148. package/lib/extensions/css.js +0 -227
  149. package/lib/extensions/css.js.map +0 -1
  150. package/lib/extensions/custom-toolbar-wrapper.js +0 -92
  151. package/lib/extensions/custom-toolbar-wrapper.js.map +0 -1
  152. package/lib/extensions/div-node.js +0 -83
  153. package/lib/extensions/div-node.js.map +0 -1
  154. package/lib/extensions/ensure-empty-root-div.js +0 -48
  155. package/lib/extensions/ensure-empty-root-div.js.map +0 -1
  156. package/lib/extensions/ensure-list-item-content-is-div.js +0 -64
  157. package/lib/extensions/ensure-list-item-content-is-div.js.map +0 -1
  158. package/lib/extensions/extended-list-item.js +0 -15
  159. package/lib/extensions/extended-list-item.js.map +0 -1
  160. package/lib/extensions/extended-table-cell.js +0 -22
  161. package/lib/extensions/extended-table-cell.js.map +0 -1
  162. package/lib/extensions/extended-table.js +0 -75
  163. package/lib/extensions/extended-table.js.map +0 -1
  164. package/lib/extensions/heading-paragraph.js +0 -61
  165. package/lib/extensions/heading-paragraph.js.map +0 -1
  166. package/lib/extensions/image-component.js +0 -351
  167. package/lib/extensions/image-component.js.map +0 -1
  168. package/lib/extensions/image.js +0 -134
  169. package/lib/extensions/image.js.map +0 -1
  170. package/lib/extensions/index.js +0 -46
  171. package/lib/extensions/index.js.map +0 -1
  172. package/lib/extensions/math.js +0 -469
  173. package/lib/extensions/math.js.map +0 -1
  174. package/lib/extensions/media.js +0 -243
  175. package/lib/extensions/media.js.map +0 -1
  176. package/lib/extensions/responseArea.js +0 -452
  177. package/lib/extensions/responseArea.js.map +0 -1
  178. package/lib/index.js +0 -37
  179. package/lib/index.js.map +0 -1
  180. package/lib/styles/editorContainerStyles.js +0 -137
  181. package/lib/styles/editorContainerStyles.js.map +0 -1
  182. package/lib/theme.js +0 -8
  183. package/lib/theme.js.map +0 -1
  184. package/lib/utils/helper.js +0 -73
  185. package/lib/utils/helper.js.map +0 -1
  186. package/lib/utils/size.js +0 -26
  187. package/lib/utils/size.js.map +0 -1
  188. package/lib/utils/toolbar.js +0 -19
  189. package/lib/utils/toolbar.js.map +0 -1
  190. package/src/__tests__/EditableHtml.test.jsx +0 -588
  191. package/src/__tests__/constants.test.js +0 -19
  192. package/src/__tests__/div-to-paragraph-conversion.test.jsx +0 -125
  193. package/src/__tests__/extensions.test.js +0 -208
  194. package/src/__tests__/index.test.jsx +0 -154
  195. package/src/__tests__/size-utils.test.js +0 -64
  196. package/src/__tests__/theme.test.js +0 -17
  197. package/src/components/CharacterPicker.jsx +0 -237
  198. package/src/components/EditableHtml.jsx +0 -458
  199. package/src/components/MenuBar.jsx +0 -561
  200. package/src/components/TiptapContainer.jsx +0 -235
  201. package/src/components/__tests__/AltDialog.test.jsx +0 -147
  202. package/src/components/__tests__/CharacterPicker.test.jsx +0 -270
  203. package/src/components/__tests__/CssIcon.test.jsx +0 -46
  204. package/src/components/__tests__/DragInTheBlank.test.jsx +0 -255
  205. package/src/components/__tests__/ExplicitConstructedResponse.test.jsx +0 -209
  206. package/src/components/__tests__/ImageToolbar.test.jsx +0 -128
  207. package/src/components/__tests__/InlineDropdown.test.jsx +0 -557
  208. package/src/components/__tests__/InsertImageHandler.test.js +0 -161
  209. package/src/components/__tests__/MediaDialog.test.jsx +0 -293
  210. package/src/components/__tests__/MediaToolbar.test.jsx +0 -74
  211. package/src/components/__tests__/MediaWrapper.test.jsx +0 -81
  212. package/src/components/__tests__/MenuBar.test.jsx +0 -250
  213. package/src/components/__tests__/RespArea.test.jsx +0 -122
  214. package/src/components/__tests__/TableIcons.test.jsx +0 -149
  215. package/src/components/__tests__/TextAlign.test.jsx +0 -167
  216. package/src/components/__tests__/TiptapContainer.test.jsx +0 -138
  217. package/src/components/__tests__/characterUtils.test.js +0 -166
  218. package/src/components/__tests__/choice.test.jsx +0 -171
  219. package/src/components/__tests__/custom-popper.test.jsx +0 -82
  220. package/src/components/__tests__/done-button.test.jsx +0 -54
  221. package/src/components/__tests__/toolbar-buttons.test.jsx +0 -234
  222. package/src/components/characters/characterUtils.js +0 -447
  223. package/src/components/characters/custom-popper.js +0 -38
  224. package/src/components/common/done-button.jsx +0 -27
  225. package/src/components/common/toolbar-buttons.jsx +0 -127
  226. package/src/components/icons/CssIcon.jsx +0 -15
  227. package/src/components/icons/RespArea.jsx +0 -71
  228. package/src/components/icons/TableIcons.jsx +0 -52
  229. package/src/components/icons/TextAlign.jsx +0 -114
  230. package/src/components/image/AltDialog.jsx +0 -82
  231. package/src/components/image/ImageToolbar.jsx +0 -99
  232. package/src/components/image/InsertImageHandler.js +0 -107
  233. package/src/components/media/MediaDialog.jsx +0 -596
  234. package/src/components/media/MediaToolbar.jsx +0 -49
  235. package/src/components/media/MediaWrapper.jsx +0 -39
  236. package/src/components/respArea/DragInTheBlank/DragInTheBlank.jsx +0 -76
  237. package/src/components/respArea/DragInTheBlank/__tests__/choice.test.jsx +0 -72
  238. package/src/components/respArea/DragInTheBlank/choice.jsx +0 -259
  239. package/src/components/respArea/ExplicitConstructedResponse.jsx +0 -136
  240. package/src/components/respArea/InlineDropdown.jsx +0 -240
  241. package/src/components/respArea/MathTemplated.jsx +0 -124
  242. package/src/components/respArea/ToolbarIcon.jsx +0 -66
  243. package/src/components/respArea/__tests__/MathTemplated.test.jsx +0 -210
  244. package/src/components/respArea/inlineDropdownUtils.js +0 -79
  245. package/src/constants.js +0 -5
  246. package/src/extensions/__tests__/css.test.js +0 -196
  247. package/src/extensions/__tests__/custom-toolbar-wrapper.test.jsx +0 -180
  248. package/src/extensions/__tests__/divNode.test.js +0 -87
  249. package/src/extensions/__tests__/ensure-empty-root-div.test.js +0 -57
  250. package/src/extensions/__tests__/ensure-list-item-content-is-div.test.js +0 -44
  251. package/src/extensions/__tests__/extended-list-item.test.js +0 -13
  252. package/src/extensions/__tests__/extended-table-cell.test.js +0 -22
  253. package/src/extensions/__tests__/extended-table.test.js +0 -183
  254. package/src/extensions/__tests__/image-component.test.jsx +0 -346
  255. package/src/extensions/__tests__/image.test.js +0 -237
  256. package/src/extensions/__tests__/math.test.js +0 -900
  257. package/src/extensions/__tests__/media-node-view.test.jsx +0 -298
  258. package/src/extensions/__tests__/media.test.js +0 -271
  259. package/src/extensions/__tests__/responseArea.test.js +0 -655
  260. package/src/extensions/css.js +0 -233
  261. package/src/extensions/custom-toolbar-wrapper.jsx +0 -78
  262. package/src/extensions/div-node.js +0 -86
  263. package/src/extensions/ensure-empty-root-div.js +0 -47
  264. package/src/extensions/ensure-list-item-content-is-div.js +0 -62
  265. package/src/extensions/extended-list-item.js +0 -10
  266. package/src/extensions/extended-table-cell.js +0 -19
  267. package/src/extensions/extended-table.js +0 -60
  268. package/src/extensions/heading-paragraph.js +0 -53
  269. package/src/extensions/image-component.jsx +0 -340
  270. package/src/extensions/image.js +0 -109
  271. package/src/extensions/index.js +0 -81
  272. package/src/extensions/math.js +0 -454
  273. package/src/extensions/media.js +0 -188
  274. package/src/extensions/responseArea.js +0 -407
  275. package/src/index.jsx +0 -5
  276. package/src/styles/editorContainerStyles.js +0 -145
  277. package/src/theme.js +0 -1
  278. package/src/utils/__tests__/helper.test.js +0 -126
  279. package/src/utils/__tests__/toolbar.test.js +0 -43
  280. package/src/utils/helper.js +0 -69
  281. package/src/utils/size.js +0 -32
  282. package/src/utils/toolbar.js +0 -15
@@ -1,655 +0,0 @@
1
- import {
2
- DragInTheBlankNode,
3
- ExplicitConstructedResponseNode,
4
- InlineDropdownNode,
5
- ResponseAreaExtension,
6
- } from '../responseArea';
7
-
8
- jest.mock('@tiptap/core', () => ({
9
- Extension: { create: jest.fn((config) => config) },
10
- Node: { create: jest.fn((config) => config) },
11
- }));
12
-
13
- jest.mock('@tiptap/react', () => ({
14
- Node: { create: jest.fn((config) => config) },
15
- ReactNodeViewRenderer: jest.fn((component) => component),
16
- }));
17
-
18
- jest.mock('prosemirror-state', () => ({
19
- Plugin: jest.fn(function (config) {
20
- return config;
21
- }),
22
- PluginKey: jest.fn(function (key) {
23
- this.key = key;
24
- }),
25
- TextSelection: {
26
- near: jest.fn((pos, dir) => ({ type: 'text', pos, dir })),
27
- create: jest.fn((doc, pos) => ({ type: 'text', pos })),
28
- },
29
- NodeSelection: {
30
- create: jest.fn((doc, pos) => ({ type: 'node', pos })),
31
- },
32
- }));
33
-
34
- jest.mock('../../components/respArea/ExplicitConstructedResponse', () => ({
35
- __esModule: true,
36
- default: jest.fn(() => <div data-testid="explicit-constructed-response" />),
37
- }));
38
-
39
- jest.mock('../../components/respArea/DragInTheBlank/DragInTheBlank', () => ({
40
- __esModule: true,
41
- default: jest.fn(() => <div data-testid="drag-in-the-blank" />),
42
- }));
43
-
44
- jest.mock('../../components/respArea/InlineDropdown', () => ({
45
- __esModule: true,
46
- default: jest.fn(() => <div data-testid="inline-dropdown" />),
47
- }));
48
-
49
- describe('ResponseAreaExtension', () => {
50
- describe('configuration', () => {
51
- it('has correct name', () => {
52
- expect(ResponseAreaExtension.name).toBe('responseArea');
53
- });
54
- });
55
-
56
- describe('addOptions', () => {
57
- it('returns default options', () => {
58
- const options = ResponseAreaExtension.addOptions();
59
-
60
- expect(options).toHaveProperty('maxResponseAreas', null);
61
- expect(options).toHaveProperty('error', null);
62
- expect(options).toHaveProperty('options', null);
63
- expect(options).toHaveProperty('respAreaToolbar', null);
64
- expect(options).toHaveProperty('onHandleAreaChange', null);
65
- });
66
- });
67
-
68
- describe('addProseMirrorPlugins', () => {
69
- it('returns empty array when no type specified', () => {
70
- const context = {
71
- options: {},
72
- };
73
-
74
- const plugins = ResponseAreaExtension.addProseMirrorPlugins.call(context);
75
-
76
- expect(Array.isArray(plugins)).toBe(true);
77
- expect(plugins).toHaveLength(0);
78
- });
79
-
80
- it('returns plugin array when type is specified', () => {
81
- const context = {
82
- options: {
83
- type: 'explicit-constructed-response',
84
- maxResponseAreas: 5,
85
- },
86
- };
87
-
88
- const plugins = ResponseAreaExtension.addProseMirrorPlugins.call(context);
89
-
90
- expect(Array.isArray(plugins)).toBe(true);
91
- expect(plugins).toHaveLength(1);
92
- expect(plugins[0]).toHaveProperty('key');
93
- expect(plugins[0]).toHaveProperty('view');
94
- });
95
- });
96
-
97
- describe('addCommands', () => {
98
- it('returns insertResponseArea command', () => {
99
- const commands = ResponseAreaExtension.addCommands();
100
-
101
- expect(commands).toHaveProperty('insertResponseArea');
102
- expect(typeof commands.insertResponseArea).toBe('function');
103
- });
104
-
105
- it('returns refreshResponseArea command', () => {
106
- const commands = ResponseAreaExtension.addCommands();
107
-
108
- expect(commands).toHaveProperty('refreshResponseArea');
109
- expect(typeof commands.refreshResponseArea).toBe('function');
110
- });
111
-
112
- it('refreshResponseArea handles node with attrs safely', () => {
113
- const context = {
114
- options: {
115
- type: 'explicit-constructed-response',
116
- maxResponseAreas: 5,
117
- },
118
- };
119
-
120
- const commands = ResponseAreaExtension.addCommands.call(context);
121
- const refreshCommand = commands.refreshResponseArea();
122
-
123
- // Mock transaction and state
124
- const mockNode = {
125
- attrs: {
126
- index: '0',
127
- value: 'test',
128
- },
129
- };
130
-
131
- const mockTr = {
132
- setNodeMarkup: jest.fn(),
133
- setSelection: jest.fn(),
134
- };
135
-
136
- const mockState = {
137
- selection: {
138
- from: 0,
139
- $from: {
140
- nodeAfter: mockNode,
141
- },
142
- },
143
- tr: mockTr,
144
- };
145
-
146
- const mockCommands = {
147
- focus: jest.fn(),
148
- };
149
-
150
- const mockDispatch = jest.fn();
151
-
152
- refreshCommand({
153
- tr: mockTr,
154
- state: mockState,
155
- commands: mockCommands,
156
- dispatch: mockDispatch,
157
- });
158
-
159
- expect(mockTr.setNodeMarkup).toHaveBeenCalled();
160
- });
161
-
162
- it('refreshResponseArea handles node without attrs safely (optional chaining)', () => {
163
- const context = {
164
- options: {
165
- type: 'explicit-constructed-response',
166
- maxResponseAreas: 5,
167
- },
168
- };
169
-
170
- const commands = ResponseAreaExtension.addCommands.call(context);
171
- const refreshCommand = commands.refreshResponseArea();
172
-
173
- // Mock transaction and state with node that has no attrs
174
- const mockNode = null;
175
-
176
- const mockTr = {
177
- setNodeMarkup: jest.fn(),
178
- setSelection: jest.fn(),
179
- };
180
-
181
- const mockState = {
182
- selection: {
183
- from: 0,
184
- $from: {
185
- nodeAfter: mockNode,
186
- },
187
- },
188
- tr: mockTr,
189
- };
190
-
191
- const mockCommands = {
192
- focus: jest.fn(),
193
- };
194
-
195
- const mockDispatch = jest.fn();
196
-
197
- // This should not throw an error due to optional chaining on node?.attrs
198
- expect(() => {
199
- refreshCommand({
200
- tr: mockTr,
201
- state: mockState,
202
- commands: mockCommands,
203
- dispatch: mockDispatch,
204
- });
205
- }).not.toThrow();
206
- });
207
-
208
- it('refreshResponseArea updates timestamp in node attributes', () => {
209
- const context = {
210
- options: {
211
- type: 'explicit-constructed-response',
212
- maxResponseAreas: 5,
213
- },
214
- };
215
-
216
- const commands = ResponseAreaExtension.addCommands.call(context);
217
- const refreshCommand = commands.refreshResponseArea();
218
-
219
- const mockNode = {
220
- attrs: {
221
- index: '0',
222
- value: 'test',
223
- updated: '1234567890',
224
- },
225
- };
226
-
227
- const mockTr = {
228
- setNodeMarkup: jest.fn((pos, type, attrs) => {
229
- // Verify that updated timestamp is being set
230
- expect(attrs.updated).toBeDefined();
231
- expect(attrs.updated).not.toBe('1234567890');
232
- }),
233
- setSelection: jest.fn(),
234
- };
235
-
236
- const mockState = {
237
- selection: {
238
- from: 0,
239
- $from: {
240
- nodeAfter: mockNode,
241
- },
242
- },
243
- tr: mockTr,
244
- };
245
-
246
- const mockCommands = {
247
- focus: jest.fn(),
248
- };
249
-
250
- const mockDispatch = jest.fn();
251
-
252
- refreshCommand({
253
- tr: mockTr,
254
- state: mockState,
255
- commands: mockCommands,
256
- dispatch: mockDispatch,
257
- });
258
-
259
- expect(mockTr.setNodeMarkup).toHaveBeenCalled();
260
- });
261
-
262
- describe('insertResponseArea', () => {
263
- beforeEach(() => {
264
- jest.resetModules();
265
- });
266
-
267
- const buildInsertCommand = (type = 'inline-dropdown') => {
268
- const { ResponseAreaExtension } = require('../responseArea');
269
- const context = {
270
- options: {
271
- type,
272
- maxResponseAreas: 5,
273
- },
274
- };
275
- const commands = ResponseAreaExtension.addCommands.call(context);
276
- return commands.insertResponseArea(type);
277
- };
278
-
279
- const createDoc = (existingCount, typeName = 'inline_dropdown') => ({
280
- descendants: jest.fn((callback) => {
281
- for (let i = 0; i < existingCount; i += 1) {
282
- callback({ type: { name: typeName } }, i);
283
- }
284
- }),
285
- content: { size: 50 },
286
- });
287
-
288
- it('assigns index 1 and id 1 on the first insert', () => {
289
- const insert = buildInsertCommand();
290
- const mockInlineNode = { nodeSize: 1 };
291
- const create = jest.fn(() => mockInlineNode);
292
- const mockDoc = createDoc(0);
293
- const mockTr = {
294
- insert: jest.fn(),
295
- doc: mockDoc,
296
- setSelection: jest.fn(),
297
- };
298
- const state = {
299
- schema: {
300
- nodes: {
301
- inline_dropdown: { create },
302
- },
303
- },
304
- doc: mockDoc,
305
- selection: { from: 5 },
306
- };
307
- const mockDispatch = jest.fn();
308
- const mockCommands = { focus: jest.fn() };
309
-
310
- const result = insert({
311
- tr: mockTr,
312
- state,
313
- dispatch: mockDispatch,
314
- commands: mockCommands,
315
- });
316
-
317
- expect(result).toBe(true);
318
- expect(create).toHaveBeenCalledWith({
319
- index: '1',
320
- id: '1',
321
- value: '',
322
- });
323
- expect(mockTr.insert).toHaveBeenCalledWith(5, mockInlineNode);
324
- expect(mockDispatch).toHaveBeenCalled();
325
- });
326
-
327
- it('assigns consecutive indices on repeated inserts', () => {
328
- const insert = buildInsertCommand();
329
- const mockInlineNode = { nodeSize: 1 };
330
- const create = jest.fn(() => mockInlineNode);
331
- const mockDoc = createDoc(0);
332
-
333
- const runOnce = () => {
334
- const mockTr = {
335
- insert: jest.fn(),
336
- doc: mockDoc,
337
- setSelection: jest.fn(),
338
- };
339
- const state = {
340
- schema: {
341
- nodes: {
342
- inline_dropdown: { create },
343
- },
344
- },
345
- doc: mockDoc,
346
- selection: { from: 1 },
347
- };
348
- insert({
349
- tr: mockTr,
350
- state,
351
- dispatch: jest.fn(),
352
- commands: { focus: jest.fn() },
353
- });
354
- };
355
-
356
- runOnce();
357
- runOnce();
358
-
359
- expect(create.mock.calls[0][0]).toEqual({ index: '1', id: '1', value: '' });
360
- expect(create.mock.calls[1][0]).toEqual({ index: '2', id: '2', value: '' });
361
- });
362
-
363
- it('returns false when maxResponseAreas is reached', () => {
364
- const insert = buildInsertCommand();
365
- const mockInlineNode = { nodeSize: 1 };
366
- const create = jest.fn(() => mockInlineNode);
367
- const mockDoc = createDoc(5);
368
- const mockTr = {
369
- insert: jest.fn(),
370
- doc: mockDoc,
371
- setSelection: jest.fn(),
372
- };
373
- const state = {
374
- schema: {
375
- nodes: {
376
- inline_dropdown: { create },
377
- },
378
- },
379
- doc: mockDoc,
380
- selection: { from: 5 },
381
- };
382
-
383
- const result = insert({
384
- tr: mockTr,
385
- state,
386
- dispatch: jest.fn(),
387
- commands: { focus: jest.fn() },
388
- });
389
-
390
- expect(result).toBe(false);
391
- expect(create).not.toHaveBeenCalled();
392
- expect(mockTr.insert).not.toHaveBeenCalled();
393
- });
394
-
395
- describe('selection after insert', () => {
396
- const buildStateAndTr = (typeName, { withResolve = false } = {}) => {
397
- const mockInlineNode = { nodeSize: 1 };
398
- const create = jest.fn(() => mockInlineNode);
399
- const mockDoc = {
400
- descendants: jest.fn(),
401
- content: { size: 50 },
402
- ...(withResolve ? { resolve: jest.fn((pos) => ({ resolved: pos })) } : {}),
403
- };
404
- const mockTr = {
405
- insert: jest.fn(),
406
- doc: mockDoc,
407
- setSelection: jest.fn(),
408
- };
409
- const state = {
410
- schema: { nodes: { [typeName]: { create } } },
411
- doc: mockDoc,
412
- selection: { from: 5 },
413
- };
414
-
415
- return { mockTr, state };
416
- };
417
-
418
- it.each(['inline-dropdown', 'explicit-constructed-response'])(
419
- 'sets a NodeSelection on the inserted node for %s',
420
- (type) => {
421
- const insert = buildInsertCommand(type);
422
- const typeName = type.replace(/-/g, '_');
423
- const { mockTr, state } = buildStateAndTr(typeName);
424
- const { NodeSelection, TextSelection } = require('prosemirror-state');
425
-
426
- insert({ tr: mockTr, state, dispatch: jest.fn(), commands: { focus: jest.fn() } });
427
-
428
- expect(NodeSelection.create).toHaveBeenCalledWith(mockTr.doc, 5);
429
- expect(TextSelection.near).not.toHaveBeenCalled();
430
- expect(mockTr.setSelection).toHaveBeenCalledWith({ type: 'node', pos: 5 });
431
- },
432
- );
433
-
434
- it('sets a TextSelection just after the inserted node for math-templated (no NodeSelection)', () => {
435
- const insert = buildInsertCommand('math-templated');
436
- const { mockTr, state } = buildStateAndTr('math_templated', { withResolve: true });
437
- const { NodeSelection, TextSelection } = require('prosemirror-state');
438
-
439
- insert({ tr: mockTr, state, dispatch: jest.fn(), commands: { focus: jest.fn() } });
440
-
441
- expect(NodeSelection.create).not.toHaveBeenCalled();
442
- // usedPos (5) + nodeSize (1) === 6
443
- expect(mockTr.doc.resolve).toHaveBeenCalledWith(6);
444
- expect(TextSelection.near).toHaveBeenCalledWith({ resolved: 6 }, 1);
445
- expect(mockTr.setSelection).toHaveBeenCalledWith({ type: 'text', pos: { resolved: 6 }, dir: 1 });
446
- });
447
- });
448
- });
449
- });
450
- });
451
-
452
- describe('ExplicitConstructedResponseNode', () => {
453
- describe('configuration', () => {
454
- it('has correct name', () => {
455
- expect(ExplicitConstructedResponseNode.name).toBe('explicit_constructed_response');
456
- });
457
-
458
- it('is inline', () => {
459
- expect(ExplicitConstructedResponseNode.inline).toBe(true);
460
- });
461
-
462
- it('is in inline group', () => {
463
- expect(ExplicitConstructedResponseNode.group).toBe('inline');
464
- });
465
-
466
- it('is atomic', () => {
467
- expect(ExplicitConstructedResponseNode.atom).toBe(true);
468
- });
469
- });
470
-
471
- describe('addAttributes', () => {
472
- it('returns required attributes', () => {
473
- const attributes = ExplicitConstructedResponseNode.addAttributes();
474
-
475
- expect(attributes).toHaveProperty('index');
476
- expect(attributes).toHaveProperty('value');
477
- expect(attributes).toHaveProperty('updated');
478
-
479
- expect(attributes.index).toEqual({ default: null });
480
- expect(attributes.value).toEqual({ default: '' });
481
- expect(attributes.updated).toEqual({ default: '' });
482
- });
483
- });
484
-
485
- describe('parseHTML', () => {
486
- it('returns parsing rules', () => {
487
- const rules = ExplicitConstructedResponseNode.parseHTML();
488
-
489
- expect(Array.isArray(rules)).toBe(true);
490
- expect(rules).toHaveLength(1);
491
- expect(rules[0]).toHaveProperty('tag');
492
- });
493
- });
494
-
495
- describe('renderHTML', () => {
496
- it('renders span with attributes', () => {
497
- const result = ExplicitConstructedResponseNode.renderHTML({
498
- HTMLAttributes: {
499
- index: '1',
500
- id: '1',
501
- value: 'test',
502
- },
503
- });
504
-
505
- expect(result[0]).toBe('span');
506
- expect(result[1]).toHaveProperty('data-type', 'explicit_constructed_response');
507
- });
508
- });
509
-
510
- describe('addNodeView', () => {
511
- it('returns ReactNodeViewRenderer result', () => {
512
- const result = ExplicitConstructedResponseNode.addNodeView();
513
-
514
- expect(result).toBeDefined();
515
- });
516
- });
517
- });
518
-
519
- describe('DragInTheBlankNode', () => {
520
- describe('configuration', () => {
521
- it('has correct name', () => {
522
- expect(DragInTheBlankNode.name).toBe('drag_in_the_blank');
523
- });
524
-
525
- it('is inline', () => {
526
- expect(DragInTheBlankNode.inline).toBe(true);
527
- });
528
-
529
- it('is in inline group', () => {
530
- expect(DragInTheBlankNode.group).toBe('inline');
531
- });
532
-
533
- it('is atomic', () => {
534
- expect(DragInTheBlankNode.atom).toBe(true);
535
- });
536
- });
537
-
538
- describe('addAttributes', () => {
539
- it('returns required attributes', () => {
540
- const attributes = DragInTheBlankNode.addAttributes();
541
-
542
- expect(attributes).toHaveProperty('index');
543
- expect(attributes).toHaveProperty('id');
544
- expect(attributes).toHaveProperty('value');
545
- expect(attributes).toHaveProperty('inTable');
546
- expect(attributes).toHaveProperty('updated');
547
-
548
- expect(attributes.index).toEqual({ default: null });
549
- expect(attributes.id).toEqual({ default: null });
550
- expect(attributes.value).toEqual({ default: '' });
551
- expect(attributes.inTable).toEqual({ default: null });
552
- expect(attributes.updated).toEqual({ default: '' });
553
- });
554
- });
555
-
556
- describe('parseHTML', () => {
557
- it('returns parsing rules', () => {
558
- const rules = DragInTheBlankNode.parseHTML();
559
-
560
- expect(Array.isArray(rules)).toBe(true);
561
- expect(rules).toHaveLength(1);
562
- expect(rules[0]).toHaveProperty('tag');
563
- });
564
- });
565
-
566
- describe('renderHTML', () => {
567
- it('renders span with attributes', () => {
568
- const result = DragInTheBlankNode.renderHTML({
569
- HTMLAttributes: {
570
- index: '1',
571
- id: '1',
572
- value: 'test',
573
- },
574
- });
575
-
576
- expect(result[0]).toBe('span');
577
- expect(result[1]).toHaveProperty('data-type', 'drag_in_the_blank');
578
- });
579
- });
580
-
581
- describe('addNodeView', () => {
582
- it('returns ReactNodeViewRenderer result', () => {
583
- const result = DragInTheBlankNode.addNodeView();
584
-
585
- expect(result).toBeDefined();
586
- });
587
- });
588
- });
589
-
590
- describe('InlineDropdownNode', () => {
591
- describe('configuration', () => {
592
- it('has correct name', () => {
593
- expect(InlineDropdownNode.name).toBe('inline_dropdown');
594
- });
595
-
596
- it('is inline', () => {
597
- expect(InlineDropdownNode.inline).toBe(true);
598
- });
599
-
600
- it('is in inline group', () => {
601
- expect(InlineDropdownNode.group).toBe('inline');
602
- });
603
-
604
- it('is atomic', () => {
605
- expect(InlineDropdownNode.atom).toBe(true);
606
- });
607
- });
608
-
609
- describe('addAttributes', () => {
610
- it('returns required attributes', () => {
611
- const attributes = InlineDropdownNode.addAttributes();
612
-
613
- expect(attributes).toHaveProperty('index');
614
- expect(attributes).toHaveProperty('value');
615
- expect(attributes).toHaveProperty('updated');
616
-
617
- expect(attributes.index).toEqual({ default: null });
618
- expect(attributes.value).toEqual({ default: '' });
619
- expect(attributes.updated).toEqual({ default: '' });
620
- });
621
- });
622
-
623
- describe('parseHTML', () => {
624
- it('returns parsing rules', () => {
625
- const rules = InlineDropdownNode.parseHTML();
626
-
627
- expect(Array.isArray(rules)).toBe(true);
628
- expect(rules).toHaveLength(1);
629
- expect(rules[0]).toHaveProperty('tag');
630
- });
631
- });
632
-
633
- describe('renderHTML', () => {
634
- it('renders span with attributes', () => {
635
- const result = InlineDropdownNode.renderHTML({
636
- HTMLAttributes: {
637
- index: '1',
638
- id: '1',
639
- value: 'test',
640
- },
641
- });
642
-
643
- expect(result[0]).toBe('span');
644
- expect(result[1]).toHaveProperty('data-type', 'inline_dropdown');
645
- });
646
- });
647
-
648
- describe('addNodeView', () => {
649
- it('returns ReactNodeViewRenderer result', () => {
650
- const result = InlineDropdownNode.addNodeView();
651
-
652
- expect(result).toBeDefined();
653
- });
654
- });
655
- });