@cozeloop/prompt-components 0.0.1
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/README.md +1 -0
- package/dist/es/basic-editor/custom-facet.js +9 -0
- package/dist/es/basic-editor/diff.js +138 -0
- package/dist/es/basic-editor/extensions/go-syntax.js +122 -0
- package/dist/es/basic-editor/extensions/go-template.js +16 -0
- package/dist/es/basic-editor/extensions/go-theme.js +1071 -0
- package/dist/es/basic-editor/extensions/jinja.js +80 -0
- package/dist/es/basic-editor/extensions/keymap.js +442 -0
- package/dist/es/basic-editor/extensions/language-support.js +12 -0
- package/dist/es/basic-editor/extensions/markdown.js +58 -0
- package/dist/es/basic-editor/extensions/search/dom/icon.js +250 -0
- package/dist/es/basic-editor/extensions/search/dom/match-count.js +33 -0
- package/dist/es/basic-editor/extensions/search/index.js +18 -0
- package/dist/es/basic-editor/extensions/search/panel.js +418 -0
- package/dist/es/basic-editor/extensions/search/theme.js +184 -0
- package/dist/es/basic-editor/extensions/validation.js +84 -0
- package/dist/es/basic-editor/extensions/validation.module.js +5 -0
- package/dist/es/basic-editor/extensions/validation_module.css +7 -0
- package/dist/es/basic-editor/extensions/variable.js +178 -0
- package/dist/es/basic-editor/index.js +171 -0
- package/dist/es/code-editor/code-editor.js +83 -0
- package/dist/es/code-editor/index.js +12 -0
- package/dist/es/code-editor/json-editor.js +157 -0
- package/dist/es/code-editor/raw-text-editor.js +46 -0
- package/dist/es/code-editor/text-editor.js +41 -0
- package/dist/es/code-editor/themes/coze-dark.js +112 -0
- package/dist/es/code-editor/themes/coze-light.js +118 -0
- package/dist/es/consts/index.js +12 -0
- package/dist/es/dev-layout/index.js +35 -0
- package/dist/es/index.js +66 -0
- package/dist/es/mermaid-diagram/index.js +148 -0
- package/dist/es/mermaid-diagram/index.module.js +5 -0
- package/dist/es/mermaid-diagram/index_module.css +4 -0
- package/dist/es/mermaid-diagram/use-svg-pan-zoom.js +49 -0
- package/dist/es/mermaid-diagram/utils.js +74 -0
- package/dist/es/model-config-editor/basic-type.js +73 -0
- package/dist/es/model-config-editor/index.module.js +5 -0
- package/dist/es/model-config-editor/index_module.css +8 -0
- package/dist/es/model-config-editor/model-config-form.js +130 -0
- package/dist/es/model-config-editor/popover-type.js +118 -0
- package/dist/es/model-select/index.js +136 -0
- package/dist/es/model-select/index.module.js +5 -0
- package/dist/es/model-select/index_module.css +14 -0
- package/dist/es/model-select/model-option/index.js +161 -0
- package/dist/es/model-select/model-option/index.module.js +5 -0
- package/dist/es/model-select/model-option/index_module.css +23 -0
- package/dist/es/model-select/model-option-group/index.js +44 -0
- package/dist/es/prompt-editor/index.js +188 -0
- package/dist/es/prompt-editor/index.module.js +5 -0
- package/dist/es/prompt-editor/index_module.css +71 -0
- package/dist/es/prompt-editor/message-type-select.js +74 -0
- package/dist/es/schema-editor/index.js +43 -0
- package/dist/es/utils/base.js +53 -0
- package/dist/es/utils/model-config.js +32 -0
- package/dist/lib/basic-editor/custom-facet.js +33 -0
- package/dist/lib/basic-editor/diff.js +167 -0
- package/dist/lib/basic-editor/extensions/go-syntax.js +146 -0
- package/dist/lib/basic-editor/extensions/go-template.js +50 -0
- package/dist/lib/basic-editor/extensions/go-theme.js +1091 -0
- package/dist/lib/basic-editor/extensions/jinja.js +100 -0
- package/dist/lib/basic-editor/extensions/keymap.js +465 -0
- package/dist/lib/basic-editor/extensions/language-support.js +32 -0
- package/dist/lib/basic-editor/extensions/markdown.js +78 -0
- package/dist/lib/basic-editor/extensions/search/dom/icon.js +291 -0
- package/dist/lib/basic-editor/extensions/search/dom/match-count.js +67 -0
- package/dist/lib/basic-editor/extensions/search/index.js +38 -0
- package/dist/lib/basic-editor/extensions/search/panel.js +429 -0
- package/dist/lib/basic-editor/extensions/search/theme.js +208 -0
- package/dist/lib/basic-editor/extensions/validation.js +118 -0
- package/dist/lib/basic-editor/extensions/validation.module.js +25 -0
- package/dist/lib/basic-editor/extensions/validation_module.css +7 -0
- package/dist/lib/basic-editor/extensions/variable.js +190 -0
- package/dist/lib/basic-editor/index.js +193 -0
- package/dist/lib/code-editor/code-editor.js +117 -0
- package/dist/lib/code-editor/index.js +40 -0
- package/dist/lib/code-editor/json-editor.js +184 -0
- package/dist/lib/code-editor/raw-text-editor.js +70 -0
- package/dist/lib/code-editor/text-editor.js +75 -0
- package/dist/lib/code-editor/themes/coze-dark.js +136 -0
- package/dist/lib/code-editor/themes/coze-light.js +142 -0
- package/dist/lib/consts/index.js +38 -0
- package/dist/lib/dev-layout/index.js +69 -0
- package/dist/lib/index.js +110 -0
- package/dist/lib/mermaid-diagram/index.js +174 -0
- package/dist/lib/mermaid-diagram/index.module.js +25 -0
- package/dist/lib/mermaid-diagram/index_module.css +4 -0
- package/dist/lib/mermaid-diagram/use-svg-pan-zoom.js +83 -0
- package/dist/lib/mermaid-diagram/utils.js +98 -0
- package/dist/lib/model-config-editor/basic-type.js +105 -0
- package/dist/lib/model-config-editor/index.module.js +25 -0
- package/dist/lib/model-config-editor/index_module.css +8 -0
- package/dist/lib/model-config-editor/model-config-form.js +149 -0
- package/dist/lib/model-config-editor/popover-type.js +145 -0
- package/dist/lib/model-select/index.js +170 -0
- package/dist/lib/model-select/index.module.js +25 -0
- package/dist/lib/model-select/index_module.css +14 -0
- package/dist/lib/model-select/model-option/index.js +188 -0
- package/dist/lib/model-select/model-option/index.module.js +25 -0
- package/dist/lib/model-select/model-option/index_module.css +23 -0
- package/dist/lib/model-select/model-option-group/index.js +75 -0
- package/dist/lib/prompt-editor/index.js +218 -0
- package/dist/lib/prompt-editor/index.module.js +25 -0
- package/dist/lib/prompt-editor/index_module.css +71 -0
- package/dist/lib/prompt-editor/message-type-select.js +108 -0
- package/dist/lib/schema-editor/index.js +77 -0
- package/dist/lib/utils/base.js +82 -0
- package/dist/lib/utils/model-config.js +57 -0
- package/dist/types/basic-editor/custom-facet.d.ts +2 -0
- package/dist/types/basic-editor/diff.d.ts +15 -0
- package/dist/types/basic-editor/extensions/go-syntax.d.ts +71 -0
- package/dist/types/basic-editor/extensions/go-template.d.ts +1 -0
- package/dist/types/basic-editor/extensions/go-theme.d.ts +2 -0
- package/dist/types/basic-editor/extensions/jinja.d.ts +6 -0
- package/dist/types/basic-editor/extensions/keymap.d.ts +4 -0
- package/dist/types/basic-editor/extensions/language-support.d.ts +2 -0
- package/dist/types/basic-editor/extensions/markdown.d.ts +2 -0
- package/dist/types/basic-editor/extensions/search/dom/icon.d.ts +59 -0
- package/dist/types/basic-editor/extensions/search/dom/match-count.d.ts +14 -0
- package/dist/types/basic-editor/extensions/search/index.d.ts +1 -0
- package/dist/types/basic-editor/extensions/search/panel.d.ts +32 -0
- package/dist/types/basic-editor/extensions/search/theme.d.ts +1 -0
- package/dist/types/basic-editor/extensions/validation.d.ts +10 -0
- package/dist/types/basic-editor/extensions/variable.d.ts +14 -0
- package/dist/types/basic-editor/index.d.ts +28 -0
- package/dist/types/code-editor/code-editor.d.ts +23 -0
- package/dist/types/code-editor/index.d.ts +5 -0
- package/dist/types/code-editor/json-editor.d.ts +17 -0
- package/dist/types/code-editor/raw-text-editor.d.ts +11 -0
- package/dist/types/code-editor/text-editor.d.ts +23 -0
- package/dist/types/code-editor/themes/coze-dark.d.ts +1 -0
- package/dist/types/code-editor/themes/coze-light.d.ts +1 -0
- package/dist/types/consts/index.d.ts +3 -0
- package/dist/types/dev-layout/index.d.ts +13 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/mermaid-diagram/index.d.ts +12 -0
- package/dist/types/mermaid-diagram/use-svg-pan-zoom.d.ts +17 -0
- package/dist/types/mermaid-diagram/utils.d.ts +1 -0
- package/dist/types/model-config-editor/basic-type.d.ts +19 -0
- package/dist/types/model-config-editor/model-config-form.d.ts +14 -0
- package/dist/types/model-config-editor/popover-type.d.ts +25 -0
- package/dist/types/model-select/index.d.ts +38 -0
- package/dist/types/model-select/model-option/index.d.ts +30 -0
- package/dist/types/model-select/model-option-group/index.d.ts +15 -0
- package/dist/types/prompt-editor/index.d.ts +30 -0
- package/dist/types/prompt-editor/message-type-select.d.ts +16 -0
- package/dist/types/schema-editor/index.d.ts +18 -0
- package/dist/types/utils/base.d.ts +10 -0
- package/dist/types/utils/model-config.d.ts +4 -0
- package/package.json +75 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var jinja_exports = {};
|
|
20
|
+
__export(jinja_exports, {
|
|
21
|
+
default: () => jinja_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(jinja_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
var import_react2 = require("@coze-editor/editor/react");
|
|
26
|
+
var import_editor = require("@coze-editor/editor");
|
|
27
|
+
var import_view = require("@codemirror/view");
|
|
28
|
+
const prec = "lowest";
|
|
29
|
+
function JinjaHighlight({ isJinja2Template }) {
|
|
30
|
+
const injector = (0, import_react2.useInjector)();
|
|
31
|
+
(0, import_react.useLayoutEffect)(
|
|
32
|
+
() => injector.inject([
|
|
33
|
+
import_editor.astDecorator.whole.of((cursor) => {
|
|
34
|
+
if (cursor.name === "JinjaStatement" || cursor.name === "JinjaRawOpenStatement" || cursor.name === "JinjaRawCloseStatement") {
|
|
35
|
+
if (isJinja2Template) {
|
|
36
|
+
return {
|
|
37
|
+
type: "className",
|
|
38
|
+
className: "jinja-statement",
|
|
39
|
+
prec
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (cursor.name === "JinjaStringLiteral") {
|
|
44
|
+
if (isJinja2Template) {
|
|
45
|
+
return {
|
|
46
|
+
type: "className",
|
|
47
|
+
className: "jinja-string",
|
|
48
|
+
prec
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (cursor.name === "JinjaComment") {
|
|
53
|
+
if (isJinja2Template) {
|
|
54
|
+
return {
|
|
55
|
+
type: "className",
|
|
56
|
+
className: "jinja-comment",
|
|
57
|
+
prec
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (cursor.name === "JinjaExpression") {
|
|
62
|
+
return {
|
|
63
|
+
type: "className",
|
|
64
|
+
className: "jinja-expression",
|
|
65
|
+
prec
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (cursor.name === "JinjaFilterName" || cursor.name === "JinjaStatementStart" || cursor.name === "JinjaStatementEnd" || cursor.name === "JinjaKeyword" || cursor.name === "JinjaFilterName") {
|
|
69
|
+
if (isJinja2Template) {
|
|
70
|
+
return {
|
|
71
|
+
type: "className",
|
|
72
|
+
className: "jinja-statement-keyword",
|
|
73
|
+
prec
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}),
|
|
78
|
+
import_view.EditorView.theme({
|
|
79
|
+
".jinja-statement": {
|
|
80
|
+
color: "#060709CC"
|
|
81
|
+
},
|
|
82
|
+
".jinja-statement-keyword": {
|
|
83
|
+
color: "#D1009D"
|
|
84
|
+
},
|
|
85
|
+
".jinja-string": {
|
|
86
|
+
color: "#060709CC"
|
|
87
|
+
},
|
|
88
|
+
".jinja-comment": {
|
|
89
|
+
color: "#0607094D"
|
|
90
|
+
},
|
|
91
|
+
".jinja-expression": {
|
|
92
|
+
color: "var(--Green-COZColorGreen7, #00A136)"
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
]),
|
|
96
|
+
[injector, isJinja2Template]
|
|
97
|
+
);
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
var jinja_default = JinjaHighlight;
|
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var keymap_exports = {};
|
|
20
|
+
__export(keymap_exports, {
|
|
21
|
+
deleteMarkupBackward: () => deleteMarkupBackward,
|
|
22
|
+
insertFourSpaces: () => insertFourSpaces,
|
|
23
|
+
insertNewlineContinueMarkup: () => insertNewlineContinueMarkup
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(keymap_exports);
|
|
26
|
+
var import_preset_prompt = require("@coze-editor/editor/preset-prompt");
|
|
27
|
+
var import_state = require("@codemirror/state");
|
|
28
|
+
var import_language = require("@codemirror/language");
|
|
29
|
+
class Context {
|
|
30
|
+
constructor(props) {
|
|
31
|
+
this.node = props.node;
|
|
32
|
+
this.from = props.from;
|
|
33
|
+
this.to = props.to;
|
|
34
|
+
this.spaceBefore = props.spaceBefore;
|
|
35
|
+
this.spaceAfter = props.spaceAfter;
|
|
36
|
+
this.type = props.type;
|
|
37
|
+
this.item = props.item;
|
|
38
|
+
}
|
|
39
|
+
blank(maxWidth, trailing = true) {
|
|
40
|
+
let result = this.spaceBefore + (this.node.name === "Blockquote" ? ">" : "");
|
|
41
|
+
if (maxWidth !== null) {
|
|
42
|
+
while (result.length < maxWidth) {
|
|
43
|
+
result += " ";
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
for (let i = this.to - this.from - result.length - this.spaceAfter.length; i > 0; i--) {
|
|
48
|
+
result += " ";
|
|
49
|
+
}
|
|
50
|
+
return result + (trailing ? this.spaceAfter : "");
|
|
51
|
+
}
|
|
52
|
+
marker(doc, add) {
|
|
53
|
+
if (this.node.name === "OrderedList" && this.item) {
|
|
54
|
+
const numberMatch = itemNumber(this.item, doc);
|
|
55
|
+
if (numberMatch) {
|
|
56
|
+
const number = Number(numberMatch[2]) + add;
|
|
57
|
+
return `${this.spaceBefore}${number}.${this.spaceAfter}`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return `${this.spaceBefore}${this.type}${this.spaceAfter}`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function getContext(node, doc) {
|
|
64
|
+
const context = [];
|
|
65
|
+
let current = node;
|
|
66
|
+
while (current) {
|
|
67
|
+
if (current.name === "FencedCode") {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
if (current.name === "ListItem" || current.name === "Blockquote") {
|
|
71
|
+
const line = doc.lineAt(current.from);
|
|
72
|
+
const startPos = current.from - line.from;
|
|
73
|
+
const lineText = line.text.slice(startPos);
|
|
74
|
+
let contextPart = null;
|
|
75
|
+
if (current.name === "Blockquote") {
|
|
76
|
+
const match = /^ *>( ?)/.exec(lineText);
|
|
77
|
+
if (match) {
|
|
78
|
+
contextPart = new Context({
|
|
79
|
+
node: current,
|
|
80
|
+
from: startPos,
|
|
81
|
+
to: startPos + match[0].length,
|
|
82
|
+
spaceBefore: "",
|
|
83
|
+
spaceAfter: match[1],
|
|
84
|
+
type: ">",
|
|
85
|
+
item: null
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
} else if (current.name === "ListItem" && current.parent) {
|
|
89
|
+
if (current.parent.name === "OrderedList") {
|
|
90
|
+
const match = /^( *)(\d+)([.)])( *)/.exec(lineText);
|
|
91
|
+
if (match) {
|
|
92
|
+
let after = match[4];
|
|
93
|
+
let len = match[0].length;
|
|
94
|
+
if (after.length >= 4) {
|
|
95
|
+
after = after.slice(0, after.length - 4);
|
|
96
|
+
len -= 4;
|
|
97
|
+
}
|
|
98
|
+
contextPart = new Context({
|
|
99
|
+
node: current.parent,
|
|
100
|
+
from: startPos,
|
|
101
|
+
to: startPos + len,
|
|
102
|
+
spaceBefore: match[1],
|
|
103
|
+
spaceAfter: after,
|
|
104
|
+
type: match[2],
|
|
105
|
+
item: current
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
} else if (current.parent.name === "BulletList") {
|
|
109
|
+
const match = /^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(lineText);
|
|
110
|
+
if (match) {
|
|
111
|
+
let after = match[4];
|
|
112
|
+
let len = match[0].length;
|
|
113
|
+
if (after.length > 4) {
|
|
114
|
+
after = after.slice(0, after.length - 4);
|
|
115
|
+
len -= 4;
|
|
116
|
+
}
|
|
117
|
+
let type = match[2];
|
|
118
|
+
if (match[3]) {
|
|
119
|
+
type += match[3].replace(/[xX]/, " ");
|
|
120
|
+
}
|
|
121
|
+
contextPart = new Context({
|
|
122
|
+
node: current.parent,
|
|
123
|
+
from: startPos,
|
|
124
|
+
to: startPos + len,
|
|
125
|
+
spaceBefore: match[1],
|
|
126
|
+
spaceAfter: after,
|
|
127
|
+
type,
|
|
128
|
+
item: current
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (contextPart) {
|
|
134
|
+
context.unshift(contextPart);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
current = current.parent;
|
|
138
|
+
}
|
|
139
|
+
return context;
|
|
140
|
+
}
|
|
141
|
+
function itemNumber(item, doc) {
|
|
142
|
+
return /^(\s*)(\d+)(?=[.)])/.exec(doc.sliceString(item.from, item.from + 10));
|
|
143
|
+
}
|
|
144
|
+
function renumberList(after, doc, changes, offset = 0) {
|
|
145
|
+
let prev = -1;
|
|
146
|
+
let node = after;
|
|
147
|
+
while (node) {
|
|
148
|
+
if (node.name === "ListItem") {
|
|
149
|
+
const m = itemNumber(node, doc);
|
|
150
|
+
if (!m) {
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
const number = Number(m[2]);
|
|
154
|
+
if (prev >= 0) {
|
|
155
|
+
if (number !== prev + 1) {
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
changes.push({
|
|
159
|
+
from: node.from + m[1].length,
|
|
160
|
+
to: node.from + m[0].length,
|
|
161
|
+
insert: String(prev + 2 + offset)
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
prev = number;
|
|
165
|
+
}
|
|
166
|
+
node = node.nextSibling;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function normalizeIndent(content, state) {
|
|
170
|
+
const match = /^[ \t]*/.exec(content);
|
|
171
|
+
const blank = match ? match[0].length : 0;
|
|
172
|
+
if (!blank || state.facet(import_language.indentUnit) !== " ") {
|
|
173
|
+
return content;
|
|
174
|
+
}
|
|
175
|
+
const col = (0, import_state.countColumn)(content, 4, blank);
|
|
176
|
+
let space = "";
|
|
177
|
+
for (let i = col; i > 0; ) {
|
|
178
|
+
if (i >= 4) {
|
|
179
|
+
space += " ";
|
|
180
|
+
i -= 4;
|
|
181
|
+
} else {
|
|
182
|
+
space += " ";
|
|
183
|
+
i--;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return space + content.slice(blank);
|
|
187
|
+
}
|
|
188
|
+
function handleEmptyLineInList(state, context, inner, pos, line) {
|
|
189
|
+
if (!inner.item) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
const { doc } = state;
|
|
193
|
+
const firstItem = inner.node.firstChild;
|
|
194
|
+
const secondItem = inner.node.getChild("ListItem", "ListItem");
|
|
195
|
+
if (!firstItem) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
if (firstItem.to >= pos || secondItem && secondItem.to < pos || line.from > 0 && !/[^\s>]/.test(doc.lineAt(line.from - 1).text)) {
|
|
199
|
+
const changes = [];
|
|
200
|
+
const nextContext = context.length > 1 ? context[context.length - 2] : null;
|
|
201
|
+
let delTo;
|
|
202
|
+
let insert = "";
|
|
203
|
+
if (nextContext) {
|
|
204
|
+
delTo = line.from + (nextContext.item ? nextContext.from : nextContext.to);
|
|
205
|
+
if (nextContext.item) {
|
|
206
|
+
insert = nextContext.marker(doc, 1);
|
|
207
|
+
}
|
|
208
|
+
} else {
|
|
209
|
+
delTo = line.from;
|
|
210
|
+
}
|
|
211
|
+
changes.push({ from: delTo, to: pos, insert });
|
|
212
|
+
if (inner.node.name === "OrderedList" && inner.item) {
|
|
213
|
+
renumberList(inner.item, doc, changes, -2);
|
|
214
|
+
}
|
|
215
|
+
if ((nextContext == null ? void 0 : nextContext.node.name) === "OrderedList" && nextContext.item) {
|
|
216
|
+
renumberList(nextContext.item, doc, changes);
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
range: import_state.EditorSelection.cursor(delTo + insert.length),
|
|
220
|
+
changes
|
|
221
|
+
};
|
|
222
|
+
} else {
|
|
223
|
+
const insert = blankLine(context, state, line);
|
|
224
|
+
return {
|
|
225
|
+
range: import_state.EditorSelection.cursor(pos + insert.length + 1),
|
|
226
|
+
changes: { from: line.from, insert: insert + state.lineBreak }
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function handleEmptyBlockquote(state, inner, line) {
|
|
231
|
+
if (inner.node.name !== "Blockquote" || !line.from) {
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
const prevLine = state.doc.lineAt(line.from - 1);
|
|
235
|
+
const quoted = />\s*$/.exec(prevLine.text);
|
|
236
|
+
if (quoted && quoted.index === inner.from) {
|
|
237
|
+
const changes = state.changes([
|
|
238
|
+
{ from: prevLine.from + quoted.index, to: prevLine.to },
|
|
239
|
+
{ from: line.from + inner.from, to: line.to }
|
|
240
|
+
]);
|
|
241
|
+
return {
|
|
242
|
+
range: import_state.EditorSelection.cursor(changes.mapPos(line.from)),
|
|
243
|
+
changes
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
function continueMarkup(state, context, inner, pos, line) {
|
|
249
|
+
const { doc } = state;
|
|
250
|
+
const changes = [];
|
|
251
|
+
if (inner.node.name === "OrderedList" && inner.item) {
|
|
252
|
+
renumberList(inner.item, doc, changes);
|
|
253
|
+
}
|
|
254
|
+
const continued = !!inner.item && inner.item.from < line.from;
|
|
255
|
+
let insert = "";
|
|
256
|
+
const lineIndentMatch = /^[\s\d.)\-+*>]*/.exec(line.text);
|
|
257
|
+
const lineIndentLen = lineIndentMatch ? lineIndentMatch[0].length : 0;
|
|
258
|
+
if (!continued || lineIndentLen >= inner.to) {
|
|
259
|
+
for (let i = 0; i < context.length; i++) {
|
|
260
|
+
const c = context[i];
|
|
261
|
+
if (i === context.length - 1 && !continued) {
|
|
262
|
+
console.log("m", doc);
|
|
263
|
+
insert += c.marker(doc, 1);
|
|
264
|
+
} else {
|
|
265
|
+
const maxWidth = i < context.length - 1 ? (0, import_state.countColumn)(line.text, 4, context[i + 1].from) - insert.length : null;
|
|
266
|
+
insert += c.blank(maxWidth);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
let from = pos;
|
|
271
|
+
while (from > line.from && /\s/.test(line.text.charAt(from - line.from - 1))) {
|
|
272
|
+
from--;
|
|
273
|
+
}
|
|
274
|
+
insert = normalizeIndent(insert, state);
|
|
275
|
+
if (nonTightList(inner.node, state.doc)) {
|
|
276
|
+
insert = blankLine(context, state, line) + state.lineBreak + insert;
|
|
277
|
+
}
|
|
278
|
+
changes.push({ from, to: pos, insert: state.lineBreak + insert });
|
|
279
|
+
return {
|
|
280
|
+
range: import_state.EditorSelection.cursor(from + insert.length + 1),
|
|
281
|
+
changes
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
const insertNewlineContinueMarkup = ({
|
|
285
|
+
state,
|
|
286
|
+
dispatch
|
|
287
|
+
}) => {
|
|
288
|
+
const tree = (0, import_language.syntaxTree)(state);
|
|
289
|
+
const { doc } = state;
|
|
290
|
+
let fallthrough = false;
|
|
291
|
+
const changes = state.changeByRange((range) => {
|
|
292
|
+
if (!range.empty || !import_preset_prompt.markdownLanguage.isActiveAt(state, range.from)) {
|
|
293
|
+
fallthrough = true;
|
|
294
|
+
return { range };
|
|
295
|
+
}
|
|
296
|
+
const pos = range.from;
|
|
297
|
+
const line = doc.lineAt(pos);
|
|
298
|
+
const context = getContext(tree.resolveInner(pos, -1), doc);
|
|
299
|
+
while (context.length && context[context.length - 1].from > pos - line.from) {
|
|
300
|
+
context.pop();
|
|
301
|
+
}
|
|
302
|
+
if (!context.length) {
|
|
303
|
+
fallthrough = true;
|
|
304
|
+
return { range };
|
|
305
|
+
}
|
|
306
|
+
const inner = context[context.length - 1];
|
|
307
|
+
if (inner.to - inner.spaceAfter.length > pos - line.from) {
|
|
308
|
+
fallthrough = true;
|
|
309
|
+
return { range };
|
|
310
|
+
}
|
|
311
|
+
const isAtEndOfMarkup = pos >= inner.to - inner.spaceAfter.length;
|
|
312
|
+
const isLineEmptyAfterMarkup = !/\S/.test(
|
|
313
|
+
line.text.slice(inner.to - (line.from + inner.from))
|
|
314
|
+
);
|
|
315
|
+
if (isAtEndOfMarkup && isLineEmptyAfterMarkup) {
|
|
316
|
+
const emptyLineInListResult = handleEmptyLineInList(
|
|
317
|
+
state,
|
|
318
|
+
context,
|
|
319
|
+
inner,
|
|
320
|
+
pos,
|
|
321
|
+
line
|
|
322
|
+
);
|
|
323
|
+
if (emptyLineInListResult) {
|
|
324
|
+
return emptyLineInListResult;
|
|
325
|
+
}
|
|
326
|
+
const emptyBlockquoteResult = handleEmptyBlockquote(state, inner, line);
|
|
327
|
+
if (emptyBlockquoteResult) {
|
|
328
|
+
return emptyBlockquoteResult;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return continueMarkup(state, context, inner, pos, line);
|
|
332
|
+
});
|
|
333
|
+
if (fallthrough || changes.changes.empty) {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
dispatch(state.update(changes, { scrollIntoView: true, userEvent: "input" }));
|
|
337
|
+
return true;
|
|
338
|
+
};
|
|
339
|
+
function nonTightList(node, doc) {
|
|
340
|
+
if (node.name !== "OrderedList" && node.name !== "BulletList") {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
const first = node.firstChild;
|
|
344
|
+
const second = node.getChild("ListItem", "ListItem");
|
|
345
|
+
if (!first || !second) {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
const line1 = doc.lineAt(first.to);
|
|
349
|
+
const line2 = doc.lineAt(second.from);
|
|
350
|
+
const empty = /^[\s>]*$/.test(line1.text);
|
|
351
|
+
return line1.number + (empty ? 0 : 1) < line2.number;
|
|
352
|
+
}
|
|
353
|
+
function blankLine(context, state, line) {
|
|
354
|
+
let insert = "";
|
|
355
|
+
for (let i = 0; i < context.length - 1; i++) {
|
|
356
|
+
const c = context[i];
|
|
357
|
+
const next = context[i + 1];
|
|
358
|
+
const maxWidth = (0, import_state.countColumn)(line.text, 4, next.from) - insert.length;
|
|
359
|
+
insert += c.blank(maxWidth, true);
|
|
360
|
+
}
|
|
361
|
+
return normalizeIndent(insert, state);
|
|
362
|
+
}
|
|
363
|
+
function contextNodeForDelete(tree, pos) {
|
|
364
|
+
let node = tree.resolveInner(pos, -1);
|
|
365
|
+
let scan = pos;
|
|
366
|
+
const isMark = (n) => n.name === "QuoteMark" || n.name === "ListMark";
|
|
367
|
+
if (isMark(node) && node.parent) {
|
|
368
|
+
scan = node.from;
|
|
369
|
+
node = node.parent;
|
|
370
|
+
}
|
|
371
|
+
while (true) {
|
|
372
|
+
const prev = node.childBefore(scan);
|
|
373
|
+
if (!prev) {
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
if (isMark(prev)) {
|
|
377
|
+
scan = prev.from;
|
|
378
|
+
} else if ((prev.name === "OrderedList" || prev.name === "BulletList") && prev.lastChild) {
|
|
379
|
+
node = prev.lastChild;
|
|
380
|
+
scan = node.to;
|
|
381
|
+
} else {
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return node;
|
|
386
|
+
}
|
|
387
|
+
const deleteMarkupBackward = ({ state, dispatch }) => {
|
|
388
|
+
const tree = (0, import_language.syntaxTree)(state);
|
|
389
|
+
let fallthrough = false;
|
|
390
|
+
const changes = state.changeByRange((range) => {
|
|
391
|
+
const { from: pos, to } = range;
|
|
392
|
+
if (to !== pos || !import_preset_prompt.markdownLanguage.isActiveAt(state, pos)) {
|
|
393
|
+
fallthrough = true;
|
|
394
|
+
return { range };
|
|
395
|
+
}
|
|
396
|
+
const line = state.doc.lineAt(pos);
|
|
397
|
+
const context = getContext(contextNodeForDelete(tree, pos), state.doc);
|
|
398
|
+
if (!context.length) {
|
|
399
|
+
fallthrough = true;
|
|
400
|
+
return { range };
|
|
401
|
+
}
|
|
402
|
+
const inner = context[context.length - 1];
|
|
403
|
+
const spaceEnd = inner.to - inner.spaceAfter.length + (inner.spaceAfter ? 1 : 0);
|
|
404
|
+
if (pos - line.from > spaceEnd && !/\S/.test(line.text.slice(spaceEnd, pos - line.from))) {
|
|
405
|
+
const targetPos = line.from + spaceEnd;
|
|
406
|
+
return {
|
|
407
|
+
range: import_state.EditorSelection.cursor(targetPos),
|
|
408
|
+
changes: { from: targetPos, to: pos }
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
const isOnSyntaxLine = !inner.item || line.from <= inner.item.from || !/\S/.test(line.text.slice(0, inner.to));
|
|
412
|
+
if (pos - line.from === spaceEnd && isOnSyntaxLine) {
|
|
413
|
+
const start = line.from + inner.from;
|
|
414
|
+
if (inner.item && inner.node.from < inner.item.from && /\S/.test(line.text.slice(inner.from, inner.to))) {
|
|
415
|
+
let insert = inner.blank(
|
|
416
|
+
(0, import_state.countColumn)(line.text, 4, inner.to) - (0, import_state.countColumn)(line.text, 4, inner.from)
|
|
417
|
+
);
|
|
418
|
+
if (start === line.from) {
|
|
419
|
+
insert = normalizeIndent(insert, state);
|
|
420
|
+
}
|
|
421
|
+
return {
|
|
422
|
+
range: import_state.EditorSelection.cursor(start + insert.length),
|
|
423
|
+
changes: { from: start, to: line.from + inner.to, insert }
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
if (start < pos) {
|
|
427
|
+
return {
|
|
428
|
+
range: import_state.EditorSelection.cursor(start),
|
|
429
|
+
changes: { from: start, to: pos }
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
fallthrough = true;
|
|
434
|
+
return { range };
|
|
435
|
+
});
|
|
436
|
+
if (fallthrough || changes.changes.empty) {
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
dispatch(
|
|
440
|
+
state.update(changes, { scrollIntoView: true, userEvent: "delete" })
|
|
441
|
+
);
|
|
442
|
+
return true;
|
|
443
|
+
};
|
|
444
|
+
const insertFourSpaces = ({ state, dispatch }) => {
|
|
445
|
+
if (!state.selection.main.empty) {
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
dispatch(
|
|
449
|
+
state.update(
|
|
450
|
+
{
|
|
451
|
+
changes: { from: state.selection.main.head, insert: " " },
|
|
452
|
+
// 插入后,将光标移动到空格后面
|
|
453
|
+
selection: import_state.EditorSelection.cursor(state.selection.main.head + 2)
|
|
454
|
+
},
|
|
455
|
+
{ userEvent: "input" }
|
|
456
|
+
)
|
|
457
|
+
);
|
|
458
|
+
return true;
|
|
459
|
+
};
|
|
460
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
461
|
+
0 && (module.exports = {
|
|
462
|
+
deleteMarkupBackward,
|
|
463
|
+
insertFourSpaces,
|
|
464
|
+
insertNewlineContinueMarkup
|
|
465
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var language_support_exports = {};
|
|
20
|
+
__export(language_support_exports, {
|
|
21
|
+
default: () => language_support_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(language_support_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
var import_react2 = require("@coze-editor/editor/react");
|
|
26
|
+
var import_preset_prompt = require("@coze-editor/editor/preset-prompt");
|
|
27
|
+
function LanguageSupport() {
|
|
28
|
+
const injector = (0, import_react2.useInjector)();
|
|
29
|
+
(0, import_react.useLayoutEffect)(() => injector.inject([import_preset_prompt.languageSupport]), [injector]);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
var language_support_default = LanguageSupport;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var markdown_exports = {};
|
|
20
|
+
__export(markdown_exports, {
|
|
21
|
+
default: () => markdown_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(markdown_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
var import_react2 = require("@coze-editor/editor/react");
|
|
26
|
+
var import_editor = require("@coze-editor/editor");
|
|
27
|
+
var import_view = require("@codemirror/view");
|
|
28
|
+
function MarkdownHighlight() {
|
|
29
|
+
const injector = (0, import_react2.useInjector)();
|
|
30
|
+
(0, import_react.useLayoutEffect)(
|
|
31
|
+
() => injector.inject([
|
|
32
|
+
import_editor.astDecorator.whole.of((cursor) => {
|
|
33
|
+
if (cursor.name.startsWith("ATXHeading")) {
|
|
34
|
+
return {
|
|
35
|
+
type: "className",
|
|
36
|
+
className: "heading"
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (cursor.name === "Emphasis") {
|
|
40
|
+
return {
|
|
41
|
+
type: "className",
|
|
42
|
+
className: "emphasis"
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (cursor.name === "StrongEmphasis") {
|
|
46
|
+
return {
|
|
47
|
+
type: "className",
|
|
48
|
+
className: "strong-emphasis"
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (cursor.name === "ListMark" || cursor.name === "QuoteMark") {
|
|
52
|
+
return {
|
|
53
|
+
type: "className",
|
|
54
|
+
className: "mark"
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}),
|
|
58
|
+
import_view.EditorView.theme({
|
|
59
|
+
".heading": {
|
|
60
|
+
color: "#00818C",
|
|
61
|
+
fontWeight: "bold"
|
|
62
|
+
},
|
|
63
|
+
".emphasis": {
|
|
64
|
+
fontStyle: "italic"
|
|
65
|
+
},
|
|
66
|
+
".strong-emphasis": {
|
|
67
|
+
fontWeight: "bold"
|
|
68
|
+
},
|
|
69
|
+
".mark": {
|
|
70
|
+
color: "#4E40E5"
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
]),
|
|
74
|
+
[injector]
|
|
75
|
+
);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
var markdown_default = MarkdownHighlight;
|