@airalogy/aimd-recorder 1.14.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 +240 -0
- package/README.zh-CN.md +224 -0
- package/dist/AimdCodeField-DC3DPvgc.js +172 -0
- package/dist/AimdDnaSequenceField-__jdnFS9.js +59466 -0
- package/dist/AimdEditor.vue_vue_type_style_index_0_lang-Bq79rKNw.js +28370 -0
- package/dist/AimdMarkdownField-98ImHGbc.js +66 -0
- package/dist/AimdMarkdownNoteField-CuUJZkgT.js +185 -0
- package/dist/_.contribution-IP0cDNhs.js +38 -0
- package/dist/_commonjsHelpers-CZXJ37nu.js +40 -0
- package/dist/abap-Bs8kvjsq.js +1398 -0
- package/dist/aimd-recorder.css +1 -0
- package/dist/apex-Dspwrl5m.js +326 -0
- package/dist/assets/css.worker-Dmf38jDD.js +79 -0
- package/dist/assets/editor.worker-CpuX8TSY.js +12 -0
- package/dist/assets/html.worker-DotaEs7v.js +456 -0
- package/dist/assets/json.worker-B4VHhH6h.js +44 -0
- package/dist/assets/ts.worker-sl17zBDo.js +51316 -0
- package/dist/azcli-k1BiOau1.js +68 -0
- package/dist/bat-BIP72KWc.js +100 -0
- package/dist/bicep-VhQeYhS3.js +102 -0
- package/dist/cameligo-DnuAXtHg.js +174 -0
- package/dist/clojure-BAuDPsal.js +761 -0
- package/dist/coffee-BV06qSnj.js +232 -0
- package/dist/components.js +3595 -0
- package/dist/composables.js +72 -0
- package/dist/cpp-Cz8Jeyrf.js +389 -0
- package/dist/csharp-F6hhlXFb.js +326 -0
- package/dist/csp-KzlEHCyI.js +53 -0
- package/dist/css-e4FKntZ3.js +187 -0
- package/dist/cssMode-uz9U6SUU.js +1571 -0
- package/dist/cypher-CpvDGKRr.js +263 -0
- package/dist/dart-DdHeFWR0.js +281 -0
- package/dist/dockerfile-aoNXDcio.js +130 -0
- package/dist/ecl-C4Q0DYuA.js +456 -0
- package/dist/editor.api-CgD9w0gG.js +77091 -0
- package/dist/editor.main-Du02abDl.js +33783 -0
- package/dist/elixir-C9X42b0T.js +569 -0
- package/dist/flow9-Bff42pfB.js +142 -0
- package/dist/freemarker2-DFLX4iQ-.js +989 -0
- package/dist/fsharp-C6vPAsHG.js +217 -0
- package/dist/go-DEr8zx9f.js +218 -0
- package/dist/graphql-BiNBBRFh.js +151 -0
- package/dist/handlebars-aiZbIuWY.js +419 -0
- package/dist/hcl-2T9lKuFg.js +183 -0
- package/dist/html-phzTMObN.js +308 -0
- package/dist/htmlMode-BF7wMi3N.js +1581 -0
- package/dist/index.js +89 -0
- package/dist/ini-CZGtssYM.js +71 -0
- package/dist/ini.contribution-DyWtiacL.js +8 -0
- package/dist/java-B260NeH3.js +232 -0
- package/dist/javascript-BKKOItMi.js +70 -0
- package/dist/jsonMode-CDYK4B5l.js +1996 -0
- package/dist/julia-kuNLM9c5.js +511 -0
- package/dist/kotlin-Bz6kAefA.js +253 -0
- package/dist/less-AZUtS89I.js +162 -0
- package/dist/lexon-BcmgnyRb.js +157 -0
- package/dist/liquid-B2eRz5SA.js +240 -0
- package/dist/lua-Dz1RbATg.js +162 -0
- package/dist/m3-CIMooLFn.js +210 -0
- package/dist/markdown-C1BsCK9P.js +229 -0
- package/dist/markdown.contribution-DYYk6zUU.js +7 -0
- package/dist/mdx-BfV1HDRG.js +165 -0
- package/dist/mips-BovsnfLQ.js +198 -0
- package/dist/monaco.contribution-C-bQhUTI.js +114 -0
- package/dist/monaco.contribution-CCVvl3Jx.js +72 -0
- package/dist/monaco.contribution-Col-f0XR.js +164 -0
- package/dist/monaco.contribution-b5xkgQ-s.js +112 -0
- package/dist/msdax-CiRB2ZB-.js +375 -0
- package/dist/mysql-BwdpPE19.js +878 -0
- package/dist/objective-c-D4nfHfso.js +183 -0
- package/dist/pascal--j5-PYtz.js +251 -0
- package/dist/pascaligo-C7TcJxNL.js +164 -0
- package/dist/perl-BzEWqUb5.js +626 -0
- package/dist/pgsql-B_KZ0mGX.js +851 -0
- package/dist/php-A19QHzQV.js +500 -0
- package/dist/pla-COeKY1hA.js +137 -0
- package/dist/postiats-BfMp7zJL.js +907 -0
- package/dist/powerquery-B0TS_5Gb.js +890 -0
- package/dist/powershell-5jSbKdYB.js +239 -0
- package/dist/protobuf-YgnOutn3.js +420 -0
- package/dist/pug-DLej6kn5.js +402 -0
- package/dist/python-CQrZx9mR.js +301 -0
- package/dist/python.contribution-CcKs2Ktm.js +8 -0
- package/dist/qsharp-AhjqtSHB.js +301 -0
- package/dist/r-D-F4P80w.js +243 -0
- package/dist/razor-DWmpHMcx.js +550 -0
- package/dist/redis-hwwIlMnV.js +302 -0
- package/dist/redshift-Bcm_kjEG.js +809 -0
- package/dist/restructuredtext-CrdzfPP-.js +174 -0
- package/dist/ruby-QC2UNm1s.js +511 -0
- package/dist/rust-5aqiQ3L5.js +343 -0
- package/dist/sb-B1g1ZfLJ.js +115 -0
- package/dist/scala-C2U4R5Gb.js +370 -0
- package/dist/scheme-DeFRbslr.js +108 -0
- package/dist/scss-RSTCiCmI.js +262 -0
- package/dist/shell-BpF-iNu8.js +221 -0
- package/dist/shell.contribution-B80NZ3iO.js +7 -0
- package/dist/solidity-C00r2mbQ.js +1367 -0
- package/dist/sophia-DVW5ZKDB.js +199 -0
- package/dist/sparql-B0nmpxeX.js +201 -0
- package/dist/sql-CJwKPERn.js +853 -0
- package/dist/sql.contribution-DQy36aE5.js +7 -0
- package/dist/st-DPlKG5DT.js +416 -0
- package/dist/swift-YZBAbVHV.js +309 -0
- package/dist/systemverilog-CDQSaH63.js +576 -0
- package/dist/tcl-Dlu8sp6Q.js +232 -0
- package/dist/tsMode-Bh-v12OL.js +887 -0
- package/dist/twig-C5TO7-kw.js +392 -0
- package/dist/typescript-c7y6IZVP.js +343 -0
- package/dist/typespec-BsmjDEu7.js +117 -0
- package/dist/useFieldRendering-BIqeE3qo.js +6083 -0
- package/dist/vb-ChHvIDrk.js +372 -0
- package/dist/wgsl-XEp1ju8c.js +439 -0
- package/dist/xml-MAEprTnF.js +95 -0
- package/dist/xml.contribution-XMOaon8i.js +27 -0
- package/dist/yaml-C1p8rXG7.js +206 -0
- package/dist/yaml.contribution-DRRVhJmJ.js +8 -0
- package/package.json +88 -0
- package/src/__tests__/client-assigner.test.ts +341 -0
- package/src/__tests__/code-types.test.ts +30 -0
- package/src/__tests__/markdown-field.test.ts +34 -0
- package/src/__tests__/markdown-note-field.test.ts +135 -0
- package/src/__tests__/quiz-recorder.test.ts +195 -0
- package/src/__tests__/recorder-editor-content-sync.test.ts +172 -0
- package/src/__tests__/recorder-editor.test.ts +143 -0
- package/src/__tests__/recorder-render.test.ts +57 -0
- package/src/__tests__/recorder-wysiwyg-field-host.test.ts +33 -0
- package/src/__tests__/step-field.test.ts +270 -0
- package/src/__tests__/type-plugins.test.ts +59 -0
- package/src/__tests__/var-field-render.test.ts +26 -0
- package/src/client-assigner.ts +269 -0
- package/src/code-types.ts +94 -0
- package/src/components/AimdCodeField.vue +228 -0
- package/src/components/AimdDnaSequenceField.vue +983 -0
- package/src/components/AimdMarkdownField.vue +168 -0
- package/src/components/AimdMarkdownNoteField.vue +457 -0
- package/src/components/AimdQuizRecorder.vue +792 -0
- package/src/components/AimdRecorder.vue +1959 -0
- package/src/components/AimdRecorderEditor.vue +2281 -0
- package/src/components/AimdRecorderWysiwygFieldHost.vue +93 -0
- package/src/components/AimdRecorderWysiwygSurface.vue +487 -0
- package/src/components/AimdSeqVizViewer.vue +122 -0
- package/src/components/AimdStepCheckField.vue +453 -0
- package/src/components/AimdVarField.vue +213 -0
- package/src/components/AimdVarTableField.vue +516 -0
- package/src/components/DnaAnnotationEditor.vue +477 -0
- package/src/components/DnaSequenceEditor.vue +44 -0
- package/src/components/DnaSequenceToolbar.vue +98 -0
- package/src/components/DnaSequenceViewer.vue +162 -0
- package/src/components/index.ts +21 -0
- package/src/components/recorderMilkdownPlugin.ts +632 -0
- package/src/composables/__tests__/useDnaSequence.test.ts +467 -0
- package/src/composables/__tests__/useFieldAdapters.test.ts +115 -0
- package/src/composables/__tests__/useFocusManagement.test.ts +66 -0
- package/src/composables/__tests__/useRecordState.test.ts +586 -0
- package/src/composables/__tests__/useStepTimers.test.ts +64 -0
- package/src/composables/__tests__/useVarHelpers.test.ts +424 -0
- package/src/composables/__tests__/workbenchFieldEditing.test.ts +97 -0
- package/src/composables/index.ts +94 -0
- package/src/composables/useClientAssignerRunner.ts +74 -0
- package/src/composables/useDnaSequence.ts +400 -0
- package/src/composables/useDnaSequenceField.ts +316 -0
- package/src/composables/useFieldAdapters.ts +61 -0
- package/src/composables/useFieldRendering.ts +269 -0
- package/src/composables/useFocusManagement.ts +144 -0
- package/src/composables/useRecordState.ts +429 -0
- package/src/composables/useStepTimers.ts +243 -0
- package/src/composables/useVarHelpers.ts +545 -0
- package/src/composables/useVarTableDragDrop.ts +236 -0
- package/src/composables/workbenchFieldEditing.ts +705 -0
- package/src/css.d.ts +9 -0
- package/src/index.ts +65 -0
- package/src/locales.ts +559 -0
- package/src/monaco-code.ts +75 -0
- package/src/styles/aimd.css +994 -0
- package/src/type-plugins.ts +132 -0
- package/src/type-utils.ts +3 -0
- package/src/types.ts +191 -0
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
import { h, render, type AppContext } from 'vue'
|
|
2
|
+
import type { MilkdownPlugin } from '@milkdown/kit/ctx'
|
|
3
|
+
import type { NodeSchema, MarkdownNode } from '@milkdown/kit/transformer'
|
|
4
|
+
import { dropCursor } from '@milkdown/kit/prose/dropcursor'
|
|
5
|
+
import type { Node as ProsemirrorNode } from '@milkdown/kit/prose/model'
|
|
6
|
+
import type { EditorView, NodeView } from '@milkdown/kit/prose/view'
|
|
7
|
+
import { NodeSelection } from '@milkdown/kit/prose/state'
|
|
8
|
+
import { hardbreakAttr, hardbreakSchema } from '@milkdown/kit/preset/commonmark'
|
|
9
|
+
import { $node, $prose, $remark, $view } from '@milkdown/kit/utils'
|
|
10
|
+
import type { ExtractedAimdFields } from '@airalogy/aimd-core/types'
|
|
11
|
+
import {
|
|
12
|
+
aimdFieldInputRule,
|
|
13
|
+
aimdFieldNode,
|
|
14
|
+
aimdRemarkPlugin,
|
|
15
|
+
} from '@airalogy/aimd-editor/vue'
|
|
16
|
+
import type { AimdComponentRenderer } from '@airalogy/aimd-renderer'
|
|
17
|
+
import type { AimdRecorderMessagesInput } from '../locales'
|
|
18
|
+
import type {
|
|
19
|
+
AimdFieldMeta,
|
|
20
|
+
AimdFieldState,
|
|
21
|
+
AimdProtocolRecordData,
|
|
22
|
+
AimdRecorderFieldAdapters,
|
|
23
|
+
AimdStepDetailDisplay,
|
|
24
|
+
AimdTypePlugin,
|
|
25
|
+
FieldEventPayload,
|
|
26
|
+
TableEventPayload,
|
|
27
|
+
} from '../types'
|
|
28
|
+
import type { AimdWorkbenchFieldType } from '../composables/workbenchFieldEditing'
|
|
29
|
+
import { scanWorkbenchFields } from '../composables/workbenchFieldEditing'
|
|
30
|
+
import AimdRecorderWysiwygFieldHost from './AimdRecorderWysiwygFieldHost.vue'
|
|
31
|
+
|
|
32
|
+
export interface RecorderMilkdownFieldIdentity {
|
|
33
|
+
fieldType: AimdWorkbenchFieldType
|
|
34
|
+
id: string
|
|
35
|
+
raw: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface RecorderMilkdownSurfaceState {
|
|
39
|
+
record: AimdProtocolRecordData
|
|
40
|
+
readonly: boolean
|
|
41
|
+
currentUserName?: string
|
|
42
|
+
now?: Date | string | number
|
|
43
|
+
locale?: string
|
|
44
|
+
messages?: AimdRecorderMessagesInput
|
|
45
|
+
stepDetailDisplay: AimdStepDetailDisplay
|
|
46
|
+
fieldMeta?: Record<string, AimdFieldMeta>
|
|
47
|
+
fieldState?: Record<string, AimdFieldState>
|
|
48
|
+
wrapField?: (fieldKey: string, fieldType: string, defaultVNode: any) => any
|
|
49
|
+
customRenderers?: Partial<Record<string, AimdComponentRenderer>>
|
|
50
|
+
fieldAdapters?: AimdRecorderFieldAdapters
|
|
51
|
+
resolveFile?: (src: string) => string | null
|
|
52
|
+
typePlugins?: AimdTypePlugin[]
|
|
53
|
+
onUpdateRecord: (value: AimdProtocolRecordData) => void
|
|
54
|
+
onFieldsChange?: (fields: ExtractedAimdFields) => void
|
|
55
|
+
onError?: (message: string) => void
|
|
56
|
+
onFieldChange?: (payload: FieldEventPayload) => void
|
|
57
|
+
onFieldBlur?: (payload: FieldEventPayload) => void
|
|
58
|
+
onAssignerRequest?: (payload: FieldEventPayload) => void
|
|
59
|
+
onAssignerCancel?: (payload: FieldEventPayload) => void
|
|
60
|
+
onTableAddRow?: (payload: TableEventPayload) => void
|
|
61
|
+
onTableRemoveRow?: (payload: TableEventPayload) => void
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface RecorderMilkdownPluginOptions {
|
|
65
|
+
appContext?: AppContext | null
|
|
66
|
+
surfaceState: RecorderMilkdownSurfaceState
|
|
67
|
+
onEditField?: (field: RecorderMilkdownFieldIdentity) => void
|
|
68
|
+
onDeleteField?: (field: RecorderMilkdownFieldIdentity) => void
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const RECORDER_QUIZ_MDAST_TYPE = 'aimdRecorderQuizBlock'
|
|
72
|
+
const RECORDER_EDITABLE_INLINE_FIELD_TYPES = new Set(['var', 'var_table', 'step', 'check'])
|
|
73
|
+
|
|
74
|
+
const AIMD_COLORS: Record<string, string> = {
|
|
75
|
+
var: '#2563eb',
|
|
76
|
+
var_table: '#059669',
|
|
77
|
+
step: '#d97706',
|
|
78
|
+
check: '#dc2626',
|
|
79
|
+
ref_step: '#0891b2',
|
|
80
|
+
ref_var: '#0891b2',
|
|
81
|
+
ref_fig: '#0891b2',
|
|
82
|
+
cite: '#6d28d9',
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const AIMD_LABELS: Record<string, string> = {
|
|
86
|
+
var: 'var',
|
|
87
|
+
var_table: 'var_table',
|
|
88
|
+
step: 'step',
|
|
89
|
+
check: 'check',
|
|
90
|
+
ref_step: 'ref_step',
|
|
91
|
+
ref_var: 'ref_var',
|
|
92
|
+
ref_fig: 'ref_fig',
|
|
93
|
+
cite: 'cite',
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function isZhLocale(locale?: string): boolean {
|
|
97
|
+
return (locale || '').toLowerCase().startsWith('zh')
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function getRecorderNodeUi(locale?: string) {
|
|
101
|
+
const zh = isZhLocale(locale)
|
|
102
|
+
return {
|
|
103
|
+
edit: zh ? '编辑' : 'Edit',
|
|
104
|
+
editTitle: zh ? '编辑字段' : 'Edit field',
|
|
105
|
+
delete: zh ? '删除' : 'Delete',
|
|
106
|
+
deleteTitle: zh ? '删除字段' : 'Delete field',
|
|
107
|
+
dragTitle: zh ? '拖动字段' : 'Drag field',
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function buildInlineFieldRaw(fieldType: string, fieldContent: string): string {
|
|
112
|
+
return `{{${fieldType}|${fieldContent}}}`
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function buildQuizBlockRaw(fieldContent: string): string {
|
|
116
|
+
const normalizedContent = fieldContent.replace(/\r\n?/g, '\n').replace(/\n+$/, '')
|
|
117
|
+
return `\`\`\`quiz\n${normalizedContent}\n\`\`\``
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function resolveFieldIdentity(raw: string, fallbackFieldType: AimdWorkbenchFieldType): RecorderMilkdownFieldIdentity | null {
|
|
121
|
+
const matched = scanWorkbenchFields(raw)[0]
|
|
122
|
+
if (matched) {
|
|
123
|
+
return {
|
|
124
|
+
fieldType: matched.fieldType,
|
|
125
|
+
id: matched.id,
|
|
126
|
+
raw: matched.raw,
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
fieldType: fallbackFieldType,
|
|
132
|
+
id: '',
|
|
133
|
+
raw,
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function getColor(fieldType: string): string {
|
|
138
|
+
return AIMD_COLORS[fieldType] || '#6b7280'
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function remarkRecorderQuizBlock() {
|
|
142
|
+
function transformer(tree: any) {
|
|
143
|
+
visitNode(tree)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function visitNode(node: any) {
|
|
147
|
+
if (node.type === 'code' && node.lang === 'quiz') {
|
|
148
|
+
node.type = RECORDER_QUIZ_MDAST_TYPE
|
|
149
|
+
node.fieldContent = node.value || ''
|
|
150
|
+
node.data = {
|
|
151
|
+
hName: 'aimd-recorder-quiz',
|
|
152
|
+
hProperties: { fieldContent: node.fieldContent },
|
|
153
|
+
}
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (node.children) {
|
|
158
|
+
const nextChildren: any[] = []
|
|
159
|
+
for (const child of node.children) {
|
|
160
|
+
visitNode(child)
|
|
161
|
+
if (child._aimdChildren) {
|
|
162
|
+
nextChildren.push(...child._aimdChildren)
|
|
163
|
+
delete child._aimdChildren
|
|
164
|
+
continue
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
nextChildren.push(child)
|
|
168
|
+
}
|
|
169
|
+
node.children = nextChildren
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return transformer
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const recorderQuizRemarkPlugin = $remark('aimdRecorderQuizBlock', () => remarkRecorderQuizBlock())
|
|
177
|
+
|
|
178
|
+
const recorderQuizNode = $node('aimd_recorder_quiz', () => ({
|
|
179
|
+
group: 'block',
|
|
180
|
+
atom: true,
|
|
181
|
+
draggable: true,
|
|
182
|
+
attrs: {
|
|
183
|
+
fieldContent: { default: '' },
|
|
184
|
+
},
|
|
185
|
+
parseDOM: [{
|
|
186
|
+
tag: 'aimd-recorder-quiz',
|
|
187
|
+
getAttrs: (dom: HTMLElement) => ({
|
|
188
|
+
fieldContent: dom.getAttribute('data-field-content') || '',
|
|
189
|
+
}),
|
|
190
|
+
}],
|
|
191
|
+
toDOM: (node: ProsemirrorNode) => ['aimd-recorder-quiz', {
|
|
192
|
+
'data-field-content': node.attrs.fieldContent,
|
|
193
|
+
class: 'aimd-recorder-wysiwyg-field aimd-recorder-wysiwyg-field--block',
|
|
194
|
+
}],
|
|
195
|
+
parseMarkdown: {
|
|
196
|
+
match: (mdNode: MarkdownNode) => mdNode.type === RECORDER_QUIZ_MDAST_TYPE,
|
|
197
|
+
runner: (state, mdNode, proseType) => {
|
|
198
|
+
state.addNode(proseType, {
|
|
199
|
+
fieldContent: (mdNode as any).fieldContent || '',
|
|
200
|
+
})
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
toMarkdown: {
|
|
204
|
+
match: (node: ProsemirrorNode) => node.type.name === 'aimd_recorder_quiz',
|
|
205
|
+
runner: (state, node) => {
|
|
206
|
+
state.addNode('code', undefined, String(node.attrs.fieldContent || ''), { lang: 'quiz' })
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
} as NodeSchema))
|
|
210
|
+
|
|
211
|
+
class RecorderWidgetNodeView implements NodeView {
|
|
212
|
+
dom: HTMLElement
|
|
213
|
+
private bodyEl: HTMLElement
|
|
214
|
+
private summaryEl: HTMLElement
|
|
215
|
+
private editButtonEl: HTMLButtonElement | null = null
|
|
216
|
+
private deleteButtonEl: HTMLButtonElement | null = null
|
|
217
|
+
private dragHandleEl: HTMLElement | null = null
|
|
218
|
+
|
|
219
|
+
constructor(
|
|
220
|
+
private node: ProsemirrorNode,
|
|
221
|
+
private view: EditorView,
|
|
222
|
+
private getPos: () => number | undefined,
|
|
223
|
+
private options: RecorderMilkdownPluginOptions,
|
|
224
|
+
private block: boolean,
|
|
225
|
+
) {
|
|
226
|
+
const tagName = block ? 'div' : 'span'
|
|
227
|
+
const ui = getRecorderNodeUi(this.options.surfaceState.locale)
|
|
228
|
+
this.dom = document.createElement(tagName)
|
|
229
|
+
this.dom.className = [
|
|
230
|
+
'aimd-recorder-wysiwyg-node',
|
|
231
|
+
block ? 'aimd-recorder-wysiwyg-node--block' : 'aimd-recorder-wysiwyg-node--inline',
|
|
232
|
+
].join(' ')
|
|
233
|
+
this.dom.contentEditable = 'false'
|
|
234
|
+
this.dom.draggable = !this.options.surfaceState.readonly
|
|
235
|
+
|
|
236
|
+
const chromeEl = document.createElement(block ? 'div' : 'span')
|
|
237
|
+
chromeEl.className = [
|
|
238
|
+
'aimd-recorder-wysiwyg-node__chrome',
|
|
239
|
+
block ? 'aimd-recorder-wysiwyg-node__chrome--block' : 'aimd-recorder-wysiwyg-node__chrome--inline',
|
|
240
|
+
].join(' ')
|
|
241
|
+
|
|
242
|
+
this.summaryEl = document.createElement('span')
|
|
243
|
+
this.summaryEl.className = 'aimd-recorder-wysiwyg-node__summary'
|
|
244
|
+
chromeEl.appendChild(this.summaryEl)
|
|
245
|
+
|
|
246
|
+
const actionsEl = document.createElement('span')
|
|
247
|
+
actionsEl.className = 'aimd-recorder-wysiwyg-node__actions'
|
|
248
|
+
|
|
249
|
+
this.editButtonEl = document.createElement('button')
|
|
250
|
+
this.editButtonEl.type = 'button'
|
|
251
|
+
this.editButtonEl.className = 'aimd-recorder-wysiwyg-node__action aimd-recorder-wysiwyg-node__action--edit'
|
|
252
|
+
this.editButtonEl.textContent = ui.edit
|
|
253
|
+
this.editButtonEl.title = ui.editTitle
|
|
254
|
+
this.editButtonEl.setAttribute('aria-label', ui.editTitle)
|
|
255
|
+
this.editButtonEl.addEventListener('click', (event) => {
|
|
256
|
+
event.preventDefault()
|
|
257
|
+
event.stopPropagation()
|
|
258
|
+
if (this.options.surfaceState.readonly) {
|
|
259
|
+
return
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const identity = this.resolveIdentity()
|
|
263
|
+
if (identity) {
|
|
264
|
+
this.options.onEditField?.(identity)
|
|
265
|
+
}
|
|
266
|
+
})
|
|
267
|
+
actionsEl.appendChild(this.editButtonEl)
|
|
268
|
+
|
|
269
|
+
this.deleteButtonEl = document.createElement('button')
|
|
270
|
+
this.deleteButtonEl.type = 'button'
|
|
271
|
+
this.deleteButtonEl.className = 'aimd-recorder-wysiwyg-node__action aimd-recorder-wysiwyg-node__action--danger'
|
|
272
|
+
this.deleteButtonEl.textContent = ui.delete
|
|
273
|
+
this.deleteButtonEl.title = ui.deleteTitle
|
|
274
|
+
this.deleteButtonEl.setAttribute('aria-label', ui.deleteTitle)
|
|
275
|
+
this.deleteButtonEl.addEventListener('click', (event) => {
|
|
276
|
+
event.preventDefault()
|
|
277
|
+
event.stopPropagation()
|
|
278
|
+
if (this.options.surfaceState.readonly) {
|
|
279
|
+
return
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const identity = this.resolveIdentity()
|
|
283
|
+
if (identity) {
|
|
284
|
+
this.options.onDeleteField?.(identity)
|
|
285
|
+
}
|
|
286
|
+
})
|
|
287
|
+
actionsEl.appendChild(this.deleteButtonEl)
|
|
288
|
+
|
|
289
|
+
this.dragHandleEl = document.createElement('span')
|
|
290
|
+
this.dragHandleEl.className = 'aimd-recorder-wysiwyg-node__drag'
|
|
291
|
+
this.dragHandleEl.textContent = '::'
|
|
292
|
+
this.dragHandleEl.title = ui.dragTitle
|
|
293
|
+
this.dragHandleEl.setAttribute('data-drag-handle', 'true')
|
|
294
|
+
this.dragHandleEl.draggable = !this.options.surfaceState.readonly
|
|
295
|
+
this.dragHandleEl.addEventListener('mousedown', (event) => {
|
|
296
|
+
this.selectThisNode()
|
|
297
|
+
})
|
|
298
|
+
this.dragHandleEl.addEventListener('dragstart', () => {
|
|
299
|
+
this.selectThisNode()
|
|
300
|
+
})
|
|
301
|
+
actionsEl.appendChild(this.dragHandleEl)
|
|
302
|
+
|
|
303
|
+
chromeEl.appendChild(actionsEl)
|
|
304
|
+
this.dom.appendChild(chromeEl)
|
|
305
|
+
|
|
306
|
+
this.bodyEl = document.createElement(tagName)
|
|
307
|
+
this.bodyEl.className = 'aimd-recorder-wysiwyg-node__body'
|
|
308
|
+
this.dom.appendChild(this.bodyEl)
|
|
309
|
+
|
|
310
|
+
this.renderField()
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
private selectThisNode() {
|
|
314
|
+
const pos = this.getPos()
|
|
315
|
+
if (typeof pos !== 'number') {
|
|
316
|
+
return
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const transaction = this.view.state.tr.setSelection(NodeSelection.create(this.view.state.doc, pos))
|
|
320
|
+
this.view.dispatch(transaction)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private resolveIdentity(): RecorderMilkdownFieldIdentity | null {
|
|
324
|
+
return resolveFieldIdentity(this.resolveRaw(), this.resolveFieldType())
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
private resolveFieldType(): AimdWorkbenchFieldType {
|
|
328
|
+
if (this.block) {
|
|
329
|
+
return 'quiz'
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return (this.node.attrs.fieldType || 'var') as AimdWorkbenchFieldType
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
private resolveRaw(): string {
|
|
336
|
+
if (this.block) {
|
|
337
|
+
return buildQuizBlockRaw(String(this.node.attrs.fieldContent || ''))
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return buildInlineFieldRaw(
|
|
341
|
+
String(this.node.attrs.fieldType || 'var'),
|
|
342
|
+
String(this.node.attrs.fieldContent || ''),
|
|
343
|
+
)
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
private renderField() {
|
|
347
|
+
const identity = this.resolveIdentity()
|
|
348
|
+
const label = identity?.id
|
|
349
|
+
? `${identity.fieldType} ${identity.id}`
|
|
350
|
+
: this.resolveFieldType()
|
|
351
|
+
this.summaryEl.textContent = label
|
|
352
|
+
this.summaryEl.title = label
|
|
353
|
+
this.dom.setAttribute('data-field-type', this.resolveFieldType())
|
|
354
|
+
this.dom.draggable = !this.options.surfaceState.readonly
|
|
355
|
+
|
|
356
|
+
if (this.dragHandleEl) {
|
|
357
|
+
this.dragHandleEl.draggable = !this.options.surfaceState.readonly
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (this.editButtonEl) {
|
|
361
|
+
this.editButtonEl.disabled = this.options.surfaceState.readonly
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (this.deleteButtonEl) {
|
|
365
|
+
this.deleteButtonEl.disabled = this.options.surfaceState.readonly
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const vnode = h(AimdRecorderWysiwygFieldHost, {
|
|
369
|
+
surfaceState: this.options.surfaceState,
|
|
370
|
+
rawContent: this.resolveRaw(),
|
|
371
|
+
displayMode: this.block ? 'block' : 'inline',
|
|
372
|
+
})
|
|
373
|
+
vnode.appContext = this.options.appContext ?? null
|
|
374
|
+
render(vnode, this.bodyEl)
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
update(node: ProsemirrorNode): boolean {
|
|
378
|
+
if (node.type.name !== this.node.type.name) {
|
|
379
|
+
return false
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
this.node = node
|
|
383
|
+
this.renderField()
|
|
384
|
+
return true
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
selectNode() {
|
|
388
|
+
this.dom.classList.add('aimd-recorder-wysiwyg-node--selected')
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
deselectNode() {
|
|
392
|
+
this.dom.classList.remove('aimd-recorder-wysiwyg-node--selected')
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
stopEvent(event: Event): boolean {
|
|
396
|
+
const target = event.target
|
|
397
|
+
if (!(target instanceof Node)) {
|
|
398
|
+
return false
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if (this.dragHandleEl?.contains(target)) {
|
|
402
|
+
return false
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (this.dom.contains(target)) {
|
|
406
|
+
return true
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return false
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
ignoreMutation(): boolean {
|
|
413
|
+
return true
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
destroy() {
|
|
417
|
+
render(null, this.bodyEl)
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
class AimdFieldChipNodeView implements NodeView {
|
|
422
|
+
dom: HTMLElement
|
|
423
|
+
private node: ProsemirrorNode
|
|
424
|
+
private view: EditorView
|
|
425
|
+
private getPos: () => number | undefined
|
|
426
|
+
private editing = false
|
|
427
|
+
private labelEl: HTMLElement
|
|
428
|
+
private contentEl: HTMLElement
|
|
429
|
+
|
|
430
|
+
constructor(node: ProsemirrorNode, view: EditorView, getPos: () => number | undefined) {
|
|
431
|
+
this.node = node
|
|
432
|
+
this.view = view
|
|
433
|
+
this.getPos = getPos
|
|
434
|
+
|
|
435
|
+
const fieldType = String(node.attrs.fieldType || 'var')
|
|
436
|
+
const fieldContent = String(node.attrs.fieldContent || '')
|
|
437
|
+
const color = getColor(fieldType)
|
|
438
|
+
|
|
439
|
+
this.dom = document.createElement('span')
|
|
440
|
+
this.dom.className = 'aimd-field-chip'
|
|
441
|
+
this.dom.setAttribute('data-field-type', fieldType)
|
|
442
|
+
this.dom.contentEditable = 'false'
|
|
443
|
+
this.dom.style.cssText = `
|
|
444
|
+
display: inline-flex;
|
|
445
|
+
align-items: center;
|
|
446
|
+
gap: 3px;
|
|
447
|
+
padding: 1px 8px 1px 6px;
|
|
448
|
+
border-radius: 4px;
|
|
449
|
+
font-size: 13px;
|
|
450
|
+
font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
|
|
451
|
+
line-height: 1.6;
|
|
452
|
+
cursor: pointer;
|
|
453
|
+
user-select: none;
|
|
454
|
+
vertical-align: baseline;
|
|
455
|
+
border: 1px solid ${color}33;
|
|
456
|
+
background: ${color}0d;
|
|
457
|
+
color: ${color};
|
|
458
|
+
transition: all 0.15s;
|
|
459
|
+
`
|
|
460
|
+
|
|
461
|
+
this.labelEl = document.createElement('span')
|
|
462
|
+
this.labelEl.className = 'aimd-field-chip-label'
|
|
463
|
+
this.labelEl.textContent = AIMD_LABELS[fieldType] || fieldType
|
|
464
|
+
this.labelEl.style.cssText = `
|
|
465
|
+
font-weight: 600;
|
|
466
|
+
font-size: 11px;
|
|
467
|
+
opacity: 0.7;
|
|
468
|
+
margin-right: 2px;
|
|
469
|
+
`
|
|
470
|
+
|
|
471
|
+
this.contentEl = document.createElement('span')
|
|
472
|
+
this.contentEl.className = 'aimd-field-chip-content'
|
|
473
|
+
this.contentEl.textContent = fieldContent
|
|
474
|
+
this.contentEl.style.cssText = 'font-weight: 500;'
|
|
475
|
+
|
|
476
|
+
this.dom.appendChild(this.labelEl)
|
|
477
|
+
this.dom.appendChild(this.contentEl)
|
|
478
|
+
|
|
479
|
+
this.dom.addEventListener('mouseenter', () => {
|
|
480
|
+
this.dom.style.background = `${color}1a`
|
|
481
|
+
this.dom.style.borderColor = `${color}66`
|
|
482
|
+
})
|
|
483
|
+
this.dom.addEventListener('mouseleave', () => {
|
|
484
|
+
if (!this.editing) {
|
|
485
|
+
this.dom.style.background = `${color}0d`
|
|
486
|
+
this.dom.style.borderColor = `${color}33`
|
|
487
|
+
}
|
|
488
|
+
})
|
|
489
|
+
this.dom.addEventListener('click', (event) => {
|
|
490
|
+
event.preventDefault()
|
|
491
|
+
event.stopPropagation()
|
|
492
|
+
this.startEditing()
|
|
493
|
+
})
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
private startEditing() {
|
|
497
|
+
if (this.editing) {
|
|
498
|
+
return
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
this.editing = true
|
|
502
|
+
const fieldType = String(this.node.attrs.fieldType || 'var')
|
|
503
|
+
const fieldContent = String(this.node.attrs.fieldContent || '')
|
|
504
|
+
const color = getColor(fieldType)
|
|
505
|
+
|
|
506
|
+
this.contentEl.contentEditable = 'true'
|
|
507
|
+
this.contentEl.style.outline = 'none'
|
|
508
|
+
this.contentEl.style.minWidth = '30px'
|
|
509
|
+
this.contentEl.style.borderBottom = `1px dashed ${color}`
|
|
510
|
+
this.dom.style.background = `${color}1a`
|
|
511
|
+
this.dom.style.borderColor = `${color}66`
|
|
512
|
+
|
|
513
|
+
this.contentEl.focus()
|
|
514
|
+
const range = document.createRange()
|
|
515
|
+
range.selectNodeContents(this.contentEl)
|
|
516
|
+
const selection = window.getSelection()
|
|
517
|
+
selection?.removeAllRanges()
|
|
518
|
+
selection?.addRange(range)
|
|
519
|
+
|
|
520
|
+
const commit = () => {
|
|
521
|
+
this.editing = false
|
|
522
|
+
const newContent = this.contentEl.textContent || ''
|
|
523
|
+
this.contentEl.contentEditable = 'false'
|
|
524
|
+
this.contentEl.style.borderBottom = 'none'
|
|
525
|
+
this.dom.style.background = `${color}0d`
|
|
526
|
+
this.dom.style.borderColor = `${color}33`
|
|
527
|
+
|
|
528
|
+
if (newContent !== fieldContent) {
|
|
529
|
+
const pos = this.getPos()
|
|
530
|
+
if (pos !== undefined) {
|
|
531
|
+
this.view.dispatch(this.view.state.tr.setNodeMarkup(pos, undefined, {
|
|
532
|
+
...this.node.attrs,
|
|
533
|
+
fieldContent: newContent,
|
|
534
|
+
}))
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
this.contentEl.addEventListener('blur', commit, { once: true })
|
|
540
|
+
this.contentEl.addEventListener('keydown', (event) => {
|
|
541
|
+
if (event.key === 'Enter') {
|
|
542
|
+
event.preventDefault()
|
|
543
|
+
this.contentEl.blur()
|
|
544
|
+
}
|
|
545
|
+
if (event.key === 'Escape') {
|
|
546
|
+
event.preventDefault()
|
|
547
|
+
this.contentEl.textContent = fieldContent
|
|
548
|
+
this.contentEl.blur()
|
|
549
|
+
}
|
|
550
|
+
})
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
update(node: ProsemirrorNode): boolean {
|
|
554
|
+
if (node.type.name !== 'aimd_field') {
|
|
555
|
+
return false
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
this.node = node
|
|
559
|
+
const fieldType = String(node.attrs.fieldType || 'var')
|
|
560
|
+
const fieldContent = String(node.attrs.fieldContent || '')
|
|
561
|
+
const color = getColor(fieldType)
|
|
562
|
+
|
|
563
|
+
this.labelEl.textContent = AIMD_LABELS[fieldType] || fieldType
|
|
564
|
+
if (!this.editing) {
|
|
565
|
+
this.contentEl.textContent = fieldContent
|
|
566
|
+
}
|
|
567
|
+
this.dom.setAttribute('data-field-type', fieldType)
|
|
568
|
+
this.dom.style.borderColor = `${color}33`
|
|
569
|
+
this.dom.style.background = `${color}0d`
|
|
570
|
+
this.dom.style.color = color
|
|
571
|
+
return true
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
stopEvent(event: Event): boolean {
|
|
575
|
+
if (this.editing) {
|
|
576
|
+
return true
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
return event.type === 'click'
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
ignoreMutation(): boolean {
|
|
583
|
+
return true
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
destroy() {}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
const recorderInlineHardbreakSchema = hardbreakSchema.extendSchema((prev) => {
|
|
590
|
+
return (ctx) => {
|
|
591
|
+
const schema = prev(ctx)
|
|
592
|
+
return {
|
|
593
|
+
...schema,
|
|
594
|
+
toDOM: (node: ProsemirrorNode) => ['br', ctx.get(hardbreakAttr.key)(node)],
|
|
595
|
+
} as NodeSchema
|
|
596
|
+
}
|
|
597
|
+
})
|
|
598
|
+
|
|
599
|
+
const recorderDropCursorPlugin = $prose(() => dropCursor({
|
|
600
|
+
class: 'aimd-recorder-dropcursor',
|
|
601
|
+
color: false,
|
|
602
|
+
width: 4,
|
|
603
|
+
}))
|
|
604
|
+
|
|
605
|
+
export function createRecorderMilkdownPlugins(options: RecorderMilkdownPluginOptions): MilkdownPlugin[] {
|
|
606
|
+
const recorderFieldView = $view(aimdFieldNode, () => {
|
|
607
|
+
return (node, view, getPos) => {
|
|
608
|
+
const fieldType = String(node.attrs.fieldType || 'var')
|
|
609
|
+
if (RECORDER_EDITABLE_INLINE_FIELD_TYPES.has(fieldType)) {
|
|
610
|
+
return new RecorderWidgetNodeView(node, view, getPos, options, false)
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
return new AimdFieldChipNodeView(node, view, getPos)
|
|
614
|
+
}
|
|
615
|
+
})
|
|
616
|
+
|
|
617
|
+
const recorderQuizView = $view(recorderQuizNode, () => {
|
|
618
|
+
return (node, view, getPos) => new RecorderWidgetNodeView(node, view, getPos, options, true)
|
|
619
|
+
})
|
|
620
|
+
|
|
621
|
+
return [
|
|
622
|
+
aimdRemarkPlugin,
|
|
623
|
+
recorderQuizRemarkPlugin,
|
|
624
|
+
aimdFieldNode,
|
|
625
|
+
recorderQuizNode,
|
|
626
|
+
recorderFieldView,
|
|
627
|
+
recorderQuizView,
|
|
628
|
+
recorderInlineHardbreakSchema,
|
|
629
|
+
recorderDropCursorPlugin,
|
|
630
|
+
aimdFieldInputRule,
|
|
631
|
+
].flat()
|
|
632
|
+
}
|