autumnnote 2.4.0 → 2.5.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "autumnnote",
3
- "version": "2.4.0",
4
- "description": "WYSIWYG rich-text editor built with vanilla JavaScript zero dependencies, no jQuery. Dark mode, @mention, markdown shortcuts, bubble toolbar. React and Vue 3 wrappers included.",
3
+ "version": "2.5.0",
4
+ "description": "WYSIWYG rich-text editor built with vanilla JavaScript \u2014 zero dependencies, no jQuery. Dark mode, @mention, markdown shortcuts, bubble toolbar. React and Vue\u00a03 wrappers included.",
5
5
  "type": "module",
6
6
  "main": "dist/autumnnote.cjs",
7
7
  "module": "dist/autumnnote.es.js",
@@ -17,12 +17,17 @@
17
17
  "types": "./types/i18n/*.d.ts",
18
18
  "import": "./src/js/i18n/*.js"
19
19
  },
20
- "./dist/autumnnote.css": "./dist/autumnnote.css"
20
+ "./dist/autumnnote.css": "./dist/autumnnote.css",
21
+ "./core": {
22
+ "types": "./types/core-entry.d.ts",
23
+ "import": "./dist/autumnnote.core.es.js"
24
+ }
21
25
  },
22
26
  "sideEffects": [
23
27
  "*.css",
24
28
  "*.scss",
25
29
  "./src/js/index.js",
30
+ "./src/js/core.js",
26
31
  "./src/js/index.umd.js",
27
32
  "./src/js/i18n/all.js"
28
33
  ],
@@ -34,7 +39,7 @@
34
39
  ],
35
40
  "scripts": {
36
41
  "dev": "vite",
37
- "build": "vite build && vite build --config vite.umd.config.js && vite build --config vite.cdn.config.js && node scripts/create-cjs-alias.mjs",
42
+ "build": "vite build && vite build --config vite.umd.config.js && vite build --config vite.cdn.config.js && vite build --config vite.core.config.js && node scripts/create-cjs-alias.mjs",
38
43
  "build:demo": "vite build --config vite.demo.config.js",
39
44
  "preview": "vite preview",
40
45
  "prepublishOnly": "npm run build",
@@ -51,7 +56,8 @@
51
56
  "build:wrappers": "pnpm --filter autumnnote-react build && pnpm --filter autumnnote-vue build",
52
57
  "check:bundle": "node scripts/check-bundle-size.mjs",
53
58
  "check:package": "node scripts/check-package-files.mjs",
54
- "check": "pnpm lint && pnpm typecheck && pnpm test:coverage && pnpm build && pnpm test:wrappers && pnpm check:bundle && pnpm check:package && pnpm build:demo && pnpm build:wrappers"
59
+ "check": "pnpm lint && pnpm typecheck && pnpm test:coverage && pnpm build && pnpm test:wrappers && pnpm check:bundle && pnpm check:package && pnpm build:demo && pnpm build:wrappers",
60
+ "build:core": "vite build --config vite.core.config.js"
55
61
  },
