@canva/cli 1.10.0 → 1.12.0
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/CHANGELOG.md +37 -0
- package/README.md +2 -0
- package/cli.js +596 -574
- package/lib/cjs/index.cjs +2 -2
- package/lib/esm/index.mjs +2 -2
- package/lib/index.d.ts +2 -0
- package/package.json +7 -2
- package/templates/base/package.json +9 -8
- package/templates/base/styles/components.css +18 -0
- package/templates/common/.env.template +1 -1
- package/templates/common/jest.config.mjs +1 -1
- package/templates/dam/backend/server.ts +8 -0
- package/templates/dam/canva-app.json +9 -0
- package/templates/dam/package.json +10 -8
- package/templates/dam/src/index.tsx +3 -21
- package/templates/dam/src/intents/design_editor/index.tsx +25 -0
- package/templates/data_connector/README.md +1 -1
- package/templates/data_connector/package.json +9 -8
- package/templates/data_connector/src/api/data_sources/designs.tsx +1 -1
- package/templates/data_connector/src/api/data_sources/templates.tsx +1 -1
- package/templates/data_connector/src/components/header.tsx +1 -1
- package/templates/data_connector/src/index.tsx +2 -66
- package/templates/data_connector/src/{app.tsx → intents/data_connector/app.tsx} +3 -3
- package/templates/data_connector/src/{entrypoint.tsx → intents/data_connector/entrypoint.tsx} +5 -5
- package/templates/data_connector/src/{home.tsx → intents/data_connector/home.tsx} +1 -1
- package/templates/data_connector/src/intents/data_connector/index.tsx +56 -0
- package/templates/data_connector/src/pages/error.tsx +1 -1
- package/templates/data_connector/src/pages/login.tsx +1 -1
- package/templates/data_connector/src/routes/protected_route.tsx +1 -1
- package/templates/data_connector/src/routes/routes.tsx +3 -3
- package/templates/data_connector/styles/components.css +18 -0
- package/templates/gen_ai/backend/server.ts +17 -0
- package/templates/gen_ai/canva-app.json +5 -0
- package/templates/gen_ai/package.json +10 -8
- package/templates/gen_ai/src/api/api.ts +4 -0
- package/templates/gen_ai/src/components/footer.tsx +1 -1
- package/templates/gen_ai/src/components/loading_results.tsx +1 -1
- package/templates/gen_ai/src/components/prompt_input.tsx +1 -1
- package/templates/gen_ai/src/index.tsx +3 -14
- package/templates/gen_ai/src/{app.tsx → intents/design_editor/app.tsx} +3 -3
- package/templates/gen_ai/src/{home.tsx → intents/design_editor/home.tsx} +1 -1
- package/templates/gen_ai/src/intents/design_editor/index.tsx +17 -0
- package/templates/gen_ai/src/pages/error.tsx +1 -1
- package/templates/gen_ai/src/routes/routes.tsx +2 -2
- package/templates/gen_ai/styles/components.css +18 -0
- package/templates/hello_world/canva-app.json +5 -0
- package/templates/hello_world/package.json +10 -8
- package/templates/hello_world/src/index.tsx +3 -21
- package/templates/hello_world/src/{app.tsx → intents/design_editor/app.tsx} +26 -3
- package/templates/hello_world/src/intents/design_editor/index.tsx +25 -0
- package/templates/hello_world/src/{tests → intents/design_editor/tests}/app.tests.tsx +19 -13
- package/templates/hello_world/styles/components.css +18 -0
- package/templates/mls/README.md +81 -0
- package/templates/mls/canva-app.json +25 -0
- package/templates/mls/declarations/declarations.d.ts +29 -0
- package/templates/mls/eslint.config.mjs +14 -0
- package/templates/mls/jest.config.mjs +36 -0
- package/templates/mls/jest.setup.ts +37 -0
- package/templates/mls/package.json +117 -0
- package/templates/mls/scripts/copy_env.ts +13 -0
- package/templates/mls/scripts/ssl/ssl.ts +131 -0
- package/templates/mls/scripts/start/app_runner.ts +223 -0
- package/templates/mls/scripts/start/context.ts +171 -0
- package/templates/mls/scripts/start/start.ts +46 -0
- package/templates/mls/src/__tests__/app.tests.tsx +11 -0
- package/templates/mls/src/__tests__/office_selection_page.tests.tsx +72 -0
- package/templates/mls/src/__tests__/utils.tsx +19 -0
- package/templates/mls/src/adapter.ts +126 -0
- package/templates/mls/src/components/agent/agent_card.tsx +57 -0
- package/templates/mls/src/components/agent/agent_grid.tsx +37 -0
- package/templates/mls/src/components/agent/agent_list.tsx +17 -0
- package/templates/mls/src/components/agent/agent_search_filters.tsx +88 -0
- package/templates/mls/src/components/breadcrumb/breadcrumb.tsx +40 -0
- package/templates/mls/src/components/listing/listing_card.tsx +64 -0
- package/templates/mls/src/components/listing/listing_grid.tsx +37 -0
- package/templates/mls/src/components/listing/listing_list.tsx +21 -0
- package/templates/mls/src/components/listing/listing_search_filters.tsx +145 -0
- package/templates/mls/src/components/placeholders/placeholders.tsx +65 -0
- package/templates/mls/src/data.ts +359 -0
- package/templates/mls/src/index.tsx +4 -0
- package/templates/mls/src/intents/design_editor/app.tsx +44 -0
- package/templates/mls/src/intents/design_editor/index.tsx +25 -0
- package/templates/mls/src/pages/agent_details_page/agent_details_page.tsx +175 -0
- package/templates/mls/src/pages/list_page/agent_tab_panel.tsx +126 -0
- package/templates/mls/src/pages/list_page/list_page.tsx +67 -0
- package/templates/mls/src/pages/list_page/listing_tab_panel.tsx +135 -0
- package/templates/mls/src/pages/listing_details_page/listing_details_page.tsx +418 -0
- package/templates/mls/src/pages/loading_page/loading_page.tsx +152 -0
- package/templates/mls/src/pages/office_selection_page/office_selection_page.tsx +144 -0
- package/templates/mls/src/real_estate.type.ts +44 -0
- package/templates/mls/src/util/use_add_element.tsx +62 -0
- package/templates/mls/src/util/use_drag_element.tsx +68 -0
- package/templates/mls/styles/components.css +56 -0
- package/templates/mls/tsconfig.json +55 -0
- package/templates/mls/webpack.config.ts +254 -0
- package/templates/optional/AGENTS.md +80 -2
- package/templates/optional/CLAUDE.md +80 -2
- package/templates/base/backend/routers/oauth.ts +0 -393
- package/templates/base/utils/backend/bearer_middleware/bearer_middleware.ts +0 -99
- package/templates/base/utils/backend/bearer_middleware/index.ts +0 -1
- package/templates/base/utils/backend/bearer_middleware/tests/bearer_middleware.tests.ts +0 -192
- package/templates/base/utils/use_add_element.ts +0 -58
- package/templates/base/utils/use_feature_support.ts +0 -28
- package/templates/common/utils/backend/base_backend/create.ts +0 -104
- package/templates/common/utils/table_wrapper.ts +0 -520
- package/templates/common/utils/use_add_element.ts +0 -58
- package/templates/common/utils/use_feature_support.ts +0 -28
- package/templates/common/utils/use_overlay_hook.ts +0 -76
- package/templates/common/utils/use_selection_hook.ts +0 -37
- package/templates/gen_ai/backend/database/database.ts +0 -42
- package/templates/gen_ai/utils/backend/bearer_middleware/bearer_middleware.ts +0 -99
- package/templates/gen_ai/utils/backend/bearer_middleware/index.ts +0 -1
- package/templates/hello_world/utils/use_add_element.ts +0 -58
- package/templates/hello_world/utils/use_feature_support.ts +0 -28
- /package/templates/base/{utils/backend → backend}/base_backend/create.ts +0 -0
- /package/templates/base/{utils/backend → backend}/jwt_middleware/index.ts +0 -0
- /package/templates/base/{utils/backend → backend}/jwt_middleware/jwt_middleware.ts +0 -0
- /package/templates/dam/src/{adapter.ts → intents/design_editor/adapter.ts} +0 -0
- /package/templates/dam/src/{app.tsx → intents/design_editor/app.tsx} +0 -0
- /package/templates/dam/src/{config.ts → intents/design_editor/config.ts} +0 -0
- /package/templates/dam/src/{index.css → intents/design_editor/index.css} +0 -0
- /package/templates/data_connector/src/{paths.ts → routes/paths.ts} +0 -0
- /package/templates/gen_ai/src/{paths.ts → routes/paths.ts} +0 -0
- /package/templates/{common → gen_ai}/utils/backend/jwt_middleware/index.ts +0 -0
- /package/templates/{common → gen_ai}/utils/backend/jwt_middleware/jwt_middleware.ts +0 -0
- /package/templates/hello_world/src/{tests → intents/design_editor/tests}/__snapshots__/app.tests.tsx.snap +0 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Avatar,
|
|
3
|
+
Box,
|
|
4
|
+
Button,
|
|
5
|
+
FormField,
|
|
6
|
+
Rows,
|
|
7
|
+
Select,
|
|
8
|
+
Text,
|
|
9
|
+
} from "@canva/app-ui-kit";
|
|
10
|
+
import React from "react";
|
|
11
|
+
import { useForm } from "react-hook-form";
|
|
12
|
+
import { useIntl } from "react-intl";
|
|
13
|
+
import { useNavigate } from "react-router-dom";
|
|
14
|
+
import { mockUserData, offices } from "../../data";
|
|
15
|
+
|
|
16
|
+
type FormValues = {
|
|
17
|
+
office: string;
|
|
18
|
+
agent: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const OfficeSelectionPage = () => {
|
|
22
|
+
const navigate = useNavigate();
|
|
23
|
+
const intl = useIntl();
|
|
24
|
+
const {
|
|
25
|
+
handleSubmit,
|
|
26
|
+
setValue,
|
|
27
|
+
watch,
|
|
28
|
+
formState: { touchedFields, isSubmitted },
|
|
29
|
+
} = useForm<FormValues>({
|
|
30
|
+
mode: "onSubmit",
|
|
31
|
+
defaultValues: {
|
|
32
|
+
office: "",
|
|
33
|
+
},
|
|
34
|
+
criteriaMode: "all",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const selectedOffice = watch("office");
|
|
38
|
+
|
|
39
|
+
const onSubmit = (data: FormValues) => {
|
|
40
|
+
const office = offices.find((o) => o.id === data.office);
|
|
41
|
+
if (office) {
|
|
42
|
+
navigate(`/loading`, { state: { office } });
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<Box paddingY="2u" height="full">
|
|
48
|
+
<Box
|
|
49
|
+
height="full"
|
|
50
|
+
display="flex"
|
|
51
|
+
flexDirection="column"
|
|
52
|
+
justifyContent="spaceBetween"
|
|
53
|
+
>
|
|
54
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
|
55
|
+
<Rows spacing="2u">
|
|
56
|
+
<FormField
|
|
57
|
+
label={intl.formatMessage({
|
|
58
|
+
defaultMessage: "Office",
|
|
59
|
+
description: "Label for office selection dropdown",
|
|
60
|
+
})}
|
|
61
|
+
error={
|
|
62
|
+
touchedFields.office &&
|
|
63
|
+
!selectedOffice &&
|
|
64
|
+
intl.formatMessage({
|
|
65
|
+
defaultMessage: "Please select an office",
|
|
66
|
+
description: "Error message when office is not selected",
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
control={(props) => (
|
|
70
|
+
<Select
|
|
71
|
+
{...props}
|
|
72
|
+
stretch
|
|
73
|
+
options={offices.map((office) => ({
|
|
74
|
+
label: office.name,
|
|
75
|
+
value: office.id,
|
|
76
|
+
}))}
|
|
77
|
+
placeholder={intl.formatMessage({
|
|
78
|
+
defaultMessage: "Select office",
|
|
79
|
+
description: "Placeholder text for office selection",
|
|
80
|
+
})}
|
|
81
|
+
onChange={(value) => {
|
|
82
|
+
setValue("office", value, {
|
|
83
|
+
shouldValidate: true,
|
|
84
|
+
});
|
|
85
|
+
}}
|
|
86
|
+
value={selectedOffice}
|
|
87
|
+
/>
|
|
88
|
+
)}
|
|
89
|
+
/>
|
|
90
|
+
<Rows spacing="0.5u">
|
|
91
|
+
<Button
|
|
92
|
+
variant="primary"
|
|
93
|
+
stretch
|
|
94
|
+
type="submit"
|
|
95
|
+
disabled={isSubmitted && !selectedOffice}
|
|
96
|
+
>
|
|
97
|
+
{intl.formatMessage({
|
|
98
|
+
defaultMessage: "Continue",
|
|
99
|
+
description: "Button text to proceed with selection",
|
|
100
|
+
})}
|
|
101
|
+
</Button>
|
|
102
|
+
{isSubmitted && !selectedOffice && (
|
|
103
|
+
<Text variant="regular" tone="critical">
|
|
104
|
+
{intl.formatMessage({
|
|
105
|
+
defaultMessage: "Please select an office and agent",
|
|
106
|
+
description:
|
|
107
|
+
"Text to prompt user to select office and agent",
|
|
108
|
+
})}
|
|
109
|
+
</Text>
|
|
110
|
+
)}
|
|
111
|
+
</Rows>
|
|
112
|
+
</Rows>
|
|
113
|
+
</form>
|
|
114
|
+
|
|
115
|
+
<Box paddingTop="4u">
|
|
116
|
+
<Rows spacing="1u">
|
|
117
|
+
<Text variant="bold">
|
|
118
|
+
{intl.formatMessage({
|
|
119
|
+
defaultMessage: "Account",
|
|
120
|
+
description: "Section header for account information",
|
|
121
|
+
})}
|
|
122
|
+
</Text>
|
|
123
|
+
<Rows spacing="1u" align="start">
|
|
124
|
+
<Box display="flex" alignItems="start">
|
|
125
|
+
<Box paddingEnd="1u">
|
|
126
|
+
<Avatar
|
|
127
|
+
photo={mockUserData.userAvatarUrl}
|
|
128
|
+
name={mockUserData.userName || ""}
|
|
129
|
+
/>
|
|
130
|
+
</Box>
|
|
131
|
+
<Rows spacing="0">
|
|
132
|
+
<Text>{mockUserData.userName}</Text>
|
|
133
|
+
<Text variant="regular" tone="secondary">
|
|
134
|
+
{mockUserData.userEmail}
|
|
135
|
+
</Text>
|
|
136
|
+
</Rows>
|
|
137
|
+
</Box>
|
|
138
|
+
</Rows>
|
|
139
|
+
</Rows>
|
|
140
|
+
</Box>
|
|
141
|
+
</Box>
|
|
142
|
+
</Box>
|
|
143
|
+
);
|
|
144
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface Property {
|
|
2
|
+
id: string;
|
|
3
|
+
thumbnail: {
|
|
4
|
+
url: string;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
};
|
|
8
|
+
url: string;
|
|
9
|
+
title: string;
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
address: string;
|
|
13
|
+
price: string;
|
|
14
|
+
suburb: string;
|
|
15
|
+
listingType: string;
|
|
16
|
+
listing_images?: {
|
|
17
|
+
url: string;
|
|
18
|
+
alt: string;
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
}[];
|
|
22
|
+
agent?: Agent;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface Agent {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
officeId?: string;
|
|
29
|
+
phoneNumber?: string;
|
|
30
|
+
roleTitle?: string;
|
|
31
|
+
headshots?: {
|
|
32
|
+
url: string;
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
}[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface Office {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
address?: string;
|
|
42
|
+
phoneNumber?: string;
|
|
43
|
+
email?: string;
|
|
44
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useFeatureSupport } from "@canva/app-hooks";
|
|
2
|
+
import { type ImageMimeType, upload } from "@canva/asset";
|
|
3
|
+
import { addElementAtCursor, addElementAtPoint } from "@canva/design";
|
|
4
|
+
import type { ImageElement, TextElement } from "@canva/design";
|
|
5
|
+
|
|
6
|
+
const getMimeTypeFromUrl = (url: string): ImageMimeType => {
|
|
7
|
+
const extension = url.split(".").pop()?.toLowerCase();
|
|
8
|
+
switch (extension) {
|
|
9
|
+
case "jpg":
|
|
10
|
+
case "jpeg":
|
|
11
|
+
return "image/jpeg";
|
|
12
|
+
case "png":
|
|
13
|
+
return "image/png";
|
|
14
|
+
case "tiff":
|
|
15
|
+
return "image/tiff";
|
|
16
|
+
default:
|
|
17
|
+
return "image/jpeg"; // fallback to jpeg
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const useAddElement = () => {
|
|
22
|
+
const isSupported = useFeatureSupport();
|
|
23
|
+
const addElement = [addElementAtPoint, addElementAtCursor].find((fn) =>
|
|
24
|
+
isSupported(fn),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const addText = (text?: string) => {
|
|
28
|
+
const textElement: TextElement = {
|
|
29
|
+
type: "text",
|
|
30
|
+
children: [text || ""],
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
addElement?.(textElement);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const addImage = async (imageUrl: string, altText: string) => {
|
|
37
|
+
const mimeType = getMimeTypeFromUrl(imageUrl);
|
|
38
|
+
const image = await upload({
|
|
39
|
+
mimeType,
|
|
40
|
+
thumbnailUrl: imageUrl,
|
|
41
|
+
type: "image",
|
|
42
|
+
url: imageUrl,
|
|
43
|
+
aiDisclosure: "none",
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const imageElement: ImageElement = {
|
|
47
|
+
type: "image",
|
|
48
|
+
altText: {
|
|
49
|
+
text: altText,
|
|
50
|
+
decorative: true,
|
|
51
|
+
},
|
|
52
|
+
ref: image.ref,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
addElement?.(imageElement);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
addText,
|
|
60
|
+
addImage,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useFeatureSupport } from "@canva/app-hooks";
|
|
2
|
+
import { type ImageMimeType, upload } from "@canva/asset";
|
|
3
|
+
import { ui } from "@canva/design";
|
|
4
|
+
import type { DragStartEvent } from "@canva/design";
|
|
5
|
+
import type { DragEvent } from "react";
|
|
6
|
+
|
|
7
|
+
const getMimeTypeFromUrl = (url: string): ImageMimeType => {
|
|
8
|
+
const extension = url.split(".").pop()?.toLowerCase();
|
|
9
|
+
switch (extension) {
|
|
10
|
+
case "jpg":
|
|
11
|
+
case "jpeg":
|
|
12
|
+
return "image/jpeg";
|
|
13
|
+
case "png":
|
|
14
|
+
return "image/png";
|
|
15
|
+
case "tiff":
|
|
16
|
+
return "image/tiff";
|
|
17
|
+
default:
|
|
18
|
+
return "image/jpeg"; // fallback to jpeg
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const useDragElement = () => {
|
|
23
|
+
const isSupported = useFeatureSupport();
|
|
24
|
+
const startDrag = [ui.startDragToPoint].find((fn) => isSupported(fn));
|
|
25
|
+
|
|
26
|
+
const dragText = (event: DragEvent<Element>, text: string) => {
|
|
27
|
+
startDrag?.(event as unknown as DragStartEvent<HTMLElement>, {
|
|
28
|
+
type: "text",
|
|
29
|
+
children: [text],
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const dragImage = (
|
|
34
|
+
event: DragStartEvent<Element>,
|
|
35
|
+
imageUrl: string,
|
|
36
|
+
altText: string,
|
|
37
|
+
width: number,
|
|
38
|
+
height: number,
|
|
39
|
+
) => {
|
|
40
|
+
const mimeType = getMimeTypeFromUrl(imageUrl);
|
|
41
|
+
startDrag?.(event as unknown as DragStartEvent<HTMLElement>, {
|
|
42
|
+
type: "image",
|
|
43
|
+
resolveImageRef: () => {
|
|
44
|
+
return upload({
|
|
45
|
+
mimeType,
|
|
46
|
+
thumbnailUrl: imageUrl,
|
|
47
|
+
type: "image",
|
|
48
|
+
url: imageUrl,
|
|
49
|
+
aiDisclosure: "none",
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
previewUrl: imageUrl,
|
|
53
|
+
previewSize: {
|
|
54
|
+
width,
|
|
55
|
+
height,
|
|
56
|
+
},
|
|
57
|
+
fullSize: {
|
|
58
|
+
width,
|
|
59
|
+
height,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
dragText,
|
|
66
|
+
dragImage,
|
|
67
|
+
};
|
|
68
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* Scroll container */
|
|
2
|
+
.scrollContainer {
|
|
3
|
+
box-sizing: border-box;
|
|
4
|
+
overflow-y: scroll;
|
|
5
|
+
height: 100%;
|
|
6
|
+
padding-top: var(--ui-kit-space-200);
|
|
7
|
+
padding-right: var(--ui-kit-space-200);
|
|
8
|
+
padding-bottom: var(--ui-kit-space-200);
|
|
9
|
+
|
|
10
|
+
/* for firefox */
|
|
11
|
+
scrollbar-width: thin;
|
|
12
|
+
scrollbar-color: var(--ui-kit-color-content-placeholder-fg) transparent;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.scrollContainer::-webkit-scrollbar {
|
|
16
|
+
position: absolute;
|
|
17
|
+
width: var(--ui-kit-base-unit);
|
|
18
|
+
height: 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.scrollContainer::-webkit-scrollbar-track {
|
|
22
|
+
background: transparent;
|
|
23
|
+
width: var(--ui-kit-base-unit);
|
|
24
|
+
margin-top: var(--ui-kit-space-100);
|
|
25
|
+
margin-bottom: var(--ui-kit-space-100);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.scrollContainer::-webkit-scrollbar-thumb {
|
|
29
|
+
border-radius: var(--ui-kit-radius-element-standard);
|
|
30
|
+
background: var(--ui-kit-color-content-placeholder-fg);
|
|
31
|
+
visibility: hidden;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.scrollContainer:hover::-webkit-scrollbar-thumb,
|
|
35
|
+
.scrollContainer:focus::-webkit-scrollbar-thumb,
|
|
36
|
+
.scrollContainer:focus-within::-webkit-scrollbar-thumb {
|
|
37
|
+
visibility: visible;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* Main container for the content publisher preview UI */
|
|
41
|
+
.previewContainer {
|
|
42
|
+
display: flex;
|
|
43
|
+
align-items: center;
|
|
44
|
+
justify-content: center;
|
|
45
|
+
flex-direction: column;
|
|
46
|
+
width: 100%;
|
|
47
|
+
height: 100%;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* Wrapper for the content publisher post preview */
|
|
51
|
+
.previewWrapper {
|
|
52
|
+
display: flex;
|
|
53
|
+
align-items: center;
|
|
54
|
+
justify-content: center;
|
|
55
|
+
width: calc(400px + 32px + 2px); /* Image width + padding + border */
|
|
56
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"jsx": "react-jsx",
|
|
4
|
+
"lib": [
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.iterable",
|
|
7
|
+
"es2018",
|
|
8
|
+
"es2019.array",
|
|
9
|
+
"es2019.object",
|
|
10
|
+
"es2019.string",
|
|
11
|
+
"es2020.promise",
|
|
12
|
+
"es2020.string"
|
|
13
|
+
],
|
|
14
|
+
"types": ["node", "webpack-env", "jest", "@testing-library/jest-dom"],
|
|
15
|
+
"composite": false,
|
|
16
|
+
"declaration": false,
|
|
17
|
+
"declarationMap": false,
|
|
18
|
+
"experimentalDecorators": true,
|
|
19
|
+
"importHelpers": true,
|
|
20
|
+
"noImplicitOverride": true,
|
|
21
|
+
"moduleResolution": "node",
|
|
22
|
+
"rootDir": ".",
|
|
23
|
+
"outDir": "dist",
|
|
24
|
+
"strict": true,
|
|
25
|
+
"skipLibCheck": true,
|
|
26
|
+
"target": "ES2019",
|
|
27
|
+
"sourceMap": true,
|
|
28
|
+
"inlineSources": true,
|
|
29
|
+
"module": "ESNext",
|
|
30
|
+
"noImplicitAny": false,
|
|
31
|
+
"removeComments": true,
|
|
32
|
+
"preserveConstEnums": true,
|
|
33
|
+
"allowSyntheticDefaultImports": true,
|
|
34
|
+
"esModuleInterop": true,
|
|
35
|
+
"baseUrl": "./",
|
|
36
|
+
"paths": {
|
|
37
|
+
"assets": ["./assets"],
|
|
38
|
+
"styles": ["./styles"]
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"include": [
|
|
42
|
+
"./src/**/*",
|
|
43
|
+
"./backend/**/*",
|
|
44
|
+
"./utils/**/*",
|
|
45
|
+
"./scripts/**/*",
|
|
46
|
+
"./declarations/declarations.d.ts",
|
|
47
|
+
"./styles/**/*",
|
|
48
|
+
"./node_modules/@types/**/*"
|
|
49
|
+
],
|
|
50
|
+
"ts-node": {
|
|
51
|
+
"compilerOptions": {
|
|
52
|
+
"module": "commonjs"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import type { Configuration } from "webpack";
|
|
2
|
+
import { DefinePlugin, optimize } from "webpack";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import TerserPlugin from "terser-webpack-plugin";
|
|
5
|
+
import { transform } from "@formatjs/ts-transformer";
|
|
6
|
+
import chalk from "chalk";
|
|
7
|
+
import { config } from "dotenv";
|
|
8
|
+
import { Configuration as DevServerConfiguration } from "webpack-dev-server";
|
|
9
|
+
|
|
10
|
+
config();
|
|
11
|
+
|
|
12
|
+
type DevConfig = {
|
|
13
|
+
port: number;
|
|
14
|
+
enableHmr: boolean;
|
|
15
|
+
enableHttps: boolean;
|
|
16
|
+
appOrigin?: string;
|
|
17
|
+
appId?: string; // Deprecated in favour of appOrigin
|
|
18
|
+
certFile?: string;
|
|
19
|
+
keyFile?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function buildConfig({
|
|
23
|
+
devConfig,
|
|
24
|
+
appEntry = path.join(process.cwd(), "src", "index.tsx"),
|
|
25
|
+
backendHost = process.env.CANVA_BACKEND_HOST,
|
|
26
|
+
// For IN_HARNESS, refer to the following docs for more information: https://www.canva.dev/docs/apps/test-harness/
|
|
27
|
+
inHarness = process.env.IN_HARNESS?.toLowerCase() === "true",
|
|
28
|
+
}: {
|
|
29
|
+
devConfig?: DevConfig;
|
|
30
|
+
appEntry?: string;
|
|
31
|
+
backendHost?: string;
|
|
32
|
+
inHarness?: boolean;
|
|
33
|
+
} = {}): Configuration & DevServerConfiguration {
|
|
34
|
+
const mode = devConfig ? "development" : "production";
|
|
35
|
+
|
|
36
|
+
if (!backendHost) {
|
|
37
|
+
console.error(
|
|
38
|
+
chalk.redBright.bold("BACKEND_HOST is undefined."),
|
|
39
|
+
`Refer to "Customizing the backend host" in the README.md for more information.`,
|
|
40
|
+
);
|
|
41
|
+
process.exit(-1);
|
|
42
|
+
} else if (backendHost.includes("localhost") && mode === "production") {
|
|
43
|
+
console.error(
|
|
44
|
+
chalk.redBright.bold(
|
|
45
|
+
"BACKEND_HOST should not be set to localhost for production builds!",
|
|
46
|
+
),
|
|
47
|
+
`Refer to "Customizing the backend host" in the README.md for more information.`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
mode,
|
|
53
|
+
context: path.resolve(process.cwd(), "./"),
|
|
54
|
+
entry: inHarness
|
|
55
|
+
? {
|
|
56
|
+
harness: path.join(process.cwd(), "harness", "harness.tsx"),
|
|
57
|
+
init: path.join(process.cwd(), "harness", "init.ts"),
|
|
58
|
+
}
|
|
59
|
+
: {
|
|
60
|
+
app: appEntry,
|
|
61
|
+
},
|
|
62
|
+
target: "web",
|
|
63
|
+
resolve: {
|
|
64
|
+
alias: {
|
|
65
|
+
assets: path.resolve(process.cwd(), "assets"),
|
|
66
|
+
utils: path.resolve(process.cwd(), "utils"),
|
|
67
|
+
styles: path.resolve(process.cwd(), "styles"),
|
|
68
|
+
src: path.resolve(process.cwd(), "src"),
|
|
69
|
+
},
|
|
70
|
+
extensions: [".ts", ".tsx", ".js", ".css", ".svg", ".woff", ".woff2"],
|
|
71
|
+
},
|
|
72
|
+
infrastructureLogging: {
|
|
73
|
+
level: inHarness ? "info" : "none",
|
|
74
|
+
},
|
|
75
|
+
module: {
|
|
76
|
+
rules: [
|
|
77
|
+
{
|
|
78
|
+
test: /\.tsx?$/,
|
|
79
|
+
exclude: /node_modules/,
|
|
80
|
+
use: [
|
|
81
|
+
{
|
|
82
|
+
loader: "ts-loader",
|
|
83
|
+
options: {
|
|
84
|
+
transpileOnly: true,
|
|
85
|
+
getCustomTransformers() {
|
|
86
|
+
return {
|
|
87
|
+
before: [
|
|
88
|
+
transform({
|
|
89
|
+
overrideIdFn: "[sha512:contenthash:base64:6]",
|
|
90
|
+
}),
|
|
91
|
+
],
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
test: /\.css$/,
|
|
100
|
+
exclude: /node_modules/,
|
|
101
|
+
use: [
|
|
102
|
+
"style-loader",
|
|
103
|
+
{
|
|
104
|
+
loader: "css-loader",
|
|
105
|
+
options: {
|
|
106
|
+
modules: true,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
loader: "postcss-loader",
|
|
111
|
+
options: {
|
|
112
|
+
postcssOptions: {
|
|
113
|
+
plugins: [require("cssnano")({ preset: "default" })],
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
test: /\.(png|jpg|jpeg)$/i,
|
|
121
|
+
type: "asset/inline",
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
test: /\.(woff|woff2)$/,
|
|
125
|
+
type: "asset/inline",
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
test: /\.svg$/,
|
|
129
|
+
oneOf: [
|
|
130
|
+
{
|
|
131
|
+
issuer: /\.[jt]sx?$/,
|
|
132
|
+
resourceQuery: /react/, // *.svg?react
|
|
133
|
+
use: ["@svgr/webpack", "url-loader"],
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
type: "asset/resource",
|
|
137
|
+
parser: {
|
|
138
|
+
dataUrlCondition: {
|
|
139
|
+
maxSize: 200,
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
test: /\.css$/,
|
|
147
|
+
include: /node_modules/,
|
|
148
|
+
use: [
|
|
149
|
+
"style-loader",
|
|
150
|
+
"css-loader",
|
|
151
|
+
{
|
|
152
|
+
loader: "postcss-loader",
|
|
153
|
+
options: {
|
|
154
|
+
postcssOptions: {
|
|
155
|
+
plugins: [require("cssnano")({ preset: "default" })],
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
optimization: {
|
|
164
|
+
minimizer: [
|
|
165
|
+
new TerserPlugin({
|
|
166
|
+
terserOptions: {
|
|
167
|
+
format: {
|
|
168
|
+
// Turned on because emoji and regex is not minified properly using default
|
|
169
|
+
// https://github.com/facebook/create-react-app/issues/2488
|
|
170
|
+
ascii_only: true,
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
}),
|
|
174
|
+
],
|
|
175
|
+
},
|
|
176
|
+
output: {
|
|
177
|
+
filename: `[name].js`,
|
|
178
|
+
path: path.resolve(process.cwd(), "dist"),
|
|
179
|
+
clean: true,
|
|
180
|
+
},
|
|
181
|
+
plugins: [
|
|
182
|
+
new DefinePlugin({
|
|
183
|
+
BACKEND_HOST: JSON.stringify(backendHost),
|
|
184
|
+
}),
|
|
185
|
+
// Apps can only submit a single JS file via the Developer Portal
|
|
186
|
+
new optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
|
|
187
|
+
].filter(Boolean),
|
|
188
|
+
...buildDevConfig(devConfig),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function buildDevConfig(options?: DevConfig): {
|
|
193
|
+
devtool?: string;
|
|
194
|
+
devServer?: DevServerConfiguration;
|
|
195
|
+
} {
|
|
196
|
+
if (!options) {
|
|
197
|
+
return {};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const { port, enableHmr, appOrigin, appId, enableHttps, certFile, keyFile } =
|
|
201
|
+
options;
|
|
202
|
+
const host = "localhost";
|
|
203
|
+
|
|
204
|
+
let devServer: DevServerConfiguration = {
|
|
205
|
+
server: enableHttps
|
|
206
|
+
? {
|
|
207
|
+
type: "https",
|
|
208
|
+
options: {
|
|
209
|
+
cert: certFile,
|
|
210
|
+
key: keyFile,
|
|
211
|
+
},
|
|
212
|
+
}
|
|
213
|
+
: "http",
|
|
214
|
+
host,
|
|
215
|
+
allowedHosts: [host],
|
|
216
|
+
historyApiFallback: {
|
|
217
|
+
rewrites: [{ from: /^\/$/, to: "/app.js" }],
|
|
218
|
+
},
|
|
219
|
+
port,
|
|
220
|
+
client: {
|
|
221
|
+
logging: "verbose",
|
|
222
|
+
},
|
|
223
|
+
static: {
|
|
224
|
+
directory: path.resolve(process.cwd(), "assets"),
|
|
225
|
+
publicPath: "/assets",
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
if (enableHmr && appOrigin) {
|
|
230
|
+
devServer = {
|
|
231
|
+
...devServer,
|
|
232
|
+
allowedHosts: [host, new URL(appOrigin).hostname],
|
|
233
|
+
headers: {
|
|
234
|
+
"Access-Control-Allow-Origin": appOrigin,
|
|
235
|
+
"Access-Control-Allow-Credentials": "true",
|
|
236
|
+
"Access-Control-Allow-Private-Network": "true",
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
} else {
|
|
240
|
+
if (enableHmr && !appOrigin) {
|
|
241
|
+
console.warn(
|
|
242
|
+
"Attempted to enable Hot Module Replacement (HMR) without configuring App Origin... Disabling HMR.",
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
devServer.webSocketServer = false;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return {
|
|
249
|
+
devtool: "source-map",
|
|
250
|
+
devServer,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export default buildConfig;
|