@api-client/ui 0.5.39 → 0.5.41

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 (292) hide show
  1. package/build/src/elements/contextual-menu/{internals/ContextualMenu.d.ts → ContextualMenu.d.ts} +11 -6
  2. package/build/src/elements/contextual-menu/ContextualMenu.d.ts.map +1 -0
  3. package/build/src/elements/contextual-menu/{internals/ContextualMenu.js → ContextualMenu.js} +25 -3
  4. package/build/src/elements/contextual-menu/ContextualMenu.js.map +1 -0
  5. package/build/src/elements/contextual-menu/internals/types.d.ts +16 -7
  6. package/build/src/elements/contextual-menu/internals/types.d.ts.map +1 -1
  7. package/build/src/elements/contextual-menu/internals/types.js.map +1 -1
  8. package/build/tsconfig.tsbuildinfo +1 -0
  9. package/package.json +1 -1
  10. package/src/elements/contextual-menu/{internals/ContextualMenu.ts → ContextualMenu.ts} +31 -7
  11. package/src/elements/contextual-menu/internals/types.ts +17 -7
  12. package/.aiexclude +0 -3
  13. package/.cursor/rules/html-and-css-best-practices.mdc +0 -63
  14. package/.cursor/rules/lit-best-practices.mdc +0 -89
  15. package/.editorconfig +0 -29
  16. package/.github/CONTRIBUTING.md +0 -24
  17. package/.github/instructions/html-and-css-best-practices.instructions.md +0 -70
  18. package/.github/instructions/lit-best-practices.instructions.md +0 -90
  19. package/.github/release.yml +0 -14
  20. package/.github/stale.yml +0 -23
  21. package/.github/workflows/auto-release.yml +0 -182
  22. package/.github/workflows/release.yml +0 -82
  23. package/.prettierrc.js +0 -14
  24. package/.vscode/settings.json +0 -18
  25. package/RELEASE.md +0 -163
  26. package/RELEASE_SETUP.md +0 -235
  27. package/build/src/demo/DemoPage.d.ts +0 -81
  28. package/build/src/demo/DemoPage.d.ts.map +0 -1
  29. package/build/src/demo/DemoPage.js +0 -175
  30. package/build/src/demo/DemoPage.js.map +0 -1
  31. package/build/src/demo/DemoStyles.d.ts +0 -3
  32. package/build/src/demo/DemoStyles.d.ts.map +0 -1
  33. package/build/src/demo/DemoStyles.js +0 -60
  34. package/build/src/demo/DemoStyles.js.map +0 -1
  35. package/build/src/elements/contextual-menu/internals/ContextualMenu.d.ts.map +0 -1
  36. package/build/src/elements/contextual-menu/internals/ContextualMenu.js.map +0 -1
  37. package/build/test/elements/navigation/Navigation.test.d.ts +0 -3
  38. package/build/test/elements/navigation/Navigation.test.d.ts.map +0 -1
  39. package/build/test/elements/navigation/Navigation.test.js +0 -113
  40. package/build/test/elements/navigation/Navigation.test.js.map +0 -1
  41. package/commitlint.config.cjs +0 -2
  42. package/demo/elements/authorization/AuthPlugin.js +0 -57
  43. package/demo/elements/authorization/AuthProxy.js +0 -215
  44. package/demo/elements/authorization/api-key.html +0 -27
  45. package/demo/elements/authorization/api-key.ts +0 -44
  46. package/demo/elements/authorization/basic.html +0 -27
  47. package/demo/elements/authorization/basic.ts +0 -43
  48. package/demo/elements/authorization/bearer.html +0 -27
  49. package/demo/elements/authorization/bearer.ts +0 -43
  50. package/demo/elements/authorization/env.js +0 -8
  51. package/demo/elements/authorization/index.html +0 -44
  52. package/demo/elements/authorization/ntlm.html +0 -27
  53. package/demo/elements/authorization/ntlm.ts +0 -43
  54. package/demo/elements/authorization/oauth-authorize.html +0 -75
  55. package/demo/elements/authorization/oauth-authorize.ts +0 -40
  56. package/demo/elements/authorization/oauth-error.html +0 -18
  57. package/demo/elements/authorization/oauth-error.ts +0 -10
  58. package/demo/elements/authorization/oauth-popup.html +0 -36
  59. package/demo/elements/authorization/oauth2.html +0 -27
  60. package/demo/elements/authorization/oauth2.ts +0 -100
  61. package/demo/elements/authorization/oidc.html +0 -27
  62. package/demo/elements/authorization/oidc.ts +0 -139
  63. package/demo/elements/authorization/private.crt +0 -31
  64. package/demo/elements/authorization/private.csr +0 -28
  65. package/demo/elements/authorization/private.key +0 -51
  66. package/demo/elements/authorization/private.pem +0 -31
  67. package/demo/elements/authorization/redirect.html +0 -20
  68. package/demo/elements/authorization/ssl-commands.sh +0 -30
  69. package/demo/elements/authorization/ssl.conf +0 -24
  70. package/demo/elements/autocomplete/index.html +0 -64
  71. package/demo/elements/autocomplete/index.ts +0 -171
  72. package/demo/elements/code-editor/CodeEditorDemo.ts +0 -173
  73. package/demo/elements/code-editor/index.html +0 -19
  74. package/demo/elements/context-menu/DemoIcons.ts +0 -21
  75. package/demo/elements/context-menu/basic.html +0 -25
  76. package/demo/elements/context-menu/basic.ts +0 -119
  77. package/demo/elements/context-menu/custom-data.html +0 -25
  78. package/demo/elements/context-menu/custom-data.ts +0 -62
  79. package/demo/elements/context-menu/demo.css +0 -28
  80. package/demo/elements/context-menu/enabled-state.html +0 -25
  81. package/demo/elements/context-menu/enabled-state.ts +0 -73
  82. package/demo/elements/context-menu/icons.html +0 -25
  83. package/demo/elements/context-menu/icons.ts +0 -64
  84. package/demo/elements/context-menu/index.html +0 -43
  85. package/demo/elements/context-menu/nested.html +0 -25
  86. package/demo/elements/context-menu/nestedt.ts +0 -152
  87. package/demo/elements/context-menu/no-execute.html +0 -25
  88. package/demo/elements/context-menu/no-execute.ts +0 -134
  89. package/demo/elements/context-menu/radio-menu.html +0 -25
  90. package/demo/elements/context-menu/radio-menu.ts +0 -83
  91. package/demo/elements/context-menu/separators.html +0 -25
  92. package/demo/elements/context-menu/separators.ts +0 -172
  93. package/demo/elements/currency/index.html +0 -91
  94. package/demo/elements/currency/index.ts +0 -352
  95. package/demo/elements/environment/environment-editor.html +0 -20
  96. package/demo/elements/environment/environment-editor.ts +0 -49
  97. package/demo/elements/environment/index.html +0 -33
  98. package/demo/elements/environment/server-editor.html +0 -20
  99. package/demo/elements/environment/server-editor.ts +0 -67
  100. package/demo/elements/environment/variables-editor.html +0 -20
  101. package/demo/elements/environment/variables-editor.ts +0 -94
  102. package/demo/elements/har/har-viewer.html +0 -20
  103. package/demo/elements/har/har-viewer.ts +0 -76
  104. package/demo/elements/har/har1.har +0 -3044
  105. package/demo/elements/har/har2.json +0 -439
  106. package/demo/elements/har/index.html +0 -26
  107. package/demo/elements/highlight/example.md +0 -27
  108. package/demo/elements/highlight/index.html +0 -31
  109. package/demo/elements/highlight/marked-highlight.html +0 -132
  110. package/demo/elements/highlight/marked-highlight.ts +0 -22
  111. package/demo/elements/highlight/prism-highlight.html +0 -62
  112. package/demo/elements/highlight/prism-highlight.ts +0 -17
  113. package/demo/elements/http/body-editor.html +0 -17
  114. package/demo/elements/http/body-editor.ts +0 -115
  115. package/demo/elements/http/headers.html +0 -17
  116. package/demo/elements/http/headers.ts +0 -59
  117. package/demo/elements/http/http-assertions.html +0 -20
  118. package/demo/elements/http/http-assertions.ts +0 -89
  119. package/demo/elements/http/http-flows.html +0 -23
  120. package/demo/elements/http/http-flows.ts +0 -89
  121. package/demo/elements/http/index.html +0 -45
  122. package/demo/elements/http/request-editor.html +0 -26
  123. package/demo/elements/http/request-editor.ts +0 -197
  124. package/demo/elements/http/request-log.html +0 -16
  125. package/demo/elements/http/request-log.ts +0 -136
  126. package/demo/elements/http/url-editing.html +0 -17
  127. package/demo/elements/http/url-editing.ts +0 -112
  128. package/demo/elements/icons/index.html +0 -81
  129. package/demo/elements/icons/index.ts +0 -52
  130. package/demo/elements/index.html +0 -72
  131. package/demo/elements/mention-textarea/index.html +0 -19
  132. package/demo/elements/mention-textarea/index.ts +0 -205
  133. package/demo/elements/navigation/navigation-item.html +0 -49
  134. package/demo/elements/navigation/navigation-item.ts +0 -131
  135. package/demo/elements/navigation/navigation.html +0 -20
  136. package/demo/elements/navigation/navigation.ts +0 -45
  137. package/demo/elements/project/index.html +0 -29
  138. package/demo/elements/project/project-run-report.html +0 -20
  139. package/demo/elements/project/project-run-report.ts +0 -132
  140. package/demo/elements/project/request-editor.html +0 -23
  141. package/demo/elements/project/request-editor.ts +0 -232
  142. package/demo/elements/user/user-avatar.html +0 -17
  143. package/demo/elements/user/user-avatar.ts +0 -60
  144. package/demo/env.js +0 -4
  145. package/demo/index.html +0 -34
  146. package/demo/layout/index.html +0 -94
  147. package/demo/layout/index.ts +0 -190
  148. package/demo/md/DemoStyles.ts +0 -61
  149. package/demo/md/UiDemoPage.ts +0 -6
  150. package/demo/md/buttons/button.html +0 -121
  151. package/demo/md/buttons/button.ts +0 -246
  152. package/demo/md/buttons/group.html +0 -36
  153. package/demo/md/buttons/group.ts +0 -171
  154. package/demo/md/checkbox/index.html +0 -39
  155. package/demo/md/checkbox/index.ts +0 -220
  156. package/demo/md/chip/chip.html +0 -70
  157. package/demo/md/chip/chip.ts +0 -219
  158. package/demo/md/chip/pawel6c9a.jpg +0 -0
  159. package/demo/md/collapse/CustomDetail.ts +0 -89
  160. package/demo/md/collapse/collapse.html +0 -21
  161. package/demo/md/collapse/collapse.ts +0 -78
  162. package/demo/md/date-picker/date-picker.ts +0 -336
  163. package/demo/md/date-picker/index.html +0 -171
  164. package/demo/md/dialog/confirm-dialog.html +0 -49
  165. package/demo/md/dialog/confirm-dialog.ts +0 -121
  166. package/demo/md/dialog/dialog.html +0 -25
  167. package/demo/md/dialog/dialog.ts +0 -468
  168. package/demo/md/dropdown-list/index.html +0 -31
  169. package/demo/md/dropdown-list/index.ts +0 -158
  170. package/demo/md/icon-button/index.html +0 -122
  171. package/demo/md/icon-button/index.ts +0 -132
  172. package/demo/md/index.html +0 -73
  173. package/demo/md/inputs/input.html +0 -73
  174. package/demo/md/inputs/input.ts +0 -278
  175. package/demo/md/inputs/radio.html +0 -39
  176. package/demo/md/inputs/radio.ts +0 -156
  177. package/demo/md/inputs/switch.html +0 -45
  178. package/demo/md/inputs/switch.ts +0 -144
  179. package/demo/md/list/list.html +0 -65
  180. package/demo/md/list/list.ts +0 -204
  181. package/demo/md/listbox/listbox.html +0 -31
  182. package/demo/md/listbox/listbox.ts +0 -27
  183. package/demo/md/menu/index.html +0 -19
  184. package/demo/md/menu/index.ts +0 -514
  185. package/demo/md/notification/snack.html +0 -21
  186. package/demo/md/notification/snack.ts +0 -70
  187. package/demo/md/progress/progress.html +0 -46
  188. package/demo/md/progress/progress.ts +0 -161
  189. package/demo/md/segmented-button/index.html +0 -21
  190. package/demo/md/segmented-button/index.ts +0 -55
  191. package/demo/md/select/index.html +0 -16
  192. package/demo/md/select/index.ts +0 -217
  193. package/demo/md/tabs/tabs.html +0 -40
  194. package/demo/md/tabs/tabs.ts +0 -214
  195. package/demo/oauth-popup.html +0 -36
  196. package/demo/page.css +0 -8
  197. package/demo/resources/calendar-month.png +0 -0
  198. package/demo/resources/favorite.png +0 -0
  199. package/demo/resources/fingerprint.png +0 -0
  200. package/demo/resources/home-work.png +0 -0
  201. package/demo/resources/mood.png +0 -0
  202. package/demo/resources/print.png +0 -0
  203. package/demo/resources/stars.png +0 -0
  204. package/demo/resources/theaters.png +0 -0
  205. package/demo/tsconfig.json +0 -4
  206. package/eslint.config.js +0 -97
  207. package/scripts/copy-assets.js +0 -21
  208. package/scripts/release.js +0 -66
  209. package/src/demo/DemoPage.ts +0 -169
  210. package/src/demo/DemoStyles.ts +0 -60
  211. package/test/README.md +0 -375
  212. package/test/contextual-menu/ContextMenu.test.ts +0 -760
  213. package/test/contextual-menu/ContextMenuElement.test.ts +0 -569
  214. package/test/core/activity.spec.ts +0 -413
  215. package/test/core/activity_manager.spec.ts +0 -544
  216. package/test/core/application.spec.ts +0 -218
  217. package/test/core/fragment.spec.ts +0 -565
  218. package/test/core/fragment_manager.spec.ts +0 -404
  219. package/test/core/live_data.spec.ts +0 -558
  220. package/test/core/renderer.spec.ts +0 -113
  221. package/test/dom-assertions.test.ts +0 -182
  222. package/test/elements/MonacoSetup.ts +0 -65
  223. package/test/elements/authorization/basic-method.test.ts +0 -177
  224. package/test/elements/authorization/bearer-method.test.ts +0 -143
  225. package/test/elements/authorization/ntlm-method.test.ts +0 -219
  226. package/test/elements/authorization/oauth2-client-credentials-method.test.ts +0 -334
  227. package/test/elements/authorization/oauth2-code-method.test.ts +0 -320
  228. package/test/elements/authorization/oauth2-custom-grant-method.test.ts +0 -255
  229. package/test/elements/authorization/oauth2-device-code-method.test.ts +0 -371
  230. package/test/elements/authorization/oauth2-implicit-method.test.ts +0 -407
  231. package/test/elements/authorization/oauth2-jwt-method.test.ts +0 -217
  232. package/test/elements/authorization/oauth2-password-method.test.ts +0 -275
  233. package/test/elements/authorization/openid-method.test.ts +0 -591
  234. package/test/elements/autocomplete/autocomplete-input.spec.ts +0 -646
  235. package/test/elements/code-editor/code-editor.accessibility.test.ts +0 -298
  236. package/test/elements/code-editor/code-editor.test.ts +0 -574
  237. package/test/elements/currency/CurrencyPicker.accessibility.test.ts +0 -328
  238. package/test/elements/currency/CurrencyPicker.core.test.ts +0 -318
  239. package/test/elements/currency/CurrencyPicker.integration.test.ts +0 -482
  240. package/test/elements/currency/CurrencyPicker.test.ts +0 -486
  241. package/test/elements/data-table/DataTable.browser.test.ts +0 -649
  242. package/test/elements/har/HarUtils.test.ts +0 -45
  243. package/test/elements/har/HarViewerElement.test.ts +0 -687
  244. package/test/elements/har/test-data/har1.har +0 -3044
  245. package/test/elements/highlight/MarkedHighlightElement.test.ts +0 -452
  246. package/test/elements/highlight/PrismHighlightElement.test.ts +0 -79
  247. package/test/elements/highlight/PrismHighlighter.test.ts +0 -94
  248. package/test/elements/highlight/remoteSanitization.md +0 -1
  249. package/test/elements/highlight/test.md +0 -3
  250. package/test/elements/highlight/test1.md +0 -3
  251. package/test/elements/highlight/test2.md +0 -1
  252. package/test/elements/http/BodyFormdataEditorElement.test.ts +0 -482
  253. package/test/elements/http/BodyMultipartEditorElement.test.ts +0 -658
  254. package/test/elements/http/BodyRawEditorElement.test.ts +0 -90
  255. package/test/elements/http/CertificateAdd.test.ts +0 -457
  256. package/test/elements/http/HttpAssertions.test.ts +0 -994
  257. package/test/elements/http/HttpFlows.test.ts +0 -502
  258. package/test/elements/http/UrlEncodeUtils.test.ts +0 -202
  259. package/test/elements/layout/SplitItem.test.ts +0 -440
  260. package/test/elements/layout/SplitLayoutManager.test.ts +0 -1501
  261. package/test/elements/layout/SplitPanel.test.ts +0 -1109
  262. package/test/elements/mention-textarea/MentionTextArea.basic.test.ts +0 -114
  263. package/test/elements/mention-textarea/MentionTextArea.test.ts +0 -613
  264. package/test/elements/navigation/Navigation.test.ts +0 -120
  265. package/test/env.ts +0 -15
  266. package/test/events/EventTypes.test.ts +0 -363
  267. package/test/events/EventsTestHelpers.ts +0 -16
  268. package/test/helpers/TestUtils.ts +0 -243
  269. package/test/helpers/UiMock.ts +0 -185
  270. package/test/lib/Dom.test.ts +0 -231
  271. package/test/md/button/UiButton.test.ts +0 -347
  272. package/test/md/button/UiIconButton.test.ts +0 -155
  273. package/test/md/chip/UiChip.test.ts +0 -219
  274. package/test/md/collapse/UiCollapse.test.ts +0 -250
  275. package/test/md/collapse/flex-layout.test.ts +0 -105
  276. package/test/md/date-time/DateTime.test.ts +0 -348
  277. package/test/md/dialog/UiConfirmDialog.test.ts +0 -131
  278. package/test/md/dialog/UiDialog.test.ts +0 -759
  279. package/test/md/menu/Menu.test.ts +0 -855
  280. package/test/md/menu/MenuIntegration.test.ts +0 -426
  281. package/test/md/menu/MenuItem.test.ts +0 -652
  282. package/test/md/menu/SubMenu.test.ts +0 -410
  283. package/test/md/progress/UiCircularProgressElement.test.ts +0 -481
  284. package/test/md/progress/UiProgressElement.test.ts +0 -117
  285. package/test/md/progress/UiRangeElement.test.ts +0 -156
  286. package/test/md/select/Select.test.ts +0 -925
  287. package/test/plugins/takeScreenshotPlugin.js +0 -35
  288. package/test/setup.test.ts +0 -217
  289. package/test/setup.ts +0 -117
  290. package/test/tsconfig.json +0 -7
  291. package/web-dev-server.config.js +0 -21
  292. package/web-test-runner.config.js +0 -90
