@payloadcms/richtext-lexical 3.0.0-beta.133 → 3.0.0-beta.134
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/exports/client/Field-S5G27AVI.js +2 -0
- package/dist/exports/client/Field-S5G27AVI.js.map +7 -0
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/chunk-2CYU43GM.js +2 -0
- package/dist/exports/client/chunk-2CYU43GM.js.map +7 -0
- package/dist/exports/client/chunk-C7S3V4EB.js +2 -0
- package/dist/exports/client/chunk-C7S3V4EB.js.map +7 -0
- package/dist/exports/client/chunk-U7O7EYCP.js +2 -0
- package/dist/exports/client/chunk-U7O7EYCP.js.map +7 -0
- package/dist/exports/client/component-H3EYQ5KG.js +2 -0
- package/dist/exports/client/{component-YICNYPTU.js.map → component-H3EYQ5KG.js.map} +1 -1
- package/dist/exports/client/componentInline-ZGO3K4TA.js +2 -0
- package/dist/exports/client/componentInline-ZGO3K4TA.js.map +7 -0
- package/dist/exports/client/index.d.ts +7 -0
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +7 -7
- package/dist/exports/client/index.js.map +4 -4
- package/dist/features/blocks/client/component/BlockContent.d.ts +34 -9
- package/dist/features/blocks/client/component/BlockContent.d.ts.map +1 -1
- package/dist/features/blocks/client/component/BlockContent.js +63 -158
- package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
- package/dist/features/blocks/client/component/components/BlockCollapsible.d.ts +11 -0
- package/dist/features/blocks/client/component/components/BlockCollapsible.d.ts.map +1 -0
- package/dist/features/blocks/client/component/components/BlockCollapsible.js +37 -0
- package/dist/features/blocks/client/component/components/BlockCollapsible.js.map +1 -0
- package/dist/features/blocks/client/component/components/BlockEditButton.d.ts +3 -0
- package/dist/features/blocks/client/component/components/BlockEditButton.d.ts.map +1 -0
- package/dist/features/blocks/client/component/components/BlockEditButton.js +22 -0
- package/dist/features/blocks/client/component/components/BlockEditButton.js.map +1 -0
- package/dist/features/blocks/client/component/components/BlockRemoveButton.d.ts +3 -0
- package/dist/features/blocks/client/component/components/BlockRemoveButton.d.ts.map +1 -0
- package/dist/features/blocks/client/component/components/BlockRemoveButton.js +22 -0
- package/dist/features/blocks/client/component/components/BlockRemoveButton.js.map +1 -0
- package/dist/features/blocks/client/component/index.d.ts.map +1 -1
- package/dist/features/blocks/client/component/index.js +242 -63
- package/dist/features/blocks/client/component/index.js.map +1 -1
- package/dist/features/blocks/client/componentInline/components/InlineBlockContainer.d.ts +5 -0
- package/dist/features/blocks/client/componentInline/components/InlineBlockContainer.d.ts.map +1 -0
- package/dist/features/blocks/client/componentInline/components/InlineBlockContainer.js +28 -0
- package/dist/features/blocks/client/componentInline/components/InlineBlockContainer.js.map +1 -0
- package/dist/features/blocks/client/componentInline/components/InlineBlockEditButton.d.ts +3 -0
- package/dist/features/blocks/client/componentInline/components/InlineBlockEditButton.d.ts.map +1 -0
- package/dist/features/blocks/client/componentInline/components/InlineBlockEditButton.js +22 -0
- package/dist/features/blocks/client/componentInline/components/InlineBlockEditButton.js.map +1 -0
- package/dist/features/blocks/client/componentInline/components/InlineBlockLabel.d.ts +3 -0
- package/dist/features/blocks/client/componentInline/components/InlineBlockLabel.d.ts.map +1 -0
- package/dist/features/blocks/client/componentInline/components/InlineBlockLabel.js +22 -0
- package/dist/features/blocks/client/componentInline/components/InlineBlockLabel.js.map +1 -0
- package/dist/features/blocks/client/componentInline/components/InlineBlockRemoveButton.d.ts +3 -0
- package/dist/features/blocks/client/componentInline/components/InlineBlockRemoveButton.d.ts.map +1 -0
- package/dist/features/blocks/client/componentInline/components/InlineBlockRemoveButton.js +22 -0
- package/dist/features/blocks/client/componentInline/components/InlineBlockRemoveButton.js.map +1 -0
- package/dist/features/blocks/client/componentInline/index.d.ts +13 -1
- package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
- package/dist/features/blocks/client/componentInline/index.js +219 -43
- package/dist/features/blocks/client/componentInline/index.js.map +1 -1
- package/dist/features/blocks/client/index.d.ts.map +1 -1
- package/dist/features/blocks/client/index.js +7 -10
- package/dist/features/blocks/client/index.js.map +1 -1
- package/dist/features/blocks/client/nodes/BlocksNode.d.ts.map +1 -1
- package/dist/features/blocks/client/nodes/BlocksNode.js +1 -3
- package/dist/features/blocks/client/nodes/BlocksNode.js.map +1 -1
- package/dist/features/blocks/client/plugin/commands.d.ts +0 -4
- package/dist/features/blocks/client/plugin/commands.d.ts.map +1 -1
- package/dist/features/blocks/client/plugin/commands.js +0 -1
- package/dist/features/blocks/client/plugin/commands.js.map +1 -1
- package/dist/features/blocks/client/plugin/index.d.ts.map +1 -1
- package/dist/features/blocks/client/plugin/index.js +28 -135
- package/dist/features/blocks/client/plugin/index.js.map +1 -1
- package/dist/features/blocks/server/index.d.ts.map +1 -1
- package/dist/features/blocks/server/index.js +28 -2
- package/dist/features/blocks/server/index.js.map +1 -1
- package/dist/features/typesClient.d.ts +1 -17
- package/dist/features/typesClient.d.ts.map +1 -1
- package/dist/features/typesClient.js.map +1 -1
- package/dist/field/Field.d.ts.map +1 -1
- package/dist/field/Field.js +163 -78
- package/dist/field/Field.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/field/rscEntry.d.ts.map +1 -1
- package/dist/field/rscEntry.js +23 -1
- package/dist/field/rscEntry.js.map +1 -1
- package/dist/lexical/LexicalProvider.d.ts.map +1 -1
- package/dist/lexical/LexicalProvider.js +9 -18
- package/dist/lexical/LexicalProvider.js.map +1 -1
- package/dist/lexical/config/client/sanitize.d.ts.map +1 -1
- package/dist/lexical/config/client/sanitize.js +0 -12
- package/dist/lexical/config/client/sanitize.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/buildInitialState.d.ts +27 -0
- package/dist/utilities/buildInitialState.d.ts.map +1 -0
- package/dist/utilities/buildInitialState.js +53 -0
- package/dist/utilities/buildInitialState.js.map +1 -0
- package/dist/utilities/fieldsDrawer/DrawerContent.d.ts.map +1 -1
- package/dist/utilities/fieldsDrawer/DrawerContent.js +8 -5
- package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -1
- package/dist/utilities/fieldsDrawer/useLexicalDrawer.d.ts.map +1 -1
- package/dist/utilities/fieldsDrawer/useLexicalDrawer.js +8 -8
- package/dist/utilities/fieldsDrawer/useLexicalDrawer.js.map +1 -1
- package/package.json +6 -6
- package/dist/exports/client/Field-GWJ72IYP.js +0 -2
- package/dist/exports/client/Field-GWJ72IYP.js.map +0 -7
- package/dist/exports/client/chunk-D7PD5DUW.js +0 -2
- package/dist/exports/client/chunk-D7PD5DUW.js.map +0 -7
- package/dist/exports/client/chunk-XDEGE6I5.js +0 -2
- package/dist/exports/client/chunk-XDEGE6I5.js.map +0 -7
- package/dist/exports/client/chunk-YGRKYSDC.js +0 -2
- package/dist/exports/client/chunk-YGRKYSDC.js.map +0 -7
- package/dist/exports/client/component-KLNTKKNE.js +0 -2
- package/dist/exports/client/component-KLNTKKNE.js.map +0 -7
- package/dist/exports/client/component-YICNYPTU.js +0 -2
- package/dist/exports/client/componentInline-6RPSMLNJ.js +0 -2
- package/dist/exports/client/componentInline-6RPSMLNJ.js.map +0 -7
- package/dist/features/blocks/client/component/FormSavePlugin.d.ts +0 -11
- package/dist/features/blocks/client/component/FormSavePlugin.d.ts.map +0 -1
- package/dist/features/blocks/client/component/FormSavePlugin.js +0 -53
- package/dist/features/blocks/client/component/FormSavePlugin.js.map +0 -1
|
@@ -1,18 +1,43 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ClientField, FormState } from 'payload';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import type { LexicalRichTextFieldProps } from '../../../../types.js';
|
|
4
|
-
import type { BlockFields } from '../../server/nodes/BlocksNode.js';
|
|
5
3
|
type Props = {
|
|
6
4
|
baseClass: string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
BlockDrawer: React.FC;
|
|
6
|
+
Collapsible: React.FC<{
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
editButton?: boolean;
|
|
9
|
+
errorCount?: number;
|
|
10
|
+
fieldHasErrors?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Override the default label with a custom label
|
|
13
|
+
*/
|
|
14
|
+
Label?: React.ReactNode;
|
|
15
|
+
removeButton?: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
CustomBlock: React.ReactNode;
|
|
18
|
+
EditButton: React.FC;
|
|
19
|
+
errorCount: number;
|
|
10
20
|
formSchema: ClientField[];
|
|
11
|
-
|
|
21
|
+
initialState: false | FormState | undefined;
|
|
12
22
|
nodeKey: string;
|
|
13
|
-
|
|
14
|
-
schemaPath: string;
|
|
23
|
+
RemoveButton: React.FC;
|
|
15
24
|
};
|
|
25
|
+
type BlockComponentContextType = {
|
|
26
|
+
BlockCollapsible?: React.FC<{
|
|
27
|
+
children?: React.ReactNode;
|
|
28
|
+
editButton?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Override the default label with a custom label
|
|
31
|
+
*/
|
|
32
|
+
Label?: React.ReactNode;
|
|
33
|
+
removeButton?: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
EditButton?: React.FC;
|
|
36
|
+
initialState: false | FormState | undefined;
|
|
37
|
+
nodeKey?: string;
|
|
38
|
+
RemoveButton?: React.FC;
|
|
39
|
+
};
|
|
40
|
+
export declare const useBlockComponentContext: () => BlockComponentContextType;
|
|
16
41
|
/**
|
|
17
42
|
* The actual content of the Block. This should be INSIDE a Form component,
|
|
18
43
|
* scoped to the block. All format operations in here are thus scoped to the block's form, and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockContent.d.ts","sourceRoot":"","sources":["../../../../../src/features/blocks/client/component/BlockContent.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"BlockContent.d.ts","sourceRoot":"","sources":["../../../../../src/features/blocks/client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EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,KAAK,CAAC,EAAE,CAAA;CACxB,CAAA;AAMD,eAAO,MAAM,wBAAwB,iCAAgD,CAAA;AAErF;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAmExC,CAAA"}
|
|
@@ -1,183 +1,88 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import { c as _c } from "react/compiler-runtime";
|
|
3
4
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// Recursively remove all undefined values from even being present in formData, as they will
|
|
13
|
-
// cause isDeepEqual to return false if, for example, formData has a key that fields.data
|
|
14
|
-
// does not have, even if it's undefined.
|
|
15
|
-
// Currently, this happens if a block has another sub-blocks field. Inside formData, that sub-blocks field has an undefined blockName property.
|
|
16
|
-
// Inside of fields.data however, that sub-blocks blockName property does not exist at all.
|
|
17
|
-
function removeUndefinedAndNullAndEmptyArraysRecursively(obj) {
|
|
18
|
-
for (const key in obj) {
|
|
19
|
-
const value = obj[key];
|
|
20
|
-
if (Array.isArray(value) && !value?.length) {
|
|
21
|
-
delete obj[key];
|
|
22
|
-
} else if (value && typeof value === 'object') {
|
|
23
|
-
removeUndefinedAndNullAndEmptyArraysRecursively(value);
|
|
24
|
-
} else if (value === undefined || value === null) {
|
|
25
|
-
delete obj[key];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
5
|
+
import { RenderFields, useFormSubmitted } from '@payloadcms/ui';
|
|
6
|
+
import React, { createContext, useMemo } from 'react';
|
|
7
|
+
const BlockComponentContext = /*#__PURE__*/createContext({
|
|
8
|
+
initialState: false
|
|
9
|
+
});
|
|
10
|
+
export const useBlockComponentContext = () => {
|
|
11
|
+
return React.useContext(BlockComponentContext);
|
|
12
|
+
};
|
|
29
13
|
/**
|
|
30
14
|
* The actual content of the Block. This should be INSIDE a Form component,
|
|
31
15
|
* scoped to the block. All format operations in here are thus scoped to the block's form, and
|
|
32
16
|
* not the whole document.
|
|
33
17
|
*/
|
|
34
18
|
export const BlockContent = props => {
|
|
19
|
+
const $ = _c(13);
|
|
35
20
|
const {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
21
|
+
BlockDrawer,
|
|
22
|
+
Collapsible,
|
|
23
|
+
CustomBlock,
|
|
24
|
+
EditButton,
|
|
25
|
+
errorCount,
|
|
39
26
|
formSchema,
|
|
40
|
-
|
|
41
|
-
nodeKey
|
|
42
|
-
|
|
43
|
-
let {
|
|
44
|
-
formData
|
|
27
|
+
initialState,
|
|
28
|
+
nodeKey,
|
|
29
|
+
RemoveButton
|
|
45
30
|
} = props;
|
|
46
|
-
const {
|
|
47
|
-
i18n
|
|
48
|
-
} = useTranslation();
|
|
49
|
-
const [editor] = useLexicalComposerContext();
|
|
50
|
-
// Used for saving collapsed to preferences (and gettin' it from there again)
|
|
51
|
-
// Remember, these preferences are scoped to the whole document, not just this form. This
|
|
52
|
-
// is important to consider for the data path used in setDocFieldPreferences
|
|
53
|
-
const {
|
|
54
|
-
getDocPreferences,
|
|
55
|
-
setDocFieldPreferences
|
|
56
|
-
} = useDocumentInfo();
|
|
57
|
-
const [isCollapsed, setIsCollapsed] = React.useState();
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
void getDocPreferences().then(currentDocPreferences => {
|
|
60
|
-
const currentFieldPreferences = currentDocPreferences?.fields[field.name];
|
|
61
|
-
const collapsedArray = currentFieldPreferences?.collapsed;
|
|
62
|
-
setIsCollapsed(collapsedArray ? collapsedArray.includes(formData.id) : false);
|
|
63
|
-
});
|
|
64
|
-
}, [field.name, formData.id, getDocPreferences]);
|
|
65
31
|
const hasSubmitted = useFormSubmitted();
|
|
66
|
-
const [errorCount, setErrorCount] = React.useState(0);
|
|
67
32
|
const fieldHasErrors = hasSubmitted && errorCount > 0;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// which would trigger the "Leave without saving" dialog unnecessarily
|
|
79
|
-
if (!dequal(formData, newFormData)) {
|
|
80
|
-
// Running this in the next tick in the meantime fixes this issue: https://github.com/payloadcms/payload/issues/4108
|
|
81
|
-
// I don't know why. When this is called immediately, it might focus out of a nested lexical editor field if an update is made there.
|
|
82
|
-
// My hypothesis is that the nested editor might not have fully finished its update cycle yet. By updating in the next tick, we
|
|
83
|
-
// ensure that the nested editor has finished its update cycle before we update the block node.
|
|
84
|
-
setTimeout(() => {
|
|
85
|
-
editor.update(() => {
|
|
86
|
-
const node = $getNodeByKey(nodeKey);
|
|
87
|
-
if (node && $isBlockNode(node)) {
|
|
88
|
-
formData = newFormData;
|
|
89
|
-
node.setFields(newFormData);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}, 0);
|
|
93
|
-
}
|
|
94
|
-
// update error count
|
|
95
|
-
if (hasSubmitted) {
|
|
96
|
-
let rowErrorCount = 0;
|
|
97
|
-
for (const formField of Object.values(fullFieldsWithValues)) {
|
|
98
|
-
if (formField?.valid === false) {
|
|
99
|
-
rowErrorCount++;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
setErrorCount(rowErrorCount);
|
|
103
|
-
}
|
|
104
|
-
}, [editor, nodeKey, hasSubmitted, formData]);
|
|
105
|
-
const onCollapsedChange = useCallback(changedCollapsed => {
|
|
106
|
-
void getDocPreferences().then(currentDocPreferences_0 => {
|
|
107
|
-
const currentFieldPreferences_0 = currentDocPreferences_0?.fields[field.name];
|
|
108
|
-
const collapsedArray_0 = currentFieldPreferences_0?.collapsed;
|
|
109
|
-
const newCollapsed = collapsedArray_0 && collapsedArray_0?.length ? collapsedArray_0 : [];
|
|
110
|
-
if (changedCollapsed) {
|
|
111
|
-
if (!newCollapsed.includes(formData.id)) {
|
|
112
|
-
newCollapsed.push(formData.id);
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
if (newCollapsed.includes(formData.id)) {
|
|
116
|
-
newCollapsed.splice(newCollapsed.indexOf(formData.id), 1);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
setDocFieldPreferences(field.name, {
|
|
120
|
-
collapsed: newCollapsed,
|
|
121
|
-
hello: 'hi'
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
}, [getDocPreferences, field.name, setDocFieldPreferences, formData.id]);
|
|
125
|
-
const removeBlock = useCallback(() => {
|
|
126
|
-
editor.update(() => {
|
|
127
|
-
$getNodeByKey(nodeKey)?.remove();
|
|
33
|
+
let t0;
|
|
34
|
+
let t1;
|
|
35
|
+
if ($[0] !== Collapsible || $[1] !== errorCount || $[2] !== fieldHasErrors) {
|
|
36
|
+
t1 = props_0 => _jsx(Collapsible, {
|
|
37
|
+
editButton: props_0.editButton,
|
|
38
|
+
errorCount,
|
|
39
|
+
fieldHasErrors,
|
|
40
|
+
Label: props_0.Label,
|
|
41
|
+
removeButton: props_0.removeButton,
|
|
42
|
+
children: props_0.children
|
|
128
43
|
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
44
|
+
$[0] = Collapsible;
|
|
45
|
+
$[1] = errorCount;
|
|
46
|
+
$[2] = fieldHasErrors;
|
|
47
|
+
$[3] = t1;
|
|
48
|
+
} else {
|
|
49
|
+
t1 = $[3];
|
|
132
50
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}), /*#__PURE__*/_jsx(SectionTitle, {
|
|
145
|
-
path: "blockName",
|
|
146
|
-
readOnly: field?.admin?.readOnly || false
|
|
147
|
-
}), fieldHasErrors && /*#__PURE__*/_jsx(ErrorPill, {
|
|
148
|
-
count: errorCount,
|
|
149
|
-
i18n: i18n,
|
|
150
|
-
withMessage: true
|
|
151
|
-
})]
|
|
152
|
-
}), editor.isEditable() && /*#__PURE__*/_jsx(Button, {
|
|
153
|
-
buttonStyle: "icon-label",
|
|
154
|
-
className: `${baseClass}__removeButton`,
|
|
155
|
-
disabled: field?.admin?.readOnly,
|
|
156
|
-
icon: "x",
|
|
157
|
-
onClick: e => {
|
|
158
|
-
e.preventDefault();
|
|
159
|
-
removeBlock();
|
|
160
|
-
},
|
|
161
|
-
round: true,
|
|
162
|
-
tooltip: "Remove Block"
|
|
163
|
-
})]
|
|
164
|
-
}),
|
|
165
|
-
isCollapsed: isCollapsed,
|
|
166
|
-
onToggle: incomingCollapsedState => {
|
|
167
|
-
onCollapsedChange(incomingCollapsedState);
|
|
168
|
-
setIsCollapsed(incomingCollapsedState);
|
|
51
|
+
t0 = t1;
|
|
52
|
+
const CollapsibleWithErrorProps = t0;
|
|
53
|
+
let t2;
|
|
54
|
+
if ($[4] !== CustomBlock || $[5] !== CollapsibleWithErrorProps || $[6] !== EditButton || $[7] !== initialState || $[8] !== nodeKey || $[9] !== RemoveButton || $[10] !== BlockDrawer || $[11] !== formSchema) {
|
|
55
|
+
t2 = CustomBlock ? _jsxs(BlockComponentContext.Provider, {
|
|
56
|
+
value: {
|
|
57
|
+
BlockCollapsible: CollapsibleWithErrorProps,
|
|
58
|
+
EditButton,
|
|
59
|
+
initialState,
|
|
60
|
+
nodeKey,
|
|
61
|
+
RemoveButton
|
|
169
62
|
},
|
|
170
|
-
children:
|
|
63
|
+
children: [CustomBlock, _jsx(BlockDrawer, {})]
|
|
64
|
+
}) : _jsx(CollapsibleWithErrorProps, {
|
|
65
|
+
children: _jsx(RenderFields, {
|
|
171
66
|
fields: formSchema,
|
|
172
67
|
forceRender: true,
|
|
173
68
|
parentIndexPath: "",
|
|
174
|
-
parentPath:
|
|
69
|
+
parentPath: "",
|
|
175
70
|
parentSchemaPath: "",
|
|
176
71
|
permissions: true
|
|
177
72
|
})
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
73
|
+
});
|
|
74
|
+
$[4] = CustomBlock;
|
|
75
|
+
$[5] = CollapsibleWithErrorProps;
|
|
76
|
+
$[6] = EditButton;
|
|
77
|
+
$[7] = initialState;
|
|
78
|
+
$[8] = nodeKey;
|
|
79
|
+
$[9] = RemoveButton;
|
|
80
|
+
$[10] = BlockDrawer;
|
|
81
|
+
$[11] = formSchema;
|
|
82
|
+
$[12] = t2;
|
|
83
|
+
} else {
|
|
84
|
+
t2 = $[12];
|
|
85
|
+
}
|
|
86
|
+
return t2;
|
|
182
87
|
};
|
|
183
88
|
//# sourceMappingURL=BlockContent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockContent.js","names":["useLexicalComposerContext","getTranslation","Button","Collapsible","ErrorPill","Pill","RenderFields","SectionTitle","useDocumentInfo","useFormSubmitted","useTranslation","dequal","$getNodeByKey","React","useCallback","useEffect","$isBlockNode","FormSavePlugin","removeUndefinedAndNullAndEmptyArraysRecursively","obj","key","value","Array","isArray","length","undefined","BlockContent","props","baseClass","clientBlock","field","formSchema","Label","nodeKey","formData","i18n","editor","getDocPreferences","setDocFieldPreferences","isCollapsed","setIsCollapsed","useState","then","currentDocPreferences","currentFieldPreferences","fields","name","collapsedArray","collapsed","includes","id","hasSubmitted","errorCount","setErrorCount","fieldHasErrors","classNames","filter","Boolean","join","onFormChange","fullFieldsWithValues","newFormData","blockType","setTimeout","update","node","setFields","rowErrorCount","formField","Object","values","valid","onCollapsedChange","changedCollapsed","newCollapsed","push","splice","indexOf","hello","removeBlock","remove","_jsxs","Fragment","_jsx","className","collapsibleStyle","header","pillStyle","labels","singular","slug","path","readOnly","admin","count","withMessage","isEditable","buttonStyle","disabled","icon","onClick","e","preventDefault","round","tooltip","onToggle","incomingCollapsedState","forceRender","parentIndexPath","parentPath","parentSchemaPath","permissions","onChange"],"sources":["../../../../../src/features/blocks/client/component/BlockContent.tsx"],"sourcesContent":["'use client'\nimport type { ClientBlock, ClientField, CollapsedPreferences, FormState } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n Button,\n Collapsible,\n ErrorPill,\n Pill,\n RenderFields,\n SectionTitle,\n useDocumentInfo,\n useFormSubmitted,\n useTranslation,\n} from '@payloadcms/ui'\nimport { dequal } from 'dequal/lite'\nimport { $getNodeByKey } from 'lexical'\nimport React, { useCallback, useEffect } from 'react'\n\nimport type { LexicalRichTextFieldProps } from '../../../../types.js'\nimport type { BlockFields } from '../../server/nodes/BlocksNode.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { $isBlockNode } from '../nodes/BlocksNode.js'\nimport { FormSavePlugin } from './FormSavePlugin.js'\n\ntype Props = {\n baseClass: string\n clientBlock: ClientBlock\n field: LexicalRichTextFieldProps['field']\n formData: BlockFields\n formSchema: ClientField[]\n Label?: React.ReactNode\n nodeKey: string\n path: string\n schemaPath: string\n}\n\n// Recursively remove all undefined values from even being present in formData, as they will\n// cause isDeepEqual to return false if, for example, formData has a key that fields.data\n// does not have, even if it's undefined.\n// Currently, this happens if a block has another sub-blocks field. Inside formData, that sub-blocks field has an undefined blockName property.\n// Inside of fields.data however, that sub-blocks blockName property does not exist at all.\nfunction removeUndefinedAndNullAndEmptyArraysRecursively(obj: object) {\n for (const key in obj) {\n const value = obj[key]\n if (Array.isArray(value) && !value?.length) {\n delete obj[key]\n } else if (value && typeof value === 'object') {\n removeUndefinedAndNullAndEmptyArraysRecursively(value)\n } else if (value === undefined || value === null) {\n delete obj[key]\n }\n }\n}\n\n/**\n * The actual content of the Block. This should be INSIDE a Form component,\n * scoped to the block. All format operations in here are thus scoped to the block's form, and\n * not the whole document.\n */\nexport const BlockContent: React.FC<Props> = (props) => {\n const { baseClass, clientBlock, field, formSchema, Label, nodeKey } = props\n let { formData } = props\n\n const { i18n } = useTranslation()\n const [editor] = useLexicalComposerContext()\n // Used for saving collapsed to preferences (and gettin' it from there again)\n // Remember, these preferences are scoped to the whole document, not just this form. This\n // is important to consider for the data path used in setDocFieldPreferences\n const { getDocPreferences, setDocFieldPreferences } = useDocumentInfo()\n\n const [isCollapsed, setIsCollapsed] = React.useState<boolean>()\n\n useEffect(() => {\n void getDocPreferences().then((currentDocPreferences) => {\n const currentFieldPreferences = currentDocPreferences?.fields[field.name]\n const collapsedArray = currentFieldPreferences?.collapsed\n setIsCollapsed(collapsedArray ? collapsedArray.includes(formData.id) : false)\n })\n }, [field.name, formData.id, getDocPreferences])\n\n const hasSubmitted = useFormSubmitted()\n\n const [errorCount, setErrorCount] = React.useState(0)\n\n const fieldHasErrors = hasSubmitted && errorCount > 0\n\n const classNames = [\n `${baseClass}__row`,\n fieldHasErrors ? `${baseClass}__row--has-errors` : `${baseClass}__row--no-errors`,\n ]\n .filter(Boolean)\n .join(' ')\n\n const onFormChange = useCallback(\n ({\n fullFieldsWithValues,\n newFormData,\n }: {\n fullFieldsWithValues: FormState\n newFormData: BlockFields\n }) => {\n newFormData.id = formData.id\n newFormData.blockType = formData.blockType\n\n removeUndefinedAndNullAndEmptyArraysRecursively(newFormData)\n removeUndefinedAndNullAndEmptyArraysRecursively(formData)\n\n // Only update if the data has actually changed. Otherwise, we may be triggering an unnecessary value change,\n // which would trigger the \"Leave without saving\" dialog unnecessarily\n if (!dequal(formData, newFormData)) {\n // Running this in the next tick in the meantime fixes this issue: https://github.com/payloadcms/payload/issues/4108\n // I don't know why. When this is called immediately, it might focus out of a nested lexical editor field if an update is made there.\n // My hypothesis is that the nested editor might not have fully finished its update cycle yet. By updating in the next tick, we\n // ensure that the nested editor has finished its update cycle before we update the block node.\n setTimeout(() => {\n editor.update(() => {\n const node = $getNodeByKey(nodeKey)\n if (node && $isBlockNode(node)) {\n formData = newFormData\n node.setFields(newFormData)\n }\n })\n }, 0)\n }\n\n // update error count\n if (hasSubmitted) {\n let rowErrorCount = 0\n for (const formField of Object.values(fullFieldsWithValues)) {\n if (formField?.valid === false) {\n rowErrorCount++\n }\n }\n setErrorCount(rowErrorCount)\n }\n },\n [editor, nodeKey, hasSubmitted, formData],\n )\n\n const onCollapsedChange = useCallback(\n (changedCollapsed: boolean) => {\n void getDocPreferences().then((currentDocPreferences) => {\n const currentFieldPreferences = currentDocPreferences?.fields[field.name]\n\n const collapsedArray = currentFieldPreferences?.collapsed\n\n const newCollapsed: CollapsedPreferences =\n collapsedArray && collapsedArray?.length ? collapsedArray : []\n\n if (changedCollapsed) {\n if (!newCollapsed.includes(formData.id)) {\n newCollapsed.push(formData.id)\n }\n } else {\n if (newCollapsed.includes(formData.id)) {\n newCollapsed.splice(newCollapsed.indexOf(formData.id), 1)\n }\n }\n\n setDocFieldPreferences(field.name, {\n collapsed: newCollapsed,\n hello: 'hi',\n })\n })\n },\n [getDocPreferences, field.name, setDocFieldPreferences, formData.id],\n )\n\n const removeBlock = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey)?.remove()\n })\n }, [editor, nodeKey])\n\n if (typeof isCollapsed !== 'boolean') {\n return null\n }\n\n return (\n <React.Fragment>\n <Collapsible\n className={classNames}\n collapsibleStyle={fieldHasErrors ? 'error' : 'default'}\n header={\n Label || (\n <div className={`${baseClass}__block-header`}>\n <div>\n <Pill\n className={`${baseClass}__block-pill ${baseClass}__block-pill-${formData?.blockType}`}\n pillStyle=\"white\"\n >\n {typeof clientBlock?.labels?.singular === 'string'\n ? getTranslation(clientBlock?.labels.singular, i18n)\n : clientBlock.slug}\n </Pill>\n <SectionTitle path=\"blockName\" readOnly={field?.admin?.readOnly || false} />\n {fieldHasErrors && <ErrorPill count={errorCount} i18n={i18n} withMessage />}\n </div>\n {editor.isEditable() && (\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={field?.admin?.readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeBlock()\n }}\n round\n tooltip=\"Remove Block\"\n />\n )}\n </div>\n )\n }\n isCollapsed={isCollapsed}\n key={0}\n onToggle={(incomingCollapsedState) => {\n onCollapsedChange(incomingCollapsedState)\n setIsCollapsed(incomingCollapsedState)\n }}\n >\n <RenderFields\n fields={formSchema}\n forceRender={true}\n parentIndexPath=\"\"\n parentPath={''}\n parentSchemaPath=\"\"\n permissions={true}\n />\n </Collapsible>\n\n <FormSavePlugin onChange={onFormChange} />\n </React.Fragment>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,yBAAyB,QAAQ;AAC1C,SAASC,cAAc,QAAQ;AAC/B,SACEC,MAAM,EACNC,WAAW,EACXC,SAAS,EACTC,IAAI,EACJC,YAAY,EACZC,YAAY,EACZC,eAAe,EACfC,gBAAgB,EAChBC,cAAc,QACT;AACP,SAASC,MAAM,QAAQ;AACvB,SAASC,aAAa,QAAQ;AAC9B,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,QAAQ;AAM9C,SAASC,YAAY,QAAQ;AAC7B,SAASC,cAAc,QAAQ;AAc/B;AACA;AACA;AACA;AACA;AACA,SAASC,gDAAgDC,GAAW;EAClE,KAAK,MAAMC,GAAA,IAAOD,GAAA,EAAK;IACrB,MAAME,KAAA,GAAQF,GAAG,CAACC,GAAA,CAAI;IACtB,IAAIE,KAAA,CAAMC,OAAO,CAACF,KAAA,KAAU,CAACA,KAAA,EAAOG,MAAA,EAAQ;MAC1C,OAAOL,GAAG,CAACC,GAAA,CAAI;IACjB,OAAO,IAAIC,KAAA,IAAS,OAAOA,KAAA,KAAU,UAAU;MAC7CH,+CAAA,CAAgDG,KAAA;IAClD,OAAO,IAAIA,KAAA,KAAUI,SAAA,IAAaJ,KAAA,KAAU,MAAM;MAChD,OAAOF,GAAG,CAACC,GAAA,CAAI;IACjB;EACF;AACF;AAEA;;;;;AAKA,OAAO,MAAMM,YAAA,GAAiCC,KAAA;EAC5C,MAAM;IAAEC,SAAS;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AAaoF,IAAA,EAAK;YAAYC,QAAA,EAAU9D,KAAA,EAAO+D,KAAA,EAAOD,QAAA,IAAY;cAClEtC,cAAA,iBAAkB6B,IAAA,CAAC/E,SAAA;YAAU0F,KAAA,EAAO1C,UAAA;YAAYjB,IAAA,EAAMA,IAAA;YAAM4D,WAAW;;YAEzE3D,MAAA,CAAO4D,UAAU,mBAChBb,IAAA,CAACjF,MAAA;UACC+F,WAAA,EAAY;UACZb,SAAA,EAAW,GAAGxD,SAAA,gBAAyB;UACvCsE,QAAA,EAAUpE,KAAA,EAAO+D,KAAA,EAAOD,QAAA;UACxBO,IAAA,EAAK;UACLC,OAAA,EAAUC,CAAA;YACRA,CAAA,CAAEC,cAAc;YAChBvB,WAAA;UACF;UACAwB,KAAK;UACLC,OAAA,EAAQ;;;MAMlBjE,WAAA,EAAaA,WAAA;MAEbkE,QAAA,EAAWC,sBAAA;QACTlC,iBAAA,CAAkBkC,sBAAA;QAClBlE,cAAA,CAAekE,sBAAA;MACjB;gBAEA,aAAAvB,IAAA,CAAC7E,YAAA;QACCuC,MAAA,EAAQd,UAAA;QACR4E,WAAA,EAAa;QACbC,eAAA,EAAgB;QAChBC,UAAA,EAAY;QACZC,gBAAA,EAAiB;QACjBC,WAAA,EAAa;;OAZV,I,aAgBP5B,IAAA,CAAClE,cAAA;MAAe+F,QAAA,EAAUrD;;;AAGhC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"BlockContent.js","names":["c","_c","RenderFields","useFormSubmitted","React","createContext","useMemo","BlockComponentContext","initialState","useBlockComponentContext","useContext","BlockContent","props","$","BlockDrawer","Collapsible","CustomBlock","EditButton","errorCount","formSchema","nodeKey","RemoveButton","hasSubmitted","fieldHasErrors","t0","t1","props_0","_jsx","editButton","Label","removeButton","children","CollapsibleWithErrorProps","t2","_jsxs","Provider","value","BlockCollapsible","fields","forceRender","parentIndexPath","parentPath","parentSchemaPath","permissions"],"sources":["../../../../../src/features/blocks/client/component/BlockContent.tsx"],"sourcesContent":["'use client'\nimport type { ClientField, FormState } from 'payload'\n\nimport { RenderFields, useFormSubmitted } from '@payloadcms/ui'\nimport React, { createContext, useMemo } from 'react'\n\ntype Props = {\n baseClass: string\n BlockDrawer: React.FC\n Collapsible: React.FC<{\n children?: React.ReactNode\n editButton?: boolean\n errorCount?: number\n fieldHasErrors?: boolean\n /**\n * Override the default label with a custom label\n */\n Label?: React.ReactNode\n removeButton?: boolean\n }>\n CustomBlock: React.ReactNode\n EditButton: React.FC\n errorCount: number\n formSchema: ClientField[]\n initialState: false | FormState | undefined\n\n nodeKey: string\n RemoveButton: React.FC\n}\n\ntype BlockComponentContextType = {\n BlockCollapsible?: React.FC<{\n children?: React.ReactNode\n editButton?: boolean\n /**\n * Override the default label with a custom label\n */\n Label?: React.ReactNode\n removeButton?: boolean\n }>\n EditButton?: React.FC\n initialState: false | FormState | undefined\n\n nodeKey?: string\n RemoveButton?: React.FC\n}\n\nconst BlockComponentContext = createContext<BlockComponentContextType>({\n initialState: false,\n})\n\nexport const useBlockComponentContext = () => React.useContext(BlockComponentContext)\n\n/**\n * The actual content of the Block. This should be INSIDE a Form component,\n * scoped to the block. All format operations in here are thus scoped to the block's form, and\n * not the whole document.\n */\nexport const BlockContent: React.FC<Props> = (props) => {\n const {\n BlockDrawer,\n Collapsible,\n CustomBlock,\n EditButton,\n errorCount,\n formSchema,\n initialState,\n nodeKey,\n RemoveButton,\n } = props\n\n const hasSubmitted = useFormSubmitted()\n\n const fieldHasErrors = hasSubmitted && errorCount > 0\n\n const CollapsibleWithErrorProps = useMemo(\n () =>\n (props: {\n children?: React.ReactNode\n editButton?: boolean\n\n /**\n * Override the default label with a custom label\n */\n Label?: React.ReactNode\n removeButton?: boolean\n }) => (\n <Collapsible\n editButton={props.editButton}\n errorCount={errorCount}\n fieldHasErrors={fieldHasErrors}\n Label={props.Label}\n removeButton={props.removeButton}\n >\n {props.children}\n </Collapsible>\n ),\n [Collapsible, fieldHasErrors, errorCount],\n )\n\n return CustomBlock ? (\n <BlockComponentContext.Provider\n value={{\n BlockCollapsible: CollapsibleWithErrorProps,\n EditButton,\n initialState,\n nodeKey,\n RemoveButton,\n }}\n >\n {CustomBlock}\n <BlockDrawer />\n </BlockComponentContext.Provider>\n ) : (\n <CollapsibleWithErrorProps>\n <RenderFields\n fields={formSchema}\n forceRender={true}\n parentIndexPath=\"\"\n parentPath={''}\n parentSchemaPath=\"\"\n permissions={true}\n />\n </CollapsibleWithErrorProps>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,YAAY,EAAEC,gBAAgB,QAAQ;AAC/C,OAAOC,KAAA,IAASC,aAAa,EAAEC,OAAO,QAAQ;AA2C9C,MAAMC,qBAAA,gBAAwBF,aAAA,CAAyC;EACrEG,YAAA,EAAc;AAChB;AAEA,OAAO,MAAMC,wBAAA,GAA2BA,CAAA;EAAA,OAAML,KAAA,CAAAM,UAAA,CAAAH,qBAAiB;AAAA;AAE/D;;;;;AAKA,OAAO,MAAMI,YAAA,GAAgCC,KAAA;EAAA,MAAAC,CAAA,GAAAZ,EAAA;EAC3C;IAAAa,WAAA;IAAAC,WAAA;IAAAC,WAAA;IAAAC,UAAA;IAAAC,UAAA;IAAAC,UAAA;IAAAX,YAAA;IAAAY,OAAA;IAAAC;EAAA,IAUIT,KAAA;EAEJ,MAAAU,YAAA,GAAqBnB,gBAAA;EAErB,MAAAoB,cAAA,GAAuBD,YAAA,IAAgBJ,UAAA,IAAa;EAAA,IAAAM,EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAZ,CAAA,QAAAE,WAAA,IAAAF,CAAA,QAAAK,UAAA,IAAAL,CAAA,QAAAU,cAAA;IAIhDE,EAAA,GAAAC,OAAA,IAUEC,IAAA,CAACZ,WAAA;MAAAa,UAAA,EACahB,OAAA,CAAAgB,UAAA;MAAAV,UAAA;MAAAK,cAAA;MAAAM,KAAA,EAGLjB,OAAA,CAAAiB,KAAA;MAAAC,YAAA,EACOlB,OAAA,CAAAkB,YAAA;MAAAC,QAAA,EAEbnB,OAAA,CAAAmB;IAAA,C;;;;;;;;OAjBLN,E;EAFJ,MAAAO,yBAAA,GAAkCR,EAsBS;EAAA,IAAAS,EAAA;EAAA,IAAApB,CAAA,QAAAG,WAAA,IAAAH,CAAA,QAAAmB,yBAAA,IAAAnB,CAAA,QAAAI,UAAA,IAAAJ,CAAA,QAAAL,YAAA,IAAAK,CAAA,QAAAO,OAAA,IAAAP,CAAA,QAAAQ,YAAA,IAAAR,CAAA,SAAAC,WAAA,IAAAD,CAAA,SAAAM,UAAA;IAGpCc,EAAA,GAAAjB,WAAA,GACLkB,KAAA,CAAA3B,qBAAA,CAAA4B,QAAA;MAAAC,KAAA;QAAAC,gBAAA,EAEsBL,yBAAA;QAAAf,UAAA;QAAAT,YAAA;QAAAY,OAAA;QAAAC;MAAA;MAAAU,QAAA,GAOnBf,WAAA,EACDW,IAAA,CAACb,WAAA;IAAA,C,IAGHa,IAAA,CAACK,yBAAA;MAAAD,QAAA,EACCJ,IAAA,CAAAzB,YAAA;QAAAoC,MAAA,EACUnB,UAAA;QAAAoB,WAAA;QAAAC,eAAA,EAEQ;QAAAC,UAAA,EACJ;QAAAC,gBAAA,EACK;QAAAC,WAAA;MAAA,C;;;;;;;;;;;;;;SApBhBV,E;CAyBT","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare const BlockCollapsible: React.FC<{
|
|
3
|
+
children?: React.ReactNode;
|
|
4
|
+
editButton?: boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Override the default label with a custom label
|
|
7
|
+
*/
|
|
8
|
+
Label?: React.ReactNode;
|
|
9
|
+
removeButton?: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=BlockCollapsible.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockCollapsible.d.ts","sourceRoot":"","sources":["../../../../../../src/features/blocks/client/component/components/BlockCollapsible.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC;IACtC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAA;IAEpB;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACvB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAQA,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { c as _c } from "react/compiler-runtime";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { useBlockComponentContext } from '../BlockContent.js';
|
|
7
|
+
export const BlockCollapsible = t0 => {
|
|
8
|
+
const $ = _c(6);
|
|
9
|
+
const {
|
|
10
|
+
children,
|
|
11
|
+
editButton,
|
|
12
|
+
Label,
|
|
13
|
+
removeButton
|
|
14
|
+
} = t0;
|
|
15
|
+
const {
|
|
16
|
+
BlockCollapsible
|
|
17
|
+
} = useBlockComponentContext();
|
|
18
|
+
let t1;
|
|
19
|
+
if ($[0] !== BlockCollapsible || $[1] !== editButton || $[2] !== Label || $[3] !== removeButton || $[4] !== children) {
|
|
20
|
+
t1 = BlockCollapsible ? _jsx(BlockCollapsible, {
|
|
21
|
+
editButton,
|
|
22
|
+
Label,
|
|
23
|
+
removeButton,
|
|
24
|
+
children
|
|
25
|
+
}) : null;
|
|
26
|
+
$[0] = BlockCollapsible;
|
|
27
|
+
$[1] = editButton;
|
|
28
|
+
$[2] = Label;
|
|
29
|
+
$[3] = removeButton;
|
|
30
|
+
$[4] = children;
|
|
31
|
+
$[5] = t1;
|
|
32
|
+
} else {
|
|
33
|
+
t1 = $[5];
|
|
34
|
+
}
|
|
35
|
+
return t1;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=BlockCollapsible.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockCollapsible.js","names":["c","_c","React","useBlockComponentContext","BlockCollapsible","t0","$","children","editButton","Label","removeButton","t1","_jsx"],"sources":["../../../../../../src/features/blocks/client/component/components/BlockCollapsible.tsx"],"sourcesContent":["'use client'\nimport React from 'react'\n\nimport { useBlockComponentContext } from '../BlockContent.js'\n\nexport const BlockCollapsible: React.FC<{\n children?: React.ReactNode\n editButton?: boolean\n\n /**\n * Override the default label with a custom label\n */\n Label?: React.ReactNode\n removeButton?: boolean\n}> = ({ children, editButton, Label, removeButton }) => {\n const { BlockCollapsible } = useBlockComponentContext()\n\n return BlockCollapsible ? (\n <BlockCollapsible editButton={editButton} Label={Label} removeButton={removeButton}>\n {children}\n </BlockCollapsible>\n ) : null\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,OAAOC,KAAA,MAAW;AAElB,SAASC,wBAAwB,QAAQ;AAEzC,OAAO,MAAMC,gBAAA,GASRC,EAAA;EAAA,MAAAC,CAAA,GAAAL,EAAA;EAAC;IAAAM,QAAA;IAAAC,UAAA;IAAAC,KAAA;IAAAC;EAAA,IAAAL,EAA6C;EACjD;IAAAD;EAAA,IAA6BD,wBAAA;EAAA,IAAAQ,EAAA;EAAA,IAAAL,CAAA,QAAAF,gBAAA,IAAAE,CAAA,QAAAE,UAAA,IAAAF,CAAA,QAAAG,KAAA,IAAAH,CAAA,QAAAI,YAAA,IAAAJ,CAAA,QAAAC,QAAA;IAEtBI,EAAA,GAAAP,gBAAA,GACLQ,IAAA,CAACR,gBAAA;MAAAI,UAAA;MAAAC,KAAA;MAAAC,YAAA;MAAAH;IAAA,C,QAGC;IAAAD,CAAA,MAAAF,gBAAA;IAAAE,CAAA,MAAAE,UAAA;IAAAF,CAAA,MAAAG,KAAA;IAAAH,CAAA,MAAAI,YAAA;IAAAJ,CAAA,MAAAC,QAAA;IAAAD,CAAA,MAAAK,EAAA;EAAA;IAAAA,EAAA,GAAAL,CAAA;EAAA;EAAA,OAJGK,EAIH;AAAA,CACN","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockEditButton.d.ts","sourceRoot":"","sources":["../../../../../../src/features/blocks/client/component/components/BlockEditButton.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,eAAO,MAAM,eAAe,gCAI3B,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { c as _c } from "react/compiler-runtime";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { useBlockComponentContext } from '../BlockContent.js';
|
|
7
|
+
export const BlockEditButton = () => {
|
|
8
|
+
const $ = _c(2);
|
|
9
|
+
const {
|
|
10
|
+
EditButton
|
|
11
|
+
} = useBlockComponentContext();
|
|
12
|
+
let t0;
|
|
13
|
+
if ($[0] !== EditButton) {
|
|
14
|
+
t0 = EditButton ? _jsx(EditButton, {}) : null;
|
|
15
|
+
$[0] = EditButton;
|
|
16
|
+
$[1] = t0;
|
|
17
|
+
} else {
|
|
18
|
+
t0 = $[1];
|
|
19
|
+
}
|
|
20
|
+
return t0;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=BlockEditButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockEditButton.js","names":["c","_c","React","useBlockComponentContext","BlockEditButton","$","EditButton","t0","_jsx"],"sources":["../../../../../../src/features/blocks/client/component/components/BlockEditButton.tsx"],"sourcesContent":["'use client'\nimport React from 'react'\n\nimport { useBlockComponentContext } from '../BlockContent.js'\n\nexport const BlockEditButton = () => {\n const { EditButton } = useBlockComponentContext()\n\n return EditButton ? <EditButton /> : null\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,OAAOC,KAAA,MAAW;AAElB,SAASC,wBAAwB,QAAQ;AAEzC,OAAO,MAAMC,eAAA,GAAkBA,CAAA;EAAA,MAAAC,CAAA,GAAAJ,EAAA;EAC7B;IAAAK;EAAA,IAAuBH,wBAAA;EAAA,IAAAI,EAAA;EAAA,IAAAF,CAAA,QAAAC,UAAA;IAEhBC,EAAA,GAAAD,UAAA,GAAaE,IAAA,CAACF,UAAA,YAAgB;IAAAD,CAAA,MAAAC,UAAA;IAAAD,CAAA,MAAAE,EAAA;EAAA;IAAAA,EAAA,GAAAF,CAAA;EAAA;EAAA,OAA9BE,EAA8B;AAAA,CACvC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockRemoveButton.d.ts","sourceRoot":"","sources":["../../../../../../src/features/blocks/client/component/components/BlockRemoveButton.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,eAAO,MAAM,iBAAiB,gCAI7B,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { c as _c } from "react/compiler-runtime";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { useBlockComponentContext } from '../BlockContent.js';
|
|
7
|
+
export const BlockRemoveButton = () => {
|
|
8
|
+
const $ = _c(2);
|
|
9
|
+
const {
|
|
10
|
+
RemoveButton
|
|
11
|
+
} = useBlockComponentContext();
|
|
12
|
+
let t0;
|
|
13
|
+
if ($[0] !== RemoveButton) {
|
|
14
|
+
t0 = RemoveButton ? _jsx(RemoveButton, {}) : null;
|
|
15
|
+
$[0] = RemoveButton;
|
|
16
|
+
$[1] = t0;
|
|
17
|
+
} else {
|
|
18
|
+
t0 = $[1];
|
|
19
|
+
}
|
|
20
|
+
return t0;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=BlockRemoveButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockRemoveButton.js","names":["c","_c","React","useBlockComponentContext","BlockRemoveButton","$","RemoveButton","t0","_jsx"],"sources":["../../../../../../src/features/blocks/client/component/components/BlockRemoveButton.tsx"],"sourcesContent":["'use client'\nimport React from 'react'\n\nimport { useBlockComponentContext } from '../BlockContent.js'\n\nexport const BlockRemoveButton = () => {\n const { RemoveButton } = useBlockComponentContext()\n\n return RemoveButton ? <RemoveButton /> : null\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,OAAOC,KAAA,MAAW;AAElB,SAASC,wBAAwB,QAAQ;AAEzC,OAAO,MAAMC,iBAAA,GAAoBA,CAAA;EAAA,MAAAC,CAAA,GAAAJ,EAAA;EAC/B;IAAAK;EAAA,IAAyBH,wBAAA;EAAA,IAAAI,EAAA;EAAA,IAAAF,CAAA,QAAAC,YAAA;IAElBC,EAAA,GAAAD,YAAA,GAAeE,IAAA,CAACF,YAAA,YAAkB;IAAAD,CAAA,MAAAC,YAAA;IAAAD,CAAA,MAAAE,EAAA;EAAA;IAAAA,EAAA,GAAAF,CAAA;EAAA;EAAA,OAAlCE,EAAkC;AAAA,CAC3C","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/blocks/client/component/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/blocks/client/component/index.tsx"],"names":[],"mappings":"AAsBA,OAAO,KAAkD,MAAM,OAAO,CAAA;AAStE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AAMnE,OAAO,cAAc,CAAA;AAGrB,KAAK,KAAK,GAAG;IACX,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACnC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAA;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA4c1C,CAAA"}
|