@edifice.io/react 2.1.1-develop-integration.20250210202453 → 2.1.1-develop-integration.20250213121025

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/dist/editor.js CHANGED
@@ -25,6 +25,7 @@ import { useResizeMedia } from "./modules/editor/hooks/useResizeMedia.js";
25
25
  import { useSpeechRecognition } from "./modules/editor/hooks/useSpeechRecognition.js";
26
26
  import { useSpeechSynthetisis } from "./modules/editor/hooks/useSpeechSynthetisis.js";
27
27
  import { useTipTapEditor } from "./modules/editor/hooks/useTipTapEditor.js";
28
+ import { useCantooEditor } from "./modules/editor/hooks/useCantooEditor.js";
28
29
  export {
29
30
  default5 as AttachmentNodeView,
30
31
  default10 as AttachmentRenderer,
@@ -43,6 +44,7 @@ export {
43
44
  default13 as TableToolbar,
44
45
  default8 as VideoNodeView,
45
46
  useActionOptions,
47
+ useCantooEditor,
46
48
  useCommentEditor,
47
49
  useEditor,
48
50
  useEditorContext,
@@ -1,7 +1,2 @@
1
- interface ModalProps {
2
- isOpen: boolean;
3
- onSuccess?: (formulaEditor: string) => void;
4
- onCancel?: () => void;
5
- }
6
- declare const CantooModal: ({ isOpen, onCancel }: ModalProps) => import('react').ReactPortal;
1
+ declare const CantooModal: () => import("react/jsx-runtime").JSX.Element;
7
2
  export default CantooModal;
@@ -1,27 +1,12 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
2
- import { createPortal } from "react-dom";
3
- import { useTranslation } from "react-i18next";
4
- import Modal from "../../../../components/Modal/Modal.js";
5
- import Button from "../../../../components/Button/Button.js";
1
+ import { jsx } from "react/jsx-runtime";
6
2
  import { useEditorContext } from "../../hooks/useEditorContext.js";
7
- const CantooModal = ({
8
- isOpen,
9
- onCancel
10
- }) => {
3
+ const CantooModal = () => {
11
4
  const {
12
- t
13
- } = useTranslation(), handleOnClose = () => {
14
- onCancel == null || onCancel();
15
- }, {
16
5
  editor
17
6
  } = useEditorContext(), Cantoo = window.Cantoo, editorHTML = editor == null ? void 0 : editor.getHTML(), cantooHTML = Cantoo == null ? void 0 : Cantoo.formatText(editorHTML);
18
- return /* @__PURE__ */ createPortal(/* @__PURE__ */ jsxs(Modal, { id: "CantooModal", isOpen, onModalClose: handleOnClose, children: [
19
- /* @__PURE__ */ jsx(Modal.Header, { onModalClose: handleOnClose, children: t("tiptap.cantoo.formatText") }),
20
- /* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: {
21
- __html: cantooHTML
22
- } }) }),
23
- /* @__PURE__ */ jsx(Modal.Footer, { children: /* @__PURE__ */ jsx(Button, { color: "tertiary", onClick: onCancel, type: "button", variant: "ghost", children: t("tiptap.cantoo.close") }) })
24
- ] }), document.getElementById("portal"));
7
+ return /* @__PURE__ */ jsx("div", { className: "card p-24 mt-8", children: /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: {
8
+ __html: cantooHTML
9
+ } }) });
25
10
  };
26
11
  export {
27
12
  CantooModal as default
@@ -78,7 +78,7 @@ const MathsModal = /* @__PURE__ */ lazy(async () => await import("../MathsModal/
78
78
  editable && /* @__PURE__ */ jsx(MediaLibrary, { appCode, visibility, multiple: !0, ref: mediaLibraryModalRef, ...mediaLibraryModalHandlers }),
79
79
  editable && mathsModalHandlers.isOpen && /* @__PURE__ */ jsx(MathsModal, { ...mathsModalHandlers }),
80
80
  editable && (imageModal == null ? void 0 : imageModal.isOpen) && (imageModal == null ? void 0 : imageModal.currentImage) && /* @__PURE__ */ jsx(ImageEditor, { altText: imageModal == null ? void 0 : imageModal.currentImage.alt, legend: imageModal == null ? void 0 : imageModal.currentImage.title, image: imageModal == null ? void 0 : imageModal.currentImage.src, isOpen: imageModal.isOpen, onCancel: imageModal.handleCancel, onSave: imageModal.handleSave, onError: console.error }),
81
- editable && cantooModalHandlers.isOpen && /* @__PURE__ */ jsx(CantooModal, { ...cantooModalHandlers })
81
+ editable && cantooModalHandlers.isOpen && /* @__PURE__ */ jsx(CantooModal, {})
82
82
  ] })
83
83
  ] });