@@ -1,760 +0,0 @@
1
- import { html, fixture, assert, nextFrame, aTimeout } from '@open-wc/testing'
2
- import sinon from 'sinon'
3
- import { ContextualMenu } from '../../src/elements/contextual-menu/internals/ContextualMenu.js'
4
- import {
5
- ContextMenuCommand,
6
- EnabledMenuOptions,
7
- CommandExecuteOptions,
8
- } from '../../src/elements/contextual-menu/internals/types.js'
9
-
10
- import '../../src/elements/contextual-menu/contextual-menu.js'
11
-
12
- const commands = [
13
- {
14
- target: 'all',
15
- label: 'test',
16
- title: 'test-title',
17
- execute: (): void => {
18
- // ..
19
- },
20
- },
21
- {
22
- target: 'all',
23
- label: 'disabled',
24
- title: 'disabled-title',
25
- enabled: false,
26
- execute: (): void => {
27
- // ..
28
- },
29
- },
30
- {
31
- target: 'target',
32
- label: 'Target only',
33
- title: 'test title',
34
- execute: (): void => {
35
- // console.log(args);
36
- },
37
- },
38
- {
39
- target: 'custom',
40
- label: 'Custom only',
41
- title: 'custom title',
42
- execute: (): void => {
43
- // console.log(args);
44
- },
45
- },
46
- {
47
- target: 'all',
48
- label: 'visible',
49
- title: 'visible-title',
50
- visible: (): boolean => false,
51
- execute: (): void => {
52
- // ..
53
- },
54
- },
55
- ]
56
-
57
- describe('ContextualMenu', () => {
58
- describe('constructor()', () => {
59
- let workspace: HTMLDivElement
60
- beforeEach(async () => {
61
- workspace = await fixture(html`<div></div>`)
62
- })
63
-
64
- it('sets the "workspace" property', async () => {
65
- const menu = new ContextualMenu(workspace)
66
- assert.isTrue(menu.workspace === workspace)
67
- })
68
-
69
- it('initializes the store', async () => {
70
- const menu = new ContextualMenu(workspace)
71
- assert.typeOf(menu.store, 'object')
72
- })
73
-
74
- it('has empty commands', async () => {
75
- const menu = new ContextualMenu(workspace)
76
- assert.deepEqual(menu.commands, [])
77
- })
78
-
79
- it('is not "connected"', async () => {
80
- const menu = new ContextualMenu(workspace)
81
- assert.isFalse(menu.connected)
82
- })
83
-
84
- it('sets the default "options"', async () => {
85
- const menu = new ContextualMenu(workspace)
86
- assert.deepEqual(menu.options, {})
87
- })
88
-
89
- it('sets the passed "options"', async () => {
90
- const menu = new ContextualMenu(workspace, { cancelNativeWhenHandled: true })
91
- assert.deepEqual(menu.options, { cancelNativeWhenHandled: true })
92
- })
93
- })
94
-
95
- describe('elementToTarget()', () => {
96
- let workspace: HTMLDivElement
97
- let menu: ContextualMenu
98
- before(async () => {
99
- workspace = await fixture(html`<div></div>`)
100
- menu = new ContextualMenu(workspace)
101
- })
102
-
103
- it('returns "root" for the workspace', () => {
104
- const result = menu.elementToTarget(workspace)
105
- assert.equal(result, 'root')
106
- })
107
-
108
- it('returns the local name of the element only', () => {
109
- const node = document.createElement('div')
110
- const result = menu.elementToTarget(node)
111
- assert.equal(result, 'div')
112
- })
113
-
114
- it('returns the local name and the classes', () => {
115
- const node = document.createElement('div')
116
- node.className = 'a b c'
117
- const result = menu.elementToTarget(node)
118
- assert.equal(result, 'div.a.b.c')
119
- })
120
-
121
- it('ignores non-elements', () => {
122
- const node = document.createTextNode('test')
123
- // @ts-expect-error Testing invalid types
124
- const result = menu.elementToTarget(node)
125
- assert.isUndefined(result)
126
- })
127
- })
128
-
129
- describe('triggering the menu', () => {
130
- let workspace: HTMLDivElement
131
- let menu: ContextualMenu
132
- beforeEach(async () => {
133
- workspace = await fixture(html`<div><span></span></div>`)
134
- menu = new ContextualMenu(workspace)
135
- menu.connect()
136
- })
137
-
138
- afterEach(() => {
139
- menu.disconnect()
140
- })
141
-
142
- it('adds the menu on the root click', () => {
143
- const [cmd] = commands
144
- menu.registerCommands([cmd])
145
- workspace.dispatchEvent(
146
- new MouseEvent('contextmenu', {
147
- clientX: 1,
148
- clientY: 1,
149
- })
150
- )
151
- const instance = workspace.querySelector('.context-menu')
152
- assert.ok(instance)
153
- })
154
-
155
- it('does not add the menu when no commands', () => {
156
- workspace.dispatchEvent(
157
- new MouseEvent('contextmenu', {
158
- clientX: 1,
159
- clientY: 1,
160
- })
161
- )
162
- const instance = workspace.querySelector('.context-menu')
163
- assert.notOk(instance)
164
- })
165
-
166
- it('does not add the menu when no target', () => {
167
- const cmd = commands[2]
168
- menu.registerCommands([cmd])
169
- workspace.dispatchEvent(
170
- new MouseEvent('contextmenu', {
171
- clientX: 1,
172
- clientY: 1,
173
- })
174
- )
175
- const instance = workspace.querySelector('.context-menu')
176
- assert.notOk(instance)
177
- })
178
-
179
- it('renders menu for a target', () => {
180
- menu.registerCommands([...commands])
181
- menu.elementToTarget = (): string => 'target'
182
- const span = workspace.querySelector('span')!
183
- span.dispatchEvent(
184
- new MouseEvent('contextmenu', {
185
- clientX: 1,
186
- clientY: 1,
187
- bubbles: true,
188
- cancelable: true,
189
- })
190
- )
191
- const instance = workspace.querySelector('.context-menu')
192
- assert.ok(instance)
193
- })
194
-
195
- it('has all target commands', async () => {
196
- menu.registerCommands([...commands])
197
- menu.elementToTarget = (): string => 'target'
198
- const span = workspace.querySelector('span')!
199
- span.dispatchEvent(
200
- new MouseEvent('contextmenu', {
201
- clientX: 1,
202
- clientY: 1,
203
- bubbles: true,
204
- cancelable: true,
205
- })
206
- )
207
- await nextFrame()
208
- const menuElement = workspace.querySelector('contextual-menu')!
209
- const instances = menuElement.shadowRoot!.querySelectorAll(':host > *')
210
- assert.lengthOf(instances, 4)
211
- })
212
-
213
- it('cancels the native event', () => {
214
- menu.registerCommands([...commands])
215
- menu.elementToTarget = (): string => 'target'
216
- const span = workspace.querySelector('span')!
217
- const e = new MouseEvent('contextmenu', {
218
- clientX: 1,
219
- clientY: 1,
220
- bubbles: true,
221
- cancelable: true,
222
- })
223
- span.dispatchEvent(e)
224
- assert.isTrue(e.defaultPrevented)
225
- })
226
-
227
- it('cancels the native event with cancelNativeWhenHandled', () => {
228
- menu.registerCommands([...commands])
229
- menu.elementToTarget = (): string => 'target'
230
- menu.options.cancelNativeWhenHandled = true
231
- const span = workspace.querySelector('span')!
232
- const e = new MouseEvent('contextmenu', {
233
- clientX: 1,
234
- clientY: 1,
235
- bubbles: true,
236
- cancelable: true,
237
- })
238
- span.dispatchEvent(e)
239
- assert.isTrue(e.defaultPrevented)
240
- })
241
-
242
- it('does not cancel the native event with cancelNativeWhenHandled', () => {
243
- const [cmd] = commands
244
- menu.registerCommands([cmd])
245
- menu.elementToTarget = (): string | undefined => undefined
246
- menu.options.cancelNativeWhenHandled = true
247
- const span = workspace.querySelector('span')!
248
- const e = new MouseEvent('contextmenu', {
249
- clientX: 1,
250
- clientY: 1,
251
- bubbles: true,
252
- cancelable: true,
253
- })
254
- span.dispatchEvent(e)
255
- assert.isFalse(e.defaultPrevented)
256
- })
257
- })
258
-
259
- describe('disabled command', () => {
260
- let workspace: HTMLDivElement
261
- let menu: ContextualMenu
262
- beforeEach(async () => {
263
- workspace = await fixture(html`<div></div>`)
264
- menu = new ContextualMenu(workspace)
265
- menu.connect()
266
- })
267
-
268
- it('renders command disabled', async () => {
269
- menu.registerCommands([...commands])
270
- workspace.dispatchEvent(
271
- new MouseEvent('contextmenu', {
272
- clientX: 1,
273
- clientY: 1,
274
- })
275
- )
276
- await nextFrame()
277
- const menuElement = workspace.querySelector('contextual-menu')!
278
- const item = menuElement.shadowRoot!.querySelector('.disabled')!
279
- assert.isTrue(item.classList.contains('disabled'))
280
- })
281
- })
282
-
283
- describe('visible command', () => {
284
- let workspace: HTMLDivElement
285
- let menu: ContextualMenu
286
- beforeEach(async () => {
287
- workspace = await fixture(html`<div></div>`)
288
- menu = new ContextualMenu(workspace)
289
- menu.connect()
290
- })
291
-
292
- it('renders command hidden', async () => {
293
- menu.registerCommands([...commands])
294
- workspace.dispatchEvent(
295
- new MouseEvent('contextmenu', {
296
- clientX: 1,
297
- clientY: 1,
298
- })
299
- )
300
- await nextFrame()
301
- const menuElement = workspace.querySelector('contextual-menu')!
302
- const item = menuElement.shadowRoot!.querySelector('.hidden')!
303
- assert.isTrue(item.hasAttribute('disabled'))
304
- })
305
- })
306
-
307
- describe('triggering the menu from the custom event', () => {
308
- let workspace: HTMLDivElement
309
- let menu: ContextualMenu
310
- beforeEach(async () => {
311
- workspace = await fixture(html`<div><span></span></div>`)
312
- menu = new ContextualMenu(workspace)
313
- menu.connect()
314
- menu.registerCommands(commands)
315
- })
316
-
317
- it('renders the menu with the default values', () => {
318
- workspace.dispatchEvent(
319
- new CustomEvent('custommenu', {
320
- detail: {
321
- name: 'custom',
322
- },
323
- })
324
- )
325
- const instance = workspace.querySelector('.context-menu')!
326
- assert.ok(instance)
327
- const styles = getComputedStyle(instance)
328
- assert.equal(styles.top, '0px', 'has default y position')
329
- assert.equal(styles.left, '0px', 'has default x position')
330
- })
331
-
332
- it('renders the menu with the passed coordinates', () => {
333
- workspace.dispatchEvent(
334
- new CustomEvent('custommenu', {
335
- detail: {
336
- name: 'custom',
337
- x: 20,
338
- y: 40,
339
- },
340
- })
341
- )
342
- const instance = workspace.querySelector('.context-menu')!
343
- const styles = getComputedStyle(instance)
344
- assert.equal(styles.top, '40px', 'has default y position')
345
- assert.equal(styles.left, '20px', 'has default x position')
346
- })
347
-
348
- it('passes the custom data to the execute function', async () => {
349
- const customData = {
350
- test: true,
351
- }
352
- let args: CommandExecuteOptions | undefined
353
- const cmd: ContextMenuCommand = {
354
- target: 'custom',
355
- label: 'Custom 2',
356
- execute: (arg: CommandExecuteOptions): void => {
357
- args = arg
358
- },
359
- }
360
- menu.addCommand(cmd)
361
- workspace.dispatchEvent(
362
- new CustomEvent('custommenu', {
363
- detail: {
364
- name: 'custom',
365
- customData,
366
- },
367
- })
368
- )
369
- await nextFrame()
370
- const menuElement = workspace.querySelector('contextual-menu')!
371
- const items = menuElement.shadowRoot!.querySelectorAll('ui-list-item')
372
- const item = items[items.length - 1] as HTMLElement
373
- item.click()
374
- await nextFrame()
375
- assert.deepEqual(args?.customData, customData)
376
- })
377
-
378
- it('passes the custom data to the enabled function', async () => {
379
- const customData = {
380
- test: true,
381
- }
382
- let args: EnabledMenuOptions | undefined
383
- const cmd: ContextMenuCommand = {
384
- target: 'custom',
385
- label: 'Custom 2',
386
- execute: (): void => {
387
- // ...
388
- },
389
- enabled: (arg: EnabledMenuOptions): boolean => {
390
- args = arg
391
- return true
392
- },
393
- }
394
- menu.addCommand(cmd)
395
- workspace.dispatchEvent(
396
- new CustomEvent('custommenu', {
397
- detail: {
398
- name: 'custom',
399
- customData,
400
- },
401
- })
402
- )
403
- await nextFrame()
404
- const menuElement = workspace.querySelector('contextual-menu')!
405
- const items = menuElement.shadowRoot!.querySelectorAll('ui-list-item')!
406
- const item = items[3] as HTMLElement
407
- item.click()
408
- await nextFrame()
409
- assert.deepEqual(args?.customData, customData)
410
- })
411
- })
412
-
413
- describe('closing the menu via click', () => {
414
- let workspace: HTMLDivElement
415
- let menu: ContextualMenu
416
- beforeEach(async () => {
417
- workspace = await fixture(html`<div><span></span></div>`)
418
- menu = new ContextualMenu(workspace)
419
- menu.registerCommands(commands)
420
- menu.connect()
421
- workspace.dispatchEvent(
422
- new CustomEvent('custommenu', {
423
- detail: {
424
- name: 'custom',
425
- x: 1,
426
- y: 1,
427
- },
428
- })
429
- )
430
- await nextFrame()
431
- assert.ok(menu.currentMenu, 'has the menu')
432
- })
433
-
434
- it('destroys the menu when clicking outside the menu', () => {
435
- document.body.click()
436
- assert.isUndefined(menu.currentMenu)
437
- })
438
-
439
- it('ignores when clicking inside the menu', () => {
440
- const menuElement = workspace.querySelector('contextual-menu')!
441
- menuElement.click()
442
- assert.ok(menu.currentMenu)
443
- })
444
-
445
- it('ignores when menu does not exist', () => {
446
- menu.destroy()
447
- document.body.click()
448
- assert.isUndefined(menu.currentMenu)
449
- })
450
- })
451
-
452
- describe('closing the menu via keyboard events', () => {
453
- let workspace: HTMLDivElement
454
- let menu: ContextualMenu
455
- beforeEach(async () => {
456
- workspace = await fixture(html`<div><span></span></div>`)
457
- menu = new ContextualMenu(workspace)
458
- menu.registerCommands(commands)
459
- menu.connect()
460
- workspace.dispatchEvent(
461
- new CustomEvent('custommenu', {
462
- detail: {
463
- name: 'custom',
464
- x: 1,
465
- y: 1,
466
- },
467
- })
468
- )
469
- await nextFrame()
470
- assert.ok(menu.currentMenu, 'has the menu')
471
- })
472
-
473
- it('destroys the menu when Escape key', () => {
474
- document.body.dispatchEvent(
475
- new KeyboardEvent('keydown', {
476
- bubbles: true,
477
- composed: true,
478
- key: 'Escape',
479
- })
480
- )
481
- assert.isUndefined(menu.currentMenu)
482
- })
483
-
484
- it('ignores other keys', () => {
485
- document.body.dispatchEvent(
486
- new KeyboardEvent('keydown', {
487
- bubbles: true,
488
- composed: true,
489
- key: 'Enter',
490
- })
491
- )
492
- assert.ok(menu.currentMenu)
493
- })
494
-
495
- it('ignores when no menu', () => {
496
- menu.destroy()
497
- document.body.dispatchEvent(
498
- new KeyboardEvent('keydown', {
499
- bubbles: true,
500
- composed: true,
501
- key: 'Escape',
502
- })
503
- )
504
- assert.isUndefined(menu.currentMenu)
505
- })
506
- })
507
-
508
- describe('nested commands', () => {
509
- const nested: ContextMenuCommand[] = [
510
- {
511
- target: 'root',
512
- label: 'Font size',
513
- id: 'font-size',
514
- children: [
515
- {
516
- label: '0.75 rem',
517
- id: '0.75rem',
518
- },
519
- {
520
- label: '1 rem',
521
- id: '1rem',
522
- },
523
- {
524
- label: '1.25 rem',
525
- id: '1.25rem',
526
- },
527
- {
528
- label: '1.5 rem',
529
- id: '1.5rem',
530
- },
531
- {
532
- label: '2 rem',
533
- id: '2rem',
534
- },
535
- ],
536
- },
537
- ]
538
-
539
- let workspace: HTMLDivElement
540
- let menu: ContextualMenu
541
- beforeEach(async () => {
542
- workspace = await fixture(html`<div><span></span></div>`)
543
- menu = new ContextualMenu(workspace)
544
- menu.registerCommands(nested)
545
- menu.connect()
546
- })
547
-
548
- it('processes child commands', () => {
549
- const [childItem] = menu.commands[0].children!
550
- assert.equal(childItem.constructor.name, 'MenuItem')
551
- })
552
-
553
- it('dispatches the "execute" event when no "execute" function in the commands chain', async () => {
554
- const spy = sinon.spy()
555
- menu.addEventListener('execute', spy)
556
- workspace.dispatchEvent(
557
- new MouseEvent('contextmenu', {
558
- clientX: 1,
559
- clientY: 1,
560
- })
561
- )
562
- await nextFrame()
563
-
564
- const item = menu.currentMenu!.shadowRoot!.querySelector(`ui-list-item[data-cmd="font-size"]`) as HTMLElement
565
- menu.currentMenu!.subMenuTimeout = 1
566
- item.dispatchEvent(
567
- new MouseEvent('mousemove', {
568
- bubbles: true,
569
- cancelable: true,
570
- composed: true,
571
- clientX: 0,
572
- clientY: 0,
573
- })
574
- )
575
- // for the menu debouncer
576
- await aTimeout(1)
577
- // for the menu to render
578
- await nextFrame()
579
-
580
- const sub = menu.currentMenu!.shadowRoot!.querySelector('contextual-menu')!
581
- const subItem = sub.shadowRoot!.querySelector(`ui-list-item`)!
582
- subItem.click()
583
- await nextFrame()
584
- assert.isTrue(spy.calledOnce, 'The event is dispatched')
585
- const { detail } = spy.args[0][0]
586
- assert.equal(detail.id, '0.75rem', 'has the id')
587
- assert.isTrue(detail.store === menu.store, 'has the store')
588
- assert.isTrue(detail.target === workspace, 'has the target')
589
- assert.isTrue(detail.root === workspace, 'has the root')
590
- assert.deepEqual(detail.clickPoint, { x: 1, y: 1 }, 'has the clickPoint')
591
- assert.equal(detail.selectedSubcommand, 0, 'has the selectedSubcommand')
592
- assert.isTrue(detail.item === sub.commands![0], 'has the item')
593
- })
594
-
595
- it('executes parent item "execute" function', async () => {
596
- let called = false
597
- let context: CommandExecuteOptions<unknown> | undefined
598
- menu.commands[0].execute = (ctx: CommandExecuteOptions<unknown>): void => {
599
- called = true
600
- context = ctx
601
- }
602
- workspace.dispatchEvent(
603
- new MouseEvent('contextmenu', {
604
- clientX: 1,
605
- clientY: 1,
606
- })
607
- )
608
- await nextFrame()
609
-
610
- const item = menu.currentMenu!.shadowRoot!.querySelector(`ui-list-item[data-cmd="font-size"]`) as HTMLElement
611
- menu.currentMenu!.subMenuTimeout = 1
612
- item.dispatchEvent(
613
- new MouseEvent('mousemove', {
614
- bubbles: true,
615
- cancelable: true,
616
- composed: true,
617
- clientX: 0,
618
- clientY: 0,
619
- })
620
- )
621
- // for the menu debouncer
622
- await aTimeout(1)
623
- // for the menu to render
624
- await nextFrame()
625
- const sub = menu.currentMenu!.shadowRoot!.querySelector('contextual-menu')!
626
- const subItem = sub.shadowRoot!.querySelector(`ui-list-item`)!
627
- subItem.click()
628
- await nextFrame()
629
- assert.isTrue(called, 'The function was called')
630
- assert.equal(context!.id, 'font-size', 'has the id')
631
- assert.isTrue(context!.store === menu.store, 'has the store')
632
- assert.isTrue(context!.target === workspace, 'has the target')
633
- assert.isTrue(context!.root === workspace, 'has the root')
634
- assert.deepEqual(context!.clickPoint, { x: 1, y: 1 }, 'has the clickPoint')
635
- assert.equal(context!.selectedSubcommand, 0, 'has the selectedSubcommand')
636
- assert.isTrue(context!.item === sub.commands![0], 'has the item')
637
- })
638
- })
639
-
640
- describe('the "execute" event', () => {
641
- let workspace: HTMLDivElement
642
- let menu: ContextualMenu
643
- beforeEach(async () => {
644
- workspace = await fixture(html`<div></div>`)
645
- menu = new ContextualMenu(workspace)
646
- menu.connect()
647
- })
648
-
649
- it('dispatches the event when no execute function', async () => {
650
- const spy = sinon.spy()
651
- menu.addEventListener('execute', spy)
652
- // @ts-expect-error For testing
653
- menu.registerCommands([{ label: 'test', target: 'all' }])
654
- workspace.dispatchEvent(
655
- new MouseEvent('contextmenu', {
656
- clientX: 1,
657
- clientY: 1,
658
- })
659
- )
660
- await nextFrame()
661
- const instance = menu.currentMenu!
662
- const item = instance.shadowRoot!.querySelector('ui-list-item') as HTMLElement
663
- item.click()
664
- await nextFrame()
665
- assert.isTrue(spy.called, 'the event is dispatched')
666
- })
667
- })
668
-
669
- describe('listCommands()', () => {
670
- let workspace: HTMLDivElement
671
- let target: HTMLDivElement
672
- let menu: ContextualMenu
673
- beforeEach(async () => {
674
- workspace = await fixture(html`<div></div>`)
675
- target = await fixture(html`<div class="container"><span class="label"></span></div>`)
676
- menu = new ContextualMenu(workspace)
677
- })
678
-
679
- it('list commands for "all" only', () => {
680
- menu.registerCommands([
681
- {
682
- target: 'all',
683
- id: '1',
684
- },
685
- {
686
- target: 'something',
687
- id: '2',
688
- },
689
- {
690
- target: 'all',
691
- id: '3',
692
- },
693
- ])
694
- const result = menu.listCommands('all', target)
695
- assert.lengthOf(result, 2, 'returns 2 items')
696
- assert.equal(result[0].id, '1', 'has the first item')
697
- assert.equal(result[1].id, '3', 'has the last item')
698
- })
699
-
700
- it('list commands for array target', () => {
701
- menu.registerCommands([
702
- {
703
- target: 'other',
704
- id: '1',
705
- },
706
- {
707
- target: ['something', 'other'],
708
- id: '2',
709
- },
710
- {
711
- target: 'other',
712
- id: '3',
713
- },
714
- ])
715
- const result = menu.listCommands('something', target)
716
- assert.lengthOf(result, 1, 'returns 1 item')
717
- assert.equal(result[0].id, '2', 'has the item')
718
- })
719
-
720
- it('returns specific target', () => {
721
- menu.registerCommands([
722
- {
723
- target: 'other',
724
- id: '1',
725
- },
726
- {
727
- target: 'something',
728
- id: '2',
729
- },
730
- {
731
- target: 'other',
732
- id: '3',
733
- },
734
- ])
735
- const result = menu.listCommands('something', target)
736
- assert.lengthOf(result, 1, 'returns 1 item')
737
- assert.equal(result[0].id, '2', 'has the item')
738
- })
739
-
740
- it('returns matched selector', () => {
741
- menu.registerCommands([
742
- {
743
- target: 'other',
744
- id: '1',
745
- },
746
- {
747
- target: 'div.container > span.label',
748
- id: '2',
749
- },
750
- {
751
- target: 'other',
752
- id: '3',
753
- },
754
- ])
755
- const result = menu.listCommands('something', target.children[0] as HTMLSpanElement)
756
- assert.lengthOf(result, 1, 'returns 1 item')
757
- assert.equal(result[0].id, '2', 'has the item')
758
- })
759
- })
760
- })