56
62
  "keywords": [
57
63
  "wysiwyg",
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Heuristic programming-language detection for code snippets.
3
+ *
4
+ * Every rule that matches adds weight to its language and the highest total
5
+ * wins; the winner must also clear a minimum score and beat the runner-up by a
6
+ * margin. A snippet that could be two things returns null rather than being
7
+ * guessed at, and prose is never reported as code.
8
+ */
9
+
10
+ /** Every language `detectLang()` can return, as Prism language ids. */
11
+ export declare const SUPPORTED_LANGS: readonly string[];
12
+
13
+ /**
14
+ * Detects the language of a code snippet.
15
+ *
16
+ * Only the first few kilobytes are examined — a language is identifiable from
17
+ * its opening lines, and bounding the input keeps the cost independent of file
18
+ * size.
19
+ *
20
+ * @param code Snippet to inspect.
21
+ * @returns A Prism language id from {@link SUPPORTED_LANGS}, or null when the
22
+ * evidence is too weak or too evenly split to commit to an answer.
23
+ */
24
+ export declare function detectLang(code: string | null | undefined): string | null;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Bidirectional HTML ↔ Markdown conversion.
3
+ *
4
+ * Exposed on the package entry point so the conversion can run without an
5
+ * editor instance — a server, a build step, or a test — since the editor's
6
+ * `getMarkdown()` / `setMarkdown()` need a live DOM.
7
+ *
8
+ * `markdownToHTML()` output is NOT sanitised. Anything that will be inserted
9
+ * into a document must be passed through `sanitiseHTML()` first.
10
+ */
11
+
12
+ /**
13
+ * Converts a Markdown string to HTML.
14
+ *
15
+ * Handles ATX and setext headings, fenced code (backtick and tilde, any fence
16
+ * length, indented) and four-space indented code, blockquotes, ordered and
17
+ * unordered lists including task lists and code blocks nested in items, GFM
18
+ * tables with or without outer pipes and with column alignment, links and
19
+ * images with titles, reference links, footnotes, autolinks, character
20
+ * references, YAML frontmatter, and a leading UTF-8 byte-order mark.
21
+ *
22
+ * @param text Markdown source. A leading BOM is stripped; CRLF is normalised.
23
+ * @returns HTML. Pass through `sanitiseHTML()` before inserting it anywhere.
24
+ */
25
+ export declare function markdownToHTML(text: string | null | undefined): string;
26
+
27
+ /**
28
+ * Converts an HTML string to Markdown.
29
+ *
30
+ * Markdown syntax appearing in ordinary prose is backslash-escaped, so text
31
+ * round-trips as text rather than being re-read as formatting. Code spans and
32
+ * code blocks are emitted literally, with line breaks read from `<br>` as well
33
+ * as newlines — which is how `contenteditable` stores them.
34
+ *
35
+ * @param html HTML source.
36
+ * @returns Markdown.
37
+ */
38
+ export declare function htmlToMarkdown(html: string | null | undefined): string;
39
+
40
+ /**
41
+ * Reports whether a string looks like Markdown.
42
+ *
43
+ * Used to decide whether pasted plain text should be converted. Deliberately
44
+ * conservative: a bare URL or a parenthetical aside is prose, and a link alone
45
+ * is too weak a signal without a second marker.
46
+ *
47
+ * @param rawText Text to inspect. A leading BOM is ignored.
48
+ */
49
+ export declare function isMarkdown(rawText: string | null | undefined): boolean;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Type surface for `autumnnote/core`.
3
+ *
4
+ * Identical to the default entry: the difference is which modules are
5
+ * installed, not which API exists. Toolbar buttons whose module is absent still
6
+ * render, and invoking one logs a warning and does nothing.
7
+ */
8
+ export * from './index.js';
9
+ export { default } from './index.js';
package/types/index.d.ts CHANGED
@@ -105,9 +105,37 @@ export interface AsnOptions {
105
105
  /** Callback fired when the word limit is reached. */
106
106
  onWordLimitReached?: (context: Context) => void;
107
107
  /** Custom image upload handler. */
108
- onImageUpload?: (files: File[]) => void;
108
+ /**
109
+ * Handles files dropped, pasted, or picked in the image dialog.
110
+ *
111
+ * Return the uploaded URL — or a promise of it — and the editor inserts a
112
+ * dimmed placeholder previewing the local file straight away, then swaps in
113
+ * the real URL when the promise settles. A rejection marks the placeholder
114
+ * failed and fires `imageError` with a `retry()` for that file.
115
+ *
116
+ * Returning `undefined` keeps the original contract: nothing is inserted and
117
+ * the handler is responsible for placing the image itself.
118
+ *
119
+ * Distinct from `imageProcessor`, which transforms a file and must resolve to
120
+ * a **data URL**; this one uploads and resolves to any URL the sanitiser
121
+ * accepts.
122
+ */
123
+ onImageUpload?: (
124
+ files: File[],
125
+ helpers: {
126
+ context: Context;
127
+ /** Reports progress for one file as a 0–1 ratio, for the placeholder's bar. */
128
+ setProgress: (file: File, ratio: number) => void;
129
+ },
130
+ ) => void | string | string[] | Promise<void | string | string[]>;
109
131
  /** Callback when an image upload error occurs. */
110
- onImageError?: (error: { file?: File; message: string; error?: unknown }) => void;
132
+ onImageError?: (error: {
133
+ file?: File;
134
+ message: string;
135
+ error?: unknown;
136
+ /** Present when an upload failed: re-runs the handler for that one file. */
137
+ retry?: () => void;
138
+ }) => void;
111
139
  /** Stick the toolbar to the viewport top when scrolling. */
112
140
  stickyToolbar?: boolean;
113
141
  /** Top offset in px for sticky toolbar (e.g. height of a fixed nav bar). */
@@ -446,6 +474,8 @@ export * from './core/key.js';
446
474
  export * from './core/lists.js';
447
475
  export * from './core/env.js';
448
476
  export * from './core/sanitise.js';
477
+ export * from './core/markdown.js';
478
+ export * from './core/detectLang.js';
449
479
 
450
480
  // ---------------------------------------------------------------------------
451
481
  // Context — per-instance editor hub