@editora/plugins 1.0.23 → 1.1.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/index.d.ts CHANGED
@@ -5,7 +5,6 @@ export interface ApiConfig {
5
5
  headers?: Record<string, string>;
6
6
  }
7
7
 
8
- export type MediaManagerConfig = Record<string, unknown>;
9
8
  export type DocumentManagerConfig = Record<string, unknown>;
10
9
 
11
10
  export interface MergeTagItem {
@@ -911,9 +910,191 @@ export function DocSchemaPlugin(options?: DocSchemaPluginOptions): Plugin;
911
910
  export function TranslationWorkflowPlugin(options?: TranslationWorkflowPluginOptions): Plugin;
912
911
  export function SlashCommandsPlugin(options?: SlashCommandsPluginOptions): Plugin;
913
912
 
914
- export function MediaManagerPlugin(): Plugin;
913
+ // ── Media manager ────────────────────────────────────────────────────────────────────────────
914
+ /** What an upload reports while it runs. `fraction` is 0..1. */
915
+ export interface UploadProgress {
916
+ loaded: number;
917
+ total: number;
918
+ fraction: number;
919
+ }
920
+
921
+ export interface UploadContext {
922
+ /** Aborted when the person cancels or closes the dialog; stop, and reject with an AbortError. */
923
+ signal?: AbortSignal;
924
+ onProgress?: (progress: UploadProgress) => void;
925
+ }
926
+
927
+ export interface MediaItem {
928
+ id: string;
929
+ name: string;
930
+ type: 'image' | 'video' | 'audio' | 'file';
931
+ /** The address the document will point at: an https URL, or a data URL when nothing is configured. */
932
+ src: string;
933
+ size: number;
934
+ width?: number;
935
+ height?: number;
936
+ duration?: number;
937
+ mime: string;
938
+ createdAt: number;
939
+ metadata: Record<string, any>;
940
+ thumbnailUrl?: string;
941
+ /** The description kept with the file in the library, offered as the alt text when it is inserted. */
942
+ alt?: string;
943
+ }
944
+
945
+ export interface MediaQuery {
946
+ page?: number;
947
+ limit?: number;
948
+ /** Free-text search over names and alt text. */
949
+ search?: string;
950
+ type?: MediaItem['type'];
951
+ folderId?: string | null;
952
+ /** The order of the listing (default `newest`). A provider that cannot sort may ignore it. */
953
+ sort?: 'newest' | 'oldest' | 'name';
954
+ }
955
+
956
+ export interface MediaPage {
957
+ items: MediaItem[];
958
+ total: number;
959
+ }
960
+
961
+ /** What can be changed about a file that is already in the library. */
962
+ export interface MediaUpdate {
963
+ name?: string;
964
+ alt?: string;
965
+ }
966
+
967
+ /**
968
+ * Where media goes and where the library comes from. Only `upload` is required; with `list` the picker has a library.
969
+ */
970
+ export interface MediaProvider {
971
+ readonly name?: string;
972
+ upload(file: File, context: UploadContext): Promise<MediaItem>;
973
+ list?(query?: MediaQuery, context?: { signal?: AbortSignal }): Promise<MediaPage>;
974
+ update?(id: string, updates: MediaUpdate): Promise<void>;
975
+ delete?(id: string): Promise<void>;
976
+ }
977
+
978
+ /** The shortest way to plug in a backend: receive the file, report progress, resolve with the URL. */
979
+ export type MediaUploadHandler = (
980
+ file: File,
981
+ context: UploadContext,
982
+ ) => Promise<string | { url: string; thumbnailUrl?: string; width?: number; height?: number; id?: string; name?: string }>;
983
+
984
+ /** A photo from a stock service, as the picker shows it. */
985
+ export interface StockPhoto {
986
+ id: string;
987
+ thumbnailUrl: string;
988
+ url: string;
989
+ width?: number;
990
+ height?: number;
991
+ /** What it shows, offered as the alt text. */
992
+ description?: string;
993
+ author?: string;
994
+ authorUrl?: string;
995
+ sourceUrl?: string;
996
+ }
997
+
998
+ /** Photos from a service such as Unsplash: you write `search` (calling your own backend); the picker shows a Stock tab. */
999
+ export interface StockProvider {
1000
+ name: string;
1001
+ search(
1002
+ query: { search: string; page: number; limit: number },
1003
+ context: { signal?: AbortSignal },
1004
+ ): Promise<{ items: StockPhoto[]; total?: number }>;
1005
+ /** The credit put under an inserted photo; by default "Photo by <author> on <name>". `false` for none. */
1006
+ caption?: false | ((photo: StockPhoto) => string | null);
1007
+ }
1008
+
1009
+ /** Describe a picture for people who cannot see it. The result fills the alt text field; it is never inserted on its own. */
1010
+ export type AltTextGenerator = (
1011
+ image: { src: string; name?: string },
1012
+ context: { signal?: AbortSignal },
1013
+ ) => Promise<string>;
1014
+
1015
+ /** What a link embeds as a player. */
1016
+ export interface EmbedSpec {
1017
+ provider: string;
1018
+ label: string;
1019
+ /** Always https. */
1020
+ src: string;
1021
+ /** Width over height. */
1022
+ aspectRatio: number;
1023
+ id: string;
1024
+ }
1025
+
1026
+ /** A service whose links can be embedded (YouTube and Vimeo are built in). `parse` must return an https address. */
1027
+ export interface EmbedProvider {
1028
+ id: string;
1029
+ label: string;
1030
+ parse(url: URL): { src: string; id: string; aspectRatio?: number } | null;
1031
+ }
1032
+
1033
+ export interface MediaManagerConfig {
1034
+ /** A complete provider. Wins over everything below. */
1035
+ provider?: MediaProvider;
1036
+ /** Upload callback; wrapped into a provider. Wins over `apiUrl`. */
1037
+ uploadHandler?: MediaUploadHandler;
1038
+ /** Base URL of a REST backend. Without it, and without a provider, files become data URLs. */
1039
+ apiUrl?: string;
1040
+ apiEndpoints?: { upload: string; library: string; delete: string };
1041
+ /** Extra request headers (authentication). */
1042
+ headers?: Record<string, string>;
1043
+ /** Send cookies with the upload request. */
1044
+ withCredentials?: boolean;
1045
+ /** Name of the multipart field that carries the file. Default `file`. */
1046
+ uploadFieldName?: string;
1047
+ /** Insert a data URL when an upload fails, instead of showing the error. Off by default. */
1048
+ fallbackToBase64?: boolean;
1049
+ /** More links that can be embedded as a player. */
1050
+ embedProviders?: EmbedProvider[];
1051
+ /** Photos from a stock service: adds a Stock tab to the image picker. */
1052
+ stockProvider?: StockProvider;
1053
+ /** Adds a Suggest button next to the alt text field. */
1054
+ generateAltText?: AltTextGenerator;
1055
+ /** Insert media as `<figure>` that can be aligned and captioned (default). `false` inserts a bare `<img>`/`<video>`. */
1056
+ wrapInFigure?: boolean;
1057
+ /** Put an Audio button in the toolbar. Off by default. */
1058
+ audio?: boolean;
1059
+ /** Upload images, videos and audio that are pasted or dropped into the editor (default `true`). */
1060
+ uploadOnPaste?: boolean;
1061
+ /** Keep a library of what is uploaded from this browser (IndexedDB) for providers that cannot list. Default `true`. */
1062
+ localLibrary?: boolean;
1063
+ /** Scale down and re-encode large JPEG, PNG and WebP files before they are stored. Off by default. */
1064
+ optimizeImages?: boolean | { maxWidth?: number; quality?: number; format?: 'keep' | 'webp' | 'jpeg' };
1065
+ /** Maximum file size in bytes (checked on the result when `optimizeImages` is on). */
1066
+ maxFileSize?: number;
1067
+ /** Allowed MIME types; `image/*` style wildcards work. */
1068
+ allowedTypes?: string[];
1069
+ }
1070
+
1071
+ export class MediaUploadError extends Error {
1072
+ readonly code: 'too-large' | 'type-not-allowed' | 'aborted' | 'network' | 'server' | 'invalid-response';
1073
+ readonly status?: number;
1074
+ constructor(code: MediaUploadError['code'], message: string, status?: number);
1075
+ }
1076
+
1077
+ export function createBase64Provider(): MediaProvider;
1078
+ export function createCallbackProvider(handler: MediaUploadHandler): MediaProvider;
1079
+ export function createRestProvider(options: {
1080
+ uploadUrl: string;
1081
+ libraryUrl?: string;
1082
+ deleteUrl?: string;
1083
+ headers?: () => Record<string, string>;
1084
+ withCredentials?: boolean;
1085
+ fieldName?: string;
1086
+ }): MediaProvider;
1087
+
1088
+ /** What a pasted link or iframe snippet embeds, or `null` when no provider knows it. */
1089
+ export function parseEmbedUrl(input: string, extra?: EmbedProvider[]): EmbedSpec | null;
1090
+
1091
+ /** Entries for `SlashCommandsPlugin({ items })`: `/image`, `/audio`, `/video`. */
1092
+ export const mediaSlashItems: Array<{ id: string; label: string; description?: string; command: string; keywords?: string[] }>;
1093
+
1094
+ export function MediaManagerPlugin(config?: Partial<MediaManagerConfig>): Plugin;
915
1095
  export function setMediaManagerConfig(config: Partial<MediaManagerConfig>): void;
916
1096
  export function getMediaManagerConfig(): MediaManagerConfig;
1097
+ // ─────────────────────────────────────────────────────────────────────────────────────────────
917
1098
 
918
1099
  export function DocumentManagerPlugin(): Plugin;
919
1100
  export function setDocumentManagerConfig(config: Partial<DocumentManagerConfig>): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@editora/plugins",
3
- "version": "1.0.23",
3
+ "version": "1.1.0",
4
4
  "description": "Enterprise plugin suite for Editora rich text editor in React and web apps, including tables, media, workflow, and compliance tooling.",
5
5
  "author": "Ajay Kumar <ajaykr089@gmail.com>",
6
6
  "license": "MIT",
@@ -437,7 +437,7 @@
437
437
  "verify:citations": "npm run typecheck:build && npm run test:citations && npm run test:content-rules && npm run test:approval-workflow && npm run test:pii-redaction && npm run test:smart-paste && npm run test:blocks-library && npm run test:doc-schema && npm run test:translation-workflow && npm run test:format-painter && npm run test:toolbar-icons && npm run test:dom && npm run build"
438
438
  },
