@frontify/guideline-blocks-settings 0.32.1 → 0.33.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/CHANGELOG.md +147 -0
- package/dist/components/Attachments/AttachmentItem.es.js +128 -109
- package/dist/components/Attachments/AttachmentItem.es.js.map +1 -1
- package/dist/components/Attachments/Attachments.es.js +9 -1
- package/dist/components/Attachments/Attachments.es.js.map +1 -1
- package/dist/components/Attachments/AttachmentsButtonTrigger.es.js +17 -9
- package/dist/components/Attachments/AttachmentsButtonTrigger.es.js.map +1 -1
- package/dist/components/BlockItemWrapper/BlockItemWrapper.es.js +38 -44
- package/dist/components/BlockItemWrapper/BlockItemWrapper.es.js.map +1 -1
- package/dist/components/BlockItemWrapper/Toolbar/AttachmentsToolbarButton/AttachmentsToolbarButton.es.js +33 -0
- package/dist/components/BlockItemWrapper/Toolbar/AttachmentsToolbarButton/AttachmentsToolbarButton.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/Toolbar/AttachmentsToolbarButton/AttachmentsToolbarButtonTrigger.es.js +26 -0
- package/dist/components/BlockItemWrapper/Toolbar/AttachmentsToolbarButton/AttachmentsToolbarButtonTrigger.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/Toolbar/BaseToolbarButton.es.js +28 -0
- package/dist/components/BlockItemWrapper/Toolbar/BaseToolbarButton.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/Toolbar/DragHandleToolbarButton/DragHandleToolbarButton.es.js +35 -0
- package/dist/components/BlockItemWrapper/Toolbar/DragHandleToolbarButton/DragHandleToolbarButton.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/Toolbar/FlyoutToolbarButton/FlyoutToolbarButton.es.js +44 -0
- package/dist/components/BlockItemWrapper/Toolbar/FlyoutToolbarButton/FlyoutToolbarButton.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/Toolbar/MenuToolbarButton/MenuToolbarButton.es.js +25 -0
- package/dist/components/BlockItemWrapper/Toolbar/MenuToolbarButton/MenuToolbarButton.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/Toolbar/MenuToolbarButton/ToolbarFlyoutMenu.es.js +29 -0
- package/dist/components/BlockItemWrapper/Toolbar/MenuToolbarButton/ToolbarFlyoutMenu.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/Toolbar/Toolbar.es.js +11 -112
- package/dist/components/BlockItemWrapper/Toolbar/Toolbar.es.js.map +1 -1
- package/dist/components/BlockItemWrapper/Toolbar/ToolbarButton/ToolbarButton.es.js +12 -0
- package/dist/components/BlockItemWrapper/Toolbar/ToolbarButton/ToolbarButton.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/Toolbar/ToolbarButtonTooltip.es.js +20 -0
- package/dist/components/BlockItemWrapper/Toolbar/ToolbarButtonTooltip.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/Toolbar/context/DragPreviewContext.es.js +11 -0
- package/dist/components/BlockItemWrapper/Toolbar/context/DragPreviewContext.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/Toolbar/context/MultiFlyoutContext.es.js +18 -0
- package/dist/components/BlockItemWrapper/Toolbar/context/MultiFlyoutContext.es.js.map +1 -0
- package/dist/components/BlockItemWrapper/Toolbar/helpers.es.js +1 -1
- package/dist/components/BlockItemWrapper/Toolbar/helpers.es.js.map +1 -1
- package/dist/components/BlockItemWrapper/Toolbar/hooks/useMultiFlyoutState.es.js +18 -0
- package/dist/components/BlockItemWrapper/Toolbar/hooks/useMultiFlyoutState.es.js.map +1 -0
- package/dist/helpers/mapColorPalettes.es.js +20 -8
- package/dist/helpers/mapColorPalettes.es.js.map +1 -1
- package/dist/index.cjs.js +3 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +92 -27
- package/dist/index.es.js +205 -187
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +3 -3
- package/dist/index.umd.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +4 -2
- package/setupTests.ts +7 -2
- package/src/components/Attachments/AttachmentItem.tsx +21 -0
- package/src/components/Attachments/Attachments.spec.ct.tsx +20 -1
- package/src/components/Attachments/Attachments.tsx +8 -4
- package/src/components/Attachments/AttachmentsButtonTrigger.tsx +11 -3
- package/src/components/Attachments/types.ts +4 -2
- package/src/components/BlockItemWrapper/BlockItemWrapper.spec.ct.tsx +37 -38
- package/src/components/BlockItemWrapper/BlockItemWrapper.tsx +44 -48
- package/src/components/BlockItemWrapper/Toolbar/AttachmentsToolbarButton/AttachmentsToolbarButton.spec.tsx +96 -0
- package/src/components/BlockItemWrapper/Toolbar/AttachmentsToolbarButton/AttachmentsToolbarButton.tsx +42 -0
- package/src/components/BlockItemWrapper/Toolbar/AttachmentsToolbarButton/AttachmentsToolbarButtonTrigger.spec.tsx +44 -0
- package/src/components/BlockItemWrapper/Toolbar/AttachmentsToolbarButton/AttachmentsToolbarButtonTrigger.tsx +24 -0
- package/src/components/BlockItemWrapper/Toolbar/AttachmentsToolbarButton/index.ts +3 -0
- package/src/components/BlockItemWrapper/Toolbar/BaseToolbarButton.spec.tsx +40 -0
- package/src/components/BlockItemWrapper/Toolbar/BaseToolbarButton.tsx +37 -0
- package/src/components/BlockItemWrapper/Toolbar/DragHandleToolbarButton/DragHandleToolbarButton.spec.tsx +89 -0
- package/src/components/BlockItemWrapper/Toolbar/DragHandleToolbarButton/DragHandleToolbarButton.tsx +40 -0
- package/src/components/BlockItemWrapper/Toolbar/DragHandleToolbarButton/index.ts +3 -0
- package/src/components/BlockItemWrapper/Toolbar/FlyoutToolbarButton/FlyoutToolbarButton.spec.tsx +140 -0
- package/src/components/BlockItemWrapper/Toolbar/FlyoutToolbarButton/FlyoutToolbarButton.tsx +61 -0
- package/src/components/BlockItemWrapper/Toolbar/FlyoutToolbarButton/index.ts +3 -0
- package/src/components/BlockItemWrapper/Toolbar/MenuToolbarButton/MenuToolbarButton.spec.tsx +77 -0
- package/src/components/BlockItemWrapper/Toolbar/MenuToolbarButton/MenuToolbarButton.tsx +30 -0
- package/src/components/BlockItemWrapper/Toolbar/MenuToolbarButton/ToolbarFlyoutMenu.spec.tsx +63 -0
- package/src/components/BlockItemWrapper/Toolbar/MenuToolbarButton/ToolbarFlyoutMenu.tsx +40 -0
- package/src/components/BlockItemWrapper/Toolbar/MenuToolbarButton/index.ts +3 -0
- package/src/components/BlockItemWrapper/Toolbar/Toolbar.spec.tsx +189 -57
- package/src/components/BlockItemWrapper/Toolbar/Toolbar.tsx +29 -126
- package/src/components/BlockItemWrapper/Toolbar/ToolbarButton/ToolbarButton.spec.tsx +70 -0
- package/src/components/BlockItemWrapper/Toolbar/ToolbarButton/ToolbarButton.tsx +19 -0
- package/src/components/BlockItemWrapper/Toolbar/ToolbarButton/index.ts +3 -0
- package/src/components/BlockItemWrapper/Toolbar/ToolbarButtonTooltip.tsx +25 -0
- package/src/components/BlockItemWrapper/Toolbar/context/DragPreviewContext.tsx +15 -0
- package/src/components/BlockItemWrapper/Toolbar/context/MultiFlyoutContext.tsx +25 -0
- package/src/components/BlockItemWrapper/Toolbar/context/index.ts +4 -0
- package/src/components/BlockItemWrapper/Toolbar/helpers.ts +1 -1
- package/src/components/BlockItemWrapper/Toolbar/hooks/index.ts +3 -0
- package/src/components/BlockItemWrapper/Toolbar/hooks/useMultiFlyoutState.spec.tsx +59 -0
- package/src/components/BlockItemWrapper/Toolbar/hooks/useMultiFlyoutState.ts +24 -0
- package/src/components/BlockItemWrapper/Toolbar/index.ts +6 -0
- package/src/components/BlockItemWrapper/Toolbar/types.ts +10 -30
- package/src/components/BlockItemWrapper/types.ts +1 -2
- package/src/helpers/mapColorPalettes.spec.ts +14 -113
- package/src/helpers/mapColorPalettes.ts +51 -8
- package/src/hooks/useAttachments.spec.tsx +1 -0
- package/tsconfig.json +1 -1
- package/dist/components/BlockItemWrapper/Toolbar/ToolbarAttachments.es.js +0 -27
- package/dist/components/BlockItemWrapper/Toolbar/ToolbarAttachments.es.js.map +0 -1
- package/dist/components/BlockItemWrapper/Toolbar/ToolbarAttachmentsTrigger.es.js +0 -12
- package/dist/components/BlockItemWrapper/Toolbar/ToolbarAttachmentsTrigger.es.js.map +0 -1
- package/src/components/BlockItemWrapper/Toolbar/ToolbarAttachments.tsx +0 -29
- package/src/components/BlockItemWrapper/Toolbar/ToolbarAttachmentsTrigger.tsx +0 -14
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { LegacyTooltip as Tooltip, TooltipPosition } from '@frontify/fondue';
|
|
4
|
+
import { ReactElement, ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
type ToolbarButtonTooltipProps = {
|
|
7
|
+
content: ReactNode;
|
|
8
|
+
children: ReactElement;
|
|
9
|
+
open?: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const ToolbarButtonTooltip = ({ open, content, children, disabled }: ToolbarButtonTooltipProps) => (
|
|
14
|
+
<Tooltip
|
|
15
|
+
withArrow
|
|
16
|
+
hoverDelay={0}
|
|
17
|
+
enterDelay={300}
|
|
18
|
+
open={open}
|
|
19
|
+
disabled={disabled}
|
|
20
|
+
position={TooltipPosition.Top}
|
|
21
|
+
content={<div>{content}</div>}
|
|
22
|
+
triggerElement={children}
|
|
23
|
+
data-test-id="toolbar-button-tooltip"
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { type ReactNode, createContext, useContext } from 'react';
|
|
4
|
+
|
|
5
|
+
const DragPreviewContext = createContext(false);
|
|
6
|
+
|
|
7
|
+
export const DragPreviewContextProvider = ({
|
|
8
|
+
children,
|
|
9
|
+
isDragPreview,
|
|
10
|
+
}: {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
isDragPreview: boolean;
|
|
13
|
+
}) => <DragPreviewContext.Provider value={isDragPreview}>{children}</DragPreviewContext.Provider>;
|
|
14
|
+
|
|
15
|
+
export const useDragPreviewContext = () => useContext(DragPreviewContext);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { Dispatch, ReactNode, SetStateAction, createContext, useContext, useMemo } from 'react';
|
|
4
|
+
|
|
5
|
+
export type MultiFlyoutContextType = {
|
|
6
|
+
openFlyoutIds: string[];
|
|
7
|
+
setOpenFlyoutIds: Dispatch<SetStateAction<string[]>>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const MultiFlyoutContext = createContext<MultiFlyoutContextType>({
|
|
11
|
+
openFlyoutIds: [],
|
|
12
|
+
setOpenFlyoutIds: () => console.error('No MultiFlyoutContext Provider found'),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const MultiFlyoutContextProvider = ({
|
|
16
|
+
children,
|
|
17
|
+
openFlyoutIds,
|
|
18
|
+
setOpenFlyoutIds,
|
|
19
|
+
}: { children: ReactNode } & MultiFlyoutContextType) => {
|
|
20
|
+
const memoizedContext = useMemo(() => ({ openFlyoutIds, setOpenFlyoutIds }), [openFlyoutIds, setOpenFlyoutIds]);
|
|
21
|
+
|
|
22
|
+
return <MultiFlyoutContext.Provider value={memoizedContext}>{children}</MultiFlyoutContext.Provider>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const useMultiFlyoutContext = () => useContext(MultiFlyoutContext);
|
|
@@ -25,7 +25,7 @@ export const getToolbarButtonClassNames = (cursor: 'grab' | 'pointer', forceActi
|
|
|
25
25
|
classNames.push(
|
|
26
26
|
'hover:tw-bg-box-neutral-hover active:tw-bg-box-neutral-pressed',
|
|
27
27
|
'tw-text-text-weak hover:tw-text-box-neutral-inverse-hover active:tw-text-box-neutral-inverse-pressed',
|
|
28
|
-
cursor === 'grab' ? 'tw-cursor-grab active:tw-cursor-grabbing' : 'tw-cursor-pointer',
|
|
28
|
+
cursor === 'grab' ? '!tw-cursor-grab active:tw-cursor-grabbing' : 'tw-cursor-pointer',
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { renderHook } from '@testing-library/react';
|
|
4
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import { useMultiFlyoutState } from './useMultiFlyoutState';
|
|
6
|
+
import { MultiFlyoutContextProvider, MultiFlyoutContextType } from '../context/MultiFlyoutContext';
|
|
7
|
+
|
|
8
|
+
const FLYOUT_ID = 'flyout';
|
|
9
|
+
|
|
10
|
+
const renderMultiFlyoutState = ({ openFlyoutIds, setOpenFlyoutIds }: MultiFlyoutContextType) =>
|
|
11
|
+
renderHook(() => useMultiFlyoutState(FLYOUT_ID), {
|
|
12
|
+
wrapper: ({ children }) => (
|
|
13
|
+
<MultiFlyoutContextProvider openFlyoutIds={openFlyoutIds} setOpenFlyoutIds={setOpenFlyoutIds}>
|
|
14
|
+
{children}
|
|
15
|
+
</MultiFlyoutContextProvider>
|
|
16
|
+
),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('useMultiFlyoutState', () => {
|
|
20
|
+
it('should be open when flyout id in context array', () => {
|
|
21
|
+
const { result } = renderMultiFlyoutState({ openFlyoutIds: [FLYOUT_ID], setOpenFlyoutIds: vi.fn() });
|
|
22
|
+
expect(result.current.isOpen).toEqual(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should be closed when flyout id is not in context array', () => {
|
|
26
|
+
const { result } = renderMultiFlyoutState({ openFlyoutIds: [], setOpenFlyoutIds: vi.fn() });
|
|
27
|
+
expect(result.current.isOpen).toEqual(false);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should add id to array when opening', () => {
|
|
31
|
+
const setOpenFlyoutIdsStub = vi.fn();
|
|
32
|
+
const { result } = renderMultiFlyoutState({ openFlyoutIds: [], setOpenFlyoutIds: setOpenFlyoutIdsStub });
|
|
33
|
+
|
|
34
|
+
result.current.onOpenChange(true);
|
|
35
|
+
const dispatchedResult = setOpenFlyoutIdsStub.mock.lastCall[0]([]);
|
|
36
|
+
|
|
37
|
+
expect(dispatchedResult).toEqual([FLYOUT_ID]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should remove id from array when closing', () => {
|
|
41
|
+
const setOpenFlyoutIdsStub = vi.fn();
|
|
42
|
+
const { result } = renderMultiFlyoutState({ openFlyoutIds: [], setOpenFlyoutIds: setOpenFlyoutIdsStub });
|
|
43
|
+
|
|
44
|
+
result.current.onOpenChange(false);
|
|
45
|
+
const dispatchedResult = setOpenFlyoutIdsStub.mock.lastCall[0]([FLYOUT_ID]);
|
|
46
|
+
|
|
47
|
+
expect(dispatchedResult).toEqual([]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should remove duplicates from array', () => {
|
|
51
|
+
const setOpenFlyoutIdsStub = vi.fn();
|
|
52
|
+
const { result } = renderMultiFlyoutState({ openFlyoutIds: [], setOpenFlyoutIds: setOpenFlyoutIdsStub });
|
|
53
|
+
|
|
54
|
+
result.current.onOpenChange(true);
|
|
55
|
+
const dispatchedResult = setOpenFlyoutIdsStub.mock.lastCall[0]([FLYOUT_ID, FLYOUT_ID, FLYOUT_ID]);
|
|
56
|
+
|
|
57
|
+
expect(dispatchedResult).toEqual([FLYOUT_ID]);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
import { useMultiFlyoutContext } from '../context/MultiFlyoutContext';
|
|
5
|
+
|
|
6
|
+
export const useMultiFlyoutState = (flyoutId: string) => {
|
|
7
|
+
const { openFlyoutIds, setOpenFlyoutIds } = useMultiFlyoutContext();
|
|
8
|
+
|
|
9
|
+
const onOpenChange = useCallback(
|
|
10
|
+
(isFlyoutOpen: boolean) => {
|
|
11
|
+
setOpenFlyoutIds((currentIds) => {
|
|
12
|
+
const filteredIds = currentIds.filter((id) => id !== flyoutId);
|
|
13
|
+
if (!isFlyoutOpen) {
|
|
14
|
+
return filteredIds;
|
|
15
|
+
} else {
|
|
16
|
+
return [...filteredIds, flyoutId];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
[flyoutId, setOpenFlyoutIds],
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return { isOpen: openFlyoutIds.includes(flyoutId), onOpenChange };
|
|
24
|
+
};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
2
|
|
|
3
|
+
export * from './context';
|
|
4
|
+
export * from './hooks';
|
|
3
5
|
export * from './Toolbar';
|
|
6
|
+
export * from './AttachmentsToolbarButton';
|
|
7
|
+
export * from './DragHandleToolbarButton';
|
|
8
|
+
export * from './FlyoutToolbarButton';
|
|
9
|
+
export * from './MenuToolbarButton';
|
|
4
10
|
export * from './types';
|
|
@@ -1,38 +1,18 @@
|
|
|
1
1
|
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
2
|
|
|
3
|
-
import { type
|
|
3
|
+
import { type ToolbarButtonProps } from './ToolbarButton';
|
|
4
|
+
import { type DragHandleToolbarButtonProps } from './DragHandleToolbarButton';
|
|
5
|
+
import { type FlyoutToolbarButtonProps } from './FlyoutToolbarButton';
|
|
6
|
+
import { type MenuToolbarButtonProps } from './MenuToolbarButton';
|
|
4
7
|
|
|
5
8
|
export type ToolbarProps = {
|
|
6
9
|
items: ToolbarItem[];
|
|
7
|
-
|
|
8
|
-
attachments: ToolbarFlyoutState & { isEnabled: boolean };
|
|
9
|
-
isDragging?: boolean;
|
|
10
|
+
attachments: { isEnabled: boolean };
|
|
10
11
|
};
|
|
11
12
|
|
|
12
|
-
export type
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
type BaseToolbarItem = {
|
|
18
|
-
icon: JSX.Element;
|
|
19
|
-
tooltip?: string;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
type DraghandleToolbarItem = BaseToolbarItem & {
|
|
23
|
-
draggableProps: Record<string, unknown>;
|
|
24
|
-
setActivatorNodeRef?: (node: HTMLElement | null) => void;
|
|
25
|
-
};
|
|
13
|
+
export type DragHandleToolbarItem = { type: 'dragHandle' } & DragHandleToolbarButtonProps;
|
|
14
|
+
export type ButtonToolbarItem = { type: 'button' } & ToolbarButtonProps;
|
|
15
|
+
export type FlyoutToolbarItem = { type: 'flyout' } & FlyoutToolbarButtonProps;
|
|
16
|
+
export type MenuToolbarItem = { type: 'menu' } & MenuToolbarButtonProps;
|
|
26
17
|
|
|
27
|
-
type
|
|
28
|
-
onClick: () => void;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type ToolbarItem = DraghandleToolbarItem | ButtonToolbarItem;
|
|
32
|
-
|
|
33
|
-
export type FlyoutToolbarItem = {
|
|
34
|
-
title: string;
|
|
35
|
-
onClick: () => void;
|
|
36
|
-
icon: JSX.Element;
|
|
37
|
-
style?: MenuItemStyle;
|
|
38
|
-
};
|
|
18
|
+
export type ToolbarItem = DragHandleToolbarItem | ButtonToolbarItem | FlyoutToolbarItem | MenuToolbarItem;
|
|
@@ -4,14 +4,13 @@ import { type ReactNode } from 'react';
|
|
|
4
4
|
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
6
|
import { type AttachmentsProvider, type withAttachmentsProvider } from '../../hooks/useAttachments';
|
|
7
|
-
import { type
|
|
7
|
+
import { type ToolbarItem } from './Toolbar';
|
|
8
8
|
|
|
9
9
|
export type BlockItemWrapperProps = {
|
|
10
10
|
children: ReactNode;
|
|
11
11
|
shouldHideWrapper?: boolean;
|
|
12
12
|
shouldHideComponent?: boolean;
|
|
13
13
|
toolbarItems: (ToolbarItem | undefined)[];
|
|
14
|
-
toolbarFlyoutItems: FlyoutToolbarItem[][];
|
|
15
14
|
isDragging?: boolean;
|
|
16
15
|
shouldFillContainer?: boolean;
|
|
17
16
|
outlineOffset?: number;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { describe, expect, it } from 'vitest';
|
|
4
4
|
import { mapAppBridgeColorPalettesToFonduePalettes } from './mapColorPalettes';
|
|
5
|
+
import { ColorDummy } from '@frontify/app-bridge';
|
|
5
6
|
|
|
6
7
|
describe('mapAppBridgeColorPalettesToFonduePalettes', () => {
|
|
7
8
|
it('should map app bridge color palette to fondue palette', () => {
|
|
@@ -10,107 +11,7 @@ describe('mapAppBridgeColorPalettesToFonduePalettes', () => {
|
|
|
10
11
|
id: 19,
|
|
11
12
|
name: 'Awesome color palette',
|
|
12
13
|
description: 'This is an awesome color palette',
|
|
13
|
-
colors: [
|
|
14
|
-
{
|
|
15
|
-
id: 6,
|
|
16
|
-
name: 'Tarawera',
|
|
17
|
-
sort: 1,
|
|
18
|
-
nameCss: 'tarawera',
|
|
19
|
-
hex: '0b486b',
|
|
20
|
-
red: 11,
|
|
21
|
-
green: 72,
|
|
22
|
-
blue: 107,
|
|
23
|
-
alpha: 255,
|
|
24
|
-
hue: 202,
|
|
25
|
-
saturation: 81,
|
|
26
|
-
lightness: 23,
|
|
27
|
-
c: 90,
|
|
28
|
-
m: 33,
|
|
29
|
-
y: 0,
|
|
30
|
-
k: 58,
|
|
31
|
-
pantone: null,
|
|
32
|
-
ral: null,
|
|
33
|
-
oracal: null,
|
|
34
|
-
pantoneCoated: null,
|
|
35
|
-
pantoneUncoated: null,
|
|
36
|
-
cmykCoated: null,
|
|
37
|
-
cmykUncoated: null,
|
|
38
|
-
cmykNewspaper: null,
|
|
39
|
-
ncs: null,
|
|
40
|
-
pantoneCp: null,
|
|
41
|
-
pantonePlastics: null,
|
|
42
|
-
pantoneTextile: null,
|
|
43
|
-
hks: null,
|
|
44
|
-
threeM: null,
|
|
45
|
-
lab: null,
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
id: 7,
|
|
49
|
-
name: 'Oracle',
|
|
50
|
-
sort: 2,
|
|
51
|
-
nameCss: 'oracle',
|
|
52
|
-
hex: '3b8686',
|
|
53
|
-
red: 59,
|
|
54
|
-
green: 134,
|
|
55
|
-
blue: 134,
|
|
56
|
-
alpha: 255,
|
|
57
|
-
hue: 180,
|
|
58
|
-
saturation: 39,
|
|
59
|
-
lightness: 38,
|
|
60
|
-
c: 56,
|
|
61
|
-
m: 0,
|
|
62
|
-
y: 0,
|
|
63
|
-
k: 47,
|
|
64
|
-
pantone: null,
|
|
65
|
-
ral: null,
|
|
66
|
-
oracal: null,
|
|
67
|
-
pantoneCoated: null,
|
|
68
|
-
pantoneUncoated: null,
|
|
69
|
-
cmykCoated: null,
|
|
70
|
-
cmykUncoated: null,
|
|
71
|
-
cmykNewspaper: null,
|
|
72
|
-
ncs: null,
|
|
73
|
-
pantoneCp: null,
|
|
74
|
-
pantonePlastics: null,
|
|
75
|
-
pantoneTextile: null,
|
|
76
|
-
hks: null,
|
|
77
|
-
threeM: null,
|
|
78
|
-
lab: null,
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
id: 8,
|
|
82
|
-
name: 'Silver Tree',
|
|
83
|
-
sort: 3,
|
|
84
|
-
nameCss: 'silver-tree',
|
|
85
|
-
hex: '79bd9a',
|
|
86
|
-
red: 121,
|
|
87
|
-
green: 189,
|
|
88
|
-
blue: 154,
|
|
89
|
-
alpha: 255,
|
|
90
|
-
hue: 149,
|
|
91
|
-
saturation: 34,
|
|
92
|
-
lightness: 61,
|
|
93
|
-
c: 36,
|
|
94
|
-
m: 0,
|
|
95
|
-
y: 19,
|
|
96
|
-
k: 26,
|
|
97
|
-
pantone: null,
|
|
98
|
-
ral: null,
|
|
99
|
-
oracal: null,
|
|
100
|
-
pantoneCoated: null,
|
|
101
|
-
pantoneUncoated: null,
|
|
102
|
-
cmykCoated: null,
|
|
103
|
-
cmykUncoated: null,
|
|
104
|
-
cmykNewspaper: null,
|
|
105
|
-
ncs: null,
|
|
106
|
-
pantoneCp: null,
|
|
107
|
-
pantonePlastics: null,
|
|
108
|
-
pantoneTextile: null,
|
|
109
|
-
hks: null,
|
|
110
|
-
threeM: null,
|
|
111
|
-
lab: null,
|
|
112
|
-
},
|
|
113
|
-
],
|
|
14
|
+
colors: [ColorDummy.green(), ColorDummy.yellow(), ColorDummy.red()],
|
|
114
15
|
},
|
|
115
16
|
]);
|
|
116
17
|
expect(result).toEqual([
|
|
@@ -120,24 +21,24 @@ describe('mapAppBridgeColorPalettesToFonduePalettes', () => {
|
|
|
120
21
|
colors: [
|
|
121
22
|
{
|
|
122
23
|
alpha: 1,
|
|
123
|
-
|
|
124
|
-
green:
|
|
125
|
-
|
|
126
|
-
name: '
|
|
24
|
+
blue: 0,
|
|
25
|
+
green: 255,
|
|
26
|
+
red: 0,
|
|
27
|
+
name: 'Green',
|
|
127
28
|
},
|
|
128
29
|
{
|
|
129
30
|
alpha: 1,
|
|
130
|
-
|
|
131
|
-
green:
|
|
132
|
-
|
|
133
|
-
name: '
|
|
31
|
+
blue: 0,
|
|
32
|
+
green: 255,
|
|
33
|
+
red: 255,
|
|
34
|
+
name: 'Yellow',
|
|
134
35
|
},
|
|
135
36
|
{
|
|
136
37
|
alpha: 1,
|
|
137
|
-
|
|
138
|
-
green:
|
|
139
|
-
|
|
140
|
-
name: '
|
|
38
|
+
blue: 0,
|
|
39
|
+
green: 0,
|
|
40
|
+
red: 255,
|
|
41
|
+
name: 'Red',
|
|
141
42
|
},
|
|
142
43
|
],
|
|
143
44
|
},
|
|
@@ -3,20 +3,63 @@
|
|
|
3
3
|
import { ColorPalette } from '@frontify/app-bridge';
|
|
4
4
|
import { Palette } from '@frontify/fondue';
|
|
5
5
|
|
|
6
|
+
type Nullable<T> = T | null;
|
|
7
|
+
|
|
8
|
+
type V3Color = {
|
|
9
|
+
id: number;
|
|
10
|
+
name: Nullable<string>;
|
|
11
|
+
red: Nullable<number>;
|
|
12
|
+
green: Nullable<number>;
|
|
13
|
+
blue: Nullable<number>;
|
|
14
|
+
alpha: Nullable<number>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type V4Color = {
|
|
18
|
+
id: number;
|
|
19
|
+
title: Nullable<string>;
|
|
20
|
+
revision: {
|
|
21
|
+
rgba: {
|
|
22
|
+
red: Nullable<number>;
|
|
23
|
+
green: Nullable<number>;
|
|
24
|
+
blue: Nullable<number>;
|
|
25
|
+
alpha: Nullable<number>;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type Color = V3Color | V4Color;
|
|
31
|
+
|
|
6
32
|
export const mapAppBridgeColorPalettesToFonduePalettes = (colorPalettes: ColorPalette[]): Palette[] => {
|
|
7
33
|
return colorPalettes.map(mapAppBridgeColorPaletteToFonduePalette);
|
|
8
34
|
};
|
|
9
|
-
|
|
10
35
|
export const mapAppBridgeColorPaletteToFonduePalette = (colorPalette: ColorPalette): Palette => {
|
|
11
36
|
return {
|
|
12
37
|
id: colorPalette.id,
|
|
13
38
|
title: colorPalette.name,
|
|
14
|
-
colors: colorPalette.colors.map(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
39
|
+
colors: colorPalette.colors.map(mapColor),
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const isV4Color = (color: Color): color is V4Color => {
|
|
44
|
+
return 'revision' in color;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const mapColor = (color: Color) => {
|
|
48
|
+
if (isV4Color(color)) {
|
|
49
|
+
const { title, revision } = color;
|
|
50
|
+
return {
|
|
51
|
+
alpha: revision.rgba.alpha ? revision.rgba.alpha / 255 : 1,
|
|
52
|
+
red: revision.rgba.red ?? 0,
|
|
53
|
+
green: revision.rgba.green ?? 0,
|
|
54
|
+
blue: revision.rgba.blue ?? 0,
|
|
55
|
+
name: title ?? '',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
alpha: color.alpha ? color.alpha / 255 : 1,
|
|
60
|
+
red: color.red ?? 0,
|
|
61
|
+
green: color.green ?? 0,
|
|
62
|
+
blue: color.blue ?? 0,
|
|
63
|
+
name: color.name ?? '',
|
|
21
64
|
};
|
|
22
65
|
};
|
|
@@ -26,6 +26,7 @@ describe('useAttachments', async () => {
|
|
|
26
26
|
const STUB_WITH_THREE_ASSETS = getAppBridgeBlockStub({
|
|
27
27
|
blockId: 2,
|
|
28
28
|
blockAssets: { [MOCK_SETTINGS_ID]: [AssetDummy.with(1), AssetDummy.with(2), AssetDummy.with(3)] },
|
|
29
|
+
editorState: true,
|
|
29
30
|
});
|
|
30
31
|
const { result } = renderHook(() => useAttachments(STUB_WITH_THREE_ASSETS, MOCK_SETTINGS_ID));
|
|
31
32
|
|
package/tsconfig.json
CHANGED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { jsx as s } from "react/jsx-runtime";
|
|
2
|
-
import { ToolbarAttachmentsTrigger as p } from "./ToolbarAttachmentsTrigger.es.js";
|
|
3
|
-
import { useAttachmentsContext as h } from "../../../hooks/useAttachments.es.js";
|
|
4
|
-
import { Attachments as i } from "../../Attachments/Attachments.es.js";
|
|
5
|
-
const f = ({ isOpen: o, onOpenChange: n }) => {
|
|
6
|
-
const { appBridge: r, attachments: m, onAttachmentsAdd: t, onAttachmentDelete: a, onAttachmentReplace: e, onAttachmentsSorted: c } = h();
|
|
7
|
-
return /* @__PURE__ */ s(
|
|
8
|
-
i,
|
|
9
|
-
{
|
|
10
|
-
onUpload: t,
|
|
11
|
-
onDelete: a,
|
|
12
|
-
onReplaceWithBrowse: e,
|
|
13
|
-
onReplaceWithUpload: e,
|
|
14
|
-
onSorted: c,
|
|
15
|
-
onBrowse: t,
|
|
16
|
-
items: m,
|
|
17
|
-
appBridge: r,
|
|
18
|
-
triggerComponent: p,
|
|
19
|
-
isOpen: o,
|
|
20
|
-
onOpenChange: n
|
|
21
|
-
}
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
export {
|
|
25
|
-
f as ToolbarAttachments
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=ToolbarAttachments.es.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ToolbarAttachments.es.js","sources":["../../../../src/components/BlockItemWrapper/Toolbar/ToolbarAttachments.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { Attachments } from '../../Attachments';\nimport { useAttachmentsContext } from '../../../hooks';\n\nimport { type ToolbarFlyoutState } from './types';\n\nimport { ToolbarAttachmentsTrigger } from './ToolbarAttachmentsTrigger';\n\nexport const ToolbarAttachments = ({ isOpen, onOpenChange }: ToolbarFlyoutState) => {\n const { appBridge, attachments, onAttachmentsAdd, onAttachmentDelete, onAttachmentReplace, onAttachmentsSorted } =\n useAttachmentsContext();\n\n return (\n <Attachments\n onUpload={onAttachmentsAdd}\n onDelete={onAttachmentDelete}\n onReplaceWithBrowse={onAttachmentReplace}\n onReplaceWithUpload={onAttachmentReplace}\n onSorted={onAttachmentsSorted}\n onBrowse={onAttachmentsAdd}\n items={attachments}\n appBridge={appBridge}\n triggerComponent={ToolbarAttachmentsTrigger}\n isOpen={isOpen}\n onOpenChange={onOpenChange}\n />\n );\n};\n"],"names":["ToolbarAttachments","isOpen","onOpenChange","appBridge","attachments","onAttachmentsAdd","onAttachmentDelete","onAttachmentReplace","onAttachmentsSorted","useAttachmentsContext","jsx","Attachments","ToolbarAttachmentsTrigger"],"mappings":";;;;AASO,MAAMA,IAAqB,CAAC,EAAE,QAAAC,GAAQ,cAAAC,QAAuC;AAC1E,QAAA,EAAE,WAAAC,GAAW,aAAAC,GAAa,kBAAAC,GAAkB,oBAAAC,GAAoB,qBAAAC,GAAqB,qBAAAC,MACvFC;AAGA,SAAA,gBAAAC;AAAA,IAACC;AAAA,IAAA;AAAA,MACG,UAAUN;AAAA,MACV,UAAUC;AAAA,MACV,qBAAqBC;AAAA,MACrB,qBAAqBA;AAAA,MACrB,UAAUC;AAAA,MACV,UAAUH;AAAA,MACV,OAAOD;AAAA,MACP,WAAAD;AAAA,MACA,kBAAkBS;AAAA,MAClB,QAAAX;AAAA,MACA,cAAAC;AAAA,IAAA;AAAA,EAAA;AAGZ;"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { jsxs as e, jsx as o } from "react/jsx-runtime";
|
|
2
|
-
import { IconPaperclip16 as s, IconCaretDown12 as a } from "@frontify/fondue";
|
|
3
|
-
import { getToolbarButtonClassNames as m } from "./helpers.es.js";
|
|
4
|
-
const p = ({ children: r, isFlyoutOpen: t }) => /* @__PURE__ */ e("div", { className: m("pointer", t), children: [
|
|
5
|
-
/* @__PURE__ */ o(s, {}),
|
|
6
|
-
r,
|
|
7
|
-
/* @__PURE__ */ o(a, {})
|
|
8
|
-
] });
|
|
9
|
-
export {
|
|
10
|
-
p as ToolbarAttachmentsTrigger
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=ToolbarAttachmentsTrigger.es.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ToolbarAttachmentsTrigger.es.js","sources":["../../../../src/components/BlockItemWrapper/Toolbar/ToolbarAttachmentsTrigger.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { IconCaretDown12, IconPaperclip16 } from '@frontify/fondue';\nimport { type AttachmentsTriggerProps } from '../../Attachments/types';\n\nimport { getToolbarButtonClassNames } from './helpers';\n\nexport const ToolbarAttachmentsTrigger = ({ children, isFlyoutOpen }: AttachmentsTriggerProps) => (\n <div className={getToolbarButtonClassNames('pointer', isFlyoutOpen)}>\n <IconPaperclip16 />\n {children}\n <IconCaretDown12 />\n </div>\n);\n"],"names":["ToolbarAttachmentsTrigger","children","isFlyoutOpen","jsxs","getToolbarButtonClassNames","jsx","IconPaperclip16","IconCaretDown12"],"mappings":";;;AAOO,MAAMA,IAA4B,CAAC,EAAE,UAAAC,GAAU,cAAAC,EAAa,MAC9D,gBAAAC,EAAA,OAAA,EAAI,WAAWC,EAA2B,WAAWF,CAAY,GAC9D,UAAA;AAAA,EAAA,gBAAAG,EAACC,GAAgB,EAAA;AAAA,EAChBL;AAAA,oBACAM,GAAgB,EAAA;AAAA,EACrB,CAAA;"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
-
|
|
3
|
-
import { Attachments } from '../../Attachments';
|
|
4
|
-
import { useAttachmentsContext } from '../../../hooks';
|
|
5
|
-
|
|
6
|
-
import { type ToolbarFlyoutState } from './types';
|
|
7
|
-
|
|
8
|
-
import { ToolbarAttachmentsTrigger } from './ToolbarAttachmentsTrigger';
|
|
9
|
-
|
|
10
|
-
export const ToolbarAttachments = ({ isOpen, onOpenChange }: ToolbarFlyoutState) => {
|
|
11
|
-
const { appBridge, attachments, onAttachmentsAdd, onAttachmentDelete, onAttachmentReplace, onAttachmentsSorted } =
|
|
12
|
-
useAttachmentsContext();
|
|
13
|
-
|
|
14
|
-
return (
|
|
15
|
-
<Attachments
|
|
16
|
-
onUpload={onAttachmentsAdd}
|
|
17
|
-
onDelete={onAttachmentDelete}
|
|
18
|
-
onReplaceWithBrowse={onAttachmentReplace}
|
|
19
|
-
onReplaceWithUpload={onAttachmentReplace}
|
|
20
|
-
onSorted={onAttachmentsSorted}
|
|
21
|
-
onBrowse={onAttachmentsAdd}
|
|
22
|
-
items={attachments}
|
|
23
|
-
appBridge={appBridge}
|
|
24
|
-
triggerComponent={ToolbarAttachmentsTrigger}
|
|
25
|
-
isOpen={isOpen}
|
|
26
|
-
onOpenChange={onOpenChange}
|
|
27
|
-
/>
|
|
28
|
-
);
|
|
29
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/* (c) Copyright Frontify Ltd., all rights reserved. */
|
|
2
|
-
|
|
3
|
-
import { IconCaretDown12, IconPaperclip16 } from '@frontify/fondue';
|
|
4
|
-
import { type AttachmentsTriggerProps } from '../../Attachments/types';
|
|
5
|
-
|
|
6
|
-
import { getToolbarButtonClassNames } from './helpers';
|
|
7
|
-
|
|
8
|
-
export const ToolbarAttachmentsTrigger = ({ children, isFlyoutOpen }: AttachmentsTriggerProps) => (
|
|
9
|
-
<div className={getToolbarButtonClassNames('pointer', isFlyoutOpen)}>
|
|
10
|
-
<IconPaperclip16 />
|
|
11
|
-
{children}
|
|
12
|
-
<IconCaretDown12 />
|
|
13
|
-
</div>
|
|
14
|
-
);
|