@instructure/platform-rce-adapter 0.3.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.
@@ -0,0 +1,13 @@
1
+ import { default as RCEWrapper } from '@instructure/canvas-rce/es/rce/RCEWrapper.js';
2
+ import { ForwardRefExoticComponent, RefAttributes } from 'react';
3
+ import { RceEditorProps } from './types';
4
+ /**
5
+ * Host-agnostic wrapper around `@instructure/canvas-rce`'s `RCE`. All Canvas
6
+ * config that used to be read from `window.ENV` / `window.INST` / the DOM is
7
+ * supplied by the host through the `config` prop (see `RceConfig`). This is the
8
+ * de-canvased port of `canvas-lms/ui/shared/rce/react/CanvasRce.tsx`.
9
+ *
10
+ * The ref forwards to the underlying `RCEWrapper` (available after `onInit`).
11
+ */
12
+ export declare const RceEditor: ForwardRefExoticComponent<RceEditorProps & RefAttributes<RCEWrapper>>;
13
+ //# sourceMappingURL=RceEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RceEditor.d.ts","sourceRoot":"","sources":["../src/RceEditor.tsx"],"names":[],"mappings":"AAmBA,OAAO,KAAK,UAAU,MAAM,8CAA8C,CAAA;AAC1E,OAAO,EAEL,KAAK,yBAAyB,EAG9B,KAAK,aAAa,EAInB,MAAM,OAAO,CAAA;AACd,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAI7C;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,EAAE,yBAAyB,CAAC,cAAc,GAAG,aAAa,CAAC,UAAU,CAAC,CAqHxF,CAAA"}
@@ -0,0 +1,3 @@
1
+ export { RceEditor } from './RceEditor';
2
+ export type { RceConfig, RceContainingContext, RceEditorProps, } from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,YAAY,EACV,SAAS,EACT,oBAAoB,EACpB,cAAc,GACf,MAAM,SAAS,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,83 @@
1
+ import { jsx as y } from "react/jsx-runtime";
2
+ import b from "@instructure/canvas-rce/es/rce/RCE.js";
3
+ import { forwardRef as w, useRef as U, useState as O, useCallback as M } from "react";
4
+ const _ = 36e5, j = w(function(r, s) {
5
+ const {
6
+ config: e,
7
+ autosave: l,
8
+ defaultContent: c,
9
+ editorOptions: u,
10
+ height: d,
11
+ maxInitRenderedRCEs: f,
12
+ mirroredAttrs: g,
13
+ onBlur: C,
14
+ onContentChange: m,
15
+ onFocus: x,
16
+ onInit: T,
17
+ readOnly: h,
18
+ textareaClassName: v,
19
+ textareaId: R,
20
+ variant: A
21
+ } = r, n = s, a = U(null), [I] = O(() => ({
22
+ enabled: l ?? !0,
23
+ maxAge: e.autosaveMaxAge ?? _
24
+ })), p = M(
25
+ (t) => {
26
+ var o, i;
27
+ n && (n.current = t), t ? t.getTextarea().remoteEditor = t : (i = (o = a.current) == null ? void 0 : o.destroy) == null || i.call(o), a.current = t;
28
+ },
29
+ [n]
30
+ ), S = {
31
+ canUploadFiles: e.canUploadFiles,
32
+ containingContext: e.containingContext,
33
+ contextId: e.contextId ?? e.containingContext.contextId,
34
+ contextType: e.contextType ?? e.containingContext.contextType,
35
+ filesTabDisabled: e.filesTabDisabled,
36
+ host: e.host,
37
+ jwt: e.jwt,
38
+ refreshToken: e.refreshToken,
39
+ themeUrl: e.themeUrl
40
+ }, E = e.ltiIframeAllowances !== void 0 || e.maxMruTools !== void 0 || e.resourceSelectionUrl != null || e.containingCanvasLtiToolId !== void 0 || e.isA2StudentView !== void 0 ? {
41
+ ltiIframeAllowances: e.ltiIframeAllowances ?? [],
42
+ containingCanvasLtiToolId: e.containingCanvasLtiToolId ?? "",
43
+ resourceSelectionUrlOverride: e.resourceSelectionUrl ?? "",
44
+ isA2StudentView: e.isA2StudentView ?? !1,
45
+ maxMruTools: e.maxMruTools ?? 0
46
+ } : void 0;
47
+ return /* @__PURE__ */ y(
48
+ b,
49
+ {
50
+ ref: p,
51
+ autosave: I,
52
+ canvasOrigin: e.canvasOrigin,
53
+ defaultContent: c,
54
+ editorOptions: u ?? {},
55
+ externalToolsConfig: E,
56
+ features: e.features ?? {},
57
+ fontFamily: e.fontFamily,
58
+ height: d,
59
+ highContrastCSS: e.highContrastCSS ?? [],
60
+ instRecordDisabled: e.instRecordDisabled,
61
+ language: e.language ?? "en",
62
+ liveRegion: e.liveRegion,
63
+ ltiTools: e.ltiTools ?? [],
64
+ maxInitRenderedRCEs: f ?? -1,
65
+ mirroredAttrs: g ?? {},
66
+ onBlur: C,
67
+ onContentChange: m,
68
+ onFocus: x,
69
+ onInit: T,
70
+ rcsProps: S,
71
+ readOnly: h ?? !1,
72
+ textareaClassName: v ?? "input-block-level",
73
+ textareaId: R,
74
+ variant: A,
75
+ use_rce_icon_maker: e.useRceIconMaker,
76
+ useHighContrast: e.useHighContrast ?? !1,
77
+ userCacheKey: e.userCacheKey
78
+ }
79
+ );
80
+ });
81
+ export {
82
+ j as RceEditor
83
+ };
@@ -0,0 +1,82 @@
1
+ import { EditorOptions } from '@instructure/canvas-rce/es/rce/RCEWrapperProps.js';
2
+ import { RCEVariant } from '@instructure/canvas-rce/es/rce/RCEVariants.js';
3
+ export type { RCEVariant };
4
+ /** The course/user context the RCS is scoped to. */
5
+ export interface RceContainingContext {
6
+ contextType: string;
7
+ contextId: string;
8
+ userId: string;
9
+ }
10
+ /**
11
+ * Host-supplied RCE configuration. Every field here is something canvas
12
+ * historically read from `window.ENV` / `window.INST` / the DOM; the host
13
+ * now computes them and passes them in, keeping this package host-agnostic.
14
+ */
15
+ export interface RceConfig {
16
+ host: string;
17
+ jwt: string;
18
+ refreshToken: (done?: (token: string) => void) => void;
19
+ containingContext: RceContainingContext;
20
+ /**
21
+ * RCS context type/id. Defaults to `containingContext`'s, but the host can
22
+ * override — canvas deliberately swaps these to the user context for account
23
+ * contexts / when the user can't upload files (see `getRCSProps`).
24
+ */
25
+ contextType?: string;
26
+ contextId?: string;
27
+ canUploadFiles: boolean;
28
+ filesTabDisabled?: boolean;
29
+ themeUrl?: string;
30
+ ltiIframeAllowances?: string[];
31
+ maxMruTools?: number;
32
+ /** Override URL for the external-tool resource picker (was a DOM read). */
33
+ resourceSelectionUrl?: string | null;
34
+ containingCanvasLtiToolId?: string;
35
+ isA2StudentView?: boolean;
36
+ canvasOrigin: string;
37
+ language?: string;
38
+ userCacheKey?: string;
39
+ useHighContrast?: boolean;
40
+ highContrastCSS?: string[];
41
+ fontFamily?: string;
42
+ ltiTools?: unknown[];
43
+ instRecordDisabled?: boolean;
44
+ autosaveMaxAge?: number;
45
+ features?: Record<string, boolean>;
46
+ useRceIconMaker?: boolean;
47
+ /**
48
+ * Returns the live-region element for screen-reader announcements. Required —
49
+ * canvas-rce always expects one and uses it for its InstUI alerts.
50
+ */
51
+ liveRegion: () => HTMLElement | null;
52
+ }
53
+ export interface RceEditorProps {
54
+ /** Host-supplied configuration (RCS connection + editor chrome). */
55
+ config: RceConfig;
56
+ /** Initial editor content (HTML). */
57
+ defaultContent?: string;
58
+ /** Called with the editor HTML whenever content changes. */
59
+ onContentChange?: (content: string) => void;
60
+ /** id applied to the backing textarea (must be selector-safe — no colons). */
61
+ textareaId: string;
62
+ /** Height of the editor; number = px. */
63
+ height?: number | string;
64
+ /** Whether the editor is read-only. */
65
+ readOnly?: boolean;
66
+ /** Attributes mirrored onto the backing textarea (e.g. aria-required). */
67
+ mirroredAttrs?: Record<string, string>;
68
+ /** Whether to autosave to localStorage as the user types. */
69
+ autosave?: boolean;
70
+ /** tinymce configuration overrides (host-built EditorConfig output). */
71
+ editorOptions?: EditorOptions;
72
+ /** RCE variant — e.g. 'block-content-editor' for the block editor. Defaults to the classic RCE. */
73
+ variant?: RCEVariant;
74
+ /** Max RCEs rendered on load before deferring; defaults to -1 (render all). */
75
+ maxInitRenderedRCEs?: number;
76
+ /** Class applied to the backing textarea; defaults to 'input-block-level'. */
77
+ textareaClassName?: string;
78
+ onFocus?: (rce: unknown) => void;
79
+ onBlur?: (event: unknown) => void;
80
+ onInit?: (...args: unknown[]) => void;
81
+ }
82
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAA;AACtF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+CAA+C,CAAA;AAE/E,YAAY,EAAE,UAAU,EAAE,CAAA;AAE1B,oDAAoD;AACpD,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;GAIG;AACH,MAAM,WAAW,SAAS;IAExB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,YAAY,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,KAAK,IAAI,CAAA;IACtD,iBAAiB,EAAE,oBAAoB,CAAA;IACvC;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,OAAO,CAAA;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IAKjB,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,2EAA2E;IAC3E,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpC,yBAAyB,CAAC,EAAE,MAAM,CAAA;IAClC,eAAe,CAAC,EAAE,OAAO,CAAA;IAGzB,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAA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MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IACjC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;CACtC"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@instructure/platform-rce-adapter",
3
+ "version": "0.3.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "scripts": {
21
+ "build": "vite build",
22
+ "dev": "vite build --watch",
23
+ "test": "vitest run",
24
+ "test:watch": "vitest",
25
+ "test:coverage": "vitest run --coverage",
26
+ "type-check": "tsc -p tsconfig.check.json"
27
+ },
28
+ "peerDependencies": {
29
+ "@instructure/canvas-rce": "^8.1.0",
30
+ "react": "^18.0.0",
31
+ "react-dom": "^18.0.0",
32
+ "tinymce": "^5.9"
33
+ },
34
+ "devDependencies": {
35
+ "@instructure/canvas-rce": "^8.1.0",
36
+ "@testing-library/jest-dom": "^6.9.1",
37
+ "@testing-library/react": "^16.0.0",
38
+ "@testing-library/user-event": "^14.0.0",
39
+ "@types/react": "^18.3.0",
40
+ "@types/react-dom": "^18.3.0",
41
+ "@vitejs/plugin-react": "^4.0.0",
42
+ "@vitest/coverage-v8": "^4.0.0",
43
+ "jsdom": "^25.0.0",
44
+ "tinymce": "^5.9",
45
+ "typescript": "^5.3.0",
46
+ "vite": "^6.0.0",
47
+ "vite-plugin-dts": "^4.0.0",
48
+ "vitest": "^4.0.0"
49
+ }
50
+ }