1// Copyright (c) 2021-2025 GrayBits LLC 2 3import MiniForm from 'gray_matter/forms/mini_form' 4import ReferenceInterface from 'gray_matter/rich_text/reference_interface' 5import * as Builder from 'gray_matter/utility/builder' 6 7import 'axios' 8 9const definitions = { 10 apostrophe: { 11 label: 'Insert apostrophe', 12 character: 'â' 13 }, 14 double_quotes: { 15 label: 'Wrap selection in double quotes', 16 start: 'â', 17 end: 'â' 18 }, 19 single_quotes: { 20 label: 'Wrap selection in single quotes', 21 start: 'â', 22 end: 'â' 23 }, 24 reference: { 25 label: 'Insert reference', 26 handler: async (view) => { 27 if (view.docView.contentDOM.parentNode.querySelector('.reference_interface')) return; 28 29 let input_interface = new ReferenceInterface(view); 30 let response = await input_interface.response(); 31 32 if (response){ 33 let node = view.state.schema.nodes.reference.create({}, [view.state.schema.text(response)]) 34 view.dispatch(view.state.tr.replaceSelectionWith(node)); 35 view.focus(); 36 } 37 } 38 } 39}; 40 41export default class InsertItem { 42 constructor(action, options){ 43 let definition = definitions[action] || options; 44 this.action = action; 45 this.label = definition.label; 46 this.character = definition.character; 47 this.start = definition.start; 48 this.end = definition.end; 49 this.handler = definition.handler; 50 } 51 render(view) { 52 let update = (state) => { return true; } 53 54 this.button = Builder.createElement('button', { 55 class: ['button', this.action], 56 attr: { 'aria-label': this.label, title: this.label, type: 'button' }, 57 listeners: { mousedown: (e) => { e.preventDefault(); this.insert(view); } } 58 });; 59 60 return { button: this.button, update: update }; 61 } 62 63 insert(view){ 64 if (this.handler){ 65 this.handler.call(this, view); 66 } 67 68 if (this.character){ 69 this.insertCharacter(view); 70 return; 71 } 72 this.insertAround(view); 73 } 74 75 insertCharacter(view){ 76 view.dispatch(view.state.tr.insertText(this.character)) 77 } 78 79 insertAround(view){ 80 view.dispatch(view.state.tr.insertText(this.start, view.state.tr.selection.from)); 81 view.dispatch(view.state.tr.insertText(this.end, view.state.tr.selection.from)); 82 } 83 84 static add(kind, definition){ 85 definitions[kind] = definition; 86 } 87};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.