@airalogy/aimd-editor 1.7.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 +59 -0
- package/README.zh-CN.md +43 -0
- package/dist/AimdEditorTopBar.vue_vue_type_script_setup_true_lang-gbfMDZSh.js +1131 -0
- package/dist/AimdSourceEditor.vue_vue_type_script_setup_true_lang-t_sUoXky.js +274 -0
- package/dist/AimdWysiwygEditor.vue_vue_type_script_setup_true_lang-B8o1VbUH.js +25012 -0
- package/dist/aimd-editor.css +1 -0
- package/dist/embedded.js +11 -0
- package/dist/index.js +44 -0
- package/dist/monaco.js +16 -0
- package/dist/theme-B8dCnOx-.js +583 -0
- package/dist/vue.js +30 -0
- package/dist/wysiwyg.js +9 -0
- package/package.json +90 -0
- package/src/__tests__/editor.test.ts +296 -0
- package/src/embedded.ts +18 -0
- package/src/index.ts +10 -0
- package/src/language-config.ts +152 -0
- package/src/monaco.ts +19 -0
- package/src/theme.ts +166 -0
- package/src/tokens.ts +120 -0
- package/src/vue/AimdEditor.vue +715 -0
- package/src/vue/AimdEditorToolbar.vue +83 -0
- package/src/vue/AimdEditorTopBar.vue +39 -0
- package/src/vue/AimdFieldDialog.vue +1102 -0
- package/src/vue/AimdSourceEditor.vue +330 -0
- package/src/vue/AimdWysiwygEditor.vue +569 -0
- package/src/vue/aimdInlineMarkdownNormalization.ts +10 -0
- package/src/vue/comparableAimdMarkdown.ts +6 -0
- package/src/vue/env.d.ts +7 -0
- package/src/vue/index.ts +45 -0
- package/src/vue/locales.ts +667 -0
- package/src/vue/milkdown-aimd-plugin.ts +378 -0
- package/src/vue/programmaticMarkdownSyncGuard.ts +66 -0
- package/src/vue/types.ts +449 -0
- package/src/vue/useEditorContent.ts +252 -0
- package/src/wysiwyg.ts +17 -0
package/src/theme.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { ThemeRegistration } from "shiki"
|
|
2
|
+
import { AimdToken } from "./tokens"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* AIMD token color settings
|
|
6
|
+
* These can be merged into any base theme
|
|
7
|
+
*/
|
|
8
|
+
export const aimdTokenColors = [
|
|
9
|
+
// {{ and }} brackets - green
|
|
10
|
+
{
|
|
11
|
+
scope: [
|
|
12
|
+
AimdToken.PUNCTUATION_DEFINITION_BEGIN_AIMD,
|
|
13
|
+
AimdToken.PUNCTUATION_DEFINITION_END_AIMD,
|
|
14
|
+
],
|
|
15
|
+
settings: {
|
|
16
|
+
foreground: "#059669",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
// var keyword - blue italic
|
|
20
|
+
{
|
|
21
|
+
scope: [
|
|
22
|
+
AimdToken.KEYWORD_VARIABLE_AIMD,
|
|
23
|
+
],
|
|
24
|
+
settings: {
|
|
25
|
+
foreground: "#2563EB",
|
|
26
|
+
fontStyle: "italic",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
// var_table keyword - green italic
|
|
30
|
+
{
|
|
31
|
+
scope: [AimdToken.KEYWORD_VARIABLE_TABLE_AIMD],
|
|
32
|
+
settings: {
|
|
33
|
+
foreground: "#059669",
|
|
34
|
+
fontStyle: "italic",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
// step, check keywords - orange italic
|
|
38
|
+
{
|
|
39
|
+
scope: [
|
|
40
|
+
AimdToken.KEYWORD_STEP_AIMD,
|
|
41
|
+
AimdToken.KEYWORD_CHECKPOINT_AIMD,
|
|
42
|
+
AimdToken.KEYWORD_CONTROL_AIMD,
|
|
43
|
+
],
|
|
44
|
+
settings: {
|
|
45
|
+
foreground: "#D97706",
|
|
46
|
+
fontStyle: "italic",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
// ref_var, ref_step reference keywords - cyan italic
|
|
50
|
+
{
|
|
51
|
+
scope: [
|
|
52
|
+
AimdToken.KEYWORD_REFERENCE_VARIABLE_AIMD,
|
|
53
|
+
AimdToken.KEYWORD_REFERENCE_STEP_AIMD,
|
|
54
|
+
],
|
|
55
|
+
settings: {
|
|
56
|
+
foreground: "#0891B2",
|
|
57
|
+
fontStyle: "italic",
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
// Variable names (title, name, age etc) - purple
|
|
61
|
+
{
|
|
62
|
+
scope: [AimdToken.VARIABLE_OTHER_AIMD],
|
|
63
|
+
settings: {
|
|
64
|
+
foreground: "#7C3AED",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
// Types (str, int, list[Student] etc) - dark purple italic
|
|
68
|
+
{
|
|
69
|
+
scope: [AimdToken.SUPPORT_TYPE_AIMD],
|
|
70
|
+
settings: {
|
|
71
|
+
foreground: "#6D28D9",
|
|
72
|
+
fontStyle: "italic",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
// Parameter variables - purple bold
|
|
76
|
+
{
|
|
77
|
+
scope: [AimdToken.VARIABLE_PARAMETER_AIMD],
|
|
78
|
+
settings: {
|
|
79
|
+
foreground: "#7C3AED",
|
|
80
|
+
fontStyle: "bold",
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
// | pipe delimiter - gray
|
|
84
|
+
{
|
|
85
|
+
scope: [AimdToken.DELIMITER_PIPE_AIMD],
|
|
86
|
+
settings: {
|
|
87
|
+
foreground: "#6B7280",
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
// : colon - gray
|
|
91
|
+
{
|
|
92
|
+
scope: [AimdToken.DELIMITER_COLON_AIMD],
|
|
93
|
+
settings: {
|
|
94
|
+
foreground: "#9CA3AF",
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
// = , and other delimiters - gray
|
|
98
|
+
{
|
|
99
|
+
scope: [AimdToken.DELIMITER_PARAMETER_AIMD],
|
|
100
|
+
settings: {
|
|
101
|
+
foreground: "#9CA3AF",
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
// Strings - green
|
|
105
|
+
{
|
|
106
|
+
scope: [AimdToken.STRING_QUOTED_AIMD],
|
|
107
|
+
settings: {
|
|
108
|
+
foreground: "#059669",
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
// Numbers - teal
|
|
112
|
+
{
|
|
113
|
+
scope: [AimdToken.CONSTANT_NUMERIC_AIMD],
|
|
114
|
+
settings: {
|
|
115
|
+
foreground: "#0D9488",
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
// Boolean/null - blue
|
|
119
|
+
{
|
|
120
|
+
scope: [AimdToken.CONSTANT_LANGUAGE_AIMD],
|
|
121
|
+
settings: {
|
|
122
|
+
foreground: "#1D4ED8",
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
// subvars keyword - dark purple bold
|
|
126
|
+
{
|
|
127
|
+
scope: [AimdToken.KEYWORD_OTHER_SUBVARS_AIMD],
|
|
128
|
+
settings: {
|
|
129
|
+
foreground: "#5B21B6",
|
|
130
|
+
fontStyle: "bold",
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
// Brackets [] () - gray
|
|
134
|
+
{
|
|
135
|
+
scope: [AimdToken.DELIMITER_BRACKET_AIMD],
|
|
136
|
+
settings: {
|
|
137
|
+
foreground: "#6B7280",
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
]
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* AIMD standalone theme
|
|
144
|
+
* Use this when you want a complete theme with only AIMD colors
|
|
145
|
+
*/
|
|
146
|
+
export const aimdTheme: ThemeRegistration = {
|
|
147
|
+
name: "aimd-theme",
|
|
148
|
+
type: "light",
|
|
149
|
+
settings: aimdTokenColors,
|
|
150
|
+
colors: {},
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Create a theme that extends a base theme with AIMD token colors
|
|
155
|
+
*/
|
|
156
|
+
export function createAimdExtendedTheme(
|
|
157
|
+
baseTheme: ThemeRegistration,
|
|
158
|
+
name = "aimd-extended",
|
|
159
|
+
): ThemeRegistration {
|
|
160
|
+
const baseSettings = baseTheme.settings || baseTheme.tokenColors || []
|
|
161
|
+
return {
|
|
162
|
+
...baseTheme,
|
|
163
|
+
name,
|
|
164
|
+
settings: [...baseSettings, ...aimdTokenColors],
|
|
165
|
+
}
|
|
166
|
+
}
|
package/src/tokens.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
type Join<T extends readonly string[], D extends string> =
|
|
2
|
+
T extends readonly [infer F, ...infer R]
|
|
3
|
+
? F extends string
|
|
4
|
+
? R extends readonly string[]
|
|
5
|
+
? R["length"] extends 0
|
|
6
|
+
? F
|
|
7
|
+
: `${F}${D}${Join<R, D>}`
|
|
8
|
+
: never
|
|
9
|
+
: never
|
|
10
|
+
: ""
|
|
11
|
+
|
|
12
|
+
type UpperCaseReplace<T extends string, S extends string, R extends string> = T extends `${infer P}${S}${infer REST}` ? `${P}${R}${UpperCaseReplace<REST, S, R>}` : T
|
|
13
|
+
type ToUpperSnake<T extends string> = UpperCaseReplace<UpperCaseReplace<Uppercase<T>, "-", "_">, ".", "_">
|
|
14
|
+
|
|
15
|
+
type ToUpperSnakeArray<T extends readonly string[]> =
|
|
16
|
+
T extends readonly [infer F, ...infer R]
|
|
17
|
+
? F extends string
|
|
18
|
+
? R extends readonly string[]
|
|
19
|
+
? [ToUpperSnake<F>, ...ToUpperSnakeArray<R>]
|
|
20
|
+
: []
|
|
21
|
+
: []
|
|
22
|
+
: []
|
|
23
|
+
|
|
24
|
+
export const AimdSuffix = "aimd"
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @docs https://microsoft.github.io/monaco-editor/monarch.html
|
|
28
|
+
* Standard CSS token classes include:
|
|
29
|
+
* identifier entity constructor
|
|
30
|
+
* operators tag namespace
|
|
31
|
+
* keyword info-token type
|
|
32
|
+
* string warn-token predefined
|
|
33
|
+
* string.escape error-token invalid
|
|
34
|
+
* comment debug-token
|
|
35
|
+
* comment.doc regexp
|
|
36
|
+
* constant attribute
|
|
37
|
+
* delimiter .[curly,square,parenthesis,angle,array,bracket]
|
|
38
|
+
* number .[hex,octal,binary,float]
|
|
39
|
+
* variable .[name,value]
|
|
40
|
+
* meta .[content]
|
|
41
|
+
*/
|
|
42
|
+
function tokenFactory<const T extends string[]>(...parts: T): {
|
|
43
|
+
[K in Join<ToUpperSnakeArray<T>, "_">]: Join<T, ".">
|
|
44
|
+
} {
|
|
45
|
+
const key = parts.map(p => p.toUpperCase().replace(/-/g, "_").replace(/\./g, "_")).join("_")
|
|
46
|
+
const value = parts.join(".")
|
|
47
|
+
return { [key]: value } as any
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function markupFactory<const T extends string>(type: T) {
|
|
51
|
+
return tokenFactory("markup", AimdSuffix, type)
|
|
52
|
+
}
|
|
53
|
+
function keywordFactory<const T extends string>(type: T) {
|
|
54
|
+
return tokenFactory("keyword", type, AimdSuffix)
|
|
55
|
+
}
|
|
56
|
+
// export const PunctuationDefinition = {
|
|
57
|
+
// ...punctuationFactory("variable"),
|
|
58
|
+
// ...punctuationFactory("variable-table"),
|
|
59
|
+
// ...punctuationFactory("checkpoint"),
|
|
60
|
+
// ...punctuationFactory("step"),
|
|
61
|
+
// ...punctuationFactory("reference"),
|
|
62
|
+
// } as const
|
|
63
|
+
|
|
64
|
+
export const MarkupDefinition = {
|
|
65
|
+
...markupFactory("variable"),
|
|
66
|
+
...markupFactory("variable-table"),
|
|
67
|
+
...markupFactory("checkpoint"),
|
|
68
|
+
...markupFactory("step"),
|
|
69
|
+
...markupFactory("reference.step"),
|
|
70
|
+
...markupFactory("reference.variable"),
|
|
71
|
+
} as const
|
|
72
|
+
|
|
73
|
+
export const KeywordDefinition = {
|
|
74
|
+
...keywordFactory("variable"),
|
|
75
|
+
...keywordFactory("variable-table"),
|
|
76
|
+
...keywordFactory("checkpoint"),
|
|
77
|
+
...keywordFactory("step"),
|
|
78
|
+
...keywordFactory("reference.step"),
|
|
79
|
+
...keywordFactory("reference.variable"),
|
|
80
|
+
} as const
|
|
81
|
+
|
|
82
|
+
export const DelimiterDefinition = {
|
|
83
|
+
...tokenFactory("delimiter", "pipe", AimdSuffix),
|
|
84
|
+
...tokenFactory("delimiter", "parameter", AimdSuffix),
|
|
85
|
+
...tokenFactory("delimiter", "colon", AimdSuffix),
|
|
86
|
+
...tokenFactory("delimiter", "bracket", AimdSuffix),
|
|
87
|
+
} as const
|
|
88
|
+
|
|
89
|
+
// export const EntityDefinition = {
|
|
90
|
+
// ...tokenFactory("entity", "name", "function", AimdSuffix),
|
|
91
|
+
// ...tokenFactory("entity", "name", "tag", AimdSuffix),
|
|
92
|
+
// } as const
|
|
93
|
+
|
|
94
|
+
export const AimdTokenDefinition = {
|
|
95
|
+
...tokenFactory("keyword", "control", AimdSuffix),
|
|
96
|
+
...tokenFactory("variable", "parameter", AimdSuffix),
|
|
97
|
+
...tokenFactory("metatag", "link", AimdSuffix),
|
|
98
|
+
...tokenFactory("string", "link", "description", AimdSuffix),
|
|
99
|
+
...tokenFactory("string", "link", "url", AimdSuffix),
|
|
100
|
+
...tokenFactory("metatag", "image", AimdSuffix),
|
|
101
|
+
// Type syntax tokens - using standard TextMate scopes for better theme compatibility
|
|
102
|
+
...tokenFactory("support", "type", AimdSuffix), // Types like str, int, list[Student] - usually colored as types
|
|
103
|
+
...tokenFactory("constant", "numeric", AimdSuffix), // Numbers like 18, 3.14
|
|
104
|
+
...tokenFactory("string", "quoted", AimdSuffix), // Strings like "Alice"
|
|
105
|
+
...tokenFactory("constant", "language", AimdSuffix), // true, false, null
|
|
106
|
+
...tokenFactory("variable", "other", AimdSuffix), // Variable names like name, age
|
|
107
|
+
...tokenFactory("keyword", "other", "subvars", AimdSuffix), // subvars keyword
|
|
108
|
+
} as const
|
|
109
|
+
|
|
110
|
+
export const AimdToken = {
|
|
111
|
+
...tokenFactory("punctuation", "definition", "begin", AimdSuffix),
|
|
112
|
+
...tokenFactory("punctuation", "definition", "end", AimdSuffix),
|
|
113
|
+
...MarkupDefinition,
|
|
114
|
+
...KeywordDefinition,
|
|
115
|
+
...DelimiterDefinition,
|
|
116
|
+
...AimdTokenDefinition,
|
|
117
|
+
} as const
|
|
118
|
+
|
|
119
|
+
// ScopeName based on markdown
|
|
120
|
+
export const scopeName = "text.html.markdown.aimd"
|