slice-machine-ui 2.16.2-alpha.xru-tracking-cr.4 → 2.16.2-beta.10
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/EvmgR0Gau-7Wz9Fnt3n3p/_buildManifest.js +1 -0
- package/out/_next/static/chunks/268-6d5fc7642a1b87c8.js +1 -0
- package/out/_next/static/chunks/34-2911c905c8a6e9d9.js +1 -0
- package/out/_next/static/chunks/630-93339694ef30b82d.js +1 -0
- package/out/_next/static/chunks/867-8164160c810122c6.js +1 -0
- package/out/_next/static/chunks/882-28837678beff7e51.js +1 -0
- package/out/_next/static/chunks/895-8c214ba470a4e23c.js +1 -0
- package/out/_next/static/chunks/pages/_app-80614b8c7575109c.js +657 -0
- package/out/_next/static/chunks/pages/changelog-80a618708f44f25f.js +1 -0
- package/out/_next/static/chunks/pages/changes-d40c17939854b984.js +1 -0
- package/out/_next/static/chunks/pages/custom-types/{[customTypeId]-a408f5a660e096a6.js → [customTypeId]-389d1b7a492fb3e7.js} +1 -1
- package/out/_next/static/chunks/pages/{custom-types-5acd56959b60346f.js → custom-types-2a5fd94ee42ba593.js} +1 -1
- package/out/_next/static/chunks/pages/{index-0d8cb369de720a35.js → index-02dd147957c8b40f.js} +1 -1
- package/out/_next/static/chunks/pages/labs-c6df252ea5d8fb6f.js +1 -0
- package/out/_next/static/chunks/pages/page-types/{[pageTypeId]-f5e851ebe35049a8.js → [pageTypeId]-3589bd1f9138a97b.js} +1 -1
- package/out/_next/static/chunks/pages/settings-170379902605f38a.js +1 -0
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-063fa88ba75f483e.js +1 -0
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-6de02b8ed13b680d.js +1 -0
- package/out/_next/static/chunks/pages/slices-071bb494907adf0f.js +1 -0
- package/out/_next/static/chunks/webpack-2f903acb0cccbf9e.js +1 -0
- package/out/_next/static/css/9c9a7de81f9ac811.css +1 -0
- 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 +7 -7
- package/src/features/customTypes/customTypesTable/CustomTypesTable.tsx +4 -2
- package/src/features/customTypes/customTypesTable/{useCustomTypesAutoRevalidation.tsx → useCustomTypes.ts} +34 -1
- package/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx +1 -12
- package/src/legacy/lib/models/common/widgets/ContentRelationship/Form.tsx +77 -35
- package/src/legacy/lib/models/common/widgets/ContentRelationship/index.ts +14 -44
- package/src/legacy/lib/models/common/widgets/Link/index.ts +1 -1
- package/src/utils/tracking/trackFieldAdded.ts +5 -2
- package/src/utils/tracking/trackFieldUpdated.ts +5 -2
- package/out/_next/static/chunks/248-03446cd9e9f13730.js +0 -1
- package/out/_next/static/chunks/268-6a9214b97195af9c.js +0 -1
- package/out/_next/static/chunks/33641354.3864aefb6106ae71.js +0 -28
- package/out/_next/static/chunks/34-e684c5fd75cc9dd0.js +0 -1
- package/out/_next/static/chunks/630-8efab4cfe04dfb06.js +0 -1
- package/out/_next/static/chunks/647-7b9b5aa9468f9e4b.js +0 -1
- package/out/_next/static/chunks/882-151468121d542ed6.js +0 -1
- package/out/_next/static/chunks/pages/_app-500efc039f19ee3b.js +0 -708
- package/out/_next/static/chunks/pages/changelog-063c5e11dfc8fd55.js +0 -1
- package/out/_next/static/chunks/pages/changes-564336edb0ed18b0.js +0 -1
- package/out/_next/static/chunks/pages/labs-9630bfb1005be02b.js +0 -1
- package/out/_next/static/chunks/pages/settings-01f4aeb9112a1f87.js +0 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-5008e29008aa04f4.js +0 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-bd5e45632c419567.js +0 -1
- package/out/_next/static/chunks/pages/slices-4a60cd5f2c71327e.js +0 -1
- package/out/_next/static/chunks/webpack-b3522fdebabf510a.js +0 -1
- package/out/_next/static/css/cc9b10286400c2b9.css +0 -1
- package/out/_next/static/zAOttmW3TuLUODww2NpRw/_buildManifest.js +0 -1
- package/src/features/builder/fields/contentRelationship/ContentRelationshipFieldPicker.tsx +0 -1276
- package/src/features/builder/fields/contentRelationship/Hint.tsx +0 -28
- package/src/features/builder/fields/contentRelationship/__tests__/ContentRelationshipFieldPicker.test.ts +0 -265
- package/src/features/customTypes/useCustomTypes.ts +0 -48
- package/src/utils/isValidObject.ts +0 -32
- package/src/utils/tracking/getLinkTrackingProperties.ts +0 -26
- /package/out/_next/static/{zAOttmW3TuLUODww2NpRw → EvmgR0Gau-7Wz9Fnt3n3p}/_ssgManifest.js +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slice-machine-ui",
|
|
3
|
-
"version": "2.16.2-
|
|
3
|
+
"version": "2.16.2-beta.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "A visual builder for your Slice Models with all the tools you need to generate data models and mock CMS content locally.",
|
|
6
6
|
"repository": {
|
|
@@ -35,18 +35,18 @@
|
|
|
35
35
|
"start-slicemachine": "./bin/start-slicemachine.cjs"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@slicemachine/manager": "0.24.16-
|
|
39
|
-
"start-slicemachine": "0.12.58-
|
|
38
|
+
"@slicemachine/manager": "0.24.16-beta.10",
|
|
39
|
+
"start-slicemachine": "0.12.58-beta.10"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@emotion/react": "11.11.1",
|
|
43
43
|
"@extractus/oembed-extractor": "3.1.8",
|
|
44
44
|
"@prismicio/client": "7.17.0",
|
|
45
|
-
"@prismicio/editor-fields": "0.4.
|
|
46
|
-
"@prismicio/editor-support": "0.4.
|
|
47
|
-
"@prismicio/editor-ui": "0.4.
|
|
45
|
+
"@prismicio/editor-fields": "0.4.75",
|
|
46
|
+
"@prismicio/editor-support": "0.4.75",
|
|
47
|
+
"@prismicio/editor-ui": "0.4.75",
|
|
48
48
|
"@prismicio/mock": "0.7.1",
|
|
49
|
-
"@prismicio/mocks": "2.
|
|
49
|
+
"@prismicio/mocks": "2.13.0",
|
|
50
50
|
"@prismicio/simulator": "0.1.4",
|
|
51
51
|
"@prismicio/types-internal": "3.11.2",
|
|
52
52
|
"@radix-ui/react-hover-card": "1.0.6",
|
|
@@ -29,8 +29,10 @@ import { SingleIcon } from "@/icons/SingleIcon";
|
|
|
29
29
|
|
|
30
30
|
import { CUSTOM_TYPES_CONFIG } from "../customTypesConfig";
|
|
31
31
|
import { EditDropdown } from "../EditDropdown";
|
|
32
|
-
import {
|
|
33
|
-
|
|
32
|
+
import {
|
|
33
|
+
useCustomTypes,
|
|
34
|
+
useCustomTypesAutoRevalidation,
|
|
35
|
+
} from "./useCustomTypes";
|
|
34
36
|
|
|
35
37
|
type CustomTypesTableProps = {
|
|
36
38
|
format: CustomTypeFormat;
|
|
@@ -1,13 +1,46 @@
|
|
|
1
|
+
import { updateData, useRequest } from "@prismicio/editor-support/Suspense";
|
|
1
2
|
import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
2
3
|
import type { CustomTypeFormat } from "@slicemachine/manager";
|
|
3
|
-
import { useEffect } from "react";
|
|
4
|
+
import { useCallback, useEffect } from "react";
|
|
4
5
|
import { useSelector } from "react-redux";
|
|
5
6
|
|
|
6
7
|
import { CustomTypes } from "@/legacy/lib/models/common/CustomType";
|
|
7
8
|
import { hasLocal } from "@/legacy/lib/models/common/ModelData";
|
|
9
|
+
import { managerClient } from "@/managerClient";
|
|
8
10
|
import { selectAllCustomTypes } from "@/modules/availableCustomTypes";
|
|
9
11
|
import type { SliceMachineStoreType } from "@/redux/type";
|
|
10
12
|
|
|
13
|
+
type UseCustomTypesReturnType = {
|
|
14
|
+
customTypes: CustomType[];
|
|
15
|
+
updateCustomTypes: (customTypes: CustomType[]) => void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function useCustomTypes(
|
|
19
|
+
format: CustomTypeFormat,
|
|
20
|
+
): UseCustomTypesReturnType {
|
|
21
|
+
const updateCustomTypes = useCallback(
|
|
22
|
+
(data: CustomType[]) => updateData(getCustomTypes, [format], data),
|
|
23
|
+
[format],
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
customTypes: useRequest(getCustomTypes, [format]),
|
|
28
|
+
updateCustomTypes,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function getCustomTypes(format: CustomTypeFormat): Promise<CustomType[]> {
|
|
33
|
+
const { errors, models } = await managerClient.customTypes.readAllCustomTypes(
|
|
34
|
+
{ format },
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if (errors.length > 0) {
|
|
38
|
+
throw errors;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return models.map(({ model }) => model);
|
|
42
|
+
}
|
|
43
|
+
|
|
11
44
|
/**
|
|
12
45
|
* TODO: DT-1363 - Update the way to have new data without Redux by revalidating
|
|
13
46
|
* Suspense
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import useSWR from "swr";
|
|
3
3
|
|
|
4
|
-
import { Hint as ContentRelationshipHint } from "@/features/builder/fields/contentRelationship/Hint";
|
|
5
4
|
import { managerClient } from "@/managerClient";
|
|
6
5
|
|
|
7
6
|
import CodeBlock, { Item, RenderHintBaseFN } from "./CodeBlock";
|
|
@@ -13,7 +12,7 @@ interface HintProps {
|
|
|
13
12
|
hintItemName?: string;
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
const
|
|
15
|
+
const Hint: React.FC<HintProps> = ({
|
|
17
16
|
show,
|
|
18
17
|
renderHintBase,
|
|
19
18
|
item,
|
|
@@ -63,14 +62,4 @@ const RegularHint: React.FC<HintProps> = ({
|
|
|
63
62
|
);
|
|
64
63
|
};
|
|
65
64
|
|
|
66
|
-
const Hint: React.FC<HintProps> = (props) => {
|
|
67
|
-
const { item } = props;
|
|
68
|
-
|
|
69
|
-
if (item.value.type === "Link" && item.value.config?.select === "document") {
|
|
70
|
-
return <ContentRelationshipHint show={props.show} />;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return <RegularHint {...props} />;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
65
|
export default Hint;
|
|
@@ -1,63 +1,105 @@
|
|
|
1
|
-
import { LinkConfig } from "@prismicio/types-internal/lib/customtypes";
|
|
2
1
|
import { FormikProps } from "formik";
|
|
3
|
-
import {
|
|
2
|
+
import { useSelector } from "react-redux";
|
|
3
|
+
import Select from "react-select";
|
|
4
|
+
import { Box, Label } from "theme-ui";
|
|
4
5
|
import * as yup from "yup";
|
|
5
6
|
|
|
6
|
-
import { ContentRelationshipFieldPicker } from "@/features/builder/fields/contentRelationship/ContentRelationshipFieldPicker";
|
|
7
7
|
import { Col, Flex as FlexGrid } from "@/legacy/components/Flex";
|
|
8
8
|
import WidgetFormField from "@/legacy/lib/builders/common/EditModal/Field";
|
|
9
9
|
import { createFieldNameFromKey } from "@/legacy/lib/forms";
|
|
10
10
|
import { DefaultFields } from "@/legacy/lib/forms/defaults";
|
|
11
|
+
import { selectAllCustomTypes } from "@/modules/availableCustomTypes";
|
|
12
|
+
|
|
13
|
+
import { hasLocal } from "../../ModelData";
|
|
11
14
|
|
|
12
15
|
const FormFields = {
|
|
13
16
|
label: DefaultFields.label,
|
|
14
17
|
id: DefaultFields.id,
|
|
15
18
|
customtypes: {
|
|
16
|
-
validate: () => yup.array(),
|
|
19
|
+
validate: () => yup.array().of(yup.string()),
|
|
17
20
|
},
|
|
18
21
|
};
|
|
19
22
|
|
|
20
23
|
type FormProps = {
|
|
21
|
-
config: {
|
|
22
|
-
label: string;
|
|
23
|
-
select: string;
|
|
24
|
-
customtypes?: LinkConfig["customtypes"];
|
|
25
|
-
};
|
|
24
|
+
config: { label: string; select: string; customtypes?: string[] };
|
|
26
25
|
id: string;
|
|
27
|
-
// TODO: this exists in the yup schema but this doesn't seem to be validated by formik
|
|
26
|
+
// type: string; // TODO: this exists in the yup schema but this doesn't seem to be validated by formik
|
|
28
27
|
};
|
|
29
28
|
|
|
30
29
|
const WidgetForm = ({
|
|
31
30
|
initialValues,
|
|
32
|
-
values,
|
|
33
|
-
setFieldValue,
|
|
31
|
+
values: formValues,
|
|
34
32
|
fields,
|
|
33
|
+
setFieldValue,
|
|
35
34
|
}: FormikProps<FormProps> & { fields: Record<string, unknown> }) => {
|
|
35
|
+
const customTypes = useSelector(selectAllCustomTypes).filter(hasLocal);
|
|
36
|
+
|
|
37
|
+
const options = customTypes.map((ct) => ({
|
|
38
|
+
value: ct.local.id,
|
|
39
|
+
label: ct.local.label,
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
const selectValues = formValues.config.customtypes
|
|
43
|
+
? formValues.config.customtypes.map((id) => {
|
|
44
|
+
const ct = customTypes.find(
|
|
45
|
+
(frontendCustomType) => frontendCustomType.local.id === id,
|
|
46
|
+
);
|
|
47
|
+
return { value: ct?.local.id, label: ct?.local.label };
|
|
48
|
+
})
|
|
49
|
+
: null;
|
|
50
|
+
|
|
36
51
|
return (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
<
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
onChange={(fields) => {
|
|
56
|
-
void setFieldValue("config.customtypes", fields);
|
|
52
|
+
<FlexGrid>
|
|
53
|
+
{Object.entries(FormFields)
|
|
54
|
+
.filter((e) => e[0] !== "customtypes")
|
|
55
|
+
.map(([key, field]) => (
|
|
56
|
+
<Col key={key}>
|
|
57
|
+
<WidgetFormField
|
|
58
|
+
fieldName={createFieldNameFromKey(key)}
|
|
59
|
+
formField={field}
|
|
60
|
+
fields={fields}
|
|
61
|
+
initialValues={initialValues}
|
|
62
|
+
/>
|
|
63
|
+
</Col>
|
|
64
|
+
))}
|
|
65
|
+
<Col>
|
|
66
|
+
<Box
|
|
67
|
+
sx={{
|
|
68
|
+
mt: 2,
|
|
69
|
+
alignItems: "center",
|
|
57
70
|
}}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
>
|
|
72
|
+
<Label htmlFor="origin" mb="1">
|
|
73
|
+
Types
|
|
74
|
+
</Label>
|
|
75
|
+
<Select
|
|
76
|
+
isMulti
|
|
77
|
+
name="origin"
|
|
78
|
+
options={options}
|
|
79
|
+
onChange={(v) => {
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
81
|
+
if (v) {
|
|
82
|
+
void setFieldValue(
|
|
83
|
+
"config.customtypes",
|
|
84
|
+
v.map(({ value }) => value),
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}}
|
|
88
|
+
value={selectValues}
|
|
89
|
+
theme={(theme) => {
|
|
90
|
+
return {
|
|
91
|
+
...theme,
|
|
92
|
+
colors: {
|
|
93
|
+
...theme.colors,
|
|
94
|
+
text: "text",
|
|
95
|
+
primary: "background",
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}}
|
|
99
|
+
/>
|
|
100
|
+
</Box>
|
|
101
|
+
</Col>
|
|
102
|
+
</FlexGrid>
|
|
61
103
|
);
|
|
62
104
|
};
|
|
63
105
|
|
|
@@ -7,44 +7,17 @@ import { Widget } from "../Widget";
|
|
|
7
7
|
import Form, { FormFields } from "./Form";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Legacy:
|
|
11
|
-
* {
|
|
12
|
-
* "type": "Link",
|
|
13
|
-
* "config": {
|
|
14
|
-
* "select": "document",
|
|
15
|
-
* "label": "relationship"
|
|
16
|
-
* "customtypes": [
|
|
17
|
-
* "page"
|
|
18
|
-
* ],
|
|
19
|
-
* }
|
|
20
|
-
* }
|
|
21
|
-
*
|
|
22
|
-
* Current format (field picking):
|
|
23
10
|
* {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* "id": "countryRelation",
|
|
35
|
-
* "customtypes": [
|
|
36
|
-
* {
|
|
37
|
-
* "id": "country",
|
|
38
|
-
* "fields": ["name"]
|
|
39
|
-
* }
|
|
40
|
-
* ]
|
|
41
|
-
* }
|
|
42
|
-
* ]
|
|
43
|
-
* }
|
|
44
|
-
* ],
|
|
45
|
-
* }
|
|
46
|
-
* }
|
|
47
|
-
*/
|
|
11
|
+
"type": "Link",
|
|
12
|
+
"config": {
|
|
13
|
+
"select": "document",
|
|
14
|
+
"customtypes": [
|
|
15
|
+
"page"
|
|
16
|
+
],
|
|
17
|
+
"label": "relationship"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
*/
|
|
48
21
|
|
|
49
22
|
const Meta = {
|
|
50
23
|
icon: MdSettingsEthernet,
|
|
@@ -57,7 +30,7 @@ const contentRelationShipConfigSchema = linkConfigSchema.shape({
|
|
|
57
30
|
.string()
|
|
58
31
|
.required()
|
|
59
32
|
.matches(/^document$/, { excludeEmptyString: true }),
|
|
60
|
-
customtypes: yup.array().optional(),
|
|
33
|
+
customtypes: yup.array(yup.string()).strict().optional(),
|
|
61
34
|
});
|
|
62
35
|
|
|
63
36
|
const schema = yup.object().shape({
|
|
@@ -92,12 +65,9 @@ export const ContentRelationshipWidget: Widget<Link, typeof schema> = {
|
|
|
92
65
|
return {
|
|
93
66
|
...initialValues,
|
|
94
67
|
customtypes: initialValues.customtypes.filter((ct) =>
|
|
95
|
-
customTypes.find(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
return frontendCustomType.local.id === ct.id;
|
|
100
|
-
}),
|
|
68
|
+
customTypes.find(
|
|
69
|
+
(frontendCustomType) => frontendCustomType.local.id === ct,
|
|
70
|
+
),
|
|
101
71
|
),
|
|
102
72
|
};
|
|
103
73
|
},
|
|
@@ -72,7 +72,7 @@ export const linkConfigSchema = yup
|
|
|
72
72
|
.optional()
|
|
73
73
|
.oneOf(["media", "document", "web", null])
|
|
74
74
|
.nullable(),
|
|
75
|
-
customtypes: yup.array().strict().optional(),
|
|
75
|
+
customtypes: yup.array(yup.string()).strict().optional(),
|
|
76
76
|
masks: yup.array(yup.string()).optional(),
|
|
77
77
|
tags: yup.array(yup.string()).optional(),
|
|
78
78
|
allowTargetBlank: yup.boolean().strict().optional(),
|
|
@@ -8,7 +8,6 @@ import { telemetry } from "@/apiClient";
|
|
|
8
8
|
import { SlicePrimaryFieldSM } from "@/legacy/lib/models/common/Slice";
|
|
9
9
|
|
|
10
10
|
import { getContentTypeForTracking } from "./getContentTypeForTracking";
|
|
11
|
-
import { getLinkTrackingProperties } from "./getLinkTrackingProperties";
|
|
12
11
|
|
|
13
12
|
type TrackFieldAddedArgs = {
|
|
14
13
|
id: string;
|
|
@@ -26,6 +25,10 @@ export function trackFieldAdded(args: TrackFieldAddedArgs) {
|
|
|
26
25
|
type: field.type,
|
|
27
26
|
isInAGroup,
|
|
28
27
|
contentType: getContentTypeForTracking(window.location.pathname),
|
|
29
|
-
...(field.type === "Link" &&
|
|
28
|
+
...(field.type === "Link" && {
|
|
29
|
+
allowText: field.config?.allowText,
|
|
30
|
+
repeat: field.config?.repeat,
|
|
31
|
+
variants: field.config?.variants,
|
|
32
|
+
}),
|
|
30
33
|
});
|
|
31
34
|
}
|
|
@@ -8,7 +8,6 @@ import { telemetry } from "@/apiClient";
|
|
|
8
8
|
import { SlicePrimaryFieldSM } from "@/legacy/lib/models/common/Slice";
|
|
9
9
|
|
|
10
10
|
import { getContentTypeForTracking } from "./getContentTypeForTracking";
|
|
11
|
-
import { getLinkTrackingProperties } from "./getLinkTrackingProperties";
|
|
12
11
|
|
|
13
12
|
type TrackFieldUpdatedArgs = {
|
|
14
13
|
id: string;
|
|
@@ -29,6 +28,10 @@ export function trackFieldUpdated(args: TrackFieldUpdatedArgs) {
|
|
|
29
28
|
type: field.type,
|
|
30
29
|
isInAGroup,
|
|
31
30
|
contentType: getContentTypeForTracking(window.location.pathname),
|
|
32
|
-
...(field.type === "Link" &&
|
|
31
|
+
...(field.type === "Link" && {
|
|
32
|
+
allowText: field.config?.allowText,
|
|
33
|
+
repeat: field.config?.repeat,
|
|
34
|
+
variants: field.config?.variants,
|
|
35
|
+
}),
|
|
33
36
|
});
|
|
34
37
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[248],{72641:function(e,t,n){"use strict";n.d(t,{R$:function(){return i},Qj:function(){return x},T9:function(){return d},nf:function(){return h},u2:function(){return o},_T:function(){return u}});var l=n(52322),r=n(56803),a=n(6277),s=n(83478),c=n.n(s);let i=e=>{let{backgroundImage:t,style:n,...r}=e,s=void 0!==t;return(0,l.jsx)("article",{...r,className:(0,a.W)(c().root,{[c().withBackground]:s}),style:{backgroundImage:s?"url(".concat(t,")"):void 0,...n}})},o=e=>(0,l.jsx)("div",{...e,className:c().image}),d=e=>(0,l.jsx)("div",{...e,className:c().content}),u=e=>(0,l.jsx)(r.bL,{...e,variant:"h3"}),h=e=>(0,l.jsx)(r.bL,{...e,color:"grey11"}),x=e=>(0,l.jsx)("div",{...e,className:c().actions,color:"grey"})},38241:function(e,t,n){"use strict";n.d(t,{F:function(){return O}});var l=n(52322),r=n(56803),a=n(97729),s=n.n(a),c=n(2784),i=n(43388),o=n(17378),d=n(98564),u=n(51384),h=n(5632),x=n(56580),m=n(75289),p=n(77630),j=n(88932),g=n(94160),b=n(39204);async function f(e){let{id:t,label:n,repeatable:l,format:r,onSuccess:a}=e,s=d.$[r],c=(0,p.Ue)({id:t,label:n,repeatable:l,format:r});try{let{errors:e}=await (0,g.KA)({customType:c});if(e.length>0)throw e;g.Xe.track({event:"custom-type:created",id:c.id,name:n,format:r,type:l?"repeatable":"single",origin:"table"}),await a(c),j.Am.success((0,b.GX)({message:"".concat(s.name({start:!0,plural:!1})," saved successfully at "),path:"./customtypes/".concat(c.id,"/index.json")}))}catch(t){let e="Internal Error: ".concat(s.name({start:!0,plural:!1})," not saved");console.error(e,t),j.Am.error(e)}}var v=n(59294),_=n(98250),S=n(68968),y=n(59532),C=n(7974),k=n(358),w=n(78254),L=n(54597),I=n(46999),R=n(63397);let B=e=>{let{selected:t,...n}=e;return(0,l.jsx)(m.kC,{sx:{p:"24px",mb:3,alignItems:"top",cursor:"pointer",borderRadius:"6px",backgroundColor:"grayLight",boxShadow:t?e=>{var t;return"0 0 0 2px ".concat(String(null===(t=e.colors)||void 0===t?void 0:t.primary))}:"none","&:hover":{boxShadow:e=>{var t;return"0 0 0 2px ".concat(String(null===(t=e.colors)||void 0===t?void 0:t.primary))}}},...n})},N=e=>{let{format:t}=e,[n,,r]=(0,R.U$)("repeatable"),a=d.$[t];return(0,l.jsxs)(m.xu,{mb:2,children:[(0,l.jsxs)(B,{selected:n.value,onClick:()=>r.setValue(!0),children:[(0,l.jsx)(m.Y8,{checked:n.value,onChange:()=>{},"data-testid":"repeatable-type-radio-btn"}),(0,l.jsxs)(m.xu,{sx:{marginLeft:2},children:["Reusable type",(0,l.jsx)(m.xu,{as:"p",sx:{fontSize:"12px",color:"textClear",mt:1},children:a.hintRepeatable})]})]}),(0,l.jsxs)(B,{selected:!n.value,onClick:()=>r.setValue(!1),children:[(0,l.jsx)(m.Y8,{checked:!n.value,onChange:()=>{},"data-testid":"single-type-radio-btn"}),(0,l.jsxs)(m.xu,{sx:{marginLeft:2},children:["Single type",(0,l.jsx)(m.xu,{as:"p",sx:{fontSize:"12px",color:"textClear",mt:1},children:a.hintSingle})]})]})]})},z=e=>{let{format:t,isCreating:n,isOpen:r,origin:a="table",onCreateChange:s,onOpenChange:i}=e,{createCustomTypeSuccess:o}=(0,L.Z)(),{completeStep:u}=(0,_.k)(),{customTypeIds:j,customTypeLabels:g}=(0,x.v9)(e=>({customTypeIds:(0,w.W6)(e),customTypeLabels:(0,w.YS)(e)})),b=d.$[t],[R,B]=(0,c.useState)(!0),{syncChanges:z}=(0,S.g)(),E=(0,h.useRouter)(),T=async e=>{let{id:n,label:l,repeatable:r}=e;s(!0),await f({format:t,id:n,label:l,origin:a,repeatable:r,onSuccess:async e=>{o(e);let t=(0,p.y6)(e),l=v.cd[t];B(!0),await E.push({pathname:l.getBuilderPagePathname(n)}),z(),"page"===t&&u("createPageType")}}),s(!1),i(!1)},G=(e,t,n)=>{n(R?{...t,label:e.target.value,id:(0,k.lV)(e.target.value)}:{...t,label:e.target.value})},D=(e,t)=>{t("id",e.target.value),B(!1)};return(0,l.jsx)(y.Z,{testId:"create-ct-modal",isOpen:r,widthInPx:"530px",formId:"create-custom-type",buttonLabel:"Create",close:()=>{i(!1),B(!0)},onSubmit:e=>{T(e)},isLoading:n,initialValues:{repeatable:!0,id:"",label:""},validate:e=>{let{id:t,label:n}=e,l={};return n&&n.length||(l.label="Cannot be empty."),!l.label&&g.includes(n)&&(l.label="".concat(b.name({start:!0,plural:!1})," name is already taken.")),["update","insert"].includes(n.toLowerCase())&&(l.label='Name "'.concat(n,'" is reserved for Slice Machine use.')),t&&t.length||(l.id="ID cannot be empty."),["update","insert"].includes(t.toLowerCase())&&(l.id='Id "'.concat(t,'" is reserved for Slice Machine use.')),l.id||!t||C.xo.exec(t)||(l.id="Invalid id: No special characters allowed."),!l.id&&t&&j.map(e=>e.toLowerCase()).includes(t)&&(l.id='ID "'.concat(t,'" exists already.')),Object.keys(l).length>0?l:void 0},content:{title:"Create a new ".concat(b.name({start:!1,plural:!1}))},children:e=>{let{errors:n,setValues:r,setFieldValue:a,values:s,touched:c}=e;return(0,l.jsxs)(m.xu,{children:[(0,l.jsx)(N,{format:t}),(0,l.jsx)(I.W,{name:"label",label:"".concat(b.name({start:!0,plural:!1})," Name"),testId:"ct-name-input",placeholder:"A display name for the ".concat(b.name({start:!1,plural:!1})),error:c.label?n.label:void 0,onChange:e=>G(e,s,r)}),(0,l.jsx)(I.W,{name:"id",testId:"ct-id-input",label:"".concat(b.name({start:!0,plural:!1})," ID"),placeholder:b.inputPlaceholder,error:c.id?n.id:void 0,onChange:e=>D(e,a)})]})}})};var E=n(72641);let T=e=>(0,l.jsxs)("svg",{viewBox:"0 0 20 24",xmlns:"http://www.w3.org/2000/svg",...e,children:[(0,l.jsx)("path",{d:"m2 24h16c1.1046 0 2-.8954 2-2v-17l-5-5h-13c-1.10457 0-2 .89543-2 2v20c0 1.1046.89543 2 2 2z",fill:"#6e56cf"}),(0,l.jsx)("path",{d:"m17 5h3l-5-5v3c0 1.10457.8954 2 2 2z",fill:"#9e8cfc"}),(0,l.jsx)("path",{d:"m10.0912 8c-2.8118 0-5.0912 2.2794-5.0912 5.0912s2.2794 5.0912 5.0912 5.0912c1.8851 0 3.5303-1.0247 4.4098-2.5452.1553-.2684.2868-.5523.3916-.8489.092-.2604-.0444-.5461-.3048-.6381-.2603-.092-.546.0445-.638.3048-.0841.238-.1897.4659-.3144.6815-.7081 1.2241-2.0305 2.0459-3.5442 2.0459-2.2595 0-4.0912-1.8317-4.0912-4.0912s1.8317-4.0912 4.0912-4.0912c1.3566 0 2.5595.66 3.3043 1.6782h-1.7739c-.2761 0-.5.2239-.5.5 0 .2762.2239.5.5.5h2.6782c.2762 0 .5-.2238.5-.5v-2.6782c0-.2761-.2238-.5-.5-.5-.2761 0-.5.2239-.5.5v1.1032c-.9281-.9865-2.2462-1.6032-3.7086-1.6032z",fill:"#fff"})]}),G=e=>(0,l.jsxs)("svg",{viewBox:"0 0 20 24",xmlns:"http://www.w3.org/2000/svg",...e,children:[(0,l.jsx)("path",{d:"m2 24h16c1.1046 0 2-.8954 2-2v-17l-5-5h-13c-1.10457 0-2 .89543-2 2v20c0 1.1046.89543 2 2 2z",fill:"#6e56cf",fillRule:"nonzero"}),(0,l.jsx)("path",{d:"m17 5h3l-5-5v3c0 1.10457.8954 2 2 2z",fill:"#9e8cfc",fillRule:"nonzero"}),(0,l.jsx)("path",{d:"m8.0869 10.6818.5758-2.3031c.0556-.2226.2556-.3787.485-.3787.3253 0 .564.3057.4851.6213l-.5151 2.0605h2.6055l.5758-2.3031c.0557-.2226.2557-.3787.4851-.3787.3253 0 .564.3057.4851.6213l-.5152 2.0605h2.246c.2761 0 .5.2239.5.5 0 .2762-.2239.5-.5.5h-2.496l-.6591 2.6364h2.1551c.2761 0 .5.2238.5.5 0 .2761-.2239.5-.5.5h-2.4051l-.5757 2.3031c-.0557.2226-.2557.3787-.4851.3787-.3253 0-.564-.3057-.4851-.6213l.5152-2.0605h-2.6056l-.5758 2.3031c-.0556.2226-.2556.3787-.4851.3787-.3253 0-.5639-.3057-.485-.6213l.5151-2.0605h-1.9278c-.2761 0-.5-.2239-.5-.5 0-.2762.2239-.5.5-.5h2.1778l.6591-2.6364h-1.8369c-.2761 0-.5-.2238-.5-.5 0-.2761.2239-.5.5-.5zm2.7273 3.6364.659-2.6364h-2.6055l-.6591 2.6364z",fill:"#fff"})]});var D=n(60867),P=n(50477),W=n(94840),A=n(16442);let $=e=>{let{format:t,isCreatingCustomType:n,openCreateCustomTypeModal:a}=e,s=(0,h.useRouter)(),{customTypes:i,updateCustomTypes:o}=(0,P.xU)(t),u=i.sort((e,t)=>e.id.localeCompare(t.id)),m=v.cd[t],p=d.$[t];return(!function(e,t,n){let{storeCustomTypes:l}=(0,x.v9)(e=>({storeCustomTypes:(0,w.Ch)(e).filter(A.TG)}));(0,c.useEffect)(()=>{let r=l.filter(e=>{let{local:n}=e;return n.format===t});(r.length!==e.length||r.some(t=>{let n=e.find(e=>e.id===t.local.id);return!n||JSON.stringify(W.Dc.fromSM(t.local))!==JSON.stringify(n)}))&&n(r.map(e=>{let{local:t}=e;return W.Dc.fromSM(t)}))},[t,n,e,l])}(i,t,o),0===u.length)?(0,l.jsxs)(E.R$,{"data-testid":"blank-slate",style:{alignSelf:"center",marginTop:r.t.space[72]},children:[(0,l.jsx)(E.u2,{children:(0,l.jsx)(r.a_,{src:m.blankSlateImage,sizing:"cover"})}),(0,l.jsxs)(E.T9,{children:[(0,l.jsx)(E._T,{children:p.name({start:!0,plural:!0})}),(0,l.jsx)(E.nf,{children:p.blankSlateDescription}),(0,l.jsx)(E.Qj,{children:(0,l.jsx)(r.E,{onClick:a,loading:n,children:"Create"})})]})]}):(0,l.jsx)("div",{children:(0,l.jsxs)(r.bE,{columnLayout:"28px 1fr 1fr 1fr 42px",children:[(0,l.jsx)(r.bH,{children:(0,l.jsxs)(r.bI,{children:[(0,l.jsx)(r.bG,{children:(0,l.jsx)(r.aX,{name:"notes",size:"medium"})}),(0,l.jsx)(r.bG,{children:(0,l.jsx)(r.bL,{color:"grey11",variant:"small",children:"Label"})}),(0,l.jsx)(r.bG,{children:(0,l.jsx)(r.bL,{color:"grey11",variant:"small",children:"API ID"})}),(0,l.jsx)(r.bG,{children:(0,l.jsx)(r.bL,{color:"grey11",variant:"small",children:"Limit"})}),(0,l.jsx)(r.bG,{})]})}),(0,l.jsx)(r.bF,{children:u.map(e=>{let{repeatable:n,label:a,id:c}=e;return(0,l.jsxs)(r.bI,{onClick:()=>{s.push(v.cd[t].getBuilderPagePathname(c))},children:[(0,l.jsx)(r.bG,{children:n?(0,l.jsx)(T,{width:r.t.space[20]}):(0,l.jsx)(G,{width:r.t.space[20]})}),(0,l.jsx)(r.bG,{children:(0,l.jsx)(r.bL,{variant:"bold",noWrap:!0,children:a})}),(0,l.jsx)(r.bG,{children:(0,l.jsx)(r.bL,{color:"grey11",noWrap:!0,children:c})}),(0,l.jsx)(r.bG,{children:(0,l.jsx)(r.bL,{color:"grey11",noWrap:!0,children:n?"Reusable":"Single"})}),(0,l.jsx)(r.bG,{children:(0,l.jsx)(D._,{isChangesLocal:!1,format:t,customType:e})})]},c)})})]})})},O=e=>{let{format:t}=e,n=d.$[t],[a,h]=(0,c.useState)(!1),[x,m]=(0,c.useState)(!1);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(s(),{children:(0,l.jsxs)("title",{children:[n.name({start:!0,plural:!0})," - Slice Machine"]})}),(0,l.jsx)(o.S,{renderError:()=>(0,l.jsx)(u.LN,{children:(0,l.jsx)(u.RN,{children:(0,l.jsx)(r.D,{alignItems:"center",justifyContent:"center",children:(0,l.jsx)(r.ax,{title:"Request failed",description:"An error occurred while fetching your ".concat(n.name({start:!1,plural:!0}),".")})})})}),children:(0,l.jsx)(c.Suspense,{fallback:(0,l.jsxs)(u.LN,{children:[(0,l.jsxs)(u.wd,{children:[(0,l.jsx)(u.Cx,{children:(0,l.jsx)(i.g,{children:n.name({start:!0,plural:!0})})}),(0,l.jsx)(u.K2,{children:(0,l.jsx)(r.E,{disabled:!0,startIcon:"add",children:"Create"})})]}),(0,l.jsx)(u.RN,{children:(0,l.jsx)(r.bg,{})})]}),children:(0,l.jsxs)(u.LN,{children:[(0,l.jsxs)(u.wd,{children:[(0,l.jsx)(u.Cx,{children:(0,l.jsx)(i.g,{children:n.name({start:!0,plural:!0})})}),(0,l.jsx)(u.K2,{children:(0,l.jsx)(r.E,{"data-testid":"create-ct",loading:a,onClick:()=>{m(!0)},startIcon:"add",children:"Create"})})]}),(0,l.jsx)(u.RN,{children:(0,l.jsxs)(r.D,{flexDirection:"column",children:[(0,l.jsx)($,{format:t,isCreatingCustomType:a,openCreateCustomTypeModal:()=>{m(!0)}}),(0,l.jsx)(z,{format:t,isCreating:a,isOpen:x,onCreateChange:h,onOpenChange:m})]})})]})})})]})}},30527:function(e,t,n){"use strict";n.d(t,{Z:function(){return o},W:function(){return i}});var l=n(52322),r=n(2784),a=n(75289);let s=e=>{let{bg:t,background:n,sx:r,withRadius:s,radius:c,children:i}=e;return(0,l.jsx)(a.xu,{sx:{p:4,bg:t||n,...s?{borderBottomLeftRadius:c,borderBottomRightRadius:c}:null,...r},children:i})},c=(0,r.createContext)("6px"),i=()=>(0,r.useContext)(c),o=e=>{let{Header:t=null,SubHeader:n=null,Body:r=null,Footer:i=null,borderFooter:o=!1,radius:d="6px",bodySx:u={},footerSx:h={},sx:x=null,bg:m,background:p,children:j,...g}=e;return(0,l.jsx)(c.Provider,{value:d,children:(0,l.jsxs)(a.Zb,{sx:{border:e=>{var t;return"1px solid ".concat(String(null===(t=e.colors)||void 0===t?void 0:t.borders))},borderRadius:d,...x},...g,children:[t||null,n||null,(0,l.jsxs)(s,{bg:m,background:p,sx:u,withRadius:!i,children:[r?(0,l.jsx)(r,{}):null,j||null]}),i?(0,l.jsx)(s,{bg:m,background:p,sx:{...o?{borderTop:e=>{let{colors:t}=e;return"1px solid ".concat(String(null==t?void 0:t.borders))}}:null,...h},radius:d,withRadius:!0,children:"object"==typeof i?i:(0,l.jsx)(i,{})}):null]})})}},7974:function(e,t,n){"use strict";n.d(t,{Sn:function(){return c},lS:function(){return l},nG:function(){return r},pq:function(){return i},rd:function(){return s},xo:function(){return a}});let l=["components","update","insert"],r=["png","jpg","jpeg"],a=/^[A-Za-z0-9]+(?:_[A-Za-z0-9]+)*$/,s="placeholders/What_are_Slices_mrvome",c="SM_HELP_VIDEOS/mock_data",i="slice-machine-simulator"},83478:function(e){e.exports={column:"BlankSlate_column__genEe",root:"BlankSlate_root__CmSqW BlankSlate_column__genEe",fadeIn:"BlankSlate_fadeIn__mAfi5",withBackground:"BlankSlate_withBackground__mLYij",image:"BlankSlate_image__Jn90S BlankSlate_column__genEe",content:"BlankSlate_content__0Yt2d BlankSlate_column__genEe",desc:"BlankSlate_desc___Dl7e",actions:"BlankSlate_actions__OYRj4"}}}]);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[268],{22654:function(e,t,a){a.d(t,{l:function(){return n}});var r=a(96317);function n(){let e=(0,r.L)("slicemachine-image-to-slice");return{eligible:(null==e?void 0:e.value)==="on"}}},91589:function(e,t,a){a.d(t,{S:function(){return x}});var r=a(52322),n=a(56803),i=a(2784),l=a(88932),s=a(94160),c=a(34166),o=a(63470),u=a(98250),d=a(68968),m=a(80148),g=a(54597),p=a(31860),h=a(62434);function f(e){let{slice:t}=e,a="uploading"===t.status||"generating"===t.status,i="uploadError"===t.status||"generateError"===t.status,l="generateError"===t.status||"generating"===t.status||"success"===t.status;return(0,r.jsxs)(h.Zb,{disabled:a,children:[l?(0,r.jsx)(h.ZB,{src:t.thumbnailUrl}):(0,r.jsx)(h.ZB,{component:"div"}),(0,r.jsx)(h.eW,{loading:a,startIcon:function(e){switch(e){case"uploadError":case"generateError":return"close";case"success":return"check";default:return}}(t.status),title:"success"===t.status?t.model.name:t.image.name,subtitle:function(e){switch(e){case"uploading":return"Uploading...";case"uploadError":return"Unable to upload image";case"generating":return"Generating...";case"generateError":return"Something went wrong";case"success":return"Generated"}}(t.status),error:i,action:i?(0,r.jsx)(n.E,{startIcon:"refresh",color:"grey",onClick:t.onRetry,children:"Retry"}):void 0})]})}function x(e){let{open:t,location:a,onSuccess:h,onClose:x}=e,[S,b]=(0,i.useState)([]),[C,I]=(0,i.useState)(!1),{syncChanges:k}=(0,d.g)(),{createSliceSuccess:A}=(0,g.Z)(),{completeStep:E}=(0,u.k)(),U=(0,o.k)(),L=(0,i.useRef)(crypto.randomUUID()),N=e=>{let{index:t,slice:a}=e;b(e=>e.map((e,r)=>r===t?a(e):e))},D=e=>{if(e.length>10){l.Am.error("You can only upload ".concat(10," images at a time."));return}b(e.map(e=>({status:"uploading",image:e}))),e.forEach((e,t)=>B({index:t,image:e}))},B=e=>{let{index:t,image:a}=e,r=L.current;N({index:t,slice:e=>({...e,status:"uploading"})}),j({image:a}).then(e=>{r===L.current&&F({index:t,imageUrl:e})},()=>{r===L.current&&N({index:t,slice:e=>({...e,status:"uploadError",onRetry:()=>B({index:t,image:a})})})})},_=function(e){let{open:t}=e,a=(0,i.useRef)([]);return(0,i.useEffect)(()=>{t&&(a.current=[],m.managerClient.slices.readAllSlices().then(e=>{a.current=e.models.map(e=>{let{model:t}=e;return t})}).catch(()=>null))},[t]),a}({open:t}),F=e=>{let{index:t,imageUrl:a}=e,r=L.current;N({index:t,slice:e=>({...e,status:"generating",thumbnailUrl:a})}),m.managerClient.customTypes.inferSlice({imageUrl:a}).then(e=>{let{slice:n,langSmithUrl:i}=e;r===L.current&&b(e=>e.map((r,l)=>l===t?{...r,status:"success",thumbnailUrl:a,model:function(e){let{existingSlices:t,newSlices:a,slice:r}=e,n=new Set,i=new Set;for(let{id:e,name:a}of t)n.add(e),i.add(a.toLowerCase());for(let e of a)"success"===e.status&&(n.add(e.model.id),i.add(e.model.name.toLowerCase()));let l=r.id,s=2;for(;n.has(l);)l="".concat(r.id,"_").concat(s),s++;let c=r.name;for(s=2;i.has(c.toLowerCase());)c="".concat(r.name).concat(s),s++;return{...r,id:l,name:c}}({existingSlices:_.current,newSlices:e,slice:n}),langSmithUrl:i}:r))},()=>{r===L.current&&N({index:t,slice:e=>({...e,status:"generateError",thumbnailUrl:a,onRetry:()=>F({index:t,imageUrl:a})})})})},z=S.some(e=>"uploading"===e.status||"generating"===e.status),R=S.filter(e=>"success"===e.status),Z=R.length>0;return(0,r.jsxs)(n.ae,{open:t,onOpenChange:e=>{e||C||(x(),L.current=crypto.randomUUID(),b([]))},children:[(0,r.jsx)(n.al,{title:"Generate from image"}),(0,r.jsxs)(n.aj,{gap:0,children:[(0,r.jsxs)(n.ak,{hidden:!0,children:["Upload images to generate ",(0,p._)(U.value)," ","with AI"]}),0===S.length?(0,r.jsx)(n.D,{padding:16,height:"100%",children:(0,r.jsx)(n.aF,{onFilesSelected:D,assetType:"image",maxFiles:10,overlay:(0,r.jsx)(y,{onFilesSelected:D,droppingFiles:!0}),children:(0,r.jsx)(y,{onFilesSelected:D})})}):(0,r.jsx)(n.bn,{stableScrollbar:!1,children:(0,r.jsx)(n.D,{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16,padding:16,children:S.map((e,t)=>(0,r.jsx)(f,{slice:e},"slice-".concat(t)))})}),(0,r.jsxs)(n.ah,{children:[(0,r.jsx)(n.ai,{disabled:C}),(0,r.jsxs)(n.af,{disabled:!Z||z,loading:C,onClick:()=>{let e=S.reduce((e,t)=>("success"===t.status&&e.push(t),e),[]);if(!e.length)return;let t=L.current;I(!0),v(e).then(async e=>{let{slices:r,library:n}=e;if(t===L.current)for(let{model:e,langSmithUrl:t}of(A((await (0,s.y0)()).libraries),k(),h({slices:r,library:n}),I(!1),L.current=crypto.randomUUID(),b([]),E("createSlice"),r))s.Xe.track({event:"slice:created",id:e.id,name:e.name,library:n,location:a,mode:"ai",langSmithUrl:t}),(0,c.nZ)({type:"model",library:n,sliceId:e.id,variationId:e.variations[0].id,langSmithUrl:t})}).catch(()=>{t===L.current&&(I(!1),l.Am.error("An unexpected error happened while adding slices."))})},children:[w({location:a,sectionsNamingExperiment:U})," (",R.length,")"]})]})]})]})}function y(e){let t=(0,o.k)(),{droppingFiles:a=!1,onFilesSelected:i}=e;return(0,r.jsx)(n.D,{justifyContent:"center",flexDirection:"column",height:"100%",backgroundColor:a?"purple2":"grey2",border:!0,borderStyle:"dashed",borderColor:a?"purple9":"grey6",children:(0,r.jsxs)(n.s,{children:[(0,r.jsx)(n.x,{lineColor:"purple11",backgroundColor:"purple5",name:"cloudUpload",size:"large"}),(0,r.jsx)(n.z,{children:"Upload your design images."}),(0,r.jsxs)(n.w,{children:["Once uploaded, you can generate"," ",(0,p._)(t.value)," automatically using AI."]}),(0,r.jsx)(n.v,{children:(0,r.jsx)(n.aG,{startIcon:"attachFile",onFilesSelected:i,color:"grey",children:"Add images"})})]})})}async function j(e){let{image:t}=e,a=[await m.managerClient.project.getResolvedRepositoryName(),"shared-slices","prismic-inferred-slices",crypto.randomUUID()].join("/");await m.managerClient.screenshots.initS3ACL();let{url:r}=await m.managerClient.screenshots.uploadScreenshot({keyPrefix:a,data:t});return r}async function v(e){let{libraries:t=[]}=await m.managerClient.project.getSliceMachineConfig(),a=t[0];if(!a)throw Error("No library found in the config.");for(let{model:t}of e){let{errors:e}=await m.managerClient.slices.createSlice({libraryID:a,model:t});if(e.length)throw Error("Failed to create slice ".concat(t.id,"."))}let r=await Promise.all(e.map(async e=>{let{model:t,image:r,langSmithUrl:n}=e;return await m.managerClient.slices.updateSliceScreenshot({libraryID:a,sliceID:t.id,variationID:t.variations[0].id,data:r}),{model:t,langSmithUrl:n}}));return{library:a,slices:r}}let w=e=>{let{location:t,sectionsNamingExperiment:a}=e;switch(t){case"custom_type":return"Add to type";case"page_type":return"Add to page";case"slices":return"Add to ".concat((0,p._)(a.value))}}},27213:function(e,t,a){a.d(t,{F:function(){return l}});var r=a(52322),n=a(56803),i=a(31860);let l=e=>{let{menuType:t,sectionsNamingExperiment:a}=e;return{fromImage:{BackgroundIcon:(0,r.jsx)(n.B,{name:"autoFixHigh",size:"ActionList"===t?"small":"extraSmall",iconSize:"ActionList"===t?"medium":"small",color:"purple",variant:"solid",radius:6}),title:"Generate from image",description:"Build a ".concat(a.value," based on your design image.")},fromScratch:{BackgroundIcon:(0,r.jsx)(n.B,{name:"add",size:"ActionList"===t?"small":"extraSmall",iconSize:"ActionList"===t?"medium":"small",color:"white",variant:"solid",radius:6}),title:"Start from scratch",description:"Build a custom ".concat(a.value," your way.")},fromTemplate:{BackgroundIcon:(0,r.jsx)(n.B,{name:"contentCopy",size:"ActionList"===t?"small":"extraSmall",iconSize:"ActionList"===t?"medium":"small",color:"white",variant:"solid",radius:6}),title:"Use a template",description:"Choose from ready-made examples."},fromExisting:{BackgroundIcon:(0,r.jsx)(n.B,{name:"folder",size:"ActionList"===t?"small":"extraSmall",iconSize:"ActionList"===t?"medium":"small",color:"white",variant:"solid",radius:6}),title:"Reuse an existing ".concat(a.value),description:"Select from your created ".concat((0,i._)(a.value))}}}},6256:function(e,t,a){a.d(t,{c:function(){return w}});var r=a(52322),n=a(2784),i=a(36131),l=a(75289),s=a(94160),c=a(63470),o=a(98250),u=a(88932),d=a(63908),m=a(358),g=a(80148);async function p(e){let{sliceName:t,libraryName:a,location:r,onSuccess:n}=e;try{let e=(0,d.fo)(t),{errors:i}=await g.managerClient.slices.createSlice({libraryID:a,model:e});if(i.length>0)throw i;s.Xe.track({event:"slice:created",id:(0,m.MP)(t),name:t,library:a,location:r,mode:"manual"}),await n(e)}catch(a){let e="An unexpected error happened while creating slice ".concat(t,".");console.error(e,a),u.Am.error(e)}}var h=a(68968),f=a(59532),x=a(54597),y=a(31860),j=a(46999),v=a(63019);let w=e=>{let{onClose:t,onSuccess:a,localLibraries:u,location:d,remoteSlices:m}=e,{createSliceSuccess:g}=(0,x.Z)(),[w,S]=(0,n.useState)(!1),{syncChanges:b}=(0,h.g)(),{completeStep:C}=(0,o.k)(),I=(0,c.k)(),k=async e=>{let t=e.sliceName,r=e.from;S(!0),await p({sliceName:t,libraryName:r,location:d,onSuccess:async e=>{g((await (0,s.y0)()).libraries),a(e,r),b(),C("createSlice")}})};return(0,r.jsx)(f.Z,{testId:"create-slice-modal",isOpen:!0,widthInPx:"530px",isLoading:w,formId:"create-new-slice",close:t,buttonLabel:"Create",onSubmit:e=>{k(e)},initialValues:{sliceName:"",from:u[0].name},validate:e=>(0,v.h)(e,u,m),content:{title:"Create a new ".concat(I.value)},children:e=>{let{touched:t,values:a,setFieldValue:n,errors:s}=e;return(0,r.jsxs)(l.xu,{children:[(0,r.jsx)(j.W,{name:"sliceName",label:"".concat((0,y.f)(I.value)," name"),placeholder:"Pascalised ".concat(I.value," API ID (e.g. TextBlock)"),error:t.sliceName?s.sliceName:void 0,testId:"slice-name-input"}),(0,r.jsx)(l.__,{htmlFor:"from",sx:{mb:2},children:"Target Library"}),(0,r.jsx)(i.ZP,{name:"from",options:u.map(e=>({value:e.name,label:e.name})),onChange:e=>e?void n("from",e.value):null,defaultValue:{value:a.from,label:a.from},styles:{option:e=>({...e,color:"#161618"})},theme:e=>({...e,colors:{...e.colors,primary:"#E9E8EA"}}),menuPortalTarget:document.body})]})}})}},63019:function(e,t,a){a.d(t,{h:function(){return c}});var r=a(96009),n=a.n(r),i=a(74600),l=a.n(i),s=a(7974);function c(e,t,a){let{sliceName:r}=e;return r?s.lS.includes(r.toLowerCase())?{sliceName:'Name "'.concat(r,'" is reserved for Slice Machine use.')}:s.xo.exec(r)?l()(n()(r)).replace(/\s/gm,"")!==r.trim()?{sliceName:"Value has to be PascalCased."}:r.match(/^\d/)?{sliceName:"Value cannot start with a number."}:[...t.flatMap(e=>e.components.map(e=>e.model.name)),...a.map(e=>e.name)].includes(r)?{sliceName:"Slice name is already taken."}:void 0:{sliceName:"No special characters allowed."}:{sliceName:"Cannot be empty"}}},21151:function(e,t,a){var r=a(52322),n=a(75289);t.Z=function(e){let{elems:t,renderElem:a,defineElementKey:i,gridTemplateMinPx:l="320px",gridGap:s="16px",sx:c}=e;return(0,r.jsx)(n.xu,{as:"section",sx:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(".concat(l,", 1fr))"),gridGap:s,pt:2,...c},children:t.map((e,t)=>e?(0,r.jsx)("span",{children:a(e,t)},"".concat(i(e),"-").concat(t+1)):null)})}}}]);
|