vue-codemirror6 1.5.1 → 1.6.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.es.js","sources":["../src/Meta.ts","../src/helpers/h-demi.ts","../src/index.ts"],"sourcesContent":["import type MetaInterface from '@/interfaces/MetaInterface';\n\n// This file is auto-generated by the build system.\nexport const Meta: MetaInterface = {\n version: __APP_VERSION__,\n date: __BUILD_DATE__,\n};\n","/**\n * h-demi - h function for Vue 2 and 3\n *\n * @see {@link https://github.com/vueuse/vue-demi/issues/65}\n */\n\nimport {\n h as hDemi,\n isVue2,\n type Component,\n type VNode,\n type VNodeProps,\n} from 'vue-demi';\n\ninterface Options extends VNodeProps {\n class?: string;\n domProps?: VNodeProps;\n on?: Record<string, () => void>;\n props?: VNodeProps;\n style?: string;\n 'aria-hidden'?: string;\n}\n\nconst adaptOnsV3 = (\n ons: Record<string, () => void>\n): Record<string, () => void> => {\n if (!ons) return {};\n return Object.entries(ons).reduce((ret, [key, handler]) => {\n key = key.charAt(0).toUpperCase() + key.slice(1);\n key = `on${key}`;\n return { ...ret, [key]: handler };\n }, {});\n};\n\n/**\n * hDemi function.\n */\nexport default function h(\n type: string | Component,\n options: Options = {},\n children?: VNode | VNode[]\n): VNode {\n if (isVue2) {\n // Makeshift support :(\n // Since Vue2.7 includes the Composition API, the functions in vue-demi are not used.\n return hDemi(type, options, children);\n }\n const { props, domProps, on, ...extraOptions } = options;\n const ons = on ? adaptOnsV3(on) : {};\n\n return hDemi(\n type,\n { ...extraOptions, ...props, ...domProps, ...ons },\n children\n );\n}\n\nexport const slot = (\n defaultSlots: (() => VNode[]) | VNode[] | undefined\n): VNode[] =>\n typeof defaultSlots === 'function' ? defaultSlots() : (defaultSlots ?? []);\n","import { indentWithTab } from '@codemirror/commands';\nimport { indentUnit, type LanguageSupport } from '@codemirror/language';\nimport {\n diagnosticCount as linterDiagnosticCount,\n forceLinting,\n linter,\n lintGutter,\n type Diagnostic,\n type LintSource,\n} from '@codemirror/lint';\nimport {\n Compartment,\n EditorSelection,\n EditorState,\n StateEffect,\n type Transaction,\n type Extension,\n type SelectionRange,\n type StateField,\n type Text,\n} from '@codemirror/state';\nimport {\n EditorView,\n keymap,\n placeholder,\n type KeyBinding,\n type ViewUpdate,\n} from '@codemirror/view';\nimport { basicSetup, minimalSetup } from 'codemirror';\nimport {\n computed,\n defineComponent,\n nextTick,\n onMounted,\n onUnmounted,\n ref,\n shallowRef,\n watch,\n type App,\n type ComputedRef,\n type PropType,\n type Ref,\n type ShallowRef,\n type WritableComputedRef,\n} from 'vue-demi';\n\nimport type { StyleSpec } from 'style-mod';\n\nimport { Meta } from '@/Meta';\nimport h, { slot } from '@/helpers/h-demi';\n\n/** CodeMirror Component */\nconst CodeMirror = defineComponent({\n /** Component Name */\n name: 'CodeMirror',\n /** Model Definition */\n model: {\n prop: 'modelValue',\n event: 'update:modelValue',\n },\n /** Props Definition */\n props: {\n /** Model value */\n modelValue: {\n type: String as PropType<string | Text>,\n default: '',\n },\n /**\n * Theme\n *\n * @see {@link https://codemirror.net/docs/ref/#view.EditorView^theme}\n */\n theme: {\n type: Object as PropType<Record<string, StyleSpec>>,\n default: () => {\n return {};\n },\n },\n /** Dark Mode */\n dark: {\n type: Boolean,\n default: false,\n },\n /**\n * Use Basic Setup\n *\n * This will enable the basic setup for the editor.\n *\n * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup}\n */\n basic: {\n type: Boolean,\n default: false,\n },\n /**\n * Use Minimal Setup (The basic setting has priority.)\n *\n * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup}\n */\n minimal: {\n type: Boolean,\n default: false,\n },\n /**\n * Placeholder\n *\n * @see {@link https://codemirror.net/docs/ref/#view.placeholder}\n */\n placeholder: {\n type: String as PropType<string | HTMLElement>,\n default: undefined,\n },\n /**\n * Line wrapping\n *\n * An extension that enables line wrapping in the editor (by setting CSS white-space to pre-wrap in the content).\n *\n * @see {@link https://codemirror.net/docs/ref/#view.EditorView%5ElineWrapping}\n */\n wrap: {\n type: Boolean,\n default: false,\n },\n /**\n * Allow tab key indent.\n *\n * This will enable the tab key to indent the current line or selection.\n *\n * @see {@link https://codemirror.net/examples/tab/}\n */\n tab: {\n type: Boolean,\n default: false,\n },\n /**\n * Tab character\n *\n * This is the unit of indentation used when the editor is configured to indent with tabs.\n * It is also used to determine the size of the tab character when the editor is configured to use tabs for indentation..\n *\n * @see {@link https://codemirror.net/docs/ref/#state.EditorState^indentUnit}\n */\n indentUnit: {\n type: String,\n default: undefined,\n },\n /**\n * Allow Multiple Selection.\n *\n * This allows the editor to have multiple selections at the same time.\n * This is useful for editing multiple parts of the document at once.\n * If this is set to true, the editor will allow multiple selections.\n * If this is set to false, the editor will only allow a single selection.\n *\n * @see {@link https://codemirror.net/docs/ref/#state.EditorState^allowMultipleSelections}\n */\n allowMultipleSelections: {\n type: Boolean,\n default: false,\n },\n /**\n * Tab size\n *\n * This is the number of spaces that a tab character represents in the editor.\n * It is used to determine the size of the tab character when the editor is configured to use tabs for indentation.\n * If this is set to a number, the editor will use that number of spaces for each tab character.\n *\n * @see {@link https://codemirror.net/docs/ref/#state.EditorState^tabSize}\n */\n tabSize: {\n type: Number,\n default: undefined,\n },\n /**\n * Set line break (separetor) char.\n *\n * This is the character that is used to separate lines in the editor.\n * It is used to determine the line break character when the editor is configured to use a specific line break character.\n *\n * @see {@link https://codemirror.net/docs/ref/#state.EditorState^lineSeparator}\n */\n lineSeparator: {\n type: String,\n default: undefined,\n },\n /**\n * Readonly\n *\n * This is a CodeMirror Facet that allows you to set the editor to read-only mode.\n * When this is set to true, the editor will not allow any changes to be made to the document.\n * This is useful for displaying code that should not be edited, such as documentation or examples.\n * If this is set to false, the editor will allow changes to be made to the document.\n *\n * @see {@link https://codemirror.net/docs/ref/#state.EditorState^readOnly}\n */\n readonly: {\n type: Boolean,\n default: false,\n },\n /**\n * Disable input.\n *\n * This is the reversed value of the CodeMirror editable.\n * Similar to `readonly`, but setting this value to true disables dragging.\n *\n * @see {@link https://codemirror.net/docs/ref/#view.EditorView^editable}\n */\n disabled: {\n type: Boolean,\n default: false,\n },\n /**\n * Additional Extension\n *\n * You can use this to add any additional extensions that you want to use in the editor.\n *\n * @see {@link https://codemirror.net/docs/ref/#state.Extension}\n */\n extensions: {\n type: Array as PropType<Extension[]>,\n default: () => {\n return [];\n },\n },\n /**\n * Language Phreses\n *\n * This is a CodeMirror Facet that allows you to define custom phrases for the editor.\n * It can be used to override default phrases or add new ones.\n * This is useful for translating the editor to different languages or for customizing the editor's UI.\n *\n * @see {@link https://codemirror.net/examples/translate/}\n */\n phrases: {\n type: Object as PropType<Record<string, string>>,\n default: undefined,\n },\n /**\n * CodeMirror Language\n *\n * This is a CodeMirror Facet that allows you to define the language of the editor.\n * It can be used to enable syntax highlighting and other language-specific features.\n * It is useful for displaying code in a specific language, such as JavaScript, Python, or HTML.\n *\n * @see {@link https://codemirror.net/docs/ref/#language}\n */\n lang: {\n type: Object as PropType<LanguageSupport>,\n default: undefined,\n },\n /**\n * CodeMirror Linter\n *\n * This is a CodeMirror Facet that allows you to define a linter for the editor.\n * It can be used to check the code for errors and warnings, and to provide feedback to the user.\n * It is useful for displaying code in a specific language, such as JavaScript, Python, or HTML.\n * This is useful for providing feedback to the user about the code they are writing.\n *\n * @see {@link https://codemirror.net/docs/ref/#lint.linter}\n */\n linter: {\n type: Function as PropType<LintSource>,\n default: undefined,\n },\n /**\n * Linter Config\n *\n * This is a CodeMirror Facet that allows you to define the configuration for the linter.\n * It can be used to specify options for the linter, such as the severity of errors and warnings, and to customize the behavior of the linter.\n * This is useful for providing feedback to the user about the code they are writing.\n *\n * @see {@link https://codemirror.net/docs/ref/#lint.linter^config}\n */\n linterConfig: {\n type: Object,\n default: () => {\n return {};\n },\n },\n /**\n * Forces any linters configured to run when the editor is idle to run right away.\n *\n * This is useful for running linters on the initial load of the editor, or when the user has made changes to the code and wants to see the results immediately.\n *\n * @see {@link https://codemirror.net/docs/ref/#lint.forceLinting}\n */\n forceLinting: {\n type: Boolean,\n default: false,\n },\n /**\n * Show Linter Gutter\n *\n * An area to 🔴 the lines with errors will be displayed.\n * This feature is not enabled if `linter` is not specified.\n *\n * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter}\n */\n gutter: {\n type: Boolean,\n default: false,\n },\n /**\n * Gutter Config\n *\n * This is a CodeMirror Facet that allows you to define the configuration for the gutter.\n * It can be used to specify options for the gutter, such as the size of the gutter, the position of the gutter, and to customize the behavior of the gutter.\n * This is useful for providing feedback to the user about the code they are writing.\n *\n * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter^config}\n */\n gutterConfig: {\n type: Object,\n default: undefined,\n },\n /**\n * Using tag\n */\n tag: {\n type: String,\n default: 'div',\n },\n /**\n * Allows an external update to scroll the form.\n *\n * This is useful for scrolling the editor to a specific position when the user has made changes to the code and wants to see the results immediately.\n * If this is set to true, the editor will scroll to the position specified in the transaction.\n * If this is set to false, the editor will not scroll to the position specified in the transaction.\n *\n * @see {@link https://codemirror.net/docs/ref/#state.TransactionSpec.scrollIntoView}\n */\n scrollIntoView: {\n type: Boolean,\n default: true,\n },\n /**\n * Preserve the current scroll position on external updates.\n *\n * This keeps the editor's own scroll container from jumping when\n * `modelValue` is updated from outside the component.\n *\n * @see {@link https://codemirror.net/docs/ref/#view.EditorView.scrollSnapshot}\n */\n preserveScrollPosition: {\n type: Boolean,\n default: false,\n },\n /**\n * Key map\n * This is a CodeMirror Facet that allows you to define custom key bindings.\n * It can be used to override default key bindings or add new ones.\n *\n * @see {@link https://codemirror.net/docs/ref/#view.keymap}\n */\n keymap: {\n type: Array as PropType<KeyBinding[]>,\n default: () => [],\n },\n },\n /** Emits */\n emits: {\n /** Model Update */\n 'update:modelValue': (_value: string | Text = '') => true,\n /** CodeMirror ViewUpdate */\n update: (_value: ViewUpdate) => true,\n /** CodeMirror onReady */\n ready: (_value: {\n view: EditorView;\n state: EditorState;\n container: HTMLElement;\n }) => true,\n /** CodeMirror onFocus */\n focus: (_value: boolean) => true,\n /** State Changed */\n change: (_value: EditorState) => true,\n /** CodeMirror onDestroy */\n destroy: () => true,\n },\n /**\n * Setup\n *\n * @param props - Props\n * @param context - Context\n */\n setup(props, context) {\n /** Editor DOM */\n const editor: Ref<HTMLElement | undefined> = ref();\n\n /** Internal value */\n const doc: Ref<string | Text> = ref(props.modelValue);\n\n /**\n * CodeMirror Editor View\n *\n * @see {@link https://codemirror.net/docs/ref/#view.EditorView}\n */\n const view: ShallowRef<EditorView | undefined> = shallowRef(undefined);\n\n /**\n * Focus\n *\n * @see {@link https://codemirror.net/docs/ref/#view.EditorView.hasFocus}\n */\n const focus: WritableComputedRef<boolean> = computed({\n get: () => view.value?.hasFocus ?? false,\n set: f => {\n if (f && view.value) {\n view.value.focus();\n }\n },\n });\n\n /**\n * Editor Selection\n *\n * @see {@link https://codemirror.net/docs/ref/#state.EditorSelection}\n */\n const selection: WritableComputedRef<EditorSelection | undefined> =\n computed({\n get: () => view.value?.state.selection,\n set: selection => {\n if (view.value && selection) {\n view.value.dispatch({ selection });\n }\n },\n });\n\n /** Cursor Position */\n const cursor: WritableComputedRef<number> = computed({\n get: () => view.value?.state.selection.main.head ?? 0,\n set: anchor => {\n if (view.value) {\n view.value.dispatch({ selection: { anchor } });\n }\n },\n });\n\n /** JSON */\n const json: WritableComputedRef<\n Record<string, StateField<unknown>> | undefined\n > = computed({\n get: () => view.value?.state.toJSON(),\n set: j => {\n if (view.value && j) {\n view.value.setState(EditorState.fromJSON(j));\n }\n },\n });\n\n /** Text length */\n const length: Ref<number> = ref(0);\n\n /**\n * Returns the number of active lint diagnostics in the given state.\n *\n * @see {@link https://codemirror.net/docs/ref/#lint.diagnosticCount}\n */\n const diagnosticCount: Ref<number> = ref(0);\n\n /** Get CodeMirror Extension */\n const extensions: ComputedRef<Extension[]> = computed(() => {\n // Synamic Reconfiguration\n // @see https://codemirror.net/examples/config/\n const language = new Compartment();\n const tabSize = new Compartment();\n if (props.basic && props.minimal) {\n throw new Error(\n '[Vue CodeMirror] Both basic and minimal cannot be specified.'\n );\n }\n /** Keymap */\n let keymaps: KeyBinding[] = [];\n if (props.keymap && props.keymap.length > 0) {\n // If keymap is specified, use it.\n keymaps = props.keymap;\n }\n if (props.tab) {\n // If tab is enabled, add indentWithTab to keymap.\n keymaps.push(indentWithTab);\n }\n\n // TODO: Ignore previous prop was not changed.\n return [\n // Toggle basic setup\n props.basic && !props.minimal ? basicSetup : undefined,\n // Toggle minimal setup\n props.minimal && !props.basic ? minimalSetup : undefined,\n // ViewUpdate event listener\n EditorView.updateListener.of((update: ViewUpdate): void => {\n if (!view.value) {\n return;\n }\n // Emit focus status\n context.emit('focus', view.value.hasFocus);\n\n // Update count\n length.value = view.value.state.doc?.length;\n\n if (update.changes.empty || !update.docChanged) {\n // Suppress event firing if no change\n return;\n }\n if (props.linter) {\n // Linter process\n if (props.forceLinting) {\n // If forceLinting enabled, first liting.\n forceLinting(view.value);\n }\n // Count diagnostics.\n diagnosticCount.value = (\n props.linter(view.value) as readonly Diagnostic[]\n ).length;\n }\n context.emit('update', update);\n }),\n // Toggle light/dark mode.\n EditorView.theme(props.theme, { dark: props.dark }),\n // Toggle line wrapping\n props.wrap ? EditorView.lineWrapping : undefined,\n // Tab character\n props.indentUnit ? indentUnit.of(props.indentUnit) : undefined,\n // Allow Multiple Selections\n EditorState.allowMultipleSelections.of(props.allowMultipleSelections),\n // Indent tab size\n props.tabSize\n ? tabSize.of(EditorState.tabSize.of(props.tabSize))\n : undefined,\n // locale settings\n props.phrases ? EditorState.phrases.of(props.phrases) : undefined,\n // Readonly option\n EditorState.readOnly.of(props.readonly),\n // Editable option\n EditorView.editable.of(!props.disabled),\n // Set Line break char\n props.lineSeparator\n ? EditorState.lineSeparator.of(props.lineSeparator)\n : undefined,\n // Lang\n props.lang ? language.of(props.lang) : undefined,\n // Append Linter settings\n props.linter ? linter(props.linter, props.linterConfig) : undefined,\n // Show 🔴 to error line when linter enabled.\n props.linter && props.gutter\n ? lintGutter(props.gutterConfig)\n : undefined,\n // Placeholder\n props.placeholder ? placeholder(props.placeholder) : undefined,\n // Keymap and Indent with Tab\n keymaps.length > 0 ? keymap.of(keymaps) : undefined,\n // Append Extensions\n ...props.extensions,\n ].filter((extension): extension is Extension => !!extension); // Filter undefined\n });\n\n // Extension (mostly props) Changed\n watch(\n extensions,\n exts =>\n view.value?.dispatch({ effects: StateEffect.reconfigure.of(exts) }),\n { immediate: true }\n );\n\n // for parent-to-child binding.\n watch(\n () => props.modelValue,\n async value => {\n if (!view.value) {\n return;\n }\n if (\n view.value.composing || // IME fix\n view.value.state.doc.toJSON().join(props.lineSeparator ?? '\\n') ===\n value // don't need to update\n ) {\n // Do not commit CodeMirror's store.\n return;\n }\n\n // Range Fix ?\n // https://github.com/logue/vue-codemirror6/issues/27\n const isSelectionOutOfRange = !view.value.state.selection.ranges.every(\n range => range.anchor < value.length && range.head < value.length\n );\n\n /** Scroll Fix */\n const changes = {\n from: 0,\n to: view.value.state.doc.length,\n insert: value,\n };\n // If preserveScrollPosition is enabled, create a scroll snapshot before updating the document.\n const scrollSnapshot = props.preserveScrollPosition\n ? view.value.scrollSnapshot().map(view.value.state.changes(changes))\n : undefined;\n\n // Update\n view.value.dispatch({\n changes,\n selection: isSelectionOutOfRange\n ? { anchor: 0, head: 0 }\n : view.value.state.selection,\n scrollIntoView: props.scrollIntoView,\n effects: scrollSnapshot ? [scrollSnapshot] : undefined,\n });\n },\n { immediate: true }\n );\n\n /** When loaded */\n onMounted(async () => {\n // Skip initialization in SSR environment\n if (globalThis.window === undefined || !editor.value) {\n return;\n }\n\n /** Initial value */\n let value: string | Text = doc.value;\n\n if (editor.value.childNodes[0]) {\n // when slot mode, overwrite initial value\n if (doc.value !== '') {\n console.warn(\n '[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values.'\n );\n }\n value = (editor.value.childNodes[0] as HTMLElement).innerText.trim();\n }\n\n // Register Codemirror\n view.value = new EditorView({\n parent: editor.value,\n state: EditorState.create({ doc: value, extensions: extensions.value }),\n dispatch: (tr: Transaction) => {\n if (!view.value) {\n return;\n }\n view.value.update([tr]);\n if (tr.changes.empty || !tr.docChanged) {\n // if not change value, no fire emit event\n return;\n }\n\n // console.log(view.state.doc.toString(), tr);\n // state.toString() is not defined, so use toJSON and toText function to convert string.\n context.emit('update:modelValue', tr.state.doc.toString());\n // Emit EditorState\n context.emit('change', tr.state);\n },\n });\n\n await nextTick();\n\n context.emit('ready', {\n view: view.value,\n state: view.value.state,\n container: editor.value,\n });\n });\n\n /** Destroy */\n onUnmounted(() => {\n if (view.value) {\n view.value.destroy();\n context.emit('destroy');\n }\n });\n\n /**\n * Forces any linters configured to run when the editor is idle to run right away.\n *\n * @see {@link https://codemirror.net/docs/ref/#lint.forceLinting}\n */\n const lint = (): void => {\n if (!props.linter || !view.value) {\n return;\n }\n if (props.forceLinting) {\n forceLinting(view.value);\n }\n diagnosticCount.value = linterDiagnosticCount(view.value.state);\n };\n\n /**\n * Force Reconfigure Extension\n *\n * @see {@link https://codemirror.net/examples/config/#top-level-reconfiguration}\n */\n const forceReconfigure = (): void => {\n // Deconfigure all Extensions\n view.value?.dispatch({\n effects: StateEffect.reconfigure.of([]),\n });\n // Register extensions\n view.value?.dispatch({\n effects: StateEffect.appendConfig.of(extensions.value),\n });\n };\n\n /* ----- Bellow is experimental. ------ */\n\n /**\n * Get the text between the given points in the editor.\n *\n * @param from - start line number\n * @param to - end line number\n */\n const getRange = (from?: number, to?: number): string | undefined =>\n view.value?.state.sliceDoc(from, to);\n /**\n * Get the content of line.\n *\n * @param number - line number\n */\n const getLine = (number: number): string | undefined =>\n view.value?.state.doc.line(number + 1).text;\n /** Get the number of lines in the editor. */\n const lineCount = (): number => view.value?.state.doc.lines ?? 0;\n /** Retrieve one end of the primary selection. */\n const getCursor = (): number => view.value?.state.selection.main.head ?? 0;\n /** Retrieves a list of all current selections. */\n const listSelections = (): readonly SelectionRange[] => {\n return view.value?.state.selection.ranges ?? [];\n };\n /** Get the currently selected code. */\n const getSelection = (): string => {\n if (!view.value) {\n return '';\n }\n return view.value.state.sliceDoc(\n view.value.state.selection.main.from,\n view.value.state.selection.main.to\n );\n };\n /**\n * The length of the given array should be the same as the number of active selections.\n * Replaces the content of the selections with the strings in the array.\n */\n const getSelections = (): string[] => {\n const s = view.value?.state;\n if (!s) {\n return [];\n }\n\n return s.selection.ranges.map((r: { from: number; to: number }) =>\n s.sliceDoc(r.from, r.to)\n );\n };\n /** Return true if any text is selected. */\n const somethingSelected = (): boolean =>\n view.value?.state.selection.ranges.some(\n (r: { empty: boolean }) => !r.empty\n ) ?? false;\n\n /**\n * Replace the part of the document between from and to with the given string.\n *\n * @param replacement - replacement text\n * @param from - start string at position\n * @param to - insert the string at position\n */\n const replaceRange = (\n replacement: string | Text,\n from: number,\n to: number\n ): void => {\n if (view.value) {\n view.value.dispatch({\n changes: { from, to, insert: replacement },\n });\n }\n };\n /**\n * Replace the selection(s) with the given string.\n * By default, the new selection ends up after the inserted text.\n *\n * @param replacement - replacement text\n */\n const replaceSelection = (replacement: string | Text): void => {\n if (view.value) {\n view.value.dispatch(view.value.state.replaceSelection(replacement));\n }\n };\n /**\n * Set the cursor position.\n *\n * @param position - position.\n */\n const setCursor = (position: number): void => {\n if (view.value) {\n view.value.dispatch({ selection: { anchor: position } });\n }\n };\n /**\n * Set a single selection range.\n *\n * @param anchor - anchor position\n * @param head -\n */\n const setSelection = (anchor: number, head?: number): void => {\n if (view.value) {\n view.value.dispatch({ selection: { anchor, head } });\n }\n };\n /**\n * Sets a new set of selections. There must be at least one selection in the given array.\n *\n * @param ranges - Selection range\n * @param primary -\n */\n const setSelections = (\n ranges: readonly SelectionRange[],\n primary?: number\n ): void => {\n if (view.value) {\n view.value.dispatch({\n selection: EditorSelection.create(ranges, primary),\n });\n }\n };\n /**\n * Applies the given function to all existing selections, and calls extendSelections on the result.\n *\n * @param f - function\n */\n const extendSelectionsBy = (f: (range: SelectionRange) => number): void => {\n if (view.value && selection.value) {\n view.value.dispatch({\n selection: EditorSelection.create(\n selection.value.ranges.map((r: SelectionRange) => r.extend(f(r)))\n ),\n });\n }\n };\n\n const exposed = {\n editor,\n view,\n cursor,\n selection,\n focus,\n length,\n json,\n diagnosticCount,\n dom: view.value?.contentDOM,\n lint,\n forceReconfigure,\n // Bellow is CodeMirror5's function\n getRange,\n getLine,\n lineCount,\n getCursor,\n listSelections,\n getSelection,\n getSelections,\n somethingSelected,\n replaceRange,\n replaceSelection,\n setCursor,\n setSelection,\n setSelections,\n extendSelectionsBy,\n };\n\n /** Export properties and functions */\n context.expose(exposed);\n return exposed;\n },\n render() {\n // <template>\n // <div ref=\"editor\" class=\"vue-codemirror\">\n // <aside v-show=\"!context.slots.default\" aria-hidden><slot /></aside>\n // </div>\n // </template>\n return h(\n this.$props.tag,\n {\n ref: 'editor',\n class: 'vue-codemirror',\n },\n this.$slots.default\n ? // Hide original content\n h(\n 'aside',\n { style: 'display: none;', 'aria-hidden': 'true' },\n slot(this.$slots.default)\n )\n : undefined\n );\n },\n});\n\nconst installCodeMirror = (app: App): void => {\n app.component('CodeMirror', CodeMirror);\n};\n\n/** Public API exposed from the CodeMirror component instance.\n * Note: Vue 3 auto-unwraps refs on the component instance proxy,\n * so reactive refs appear as their underlying value types here.\n */\nexport type CodeMirrorExposed = {\n editor: HTMLElement | undefined;\n view: EditorView | undefined;\n cursor: number;\n selection: EditorSelection | undefined;\n focus: boolean;\n length: number;\n json: Record<string, StateField<unknown>> | undefined;\n diagnosticCount: number;\n dom: Element | undefined;\n lint: () => void;\n forceReconfigure: () => void;\n getRange: (from?: number, to?: number) => string | undefined;\n getLine: (number: number) => string | undefined;\n lineCount: () => number;\n getCursor: () => number;\n listSelections: () => readonly SelectionRange[];\n getSelection: () => string;\n getSelections: () => string[];\n somethingSelected: () => boolean;\n replaceRange: (replacement: string | Text, from: number, to: number) => void;\n replaceSelection: (replacement: string | Text) => void;\n setCursor: (position: number) => void;\n setSelection: (anchor: number, head?: number) => void;\n setSelections: (ranges: readonly SelectionRange[], primary?: number) => void;\n extendSelectionsBy: (f: (range: SelectionRange) => number) => void;\n};\n\nexport { CodeMirror as default, installCodeMirror as install, Meta };\n"],"names":["Meta","__APP_VERSION__","__BUILD_DATE__","adaptOnsV3","ons","Object","ret","key","handler","h","type","options","children","isVue2","hDemi","props","domProps","on","extraOptions","slot","defaultSlots","CodeMirror","defineComponent","String","Boolean","undefined","Number","Array","Function","_value","context","editor","ref","doc","view","shallowRef","focus","computed","f","selection","cursor","anchor","json","j","EditorState","length","diagnosticCount","extensions","language","Compartment","tabSize","Error","keymaps","indentWithTab","basicSetup","minimalSetup","EditorView","update","forceLinting","indentUnit","linter","lintGutter","placeholder","keymap","extension","watch","exts","StateEffect","value","isSelectionOutOfRange","range","changes","scrollSnapshot","onMounted","globalThis","console","tr","nextTick","onUnmounted","lint","linterDiagnosticCount","forceReconfigure","getRange","from","to","getLine","number","lineCount","getCursor","listSelections","getSelection","getSelections","s","r","somethingSelected","replaceRange","replacement","replaceSelection","setCursor","position","setSelection","head","setSelections","ranges","primary","EditorSelection","extendSelectionsBy","exposed","installCodeMirror","app"],"mappings":";;;;;;;;;;;;;;;;;AAGO,MAAMA,OAAsB;IACjC,SAASC;IACT,MAAMC;AACR;ACiBA,MAAMC,aAAa,CACjBC;IAEA,IAAI,CAACA,KAAK,OAAO,CAAC;IAClB,OAAOC,OAAO,OAAO,CAACD,KAAK,MAAM,CAAC,CAACE,KAAK,CAACC,KAAKC,QAAQ;QACpDD,MAAMA,IAAI,MAAM,CAAC,GAAG,WAAW,KAAKA,IAAI,KAAK,CAAC;QAC9CA,MAAM,CAAC,EAAE,EAAEA,KAAK;QAChB,OAAO;YAAE,GAAGD,GAAG;YAAE,CAACC,IAAI,EAAEC;QAAQ;IAClC,GAAG,CAAC;AACN;AAKe,SAASC,SACtBC,IAAwB,EACxBC,UAAmB,CAAC,CAAC,EACrBC,QAA0B;IAE1B,IA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.umd.js CHANGED
@@ -3,11 +3,497 @@
3
3
  *
