@airalogy/aimd-editor 1.7.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,274 +0,0 @@
1
- import { defineComponent as V, ref as p, onMounted as q, onBeforeUnmount as F, watch as u, openBlock as k, createElementBlock as b, normalizeStyle as P, toDisplayString as R, createCommentVNode as D, createElementVNode as K } from "vue";
2
- const Z = {
3
- key: 0,
4
- class: "aimd-editor-loading"
5
- }, G = /* @__PURE__ */ V({
6
- __name: "AimdSourceEditor",
7
- props: {
8
- content: {},
9
- theme: {},
10
- minHeight: {},
11
- readonly: { type: Boolean },
12
- monacoOptions: {},
13
- resolvedMessages: {}
14
- },
15
- emits: ["content-change", "ready", "monaco-loaded"],
16
- setup(l, { expose: _, emit: y }) {
17
- const n = l, c = y, x = /^\s*(```|~~~)\s*assigner(?:\s+.*\bruntime\s*=\s*(?:"client"|'client'|client)\b.*)\s*$/, h = /^\s*(```|~~~)\s*assigner(?:\s+.*)?\s*$/, E = /^\s*(```|~~~)\s*quiz(?:\s+.*)?\s*$/, v = /^\s*(```|~~~)\s*((?:\w|[/#-])+)(?:\s+.*)?\s*$/, C = /^\s*(```|~~~)\s*$/, m = p(null);
18
- let t = null, r = null, i = !1;
19
- const d = p(!0);
20
- function S(e) {
21
- const o = n.resolvedMessages;
22
- e.languages.getLanguages().some((s) => s.id === "aimd") || (e.languages.register({
23
- id: "aimd",
24
- extensions: [".aimd"],
25
- aliases: ["AIMD", "aimd"],
26
- mimetypes: ["text/x-aimd"]
27
- }), e.languages.setLanguageConfiguration("aimd", {
28
- brackets: [
29
- ["{", "}"],
30
- ["[", "]"],
31
- ["(", ")"]
32
- ],
33
- autoClosingPairs: [
34
- { open: "{", close: "}" },
35
- { open: "[", close: "]" },
36
- { open: "(", close: ")" },
37
- { open: '"', close: '"' },
38
- { open: "'", close: "'" },
39
- { open: "`", close: "`" },
40
- { open: "{{", close: "}}" }
41
- ],
42
- surroundingPairs: [
43
- { open: "{", close: "}" },
44
- { open: "[", close: "]" },
45
- { open: "(", close: ")" },
46
- { open: '"', close: '"' },
47
- { open: "'", close: "'" },
48
- { open: "`", close: "`" }
49
- ]
50
- }), e.languages.setMonarchTokensProvider("aimd", {
51
- defaultToken: "",
52
- tokenPostfix: ".aimd",
53
- tokenizer: {
54
- root: [
55
- [/\{\{/, { token: "delimiter.bracket.aimd", next: "@aimdField" }],
56
- [/^#{1,6}\s.*$/, "keyword.md"],
57
- [E, { token: "string.code", next: "@embeddedCodeblock", nextEmbedded: "yaml" }],
58
- [x, { token: "string.code", next: "@embeddedCodeblock", nextEmbedded: "javascript" }],
59
- [h, { token: "string.code", next: "@embeddedCodeblock", nextEmbedded: "python" }],
60
- [v, { token: "string.code", next: "@embeddedCodeblock", nextEmbedded: "$2" }],
61
- [C, { token: "string.code", next: "@codeblock" }],
62
- [/`[^`]+`/, "string.code"],
63
- [/\*\*[^*]+\*\*/, "strong"],
64
- [/__[^_]+__/, "strong"],
65
- [/\*[^*]+\*/, "emphasis"],
66
- [/_[^_]+_/, "emphasis"],
67
- [/\[[^\]]+\]\([^)]+\)/, "string.link"],
68
- [/!\[[^\]]*\]\([^)]+\)/, "string.link"],
69
- [/^>.*$/, "comment.quote"],
70
- [/^\s*[-*+]\s/, "keyword.list"],
71
- [/^\s*\d+\.\s/, "keyword.list"],
72
- [/^[-*_]{3,}\s*$/, "keyword.hr"],
73
- [/<\/?[\w-][^>]*>/, "tag"]
74
- ],
75
- aimdField: [
76
- [/\}\}/, { token: "delimiter.bracket.aimd", next: "@pop" }],
77
- [/\b(var_table|var|step|check|ref_step|ref_var|ref_fig|cite)\b/, "keyword.aimd"],
78
- [/\|/, "delimiter.aimd"],
79
- [/:/, "delimiter"],
80
- [/\b(str|int|float|bool|list|dict|any)\b/, "type.aimd"],
81
- [/\b[A-Z][A-Za-z0-9_]*(?:\[[A-Za-z0-9_,\s]+\])?\b/, "type.aimd"],
82
- [/[[\]()]/, "delimiter.bracket"],
83
- [/=/, "delimiter"],
84
- [/"[^"]*"/, "string"],
85
- [/'[^']*'/, "string"],
86
- [/-?\d+\.?\d*/, "number"],
87
- [/\b(true|false|True|False|null|None)\b/, "constant"],
88
- [/\bsubvars\b/, "keyword"],
89
- [/,/, "delimiter"],
90
- [/[A-Za-z_]\w*/, "variable.aimd"],
91
- [/\s+/, ""]
92
- ],
93
- codeblock: [
94
- [/^```\s*$/, { token: "string.code", next: "@pop" }],
95
- [/^~~~\s*$/, { token: "string.code", next: "@pop" }],
96
- [/.*$/, "string.code"]
97
- ],
98
- embeddedCodeblock: [
99
- [/^```\s*$/, { token: "string.code", next: "@pop", nextEmbedded: "@pop" }],
100
- [/^~~~\s*$/, { token: "string.code", next: "@pop", nextEmbedded: "@pop" }],
101
- [/.*$/, ""]
102
- ]
103
- }
104
- }), e.languages.registerCompletionItemProvider("aimd", {
105
- provideCompletionItems: () => {
106
- const s = ["var", "var_table", "step", "check", "ref_step", "ref_var", "ref_fig", "cite"], L = {
107
- var: "var_id",
108
- var_table: "table_id",
109
- step: "step_id",
110
- check: "check_id",
111
- ref_step: "step_id",
112
- ref_var: "var_id",
113
- ref_fig: "fig_id",
114
- cite: "ref_id"
115
- }, f = s.map((a) => ({
116
- label: `{{${a}|}}`,
117
- kind: e.languages.CompletionItemKind.Snippet,
118
- insertText: `{{${a}|\${1:${L[a] ?? "id"}}}}`,
119
- insertTextRules: e.languages.CompletionItemInsertTextRule.InsertAsSnippet,
120
- documentation: o.completions.insertAimdField(a)
121
- }));
122
- return f.push({
123
- label: o.completions.quizBlockLabel,
124
- kind: e.languages.CompletionItemKind.Snippet,
125
- insertText: [
126
- "```quiz",
127
- "id: ${1:quiz_choice_1}",
128
- "type: choice",
129
- "mode: single",
130
- "stem: |",
131
- ` \${2:${o.defaults.questionStem}}`,
132
- "options:",
133
- " - key: A",
134
- ` text: ${o.defaults.optionText("A")}`,
135
- " - key: B",
136
- ` text: ${o.defaults.optionText("B")}`,
137
- "answer: A",
138
- "```"
139
- ].join(`
140
- `),
141
- insertTextRules: e.languages.CompletionItemInsertTextRule.InsertAsSnippet,
142
- documentation: o.completions.quizBlock
143
- }), { suggestions: f };
144
- }
145
- }), e.editor.defineTheme("aimd-light", {
146
- base: "vs",
147
- inherit: !0,
148
- rules: [
149
- { token: "delimiter.bracket.aimd", foreground: "2563eb" },
150
- { token: "keyword.aimd", foreground: "2563eb", fontStyle: "bold" },
151
- { token: "delimiter.aimd", foreground: "6b7280" },
152
- { token: "type.aimd", foreground: "7c3aed" },
153
- { token: "variable.aimd", foreground: "059669" },
154
- { token: "keyword.md", foreground: "1e40af" },
155
- { token: "string.code", foreground: "be185d" },
156
- { token: "strong", fontStyle: "bold" },
157
- { token: "emphasis", fontStyle: "italic" },
158
- { token: "string.link", foreground: "2563eb" },
159
- { token: "comment.quote", foreground: "6b7280", fontStyle: "italic" }
160
- ],
161
- colors: {}
162
- }), e.editor.defineTheme("aimd-dark", {
163
- base: "vs-dark",
164
- inherit: !0,
165
- rules: [
166
- { token: "delimiter.bracket.aimd", foreground: "60a5fa" },
167
- { token: "keyword.aimd", foreground: "60a5fa", fontStyle: "bold" },
168
- { token: "delimiter.aimd", foreground: "9ca3af" },
169
- { token: "type.aimd", foreground: "a78bfa" },
170
- { token: "variable.aimd", foreground: "34d399" },
171
- { token: "keyword.md", foreground: "93c5fd" },
172
- { token: "string.code", foreground: "f472b6" },
173
- { token: "strong", fontStyle: "bold" },
174
- { token: "emphasis", fontStyle: "italic" },
175
- { token: "string.link", foreground: "60a5fa" },
176
- { token: "comment.quote", foreground: "9ca3af", fontStyle: "italic" }
177
- ],
178
- colors: {}
179
- }));
180
- }
181
- function $(e) {
182
- if (!m.value || t) return;
183
- const o = /* @__PURE__ */ new Set(["value", "language", "model"]), g = Object.fromEntries(
184
- Object.entries(n.monacoOptions).filter(([s]) => !o.has(s))
185
- );
186
- t = e.editor.create(m.value, {
187
- value: n.content,
188
- language: "aimd",
189
- theme: n.theme,
190
- minimap: { enabled: !1 },
191
- fontSize: 14,
192
- lineNumbers: "on",
193
- wordWrap: "on",
194
- scrollBeyondLastLine: !1,
195
- automaticLayout: !0,
196
- tabSize: 2,
197
- padding: { top: 12 },
198
- readOnly: n.readonly,
199
- ...g
200
- }), t.onDidChangeModelContent(() => {
201
- i || c("content-change", t.getValue());
202
- }), c("ready", t), c("monaco-loaded", e, t);
203
- }
204
- q(async () => {
205
- try {
206
- d.value = !0;
207
- const e = await import("monaco-editor");
208
- r = e, S(e), $(e);
209
- } finally {
210
- d.value = !1;
211
- }
212
- }), F(() => {
213
- t?.dispose();
214
- }), u(() => n.content, (e) => {
215
- !t || e === t.getValue() || (i = !0, t.setValue(e), i = !1);
216
- }), u(() => n.theme, (e) => {
217
- r && r.editor.setTheme(e);
218
- }), u(() => n.readonly, (e) => {
219
- t?.updateOptions({ readOnly: e });
220
- });
221
- function I() {
222
- return t;
223
- }
224
- function T() {
225
- return r;
226
- }
227
- function w(e) {
228
- t && (i = !0, t.setValue(e), i = !1);
229
- }
230
- function A() {
231
- return t?.getSelection();
232
- }
233
- function N(e, o) {
234
- t?.executeEdits(e, o);
235
- }
236
- function M() {
237
- t?.focus();
238
- }
239
- function O() {
240
- return t?.getModel();
241
- }
242
- function z() {
243
- return t?.getPosition();
244
- }
245
- function B() {
246
- return t?.getValue();
247
- }
248
- return _({
249
- getEditor: I,
250
- getMonaco: T,
251
- setValue: w,
252
- getSelection: A,
253
- executeEdits: N,
254
- focus: M,
255
- getModel: O,
256
- getPosition: z,
257
- getValue: B,
258
- loading: d
259
- }), (e, o) => (k(), b("div", {
260
- class: "aimd-editor-source-mode",
261
- style: P({ height: l.minHeight + "px" })
262
- }, [
263
- d.value ? (k(), b("div", Z, R(l.resolvedMessages.common.loadingEditor), 1)) : D("", !0),
264
- K("div", {
265
- ref_key: "editorContainer",
266
- ref: m,
267
- class: "aimd-editor-container"
268
- }, null, 512)
269
- ], 4));
270
- }
271
- });
272
- export {
273
- G as _
274
- };