84
84
  });
@@ -0,0 +1,54 @@
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { Fragment as Fragment$1 } from "react";
3
+ import { useTranslation } from "react-i18next";
4
+ import SvgIconCantoo from "../../../icons/components/IconCantoo.js";
5
+ import SvgIconMicOff from "../../../icons/components/IconMicOff.js";
6
+ import SvgIconMic from "../../../icons/components/IconMic.js";
7
+ import SvgIconTextToSpeechOff from "../../../icons/components/IconTextToSpeechOff.js";
8
+ import SvgIconTextToSpeech from "../../../icons/components/IconTextToSpeech.js";
9
+ import SvgIconWand from "../../../icons/components/IconWand.js";
10
+ import { useCantooEditor } from "../../hooks/useCantooEditor.js";
11
+ import { useEditorContext } from "../../hooks/useEditorContext.js";
12
+ import Tooltip from "../../../../components/Tooltip/Tooltip.js";
13
+ import IconButton from "../../../../components/Button/IconButton.js";
14
+ import Dropdown from "../../../../components/Dropdown/Dropdown.js";
15
+ const EditorToolbarCantoo = ({
16
+ triggerProps,
17
+ openModal
18
+ }) => {
19
+ const {
20
+ t
21
+ } = useTranslation(), {
22
+ editor
23
+ } = useEditorContext(), {
24
+ speech2textIsActive,
25
+ text2speechIsActive,
26
+ toggleSpeech2Text,
27
+ toggleText2Speech,
28
+ formatText
29
+ } = useCantooEditor(editor), cantooOptions = [{
30
+ id: "speech2text",
31
+ label: t("tiptap.toolbar.cantoo.speech2text"),
32
+ className: speech2textIsActive ? "fw-bold" : "",
33
+ icon: speech2textIsActive ? /* @__PURE__ */ jsx(SvgIconMicOff, {}) : /* @__PURE__ */ jsx(SvgIconMic, {}),
34
+ action: () => toggleSpeech2Text()
35
+ }, {
36
+ id: "text2speech",
37
+ label: t("tiptap.toolbar.cantoo.text2speech"),
38
+ className: text2speechIsActive ? "fw-bold" : "",
39
+ icon: text2speechIsActive ? /* @__PURE__ */ jsx(SvgIconTextToSpeechOff, {}) : /* @__PURE__ */ jsx(SvgIconTextToSpeech, {}),
40
+ action: () => toggleText2Speech()
41
+ }, {
42
+ id: "formatText",
43
+ label: t("tiptap.toolbar.cantoo.formatText"),
44
+ icon: /* @__PURE__ */ jsx(SvgIconWand, {}),
45
+ action: () => formatText(openModal)
46
+ }];
47
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
48
+ /* @__PURE__ */ jsx(Tooltip, { message: t("tiptap.toolbar.cantoo.choice"), placement: "top", children: /* @__PURE__ */ jsx(IconButton, { ...triggerProps, type: "button", variant: "ghost", color: "tertiary", icon: /* @__PURE__ */ jsx(SvgIconCantoo, {}), className: speech2textIsActive || text2speechIsActive ? "is-selected" : "", "aria-label": t("tiptap.toolbar.cantoo.choice") }) }),
49
+ /* @__PURE__ */ jsx(Dropdown.Menu, { children: cantooOptions.map((option) => /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(Dropdown.Item, { onClick: option.action, icon: option.icon, children: /* @__PURE__ */ jsx("span", { className: option.className, children: option.label }) }) }, option.id)) })
50
+ ] });
51
+ };
52
+ export {
53
+ EditorToolbarCantoo
54
+ };
@@ -5,6 +5,8 @@ interface Props {
5
5
  mediaLibraryRef: RefObject<MediaLibraryRef>;
6
6
  /** API to open/close a Math modal. */
7
7
  toggleMathsModal: () => void;
8
+ /** API to open/close a Cantoo modal. */
9
+ toggleCantooModal: () => void;
8
10
  }