439
439
  "peerDependencies": {
440
- "@editora/core": "^1.0.24"
440
+ "@editora/core": "^1.0.25"
441
441
  },
442
442
  "dependencies": {
443
443
  "@editora/light-code-editor": "^1.0.19",
@@ -445,7 +445,7 @@
445
445
  "mathjax": "^3.2.2"
446
446
  },
447
447
  "devDependencies": {
448
- "@editora/core": "^1.0.24",
448
+ "@editora/core": "^1.0.25",
449
449
  "@types/katex": "^0.16.8",
450
450
  "dompurify": "^3.4.16",
451
451
  "typescript": "^5.0.0",
@@ -1,106 +0,0 @@
1
- import { e as l } from "./escapeHtml-DyksyvcZ.mjs";
2
- import { i as p } from "./dialogHelpers-BbwpIXD9.mjs";
3
- const u = "rte-confirm-styles", x = '[data-theme="dark"], .dark, .editora-theme-dark';
4
- let g = 0;
5
- function v() {
6
- if (document.getElementById(u)) return;
7
- const o = document.createElement("style");
8
- o.id = u, o.textContent = `
9
- .rte-confirm-overlay {
10
- position: fixed; inset: 0; z-index: 100002; display: flex; align-items: center; justify-content: center;
11
- padding: 16px; background: rgba(15, 23, 36, 0.56);
12
- --rte-confirm-bg: #ffffff; --rte-confirm-text: #101828; --rte-confirm-muted: #5f6b7d; --rte-confirm-border: #d6dbe4;
13
- --rte-confirm-accent: #1f75fe; --rte-confirm-danger: #c62828;
14
- }
15
- .rte-confirm-overlay.rte-confirm-dark {
16
- --rte-confirm-bg: #1f2937; --rte-confirm-text: #e5e7eb; --rte-confirm-muted: #9ca3af; --rte-confirm-border: #3b4657;
17
- --rte-confirm-accent: #3b82f6; --rte-confirm-danger: #ef4444;
18
- }
19
- .rte-confirm-dialog {
20
- box-sizing: border-box; width: min(100%, 420px); padding: 20px; border-radius: 10px;
21
- background: var(--rte-confirm-bg); color: var(--rte-confirm-text); border: 1px solid var(--rte-confirm-border);
22
- box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35); font-size: 14px; line-height: 1.45;
23
- }
24
- .rte-confirm-title { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
25
- .rte-confirm-message { margin: 0 0 14px; color: var(--rte-confirm-muted); }
26
- .rte-confirm-field { display: block; margin: 0 0 6px; }
27
- .rte-confirm-input {
28
- box-sizing: border-box; width: 100%; padding: 8px 10px; border-radius: 6px; font: inherit;
29
- border: 1px solid var(--rte-confirm-border); background: transparent; color: inherit;
30
- }
31
- .rte-confirm-input[aria-invalid="true"] { border-color: var(--rte-confirm-danger); }
32
- .rte-confirm-error { margin: 6px 0 0; color: var(--rte-confirm-danger); font-size: 13px; }
33
- .rte-confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
34
- .rte-confirm-button {
35
- padding: 8px 14px; border-radius: 6px; font: inherit; cursor: pointer;
36
- border: 1px solid var(--rte-confirm-border); background: transparent; color: inherit;
37
- }
38
- .rte-confirm-button.primary { background: var(--rte-confirm-accent); border-color: var(--rte-confirm-accent); color: #fff; }
39
- .rte-confirm-button.danger { background: var(--rte-confirm-danger); border-color: var(--rte-confirm-danger); color: #fff; }
40
- .rte-confirm-button:focus-visible, .rte-confirm-input:focus-visible { outline: 2px solid var(--rte-confirm-accent); outline-offset: 2px; }
41
- `, document.head.appendChild(o);
42
- }
43
- function m(o, t, r) {
44
- v();
45
- const e = `rte-confirm-${++g}`, c = document.createElement("div");
46
- p(c), c.className = "rte-confirm-overlay", (t.context ?? (document.activeElement instanceof Element ? document.activeElement : null))?.closest(x) && c.classList.add("rte-confirm-dark");
47
- const f = t.title ?? (r ? "Enter a value" : "Please confirm"), a = t.confirmText ?? (r ? "OK" : "Confirm"), d = t.cancelText ?? "Cancel", i = t.danger === !0, n = document.createElement("div");
48
- return n.className = "rte-confirm-dialog", n.setAttribute("role", r ? "dialog" : "alertdialog"), n.setAttribute("aria-modal", "true"), n.setAttribute("aria-labelledby", `${e}-title`), n.setAttribute("aria-describedby", `${e}-message`), n.innerHTML = `
49
- <h2 class="rte-confirm-title" id="${e}-title">${l(f)}</h2>
50
- <p class="rte-confirm-message" id="${e}-message">${l(o)}</p>
51
- ${r ? `<label class="rte-confirm-field" for="${e}-input">${l(r.label ?? o)}</label>
52
- <input class="rte-confirm-input" id="${e}-input" type="text" inputmode="${r.inputMode ?? "text"}"
53
- autocomplete="off" value="${l(r.initialValue ?? "")}" placeholder="${l(r.placeholder ?? "")}"
54
- aria-describedby="${e}-error">
55
- <p class="rte-confirm-error" id="${e}-error" role="alert" hidden></p>` : ""}
56
- <div class="rte-confirm-actions">
57
- <button type="button" class="rte-confirm-button" data-action="cancel">${l(d)}</button>
58
- <button type="button" class="rte-confirm-button ${i ? "danger" : "primary"}" data-action="confirm">${l(a)}</button>
59
- </div>
60
- `, c.appendChild(n), {
61
- overlay: c,
62
- confirmButton: n.querySelector('[data-action="confirm"]'),
63
- cancelButton: n.querySelector('[data-action="cancel"]'),
64
- input: n.querySelector("input"),
65
- error: n.querySelector(".rte-confirm-error")
66
- };
67
- }
68
- function b(o, t) {
69
- return new Promise((r) => {
70
- const { overlay: e, confirmButton: c, cancelButton: s } = o;
71
- let f = !1;
72
- const a = (i) => {
73
- const n = t(i);
74
- n !== void 0 && (f || (f = !0, window.removeEventListener("keydown", d, !0), e.remove(), r(n)));
75
- }, d = (i) => {
76
- i.key !== "Escape" || !e.isConnected || (i.preventDefault(), i.stopPropagation(), a(!1));
77
- };
78
- window.addEventListener("keydown", d, !0), s.addEventListener("click", () => a(!1)), c.addEventListener("click", () => a(!0)), e.addEventListener("click", (i) => {
79
- i.target === e && a(!1);
80
- }), o.input?.addEventListener("keydown", (i) => {
81
- i.key === "Enter" && (i.preventDefault(), a(!0));
82
- }), document.body.appendChild(e);
83
- });
84
- }
85
- function k(o, t = {}) {
86
- const r = m(o, t, null);
87
- return b(r, (e) => e);
88
- }
89
- function E(o, t = {}) {
90
- const r = m(o, t, t), { input: e, error: c } = r, s = b(r, (f) => {
91
- if (!f) return null;
92
- const a = e?.value ?? "", d = t.validate ? t.validate(a) : null;
93
- if (d) {
94
- c && (c.textContent = d, c.hidden = !1), e?.setAttribute("aria-invalid", "true"), e?.focus(), e?.select();
95
- return;
96
- }
97
- return a;
98
- });
99
- return window.setTimeout(() => {
100
- e?.isConnected && (e.focus(), e.select());
101
- }, 10), s;
102
- }
103
- export {
104
- k as c,
105
- E as p
106
- };
@@ -1,46 +0,0 @@
1
- "use strict";const d=require("./escapeHtml-D2Zh82pD.js"),b=require("./dialogHelpers-BxSQ7A6M.js"),u="rte-confirm-styles",x='[data-theme="dark"], .dark, .editora-theme-dark';let g=0;function v(){if(document.getElementById(u))return;const o=document.createElement("style");o.id=u,o.textContent=`
2
- .rte-confirm-overlay {
3
- position: fixed; inset: 0; z-index: 100002; display: flex; align-items: center; justify-content: center;
4
- padding: 16px; background: rgba(15, 23, 36, 0.56);
5
- --rte-confirm-bg: #ffffff; --rte-confirm-text: #101828; --rte-confirm-muted: #5f6b7d; --rte-confirm-border: #d6dbe4;
6
- --rte-confirm-accent: #1f75fe; --rte-confirm-danger: #c62828;
7
- }
8
- .rte-confirm-overlay.rte-confirm-dark {
9
- --rte-confirm-bg: #1f2937; --rte-confirm-text: #e5e7eb; --rte-confirm-muted: #9ca3af; --rte-confirm-border: #3b4657;
10
- --rte-confirm-accent: #3b82f6; --rte-confirm-danger: #ef4444;
11
- }
12
- .rte-confirm-dialog {
13
- box-sizing: border-box; width: min(100%, 420px); padding: 20px; border-radius: 10px;
14
- background: var(--rte-confirm-bg); color: var(--rte-confirm-text); border: 1px solid var(--rte-confirm-border);
15
- box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35); font-size: 14px; line-height: 1.45;
16
- }
17
- .rte-confirm-title { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
18
- .rte-confirm-message { margin: 0 0 14px; color: var(--rte-confirm-muted); }
19
- .rte-confirm-field { display: block; margin: 0 0 6px; }
20
- .rte-confirm-input {
21
- box-sizing: border-box; width: 100%; padding: 8px 10px; border-radius: 6px; font: inherit;
22
- border: 1px solid var(--rte-confirm-border); background: transparent; color: inherit;
23
- }
24
- .rte-confirm-input[aria-invalid="true"] { border-color: var(--rte-confirm-danger); }
25
- .rte-confirm-error { margin: 6px 0 0; color: var(--rte-confirm-danger); font-size: 13px; }
26
- .rte-confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
27
- .rte-confirm-button {
28
- padding: 8px 14px; border-radius: 6px; font: inherit; cursor: pointer;
29
- border: 1px solid var(--rte-confirm-border); background: transparent; color: inherit;
30
- }
31
- .rte-confirm-button.primary { background: var(--rte-confirm-accent); border-color: var(--rte-confirm-accent); color: #fff; }
32
- .rte-confirm-button.danger { background: var(--rte-confirm-danger); border-color: var(--rte-confirm-danger); color: #fff; }
33
- .rte-confirm-button:focus-visible, .rte-confirm-input:focus-visible { outline: 2px solid var(--rte-confirm-accent); outline-offset: 2px; }
34
- `,document.head.appendChild(o)}function m(o,r,t){v();const e=`rte-confirm-${++g}`,c=document.createElement("div");b.initDialogOverlay(c),c.className="rte-confirm-overlay",(r.context??(document.activeElement instanceof Element?document.activeElement:null))?.closest(x)&&c.classList.add("rte-confirm-dark");const f=r.title??(t?"Enter a value":"Please confirm"),a=r.confirmText??(t?"OK":"Confirm"),l=r.cancelText??"Cancel",i=r.danger===!0,n=document.createElement("div");return n.className="rte-confirm-dialog",n.setAttribute("role",t?"dialog":"alertdialog"),n.setAttribute("aria-modal","true"),n.setAttribute("aria-labelledby",`${e}-title`),n.setAttribute("aria-describedby",`${e}-message`),n.innerHTML=`
35
- <h2 class="rte-confirm-title" id="${e}-title">${d.escapeHtml(f)}</h2>
36
- <p class="rte-confirm-message" id="${e}-message">${d.escapeHtml(o)}</p>
37
- ${t?`<label class="rte-confirm-field" for="${e}-input">${d.escapeHtml(t.label??o)}</label>
38
- <input class="rte-confirm-input" id="${e}-input" type="text" inputmode="${t.inputMode??"text"}"
39
- autocomplete="off" value="${d.escapeHtml(t.initialValue??"")}" placeholder="${d.escapeHtml(t.placeholder??"")}"
40
- aria-describedby="${e}-error">
41
- <p class="rte-confirm-error" id="${e}-error" role="alert" hidden></p>`:""}
42
- <div class="rte-confirm-actions">
43
- <button type="button" class="rte-confirm-button" data-action="cancel">${d.escapeHtml(l)}</button>
44
- <button type="button" class="rte-confirm-button ${i?"danger":"primary"}" data-action="confirm">${d.escapeHtml(a)}</button>
45
- </div>
46
- `,c.appendChild(n),{overlay:c,confirmButton:n.querySelector('[data-action="confirm"]'),cancelButton:n.querySelector('[data-action="cancel"]'),input:n.querySelector("input"),error:n.querySelector(".rte-confirm-error")}}function p(o,r){return new Promise(t=>{const{overlay:e,confirmButton:c,cancelButton:s}=o;let f=!1;const a=i=>{const n=r(i);n!==void 0&&(f||(f=!0,window.removeEventListener("keydown",l,!0),e.remove(),t(n)))},l=i=>{i.key!=="Escape"||!e.isConnected||(i.preventDefault(),i.stopPropagation(),a(!1))};window.addEventListener("keydown",l,!0),s.addEventListener("click",()=>a(!1)),c.addEventListener("click",()=>a(!0)),e.addEventListener("click",i=>{i.target===e&&a(!1)}),o.input?.addEventListener("keydown",i=>{i.key==="Enter"&&(i.preventDefault(),a(!0))}),document.body.appendChild(e)})}function y(o,r={}){const t=m(o,r,null);return p(t,e=>e)}function h(o,r={}){const t=m(o,r,r),{input:e,error:c}=t,s=p(t,f=>{if(!f)return null;const a=e?.value??"",l=r.validate?r.validate(a):null;if(l){c&&(c.textContent=l,c.hidden=!1),e?.setAttribute("aria-invalid","true"),e?.focus(),e?.select();return}return a});return window.setTimeout(()=>{e?.isConnected&&(e.focus(),e.select())},10),s}exports.confirmAction=y;exports.promptText=h;