@frontify/fondue 12.1.13 → 12.1.14
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/dist/components/ActionMenu/Aria/AriaMenuItem.es.js +26 -29
- package/dist/components/ActionMenu/Aria/AriaMenuItem.es.js.map +1 -1
- package/dist/components/RichTextEditor/BlurObserver.es.js +1 -1
- package/dist/components/RichTextEditor/BlurObserver.es.js.map +1 -1
- package/dist/components/RichTextEditor/RichTextEditor.es.js.map +1 -1
- package/dist/components/Table/TableCell.es.js.map +1 -1
- package/dist/components/Tree/helpers/projection.es.js.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/components/style.css +1 -1
- package/dist/packages/tokens/tailwind.config.js +1 -1
- package/package.json +33 -33
|
@@ -37,35 +37,32 @@ const z = (t) => typeof t.onClick < "u" && typeof t.type > "u", n = (t) => typeo
|
|
|
37
37
|
o,
|
|
38
38
|
s
|
|
39
39
|
), { title: u, decorator: b, subtitle: S, size: g, style: y, disabled: p, selectionIndicator: v } = t, { isFocusVisible: M, focusProps: V } = C();
|
|
40
|
-
return (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
)
|
|
40
|
+
return /* @__PURE__ */ r(
|
|
41
|
+
"li",
|
|
42
|
+
{
|
|
43
|
+
...x(h, V, { onClick: () => i == null ? void 0 : i() }),
|
|
44
|
+
"data-test-id": "menu-item",
|
|
45
|
+
className: O([
|
|
46
|
+
"tw-relative hover:tw-bg-box-neutral-hover tw-list-none tw-outline-none",
|
|
47
|
+
p && "tw-pointer-events-none tw-top-px",
|
|
48
|
+
M && N
|
|
49
|
+
]),
|
|
50
|
+
ref: s,
|
|
51
|
+
children: /* @__PURE__ */ r(
|
|
52
|
+
E,
|
|
53
|
+
{
|
|
54
|
+
title: u,
|
|
55
|
+
decorator: b,
|
|
56
|
+
subtitle: S,
|
|
57
|
+
size: g,
|
|
58
|
+
style: y,
|
|
59
|
+
disabled: p,
|
|
60
|
+
active: l,
|
|
61
|
+
selectionIndicator: v,
|
|
62
|
+
switchComponent: f
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
}
|
|
69
66
|
);
|
|
70
67
|
};
|
|
71
68
|
T.displayName = "FondueAriaMenuItem";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AriaMenuItem.es.js","sources":["../../../../src/components/ActionMenu/Aria/AriaMenuItem.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useFocusRing } from '@react-aria/focus';\nimport { useMenuItem } from '@react-aria/menu';\nimport { mergeProps } from '@react-aria/utils';\nimport { type TreeState } from '@react-stately/tree';\nimport { type Node } from '@react-types/shared';\nimport { type ReactElement, useEffect, useRef, useState } from 'react';\n\nimport { type ActionMenuItemType, type ActionMenuSwitchItemType } from '@components/ActionMenu';\nimport { type MenuItemType } from '@components/Dropdown';\nimport { MenuItem } from '@components/MenuItem/MenuItem';\nimport { Switch } from '@components/Switch';\nimport { FOCUS_STYLE_INSET } from '@utilities/focusStyle';\nimport { merge } from '@utilities/merge';\n\nexport type AriaOptionProps = {\n menuItem: MenuItemType | ActionMenuItemType | ActionMenuSwitchItemType;\n node: Node<object>;\n isSelected?: boolean;\n state: TreeState<object>;\n /**\n * @deprecated Use `menuItem.onClick` instead\n * */\n onClick?: () => void;\n};\n\ninterface SwitchObject {\n switchComponent: ReactElement | undefined;\n switchValue: boolean | null;\n toggleSwitch: VoidFunction | null;\n}\n\nconst isActionMenuItem = (\n menuItem: MenuItemType | ActionMenuItemType | ActionMenuSwitchItemType,\n): menuItem is ActionMenuItemType =>\n typeof (menuItem as ActionMenuItemType).onClick !== 'undefined' && typeof menuItem.type === 'undefined';\nconst isActionMenuSwitchItem = (\n menuItem: MenuItemType | ActionMenuItemType | ActionMenuSwitchItemType,\n): menuItem is ActionMenuSwitchItemType =>\n typeof (menuItem as ActionMenuSwitchItemType).onClick !== 'undefined' && menuItem.type === 'switch';\n\nconst useSwitch = (isSwitch: boolean, initialValue: boolean) => {\n const [switchValue, setSwitchValue] = useState<boolean>(initialValue ?? false);\n const [switchObject, setSwitchObject] = useState<SwitchObject>({\n switchComponent: undefined,\n switchValue: null,\n toggleSwitch: null,\n });\n\n useEffect(() => {\n if (isSwitch) {\n const toggleSwitch = () => setSwitchValue(!switchValue);\n const switchComponent = <Switch size=\"small\" mode={switchValue ? 'on' : 'off'} />;\n\n setSwitchObject({\n switchComponent,\n switchValue,\n toggleSwitch,\n });\n }\n }, [isSwitch, switchValue]);\n\n return switchObject;\n};\n\nexport const AriaMenuItem = ({ menuItem, node, state, isSelected, onClick }: AriaOptionProps): ReactElement => {\n const ref = useRef<HTMLLIElement | null>(null);\n const initialValue = isActionMenuSwitchItem(menuItem) ? menuItem.initialValue : false;\n const {\n switchComponent = undefined,\n switchValue = null,\n toggleSwitch = null,\n } = useSwitch(isActionMenuSwitchItem(menuItem), initialValue);\n\n const { menuItemProps } = useMenuItem(\n {\n ...node,\n onAction: () => {\n if (isActionMenuItem(menuItem)) {\n menuItem.onClick();\n }\n if (isActionMenuSwitchItem(menuItem)) {\n toggleSwitch?.();\n menuItem.onClick(Boolean(!switchValue));\n }\n },\n isDisabled: menuItem?.disabled || false,\n 'aria-label': typeof menuItem?.title === 'string' ? menuItem?.title : 'Menu item',\n },\n state,\n ref,\n );\n const { title, decorator, subtitle, size, style, disabled, selectionIndicator } = menuItem;\n const { isFocusVisible, focusProps } = useFocusRing();\n\n return (\n
|
|
1
|
+
{"version":3,"file":"AriaMenuItem.es.js","sources":["../../../../src/components/ActionMenu/Aria/AriaMenuItem.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useFocusRing } from '@react-aria/focus';\nimport { useMenuItem } from '@react-aria/menu';\nimport { mergeProps } from '@react-aria/utils';\nimport { type TreeState } from '@react-stately/tree';\nimport { type Node } from '@react-types/shared';\nimport { type ReactElement, useEffect, useRef, useState } from 'react';\n\nimport { type ActionMenuItemType, type ActionMenuSwitchItemType } from '@components/ActionMenu';\nimport { type MenuItemType } from '@components/Dropdown';\nimport { MenuItem } from '@components/MenuItem/MenuItem';\nimport { Switch } from '@components/Switch';\nimport { FOCUS_STYLE_INSET } from '@utilities/focusStyle';\nimport { merge } from '@utilities/merge';\n\nexport type AriaOptionProps = {\n menuItem: MenuItemType | ActionMenuItemType | ActionMenuSwitchItemType;\n node: Node<object>;\n isSelected?: boolean;\n state: TreeState<object>;\n /**\n * @deprecated Use `menuItem.onClick` instead\n * */\n onClick?: () => void;\n};\n\ninterface SwitchObject {\n switchComponent: ReactElement | undefined;\n switchValue: boolean | null;\n toggleSwitch: VoidFunction | null;\n}\n\nconst isActionMenuItem = (\n menuItem: MenuItemType | ActionMenuItemType | ActionMenuSwitchItemType,\n): menuItem is ActionMenuItemType =>\n typeof (menuItem as ActionMenuItemType).onClick !== 'undefined' && typeof menuItem.type === 'undefined';\nconst isActionMenuSwitchItem = (\n menuItem: MenuItemType | ActionMenuItemType | ActionMenuSwitchItemType,\n): menuItem is ActionMenuSwitchItemType =>\n typeof (menuItem as ActionMenuSwitchItemType).onClick !== 'undefined' && menuItem.type === 'switch';\n\nconst useSwitch = (isSwitch: boolean, initialValue: boolean) => {\n const [switchValue, setSwitchValue] = useState<boolean>(initialValue ?? false);\n const [switchObject, setSwitchObject] = useState<SwitchObject>({\n switchComponent: undefined,\n switchValue: null,\n toggleSwitch: null,\n });\n\n useEffect(() => {\n if (isSwitch) {\n const toggleSwitch = () => setSwitchValue(!switchValue);\n const switchComponent = <Switch size=\"small\" mode={switchValue ? 'on' : 'off'} />;\n\n setSwitchObject({\n switchComponent,\n switchValue,\n toggleSwitch,\n });\n }\n }, [isSwitch, switchValue]);\n\n return switchObject;\n};\n\nexport const AriaMenuItem = ({ menuItem, node, state, isSelected, onClick }: AriaOptionProps): ReactElement => {\n const ref = useRef<HTMLLIElement | null>(null);\n const initialValue = isActionMenuSwitchItem(menuItem) ? menuItem.initialValue : false;\n const {\n switchComponent = undefined,\n switchValue = null,\n toggleSwitch = null,\n } = useSwitch(isActionMenuSwitchItem(menuItem), initialValue);\n\n const { menuItemProps } = useMenuItem(\n {\n ...node,\n onAction: () => {\n if (isActionMenuItem(menuItem)) {\n menuItem.onClick();\n }\n if (isActionMenuSwitchItem(menuItem)) {\n toggleSwitch?.();\n menuItem.onClick(Boolean(!switchValue));\n }\n },\n isDisabled: menuItem?.disabled || false,\n 'aria-label': typeof menuItem?.title === 'string' ? menuItem?.title : 'Menu item',\n },\n state,\n ref,\n );\n const { title, decorator, subtitle, size, style, disabled, selectionIndicator } = menuItem;\n const { isFocusVisible, focusProps } = useFocusRing();\n\n return (\n <li\n {...mergeProps(menuItemProps, focusProps, { onClick: () => onClick?.() })}\n data-test-id=\"menu-item\"\n className={merge([\n 'tw-relative hover:tw-bg-box-neutral-hover tw-list-none tw-outline-none',\n disabled && 'tw-pointer-events-none tw-top-px',\n isFocusVisible && FOCUS_STYLE_INSET,\n ])}\n ref={ref}\n >\n <MenuItem\n title={title}\n decorator={decorator}\n subtitle={subtitle}\n size={size}\n style={style}\n disabled={disabled}\n active={isSelected}\n selectionIndicator={selectionIndicator}\n switchComponent={switchComponent}\n />\n </li>\n );\n};\nAriaMenuItem.displayName = 'FondueAriaMenuItem';\n"],"names":["isActionMenuItem","menuItem","isActionMenuSwitchItem","useSwitch","isSwitch","initialValue","switchValue","setSwitchValue","useState","switchObject","setSwitchObject","useEffect","Switch","AriaMenuItem","node","state","isSelected","onClick","ref","useRef","switchComponent","toggleSwitch","menuItemProps","useMenuItem","title","decorator","subtitle","size","style","disabled","selectionIndicator","isFocusVisible","focusProps","useFocusRing","jsx","mergeProps","merge","FOCUS_STYLE_INSET","MenuItem"],"mappings":";;;;;;;;;AAiCA,MAAMA,IAAmB,CACrBC,MAEA,OAAQA,EAAgC,UAAY,OAAe,OAAOA,EAAS,OAAS,KAC1FC,IAAyB,CAC3BD,MAEA,OAAQA,EAAsC,UAAY,OAAeA,EAAS,SAAS,UAEzFE,IAAY,CAACC,GAAmBC,MAA0B;AAC5D,QAAM,CAACC,GAAaC,CAAc,IAAIC,EAAkBH,KAAgB,EAAK,GACvE,CAACI,GAAcC,CAAe,IAAIF,EAAuB;AAAA,IAC3D,iBAAiB;AAAA,IACjB,aAAa;AAAA,IACb,cAAc;AAAA,EAAA,CACjB;AAED,SAAAG,EAAU,MAAM;AACZ,IAAIP,KAIgBM,EAAA;AAAA,MACZ,mCAHqBE,GAAO,EAAA,MAAK,SAAQ,MAAMN,IAAc,OAAO,MAAO,CAAA;AAAA,MAI3E,aAAAA;AAAA,MACA,cANiB,MAAMC,EAAe,CAACD,CAAW;AAAA,IAMlD,CACH;AAAA,EACL,GACD,CAACF,GAAUE,CAAW,CAAC,GAEnBG;AACX,GAEaI,IAAe,CAAC,EAAE,UAAAZ,GAAU,MAAAa,GAAM,OAAAC,GAAO,YAAAC,GAAY,SAAAC,QAA6C;AACrG,QAAAC,IAAMC,EAA6B,IAAI,GACvCd,IAAeH,EAAuBD,CAAQ,IAAIA,EAAS,eAAe,IAC1E;AAAA,IACF,iBAAAmB,IAAkB;AAAA,IAClB,aAAAd,IAAc;AAAA,IACd,cAAAe,IAAe;AAAA,EACf,IAAAlB,EAAUD,EAAuBD,CAAQ,GAAGI,CAAY,GAEtD,EAAE,eAAAiB,MAAkBC;AAAA,IACtB;AAAA,MACI,GAAGT;AAAA,MACH,UAAU,MAAM;AACR,QAAAd,EAAiBC,CAAQ,KACzBA,EAAS,QAAQ,GAEjBC,EAAuBD,CAAQ,MAChBoB,KAAA,QAAAA,KACfpB,EAAS,QAAgB,CAACK,CAAY;AAAA,MAE9C;AAAA,MACA,aAAYL,KAAA,gBAAAA,EAAU,aAAY;AAAA,MAClC,cAAc,QAAOA,KAAA,gBAAAA,EAAU,UAAU,WAAWA,KAAA,gBAAAA,EAAU,QAAQ;AAAA,IAC1E;AAAA,IACAc;AAAA,IACAG;AAAA,EAAA,GAEE,EAAE,OAAAM,GAAO,WAAAC,GAAW,UAAAC,GAAU,MAAAC,GAAM,OAAAC,GAAO,UAAAC,GAAU,oBAAAC,EAAuB,IAAA7B,GAC5E,EAAE,gBAAA8B,GAAgB,YAAAC,EAAW,IAAIC,EAAa;AAGhD,SAAA,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACI,GAAGC,EAAWb,GAAeU,GAAY,EAAE,SAAS,MAAMf,KAAA,gBAAAA,KAAa;AAAA,MACxE,gBAAa;AAAA,MACb,WAAWmB,EAAM;AAAA,QACb;AAAA,QACAP,KAAY;AAAA,QACZE,KAAkBM;AAAA,MAAA,CACrB;AAAA,MACD,KAAAnB;AAAA,MAEA,UAAA,gBAAAgB;AAAA,QAACI;AAAA,QAAA;AAAA,UACG,OAAAd;AAAA,UACA,WAAAC;AAAA,UACA,UAAAC;AAAA,UACA,MAAAC;AAAA,UACA,OAAAC;AAAA,UACA,UAAAC;AAAA,UACA,QAAQb;AAAA,UACR,oBAAAc;AAAA,UACA,iBAAAV;AAAA,QAAA;AAAA,MACJ;AAAA,IAAA;AAAA,EAAA;AAGZ;AACAP,EAAa,cAAc;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlurObserver.es.js","sources":["../../../src/components/RichTextEditor/BlurObserver.ts"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useEditorRef } from '@udecode/plate-core';\nimport { floatingLinkActions, useFloatingLinkSelectors } from '@udecode/plate-link';\nimport { useCallback, useEffect, useState } from 'react';\n\nimport { FLOATING_MODAL_SELECTOR } from './components';\n\nexport const BlurObserver = ({\n hideExternalFloatingModals,\n}: {\n hideExternalFloatingModals?: (editorId: string) => void;\n}) => {\n const editorRef = useEditorRef();\n const isFloatingLinkModalOpen = useFloatingLinkSelectors().isOpen(editorRef.id);\n const [isBlurObserverActive, setIsBlurObserverActive] = useState(false);\n\n const collapseFloatingModals = useCallback(() => {\n if (isFloatingLinkModalOpen) {\n floatingLinkActions.hide();\n }\n if (hideExternalFloatingModals) {\n hideExternalFloatingModals(editorRef.id);\n }\n }, [isFloatingLinkModalOpen, hideExternalFloatingModals, editorRef]);\n\n const collapseEverything = useCallback(() => {\n editorRef.
|
|
1
|
+
{"version":3,"file":"BlurObserver.es.js","sources":["../../../src/components/RichTextEditor/BlurObserver.ts"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { useEditorRef } from '@udecode/plate-core';\nimport { floatingLinkActions, useFloatingLinkSelectors } from '@udecode/plate-link';\nimport { useCallback, useEffect, useState } from 'react';\n\nimport { FLOATING_MODAL_SELECTOR } from './components';\n\nexport const BlurObserver = ({\n hideExternalFloatingModals,\n}: {\n hideExternalFloatingModals?: (editorId: string) => void;\n}) => {\n const editorRef = useEditorRef();\n const isFloatingLinkModalOpen = useFloatingLinkSelectors().isOpen(editorRef.id);\n const [isBlurObserverActive, setIsBlurObserverActive] = useState(false);\n\n const collapseFloatingModals = useCallback(() => {\n if (isFloatingLinkModalOpen) {\n floatingLinkActions.hide();\n }\n if (hideExternalFloatingModals) {\n hideExternalFloatingModals(editorRef.id);\n }\n }, [isFloatingLinkModalOpen, hideExternalFloatingModals, editorRef]);\n\n const collapseEverything = useCallback(() => {\n collapseFloatingModals();\n editorRef.deselect();\n editorRef.collapse();\n }, [editorRef, collapseFloatingModals]);\n\n useEffect(() => {\n if (!isBlurObserverActive) {\n return;\n }\n\n const handleInteractWithOutside = (event: FocusEvent | MouseEvent) => {\n const richTextEditorSelector = `[data-editor-id='${editorRef.id}']`;\n const toolbarSelector = \"[role='toolbar']\";\n const modalSelector = '[data-is-underlay]';\n\n const targetElement = event.target as HTMLElement;\n\n const isInsidePortalledModal = targetElement.closest(modalSelector);\n const isInsideNonPortalledModal = targetElement.closest(FLOATING_MODAL_SELECTOR);\n const isInsideRichTextEditor = targetElement.closest(richTextEditorSelector);\n const isInsideRichTextEditorToolbar = targetElement.closest(toolbarSelector);\n\n if ((isInsideRichTextEditor && !isInsideNonPortalledModal) || isInsideRichTextEditorToolbar) {\n collapseFloatingModals();\n } else if (!isInsideRichTextEditor && !isInsideRichTextEditorToolbar && !isInsidePortalledModal) {\n collapseEverything();\n setIsBlurObserverActive(false);\n }\n };\n\n document.addEventListener('pointerdown', handleInteractWithOutside);\n document.addEventListener('focusin', handleInteractWithOutside);\n\n return () => {\n document.removeEventListener('focusin', handleInteractWithOutside);\n document.removeEventListener('pointerdown', handleInteractWithOutside);\n };\n }, [collapseEverything, collapseFloatingModals, editorRef.id, isBlurObserverActive]);\n\n /* Only activate blur observer when the user has focused the editor\n to limit the number of active document event listeners */\n useEffect(() => {\n const richTextEditor = document.querySelector(`[data-editor-id='${editorRef.id}']`);\n\n if (!richTextEditor) {\n return;\n }\n\n const setupBlurObserver = () => {\n setIsBlurObserverActive(true);\n };\n\n richTextEditor.addEventListener('focusin', setupBlurObserver);\n\n return () => {\n richTextEditor.removeEventListener('focusin', setupBlurObserver);\n };\n }, [editorRef.id]);\n\n return null;\n};\n"],"names":["BlurObserver","hideExternalFloatingModals","editorRef","useEditorRef","isFloatingLinkModalOpen","useFloatingLinkSelectors","isBlurObserverActive","setIsBlurObserverActive","useState","collapseFloatingModals","useCallback","floatingLinkActions","collapseEverything","useEffect","handleInteractWithOutside","event","richTextEditorSelector","toolbarSelector","modalSelector","targetElement","isInsidePortalledModal","isInsideNonPortalledModal","FLOATING_MODA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AAMY,IAAiB,SAAS,cAAc,oBAAoBvB,EAAU,EAAE,IAAI;AAElF,QAAI,CAACuB;AACD;AAGJ,UAAMC,IAAoB,MAAM;AAC5B,MAAAnB,EAAwB,EAAI;AAAA,IAAA;AAGjB,WAAAkB,EAAA,iBAAiB,WAAWC,CAAiB,GAErD,MAAM;AACM,MAAAD,EAAA,oBAAoB,WAAWC,CAAiB;AAAA,IAAA;AAAA,EACnE,GACD,CAACxB,EAAU,EAAE,CAAC,GAEV;AACX;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RichTextEditor.es.js","sources":["../../../src/components/RichTextEditor/RichTextEditor.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { Plate, PlateContent, type TEditableProps } from '@udecode/plate-core';\nimport { noop } from 'lodash-es';\nimport { type KeyboardEvent, useCallback, useMemo } from 'react';\n\nimport { BlurObserver } from '@components/RichTextEditor/BlurObserver';\nimport { useMemoizedId } from '@hooks/useMemoizedId';\nimport { merge } from '@utilities/merge';\n\nimport { ContentReplacement } from './ContentReplacement';\nimport { GAP_DEFAULT, KEY_ELEMENT_BREAK_AFTER_COLUMN, type PluginComposer, defaultPlugins } from './Plugins';\nimport { Position } from './components/EditorPositioningWrapper';\nimport { RenderPlaceholder } from './components/RenderPlaceholder';\nimport { RichTextEditorProvider } from './context/RichTextEditorContext';\nimport { forceToFocusNextElement } from './helpers';\nimport { useEditorState } from './hooks';\nimport { PaddingSizes, type TreeOfNodes } from './types';\nimport { parseRawValue } from './utils';\n\nexport type RichTextEditorProps = {\n id?: string;\n placeholder?: string;\n value?: string;\n onTextChange?: (value: string) => void;\n onBlur?: (value: string) => void;\n readonly?: boolean;\n padding?: PaddingSizes;\n position?: Position;\n plugins?: PluginComposer;\n onValueChanged?: (value: TreeOfNodes | null) => void;\n border?: boolean;\n updateValueOnChange?: boolean; // Only set to true when you are sure that performance isn't an issue\n toolbarWidth?: number;\n hideExternalFloatingModals?: (editorId: string) => void;\n};\n\nexport const RichTextEditor = ({\n id,\n value,\n placeholder = '',\n readonly: readOnly = false,\n onTextChange,\n onBlur,\n padding = PaddingSizes.None,\n position = Position.FLOATING,\n plugins = defaultPlugins,\n updateValueOnChange = false,\n onValueChanged,\n border = true,\n toolbarWidth,\n hideExternalFloatingModals,\n}: RichTextEditorProps) => {\n const editorId = useMemoizedId(id);\n const { localValue, onChange, memoizedValue, config } = useEditorState({\n editorId,\n initialValue: value,\n onTextChange,\n plugins,\n onValueChanged,\n });\n const breakAfterPlugin = plugins.plugins.find((plugin) => plugin.key === KEY_ELEMENT_BREAK_AFTER_COLUMN);\n const customClass = breakAfterPlugin?.options?.customClass as string | undefined;\n const columns = customClass ? null : breakAfterPlugin?.options?.columns ?? 1;\n const columnGap = breakAfterPlugin?.options?.gap ?? GAP_DEFAULT;\n\n const style = useMemo(\n () => ({\n columns,\n columnGap,\n outline: 'none',\n }),\n [columns, columnGap],\n );\n\n const onBlurHandler = useCallback(() => {\n if (onBlur) {\n onBlur(JSON.stringify(localValue.current));\n }\n }, [onBlur, localValue]);\n\n const onKeyDownHandler = useCallback((event: KeyboardEvent<HTMLDivElement>) => {\n if (event.code === 'Tab') {\n forceToFocusNextElement(event, !event.shiftKey);\n }\n }, []);\n\n const editableProps: TEditableProps = {\n placeholder,\n renderPlaceholder: RenderPlaceholder,\n readOnly,\n onBlur: onBlurHandler,\n className: merge([padding, customClass]),\n style,\n onKeyDown: onKeyDownHandler,\n scrollSelectionIntoView: noop,\n };\n\n return (\n <RichTextEditorProvider styles={config.styles()} position={position} border={border} editorId={editorId}>\n <Plate id={editorId} onChange={onChange} plugins={config.plugins} initialValue={memoizedValue}>\n <PlateContent {...editableProps} />\n {!editableProps.readOnly && config.toolbar(toolbarWidth)}\n {config.inline()}\n {updateValueOnChange && <ContentReplacement value={parseRawValue({ editorId, raw: value, plugins })} />}\n {position === Position.FLOATING && (\n <BlurObserver hideExternalFloatingModals={hideExternalFloatingModals} />\n )}\n </Plate>\n </RichTextEditorProvider>\n );\n};\nRichTextEditor.displayName = 'FondueRichTextEditor';\n"],"names":["RichTextEditor","id","value","placeholder","readOnly","onTextChange","onBlur","padding","PaddingSizes","position","Position","plugins","defaultPlugins","updateValueOnChange","onValueChanged","border","toolbarWidth","hideExternalFloatingModals","editorId","useMemoizedId","localValue","onChange","memoizedValue","config","useEditorState","breakAfterPlugin","plugin","KEY_ELEMENT_BREAK_AFTER_COLUMN","customClass","_a","columns","_b","columnGap","_c","GAP_DEFAULT","style","useMemo","onBlurHandler","useCallback","onKeyDownHandler","event","forceToFocusNextElement","editableProps","RenderPlaceholder","merge","noop","RichTextEditorProvider","jsxs","Plate","jsx","PlateContent","ContentReplacement","parseRawValue","BlurObserver"],"mappings":";;;;;;;;;;;;;;;;;AAqCO,MAAMA,IAAiB,CAAC;AAAA,EAC3B,IAAAC;AAAA,EACA,OAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,UAAUC,IAAW;AAAA,EACrB,cAAAC;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC,IAAUC,EAAa;AAAA,EACvB,UAAAC,IAAWC,EAAS;AAAA,EACpB,SAAAC,IAAUC;AAAA,EACV,qBAAAC,IAAsB;AAAA,EACtB,gBAAAC;AAAA,EACA,QAAAC,IAAS;AAAA,EACT,cAAAC;AAAA,EACA,4BAAAC;AACJ,MAA2B;;AACjB,QAAAC,IAAWC,EAAclB,CAAE,GAC3B,EAAE,YAAAmB,GAAY,UAAAC,GAAU,eAAAC,GAAe,QAAAC,EAAA,IAAWC,EAAe;AAAA,IACnE,UAAAN;AAAA,IACA,cAAchB;AAAA,IACd,cAAAG;AAAA,IACA,SAAAM;AAAA,IACA,gBAAAG;AAAA,EAAA,CACH,GACKW,IAAmBd,EAAQ,QAAQ,KAAK,CAACe,MAAWA,EAAO,QAAQC,CAA8B,GACjGC,KAAcC,IAAAJ,KAAA,gBAAAA,EAAkB,YAAlB,gBAAAI,EAA2B,aACzCC,IAAUF,IAAc,
|
|
1
|
+
{"version":3,"file":"RichTextEditor.es.js","sources":["../../../src/components/RichTextEditor/RichTextEditor.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { Plate, PlateContent, type TEditableProps } from '@udecode/plate-core';\nimport { noop } from 'lodash-es';\nimport { type KeyboardEvent, useCallback, useMemo } from 'react';\n\nimport { BlurObserver } from '@components/RichTextEditor/BlurObserver';\nimport { useMemoizedId } from '@hooks/useMemoizedId';\nimport { merge } from '@utilities/merge';\n\nimport { ContentReplacement } from './ContentReplacement';\nimport { GAP_DEFAULT, KEY_ELEMENT_BREAK_AFTER_COLUMN, type PluginComposer, defaultPlugins } from './Plugins';\nimport { Position } from './components/EditorPositioningWrapper';\nimport { RenderPlaceholder } from './components/RenderPlaceholder';\nimport { RichTextEditorProvider } from './context/RichTextEditorContext';\nimport { forceToFocusNextElement } from './helpers';\nimport { useEditorState } from './hooks';\nimport { PaddingSizes, type TreeOfNodes } from './types';\nimport { parseRawValue } from './utils';\n\nexport type RichTextEditorProps = {\n id?: string;\n placeholder?: string;\n value?: string;\n onTextChange?: (value: string) => void;\n onBlur?: (value: string) => void;\n readonly?: boolean;\n padding?: PaddingSizes;\n position?: Position;\n plugins?: PluginComposer;\n onValueChanged?: (value: TreeOfNodes | null) => void;\n border?: boolean;\n updateValueOnChange?: boolean; // Only set to true when you are sure that performance isn't an issue\n toolbarWidth?: number;\n hideExternalFloatingModals?: (editorId: string) => void;\n};\n\nexport const RichTextEditor = ({\n id,\n value,\n placeholder = '',\n readonly: readOnly = false,\n onTextChange,\n onBlur,\n padding = PaddingSizes.None,\n position = Position.FLOATING,\n plugins = defaultPlugins,\n updateValueOnChange = false,\n onValueChanged,\n border = true,\n toolbarWidth,\n hideExternalFloatingModals,\n}: RichTextEditorProps) => {\n const editorId = useMemoizedId(id);\n const { localValue, onChange, memoizedValue, config } = useEditorState({\n editorId,\n initialValue: value,\n onTextChange,\n plugins,\n onValueChanged,\n });\n const breakAfterPlugin = plugins.plugins.find((plugin) => plugin.key === KEY_ELEMENT_BREAK_AFTER_COLUMN);\n const customClass = breakAfterPlugin?.options?.customClass as string | undefined;\n const columns = customClass ? null : (breakAfterPlugin?.options?.columns ?? 1);\n const columnGap = breakAfterPlugin?.options?.gap ?? GAP_DEFAULT;\n\n const style = useMemo(\n () => ({\n columns,\n columnGap,\n outline: 'none',\n }),\n [columns, columnGap],\n );\n\n const onBlurHandler = useCallback(() => {\n if (onBlur) {\n onBlur(JSON.stringify(localValue.current));\n }\n }, [onBlur, localValue]);\n\n const onKeyDownHandler = useCallback((event: KeyboardEvent<HTMLDivElement>) => {\n if (event.code === 'Tab') {\n forceToFocusNextElement(event, !event.shiftKey);\n }\n }, []);\n\n const editableProps: TEditableProps = {\n placeholder,\n renderPlaceholder: RenderPlaceholder,\n readOnly,\n onBlur: onBlurHandler,\n className: merge([padding, customClass]),\n style,\n onKeyDown: onKeyDownHandler,\n scrollSelectionIntoView: noop,\n };\n\n return (\n <RichTextEditorProvider styles={config.styles()} position={position} border={border} editorId={editorId}>\n <Plate id={editorId} onChange={onChange} plugins={config.plugins} initialValue={memoizedValue}>\n <PlateContent {...editableProps} />\n {!editableProps.readOnly && config.toolbar(toolbarWidth)}\n {config.inline()}\n {updateValueOnChange && <ContentReplacement value={parseRawValue({ editorId, raw: value, plugins })} />}\n {position === Position.FLOATING && (\n <BlurObserver hideExternalFloatingModals={hideExternalFloatingModals} />\n )}\n </Plate>\n </RichTextEditorProvider>\n );\n};\nRichTextEditor.displayName = 'FondueRichTextEditor';\n"],"names":["RichTextEditor","id","value","placeholder","readOnly","onTextChange","onBlur","padding","PaddingSizes","position","Position","plugins","defaultPlugins","updateValueOnChange","onValueChanged","border","toolbarWidth","hideExternalFloatingModals","editorId","useMemoizedId","localValue","onChange","memoizedValue","config","useEditorState","breakAfterPlugin","plugin","KEY_ELEMENT_BREAK_AFTER_COLUMN","customClass","_a","columns","_b","columnGap","_c","GAP_DEFAULT","style","useMemo","onBlurHandler","useCallback","onKeyDownHandler","event","forceToFocusNextElement","editableProps","RenderPlaceholder","merge","noop","RichTextEditorProvider","jsxs","Plate","jsx","PlateContent","ContentReplacement","parseRawValue","BlurObserver"],"mappings":";;;;;;;;;;;;;;;;;AAqCO,MAAMA,IAAiB,CAAC;AAAA,EAC3B,IAAAC;AAAA,EACA,OAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,UAAUC,IAAW;AAAA,EACrB,cAAAC;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC,IAAUC,EAAa;AAAA,EACvB,UAAAC,IAAWC,EAAS;AAAA,EACpB,SAAAC,IAAUC;AAAA,EACV,qBAAAC,IAAsB;AAAA,EACtB,gBAAAC;AAAA,EACA,QAAAC,IAAS;AAAA,EACT,cAAAC;AAAA,EACA,4BAAAC;AACJ,MAA2B;;AACjB,QAAAC,IAAWC,EAAclB,CAAE,GAC3B,EAAE,YAAAmB,GAAY,UAAAC,GAAU,eAAAC,GAAe,QAAAC,EAAA,IAAWC,EAAe;AAAA,IACnE,UAAAN;AAAA,IACA,cAAchB;AAAA,IACd,cAAAG;AAAA,IACA,SAAAM;AAAA,IACA,gBAAAG;AAAA,EAAA,CACH,GACKW,IAAmBd,EAAQ,QAAQ,KAAK,CAACe,MAAWA,EAAO,QAAQC,CAA8B,GACjGC,KAAcC,IAAAJ,KAAA,gBAAAA,EAAkB,YAAlB,gBAAAI,EAA2B,aACzCC,IAAUF,IAAc,SAAQG,IAAAN,KAAA,gBAAAA,EAAkB,YAAlB,gBAAAM,EAA2B,YAAW,GACtEC,MAAYC,IAAAR,KAAA,gBAAAA,EAAkB,YAAlB,gBAAAQ,EAA2B,QAAOC,GAE9CC,IAAQC;AAAA,IACV,OAAO;AAAA,MACH,SAAAN;AAAA,MACA,WAAAE;AAAA,MACA,SAAS;AAAA,IAAA;AAAA,IAEb,CAACF,GAASE,CAAS;AAAA,EAAA,GAGjBK,IAAgBC,EAAY,MAAM;AACpC,IAAIhC,KACAA,EAAO,KAAK,UAAUc,EAAW,OAAO,CAAC;AAAA,EAC7C,GACD,CAACd,GAAQc,CAAU,CAAC,GAEjBmB,IAAmBD,EAAY,CAACE,MAAyC;AACvE,IAAAA,EAAM,SAAS,SACSC,EAAAD,GAAO,CAACA,EAAM,QAAQ;AAAA,EAEtD,GAAG,CAAE,CAAA,GAECE,IAAgC;AAAA,IAClC,aAAAvC;AAAA,IACA,mBAAmBwC;AAAA,IACnB,UAAAvC;AAAA,IACA,QAAQiC;AAAA,IACR,WAAWO,EAAM,CAACrC,GAASqB,CAAW,CAAC;AAAA,IACvC,OAAAO;AAAA,IACA,WAAWI;AAAA,IACX,yBAAyBM;AAAA,EAAA;AAG7B,2BACKC,GAAuB,EAAA,QAAQvB,EAAO,OAAO,GAAG,UAAAd,GAAoB,QAAAM,GAAgB,UAAAG,GACjF,UAAC,gBAAA6B,EAAAC,GAAA,EAAM,IAAI9B,GAAU,UAAAG,GAAoB,SAASE,EAAO,SAAS,cAAcD,GAC5E,UAAA;AAAA,IAAC,gBAAA2B,EAAAC,GAAA,EAAc,GAAGR,GAAe;AAAA,IAChC,CAACA,EAAc,YAAYnB,EAAO,QAAQP,CAAY;AAAA,IACtDO,EAAO,OAAO;AAAA,IACdV,KAAwB,gBAAAoC,EAAAE,GAAA,EAAmB,OAAOC,EAAc,EAAE,UAAAlC,GAAU,KAAKhB,GAAO,SAAAS,EAAQ,CAAC,EAAG,CAAA;AAAA,IACpGF,MAAaC,EAAS,YACnB,gBAAAuC,EAACI,KAAa,4BAAApC,GAAwD;AAAA,EAAA,EAE9E,CAAA,EACJ,CAAA;AAER;AACAjB,EAAe,cAAc;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableCell.es.js","sources":["../../../src/components/Table/TableCell.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { type Key, useRef } from 'react';\n\nimport { Checkbox as CheckboxComponent, CheckboxState } from '@components/Checkbox/Checkbox';\nimport { merge } from '@utilities/merge';\n\nimport { SelectionMode } from './Table';\n\nexport enum TableCellType {\n Default = 'Default',\n Checkbox = 'Checkbox',\n}\n\nexport type TableCellProps = {\n cell: any;\n selectionMode: string;\n type?: TableCellType;\n isChecked?: boolean;\n selectedRows: Key[];\n setSelectedRows?: (ids?: Key[]) => void;\n};\n\nexport const TableCell = ({\n cell,\n selectionMode,\n type = TableCellType.Default,\n isChecked = false,\n selectedRows,\n setSelectedRows,\n}: TableCellProps) => {\n const ref = useRef<HTMLTableCellElement | null>(null);\n\n if (type === TableCellType.Checkbox) {\n const { key } = cell;\n const handleChange = () => {\n if (!setSelectedRows) {\n return;\n }\n\n if (isChecked) {\n const filteredRows = selectedRows.filter((row) => row !== cell.parentKey);\n setSelectedRows(filteredRows);\n return;\n }\n\n const rowsToSelect =\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n selectionMode === SelectionMode.SingleSelect ? [cell.parentKey] : [...selectedRows, cell.parentKey];\n setSelectedRows(rowsToSelect);\n };\n\n return (\n <td\n
|
|
1
|
+
{"version":3,"file":"TableCell.es.js","sources":["../../../src/components/Table/TableCell.tsx"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { type Key, useRef } from 'react';\n\nimport { Checkbox as CheckboxComponent, CheckboxState } from '@components/Checkbox/Checkbox';\nimport { merge } from '@utilities/merge';\n\nimport { SelectionMode } from './Table';\n\nexport enum TableCellType {\n Default = 'Default',\n Checkbox = 'Checkbox',\n}\n\nexport type TableCellProps = {\n cell: any;\n selectionMode: string;\n type?: TableCellType;\n isChecked?: boolean;\n selectedRows: Key[];\n setSelectedRows?: (ids?: Key[]) => void;\n};\n\nexport const TableCell = ({\n cell,\n selectionMode,\n type = TableCellType.Default,\n isChecked = false,\n selectedRows,\n setSelectedRows,\n}: TableCellProps) => {\n const ref = useRef<HTMLTableCellElement | null>(null);\n\n if (type === TableCellType.Checkbox) {\n const { key } = cell;\n const handleChange = () => {\n if (!setSelectedRows) {\n return;\n }\n\n if (isChecked) {\n const filteredRows = selectedRows.filter((row) => row !== cell.parentKey);\n setSelectedRows(filteredRows);\n return;\n }\n\n const rowsToSelect =\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n selectionMode === SelectionMode.SingleSelect ? [cell.parentKey] : [...selectedRows, cell.parentKey];\n setSelectedRows(rowsToSelect);\n };\n\n return (\n <td\n role=\"cell\"\n ref={ref}\n className={merge([\n 'tw-pl-8 tw-py-4 tw-pr-4 tw-relative after:tw-absolute after:tw-left-0 after:tw-top-[-1px] after:tw-bottom-[-1px] after:tw-w-1',\n isChecked ? 'after:tw-bg-box-selected-strong' : 'after:tw-bg-transparent',\n ])}\n data-test-id=\"table-select-cell\"\n >\n <CheckboxComponent\n value={key}\n aria-label={cell['aria-label'] || key}\n state={isChecked ? CheckboxState.Checked : CheckboxState.Unchecked}\n onChange={handleChange}\n />\n </td>\n );\n }\n\n return (\n <td\n role=\"cell\"\n ref={ref}\n className={merge([\n 'tw-p-4 tw-font-normal tw-text-xs focus:tw-outline-none',\n isChecked ? 'tw-text-black-100 dark:tw-text-white' : 'tw-text-black-80 dark:tw-text-black-20',\n ])}\n >\n {cell.rendered}\n </td>\n );\n};\nTableCell.displayName = 'FondueTableCell';\n"],"names":["TableCellType","TableCell","cell","selectionMode","type","isChecked","selectedRows","setSelectedRows","ref","useRef","key","handleChange","filteredRows","row","rowsToSelect","SelectionMode","jsx","merge","CheckboxComponent","CheckboxState"],"mappings":";;;;;AASY,IAAAA,sBAAAA,OACRA,EAAA,UAAU,WACVA,EAAA,WAAW,YAFHA,IAAAA,KAAA,CAAA,CAAA;AAcL,MAAMC,IAAY,CAAC;AAAA,EACtB,MAAAC;AAAA,EACA,eAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,WAAAC,IAAY;AAAA,EACZ,cAAAC;AAAA,EACA,iBAAAC;AACJ,MAAsB;AACZ,QAAAC,IAAMC,EAAoC,IAAI;AAEpD,MAAIL,MAAS,YAAwB;AAC3B,UAAA,EAAE,KAAAM,EAAQ,IAAAR,GACVS,IAAe,MAAM;AACvB,UAAI,CAACJ;AACD;AAGJ,UAAIF,GAAW;AACX,cAAMO,IAAeN,EAAa,OAAO,CAACO,MAAQA,MAAQX,EAAK,SAAS;AACxE,QAAAK,EAAgBK,CAAY;AAC5B;AAAA,MACJ;AAEM,YAAAE;AAAA;AAAA,QAEFX,MAAkBY,EAAc,eAAe,CAACb,EAAK,SAAS,IAAI,CAAC,GAAGI,GAAcJ,EAAK,SAAS;AAAA;AACtG,MAAAK,EAAgBO,CAAY;AAAA,IAAA;AAI5B,WAAA,gBAAAE;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,MAAK;AAAA,QACL,KAAAR;AAAA,QACA,WAAWS,EAAM;AAAA,UACb;AAAA,UACAZ,IAAY,oCAAoC;AAAA,QAAA,CACnD;AAAA,QACD,gBAAa;AAAA,QAEb,UAAA,gBAAAW;AAAA,UAACE;AAAAA,UAAA;AAAA,YACG,OAAOR;AAAA,YACP,cAAYR,EAAK,YAAY,KAAKQ;AAAA,YAClC,OAAOL,IAAYc,EAAc,UAAUA,EAAc;AAAA,YACzD,UAAUR;AAAA,UAAA;AAAA,QACd;AAAA,MAAA;AAAA,IAAA;AAAA,EAGZ;AAGI,SAAA,gBAAAK;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,MAAK;AAAA,MACL,KAAAR;AAAA,MACA,WAAWS,EAAM;AAAA,QACb;AAAA,QACAZ,IAAY,yCAAyC;AAAA,MAAA,CACxD;AAAA,MAEA,UAAKH,EAAA;AAAA,IAAA;AAAA,EAAA;AAGlB;AACAD,EAAU,cAAc;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projection.es.js","sources":["../../../../src/components/Tree/helpers/projection.ts"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { arrayMove } from '@dnd-kit/sortable';\nimport { type ReactElement } from 'react';\n\nimport { type InternalTreeItemProps } from '../TreeItem';\nimport { INDENTATION_WIDTH, ROOT_ID } from '../helpers';\n\nexport type ProjectionArgs = {\n nodes: ReactElement<InternalTreeItemProps>[];\n activeId: string;\n overId: string;\n dragOffset: number;\n};\n\nexport type Projection = {\n depth: number;\n maxDepth: number;\n minDepth: number;\n position: number;\n type?: string;\n accepts?: string;\n parentId: Nullable<string>;\n isWithinParent: boolean | undefined;\n previousNode: Nullable<{ id: string; depth: number; accepts?: string }>;\n};\n\nconst getNodeDepth = (node: ReactElement) => {\n return node ? node.props.level : 0;\n};\n\nconst getDragDepth = (offset: number) => {\n return Math.round(offset / INDENTATION_WIDTH);\n};\n\nconst getNodeDepthConstraint = (node: ReactElement) => {\n return (node?.props.levelConstraint ?? null) !== null ? node.props.levelConstraint : false;\n};\n\nconst calculateMaxDepth = (previousNode: ReactElement, nextNode: ReactElement) => {\n const previousNodeDepth = getNodeDepth(previousNode);\n\n if (previousNode?.props.accepts) {\n const nextNodeDepth = getNodeDepth(nextNode);\n return previousNodeDepth >= nextNodeDepth ? previousNodeDepth + 1 : nextNodeDepth;\n } else {\n return previousNodeDepth;\n }\n};\n\nconst calculateMinDepth = (previousNode: ReactElement, nextNode: ReactElement) => {\n const nextNodeDepth = getNodeDepth(nextNode);\n\n if (previousNode?.props.accepts) {\n return nextNodeDepth;\n } else {\n return Math.min(getNodeDepth(previousNode), nextNodeDepth);\n }\n};\n\nexport const getProjection = ({ nodes, activeId, overId, dragOffset }: ProjectionArgs): Projection => {\n const overNodeIndex = nodes.findIndex(({ props }) => props.id === overId);\n const activeNodeIndex = nodes.findIndex(({ props }) => props.id === activeId);\n\n const activeNode = nodes[activeNodeIndex];\n const newNodes = arrayMove(nodes, activeNodeIndex, overNodeIndex);\n\n const previousNode = newNodes[overNodeIndex - 1];\n const nextNode = newNodes[overNodeIndex + 1];\n\n const activeNodeDepthConstraint = getNodeDepthConstraint(activeNode);\n const dragDepth = getDragDepth(dragOffset);\n const projectedDepth = (activeNode?.props?.level ?? 0) + dragDepth;\n\n const maxDepth =\n activeNodeDepthConstraint !== false ? activeNodeDepthConstraint : calculateMaxDepth(previousNode, nextNode);\n const minDepth =\n activeNodeDepthConstraint !== false ? activeNodeDepthConstraint : calculateMinDepth(previousNode, nextNode);\n\n let depth = projectedDepth || getNodeDepth(nextNode);\n if (projectedDepth >= maxDepth) {\n depth = maxDepth;\n } else if (projectedDepth < minDepth) {\n depth = minDepth;\n }\n\n const getParentId = () => {\n if (depth === 0 || !previousNode) {\n return ROOT_ID;\n }\n\n if (previousNode.props.parentId && depth === previousNode.props.level) {\n return previousNode.props.parentId ?? null;\n }\n\n if (previousNode.props.level !== undefined && depth > previousNode.props.level) {\n return previousNode.props.accepts\n ? previousNode.props.id\n : previousNode.props.parentId ?? previousNode.props.id;\n }\n\n const newParent = newNodes\n .slice(0, overNodeIndex)\n .reverse()\n .find((item) => item.props.level === depth)?.props.parentId;\n\n return newParent ?? null;\n };\n\n const getParent = (parentId: Nullable<string>) => {\n if (!parentId) {\n return null;\n }\n return nodes.find(({ props }) => props.id === parentId)?.props;\n };\n\n const parentId = getParentId();\n const parent = getParent(parentId);\n\n // whether we are moving down there is a +1 offset, unless we are in the same parent\n const correctionDueDragDirection =\n activeNodeIndex < overNodeIndex && activeNode.props.parentId !== parentId ? 1 : 0;\n\n const nodesInParent = newNodes.filter(({ props }) => props.parentId === parentId);\n\n /**\n * To get the position the item is dropped within its parent (first match wins):\n * - Get the index of the active item among the parent nodes\n * - Use the 'over' item to get the position\n * - If the over element is the parent matched set it to the top\n * - If the item is going out:\n * - try to figure the position by the parent from the next element\n * - Or go to the first (going down) or last position (going up)\n * - if we move the item in or same depth and up it goes to the last position\n */\n let dropIndexInParent = nodesInParent.findIndex(({ props }) => props.id === activeId);\n\n if (dropIndexInParent < 0) {\n const overNextIndex = nodesInParent.findIndex(({ props }) => props.id === overId);\n if (overNextIndex >= 0) {\n dropIndexInParent = overNextIndex;\n } else if (parentId === overId) {\n dropIndexInParent = -1;\n } else if (dragDepth < 0) {\n const nextNodeNodesInParent = nextNode.props.parentId\n ? newNodes.filter(({ props }) => props.parentId === nextNode.props.parentId)\n : [];\n const nextNodePosition = nextNodeNodesInParent.findIndex(({ props }) => props.id === nextNode.props.id);\n if (nextNodePosition >= 0) {\n dropIndexInParent = nextNodePosition + (activeNodeIndex < overNodeIndex ? -1 : 0);\n } else {\n dropIndexInParent = activeNodeIndex < overNodeIndex ? nodesInParent.length : -1;\n }\n } else if (activeNodeIndex >= overNodeIndex) {\n dropIndexInParent = nodesInParent.length;\n }\n }\n\n dropIndexInParent = dropIndexInParent + correctionDueDragDirection;\n const parentDepth = parent?.level ?? 0;\n\n return {\n depth,\n maxDepth,\n minDepth,\n parentId: parentId ?? null,\n type: parent?.type,\n accepts: parent?.accepts,\n position: dropIndexInParent >= 0 ? dropIndexInParent : 0,\n isWithinParent: parentDepth ? depth > parentDepth : false,\n previousNode: previousNode\n ? {\n id: previousNode.props.id,\n depth: getNodeDepth(previousNode),\n accepts: previousNode.props.accepts,\n }\n : null,\n };\n};\n"],"names":["getNodeDepth","node","getDragDepth","offset","INDENTATION_WIDTH","getNodeDepthConstraint","calculateMaxDepth","previousNode","nextNode","previousNodeDepth","nextNodeDepth","calculateMinDepth","getProjection","nodes","activeId","overId","dragOffset","overNodeIndex","props","activeNodeIndex","activeNode","newNodes","arrayMove","activeNodeDepthConstraint","dragDepth","projectedDepth","_a","maxDepth","minDepth","depth","getParentId","ROOT_ID","item","getParent","parentId","parent","correctionDueDragDirection","nodesInParent","dropIndexInParent","overNextIndex","nextNodePosition","parentDepth"],"mappings":";;AA2BA,MAAMA,IAAe,CAACC,MACXA,IAAOA,EAAK,MAAM,QAAQ,GAG/BC,IAAe,CAACC,MACX,KAAK,MAAMA,IAASC,CAAiB,GAG1CC,IAAyB,CAACJ,QACpBA,KAAA,gBAAAA,EAAM,MAAM,oBAAmB,UAAU,OAAOA,EAAK,MAAM,kBAAkB,IAGnFK,IAAoB,CAACC,GAA4BC,MAA2B;AACxE,QAAAC,IA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,KAAK,KAE3DqB,IAAAnB,IAAkBF,IAAgBoB,EAAc,SAAS;AAAA,IACjF,MACJ,CAAWlB,KAAmBF,MAC1BqB,IAAoBD,EAAc;AAAA,EAE1C;AAEA,EAAAC,IAAoBA,IAAoBF;AAClC,QAAAK,KAAcN,KAAA,gBAAAA,EAAQ,UAAS;AAE9B,SAAA;AAAA,IACH,OAAAN;AAAA,IACA,UAAAF;AAAA,IACA,UAAAC;AAAA,IACA,UAAUM,KAAY;AAAA,IACtB,MAAMC,KAAA,gBAAAA,EAAQ;AAAA,IACd,SAASA,KAAA,gBAAAA,EAAQ;AAAA,IACjB,UAAUG,KAAqB,IAAIA,IAAoB;AAAA,IACvD,gBAAgBG,IAAcZ,IAAQY,IAAc;AAAA,IACpD,cAAclC,IACR;AAAA,MACI,IAAIA,EAAa,MAAM;AAAA,MACvB,OAAOP,EAAaO,CAAY;AAAA,MAChC,SAASA,EAAa,MAAM;AAAA,IAAA,IAEhC;AAAA,EAAA;AAEd;"}
|
|
1
|
+
{"version":3,"file":"projection.es.js","sources":["../../../../src/components/Tree/helpers/projection.ts"],"sourcesContent":["/* (c) Copyright Frontify Ltd., all rights reserved. */\n\nimport { arrayMove } from '@dnd-kit/sortable';\nimport { type ReactElement } from 'react';\n\nimport { type InternalTreeItemProps } from '../TreeItem';\nimport { INDENTATION_WIDTH, ROOT_ID } from '../helpers';\n\nexport type ProjectionArgs = {\n nodes: ReactElement<InternalTreeItemProps>[];\n activeId: string;\n overId: string;\n dragOffset: number;\n};\n\nexport type Projection = {\n depth: number;\n maxDepth: number;\n minDepth: number;\n position: number;\n type?: string;\n accepts?: string;\n parentId: Nullable<string>;\n isWithinParent: boolean | undefined;\n previousNode: Nullable<{ id: string; depth: number; accepts?: string }>;\n};\n\nconst getNodeDepth = (node: ReactElement) => {\n return node ? node.props.level : 0;\n};\n\nconst getDragDepth = (offset: number) => {\n return Math.round(offset / INDENTATION_WIDTH);\n};\n\nconst getNodeDepthConstraint = (node: ReactElement) => {\n return (node?.props.levelConstraint ?? null) !== null ? node.props.levelConstraint : false;\n};\n\nconst calculateMaxDepth = (previousNode: ReactElement, nextNode: ReactElement) => {\n const previousNodeDepth = getNodeDepth(previousNode);\n\n if (previousNode?.props.accepts) {\n const nextNodeDepth = getNodeDepth(nextNode);\n return previousNodeDepth >= nextNodeDepth ? previousNodeDepth + 1 : nextNodeDepth;\n } else {\n return previousNodeDepth;\n }\n};\n\nconst calculateMinDepth = (previousNode: ReactElement, nextNode: ReactElement) => {\n const nextNodeDepth = getNodeDepth(nextNode);\n\n if (previousNode?.props.accepts) {\n return nextNodeDepth;\n } else {\n return Math.min(getNodeDepth(previousNode), nextNodeDepth);\n }\n};\n\nexport const getProjection = ({ nodes, activeId, overId, dragOffset }: ProjectionArgs): Projection => {\n const overNodeIndex = nodes.findIndex(({ props }) => props.id === overId);\n const activeNodeIndex = nodes.findIndex(({ props }) => props.id === activeId);\n\n const activeNode = nodes[activeNodeIndex];\n const newNodes = arrayMove(nodes, activeNodeIndex, overNodeIndex);\n\n const previousNode = newNodes[overNodeIndex - 1];\n const nextNode = newNodes[overNodeIndex + 1];\n\n const activeNodeDepthConstraint = getNodeDepthConstraint(activeNode);\n const dragDepth = getDragDepth(dragOffset);\n const projectedDepth = (activeNode?.props?.level ?? 0) + dragDepth;\n\n const maxDepth =\n activeNodeDepthConstraint !== false ? activeNodeDepthConstraint : calculateMaxDepth(previousNode, nextNode);\n const minDepth =\n activeNodeDepthConstraint !== false ? activeNodeDepthConstraint : calculateMinDepth(previousNode, nextNode);\n\n let depth = projectedDepth || getNodeDepth(nextNode);\n if (projectedDepth >= maxDepth) {\n depth = maxDepth;\n } else if (projectedDepth < minDepth) {\n depth = minDepth;\n }\n\n const getParentId = () => {\n if (depth === 0 || !previousNode) {\n return ROOT_ID;\n }\n\n if (previousNode.props.parentId && depth === previousNode.props.level) {\n return previousNode.props.parentId ?? null;\n }\n\n if (previousNode.props.level !== undefined && depth > previousNode.props.level) {\n return previousNode.props.accepts\n ? previousNode.props.id\n : (previousNode.props.parentId ?? previousNode.props.id);\n }\n\n const newParent = newNodes\n .slice(0, overNodeIndex)\n .reverse()\n .find((item) => item.props.level === depth)?.props.parentId;\n\n return newParent ?? null;\n };\n\n const getParent = (parentId: Nullable<string>) => {\n if (!parentId) {\n return null;\n }\n return nodes.find(({ props }) => props.id === parentId)?.props;\n };\n\n const parentId = getParentId();\n const parent = getParent(parentId);\n\n // whether we are moving down there is a +1 offset, unless we are in the same parent\n const correctionDueDragDirection =\n activeNodeIndex < overNodeIndex && activeNode.props.parentId !== parentId ? 1 : 0;\n\n const nodesInParent = newNodes.filter(({ props }) => props.parentId === parentId);\n\n /**\n * To get the position the item is dropped within its parent (first match wins):\n * - Get the index of the active item among the parent nodes\n * - Use the 'over' item to get the position\n * - If the over element is the parent matched set it to the top\n * - If the item is going out:\n * - try to figure the position by the parent from the next element\n * - Or go to the first (going down) or last position (going up)\n * - if we move the item in or same depth and up it goes to the last position\n */\n let dropIndexInParent = nodesInParent.findIndex(({ props }) => props.id === activeId);\n\n if (dropIndexInParent < 0) {\n const overNextIndex = nodesInParent.findIndex(({ props }) => props.id === overId);\n if (overNextIndex >= 0) {\n dropIndexInParent = overNextIndex;\n } else if (parentId === overId) {\n dropIndexInParent = -1;\n } else if (dragDepth < 0) {\n const nextNodeNodesInParent = nextNode.props.parentId\n ? newNodes.filter(({ props }) => props.parentId === nextNode.props.parentId)\n : [];\n const nextNodePosition = nextNodeNodesInParent.findIndex(({ props }) => props.id === nextNode.props.id);\n if (nextNodePosition >= 0) {\n dropIndexInParent = nextNodePosition + (activeNodeIndex < overNodeIndex ? -1 : 0);\n } else {\n dropIndexInParent = activeNodeIndex < overNodeIndex ? nodesInParent.length : -1;\n }\n } else if (activeNodeIndex >= overNodeIndex) {\n dropIndexInParent = nodesInParent.length;\n }\n }\n\n dropIndexInParent = dropIndexInParent + correctionDueDragDirection;\n const parentDepth = parent?.level ?? 0;\n\n return {\n depth,\n maxDepth,\n minDepth,\n parentId: parentId ?? null,\n type: parent?.type,\n accepts: parent?.accepts,\n position: dropIndexInParent >= 0 ? dropIndexInParent : 0,\n isWithinParent: parentDepth ? depth > parentDepth : false,\n previousNode: previousNode\n ? {\n id: previousNode.props.id,\n depth: getNodeDepth(previousNode),\n accepts: previousNode.props.accepts,\n }\n : null,\n };\n};\n"],"names":["getNodeDepth","node","getDragDepth","offset","INDENTATION_WIDTH","getNodeDepthConstraint","calculateMaxDepth","previousNode","nextNode","previousNodeDepth","nextNodeDepth","calculateMinDepth","getProjection","nodes","activeId","overId","dragOffset","overNodeIndex","props","activeNodeIndex","activeNode","newNodes","arrayMove","activeNodeDepthConstraint","dragDepth","projectedDepth","_a","maxDepth","minDepth","depth","getParentId","ROOT_ID","item","getParent","parentId","parent","correctionDueDragDirection","nodesInParent","dropIndexInParent","overNextIndex","nextNodePosition","parentDepth"],"mappings":";;AA2BA,MAAMA,IAAe,CAACC,MACXA,IAAOA,EAAK,MAAM,QAAQ,GAG/BC,IAAe,CAACC,MACX,KAAK,MAAMA,IAASC,CAAiB,GAG1CC,IAAyB,CAACJ,QACpBA,KAAA,gBAAAA,EAAM,MAAM,oBAAmB,UAAU,OAAOA,EAAK,MAAM,kBAAkB,IAGnFK,IAAoB,CAACC,GAA4BC,MAA2B;AACxE,QAAAC,IAAoBT,EAAaO,CAAY;AAE/C,MAAAA,KAAA,QAAAA,EAAc,MAAM,SAAS;AACvB,UAAAG,IAAgBV,EAAaQ,CAAQ;AACpC,WAAAC,KAAqBC,IAAgBD,IAAoB,IAAIC;AAAA,EAAA;AAE7D,WAAAD;AAEf,GAEME,IAAoB,CAACJ,GAA4BC,MAA2B;AACxE,QAAAE,IAAgBV,EAAaQ,CAAQ;AAEvC,SAAAD,KAAA,QAAAA,EAAc,MAAM,UACbG,IAEA,KAAK,IAAIV,EAAaO,CAAY,GAAGG,CAAa;AAEjE,GAEaE,IAAgB,CAAC,EAAE,OAAAC,GAAO,UAAAC,GAAU,QAAAC,GAAQ,YAA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,IACvD,gBAAgBG,IAAcZ,IAAQY,IAAc;AAAA,IACpD,cAAclC,IACR;AAAA,MACI,IAAIA,EAAa,MAAM;AAAA,MACvB,OAAOP,EAAaO,CAAY;AAAA,MAChC,SAASA,EAAa,MAAM;AAAA,IAAA,IAEhC;AAAA,EAAA;AAEd;"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -10,7 +10,7 @@ ${H1("Ctrl+I")}`),nodeType:k.getPluginType(e,l),children:t.jsx(C0,{icon:t.jsx(y7
|
|
|
10
10
|
${H1("Ctrl+.")}`),nodeType:k.getPluginType(e,l),clear:k.getPluginType(e,c0.MARK_SUPERSCRIPT),children:t.jsx(C0,{icon:t.jsx(C7,{})})})}),RV=({attributes:e,children:l})=>t.jsx("sub",{...e,children:l});class HV extends s0{constructor(l=c0.MARK_SUBSCRIPT,s=RV){super(l,s)}}const Uu0="subscript-plugin";class Wu0 extends a0{constructor(l){super(Uu0,{button:qu0,markupElement:new HV,...l})}plugins(){return[c0.createSubscriptPlugin({options:{hotkey:["mod+.","ctrl+."]}})]}}const Gu0=({editor:e,id:l})=>t.jsx(j0,{id:l,children:t.jsx(x1,{tooltip:z0(`Superscript
|
|
11
11
|
${H1("Ctrl+,")}`),nodeType:k.getPluginType(e,l),clear:k.getPluginType(e,c0.MARK_SUBSCRIPT),children:t.jsx(C0,{icon:t.jsx(j7,{})})})}),kV=({attributes:e,children:l})=>t.jsx("sup",{...e,children:l});class TV extends s0{constructor(l=c0.MARK_SUPERSCRIPT,s=kV){super(l,s)}}const Ku0="superscript-plugin";class Qu0 extends a0{constructor(l){super(Ku0,{button:Gu0,markupElement:new TV,...l})}plugins(){return[c0.createSuperscriptPlugin({options:{hotkey:["mod+,","ctrl+,"]}})]}}const Xu0=({editor:e,id:l})=>t.jsx(j0,{id:l,children:t.jsx(x1,{tooltip:z0(`Underline
|
|
12
12
|
${H1("Ctrl+U")}`),nodeType:k.getPluginType(e,l),children:t.jsx(C0,{icon:t.jsx(b7,{})})})}),Z5="tw-underline",VV=({attributes:e,children:l})=>t.jsx("span",{...e,className:Z5,children:l});class FV extends s0{constructor(l=c0.MARK_UNDERLINE,s=VV){super(l,s)}}const Yu0="underline-plugin",Ju0=[{validNodeName:["U"]},{validStyle:{textDecoration:["underline"]}}];class PV extends a0{constructor(l){super(Yu0,{button:Xu0,markupElement:new FV,...l})}plugins(){return[c0.createUnderlinePlugin({deserializeHtml:{rules:[...Ju0,{validNodeName:["SPAN"],validClassName:Z5}]},options:{hotkey:["mod+u","ctrl+u"]}})]}}class Eu0{constructor(){Y(this,"toolbarButtons",{[x0.BOTTOM]:[],[x0.FLOATING]:[],[x0.TOP]:[]})}createGroupOfButtons(l){const s=[],o=[],c=[];for(const{markupElement:r,button:i,id:d,showIn:u}of l){if(!i)continue;const m={id:(r==null?void 0:r.getId())||d,button:i};u.includes(x0.BOTTOM)&&s.push(m),u.includes(x0.TOP)&&o.push(m),u.includes(x0.FLOATING)&&c.push(m)}s.length>0&&this.toolbarButtons[x0.BOTTOM].push(s),o.length>0&&this.toolbarButtons[x0.TOP].push(o),c.length>0&&this.toolbarButtons[x0.FLOATING].push(c)}at(l){return this.toolbarButtons[l]}}class BV{constructor(l){Y(this,"platePlugins",new Map);Y(this,"markupElements",{});Y(this,"inlineElements",[]);Y(this,"toolbarButtons",new Eu0);Y(this,"styles",{});this.props=l}setPlugin(...l){for(const s of l){const o=Array.isArray(s)?s:[s];for(const c of o)this.addElement(c.markupElement),this.addElement(c.markupInputElement),this.addLeafElements(c.leafMarkupElements),this.addPlugin(c),this.addInline(c.inline()),c.styles&&this.addStyles(c.styles,c.id),c.textStyles&&this.addTextStylesOfSubPlugins(c.textStyles);this.hasToolbar&&this.toolbarButtons.createGroupOfButtons(o)}return this}addTextStylesOfSubPlugins(l){for(const s of l)s.styles&&this.addStyles(s.styles,s.id)}addLeafElements(l){if(l===void 0)return;const s=Array.isArray(l)?l:[l];for(const o of s)this.addElement(o)}addElement(l){if(l===void 0)return;const s=l.getId(),o=l.getNode();o&&!this.markupElements[s]&&(this.markupElements[s]=o)}addPlugin(l){l.id&&!this.platePlugins.has(l.id)&&this.platePlugins.set(l.id,l.plugins())}addInline(l){l&&this.inlineElements.push(l)}addStyles(l,s){this.styles[s]=l}get elements(){return{...this.defaultElementsFromPlugins,...this.markupElements}}get defaultElementsFromPlugins(){const l={};for(const s of this.platePlugins.values())for(const o of s){const{key:c,component:r}=o;r&&(l[c]=r)}return l}get plugins(){const l=[];for(const s of this.platePlugins.values())l.push(...s);return l}get buttons(){return this.toolbarButtons}get inline(){return this.inlineElements}get hasToolbar(){var l;return!((l=this.props)!=null&&l.noToolbar)}get getStyles(){return this.styles}}const em0=e=>{!e||!e.selection||(c1.removeMark(e,{key:[c0.MARK_BOLD,c0.MARK_ITALIC,c0.MARK_CODE,c0.MARK_UNDERLINE,c0.MARK_STRIKETHROUGH]}),Q.unwrapList(e,{}),Z.setElements(e,{type:w1.ELEMENT_PARAGRAPH,align:void 0}))},tm0=({id:e,...l})=>{const s=k.useEditorState(k.useEventPlateId(e));return t.jsx(E0,{tooltip:z0("Clear formatting"),onPointerDown:o=>{o.preventDefault(),em0(s)},...l,children:t.jsx(C0,{icon:t.jsx(m7,{})})})},lm0=({id:e})=>t.jsx(j0,{id:e,children:t.jsx(tm0,{id:e})}),$V="reset-formatting-plugin",DV="reset-formatting",OV=k.createPluginFactory({key:DV,isElement:!1});class ZV extends a0{constructor(l){super($V,{button:lm0,...l})}plugins(){return[OV()]}}const nm0="soft-break-plugin";class _V extends a0{constructor(l){super(nm0,{...l})}plugins(){return[jP.createSoftBreakPlugin()]}}const a2=new BV;a2.setPlugin(new _V).setPlugin(new cV({textStyles:[new nV]})).setPlugin([new jV,new SV,new PV,new bV,new KT,new pV],[new BT,new PT,new DT,new $T,new vV,new FT,new hV,new ZV,new UT]);class h2{static getInstance(){return this.editor===void 0&&this.init(),this.editor}static init(l=M1(),s=a2){const o=d7(l,s);return this.editor=k.createPlateEditor({id:l,plugins:o.plugins}),this}}Y(h2,"editor"),Y(h2,"editorId",M1());const am0=e=>"type"in e[0]?e:[{type:"p",children:e}],qV=[{type:w1.ELEMENT_PARAGRAPH,children:[{text:""}]}],A2=({editorId:e="parseRawValue",raw:l,plugins:s})=>{const o=h2.init(`${e}_parseRawValue`,s).getInstance();let c=qV;if(!l)return c;try{c=JSON.parse(l)}catch{const r=l.trim().replaceAll(/>\s+</g,"><"),i=k.deserializeHtml(o,{element:r});c=am0(i)}return o.children=c,Z.normalizeEditor(o,{force:!0}),o.children},Z2=e=>e&&typeof e=="object"&&!Array.isArray(e),UV=(e,l)=>{if(!Z2(e)||!Z2(l))return{};const s=Object.assign({},e);for(const o of Object.keys(l)){if(o in e&&Z2(l[o])){s[o]=UV(e[o],l[o]);continue}Object.assign(s,{[o]:l[o]})}return s},sm0=e=>"type"in e&&typeof e.type=="string"&&e.type.length>0,om0=e=>"children"in e&&Array.isArray(e.children)&&e.children.length===1,cm0=e=>typeof e=="object"&&"text"in e&&typeof e.text=="string"&&e.text.length===0,rm0=e=>om0(e)&&cm0(e.children[0]),im0=e=>{if(!e)return!0;if(Array.isArray(e)&&e.length<2){if(e.length===0)return!0;const l=e[0];if(sm0(l)&&rm0(l))return!0}return!1},q7=n.createContext({styles:H0,position:x0.FLOATING,wrapperClassNames:"",editorId:""}),k1=()=>n.useContext(q7),WV=({children:e,styles:l,position:s,border:o,editorId:c})=>{const r=n.useMemo(()=>({styles:l,editorId:c,position:s,wrapperClassNames:C9(s,o)}),[l,c,s,o]);return t.jsx(q7.Provider,{value:r,children:t.jsx(nF,{children:e})})},GV=n.forwardRef(({children:e},l)=>{const{wrapperClassNames:s,editorId:o}=k1();return t.jsx("div",{"data-editor-id":o,"data-test-id":"rich-text-editor",className:s,ref:l,children:e})});GV.displayName="PlateWrapper";const dm0="autoformat-plugin";class um0 extends a0{constructor(l){super(dm0,{...l})}plugins(){return[l1.createAutoformatPlugin({options:{rules:[...l1.autoformatPunctuation,...l1.autoformatArrow,...l1.autoformatLegal,...l1.autoformatSubscriptNumbers,...l1.autoformatSubscriptSymbols,...l1.autoformatSuperscriptNumbers,...l1.autoformatSuperscriptSymbols,...l1.autoformatFraction,{mode:"mark",type:[c0.MARK_UNDERLINE],match:["_","_"],ignoreTrim:!0},{mode:"mark",type:[c0.MARK_BOLD],match:["**","**"],ignoreTrim:!0},{mode:"mark",type:[c0.MARK_ITALIC],match:["*","*"],ignoreTrim:!0},{mode:"mark",type:[c0.MARK_STRIKETHROUGH],match:["~~","~~"],ignoreTrim:!0},{mode:"mark",type:[c0.MARK_CODE],match:["`","`"],ignoreTrim:!0},{mode:"block",match:["# "],type:O.heading1},{mode:"block",match:["## "],type:O.heading2},{mode:"block",match:["### "],type:O.heading3},{mode:"block",match:["#### "],type:O.heading4},{mode:"block",type:Q.ELEMENT_UL,match:["- "],preFormat:Q.unwrapList,format:l=>Q.toggleList(l,{type:Q.ELEMENT_UL})},{mode:"block",type:Q.ELEMENT_OL,match:["1. ","1) "],preFormat:Q.unwrapList,format:l=>Q.toggleList(l,{type:Q.ELEMENT_OL})},{mode:"block",type:e1,match:["[] "]}]}})]}}const KV=e=>Array.from(Z.getNodeEntries(e,{at:[],match:l=>!!l.breakAfterColumn})).length,w2=(e,{key:l=s2,value:s,at:o})=>{const c=r=>Z.isBlock(e,r);s?Z.setElements(e,{[l]:s},{mode:"lowest",match:c,at:o}):Z.unsetNodes(e,l,{match:c,mode:"lowest",at:o})},mm0=(e,l,s)=>{w2(e,{at:l,value:s})},fe=(e,l)=>{const s=Array.from(Z.getNodeEntries(e,{at:[],match:o=>!!o.breakAfterColumn}));for(const[o,[,c]]of s.entries())mm0(e,c,o<l-1?"active":"inactive")},QV=(e,l,s)=>{if(s.preventDefault(),s.stopPropagation(),!!(e!=null&&e.selection)&&Z.someNode(e,{match:c=>!!c.breakAfterColumn}))w2(e,{value:void 0});else{const c=KV(e),r=Math.max(l-c-1,0);if(r===0)return;const i=Array.from(Z.getNodeEntries(e,{at:e.selection,match:d=>Z.isBlock(e,d),mode:"lowest"})).slice(-r);for(const d of i)w2(e,{value:"active",at:d[1]})}fe(e,l)},Lm0=(e,{options:{hotkey:l}})=>s=>{var o;if(!s.defaultPrevented&&l&&k.isHotkey(l,s)){const c=e.plugins.find(i=>i.key===s2),r=((o=c==null?void 0:c.options)==null?void 0:o.columns)??1;QV(e,r,s)}},hm0=({id:e,...l})=>{var d,u;const s=k.useEditorState(k.useEventPlateId(e)),o=!!(s!=null&&s.selection)&&Z.someNode(s,{match:m=>!!m.breakAfterColumn}),c=(u=(d=s==null?void 0:s.pluginsByKey.breakAfterColumn)==null?void 0:d.options)==null?void 0:u.columns,r=Number(c)||1,i=wm0(s,r,o);return t.jsx(E0,{disabled:!i,pressed:!o,tooltip:z0(i?`Column Break
|
|
13
|
-
Shift+Ctrl+Return`:"Already at maximum numbers of columns"),onPointerDown:m=>m.preventDefault(),onClick:m=>{QV(s,r,m)},...l,children:t.jsx(C0,{icon:t.jsx(P5,{})})})},wm0=(e,l,s)=>KV(e)+1<l||s,XV=({id:e})=>t.jsx(j0,{id:e,children:t.jsx(hm0,{children:t.jsx(C0,{icon:t.jsx(P5,{})})})}),fm0=(e,l)=>{const s=Z.getStartPoint(e,l);setTimeout(()=>{Z.select(e,{anchor:s,focus:s})})},xm0=e=>{var s;const l=e.plugins.find(o=>o.key===s2);return((s=l==null?void 0:l.options)==null?void 0:s.columns)??1},vm0=e=>{const{apply:l}=e,s=xm0(e);e.apply=o=>{switch(o.type){case"split_node":{o.properties={...o.properties,breakAfterColumn:void 0};break}case"merge_node":{const c=Z.getPointBefore(e,o.path);if(!c)break;const r=Z.getParentNode(e,c.path);if(w2(e,{at:c,value:void 0}),fe(e,s),r!=null&&r[0].breakAfterColumn)return fm0(e,o.path),e;break}}l(o)},setTimeout(()=>fe(e,s))},s2="breakAfterColumn",U7="normal";class gm0 extends a0{constructor(s){super("break-after-plugin",{button:XV,...s});Y(this,"columns");Y(this,"gap");Y(this,"customClass");this.columns=(s==null?void 0:s.columns)??1,this.gap=(s==null?void 0:s.gap)??U7,this.customClass=s==null?void 0:s.customClass}plugins(){return[YV(this.columns,this.gap,this.customClass)]}}const YV=(e,l,s)=>k.createPluginFactory({key:s2,handlers:{onKeyDown:Lm0},useHooks:vm0,options:{columns:e,gap:l,customClass:s,hotkey:["shift+ctrl+enter"]}})();var n1=(e=>(e.GROUP="group",e.ALL="all",e.USER="user",e))(n1||{});const Cm0=({image:e,category:l,text:s,id:o})=>{if(e)return t.jsx("img",{src:e,alt:`${o}-${l}-${s}`});switch(l){case n1.GROUP:return t.jsx(F5,{});case n1.ALL:return t.jsx(I7,{});default:return t.jsx(g7,{})}},jm0=({item:e})=>{const{data:{image:l,category:s},key:o,text:c}=e;return t.jsxs("div",{className:"tw-flex tw-items-center tw-w-full tw-min-h-[inherit]",children:[t.jsx("span",{className:"tw-flex tw-items-center tw-justify-center tw-rounded-full tw-mr-2.5 tw-bg-base-alt tw-border tw-border-line-weak tw-w-[22px] tw-h-[22px] tw-shrink-0 tw-overflow-hidden group-hover:tw-border-base group-aria-selected:tw-border-base",children:t.jsx(Cm0,{image:l,category:s,text:c,id:o})}),t.jsx("span",{className:"tw-whitespace-nowrap tw-overflow-hidden tw-text-ellipsis",children:c})]})};function Im0({pluginKey:e=p1.ELEMENT_MENTION,id:l=e,...s}){const o=k.useEditorRef(),{trigger:c}=k.getPluginOptions(o,e);return t.jsx(qT,{id:l,trigger:c,controlled:!0,onSelectItem:(r,i)=>p1.getMentionOnSelectItem({key:e})(o,i),onRenderItem:jm0,...s})}const Nm0=e=>l=>l.text.toLowerCase().includes(e.toLowerCase()),W7=(e,l)=>`${e}:${l}`,G7=e=>{const l=new Map;for(const s of e){const o=W7(s.data.category,s.data.id),c=s.text;l.set(o,c)}return l},JV=(e,l,s)=>e.get(l)??s,pm0=e=>()=>t.jsx(Im0,{items:e,filter:Nm0}),EV=n.forwardRef(({className:e,onClick:l,...s},o)=>{const{children:c,element:r}=s;return t.jsx(te.PlateElement,{ref:o,asChild:!0,"data-slate-value":r.value,className:f(["tw-inline-block tw-rounded-sm tw-shadow-none tw-font-bold tw-leading-[10px] tw-m-0 tw-py-0.5 tw-px-1.5 tw-text-[rgb(130,95,255)] tw-bg-[rgb(227,232,246)]",e]),onClick:pe.getHandler(l,r),...s,children:t.jsx("span",{children:c})})});EV.displayName="MentionInputElement";const Mm0=e=>t.jsx(EV,{...e});class zm0 extends s0{constructor(l=p1.ELEMENT_MENTION_INPUT,s=Mm0){super(l,s)}}const K7=({attributes:e,element:l,nodeProps:s,children:o})=>t.jsx("span",{...e,dir:"auto","data-slate-value":l==null?void 0:l.value,"data-slate-key":l==null?void 0:l.key,"data-slate-category":l==null?void 0:l.category,contentEditable:!1,style:{lineHeight:"10px",padding:"1px",margin:"0 1px",fontWeight:"bold",verticalAlign:"baseline",display:"inline-block",borderRadius:"2px",backgroundColor:"rgb(227, 232, 246)",color:"rgb(130, 95, 255)"},...s,children:o}),Sm0=({children:e,...l})=>t.jsxs(K7,{...l,children:[t.jsx("span",{style:{paddingRight:"3px",display:"inline-block",margin:"-1px 0"},children:t.jsx(F5,{})}),e]}),Am0=({children:e,...l})=>t.jsxs(K7,{...l,children:["@",e]}),ym0=({children:e,...l})=>t.jsx(K7,{...l,children:e}),bm0=({category:e,children:l,...s})=>{const o={[n1.USER]:ym0,[n1.GROUP]:Sm0,[n1.ALL]:Am0},c=o[e]??o[n1.USER];return t.jsx(c,{...s,children:l})},Q7=e=>l=>{const{element:s,children:o}=l,c=W7(s==null?void 0:s.category,String(s==null?void 0:s.id));return t.jsxs(bm0,{category:s==null?void 0:s.category,...l,children:[JV(e,c,String(s==null?void 0:s.id)),o]})};class eF extends s0{constructor(l=p1.ELEMENT_MENTION){super(l)}setNodeWithMentionable(l){return this.node=Q7(G7(l)),this}}const Rm0={options:{trigger:"@",insertSpaceAfterMention:!0,createMentionNode:e=>({value:e.text,category:e.data.category,id:e.data.id})}},Hm0="mention-plugin";class km0 extends a0{constructor(l){super(Hm0,{markupElement:new eF().setNodeWithMentionable(l.mentionableItems),markupInputElement:new zm0,...l})}inline(){var l;return pm0(((l=this.props)==null?void 0:l.mentionableItems)||[])}plugins(){return[P0.createComboboxPlugin(),p1.createMentionPlugin(Rm0)]}}const Tm0=(e,{options:{onBreak:l=()=>{}}})=>s=>{k.Hotkeys.isSplitBlock(s)&&(s.stopPropagation(),s.preventDefault(),x9(),typeof l=="function"&&l(e.children))},Vm0="blurOnBreak",Fm0=k.createPluginFactory({key:Vm0,handlers:{onKeyDown:Tm0}}),Pm0="blur-on-break-plugin";class Bm0 extends a0{constructor(s){super(Pm0,{...s});Y(this,"onBreak");this.onBreak=s==null?void 0:s.onBreak}plugins(){return[Fm0({options:{onBreak:this.onBreak}})]}}const $m0=({editorId:e,initialValue:l,plugins:s,onTextChange:o,onValueChanged:c})=>{const r=n.useRef(null),i=n.useCallback(h=>{o&&o(JSON.stringify(h))},[o]),d=t5(i,I9),u=n.useCallback(h=>{d(h),r.current=h,c&&c(h)},[d,r,c]),m=n.useMemo(()=>A2({editorId:e,raw:l,plugins:s}),[e]),L=n.useMemo(()=>d7(e,s),[e,s]);return{localValue:r,onChange:u,memoizedValue:m,config:L}},Dm0=()=>{const[e,l]=n.useState(0),s=n.useRef(o3(c=>l(c)));return{editorRef:n.useCallback(c=>{if(!c)return;l(c.clientWidth);const r=new ResizeObserver(i=>{if(i.length===0)return;const d=i[0].target.clientWidth;d>0&&s.current(d)});return setTimeout(()=>{r.observe(c)},0),r},[]),editorWidth:e}},tF=n.createContext({editorWidth:0,editorRef:null}),lF=()=>n.useContext(tF),nF=({children:e})=>{const{editorRef:l,editorWidth:s}=Dm0(),o=n.useMemo(()=>({editorWidth:s,editorRef:l}),[s,l]);return t.jsx(tF.Provider,{value:o,children:t.jsx(GV,{ref:l,children:e})})},Om0=({index:e,children:l})=>t.jsx("div",{"data-test-id":`toolbar-group-${e}`,className:"tw-flex tw-items-center tw-h-9 tw-p-2",children:l}),Zm0=12,_m0=26,qm0=124,Um0=e=>e.map((l,s)=>({group:l,buttonGroupWidth:l.reduce((o,c)=>c.id===ET?qm0:_m0+o,Zm0),index:s})),Wm0=(e,l)=>l.reduce((s,{group:o,buttonGroupWidth:c,index:r})=>{const i=Math.max(0,s.length-1);return s[i]=s[i]??[],(s[i]??[{actions:[],buttonGroupWidth:0}]).reduce((u,{buttonGroupWidth:m})=>u+m,0)+c<=e?s[i].push({group:o,buttonGroupWidth:c,index:r}):s.push([{group:o,buttonGroupWidth:c,index:r}]),s.filter(u=>u.length)},[]),aF=({toolbarButtons:e,editorId:l,toolbarWidth:s})=>{const o=k.useEditorRef(l),{editorWidth:c}=lF(),{position:r}=k1(),i=s||c||0,d=Um0(e.at(r)),u=Wm0(i,d),m=i7[r];return t.jsx(m.ToolbarWrapper,{editorWidth:c,toolbarWidth:s,toolbarButtonGroups:u,children:u.map((L,h)=>t.jsx("div",{className:"tw-divide-x tw-divide-line tw-flex tw-w-full",children:L.map(({group:w,index:v})=>t.jsx(Om0,{index:v,children:w.map((x,C)=>t.jsx(x.button,{editor:o,editorId:l,id:x.id},C.toString()))},v))},h))})},sF="[data-floating-modal]",X7=({children:e,minWidth:l,padding:s,"data-test-id":o="floating-modal"})=>t.jsx("div",{"data-test-id":o,className:"tw-bg-white tw-rounded tw-shadow tw-overflow-y-auto",style:{minWidth:l,padding:s},"data-floating-modal":!0,children:e}),Gm0=({hideExternalFloatingModals:e})=>{const l=k.useEditorRef(),s=e0.useFloatingLinkSelectors().isOpen(l.id),[o,c]=n.useState(!1),r=n.useCallback(()=>{s&&e0.floatingLinkActions.hide(),e&&e(l.id)},[s,e,l]),i=n.useCallback(()=>{l.collapse(),r()},[l,r]);return n.useEffect(()=>{if(!o)return;const d=u=>{const m=`[data-editor-id='${l.id}']`,L="[role='toolbar']",h="[data-is-underlay]",w=u.target,v=w.closest(h),x=w.closest(sF),C=w.closest(m),I=w.closest(L);C&&!x||I?r():!C&&!I&&!v&&(i(),c(!1))};return document.addEventListener("pointerdown",d),document.addEventListener("focusin",d),()=>{document.removeEventListener("focusin",d),document.removeEventListener("pointerdown",d)}},[i,r,l.id,o]),n.useEffect(()=>{const d=document.querySelector(`[data-editor-id='${l.id}']`);if(!d)return;const u=()=>{c(!0)};return d.addEventListener("focusin",u),()=>{d.removeEventListener("focusin",u)}},[l.id]),null},Km0=({children:e,apply:l})=>{for(const s of e)l({type:"remove_node",path:[0],node:s})},Qm0=({value:e})=>{const l=k.useEditorRef();return n.useEffect(()=>{e&&(Km0(l),Z.insertNodes(l,e))},[l,e]),null},Xm0={position:"relative",height:"0"},Ym0=({children:e,attributes:l})=>{const s={...l,style:{...l.style,...Xm0}};return t.jsx("span",{...s,children:e})},oF=({id:e,value:l,placeholder:s="",readonly:o=!1,onTextChange:c,onBlur:r,padding:i=c7.None,position:d=x0.FLOATING,plugins:u=a2,updateValueOnChange:m=!1,onValueChanged:L,border:h=!0,toolbarWidth:w,hideExternalFloatingModals:v})=>{var S,P,$;const x=g0(e),{localValue:C,onChange:I,memoizedValue:g,config:N}=$m0({editorId:x,initialValue:l,onTextChange:c,plugins:u,onValueChanged:L}),p=u.plugins.find(V=>V.key===s2),A=(S=p==null?void 0:p.options)==null?void 0:S.customClass,y=A?null:((P=p==null?void 0:p.options)==null?void 0:P.columns)??1,z=(($=p==null?void 0:p.options)==null?void 0:$.gap)??U7,H=n.useMemo(()=>({columns:y,columnGap:z,outline:"none"}),[y,z]),j=n.useCallback(()=>{r&&r(JSON.stringify(C.current))},[r,C]),R=n.useCallback(V=>{V.code==="Tab"&&f9(V,!V.shiftKey)},[]),M={placeholder:s,renderPlaceholder:Ym0,readOnly:o,onBlur:j,className:f([i,A]),style:H,onKeyDown:R,scrollSelectionIntoView:N1.noop};return t.jsx(WV,{styles:N.styles(),position:d,border:h,editorId:x,children:t.jsxs(k.Plate,{id:x,onChange:I,plugins:N.plugins,initialValue:g,children:[t.jsx(k.PlateContent,{...M}),!M.readOnly&&N.toolbar(w),N.inline(),m&&t.jsx(Qm0,{value:A2({editorId:x,raw:l,plugins:u})}),d===x0.FLOATING&&t.jsx(Gm0,{hideExternalFloatingModals:v})]})})};oF.displayName="FondueRichTextEditor";const Jm0={paragraph:"paragraph",blockQuote:"block_quote",codeBlock:"code_block",link:"link",ulList:"ul_list",olList:"ol_list",listItem:"list_item",listItemChild:"lic",heading:{1:"heading_one",2:"heading_two",3:"heading_three",4:"heading_four",5:"heading_five",6:"heading_six"},emphasisMark:"italic",strongMark:"bold",deleteMark:"strikethrough",inlineCodeMark:"code",thematicBreak:"thematic_break",image:"image",mention:"mention"},r5={Blank:"_blank",Self:"_self"},cF="[\\d=a-z]+",rF=Object.values(n1).join("|"),Em0=`@\\[(${rF}):${cF}\\]`,iF=`@\\[(${rF}):(${cF})\\]`,eL0=new RegExp(Em0,"gi"),tL0=new RegExp(iF,"i"),Jt="<br>",lL0="link",Y5={nodeTypes:Jm0,ignoreParagraphNewline:!1,listDepth:0,linkDestinationKey:lL0},dF=e=>{var l;return{...Y5,...e,nodeTypes:{...Y5.nodeTypes,...e==null?void 0:e.nodeTypes,heading:{...Y5.nodeTypes.heading,...(l=e==null?void 0:e.nodeTypes)==null?void 0:l.heading}}}},xe=e=>/^(javascript:|data:text\/).+/i.test(e),Q1=e=>!("type"in e),nL0=e=>`@[${e.category}:${e.id}]`,aL0=e=>`${e}
|
|
13
|
+
Shift+Ctrl+Return`:"Already at maximum numbers of columns"),onPointerDown:m=>m.preventDefault(),onClick:m=>{QV(s,r,m)},...l,children:t.jsx(C0,{icon:t.jsx(P5,{})})})},wm0=(e,l,s)=>KV(e)+1<l||s,XV=({id:e})=>t.jsx(j0,{id:e,children:t.jsx(hm0,{children:t.jsx(C0,{icon:t.jsx(P5,{})})})}),fm0=(e,l)=>{const s=Z.getStartPoint(e,l);setTimeout(()=>{Z.select(e,{anchor:s,focus:s})})},xm0=e=>{var s;const l=e.plugins.find(o=>o.key===s2);return((s=l==null?void 0:l.options)==null?void 0:s.columns)??1},vm0=e=>{const{apply:l}=e,s=xm0(e);e.apply=o=>{switch(o.type){case"split_node":{o.properties={...o.properties,breakAfterColumn:void 0};break}case"merge_node":{const c=Z.getPointBefore(e,o.path);if(!c)break;const r=Z.getParentNode(e,c.path);if(w2(e,{at:c,value:void 0}),fe(e,s),r!=null&&r[0].breakAfterColumn)return fm0(e,o.path),e;break}}l(o)},setTimeout(()=>fe(e,s))},s2="breakAfterColumn",U7="normal";class gm0 extends a0{constructor(s){super("break-after-plugin",{button:XV,...s});Y(this,"columns");Y(this,"gap");Y(this,"customClass");this.columns=(s==null?void 0:s.columns)??1,this.gap=(s==null?void 0:s.gap)??U7,this.customClass=s==null?void 0:s.customClass}plugins(){return[YV(this.columns,this.gap,this.customClass)]}}const YV=(e,l,s)=>k.createPluginFactory({key:s2,handlers:{onKeyDown:Lm0},useHooks:vm0,options:{columns:e,gap:l,customClass:s,hotkey:["shift+ctrl+enter"]}})();var n1=(e=>(e.GROUP="group",e.ALL="all",e.USER="user",e))(n1||{});const Cm0=({image:e,category:l,text:s,id:o})=>{if(e)return t.jsx("img",{src:e,alt:`${o}-${l}-${s}`});switch(l){case n1.GROUP:return t.jsx(F5,{});case n1.ALL:return t.jsx(I7,{});default:return t.jsx(g7,{})}},jm0=({item:e})=>{const{data:{image:l,category:s},key:o,text:c}=e;return t.jsxs("div",{className:"tw-flex tw-items-center tw-w-full tw-min-h-[inherit]",children:[t.jsx("span",{className:"tw-flex tw-items-center tw-justify-center tw-rounded-full tw-mr-2.5 tw-bg-base-alt tw-border tw-border-line-weak tw-w-[22px] tw-h-[22px] tw-shrink-0 tw-overflow-hidden group-hover:tw-border-base group-aria-selected:tw-border-base",children:t.jsx(Cm0,{image:l,category:s,text:c,id:o})}),t.jsx("span",{className:"tw-whitespace-nowrap tw-overflow-hidden tw-text-ellipsis",children:c})]})};function Im0({pluginKey:e=p1.ELEMENT_MENTION,id:l=e,...s}){const o=k.useEditorRef(),{trigger:c}=k.getPluginOptions(o,e);return t.jsx(qT,{id:l,trigger:c,controlled:!0,onSelectItem:(r,i)=>p1.getMentionOnSelectItem({key:e})(o,i),onRenderItem:jm0,...s})}const Nm0=e=>l=>l.text.toLowerCase().includes(e.toLowerCase()),W7=(e,l)=>`${e}:${l}`,G7=e=>{const l=new Map;for(const s of e){const o=W7(s.data.category,s.data.id),c=s.text;l.set(o,c)}return l},JV=(e,l,s)=>e.get(l)??s,pm0=e=>()=>t.jsx(Im0,{items:e,filter:Nm0}),EV=n.forwardRef(({className:e,onClick:l,...s},o)=>{const{children:c,element:r}=s;return t.jsx(te.PlateElement,{ref:o,asChild:!0,"data-slate-value":r.value,className:f(["tw-inline-block tw-rounded-sm tw-shadow-none tw-font-bold tw-leading-[10px] tw-m-0 tw-py-0.5 tw-px-1.5 tw-text-[rgb(130,95,255)] tw-bg-[rgb(227,232,246)]",e]),onClick:pe.getHandler(l,r),...s,children:t.jsx("span",{children:c})})});EV.displayName="MentionInputElement";const Mm0=e=>t.jsx(EV,{...e});class zm0 extends s0{constructor(l=p1.ELEMENT_MENTION_INPUT,s=Mm0){super(l,s)}}const K7=({attributes:e,element:l,nodeProps:s,children:o})=>t.jsx("span",{...e,dir:"auto","data-slate-value":l==null?void 0:l.value,"data-slate-key":l==null?void 0:l.key,"data-slate-category":l==null?void 0:l.category,contentEditable:!1,style:{lineHeight:"10px",padding:"1px",margin:"0 1px",fontWeight:"bold",verticalAlign:"baseline",display:"inline-block",borderRadius:"2px",backgroundColor:"rgb(227, 232, 246)",color:"rgb(130, 95, 255)"},...s,children:o}),Sm0=({children:e,...l})=>t.jsxs(K7,{...l,children:[t.jsx("span",{style:{paddingRight:"3px",display:"inline-block",margin:"-1px 0"},children:t.jsx(F5,{})}),e]}),Am0=({children:e,...l})=>t.jsxs(K7,{...l,children:["@",e]}),ym0=({children:e,...l})=>t.jsx(K7,{...l,children:e}),bm0=({category:e,children:l,...s})=>{const o={[n1.USER]:ym0,[n1.GROUP]:Sm0,[n1.ALL]:Am0},c=o[e]??o[n1.USER];return t.jsx(c,{...s,children:l})},Q7=e=>l=>{const{element:s,children:o}=l,c=W7(s==null?void 0:s.category,String(s==null?void 0:s.id));return t.jsxs(bm0,{category:s==null?void 0:s.category,...l,children:[JV(e,c,String(s==null?void 0:s.id)),o]})};class eF extends s0{constructor(l=p1.ELEMENT_MENTION){super(l)}setNodeWithMentionable(l){return this.node=Q7(G7(l)),this}}const Rm0={options:{trigger:"@",insertSpaceAfterMention:!0,createMentionNode:e=>({value:e.text,category:e.data.category,id:e.data.id})}},Hm0="mention-plugin";class km0 extends a0{constructor(l){super(Hm0,{markupElement:new eF().setNodeWithMentionable(l.mentionableItems),markupInputElement:new zm0,...l})}inline(){var l;return pm0(((l=this.props)==null?void 0:l.mentionableItems)||[])}plugins(){return[P0.createComboboxPlugin(),p1.createMentionPlugin(Rm0)]}}const Tm0=(e,{options:{onBreak:l=()=>{}}})=>s=>{k.Hotkeys.isSplitBlock(s)&&(s.stopPropagation(),s.preventDefault(),x9(),typeof l=="function"&&l(e.children))},Vm0="blurOnBreak",Fm0=k.createPluginFactory({key:Vm0,handlers:{onKeyDown:Tm0}}),Pm0="blur-on-break-plugin";class Bm0 extends a0{constructor(s){super(Pm0,{...s});Y(this,"onBreak");this.onBreak=s==null?void 0:s.onBreak}plugins(){return[Fm0({options:{onBreak:this.onBreak}})]}}const $m0=({editorId:e,initialValue:l,plugins:s,onTextChange:o,onValueChanged:c})=>{const r=n.useRef(null),i=n.useCallback(h=>{o&&o(JSON.stringify(h))},[o]),d=t5(i,I9),u=n.useCallback(h=>{d(h),r.current=h,c&&c(h)},[d,r,c]),m=n.useMemo(()=>A2({editorId:e,raw:l,plugins:s}),[e]),L=n.useMemo(()=>d7(e,s),[e,s]);return{localValue:r,onChange:u,memoizedValue:m,config:L}},Dm0=()=>{const[e,l]=n.useState(0),s=n.useRef(o3(c=>l(c)));return{editorRef:n.useCallback(c=>{if(!c)return;l(c.clientWidth);const r=new ResizeObserver(i=>{if(i.length===0)return;const d=i[0].target.clientWidth;d>0&&s.current(d)});return setTimeout(()=>{r.observe(c)},0),r},[]),editorWidth:e}},tF=n.createContext({editorWidth:0,editorRef:null}),lF=()=>n.useContext(tF),nF=({children:e})=>{const{editorRef:l,editorWidth:s}=Dm0(),o=n.useMemo(()=>({editorWidth:s,editorRef:l}),[s,l]);return t.jsx(tF.Provider,{value:o,children:t.jsx(GV,{ref:l,children:e})})},Om0=({index:e,children:l})=>t.jsx("div",{"data-test-id":`toolbar-group-${e}`,className:"tw-flex tw-items-center tw-h-9 tw-p-2",children:l}),Zm0=12,_m0=26,qm0=124,Um0=e=>e.map((l,s)=>({group:l,buttonGroupWidth:l.reduce((o,c)=>c.id===ET?qm0:_m0+o,Zm0),index:s})),Wm0=(e,l)=>l.reduce((s,{group:o,buttonGroupWidth:c,index:r})=>{const i=Math.max(0,s.length-1);return s[i]=s[i]??[],(s[i]??[{actions:[],buttonGroupWidth:0}]).reduce((u,{buttonGroupWidth:m})=>u+m,0)+c<=e?s[i].push({group:o,buttonGroupWidth:c,index:r}):s.push([{group:o,buttonGroupWidth:c,index:r}]),s.filter(u=>u.length)},[]),aF=({toolbarButtons:e,editorId:l,toolbarWidth:s})=>{const o=k.useEditorRef(l),{editorWidth:c}=lF(),{position:r}=k1(),i=s||c||0,d=Um0(e.at(r)),u=Wm0(i,d),m=i7[r];return t.jsx(m.ToolbarWrapper,{editorWidth:c,toolbarWidth:s,toolbarButtonGroups:u,children:u.map((L,h)=>t.jsx("div",{className:"tw-divide-x tw-divide-line tw-flex tw-w-full",children:L.map(({group:w,index:v})=>t.jsx(Om0,{index:v,children:w.map((x,C)=>t.jsx(x.button,{editor:o,editorId:l,id:x.id},C.toString()))},v))},h))})},sF="[data-floating-modal]",X7=({children:e,minWidth:l,padding:s,"data-test-id":o="floating-modal"})=>t.jsx("div",{"data-test-id":o,className:"tw-bg-white tw-rounded tw-shadow tw-overflow-y-auto",style:{minWidth:l,padding:s},"data-floating-modal":!0,children:e}),Gm0=({hideExternalFloatingModals:e})=>{const l=k.useEditorRef(),s=e0.useFloatingLinkSelectors().isOpen(l.id),[o,c]=n.useState(!1),r=n.useCallback(()=>{s&&e0.floatingLinkActions.hide(),e&&e(l.id)},[s,e,l]),i=n.useCallback(()=>{r(),l.deselect(),l.collapse()},[l,r]);return n.useEffect(()=>{if(!o)return;const d=u=>{const m=`[data-editor-id='${l.id}']`,L="[role='toolbar']",h="[data-is-underlay]",w=u.target,v=w.closest(h),x=w.closest(sF),C=w.closest(m),I=w.closest(L);C&&!x||I?r():!C&&!I&&!v&&(i(),c(!1))};return document.addEventListener("pointerdown",d),document.addEventListener("focusin",d),()=>{document.removeEventListener("focusin",d),document.removeEventListener("pointerdown",d)}},[i,r,l.id,o]),n.useEffect(()=>{const d=document.querySelector(`[data-editor-id='${l.id}']`);if(!d)return;const u=()=>{c(!0)};return d.addEventListener("focusin",u),()=>{d.removeEventListener("focusin",u)}},[l.id]),null},Km0=({children:e,apply:l})=>{for(const s of e)l({type:"remove_node",path:[0],node:s})},Qm0=({value:e})=>{const l=k.useEditorRef();return n.useEffect(()=>{e&&(Km0(l),Z.insertNodes(l,e))},[l,e]),null},Xm0={position:"relative",height:"0"},Ym0=({children:e,attributes:l})=>{const s={...l,style:{...l.style,...Xm0}};return t.jsx("span",{...s,children:e})},oF=({id:e,value:l,placeholder:s="",readonly:o=!1,onTextChange:c,onBlur:r,padding:i=c7.None,position:d=x0.FLOATING,plugins:u=a2,updateValueOnChange:m=!1,onValueChanged:L,border:h=!0,toolbarWidth:w,hideExternalFloatingModals:v})=>{var S,P,$;const x=g0(e),{localValue:C,onChange:I,memoizedValue:g,config:N}=$m0({editorId:x,initialValue:l,onTextChange:c,plugins:u,onValueChanged:L}),p=u.plugins.find(V=>V.key===s2),A=(S=p==null?void 0:p.options)==null?void 0:S.customClass,y=A?null:((P=p==null?void 0:p.options)==null?void 0:P.columns)??1,z=(($=p==null?void 0:p.options)==null?void 0:$.gap)??U7,H=n.useMemo(()=>({columns:y,columnGap:z,outline:"none"}),[y,z]),j=n.useCallback(()=>{r&&r(JSON.stringify(C.current))},[r,C]),R=n.useCallback(V=>{V.code==="Tab"&&f9(V,!V.shiftKey)},[]),M={placeholder:s,renderPlaceholder:Ym0,readOnly:o,onBlur:j,className:f([i,A]),style:H,onKeyDown:R,scrollSelectionIntoView:N1.noop};return t.jsx(WV,{styles:N.styles(),position:d,border:h,editorId:x,children:t.jsxs(k.Plate,{id:x,onChange:I,plugins:N.plugins,initialValue:g,children:[t.jsx(k.PlateContent,{...M}),!M.readOnly&&N.toolbar(w),N.inline(),m&&t.jsx(Qm0,{value:A2({editorId:x,raw:l,plugins:u})}),d===x0.FLOATING&&t.jsx(Gm0,{hideExternalFloatingModals:v})]})})};oF.displayName="FondueRichTextEditor";const Jm0={paragraph:"paragraph",blockQuote:"block_quote",codeBlock:"code_block",link:"link",ulList:"ul_list",olList:"ol_list",listItem:"list_item",listItemChild:"lic",heading:{1:"heading_one",2:"heading_two",3:"heading_three",4:"heading_four",5:"heading_five",6:"heading_six"},emphasisMark:"italic",strongMark:"bold",deleteMark:"strikethrough",inlineCodeMark:"code",thematicBreak:"thematic_break",image:"image",mention:"mention"},r5={Blank:"_blank",Self:"_self"},cF="[\\d=a-z]+",rF=Object.values(n1).join("|"),Em0=`@\\[(${rF}):${cF}\\]`,iF=`@\\[(${rF}):(${cF})\\]`,eL0=new RegExp(Em0,"gi"),tL0=new RegExp(iF,"i"),Jt="<br>",lL0="link",Y5={nodeTypes:Jm0,ignoreParagraphNewline:!1,listDepth:0,linkDestinationKey:lL0},dF=e=>{var l;return{...Y5,...e,nodeTypes:{...Y5.nodeTypes,...e==null?void 0:e.nodeTypes,heading:{...Y5.nodeTypes.heading,...(l=e==null?void 0:e.nodeTypes)==null?void 0:l.heading}}}},xe=e=>/^(javascript:|data:text\/).+/i.test(e),Q1=e=>!("type"in e),nL0=e=>`@[${e.category}:${e.id}]`,aL0=e=>`${e}
|
|
14
14
|
`,sL0=(e,l,s,o)=>{const c=s&&s.parentType===e.olList,r=s.children.length===1&&Q1(s.children[0]);let i="";for(let d=0;o>d;d++)c?i+=" ":i+=" ";return`${i}${c?"1.":"-"} ${l}${r?`
|
|
15
15
|
`:""}`},oL0=(e,l,s,o)=>(o===l.codeBlock||s===l.codeBlock||(e=_2(e)),e),cL0=(e,l,s,o,c,r)=>{const i=e.nodeTypes;switch(c){case i.heading[1]:return`# ${l}
|
|
16
16
|
`;case i.heading[2]:return`## ${l}
|