repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
wordflow
github_2023
poloclub
typescript
WordflowPanelLocal.showSearchBarCancelButtonClicked
showSearchBarCancelButtonClicked() { if (this.shadowRoot === null) { throw Error('shadowRoot is null.'); } const inputElement = this.shadowRoot.querySelector( '#search-bar-input' ) as HTMLInputElement; inputElement.value = ''; this.showSearchBarCancelButton = false; if (this.se...
/** * Handler for the search bar cancel click event */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/panel-local/panel-local.ts#L437-L457
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPanelLocal.render
render() { // Compose the prompt cards let promptCards = html``; for (const [i, promptData] of this.localPrompts .slice(0, Math.min(this.maxPromptCount, this.localPrompts.length)) .entries()) { promptCards = html`${promptCards} <div class="prompt-card-container" ...
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/panel-local/panel-local.ts#L466-L705
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPanelSetting.constructor
constructor() { super(); this.selectedModel = SupportedRemoteModel['gpt-3.5-free']; }
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/panel-setting/panel-setting.ts#L134-L137
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPanelSetting.willUpdate
willUpdate(changedProperties: PropertyValues<this>) { if (changedProperties.has('userConfig')) { if (this.selectedModel !== this.userConfig.preferredLLM) { this.selectedModel = this.userConfig.preferredLLM; // Need to manually update the select element const selectElement = this.shado...
/** * This method is called before new DOM is updated and rendered * @param changedProperties Property that has been changed */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/panel-setting/panel-setting.ts#L143-L180
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPanelSetting.initData
async initData() {}
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/panel-setting/panel-setting.ts#L222-L222
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPanelSetting.textGenMessageHandler
textGenMessageHandler = ( model: SupportedRemoteModel, apiKey: string, message: TextGenMessage ) => { switch (message.command) { case 'finishTextGen': { // If the textGen is initialized in the auth function, add the api key // to the local storage if (message.payload.requ...
// ===== Event Methods ======
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/panel-setting/panel-setting.ts
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPanelSetting.textGenLocalWorkerMessageHandler
textGenLocalWorkerMessageHandler(e: MessageEvent<TextGenLocalWorkerMessage>) { switch (e.data.command) { case 'finishTextGen': { break; } case 'progressLoadModel': { this.progressBarComponent?.updateProgress(e.data.payload.progress); break; } case 'finishLoadM...
/** * Event handler for the text gen local worker * @param e Text gen message */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/panel-setting/panel-setting.ts#L277-L315
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPanelSetting.infoIconMouseEntered
infoIconMouseEntered( e: MouseEvent, field: 'model' | 'api-key' | 'local-llm' ) { let message = ''; switch (field) { case 'model': { message = 'Preferred LLM model to run the prompts'; break; } case 'api-key': { message = 'Enter the API key to call the LLM m...
/** * Event handler for mouse entering the info icon in each filed * @param e Mouse event * @param field Field type */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/panel-setting/panel-setting.ts#L449-L481
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPanelSetting.infoIconMouseLeft
infoIconMouseLeft() { tooltipMouseLeave(this.tooltipConfig); }
/** * Event handler for mouse leaving the info icon in each filed */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/panel-setting/panel-setting.ts#L486-L488
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPanelSetting._updateSelectedLocalModelInCache
async _updateSelectedLocalModelInCache() { if (this.selectedModelFamily !== ModelFamily.local) { this.selectedLocalModelInCache = false; } else { this.selectedLocalModelInCache = await hasLocalModelInCache( this.selectedModel as SupportedLocalModel ); } }
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/panel-setting/panel-setting.ts#L493-L501
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPanelSetting.render
render() { // Compose the model select options let remoteModelSelectOptions = html``; let localModelSelectOptions = html``; // Remote models for (const [name, label] of Object.entries(SupportedRemoteModel)) { remoteModelSelectOptions = html`${remoteModelSelectOptions} <option value=${...
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/panel-setting/panel-setting.ts#L506-L716
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
PrivacyDialogSimple.constructor
constructor() { super(); this.confirmAction = () => {}; }
// ===== Lifecycle Methods ======
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/privacy-dialog/privacy-dialog-simple.ts#L29-L32
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
PrivacyDialogSimple.willUpdate
willUpdate(changedProperties: PropertyValues<this>) {}
/** * This method is called before new DOM is updated and rendered * @param changedProperties Property that has been changed */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/privacy-dialog/privacy-dialog-simple.ts#L42-L42
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
PrivacyDialogSimple.initData
initData = async () => {}
// ===== Custom Methods ======
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/privacy-dialog/privacy-dialog-simple.ts
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
PrivacyDialogSimple.dialogClicked
dialogClicked(e: MouseEvent) { if (e.target === this.dialogElement) { this.dialogElement.close(); } }
// ===== Event Methods ======
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/privacy-dialog/privacy-dialog-simple.ts#L56-L60
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
PrivacyDialogSimple.render
render() { return html` <dialog class="confirm-dialog" @click=${(e: MouseEvent) => this.dialogClicked(e)} > <div class="header"> <div class="header-name">Wordflow Privacy</div> </div> <div class="content"> <div class="message"> <p>...
// ===== Templates and Styles ======
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/privacy-dialog/privacy-dialog-simple.ts#L70-L101
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
PrivacyDialog.constructor
constructor() { super(); this.confirmAction = () => {}; }
// ===== Lifecycle Methods ======
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/privacy-dialog/privacy-dialog.ts#L29-L32
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
PrivacyDialog.willUpdate
willUpdate(changedProperties: PropertyValues<this>) {}
/** * This method is called before new DOM is updated and rendered * @param changedProperties Property that has been changed */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/privacy-dialog/privacy-dialog.ts#L42-L42
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
PrivacyDialog.initData
initData = async () => {}
// ===== Custom Methods ======
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/privacy-dialog/privacy-dialog.ts
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
PrivacyDialog.dialogClicked
dialogClicked(e: MouseEvent) { if (e.target === this.dialogElement) { this.dialogElement.close(); } }
// ===== Event Methods ======
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/privacy-dialog/privacy-dialog.ts#L56-L60
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
PrivacyDialog.render
render() { return html` <dialog class="confirm-dialog" @click=${(e: MouseEvent) => this.dialogClicked(e)} > <div class="header"> <div class="header-name">Usage Data Collection Acknowledgement</div> </div> <div class="content"> <div class="mess...
// ===== Templates and Styles ======
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/privacy-dialog/privacy-dialog.ts#L80-L181
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
NightjarProgressBar.constructor
constructor() { super(); }
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/progress-bar/progress-bar.ts#L36-L38
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
NightjarProgressBar.willUpdate
willUpdate(changedProperties: PropertyValues<this>) { if (changedProperties.has('progress')) { this.updateProgress(this.progress); } }
/** * This method is called before new DOM is updated and rendered * @param changedProperties Property that has been changed */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/progress-bar/progress-bar.ts#L66-L70
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
NightjarProgressBar.initData
async initData() {}
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/progress-bar/progress-bar.ts#L75-L75
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
NightjarProgressBar.updateProgress
updateProgress(progress: number) { this._progress = Math.min(1, Math.max(0, progress)); this.curProgressWidth = this.totalWidth * this._progress; this.alignProgressLabel(); }
/** * Update the current progress * @param progress Progress form 0 to 1 */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/progress-bar/progress-bar.ts#L103-L107
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
NightjarProgressBar.render
render() { return html` <div class="progress-bar"> <div class="current-progress" ?is-done=${this._progress >= 1} style="width: ${this.curProgressWidth}px;" > <span class="progress-label" ?align-left=${this.labelAlign === 'left'} >${Math.floor...
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/progress-bar/progress-bar.ts#L120-L134
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptCard.constructor
constructor() { super(); this.promptData = getEmptyPromptDataRemote(); }
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-card/prompt-card.ts#L39-L42
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptCard.willUpdate
willUpdate(changedProperties: PropertyValues<this>) {}
/** * This method is called before new DOM is updated and rendered * @param changedProperties Property that has been changed */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-card/prompt-card.ts#L48-L48
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptCard.initData
async initData() {}
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-card/prompt-card.ts#L53-L53
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptCard.tagClicked
tagClicked(e: MouseEvent, tag: string) { e.preventDefault(); e.stopPropagation(); // Notify the parent const event = new CustomEvent('tag-clicked', { detail: tag, bubbles: true, composed: true }); this.dispatchEvent(event); }
/** * Tag clicked event handler * @param tag Clicked tag name */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-card/prompt-card.ts#L62-L73
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptCard.render
render() { // Compose the tag list let tagList = html``; if (this.promptData.tags !== undefined) { if (!this.isLocalPrompt) { for (const tag of this.promptData.tags) { tagList = html`${tagList} <span class="tag" ?is-selected=${this.curSelectedT...
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-card/prompt-card.ts#L82-L149
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptEditor.constructor
constructor() { super(); this.promptData = getEmptyPromptDataLocal(); this.availableModels = structuredClone(ALL_MODELS); this.placeholderEmoji = EMOJI_CANDIDATES[Math.floor(Math.random() * EMOJI_CANDIDATES.length)]; }
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-editor/prompt-editor.ts#L225-L232
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptEditor.willUpdate
willUpdate(changedProperties: PropertyValues<this>) { if (changedProperties.has('promptData')) { this.injectionMode = this.promptData.injectionMode; this.temperature = this.promptData.temperature; } }
/** * This method is called before new DOM is updated and rendered * @param changedProperties Property that has been changed */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-editor/prompt-editor.ts#L249-L254
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptEditor.initData
async initData() {}
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-editor/prompt-editor.ts#L259-L259
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptEditor.parseForm
parseForm() { if (this.shadowRoot === null) { throw Error('Shadow root is null.'); } const newPromptData = getEmptyPromptDataLocal(); // Add the information that is not included in the input fields // `forkFrom`, `key`, `promptRunCount` // We will use a new `created` for the new data ...
/** * Create a prompt object by parsing the current form. This function does not * validate the user's inputs. */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-editor/prompt-editor.ts#L265-L377
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptEditor.savePrompt
savePrompt() { if (this.toastComponent === undefined) { throw Error('toastComponent is undefined.'); } // Parse the input fields const newPromptData = this.parseForm(); // Validate the data if (newPromptData.title.length === 0) { this.toastMessage = "Title can't be empty."; t...
/** * Save the user's input as a prompt. It creates a new prompt or updates an * existing prompt. */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-editor/prompt-editor.ts#L383-L424
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptEditor.sharePrompt
sharePrompt() { if (this.toastComponent === undefined) { throw Error('toastComponent is undefined.'); } if (this.shadowRoot === null) { throw Error('Shadow root is null'); } if (this.confirmDialogComponent === undefined) { throw Error('confirmDialogComponent is undefined'); }...
/** * Share the current prompt. */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-editor/prompt-editor.ts#L429-L572
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptEditor.deletePrompt
deletePrompt() { if (this.confirmDialogComponent === undefined) { throw Error('confirmDialogComponent is undefined'); } const dialogInfo: DialogInfo = { header: 'Delete Prompt', message: 'Are you sure you want to delete this prompt? This action cannot be undone.', yesButtonT...
/** * Delete the current prompt. */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-editor/prompt-editor.ts#L577-L594
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptEditor.accordionHeaderClicked
async accordionHeaderClicked(e: MouseEvent, type: 'advanced' | 'sharing') { e.preventDefault(); if (type === 'advanced') { if (!this.sliderComponent) { throw Error('sliderComponent is not initialized'); } this.showAdvancedOptions = !this.showAdvancedOptions; // Need to force the...
/** * Event handler for clicking the accordion header * @param e Event * @param type Accordion type */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-editor/prompt-editor.ts#L604-L619
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptEditor.closeButtonClicked
closeButtonClicked() { if (this.shadowRoot === null) { throw Error('shadowRoot is null'); } // Notify the parent const event = new Event('close-clicked', { bubbles: true, composed: true }); this.dispatchEvent(event); // Clean up the input const formElement = this.shad...
/** * Event handler for clicking the close button */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-editor/prompt-editor.ts#L624-L648
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptEditor.infoIconMouseEntered
infoIconMouseEntered(e: MouseEvent, field: Field) { const target = (e.currentTarget as HTMLElement).querySelector( '.info-icon' ) as HTMLElement; tooltipMouseEnter( e, FIELD_INFO[field].tooltip, 'top', this.tooltipConfig, 200, target, 10 ); }
/** * Event handler for mouse entering the info icon in each filed * @param e Mouse event * @param field Field type */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-editor/prompt-editor.ts#L655-L668
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptEditor.infoIconMouseLeft
infoIconMouseLeft() { tooltipMouseLeave(this.tooltipConfig); }
/** * Event handler for mouse leaving the info icon in each filed */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-editor/prompt-editor.ts#L673-L675
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptEditor.iconInput
iconInput(e: InputEvent) { const iconElement = e.currentTarget as HTMLInputElement; // Check if the delete key is pressed if (e.inputType === 'deleteContentBackward') { iconElement.value = ''; // Empty the input field } else { // Check if there is an emoji in the icon element const ma...
/** * Only allow users to enter one character or one emoji in the icon input * @param e Input event */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-editor/prompt-editor.ts#L681-L699
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptEditor.promptEditorBackgroundClicked
promptEditorBackgroundClicked(e: MouseEvent) { const target = e.target as HTMLElement; if (target.classList.contains('prompt-editor')) { this.closeButtonClicked(); } }
/** * Close the modal if the user clicks the background * @param e Mouse event */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-editor/prompt-editor.ts#L705-L710
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptEditor.render
render() { // Compose the model checkbox lists let modelCheckboxes = html``; for (const model of this.availableModels) { // Check if the model is included in the recommended model list modelCheckboxes = html`${modelCheckboxes} <div class="checkbox-group"> <input ty...
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-editor/prompt-editor.ts#L719-L1202
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptViewer.constructor
constructor() { super(); this.promptData = getEmptyPromptDataRemote(); }
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-viewer/prompt-viewer.ts#L43-L46
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptViewer.willUpdate
willUpdate(changedProperties: PropertyValues<this>) {}
/** * This method is called before new DOM is updated and rendered * @param changedProperties Property that has been changed */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-viewer/prompt-viewer.ts#L52-L52
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptViewer.initData
async initData() {}
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-viewer/prompt-viewer.ts#L57-L57
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptViewer.tagClicked
tagClicked(e: MouseEvent, tag: string) { e.preventDefault(); e.stopPropagation(); }
/** * Tag clicked event handler * @param tag Clicked tag name */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-viewer/prompt-viewer.ts#L66-L69
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptViewer.closeButtonClicked
closeButtonClicked() { if (this.shadowRoot === null) { throw Error('shadowRoot is null'); } // Notify the parent const event = new Event('close-clicked', { bubbles: true, composed: true }); this.dispatchEvent(event); }
/** * Event handler for clicking the close button */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-viewer/prompt-viewer.ts#L74-L85
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptViewer.promptEditorBackgroundClicked
promptEditorBackgroundClicked(e: MouseEvent) { const target = e.target as HTMLElement; if (target.classList.contains('prompt-viewer')) { this.closeButtonClicked(); } }
/** * Close the modal if the user clicks the background * @param e Mouse event */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-viewer/prompt-viewer.ts#L91-L96
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptViewer.shareButtonClicked
shareButtonClicked() { const promptID = this.promptData.forkFrom.replace('prompt#', ''); const shareData: ShareData = { title: 'Wordflow', text: this.promptData.title, url: `https://poloclub.github.io/wordflow?prompt=${promptID}` }; navigator.share(shareData); }
/** * Use web share api to share this prompt */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-viewer/prompt-viewer.ts#L111-L119
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptViewer.getInfoPairs
getInfoPairs() { const infos: InfoPair[] = []; infos.push({ key: 'Injection mode', value: this.promptData.injectionMode }); if (this.promptData.recommendedModels.length > 0) { const models = this.promptData.recommendedModels.join(', '); infos.push({ key: 'Models', value: models }); } i...
/** * Create info as key-value pairs */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-viewer/prompt-viewer.ts#L128-L151
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowPromptViewer.render
render() { // Compose the share info const numFormatter = d3.format(','); // d3.timeFormat('%m/%d/%Y'); let dateFormatter = d3.timeFormat('%b %d, %Y'); const fullTimeFormatter = d3.timeFormat('%b %d, %Y %H:%M'); const date = d3.isoParse(this.promptData.created)!; const curDate = new Date(); ...
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/prompt-viewer/prompt-viewer.ts#L156-L280
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowSettingWindow.constructor
constructor() { super(); }
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/setting-window/setting-window.ts#L103-L105
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowSettingWindow.willUpdate
willUpdate(changedProperties: PropertyValues<this>) {}
/** * This method is called before new DOM is updated and rendered * @param changedProperties Property that has been changed */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/setting-window/setting-window.ts#L111-L111
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowSettingWindow.initData
async initData() {}
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/setting-window/setting-window.ts#L124-L124
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowSettingWindow.showCommunityPrompt
showCommunityPrompt(prompt: PromptDataRemote) { this.activeMenuItemIndex = 1; this.communityPanelComponent.then(panel => { panel.promptCardClicked(prompt); }); }
/** * Show a community prompt without clicking * @param prompt remote prompt data */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/setting-window/setting-window.ts#L130-L135
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowSettingWindow.menuItemClicked
menuItemClicked(index: number) { this.activeMenuItemIndex = index; }
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/setting-window/setting-window.ts#L140-L142
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowSettingWindow.promptViewerAddClickHandler
promptViewerAddClickHandler(e: CustomEvent<PromptDataRemote>) { if (!this.toastComponent) { throw Error('Toast is undefined.'); } const remotePrompt = e.detail; const newLocalPrompt: PromptDataLocal = { ...remotePrompt, key: uuidv4() }; let curUserID = localStorage.getItem('user-id'); if...
/** * Fork a remote prompt into the local library */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/setting-window/setting-window.ts#L147-L175
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowSettingWindow.backgroundClicked
backgroundClicked(e: MouseEvent) { const target = e.target as HTMLElement; if (target.classList.contains('setting-window')) { this.closeButtonClicked(); } }
/** * Close the modal if the user clicks the background * @param e Mouse event */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/setting-window/setting-window.ts#L189-L194
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowSettingWindow.render
render() { const menuItems: MenuItem[] = [ { name: 'My Prompts', component: html`<wordflow-panel-local class="setting-panel" ?is-shown=${this.activeMenuItemIndex === 0} .promptManager=${this.promptManager} .localPrompts=${this.localPrompts} .fa...
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/setting-window/setting-window.ts#L203-L289
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowSidebarMenu.constructor
constructor() { super(); this.modeColorMap = { add: { backgroundColor: config.customColors.addedColor, circleColor: config.colors['green-200'] }, replace: { backgroundColor: config.customColors.replacedColor, circleColor: config.colors['orange-200'] }, ...
// ===== Lifecycle Methods ======
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/sidebar-menu/sidebar-menu.ts#L63-L97
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowSidebarMenu.willUpdate
willUpdate(changedProperties: PropertyValues<this>) {}
/** * This method is called before new DOM is updated and rendered * @param changedProperties Property that has been changed */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/sidebar-menu/sidebar-menu.ts#L103-L103
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowSidebarMenu.initData
async initData() {}
// ===== Custom Methods ======
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/sidebar-menu/sidebar-menu.ts#L117-L117
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowSidebarMenu.footerButtonClicked
footerButtonClicked(e: MouseEvent) { const target = e.target as HTMLElement; if (target.tagName !== 'BUTTON') { return; } // Event delegation based on the button that the user clicks const buttonName = target.getAttribute('button-key'); if (buttonName === null) { console.error('Cli...
// ===== Event Methods ======
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/sidebar-menu/sidebar-menu.ts#L120-L141
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowSidebarMenu.buttonMouseEntered
buttonMouseEntered(e: MouseEvent, message: string) { const target = e.currentTarget as HTMLElement; tooltipMouseEnter(e, message, 'top', this.tooltipConfig, 200, target, 10); }
/** * Event handler for mouse entering the info icon in each filed * @param e Mouse event * @param field Field type */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/sidebar-menu/sidebar-menu.ts#L148-L151
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowSidebarMenu.buttonMouseLeft
buttonMouseLeft() { tooltipMouseLeave(this.tooltipConfig); }
/** * Event handler for mouse leaving the info icon in each filed */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/sidebar-menu/sidebar-menu.ts#L156-L158
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowSidebarMenu.render
render() { // Compose the summary text let summaryText = html``; if (this.summaryCounter) { for (const key of Object.keys(this.summaryCounter)) { const k = key as keyof SidebarSummaryCounter; const count = this.summaryCounter[k]; if (count > 0) { summaryText = html`$...
// ===== Templates and Styles ======
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/sidebar-menu/sidebar-menu.ts#L161-L270
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
NightjarSlider.constructor
constructor() { super(); }
// ===== Lifecycle Methods ======
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/slider/slider.ts#L46-L48
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
NightjarSlider.willUpdate
willUpdate(changedProperties: PropertyValues<this>) { if (changedProperties.has('curValue') && this.curValue !== null) { this.syncThumb(); } }
/** * This method is called before new DOM is updated and rendered * @param changedProperties Property that has been changed */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/slider/slider.ts#L61-L65
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
NightjarSlider.initData
initData = async () => {}
// ===== Custom Methods ======
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/slider/slider.ts
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
NightjarSlider.syncThumb
syncThumb() { if (this.curValue !== null) { // Update the thumb to reflect the cur value const track = this.backgroundTrackElement; const thumb = this.middleThumbElement; const rangeTrack = this.rangeTrackElement; if (track && thumb && rangeTrack) { const thumbBBox = thumb.get...
/** * Sync thumb position to this.curValue */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/slider/slider.ts#L73-L91
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
NightjarSlider.thumbMouseDownHandler
thumbMouseDownHandler(e: MouseEvent) { e.preventDefault(); e.stopPropagation(); const thumb = e.target! as HTMLElement; if (!thumb.id.includes('thumb')) { console.error('Thumb event target is not thumb itself.'); } // const eventBlocker = this.component.querySelector('.grab-blocker')!; ...
/** * Event handler for the thumb mousedown */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/slider/slider.ts#L97-L160
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
NightjarSlider.render
render() { const cssVariables = { '--foreground-color': this.styleConfig?.foregroundColor || 'hsl(174, 41.28%, 78.63%)', '--background-color': this.styleConfig?.backgroundColor || 'hsl(174, 100%, 29.41%)' }; return html` <div class="slider" style=${styleMap(cssVariables)}>...
// ===== Templates and Styles ======
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/slider/slider.ts#L163-L187
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
updateFloatingMenuPosition
const updateFloatingMenuPosition = async ( options: EventHandlerProps, editor: Editor, view: EditorView ) => { const floatingMenuBox = await options.floatingMenuBox; const $from = view.state.selection.$from; const cursorCoordinate = view.coordsAtPos($from.pos); // Need to bound the box inside the view ...
/** * Update the position of the floating menu * @param options Props * @param editor Editor * @param view Editor view */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/event-handler.ts#L33-L64
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
diff_linesToCharsMunge_
const diff_linesToCharsMunge_ = (text: string) => { let chars = ''; // Walk the text, pulling out a substring for each line. // text.split('\n') would would temporarily double our memory footprint. // Modifying text would create many large strings to garbage collect. let lineStart = 0; let lineE...
/** * Split a text into an array of strings. Reduce the texts to a string of * hashes where each Unicode character represents one line. * Modifies linearray and linehash through being a closure. * @param {string} text String to encode. * @return {string} Encoded string. * @private */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-diff.ts#L37-L75
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor.constructor
constructor() { super(); }
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L124-L126
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor.willUpdate
willUpdate(changedProperties: PropertyValues<this>) {}
/** * This method is called before new DOM is updated and rendered * @param changedProperties Property that has been changed */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L285-L285
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor.initData
async initData() {}
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L290-L290
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor.isEmptySelection
isEmptySelection() { if (this.editor === null) { console.error('Editor is not initialized yet.'); return; } const { $from, $to } = this.editor.view.state.selection; let hasSelection = $from.pos !== $to.pos; // If the user select the collapse node, the selection range is also 1 if (Ma...
/** * Detection if the users has not selected anything * @returns True if there is empty selection */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L407-L422
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor.acceptChange
acceptChange() { if (this.editor === null) { throw Error('Editor is not fully initialized'); } const view = this.editor.view; const state = view.state; const selection = state.selection; const { $from } = selection; const isActive = this._isEditActive(); if (!isActive) { re...
/** * Accept the current active edit (replace, add, or delete) */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L427-L459
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor.rejectChange
rejectChange() { if (this.editor === null) { throw Error('Editor is not fully initialized'); } const view = this.editor.view; const state = view.state; const { selection, schema } = state; const { $from } = selection; const isActive = this._isEditActive(); if (!isActive) { ...
/** * Reject the current active edit (replace, add, or delete) */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L464-L536
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor.acceptAllChanges
acceptAllChanges() { if (this.editor === null) { throw Error('Editor is not fully initialized'); } const view = this.editor.view; const state = view.state; const selection = state.selection; const { $from, $to } = selection; const tr = state.tr; // Remove all the marks const ...
/** * Accept all edits in the selection (replace, add, or delete) */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L541-L576
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor.rejectAllChanges
rejectAllChanges() { if (this.editor === null) { throw Error('Editor is not fully initialized'); } const view = this.editor.view; const state = view.state; const { selection, schema } = state; const { $from, $to } = selection; const tr = state.tr; // To reject a change, we need t...
/** * Reject all edits in the selection (replace, add, or delete) */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L581-L629
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor.textGenLocalWorkerMessageHandler
textGenLocalWorkerMessageHandler(e: MessageEvent<TextGenLocalWorkerMessage>) { switch (e.data.command) { case 'finishTextGen': { const message: TextGenMessage = { command: 'finishTextGen', payload: e.data.payload }; this.textGenLocalWorkerResolve(message); b...
/** * Event handler for the text gen local worker * @param e Text gen message */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L638-L671
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor.floatingMenuToolsMouseEnterHandler
floatingMenuToolsMouseEnterHandler() { if (this.editor === null) { console.error('Editor is not initialized yet.'); return; } this.isHoveringFloatingMenu = true; const { $from, $to } = this.editor.view.state.selection; const hasSelection = this.isEmptySelection(); // Highlight the p...
/** * Highlight the currently effective selection. It is the user's selected * text or the current paragraph (if there is no selection). */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L705-L721
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor.floatingMenuToolsMouseLeaveHandler
floatingMenuToolsMouseLeaveHandler() { if (this.editor === null) { console.error('Editor is not initialized yet.'); return; } this.isHoveringFloatingMenu = false; const { $from, $to } = this.editor.view.state.selection; const hasSelection = this.isEmptySelection(); // Highlight the ...
/** * Cancel any highlighting set from mouseenter */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L726-L739
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor.floatingMenuToolButtonClickHandler
floatingMenuToolButtonClickHandler(promptData: PromptDataLocal) { if (this.editor === null) { console.error('Editor is not initialized yet.'); return; } const { state } = this.editor.view; const { $from, $to } = state.selection; const hasSelection = this.isEmptySelection(); // Para...
/** * Execute the prompt on the selected text */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L744-L950
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor._runPrompt
_runPrompt(promptData: PromptDataLocal, inputText: string) { const curPrompt = this._formatPrompt( promptData.prompt, inputText, INPUT_TEXT_PLACEHOLDER ); let runRequest: Promise<TextGenMessage>; switch (this.userConfig.preferredLLM) { case SupportedRemoteModel['gpt-3.5']: { ...
/** * Run the given prompt using the preferred model * @returns A promise of the prompt inference */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L960-L1053
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor._handleError
_handleError(errorMessage: string) { console.error('Failed to generate text', errorMessage); let message = 'Failed to run this prompt. Try again later.'; if (errorMessage === 'time out') { message = 'Fail to run this prompt (OpenAI API timed out!)'; } if (errorMessage === 'Rate limit exceed...
/** * Show a toast when the API call is timed out * @param errorMessage Error message */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L1059-L1081
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor._updateAfterSuccessfulPromptRun
_updateAfterSuccessfulPromptRun(promptData: PromptDataLocal) { if (this.editor === null) { console.error('Editor is not initialized yet.'); return; } const newPrompt = structuredClone(promptData); newPrompt.promptRunCount += 1; this.promptManager.setPrompt(newPrompt); // Also updat...
/** * Increase the prompt run count by 1 * @param promptData Prompt data */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L1087-L1103
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor._formatPrompt
_formatPrompt(prompt: string, inputText: string, placeholder: string) { let curPrompt = ''; if (prompt.includes(placeholder)) { curPrompt = prompt.replace(placeholder, inputText); } else { curPrompt = prompt + '\n' + inputText; } return curPrompt; }
/** * Combine prompt prefix and the input text * @param prompt Prompt prefix * @param inputText Input text * @param placeholder Placeholder string * @returns Formatted prompt */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L1112-L1120
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor._parseOutput
_parseOutput(prompt: PromptDataLocal, output: string) { if (prompt.outputParsingPattern === '') { return output; } const pattern = new RegExp(prompt.outputParsingPattern); let replacement = prompt.outputParsingReplacement; if (replacement === '') { replacement = '$1'; } const o...
/** * Parse an LLM output using rules defined in a prompt * @param prompt Prompt data * @param output LLM output */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L1127-L1140
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor._isEditActive
_isEditActive() { if (this.editor === null) { throw Error('Editor is not fully initialized'); } const view = this.editor.view; const selection = view.state.selection; const { $from } = selection; let isActive = false; if (this.editor.isActive('edit-highlight')) { if ($from.mark...
/** * Helper method to check if the user has selected an edit * @returns True if an edit is actively selected */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L1146-L1167
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor._setParagraphAttribute
_setParagraphAttribute( $from: ResolvedPos, attribute: string, value: string | null ) { if (this.editor === null) { console.error('Editor is not initialized yet.'); return; } // Find the paragraph node of the cursor's region const paragraphNode = $from.node(1); const parag...
/** * Set the attribute of the current paragraph node * @param $from From position of the selection * @param attribute Attribute name * @param value Attribute value * @returns void */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L1176-L1200
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor._dispatchLoadingFinishedEvent
_dispatchLoadingFinishedEvent() { const event = new Event('loading-finished', { bubbles: true, composed: true }); this.dispatchEvent(event); }
/** * Notify the parent that the loading is finished. */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L1205-L1211
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
WordflowTextEditor.render
render() { return html` <div class="text-editor-container"> <div class="text-editor" ?is-hovering-floating-menu=${this.isHoveringFloatingMenu} ></div> </div>`; }
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/text-editor/text-editor.ts#L1216-L1223
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
NightjarToast.constructor
constructor() { super(); }
//==========================================================================||
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/toast/toast.ts#L109-L111
09840c4b7b4434152c83b55c5d47ab85d367e772
wordflow
github_2023
poloclub
typescript
NightjarToast.willUpdate
willUpdate(changedProperties: PropertyValues<this>) {}
/** * This method is called before new DOM is updated and rendered * @param changedProperties Property that has been changed */
https://github.com/poloclub/wordflow/blob/09840c4b7b4434152c83b55c5d47ab85d367e772/src/components/toast/toast.ts#L117-L117
09840c4b7b4434152c83b55c5d47ab85d367e772