tosijs-ui 1.6.21 → 1.6.23
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 +97 -0
- package/dist/code-editor.d.ts +9 -35
- package/dist/code-editor.js +62 -90
- package/dist/doc-browser.js +6 -3
- package/dist/doc-system/doc-title.d.ts +19 -0
- package/dist/doc-system/doc-title.js +51 -0
- package/dist/doc-system/site/check-examples-cli.d.ts +1 -0
- package/dist/doc-system/site/check-examples-cli.js +39 -0
- package/dist/doc-system/site/dev-server.d.ts +26 -0
- package/dist/doc-system/site/dev-server.js +444 -19
- package/dist/doc-system/site/epub-cli.d.ts +1 -0
- package/dist/doc-system/site/epub-cli.js +22 -0
- package/dist/doc-system/site/epub.js +6 -0
- package/dist/doc-system/site/generate-site.js +4 -6
- package/dist/doc-system/site/make-llms-txt.js +0 -16
- package/dist/doc-system/site/orchestrator.js +176 -52
- package/dist/doc-system/site/preflight.d.ts +152 -0
- package/dist/doc-system/site/preflight.js +401 -0
- package/dist/doc-system/site/site-config.d.ts +34 -0
- package/dist/iife.js +109 -153
- package/dist/iife.js.map +9 -36
- package/dist/live-example/component.d.ts +0 -1
- package/dist/live-example/component.js +22 -200
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/llms.txt +2 -9
- package/package.json +3 -18
- package/tls/create-dev-certs.sh +9 -25
- package/dist/code-editor-cm.d.ts +0 -48
- package/dist/code-editor-cm.js +0 -219
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.6.
|
|
1
|
+
export declare const version = "1.6.23";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.6.
|
|
1
|
+
export const version = '1.6.23';
|
package/llms.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# tosijs-ui v1.6.
|
|
1
|
+
# tosijs-ui v1.6.23
|
|
2
2
|
|
|
3
3
|
Simple, robust web-components for use with tosijs or anything else.
|
|
4
4
|
|
|
@@ -10,13 +10,6 @@ Simple, robust web-components for use with tosijs or anything else.
|
|
|
10
10
|
|
|
11
11
|
Full documentation, with live code examples, is at the links below.
|
|
12
12
|
|
|
13
|
-
Live examples run inline on the shared page by default (not sandboxed):
|
|
14
|
-
each has its own `preview` element, but they share one tosijs module, so
|
|
15
|
-
`tosi()` state singletons are shared across every example on a page. This is
|
|
16
|
-
deliberate (it shows tosi isolation and lets you drive demos via the global
|
|
17
|
-
singleton). Namespace example state with unique top-level keys so examples
|
|
18
|
-
don't clobber each other; the `iframe` attribute isolates DOM/CSS, not state.
|
|
19
|
-
|
|
20
13
|
## Pages
|
|
21
14
|
|
|
22
15
|
- https://ui.tosijs.net/babylon-3d/ — 3d
|
|
@@ -30,7 +23,7 @@ don't clobber each other; the `iframe` attribute isolates DOM/CSS, not state.
|
|
|
30
23
|
- https://ui.tosijs.net/carousel/ — carousel
|
|
31
24
|
This is a minimalist carousel component that supports the usual stuff.
|
|
32
25
|
- https://ui.tosijs.net/code-editor/ — code
|
|
33
|
-
|
|
26
|
+
An [ACE Editor](https://ace.c9.io/) wrapper.
|
|
34
27
|
- https://ui.tosijs.net/color-input/ — color input field
|
|
35
28
|
This is a color input field that supports opacity
|
|
36
29
|
- https://ui.tosijs.net/components/ — Components
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tosijs-ui",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.23",
|
|
4
4
|
"description": "simple robust web-components for use with tosijs or anything else",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "bun --watch bin/dev.ts",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"playwright": "^1.58.2",
|
|
44
44
|
"prettier": "^2.8.8",
|
|
45
45
|
"tjs-lang": "0.9.0",
|
|
46
|
-
"tosijs": "^1.6.
|
|
46
|
+
"tosijs": "^1.6.9",
|
|
47
47
|
"typescript": "^5.9.3",
|
|
48
48
|
"typescript-eslint": "^8"
|
|
49
49
|
},
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"happy-dom": "^20.7.0",
|
|
53
53
|
"marked": "^16.4.2",
|
|
54
54
|
"tjs-lang": "^0.9.0",
|
|
55
|
-
"tosijs": "^1.6.
|
|
55
|
+
"tosijs": "^1.6.9"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"@resvg/resvg-js": {
|
|
@@ -127,20 +127,5 @@
|
|
|
127
127
|
"import": "./dist/*.js",
|
|
128
128
|
"default": "./dist/*.js"
|
|
129
129
|
}
|
|
130
|
-
},
|
|
131
|
-
"dependencies": {
|
|
132
|
-
"@codemirror/autocomplete": "^6.20.3",
|
|
133
|
-
"@codemirror/commands": "^6.10.4",
|
|
134
|
-
"@codemirror/lang-css": "^6.3.1",
|
|
135
|
-
"@codemirror/lang-html": "^6.4.11",
|
|
136
|
-
"@codemirror/lang-javascript": "^6.2.5",
|
|
137
|
-
"@codemirror/lang-markdown": "^6.5.0",
|
|
138
|
-
"@codemirror/language": "^6.12.4",
|
|
139
|
-
"@codemirror/lint": "^6.9.7",
|
|
140
|
-
"@codemirror/search": "^6.7.1",
|
|
141
|
-
"@codemirror/state": "^6.7.0",
|
|
142
|
-
"@codemirror/theme-one-dark": "^6.1.3",
|
|
143
|
-
"@codemirror/view": "^6.43.4",
|
|
144
|
-
"codemirror": "^6.0.2"
|
|
145
130
|
}
|
|
146
131
|
}
|
package/tls/create-dev-certs.sh
CHANGED
|
@@ -50,38 +50,22 @@ fi
|
|
|
50
50
|
# Trust the local CA (idempotent — safe to run every time).
|
|
51
51
|
mkcert -install
|
|
52
52
|
|
|
53
|
-
# Bonjour/mDNS name of this machine, so the same cert works when another
|
|
54
|
-
# on the LAN hits https://<name>.local:8787.
|
|
55
|
-
# LocalHostName (`scutil --get LocalHostName`), e.g. "Persiflex" → persiflex.local.
|
|
56
|
-
#
|
|
57
|
-
# Hardened: lowercase it (the mDNS convention, and dodges any case-sensitive
|
|
58
|
-
# client), strip a `.local` the source may already carry (no `foo.local.local`),
|
|
59
|
-
# and only add it when we actually have a usable name — so a machine with no
|
|
60
|
-
# LocalHostName never gets a bare ".local" SAN.
|
|
53
|
+
# Bonjour/mDNS name of this machine, so the same cert works when another
|
|
54
|
+
# device on the LAN hits https://<name>.local:8787.
|
|
61
55
|
if [[ "$(uname)" == "Darwin" ]]; then
|
|
62
|
-
|
|
63
|
-
[[ -z "$MDNS" ]] && MDNS="$(hostname -s 2>/dev/null || true)"
|
|
56
|
+
LOCAL_NAME="$(scutil --get LocalHostName 2>/dev/null || hostname -s).local"
|
|
64
57
|
else
|
|
65
|
-
|
|
66
|
-
fi
|
|
67
|
-
MDNS="$(printf '%s' "$MDNS" | tr '[:upper:]' '[:lower:]' | sed -E 's/\.local$//')"
|
|
68
|
-
|
|
69
|
-
NAMES=(localhost 127.0.0.1 ::1)
|
|
70
|
-
LOCAL_NAME=""
|
|
71
|
-
if [[ -n "$MDNS" && "$MDNS" != "localhost" ]]; then
|
|
72
|
-
LOCAL_NAME="${MDNS}.local"
|
|
73
|
-
NAMES+=("$LOCAL_NAME")
|
|
58
|
+
LOCAL_NAME="$(hostname -s).local"
|
|
74
59
|
fi
|
|
75
60
|
|
|
76
|
-
mkcert
|
|
61
|
+
mkcert \
|
|
62
|
+
-key-file key.pem \
|
|
63
|
+
-cert-file certificate.pem \
|
|
64
|
+
localhost 127.0.0.1 ::1 "$LOCAL_NAME"
|
|
77
65
|
|
|
78
66
|
echo
|
|
79
67
|
echo "Wrote tls/key.pem and tls/certificate.pem"
|
|
80
|
-
echo "Valid for: $
|
|
81
|
-
if [[ -z "$LOCAL_NAME" ]]; then
|
|
82
|
-
echo "(No Bonjour/.local name detected — set one in System Settings > Sharing"
|
|
83
|
-
echo " > Local hostname, then re-run to cover https://<name>.local.)"
|
|
84
|
-
fi
|
|
68
|
+
echo "Valid for: localhost, 127.0.0.1, ::1, $LOCAL_NAME"
|
|
85
69
|
echo
|
|
86
70
|
echo "Local browsers: no warnings."
|
|
87
71
|
echo "Other devices (phone, another laptop): copy the CA root to each and trust it —"
|
package/dist/code-editor-cm.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { EditorView } from '@codemirror/view';
|
|
2
|
-
import { Extension } from '@codemirror/state';
|
|
3
|
-
/** Map a `<tosi-code mode>` value to a CodeMirror language extension. */
|
|
4
|
-
export declare function languageForMode(mode: string): Extension;
|
|
5
|
-
/** Runtime-introspection hooks for tjs autocomplete (all optional). */
|
|
6
|
-
export interface TjsAutocompleteConfig {
|
|
7
|
-
getMetadata?: () => Record<string, unknown> | undefined;
|
|
8
|
-
getImports?: () => Record<string, Record<string, unknown>> | undefined;
|
|
9
|
-
getLiveBindings?: () => Record<string, unknown> | undefined;
|
|
10
|
-
getMembers?: (path: string) => Promise<unknown[] | undefined>;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Lazy-load tjs-lang's CodeMirror language + completion bundle. Returns a single
|
|
14
|
-
* CodeMirror `Extension` (tjs language, forbidden-keyword highlighting, theme, and
|
|
15
|
-
* `tjsCompletionSource`-driven autocomplete) suitable for `setLanguageExtension()`,
|
|
16
|
-
* or `null` when tjs-lang (an optional peer) isn't installed or its editor build
|
|
17
|
-
* lacks `tjsEditorExtension`. The dynamic import keeps it out of the bundle until a
|
|
18
|
-
* tjs editor actually mounts.
|
|
19
|
-
*/
|
|
20
|
-
export declare function loadTjsExtension(autocomplete?: TjsAutocompleteConfig): Promise<Extension | null>;
|
|
21
|
-
export interface CmHandle {
|
|
22
|
-
view: EditorView;
|
|
23
|
-
getValue(): string;
|
|
24
|
-
setValue(text: string): void;
|
|
25
|
-
setMode(mode: string): void;
|
|
26
|
-
/** Swap the language compartment wholesale (e.g. an async-loaded tjs bundle). */
|
|
27
|
-
setLanguageExtension(ext: Extension): void;
|
|
28
|
-
setReadOnly(readOnly: boolean): void;
|
|
29
|
-
undo(): void;
|
|
30
|
-
redo(): void;
|
|
31
|
-
canUndo(): boolean;
|
|
32
|
-
canRedo(): boolean;
|
|
33
|
-
focus(): void;
|
|
34
|
-
refresh(): void;
|
|
35
|
-
destroy(): void;
|
|
36
|
-
}
|
|
37
|
-
export interface CmOptions {
|
|
38
|
-
value?: string;
|
|
39
|
-
mode?: string;
|
|
40
|
-
readOnly?: boolean;
|
|
41
|
-
/** additional language-adjacent extensions (e.g. a tjs language + autocomplete) */
|
|
42
|
-
languageExtension?: Extension;
|
|
43
|
-
onChange?: (value: string) => void;
|
|
44
|
-
/** style-injection root — pass the host's ShadowRoot when mounted in shadow DOM */
|
|
45
|
-
root?: Document | ShadowRoot;
|
|
46
|
-
}
|
|
47
|
-
/** Create a CodeMirror editor mounted in `parent`, returning an editor-agnostic handle. */
|
|
48
|
-
export declare function createCmEditor(parent: HTMLElement, opts?: CmOptions): CmHandle;
|
package/dist/code-editor-cm.js
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
CodeMirror 6 editor factory — the "heavy" module.
|
|
3
|
-
|
|
4
|
-
`code-editor.ts` imports this **dynamically** (on first `<tosi-code>` connect), so
|
|
5
|
-
CodeMirror only enters a consumer's bundle as a separate lazy chunk when the editor
|
|
6
|
-
is actually used — mirroring the way the old ACE build loaded from a CDN on first
|
|
7
|
-
use. No `<tosi-code>` in the page → no CodeMirror.
|
|
8
|
-
|
|
9
|
-
Languages here are the always-available set (js/ts/css/html/markdown). First-class
|
|
10
|
-
tjs (highlighting + runtime-value autocomplete via tjs-lang's editors/codemirror) is
|
|
11
|
-
layered in separately and only when tjs-lang is installed.
|
|
12
|
-
*/
|
|
13
|
-
import { EditorView, keymap, lineNumbers, highlightActiveLineGutter, highlightSpecialChars, drawSelection, dropCursor, rectangularSelection, crosshairCursor, highlightActiveLine } from '@codemirror/view';
|
|
14
|
-
import { EditorState, Compartment } from '@codemirror/state';
|
|
15
|
-
import { indentWithTab, history, defaultKeymap, historyKeymap, undo, redo, undoDepth, redoDepth } from '@codemirror/commands';
|
|
16
|
-
import { indentUnit, foldGutter, foldKeymap, indentOnInput, syntaxHighlighting, defaultHighlightStyle, bracketMatching } from '@codemirror/language';
|
|
17
|
-
import { closeBrackets, closeBracketsKeymap, autocompletion, completionKeymap } from '@codemirror/autocomplete';
|
|
18
|
-
import { searchKeymap, highlightSelectionMatches } from '@codemirror/search';
|
|
19
|
-
import { lintKeymap } from '@codemirror/lint';
|
|
20
|
-
import { javascript } from '@codemirror/lang-javascript';
|
|
21
|
-
import { css } from '@codemirror/lang-css';
|
|
22
|
-
import { html } from '@codemirror/lang-html';
|
|
23
|
-
import { markdown } from '@codemirror/lang-markdown';
|
|
24
|
-
import { oneDarkHighlightStyle } from '@codemirror/theme-one-dark';
|
|
25
|
-
// The doc-system flips dark mode with a `darkmode` class on <body> (which inverts
|
|
26
|
-
// the luminance of --code-bg / --text-color, so the editor SURFACE adapts for
|
|
27
|
-
// free). Only CM's syntax-token colors need swapping: the light defaultHighlightStyle
|
|
28
|
-
// washes out on a dark surface, so use oneDark's brighter palette in dark mode.
|
|
29
|
-
const isDarkMode = () => typeof document !== 'undefined' &&
|
|
30
|
-
!!document.body &&
|
|
31
|
-
document.body.classList.contains('darkmode');
|
|
32
|
-
const highlightFor = (dark) => dark
|
|
33
|
-
? syntaxHighlighting(oneDarkHighlightStyle)
|
|
34
|
-
: syntaxHighlighting(defaultHighlightStyle, { fallback: true });
|
|
35
|
-
const isTjsMode = (mode) => mode === 'tjs' || mode === 'ajs';
|
|
36
|
-
/** Map a `<tosi-code mode>` value to a CodeMirror language extension. */
|
|
37
|
-
export function languageForMode(mode) {
|
|
38
|
-
switch (mode) {
|
|
39
|
-
case 'js':
|
|
40
|
-
case 'javascript':
|
|
41
|
-
return javascript();
|
|
42
|
-
case 'ts':
|
|
43
|
-
case 'typescript':
|
|
44
|
-
// tjs highlights as TypeScript here (the sync default). First-class tjs — the
|
|
45
|
-
// tjs-lang language + autocomplete — is layered on asynchronously via
|
|
46
|
-
// `loadTjsExtension()` + `setLanguageExtension()`, since it lazy-loads the
|
|
47
|
-
// (optional) tjs-lang editor build; this keeps `mode="tjs"` readable meanwhile.
|
|
48
|
-
case 'tjs':
|
|
49
|
-
case 'ajs':
|
|
50
|
-
return javascript({ typescript: true });
|
|
51
|
-
case 'css':
|
|
52
|
-
return css();
|
|
53
|
-
case 'html':
|
|
54
|
-
return html();
|
|
55
|
-
case 'md':
|
|
56
|
-
case 'markdown':
|
|
57
|
-
return markdown();
|
|
58
|
-
default:
|
|
59
|
-
return javascript();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// The language compartment carries the language AND its completion source, so
|
|
63
|
-
// exactly ONE `autocompletion()` is ever active: standard modes use CM's built-in
|
|
64
|
-
// (language-provided) completions here, while the tjs bundle brings its own
|
|
65
|
-
// `autocompletion({ override: [tjsCompletionSource] })`. (This is why the base
|
|
66
|
-
// extension set below does NOT include `autocompletion()`.)
|
|
67
|
-
function standardLanguageBundle(mode) {
|
|
68
|
-
return [languageForMode(mode), autocompletion()];
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Lazy-load tjs-lang's CodeMirror language + completion bundle. Returns a single
|
|
72
|
-
* CodeMirror `Extension` (tjs language, forbidden-keyword highlighting, theme, and
|
|
73
|
-
* `tjsCompletionSource`-driven autocomplete) suitable for `setLanguageExtension()`,
|
|
74
|
-
* or `null` when tjs-lang (an optional peer) isn't installed or its editor build
|
|
75
|
-
* lacks `tjsEditorExtension`. The dynamic import keeps it out of the bundle until a
|
|
76
|
-
* tjs editor actually mounts.
|
|
77
|
-
*/
|
|
78
|
-
export async function loadTjsExtension(autocomplete = {}) {
|
|
79
|
-
try {
|
|
80
|
-
const mod = (await import('tjs-lang/editors/codemirror'));
|
|
81
|
-
if (typeof mod.tjsEditorExtension === 'function') {
|
|
82
|
-
return mod.tjsEditorExtension({ typescript: true, autocomplete });
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
// tjs-lang absent or editor build unavailable — caller keeps TS highlighting.
|
|
87
|
-
}
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
// A minimal theme so the editor has a real surface instead of showing whatever is
|
|
91
|
-
// behind it. It's applied as a CodeMirror theme (not shadow-DOM CSS) so it beats
|
|
92
|
-
// CM's injected base styles. Colors come from the doc-system theme vars
|
|
93
|
-
// (`--code-bg` / `--text-color`, which pierce the shadow root and adapt to dark
|
|
94
|
-
// mode) with sensible standalone fallbacks.
|
|
95
|
-
const editorTheme = EditorView.theme({
|
|
96
|
-
'&': {
|
|
97
|
-
height: '100%',
|
|
98
|
-
backgroundColor: 'var(--code-bg, var(--input-bg, #fdfdfd))',
|
|
99
|
-
color: 'var(--text-color, #222)',
|
|
100
|
-
},
|
|
101
|
-
'.cm-scroller': {
|
|
102
|
-
fontFamily: "Menlo, Monaco, Consolas, 'Courier New', monospace",
|
|
103
|
-
},
|
|
104
|
-
'.cm-gutters': {
|
|
105
|
-
backgroundColor: 'var(--code-bg, var(--input-bg, #fdfdfd))',
|
|
106
|
-
color: 'var(--text-color, #888)',
|
|
107
|
-
border: 'none',
|
|
108
|
-
},
|
|
109
|
-
'.cm-activeLine': { backgroundColor: 'transparent' },
|
|
110
|
-
'.cm-activeLineGutter': { backgroundColor: 'transparent' },
|
|
111
|
-
});
|
|
112
|
-
// A basicSetup-equivalent without a hard-coded color theme, so the host page's CSS
|
|
113
|
-
// (and dark mode) controls the palette. Line-wrapping mirrors the old ACE `wrap:true`.
|
|
114
|
-
function baseExtensions() {
|
|
115
|
-
return [
|
|
116
|
-
editorTheme,
|
|
117
|
-
lineNumbers(),
|
|
118
|
-
highlightActiveLineGutter(),
|
|
119
|
-
highlightSpecialChars(),
|
|
120
|
-
history(),
|
|
121
|
-
foldGutter(),
|
|
122
|
-
drawSelection(),
|
|
123
|
-
dropCursor(),
|
|
124
|
-
EditorState.allowMultipleSelections.of(true),
|
|
125
|
-
indentOnInput(),
|
|
126
|
-
indentUnit.of(' '),
|
|
127
|
-
EditorState.tabSize.of(2),
|
|
128
|
-
// syntax highlighting is applied per-instance via a compartment (dark-mode aware)
|
|
129
|
-
bracketMatching(),
|
|
130
|
-
closeBrackets(),
|
|
131
|
-
// NB: autocompletion() lives in the language compartment (see
|
|
132
|
-
// standardLanguageBundle) so tjs's own completion source never doubles up.
|
|
133
|
-
rectangularSelection(),
|
|
134
|
-
crosshairCursor(),
|
|
135
|
-
highlightActiveLine(),
|
|
136
|
-
highlightSelectionMatches(),
|
|
137
|
-
EditorView.lineWrapping,
|
|
138
|
-
keymap.of([
|
|
139
|
-
indentWithTab,
|
|
140
|
-
...closeBracketsKeymap,
|
|
141
|
-
...defaultKeymap,
|
|
142
|
-
...searchKeymap,
|
|
143
|
-
...historyKeymap,
|
|
144
|
-
...foldKeymap,
|
|
145
|
-
...completionKeymap,
|
|
146
|
-
...lintKeymap,
|
|
147
|
-
]),
|
|
148
|
-
];
|
|
149
|
-
}
|
|
150
|
-
/** Create a CodeMirror editor mounted in `parent`, returning an editor-agnostic handle. */
|
|
151
|
-
export function createCmEditor(parent, opts = {}) {
|
|
152
|
-
const language = new Compartment();
|
|
153
|
-
const readonly = new Compartment();
|
|
154
|
-
const highlight = new Compartment();
|
|
155
|
-
const langExt = opts.languageExtension ?? standardLanguageBundle(opts.mode ?? 'javascript');
|
|
156
|
-
const view = new EditorView({
|
|
157
|
-
parent,
|
|
158
|
-
root: opts.root,
|
|
159
|
-
state: EditorState.create({
|
|
160
|
-
doc: opts.value ?? '',
|
|
161
|
-
extensions: [
|
|
162
|
-
baseExtensions(),
|
|
163
|
-
highlight.of(highlightFor(isDarkMode())),
|
|
164
|
-
language.of(langExt),
|
|
165
|
-
readonly.of(EditorState.readOnly.of(!!opts.readOnly)),
|
|
166
|
-
EditorView.updateListener.of((u) => {
|
|
167
|
-
if (u.docChanged && opts.onChange)
|
|
168
|
-
opts.onChange(u.state.doc.toString());
|
|
169
|
-
}),
|
|
170
|
-
],
|
|
171
|
-
}),
|
|
172
|
-
});
|
|
173
|
-
// Re-apply the right highlight palette when the doc-system toggles dark mode
|
|
174
|
-
// (it flips the `darkmode` class on <body>).
|
|
175
|
-
let dark = isDarkMode();
|
|
176
|
-
const darkObserver = typeof MutationObserver !== 'undefined' && typeof document !== 'undefined'
|
|
177
|
-
? new MutationObserver(() => {
|
|
178
|
-
const nowDark = isDarkMode();
|
|
179
|
-
if (nowDark !== dark) {
|
|
180
|
-
dark = nowDark;
|
|
181
|
-
view.dispatch({ effects: highlight.reconfigure(highlightFor(dark)) });
|
|
182
|
-
}
|
|
183
|
-
})
|
|
184
|
-
: null;
|
|
185
|
-
darkObserver?.observe(document.body, { attributes: true, attributeFilter: ['class'] });
|
|
186
|
-
const handle = {
|
|
187
|
-
view,
|
|
188
|
-
getValue: () => view.state.doc.toString(),
|
|
189
|
-
setValue(text) {
|
|
190
|
-
if (view.state.doc.toString() === text)
|
|
191
|
-
return;
|
|
192
|
-
view.dispatch({
|
|
193
|
-
changes: { from: 0, to: view.state.doc.length, insert: text },
|
|
194
|
-
});
|
|
195
|
-
},
|
|
196
|
-
setMode(mode) {
|
|
197
|
-
view.dispatch({ effects: language.reconfigure(standardLanguageBundle(mode)) });
|
|
198
|
-
},
|
|
199
|
-
setLanguageExtension(ext) {
|
|
200
|
-
view.dispatch({ effects: language.reconfigure(ext) });
|
|
201
|
-
},
|
|
202
|
-
setReadOnly(ro) {
|
|
203
|
-
view.dispatch({
|
|
204
|
-
effects: readonly.reconfigure(EditorState.readOnly.of(ro)),
|
|
205
|
-
});
|
|
206
|
-
},
|
|
207
|
-
undo: () => void undo(view),
|
|
208
|
-
redo: () => void redo(view),
|
|
209
|
-
canUndo: () => undoDepth(view.state) > 0,
|
|
210
|
-
canRedo: () => redoDepth(view.state) > 0,
|
|
211
|
-
focus: () => view.focus(),
|
|
212
|
-
refresh: () => view.requestMeasure(),
|
|
213
|
-
destroy: () => {
|
|
214
|
-
darkObserver?.disconnect();
|
|
215
|
-
view.destroy();
|
|
216
|
-
},
|
|
217
|
-
};
|
|
218
|
-
return handle;
|
|
219
|
-
}
|