9
- export declare const EditorToolbar: ({ mediaLibraryRef, toggleMathsModal }: Props) => import("react/jsx-runtime").JSX.Element;
11
+ export declare const EditorToolbar: ({ mediaLibraryRef, toggleMathsModal, toggleCantooModal, }: Props) => import("react/jsx-runtime").JSX.Element;
10
12
  export {};
@@ -25,20 +25,25 @@ import { EditorToolbarPlusMenu } from "./EditorToolbar.PlusMenu.js";
25
25
  import { EditorToolbarTextColor } from "./EditorToolbar.TextColor.js";
26
26
  import { EditorToolbarTextSize } from "./EditorToolbar.TextSize.js";
27
27
  import { EditorToolbarTypography } from "./EditorToolbar.Typography.js";
28
- import { useEditorContext } from "../../hooks/useEditorContext.js";
28
+ import { EditorToolbarCantoo } from "./EditorToolbar.Cantoo.js";
29
+ import { useCantooEditor } from "../../hooks/useCantooEditor.js";
29
30
  import { useActionOptions } from "../../hooks/useActionOptions.js";
30
31
  import { useSpeechRecognition } from "../../hooks/useSpeechRecognition.js";
32
+ import { useEditorContext } from "../../hooks/useEditorContext.js";
31
33
  import { Toolbar } from "../../../../components/Toolbar/Toolbar.js";
