@canva/cli 1.19.0 → 1.20.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 +7 -0
- package/README.md +1 -9
- package/cli.js +408 -409
- package/package.json +1 -2
- package/templates/base/backend/base_backend/create.ts +0 -114
- package/templates/base/backend/database/database.ts +0 -42
- package/templates/base/backend/routers/auth.ts +0 -288
- package/templates/base/declarations/declarations.d.ts +0 -29
- package/templates/base/eslint.config.mjs +0 -14
- package/templates/base/package.json +0 -91
- package/templates/base/scripts/copy_env.ts +0 -13
- package/templates/base/scripts/ssl/ssl.ts +0 -131
- package/templates/base/scripts/start/app_runner.ts +0 -223
- package/templates/base/scripts/start/context.ts +0 -171
- package/templates/base/scripts/start/start.ts +0 -46
- package/templates/base/scripts/start.tests.ts +0 -61
- package/templates/base/styles/components.css +0 -38
- package/templates/base/tsconfig.json +0 -56
- package/templates/base/webpack.config.ts +0 -247
- package/templates/common/.env.template +0 -6
- package/templates/common/.gitignore.template +0 -8
- package/templates/common/.nvmrc +0 -1
- package/templates/common/.prettierrc +0 -21
- package/templates/common/LICENSE.md +0 -48
- package/templates/common/README.md +0 -179
- package/templates/common/jest.config.mjs +0 -35
- package/templates/common/jest.setup.ts +0 -35
- package/templates/content_publisher/README.md +0 -58
- package/templates/content_publisher/canva-app.json +0 -17
- package/templates/content_publisher/declarations/declarations.d.ts +0 -29
- package/templates/content_publisher/eslint.config.mjs +0 -14
- package/templates/content_publisher/package.json +0 -90
- package/templates/content_publisher/scripts/copy_env.ts +0 -13
- package/templates/content_publisher/scripts/ssl/ssl.ts +0 -131
- package/templates/content_publisher/scripts/start/app_runner.ts +0 -223
- package/templates/content_publisher/scripts/start/context.ts +0 -171
- package/templates/content_publisher/scripts/start/start.ts +0 -46
- package/templates/content_publisher/src/index.tsx +0 -4
- package/templates/content_publisher/src/intents/content_publisher/index.tsx +0 -107
- package/templates/content_publisher/src/intents/content_publisher/post_preview.tsx +0 -240
- package/templates/content_publisher/src/intents/content_publisher/preview_ui.tsx +0 -62
- package/templates/content_publisher/src/intents/content_publisher/settings_ui.tsx +0 -81
- package/templates/content_publisher/src/intents/content_publisher/types.ts +0 -29
- package/templates/content_publisher/styles/components.css +0 -38
- package/templates/content_publisher/styles/preview_ui.css +0 -49
- package/templates/content_publisher/tsconfig.json +0 -56
- package/templates/content_publisher/webpack.config.ts +0 -247
- package/templates/dam/backend/routers/dam.ts +0 -108
- package/templates/dam/backend/server.ts +0 -65
- package/templates/dam/canva-app.json +0 -25
- package/templates/dam/declarations/declarations.d.ts +0 -29
- package/templates/dam/eslint.config.mjs +0 -14
- package/templates/dam/package.json +0 -97
- package/templates/dam/scripts/copy_env.ts +0 -13
- package/templates/dam/scripts/ssl/ssl.ts +0 -131
- package/templates/dam/scripts/start/app_runner.ts +0 -223
- package/templates/dam/scripts/start/context.ts +0 -171
- package/templates/dam/scripts/start/start.ts +0 -46
- package/templates/dam/src/index.tsx +0 -4
- package/templates/dam/src/intents/design_editor/adapter.ts +0 -44
- package/templates/dam/src/intents/design_editor/app.tsx +0 -35
- package/templates/dam/src/intents/design_editor/config.ts +0 -220
- package/templates/dam/src/intents/design_editor/index.css +0 -3
- package/templates/dam/src/intents/design_editor/index.tsx +0 -25
- package/templates/dam/tsconfig.json +0 -56
- package/templates/dam/utils/backend/base_backend/create.ts +0 -114
- package/templates/dam/webpack.config.ts +0 -247
- package/templates/data_connector/README.md +0 -84
- package/templates/data_connector/canva-app.json +0 -21
- package/templates/data_connector/declarations/declarations.d.ts +0 -29
- package/templates/data_connector/eslint.config.mjs +0 -14
- package/templates/data_connector/package.json +0 -92
- package/templates/data_connector/scripts/copy_env.ts +0 -13
- package/templates/data_connector/scripts/ssl/ssl.ts +0 -131
- package/templates/data_connector/scripts/start/app_runner.ts +0 -223
- package/templates/data_connector/scripts/start/context.ts +0 -171
- package/templates/data_connector/scripts/start/start.ts +0 -46
- package/templates/data_connector/src/api/connect_client.ts +0 -6
- package/templates/data_connector/src/api/data_source.ts +0 -97
- package/templates/data_connector/src/api/data_sources/designs.tsx +0 -296
- package/templates/data_connector/src/api/data_sources/index.ts +0 -4
- package/templates/data_connector/src/api/data_sources/templates.tsx +0 -328
- package/templates/data_connector/src/api/fetch_data_table.ts +0 -55
- package/templates/data_connector/src/api/index.ts +0 -4
- package/templates/data_connector/src/api/oauth.ts +0 -8
- package/templates/data_connector/src/api/tests/data_source.test.tsx +0 -99
- package/templates/data_connector/src/components/app_error.tsx +0 -15
- package/templates/data_connector/src/components/footer.tsx +0 -26
- package/templates/data_connector/src/components/header.tsx +0 -40
- package/templates/data_connector/src/components/index.ts +0 -3
- package/templates/data_connector/src/components/inputs/messages.tsx +0 -95
- package/templates/data_connector/src/components/inputs/search_filter.tsx +0 -109
- package/templates/data_connector/src/components/inputs/select_field.tsx +0 -26
- package/templates/data_connector/src/context/app_context.tsx +0 -125
- package/templates/data_connector/src/context/index.ts +0 -2
- package/templates/data_connector/src/context/use_app_context.ts +0 -17
- package/templates/data_connector/src/index.tsx +0 -4
- package/templates/data_connector/src/intents/data_connector/app.tsx +0 -20
- package/templates/data_connector/src/intents/data_connector/entrypoint.tsx +0 -70
- package/templates/data_connector/src/intents/data_connector/home.tsx +0 -21
- package/templates/data_connector/src/intents/data_connector/index.tsx +0 -56
- package/templates/data_connector/src/pages/data_source_config.tsx +0 -9
- package/templates/data_connector/src/pages/error.tsx +0 -37
- package/templates/data_connector/src/pages/index.ts +0 -4
- package/templates/data_connector/src/pages/login.tsx +0 -145
- package/templates/data_connector/src/pages/select_source.tsx +0 -24
- package/templates/data_connector/src/routes/index.ts +0 -2
- package/templates/data_connector/src/routes/paths.ts +0 -7
- package/templates/data_connector/src/routes/protected_route.tsx +0 -26
- package/templates/data_connector/src/routes/routes.tsx +0 -42
- package/templates/data_connector/src/utils/data_params.ts +0 -17
- package/templates/data_connector/src/utils/data_table.ts +0 -116
- package/templates/data_connector/src/utils/fetch_result.ts +0 -36
- package/templates/data_connector/src/utils/index.ts +0 -2
- package/templates/data_connector/src/utils/tests/data_table.test.ts +0 -133
- package/templates/data_connector/styles/components.css +0 -38
- package/templates/data_connector/tsconfig.json +0 -56
- package/templates/data_connector/webpack.config.ts +0 -247
- package/templates/gen_ai/README.md +0 -27
- package/templates/gen_ai/backend/routers/image.ts +0 -232
- package/templates/gen_ai/backend/server.ts +0 -65
- package/templates/gen_ai/canva-app.json +0 -25
- package/templates/gen_ai/declarations/declarations.d.ts +0 -29
- package/templates/gen_ai/eslint.config.mjs +0 -14
- package/templates/gen_ai/package.json +0 -101
- package/templates/gen_ai/scripts/copy_env.ts +0 -13
- package/templates/gen_ai/scripts/ssl/ssl.ts +0 -131
- package/templates/gen_ai/scripts/start/app_runner.ts +0 -223
- package/templates/gen_ai/scripts/start/context.ts +0 -171
- package/templates/gen_ai/scripts/start/start.ts +0 -46
- package/templates/gen_ai/src/api/api.ts +0 -194
- package/templates/gen_ai/src/api/index.ts +0 -1
- package/templates/gen_ai/src/components/app_error.tsx +0 -18
- package/templates/gen_ai/src/components/footer.messages.ts +0 -48
- package/templates/gen_ai/src/components/footer.tsx +0 -156
- package/templates/gen_ai/src/components/image_grid.tsx +0 -103
- package/templates/gen_ai/src/components/index.ts +0 -7
- package/templates/gen_ai/src/components/loading_results.tsx +0 -169
- package/templates/gen_ai/src/components/prompt_input.messages.ts +0 -14
- package/templates/gen_ai/src/components/prompt_input.tsx +0 -154
- package/templates/gen_ai/src/components/remaining_credits.tsx +0 -84
- package/templates/gen_ai/src/components/report_box.tsx +0 -54
- package/templates/gen_ai/src/components/tests/remaining_credit.tests.tsx +0 -47
- package/templates/gen_ai/src/config.ts +0 -21
- package/templates/gen_ai/src/context/app_context.tsx +0 -153
- package/templates/gen_ai/src/context/context.messages.ts +0 -30
- package/templates/gen_ai/src/context/index.ts +0 -2
- package/templates/gen_ai/src/context/use_app_context.ts +0 -17
- package/templates/gen_ai/src/index.tsx +0 -4
- package/templates/gen_ai/src/intents/design_editor/app.tsx +0 -19
- package/templates/gen_ai/src/intents/design_editor/home.tsx +0 -13
- package/templates/gen_ai/src/intents/design_editor/index.tsx +0 -17
- package/templates/gen_ai/src/pages/error.tsx +0 -41
- package/templates/gen_ai/src/pages/generate.tsx +0 -9
- package/templates/gen_ai/src/pages/index.ts +0 -3
- package/templates/gen_ai/src/pages/results.tsx +0 -31
- package/templates/gen_ai/src/routes/index.ts +0 -1
- package/templates/gen_ai/src/routes/paths.ts +0 -4
- package/templates/gen_ai/src/routes/routes.tsx +0 -24
- package/templates/gen_ai/src/utils/index.ts +0 -1
- package/templates/gen_ai/src/utils/obscenity_filter.ts +0 -33
- package/templates/gen_ai/styles/components.css +0 -38
- package/templates/gen_ai/styles/utils.css +0 -3
- package/templates/gen_ai/tsconfig.json +0 -56
- package/templates/gen_ai/utils/backend/base_backend/create.ts +0 -114
- package/templates/gen_ai/webpack.config.ts +0 -247
- package/templates/hello_world/canva-app.json +0 -21
- package/templates/hello_world/declarations/declarations.d.ts +0 -29
- package/templates/hello_world/eslint.config.mjs +0 -14
- package/templates/hello_world/package.json +0 -90
- package/templates/hello_world/scripts/copy_env.ts +0 -13
- package/templates/hello_world/scripts/ssl/ssl.ts +0 -131
- package/templates/hello_world/scripts/start/app_runner.ts +0 -223
- package/templates/hello_world/scripts/start/context.ts +0 -171
- package/templates/hello_world/scripts/start/start.ts +0 -46
- package/templates/hello_world/src/index.tsx +0 -4
- package/templates/hello_world/src/intents/design_editor/app.tsx +0 -86
- package/templates/hello_world/src/intents/design_editor/index.tsx +0 -25
- package/templates/hello_world/src/intents/design_editor/tests/__snapshots__/app.tests.tsx.snap +0 -45
- package/templates/hello_world/src/intents/design_editor/tests/app.tests.tsx +0 -92
- package/templates/hello_world/styles/components.css +0 -38
- package/templates/hello_world/tsconfig.json +0 -56
- package/templates/hello_world/webpack.config.ts +0 -247
- package/templates/mls/README.md +0 -81
- package/templates/mls/canva-app.json +0 -25
- package/templates/mls/declarations/declarations.d.ts +0 -29
- package/templates/mls/eslint.config.mjs +0 -14
- package/templates/mls/jest.config.mjs +0 -36
- package/templates/mls/jest.setup.ts +0 -39
- package/templates/mls/package.json +0 -117
- package/templates/mls/scripts/copy_env.ts +0 -13
- package/templates/mls/scripts/ssl/ssl.ts +0 -131
- package/templates/mls/scripts/start/app_runner.ts +0 -223
- package/templates/mls/scripts/start/context.ts +0 -171
- package/templates/mls/scripts/start/start.ts +0 -46
- package/templates/mls/src/__tests__/app.tests.tsx +0 -11
- package/templates/mls/src/__tests__/office_selection_page.tests.tsx +0 -72
- package/templates/mls/src/__tests__/utils.tsx +0 -19
- package/templates/mls/src/adapter.ts +0 -126
- package/templates/mls/src/components/agent/agent_card.tsx +0 -57
- package/templates/mls/src/components/agent/agent_grid.tsx +0 -37
- package/templates/mls/src/components/agent/agent_list.tsx +0 -17
- package/templates/mls/src/components/agent/agent_search_filters.tsx +0 -88
- package/templates/mls/src/components/breadcrumb/breadcrumb.tsx +0 -40
- package/templates/mls/src/components/listing/listing_card.tsx +0 -64
- package/templates/mls/src/components/listing/listing_grid.tsx +0 -37
- package/templates/mls/src/components/listing/listing_list.tsx +0 -21
- package/templates/mls/src/components/listing/listing_search_filters.tsx +0 -145
- package/templates/mls/src/components/placeholders/placeholders.tsx +0 -65
- package/templates/mls/src/data.ts +0 -359
- package/templates/mls/src/index.tsx +0 -4
- package/templates/mls/src/intents/design_editor/app.tsx +0 -44
- package/templates/mls/src/intents/design_editor/index.tsx +0 -25
- package/templates/mls/src/pages/agent_details_page/agent_details_page.tsx +0 -175
- package/templates/mls/src/pages/list_page/agent_tab_panel.tsx +0 -126
- package/templates/mls/src/pages/list_page/list_page.tsx +0 -67
- package/templates/mls/src/pages/list_page/listing_tab_panel.tsx +0 -135
- package/templates/mls/src/pages/listing_details_page/listing_details_page.tsx +0 -418
- package/templates/mls/src/pages/loading_page/loading_page.tsx +0 -152
- package/templates/mls/src/pages/office_selection_page/office_selection_page.tsx +0 -144
- package/templates/mls/src/real_estate.type.ts +0 -44
- package/templates/mls/src/util/use_add_element.tsx +0 -62
- package/templates/mls/src/util/use_drag_element.tsx +0 -68
- package/templates/mls/styles/components.css +0 -38
- package/templates/mls/tsconfig.json +0 -54
- package/templates/mls/webpack.config.ts +0 -248
- package/templates/optional/.cursor/mcp.json +0 -8
- package/templates/optional/.vscode/extensions.json +0 -6
- package/templates/optional/.vscode/mcp.json +0 -9
- package/templates/optional/AGENTS.md +0 -154
- package/templates/optional/CLAUDE.md +0 -154
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
# Canva Apps SDK Starter Kit - Agent Guide
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
This project is for creating Canva Apps, which are react single page applications (SPA) that run in the Canva Editor, and other pages in Canva.
|
|
6
|
-
The app, once submitted to Canva, will be rendered in a sandboxed iframe within a standard HTML shell.
|
|
7
|
-
|
|
8
|
-
## Commands
|
|
9
|
-
|
|
10
|
-
- **Build**:
|
|
11
|
-
- `npm run build` - Production build with localization message extraction. The build output is in the `dist` directory which should be submitted to Canva for review through the [Developer Portal](https://www.canva.com/developers/apps).
|
|
12
|
-
- **Dev**:
|
|
13
|
-
- `npm start` - Start development server (localhost:8080), once the server is running, app can be previewed in Canva, either by clicking the "Preview" button in the [Developer Portal](https://www.canva.com/developers/apps) or by running `canva apps preview` in the CLI.
|
|
14
|
-
- Hot Module Replacement (HMR) is strongly encouraged, as it allows for faster development and debugging.
|
|
15
|
-
- **Test**:
|
|
16
|
-
- `npm test` - Run Jest tests, `npm run test:watch` for watch mode.
|
|
17
|
-
- Tests are encouraged but not required.
|
|
18
|
-
- Tests are not submitted to Canva for review.
|
|
19
|
-
- **Lint**:
|
|
20
|
-
- `npm run lint` - ESLint check, `npm run lint:fix` to auto-fix.
|
|
21
|
-
- Linting is encouraged but not required.
|
|
22
|
-
- Lint errors from `@canva/app-eslint-plugin` help catch common mistakes and improve code quality that would result in a rejection from Canva.
|
|
23
|
-
- **Type Check**:
|
|
24
|
-
- `npm run lint:types` - TypeScript type checking.
|
|
25
|
-
- **Format**:
|
|
26
|
-
- `npm run format` - Prettier formatting, `npm run format:check` to verify.
|
|
27
|
-
- Formatting is encouraged but not required.
|
|
28
|
-
|
|
29
|
-
## Architecture
|
|
30
|
-
|
|
31
|
-
- **Main App**:
|
|
32
|
-
- `src/index.tsx` - Main application React application entry point.
|
|
33
|
-
- `src/intents/[intent]/index.tsx` - Every intent that the app implements should be contained in the intents path.
|
|
34
|
-
- `src/intents/[intent]/app.tsx` - Main application component for each intent, which should be split into smaller components as needed, following React best practices.
|
|
35
|
-
- `src/styles/component.css` - Main application styles.
|
|
36
|
-
- `utils/` - Utility functions and helpers, which can be used across the app.
|
|
37
|
-
- `scripts/` - Scripts for building, and running the app, should not contain any business logic.
|
|
38
|
-
- **Environment**:
|
|
39
|
-
- `.env` file for app credentials and HMR configuration.
|
|
40
|
-
- `CANVA_APP_ID` - The ID of the app, which is used to identify the app in the Canva Developer Portal.
|
|
41
|
-
- `CANVA_APP_ORIGIN` - The origin of the app, which is used for Hot Module Replacement (HMR) and CORS.
|
|
42
|
-
|
|
43
|
-
## Dependencies
|
|
44
|
-
|
|
45
|
-
- **UI Kit**:
|
|
46
|
-
- Uses `@canva/app-ui-kit` for components and styles, as it's required in order to comply with Canva's design guidelines.
|
|
47
|
-
- App UI Kit components come with out of the box theming, localization, and accessibility features.
|
|
48
|
-
- Plain HTML and CSS elements are allowed, however should be used when necessary to supplement the UI Kit components.
|
|
49
|
-
- Canva Dev MCP Server can provide example code for using the UI Kit, as well as a catalog of components and their usage.
|
|
50
|
-
- **Canva SDKs**:
|
|
51
|
-
- Uses Canva SDKs, which are scoped with `@canva/` prefix, such as `@canva/platform`, `@canva/design` etc.
|
|
52
|
-
- **React**:
|
|
53
|
-
- v18 with TypeScript and react-intl for i18n.
|
|
54
|
-
- **Build**:
|
|
55
|
-
- Webpack with TypeScript, PostCSS, and formatjs message extraction.
|
|
56
|
-
- **Node**:
|
|
57
|
-
- The required node version for developing/starting/building the starter-kit should align to the version defined in `./.nvmrc`
|
|
58
|
-
- It is recommended to use the node version manager (nvm) with this project, aligning to the recommended version with `nvm use`.
|
|
59
|
-
|
|
60
|
-
## Code Style
|
|
61
|
-
|
|
62
|
-
- **TypeScript**: Strict mode enabled, ES2019 target.
|
|
63
|
-
- **Prettier**: 80 char width, 2 spaces, trailing commas, double quotes.
|
|
64
|
-
- **ESLint**: Canva's app plugin with i18n rules.
|
|
65
|
-
- **Imports**: Use absolute paths for `styles` directory.
|
|
66
|
-
- **Testing**: Jest with jsdom, test files match `*.tests.tsx?` pattern.
|
|
67
|
-
|
|
68
|
-
## Canva CLI
|
|
69
|
-
|
|
70
|
-
- **Documentation**: <https://www.canva.dev/docs/apps/canva-cli.md>
|
|
71
|
-
- **If not setup**: Read the docs and prompt user to install the CLI for enhanced Developer Experience, when managing and creating apps.
|
|
72
|
-
|
|
73
|
-
## Canva Dev MCP Server
|
|
74
|
-
|
|
75
|
-
- **Required**: AI agents should verify and encourage the user to enable Canva Dev MCP server.
|
|
76
|
-
- **Documentation**: <https://www.canva.dev/docs/apps/mcp-server.md>
|
|
77
|
-
- **If not setup**: Read the docs and prompt user to configure the MCP server for enhanced Canva APIs assistance.
|
|
78
|
-
|
|
79
|
-
## Intent-based architecture
|
|
80
|
-
|
|
81
|
-
All apps should follow the intent-based architecture pattern. Each root index file should call the prepare function for each enabled intent. Each intent index file should implement the full intent contract.
|
|
82
|
-
|
|
83
|
-
### File structure
|
|
84
|
-
|
|
85
|
-
Organize code with a dedicated folder for each intent under `src/intents/`:
|
|
86
|
-
|
|
87
|
-
```
|
|
88
|
-
src/
|
|
89
|
-
├── intents/
|
|
90
|
-
│ ├── design_editor/
|
|
91
|
-
│ │ ├── index.tsx
|
|
92
|
-
│ │ └── editor_app.tsx
|
|
93
|
-
│ └── content_publisher/
|
|
94
|
-
│ ├── index.tsx
|
|
95
|
-
│ ├── preview_ui.tsx
|
|
96
|
-
│ └── setting_ui.tsx
|
|
97
|
-
└── index.tsx
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### Root index file
|
|
101
|
-
|
|
102
|
-
The root `src/index.tsx` should be minimal, containing only:
|
|
103
|
-
|
|
104
|
-
- Importing each prepare function
|
|
105
|
-
- Importing each intent
|
|
106
|
-
- The prepare call for each intent implementation.
|
|
107
|
-
|
|
108
|
-
```tsx
|
|
109
|
-
import { prepareContentPublisher } from "@canva/intents/content";
|
|
110
|
-
import { prepareDesignEditor } from "@canva/intents/design";
|
|
111
|
-
|
|
112
|
-
import contentPublisher from "./intents/content_publisher";
|
|
113
|
-
import designEditor from "./intents/design_editor";
|
|
114
|
-
|
|
115
|
-
prepareContentPublisher(contentPublisher);
|
|
116
|
-
prepareDesignEditor(designEditor);
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### Intent index files
|
|
120
|
-
|
|
121
|
-
Each intent's `index.tsx` file should:
|
|
122
|
-
|
|
123
|
-
- Import dependencies, including the app ui kit css.
|
|
124
|
-
- Implement the full contract for the intent and use this as the default export from the file.
|
|
125
|
-
|
|
126
|
-
```tsx
|
|
127
|
-
// src/intents/design_editor/index.tsx
|
|
128
|
-
import "@canva/app-ui-kit/styles.css";
|
|
129
|
-
import type { DesignEditorIntent } from "@canva/intents/design";
|
|
130
|
-
import { prepareDesignEditor } from "@canva/intents/design";
|
|
131
|
-
import { AppI18nProvider } from "@canva/app-i18n-kit";
|
|
132
|
-
import { AppUiProvider } from "@canva/app-ui-kit";
|
|
133
|
-
import { createRoot } from "react-dom/client";
|
|
134
|
-
import { App } from "./app";
|
|
135
|
-
|
|
136
|
-
async function render() {
|
|
137
|
-
const root = createRoot(document.getElementById("root") as Element);
|
|
138
|
-
|
|
139
|
-
root.render(
|
|
140
|
-
<AppI18nProvider>
|
|
141
|
-
<AppUiProvider>
|
|
142
|
-
<App />
|
|
143
|
-
</AppUiProvider>
|
|
144
|
-
</AppI18nProvider>,
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const designEditor: DesignEditorIntent = { render };
|
|
149
|
-
export default designEditor;
|
|
150
|
-
|
|
151
|
-
if (module.hot) {
|
|
152
|
-
module.hot.accept("./app", render);
|
|
153
|
-
}
|
|
154
|
-
```
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
# Canva Apps SDK Starter Kit - Agent Guide
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
This project is for creating Canva Apps, which are react single page applications (SPA) that run in the Canva Editor, and other pages in Canva.
|
|
6
|
-
The app, once submitted to Canva, will be rendered in a sandboxed iframe within a standard HTML shell.
|
|
7
|
-
|
|
8
|
-
## Commands
|
|
9
|
-
|
|
10
|
-
- **Build**:
|
|
11
|
-
- `npm run build` - Production build with localization message extraction. The build output is in the `dist` directory which should be submitted to Canva for review through the [Developer Portal](https://www.canva.com/developers/apps).
|
|
12
|
-
- **Dev**:
|
|
13
|
-
- `npm start` - Start development server (localhost:8080), once the server is running, app can be previewed in Canva, either by clicking the "Preview" button in the [Developer Portal](https://www.canva.com/developers/apps) or by running `canva apps preview` in the CLI.
|
|
14
|
-
- Hot Module Replacement (HMR) is strongly encouraged, as it allows for faster development and debugging.
|
|
15
|
-
- **Test**:
|
|
16
|
-
- `npm test` - Run Jest tests, `npm run test:watch` for watch mode.
|
|
17
|
-
- Tests are encouraged but not required.
|
|
18
|
-
- Tests are not submitted to Canva for review.
|
|
19
|
-
- **Lint**:
|
|
20
|
-
- `npm run lint` - ESLint check, `npm run lint:fix` to auto-fix.
|
|
21
|
-
- Linting is encouraged but not required.
|
|
22
|
-
- Lint errors from `@canva/app-eslint-plugin` help catch common mistakes and improve code quality that would result in a rejection from Canva.
|
|
23
|
-
- **Type Check**:
|
|
24
|
-
- `npm run lint:types` - TypeScript type checking.
|
|
25
|
-
- **Format**:
|
|
26
|
-
- `npm run format` - Prettier formatting, `npm run format:check` to verify.
|
|
27
|
-
- Formatting is encouraged but not required.
|
|
28
|
-
|
|
29
|
-
## Architecture
|
|
30
|
-
|
|
31
|
-
- **Main App**:
|
|
32
|
-
- `src/index.tsx` - Main application React application entry point.
|
|
33
|
-
- `src/intents/[intent]/index.tsx` - Every intent that the app implements should be contained in the intents path.
|
|
34
|
-
- `src/intents/[intent]/app.tsx` - Main application component for each intent, which should be split into smaller components as needed, following React best practices.
|
|
35
|
-
- `src/styles/component.css` - Main application styles.
|
|
36
|
-
- `utils/` - Utility functions and helpers, which can be used across the app.
|
|
37
|
-
- `scripts/` - Scripts for building, and running the app, should not contain any business logic.
|
|
38
|
-
- **Environment**:
|
|
39
|
-
- `.env` file for app credentials and HMR configuration.
|
|
40
|
-
- `CANVA_APP_ID` - The ID of the app, which is used to identify the app in the Canva Developer Portal.
|
|
41
|
-
- `CANVA_APP_ORIGIN` - The origin of the app, which is used for Hot Module Replacement (HMR) and CORS.
|
|
42
|
-
|
|
43
|
-
## Dependencies
|
|
44
|
-
|
|
45
|
-
- **UI Kit**:
|
|
46
|
-
- Uses `@canva/app-ui-kit` for components and styles, as it's required in order to comply with Canva's design guidelines.
|
|
47
|
-
- App UI Kit components come with out of the box theming, localization, and accessibility features.
|
|
48
|
-
- Plain HTML and CSS elements are allowed, however should be used when necessary to supplement the UI Kit components.
|
|
49
|
-
- Canva Dev MCP Server can provide example code for using the UI Kit, as well as a catalog of components and their usage.
|
|
50
|
-
- **Canva SDKs**:
|
|
51
|
-
- Uses Canva SDKs, which are scoped with `@canva/` prefix, such as `@canva/platform`, `@canva/design` etc.
|
|
52
|
-
- **React**:
|
|
53
|
-
- v18 with TypeScript and react-intl for i18n.
|
|
54
|
-
- **Build**:
|
|
55
|
-
- Webpack with TypeScript, PostCSS, and formatjs message extraction.
|
|
56
|
-
- **Node**:
|
|
57
|
-
- The required node version for developing/starting/building the starter-kit should align to the version defined in `./.nvmrc`
|
|
58
|
-
- It is recommended to use the node version manager (nvm) with this project, aligning to the recommended version with `nvm use`.
|
|
59
|
-
|
|
60
|
-
## Code Style
|
|
61
|
-
|
|
62
|
-
- **TypeScript**: Strict mode enabled, ES2019 target.
|
|
63
|
-
- **Prettier**: 80 char width, 2 spaces, trailing commas, double quotes.
|
|
64
|
-
- **ESLint**: Canva's app plugin with i18n rules.
|
|
65
|
-
- **Imports**: Use absolute paths for `styles` directory.
|
|
66
|
-
- **Testing**: Jest with jsdom, test files match `*.tests.tsx?` pattern.
|
|
67
|
-
|
|
68
|
-
## Canva CLI
|
|
69
|
-
|
|
70
|
-
- **Documentation**: <https://www.canva.dev/docs/apps/canva-cli.md>
|
|
71
|
-
- **If not setup**: Read the docs and prompt user to install the CLI for enhanced Developer Experience, when managing and creating apps.
|
|
72
|
-
|
|
73
|
-
## Canva Dev MCP Server
|
|
74
|
-
|
|
75
|
-
- **Required**: AI agents should verify and encourage the user to enable Canva Dev MCP server.
|
|
76
|
-
- **Documentation**: <https://www.canva.dev/docs/apps/mcp-server.md>
|
|
77
|
-
- **If not setup**: Read the docs and prompt user to configure the MCP server for enhanced Canva APIs assistance.
|
|
78
|
-
|
|
79
|
-
## Intent-based architecture
|
|
80
|
-
|
|
81
|
-
All apps should follow the intent-based architecture pattern. Each root index file should call the prepare function for each enabled intent. Each intent index file should implement the full intent contract.
|
|
82
|
-
|
|
83
|
-
### File structure
|
|
84
|
-
|
|
85
|
-
Organize code with a dedicated folder for each intent under `src/intents/`:
|
|
86
|
-
|
|
87
|
-
```
|
|
88
|
-
src/
|
|
89
|
-
├── intents/
|
|
90
|
-
│ ├── design_editor/
|
|
91
|
-
│ │ ├── index.tsx
|
|
92
|
-
│ │ └── editor_app.tsx
|
|
93
|
-
│ └── content_publisher/
|
|
94
|
-
│ ├── index.tsx
|
|
95
|
-
│ ├── preview_ui.tsx
|
|
96
|
-
│ └── setting_ui.tsx
|
|
97
|
-
└── index.tsx
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### Root index file
|
|
101
|
-
|
|
102
|
-
The root `src/index.tsx` should be minimal, containing only:
|
|
103
|
-
|
|
104
|
-
- Importing each prepare function
|
|
105
|
-
- Importing each intent
|
|
106
|
-
- The prepare call for each intent implementation.
|
|
107
|
-
|
|
108
|
-
```tsx
|
|
109
|
-
import { prepareContentPublisher } from "@canva/intents/content";
|
|
110
|
-
import { prepareDesignEditor } from "@canva/intents/design";
|
|
111
|
-
|
|
112
|
-
import contentPublisher from "./intents/content_publisher";
|
|
113
|
-
import designEditor from "./intents/design_editor";
|
|
114
|
-
|
|
115
|
-
prepareContentPublisher(contentPublisher);
|
|
116
|
-
prepareDesignEditor(designEditor);
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### Intent index files
|
|
120
|
-
|
|
121
|
-
Each intent's `index.tsx` file should:
|
|
122
|
-
|
|
123
|
-
- Import dependencies, including the app ui kit css.
|
|
124
|
-
- Implement the full contract for the intent and use this as the default export from the file.
|
|
125
|
-
|
|
126
|
-
```tsx
|
|
127
|
-
// src/intents/design_editor/index.tsx
|
|
128
|
-
import "@canva/app-ui-kit/styles.css";
|
|
129
|
-
import type { DesignEditorIntent } from "@canva/intents/design";
|
|
130
|
-
import { prepareDesignEditor } from "@canva/intents/design";
|
|
131
|
-
import { AppI18nProvider } from "@canva/app-i18n-kit";
|
|
132
|
-
import { AppUiProvider } from "@canva/app-ui-kit";
|
|
133
|
-
import { createRoot } from "react-dom/client";
|
|
134
|
-
import { App } from "./app";
|
|
135
|
-
|
|
136
|
-
async function render() {
|
|
137
|
-
const root = createRoot(document.getElementById("root") as Element);
|
|
138
|
-
|
|
139
|
-
root.render(
|
|
140
|
-
<AppI18nProvider>
|
|
141
|
-
<AppUiProvider>
|
|
142
|
-
<App />
|
|
143
|
-
</AppUiProvider>
|
|
144
|
-
</AppI18nProvider>,
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const designEditor: DesignEditorIntent = { render };
|
|
149
|
-
export default designEditor;
|
|
150
|
-
|
|
151
|
-
if (module.hot) {
|
|
152
|
-
module.hot.accept("./app", render);
|
|
153
|
-
}
|
|
154
|
-
```
|