From 0fa8508232b454e13e6037c37daa73afe1651804 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Sat, 20 Feb 2021 02:53:33 +0000 Subject: [PATCH] Implement getTextLabel on draftail widget --- .../src/entrypoints/admin/telepath/widgets.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/client/src/entrypoints/admin/telepath/widgets.js b/client/src/entrypoints/admin/telepath/widgets.js index 74918f59fb..9bb8f6b698 100644 --- a/client/src/entrypoints/admin/telepath/widgets.js +++ b/client/src/entrypoints/admin/telepath/widgets.js @@ -137,6 +137,23 @@ class DraftailRichTextArea { setState() { throw new Error('DraftailRichTextArea.setState is not implemented'); }, + getTextLabel(opts) { + const maxLength = opts && opts.maxLength; + if (!input.value) return ''; + const value = JSON.parse(input.value); + if (!value || !value.blocks) return ''; + + let result = ''; + for (const block of value.blocks) { + if (block.text) { + result += (result ? ' ' + block.text : block.text); + if (maxLength && result.length > maxLength) { + return result.substring(0, maxLength - 1) + '…'; + } + } + } + return result; + }, focus: () => { input.draftailEditor.focus(); },