32
34
  const EditorToolbar = ({
33
35
  mediaLibraryRef,
34
- toggleMathsModal
36
+ toggleMathsModal,
37
+ toggleCantooModal
35
38
  }) => {
36
39
  const {
37
40
  t
38
41
  } = useTranslation(), {
39
42
  id,
40
43
  editor
41
- } = useEditorContext(), [plusOptions, listOptions, alignmentOptions] = useActionOptions(editor, toggleMathsModal, mediaLibraryRef), {
44
+ } = useEditorContext(), {
45
+ isAvailable: canUseCantoo
46
+ } = useCantooEditor(editor), [plusOptions, listOptions, alignmentOptions] = useActionOptions(editor, toggleMathsModal, mediaLibraryRef), {
42
47
  isAvailable: canRecognizeSpeech,
43
48
  isActive: speechRecognition,
44
49
  toggle: toggleSpeechRecognition
@@ -165,6 +170,16 @@ const EditorToolbar = ({
165
170
  name: "speechtotext",
166
171
  tooltip: t("tiptap.toolbar.stt")
167
172
  },
173
+ //------------- CANTOO ---------------//
174
+ {
175
+ type: "dropdown",
176
+ props: {
177
+ children: (triggerProps) => /* @__PURE__ */ jsx(EditorToolbarCantoo, { triggerProps, openModal: toggleCantooModal })
178
+ },
179
+ name: "cantoo",
180
+ visibility: canUseCantoo ? "show" : "hide",
181
+ tooltip: t("tiptap.toolbar.cantoo.choice")
182
+ },
168
183
  //------------------------------------//
169
184
  {
170
185
  type: "divider",
@@ -10,3 +10,4 @@ export * from './useResizeMedia';
10
10
  export * from './useSpeechRecognition';
11
11
  export * from './useSpeechSynthetisis';
12
12
  export * from './useTipTapEditor';
13
+ export * from './useCantooEditor';
@@ -0,0 +1,51 @@
1
+ import { useState } from "react";
2
+ import useHasWorkflow from "../../../hooks/useHasWorkflow/useHasWorkflow.js";
3
+ const useCantooEditor = (editor) => {
4
+ const isAvailable = useHasWorkflow("org.entcore.portal.controllers.PortalController|optionalFeatureCantoo"), [speech2textIsActive, setSpeech2textActive] = useState(!1), [text2speechIsActive, setText2speechActive] = useState(!1), Cantoo = window.Cantoo;
5
+ return {
6
+ isAvailable,
7
+ speech2textIsActive,
8
+ text2speechIsActive,
9
+ toggleSpeech2Text: async () => {
10
+ if (speech2textIsActive) {
11
+ setSpeech2textActive(!1);
12
+ try {
13
+ await Cantoo.speech2text.stop();
14
+ } catch (e) {
15
+ console.warn("Error while trying to stop Cantoo (speech2text)", e);
16
+ }
17
+ } else
18
+ try {
19
+ if (setSpeech2textActive(!0), await Cantoo.speech2text.isAvailableOnDevice())
20
+ if (await Cantoo.speech2text.requestPermission())
21
+ await Cantoo.speech2text.start((data) => {
22
+ editor == null || editor.chain().focus().insertContent(data.join(" ")).run();
23
+ }, window.navigator.language);
24
+ else
25
+ throw new Error("Permission denied");
26
+ else
27
+ throw new Error("Cantoo not available");
28
+ } catch (e) {
29
+ console.warn("Error while trying to use Cantoo (speech2text)", e), setSpeech2textActive(!1);
30
+ }
31
+ },
32
+ toggleText2Speech: () => {
33
+ if (text2speechIsActive)
34
+ setText2speechActive(!1), window.speechSynthesis.cancel();
35
+ else
36
+ try {
37
+ setText2speechActive(!0), Cantoo.text2speech.readText(editor == null ? void 0 : editor.getText()), Cantoo.text2speech.utter.onend = () => {
38
+ setText2speechActive(!1);
39
+ };
40
+ } catch (e) {
41
+ console.warn("Error while trying to use Cantoo (text2speech)", e), setText2speechActive(!1);
42
+ }
43
+ },
44
+ formatText: (openModal) => {
45
+ openModal();
46
+ }
47
+ };
48
+ };
49
+ export {
50
+ useCantooEditor
51
+ };
@@ -3,9 +3,20 @@ const SvgIconCantoo = ({
3
3
  title,
4
4
  titleId,
5
5
  ...props
6
- }) => /* @__PURE__ */ jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", fill: "none", viewBox: "0 0 16 16", "aria-hidden": "true", "aria-labelledby": titleId, ...props, children: [
6
+ }) => /* @__PURE__ */ jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", fill: "none", viewBox: "0 0 88 104", "aria-hidden": "true", "aria-labelledby": titleId, ...props, children: [
7
7
  title ? /* @__PURE__ */ jsx("title", { id: titleId, children: title }) : null,
8
- /* @__PURE__ */ jsx("path", { fill: "#000", d: "M8 3a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3M15 4v2h-4.455l.445 10H8.988l-.222-5H7.234l-.222 5H5.01l.445-10H1V4z" })
8
+ /* @__PURE__ */ jsx("ellipse", { cx: 44.305, cy: 15.281, fill: "url(#icon-cantoo_svg__a)", rx: 14.472, ry: 14.367, transform: "rotate(-.145 44.305 15.281)" }),
9
+ /* @__PURE__ */ jsx("path", { fill: "url(#icon-cantoo_svg__b)", fillRule: "evenodd", d: "m44.529 39.653-28.126-8.41c-6.42-1.785-13.121 1.8-14.968 8.008C-.414 45.46 3.294 51.94 9.713 53.724l17.54 5.245-16.845 28.892c-2.73 5.401.023 11.938 6.147 14.601 6.125 2.662 13.301.442 16.03-4.96l11.88-20.374 11.974 20.3c2.757 5.387 9.945 7.57 16.055 4.877 6.111-2.694 8.83-9.244 6.074-14.632l-16.953-28.74 17.478-5.384c6.41-1.818 10.084-8.316 8.206-14.514-1.879-6.199-8.598-9.75-15.009-7.932z", clipRule: "evenodd" }),
10
+ /* @__PURE__ */ jsxs("defs", { children: [
11
+ /* @__PURE__ */ jsxs("linearGradient", { id: "icon-cantoo_svg__a", x1: 28.13, x2: 60.619, y1: -6.867, y2: 27.927, gradientUnits: "userSpaceOnUse", children: [
12
+ /* @__PURE__ */ jsx("stop", { stopColor: "#0B4EFC" }),
13
+ /* @__PURE__ */ jsx("stop", { offset: 1, stopColor: "#30B3E8" })
14
+ ] }),
15
+ /* @__PURE__ */ jsxs("linearGradient", { id: "icon-cantoo_svg__b", x1: -4.227, x2: 76.299, y1: 11.105, y2: 112.656, gradientUnits: "userSpaceOnUse", children: [
16
+ /* @__PURE__ */ jsx("stop", { stopColor: "#0B4EFC" }),
17
+ /* @__PURE__ */ jsx("stop", { offset: 1, stopColor: "#30B3E8" })
18
+ ] })
19
+ ] })
9
20
  ] });
