@wordpress/block-editor
Version:
8 lines (7 loc) • 1.95 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/components/rich-text/use-mark-persistent.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useLayoutEffect, useRef } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\nexport function useMarkPersistent( { html, value } ) {\n\tconst previousTextRef = useRef();\n\tconst hasActiveFormats = !! value.activeFormats?.length;\n\tconst { __unstableMarkLastChangeAsPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\n\t// Must be set synchronously to make sure it applies to the last change.\n\tuseLayoutEffect( () => {\n\t\t// Ignore mount.\n\t\tif ( ! previousTextRef.current ) {\n\t\t\tpreviousTextRef.current = value.text;\n\t\t\treturn;\n\t\t}\n\n\t\t// Text input, so don't create an undo level for every character.\n\t\t// Create an undo level after 1 second of no input.\n\t\tif ( previousTextRef.current !== value.text ) {\n\t\t\tconst timeout = window.setTimeout( () => {\n\t\t\t\t__unstableMarkLastChangeAsPersistent();\n\t\t\t}, 1000 );\n\t\t\tpreviousTextRef.current = value.text;\n\t\t\treturn () => {\n\t\t\t\twindow.clearTimeout( timeout );\n\t\t\t};\n\t\t}\n\n\t\t__unstableMarkLastChangeAsPersistent();\n\t}, [ html, hasActiveFormats ] );\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAwC;AACxC,kBAA4B;AAK5B,mBAA0C;AAEnC,SAAS,kBAAmB,EAAE,MAAM,MAAM,GAAI;AACpD,QAAM,sBAAkB,uBAAO;AAC/B,QAAM,mBAAmB,CAAC,CAAE,MAAM,eAAe;AACjD,QAAM,EAAE,qCAAqC,QAC5C,yBAAa,aAAAA,KAAiB;AAG/B,sCAAiB,MAAM;AAEtB,QAAK,CAAE,gBAAgB,SAAU;AAChC,sBAAgB,UAAU,MAAM;AAChC;AAAA,IACD;AAIA,QAAK,gBAAgB,YAAY,MAAM,MAAO;AAC7C,YAAM,UAAU,OAAO,WAAY,MAAM;AACxC,6CAAqC;AAAA,MACtC,GAAG,GAAK;AACR,sBAAgB,UAAU,MAAM;AAChC,aAAO,MAAM;AACZ,eAAO,aAAc,OAAQ;AAAA,MAC9B;AAAA,IACD;AAEA,yCAAqC;AAAA,EACtC,GAAG,CAAE,MAAM,gBAAiB,CAAE;AAC/B;",
"names": ["blockEditorStore"]
}