@strapi/content-manager 5.12.5 → 5.12.7
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/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js +7 -12
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.mjs +8 -13
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/EditorLayout.js +46 -95
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/EditorLayout.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/EditorLayout.mjs +48 -78
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/EditorLayout.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js +2 -0
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs +2 -0
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.js +50 -97
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.mjs +51 -79
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.mjs.map +1 -1
- package/dist/admin/preview/components/PreviewHeader.js +1 -1
- package/dist/admin/preview/components/PreviewHeader.js.map +1 -1
- package/dist/admin/preview/components/PreviewHeader.mjs +1 -1
- package/dist/admin/preview/components/PreviewHeader.mjs.map +1 -1
- package/dist/admin/services/homepage.js +9 -5
- package/dist/admin/services/homepage.js.map +1 -1
- package/dist/admin/services/homepage.mjs +9 -5
- package/dist/admin/services/homepage.mjs.map +1 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/EditorLayout.d.ts +2 -2
- package/dist/server/controllers/index.js +3 -1
- package/dist/server/controllers/index.js.map +1 -1
- package/dist/server/controllers/index.mjs +3 -1
- package/dist/server/controllers/index.mjs.map +1 -1
- package/dist/server/homepage/controllers/homepage.js +57 -0
- package/dist/server/homepage/controllers/homepage.js.map +1 -0
- package/dist/server/homepage/controllers/homepage.mjs +36 -0
- package/dist/server/homepage/controllers/homepage.mjs.map +1 -0
- package/dist/server/homepage/controllers/index.js +10 -0
- package/dist/server/homepage/controllers/index.js.map +1 -0
- package/dist/server/homepage/controllers/index.mjs +8 -0
- package/dist/server/homepage/controllers/index.mjs.map +1 -0
- package/dist/server/homepage/index.js +14 -0
- package/dist/server/homepage/index.js.map +1 -0
- package/dist/server/homepage/index.mjs +12 -0
- package/dist/server/homepage/index.mjs.map +1 -0
- package/dist/server/homepage/routes/homepage.js +25 -0
- package/dist/server/homepage/routes/homepage.js.map +1 -0
- package/dist/server/homepage/routes/homepage.mjs +23 -0
- package/dist/server/homepage/routes/homepage.mjs.map +1 -0
- package/dist/server/homepage/routes/index.js +13 -0
- package/dist/server/homepage/routes/index.js.map +1 -0
- package/dist/server/homepage/routes/index.mjs +11 -0
- package/dist/server/homepage/routes/index.mjs.map +1 -0
- package/dist/server/homepage/services/homepage.js +157 -0
- package/dist/server/homepage/services/homepage.js.map +1 -0
- package/dist/server/homepage/services/homepage.mjs +155 -0
- package/dist/server/homepage/services/homepage.mjs.map +1 -0
- package/dist/server/homepage/services/index.js +10 -0
- package/dist/server/homepage/services/index.js.map +1 -0
- package/dist/server/homepage/services/index.mjs +8 -0
- package/dist/server/homepage/services/index.mjs.map +1 -0
- package/dist/server/preview/services/preview.js +0 -1
- package/dist/server/preview/services/preview.js.map +1 -1
- package/dist/server/preview/services/preview.mjs +0 -1
- package/dist/server/preview/services/preview.mjs.map +1 -1
- package/dist/server/routes/index.js +3 -1
- package/dist/server/routes/index.js.map +1 -1
- package/dist/server/routes/index.mjs +3 -1
- package/dist/server/routes/index.mjs.map +1 -1
- package/dist/server/services/index.js +3 -1
- package/dist/server/services/index.js.map +1 -1
- package/dist/server/services/index.mjs +3 -1
- package/dist/server/services/index.mjs.map +1 -1
- package/dist/server/src/controllers/index.d.ts.map +1 -1
- package/dist/server/src/homepage/controllers/homepage.d.ts +7 -0
- package/dist/server/src/homepage/controllers/homepage.d.ts.map +1 -0
- package/dist/server/src/homepage/controllers/index.d.ts +2 -0
- package/dist/server/src/homepage/controllers/index.d.ts.map +1 -0
- package/dist/server/src/homepage/index.d.ts +16 -0
- package/dist/server/src/homepage/index.d.ts.map +1 -0
- package/dist/server/src/homepage/routes/homepage.d.ts +4 -0
- package/dist/server/src/homepage/routes/homepage.d.ts.map +1 -0
- package/dist/server/src/homepage/routes/index.d.ts +8 -0
- package/dist/server/src/homepage/routes/index.d.ts.map +1 -0
- package/dist/server/src/{services → homepage/services}/homepage.d.ts +1 -1
- package/dist/server/src/homepage/services/homepage.d.ts.map +1 -0
- package/dist/server/src/homepage/services/index.d.ts +9 -0
- package/dist/server/src/homepage/services/index.d.ts.map +1 -0
- package/dist/server/src/index.d.ts +7 -0
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/preview/services/preview.d.ts.map +1 -1
- package/dist/server/src/routes/index.d.ts +1 -0
- package/dist/server/src/routes/index.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +6 -0
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/package.json +7 -7
- package/dist/server/src/services/homepage.d.ts.map +0 -1
@@ -76,12 +76,6 @@ function useBlocksEditorContext(consumerName) {
|
|
76
76
|
* -----------------------------------------------------------------------------------------------*/ const EditorDivider = styledComponents.styled(designSystem.Divider)`
|
77
77
|
background: ${({ theme })=>theme.colors.neutral200};
|
78
78
|
`;
|
79
|
-
const ExpandIconButton = styledComponents.styled(designSystem.IconButton)`
|
80
|
-
position: absolute;
|
81
|
-
bottom: 1.2rem;
|
82
|
-
right: 1.2rem;
|
83
|
-
box-shadow: ${({ theme })=>theme.shadows.filterShadow};
|
84
|
-
`;
|
85
79
|
/**
|
86
80
|
* Forces an update of the Slate editor when the value prop changes from outside of Slate.
|
87
81
|
* The root cause is that Slate is not a controlled component: https://github.com/ianstormtaylor/slate/issues/4612
|
@@ -120,10 +114,7 @@ const BlocksEditor = /*#__PURE__*/ React__namespace.forwardRef(({ disabled = fal
|
|
120
114
|
const [editor] = React__namespace.useState(()=>pipe(slateHistory.withHistory, withImages.withImages, withStrapiSchema.withStrapiSchema, slateReact.withReact, withLinks.withLinks)(slate.createEditor()));
|
121
115
|
const [liveText, setLiveText] = React__namespace.useState('');
|
122
116
|
const ariaDescriptionId = React__namespace.useId();
|
123
|
-
const [isExpandedMode,
|
124
|
-
const handleToggleExpand = ()=>{
|
125
|
-
setIsExpandedMode((prev)=>!prev);
|
126
|
-
};
|
117
|
+
const [isExpandedMode, handleToggleExpand] = React__namespace.useReducer((prev)=>!prev, false);
|
127
118
|
/**
|
128
119
|
* Editable is not able to hold the ref, https://github.com/ianstormtaylor/slate/issues/4082
|
129
120
|
* so with "useImperativeHandle" we can use ReactEditor methods to expose to the parent above
|
@@ -189,7 +180,7 @@ const BlocksEditor = /*#__PURE__*/ React__namespace.forwardRef(({ disabled = fal
|
|
189
180
|
children: /*#__PURE__*/ jsxRuntime.jsxs(EditorLayout.EditorLayout, {
|
190
181
|
error: error,
|
191
182
|
disabled: disabled,
|
192
|
-
|
183
|
+
onToggleExpand: handleToggleExpand,
|
193
184
|
ariaDescriptionId: ariaDescriptionId,
|
194
185
|
children: [
|
195
186
|
/*#__PURE__*/ jsxRuntime.jsx(BlocksToolbar.BlocksToolbar, {}),
|
@@ -199,7 +190,11 @@ const BlocksEditor = /*#__PURE__*/ React__namespace.forwardRef(({ disabled = fal
|
|
199
190
|
/*#__PURE__*/ jsxRuntime.jsx(BlocksContent.BlocksContent, {
|
200
191
|
...contentProps
|
201
192
|
}),
|
202
|
-
!isExpandedMode && /*#__PURE__*/ jsxRuntime.jsx(
|
193
|
+
!isExpandedMode && /*#__PURE__*/ jsxRuntime.jsx(designSystem.IconButton, {
|
194
|
+
position: "absolute",
|
195
|
+
bottom: "1.2rem",
|
196
|
+
right: "1.2rem",
|
197
|
+
shadow: "filterShadow",
|
203
198
|
label: formatMessage({
|
204
199
|
id: translations.getTranslation('components.Blocks.expand'),
|
205
200
|
defaultMessage: 'Expand'
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"BlocksEditor.js","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { createContext, type FieldValue } from '@strapi/admin/strapi-admin';\nimport { IconButton, Divider, VisuallyHidden } from '@strapi/design-system';\nimport { Expand } from '@strapi/icons';\nimport { MessageDescriptor, useIntl } from 'react-intl';\nimport { Editor, type Descendant, createEditor } from 'slate';\nimport { withHistory } from 'slate-history';\nimport { type RenderElementProps, Slate, withReact, ReactEditor, useSlate } from 'slate-react';\nimport { styled, type CSSProperties } from 'styled-components';\n\nimport { getTranslation } from '../../../../../utils/translations';\n\nimport { codeBlocks } from './Blocks/Code';\nimport { headingBlocks } from './Blocks/Heading';\nimport { imageBlocks } from './Blocks/Image';\nimport { linkBlocks } from './Blocks/Link';\nimport { listBlocks } from './Blocks/List';\nimport { paragraphBlocks } from './Blocks/Paragraph';\nimport { quoteBlocks } from './Blocks/Quote';\nimport { BlocksContent, type BlocksContentProps } from './BlocksContent';\nimport { BlocksToolbar } from './BlocksToolbar';\nimport { EditorLayout } from './EditorLayout';\nimport { type ModifiersStore, modifiers } from './Modifiers';\nimport { withImages } from './plugins/withImages';\nimport { withLinks } from './plugins/withLinks';\nimport { withStrapiSchema } from './plugins/withStrapiSchema';\n\nimport type { Schema } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * BlocksEditorProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface BaseBlock {\n renderElement: (props: RenderElementProps) => React.JSX.Element;\n matchNode: (node: Schema.Attribute.BlocksNode) => boolean;\n handleConvert?: (editor: Editor) => void | (() => React.JSX.Element);\n handleEnterKey?: (editor: Editor) => void;\n handleBackspaceKey?: (editor: Editor, event: React.KeyboardEvent<HTMLElement>) => void;\n handleTab?: (editor: Editor) => void;\n snippets?: string[];\n dragHandleTopMargin?: CSSProperties['marginTop'];\n}\n\ninterface NonSelectorBlock extends BaseBlock {\n isInBlocksSelector: false;\n}\n\ninterface SelectorBlock extends BaseBlock {\n isInBlocksSelector: true;\n icon: React.ComponentType;\n label: MessageDescriptor;\n}\n\ntype NonSelectorBlockKey = 'list-item' | 'link';\n\nconst selectorBlockKeys = [\n 'paragraph',\n 'heading-one',\n 'heading-two',\n 'heading-three',\n 'heading-four',\n 'heading-five',\n 'heading-six',\n 'list-ordered',\n 'list-unordered',\n 'image',\n 'quote',\n 'code',\n] as const;\n\ntype SelectorBlockKey = (typeof selectorBlockKeys)[number];\n\nconst isSelectorBlockKey = (key: unknown): key is SelectorBlockKey => {\n return typeof key === 'string' && selectorBlockKeys.includes(key as SelectorBlockKey);\n};\n\ntype BlocksStore = {\n [K in SelectorBlockKey]: SelectorBlock;\n} & {\n [K in NonSelectorBlockKey]: NonSelectorBlock;\n};\n\ninterface BlocksEditorContextValue {\n blocks: BlocksStore;\n modifiers: ModifiersStore;\n disabled: boolean;\n name: string;\n setLiveText: (text: string) => void;\n isExpandedMode: boolean;\n}\n\nconst [BlocksEditorProvider, usePartialBlocksEditorContext] =\n createContext<BlocksEditorContextValue>('BlocksEditor');\n\nfunction useBlocksEditorContext(\n consumerName: string\n): BlocksEditorContextValue & { editor: Editor } {\n const context = usePartialBlocksEditorContext(consumerName, (state) => state);\n const editor = useSlate();\n\n return {\n ...context,\n editor,\n };\n}\n\n/* -------------------------------------------------------------------------------------------------\n * BlocksEditor\n * -----------------------------------------------------------------------------------------------*/\n\nconst EditorDivider = styled(Divider)`\n background: ${({ theme }) => theme.colors.neutral200};\n`;\n\nconst ExpandIconButton = styled(IconButton)`\n position: absolute;\n bottom: 1.2rem;\n right: 1.2rem;\n box-shadow: ${({ theme }) => theme.shadows.filterShadow};\n`;\n\n/**\n * Forces an update of the Slate editor when the value prop changes from outside of Slate.\n * The root cause is that Slate is not a controlled component: https://github.com/ianstormtaylor/slate/issues/4612\n * Why not use JSON.stringify(value) as the key?\n * Because it would force a rerender of the entire editor every time the user types a character.\n * Why not use the entity id as the key, since it's unique for each locale?\n * Because it would not solve the problem when using the \"fill in from other locale\" feature\n */\nfunction useResetKey(value?: Schema.Attribute.BlocksValue): {\n key: number;\n incrementSlateUpdatesCount: () => void;\n} {\n // Keep track how many times Slate detected a change from a user interaction in the editor\n const slateUpdatesCount = React.useRef(0);\n // Keep track of how many times the value prop was updated, whether from within editor or from outside\n const valueUpdatesCount = React.useRef(0);\n // Use a key to force a rerender of the Slate editor when needed\n const [key, setKey] = React.useState(0);\n\n React.useEffect(() => {\n valueUpdatesCount.current += 1;\n\n // If the 2 refs are not equal, it means the value was updated from outside\n if (valueUpdatesCount.current !== slateUpdatesCount.current) {\n // So we change the key to force a rerender of the Slate editor,\n // which will pick up the new value through its initialValue prop\n setKey((previousKey) => previousKey + 1);\n\n // Then bring the 2 refs back in sync\n slateUpdatesCount.current = valueUpdatesCount.current;\n }\n }, [value]);\n\n return { key, incrementSlateUpdatesCount: () => (slateUpdatesCount.current += 1) };\n}\n\nconst pipe =\n (...fns: ((baseEditor: Editor) => Editor)[]) =>\n (value: Editor) =>\n fns.reduce<Editor>((prev, fn) => fn(prev), value);\n\ninterface BlocksEditorProps\n extends Pick<FieldValue<Schema.Attribute.BlocksValue>, 'onChange' | 'value' | 'error'>,\n BlocksContentProps {\n disabled?: boolean;\n name: string;\n}\n\nconst BlocksEditor = React.forwardRef<{ focus: () => void }, BlocksEditorProps>(\n ({ disabled = false, name, onChange, value, error, ...contentProps }, forwardedRef) => {\n const { formatMessage } = useIntl();\n const [editor] = React.useState(() =>\n pipe(withHistory, withImages, withStrapiSchema, withReact, withLinks)(createEditor())\n );\n const [liveText, setLiveText] = React.useState('');\n const ariaDescriptionId = React.useId();\n const [isExpandedMode, setIsExpandedMode] = React.useState(false);\n\n const handleToggleExpand = () => {\n setIsExpandedMode((prev) => !prev);\n };\n\n /**\n * Editable is not able to hold the ref, https://github.com/ianstormtaylor/slate/issues/4082\n * so with \"useImperativeHandle\" we can use ReactEditor methods to expose to the parent above\n * also not passing forwarded ref here, gives console warning.\n */\n React.useImperativeHandle(\n forwardedRef,\n () => ({\n focus() {\n ReactEditor.focus(editor);\n },\n }),\n [editor]\n );\n\n const { key, incrementSlateUpdatesCount } = useResetKey(value);\n\n const handleSlateChange = (state: Descendant[]) => {\n const isAstChange = editor.operations.some((op) => op.type !== 'set_selection');\n\n if (isAstChange) {\n incrementSlateUpdatesCount();\n\n onChange(name, state as Schema.Attribute.BlocksValue);\n }\n };\n\n const blocks: BlocksStore = {\n ...paragraphBlocks,\n ...headingBlocks,\n ...listBlocks,\n ...linkBlocks,\n ...imageBlocks,\n ...quoteBlocks,\n ...codeBlocks,\n };\n\n return (\n <>\n <VisuallyHidden id={ariaDescriptionId}>\n {formatMessage({\n id: getTranslation('components.Blocks.dnd.instruction'),\n defaultMessage: `To reorder blocks, press Command or Control along with Shift and the Up or Down arrow keys`,\n })}\n </VisuallyHidden>\n <VisuallyHidden aria-live=\"assertive\">{liveText}</VisuallyHidden>\n <Slate\n editor={editor}\n initialValue={value || [{ type: 'paragraph', children: [{ type: 'text', text: '' }] }]}\n onChange={handleSlateChange}\n key={key}\n >\n <BlocksEditorProvider\n blocks={blocks}\n modifiers={modifiers}\n disabled={disabled}\n name={name}\n setLiveText={setLiveText}\n isExpandedMode={isExpandedMode}\n >\n <EditorLayout\n error={error}\n disabled={disabled}\n onCollapse={handleToggleExpand}\n ariaDescriptionId={ariaDescriptionId}\n >\n <BlocksToolbar />\n <EditorDivider width=\"100%\" />\n <BlocksContent {...contentProps} />\n {!isExpandedMode && (\n <ExpandIconButton\n label={formatMessage({\n id: getTranslation('components.Blocks.expand'),\n defaultMessage: 'Expand',\n })}\n onClick={handleToggleExpand}\n >\n <Expand />\n </ExpandIconButton>\n )}\n </EditorLayout>\n </BlocksEditorProvider>\n </Slate>\n </>\n );\n }\n);\n\nexport {\n type BlocksStore,\n type SelectorBlockKey,\n BlocksEditor,\n BlocksEditorProvider,\n useBlocksEditorContext,\n isSelectorBlockKey,\n};\n"],"names":["selectorBlockKeys","isSelectorBlockKey","key","includes","BlocksEditorProvider","usePartialBlocksEditorContext","createContext","useBlocksEditorContext","consumerName","context","state","editor","useSlate","EditorDivider","styled","Divider","theme","colors","neutral200","ExpandIconButton","IconButton","shadows","filterShadow","useResetKey","value","slateUpdatesCount","React","useRef","valueUpdatesCount","setKey","useState","useEffect","current","previousKey","incrementSlateUpdatesCount","pipe","fns","reduce","prev","fn","BlocksEditor","forwardRef","disabled","name","onChange","error","contentProps","forwardedRef","formatMessage","useIntl","withHistory","withImages","withStrapiSchema","withReact","withLinks","createEditor","liveText","setLiveText","ariaDescriptionId","useId","isExpandedMode","setIsExpandedMode","handleToggleExpand","useImperativeHandle","focus","ReactEditor","handleSlateChange","isAstChange","operations","some","op","type","blocks","paragraphBlocks","headingBlocks","listBlocks","linkBlocks","imageBlocks","quoteBlocks","codeBlocks","_jsxs","_Fragment","_jsx","VisuallyHidden","id","getTranslation","defaultMessage","aria-live","Slate","initialValue","children","text","modifiers","EditorLayout","onCollapse","BlocksToolbar","width","BlocksContent","label","onClick","Expand"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,MAAMA,iBAAoB,GAAA;AACxB,IAAA,WAAA;AACA,IAAA,aAAA;AACA,IAAA,aAAA;AACA,IAAA,eAAA;AACA,IAAA,cAAA;AACA,IAAA,cAAA;AACA,IAAA,aAAA;AACA,IAAA,cAAA;AACA,IAAA,gBAAA;AACA,IAAA,OAAA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AAoB,cAACkB,CAAAA,YAAAA,EAAAA,EAAAA;;;;;AA3BJlG,aAAAA,EAAAA,GAAAA;;;AAmCb,CAAA;;;;;;;"}
|
1
|
+
{"version":3,"file":"BlocksEditor.js","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { createContext, type FieldValue } from '@strapi/admin/strapi-admin';\nimport { IconButton, Divider, VisuallyHidden } from '@strapi/design-system';\nimport { Expand } from '@strapi/icons';\nimport { MessageDescriptor, useIntl } from 'react-intl';\nimport { Editor, type Descendant, createEditor } from 'slate';\nimport { withHistory } from 'slate-history';\nimport { type RenderElementProps, Slate, withReact, ReactEditor, useSlate } from 'slate-react';\nimport { styled, type CSSProperties } from 'styled-components';\n\nimport { getTranslation } from '../../../../../utils/translations';\n\nimport { codeBlocks } from './Blocks/Code';\nimport { headingBlocks } from './Blocks/Heading';\nimport { imageBlocks } from './Blocks/Image';\nimport { linkBlocks } from './Blocks/Link';\nimport { listBlocks } from './Blocks/List';\nimport { paragraphBlocks } from './Blocks/Paragraph';\nimport { quoteBlocks } from './Blocks/Quote';\nimport { BlocksContent, type BlocksContentProps } from './BlocksContent';\nimport { BlocksToolbar } from './BlocksToolbar';\nimport { EditorLayout } from './EditorLayout';\nimport { type ModifiersStore, modifiers } from './Modifiers';\nimport { withImages } from './plugins/withImages';\nimport { withLinks } from './plugins/withLinks';\nimport { withStrapiSchema } from './plugins/withStrapiSchema';\n\nimport type { Schema } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * BlocksEditorProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface BaseBlock {\n renderElement: (props: RenderElementProps) => React.JSX.Element;\n matchNode: (node: Schema.Attribute.BlocksNode) => boolean;\n handleConvert?: (editor: Editor) => void | (() => React.JSX.Element);\n handleEnterKey?: (editor: Editor) => void;\n handleBackspaceKey?: (editor: Editor, event: React.KeyboardEvent<HTMLElement>) => void;\n handleTab?: (editor: Editor) => void;\n snippets?: string[];\n dragHandleTopMargin?: CSSProperties['marginTop'];\n}\n\ninterface NonSelectorBlock extends BaseBlock {\n isInBlocksSelector: false;\n}\n\ninterface SelectorBlock extends BaseBlock {\n isInBlocksSelector: true;\n icon: React.ComponentType;\n label: MessageDescriptor;\n}\n\ntype NonSelectorBlockKey = 'list-item' | 'link';\n\nconst selectorBlockKeys = [\n 'paragraph',\n 'heading-one',\n 'heading-two',\n 'heading-three',\n 'heading-four',\n 'heading-five',\n 'heading-six',\n 'list-ordered',\n 'list-unordered',\n 'image',\n 'quote',\n 'code',\n] as const;\n\ntype SelectorBlockKey = (typeof selectorBlockKeys)[number];\n\nconst isSelectorBlockKey = (key: unknown): key is SelectorBlockKey => {\n return typeof key === 'string' && selectorBlockKeys.includes(key as SelectorBlockKey);\n};\n\ntype BlocksStore = {\n [K in SelectorBlockKey]: SelectorBlock;\n} & {\n [K in NonSelectorBlockKey]: NonSelectorBlock;\n};\n\ninterface BlocksEditorContextValue {\n blocks: BlocksStore;\n modifiers: ModifiersStore;\n disabled: boolean;\n name: string;\n setLiveText: (text: string) => void;\n isExpandedMode: boolean;\n}\n\nconst [BlocksEditorProvider, usePartialBlocksEditorContext] =\n createContext<BlocksEditorContextValue>('BlocksEditor');\n\nfunction useBlocksEditorContext(\n consumerName: string\n): BlocksEditorContextValue & { editor: Editor } {\n const context = usePartialBlocksEditorContext(consumerName, (state) => state);\n const editor = useSlate();\n\n return {\n ...context,\n editor,\n };\n}\n\n/* -------------------------------------------------------------------------------------------------\n * BlocksEditor\n * -----------------------------------------------------------------------------------------------*/\n\nconst EditorDivider = styled(Divider)`\n background: ${({ theme }) => theme.colors.neutral200};\n`;\n\n/**\n * Forces an update of the Slate editor when the value prop changes from outside of Slate.\n * The root cause is that Slate is not a controlled component: https://github.com/ianstormtaylor/slate/issues/4612\n * Why not use JSON.stringify(value) as the key?\n * Because it would force a rerender of the entire editor every time the user types a character.\n * Why not use the entity id as the key, since it's unique for each locale?\n * Because it would not solve the problem when using the \"fill in from other locale\" feature\n */\nfunction useResetKey(value?: Schema.Attribute.BlocksValue): {\n key: number;\n incrementSlateUpdatesCount: () => void;\n} {\n // Keep track how many times Slate detected a change from a user interaction in the editor\n const slateUpdatesCount = React.useRef(0);\n // Keep track of how many times the value prop was updated, whether from within editor or from outside\n const valueUpdatesCount = React.useRef(0);\n // Use a key to force a rerender of the Slate editor when needed\n const [key, setKey] = React.useState(0);\n\n React.useEffect(() => {\n valueUpdatesCount.current += 1;\n\n // If the 2 refs are not equal, it means the value was updated from outside\n if (valueUpdatesCount.current !== slateUpdatesCount.current) {\n // So we change the key to force a rerender of the Slate editor,\n // which will pick up the new value through its initialValue prop\n setKey((previousKey) => previousKey + 1);\n\n // Then bring the 2 refs back in sync\n slateUpdatesCount.current = valueUpdatesCount.current;\n }\n }, [value]);\n\n return { key, incrementSlateUpdatesCount: () => (slateUpdatesCount.current += 1) };\n}\n\nconst pipe =\n (...fns: ((baseEditor: Editor) => Editor)[]) =>\n (value: Editor) =>\n fns.reduce<Editor>((prev, fn) => fn(prev), value);\n\ninterface BlocksEditorProps\n extends Pick<FieldValue<Schema.Attribute.BlocksValue>, 'onChange' | 'value' | 'error'>,\n BlocksContentProps {\n disabled?: boolean;\n name: string;\n}\n\nconst BlocksEditor = React.forwardRef<{ focus: () => void }, BlocksEditorProps>(\n ({ disabled = false, name, onChange, value, error, ...contentProps }, forwardedRef) => {\n const { formatMessage } = useIntl();\n const [editor] = React.useState(() =>\n pipe(withHistory, withImages, withStrapiSchema, withReact, withLinks)(createEditor())\n );\n const [liveText, setLiveText] = React.useState('');\n const ariaDescriptionId = React.useId();\n const [isExpandedMode, handleToggleExpand] = React.useReducer((prev) => !prev, false);\n\n /**\n * Editable is not able to hold the ref, https://github.com/ianstormtaylor/slate/issues/4082\n * so with \"useImperativeHandle\" we can use ReactEditor methods to expose to the parent above\n * also not passing forwarded ref here, gives console warning.\n */\n React.useImperativeHandle(\n forwardedRef,\n () => ({\n focus() {\n ReactEditor.focus(editor);\n },\n }),\n [editor]\n );\n\n const { key, incrementSlateUpdatesCount } = useResetKey(value);\n\n const handleSlateChange = (state: Descendant[]) => {\n const isAstChange = editor.operations.some((op) => op.type !== 'set_selection');\n\n if (isAstChange) {\n incrementSlateUpdatesCount();\n\n onChange(name, state as Schema.Attribute.BlocksValue);\n }\n };\n\n const blocks: BlocksStore = {\n ...paragraphBlocks,\n ...headingBlocks,\n ...listBlocks,\n ...linkBlocks,\n ...imageBlocks,\n ...quoteBlocks,\n ...codeBlocks,\n };\n\n return (\n <>\n <VisuallyHidden id={ariaDescriptionId}>\n {formatMessage({\n id: getTranslation('components.Blocks.dnd.instruction'),\n defaultMessage: `To reorder blocks, press Command or Control along with Shift and the Up or Down arrow keys`,\n })}\n </VisuallyHidden>\n <VisuallyHidden aria-live=\"assertive\">{liveText}</VisuallyHidden>\n <Slate\n editor={editor}\n initialValue={value || [{ type: 'paragraph', children: [{ type: 'text', text: '' }] }]}\n onChange={handleSlateChange}\n key={key}\n >\n <BlocksEditorProvider\n blocks={blocks}\n modifiers={modifiers}\n disabled={disabled}\n name={name}\n setLiveText={setLiveText}\n isExpandedMode={isExpandedMode}\n >\n <EditorLayout\n error={error}\n disabled={disabled}\n onToggleExpand={handleToggleExpand}\n ariaDescriptionId={ariaDescriptionId}\n >\n <BlocksToolbar />\n <EditorDivider width=\"100%\" />\n <BlocksContent {...contentProps} />\n {!isExpandedMode && (\n <IconButton\n position=\"absolute\"\n bottom=\"1.2rem\"\n right=\"1.2rem\"\n shadow=\"filterShadow\"\n label={formatMessage({\n id: getTranslation('components.Blocks.expand'),\n defaultMessage: 'Expand',\n })}\n onClick={handleToggleExpand}\n >\n <Expand />\n </IconButton>\n )}\n </EditorLayout>\n </BlocksEditorProvider>\n </Slate>\n </>\n );\n }\n);\n\nexport {\n type BlocksStore,\n type SelectorBlockKey,\n BlocksEditor,\n BlocksEditorProvider,\n useBlocksEditorContext,\n isSelectorBlockKey,\n};\n"],"names":["selectorBlockKeys","isSelectorBlockKey","key","includes","BlocksEditorProvider","usePartialBlocksEditorContext","createContext","useBlocksEditorContext","consumerName","context","state","editor","useSlate","EditorDivider","styled","Divider","theme","colors","neutral200","useResetKey","value","slateUpdatesCount","React","useRef","valueUpdatesCount","setKey","useState","useEffect","current","previousKey","incrementSlateUpdatesCount","pipe","fns","reduce","prev","fn","BlocksEditor","forwardRef","disabled","name","onChange","error","contentProps","forwardedRef","formatMessage","useIntl","withHistory","withImages","withStrapiSchema","withReact","withLinks","createEditor","liveText","setLiveText","ariaDescriptionId","useId","isExpandedMode","handleToggleExpand","useReducer","useImperativeHandle","focus","ReactEditor","handleSlateChange","isAstChange","operations","some","op","type","blocks","paragraphBlocks","headingBlocks","listBlocks","linkBlocks","imageBlocks","quoteBlocks","codeBlocks","_jsxs","_Fragment","_jsx","VisuallyHidden","id","getTranslation","defaultMessage","aria-live","Slate","initialValue","children","text","modifiers","EditorLayout","onToggleExpand","BlocksToolbar","width","BlocksContent","IconButton","position","bottom","right","shadow","label","onClick","Expand"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,MAAMA,iBAAoB,GAAA;AACxB,IAAA,WAAA;AACA,IAAA,aAAA;AACA,IAAA,aAAA;AACA,IAAA,eAAA;AACA,IAAA,cAAA;AACA,IAAA,cAAA;AACA,IAAA,aAAA;AACA,IAAA,cAAA;AACA,IAAA,gBAAA;AACA,IAAA,OAAA;AACA,IAAA,OAAA;AACA,IAAA;AACD,CAAA;AAID,MAAMC,qBAAqB,CAACC,GAAAA,GAAAA;AAC1B,IAAA,OAAO,OAAOA,GAAAA,KAAQ,QAAYF,IAAAA,iBAAAA,CAAkBG,QAAQ,CAACD,GAAAA,CAAAA;AAC/D;AAiBA,MAAM,CAACE,oBAAAA,EAAsBC,6BAA8B,CAAA,GACzDC,yBAAwC,CAAA,cAAA;AAE1C,SAASC,uBACPC,YAAoB,EAAA;AAEpB,IAAA,M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,IAAAA;oBACNc,WAAaA,EAAAA,WAAAA;oBACbG,cAAgBA,EAAAA,cAAAA;AAEhB,oBAAA,QAAA,gBAAAoB,eAACa,CAAAA,yBAAAA,EAAAA;wBACChD,KAAOA,EAAAA,KAAAA;wBACPH,QAAUA,EAAAA,QAAAA;wBACVoD,cAAgBjC,EAAAA,kBAAAA;wBAChBH,iBAAmBA,EAAAA,iBAAAA;;0CAEnBwB,cAACa,CAAAA,2BAAAA,EAAAA,EAAAA,CAAAA;0CACDb,cAACjE,CAAAA,aAAAA,EAAAA;gCAAc+E,KAAM,EAAA;;0CACrBd,cAACe,CAAAA,2BAAAA,EAAAA;AAAe,gCAAA,GAAGnD;;AAClB,4BAAA,CAACc,gCACAsB,cAACgB,CAAAA,uBAAAA,EAAAA;gCACCC,QAAS,EAAA,UAAA;gCACTC,MAAO,EAAA,QAAA;gCACPC,KAAM,EAAA,QAAA;gCACNC,MAAO,EAAA,cAAA;AACPC,gCAAAA,KAAAA,EAAOvD,aAAc,CAAA;AACnBoC,oCAAAA,EAAAA,EAAIC,2BAAe,CAAA,0BAAA,CAAA;oCACnBC,cAAgB,EAAA;AAClB,iCAAA,CAAA;gCACAkB,OAAS3C,EAAAA,kBAAAA;AAET,gCAAA,QAAA,gBAAAqB,cAACuB,CAAAA,YAAAA,EAAAA,EAAAA;;;;;AA/BJnG,aAAAA,EAAAA,GAAAA;;;AAuCb,CAAA;;;;;;;"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
2
2
|
import * as React from 'react';
|
3
3
|
import { createContext } from '@strapi/admin/strapi-admin';
|
4
|
-
import { Divider,
|
4
|
+
import { Divider, VisuallyHidden, IconButton } from '@strapi/design-system';
|
5
5
|
import { Expand } from '@strapi/icons';
|
6
6
|
import { useIntl } from 'react-intl';
|
7
7
|
import { createEditor } from 'slate';
|
@@ -55,12 +55,6 @@ function useBlocksEditorContext(consumerName) {
|
|
55
55
|
* -----------------------------------------------------------------------------------------------*/ const EditorDivider = styled(Divider)`
|
56
56
|
background: ${({ theme })=>theme.colors.neutral200};
|
57
57
|
`;
|
58
|
-
const ExpandIconButton = styled(IconButton)`
|
59
|
-
position: absolute;
|
60
|
-
bottom: 1.2rem;
|
61
|
-
right: 1.2rem;
|
62
|
-
box-shadow: ${({ theme })=>theme.shadows.filterShadow};
|
63
|
-
`;
|
64
58
|
/**
|
65
59
|
* Forces an update of the Slate editor when the value prop changes from outside of Slate.
|
66
60
|
* The root cause is that Slate is not a controlled component: https://github.com/ianstormtaylor/slate/issues/4612
|
@@ -99,10 +93,7 @@ const BlocksEditor = /*#__PURE__*/ React.forwardRef(({ disabled = false, name, o
|
|
99
93
|
const [editor] = React.useState(()=>pipe(withHistory, withImages, withStrapiSchema, withReact, withLinks)(createEditor()));
|
100
94
|
const [liveText, setLiveText] = React.useState('');
|
101
95
|
const ariaDescriptionId = React.useId();
|
102
|
-
const [isExpandedMode,
|
103
|
-
const handleToggleExpand = ()=>{
|
104
|
-
setIsExpandedMode((prev)=>!prev);
|
105
|
-
};
|
96
|
+
const [isExpandedMode, handleToggleExpand] = React.useReducer((prev)=>!prev, false);
|
106
97
|
/**
|
107
98
|
* Editable is not able to hold the ref, https://github.com/ianstormtaylor/slate/issues/4082
|
108
99
|
* so with "useImperativeHandle" we can use ReactEditor methods to expose to the parent above
|
@@ -168,7 +159,7 @@ const BlocksEditor = /*#__PURE__*/ React.forwardRef(({ disabled = false, name, o
|
|
168
159
|
children: /*#__PURE__*/ jsxs(EditorLayout, {
|
169
160
|
error: error,
|
170
161
|
disabled: disabled,
|
171
|
-
|
162
|
+
onToggleExpand: handleToggleExpand,
|
172
163
|
ariaDescriptionId: ariaDescriptionId,
|
173
164
|
children: [
|
174
165
|
/*#__PURE__*/ jsx(BlocksToolbar, {}),
|
@@ -178,7 +169,11 @@ const BlocksEditor = /*#__PURE__*/ React.forwardRef(({ disabled = false, name, o
|
|
178
169
|
/*#__PURE__*/ jsx(BlocksContent, {
|
179
170
|
...contentProps
|
180
171
|
}),
|
181
|
-
!isExpandedMode && /*#__PURE__*/ jsx(
|
172
|
+
!isExpandedMode && /*#__PURE__*/ jsx(IconButton, {
|
173
|
+
position: "absolute",
|
174
|
+
bottom: "1.2rem",
|
175
|
+
right: "1.2rem",
|
176
|
+
shadow: "filterShadow",
|
182
177
|
label: formatMessage({
|
183
178
|
id: getTranslation('components.Blocks.expand'),
|
184
179
|
defaultMessage: 'Expand'
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"BlocksEditor.mjs","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { createContext, type FieldValue } from '@strapi/admin/strapi-admin';\nimport { IconButton, Divider, VisuallyHidden } from '@strapi/design-system';\nimport { Expand } from '@strapi/icons';\nimport { MessageDescriptor, useIntl } from 'react-intl';\nimport { Editor, type Descendant, createEditor } from 'slate';\nimport { withHistory } from 'slate-history';\nimport { type RenderElementProps, Slate, withReact, ReactEditor, useSlate } from 'slate-react';\nimport { styled, type CSSProperties } from 'styled-components';\n\nimport { getTranslation } from '../../../../../utils/translations';\n\nimport { codeBlocks } from './Blocks/Code';\nimport { headingBlocks } from './Blocks/Heading';\nimport { imageBlocks } from './Blocks/Image';\nimport { linkBlocks } from './Blocks/Link';\nimport { listBlocks } from './Blocks/List';\nimport { paragraphBlocks } from './Blocks/Paragraph';\nimport { quoteBlocks } from './Blocks/Quote';\nimport { BlocksContent, type BlocksContentProps } from './BlocksContent';\nimport { BlocksToolbar } from './BlocksToolbar';\nimport { EditorLayout } from './EditorLayout';\nimport { type ModifiersStore, modifiers } from './Modifiers';\nimport { withImages } from './plugins/withImages';\nimport { withLinks } from './plugins/withLinks';\nimport { withStrapiSchema } from './plugins/withStrapiSchema';\n\nimport type { Schema } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * BlocksEditorProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface BaseBlock {\n renderElement: (props: RenderElementProps) => React.JSX.Element;\n matchNode: (node: Schema.Attribute.BlocksNode) => boolean;\n handleConvert?: (editor: Editor) => void | (() => React.JSX.Element);\n handleEnterKey?: (editor: Editor) => void;\n handleBackspaceKey?: (editor: Editor, event: React.KeyboardEvent<HTMLElement>) => void;\n handleTab?: (editor: Editor) => void;\n snippets?: string[];\n dragHandleTopMargin?: CSSProperties['marginTop'];\n}\n\ninterface NonSelectorBlock extends BaseBlock {\n isInBlocksSelector: false;\n}\n\ninterface SelectorBlock extends BaseBlock {\n isInBlocksSelector: true;\n icon: React.ComponentType;\n label: MessageDescriptor;\n}\n\ntype NonSelectorBlockKey = 'list-item' | 'link';\n\nconst selectorBlockKeys = [\n 'paragraph',\n 'heading-one',\n 'heading-two',\n 'heading-three',\n 'heading-four',\n 'heading-five',\n 'heading-six',\n 'list-ordered',\n 'list-unordered',\n 'image',\n 'quote',\n 'code',\n] as const;\n\ntype SelectorBlockKey = (typeof selectorBlockKeys)[number];\n\nconst isSelectorBlockKey = (key: unknown): key is SelectorBlockKey => {\n return typeof key === 'string' && selectorBlockKeys.includes(key as SelectorBlockKey);\n};\n\ntype BlocksStore = {\n [K in SelectorBlockKey]: SelectorBlock;\n} & {\n [K in NonSelectorBlockKey]: NonSelectorBlock;\n};\n\ninterface BlocksEditorContextValue {\n blocks: BlocksStore;\n modifiers: ModifiersStore;\n disabled: boolean;\n name: string;\n setLiveText: (text: string) => void;\n isExpandedMode: boolean;\n}\n\nconst [BlocksEditorProvider, usePartialBlocksEditorContext] =\n createContext<BlocksEditorContextValue>('BlocksEditor');\n\nfunction useBlocksEditorContext(\n consumerName: string\n): BlocksEditorContextValue & { editor: Editor } {\n const context = usePartialBlocksEditorContext(consumerName, (state) => state);\n const editor = useSlate();\n\n return {\n ...context,\n editor,\n };\n}\n\n/* -------------------------------------------------------------------------------------------------\n * BlocksEditor\n * -----------------------------------------------------------------------------------------------*/\n\nconst EditorDivider = styled(Divider)`\n background: ${({ theme }) => theme.colors.neutral200};\n`;\n\nconst ExpandIconButton = styled(IconButton)`\n position: absolute;\n bottom: 1.2rem;\n right: 1.2rem;\n box-shadow: ${({ theme }) => theme.shadows.filterShadow};\n`;\n\n/**\n * Forces an update of the Slate editor when the value prop changes from outside of Slate.\n * The root cause is that Slate is not a controlled component: https://github.com/ianstormtaylor/slate/issues/4612\n * Why not use JSON.stringify(value) as the key?\n * Because it would force a rerender of the entire editor every time the user types a character.\n * Why not use the entity id as the key, since it's unique for each locale?\n * Because it would not solve the problem when using the \"fill in from other locale\" feature\n */\nfunction useResetKey(value?: Schema.Attribute.BlocksValue): {\n key: number;\n incrementSlateUpdatesCount: () => void;\n} {\n // Keep track how many times Slate detected a change from a user interaction in the editor\n const slateUpdatesCount = React.useRef(0);\n // Keep track of how many times the value prop was updated, whether from within editor or from outside\n const valueUpdatesCount = React.useRef(0);\n // Use a key to force a rerender of the Slate editor when needed\n const [key, setKey] = React.useState(0);\n\n React.useEffect(() => {\n valueUpdatesCount.current += 1;\n\n // If the 2 refs are not equal, it means the value was updated from outside\n if (valueUpdatesCount.current !== slateUpdatesCount.current) {\n // So we change the key to force a rerender of the Slate editor,\n // which will pick up the new value through its initialValue prop\n setKey((previousKey) => previousKey + 1);\n\n // Then bring the 2 refs back in sync\n slateUpdatesCount.current = valueUpdatesCount.current;\n }\n }, [value]);\n\n return { key, incrementSlateUpdatesCount: () => (slateUpdatesCount.current += 1) };\n}\n\nconst pipe =\n (...fns: ((baseEditor: Editor) => Editor)[]) =>\n (value: Editor) =>\n fns.reduce<Editor>((prev, fn) => fn(prev), value);\n\ninterface BlocksEditorProps\n extends Pick<FieldValue<Schema.Attribute.BlocksValue>, 'onChange' | 'value' | 'error'>,\n BlocksContentProps {\n disabled?: boolean;\n name: string;\n}\n\nconst BlocksEditor = React.forwardRef<{ focus: () => void }, BlocksEditorProps>(\n ({ disabled = false, name, onChange, value, error, ...contentProps }, forwardedRef) => {\n const { formatMessage } = useIntl();\n const [editor] = React.useState(() =>\n pipe(withHistory, withImages, withStrapiSchema, withReact, withLinks)(createEditor())\n );\n const [liveText, setLiveText] = React.useState('');\n const ariaDescriptionId = React.useId();\n const [isExpandedMode, setIsExpandedMode] = React.useState(false);\n\n const handleToggleExpand = () => {\n setIsExpandedMode((prev) => !prev);\n };\n\n /**\n * Editable is not able to hold the ref, https://github.com/ianstormtaylor/slate/issues/4082\n * so with \"useImperativeHandle\" we can use ReactEditor methods to expose to the parent above\n * also not passing forwarded ref here, gives console warning.\n */\n React.useImperativeHandle(\n forwardedRef,\n () => ({\n focus() {\n ReactEditor.focus(editor);\n },\n }),\n [editor]\n );\n\n const { key, incrementSlateUpdatesCount } = useResetKey(value);\n\n const handleSlateChange = (state: Descendant[]) => {\n const isAstChange = editor.operations.some((op) => op.type !== 'set_selection');\n\n if (isAstChange) {\n incrementSlateUpdatesCount();\n\n onChange(name, state as Schema.Attribute.BlocksValue);\n }\n };\n\n const blocks: BlocksStore = {\n ...paragraphBlocks,\n ...headingBlocks,\n ...listBlocks,\n ...linkBlocks,\n ...imageBlocks,\n ...quoteBlocks,\n ...codeBlocks,\n };\n\n return (\n <>\n <VisuallyHidden id={ariaDescriptionId}>\n {formatMessage({\n id: getTranslation('components.Blocks.dnd.instruction'),\n defaultMessage: `To reorder blocks, press Command or Control along with Shift and the Up or Down arrow keys`,\n })}\n </VisuallyHidden>\n <VisuallyHidden aria-live=\"assertive\">{liveText}</VisuallyHidden>\n <Slate\n editor={editor}\n initialValue={value || [{ type: 'paragraph', children: [{ type: 'text', text: '' }] }]}\n onChange={handleSlateChange}\n key={key}\n >\n <BlocksEditorProvider\n blocks={blocks}\n modifiers={modifiers}\n disabled={disabled}\n name={name}\n setLiveText={setLiveText}\n isExpandedMode={isExpandedMode}\n >\n <EditorLayout\n error={error}\n disabled={disabled}\n onCollapse={handleToggleExpand}\n ariaDescriptionId={ariaDescriptionId}\n >\n <BlocksToolbar />\n <EditorDivider width=\"100%\" />\n <BlocksContent {...contentProps} />\n {!isExpandedMode && (\n <ExpandIconButton\n label={formatMessage({\n id: getTranslation('components.Blocks.expand'),\n defaultMessage: 'Expand',\n })}\n onClick={handleToggleExpand}\n >\n <Expand />\n </ExpandIconButton>\n )}\n </EditorLayout>\n </BlocksEditorProvider>\n </Slate>\n </>\n );\n }\n);\n\nexport {\n type BlocksStore,\n type SelectorBlockKey,\n BlocksEditor,\n BlocksEditorProvider,\n useBlocksEditorContext,\n isSelectorBlockKey,\n};\n"],"names":["selectorBlockKeys","isSelectorBlockKey","key","includes","BlocksEditorProvider","usePartialBlocksEditorContext","createContext","useBlocksEditorContext","consumerName","context","state","editor","useSlate","EditorDivider","styled","Divider","theme","colors","neutral200","ExpandIconButton","IconButton","shadows","filterShadow","useResetKey","value","slateUpdatesCount","React","useRef","valueUpdatesCount","setKey","useState","useEffect","current","previousKey","incrementSlateUpdatesCount","pipe","fns","reduce","prev","fn","BlocksEditor","forwardRef","disabled","name","onChange","error","contentProps","forwardedRef","formatMessage","useIntl","withHistory","withImages","withStrapiSchema","withReact","withLinks","createEditor","liveText","setLiveText","ariaDescriptionId","useId","isExpandedMode","setIsExpandedMode","handleToggleExpand","useImperativeHandle","focus","ReactEditor","handleSlateChange","isAstChange","operations","some","op","type","blocks","paragraphBlocks","headingBlocks","listBlocks","linkBlocks","imageBlocks","quoteBlocks","codeBlocks","_jsxs","_Fragment","_jsx","VisuallyHidden","id","getTranslation","defaultMessage","aria-live","Slate","initialValue","children","text","modifiers","EditorLayout","onCollapse","BlocksToolbar","width","BlocksContent","label","onClick","Expand"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,MAAMA,iBAAoB,GAAA;AACxB,IAAA,WAAA;AACA,IAAA,aAAA;AACA,IAAA,aAAA;AACA,IAAA,eAAA;AACA,IAAA,cAAA;AACA,IAAA,cAAA;AACA,IAAA,aAAA;AACA,IAAA,cAAA;AACA,IAAA,gBAAA;AACA,IAAA,OAAA;AACA,IAAA,OAAA;AACA,IAAA;AACD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;;;AAmCb,CAAA;;;;"}
|
1
|
+
{"version":3,"file":"BlocksEditor.mjs","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { createContext, type FieldValue } from '@strapi/admin/strapi-admin';\nimport { IconButton, Divider, VisuallyHidden } from '@strapi/design-system';\nimport { Expand } from '@strapi/icons';\nimport { MessageDescriptor, useIntl } from 'react-intl';\nimport { Editor, type Descendant, createEditor } from 'slate';\nimport { withHistory } from 'slate-history';\nimport { type RenderElementProps, Slate, withReact, ReactEditor, useSlate } from 'slate-react';\nimport { styled, type CSSProperties } from 'styled-components';\n\nimport { getTranslation } from '../../../../../utils/translations';\n\nimport { codeBlocks } from './Blocks/Code';\nimport { headingBlocks } from './Blocks/Heading';\nimport { imageBlocks } from './Blocks/Image';\nimport { linkBlocks } from './Blocks/Link';\nimport { listBlocks } from './Blocks/List';\nimport { paragraphBlocks } from './Blocks/Paragraph';\nimport { quoteBlocks } from './Blocks/Quote';\nimport { BlocksContent, type BlocksContentProps } from './BlocksContent';\nimport { BlocksToolbar } from './BlocksToolbar';\nimport { EditorLayout } from './EditorLayout';\nimport { type ModifiersStore, modifiers } from './Modifiers';\nimport { withImages } from './plugins/withImages';\nimport { withLinks } from './plugins/withLinks';\nimport { withStrapiSchema } from './plugins/withStrapiSchema';\n\nimport type { Schema } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * BlocksEditorProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface BaseBlock {\n renderElement: (props: RenderElementProps) => React.JSX.Element;\n matchNode: (node: Schema.Attribute.BlocksNode) => boolean;\n handleConvert?: (editor: Editor) => void | (() => React.JSX.Element);\n handleEnterKey?: (editor: Editor) => void;\n handleBackspaceKey?: (editor: Editor, event: React.KeyboardEvent<HTMLElement>) => void;\n handleTab?: (editor: Editor) => void;\n snippets?: string[];\n dragHandleTopMargin?: CSSProperties['marginTop'];\n}\n\ninterface NonSelectorBlock extends BaseBlock {\n isInBlocksSelector: false;\n}\n\ninterface SelectorBlock extends BaseBlock {\n isInBlocksSelector: true;\n icon: React.ComponentType;\n label: MessageDescriptor;\n}\n\ntype NonSelectorBlockKey = 'list-item' | 'link';\n\nconst selectorBlockKeys = [\n 'paragraph',\n 'heading-one',\n 'heading-two',\n 'heading-three',\n 'heading-four',\n 'heading-five',\n 'heading-six',\n 'list-ordered',\n 'list-unordered',\n 'image',\n 'quote',\n 'code',\n] as const;\n\ntype SelectorBlockKey = (typeof selectorBlockKeys)[number];\n\nconst isSelectorBlockKey = (key: unknown): key is SelectorBlockKey => {\n return typeof key === 'string' && selectorBlockKeys.includes(key as SelectorBlockKey);\n};\n\ntype BlocksStore = {\n [K in SelectorBlockKey]: SelectorBlock;\n} & {\n [K in NonSelectorBlockKey]: NonSelectorBlock;\n};\n\ninterface BlocksEditorContextValue {\n blocks: BlocksStore;\n modifiers: ModifiersStore;\n disabled: boolean;\n name: string;\n setLiveText: (text: string) => void;\n isExpandedMode: boolean;\n}\n\nconst [BlocksEditorProvider, usePartialBlocksEditorContext] =\n createContext<BlocksEditorContextValue>('BlocksEditor');\n\nfunction useBlocksEditorContext(\n consumerName: string\n): BlocksEditorContextValue & { editor: Editor } {\n const context = usePartialBlocksEditorContext(consumerName, (state) => state);\n const editor = useSlate();\n\n return {\n ...context,\n editor,\n };\n}\n\n/* -------------------------------------------------------------------------------------------------\n * BlocksEditor\n * -----------------------------------------------------------------------------------------------*/\n\nconst EditorDivider = styled(Divider)`\n background: ${({ theme }) => theme.colors.neutral200};\n`;\n\n/**\n * Forces an update of the Slate editor when the value prop changes from outside of Slate.\n * The root cause is that Slate is not a controlled component: https://github.com/ianstormtaylor/slate/issues/4612\n * Why not use JSON.stringify(value) as the key?\n * Because it would force a rerender of the entire editor every time the user types a character.\n * Why not use the entity id as the key, since it's unique for each locale?\n * Because it would not solve the problem when using the \"fill in from other locale\" feature\n */\nfunction useResetKey(value?: Schema.Attribute.BlocksValue): {\n key: number;\n incrementSlateUpdatesCount: () => void;\n} {\n // Keep track how many times Slate detected a change from a user interaction in the editor\n const slateUpdatesCount = React.useRef(0);\n // Keep track of how many times the value prop was updated, whether from within editor or from outside\n const valueUpdatesCount = React.useRef(0);\n // Use a key to force a rerender of the Slate editor when needed\n const [key, setKey] = React.useState(0);\n\n React.useEffect(() => {\n valueUpdatesCount.current += 1;\n\n // If the 2 refs are not equal, it means the value was updated from outside\n if (valueUpdatesCount.current !== slateUpdatesCount.current) {\n // So we change the key to force a rerender of the Slate editor,\n // which will pick up the new value through its initialValue prop\n setKey((previousKey) => previousKey + 1);\n\n // Then bring the 2 refs back in sync\n slateUpdatesCount.current = valueUpdatesCount.current;\n }\n }, [value]);\n\n return { key, incrementSlateUpdatesCount: () => (slateUpdatesCount.current += 1) };\n}\n\nconst pipe =\n (...fns: ((baseEditor: Editor) => Editor)[]) =>\n (value: Editor) =>\n fns.reduce<Editor>((prev, fn) => fn(prev), value);\n\ninterface BlocksEditorProps\n extends Pick<FieldValue<Schema.Attribute.BlocksValue>, 'onChange' | 'value' | 'error'>,\n BlocksContentProps {\n disabled?: boolean;\n name: string;\n}\n\nconst BlocksEditor = React.forwardRef<{ focus: () => void }, BlocksEditorProps>(\n ({ disabled = false, name, onChange, value, error, ...contentProps }, forwardedRef) => {\n const { formatMessage } = useIntl();\n const [editor] = React.useState(() =>\n pipe(withHistory, withImages, withStrapiSchema, withReact, withLinks)(createEditor())\n );\n const [liveText, setLiveText] = React.useState('');\n const ariaDescriptionId = React.useId();\n const [isExpandedMode, handleToggleExpand] = React.useReducer((prev) => !prev, false);\n\n /**\n * Editable is not able to hold the ref, https://github.com/ianstormtaylor/slate/issues/4082\n * so with \"useImperativeHandle\" we can use ReactEditor methods to expose to the parent above\n * also not passing forwarded ref here, gives console warning.\n */\n React.useImperativeHandle(\n forwardedRef,\n () => ({\n focus() {\n ReactEditor.focus(editor);\n },\n }),\n [editor]\n );\n\n const { key, incrementSlateUpdatesCount } = useResetKey(value);\n\n const handleSlateChange = (state: Descendant[]) => {\n const isAstChange = editor.operations.some((op) => op.type !== 'set_selection');\n\n if (isAstChange) {\n incrementSlateUpdatesCount();\n\n onChange(name, state as Schema.Attribute.BlocksValue);\n }\n };\n\n const blocks: BlocksStore = {\n ...paragraphBlocks,\n ...headingBlocks,\n ...listBlocks,\n ...linkBlocks,\n ...imageBlocks,\n ...quoteBlocks,\n ...codeBlocks,\n };\n\n return (\n <>\n <VisuallyHidden id={ariaDescriptionId}>\n {formatMessage({\n id: getTranslation('components.Blocks.dnd.instruction'),\n defaultMessage: `To reorder blocks, press Command or Control along with Shift and the Up or Down arrow keys`,\n })}\n </VisuallyHidden>\n <VisuallyHidden aria-live=\"assertive\">{liveText}</VisuallyHidden>\n <Slate\n editor={editor}\n initialValue={value || [{ type: 'paragraph', children: [{ type: 'text', text: '' }] }]}\n onChange={handleSlateChange}\n key={key}\n >\n <BlocksEditorProvider\n blocks={blocks}\n modifiers={modifiers}\n disabled={disabled}\n name={name}\n setLiveText={setLiveText}\n isExpandedMode={isExpandedMode}\n >\n <EditorLayout\n error={error}\n disabled={disabled}\n onToggleExpand={handleToggleExpand}\n ariaDescriptionId={ariaDescriptionId}\n >\n <BlocksToolbar />\n <EditorDivider width=\"100%\" />\n <BlocksContent {...contentProps} />\n {!isExpandedMode && (\n <IconButton\n position=\"absolute\"\n bottom=\"1.2rem\"\n right=\"1.2rem\"\n shadow=\"filterShadow\"\n label={formatMessage({\n id: getTranslation('components.Blocks.expand'),\n defaultMessage: 'Expand',\n })}\n onClick={handleToggleExpand}\n >\n <Expand />\n </IconButton>\n )}\n </EditorLayout>\n </BlocksEditorProvider>\n </Slate>\n </>\n );\n }\n);\n\nexport {\n type BlocksStore,\n type SelectorBlockKey,\n BlocksEditor,\n BlocksEditorProvider,\n useBlocksEditorContext,\n isSelectorBlockKey,\n};\n"],"names":["selectorBlockKeys","isSelectorBlockKey","key","includes","BlocksEditorProvider","usePartialBlocksEditorContext","createContext","useBlocksEditorContext","consumerName","context","state","editor","useSlate","EditorDivider","styled","Divider","theme","colors","neutral200","useResetKey","value","slateUpdatesCount","React","useRef","valueUpdatesCount","setKey","useState","useEffect","current","previousKey","incrementSlateUpdatesCount","pipe","fns","reduce","prev","fn","BlocksEditor","forwardRef","disabled","name","onChange","error","contentProps","forwardedRef","formatMessage","useIntl","withHistory","withImages","withStrapiSchema","withReact","withLinks","createEditor","liveText","setLiveText","ariaDescriptionId","useId","isExpandedMode","handleToggleExpand","useReducer","useImperativeHandle","focus","ReactEditor","handleSlateChange","isAstChange","operations","some","op","type","blocks","paragraphBlocks","headingBlocks","listBlocks","linkBlocks","imageBlocks","quoteBlocks","codeBlocks","_jsxs","_Fragment","_jsx","VisuallyHidden","id","getTranslation","defaultMessage","aria-live","Slate","initialValue","children","text","modifiers","EditorLayout","onToggleExpand","BlocksToolbar","width","BlocksContent","IconButton","position","bottom","right","shadow","label","onClick","Expand"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,MAAMA,iBAAoB,GAAA;AACxB,IAAA,WAAA;AACA,IAAA,aAAA;AACA,IAAA,aAAA;AACA,IAAA,eAAA;AACA,IAAA,cAAA;AACA,IAAA,cAAA;AACA,IAAA,aAAA;AACA,IAAA,cAAA;AACA,IAAA,gBAAA;AACA,IAAA,OAAA;AACA,IAAA,OAAA;AACA,IAAA;AACD,CAAA;AAID,MAAMC,qBAAqB,CAACC,GAAAA,GAAAA;AAC1B,IAAA,OAAO,OAAOA,GAAAA,KAAQ,QAAYF,IAAAA,iBAAAA,CAAkBG,QAAQ,CAACD,GAAAA,CAAAA;AAC/D;AAiBA,MAAM,CAACE,oBAAAA,EAAsBC,6BAA8B,CAAA,GACzDC,aAAwC,CAAA,cAAA;AAE1C,SAASC,uBACPC,YAAoB,EAAA;AAEpB,IAAA,MAAMC,OAAUJ,GAAAA,6BAAAA,CAA8BG,YAAc,EAAA,CAACE,KAAUA,GAAAA,KAAAA,CAAAA;AACvE,IAAA,MAAMC,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AAAA,KAAAA;wBACPH,QAAUA,EAAAA,QAAAA;wBACVoD,cAAgBjC,EAAAA,kBAAAA;wBAChBH,iBAAmBA,EAAAA,iBAAAA;;0CAEnBwB,GAACa,CAAAA,aAAAA,EAAAA,EAAAA,CAAAA;0CACDb,GAACjE,CAAAA,aAAAA,EAAAA;gCAAc+E,KAAM,EAAA;;0CACrBd,GAACe,CAAAA,aAAAA,EAAAA;AAAe,gCAAA,GAAGnD;;AAClB,4BAAA,CAACc,gCACAsB,GAACgB,CAAAA,UAAAA,EAAAA;gCACCC,QAAS,EAAA,UAAA;gCACTC,MAAO,EAAA,QAAA;gCACPC,KAAM,EAAA,QAAA;gCACNC,MAAO,EAAA,cAAA;AACPC,gCAAAA,KAAAA,EAAOvD,aAAc,CAAA;AACnBoC,oCAAAA,EAAAA,EAAIC,cAAe,CAAA,0BAAA,CAAA;oCACnBC,cAAgB,EAAA;AAClB,iCAAA,CAAA;gCACAkB,OAAS3C,EAAAA,kBAAAA;AAET,gCAAA,QAAA,gBAAAqB,GAACuB,CAAAA,MAAAA,EAAAA,EAAAA;;;;;AA/BJnG,aAAAA,EAAAA,GAAAA;;;AAuCb,CAAA;;;;"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
4
|
-
|
4
|
+
require('react');
|
5
5
|
var designSystem = require('@strapi/design-system');
|
6
6
|
var Icons = require('@strapi/icons');
|
7
7
|
var reactIntl = require('react-intl');
|
@@ -9,105 +9,56 @@ var styledComponents = require('styled-components');
|
|
9
9
|
var translations = require('../../../../../utils/translations.js');
|
10
10
|
var BlocksEditor = require('./BlocksEditor.js');
|
11
11
|
|
12
|
-
|
13
|
-
var n = Object.create(null);
|
14
|
-
if (e) {
|
15
|
-
Object.keys(e).forEach(function (k) {
|
16
|
-
if (k !== 'default') {
|
17
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
18
|
-
Object.defineProperty(n, k, d.get ? d : {
|
19
|
-
enumerable: true,
|
20
|
-
get: function () { return e[k]; }
|
21
|
-
});
|
22
|
-
}
|
23
|
-
});
|
24
|
-
}
|
25
|
-
n.default = e;
|
26
|
-
return Object.freeze(n);
|
27
|
-
}
|
28
|
-
|
29
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
30
|
-
|
31
|
-
const CollapseIconButton = styledComponents.styled(designSystem.IconButton)`
|
32
|
-
position: absolute;
|
33
|
-
bottom: 1.2rem;
|
34
|
-
right: 1.2rem;
|
35
|
-
`;
|
36
|
-
const ExpandWrapper = styledComponents.styled(designSystem.Flex)`
|
37
|
-
// Background with 20% opacity
|
38
|
-
background: ${({ theme })=>`${theme.colors.neutral800}1F`};
|
39
|
-
`;
|
40
|
-
const EditorLayout = ({ children, error, disabled, onCollapse, ariaDescriptionId })=>{
|
12
|
+
const EditorLayout = ({ children, error, disabled, onToggleExpand, ariaDescriptionId })=>{
|
41
13
|
const { formatMessage } = reactIntl.useIntl();
|
42
14
|
const { isExpandedMode } = BlocksEditor.useBlocksEditorContext('editorLayout');
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
width: "90%",
|
74
|
-
height: "90%",
|
75
|
-
onClick: (e)=>e.stopPropagation(),
|
76
|
-
"aria-describedby": ariaDescriptionId,
|
77
|
-
position: "relative",
|
78
|
-
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
79
|
-
height: "100%",
|
80
|
-
alignItems: "flex-start",
|
81
|
-
direction: "column",
|
82
|
-
children: [
|
83
|
-
children,
|
84
|
-
/*#__PURE__*/ jsxRuntime.jsx(CollapseIconButton, {
|
85
|
-
label: formatMessage({
|
86
|
-
id: translations.getTranslation('components.Blocks.collapse'),
|
87
|
-
defaultMessage: 'Collapse'
|
88
|
-
}),
|
89
|
-
onClick: onCollapse,
|
90
|
-
children: /*#__PURE__*/ jsxRuntime.jsx(Icons.Collapse, {})
|
91
|
-
})
|
92
|
-
]
|
93
|
-
})
|
15
|
+
return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
16
|
+
children: [
|
17
|
+
isExpandedMode && /*#__PURE__*/ jsxRuntime.jsx(designSystem.Modal.Root, {
|
18
|
+
open: isExpandedMode,
|
19
|
+
onOpenChange: onToggleExpand,
|
20
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Modal.Content, {
|
21
|
+
style: {
|
22
|
+
maxWidth: 'unset',
|
23
|
+
width: 'unset'
|
24
|
+
},
|
25
|
+
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
26
|
+
height: "90vh",
|
27
|
+
width: "90vw",
|
28
|
+
alignItems: "flex-start",
|
29
|
+
direction: "column",
|
30
|
+
children: [
|
31
|
+
children,
|
32
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.IconButton, {
|
33
|
+
position: "absolute",
|
34
|
+
bottom: "1.2rem",
|
35
|
+
right: "1.2rem",
|
36
|
+
shadow: "filterShadow",
|
37
|
+
label: formatMessage({
|
38
|
+
id: translations.getTranslation('components.Blocks.collapse'),
|
39
|
+
defaultMessage: 'Collapse'
|
40
|
+
}),
|
41
|
+
onClick: onToggleExpand,
|
42
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(Icons.Collapse, {})
|
43
|
+
})
|
44
|
+
]
|
94
45
|
})
|
95
46
|
})
|
47
|
+
}),
|
48
|
+
/*#__PURE__*/ jsxRuntime.jsx(InputWrapper, {
|
49
|
+
direction: "column",
|
50
|
+
alignItems: "flex-start",
|
51
|
+
height: "512px",
|
52
|
+
$disabled: disabled,
|
53
|
+
$hasError: Boolean(error),
|
54
|
+
style: {
|
55
|
+
overflow: 'hidden'
|
56
|
+
},
|
57
|
+
"aria-describedby": ariaDescriptionId,
|
58
|
+
position: "relative",
|
59
|
+
children: !isExpandedMode && children
|
96
60
|
})
|
97
|
-
|
98
|
-
}
|
99
|
-
return /*#__PURE__*/ jsxRuntime.jsx(InputWrapper, {
|
100
|
-
direction: "column",
|
101
|
-
alignItems: "flex-start",
|
102
|
-
height: "512px",
|
103
|
-
$disabled: disabled,
|
104
|
-
$hasError: Boolean(error),
|
105
|
-
style: {
|
106
|
-
overflow: 'hidden'
|
107
|
-
},
|
108
|
-
"aria-describedby": ariaDescriptionId,
|
109
|
-
position: "relative",
|
110
|
-
children: children
|
61
|
+
]
|
111
62
|
});
|
112
63
|
};
|
113
64
|
const InputWrapper = styledComponents.styled(designSystem.Flex)`
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"EditorLayout.js","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/EditorLayout.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {
|
1
|
+
{"version":3,"file":"EditorLayout.js","sources":["../../../../../../../admin/src/pages/EditView/components/FormInputs/BlocksInput/EditorLayout.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Flex, IconButton, FlexComponent, Modal } from '@strapi/design-system';\nimport { Collapse } from '@strapi/icons';\nimport { useIntl } from 'react-intl';\nimport { css, styled } from 'styled-components';\n\nimport { getTranslation } from '../../../../../utils/translations';\n\nimport { useBlocksEditorContext } from './BlocksEditor';\n\ninterface EditorLayoutProps {\n children: React.ReactNode;\n error?: string;\n onToggleExpand: () => void;\n disabled: boolean;\n ariaDescriptionId: string;\n}\n\nconst EditorLayout = ({\n children,\n error,\n disabled,\n onToggleExpand,\n ariaDescriptionId,\n}: EditorLayoutProps) => {\n const { formatMessage } = useIntl();\n const { isExpandedMode } = useBlocksEditorContext('editorLayout');\n\n return (\n <>\n {isExpandedMode && (\n <Modal.Root open={isExpandedMode} onOpenChange={onToggleExpand}>\n <Modal.Content style={{ maxWidth: 'unset', width: 'unset' }}>\n <Flex height=\"90vh\" width=\"90vw\" alignItems=\"flex-start\" direction=\"column\">\n {children}\n <IconButton\n position=\"absolute\"\n bottom=\"1.2rem\"\n right=\"1.2rem\"\n shadow=\"filterShadow\"\n label={formatMessage({\n id: getTranslation('components.Blocks.collapse'),\n defaultMessage: 'Collapse',\n })}\n onClick={onToggleExpand}\n >\n <Collapse />\n </IconButton>\n </Flex>\n </Modal.Content>\n </Modal.Root>\n )}\n <InputWrapper\n direction=\"column\"\n alignItems=\"flex-start\"\n height=\"512px\"\n $disabled={disabled}\n $hasError={Boolean(error)}\n style={{ overflow: 'hidden' }}\n aria-describedby={ariaDescriptionId}\n position=\"relative\"\n >\n {!isExpandedMode && children}\n </InputWrapper>\n </>\n );\n};\n\nconst InputWrapper = styled<FlexComponent>(Flex)<{ $disabled?: boolean; $hasError?: boolean }>`\n border: 1px solid\n ${({ theme, $hasError }) => ($hasError ? theme.colors.danger600 : theme.colors.neutral200)};\n border-radius: ${({ theme }) => theme.borderRadius};\n background: ${({ theme }) => theme.colors.neutral0};\n\n ${({ theme, $hasError = false }) => css`\n outline: none;\n box-shadow: 0;\n transition-property: border-color, box-shadow, fill;\n transition-duration: 0.2s;\n\n &:focus-within {\n border: 1px solid ${$hasError ? theme.colors.danger600 : theme.colors.primary600};\n box-shadow: ${$hasError ? theme.colors.danger600 : theme.colors.primary600} 0px 0px 0px 2px;\n }\n `}\n\n ${({ theme, $disabled }) =>\n $disabled\n ? css`\n color: ${theme.colors.neutral600};\n background: ${theme.colors.neutral150};\n `\n : undefined}\n`;\n\nexport { EditorLayout };\n"],"names":["EditorLayout","children","error","disabled","onToggleExpand","ariaDescriptionId","formatMessage","useIntl","isExpandedMode","useBlocksEditorContext","_jsxs","_Fragment","_jsx","Modal","Root","open","onOpenChange","Content","style","maxWidth","width","Flex","height","alignItems","direction","IconButton","position","bottom","right","shadow","label","id","getTranslation","defaultMessage","onClick","Collapse","InputWrapper","$disabled","$hasError","Boolean","overflow","aria-describedby","styled","theme","colors","danger600","neutral200","borderRadius","neutral0","css","primary600","neutral600","neutral150","undefined"],"mappings":";;;;;;;;;;;AAmBA,MAAMA,YAAe,GAAA,CAAC,EACpBC,QAAQ,EACRC,KAAK,EACLC,QAAQ,EACRC,cAAc,EACdC,iBAAiB,EACC,GAAA;IAClB,MAAM,EAAEC,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;AAC1B,IAAA,MAAM,EAAEC,cAAc,EAAE,GAAGC,mCAAuB,CAAA,cAAA,CAAA;IAElD,qBACEC,eAAA,CAAAC,mBAAA,EAAA;;YACGH,cACC,kBAAAI,cAAA,CAACC,mBAAMC,IAAI,EAAA;gBAACC,IAAMP,EAAAA,cAAAA;gBAAgBQ,YAAcZ,EAAAA,cAAAA;wCAC9CQ,cAAA,CAACC,mBAAMI,OAAO,EAAA;oBAACC,KAAO,EAAA;wBAAEC,QAAU,EAAA,OAAA;wBAASC,KAAO,EAAA;AAAQ,qBAAA;AACxD,oBAAA,QAAA,gBAAAV,eAACW,CAAAA,iBAAAA,EAAAA;wBAAKC,MAAO,EAAA,MAAA;wBAAOF,KAAM,EAAA,MAAA;wBAAOG,UAAW,EAAA,YAAA;wBAAaC,SAAU,EAAA,QAAA;;AAChEvB,4BAAAA,QAAAA;0CACDW,cAACa,CAAAA,uBAAAA,EAAAA;gCACCC,QAAS,EAAA,UAAA;gCACTC,MAAO,EAAA,QAAA;gCACPC,KAAM,EAAA,QAAA;gCACNC,MAAO,EAAA,cAAA;AACPC,gCAAAA,KAAAA,EAAOxB,aAAc,CAAA;AACnByB,oCAAAA,EAAAA,EAAIC,2BAAe,CAAA,4BAAA,CAAA;oCACnBC,cAAgB,EAAA;AAClB,iCAAA,CAAA;gCACAC,OAAS9B,EAAAA,cAAAA;AAET,gCAAA,QAAA,gBAAAQ,cAACuB,CAAAA,cAAAA,EAAAA,EAAAA;;;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A,EAAER,KAAMC,CAAAA,MAAM,CAACQ,UAAU,CAAC;AACxC,QAAA,CAAC,GACDC,SAAU;AAClB,CAAC;;;;"}
|
@@ -1,92 +1,62 @@
|
|
1
|
-
import {
|
2
|
-
import
|
3
|
-
import {
|
1
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
2
|
+
import 'react';
|
3
|
+
import { Flex, Modal, IconButton } from '@strapi/design-system';
|
4
4
|
import { Collapse } from '@strapi/icons';
|
5
5
|
import { useIntl } from 'react-intl';
|
6
6
|
import { styled, css } from 'styled-components';
|
7
7
|
import { getTranslation } from '../../../../../utils/translations.mjs';
|
8
8
|
import { useBlocksEditorContext } from './BlocksEditor.mjs';
|
9
9
|
|
10
|
-
const
|
11
|
-
position: absolute;
|
12
|
-
bottom: 1.2rem;
|
13
|
-
right: 1.2rem;
|
14
|
-
`;
|
15
|
-
const ExpandWrapper = styled(Flex)`
|
16
|
-
// Background with 20% opacity
|
17
|
-
background: ${({ theme })=>`${theme.colors.neutral800}1F`};
|
18
|
-
`;
|
19
|
-
const EditorLayout = ({ children, error, disabled, onCollapse, ariaDescriptionId })=>{
|
10
|
+
const EditorLayout = ({ children, error, disabled, onToggleExpand, ariaDescriptionId })=>{
|
20
11
|
const { formatMessage } = useIntl();
|
21
12
|
const { isExpandedMode } = useBlocksEditorContext('editorLayout');
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
width: "90%",
|
53
|
-
height: "90%",
|
54
|
-
onClick: (e)=>e.stopPropagation(),
|
55
|
-
"aria-describedby": ariaDescriptionId,
|
56
|
-
position: "relative",
|
57
|
-
children: /*#__PURE__*/ jsxs(Flex, {
|
58
|
-
height: "100%",
|
59
|
-
alignItems: "flex-start",
|
60
|
-
direction: "column",
|
61
|
-
children: [
|
62
|
-
children,
|
63
|
-
/*#__PURE__*/ jsx(CollapseIconButton, {
|
64
|
-
label: formatMessage({
|
65
|
-
id: getTranslation('components.Blocks.collapse'),
|
66
|
-
defaultMessage: 'Collapse'
|
67
|
-
}),
|
68
|
-
onClick: onCollapse,
|
69
|
-
children: /*#__PURE__*/ jsx(Collapse, {})
|
70
|
-
})
|
71
|
-
]
|
72
|
-
})
|
13
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
14
|
+
children: [
|
15
|
+
isExpandedMode && /*#__PURE__*/ jsx(Modal.Root, {
|
16
|
+
open: isExpandedMode,
|
17
|
+
onOpenChange: onToggleExpand,
|
18
|
+
children: /*#__PURE__*/ jsx(Modal.Content, {
|
19
|
+
style: {
|
20
|
+
maxWidth: 'unset',
|
21
|
+
width: 'unset'
|
22
|
+
},
|
23
|
+
children: /*#__PURE__*/ jsxs(Flex, {
|
24
|
+
height: "90vh",
|
25
|
+
width: "90vw",
|
26
|
+
alignItems: "flex-start",
|
27
|
+
direction: "column",
|
28
|
+
children: [
|
29
|
+
children,
|
30
|
+
/*#__PURE__*/ jsx(IconButton, {
|
31
|
+
position: "absolute",
|
32
|
+
bottom: "1.2rem",
|
33
|
+
right: "1.2rem",
|
34
|
+
shadow: "filterShadow",
|
35
|
+
label: formatMessage({
|
36
|
+
id: getTranslation('components.Blocks.collapse'),
|
37
|
+
defaultMessage: 'Collapse'
|
38
|
+
}),
|
39
|
+
onClick: onToggleExpand,
|
40
|
+
children: /*#__PURE__*/ jsx(Collapse, {})
|
41
|
+
})
|
42
|
+
]
|
73
43
|
})
|
74
44
|
})
|
45
|
+
}),
|
46
|
+
/*#__PURE__*/ jsx(InputWrapper, {
|
47
|
+
direction: "column",
|
48
|
+
alignItems: "flex-start",
|
49
|
+
height: "512px",
|
50
|
+
$disabled: disabled,
|
51
|
+
$hasError: Boolean(error),
|
52
|
+
style: {
|
53
|
+
overflow: 'hidden'
|
54
|
+
},
|
55
|
+
"aria-describedby": ariaDescriptionId,
|
56
|
+
position: "relative",
|
57
|
+
children: !isExpandedMode && children
|
75
58
|
})
|
76
|
-
|
77
|
-
}
|
78
|
-
return /*#__PURE__*/ jsx(InputWrapper, {
|
79
|
-
direction: "column",
|
80
|
-
alignItems: "flex-start",
|
81
|
-
height: "512px",
|
82
|
-
$disabled: disabled,
|
83
|
-
$hasError: Boolean(error),
|
84
|
-
style: {
|
85
|
-
overflow: 'hidden'
|
86
|
-
},
|
87
|
-
"aria-describedby": ariaDescriptionId,
|
88
|
-
position: "relative",
|
89
|
-
children: children
|
59
|
+
]
|
90
60
|
});
|
91
61
|
};
|
92
62
|
const InputWrapper = styled(Flex)`
|