10
21
  export {
11
22
  SvgIconCantoo as default
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edifice.io/react",
3
- "version": "2.1.1-develop-integration.20250210202453",
3
+ "version": "2.1.1-develop-integration.20250213121025",
4
4
  "description": "Edifice React Library",
5
5
  "keywords": [
6
6
  "react",
@@ -118,9 +118,9 @@
118
118
  "react-slugify": "^3.0.3",
119
119
  "swiper": "^10.1.0",
120
120
  "ua-parser-js": "^1.0.36",
121
- "@edifice.io/bootstrap": "2.1.1-develop-integration.20250210202453",
122
- "@edifice.io/tiptap-extensions": "2.1.1-develop-integration.20250210202453",
123
- "@edifice.io/utilities": "2.1.1-develop-integration.20250210202453"
121
+ "@edifice.io/bootstrap": "2.1.1-develop-integration.20250213121025",
122
+ "@edifice.io/tiptap-extensions": "2.1.1-develop-integration.20250213121025",
123
+ "@edifice.io/utilities": "2.1.1-develop-integration.20250213121025"
124
124
  },
125
125
  "devDependencies": {
126
126
  "@babel/plugin-transform-react-pure-annotations": "^7.23.3",
@@ -129,6 +129,9 @@
129
129
  "@svgr/cli": "^8.1.0",
130
130
  "@tanstack/query-core": "5.62.7",
131
131
  "@tanstack/react-query": "5.62.7",
132
+ "@testing-library/jest-dom": "^6.5.0",
133
+ "@testing-library/react": "^16.0.1",
134
+ "@testing-library/user-event": "^14.5.2",
132
135
  "@types/node": "^22.9.1",
133
136
  "@types/pako": "^2.0.3",
134
137
  "@types/react": "^18.2.33",
@@ -148,8 +151,8 @@
148
151
  "vite": "^5.4.11",
149
152
  "vite-plugin-dts": "^4.1.0",
150
153
  "vite-tsconfig-paths": "^5.0.1",
151
- "@edifice.io/client": "2.1.1-develop-integration.20250210202453",
152
- "@edifice.io/config": "2.1.1-develop-integration.20250210202453"
154
+ "@edifice.io/client": "2.1.1-develop-integration.20250213121025",
155
+ "@edifice.io/config": "2.1.1-develop-integration.20250213121025"
153
156
  },
154
157
  "peerDependencies": {
155
158
  "@react-spring/web": "^9.7.5",