slice-machine-ui 1.26.1-beta.12 → 1.26.1-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/404.html +1 -1
- package/out/_next/static/chunks/127-ebfffb85bdb0bf53.js +1 -0
- package/out/_next/static/chunks/453-4e2d00a3515202f4.js +1 -0
- package/out/_next/static/chunks/46-bd45510ac2a839b5.js +10 -0
- package/out/_next/static/chunks/{91-1c3665ce38e58792.js → 91-e96855cdfbfbbade.js} +1 -1
- package/out/_next/static/chunks/96-24fed6adc069e313.js +1 -0
- package/out/_next/static/chunks/pages/{_app-01bcd29a595cec3a.js → _app-451e6ea8230ca7e5.js} +3 -3
- package/out/_next/static/chunks/pages/{changelog-ac1004bdd31d17f8.js → changelog-db23fdc674e68e53.js} +1 -1
- package/out/_next/static/chunks/pages/{changes-5c4bd80747884a8c.js → changes-92929e59b38adef8.js} +1 -1
- package/out/_next/static/chunks/pages/custom-types/{[customTypeId]-8bcc4d88f470d3f7.js → [customTypeId]-5b08515fec5e6668.js} +1 -1
- package/out/_next/static/chunks/pages/{labs-d6f2feb6720ee64c.js → labs-f9e359543631af2a.js} +1 -1
- package/out/_next/static/chunks/pages/page-types/{[pageTypeId]-8461ab4fcfaf0755.js → [pageTypeId]-41fc6d4f726fdfb9.js} +1 -1
- package/out/_next/static/chunks/pages/{settings-7ad1540dc0af794d.js → settings-a61e874536e40574.js} +1 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-a822e349e3e0b18f.js +1 -0
- package/out/_next/static/chunks/pages/{slices-801310de228fd05e.js → slices-98f88ac46b6ad58b.js} +1 -1
- package/out/_next/static/css/{df904982b9637c1a.css → 09a4e5669351d4e2.css} +1 -1
- package/out/_next/static/{svF8JPCb25QlsmymuzIiN → meJPGne56O3xxrr3mYozg}/_buildManifest.js +1 -1
- package/out/changelog.html +1 -1
- package/out/changes.html +1 -1
- package/out/custom-types/[customTypeId].html +1 -1
- package/out/custom-types.html +1 -1
- package/out/index.html +1 -1
- package/out/labs.html +1 -1
- package/out/page-types/[pageTypeId].html +1 -1
- package/out/settings.html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
- package/out/slices.html +1 -1
- package/package.json +6 -6
- package/src/components/Divider/Divider.module.css +23 -0
- package/src/components/Divider/Divider.module.css.d.ts +7 -0
- package/src/components/Divider/Divider.stories.tsx +3 -4
- package/src/components/Divider/Divider.tsx +5 -8
- package/src/domain/__tests__/customType.test.ts +0 -184
- package/src/domain/__tests__/group.test.ts +161 -0
- package/src/domain/customType.ts +0 -191
- package/src/domain/group.ts +89 -0
- package/src/domain/slice.ts +24 -11
- package/src/legacy/lib/builders/CustomTypeBuilder/TabZone/index.tsx +4 -7
- package/src/legacy/lib/builders/SliceBuilder/FieldZones/index.tsx +27 -35
- package/src/legacy/lib/builders/common/Zone/Card/index.jsx +3 -0
- package/src/legacy/lib/builders/common/Zone/index.jsx +4 -7
- package/src/legacy/lib/models/common/Slice.ts +17 -3
- package/src/legacy/lib/models/common/widgets/Group/ListItem/index.jsx +51 -60
- package/src/legacy/lib/models/common/widgets/groupBuilderArray.ts +18 -0
- package/src/legacy/lib/models/common/widgets/sliceBuilderArray.ts +16 -28
- package/src/legacy/lib/models/common/widgets/withGroup.ts +1 -18
- package/src/utils/getContentTypeForTracking.ts +21 -0
- package/out/_next/static/chunks/207-f71df53ed0b0ac4d.js +0 -1
- package/out/_next/static/chunks/453-1a14e86de385fe7c.js +0 -1
- package/out/_next/static/chunks/46-d22d7a121254e31d.js +0 -8
- package/out/_next/static/chunks/96-33e38032f1e55366.js +0 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-217d0b0469d4320e.js +0 -1
- package/src/components/Divider/Divider.css.ts +0 -31
- /package/out/_next/static/{svF8JPCb25QlsmymuzIiN → meJPGne56O3xxrr3mYozg}/_ssgManifest.js +0 -0
|
@@ -5,10 +5,7 @@ import {
|
|
|
5
5
|
DialogContent,
|
|
6
6
|
DialogHeader,
|
|
7
7
|
} from "@prismicio/editor-ui";
|
|
8
|
-
import {
|
|
9
|
-
FieldType,
|
|
10
|
-
NestableWidget,
|
|
11
|
-
} from "@prismicio/types-internal/lib/customtypes";
|
|
8
|
+
import { GroupFieldType } from "@prismicio/types-internal/lib/customtypes";
|
|
12
9
|
import { FC, useState } from "react";
|
|
13
10
|
import { DropResult } from "react-beautiful-dnd";
|
|
14
11
|
import { flushSync } from "react-dom";
|
|
@@ -26,12 +23,17 @@ import { useSliceState } from "@/features/slices/sliceBuilder/SliceBuilderProvid
|
|
|
26
23
|
import { useGroupsInSlicesExperiment } from "@/features/slices/sliceBuilder/useGroupsInSlicesExperiment";
|
|
27
24
|
import EditModal from "@/legacy/lib/builders/common/EditModal";
|
|
28
25
|
import Zone from "@/legacy/lib/builders/common/Zone";
|
|
29
|
-
import {
|
|
26
|
+
import { Groups } from "@/legacy/lib/models/common/Group";
|
|
27
|
+
import {
|
|
28
|
+
SlicePrimaryFieldSM,
|
|
29
|
+
WidgetsArea,
|
|
30
|
+
} from "@/legacy/lib/models/common/Slice";
|
|
30
31
|
import * as Widgets from "@/legacy/lib/models/common/widgets";
|
|
32
|
+
import groupBuilderWidgetsArray from "@/legacy/lib/models/common/widgets/groupBuilderArray";
|
|
31
33
|
import sliceBuilderWidgetsArray from "@/legacy/lib/models/common/widgets/sliceBuilderArray";
|
|
32
|
-
import { AnyWidget } from "@/legacy/lib/models/common/widgets/Widget";
|
|
33
34
|
import { ensureDnDDestination } from "@/legacy/lib/utils";
|
|
34
35
|
import { transformKeyAccessor } from "@/legacy/lib/utils/str";
|
|
36
|
+
import { getContentTypeForTracking } from "@/utils/getContentTypeForTracking";
|
|
35
37
|
|
|
36
38
|
const dataTipText = ` The non-repeatable zone
|
|
37
39
|
is for fields<br/> that should appear once, like a<br/>
|
|
@@ -109,34 +111,21 @@ const FieldZones: FC = () => {
|
|
|
109
111
|
}: {
|
|
110
112
|
id: string;
|
|
111
113
|
label: string;
|
|
112
|
-
widgetTypeName:
|
|
114
|
+
widgetTypeName: keyof typeof Widgets;
|
|
113
115
|
}) => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
const widget = sliceBuilderWidgetsArray.find(
|
|
117
|
+
(sliceBuilderWidget) =>
|
|
118
|
+
sliceBuilderWidget.CUSTOM_NAME === widgetTypeName ||
|
|
119
|
+
sliceBuilderWidget.TYPE_NAME === widgetTypeName,
|
|
120
|
+
);
|
|
119
121
|
if (!widget) {
|
|
120
|
-
|
|
121
|
-
`Could not find widget with type name "${widgetTypeName}". Please contact us!`,
|
|
122
|
-
);
|
|
122
|
+
throw new Error(`Unsupported Field Type: ${widgetTypeName}`);
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
const newField = widget.create(label) as NestableWidget;
|
|
127
|
-
|
|
128
|
-
if (
|
|
129
|
-
newField.type === "Range" ||
|
|
130
|
-
newField.type === "IntegrationFields" ||
|
|
131
|
-
newField.type === "Separator"
|
|
132
|
-
) {
|
|
133
|
-
throw new Error(`Unsupported Field Type: ${newField.type}`);
|
|
134
|
-
}
|
|
125
|
+
const newField = widget.create(label) as SlicePrimaryFieldSM;
|
|
135
126
|
|
|
136
127
|
try {
|
|
137
|
-
|
|
138
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
139
|
-
CurrentWidget.schema.validateSync(newField, { stripUnknown: false });
|
|
128
|
+
widget.schema.validateSync(newField, { stripUnknown: false });
|
|
140
129
|
} catch (error) {
|
|
141
130
|
throw new Error(`Model is invalid for widget "${newField.type}".`);
|
|
142
131
|
}
|
|
@@ -146,7 +135,8 @@ const FieldZones: FC = () => {
|
|
|
146
135
|
variationId: variation.id,
|
|
147
136
|
widgetArea,
|
|
148
137
|
newFieldId: id,
|
|
149
|
-
newField
|
|
138
|
+
newField:
|
|
139
|
+
newField.type === GroupFieldType ? Groups.fromSM(newField) : newField,
|
|
150
140
|
});
|
|
151
141
|
|
|
152
142
|
setSlice(newSlice);
|
|
@@ -155,9 +145,9 @@ const FieldZones: FC = () => {
|
|
|
155
145
|
event: "field:added",
|
|
156
146
|
id,
|
|
157
147
|
name: label,
|
|
158
|
-
type:
|
|
148
|
+
type: newField.type,
|
|
159
149
|
isInAGroup: false,
|
|
160
|
-
contentType:
|
|
150
|
+
contentType: getContentTypeForTracking(window.location.pathname),
|
|
161
151
|
});
|
|
162
152
|
};
|
|
163
153
|
|
|
@@ -194,14 +184,17 @@ const FieldZones: FC = () => {
|
|
|
194
184
|
<List>
|
|
195
185
|
<Zone
|
|
196
186
|
zoneType="slice"
|
|
197
|
-
zoneTypeFormat={undefined}
|
|
198
187
|
tabId={undefined}
|
|
199
188
|
title="Fields"
|
|
200
189
|
dataTip={dataTipText}
|
|
201
190
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
202
191
|
fields={variation.primary}
|
|
203
192
|
EditModal={EditModal}
|
|
204
|
-
widgetsArray={
|
|
193
|
+
widgetsArray={
|
|
194
|
+
groupsInSlicesExperiment.eligible
|
|
195
|
+
? sliceBuilderWidgetsArray
|
|
196
|
+
: groupBuilderWidgetsArray
|
|
197
|
+
}
|
|
205
198
|
onDeleteItem={_onDeleteItem(WidgetsArea.Primary)}
|
|
206
199
|
onSave={_onSave(WidgetsArea.Primary)}
|
|
207
200
|
onSaveNewField={_onSaveNewField(WidgetsArea.Primary)}
|
|
@@ -222,12 +215,11 @@ const FieldZones: FC = () => {
|
|
|
222
215
|
{!groupsInSlicesExperiment.eligible || hasItems ? (
|
|
223
216
|
<Zone
|
|
224
217
|
zoneType="slice"
|
|
225
|
-
zoneTypeFormat={undefined}
|
|
226
218
|
tabId={undefined}
|
|
227
219
|
isRepeatable
|
|
228
220
|
title="Repeatable Zone"
|
|
229
221
|
dataTip={dataTipText2}
|
|
230
|
-
widgetsArray={
|
|
222
|
+
widgetsArray={groupBuilderWidgetsArray}
|
|
231
223
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
232
224
|
fields={variation.items}
|
|
233
225
|
EditModal={EditModal}
|
|
@@ -17,6 +17,7 @@ const FieldZone = ({
|
|
|
17
17
|
onDragEnd,
|
|
18
18
|
renderFieldAccessor,
|
|
19
19
|
onDeleteItem,
|
|
20
|
+
onSave,
|
|
20
21
|
showHints,
|
|
21
22
|
newField,
|
|
22
23
|
renderHintBase,
|
|
@@ -82,6 +83,8 @@ const FieldZone = ({
|
|
|
82
83
|
parentSnapshot: snapshot,
|
|
83
84
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
84
85
|
deleteItem: onDeleteItem,
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
87
|
+
saveItem: onSave,
|
|
85
88
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-member-access
|
|
86
89
|
draggableId: `list-item-${item.key}`,
|
|
87
90
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
@@ -5,6 +5,7 @@ import { BaseStyles } from "theme-ui";
|
|
|
5
5
|
|
|
6
6
|
import { telemetry } from "@/apiClient";
|
|
7
7
|
import { ListHeader } from "@/components/List";
|
|
8
|
+
import { getContentTypeForTracking } from "@/utils/getContentTypeForTracking";
|
|
8
9
|
|
|
9
10
|
import SelectFieldTypeModal from "../SelectFieldTypeModal";
|
|
10
11
|
import Card from "./Card";
|
|
@@ -13,7 +14,6 @@ import EmptyState from "./components/EmptyState";
|
|
|
13
14
|
|
|
14
15
|
const Zone = ({
|
|
15
16
|
zoneType /* type of the zone: customType or slice */,
|
|
16
|
-
zoneTypeFormat /* format of the zone: custom or page (or undefined if not a custom type) */,
|
|
17
17
|
tabId,
|
|
18
18
|
title /* text info to display in Card Header */,
|
|
19
19
|
fields /* widgets registered in the zone */,
|
|
@@ -62,12 +62,7 @@ const Zone = ({
|
|
|
62
62
|
name: model.config.label,
|
|
63
63
|
type: model.type,
|
|
64
64
|
isInAGroup: false,
|
|
65
|
-
contentType:
|
|
66
|
-
zoneType === "customType"
|
|
67
|
-
? zoneTypeFormat === "page"
|
|
68
|
-
? "page type"
|
|
69
|
-
: "custom type"
|
|
70
|
-
: "slice",
|
|
65
|
+
contentType: getContentTypeForTracking(window.location.pathname),
|
|
71
66
|
});
|
|
72
67
|
};
|
|
73
68
|
const enterSelectMode = () => {
|
|
@@ -159,6 +154,8 @@ const Zone = ({
|
|
|
159
154
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
160
155
|
onDeleteItem={onDeleteItem}
|
|
161
156
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
157
|
+
onSave={onSave}
|
|
158
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
162
159
|
testId={testId}
|
|
163
160
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
164
161
|
isRepeatableCustomType={isRepeatableCustomType}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
+
GroupFieldType,
|
|
3
|
+
NestableWidget,
|
|
2
4
|
SharedSlice,
|
|
3
5
|
Variation,
|
|
4
6
|
} from "@prismicio/types-internal/lib/customtypes";
|
|
@@ -6,6 +8,7 @@ import { getOrElseW } from "fp-ts/lib/Either";
|
|
|
6
8
|
import * as t from "io-ts";
|
|
7
9
|
|
|
8
10
|
import { FieldsSM } from "./Fields";
|
|
11
|
+
import { Groups, GroupSM } from "./Group";
|
|
9
12
|
|
|
10
13
|
const IMAGE_PLACEHOLDER_URL =
|
|
11
14
|
"https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format";
|
|
@@ -15,6 +18,14 @@ export enum WidgetsArea {
|
|
|
15
18
|
Items = "items",
|
|
16
19
|
}
|
|
17
20
|
|
|
21
|
+
export const SlicePrimaryFieldSM = t.union([GroupSM, NestableWidget]);
|
|
22
|
+
export type SlicePrimaryFieldSM = t.TypeOf<typeof SlicePrimaryFieldSM>;
|
|
23
|
+
|
|
24
|
+
export const SlicePrimaryFieldsSM = t.array(
|
|
25
|
+
t.type({ key: t.string, value: SlicePrimaryFieldSM }),
|
|
26
|
+
);
|
|
27
|
+
export type SlicePrimaryFieldsSM = t.TypeOf<typeof SlicePrimaryFieldsSM>;
|
|
28
|
+
|
|
18
29
|
export const VariationSM = t.intersection([
|
|
19
30
|
t.type({
|
|
20
31
|
id: t.string,
|
|
@@ -25,7 +36,7 @@ export const VariationSM = t.intersection([
|
|
|
25
36
|
}),
|
|
26
37
|
t.partial({
|
|
27
38
|
imageUrl: t.string,
|
|
28
|
-
primary:
|
|
39
|
+
primary: SlicePrimaryFieldsSM,
|
|
29
40
|
items: FieldsSM,
|
|
30
41
|
display: t.string,
|
|
31
42
|
}),
|
|
@@ -55,7 +66,10 @@ export const Variations = {
|
|
|
55
66
|
Variation.decode({
|
|
56
67
|
...variation,
|
|
57
68
|
primary: variation.primary?.reduce(
|
|
58
|
-
(acc, { key, value }) => ({
|
|
69
|
+
(acc, { key, value }) => ({
|
|
70
|
+
...acc,
|
|
71
|
+
[key]: value.type === GroupFieldType ? Groups.fromSM(value) : value,
|
|
72
|
+
}),
|
|
59
73
|
{},
|
|
60
74
|
),
|
|
61
75
|
items: variation.items?.reduce(
|
|
@@ -80,7 +94,7 @@ export const Variations = {
|
|
|
80
94
|
primary: Object.entries(variation.primary || {}).map(
|
|
81
95
|
([key, value]) => ({
|
|
82
96
|
key,
|
|
83
|
-
value,
|
|
97
|
+
value: value.type === GroupFieldType ? Groups.toSM(value) : value,
|
|
84
98
|
}),
|
|
85
99
|
),
|
|
86
100
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
@@ -5,26 +5,23 @@ import { Box, Button } from "theme-ui";
|
|
|
5
5
|
|
|
6
6
|
import { telemetry } from "@/apiClient";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from "@/domain/
|
|
13
|
-
import { useCustomTypeState } from "@/features/customTypes/customTypesBuilder/CustomTypeProvider";
|
|
8
|
+
addFieldToGroup,
|
|
9
|
+
deleteFieldFromGroup,
|
|
10
|
+
reorderFieldInGroup,
|
|
11
|
+
updateFieldInGroup,
|
|
12
|
+
} from "@/domain/group";
|
|
14
13
|
import ListItem from "@/legacy/components/ListItem";
|
|
15
14
|
import EditModal from "@/legacy/lib/builders/common/EditModal";
|
|
16
15
|
import SelectFieldTypeModal from "@/legacy/lib/builders/common/SelectFieldTypeModal";
|
|
17
16
|
import Hint from "@/legacy/lib/builders/common/Zone/Card/components/Hints";
|
|
18
17
|
import NewField from "@/legacy/lib/builders/common/Zone/Card/components/NewField";
|
|
19
18
|
import { findWidgetByConfigOrType } from "@/legacy/lib/builders/utils";
|
|
20
|
-
import {
|
|
19
|
+
import { Groups } from "@/legacy/lib/models/common/Group";
|
|
21
20
|
import * as Widgets from "@/legacy/lib/models/common/widgets";
|
|
22
|
-
import
|
|
23
|
-
import {
|
|
24
|
-
ensureDnDDestination,
|
|
25
|
-
ensureWidgetTypeExistence,
|
|
26
|
-
} from "@/legacy/lib/utils";
|
|
21
|
+
import groupBuilderWidgetsArray from "@/legacy/lib/models/common/widgets/groupBuilderArray";
|
|
22
|
+
import { ensureDnDDestination } from "@/legacy/lib/utils";
|
|
27
23
|
import { transformKeyAccessor } from "@/legacy/lib/utils/str";
|
|
24
|
+
import { getContentTypeForTracking } from "@/utils/getContentTypeForTracking";
|
|
28
25
|
|
|
29
26
|
/* eslint-disable */
|
|
30
27
|
const CustomListItem = ({
|
|
@@ -36,14 +33,12 @@ const CustomListItem = ({
|
|
|
36
33
|
isRepeatable,
|
|
37
34
|
item: groupItem,
|
|
38
35
|
draggableId,
|
|
39
|
-
|
|
40
|
-
renderFieldAccessor,
|
|
36
|
+
saveItem,
|
|
41
37
|
...rest
|
|
42
38
|
}) => {
|
|
43
39
|
const [selectMode, setSelectMode] = useState(false);
|
|
44
40
|
const [newFieldData, setNewFieldData] = useState(null);
|
|
45
41
|
const [editModalData, setEditModalData] = useState({ isOpen: false });
|
|
46
|
-
const { customType, setCustomType } = useCustomTypeState();
|
|
47
42
|
|
|
48
43
|
const onSelectFieldType = (widgetTypeName) => {
|
|
49
44
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
@@ -60,54 +55,47 @@ const CustomListItem = ({
|
|
|
60
55
|
};
|
|
61
56
|
|
|
62
57
|
const onSaveNewField = ({ id, label, widgetTypeName }) => {
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
64
58
|
const widget = Widgets[widgetTypeName];
|
|
59
|
+
const newField = widget.create(label);
|
|
65
60
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const newCustomType = addGroupField({
|
|
71
|
-
customType,
|
|
72
|
-
sectionId: tabId,
|
|
73
|
-
groupFieldId: groupItem.key,
|
|
74
|
-
newField,
|
|
75
|
-
newFieldId: id,
|
|
61
|
+
const newGroupValue = addFieldToGroup({
|
|
62
|
+
group: Groups.fromSM(groupItem.value),
|
|
63
|
+
fieldId: id,
|
|
64
|
+
field: newField,
|
|
76
65
|
});
|
|
77
66
|
|
|
78
|
-
|
|
67
|
+
saveItem({
|
|
68
|
+
apiId: groupItem.key,
|
|
69
|
+
newKey: groupItem.key,
|
|
70
|
+
value: Groups.toSM(newGroupValue),
|
|
71
|
+
});
|
|
79
72
|
|
|
80
73
|
void telemetry.track({
|
|
81
74
|
event: "field:added",
|
|
82
75
|
id,
|
|
83
76
|
name: label,
|
|
84
|
-
type:
|
|
77
|
+
type: newField.type,
|
|
85
78
|
isInAGroup: true,
|
|
86
|
-
contentType:
|
|
79
|
+
contentType: getContentTypeForTracking(window.location.pathname),
|
|
87
80
|
});
|
|
88
81
|
};
|
|
89
82
|
|
|
90
83
|
const onSaveField = ({ apiId: previousKey, newKey, value }) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const newField = TabFieldsModel.fromSM(value);
|
|
97
|
-
const newCustomType = updateGroupField({
|
|
98
|
-
customType,
|
|
99
|
-
sectionId: tabId,
|
|
100
|
-
groupFieldId: groupItem.key,
|
|
84
|
+
const newGroupValue = updateFieldInGroup({
|
|
85
|
+
group: Groups.fromSM(groupItem.value),
|
|
101
86
|
previousFieldId: previousKey,
|
|
102
87
|
newFieldId: newKey,
|
|
103
|
-
|
|
88
|
+
field: value,
|
|
104
89
|
});
|
|
105
90
|
|
|
106
|
-
|
|
91
|
+
saveItem({
|
|
92
|
+
apiId: groupItem.key,
|
|
93
|
+
newKey: groupItem.key,
|
|
94
|
+
value: Groups.toSM(newGroupValue),
|
|
95
|
+
});
|
|
107
96
|
};
|
|
108
97
|
|
|
109
98
|
const onDragEnd = (result) => {
|
|
110
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
111
99
|
if (ensureDnDDestination(result)) {
|
|
112
100
|
return;
|
|
113
101
|
}
|
|
@@ -120,10 +108,8 @@ const CustomListItem = ({
|
|
|
120
108
|
const { index: sourceIndex } = source;
|
|
121
109
|
const { index: destinationIndex } = destination;
|
|
122
110
|
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
sectionId: tabId,
|
|
126
|
-
groupFieldId: groupItem.key,
|
|
111
|
+
const newGroupValue = reorderFieldInGroup({
|
|
112
|
+
group: Groups.fromSM(groupItem.value),
|
|
127
113
|
sourceIndex,
|
|
128
114
|
destinationIndex,
|
|
129
115
|
});
|
|
@@ -131,18 +117,26 @@ const CustomListItem = ({
|
|
|
131
117
|
// When removing redux and replacing it by a simple useState, react-beautiful-dnd (that is deprecated library) was making the fields flickering on reorder.
|
|
132
118
|
// The problem seems to come from the react non-synchronous way to handle our state update that didn't work well with the library.
|
|
133
119
|
// It's a hack and since it's used on an old pure JavaScript code with a deprecated library it will be removed when updating the UI of the fields.
|
|
134
|
-
flushSync(() =>
|
|
120
|
+
flushSync(() => {
|
|
121
|
+
saveItem({
|
|
122
|
+
apiId: groupItem.key,
|
|
123
|
+
newKey: groupItem.key,
|
|
124
|
+
value: Groups.toSM(newGroupValue),
|
|
125
|
+
});
|
|
126
|
+
});
|
|
135
127
|
};
|
|
136
128
|
|
|
137
129
|
const onDeleteItem = (key) => {
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
sectionId: tabId,
|
|
141
|
-
groupFieldId: groupItem.key,
|
|
130
|
+
const newGroupValue = deleteFieldFromGroup({
|
|
131
|
+
group: Groups.fromSM(groupItem.value),
|
|
142
132
|
fieldId: key,
|
|
143
133
|
});
|
|
144
134
|
|
|
145
|
-
|
|
135
|
+
saveItem({
|
|
136
|
+
apiId: groupItem.key,
|
|
137
|
+
newKey: groupItem.key,
|
|
138
|
+
value: Groups.toSM(newGroupValue),
|
|
139
|
+
});
|
|
146
140
|
};
|
|
147
141
|
|
|
148
142
|
/** @param {[string, import("@prismicio/types-internal/lib/customtypes").NestableWidget]} field */
|
|
@@ -157,9 +151,10 @@ const CustomListItem = ({
|
|
|
157
151
|
name: model.config.label,
|
|
158
152
|
type: model.type,
|
|
159
153
|
isInAGroup: true,
|
|
160
|
-
contentType:
|
|
154
|
+
contentType: getContentTypeForTracking(window.location.pathname),
|
|
161
155
|
});
|
|
162
156
|
};
|
|
157
|
+
|
|
163
158
|
return (
|
|
164
159
|
<Fragment>
|
|
165
160
|
<ListItem
|
|
@@ -170,7 +165,6 @@ const CustomListItem = ({
|
|
|
170
165
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
|
171
166
|
draggableId={draggableId}
|
|
172
167
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unused-vars, @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-member-access
|
|
173
|
-
renderFieldAccessor={(key) => `data.${groupItem.key}.[...]`}
|
|
174
168
|
{...rest}
|
|
175
169
|
CustomEditElements={[
|
|
176
170
|
<Button
|
|
@@ -220,8 +214,7 @@ const CustomListItem = ({
|
|
|
220
214
|
enterEditMode,
|
|
221
215
|
deleteItem: onDeleteItem,
|
|
222
216
|
renderFieldAccessor: (key) =>
|
|
223
|
-
|
|
224
|
-
`data.${groupItem.key}.${key}`,
|
|
217
|
+
`item${transformKeyAccessor(item.key)}`,
|
|
225
218
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions
|
|
226
219
|
draggableId: `group-${groupItem.key}-${item.key}-${index}`,
|
|
227
220
|
testId: `list-item-group-${groupItem.key}-${item.key}`,
|
|
@@ -237,9 +230,7 @@ const CustomListItem = ({
|
|
|
237
230
|
isRepeatable={isRepeatable}
|
|
238
231
|
renderHintBase={({ item }) =>
|
|
239
232
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-member-access
|
|
240
|
-
`
|
|
241
|
-
item.key,
|
|
242
|
-
)}`
|
|
233
|
+
`item${transformKeyAccessor(item.key)}`
|
|
243
234
|
}
|
|
244
235
|
Widgets={Widgets}
|
|
245
236
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
@@ -277,7 +268,7 @@ const CustomListItem = ({
|
|
|
277
268
|
data={{ isOpen: selectMode }}
|
|
278
269
|
close={() => setSelectMode(false)}
|
|
279
270
|
onSelect={onSelectFieldType}
|
|
280
|
-
widgetsArray={
|
|
271
|
+
widgetsArray={groupBuilderWidgetsArray}
|
|
281
272
|
/>
|
|
282
273
|
<EditModal
|
|
283
274
|
data={editModalData}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as Widgets from ".";
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
Widgets.StructuredText,
|
|
5
|
+
Widgets.Image,
|
|
6
|
+
Widgets.Link,
|
|
7
|
+
Widgets.LinkToMedia,
|
|
8
|
+
Widgets.ContentRelationship,
|
|
9
|
+
Widgets.Select,
|
|
10
|
+
Widgets.Boolean,
|
|
11
|
+
Widgets.Date,
|
|
12
|
+
Widgets.Timestamp,
|
|
13
|
+
Widgets.Embed,
|
|
14
|
+
Widgets.Number,
|
|
15
|
+
Widgets.GeoPoint,
|
|
16
|
+
Widgets.Color,
|
|
17
|
+
Widgets.Text,
|
|
18
|
+
];
|
|
@@ -1,31 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ColorWidget } from "./Color";
|
|
3
|
-
import { ContentRelationshipWidget } from "./ContentRelationship";
|
|
4
|
-
import { DateWidget } from "./Date";
|
|
5
|
-
import { EmbedWidget } from "./Embed";
|
|
6
|
-
import { GeoPointWidget } from "./GeoPoint";
|
|
7
|
-
import { ImageWidget } from "./Image";
|
|
8
|
-
import { LinkWidget } from "./Link";
|
|
9
|
-
import { LinkToMediaWidget } from "./LinkToMedia";
|
|
10
|
-
import { NumberWidget } from "./Number";
|
|
11
|
-
import { SelectWidget } from "./Select";
|
|
12
|
-
import { StructuredTextWidget } from "./StructuredText";
|
|
13
|
-
import { TextWidget } from "./Text";
|
|
14
|
-
import { TimestampWidget } from "./Timestamp";
|
|
1
|
+
import * as Widgets from "./withGroup";
|
|
15
2
|
|
|
16
3
|
export default [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
4
|
+
Widgets.Group,
|
|
5
|
+
Widgets.StructuredText,
|
|
6
|
+
Widgets.Image,
|
|
7
|
+
Widgets.Link,
|
|
8
|
+
Widgets.LinkToMedia,
|
|
9
|
+
Widgets.ContentRelationship,
|
|
10
|
+
Widgets.Select,
|
|
11
|
+
Widgets.Boolean,
|
|
12
|
+
Widgets.Date,
|
|
13
|
+
Widgets.Timestamp,
|
|
14
|
+
Widgets.Embed,
|
|
15
|
+
Widgets.Number,
|
|
16
|
+
Widgets.GeoPoint,
|
|
17
|
+
Widgets.Color,
|
|
18
|
+
Widgets.Text,
|
|
31
19
|
];
|
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { ContentRelationship } from ".";
|
|
3
|
-
export { Date } from ".";
|
|
4
|
-
export { Embed } from ".";
|
|
5
|
-
export { GeoPoint } from ".";
|
|
6
|
-
export { Image } from ".";
|
|
7
|
-
export { Link } from ".";
|
|
8
|
-
export { LinkToMedia } from ".";
|
|
9
|
-
export { Number } from ".";
|
|
10
|
-
export { Select } from ".";
|
|
11
|
-
export { StructuredText } from ".";
|
|
12
|
-
export { Text } from ".";
|
|
13
|
-
export { Timestamp } from ".";
|
|
14
|
-
export { UID } from ".";
|
|
15
|
-
export { Boolean } from "./";
|
|
1
|
+
export * from ".";
|
|
16
2
|
export { GroupWidget as Group } from "./Group";
|
|
17
|
-
|
|
18
|
-
export const SharedSlice = null;
|
|
19
|
-
export const SliceZone = null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines the content type of a given URL's pathname. This method is
|
|
3
|
+
* designed for the `field:*` tracking event, but may be used elsewhere.
|
|
4
|
+
*
|
|
5
|
+
* @param pathname - A URL's pathname.
|
|
6
|
+
*
|
|
7
|
+
* @throws {Error} Thrown when not on a slice, custom type, or page type page.
|
|
8
|
+
*/
|
|
9
|
+
export function getContentTypeForTracking(
|
|
10
|
+
pathname: string,
|
|
11
|
+
): "page type" | "custom type" | "slice" {
|
|
12
|
+
if (pathname.startsWith("/slices/")) {
|
|
13
|
+
return "slice";
|
|
14
|
+
} else if (pathname.startsWith("/custom-types/")) {
|
|
15
|
+
return "custom type";
|
|
16
|
+
} else if (pathname.startsWith("/page-types/")) {
|
|
17
|
+
return "page type";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
throw new Error(`Did not detect a content type from: ${pathname}`);
|
|
21
|
+
}
|