quoin-editor 1.5.0 → 1.6.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 +8 -0
- package/README.md +2 -2
- package/dist/ai.cjs +0 -2
- package/dist/catalogue.cjs +5 -7
- package/dist/catalogue.js +4 -4
- package/dist/chunk-2SWLD6R5.cjs +0 -2
- package/dist/chunk-46JH34SR.cjs +0 -2
- package/dist/chunk-4T4TJ2QS.cjs +0 -2
- package/dist/chunk-A6PGQVTR.cjs +0 -2
- package/dist/chunk-AZF7B2AE.cjs +0 -2
- package/dist/chunk-BM2GRZNM.cjs +0 -2
- package/dist/chunk-H3C3MJW5.cjs +0 -2
- package/dist/{chunk-FNZGXL3O.cjs → chunk-JVSYEENH.cjs} +1 -3
- package/dist/{chunk-HVT5HAAZ.js → chunk-KFYJW7W5.js} +3 -3
- package/dist/{chunk-HVT5HAAZ.js.map → chunk-KFYJW7W5.js.map} +1 -1
- package/dist/chunk-L6RB43YM.cjs +0 -2
- package/dist/chunk-LE5XMIFJ.cjs +0 -2
- package/dist/chunk-LOP66FVU.cjs +0 -2
- package/dist/chunk-QJ34MOFV.cjs +0 -2
- package/dist/chunk-QR2NIDUK.cjs +0 -2
- package/dist/chunk-STKGRXSA.cjs +0 -2
- package/dist/chunk-T7O3BROK.cjs +0 -2
- package/dist/chunk-TKCPXUPP.cjs +0 -2
- package/dist/chunk-UUSZGUXJ.cjs +0 -2
- package/dist/chunk-VZZPCYA3.cjs +0 -2
- package/dist/chunk-WN7BZDNH.cjs +0 -2
- package/dist/chunk-WZA5S5EJ.cjs +0 -2
- package/dist/chunk-XFR7QGSN.cjs +0 -2
- package/dist/chunk-XZ4NC3Q7.cjs +0 -2
- package/dist/comments.cjs +0 -2
- package/dist/diff.cjs +0 -2
- package/dist/docx.cjs +0 -2
- package/dist/embed.cjs +0 -2
- package/dist/emoji-data.cjs +0 -2
- package/dist/emoji.cjs +0 -2
- package/dist/engine.cjs +0 -2
- package/dist/engine.d.cts +3 -15
- package/dist/engine.d.ts +3 -15
- package/dist/find.cjs +0 -2
- package/dist/headless.cjs +0 -2
- package/dist/headless.d.cts +2 -1
- package/dist/headless.d.ts +2 -1
- package/dist/highlight.cjs +0 -2
- package/dist/index.cjs +0 -2
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/math.cjs +4 -6
- package/dist/math.js +2 -2
- package/dist/mention.cjs +0 -2
- package/dist/presence.cjs +0 -2
- package/dist/prism-grammars.cjs +0 -2
- package/dist/source.cjs +97 -0
- package/dist/source.d.cts +56 -0
- package/dist/source.d.ts +56 -0
- package/dist/source.js +94 -0
- package/dist/source.js.map +1 -0
- package/dist/stats.cjs +0 -2
- package/dist/styles.css +1 -1
- package/dist/table.cjs +0 -2
- package/dist/to-markdown-BVOzhgVM.d.ts +17 -0
- package/dist/to-markdown-CFPMbbiX.d.cts +17 -0
- package/dist/toc.cjs +0 -2
- package/dist/view.cjs +0 -2
- package/dist/yjs.cjs +0 -2
- package/package.json +12 -2
- package/dist/ai.cjs.map +0 -1
- package/dist/catalogue.cjs.map +0 -1
- package/dist/chunk-2SWLD6R5.cjs.map +0 -1
- package/dist/chunk-46JH34SR.cjs.map +0 -1
- package/dist/chunk-4T4TJ2QS.cjs.map +0 -1
- package/dist/chunk-A6PGQVTR.cjs.map +0 -1
- package/dist/chunk-AZF7B2AE.cjs.map +0 -1
- package/dist/chunk-BM2GRZNM.cjs.map +0 -1
- package/dist/chunk-FNZGXL3O.cjs.map +0 -1
- package/dist/chunk-H3C3MJW5.cjs.map +0 -1
- package/dist/chunk-L6RB43YM.cjs.map +0 -1
- package/dist/chunk-LE5XMIFJ.cjs.map +0 -1
- package/dist/chunk-LOP66FVU.cjs.map +0 -1
- package/dist/chunk-QJ34MOFV.cjs.map +0 -1
- package/dist/chunk-QR2NIDUK.cjs.map +0 -1
- package/dist/chunk-STKGRXSA.cjs.map +0 -1
- package/dist/chunk-T7O3BROK.cjs.map +0 -1
- package/dist/chunk-TKCPXUPP.cjs.map +0 -1
- package/dist/chunk-UUSZGUXJ.cjs.map +0 -1
- package/dist/chunk-VZZPCYA3.cjs.map +0 -1
- package/dist/chunk-WN7BZDNH.cjs.map +0 -1
- package/dist/chunk-WZA5S5EJ.cjs.map +0 -1
- package/dist/chunk-XFR7QGSN.cjs.map +0 -1
- package/dist/chunk-XZ4NC3Q7.cjs.map +0 -1
- package/dist/comments.cjs.map +0 -1
- package/dist/diff.cjs.map +0 -1
- package/dist/docx.cjs.map +0 -1
- package/dist/embed.cjs.map +0 -1
- package/dist/emoji-data.cjs.map +0 -1
- package/dist/emoji.cjs.map +0 -1
- package/dist/engine.cjs.map +0 -1
- package/dist/find.cjs.map +0 -1
- package/dist/headless.cjs.map +0 -1
- package/dist/highlight.cjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/math.cjs.map +0 -1
- package/dist/mention.cjs.map +0 -1
- package/dist/presence.cjs.map +0 -1
- package/dist/prism-grammars.cjs.map +0 -1
- package/dist/stats.cjs.map +0 -1
- package/dist/table.cjs.map +0 -1
- package/dist/toc.cjs.map +0 -1
- package/dist/view.cjs.map +0 -1
- package/dist/yjs.cjs.map +0 -1
package/dist/math.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
export { englishMathLabels, mathExtension } from './chunk-
|
|
3
|
-
import './chunk-AD3NY7NA.js';
|
|
2
|
+
export { englishMathLabels, mathExtension } from './chunk-KFYJW7W5.js';
|
|
4
3
|
import './chunk-QOIVLYMW.js';
|
|
4
|
+
import './chunk-AD3NY7NA.js';
|
|
5
5
|
import './chunk-32OZ2WM2.js';
|
|
6
6
|
import './chunk-XFEDJEJF.js';
|
|
7
7
|
import './chunk-HDJ653LM.js';
|
package/dist/mention.cjs
CHANGED
package/dist/presence.cjs
CHANGED
package/dist/prism-grammars.cjs
CHANGED
package/dist/source.cjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
require('./chunk-UUSZGUXJ.cjs');
|
|
5
|
+
require('./chunk-QJ34MOFV.cjs');
|
|
6
|
+
require('./chunk-A6PGQVTR.cjs');
|
|
7
|
+
var chunkVZZPCYA3_cjs = require('./chunk-VZZPCYA3.cjs');
|
|
8
|
+
require('./chunk-BM2GRZNM.cjs');
|
|
9
|
+
require('./chunk-WZA5S5EJ.cjs');
|
|
10
|
+
var react = require('react');
|
|
11
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
12
|
+
|
|
13
|
+
// src/extensions/source/source-labels.ts
|
|
14
|
+
var englishSourceLabels = { region: "Markdown source" };
|
|
15
|
+
function resolveSourceLabels(overrides) {
|
|
16
|
+
if (overrides === void 0) return englishSourceLabels;
|
|
17
|
+
const given = Object.entries(overrides).filter(([, value]) => value !== void 0);
|
|
18
|
+
return given.length === 0 ? englishSourceLabels : { ...englishSourceLabels, ...Object.fromEntries(given) };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/extensions/source/source-lines.ts
|
|
22
|
+
var lineCount = (text) => text.split("\n").length - 1;
|
|
23
|
+
var withoutTrailingNewlines = (text) => text.replace(/\n+$/, "");
|
|
24
|
+
function blockLines(blocks, index, options) {
|
|
25
|
+
if (!Number.isInteger(index) || index < 0 || index >= blocks.length) return null;
|
|
26
|
+
const before = withoutTrailingNewlines(chunkVZZPCYA3_cjs.toMarkdown(blocks.slice(0, index), options));
|
|
27
|
+
const through = chunkVZZPCYA3_cjs.toMarkdown(blocks.slice(0, index + 1), options);
|
|
28
|
+
const separator = /^\n*/.exec(through.slice(before.length))?.[0].length ?? 0;
|
|
29
|
+
return { from: lineCount(before) + separator, to: lineCount(withoutTrailingNewlines(through)) };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/extensions/source/use-editor-source.ts
|
|
33
|
+
function sourceOf(editor, given) {
|
|
34
|
+
const blocks = editor.getBlocks();
|
|
35
|
+
const options = { ...given, schema: editor.state.schema };
|
|
36
|
+
const [id] = chunkVZZPCYA3_cjs.selectedBlockIds(editor.state.doc, editor.state.selection);
|
|
37
|
+
const index = id === void 0 ? -1 : blocks.findIndex((block) => block.id === id);
|
|
38
|
+
return { markdown: chunkVZZPCYA3_cjs.toMarkdown(blocks, options), active: blockLines(blocks, index, options) };
|
|
39
|
+
}
|
|
40
|
+
var sameSource = (a, b) => a.markdown === b.markdown && a.active?.from === b.active?.from && a.active?.to === b.active?.to;
|
|
41
|
+
function useEditorSource(controller, options = {}) {
|
|
42
|
+
const { comments, lossless, resolveAssetUrl } = options;
|
|
43
|
+
const settings = react.useMemo(
|
|
44
|
+
() => ({ comments, lossless, resolveAssetUrl }),
|
|
45
|
+
[comments, lossless, resolveAssetUrl]
|
|
46
|
+
);
|
|
47
|
+
const [source, setSource] = react.useState(() => sourceOf(controller.editor, settings));
|
|
48
|
+
react.useEffect(() => {
|
|
49
|
+
const { editor } = controller;
|
|
50
|
+
let frame = 0;
|
|
51
|
+
const reread = () => {
|
|
52
|
+
frame = 0;
|
|
53
|
+
const next = sourceOf(editor, settings);
|
|
54
|
+
setSource((current) => sameSource(current, next) ? current : next);
|
|
55
|
+
};
|
|
56
|
+
reread();
|
|
57
|
+
const stop = editor.subscribe(() => {
|
|
58
|
+
if (frame === 0) frame = requestAnimationFrame(reread);
|
|
59
|
+
});
|
|
60
|
+
return () => {
|
|
61
|
+
stop();
|
|
62
|
+
cancelAnimationFrame(frame);
|
|
63
|
+
};
|
|
64
|
+
}, [controller, settings]);
|
|
65
|
+
return source;
|
|
66
|
+
}
|
|
67
|
+
function QuoinSource({ controller, options, labels: given, className, ...props }) {
|
|
68
|
+
const labels = react.useMemo(() => resolveSourceLabels(given), [given]);
|
|
69
|
+
const { markdown, active } = useEditorSource(controller, options);
|
|
70
|
+
const lines = react.useMemo(() => markdown === "" ? [] : markdown.replace(/\n$/, "").split("\n"), [markdown]);
|
|
71
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
72
|
+
"div",
|
|
73
|
+
{
|
|
74
|
+
...props,
|
|
75
|
+
role: "region",
|
|
76
|
+
"aria-label": labels.region,
|
|
77
|
+
tabIndex: 0,
|
|
78
|
+
className: className === void 0 ? "quoin-source" : `quoin-source ${className}`,
|
|
79
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "quoin-source-text", children: lines.map((line, index) => /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
|
|
80
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
81
|
+
"span",
|
|
82
|
+
{
|
|
83
|
+
"data-quoin-source-line": index,
|
|
84
|
+
className: active && index >= active.from && index <= active.to ? "quoin-source-active" : void 0,
|
|
85
|
+
children: line
|
|
86
|
+
}
|
|
87
|
+
),
|
|
88
|
+
"\n"
|
|
89
|
+
] }, index)) })
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
exports.QuoinSource = QuoinSource;
|
|
95
|
+
exports.blockLines = blockLines;
|
|
96
|
+
exports.englishSourceLabels = englishSourceLabels;
|
|
97
|
+
exports.useEditorSource = useEditorSource;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentPropsWithoutRef } from 'react';
|
|
3
|
+
import { ViewController } from './headless.cjs';
|
|
4
|
+
import { ToMarkdownOptions } from './engine.cjs';
|
|
5
|
+
import { QuoinBlock } from './engine.cjs';
|
|
6
|
+
import './types-DXF9p4qV.cjs';
|
|
7
|
+
|
|
8
|
+
/** Every string the markdown source pane shows or speaks. */
|
|
9
|
+
type SourceLabels = {
|
|
10
|
+
/** The accessible name of the pane. */
|
|
11
|
+
region: string;
|
|
12
|
+
};
|
|
13
|
+
declare const englishSourceLabels: SourceLabels;
|
|
14
|
+
|
|
15
|
+
/** The lines of the document's markdown a block is drawn on, both ends counted from zero and both inside the block. */
|
|
16
|
+
type LineSpan = {
|
|
17
|
+
readonly from: number;
|
|
18
|
+
readonly to: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Where a block lands in the markdown of the whole document, read from the length of the document's prefixes: the
|
|
22
|
+
* markdown of the blocks before it is a prefix of the whole, so the lines it adds are the block's own, less the blank
|
|
23
|
+
* lines that separate it from the block above. Blocks are not serialised one by one, because a list item reads the
|
|
24
|
+
* items above it and so spells itself differently alone.
|
|
25
|
+
*/
|
|
26
|
+
declare function blockLines(blocks: readonly QuoinBlock[], index: number, options?: ToMarkdownOptions): LineSpan | null;
|
|
27
|
+
|
|
28
|
+
/** The document as markdown, and the lines of it the caret's block is drawn on. */
|
|
29
|
+
type EditorSource = {
|
|
30
|
+
readonly markdown: string;
|
|
31
|
+
readonly active: LineSpan | null;
|
|
32
|
+
};
|
|
33
|
+
/** How the pane writes the markdown. Pass what the canvas was given, so the pane reads as the document is stored. */
|
|
34
|
+
type SourceOptions = Pick<ToMarkdownOptions, 'comments' | 'lossless' | 'resolveAssetUrl'>;
|
|
35
|
+
/**
|
|
36
|
+
* The markdown of the document of `controller`, the one a canvas handle or `useViewController()` gives, as `onChange`
|
|
37
|
+
* would hand it back, with the lines the caret's block is drawn on. Read again at most once per animation frame
|
|
38
|
+
* however many edits or caret moves it holds.
|
|
39
|
+
*/
|
|
40
|
+
declare function useEditorSource(controller: ViewController, options?: SourceOptions): EditorSource;
|
|
41
|
+
|
|
42
|
+
type QuoinSourceProps = Omit<ComponentPropsWithoutRef<'div'>, 'children'> & {
|
|
43
|
+
controller: ViewController;
|
|
44
|
+
/** How the markdown is written. Pass what the canvas was given, so the pane reads as the document is stored. */
|
|
45
|
+
options?: SourceOptions;
|
|
46
|
+
/** Every string the pane shows or speaks, English by default. A key left out stays English. */
|
|
47
|
+
labels?: Partial<SourceLabels>;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* The document of `controller` as the markdown it is stored as, read only, with the block holding the caret marked.
|
|
51
|
+
* Place it beside or below the canvas; the controller is the one a `BlockCanvas` handle gives.
|
|
52
|
+
*/
|
|
53
|
+
declare function QuoinSource({ controller, options, labels: given, className, ...props }: QuoinSourceProps): react.JSX.Element;
|
|
54
|
+
|
|
55
|
+
export { QuoinSource, blockLines, englishSourceLabels, useEditorSource };
|
|
56
|
+
export type { EditorSource, LineSpan, QuoinSourceProps, SourceLabels };
|
package/dist/source.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentPropsWithoutRef } from 'react';
|
|
3
|
+
import { ViewController } from './headless.js';
|
|
4
|
+
import { ToMarkdownOptions } from './engine.js';
|
|
5
|
+
import { QuoinBlock } from './engine.js';
|
|
6
|
+
import './types-BjLcmV00.js';
|
|
7
|
+
|
|
8
|
+
/** Every string the markdown source pane shows or speaks. */
|
|
9
|
+
type SourceLabels = {
|
|
10
|
+
/** The accessible name of the pane. */
|
|
11
|
+
region: string;
|
|
12
|
+
};
|
|
13
|
+
declare const englishSourceLabels: SourceLabels;
|
|
14
|
+
|
|
15
|
+
/** The lines of the document's markdown a block is drawn on, both ends counted from zero and both inside the block. */
|
|
16
|
+
type LineSpan = {
|
|
17
|
+
readonly from: number;
|
|
18
|
+
readonly to: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Where a block lands in the markdown of the whole document, read from the length of the document's prefixes: the
|
|
22
|
+
* markdown of the blocks before it is a prefix of the whole, so the lines it adds are the block's own, less the blank
|
|
23
|
+
* lines that separate it from the block above. Blocks are not serialised one by one, because a list item reads the
|
|
24
|
+
* items above it and so spells itself differently alone.
|
|
25
|
+
*/
|
|
26
|
+
declare function blockLines(blocks: readonly QuoinBlock[], index: number, options?: ToMarkdownOptions): LineSpan | null;
|
|
27
|
+
|
|
28
|
+
/** The document as markdown, and the lines of it the caret's block is drawn on. */
|
|
29
|
+
type EditorSource = {
|
|
30
|
+
readonly markdown: string;
|
|
31
|
+
readonly active: LineSpan | null;
|
|
32
|
+
};
|
|
33
|
+
/** How the pane writes the markdown. Pass what the canvas was given, so the pane reads as the document is stored. */
|
|
34
|
+
type SourceOptions = Pick<ToMarkdownOptions, 'comments' | 'lossless' | 'resolveAssetUrl'>;
|
|
35
|
+
/**
|
|
36
|
+
* The markdown of the document of `controller`, the one a canvas handle or `useViewController()` gives, as `onChange`
|
|
37
|
+
* would hand it back, with the lines the caret's block is drawn on. Read again at most once per animation frame
|
|
38
|
+
* however many edits or caret moves it holds.
|
|
39
|
+
*/
|
|
40
|
+
declare function useEditorSource(controller: ViewController, options?: SourceOptions): EditorSource;
|
|
41
|
+
|
|
42
|
+
type QuoinSourceProps = Omit<ComponentPropsWithoutRef<'div'>, 'children'> & {
|
|
43
|
+
controller: ViewController;
|
|
44
|
+
/** How the markdown is written. Pass what the canvas was given, so the pane reads as the document is stored. */
|
|
45
|
+
options?: SourceOptions;
|
|
46
|
+
/** Every string the pane shows or speaks, English by default. A key left out stays English. */
|
|
47
|
+
labels?: Partial<SourceLabels>;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* The document of `controller` as the markdown it is stored as, read only, with the block holding the caret marked.
|
|
51
|
+
* Place it beside or below the canvas; the controller is the one a `BlockCanvas` handle gives.
|
|
52
|
+
*/
|
|
53
|
+
declare function QuoinSource({ controller, options, labels: given, className, ...props }: QuoinSourceProps): react.JSX.Element;
|
|
54
|
+
|
|
55
|
+
export { QuoinSource, blockLines, englishSourceLabels, useEditorSource };
|
|
56
|
+
export type { EditorSource, LineSpan, QuoinSourceProps, SourceLabels };
|
package/dist/source.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import './chunk-32OZ2WM2.js';
|
|
3
|
+
import './chunk-XFEDJEJF.js';
|
|
4
|
+
import './chunk-HDJ653LM.js';
|
|
5
|
+
import { toMarkdown, selectedBlockIds } from './chunk-OS2O6IKX.js';
|
|
6
|
+
import './chunk-CSKKSXCE.js';
|
|
7
|
+
import './chunk-BJTOLCRR.js';
|
|
8
|
+
import { useMemo, useState, useEffect, Fragment } from 'react';
|
|
9
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
10
|
+
|
|
11
|
+
// src/extensions/source/source-labels.ts
|
|
12
|
+
var englishSourceLabels = { region: "Markdown source" };
|
|
13
|
+
function resolveSourceLabels(overrides) {
|
|
14
|
+
if (overrides === void 0) return englishSourceLabels;
|
|
15
|
+
const given = Object.entries(overrides).filter(([, value]) => value !== void 0);
|
|
16
|
+
return given.length === 0 ? englishSourceLabels : { ...englishSourceLabels, ...Object.fromEntries(given) };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/extensions/source/source-lines.ts
|
|
20
|
+
var lineCount = (text) => text.split("\n").length - 1;
|
|
21
|
+
var withoutTrailingNewlines = (text) => text.replace(/\n+$/, "");
|
|
22
|
+
function blockLines(blocks, index, options) {
|
|
23
|
+
if (!Number.isInteger(index) || index < 0 || index >= blocks.length) return null;
|
|
24
|
+
const before = withoutTrailingNewlines(toMarkdown(blocks.slice(0, index), options));
|
|
25
|
+
const through = toMarkdown(blocks.slice(0, index + 1), options);
|
|
26
|
+
const separator = /^\n*/.exec(through.slice(before.length))?.[0].length ?? 0;
|
|
27
|
+
return { from: lineCount(before) + separator, to: lineCount(withoutTrailingNewlines(through)) };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/extensions/source/use-editor-source.ts
|
|
31
|
+
function sourceOf(editor, given) {
|
|
32
|
+
const blocks = editor.getBlocks();
|
|
33
|
+
const options = { ...given, schema: editor.state.schema };
|
|
34
|
+
const [id] = selectedBlockIds(editor.state.doc, editor.state.selection);
|
|
35
|
+
const index = id === void 0 ? -1 : blocks.findIndex((block) => block.id === id);
|
|
36
|
+
return { markdown: toMarkdown(blocks, options), active: blockLines(blocks, index, options) };
|
|
37
|
+
}
|
|
38
|
+
var sameSource = (a, b) => a.markdown === b.markdown && a.active?.from === b.active?.from && a.active?.to === b.active?.to;
|
|
39
|
+
function useEditorSource(controller, options = {}) {
|
|
40
|
+
const { comments, lossless, resolveAssetUrl } = options;
|
|
41
|
+
const settings = useMemo(
|
|
42
|
+
() => ({ comments, lossless, resolveAssetUrl }),
|
|
43
|
+
[comments, lossless, resolveAssetUrl]
|
|
44
|
+
);
|
|
45
|
+
const [source, setSource] = useState(() => sourceOf(controller.editor, settings));
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
const { editor } = controller;
|
|
48
|
+
let frame = 0;
|
|
49
|
+
const reread = () => {
|
|
50
|
+
frame = 0;
|
|
51
|
+
const next = sourceOf(editor, settings);
|
|
52
|
+
setSource((current) => sameSource(current, next) ? current : next);
|
|
53
|
+
};
|
|
54
|
+
reread();
|
|
55
|
+
const stop = editor.subscribe(() => {
|
|
56
|
+
if (frame === 0) frame = requestAnimationFrame(reread);
|
|
57
|
+
});
|
|
58
|
+
return () => {
|
|
59
|
+
stop();
|
|
60
|
+
cancelAnimationFrame(frame);
|
|
61
|
+
};
|
|
62
|
+
}, [controller, settings]);
|
|
63
|
+
return source;
|
|
64
|
+
}
|
|
65
|
+
function QuoinSource({ controller, options, labels: given, className, ...props }) {
|
|
66
|
+
const labels = useMemo(() => resolveSourceLabels(given), [given]);
|
|
67
|
+
const { markdown, active } = useEditorSource(controller, options);
|
|
68
|
+
const lines = useMemo(() => markdown === "" ? [] : markdown.replace(/\n$/, "").split("\n"), [markdown]);
|
|
69
|
+
return /* @__PURE__ */ jsx(
|
|
70
|
+
"div",
|
|
71
|
+
{
|
|
72
|
+
...props,
|
|
73
|
+
role: "region",
|
|
74
|
+
"aria-label": labels.region,
|
|
75
|
+
tabIndex: 0,
|
|
76
|
+
className: className === void 0 ? "quoin-source" : `quoin-source ${className}`,
|
|
77
|
+
children: /* @__PURE__ */ jsx("pre", { className: "quoin-source-text", children: lines.map((line, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
78
|
+
/* @__PURE__ */ jsx(
|
|
79
|
+
"span",
|
|
80
|
+
{
|
|
81
|
+
"data-quoin-source-line": index,
|
|
82
|
+
className: active && index >= active.from && index <= active.to ? "quoin-source-active" : void 0,
|
|
83
|
+
children: line
|
|
84
|
+
}
|
|
85
|
+
),
|
|
86
|
+
"\n"
|
|
87
|
+
] }, index)) })
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { QuoinSource, blockLines, englishSourceLabels, useEditorSource };
|
|
93
|
+
//# sourceMappingURL=source.js.map
|
|
94
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/extensions/source/source-labels.ts","../src/extensions/source/source-lines.ts","../src/extensions/source/use-editor-source.ts","../src/extensions/source/QuoinSource.tsx"],"names":["useMemo"],"mappings":";;;;;;;;;;;AAMO,IAAM,sBAAoC,EAAE,QAAQ;AAGpD,SAAS,oBAAoB,WAAiD;AACnF,MAAI,cAAc,QAAW,OAAO;AACpC,QAAM,QAAQ,OAAO,QAAQ,SAAS,EAAE,OAAO,CAAC,GAAG,KAAK,MAAM,UAAU,MAAS;AACjF,SAAO,MAAM,WAAW,IAAI,sBAAsB,EAAE,GAAG,qBAAqB,GAAG,OAAO,YAAY,KAAK,GAAE;AAC3G;;;ACRA,IAAM,YAAY,CAAC,SAAyB,KAAK,MAAM,IAAI,EAAE,SAAS;AAGtE,IAAM,0BAA0B,CAAC,SAAyB,KAAK,QAAQ,QAAQ,EAAE;AAQ1E,SAAS,WACd,QACA,OACA,SACiB;AACjB,MAAI,CAAC,OAAO,UAAU,KAAK,KAAK,QAAQ,KAAK,SAAS,OAAO,QAAQ,OAAO;AAC5E,QAAM,SAAS,wBAAwB,WAAW,OAAO,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;AAClF,QAAM,UAAU,WAAW,OAAO,MAAM,GAAG,QAAQ,CAAC,GAAG,OAAO;AAC9D,QAAM,YAAY,OAAO,KAAK,QAAQ,MAAM,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,UAAU;AAC3E,SAAO,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