@coze-editor/preset-expression 0.1.0-alpha.09ffeb
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/LICENSE +21 -0
- package/dist/esm/index.js +102 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +50 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +90 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 coze-dev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { updateWholeDecorations, inputRules } from "@coze-editor/extensions";
|
|
3
|
+
import {
|
|
4
|
+
basic,
|
|
5
|
+
fontSize,
|
|
6
|
+
getValue,
|
|
7
|
+
setValue,
|
|
8
|
+
focus,
|
|
9
|
+
blur,
|
|
10
|
+
eventChange,
|
|
11
|
+
eventFocus,
|
|
12
|
+
eventBlur,
|
|
13
|
+
eventSelectionChange,
|
|
14
|
+
getView,
|
|
15
|
+
eventViewUpdate,
|
|
16
|
+
matchBefore,
|
|
17
|
+
placeholder,
|
|
18
|
+
readOnly,
|
|
19
|
+
replaceTextByRange,
|
|
20
|
+
getCursorPosition,
|
|
21
|
+
setCursorPosition,
|
|
22
|
+
disableKeybindings,
|
|
23
|
+
disableKeybindingsField,
|
|
24
|
+
contentAttributes,
|
|
25
|
+
getSelection,
|
|
26
|
+
focusChangeNotifier,
|
|
27
|
+
isFocused,
|
|
28
|
+
editable
|
|
29
|
+
} from "@coze-editor/core-plugins";
|
|
30
|
+
import {
|
|
31
|
+
option,
|
|
32
|
+
api,
|
|
33
|
+
event,
|
|
34
|
+
extension,
|
|
35
|
+
domEventHandler
|
|
36
|
+
} from "@coze-editor/core";
|
|
37
|
+
import { highlightSpecialChars, keymap, EditorView } from "@codemirror/view";
|
|
38
|
+
import { EditorState } from "@codemirror/state";
|
|
39
|
+
import {
|
|
40
|
+
syntaxHighlighting,
|
|
41
|
+
defaultHighlightStyle,
|
|
42
|
+
indentUnit
|
|
43
|
+
} from "@codemirror/language";
|
|
44
|
+
import { defaultKeymap, historyKeymap, history } from "@codemirror/commands";
|
|
45
|
+
import { closeBrackets } from "@codemirror/autocomplete";
|
|
46
|
+
var sharedPreset = [
|
|
47
|
+
extension([
|
|
48
|
+
highlightSpecialChars(),
|
|
49
|
+
history(),
|
|
50
|
+
keymap.of([...defaultKeymap, ...historyKeymap]),
|
|
51
|
+
EditorState.tabSize.of(2),
|
|
52
|
+
indentUnit.of(" ".repeat(2)),
|
|
53
|
+
EditorView.lineWrapping,
|
|
54
|
+
basic(),
|
|
55
|
+
focusChangeNotifier
|
|
56
|
+
]),
|
|
57
|
+
option("fontSize", fontSize),
|
|
58
|
+
option("placeholder", placeholder),
|
|
59
|
+
option("readOnly", readOnly),
|
|
60
|
+
option("editable", editable),
|
|
61
|
+
option("inputRules", inputRules),
|
|
62
|
+
option("contentAttributes", contentAttributes),
|
|
63
|
+
event("change", eventChange),
|
|
64
|
+
event("focus", eventFocus),
|
|
65
|
+
event("blur", eventBlur),
|
|
66
|
+
event("selectionChange", eventSelectionChange),
|
|
67
|
+
event("viewUpdate", eventViewUpdate),
|
|
68
|
+
domEventHandler("compositionstart"),
|
|
69
|
+
domEventHandler("compositionend"),
|
|
70
|
+
domEventHandler("mousedown"),
|
|
71
|
+
domEventHandler("mouseup"),
|
|
72
|
+
// 需组合使用
|
|
73
|
+
extension(disableKeybindingsField),
|
|
74
|
+
api("disableKeybindings", disableKeybindings),
|
|
75
|
+
api("getView", getView),
|
|
76
|
+
api("matchBefore", matchBefore),
|
|
77
|
+
api("updateWholeDecorations", ({ view }) => () => {
|
|
78
|
+
updateWholeDecorations(view);
|
|
79
|
+
}),
|
|
80
|
+
api("getValue", getValue),
|
|
81
|
+
api("setValue", setValue),
|
|
82
|
+
api("focus", focus),
|
|
83
|
+
api("blur", blur),
|
|
84
|
+
api("isFocused", isFocused),
|
|
85
|
+
api("getCursorPosition", getCursorPosition),
|
|
86
|
+
api("setCursorPosition", setCursorPosition),
|
|
87
|
+
api("getSelection", getSelection),
|
|
88
|
+
api("replaceTextByRange", replaceTextByRange)
|
|
89
|
+
];
|
|
90
|
+
var preset = [
|
|
91
|
+
...sharedPreset,
|
|
92
|
+
extension([
|
|
93
|
+
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
|
|
94
|
+
closeBrackets()
|
|
95
|
+
])
|
|
96
|
+
];
|
|
97
|
+
var index_default = preset;
|
|
98
|
+
export {
|
|
99
|
+
index_default as default,
|
|
100
|
+
sharedPreset
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { updateWholeDecorations, inputRules } from '@coze-editor/extensions';\nimport {\n basic,\n fontSize,\n getValue,\n setValue,\n focus,\n blur,\n eventChange,\n eventFocus,\n eventBlur,\n eventSelectionChange,\n getView,\n eventViewUpdate,\n matchBefore,\n placeholder,\n readOnly,\n replaceTextByRange,\n getCursorPosition,\n setCursorPosition,\n disableKeybindings,\n disableKeybindingsField,\n contentAttributes,\n getSelection,\n focusChangeNotifier,\n isFocused,\n editable,\n} from '@coze-editor/core-plugins';\nimport {\n option,\n api,\n event,\n extension,\n type InferEditorAPIFromPlugins,\n domEventHandler,\n} from '@coze-editor/core';\nimport { highlightSpecialChars, keymap, EditorView } from '@codemirror/view';\nimport { EditorState } from '@codemirror/state';\nimport {\n syntaxHighlighting,\n defaultHighlightStyle,\n indentUnit,\n} from '@codemirror/language';\nimport { defaultKeymap, historyKeymap, history } from '@codemirror/commands';\nimport { closeBrackets } from '@codemirror/autocomplete';\n\nconst sharedPreset = [\n extension([\n highlightSpecialChars(),\n history(),\n keymap.of([...defaultKeymap, ...historyKeymap]),\n EditorState.tabSize.of(2),\n indentUnit.of(' '.repeat(2)),\n EditorView.lineWrapping,\n basic(),\n focusChangeNotifier,\n ]),\n\n option('fontSize', fontSize),\n option('placeholder', placeholder),\n option('readOnly', readOnly),\n option('editable', editable),\n option('inputRules', inputRules),\n option('contentAttributes', contentAttributes),\n\n event('change', eventChange),\n event('focus', eventFocus),\n event('blur', eventBlur),\n event('selectionChange', eventSelectionChange),\n event('viewUpdate', eventViewUpdate),\n domEventHandler('compositionstart'),\n domEventHandler('compositionend'),\n domEventHandler('mousedown'),\n domEventHandler('mouseup'),\n\n // 需组合使用\n extension(disableKeybindingsField),\n api('disableKeybindings', disableKeybindings),\n api('getView', getView),\n api('matchBefore', matchBefore),\n api('updateWholeDecorations', ({ view }) => () => {\n updateWholeDecorations(view);\n }),\n api('getValue', getValue),\n api('setValue', setValue),\n api('focus', focus),\n api('blur', blur),\n api('isFocused', isFocused),\n api('getCursorPosition', getCursorPosition),\n api('setCursorPosition', setCursorPosition),\n api('getSelection', getSelection),\n api('replaceTextByRange', replaceTextByRange),\n];\n\nconst preset = [\n ...sharedPreset,\n extension([\n syntaxHighlighting(defaultHighlightStyle, { fallback: true }),\n closeBrackets(),\n ]),\n];\n\ntype EditorAPI = InferEditorAPIFromPlugins<typeof preset>;\n\nexport { sharedPreset };\nexport default preset;\nexport type { EditorAPI };\n"],"mappings":";AAGA,SAAS,wBAAwB,kBAAkB;AACnD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP,SAAS,uBAAuB,QAAQ,kBAAkB;AAC1D,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe,eAAe,eAAe;AACtD,SAAS,qBAAqB;AAE9B,IAAM,eAAe;AAAA,EACnB,UAAU;AAAA,IACR,sBAAsB;AAAA,IACtB,QAAQ;AAAA,IACR,OAAO,GAAG,CAAC,GAAG,eAAe,GAAG,aAAa,CAAC;AAAA,IAC9C,YAAY,QAAQ,GAAG,CAAC;AAAA,IACxB,WAAW,GAAG,IAAI,OAAO,CAAC,CAAC;AAAA,IAC3B,WAAW;AAAA,IACX,MAAM;AAAA,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
|
|
|
1
|
+
import * as _codemirror_view from '@codemirror/view';
|
|
2
|
+
import { EditorView } from '@codemirror/view';
|
|
3
|
+
import * as _coze_editor_core_plugins from '@coze-editor/core-plugins';
|
|
4
|
+
import * as _coze_editor_extensions from '@coze-editor/extensions';
|
|
5
|
+
import * as _coze_editor_core from '@coze-editor/core';
|
|
6
|
+
import { InferEditorAPIFromPlugins } from '@coze-editor/core';
|
|
7
|
+
|
|
8
|
+
declare const sharedPreset: (_coze_editor_core.ExtensionPluginSpec | _coze_editor_core.OptionPluginSpec<"fontSize", number> | _coze_editor_core.OptionPluginSpec<"placeholder", string | HTMLElement> | _coze_editor_core.OptionPluginSpec<"readOnly", boolean> | _coze_editor_core.OptionPluginSpec<"editable", boolean> | _coze_editor_core.OptionPluginSpec<"inputRules", _coze_editor_extensions.InputRule[]> | _coze_editor_core.OptionPluginSpec<"contentAttributes", _coze_editor_core_plugins.Attrs | ((view: EditorView) => _coze_editor_core_plugins.Attrs | null)> | _coze_editor_core.EventPluginSpec<"change", {
|
|
9
|
+
value: string;
|
|
10
|
+
}> | _coze_editor_core.EventPluginSpec<"focus", symbol> | _coze_editor_core.EventPluginSpec<"blur", symbol> | _coze_editor_core.EventPluginSpec<"selectionChange", {
|
|
11
|
+
selection: {
|
|
12
|
+
from: number;
|
|
13
|
+
to: number;
|
|
14
|
+
head: number;
|
|
15
|
+
anchor: number;
|
|
16
|
+
};
|
|
17
|
+
update: _codemirror_view.ViewUpdate;
|
|
18
|
+
}> | _coze_editor_core.EventPluginSpec<"viewUpdate", _codemirror_view.ViewUpdate> | _coze_editor_core.DOMEventHandlerPluginSpec<"compositionstart"> | _coze_editor_core.DOMEventHandlerPluginSpec<"compositionend"> | _coze_editor_core.DOMEventHandlerPluginSpec<"mousedown"> | _coze_editor_core.DOMEventHandlerPluginSpec<"mouseup"> | _coze_editor_core.APIPluginSpec<"disableKeybindings", [keys: string[]], void> | _coze_editor_core.APIPluginSpec<"getView", [], EditorView> | _coze_editor_core.APIPluginSpec<"matchBefore", [match: RegExp], {
|
|
19
|
+
from: number;
|
|
20
|
+
to: number;
|
|
21
|
+
text: string;
|
|
22
|
+
}> | _coze_editor_core.APIPluginSpec<"updateWholeDecorations", [], void> | _coze_editor_core.APIPluginSpec<"getValue", [], string> | _coze_editor_core.APIPluginSpec<"setValue", [value: string], void> | _coze_editor_core.APIPluginSpec<"focus", [], void> | _coze_editor_core.APIPluginSpec<"blur", [], void> | _coze_editor_core.APIPluginSpec<"isFocused", [], boolean> | _coze_editor_core.APIPluginSpec<"getCursorPosition", [], number> | _coze_editor_core.APIPluginSpec<"setCursorPosition", [pos: number], void> | _coze_editor_core.APIPluginSpec<"getSelection", [], {
|
|
23
|
+
from: number;
|
|
24
|
+
to: number;
|
|
25
|
+
anchor: number;
|
|
26
|
+
head: number;
|
|
27
|
+
}> | _coze_editor_core.APIPluginSpec<"replaceTextByRange", [_coze_editor_core_plugins.ReplaceTextByRangeOptions], void>)[];
|
|
28
|
+
declare const preset: (_coze_editor_core.ExtensionPluginSpec | _coze_editor_core.OptionPluginSpec<"fontSize", number> | _coze_editor_core.OptionPluginSpec<"placeholder", string | HTMLElement> | _coze_editor_core.OptionPluginSpec<"readOnly", boolean> | _coze_editor_core.OptionPluginSpec<"editable", boolean> | _coze_editor_core.OptionPluginSpec<"inputRules", _coze_editor_extensions.InputRule[]> | _coze_editor_core.OptionPluginSpec<"contentAttributes", _coze_editor_core_plugins.Attrs | ((view: EditorView) => _coze_editor_core_plugins.Attrs | null)> | _coze_editor_core.EventPluginSpec<"change", {
|
|
29
|
+
value: string;
|
|
30
|
+
}> | _coze_editor_core.EventPluginSpec<"focus", symbol> | _coze_editor_core.EventPluginSpec<"blur", symbol> | _coze_editor_core.EventPluginSpec<"selectionChange", {
|
|
31
|
+
selection: {
|
|
32
|
+
from: number;
|
|
33
|
+
to: number;
|
|
34
|
+
head: number;
|
|
35
|
+
anchor: number;
|
|
36
|
+
};
|
|
37
|
+
update: _codemirror_view.ViewUpdate;
|
|
38
|
+
}> | _coze_editor_core.EventPluginSpec<"viewUpdate", _codemirror_view.ViewUpdate> | _coze_editor_core.DOMEventHandlerPluginSpec<"compositionstart"> | _coze_editor_core.DOMEventHandlerPluginSpec<"compositionend"> | _coze_editor_core.DOMEventHandlerPluginSpec<"mousedown"> | _coze_editor_core.DOMEventHandlerPluginSpec<"mouseup"> | _coze_editor_core.APIPluginSpec<"disableKeybindings", [keys: string[]], void> | _coze_editor_core.APIPluginSpec<"getView", [], EditorView> | _coze_editor_core.APIPluginSpec<"matchBefore", [match: RegExp], {
|
|
39
|
+
from: number;
|
|
40
|
+
to: number;
|
|
41
|
+
text: string;
|
|
42
|
+
}> | _coze_editor_core.APIPluginSpec<"updateWholeDecorations", [], void> | _coze_editor_core.APIPluginSpec<"getValue", [], string> | _coze_editor_core.APIPluginSpec<"setValue", [value: string], void> | _coze_editor_core.APIPluginSpec<"focus", [], void> | _coze_editor_core.APIPluginSpec<"blur", [], void> | _coze_editor_core.APIPluginSpec<"isFocused", [], boolean> | _coze_editor_core.APIPluginSpec<"getCursorPosition", [], number> | _coze_editor_core.APIPluginSpec<"setCursorPosition", [pos: number], void> | _coze_editor_core.APIPluginSpec<"getSelection", [], {
|
|
43
|
+
from: number;
|
|
44
|
+
to: number;
|
|
45
|
+
anchor: number;
|
|
46
|
+
head: number;
|
|
47
|
+
}> | _coze_editor_core.APIPluginSpec<"replaceTextByRange", [_coze_editor_core_plugins.ReplaceTextByRangeOptions], void>)[];
|
|
48
|
+
type EditorAPI = InferEditorAPIFromPlugins<typeof preset>;
|
|
49
|
+
|
|
50
|
+
export { type EditorAPI, preset as default, sharedPreset };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as _codemirror_view from '@codemirror/view';
|
|
2
|
+
import { EditorView } from '@codemirror/view';
|
|
3
|
+
import * as _coze_editor_core_plugins from '@coze-editor/core-plugins';
|
|
4
|
+
import * as _coze_editor_extensions from '@coze-editor/extensions';
|
|
5
|
+
import * as _coze_editor_core from '@coze-editor/core';
|
|
6
|
+
import { InferEditorAPIFromPlugins } from '@coze-editor/core';
|
|
7
|
+
|
|
8
|
+
declare const sharedPreset: (_coze_editor_core.ExtensionPluginSpec | _coze_editor_core.OptionPluginSpec<"fontSize", number> | _coze_editor_core.OptionPluginSpec<"placeholder", string | HTMLElement> | _coze_editor_core.OptionPluginSpec<"readOnly", boolean> | _coze_editor_core.OptionPluginSpec<"editable", boolean> | _coze_editor_core.OptionPluginSpec<"inputRules", _coze_editor_extensions.InputRule[]> | _coze_editor_core.OptionPluginSpec<"contentAttributes", _coze_editor_core_plugins.Attrs | ((view: EditorView) => _coze_editor_core_plugins.Attrs | null)> | _coze_editor_core.EventPluginSpec<"change", {
|
|
9
|
+
value: string;
|
|
10
|
+
}> | _coze_editor_core.EventPluginSpec<"focus", symbol> | _coze_editor_core.EventPluginSpec<"blur", symbol> | _coze_editor_core.EventPluginSpec<"selectionChange", {
|
|
11
|
+
selection: {
|
|
12
|
+
from: number;
|
|
13
|
+
to: number;
|
|
14
|
+
head: number;
|
|
15
|
+
anchor: number;
|
|
16
|
+
};
|
|
17
|
+
update: _codemirror_view.ViewUpdate;
|
|
18
|
+
}> | _coze_editor_core.EventPluginSpec<"viewUpdate", _codemirror_view.ViewUpdate> | _coze_editor_core.DOMEventHandlerPluginSpec<"compositionstart"> | _coze_editor_core.DOMEventHandlerPluginSpec<"compositionend"> | _coze_editor_core.DOMEventHandlerPluginSpec<"mousedown"> | _coze_editor_core.DOMEventHandlerPluginSpec<"mouseup"> | _coze_editor_core.APIPluginSpec<"disableKeybindings", [keys: string[]], void> | _coze_editor_core.APIPluginSpec<"getView", [], EditorView> | _coze_editor_core.APIPluginSpec<"matchBefore", [match: RegExp], {
|
|
19
|
+
from: number;
|
|
20
|
+
to: number;
|
|
21
|
+
text: string;
|
|
22
|
+
}> | _coze_editor_core.APIPluginSpec<"updateWholeDecorations", [], void> | _coze_editor_core.APIPluginSpec<"getValue", [], string> | _coze_editor_core.APIPluginSpec<"setValue", [value: string], void> | _coze_editor_core.APIPluginSpec<"focus", [], void> | _coze_editor_core.APIPluginSpec<"blur", [], void> | _coze_editor_core.APIPluginSpec<"isFocused", [], boolean> | _coze_editor_core.APIPluginSpec<"getCursorPosition", [], number> | _coze_editor_core.APIPluginSpec<"setCursorPosition", [pos: number], void> | _coze_editor_core.APIPluginSpec<"getSelection", [], {
|
|
23
|
+
from: number;
|
|
24
|
+
to: number;
|
|
25
|
+
anchor: number;
|
|
26
|
+
head: number;
|
|
27
|
+
}> | _coze_editor_core.APIPluginSpec<"replaceTextByRange", [_coze_editor_core_plugins.ReplaceTextByRangeOptions], void>)[];
|
|
28
|
+
declare const preset: (_coze_editor_core.ExtensionPluginSpec | _coze_editor_core.OptionPluginSpec<"fontSize", number> | _coze_editor_core.OptionPluginSpec<"placeholder", string | HTMLElement> | _coze_editor_core.OptionPluginSpec<"readOnly", boolean> | _coze_editor_core.OptionPluginSpec<"editable", boolean> | _coze_editor_core.OptionPluginSpec<"inputRules", _coze_editor_extensions.InputRule[]> | _coze_editor_core.OptionPluginSpec<"contentAttributes", _coze_editor_core_plugins.Attrs | ((view: EditorView) => _coze_editor_core_plugins.Attrs | null)> | _coze_editor_core.EventPluginSpec<"change", {
|
|
29
|
+
value: string;
|
|
30
|
+
}> | _coze_editor_core.EventPluginSpec<"focus", symbol> | _coze_editor_core.EventPluginSpec<"blur", symbol> | _coze_editor_core.EventPluginSpec<"selectionChange", {
|
|
31
|
+
selection: {
|
|
32
|
+
from: number;
|
|
33
|
+
to: number;
|
|
34
|
+
head: number;
|
|
35
|
+
anchor: number;
|
|
36
|
+
};
|
|
37
|
+
update: _codemirror_view.ViewUpdate;
|
|
38
|
+
}> | _coze_editor_core.EventPluginSpec<"viewUpdate", _codemirror_view.ViewUpdate> | _coze_editor_core.DOMEventHandlerPluginSpec<"compositionstart"> | _coze_editor_core.DOMEventHandlerPluginSpec<"compositionend"> | _coze_editor_core.DOMEventHandlerPluginSpec<"mousedown"> | _coze_editor_core.DOMEventHandlerPluginSpec<"mouseup"> | _coze_editor_core.APIPluginSpec<"disableKeybindings", [keys: string[]], void> | _coze_editor_core.APIPluginSpec<"getView", [], EditorView> | _coze_editor_core.APIPluginSpec<"matchBefore", [match: RegExp], {
|
|
39
|
+
from: number;
|
|
40
|
+
to: number;
|
|
41
|
+
text: string;
|
|
42
|
+
}> | _coze_editor_core.APIPluginSpec<"updateWholeDecorations", [], void> | _coze_editor_core.APIPluginSpec<"getValue", [], string> | _coze_editor_core.APIPluginSpec<"setValue", [value: string], void> | _coze_editor_core.APIPluginSpec<"focus", [], void> | _coze_editor_core.APIPluginSpec<"blur", [], void> | _coze_editor_core.APIPluginSpec<"isFocused", [], boolean> | _coze_editor_core.APIPluginSpec<"getCursorPosition", [], number> | _coze_editor_core.APIPluginSpec<"setCursorPosition", [pos: number], void> | _coze_editor_core.APIPluginSpec<"getSelection", [], {
|
|
43
|
+
from: number;
|
|
44
|
+
to: number;
|
|
45
|
+
anchor: number;
|
|
46
|
+
head: number;
|
|
47
|
+
}> | _coze_editor_core.APIPluginSpec<"replaceTextByRange", [_coze_editor_core_plugins.ReplaceTextByRangeOptions], void>)[];
|
|
48
|
+
type EditorAPI = InferEditorAPIFromPlugins<typeof preset>;
|
|
49
|
+
|
|
50
|
+
export { type EditorAPI, preset as default, sharedPreset };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
default: () => index_default,
|
|
23
|
+
sharedPreset: () => sharedPreset
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_extensions = require("@coze-editor/extensions");
|
|
27
|
+
var import_core_plugins = require("@coze-editor/core-plugins");
|
|
28
|
+
var import_core = require("@coze-editor/core");
|
|
29
|
+
var import_view = require("@codemirror/view");
|
|
30
|
+
var import_state = require("@codemirror/state");
|
|
31
|
+
var import_language = require("@codemirror/language");
|
|
32
|
+
var import_commands = require("@codemirror/commands");
|
|
33
|
+
var import_autocomplete = require("@codemirror/autocomplete");
|
|
34
|
+
var sharedPreset = [
|
|
35
|
+
(0, import_core.extension)([
|
|
36
|
+
(0, import_view.highlightSpecialChars)(),
|
|
37
|
+
(0, import_commands.history)(),
|
|
38
|
+
import_view.keymap.of([...import_commands.defaultKeymap, ...import_commands.historyKeymap]),
|
|
39
|
+
import_state.EditorState.tabSize.of(2),
|
|
40
|
+
import_language.indentUnit.of(" ".repeat(2)),
|
|
41
|
+
import_view.EditorView.lineWrapping,
|
|
42
|
+
(0, import_core_plugins.basic)(),
|
|
43
|
+
import_core_plugins.focusChangeNotifier
|
|
44
|
+
]),
|
|
45
|
+
(0, import_core.option)("fontSize", import_core_plugins.fontSize),
|
|
46
|
+
(0, import_core.option)("placeholder", import_core_plugins.placeholder),
|
|
47
|
+
(0, import_core.option)("readOnly", import_core_plugins.readOnly),
|
|
48
|
+
(0, import_core.option)("editable", import_core_plugins.editable),
|
|
49
|
+
(0, import_core.option)("inputRules", import_extensions.inputRules),
|
|
50
|
+
(0, import_core.option)("contentAttributes", import_core_plugins.contentAttributes),
|
|
51
|
+
(0, import_core.event)("change", import_core_plugins.eventChange),
|
|
52
|
+
(0, import_core.event)("focus", import_core_plugins.eventFocus),
|
|
53
|
+
(0, import_core.event)("blur", import_core_plugins.eventBlur),
|
|
54
|
+
(0, import_core.event)("selectionChange", import_core_plugins.eventSelectionChange),
|
|
55
|
+
(0, import_core.event)("viewUpdate", import_core_plugins.eventViewUpdate),
|
|
56
|
+
(0, import_core.domEventHandler)("compositionstart"),
|
|
57
|
+
(0, import_core.domEventHandler)("compositionend"),
|
|
58
|
+
(0, import_core.domEventHandler)("mousedown"),
|
|
59
|
+
(0, import_core.domEventHandler)("mouseup"),
|
|
60
|
+
// 需组合使用
|
|
61
|
+
(0, import_core.extension)(import_core_plugins.disableKeybindingsField),
|
|
62
|
+
(0, import_core.api)("disableKeybindings", import_core_plugins.disableKeybindings),
|
|
63
|
+
(0, import_core.api)("getView", import_core_plugins.getView),
|
|
64
|
+
(0, import_core.api)("matchBefore", import_core_plugins.matchBefore),
|
|
65
|
+
(0, import_core.api)("updateWholeDecorations", ({ view }) => () => {
|
|
66
|
+
(0, import_extensions.updateWholeDecorations)(view);
|
|
67
|
+
}),
|
|
68
|
+
(0, import_core.api)("getValue", import_core_plugins.getValue),
|
|
69
|
+
(0, import_core.api)("setValue", import_core_plugins.setValue),
|
|
70
|
+
(0, import_core.api)("focus", import_core_plugins.focus),
|
|
71
|
+
(0, import_core.api)("blur", import_core_plugins.blur),
|
|
72
|
+
(0, import_core.api)("isFocused", import_core_plugins.isFocused),
|
|
73
|
+
(0, import_core.api)("getCursorPosition", import_core_plugins.getCursorPosition),
|
|
74
|
+
(0, import_core.api)("setCursorPosition", import_core_plugins.setCursorPosition),
|
|
75
|
+
(0, import_core.api)("getSelection", import_core_plugins.getSelection),
|
|
76
|
+
(0, import_core.api)("replaceTextByRange", import_core_plugins.replaceTextByRange)
|
|
77
|
+
];
|
|
78
|
+
var preset = [
|
|
79
|
+
...sharedPreset,
|
|
80
|
+
(0, import_core.extension)([
|
|
81
|
+
(0, import_language.syntaxHighlighting)(import_language.defaultHighlightStyle, { fallback: true }),
|
|
82
|
+
(0, import_autocomplete.closeBrackets)()
|
|
83
|
+
])
|
|
84
|
+
];
|
|
85
|
+
var index_default = preset;
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
sharedPreset
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright (c) 2025 coze-dev\n// SPDX-License-Identifier: MIT\n\nimport { updateWholeDecorations, inputRules } from '@coze-editor/extensions';\nimport {\n basic,\n fontSize,\n getValue,\n setValue,\n focus,\n blur,\n eventChange,\n eventFocus,\n eventBlur,\n eventSelectionChange,\n getView,\n eventViewUpdate,\n matchBefore,\n placeholder,\n readOnly,\n replaceTextByRange,\n getCursorPosition,\n setCursorPosition,\n disableKeybindings,\n disableKeybindingsField,\n contentAttributes,\n getSelection,\n focusChangeNotifier,\n isFocused,\n editable,\n} from '@coze-editor/core-plugins';\nimport {\n option,\n api,\n event,\n extension,\n type InferEditorAPIFromPlugins,\n domEventHandler,\n} from '@coze-editor/core';\nimport { highlightSpecialChars, keymap, EditorView } from '@codemirror/view';\nimport { EditorState } from '@codemirror/state';\nimport {\n syntaxHighlighting,\n defaultHighlightStyle,\n indentUnit,\n} from '@codemirror/language';\nimport { defaultKeymap, historyKeymap, history } from '@codemirror/commands';\nimport { closeBrackets } from '@codemirror/autocomplete';\n\nconst sharedPreset = [\n extension([\n highlightSpecialChars(),\n history(),\n keymap.of([...defaultKeymap, ...historyKeymap]),\n EditorState.tabSize.of(2),\n indentUnit.of(' '.repeat(2)),\n EditorView.lineWrapping,\n basic(),\n focusChangeNotifier,\n ]),\n\n option('fontSize', fontSize),\n option('placeholder', placeholder),\n option('readOnly', readOnly),\n option('editable', editable),\n option('inputRules', inputRules),\n option('contentAttributes', contentAttributes),\n\n event('change', eventChange),\n event('focus', eventFocus),\n event('blur', eventBlur),\n event('selectionChange', eventSelectionChange),\n event('viewUpdate', eventViewUpdate),\n domEventHandler('compositionstart'),\n domEventHandler('compositionend'),\n domEventHandler('mousedown'),\n domEventHandler('mouseup'),\n\n // 需组合使用\n extension(disableKeybindingsField),\n api('disableKeybindings', disableKeybindings),\n api('getView', getView),\n api('matchBefore', matchBefore),\n api('updateWholeDecorations', ({ view }) => () => {\n updateWholeDecorations(view);\n }),\n api('getValue', getValue),\n api('setValue', setValue),\n api('focus', focus),\n api('blur', blur),\n api('isFocused', isFocused),\n api('getCursorPosition', getCursorPosition),\n api('setCursorPosition', setCursorPosition),\n api('getSelection', getSelection),\n api('replaceTextByRange', replaceTextByRange),\n];\n\nconst preset = [\n ...sharedPreset,\n extension([\n syntaxHighlighting(defaultHighlightStyle, { fallback: true }),\n closeBrackets(),\n ]),\n];\n\ntype EditorAPI = InferEditorAPIFromPlugins<typeof preset>;\n\nexport { sharedPreset };\nexport default preset;\nexport type { EditorAPI };\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAmD;AACnD,0BA0BO;AACP,kBAOO;AACP,kBAA0D;AAC1D,mBAA4B;AAC5B,sBAIO;AACP,sBAAsD;AACtD,0BAA8B;AAE9B,IAAM,eAAe;AAAA,MACnB,uBAAU;AAAA,QACR,mCAAsB;AAAA,QACtB,yBAAQ;AAAA,IACR,mBAAO,GAAG,CAAC,GAAG,+BAAe,GAAG,6BAAa,CAAC;AAAA,IAC9C,yBAAY,QAAQ,GAAG,CAAC;AAAA,IACxB,2BAAW,GAAG,IAAI,OAAO,CAAC,CAAC;AAAA,IAC3B,uBAAW;A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ACH;AAKA,IAAO,gBAAQ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@coze-editor/preset-expression",
|
|
3
|
+
"version": "0.1.0-alpha.09ffeb",
|
|
4
|
+
"description": "preset-expression",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "fengzilong",
|
|
7
|
+
"maintainers": [],
|
|
8
|
+
"sideEffects": [
|
|
9
|
+
"**/*.css",
|
|
10
|
+
"**/*.less",
|
|
11
|
+
"**/*.sass",
|
|
12
|
+
"**/*.scss"
|
|
13
|
+
],
|
|
14
|
+
"main": "./dist/esm/index.js",
|
|
15
|
+
"module": "./dist/esm/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsup",
|
|
22
|
+
"lint": "eslint && tsc --noEmit"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@codemirror/autocomplete": "^6.18.0",
|
|
26
|
+
"@codemirror/language": "^6.10.1",
|
|
27
|
+
"@coze-editor/core": "0.1.0-alpha.09ffeb",
|
|
28
|
+
"@coze-editor/core-plugins": "0.1.0-alpha.09ffeb",
|
|
29
|
+
"@coze-editor/extensions": "0.1.0-alpha.09ffeb"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@codemirror/commands": "^6.3.3",
|
|
33
|
+
"@codemirror/state": "^6.4.1",
|
|
34
|
+
"@codemirror/view": "^6.26.1",
|
|
35
|
+
"@coze-arch/ts-config": "workspace:*",
|
|
36
|
+
"@coze-editor/eslint-config": "workspace:*",
|
|
37
|
+
"@types/node": "^22",
|
|
38
|
+
"eslint": "9.14.0",
|
|
39
|
+
"tsup": "^8.0.1",
|
|
40
|
+
"typescript": "^5.8.2"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@codemirror/commands": "^6.3.3",
|
|
44
|
+
"@codemirror/state": "^6.4.1",
|
|
45
|
+
"@codemirror/view": "^6.26.1"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public",
|
|
49
|
+
"registry": "https://registry.npmjs.org"
|
|
50
|
+
},
|
|
51
|
+
"test:main": "./src/index.ts"
|
|
52
|
+
}
|