From 0d8c05db9cbb5a23a94554c65015c347ff8c38b9 Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 31 Jan 2024 20:39:47 -0500 Subject: cleaned up accessing/setting proto_embeddings with api on Doc. fixed some css related to IconButtons. added a paintView toggle button to dec decorations for text with code blocks. enabled text with code to modify Docs and get this and documentView as params. --- .../views/nodes/formattedText/RichTextRules.ts | 49 +++++++--------------- 1 file changed, 15 insertions(+), 34 deletions(-) (limited to 'src/client/views/nodes/formattedText/RichTextRules.ts') diff --git a/src/client/views/nodes/formattedText/RichTextRules.ts b/src/client/views/nodes/formattedText/RichTextRules.ts index 8f7bc5282..ce2c33fb4 100644 --- a/src/client/views/nodes/formattedText/RichTextRules.ts +++ b/src/client/views/nodes/formattedText/RichTextRules.ts @@ -68,40 +68,21 @@ export class RichTextRules { ), // ``` create code block - textblockTypeInputRule(/^```$/, schema.nodes.code_block), - new InputRule( - new RegExp(/(^|\n)\^@paint/), // for code blocks '^' means the beginning of the block, not the line, so need to test for \n - (state, match, start, end) => { - const { dataDoc, layoutDoc, fieldKey } = this.TextBox; - layoutDoc.type_collection = CollectionViewType.Freeform; - const paintedField = 'layout_' + this.TextBox.fieldKey + 'Painted'; - dataDoc[paintedField] = CollectionView.LayoutString(this.TextBox.fieldKey); - const layoutFieldKey = StrCast(layoutDoc.layout_fieldKey); - layoutDoc.layout_fieldKey = paintedField; - this.TextBox.DocumentView?.().setToggleDetail(layoutFieldKey.replace('layout_', '').replace('layout', '')); - layoutDoc.layout_fieldKey = layoutFieldKey; - const comment = '/* enable as paint function '; - const endComment = ' */\n'; - const inCode = state.tr.selection.$anchor.node().type === schema.nodes.code_block; - if (inCode) { - const tr = state.tr - .deleteRange(start, end) - .insertText(comment) - .insert(start + comment.length, schema.nodes.paintButton.create()) - .insertText(endComment); - return tr.setSelection(new TextSelection(tr.doc.resolve(start + comment.length + endComment.length + 1))); - } else { - const tr = state.tr - .deleteRange(start, end) - .insertText(comment) - .insert(start + comment.length, schema.nodes.paintButton.create()) - .insertText(endComment) - .insert(start + comment.length + endComment.length + 1, schema.nodes.code_block.create()); - return tr.setSelection(new TextSelection(tr.doc.resolve(start + comment.length + endComment.length + 3))); - } - }, - { inCode: true } - ), + new InputRule(/^```$/, (state, match, start, end) => { + let $start = state.doc.resolve(start); + if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), schema.nodes.code_block)) return null; + + // this enables text with code blocks to be used as a 'paint' function via a styleprovider button that is added to Docs that have an onPaint script + this.TextBox.layoutDoc.type_collection = CollectionViewType.Freeform; // make it a freeform when rendered as a collection since those are the only views that know about the paint function + const paintedField = 'layout_' + this.TextBox.fieldKey + 'Painted'; // make a layout field key for storing the CollectionView jsx string pointing to the textbox's text + this.TextBox.dataDoc[paintedField] = CollectionView.LayoutString(this.TextBox.fieldKey); + const layoutFieldKey = StrCast(this.TextBox.layoutDoc.layout_fieldKey); // save the current layout fieldkey + this.TextBox.layoutDoc.layout_fieldKey = paintedField; // setup the paint layout field key + this.TextBox.DocumentView?.().setToggleDetail(layoutFieldKey.replace('layout_', '').replace('layout', ''), 'onPaint'); // create the script to toggle between the painted and regular view + this.TextBox.layoutDoc.layout_fieldKey = layoutFieldKey; // restore the layout field key to text + + return state.tr.delete(start, end).setBlockType(start, start, schema.nodes.code_block); + }), // % set the font size new InputRule(new RegExp(/%([0-9]+)\s$/), (state, match, start, end) => { -- cgit v1.2.3-70-g09d2