Skip to content

Commit

Permalink
remove comments, console.log, etc. ; type imports
Browse files Browse the repository at this point in the history
  • Loading branch information
benrbray committed May 3, 2023
1 parent f0ec7f8 commit ed80514
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 173 deletions.
30 changes: 13 additions & 17 deletions noteworthy-electron/src/common/doctypes/markdown-doc.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// noteworthy imports
import { ICrossRefProvider } from "@main/plugins/crossref-plugin";
import { IDoc, DocMeta, AstParser } from "./doctypes";
import { IOutlineProvider, IOutlineEntry } from "@main/plugins/outline-plugin";
import { IMetadataProvider, IMetadata } from "@main/plugins/metadata-plugin";
import type { IOutlineProvider, IOutlineEntry } from "@main/plugins/outline-plugin";
import type { IMetadataProvider, IMetadata } from "@main/plugins/metadata-plugin";
import { EditorConfig } from "@common/extensions/editor-config";

// markdown / mdast
Expand All @@ -16,8 +16,7 @@ import {
ImageExtension, HardBreakExtension, ParagraphExtension,
ContainerDirectiveExtension,
CitationExtension,
RootExtension,
//RegionExtension, EmbedExtension,
RootExtension
} from "@common/extensions/node-extensions";

// mark extensions
Expand All @@ -31,11 +30,11 @@ import {
import { unistPredicate, visit, visitNodeType } from "@common/markdown/unist-utils";
import { SyntaxExtension } from "@common/extensions/extension";
import { mdastTextContent } from "@common/markdown/mdast-to-string";
import { Citation, ICitationProvider } from "@main/plugins/citation-plugin";
import type { Citation, ICitationProvider } from "@main/plugins/citation-plugin";
import { pick } from "@common/util/pick";
import { parseDate, formatDate } from "@common/util/date";

// yaml / toml
// yaml / toml
import YAML from "yaml";


Expand Down Expand Up @@ -63,9 +62,6 @@ export function makeDefaultMarkdownExtensions(): SyntaxExtension[] {
// nodes: math
new InlineMathExtension(),
new BlockMathExtension(),
// nodes: special
// new RegionExtension(),
// new EmbedExtension(),
// nodes: directives
// new TextDirectiveExtension(),
// new LeafDirectiveExtension(),
Expand Down Expand Up @@ -95,7 +91,7 @@ export const defaultMarkdownConfig = new EditorConfig(
////////////////////////////////////////////////////////////////////////////////

export class MarkdownAst implements IDoc, ICrossRefProvider, IOutlineProvider, IMetadataProvider, ICitationProvider {

private readonly _yaml: { [key:string] : string|string[] };

/**
Expand All @@ -110,15 +106,15 @@ export class MarkdownAst implements IDoc, ICrossRefProvider, IOutlineProvider, I
* At the moment, YAML is only lifted from the doc during the mdast -> prose tree
* transformation phase. This function is called by workspace plugins, which work
* with the AST directly rather than instantiating a ProseMirror document. So,
* we have to manually extract the metadata here.
* we have to manually extract the metadata here.
*
* We shouldn't need to parse the YAML more than once in different places. This
* will also cause trouble when we want to pass TOML/JSON metadata, or extract
* metadata that might be interspersed throughout the document.
*
* Probably, we should do a metadata collection pass on the tree as part of parsing.
*/

// expect YAML node at start of document, otherwise return empty metadata
if(this._root?.children?.length > 0 && this._root.children[0].type === "yaml") {
// parse YAML
Expand All @@ -131,13 +127,13 @@ export class MarkdownAst implements IDoc, ICrossRefProvider, IOutlineProvider, I
}

get root(): Md.Root { return this._root; }

// -- IMarkdownDoc ---------------------------------- //

getMeta(): DocMeta {
return this._yaml;
}

static parseAST(serialized: string) : MarkdownAst|null {
let ast = defaultMarkdownConfig.parseAST(serialized);
if(!ast){ return null; }
Expand Down Expand Up @@ -170,7 +166,7 @@ export class MarkdownAst implements IDoc, ICrossRefProvider, IOutlineProvider, I
// -- IMetadataProvider ----------------------------- //

public IS_METADATA_PROVIDER: true = true;

getMetadata(): IMetadata {
/** @todo (10/2/20) unify this function with getMeta() above */
return this._yaml;
Expand Down Expand Up @@ -225,7 +221,7 @@ export class MarkdownAst implements IDoc, ICrossRefProvider, IOutlineProvider, I

getTagsDefined():string[] {
let tags:string[] = [];

// tags defined by YAML metadata
let meta = this.getMeta();
if(meta.tags_defined){
Expand Down Expand Up @@ -269,7 +265,7 @@ export class MarkdownAst implements IDoc, ICrossRefProvider, IOutlineProvider, I
// find all wikilinks and citations
// TODO: (2021-05-30) restore #tag syntax?
visit(this._root, node => {
if(unistPredicate<Md.Wikilink>(node, "wikiLink")) {
if(unistPredicate<Md.Wikilink>(node, "wikiLink")) {
tags.push(node.value);
} else if(unistPredicate<Md.Cite>(node, "cite")) {
node.data.citeItems.forEach(item => {
Expand Down
117 changes: 0 additions & 117 deletions noteworthy-electron/src/common/extensions/node-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,123 +850,6 @@ export class BlockMathExtension extends NodeSyntaxExtension<Md.BlockMath> {
prose2mdast() { return Prose2Mdast_NodeMap_Presets.NODE_LIFT_LITERAL; }
}

/* -- Region -------------------------------------------- */

// TODO (2021/05/09) Markdown Directives Plugin for Remark

// export class RegionExtension extends NodeSyntaxExtension {

// get name() { return "region" as const; }

// createNodeSpec(): NodeSpec {
// return {
// content: "block+",
// attrs: { "region" : { default: null } },
// parseDOM: [{
// tag: "div.region",
// getAttrs(d:string|Node){
// let dom: HTMLElement = d as HTMLElement;
// return {
// ...(dom.hasAttribute("data-region") && { "region": dom.getAttribute("data-region") })
// }
// }
// }],
// toDOM(node: ProseNode): DOMOutputSpec {
// return ["div", {
// class: "region",
// ...( node.attrs.region && { "data-region": node.attrs.region } )
// }, 0];
// }
// };
// }

// createKeymap(): Keymap { return {
// "Mod-r" : (state, dispatch, view) => {
// let { $to } = state.selection;

// openPrompt({
// title: "Create Region",
// fields: {
// region: new TextField({
// label: "Region Name",
// required: true
// }),
// },
// callback(attrs: { [key: string]: any; } | undefined) {
// // insert new embed node at top level
// let tr = state.tr.insert($to.after(1), this.type.createAndFill(attrs))
// if(dispatch){ dispatch(tr); }
// if(view){ view.focus(); }
// }
// })
// return true;
// }
// }}
// }

/* -- Embed -------------------------------------------- */

// export class EmbedExtension extends NodeSyntaxExtension {

// get name() { return "embed" as const; }

// createNodeSpec(): NodeSpec {
// return {
// content: "block+",
// group: "embed",
// atom: true,
// attrs: {
// fileName: {default: "" },
// regionName : { default: "" },
// },
// parseDOM: [{
// tag: "div.embed",
// getAttrs(d: string| Node){
// let dom: HTMLElement = d as HTMLElement;
// return {
// ...(dom.hasAttribute("data-fileName") && { fileName: dom.getAttribute("data-fileName") }),
// ...(dom.hasAttribute("data-regionName") && { regionName: dom.getAttribute("data-regionName")})
// }
// }
// }],
// toDOM(node: ProseNode): DOMOutputSpec {
// return ["div", {
// class: "embed",
// ...node.attrs
// }, 0];
// }
// };
// }

// createKeymap(): Keymap { return {
// "Mod-m" : (state, dispatch, view) => {
// let { $to } = state.selection;

// openPrompt({
// title: "Embed Region",
// fields: {
// fileName: new TextField({
// label: "File Name",
// required: true
// }),
// regionName: new TextField({
// label: "Region Name",
// required: true
// }),
// },
// callback(attrs: { [key: string]: any; } | undefined) {
// // insert new embed node at top level
// let tr = state.tr.insert($to.after(1), this.type.createAndFill(attrs))
// if(dispatch){ dispatch(tr); }
// if(view){ view.focus(); }
// }
// })
// return true;
// }
// }}

// }

////////////////////////////////////////////////////////////

export interface ContainerDirective_ProseAttrs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export const Suggest = (
result[k] = len;
len += groupLen;
}
console.log("foo", result);
return result;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ extends NoteworthyExtension<Autocomplete.Name> {
private _providers: AutocompleteProviders
){
super();
console.log("autocomplete :: constructor");

// add suggest
// create suggestion overlay
let suggestElt: HTMLDivElement|null = document.getElementById("suggest-wrapper") as HTMLDivElement;
if(!suggestElt) { suggestElt = document.createElement("div"); }
suggestElt.replaceChildren("");
Expand Down Expand Up @@ -159,7 +158,7 @@ extends NoteworthyExtension<Autocomplete.Name> {

const options: Options = {
triggers: triggers,
reducer: (action) => this._reducer(action)
reducer: (action: AutocompleteAction) => this._reducer(action)
};

return [...autocomplete(options)];
Expand Down Expand Up @@ -203,8 +202,6 @@ extends NoteworthyExtension<Autocomplete.Name> {
}

private _reducer(action: AutocompleteAction): boolean {
console.log(`autocomplete :: action=${action.kind}`);

this._view = action.view;

// get autocomplete provider
Expand All @@ -213,10 +210,10 @@ extends NoteworthyExtension<Autocomplete.Name> {
const provider = this.getProvider(type.name);
if(!provider) { return false; }


// filter
// position info
let rect = action.view.dom.getBoundingClientRect();

// state machine
switch (action.kind) {
case ActionKind.open:
this._signals.setIsOpen(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ const makeProviders = (api: NoteworthyExtensionApi): AutocompleteProviders => ({
items: group.items.filter(s => s.text.toLowerCase().startsWith(query.toLowerCase()))
};
}).filter(group => group.items.length > 0);

console.log(result);
return result;
},
accept: (id: string) => {
Expand All @@ -44,8 +42,6 @@ const makeProviders = (api: NoteworthyExtensionApi): AutocompleteProviders => ({
allowSpace: false,
search: async (query: string) => {
const result = await api.fuzzyTagSearch(query);
console.log(result);

const data: SuggestData = [{
label: "Tag Search",
items: result.map(tag => ({
Expand Down
13 changes: 0 additions & 13 deletions noteworthy-electron/src/renderer/src/editors/editor-markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ import { SetDocAttrStep } from "@common/prosemirror/steps";

////////////////////////////////////////////////////////////

// The use of `contextIsolation=true` for election requires a preload phase to
// expose Electron APIs to the render process. These APIs are made available
// globally at runtime, and I haven't found clever enough typings yet to express
// this transformation. So, we must explicitly declare them here:
// import { WindowAfterPreload } from "@renderer/preload_types";
// declare let window: Window & typeof globalThis & WindowAfterPreload;

// extensions
import { NoteworthyExtension, NoteworthyExtensionInitializer, RegisteredExtensionName } from "@common/extensions/noteworthy-extension";
import codeMirrorPreviewExtension from "@extensions/noteworthy-codemirror-preview";
Expand Down Expand Up @@ -400,12 +393,6 @@ export class MarkdownEditor<S extends ProseSchema = ProseSchema> extends Editor<
state: state,
nodeViews: {
...this._config.nodeViews
// TODO: restore embed view?
// "embed": (node, view, getPos) => {
// return new EmbedView(
// node, view, getPos as (() => number), this._mainProxy
// );
// },
},
dispatchTransaction: (tr: Transaction): void => {
// unsaved changes?
Expand Down
14 changes: 0 additions & 14 deletions noteworthy-electron/src/renderer/src/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ import { ITagSearchResult, IFileSearchResult } from "@main/plugins/crossref-plug

////////////////////////////////////////////////////////////

// The use of `contextIsolation=true` for election requires a preload phase to
// expose Electron APIs to the render process. These APIs are made available
// globally at runtime, and I haven't found clever enough typings yet to express
// this transformation. So, we must explicitly declare them here:
// import { WindowAfterPreload } from "@preload/preload";
// declare let window: Window & typeof globalThis & WindowAfterPreload;

import { MouseButton } from "@common/inputEvents";
import { visitNodeType } from "@common/markdown/unist-utils";
// this is a "safe" version of ipcRenderer exposed by the preload script
Expand Down Expand Up @@ -135,8 +128,6 @@ class Renderer {
}

init() {
console.log("render :: init()");

ipcRenderer.receive(IpcEvents.RENDERER_INVOKE,
(responseId: string, key: RendererIpcEvents, data: any) => {
console.log("render.on() :: RENDERER_INVOKE ::", responseId, key, data);
Expand Down Expand Up @@ -182,12 +173,9 @@ class Renderer {
}

const getOutline = async (): Promise<IOutline|null> => {
console.log("getOutline");
let hash = activeHash();
if(!hash){ return null; }
console.log("getOutline :: hash=", hash);
let outline = await this._mainProxy.outline.requestOutlineForHash(hash);
console.log("outline found", outline);
return outline;
}

Expand Down Expand Up @@ -217,7 +205,6 @@ class Renderer {
let fileHash = target.getAttribute("data-filehash");
if(fileHash === null){ return; }

console.log("explorer :: clicked", fileHash);
this._mainProxy.navigation.navigateToHash({ hash: fileHash });
}

Expand Down Expand Up @@ -252,7 +239,6 @@ class Renderer {
}

const search = async (query:string): Promise<(ITagSearchResult|IFileSearchResult)[]> => {
console.log("searching...", query);
let result = await this._mainProxy.tag.fuzzyTagFileSearch(query);
return result;
}
Expand Down

0 comments on commit ed80514

Please sign in to comment.