@canva/cli 1.10.0 → 1.11.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 +13 -0
- package/cli.js +472 -463
- package/lib/cjs/index.cjs +2 -2
- package/lib/esm/index.mjs +2 -2
- package/lib/index.d.ts +2 -0
- package/package.json +1 -1
- package/templates/base/package.json +3 -2
- package/templates/base/styles/components.css +18 -0
- package/templates/common/.env.template +1 -1
- package/templates/dam/canva-app.json +5 -0
- package/templates/dam/package.json +4 -2
- package/templates/dam/src/index.tsx +3 -21
- package/templates/dam/src/intents/design_editor/index.tsx +25 -0
- package/templates/data_connector/package.json +3 -2
- 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/canva-app.json +5 -0
- package/templates/gen_ai/package.json +4 -2
- 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 +4 -2
- 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/optional/AGENTS.md +80 -2
- package/templates/optional/CLAUDE.md +80 -2
- package/templates/base/utils/use_add_element.ts +0 -58
- package/templates/base/utils/use_feature_support.ts +0 -28
- 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/hello_world/utils/use_add_element.ts +0 -58
- package/templates/hello_world/utils/use_feature_support.ts +0 -28
- /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/hello_world/src/{tests → intents/design_editor/tests}/__snapshots__/app.tests.tsx.snap +0 -0
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { selection as designSelection } from "@canva/design";
|
|
2
|
-
import type { SelectionEvent, SelectionScope } from "@canva/design";
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Returns a selection event, representing a user selection of the specified content type. The
|
|
7
|
-
* event contains methods to read a snapshot of the selected content, and optionally mutate it.
|
|
8
|
-
* This is a reactive value. Calling this multiple times will return different instances
|
|
9
|
-
* representing the same selection.
|
|
10
|
-
* @param scope The type of content to listen for selection changes on
|
|
11
|
-
*/
|
|
12
|
-
export function useSelection<S extends SelectionScope>(
|
|
13
|
-
scope: S,
|
|
14
|
-
): SelectionEvent<S> {
|
|
15
|
-
const [selection, setSelection] = useState<SelectionEvent<S>>({
|
|
16
|
-
scope,
|
|
17
|
-
count: 0,
|
|
18
|
-
read() {
|
|
19
|
-
return Promise.resolve({
|
|
20
|
-
contents: Object.freeze([]),
|
|
21
|
-
save() {
|
|
22
|
-
return Promise.resolve();
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
const disposer = designSelection.registerOnChange({
|
|
30
|
-
scope,
|
|
31
|
-
onChange: setSelection,
|
|
32
|
-
});
|
|
33
|
-
return disposer;
|
|
34
|
-
}, [scope]);
|
|
35
|
-
|
|
36
|
-
return selection;
|
|
37
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
EmbedElement,
|
|
3
|
-
ImageElement,
|
|
4
|
-
RichtextElement,
|
|
5
|
-
TableElement,
|
|
6
|
-
TextElement,
|
|
7
|
-
VideoElement,
|
|
8
|
-
} from "@canva/design";
|
|
9
|
-
import { addElementAtCursor, addElementAtPoint } from "@canva/design";
|
|
10
|
-
import { features } from "@canva/platform";
|
|
11
|
-
import { useEffect, useState } from "react";
|
|
12
|
-
import { useFeatureSupport } from "./use_feature_support";
|
|
13
|
-
|
|
14
|
-
type AddElementParams =
|
|
15
|
-
| ImageElement
|
|
16
|
-
| VideoElement
|
|
17
|
-
| EmbedElement
|
|
18
|
-
| TextElement
|
|
19
|
-
| RichtextElement
|
|
20
|
-
| TableElement;
|
|
21
|
-
|
|
22
|
-
export const useAddElement = () => {
|
|
23
|
-
const isSupported = useFeatureSupport();
|
|
24
|
-
|
|
25
|
-
// Store a wrapped addElement function that checks feature support
|
|
26
|
-
const [addElement, setAddElement] = useState(() => {
|
|
27
|
-
return (element: AddElementParams) => {
|
|
28
|
-
if (features.isSupported(addElementAtPoint)) {
|
|
29
|
-
return addElementAtPoint(element);
|
|
30
|
-
} else if (features.isSupported(addElementAtCursor)) {
|
|
31
|
-
return addElementAtCursor(element);
|
|
32
|
-
}
|
|
33
|
-
// eslint-disable-next-line no-console
|
|
34
|
-
console.warn(
|
|
35
|
-
"Neither addElementAtPoint nor addElementAtCursor are supported",
|
|
36
|
-
);
|
|
37
|
-
return Promise.resolve();
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
const addElement = (element: AddElementParams) => {
|
|
43
|
-
if (isSupported(addElementAtPoint)) {
|
|
44
|
-
return addElementAtPoint(element);
|
|
45
|
-
} else if (isSupported(addElementAtCursor)) {
|
|
46
|
-
return addElementAtCursor(element);
|
|
47
|
-
}
|
|
48
|
-
// eslint-disable-next-line no-console
|
|
49
|
-
console.warn(
|
|
50
|
-
"Neither addElementAtPoint nor addElementAtCursor are supported",
|
|
51
|
-
);
|
|
52
|
-
return Promise.resolve();
|
|
53
|
-
};
|
|
54
|
-
setAddElement(() => addElement);
|
|
55
|
-
}, [isSupported]);
|
|
56
|
-
|
|
57
|
-
return addElement;
|
|
58
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { features } from "@canva/platform";
|
|
2
|
-
import type { Feature } from "@canva/platform";
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* This hook allows re-rendering of a React component whenever
|
|
7
|
-
* the state of feature support changes in Canva.
|
|
8
|
-
*
|
|
9
|
-
* @returns isSupported - callback to inspect a Canva SDK method.
|
|
10
|
-
**/
|
|
11
|
-
export function useFeatureSupport() {
|
|
12
|
-
// Store a wrapped function that checks feature support
|
|
13
|
-
const [isSupported, setIsSupported] = useState(() => {
|
|
14
|
-
return (...args: Feature[]) => features.isSupported(...args);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
// create new function ref when feature support changes to trigger
|
|
19
|
-
// re-render
|
|
20
|
-
return features.registerOnSupportChange(() => {
|
|
21
|
-
setIsSupported(() => {
|
|
22
|
-
return (...args: Feature[]) => features.isSupported(...args);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}, []);
|
|
26
|
-
|
|
27
|
-
return isSupported;
|
|
28
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|