@frontify/guideline-blocks-settings 0.27.0 → 0.28.0
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.
- package/.eslintrc.js +1 -1
- package/CHANGELOG.md +15 -0
- package/README.md +24 -5
- package/package.json +46 -10
- package/postcss.config.js +8 -0
- package/setupTests.ts +13 -0
- package/src/components/Attachments/AttachmentItem.tsx +257 -0
- package/src/components/Attachments/Attachments.spec.ct.tsx +151 -0
- package/src/components/Attachments/Attachments.tsx +221 -0
- package/src/components/Attachments/index.ts +4 -0
- package/src/components/Attachments/types.ts +30 -0
- package/src/components/BlockInjectButton/BlockInjectButton.spec.ct.tsx +48 -0
- package/src/components/BlockInjectButton/BlockInjectButton.tsx +212 -0
- package/src/components/BlockInjectButton/index.ts +4 -0
- package/src/components/BlockInjectButton/types.ts +18 -0
- package/src/components/BlockItemWrapper/BlockItemWrapper.spec.ct.tsx +146 -0
- package/src/components/BlockItemWrapper/BlockItemWrapper.tsx +76 -0
- package/src/components/BlockItemWrapper/Toolbar.tsx +128 -0
- package/src/components/BlockItemWrapper/constants.ts +4 -0
- package/src/components/BlockItemWrapper/index.ts +5 -0
- package/src/components/BlockItemWrapper/types.ts +46 -0
- package/src/components/DownloadButton/DownloadButton.spec.ct.tsx +20 -0
- package/src/components/DownloadButton/DownloadButton.tsx +36 -0
- package/src/components/DownloadButton/index.ts +3 -0
- package/src/components/DownloadButton/types.ts +5 -0
- package/src/components/RichTextEditor/RichTextEditor.spec.ct.tsx +204 -0
- package/src/components/RichTextEditor/RichTextEditor.tsx +62 -0
- package/src/components/RichTextEditor/SerializedText.tsx +25 -0
- package/src/components/RichTextEditor/constants.ts +3 -0
- package/src/components/RichTextEditor/index.ts +6 -0
- package/src/components/RichTextEditor/pluginPresets/defaultPluginsWithLinkChooser.tsx +53 -0
- package/src/components/RichTextEditor/pluginPresets/index.ts +3 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/ButtonMarkupElement/ButtonMarkupElementNode.tsx +74 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/ButtonMarkupElement/index.ts +11 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/ButtonButton.tsx +20 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/ButtonToolbarButton.tsx +56 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/CustomFloatingButton.tsx +19 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/EditButtonModal/EditModal.tsx +42 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButton.tsx +37 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButtonEditButton.tsx +22 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/FloatingButtonUrlInput.tsx +30 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/InsertButtonModal/InsertButtonModal.tsx +81 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/InsertButtonModal/types.ts +13 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/InsertButtonModal/useInsertModal.ts +143 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/UnlinkButton.tsx +31 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/floatingButtonStore.ts +46 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/index.ts +12 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEdit.ts +113 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEnter.ts +21 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonEscape.ts +30 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useFloatingButtonInsert.ts +71 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/FloatingButton/useVirtualFloatingButton.ts +22 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/components/index.ts +3 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/createButtonPlugin.ts +116 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/index.ts +7 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/index.ts +8 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/insertButton.ts +17 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/submitFloatingButton.ts +40 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/unwrapButton.ts +68 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/upsertButton.ts +198 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/upsertButtonText.ts +40 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/transforms/wrapButton.ts +30 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/types.ts +13 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/createButtonNode.ts +28 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/getButtonStyle.ts +14 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/getUrl.ts +18 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/index.ts +8 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/styles.ts +77 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButton.ts +23 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButtonEdit.ts +30 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/utils/triggerFloatingButtonInsert.ts +45 -0
- package/src/components/RichTextEditor/plugins/ButtonPlugin/withButton.ts +106 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/CustomFloatingLink.tsx +26 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/EditModal.tsx +43 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/index.ts +4 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/EditLinkModal/useFloatingLinkEdit.ts +113 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/FloatingLink.tsx +45 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/InsertLinkModal.tsx +5 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/InsertModal.tsx +105 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/index.ts +4 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/types.ts +16 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/useFloatingLinkInsert.ts +73 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/FloatingLink/InsertLinkModal/useInsertModal.ts +136 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/LinkButton.tsx +38 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/LinkMarkupElement/LinkMarkupElementNode.tsx +36 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/LinkMarkupElement/index.ts +11 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/id.ts +3 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/index.ts +48 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/types.ts +12 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/getUrl.ts +30 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/index.ts +4 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/relativeUrlRegex.spec.ts +35 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/relativeUrlRegex.ts +3 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/url.spec.ts +75 -0
- package/src/components/RichTextEditor/plugins/LinkPlugin/utils/url.ts +21 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/custom1Plugin.tsx +61 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/custom2Plugin.tsx +61 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/custom3Plugin.tsx +62 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/heading1Plugin.tsx +61 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/heading2Plugin.tsx +58 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/heading3Plugin.tsx +58 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/heading4Plugin.tsx +59 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/helpers.tsx +44 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/imageCaptionPlugin.tsx +61 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/imageTitlePlugin.tsx +61 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/index.ts +15 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/paragraphPlugin.tsx +58 -0
- package/src/components/RichTextEditor/plugins/TextStylePlugins/quotePlugin.tsx +62 -0
- package/src/components/RichTextEditor/plugins/index.ts +6 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/DocumentLink.tsx +80 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/DocumentLinks.tsx +97 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/LinkSelector.spec.ct.tsx +138 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/LinkSelector.tsx +80 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/PageLink.tsx +83 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/PageLinks.tsx +68 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/SectionLink.tsx +37 -0
- package/src/components/RichTextEditor/plugins/shared/LinkSelector/index.ts +3 -0
- package/src/components/RichTextEditor/plugins/styles.ts +179 -0
- package/src/components/RichTextEditor/serializer/index.ts +3 -0
- package/src/components/RichTextEditor/serializer/nodes/button.ts +25 -0
- package/src/components/RichTextEditor/serializer/nodes/checkItemNode.ts +29 -0
- package/src/components/RichTextEditor/serializer/nodes/default.ts +52 -0
- package/src/components/RichTextEditor/serializer/nodes/link.ts +25 -0
- package/src/components/RichTextEditor/serializer/nodes/mentionHtmlNode.ts +17 -0
- package/src/components/RichTextEditor/serializer/serializeNodesToHtmlRecursive.ts +134 -0
- package/src/components/RichTextEditor/serializer/serializeToHtml.ts +49 -0
- package/src/components/RichTextEditor/serializer/utlis/reactCssPropsToCss.ts +21 -0
- package/src/components/RichTextEditor/serializer/utlis/serializeLeafToHtml.ts +32 -0
- package/src/components/RichTextEditor/types.ts +23 -0
- package/src/components/index.ts +7 -0
- package/src/helpers/addHttps.spec.ts +42 -0
- package/src/helpers/addHttps.ts +15 -0
- package/src/helpers/convertToRichTextValue.spec.ts +32 -0
- package/src/helpers/convertToRichTextValue.ts +6 -0
- package/src/helpers/customCoordinatesGetterFactory.spec.ts +69 -0
- package/src/helpers/customCoordinatesGetterFactory.ts +39 -0
- package/src/helpers/hasRichTextValue.spec.ts +63 -0
- package/src/helpers/hasRichTextValue.ts +29 -0
- package/src/helpers/index.ts +8 -0
- package/src/helpers/isDownloadable.spec.ts +47 -0
- package/src/helpers/isDownloadable.ts +7 -0
- package/src/helpers/mapColorPalettes.spec.ts +146 -0
- package/src/helpers/mapColorPalettes.ts +22 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useAttachments.spec.ts +79 -0
- package/src/hooks/useAttachments.ts +46 -0
- package/src/hooks/useDndSensors.spec.ts +40 -0
- package/src/hooks/useDndSensors.ts +23 -0
- package/src/index.ts +8 -0
- package/src/settings/background.spec.ts +173 -0
- package/src/settings/background.ts +49 -0
- package/src/settings/border.spec.ts +76 -0
- package/src/settings/border.ts +90 -0
- package/src/settings/borderRadius.spec.ts +30 -0
- package/src/settings/borderRadius.ts +73 -0
- package/src/settings/borderRadiusExtended.spec.ts +52 -0
- package/src/settings/borderRadiusExtended.ts +84 -0
- package/src/settings/defaultValues.ts +21 -0
- package/src/settings/gutter.spec.ts +60 -0
- package/src/settings/gutter.ts +75 -0
- package/src/settings/index.ts +14 -0
- package/src/settings/margin.spec.ts +42 -0
- package/src/settings/margin.ts +72 -0
- package/src/settings/marginExtended.spec.ts +45 -0
- package/src/settings/marginExtended.ts +91 -0
- package/src/settings/padding.spec.ts +42 -0
- package/src/settings/padding.ts +73 -0
- package/src/settings/paddingExtended.spec.ts +45 -0
- package/src/settings/paddingExtended.ts +91 -0
- package/src/settings/security.spec.ts +87 -0
- package/src/settings/security.ts +61 -0
- package/src/settings/securityDownloadable.spec.ts +46 -0
- package/src/settings/securityDownloadable.ts +33 -0
- package/src/settings/securityGlobalControl.ts +42 -0
- package/src/settings/types.ts +128 -0
- package/src/utilities/color/getReadableColor.spec.ts +32 -0
- package/src/utilities/color/getReadableColor.ts +34 -0
- package/src/utilities/color/index.ts +10 -0
- package/src/utilities/color/isDark.spec.ts +33 -0
- package/src/utilities/color/isDark.ts +29 -0
- package/src/utilities/color/setAlpha.spec.ts +28 -0
- package/src/utilities/color/setAlpha.ts +14 -0
- package/src/utilities/color/toColorObject.spec.ts +19 -0
- package/src/utilities/color/toColorObject.ts +16 -0
- package/src/utilities/color/toHex8String.spec.ts +17 -0
- package/src/utilities/color/toHex8String.ts +14 -0
- package/src/utilities/color/toHexString.spec.ts +17 -0
- package/src/utilities/color/toHexString.ts +10 -0
- package/src/utilities/color/toRgbaString.spec.ts +12 -0
- package/src/utilities/color/toRgbaString.ts +14 -0
- package/src/utilities/color/toShortRgba.spec.ts +16 -0
- package/src/utilities/color/toShortRgba.ts +35 -0
- package/src/utilities/index.ts +5 -0
- package/src/utilities/moveItemInArray.spec.ts +17 -0
- package/src/utilities/moveItemInArray.ts +21 -0
- package/src/utilities/react/getBackgroundColorStyles.spec.ts +18 -0
- package/src/utilities/react/getBackgroundColorStyles.ts +11 -0
- package/src/utilities/react/getBorderStyles.spec.ts +39 -0
- package/src/utilities/react/getBorderStyles.ts +21 -0
- package/src/utilities/react/getRadiusStyles.spec.ts +25 -0
- package/src/utilities/react/getRadiusStyles.ts +8 -0
- package/src/utilities/react/index.ts +6 -0
- package/src/utilities/react/joinClassNames.spec.ts +18 -0
- package/src/utilities/react/joinClassNames.ts +10 -0
- package/tailwind.config.js +27 -0
- package/tsconfig.json +3 -1
- package/vite.config.ts +11 -1
- package/dist/index.cjs.js +0 -2
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.d.ts +0 -147
- package/dist/index.es.js +0 -9
- package/dist/index.es.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
package/.eslintrc.js
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @frontify/guideline-blocks-settings
|
|
2
2
|
|
|
3
|
+
## 0.28.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#453](https://github.com/Frontify/brand-sdk/pull/453) [`0807349`](https://github.com/Frontify/brand-sdk/commit/0807349856fe972953493c253ac8e4ce352d3ede) Thanks [@fulopdaniel](https://github.com/fulopdaniel)! - Added components, helpers and utilities to simplify Blocks development
|
|
8
|
+
|
|
9
|
+
- [#466](https://github.com/Frontify/brand-sdk/pull/466) [`9f81a23`](https://github.com/Frontify/brand-sdk/commit/9f81a2363cd3c842d0ac5c014e0b07c46a3a1cca) Thanks [@triggertoo](https://github.com/triggertoo)! - Remove downloadAsset helper since it's unrelated to the settings
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#482](https://github.com/Frontify/brand-sdk/pull/482) [`6b18a74`](https://github.com/Frontify/brand-sdk/commit/6b18a74794612f61bd2e34ea8fdd4572ebb5274e) Thanks [@fulopdaniel](https://github.com/fulopdaniel)! - feat(\*): update shared folder with latest changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`4105251`](https://github.com/Frontify/brand-sdk/commit/4105251969f8ae639014a013a2cbc88df8e4935d), [`af49f65`](https://github.com/Frontify/brand-sdk/commit/af49f6572592522a550f970c98e3d8fd2d377cc3)]:
|
|
16
|
+
- @frontify/sidebar-settings@0.6.0
|
|
17
|
+
|
|
3
18
|
## 0.27.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -7,10 +7,9 @@ Provides the block settings types for the guideline-blocks.
|
|
|
7
7
|
```ts
|
|
8
8
|
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
import { IconEnum } from '@frontify/fondue';
|
|
10
|
+
import { IconEnum, defineSettings } from '@frontify/guideline-blocks-settings';
|
|
12
11
|
|
|
13
|
-
export const settings
|
|
12
|
+
export const settings = defineSettings({
|
|
14
13
|
main: [
|
|
15
14
|
{
|
|
16
15
|
id: 'example',
|
|
@@ -29,7 +28,7 @@ export const settings: BlockSettings = {
|
|
|
29
28
|
label: 'Line',
|
|
30
29
|
},
|
|
31
30
|
],
|
|
32
|
-
onChange: (bundle
|
|
31
|
+
onChange: (bundle): void => {
|
|
33
32
|
const blockWidth = Number(bundle.getBlock('widthCustom')?.value);
|
|
34
33
|
if (!Number.isNaN(blockWidth)) {
|
|
35
34
|
bundle.setBlockValue('widthCustom', `${blockWidth}%`);
|
|
@@ -37,5 +36,25 @@ export const settings: BlockSettings = {
|
|
|
37
36
|
},
|
|
38
37
|
},
|
|
39
38
|
],
|
|
40
|
-
};
|
|
39
|
+
});
|
|
41
40
|
```
|
|
41
|
+
|
|
42
|
+
# Block development helpers
|
|
43
|
+
|
|
44
|
+
## Code Structure
|
|
45
|
+
|
|
46
|
+
- `components` (React components which are reused across multiple blocks)
|
|
47
|
+
- `utilities` (functionality without business logic)
|
|
48
|
+
- `helpers` (functionality with business logic)
|
|
49
|
+
|
|
50
|
+
## Using components
|
|
51
|
+
|
|
52
|
+
To use React components, you need to add the styles import from the `@frontify/guideline-blocks-settings` package:
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
import '@frontify/guideline-blocks-settings/styles';
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Development
|
|
59
|
+
|
|
60
|
+
Run `pnpm build` to make changes directly available to the linked packages.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frontify/guideline-blocks-settings",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "Provides types and helpers for the guideline block development",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "dist/index.umd.js",
|
|
@@ -14,22 +14,56 @@
|
|
|
14
14
|
"url": "https://github.com/Frontify/brand-sdk",
|
|
15
15
|
"directory": "packages/guideline-blocks-settings"
|
|
16
16
|
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": "./dist/index.es.js",
|
|
20
|
+
"require": "./dist/index.umd.js"
|
|
21
|
+
},
|
|
22
|
+
"./styles": "./dist/style.css"
|
|
23
|
+
},
|
|
17
24
|
"devDependencies": {
|
|
18
|
-
"@
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
21
|
-
"
|
|
25
|
+
"@babel/core": "^7.22.5",
|
|
26
|
+
"@frontify/eslint-config-typescript": "^0.15.8",
|
|
27
|
+
"@testing-library/react": "^14.0.0",
|
|
28
|
+
"@types/escape-html": "^1.0.2",
|
|
29
|
+
"@types/node": "^18.7.21",
|
|
30
|
+
"@types/react": "^18.2.14",
|
|
31
|
+
"@types/react-dom": "^18.2.6",
|
|
32
|
+
"@types/sinon": "^10.0.15",
|
|
33
|
+
"@vitejs/plugin-react": "^4.0.1",
|
|
34
|
+
"autoprefixer": "^10.4.14",
|
|
35
|
+
"cypress": "^12.16.0",
|
|
36
|
+
"cypress-real-events": "^1.8.1",
|
|
37
|
+
"eslint": "^8.43.0",
|
|
22
38
|
"eslint-plugin-notice": "^0.9.10",
|
|
39
|
+
"happy-dom": "^9.20.3",
|
|
40
|
+
"mitt": "^3.0.0",
|
|
41
|
+
"msw": "^1.2.2",
|
|
42
|
+
"postcss": "^8.4.24",
|
|
23
43
|
"prettier": "^2.8.8",
|
|
24
44
|
"react": "^18.2.0",
|
|
25
45
|
"react-dom": "^18.2.0",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
46
|
+
"sinon": "15.2.0",
|
|
47
|
+
"tailwindcss": "^3.3.2",
|
|
48
|
+
"typescript": "^5.1.5",
|
|
49
|
+
"vite": "^4.3.9",
|
|
50
|
+
"vite-plugin-dts": "^2.3.0",
|
|
51
|
+
"vitest": "^0.32.2"
|
|
29
52
|
},
|
|
30
53
|
"dependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
54
|
+
"@ctrl/tinycolor": "^3.6.0",
|
|
55
|
+
"@dnd-kit/core": "^6.0.8",
|
|
56
|
+
"@dnd-kit/modifiers": "^6.0.1",
|
|
57
|
+
"@dnd-kit/sortable": "^7.0.2",
|
|
58
|
+
"@frontify/fondue": "^12.0.0-beta.287",
|
|
59
|
+
"@react-aria/focus": "^3.13.0",
|
|
60
|
+
"@react-stately/overlays": "^3.6.0",
|
|
61
|
+
"@udecode/plate": "^21",
|
|
62
|
+
"escape-html": "^1.0.3",
|
|
63
|
+
"slate": "^0.94.1",
|
|
64
|
+
"slate-react": "^0.97.1",
|
|
65
|
+
"@frontify/app-bridge": "3.0.0-beta.86",
|
|
66
|
+
"@frontify/sidebar-settings": "0.6.0"
|
|
33
67
|
},
|
|
34
68
|
"peerDependencies": {
|
|
35
69
|
"react": "^18",
|
|
@@ -41,6 +75,8 @@
|
|
|
41
75
|
"lint:fix": "eslint --fix .",
|
|
42
76
|
"prettier": "prettier --check .",
|
|
43
77
|
"prettier:fix": "prettier --write .",
|
|
78
|
+
"test": "vitest run --silent",
|
|
79
|
+
"test:watch": "vitest",
|
|
44
80
|
"typecheck": "tsc --noEmit"
|
|
45
81
|
}
|
|
46
82
|
}
|
package/setupTests.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { afterEach, vi } from 'vitest';
|
|
4
|
+
|
|
5
|
+
vi.stubGlobal('crypto', {
|
|
6
|
+
getRandomValues: vi.fn(),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
vi.restoreAllMocks();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
globalThis.structuredClone = (data: unknown) => JSON.parse(JSON.stringify(data));
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { MutableRefObject, forwardRef, useEffect, useState } from 'react';
|
|
4
|
+
import { Asset, useAssetUpload, useFileInput } from '@frontify/app-bridge';
|
|
5
|
+
import { useSortable } from '@dnd-kit/sortable';
|
|
6
|
+
import { useFocusRing } from '@react-aria/focus';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
ActionMenu,
|
|
10
|
+
Button,
|
|
11
|
+
ButtonEmphasis,
|
|
12
|
+
FOCUS_STYLE,
|
|
13
|
+
Flyout,
|
|
14
|
+
FlyoutPlacement,
|
|
15
|
+
IconArrowCircleUp20,
|
|
16
|
+
IconDocument24,
|
|
17
|
+
IconGrabHandle20,
|
|
18
|
+
IconImage24,
|
|
19
|
+
IconImageStack20,
|
|
20
|
+
IconMusicNote24,
|
|
21
|
+
IconPen20,
|
|
22
|
+
IconPlayFrame24,
|
|
23
|
+
IconTrashBin20,
|
|
24
|
+
LoadingCircle,
|
|
25
|
+
LoadingCircleSize,
|
|
26
|
+
MenuItemContentSize,
|
|
27
|
+
MenuItemStyle,
|
|
28
|
+
} from '@frontify/fondue';
|
|
29
|
+
import { AttachmentItemProps, SortableAttachmentItemProps } from './types';
|
|
30
|
+
import { joinClassNames } from '../../utilities';
|
|
31
|
+
|
|
32
|
+
const getDecorator = (type: string) => {
|
|
33
|
+
if (type === 'IMAGE') {
|
|
34
|
+
return <IconImage24 />;
|
|
35
|
+
} else if (type === 'VIDEO') {
|
|
36
|
+
return <IconPlayFrame24 />;
|
|
37
|
+
} else if (type === 'AUDIO') {
|
|
38
|
+
return <IconMusicNote24 />;
|
|
39
|
+
} else {
|
|
40
|
+
return <IconDocument24 />;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const AttachmentItem = forwardRef<HTMLButtonElement, AttachmentItemProps>(
|
|
45
|
+
(
|
|
46
|
+
{
|
|
47
|
+
item,
|
|
48
|
+
isEditing,
|
|
49
|
+
draggableProps,
|
|
50
|
+
transformStyle,
|
|
51
|
+
isDragging,
|
|
52
|
+
isOverlay,
|
|
53
|
+
isLoading,
|
|
54
|
+
onDelete,
|
|
55
|
+
onReplaceWithBrowse,
|
|
56
|
+
onReplaceWithUpload,
|
|
57
|
+
},
|
|
58
|
+
ref
|
|
59
|
+
) => {
|
|
60
|
+
const [selectedAsset, setSelectedAsset] = useState<Asset | undefined>();
|
|
61
|
+
const [openFileDialog, { selectedFiles }] = useFileInput({ multiple: true, accept: 'image/*' });
|
|
62
|
+
const [uploadFile, { results: uploadResults, doneAll }] = useAssetUpload();
|
|
63
|
+
const { focusProps, isFocusVisible } = useFocusRing();
|
|
64
|
+
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (selectedFiles) {
|
|
67
|
+
uploadFile(selectedFiles[0]);
|
|
68
|
+
}
|
|
69
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
70
|
+
}, [selectedFiles]);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (doneAll) {
|
|
74
|
+
onReplaceWithUpload(uploadResults[0]);
|
|
75
|
+
}
|
|
76
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
|
+
}, [doneAll, uploadResults]);
|
|
78
|
+
|
|
79
|
+
const download = (url: string, filename: string) => {
|
|
80
|
+
fetch(url).then((response) => {
|
|
81
|
+
response.blob().then((blob) => {
|
|
82
|
+
const url = URL.createObjectURL(blob);
|
|
83
|
+
const a = document.createElement('a');
|
|
84
|
+
a.href = url;
|
|
85
|
+
a.download = filename;
|
|
86
|
+
a.click();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const showLoadingCircle = isLoading || (selectedFiles && !doneAll);
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<button
|
|
95
|
+
aria-label="Download attachment"
|
|
96
|
+
data-test-id="attachments-item"
|
|
97
|
+
onClick={() => download(item.genericUrl, item.fileName)}
|
|
98
|
+
ref={ref}
|
|
99
|
+
style={{
|
|
100
|
+
...transformStyle,
|
|
101
|
+
opacity: isDragging && !isOverlay ? 0.3 : 1,
|
|
102
|
+
fontFamily: 'var(-f-theme-settings-body-font-family)',
|
|
103
|
+
}}
|
|
104
|
+
className={joinClassNames([
|
|
105
|
+
'tw-cursor-pointer tw-text-left tw-w-full tw-relative tw-flex tw-gap-3 tw-px-5 tw-py-3 tw-items-center tw-group hover:tw-bg-box-neutral-hover',
|
|
106
|
+
isDragging ? 'tw-bg-box-neutral-hover' : '',
|
|
107
|
+
])}
|
|
108
|
+
>
|
|
109
|
+
<div className="tw-text-text-weak group-hover:tw-text-box-neutral-inverse-hover">
|
|
110
|
+
{showLoadingCircle ? (
|
|
111
|
+
<LoadingCircle size={LoadingCircleSize.Small} />
|
|
112
|
+
) : (
|
|
113
|
+
getDecorator(item.objectType)
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
<div className="tw-text-s tw-flex-1 tw-min-w-0">
|
|
117
|
+
<div className="tw-whitespace-nowrap tw-overflow-hidden tw-text-ellipsis tw-font-bold tw-text-text-weak group-hover:tw-text-box-neutral-inverse-hover">
|
|
118
|
+
{item.title}
|
|
119
|
+
</div>
|
|
120
|
+
<div className="tw-text-text-weak">{`${item.fileSizeHumanReadable} - ${item.extension}`}</div>
|
|
121
|
+
</div>
|
|
122
|
+
{isEditing && (
|
|
123
|
+
<div
|
|
124
|
+
data-test-id="attachments-actionbar"
|
|
125
|
+
className={joinClassNames([
|
|
126
|
+
'tw-flex tw-gap-0.5 group-focus:tw-opacity-100 focus-visible:tw-opacity-100 focus-within:tw-opacity-100 group-hover:tw-opacity-100',
|
|
127
|
+
isOverlay || selectedAsset?.id === item.id ? 'tw-opacity-100' : 'tw-opacity-0',
|
|
128
|
+
])}
|
|
129
|
+
>
|
|
130
|
+
<button
|
|
131
|
+
{...focusProps}
|
|
132
|
+
{...draggableProps}
|
|
133
|
+
aria-label="Drag attachment"
|
|
134
|
+
className={joinClassNames([
|
|
135
|
+
' tw-border-button-border tw-bg-button-background active:tw-bg-button-background-pressed tw-group tw-border tw-box-box tw-relative tw-flex tw-items-center tw-justify-center tw-outline-none tw-font-medium tw-rounded tw-h-9 tw-w-9 ',
|
|
136
|
+
isDragging || isOverlay
|
|
137
|
+
? 'tw-cursor-grabbing tw-bg-button-background-pressed hover:tw-bg-button-background-pressed'
|
|
138
|
+
: 'tw-cursor-grab hover:tw-bg-button-background-hover',
|
|
139
|
+
isFocusVisible && FOCUS_STYLE,
|
|
140
|
+
isFocusVisible && 'tw-z-[2]',
|
|
141
|
+
])}
|
|
142
|
+
>
|
|
143
|
+
<IconGrabHandle20 />
|
|
144
|
+
</button>
|
|
145
|
+
<div data-test-id="attachments-actionbar-flyout">
|
|
146
|
+
<Flyout
|
|
147
|
+
placement={FlyoutPlacement.Right}
|
|
148
|
+
isOpen={selectedAsset?.id === item.id}
|
|
149
|
+
fitContent
|
|
150
|
+
legacyFooter={false}
|
|
151
|
+
onOpenChange={(isOpen) => setSelectedAsset(isOpen ? item : undefined)}
|
|
152
|
+
trigger={(_, ref) => (
|
|
153
|
+
<Button
|
|
154
|
+
ref={ref as MutableRefObject<HTMLButtonElement>}
|
|
155
|
+
icon={<IconPen20 />}
|
|
156
|
+
emphasis={ButtonEmphasis.Default}
|
|
157
|
+
onClick={() => setSelectedAsset(item)}
|
|
158
|
+
/>
|
|
159
|
+
)}
|
|
160
|
+
>
|
|
161
|
+
<ActionMenu
|
|
162
|
+
menuBlocks={[
|
|
163
|
+
{
|
|
164
|
+
id: 'menu',
|
|
165
|
+
menuItems: [
|
|
166
|
+
{
|
|
167
|
+
id: 'upload',
|
|
168
|
+
size: MenuItemContentSize.XSmall,
|
|
169
|
+
title: 'Replace with upload',
|
|
170
|
+
onClick: () => {
|
|
171
|
+
openFileDialog();
|
|
172
|
+
setSelectedAsset(undefined);
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
initialValue: true,
|
|
176
|
+
decorator: (
|
|
177
|
+
<div className="tw-mr-2">
|
|
178
|
+
<IconArrowCircleUp20 />
|
|
179
|
+
</div>
|
|
180
|
+
),
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
{
|
|
184
|
+
id: 'asset',
|
|
185
|
+
size: MenuItemContentSize.XSmall,
|
|
186
|
+
title: 'Replace with asset',
|
|
187
|
+
onClick: () => {
|
|
188
|
+
onReplaceWithBrowse();
|
|
189
|
+
setSelectedAsset(undefined);
|
|
190
|
+
},
|
|
191
|
+
initialValue: true,
|
|
192
|
+
decorator: (
|
|
193
|
+
<div className="tw-mr-2">
|
|
194
|
+
<IconImageStack20 />
|
|
195
|
+
</div>
|
|
196
|
+
),
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
id: 'menu-delete',
|
|
202
|
+
menuItems: [
|
|
203
|
+
{
|
|
204
|
+
id: 'delete',
|
|
205
|
+
size: MenuItemContentSize.XSmall,
|
|
206
|
+
title: 'Delete',
|
|
207
|
+
style: MenuItemStyle.Danger,
|
|
208
|
+
onClick: () => {
|
|
209
|
+
onDelete();
|
|
210
|
+
setSelectedAsset(undefined);
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
initialValue: true,
|
|
214
|
+
decorator: (
|
|
215
|
+
<div className="tw-mr-2">
|
|
216
|
+
<IconTrashBin20 />
|
|
217
|
+
</div>
|
|
218
|
+
),
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
},
|
|
222
|
+
]}
|
|
223
|
+
/>
|
|
224
|
+
</Flyout>
|
|
225
|
+
</div>
|
|
226
|
+
</div>
|
|
227
|
+
)}
|
|
228
|
+
</button>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
AttachmentItem.displayName = 'AttachmentItem';
|
|
234
|
+
|
|
235
|
+
export const SortableAttachmentItem = (props: SortableAttachmentItemProps) => {
|
|
236
|
+
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
237
|
+
id: props.item.id,
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const transformStyle = {
|
|
241
|
+
transform: transform ? `translate(${transform.x}px, ${transform.y}px)` : '',
|
|
242
|
+
transition,
|
|
243
|
+
zIndex: isDragging ? 2 : 1,
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const draggableProps = { ...attributes, ...listeners };
|
|
247
|
+
|
|
248
|
+
return (
|
|
249
|
+
<AttachmentItem
|
|
250
|
+
ref={setNodeRef}
|
|
251
|
+
isDragging={isDragging}
|
|
252
|
+
transformStyle={transformStyle}
|
|
253
|
+
draggableProps={draggableProps}
|
|
254
|
+
{...props}
|
|
255
|
+
/>
|
|
256
|
+
);
|
|
257
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { AssetDummy, getAppBridgeBlockStub } from '@frontify/app-bridge';
|
|
4
|
+
import { mount } from 'cypress/react18';
|
|
5
|
+
import { Attachments as AttachmentsComponent } from './Attachments';
|
|
6
|
+
import { AttachmentsProps } from './types';
|
|
7
|
+
import { SinonStub } from 'cypress/types/sinon';
|
|
8
|
+
|
|
9
|
+
const FlyoutButtonSelector = '[data-test-id="attachments-flyout-button"]';
|
|
10
|
+
const AssetInputSelector = '[data-test-id="asset-input-placeholder"]';
|
|
11
|
+
const ActionBarSelector = '[data-test-id="attachments-actionbar"]';
|
|
12
|
+
const DragHandleSelector = '[data-test-id="attachments-actionbar"] > button';
|
|
13
|
+
const FlyoutTriggerSelector = '[data-test-id="attachments-actionbar-flyout"] button';
|
|
14
|
+
const AttachmentItemSelector = '[data-test-id="attachments-item"]';
|
|
15
|
+
const MenuItemSelector = '[data-test-id="menu-item"]';
|
|
16
|
+
const LoadingCircleSelector = '[data-test-id="loading-circle"]';
|
|
17
|
+
|
|
18
|
+
const Attachments = ({
|
|
19
|
+
appBridge = getAppBridgeBlockStub(),
|
|
20
|
+
onDelete = cy.stub(),
|
|
21
|
+
items,
|
|
22
|
+
onReplaceWithBrowse = cy.stub(),
|
|
23
|
+
onReplaceWithUpload = cy.stub(),
|
|
24
|
+
onSorted = cy.stub(),
|
|
25
|
+
onBrowse = cy.stub(),
|
|
26
|
+
onUpload = cy.stub(),
|
|
27
|
+
}: Partial<AttachmentsProps>) => {
|
|
28
|
+
return (
|
|
29
|
+
<AttachmentsComponent
|
|
30
|
+
appBridge={appBridge}
|
|
31
|
+
onDelete={onDelete}
|
|
32
|
+
items={items}
|
|
33
|
+
onReplaceWithBrowse={onReplaceWithBrowse}
|
|
34
|
+
onReplaceWithUpload={onReplaceWithUpload}
|
|
35
|
+
onSorted={onSorted}
|
|
36
|
+
onBrowse={onBrowse}
|
|
37
|
+
onUpload={onUpload}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
describe('Attachments', () => {
|
|
43
|
+
it('renders attachments flyout if it is in edit mode', () => {
|
|
44
|
+
mount(<Attachments appBridge={getAppBridgeBlockStub({ editorState: true })} />);
|
|
45
|
+
cy.get(FlyoutButtonSelector).should('exist');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('renders attachments flyout if it has attachments', () => {
|
|
49
|
+
mount(<Attachments items={[AssetDummy.with(1)]} />);
|
|
50
|
+
cy.get(FlyoutButtonSelector).should('exist');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('does not render attachments flyout if there are no attachments', () => {
|
|
54
|
+
mount(<Attachments items={[]} />);
|
|
55
|
+
cy.get(FlyoutButtonSelector).should('not.exist');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('renders asset input if in edit mode', () => {
|
|
59
|
+
mount(<Attachments appBridge={getAppBridgeBlockStub({ editorState: true })} items={[AssetDummy.with(1)]} />);
|
|
60
|
+
cy.get(FlyoutButtonSelector).click();
|
|
61
|
+
cy.get(AssetInputSelector).should('exist');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('does not render asset input if in view mode', () => {
|
|
65
|
+
mount(<Attachments items={[AssetDummy.with(1)]} />);
|
|
66
|
+
cy.get(FlyoutButtonSelector).click();
|
|
67
|
+
cy.get(AssetInputSelector).should('not.exist');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('renders asset action buttons if in edit mode', () => {
|
|
71
|
+
mount(<Attachments appBridge={getAppBridgeBlockStub({ editorState: true })} items={[AssetDummy.with(1)]} />);
|
|
72
|
+
cy.get(FlyoutButtonSelector).click();
|
|
73
|
+
cy.get(ActionBarSelector).should('exist');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('does not render asset action buttons if in view mode', () => {
|
|
77
|
+
mount(<Attachments items={[AssetDummy.with(1)]} />);
|
|
78
|
+
cy.get(FlyoutButtonSelector).click();
|
|
79
|
+
cy.get(ActionBarSelector).should('not.exist');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('renders an attachment item for each asset', () => {
|
|
83
|
+
mount(<Attachments items={[AssetDummy.with(1), AssetDummy.with(2), AssetDummy.with(3)]} />);
|
|
84
|
+
cy.get(FlyoutButtonSelector).click();
|
|
85
|
+
cy.get(AttachmentItemSelector).should('have.length', 3);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('renders loading circle for attachment item', () => {
|
|
89
|
+
const appBridge = getAppBridgeBlockStub({
|
|
90
|
+
editorState: true,
|
|
91
|
+
});
|
|
92
|
+
(appBridge.openAssetChooser as SinonStub) = cy.stub().callsArgWith(0, AssetDummy.with(4));
|
|
93
|
+
|
|
94
|
+
cy.clock();
|
|
95
|
+
const replaceStub = () =>
|
|
96
|
+
new Promise<void>((resolve) =>
|
|
97
|
+
setTimeout(() => {
|
|
98
|
+
resolve();
|
|
99
|
+
}, 2000)
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
mount(
|
|
103
|
+
<Attachments
|
|
104
|
+
onReplaceWithBrowse={replaceStub}
|
|
105
|
+
items={[AssetDummy.with(1), AssetDummy.with(2), AssetDummy.with(3)]}
|
|
106
|
+
appBridge={appBridge}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
cy.get(FlyoutButtonSelector).click();
|
|
111
|
+
cy.get(AttachmentItemSelector).eq(0).focus();
|
|
112
|
+
cy.get(FlyoutTriggerSelector).eq(1).click();
|
|
113
|
+
cy.get(MenuItemSelector).eq(1).click();
|
|
114
|
+
cy.get(LoadingCircleSelector).should('exist');
|
|
115
|
+
cy.tick(2000);
|
|
116
|
+
cy.get(LoadingCircleSelector).should('not.exist');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('renders focus ring on flyout button while tabbing and open it', () => {
|
|
120
|
+
mount(
|
|
121
|
+
<Attachments
|
|
122
|
+
appBridge={getAppBridgeBlockStub({ editorState: true })}
|
|
123
|
+
items={[AssetDummy.with(1), AssetDummy.with(2), AssetDummy.with(3)]}
|
|
124
|
+
/>
|
|
125
|
+
);
|
|
126
|
+
cy.get(FlyoutButtonSelector).click();
|
|
127
|
+
cy.realPress('Tab');
|
|
128
|
+
cy.realPress('Tab');
|
|
129
|
+
cy.realPress('Tab');
|
|
130
|
+
cy.get(FlyoutTriggerSelector).eq(0).should('have.class', 'focus-visible:tw-ring-blue');
|
|
131
|
+
cy.get(FlyoutTriggerSelector).eq(0).type('{enter}');
|
|
132
|
+
cy.get(MenuItemSelector).should('exist');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('reorders items using only keyboard events', () => {
|
|
136
|
+
const onSortStub = cy.stub();
|
|
137
|
+
mount(
|
|
138
|
+
<Attachments
|
|
139
|
+
appBridge={getAppBridgeBlockStub({ editorState: true })}
|
|
140
|
+
items={[{ ...AssetDummy.with(1), title: 'Moved item' }, AssetDummy.with(2), AssetDummy.with(3)]}
|
|
141
|
+
onSorted={onSortStub}
|
|
142
|
+
/>
|
|
143
|
+
);
|
|
144
|
+
cy.get(FlyoutButtonSelector).click();
|
|
145
|
+
cy.realPress('Tab');
|
|
146
|
+
cy.realPress('Tab');
|
|
147
|
+
cy.realPress('Tab');
|
|
148
|
+
cy.get(DragHandleSelector).eq(0).type(' {downarrow}{downarrow} ');
|
|
149
|
+
cy.get(AttachmentItemSelector).eq(1).should('contain.text', 'Moved item');
|
|
150
|
+
});
|
|
151
|
+
});
|