4
4
  * @description CodeMirror6 Component for vue2 and vue3.
5
5
  * @author Logue <logue@hotmail.co.jp>
6
- * @copyright 2022-2026 By Masashi Yoshikawa All rights reserved.
7
6
  * @license MIT
8
- * @version 1.5.1
7
+ * @version 1.6.0
9
8
  * @see {@link https://github.com/logue/vue-codemirror6}
10
9
  */
11
10
 
12
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@codemirror/commands`),require(`@codemirror/language`),require(`@codemirror/lint`),require(`@codemirror/state`),require(`@codemirror/view`),require(`codemirror`),require(`vue-demi`)):typeof define==`function`&&define.amd?define([`exports`,`@codemirror/commands`,`@codemirror/language`,`@codemirror/lint`,`@codemirror/state`,`@codemirror/view`,`codemirror`,`vue-demi`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.CodeMirror={},e.commands,e.language,e.lint,e.state,e.view,e.codemirror,e.VueDemi))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var c={version:`1.5.1`,date:`2026-04-03T05:31:33.377Z`},l=e=>e?Object.entries(e).reduce((e,[t,n])=>(t=t.charAt(0).toUpperCase()+t.slice(1),t=`on${t}`,{...e,[t]:n}),{}):{};function u(e,t={},n){if(s.isVue2)return(0,s.h)(e,t,n);let{props:r,domProps:i,on:a,...o}=t,c=a?l(a):{};return(0,s.h)(e,{...o,...r,...i,...c},n)}var d=e=>typeof e==`function`?e():e,f=(0,s.defineComponent)({name:`CodeMirror`,model:{prop:`modelValue`,event:`update:modelValue`},props:{modelValue:{type:String,default:``},theme:{type:Object,default:()=>({})},dark:{type:Boolean,default:!1},basic:{type:Boolean,default:!1},minimal:{type:Boolean,default:!1},placeholder:{type:String,default:void 0},wrap:{type:Boolean,default:!1},tab:{type:Boolean,default:!1},indentUnit:{type:String,default:void 0},allowMultipleSelections:{type:Boolean,default:!1},tabSize:{type:Number,default:void 0},lineSeparator:{type:String,default:void 0},readonly:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},extensions:{type:Array,default:()=>[]},phrases:{type:Object,default:void 0},lang:{type:Object,default:void 0},linter:{type:Function,default:void 0},linterConfig:{type:Object,default:()=>({})},forceLinting:{type:Boolean,default:!1},gutter:{type:Boolean,default:!1},gutterConfig:{type:Object,default:void 0},tag:{type:String,default:`div`},scrollIntoView:{type:Boolean,default:!0},preserveScrollPosition:{type:Boolean,default:!1},keymap:{type:Array,default:()=>[]}},emits:{"update:modelValue":(e=``)=>!0,update:e=>!0,ready:e=>!0,focus:e=>!0,change:e=>!0,destroy:()=>!0},setup(e,c){let l=(0,s.ref)(),u=(0,s.ref)(e.modelValue),d=(0,s.shallowRef)(void 0),f=(0,s.computed)({get:()=>d.value?.hasFocus??!1,set:e=>{e&&d.value&&d.value.focus()}}),p=(0,s.computed)({get:()=>d.value?.state.selection,set:e=>{d.value&&e&&d.value.dispatch({selection:e})}}),m=(0,s.computed)({get:()=>d.value?.state.selection.main.head??0,set:e=>{d.value&&d.value.dispatch({selection:{anchor:e}})}}),h=(0,s.computed)({get:()=>d.value?.state.toJSON(),set:e=>{d.value&&e&&d.value.setState(i.EditorState.fromJSON(e))}}),g=(0,s.ref)(0),_=(0,s.ref)(0),v=(0,s.computed)(()=>{let s=new i.Compartment,l=new i.Compartment;if(e.basic&&e.minimal)throw Error(`[Vue CodeMirror] Both basic and minimal cannot be specified.`);let u=[];return e.keymap&&e.keymap.length>0&&(u=e.keymap),e.tab&&u.push(t.indentWithTab),[e.basic&&!e.minimal?o.basicSetup:void 0,e.minimal&&!e.basic?o.minimalSetup:void 0,a.EditorView.updateListener.of(t=>{d.value&&(c.emit(`focus`,d.value.hasFocus),g.value=d.value.state.doc?.length,!(t.changes.empty||!t.docChanged)&&(e.linter&&(e.forceLinting&&(0,r.forceLinting)(d.value),_.value=e.linter(d.value).length),c.emit(`update`,t)))}),a.EditorView.theme(e.theme,{dark:e.dark}),e.wrap?a.EditorView.lineWrapping:void 0,e.indentUnit?n.indentUnit.of(e.indentUnit):void 0,i.EditorState.allowMultipleSelections.of(e.allowMultipleSelections),e.tabSize?l.of(i.EditorState.tabSize.of(e.tabSize)):void 0,e.phrases?i.EditorState.phrases.of(e.phrases):void 0,i.EditorState.readOnly.of(e.readonly),a.EditorView.editable.of(!e.disabled),e.lineSeparator?i.EditorState.lineSeparator.of(e.lineSeparator):void 0,e.lang?s.of(e.lang):void 0,e.linter?(0,r.linter)(e.linter,e.linterConfig):void 0,e.linter&&e.gutter?(0,r.lintGutter)(e.gutterConfig):void 0,e.placeholder?(0,a.placeholder)(e.placeholder):void 0,u.length>0?a.keymap.of(u):void 0,...e.extensions].filter(e=>!!e)});(0,s.watch)(v,e=>d.value?.dispatch({effects:i.StateEffect.reconfigure.of(e)}),{immediate:!0}),(0,s.watch)(()=>e.modelValue,async t=>{if(!d.value||d.value.composing||d.value.state.doc.toJSON().join(e.lineSeparator??`
13
- `)===t)return;let n=!d.value.state.selection.ranges.every(e=>e.anchor<t.length&&e.head<t.length),r={from:0,to:d.value.state.doc.length,insert:t},i=e.preserveScrollPosition?d.value.scrollSnapshot().map(d.value.state.changes(r)):void 0;d.value.dispatch({changes:r,selection:n?{anchor:0,head:0}:d.value.state.selection,scrollIntoView:e.scrollIntoView,effects:i?[i]:void 0})},{immediate:!0}),(0,s.onMounted)(async()=>{if(globalThis.window===void 0||!l.value)return;let e=u.value;l.value.childNodes[0]&&(u.value!==``&&console.warn("[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values."),e=l.value.childNodes[0].innerText.trim()),d.value=new a.EditorView({parent:l.value,state:i.EditorState.create({doc:e,extensions:v.value}),dispatch:e=>{d.value&&(d.value.update([e]),!(e.changes.empty||!e.docChanged)&&(c.emit(`update:modelValue`,e.state.doc.toString()),c.emit(`change`,e.state)))}}),await(0,s.nextTick)(),c.emit(`ready`,{view:d.value,state:d.value.state,container:l.value})}),(0,s.onUnmounted)(()=>{d.value&&(d.value.destroy(),c.emit(`destroy`))});let y={editor:l,view:d,cursor:m,selection:p,focus:f,length:g,json:h,diagnosticCount:_,dom:d.value?.contentDOM,lint:()=>{!e.linter||!d.value||(e.forceLinting&&(0,r.forceLinting)(d.value),_.value=(0,r.diagnosticCount)(d.value.state))},forceReconfigure:()=>{d.value?.dispatch({effects:i.StateEffect.reconfigure.of([])}),d.value?.dispatch({effects:i.StateEffect.appendConfig.of(v.value)})},getRange:(e,t)=>d.value?.state.sliceDoc(e,t),getLine:e=>d.value?.state.doc.line(e+1).text,lineCount:()=>d.value?.state.doc.lines??0,getCursor:()=>d.value?.state.selection.main.head??0,listSelections:()=>d.value?.state.selection.ranges??[],getSelection:()=>d.value?d.value.state.sliceDoc(d.value.state.selection.main.from,d.value.state.selection.main.to):``,getSelections:()=>{let e=d.value?.state;return e?e.selection.ranges.map(t=>e.sliceDoc(t.from,t.to)):[]},somethingSelected:()=>d.value?.state.selection.ranges.some(e=>!e.empty)??!1,replaceRange:(e,t,n)=>{d.value&&d.value.dispatch({changes:{from:t,to:n,insert:e}})},replaceSelection:e=>{d.value&&d.value.dispatch(d.value.state.replaceSelection(e))},setCursor:e=>{d.value&&d.value.dispatch({selection:{anchor:e}})},setSelection:(e,t)=>{d.value&&d.value.dispatch({selection:{anchor:e,head:t}})},setSelections:(e,t)=>{d.value&&d.value.dispatch({selection:i.EditorSelection.create(e,t)})},extendSelectionsBy:e=>{d.value&&p.value&&d.value.dispatch({selection:i.EditorSelection.create(p.value.ranges.map(t=>t.extend(e(t))))})}};return c.expose(y),y},render(){return u(this.$props.tag,{ref:`editor`,class:`vue-codemirror`},this.$slots.default?u(`aside`,{style:`display: none;`,"aria-hidden":`true`},d(this.$slots.default)):void 0)}});e.Meta=c,e.default=f,e.install=e=>e.component(`CodeMirror`,f)});
11
+ (function(root, factory) {
12
+ if ('object' == typeof exports && 'object' == typeof module) module.exports = factory(require("codemirror"), require("@codemirror/lint"), require("@codemirror/language"), require("@codemirror/state"), require("vue-demi"), require("@codemirror/commands"), require("@codemirror/view"));
13
+ else if ('function' == typeof define && define.amd) define([
14
+ "codemirror",
15
+ "@codemirror/lint",
16
+ "@codemirror/language",
17
+ "@codemirror/state",
18
+ "vue-demi",
19
+ "@codemirror/commands",
20
+ "@codemirror/view"
21
+ ], factory);
22
+ else if ('object' == typeof exports) exports["vue-codemirror"] = factory(require("codemirror"), require("@codemirror/lint"), require("@codemirror/language"), require("@codemirror/state"), require("vue-demi"), require("@codemirror/commands"), require("@codemirror/view"));
23
+ else root["vue-codemirror"] = factory(root["codemirror"], root["lint"], root["language"], root["state"], root["VueDemi"], root["commands"], root["view"]);
24
+ })(global, (__rspack_external_codemirror, __rspack_external__codemirror_lint, __rspack_external__codemirror_language, __rspack_external__codemirror_state, __rspack_external_vue_demi, __rspack_external__codemirror_commands, __rspack_external__codemirror_view)=>(()=>{
25
+ "use strict";
26
+ var __webpack_modules__ = {
27
+ "@codemirror/commands" (module1) {
28
+ module1.exports = __rspack_external__codemirror_commands;
29
+ },
30
+ "@codemirror/language" (module1) {
31
+ module1.exports = __rspack_external__codemirror_language;
32
+ },
33
+ "@codemirror/lint" (module1) {
34
+ module1.exports = __rspack_external__codemirror_lint;
35
+ },
36
+ "@codemirror/state" (module1) {
37
+ module1.exports = __rspack_external__codemirror_state;
38
+ },
39
+ "@codemirror/view" (module1) {
40
+ module1.exports = __rspack_external__codemirror_view;
41
+ },
42
+ codemirror (module1) {
43
+ module1.exports = __rspack_external_codemirror;
44
+ },
45
+ "vue-demi" (module1) {
46
+ module1.exports = __rspack_external_vue_demi;
47
+ }
48
+ };
49
+ var __webpack_module_cache__ = {};
50
+ function __webpack_require__(moduleId) {
51
+ var cachedModule = __webpack_module_cache__[moduleId];
52
+ if (void 0 !== cachedModule) return cachedModule.exports;
53
+ var module1 = __webpack_module_cache__[moduleId] = {
54
+ exports: {}
55
+ };
56
+ __webpack_modules__[moduleId](module1, module1.exports, __webpack_require__);
57
+ return module1.exports;
58
+ }
59
+ (()=>{
60
+ __webpack_require__.d = (exports1, getters, values)=>{
61
+ var define1 = (defs, kind)=>{
62
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
63
+ enumerable: true,
64
+ [kind]: defs[key]
65
+ });
66
+ };
67
+ define1(getters, "get");
68
+ define1(values, "value");
69
+ };
70
+ })();
71
+ (()=>{
72
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
73
+ })();
74
+ (()=>{
75
+ __webpack_require__.r = (exports1)=>{
76
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
77
+ value: 'Module'
78
+ });
79
+ Object.defineProperty(exports1, '__esModule', {
80
+ value: true
81
+ });
82
+ };
83
+ })();
84
+ var __webpack_exports__ = {};
85
+ (()=>{
86
+ __webpack_require__.r(__webpack_exports__);
87
+ __webpack_require__.d(__webpack_exports__, {
88
+ Meta: ()=>Meta,
89
+ default: ()=>CodeMirror,
90
+ install: ()=>installCodeMirror
91
+ });
92
+ var commands_ = __webpack_require__("@codemirror/commands");
93
+ var language_ = __webpack_require__("@codemirror/language");
94
+ var lint_ = __webpack_require__("@codemirror/lint");
95
+ var state_ = __webpack_require__("@codemirror/state");
96
+ var view_ = __webpack_require__("@codemirror/view");
97
+ var external_commonjs2_codemirror_root_codemirror_amd_codemirror_commonjs_codemirror_ = __webpack_require__("codemirror");
98
+ var external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_ = __webpack_require__("vue-demi");
99
+ const Meta = {
100
+ version: "1.6.0",
101
+ date: "2026-07-03T10:06:19.129Z"
102
+ };
103
+ const adaptOnsV3 = (ons)=>{
104
+ if (!ons) return {};
105
+ return Object.entries(ons).reduce((ret, [key, handler])=>{
106
+ key = key.charAt(0).toUpperCase() + key.slice(1);
107
+ key = `on${key}`;
108
+ return {
109
+ ...ret,
110
+ [key]: handler
111
+ };
112
+ }, {});
113
+ };
114
+ function h(type, options = {}, children) {
115
+ if (external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.isVue2) return (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.h)(type, options, children);
116
+ const { props, domProps, on, ...extraOptions } = options;
117
+ const ons = on ? adaptOnsV3(on) : {};
118
+ return (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.h)(type, {
119
+ ...extraOptions,
120
+ ...props,
121
+ ...domProps,
122
+ ...ons
123
+ }, children);
124
+ }
125
+ const slot = (defaultSlots)=>'function' == typeof defaultSlots ? defaultSlots() : defaultSlots ?? [];
126
+ const CodeMirror = (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.defineComponent)({
127
+ name: 'CodeMirror',
128
+ model: {
129
+ prop: 'modelValue',
130
+ event: 'update:modelValue'
131
+ },
132
+ props: {
133
+ modelValue: {
134
+ type: String,
135
+ default: ''
136
+ },
137
+ theme: {
138
+ type: Object,
139
+ default: ()=>({})
140
+ },
141
+ dark: {
142
+ type: Boolean,
143
+ default: false
144
+ },
145
+ basic: {
146
+ type: Boolean,
147
+ default: false
148
+ },
149
+ minimal: {
150
+ type: Boolean,
151
+ default: false
152
+ },
153
+ placeholder: {
154
+ type: String,
155
+ default: void 0
156
+ },
157
+ wrap: {
158
+ type: Boolean,
159
+ default: false
160
+ },
161
+ tab: {
162
+ type: Boolean,
163
+ default: false
164
+ },
165
+ indentUnit: {
166
+ type: String,
167
+ default: void 0
168
+ },
169
+ allowMultipleSelections: {
170
+ type: Boolean,
171
+ default: false
172
+ },
173
+ tabSize: {
174
+ type: Number,
175
+ default: void 0
176
+ },
177
+ lineSeparator: {
178
+ type: String,
179
+ default: void 0
180
+ },
181
+ readonly: {
182
+ type: Boolean,
183
+ default: false
184
+ },
185
+ disabled: {
186
+ type: Boolean,
187
+ default: false
188
+ },
189
+ extensions: {
190
+ type: Array,
191
+ default: ()=>[]
192
+ },
193
+ phrases: {
194
+ type: Object,
195
+ default: void 0
196
+ },
197
+ lang: {
198
+ type: Object,
199
+ default: void 0
200
+ },
201
+ linter: {
202
+ type: Function,
203
+ default: void 0
204
+ },
205
+ linterConfig: {
206
+ type: Object,
207
+ default: ()=>({})
208
+ },
209
+ forceLinting: {
210
+ type: Boolean,
211
+ default: false
212
+ },
213
+ gutter: {
214
+ type: Boolean,
215
+ default: false
216
+ },
217
+ gutterConfig: {
218
+ type: Object,
219
+ default: void 0
220
+ },
221
+ tag: {
222
+ type: String,
223
+ default: 'div'
224
+ },
225
+ scrollIntoView: {
226
+ type: Boolean,
227
+ default: true
228
+ },
229
+ preserveScrollPosition: {
230
+ type: Boolean,
231
+ default: false
232
+ },
233
+ keymap: {
234
+ type: Array,
235
+ default: ()=>[]
236
+ }
237
+ },
238
+ emits: {
239
+ 'update:modelValue': (_value = '')=>true,
240
+ update: (_value)=>true,
241
+ ready: (_value)=>true,
242
+ focus: (_value)=>true,
243
+ change: (_value)=>true,
244
+ destroy: ()=>true
245
+ },
246
+ setup (props, context) {
247
+ const editor = (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.ref)();
248
+ const doc = (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.ref)(props.modelValue);
249
+ const view = (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.shallowRef)(void 0);
250
+ const focus = (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.computed)({
251
+ get: ()=>view.value?.hasFocus ?? false,
252
+ set: (f)=>{
253
+ if (f && view.value) view.value.focus();
254
+ }
255
+ });
256
+ const selection = (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.computed)({
257
+ get: ()=>view.value?.state.selection,
258
+ set: (selection)=>{
259
+ if (view.value && selection) view.value.dispatch({
260
+ selection
261
+ });
262
+ }
263
+ });
264
+ const cursor = (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.computed)({
265
+ get: ()=>view.value?.state.selection.main.head ?? 0,
266
+ set: (anchor)=>{
267
+ if (view.value) view.value.dispatch({
268
+ selection: {
269
+ anchor
270
+ }
271
+ });
272
+ }
273
+ });
274
+ const json = (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.computed)({
275
+ get: ()=>view.value?.state.toJSON(),
276
+ set: (j)=>{
277
+ if (view.value && j) view.value.setState(state_.EditorState.fromJSON(j));
278
+ }
279
+ });
280
+ const length = (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.ref)(0);
281
+ const diagnosticCount = (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.ref)(0);
282
+ const extensions = (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.computed)(()=>{
283
+ const language = new state_.Compartment();
284
+ const tabSize = new state_.Compartment();
285
+ if (props.basic && props.minimal) throw new Error('[Vue CodeMirror] Both basic and minimal cannot be specified.');
286
+ let keymaps = [];
287
+ if (props.keymap && props.keymap.length > 0) keymaps = props.keymap;
288
+ if (props.tab) keymaps.push(commands_.indentWithTab);
289
+ return [
290
+ props.basic && !props.minimal ? external_commonjs2_codemirror_root_codemirror_amd_codemirror_commonjs_codemirror_.basicSetup : void 0,
291
+ props.minimal && !props.basic ? external_commonjs2_codemirror_root_codemirror_amd_codemirror_commonjs_codemirror_.minimalSetup : void 0,
292
+ view_.EditorView.updateListener.of((update)=>{
293
+ if (!view.value) return;
294
+ context.emit('focus', view.value.hasFocus);
295
+ length.value = view.value.state.doc?.length;
296
+ if (update.changes.empty || !update.docChanged) return;
297
+ if (props.linter) {
298
+ if (props.forceLinting) (0, lint_.forceLinting)(view.value);
299
+ diagnosticCount.value = props.linter(view.value).length;
300
+ }
301
+ context.emit('update', update);
302
+ }),
303
+ view_.EditorView.theme(props.theme, {
304
+ dark: props.dark
305
+ }),
306
+ props.wrap ? view_.EditorView.lineWrapping : void 0,
307
+ props.indentUnit ? language_.indentUnit.of(props.indentUnit) : void 0,
308
+ state_.EditorState.allowMultipleSelections.of(props.allowMultipleSelections),
309
+ props.tabSize ? tabSize.of(state_.EditorState.tabSize.of(props.tabSize)) : void 0,
310
+ props.phrases ? state_.EditorState.phrases.of(props.phrases) : void 0,
311
+ state_.EditorState.readOnly.of(props.readonly),
312
+ view_.EditorView.editable.of(!props.disabled),
313
+ props.lineSeparator ? state_.EditorState.lineSeparator.of(props.lineSeparator) : void 0,
314
+ props.lang ? language.of(props.lang) : void 0,
315
+ props.linter ? (0, lint_.linter)(props.linter, props.linterConfig) : void 0,
316
+ props.linter && props.gutter ? (0, lint_.lintGutter)(props.gutterConfig) : void 0,
317
+ props.placeholder ? (0, view_.placeholder)(props.placeholder) : void 0,
318
+ keymaps.length > 0 ? view_.keymap.of(keymaps) : void 0,
319
+ ...props.extensions
320
+ ].filter((extension)=>!!extension);
321
+ });
322
+ (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.watch)(extensions, (exts)=>view.value?.dispatch({
323
+ effects: state_.StateEffect.reconfigure.of(exts)
324
+ }), {
325
+ immediate: true
326
+ });
327
+ (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.watch)(()=>props.modelValue, async (value)=>{
328
+ if (!view.value) return;
329
+ if (view.value.composing || view.value.state.doc.toJSON().join(props.lineSeparator ?? '\n') === value) return;
330
+ const isSelectionOutOfRange = !view.value.state.selection.ranges.every((range)=>range.anchor < value.length && range.head < value.length);
331
+ const changes = {
332
+ from: 0,
333
+ to: view.value.state.doc.length,
334
+ insert: value
335
+ };
336
+ const scrollSnapshot = props.preserveScrollPosition ? view.value.scrollSnapshot().map(view.value.state.changes(changes)) : void 0;
337
+ view.value.dispatch({
338
+ changes,
339
+ selection: isSelectionOutOfRange ? {
340
+ anchor: 0,
341
+ head: 0
342
+ } : view.value.state.selection,
343
+ scrollIntoView: props.scrollIntoView,
344
+ effects: scrollSnapshot ? [
345
+ scrollSnapshot
346
+ ] : void 0
347
+ });
348
+ }, {
349
+ immediate: true
350
+ });
351
+ (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.onMounted)(async ()=>{
352
+ if (void 0 === globalThis.window || !editor.value) return;
353
+ let value = doc.value;
354
+ if (editor.value.childNodes[0]) {
355
+ if ('' !== doc.value) console.warn('[CodeMirror.vue] The <code-mirror> tag contains child elements that overwrite the `v-model` values.');
356
+ value = editor.value.childNodes[0].innerText.trim();
357
+ }
358
+ view.value = new view_.EditorView({
359
+ parent: editor.value,
360
+ state: state_.EditorState.create({
361
+ doc: value,
362
+ extensions: extensions.value
363
+ }),
364
+ dispatch: (tr)=>{
365
+ if (!view.value) return;
366
+ view.value.update([
367
+ tr
368
+ ]);
369
+ if (tr.changes.empty || !tr.docChanged) return;
370
+ context.emit('update:modelValue', tr.state.doc.toString());
371
+ context.emit('change', tr.state);
372
+ }
373
+ });
374
+ await (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.nextTick)();
375
+ context.emit('ready', {
376
+ view: view.value,
377
+ state: view.value.state,
378
+ container: editor.value
379
+ });
380
+ });
381
+ (0, external_commonjs2_vue_demi_root_VueDemi_amd_vue_demi_commonjs_vue_demi_.onUnmounted)(()=>{
382
+ if (view.value) {
383
+ view.value.destroy();
384
+ context.emit('destroy');
385
+ }
386
+ });
387
+ const lint = ()=>{
388
+ if (!props.linter || !view.value) return;
389
+ if (props.forceLinting) (0, lint_.forceLinting)(view.value);
390
+ diagnosticCount.value = (0, lint_.diagnosticCount)(view.value.state);
391
+ };
392
+ const forceReconfigure = ()=>{
393
+ view.value?.dispatch({
394
+ effects: state_.StateEffect.reconfigure.of([])
395
+ });
396
+ view.value?.dispatch({
397
+ effects: state_.StateEffect.appendConfig.of(extensions.value)
398
+ });
399
+ };
400
+ const getRange = (from, to)=>view.value?.state.sliceDoc(from, to);
401
+ const getLine = (number)=>view.value?.state.doc.line(number + 1).text;
402
+ const lineCount = ()=>view.value?.state.doc.lines ?? 0;
403
+ const getCursor = ()=>view.value?.state.selection.main.head ?? 0;
404
+ const listSelections = ()=>view.value?.state.selection.ranges ?? [];
405
+ const getSelection = ()=>{
406
+ if (!view.value) return '';
407
+ return view.value.state.sliceDoc(view.value.state.selection.main.from, view.value.state.selection.main.to);
408
+ };
409
+ const getSelections = ()=>{
410
+ const s = view.value?.state;
411
+ if (!s) return [];
412
+ return s.selection.ranges.map((r)=>s.sliceDoc(r.from, r.to));
413
+ };
414
+ const somethingSelected = ()=>view.value?.state.selection.ranges.some((r)=>!r.empty) ?? false;
415
+ const replaceRange = (replacement, from, to)=>{
416
+ if (view.value) view.value.dispatch({
417
+ changes: {
418
+ from,
419
+ to,
420
+ insert: replacement
421
+ }
422
+ });
423
+ };
424
+ const replaceSelection = (replacement)=>{
425
+ if (view.value) view.value.dispatch(view.value.state.replaceSelection(replacement));
426
+ };
427
+ const setCursor = (position)=>{
428
+ if (view.value) view.value.dispatch({
429
+ selection: {
430
+ anchor: position
431
+ }
432
+ });
433
+ };
434
+ const setSelection = (anchor, head)=>{
435
+ if (view.value) view.value.dispatch({
436
+ selection: {
437
+ anchor,
438
+ head
439
+ }
440
+ });
441
+ };
442
+ const setSelections = (ranges, primary)=>{
443
+ if (view.value) view.value.dispatch({
444
+ selection: state_.EditorSelection.create(ranges, primary)
445
+ });
446
+ };
447
+ const extendSelectionsBy = (f)=>{
448
+ if (view.value && selection.value) view.value.dispatch({
449
+ selection: state_.EditorSelection.create(selection.value.ranges.map((r)=>r.extend(f(r))))
450
+ });
451
+ };
452
+ const exposed = {
453
+ editor,
454
+ view,
455
+ cursor,
456
+ selection,
457
+ focus,
458
+ length,
459
+ json,
460
+ diagnosticCount,
461
+ dom: view.value?.contentDOM,
462
+ lint,
463
+ forceReconfigure,
464
+ getRange,
465
+ getLine,
466
+ lineCount,
467
+ getCursor,
468
+ listSelections,
469
+ getSelection,
470
+ getSelections,
471
+ somethingSelected,
472
+ replaceRange,
473
+ replaceSelection,
474
+ setCursor,
475
+ setSelection,
476
+ setSelections,
477
+ extendSelectionsBy
478
+ };
479
+ context.expose(exposed);
480
+ return exposed;
481
+ },
482
+ render () {
483
+ return h(this.$props.tag, {
484
+ ref: 'editor',
485
+ class: 'vue-codemirror'
486
+ }, this.$slots.default ? h('aside', {
487
+ style: 'display: none;',
488
+ 'aria-hidden': 'true'
489
+ }, slot(this.$slots.default)) : void 0);
490
+ }
491
+ });
492
+ const installCodeMirror = (app)=>{
493
+ app.component('CodeMirror', CodeMirror);
494
+ };
495
+ })();
496
+ return __webpack_exports__;
497
+ })());
498
+
499
+ //# sourceMappingURL=index.umd.js.map