@wordpress/editor 12.6.0 → 12.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/build/components/editor-help/help-section-title.native.js +43 -0
- package/build/components/editor-help/help-section-title.native.js.map +1 -0
- package/build/components/editor-help/help-topic-row.native.js +3 -2
- package/build/components/editor-help/help-topic-row.native.js.map +1 -1
- package/build/components/editor-help/icon-move-blocks.native.js +23 -0
- package/build/components/editor-help/icon-move-blocks.native.js.map +1 -0
- package/build/components/editor-help/index.native.js +10 -11
- package/build/components/editor-help/index.native.js.map +1 -1
- package/build/components/editor-help/move-blocks.native.js +14 -2
- package/build/components/editor-help/move-blocks.native.js.map +1 -1
- package/build/components/editor-help/view-sections.native.js +21 -5
- package/build/components/editor-help/view-sections.native.js.map +1 -1
- package/build/components/post-featured-image/index.js +84 -41
- package/build/components/post-featured-image/index.js.map +1 -1
- package/build/components/post-schedule/index.js +11 -18
- package/build/components/post-schedule/index.js.map +1 -1
- package/build/components/post-taxonomies/flat-term-selector.js +2 -2
- package/build/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build/components/post-taxonomies/index.js +7 -1
- package/build/components/post-taxonomies/index.js.map +1 -1
- package/build/components/post-text-editor/index.js +12 -1
- package/build/components/post-text-editor/index.js.map +1 -1
- package/build/components/post-visibility/index.js +132 -167
- package/build/components/post-visibility/index.js.map +1 -1
- package/build/components/post-visibility/label.js +5 -22
- package/build/components/post-visibility/label.js.map +1 -1
- package/build/components/post-visibility/utils.js +14 -13
- package/build/components/post-visibility/utils.js.map +1 -1
- package/build/components/provider/index.native.js +3 -1
- package/build/components/provider/index.native.js.map +1 -1
- package/build/components/provider/use-block-editor-settings.js +15 -9
- package/build/components/provider/use-block-editor-settings.js.map +1 -1
- package/build/store/selectors.js +2 -2
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/editor-help/help-section-title.native.js +31 -0
- package/build-module/components/editor-help/help-section-title.native.js.map +1 -0
- package/build-module/components/editor-help/help-topic-row.native.js +3 -2
- package/build-module/components/editor-help/help-topic-row.native.js.map +1 -1
- package/build-module/components/editor-help/icon-move-blocks.native.js +13 -0
- package/build-module/components/editor-help/icon-move-blocks.native.js.map +1 -0
- package/build-module/components/editor-help/index.native.js +10 -12
- package/build-module/components/editor-help/index.native.js.map +1 -1
- package/build-module/components/editor-help/move-blocks.native.js +15 -3
- package/build-module/components/editor-help/move-blocks.native.js.map +1 -1
- package/build-module/components/editor-help/view-sections.native.js +22 -6
- package/build-module/components/editor-help/view-sections.native.js.map +1 -1
- package/build-module/components/post-featured-image/index.js +86 -42
- package/build-module/components/post-featured-image/index.js.map +1 -1
- package/build-module/components/post-schedule/index.js +12 -19
- package/build-module/components/post-schedule/index.js.map +1 -1
- package/build-module/components/post-taxonomies/flat-term-selector.js +2 -2
- package/build-module/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build-module/components/post-taxonomies/index.js +7 -1
- package/build-module/components/post-taxonomies/index.js.map +1 -1
- package/build-module/components/post-text-editor/index.js +13 -2
- package/build-module/components/post-text-editor/index.js.map +1 -1
- package/build-module/components/post-visibility/index.js +132 -166
- package/build-module/components/post-visibility/index.js.map +1 -1
- package/build-module/components/post-visibility/label.js +5 -20
- package/build-module/components/post-visibility/label.js.map +1 -1
- package/build-module/components/post-visibility/utils.js +14 -13
- package/build-module/components/post-visibility/utils.js.map +1 -1
- package/build-module/components/provider/index.native.js +2 -1
- package/build-module/components/provider/index.native.js.map +1 -1
- package/build-module/components/provider/use-block-editor-settings.js +16 -10
- package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
- package/build-module/store/selectors.js +2 -2
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +51 -52
- package/build-style/style.css +51 -52
- package/package.json +29 -28
- package/src/components/autosave-monitor/test/index.js +3 -0
- package/src/components/editor-help/help-section-title.native.js +29 -0
- package/src/components/editor-help/help-topic-row.native.js +2 -2
- package/src/components/editor-help/icon-move-blocks.native.js +10 -0
- package/src/components/editor-help/images/drag-and-drop-dark.png +0 -0
- package/src/components/editor-help/images/drag-and-drop-dark@2x.png +0 -0
- package/src/components/editor-help/images/drag-and-drop-dark@3x.png +0 -0
- package/src/components/editor-help/images/drag-and-drop-light.png +0 -0
- package/src/components/editor-help/images/drag-and-drop-light@2x.png +0 -0
- package/src/components/editor-help/images/drag-and-drop-light@3x.png +0 -0
- package/src/components/editor-help/index.native.js +20 -22
- package/src/components/editor-help/move-blocks.native.js +22 -2
- package/src/components/editor-help/style.scss +36 -4
- package/src/components/editor-help/test/index.native.js +1 -1
- package/src/components/editor-help/view-sections.native.js +23 -8
- package/src/components/post-featured-image/index.js +102 -69
- package/src/components/post-saved-state/style.scss +9 -0
- package/src/components/post-schedule/index.js +6 -13
- package/src/components/post-slug/test/index.js +4 -4
- package/src/components/post-taxonomies/flat-term-selector.js +5 -2
- package/src/components/post-taxonomies/index.js +3 -1
- package/src/components/post-text-editor/index.js +13 -1
- package/src/components/post-visibility/index.js +130 -150
- package/src/components/post-visibility/label.js +6 -15
- package/src/components/post-visibility/style.scss +25 -20
- package/src/components/post-visibility/utils.js +7 -12
- package/src/components/provider/index.native.js +2 -1
- package/src/components/provider/use-block-editor-settings.js +28 -12
- package/src/components/table-of-contents/style.scss +1 -3
- package/src/store/selectors.js +4 -2
- package/src/store/test/selectors.js +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-taxonomies/flat-term-selector.js"],"names":["escape","escapeString","find","get","uniqBy","__","_x","sprintf","useEffect","useMemo","useState","FormTokenField","withFilters","useSelect","useDispatch","store","coreStore","useDebounce","apiFetch","addQueryArgs","speak","editorStore","unescapeString","unescapeTerm","unescapeTerms","MostUsedTerms","EMPTY_ARRAY","MAX_TERMS_SUGGESTIONS","DEFAULT_QUERY","per_page","orderby","order","_fields","context","isSameTermName","termA","termB","toLowerCase","termNamesToIds","names","terms","map","termName","term","name","id","findOrCreateTerm","restBase","escapedTermName","path","method","data","catch","error","errorCode","code","addRequest","search","then","searchResult","result","Promise","reject","FlatTermSelector","slug","values","setValues","setSearch","debouncedSearch","termIds","taxonomy","hasAssignAction","hasCreateAction","hasResolvedTerms","select","getCurrentPost","getEditedPostAttribute","getEntityRecords","getTaxonomy","hasFinishedResolution","post","_taxonomy","_termIds","rest_base","query","include","join","length","searchResults","newValues","suggestions","editPost","onUpdateTerms","newTermIds","onChange","termNames","availableTerms","uniqueTerms","newTermNames","filter","all","newTerms","newAvailableTerms","concat","appendTerm","newTerm","includes","termAddedMessage","newTermLabel","singularName","termAddedLabel","termRemovedLabel","removeTermLabel","added","removed","remove"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,MAAM,IAAIC,YAAnB,EAAiCC,IAAjC,EAAuCC,GAAvC,EAA4CC,MAA5C,QAA0D,QAA1D;AAEA;AACA;AACA;;AACA,SAASC,EAAT,EAAaC,EAAb,EAAiBC,OAAjB,QAAgC,iBAAhC;AACA,SAASC,SAAT,EAAoBC,OAApB,EAA6BC,QAA7B,QAA6C,oBAA7C;AACA,SAASC,cAAT,EAAyBC,WAAzB,QAA4C,uBAA5C;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASC,WAAT,QAA4B,oBAA5B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SAASC,KAAT,QAAsB,iBAAtB;AAEA;AACA;AACA;;AACA,SAASL,KAAK,IAAIM,WAAlB,QAAqC,aAArC;AACA,SAASC,cAAT,EAAyBC,YAAzB,EAAuCC,aAAvC,QAA4D,mBAA5D;AACA,OAAOC,aAAP,MAA0B,mBAA1B;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,WAAW,GAAG,EAApB;AAEA;AACA;AACA;;AACA,MAAMC,qBAAqB,GAAG,EAA9B;AACA,MAAMC,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CA,EAAE,CAAE,cAAF,CAHvB,CAAxB;AAKA,QAAMwG,YAAY,GAAG1G,GAAG,CACvBmE,QADuB,EAEvB,CAAE,QAAF,EAAY,eAAZ,CAFuB,EAGvBN,IAAI,KAAK,UAAT,GAAsB3D,EAAE,CAAE,KAAF,CAAxB,GAAoCA,EAAE,CAAE,MAAF,CAHf,CAAxB;AAKA,QAAMyG,cAAc,GAAGvG,OAAO;AAC7B;AACAD,EAAAA,EAAE,CAAE,UAAF,EAAc,MAAd,CAF2B,EAG7BuG,YAH6B,CAA9B;AAKA,QAAME,gBAAgB,GAAGxG,OAAO;AAC/B;AACAD,EAAAA,EAAE,CAAE,YAAF,EAAgB,MAAhB,CAF6B,EAG/BuG,YAH+B,CAAhC;AAKA,QAAMG,eAAe,GAAGzG,OAAO;AAC9B;AACAD,EAAAA,EAAE,CAAE,WAAF,EAAe,MAAf,CAF4B,EAG9BuG,YAH8B,CAA/B;AAMA,SACC,8BACC,cAAC,cAAD;AACC,IAAA,KAAK,EAAG5C,MADT;AAEC,IAAA,WAAW,EAAGyB,WAFf;AAGC,IAAA,QAAQ,EAAGI,QAHZ;AAIC,IAAA,aAAa,EAAG1B,eAJjB;AAKC,IAAA,cAAc,EAAGzC,qBALlB;AAMC,IAAA,KAAK,EAAGiF,YANT;AAOC,IAAA,QAAQ,EAAG;AACVK,MAAAA,KAAK,EAAEH,cADG;AAEVI,MAAAA,OAAO,EAAEH,gBAFC;AAGVI,MAAAA,MAAM,EAAEH;AAHE;AAPZ,IADD,EAcC,cAAC,aAAD;AAAe,IAAA,QAAQ,EAAG1C,QAA1B;AAAqC,IAAA,QAAQ,EAAGkC;AAAhD,IAdD,CADD;AAkBA;;AAED,eAAe5F,WAAW,CAAE,yBAAF,CAAX,CAA0CmD,gBAA1C,CAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { escape as escapeString, find, get, uniqBy } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { useEffect, useMemo, useState } from '@wordpress/element';\nimport { FormTokenField, withFilters } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDebounce } from '@wordpress/compose';\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport { unescapeString, unescapeTerm, unescapeTerms } from '../../utils/terms';\nimport MostUsedTerms from './most-used-terms';\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation.\n *\n * @type {Array<any>}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Module constants\n */\nconst MAX_TERMS_SUGGESTIONS = 20;\nconst DEFAULT_QUERY = {\n\tper_page: MAX_TERMS_SUGGESTIONS,\n\torderby: 'count',\n\torder: 'desc',\n\t_fields: 'id,name',\n\tcontext: 'view',\n};\n\nconst isSameTermName = ( termA, termB ) =>\n\tunescapeString( termA ).toLowerCase() ===\n\tunescapeString( termB ).toLowerCase();\n\nconst termNamesToIds = ( names, terms ) => {\n\treturn names.map(\n\t\t( termName ) =>\n\t\t\tfind( terms, ( term ) => isSameTermName( term.name, termName ) ).id\n\t);\n};\n\n// Tries to create a term or fetch it if it already exists.\nfunction findOrCreateTerm( termName, restBase ) {\n\tconst escapedTermName = escapeString( termName );\n\n\treturn apiFetch( {\n\t\tpath: `/wp/v2/${ restBase }`,\n\t\tmethod: 'POST',\n\t\tdata: { name: escapedTermName },\n\t} )\n\t\t.catch( ( error ) => {\n\t\t\tconst errorCode = error.code;\n\t\t\tif ( errorCode === 'term_exists' ) {\n\t\t\t\t// If the terms exist, fetch it instead of creating a new one.\n\t\t\t\tconst addRequest = apiFetch( {\n\t\t\t\t\tpath: addQueryArgs( `/wp/v2/${ restBase }`, {\n\t\t\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\t\t\tsearch: escapedTermName,\n\t\t\t\t\t} ),\n\t\t\t\t} ).then( unescapeTerms );\n\n\t\t\t\treturn addRequest.then( ( searchResult ) => {\n\t\t\t\t\treturn find( searchResult, ( result ) =>\n\t\t\t\t\t\tisSameTermName( result.name, termName )\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\treturn Promise.reject( error );\n\t\t} )\n\t\t.then( unescapeTerm );\n}\n\nfunction FlatTermSelector( { slug } ) {\n\tconst [ values, setValues ] = useState( [] );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst debouncedSearch = useDebounce( setSearch, 500 );\n\n\tconst {\n\t\tterms,\n\t\ttermIds,\n\t\ttaxonomy,\n\t\thasAssignAction,\n\t\thasCreateAction,\n\t\thasResolvedTerms,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCurrentPost, getEditedPostAttribute } = select(\n\t\t\t\teditorStore\n\t\t\t);\n\t\t\tconst {\n\t\t\t\tgetEntityRecords,\n\t\t\t\tgetTaxonomy,\n\t\t\t\thasFinishedResolution,\n\t\t\t} = select( coreStore );\n\t\t\tconst post = getCurrentPost();\n\t\t\tconst _taxonomy = getTaxonomy( slug );\n\t\t\tconst _termIds = _taxonomy\n\t\t\t\t? getEditedPostAttribute( _taxonomy.rest_base )\n\t\t\t\t: EMPTY_ARRAY;\n\n\t\t\tconst query = {\n\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\tinclude: _termIds.join( ',' ),\n\t\t\t\tper_page: -1,\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\thasCreateAction: _taxonomy\n\t\t\t\t\t? get(\n\t\t\t\t\t\t\tpost,\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t'_links',\n\t\t\t\t\t\t\t\t'wp:action-create-' + _taxonomy.rest_base,\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tfalse\n\t\t\t\t\t )\n\t\t\t\t\t: false,\n\t\t\t\thasAssignAction: _taxonomy\n\t\t\t\t\t? get(\n\t\t\t\t\t\t\tpost,\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t'_links',\n\t\t\t\t\t\t\t\t'wp:action-assign-' + _taxonomy.rest_base,\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tfalse\n\t\t\t\t\t )\n\t\t\t\t\t: false,\n\t\t\t\ttaxonomy: _taxonomy,\n\t\t\t\ttermIds: _termIds,\n\t\t\t\tterms: _termIds.length\n\t\t\t\t\t? getEntityRecords( 'taxonomy', slug, query )\n\t\t\t\t\t: EMPTY_ARRAY,\n\t\t\t\thasResolvedTerms: hasFinishedResolution( 'getEntityRecords', [\n\t\t\t\t\t'taxonomy',\n\t\t\t\t\tslug,\n\t\t\t\t\tquery,\n\t\t\t\t] ),\n\t\t\t};\n\t\t},\n\t\t[ slug ]\n\t);\n\n\tconst { searchResults } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\n\t\t\treturn {\n\t\t\t\tsearchResults: !! search\n\t\t\t\t\t? getEntityRecords( 'taxonomy', slug, {\n\t\t\t\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\t\t\t\tsearch,\n\t\t\t\t\t } )\n\t\t\t\t\t: EMPTY_ARRAY,\n\t\t\t};\n\t\t},\n\t\t[ search ]\n\t);\n\n\t// Update terms state only after the selectors are resolved.\n\t// We're using this to avoid terms temporarily disappearing on slow networks\n\t// while core data makes REST API requests.\n\tuseEffect( () => {\n\t\tif ( hasResolvedTerms ) {\n\t\t\tconst newValues = terms.map( ( term ) =>\n\t\t\t\tunescapeString( term.name )\n\t\t\t);\n\n\t\t\tsetValues( newValues );\n\t\t}\n\t}, [ terms, hasResolvedTerms ] );\n\n\tconst suggestions = useMemo( () => {\n\t\treturn ( searchResults ?? [] ).map( ( term ) =>\n\t\t\tunescapeString( term.name )\n\t\t);\n\t}, [ searchResults ] );\n\n\tconst { editPost } = useDispatch( editorStore );\n\n\tif ( ! hasAssignAction ) {\n\t\treturn null;\n\t}\n\n\tfunction onUpdateTerms( newTermIds ) {\n\t\teditPost( { [ taxonomy.rest_base ]: newTermIds } );\n\t}\n\n\tfunction onChange( termNames ) {\n\t\tconst availableTerms = [ ...terms, ...( searchResults ?? [] ) ];\n\t\tconst uniqueTerms = uniqBy( termNames, ( term ) => term.toLowerCase() );\n\t\tconst newTermNames = uniqueTerms.filter(\n\t\t\t( termName ) =>\n\t\t\t\t! find( availableTerms, ( term ) =>\n\t\t\t\t\tisSameTermName( term.name, termName )\n\t\t\t\t)\n\t\t);\n\n\t\t// Optimistically update term values.\n\t\t// The selector will always re-fetch terms later.\n\t\tsetValues( uniqueTerms );\n\n\t\tif ( newTermNames.length === 0 ) {\n\t\t\treturn onUpdateTerms(\n\t\t\t\ttermNamesToIds( uniqueTerms, availableTerms )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! hasCreateAction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tPromise.all(\n\t\t\tnewTermNames.map( ( termName ) =>\n\t\t\t\tfindOrCreateTerm( termName, taxonomy.rest_base )\n\t\t\t)\n\t\t).then( ( newTerms ) => {\n\t\t\tconst newAvailableTerms = availableTerms.concat( newTerms );\n\t\t\treturn onUpdateTerms(\n\t\t\t\ttermNamesToIds( uniqueTerms, newAvailableTerms )\n\t\t\t);\n\t\t} );\n\t}\n\n\tfunction appendTerm( newTerm ) {\n\t\tif ( termIds.includes( newTerm.id ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newTermIds = [ ...termIds, newTerm.id ];\n\t\tconst termAddedMessage = sprintf(\n\t\t\t/* translators: %s: term name. */\n\t\t\t_x( '%s added', 'term' ),\n\t\t\tget(\n\t\t\t\ttaxonomy,\n\t\t\t\t[ 'labels', 'singular_name' ],\n\t\t\t\tslug === 'post_tag' ? __( 'Tag' ) : __( 'Term' )\n\t\t\t)\n\t\t);\n\n\t\tspeak( termAddedMessage, 'assertive' );\n\t\tonUpdateTerms( newTermIds );\n\t}\n\n\tconst newTermLabel = get(\n\t\ttaxonomy,\n\t\t[ 'labels', 'add_new_item' ],\n\t\tslug === 'post_tag' ? __( 'Add new tag' ) : __( 'Add new Term' )\n\t);\n\tconst singularName = get(\n\t\ttaxonomy,\n\t\t[ 'labels', 'singular_name' ],\n\t\tslug === 'post_tag' ? __( 'Tag' ) : __( 'Term' )\n\t);\n\tconst termAddedLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( '%s added', 'term' ),\n\t\tsingularName\n\t);\n\tconst termRemovedLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( '%s removed', 'term' ),\n\t\tsingularName\n\t);\n\tconst removeTermLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( 'Remove %s', 'term' ),\n\t\tsingularName\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<FormTokenField\n\t\t\t\tvalue={ values }\n\t\t\t\tsuggestions={ suggestions }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tonInputChange={ debouncedSearch }\n\t\t\t\tmaxSuggestions={ MAX_TERMS_SUGGESTIONS }\n\t\t\t\tlabel={ newTermLabel }\n\t\t\t\tmessages={ {\n\t\t\t\t\tadded: termAddedLabel,\n\t\t\t\t\tremoved: termRemovedLabel,\n\t\t\t\t\tremove: removeTermLabel,\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t<MostUsedTerms taxonomy={ taxonomy } onSelect={ appendTerm } />\n\t\t</>\n\t);\n}\n\nexport default withFilters( 'editor.PostTaxonomyType' )( FlatTermSelector );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/post-taxonomies/flat-term-selector.js"],"names":["escape","escapeString","find","get","uniqBy","__","_x","sprintf","useEffect","useMemo","useState","FormTokenField","withFilters","useSelect","useDispatch","store","coreStore","useDebounce","apiFetch","addQueryArgs","speak","editorStore","unescapeString","unescapeTerm","unescapeTerms","MostUsedTerms","EMPTY_ARRAY","MAX_TERMS_SUGGESTIONS","DEFAULT_QUERY","per_page","orderby","order","_fields","context","isSameTermName","termA","termB","toLowerCase","termNamesToIds","names","terms","map","termName","term","name","id","findOrCreateTerm","restBase","escapedTermName","path","method","data","catch","error","errorCode","code","addRequest","search","then","searchResult","result","Promise","reject","FlatTermSelector","slug","values","setValues","setSearch","debouncedSearch","termIds","taxonomy","hasAssignAction","hasCreateAction","hasResolvedTerms","select","getCurrentPost","getEditedPostAttribute","getEntityRecords","getTaxonomy","hasFinishedResolution","post","_taxonomy","_termIds","rest_base","query","include","join","length","searchResults","newValues","suggestions","editPost","onUpdateTerms","newTermIds","onChange","termNames","availableTerms","uniqueTerms","newTermNames","filter","all","newTerms","newAvailableTerms","concat","appendTerm","newTerm","includes","termAddedMessage","newTermLabel","singularName","termAddedLabel","termRemovedLabel","removeTermLabel","added","removed","remove"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,MAAM,IAAIC,YAAnB,EAAiCC,IAAjC,EAAuCC,GAAvC,EAA4CC,MAA5C,QAA0D,QAA1D;AAEA;AACA;AACA;;AACA,SAASC,EAAT,EAAaC,EAAb,EAAiBC,OAAjB,QAAgC,iBAAhC;AACA,SAASC,SAAT,EAAoBC,OAApB,EAA6BC,QAA7B,QAA6C,oBAA7C;AACA,SAASC,cAAT,EAAyBC,WAAzB,QAA4C,uBAA5C;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASC,WAAT,QAA4B,oBAA5B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SAASC,KAAT,QAAsB,iBAAtB;AAEA;AACA;AACA;;AACA,SAASL,KAAK,IAAIM,WAAlB,QAAqC,aAArC;AACA,SAASC,cAAT,EAAyBC,YAAzB,EAAuCC,aAAvC,QAA4D,mBAA5D;AACA,OAAOC,aAAP,MAA0B,mBAA1B;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,WAAW,GAAG,EAApB;AAEA;AACA;AACA;;AACA,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BAA1C,CAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { escape as escapeString, find, get, uniqBy } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { useEffect, useMemo, useState } from '@wordpress/element';\nimport { FormTokenField, withFilters } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDebounce } from '@wordpress/compose';\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport { unescapeString, unescapeTerm, unescapeTerms } from '../../utils/terms';\nimport MostUsedTerms from './most-used-terms';\n\n/**\n * Shared reference to an empty array for cases where it is important to avoid\n * returning a new array reference on every invocation.\n *\n * @type {Array<any>}\n */\nconst EMPTY_ARRAY = [];\n\n/**\n * Module constants\n */\nconst MAX_TERMS_SUGGESTIONS = 20;\nconst DEFAULT_QUERY = {\n\tper_page: MAX_TERMS_SUGGESTIONS,\n\torderby: 'count',\n\torder: 'desc',\n\t_fields: 'id,name',\n\tcontext: 'view',\n};\n\nconst isSameTermName = ( termA, termB ) =>\n\tunescapeString( termA ).toLowerCase() ===\n\tunescapeString( termB ).toLowerCase();\n\nconst termNamesToIds = ( names, terms ) => {\n\treturn names.map(\n\t\t( termName ) =>\n\t\t\tfind( terms, ( term ) => isSameTermName( term.name, termName ) ).id\n\t);\n};\n\n// Tries to create a term or fetch it if it already exists.\nfunction findOrCreateTerm( termName, restBase ) {\n\tconst escapedTermName = escapeString( termName );\n\n\treturn apiFetch( {\n\t\tpath: `/wp/v2/${ restBase }`,\n\t\tmethod: 'POST',\n\t\tdata: { name: escapedTermName },\n\t} )\n\t\t.catch( ( error ) => {\n\t\t\tconst errorCode = error.code;\n\t\t\tif ( errorCode === 'term_exists' ) {\n\t\t\t\t// If the terms exist, fetch it instead of creating a new one.\n\t\t\t\tconst addRequest = apiFetch( {\n\t\t\t\t\tpath: addQueryArgs( `/wp/v2/${ restBase }`, {\n\t\t\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\t\t\tsearch: escapedTermName,\n\t\t\t\t\t} ),\n\t\t\t\t} ).then( unescapeTerms );\n\n\t\t\t\treturn addRequest.then( ( searchResult ) => {\n\t\t\t\t\treturn find( searchResult, ( result ) =>\n\t\t\t\t\t\tisSameTermName( result.name, termName )\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\treturn Promise.reject( error );\n\t\t} )\n\t\t.then( unescapeTerm );\n}\n\nfunction FlatTermSelector( { slug } ) {\n\tconst [ values, setValues ] = useState( [] );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst debouncedSearch = useDebounce( setSearch, 500 );\n\n\tconst {\n\t\tterms,\n\t\ttermIds,\n\t\ttaxonomy,\n\t\thasAssignAction,\n\t\thasCreateAction,\n\t\thasResolvedTerms,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCurrentPost, getEditedPostAttribute } = select(\n\t\t\t\teditorStore\n\t\t\t);\n\t\t\tconst {\n\t\t\t\tgetEntityRecords,\n\t\t\t\tgetTaxonomy,\n\t\t\t\thasFinishedResolution,\n\t\t\t} = select( coreStore );\n\t\t\tconst post = getCurrentPost();\n\t\t\tconst _taxonomy = getTaxonomy( slug );\n\t\t\tconst _termIds = _taxonomy\n\t\t\t\t? getEditedPostAttribute( _taxonomy.rest_base )\n\t\t\t\t: EMPTY_ARRAY;\n\n\t\t\tconst query = {\n\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\tinclude: _termIds.join( ',' ),\n\t\t\t\tper_page: -1,\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\thasCreateAction: _taxonomy\n\t\t\t\t\t? get(\n\t\t\t\t\t\t\tpost,\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t'_links',\n\t\t\t\t\t\t\t\t'wp:action-create-' + _taxonomy.rest_base,\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tfalse\n\t\t\t\t\t )\n\t\t\t\t\t: false,\n\t\t\t\thasAssignAction: _taxonomy\n\t\t\t\t\t? get(\n\t\t\t\t\t\t\tpost,\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t'_links',\n\t\t\t\t\t\t\t\t'wp:action-assign-' + _taxonomy.rest_base,\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tfalse\n\t\t\t\t\t )\n\t\t\t\t\t: false,\n\t\t\t\ttaxonomy: _taxonomy,\n\t\t\t\ttermIds: _termIds,\n\t\t\t\tterms: _termIds.length\n\t\t\t\t\t? getEntityRecords( 'taxonomy', slug, query )\n\t\t\t\t\t: EMPTY_ARRAY,\n\t\t\t\thasResolvedTerms: hasFinishedResolution( 'getEntityRecords', [\n\t\t\t\t\t'taxonomy',\n\t\t\t\t\tslug,\n\t\t\t\t\tquery,\n\t\t\t\t] ),\n\t\t\t};\n\t\t},\n\t\t[ slug ]\n\t);\n\n\tconst { searchResults } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\n\t\t\treturn {\n\t\t\t\tsearchResults: !! search\n\t\t\t\t\t? getEntityRecords( 'taxonomy', slug, {\n\t\t\t\t\t\t\t...DEFAULT_QUERY,\n\t\t\t\t\t\t\tsearch,\n\t\t\t\t\t } )\n\t\t\t\t\t: EMPTY_ARRAY,\n\t\t\t};\n\t\t},\n\t\t[ search ]\n\t);\n\n\t// Update terms state only after the selectors are resolved.\n\t// We're using this to avoid terms temporarily disappearing on slow networks\n\t// while core data makes REST API requests.\n\tuseEffect( () => {\n\t\tif ( hasResolvedTerms ) {\n\t\t\tconst newValues = ( terms ?? [] ).map( ( term ) =>\n\t\t\t\tunescapeString( term.name )\n\t\t\t);\n\n\t\t\tsetValues( newValues );\n\t\t}\n\t}, [ terms, hasResolvedTerms ] );\n\n\tconst suggestions = useMemo( () => {\n\t\treturn ( searchResults ?? [] ).map( ( term ) =>\n\t\t\tunescapeString( term.name )\n\t\t);\n\t}, [ searchResults ] );\n\n\tconst { editPost } = useDispatch( editorStore );\n\n\tif ( ! hasAssignAction ) {\n\t\treturn null;\n\t}\n\n\tfunction onUpdateTerms( newTermIds ) {\n\t\teditPost( { [ taxonomy.rest_base ]: newTermIds } );\n\t}\n\n\tfunction onChange( termNames ) {\n\t\tconst availableTerms = [\n\t\t\t...( terms ?? [] ),\n\t\t\t...( searchResults ?? [] ),\n\t\t];\n\t\tconst uniqueTerms = uniqBy( termNames, ( term ) => term.toLowerCase() );\n\t\tconst newTermNames = uniqueTerms.filter(\n\t\t\t( termName ) =>\n\t\t\t\t! find( availableTerms, ( term ) =>\n\t\t\t\t\tisSameTermName( term.name, termName )\n\t\t\t\t)\n\t\t);\n\n\t\t// Optimistically update term values.\n\t\t// The selector will always re-fetch terms later.\n\t\tsetValues( uniqueTerms );\n\n\t\tif ( newTermNames.length === 0 ) {\n\t\t\treturn onUpdateTerms(\n\t\t\t\ttermNamesToIds( uniqueTerms, availableTerms )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! hasCreateAction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tPromise.all(\n\t\t\tnewTermNames.map( ( termName ) =>\n\t\t\t\tfindOrCreateTerm( termName, taxonomy.rest_base )\n\t\t\t)\n\t\t).then( ( newTerms ) => {\n\t\t\tconst newAvailableTerms = availableTerms.concat( newTerms );\n\t\t\treturn onUpdateTerms(\n\t\t\t\ttermNamesToIds( uniqueTerms, newAvailableTerms )\n\t\t\t);\n\t\t} );\n\t}\n\n\tfunction appendTerm( newTerm ) {\n\t\tif ( termIds.includes( newTerm.id ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newTermIds = [ ...termIds, newTerm.id ];\n\t\tconst termAddedMessage = sprintf(\n\t\t\t/* translators: %s: term name. */\n\t\t\t_x( '%s added', 'term' ),\n\t\t\tget(\n\t\t\t\ttaxonomy,\n\t\t\t\t[ 'labels', 'singular_name' ],\n\t\t\t\tslug === 'post_tag' ? __( 'Tag' ) : __( 'Term' )\n\t\t\t)\n\t\t);\n\n\t\tspeak( termAddedMessage, 'assertive' );\n\t\tonUpdateTerms( newTermIds );\n\t}\n\n\tconst newTermLabel = get(\n\t\ttaxonomy,\n\t\t[ 'labels', 'add_new_item' ],\n\t\tslug === 'post_tag' ? __( 'Add new tag' ) : __( 'Add new Term' )\n\t);\n\tconst singularName = get(\n\t\ttaxonomy,\n\t\t[ 'labels', 'singular_name' ],\n\t\tslug === 'post_tag' ? __( 'Tag' ) : __( 'Term' )\n\t);\n\tconst termAddedLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( '%s added', 'term' ),\n\t\tsingularName\n\t);\n\tconst termRemovedLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( '%s removed', 'term' ),\n\t\tsingularName\n\t);\n\tconst removeTermLabel = sprintf(\n\t\t/* translators: %s: term name. */\n\t\t_x( 'Remove %s', 'term' ),\n\t\tsingularName\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<FormTokenField\n\t\t\t\tvalue={ values }\n\t\t\t\tsuggestions={ suggestions }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tonInputChange={ debouncedSearch }\n\t\t\t\tmaxSuggestions={ MAX_TERMS_SUGGESTIONS }\n\t\t\t\tlabel={ newTermLabel }\n\t\t\t\tmessages={ {\n\t\t\t\t\tadded: termAddedLabel,\n\t\t\t\t\tremoved: termRemovedLabel,\n\t\t\t\t\tremove: removeTermLabel,\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t<MostUsedTerms taxonomy={ taxonomy } onSelect={ appendTerm } />\n\t\t</>\n\t);\n}\n\nexport default withFilters( 'editor.PostTaxonomyType' )( FlatTermSelector );\n"]}
|
|
@@ -26,7 +26,13 @@ export function PostTaxonomies(_ref) {
|
|
|
26
26
|
taxonomyWrapper = identity
|
|
27
27
|
} = _ref;
|
|
28
28
|
const availableTaxonomies = filter(taxonomies, taxonomy => includes(taxonomy.types, postType));
|
|
29
|
-
const visibleTaxonomies = filter(availableTaxonomies,
|
|
29
|
+
const visibleTaxonomies = filter(availableTaxonomies, // In some circumstances .visibility can end up as undefined so optional chaining operator required.
|
|
30
|
+
// https://github.com/WordPress/gutenberg/issues/40326
|
|
31
|
+
taxonomy => {
|
|
32
|
+
var _taxonomy$visibility;
|
|
33
|
+
|
|
34
|
+
return (_taxonomy$visibility = taxonomy.visibility) === null || _taxonomy$visibility === void 0 ? void 0 : _taxonomy$visibility.show_ui;
|
|
35
|
+
});
|
|
30
36
|
return visibleTaxonomies.map(taxonomy => {
|
|
31
37
|
const TaxonomyComponent = taxonomy.hierarchical ? HierarchicalTermSelector : FlatTermSelector;
|
|
32
38
|
return createElement(Fragment, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-taxonomies/index.js"],"names":["filter","identity","includes","Fragment","withSelect","compose","store","coreStore","HierarchicalTermSelector","FlatTermSelector","editorStore","PostTaxonomies","postType","taxonomies","taxonomyWrapper","availableTaxonomies","taxonomy","types","visibleTaxonomies","visibility","show_ui","map","TaxonomyComponent","hierarchical","slug","select","getCurrentPostType","getTaxonomies","per_page"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,MAAT,EAAiBC,QAAjB,EAA2BC,QAA3B,QAA2C,QAA3C;AAEA;AACA;AACA;;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,UAAT,QAA2B,iBAA3B;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,OAAOC,wBAAP,MAAqC,8BAArC;AACA,OAAOC,gBAAP,MAA6B,sBAA7B;AACA,SAASH,KAAK,IAAII,WAAlB,QAAqC,aAArC;AAEA,OAAO,SAASC,cAAT,OAIH;AAAA,MAJ4B;AAC/BC,IAAAA,QAD+B;AAE/BC,IAAAA,UAF+B;AAG/BC,IAAAA,eAAe,GAAGb;AAHa,GAI5B;AACH,QAAMc,mBAAmB,GAAGf,MAAM,CAAEa,UAAF,EAAgBG,QAAF,IAC/Cd,QAAQ,CAAEc,QAAQ,CAACC,KAAX,EAAkBL,QAAlB,CADyB,CAAlC;AAGA,QAAMM,iBAAiB,GAAGlB,MAAM,CAC/Be,mBAD+B,
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/post-taxonomies/index.js"],"names":["filter","identity","includes","Fragment","withSelect","compose","store","coreStore","HierarchicalTermSelector","FlatTermSelector","editorStore","PostTaxonomies","postType","taxonomies","taxonomyWrapper","availableTaxonomies","taxonomy","types","visibleTaxonomies","visibility","show_ui","map","TaxonomyComponent","hierarchical","slug","select","getCurrentPostType","getTaxonomies","per_page"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,MAAT,EAAiBC,QAAjB,EAA2BC,QAA3B,QAA2C,QAA3C;AAEA;AACA;AACA;;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,UAAT,QAA2B,iBAA3B;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,OAAOC,wBAAP,MAAqC,8BAArC;AACA,OAAOC,gBAAP,MAA6B,sBAA7B;AACA,SAASH,KAAK,IAAII,WAAlB,QAAqC,aAArC;AAEA,OAAO,SAASC,cAAT,OAIH;AAAA,MAJ4B;AAC/BC,IAAAA,QAD+B;AAE/BC,IAAAA,UAF+B;AAG/BC,IAAAA,eAAe,GAAGb;AAHa,GAI5B;AACH,QAAMc,mBAAmB,GAAGf,MAAM,CAAEa,UAAF,EAAgBG,QAAF,IAC/Cd,QAAQ,CAAEc,QAAQ,CAACC,KAAX,EAAkBL,QAAlB,CADyB,CAAlC;AAGA,QAAMM,iBAAiB,GAAGlB,MAAM,CAC/Be,mBAD+B,EAE/B;AACA;AACEC,EAAAA,QAAF;AAAA;;AAAA,mCAAgBA,QAAQ,CAACG,UAAzB,yDAAgB,qBAAqBC,OAArC;AAAA,GAJ+B,CAAhC;AAMA,SAAOF,iBAAiB,CAACG,GAAlB,CAAyBL,QAAF,IAAgB;AAC7C,UAAMM,iBAAiB,GAAGN,QAAQ,CAACO,YAAT,GACvBf,wBADuB,GAEvBC,gBAFH;AAGA,WACC,cAAC,QAAD;AAAU,MAAA,GAAG,EAAI,YAAYO,QAAQ,CAACQ,IAAM;AAA5C,OACGV,eAAe,CAChB,cAAC,iBAAD;AAAmB,MAAA,IAAI,EAAGE,QAAQ,CAACQ;AAAnC,MADgB,EAEhBR,QAFgB,CADlB,CADD;AAQA,GAZM,CAAP;AAaA;AAED,eAAeX,OAAO,CAAE,CACvBD,UAAU,CAAIqB,MAAF,IAAc;AACzB,SAAO;AACNb,IAAAA,QAAQ,EAAEa,MAAM,CAAEf,WAAF,CAAN,CAAsBgB,kBAAtB,EADJ;AAENb,IAAAA,UAAU,EAAEY,MAAM,CAAElB,SAAF,CAAN,CAAoBoB,aAApB,CAAmC;AAAEC,MAAAA,QAAQ,EAAE,CAAC;AAAb,KAAnC;AAFN,GAAP;AAIA,CALS,CADa,CAAF,CAAP,CAOVjB,cAPU,CAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { filter, identity, includes } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { Fragment } from '@wordpress/element';\nimport { withSelect } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport HierarchicalTermSelector from './hierarchical-term-selector';\nimport FlatTermSelector from './flat-term-selector';\nimport { store as editorStore } from '../../store';\n\nexport function PostTaxonomies( {\n\tpostType,\n\ttaxonomies,\n\ttaxonomyWrapper = identity,\n} ) {\n\tconst availableTaxonomies = filter( taxonomies, ( taxonomy ) =>\n\t\tincludes( taxonomy.types, postType )\n\t);\n\tconst visibleTaxonomies = filter(\n\t\tavailableTaxonomies,\n\t\t// In some circumstances .visibility can end up as undefined so optional chaining operator required.\n\t\t// https://github.com/WordPress/gutenberg/issues/40326\n\t\t( taxonomy ) => taxonomy.visibility?.show_ui\n\t);\n\treturn visibleTaxonomies.map( ( taxonomy ) => {\n\t\tconst TaxonomyComponent = taxonomy.hierarchical\n\t\t\t? HierarchicalTermSelector\n\t\t\t: FlatTermSelector;\n\t\treturn (\n\t\t\t<Fragment key={ `taxonomy-${ taxonomy.slug }` }>\n\t\t\t\t{ taxonomyWrapper(\n\t\t\t\t\t<TaxonomyComponent slug={ taxonomy.slug } />,\n\t\t\t\t\ttaxonomy\n\t\t\t\t) }\n\t\t\t</Fragment>\n\t\t);\n\t} );\n}\n\nexport default compose( [\n\twithSelect( ( select ) => {\n\t\treturn {\n\t\t\tpostType: select( editorStore ).getCurrentPostType(),\n\t\t\ttaxonomies: select( coreStore ).getTaxonomies( { per_page: -1 } ),\n\t\t};\n\t} ),\n] )( PostTaxonomies );\n"]}
|
|
@@ -9,7 +9,7 @@ import Textarea from 'react-autosize-textarea';
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { __ } from '@wordpress/i18n';
|
|
12
|
-
import { useState } from '@wordpress/element';
|
|
12
|
+
import { useEffect, useState, useRef } from '@wordpress/element';
|
|
13
13
|
import { parse } from '@wordpress/blocks';
|
|
14
14
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
15
15
|
import { useInstanceId } from '@wordpress/compose';
|
|
@@ -28,6 +28,7 @@ export default function PostTextEditor() {
|
|
|
28
28
|
const [value, setValue] = useState(postContent);
|
|
29
29
|
const [isDirty, setIsDirty] = useState(false);
|
|
30
30
|
const instanceId = useInstanceId(PostTextEditor);
|
|
31
|
+
const valueRef = useRef();
|
|
31
32
|
|
|
32
33
|
if (!isDirty && value !== postContent) {
|
|
33
34
|
setValue(postContent);
|
|
@@ -52,6 +53,7 @@ export default function PostTextEditor() {
|
|
|
52
53
|
});
|
|
53
54
|
setValue(newValue);
|
|
54
55
|
setIsDirty(true);
|
|
56
|
+
valueRef.current = newValue;
|
|
55
57
|
};
|
|
56
58
|
/**
|
|
57
59
|
* Function called when the user has completed their edits, responsible for
|
|
@@ -66,8 +68,17 @@ export default function PostTextEditor() {
|
|
|
66
68
|
resetEditorBlocks(blocks);
|
|
67
69
|
setIsDirty(false);
|
|
68
70
|
}
|
|
69
|
-
};
|
|
71
|
+
}; // Ensure changes aren't lost when component unmounts.
|
|
72
|
+
|
|
70
73
|
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
return () => {
|
|
76
|
+
if (valueRef.current) {
|
|
77
|
+
const blocks = parse(valueRef.current);
|
|
78
|
+
resetEditorBlocks(blocks);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}, []);
|
|
71
82
|
return createElement(Fragment, null, createElement(VisuallyHidden, {
|
|
72
83
|
as: "label",
|
|
73
84
|
htmlFor: `post-content-${instanceId}`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-text-editor/index.js"],"names":["Textarea","__","useState","parse","useDispatch","useSelect","useInstanceId","VisuallyHidden","store","editorStore","PostTextEditor","postContent","select","getEditedPostContent","editPost","resetEditorBlocks","value","setValue","isDirty","setIsDirty","instanceId","onChange","event","newValue","target","content","stopEditing","blocks"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,yBAArB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/post-text-editor/index.js"],"names":["Textarea","__","useEffect","useState","useRef","parse","useDispatch","useSelect","useInstanceId","VisuallyHidden","store","editorStore","PostTextEditor","postContent","select","getEditedPostContent","editPost","resetEditorBlocks","value","setValue","isDirty","setIsDirty","instanceId","valueRef","onChange","event","newValue","target","content","current","stopEditing","blocks"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,yBAArB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAA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AND;AAQA;AACD;AACA;AACA;AACA;;;AACC,QAAMI,WAAW,GAAG,MAAM;AACzB,QAAKV,OAAL,EAAe;AACd,YAAMW,MAAM,GAAG1B,KAAK,CAAEa,KAAF,CAApB;AACAD,MAAAA,iBAAiB,CAAEc,MAAF,CAAjB;AACAV,MAAAA,UAAU,CAAE,KAAF,CAAV;AACA;AACD,GAND,CAzCwC,CAiDxC;;;AACAnB,EAAAA,SAAS,CAAE,MAAM;AAChB,WAAO,MAAM;AACZ,UAAKqB,QAAQ,CAACM,OAAd,EAAwB;AACvB,cAAME,MAAM,GAAG1B,KAAK,CAAEkB,QAAQ,CAACM,OAAX,CAApB;AACAZ,QAAAA,iBAAiB,CAAEc,MAAF,CAAjB;AACA;AACD,KALD;AAMA,GAPQ,EAON,EAPM,CAAT;AASA,SACC,8BACC,cAAC,cAAD;AACC,IAAA,EAAE,EAAC,OADJ;AAEC,IAAA,OAAO,EAAI,gBAAgBT,UAAY;AAFxC,KAIGrB,EAAE,CAAE,mBAAF,CAJL,CADD,EAOC,cAAC,QAAD;AACC,IAAA,YAAY,EAAC,KADd;AAEC,IAAA,GAAG,EAAC,MAFL;AAGC,IAAA,KAAK,EAAGiB,KAHT;AAIC,IAAA,QAAQ,EAAGM,QAJZ;AAKC,IAAA,MAAM,EAAGM,WALV;AAMC,IAAA,SAAS,EAAC,yBANX;AAOC,IAAA,EAAE,EAAI,gBAAgBR,UAAY,EAPnC;AAQC,IAAA,WAAW,EAAGrB,EAAE,CAAE,iCAAF;AARjB,IAPD,CADD;AAoBA","sourcesContent":["/**\n * External dependencies\n */\nimport Textarea from 'react-autosize-textarea';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useEffect, useState, useRef } from '@wordpress/element';\nimport { parse } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useInstanceId } from '@wordpress/compose';\nimport { VisuallyHidden } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\n\nexport default function PostTextEditor() {\n\tconst postContent = useSelect(\n\t\t( select ) => select( editorStore ).getEditedPostContent(),\n\t\t[]\n\t);\n\n\tconst { editPost, resetEditorBlocks } = useDispatch( editorStore );\n\n\tconst [ value, setValue ] = useState( postContent );\n\tconst [ isDirty, setIsDirty ] = useState( false );\n\tconst instanceId = useInstanceId( PostTextEditor );\n\tconst valueRef = useRef();\n\n\tif ( ! isDirty && value !== postContent ) {\n\t\tsetValue( postContent );\n\t}\n\n\t/**\n\t * Handles a textarea change event to notify the onChange prop callback and\n\t * reflect the new value in the component's own state. This marks the start\n\t * of the user's edits, if not already changed, preventing future props\n\t * changes to value from replacing the rendered value. This is expected to\n\t * be followed by a reset to dirty state via `stopEditing`.\n\t *\n\t * @see stopEditing\n\t *\n\t * @param {Event} event Change event.\n\t */\n\tconst onChange = ( event ) => {\n\t\tconst newValue = event.target.value;\n\t\teditPost( { content: newValue } );\n\t\tsetValue( newValue );\n\t\tsetIsDirty( true );\n\t\tvalueRef.current = newValue;\n\t};\n\n\t/**\n\t * Function called when the user has completed their edits, responsible for\n\t * ensuring that changes, if made, are surfaced to the onPersist prop\n\t * callback and resetting dirty state.\n\t */\n\tconst stopEditing = () => {\n\t\tif ( isDirty ) {\n\t\t\tconst blocks = parse( value );\n\t\t\tresetEditorBlocks( blocks );\n\t\t\tsetIsDirty( false );\n\t\t}\n\t};\n\n\t// Ensure changes aren't lost when component unmounts.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tif ( valueRef.current ) {\n\t\t\t\tconst blocks = parse( valueRef.current );\n\t\t\t\tresetEditorBlocks( blocks );\n\t\t\t}\n\t\t};\n\t}, [] );\n\n\treturn (\n\t\t<>\n\t\t\t<VisuallyHidden\n\t\t\t\tas=\"label\"\n\t\t\t\thtmlFor={ `post-content-${ instanceId }` }\n\t\t\t>\n\t\t\t\t{ __( 'Type text or HTML' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<Textarea\n\t\t\t\tautoComplete=\"off\"\n\t\t\t\tdir=\"auto\"\n\t\t\t\tvalue={ value }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tonBlur={ stopEditing }\n\t\t\t\tclassName=\"editor-post-text-editor\"\n\t\t\t\tid={ `post-content-${ instanceId }` }\n\t\t\t\tplaceholder={ __( 'Start writing with text or HTML' ) }\n\t\t\t/>\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -1,190 +1,156 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createElement } from "@wordpress/element";
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { createElement, Fragment } from "@wordpress/element";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* WordPress dependencies
|
|
6
6
|
*/
|
|
7
7
|
import { __ } from '@wordpress/i18n';
|
|
8
|
-
import {
|
|
9
|
-
import { VisuallyHidden, __experimentalConfirmDialog as ConfirmDialog } from '@wordpress/components';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
8
|
+
import { useState } from '@wordpress/element';
|
|
9
|
+
import { VisuallyHidden, __experimentalConfirmDialog as ConfirmDialog, Button } from '@wordpress/components';
|
|
10
|
+
import { useInstanceId } from '@wordpress/compose';
|
|
11
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
12
|
+
import { close as closeIcon } from '@wordpress/icons';
|
|
12
13
|
/**
|
|
13
14
|
* Internal dependencies
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
17
|
import { visibilityOptions } from './utils';
|
|
17
18
|
import { store as editorStore } from '../../store';
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
export default function PostVisibility(_ref) {
|
|
20
|
+
let {
|
|
21
|
+
onClose
|
|
22
|
+
} = _ref;
|
|
23
|
+
const instanceId = useInstanceId(PostVisibility);
|
|
24
|
+
const {
|
|
25
|
+
status,
|
|
26
|
+
visibility,
|
|
27
|
+
password
|
|
28
|
+
} = useSelect(select => ({
|
|
29
|
+
status: select(editorStore).getEditedPostAttribute('status'),
|
|
30
|
+
visibility: select(editorStore).getEditedPostVisibility(),
|
|
31
|
+
password: select(editorStore).getEditedPostAttribute('password')
|
|
32
|
+
}));
|
|
33
|
+
const {
|
|
34
|
+
editPost,
|
|
35
|
+
savePost
|
|
36
|
+
} = useDispatch(editorStore);
|
|
37
|
+
const [hasPassword, setHasPassword] = useState(!!password);
|
|
38
|
+
const [showPrivateConfirmDialog, setShowPrivateConfirmDialog] = useState(false);
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
const setPublic = () => {
|
|
41
|
+
editPost({
|
|
42
|
+
status: visibility === 'private' ? 'draft' : status,
|
|
43
|
+
password: ''
|
|
39
44
|
});
|
|
45
|
+
setHasPassword(false);
|
|
46
|
+
};
|
|
40
47
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this.updatePassword = this.updatePassword.bind(this);
|
|
45
|
-
this.state = {
|
|
46
|
-
hasPassword: !!props.password,
|
|
47
|
-
showPrivateConfirmDialog: false
|
|
48
|
-
};
|
|
49
|
-
}
|
|
48
|
+
const setPrivate = () => {
|
|
49
|
+
setShowPrivateConfirmDialog(true);
|
|
50
|
+
};
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
status
|
|
56
|
-
} = this.props;
|
|
57
|
-
onUpdateVisibility(visibility === 'private' ? 'draft' : status);
|
|
58
|
-
this.setState({
|
|
59
|
-
hasPassword: false
|
|
52
|
+
const confirmPrivate = () => {
|
|
53
|
+
editPost({
|
|
54
|
+
status: 'private',
|
|
55
|
+
password: ''
|
|
60
56
|
});
|
|
61
|
-
|
|
57
|
+
setHasPassword(false);
|
|
58
|
+
setShowPrivateConfirmDialog(false);
|
|
59
|
+
savePost();
|
|
60
|
+
};
|
|
62
61
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
67
|
-
}
|
|
62
|
+
const handleDialogCancel = () => {
|
|
63
|
+
setShowPrivateConfirmDialog(false);
|
|
64
|
+
};
|
|
68
65
|
|
|
69
|
-
setPasswordProtected() {
|
|
70
|
-
|
|
71
|
-
visibility,
|
|
72
|
-
|
|
73
|
-
status,
|
|
74
|
-
password
|
|
75
|
-
} = this.props;
|
|
76
|
-
onUpdateVisibility(visibility === 'private' ? 'draft' : status, password || '');
|
|
77
|
-
this.setState({
|
|
78
|
-
hasPassword: true
|
|
66
|
+
const setPasswordProtected = () => {
|
|
67
|
+
editPost({
|
|
68
|
+
status: visibility === 'private' ? 'draft' : status,
|
|
69
|
+
password: password || ''
|
|
79
70
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
updatePassword(event) {
|
|
83
|
-
const {
|
|
84
|
-
status,
|
|
85
|
-
onUpdateVisibility
|
|
86
|
-
} = this.props;
|
|
87
|
-
onUpdateVisibility(status, event.target.value);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
render() {
|
|
91
|
-
const {
|
|
92
|
-
visibility,
|
|
93
|
-
password,
|
|
94
|
-
instanceId
|
|
95
|
-
} = this.props;
|
|
96
|
-
const visibilityHandlers = {
|
|
97
|
-
public: {
|
|
98
|
-
onSelect: this.setPublic,
|
|
99
|
-
checked: visibility === 'public' && !this.state.hasPassword
|
|
100
|
-
},
|
|
101
|
-
private: {
|
|
102
|
-
onSelect: this.setPrivate,
|
|
103
|
-
checked: visibility === 'private'
|
|
104
|
-
},
|
|
105
|
-
password: {
|
|
106
|
-
onSelect: this.setPasswordProtected,
|
|
107
|
-
checked: this.state.hasPassword
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
return [createElement("fieldset", {
|
|
111
|
-
key: "visibility-selector",
|
|
112
|
-
className: "editor-post-visibility__dialog-fieldset"
|
|
113
|
-
}, createElement("legend", {
|
|
114
|
-
className: "editor-post-visibility__dialog-legend"
|
|
115
|
-
}, __('Post Visibility')), visibilityOptions.map(_ref => {
|
|
116
|
-
let {
|
|
117
|
-
value,
|
|
118
|
-
label,
|
|
119
|
-
info
|
|
120
|
-
} = _ref;
|
|
121
|
-
return createElement("div", {
|
|
122
|
-
key: value,
|
|
123
|
-
className: "editor-post-visibility__choice"
|
|
124
|
-
}, createElement("input", {
|
|
125
|
-
type: "radio",
|
|
126
|
-
name: `editor-post-visibility__setting-${instanceId}`,
|
|
127
|
-
value: value,
|
|
128
|
-
onChange: visibilityHandlers[value].onSelect,
|
|
129
|
-
checked: visibilityHandlers[value].checked,
|
|
130
|
-
id: `editor-post-${value}-${instanceId}`,
|
|
131
|
-
"aria-describedby": `editor-post-${value}-${instanceId}-description`,
|
|
132
|
-
className: "editor-post-visibility__dialog-radio"
|
|
133
|
-
}), createElement("label", {
|
|
134
|
-
htmlFor: `editor-post-${value}-${instanceId}`,
|
|
135
|
-
className: "editor-post-visibility__dialog-label"
|
|
136
|
-
}, label), createElement("p", {
|
|
137
|
-
id: `editor-post-${value}-${instanceId}-description`,
|
|
138
|
-
className: "editor-post-visibility__dialog-info"
|
|
139
|
-
}, info));
|
|
140
|
-
})), this.state.hasPassword && createElement("div", {
|
|
141
|
-
className: "editor-post-visibility__dialog-password",
|
|
142
|
-
key: "password-selector"
|
|
143
|
-
}, createElement(VisuallyHidden, {
|
|
144
|
-
as: "label",
|
|
145
|
-
htmlFor: `editor-post-visibility__dialog-password-input-${instanceId}`
|
|
146
|
-
}, __('Create password')), createElement("input", {
|
|
147
|
-
className: "editor-post-visibility__dialog-password-input",
|
|
148
|
-
id: `editor-post-visibility__dialog-password-input-${instanceId}`,
|
|
149
|
-
type: "text",
|
|
150
|
-
onChange: this.updatePassword,
|
|
151
|
-
value: password,
|
|
152
|
-
placeholder: __('Use a secure password')
|
|
153
|
-
})), createElement(ConfirmDialog, {
|
|
154
|
-
key: "private-publish-confirmation",
|
|
155
|
-
isOpen: this.state.showPrivateConfirmDialog,
|
|
156
|
-
onConfirm: this.confirmPrivate,
|
|
157
|
-
onCancel: this.handleDialogCancel
|
|
158
|
-
}, __('Would you like to privately publish this post now?'))];
|
|
159
|
-
}
|
|
71
|
+
setHasPassword(true);
|
|
72
|
+
};
|
|
160
73
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
getEditedPostVisibility
|
|
166
|
-
} = select(editorStore);
|
|
167
|
-
return {
|
|
168
|
-
status: getEditedPostAttribute('status'),
|
|
169
|
-
visibility: getEditedPostVisibility(),
|
|
170
|
-
password: getEditedPostAttribute('password')
|
|
74
|
+
const updatePassword = event => {
|
|
75
|
+
editPost({
|
|
76
|
+
password: event.target.value
|
|
77
|
+
});
|
|
171
78
|
};
|
|
172
|
-
}), withDispatch(dispatch => {
|
|
173
|
-
const {
|
|
174
|
-
savePost,
|
|
175
|
-
editPost
|
|
176
|
-
} = dispatch(editorStore);
|
|
177
|
-
return {
|
|
178
|
-
onSave: savePost,
|
|
179
79
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
80
|
+
return createElement(Fragment, null, createElement(Button, {
|
|
81
|
+
className: "editor-post-visibility__close",
|
|
82
|
+
isSmall: true,
|
|
83
|
+
icon: closeIcon,
|
|
84
|
+
onClick: onClose
|
|
85
|
+
}), createElement("fieldset", {
|
|
86
|
+
className: "editor-post-visibility__fieldset"
|
|
87
|
+
}, createElement("legend", {
|
|
88
|
+
className: "editor-post-visibility__legend"
|
|
89
|
+
}, __('Visibility')), createElement("p", {
|
|
90
|
+
className: "editor-post-visibility__description"
|
|
91
|
+
}, __('Control how this post is viewed.')), createElement(PostVisibilityChoice, {
|
|
92
|
+
instanceId: instanceId,
|
|
93
|
+
value: "public",
|
|
94
|
+
label: visibilityOptions.public.label,
|
|
95
|
+
info: visibilityOptions.public.info,
|
|
96
|
+
checked: visibility === 'public' && !hasPassword,
|
|
97
|
+
onChange: setPublic
|
|
98
|
+
}), createElement(PostVisibilityChoice, {
|
|
99
|
+
instanceId: instanceId,
|
|
100
|
+
value: "private",
|
|
101
|
+
label: visibilityOptions.private.label,
|
|
102
|
+
info: visibilityOptions.private.info,
|
|
103
|
+
checked: visibility === 'private',
|
|
104
|
+
onChange: setPrivate
|
|
105
|
+
}), createElement(PostVisibilityChoice, {
|
|
106
|
+
instanceId: instanceId,
|
|
107
|
+
value: "password",
|
|
108
|
+
label: visibilityOptions.password.label,
|
|
109
|
+
info: visibilityOptions.password.info,
|
|
110
|
+
checked: hasPassword,
|
|
111
|
+
onChange: setPasswordProtected
|
|
112
|
+
}), hasPassword && createElement("div", {
|
|
113
|
+
className: "editor-post-visibility__password"
|
|
114
|
+
}, createElement(VisuallyHidden, {
|
|
115
|
+
as: "label",
|
|
116
|
+
htmlFor: `editor-post-visibility__password-input-${instanceId}`
|
|
117
|
+
}, __('Create password')), createElement("input", {
|
|
118
|
+
className: "editor-post-visibility__password-input",
|
|
119
|
+
id: `editor-post-visibility__password-input-${instanceId}`,
|
|
120
|
+
type: "text",
|
|
121
|
+
onChange: updatePassword,
|
|
122
|
+
value: password,
|
|
123
|
+
placeholder: __('Use a secure password')
|
|
124
|
+
}))), createElement(ConfirmDialog, {
|
|
125
|
+
isOpen: showPrivateConfirmDialog,
|
|
126
|
+
onConfirm: confirmPrivate,
|
|
127
|
+
onCancel: handleDialogCancel
|
|
128
|
+
}, __('Would you like to privately publish this post now?')));
|
|
129
|
+
}
|
|
187
130
|
|
|
188
|
-
|
|
189
|
-
|
|
131
|
+
function PostVisibilityChoice(_ref2) {
|
|
132
|
+
let {
|
|
133
|
+
instanceId,
|
|
134
|
+
value,
|
|
135
|
+
label,
|
|
136
|
+
info,
|
|
137
|
+
...props
|
|
138
|
+
} = _ref2;
|
|
139
|
+
return createElement("div", {
|
|
140
|
+
className: "editor-post-visibility__choice"
|
|
141
|
+
}, createElement("input", _extends({
|
|
142
|
+
type: "radio",
|
|
143
|
+
name: `editor-post-visibility__setting-${instanceId}`,
|
|
144
|
+
value: value,
|
|
145
|
+
id: `editor-post-${value}-${instanceId}`,
|
|
146
|
+
"aria-describedby": `editor-post-${value}-${instanceId}-description`,
|
|
147
|
+
className: "editor-post-visibility__radio"
|
|
148
|
+
}, props)), createElement("label", {
|
|
149
|
+
htmlFor: `editor-post-${value}-${instanceId}`,
|
|
150
|
+
className: "editor-post-visibility__label"
|
|
151
|
+
}, label), createElement("p", {
|
|
152
|
+
id: `editor-post-${value}-${instanceId}-description`,
|
|
153
|
+
className: "editor-post-visibility__info"
|
|
154
|
+
}, info));
|
|
155
|
+
}
|
|
190
156
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-visibility/index.js"],"names":["__","Component","VisuallyHidden","__experimentalConfirmDialog","ConfirmDialog","withInstanceId","compose","withSelect","withDispatch","visibilityOptions","store","editorStore","PostVisibility","constructor","props","arguments","onUpdateVisibility","onSave","setState","hasPassword","showPrivateConfirmDialog","setPublic","bind","setPrivate","setPasswordProtected","updatePassword","state","password","visibility","status","event","target","value","render","instanceId","visibilityHandlers","public","onSelect","checked","private","map","label","info","confirmPrivate","handleDialogCancel","select","getEditedPostAttribute","getEditedPostVisibility","dispatch","savePost","editPost"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,SAAT,QAA0B,oBAA1B;AACA,SACCC,cADD,EAECC,2BAA2B,IAAIC,aAFhC,QAGO,uBAHP;AAIA,SAASC,cAAT,EAAyBC,OAAzB,QAAwC,oBAAxC;AACA,SAASC,UAAT,EAAqBC,YAArB,QAAyC,iBAAzC;AAEA;AACA;AACA;;AACA,SAASC,iBAAT,QAAkC,SAAlC;AACA,SAASC,KAAK,IAAIC,W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encies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Component } from '@wordpress/element';\nimport {\n\tVisuallyHidden,\n\t__experimentalConfirmDialog as ConfirmDialog,\n} from '@wordpress/components';\nimport { withInstanceId, compose } from '@wordpress/compose';\nimport { withSelect, withDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { visibilityOptions } from './utils';\nimport { store as editorStore } from '../../store';\n\nexport class PostVisibility extends Component {\n\tconstructor( props ) {\n\t\tsuper( ...arguments );\n\n\t\tthis.setPublic = this.setPublic.bind( this );\n\t\tthis.setPrivate = this.setPrivate.bind( this );\n\t\tthis.setPasswordProtected = this.setPasswordProtected.bind( this );\n\t\tthis.updatePassword = this.updatePassword.bind( this );\n\n\t\tthis.state = {\n\t\t\thasPassword: !! props.password,\n\t\t\tshowPrivateConfirmDialog: false,\n\t\t};\n\t}\n\n\tsetPublic() {\n\t\tconst { visibility, onUpdateVisibility, status } = this.props;\n\n\t\tonUpdateVisibility( visibility === 'private' ? 'draft' : status );\n\t\tthis.setState( { hasPassword: false } );\n\t}\n\n\tsetPrivate() {\n\t\tthis.setState( { showPrivateConfirmDialog: true } );\n\t}\n\n\tconfirmPrivate = () => {\n\t\tconst { onUpdateVisibility, onSave } = this.props;\n\n\t\tonUpdateVisibility( 'private' );\n\t\tthis.setState( {\n\t\t\thasPassword: false,\n\t\t\tshowPrivateConfirmDialog: false,\n\t\t} );\n\t\tonSave();\n\t};\n\n\thandleDialogCancel = () => {\n\t\tthis.setState( { showPrivateConfirmDialog: false } );\n\t};\n\n\tsetPasswordProtected() {\n\t\tconst { visibility, onUpdateVisibility, status, password } = this.props;\n\n\t\tonUpdateVisibility(\n\t\t\tvisibility === 'private' ? 'draft' : status,\n\t\t\tpassword || ''\n\t\t);\n\t\tthis.setState( { hasPassword: true } );\n\t}\n\n\tupdatePassword( event ) {\n\t\tconst { status, onUpdateVisibility } = this.props;\n\t\tonUpdateVisibility( status, event.target.value );\n\t}\n\n\trender() {\n\t\tconst { visibility, password, instanceId } = this.props;\n\n\t\tconst visibilityHandlers = {\n\t\t\tpublic: {\n\t\t\t\tonSelect: this.setPublic,\n\t\t\t\tchecked: visibility === 'public' && ! this.state.hasPassword,\n\t\t\t},\n\t\t\tprivate: {\n\t\t\t\tonSelect: this.setPrivate,\n\t\t\t\tchecked: visibility === 'private',\n\t\t\t},\n\t\t\tpassword: {\n\t\t\t\tonSelect: this.setPasswordProtected,\n\t\t\t\tchecked: this.state.hasPassword,\n\t\t\t},\n\t\t};\n\n\t\treturn [\n\t\t\t<fieldset\n\t\t\t\tkey=\"visibility-selector\"\n\t\t\t\tclassName=\"editor-post-visibility__dialog-fieldset\"\n\t\t\t>\n\t\t\t\t<legend className=\"editor-post-visibility__dialog-legend\">\n\t\t\t\t\t{ __( 'Post Visibility' ) }\n\t\t\t\t</legend>\n\t\t\t\t{ visibilityOptions.map( ( { value, label, info } ) => (\n\t\t\t\t\t<div\n\t\t\t\t\t\tkey={ value }\n\t\t\t\t\t\tclassName=\"editor-post-visibility__choice\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\ttype=\"radio\"\n\t\t\t\t\t\t\tname={ `editor-post-visibility__setting-${ instanceId }` }\n\t\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\t\tonChange={ visibilityHandlers[ value ].onSelect }\n\t\t\t\t\t\t\tchecked={ visibilityHandlers[ value ].checked }\n\t\t\t\t\t\t\tid={ `editor-post-${ value }-${ instanceId }` }\n\t\t\t\t\t\t\taria-describedby={ `editor-post-${ value }-${ instanceId }-description` }\n\t\t\t\t\t\t\tclassName=\"editor-post-visibility__dialog-radio\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<label\n\t\t\t\t\t\t\thtmlFor={ `editor-post-${ value }-${ instanceId }` }\n\t\t\t\t\t\t\tclassName=\"editor-post-visibility__dialog-label\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ label }\n\t\t\t\t\t\t</label>\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t<p\n\t\t\t\t\t\t\t\tid={ `editor-post-${ value }-${ instanceId }-description` }\n\t\t\t\t\t\t\t\tclassName=\"editor-post-visibility__dialog-info\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ info }\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t}\n\t\t\t\t\t</div>\n\t\t\t\t) ) }\n\t\t\t</fieldset>,\n\t\t\tthis.state.hasPassword && (\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"editor-post-visibility__dialog-password\"\n\t\t\t\t\tkey=\"password-selector\"\n\t\t\t\t>\n\t\t\t\t\t<VisuallyHidden\n\t\t\t\t\t\tas=\"label\"\n\t\t\t\t\t\thtmlFor={ `editor-post-visibility__dialog-password-input-${ instanceId }` }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Create password' ) }\n\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t<input\n\t\t\t\t\t\tclassName=\"editor-post-visibility__dialog-password-input\"\n\t\t\t\t\t\tid={ `editor-post-visibility__dialog-password-input-${ instanceId }` }\n\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\tonChange={ this.updatePassword }\n\t\t\t\t\t\tvalue={ password }\n\t\t\t\t\t\tplaceholder={ __( 'Use a secure password' ) }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t),\n\t\t\t<ConfirmDialog\n\t\t\t\tkey=\"private-publish-confirmation\"\n\t\t\t\tisOpen={ this.state.showPrivateConfirmDialog }\n\t\t\t\tonConfirm={ this.confirmPrivate }\n\t\t\t\tonCancel={ this.handleDialogCancel }\n\t\t\t>\n\t\t\t\t{ __( 'Would you like to privately publish this post now?' ) }\n\t\t\t</ConfirmDialog>,\n\t\t];\n\t}\n}\n\nexport default compose( [\n\twithSelect( ( select ) => {\n\t\tconst { getEditedPostAttribute, getEditedPostVisibility } = select(\n\t\t\teditorStore\n\t\t);\n\t\treturn {\n\t\t\tstatus: getEditedPostAttribute( 'status' ),\n\t\t\tvisibility: getEditedPostVisibility(),\n\t\t\tpassword: getEditedPostAttribute( 'password' ),\n\t\t};\n\t} ),\n\twithDispatch( ( dispatch ) => {\n\t\tconst { savePost, editPost } = dispatch( editorStore );\n\t\treturn {\n\t\t\tonSave: savePost,\n\t\t\tonUpdateVisibility( status, password = '' ) {\n\t\t\t\teditPost( { status, password } );\n\t\t\t},\n\t\t};\n\t} ),\n\twithInstanceId,\n] )( PostVisibility );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/post-visibility/index.js"],"names":["__","useState","VisuallyHidden","__experimentalConfirmDialog","ConfirmDialog","Button","useInstanceId","useSelect","useDispatch","close","closeIcon","visibilityOptions","store","editorStore","PostVisibility","onClose","instanceId","status","visibility","password","select","getEditedPostAttribute","getEditedPostVisibility","editPost","savePost","hasPassword","setHasPassword","showPrivateConfirmDialog","setShowPrivateConfirmDialog","setPublic","setPrivate","confirmPrivate","handleDialogCancel","setPasswordProtected","updatePassword","event","target","value","public","label","info","private","PostVisibilityChoice","props"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SACCC,cADD,EAECC,2BAA2B,IAAIC,aAFhC,EAGCC,MAHD,QAIO,uBAJP;AAKA,SAASC,aAAT,QAA8B,oBAA9B;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,kBAAnC;AAEA;AACA;AACA;;AACA,SAASC,iBAAT,QAAkC,SAAlC;AACA,SAASC,KAAK,IAAIC,WAAlB,QAAqC,aAArC;AAEA,eAAe,SAASC,cAAT,OAAuC;AAAA,MAAd;AAAEC,IAAAA;AAAF,GAAc;AACrD,QAAMC,UAAU,GAAGV,aAAa,CAAEQ,cAAF,CAAhC;AAEA,QAAM;AAAEG,IAAAA,MAAF;AAAUC,IAAAA,UAAV;AAAsBC,IAAAA;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C,IAAA,IAAI,EAAI,mCAAmC3B,UAAY,EAFxD;AAGC,IAAA,KAAK,EAAGqB,KAHT;AAIC,IAAA,EAAE,EAAI,eAAeA,KAAO,IAAIrB,UAAY,EAJ7C;AAKC,wBAAoB,eAAeqB,KAAO,IAAIrB,UAAY,cAL3D;AAMC,IAAA,SAAS,EAAC;AANX,KAOM2B,KAPN,EADD,EAUC;AACC,IAAA,OAAO,EAAI,eAAeN,KAAO,IAAIrB,UAAY,EADlD;AAEC,IAAA,SAAS,EAAC;AAFX,KAIGuB,KAJH,CAVD,EAgBC;AACC,IAAA,EAAE,EAAI,eAAeF,KAAO,IAAIrB,UAAY,cAD7C;AAEC,IAAA,SAAS,EAAC;AAFX,KAIGwB,IAJH,CAhBD,CADD;AAyBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport {\n\tVisuallyHidden,\n\t__experimentalConfirmDialog as ConfirmDialog,\n\tButton,\n} from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { close as closeIcon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { visibilityOptions } from './utils';\nimport { store as editorStore } from '../../store';\n\nexport default function PostVisibility( { onClose } ) {\n\tconst instanceId = useInstanceId( PostVisibility );\n\n\tconst { status, visibility, password } = useSelect( ( select ) => ( {\n\t\tstatus: select( editorStore ).getEditedPostAttribute( 'status' ),\n\t\tvisibility: select( editorStore ).getEditedPostVisibility(),\n\t\tpassword: select( editorStore ).getEditedPostAttribute( 'password' ),\n\t} ) );\n\n\tconst { editPost, savePost } = useDispatch( editorStore );\n\n\tconst [ hasPassword, setHasPassword ] = useState( !! password );\n\tconst [ showPrivateConfirmDialog, setShowPrivateConfirmDialog ] = useState(\n\t\tfalse\n\t);\n\n\tconst setPublic = () => {\n\t\teditPost( {\n\t\t\tstatus: visibility === 'private' ? 'draft' : status,\n\t\t\tpassword: '',\n\t\t} );\n\t\tsetHasPassword( false );\n\t};\n\n\tconst setPrivate = () => {\n\t\tsetShowPrivateConfirmDialog( true );\n\t};\n\n\tconst confirmPrivate = () => {\n\t\teditPost( { status: 'private', password: '' } );\n\t\tsetHasPassword( false );\n\t\tsetShowPrivateConfirmDialog( false );\n\t\tsavePost();\n\t};\n\n\tconst handleDialogCancel = () => {\n\t\tsetShowPrivateConfirmDialog( false );\n\t};\n\n\tconst setPasswordProtected = () => {\n\t\teditPost( {\n\t\t\tstatus: visibility === 'private' ? 'draft' : status,\n\t\t\tpassword: password || '',\n\t\t} );\n\t\tsetHasPassword( true );\n\t};\n\n\tconst updatePassword = ( event ) => {\n\t\teditPost( { password: event.target.value } );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tclassName=\"editor-post-visibility__close\"\n\t\t\t\tisSmall\n\t\t\t\ticon={ closeIcon }\n\t\t\t\tonClick={ onClose }\n\t\t\t/>\n\t\t\t<fieldset className=\"editor-post-visibility__fieldset\">\n\t\t\t\t<legend className=\"editor-post-visibility__legend\">\n\t\t\t\t\t{ __( 'Visibility' ) }\n\t\t\t\t</legend>\n\t\t\t\t<p className=\"editor-post-visibility__description\">\n\t\t\t\t\t{ __( 'Control how this post is viewed.' ) }\n\t\t\t\t</p>\n\t\t\t\t<PostVisibilityChoice\n\t\t\t\t\tinstanceId={ instanceId }\n\t\t\t\t\tvalue=\"public\"\n\t\t\t\t\tlabel={ visibilityOptions.public.label }\n\t\t\t\t\tinfo={ visibilityOptions.public.info }\n\t\t\t\t\tchecked={ visibility === 'public' && ! hasPassword }\n\t\t\t\t\tonChange={ setPublic }\n\t\t\t\t/>\n\t\t\t\t<PostVisibilityChoice\n\t\t\t\t\tinstanceId={ instanceId }\n\t\t\t\t\tvalue=\"private\"\n\t\t\t\t\tlabel={ visibilityOptions.private.label }\n\t\t\t\t\tinfo={ visibilityOptions.private.info }\n\t\t\t\t\tchecked={ visibility === 'private' }\n\t\t\t\t\tonChange={ setPrivate }\n\t\t\t\t/>\n\t\t\t\t<PostVisibilityChoice\n\t\t\t\t\tinstanceId={ instanceId }\n\t\t\t\t\tvalue=\"password\"\n\t\t\t\t\tlabel={ visibilityOptions.password.label }\n\t\t\t\t\tinfo={ visibilityOptions.password.info }\n\t\t\t\t\tchecked={ hasPassword }\n\t\t\t\t\tonChange={ setPasswordProtected }\n\t\t\t\t/>\n\t\t\t\t{ hasPassword && (\n\t\t\t\t\t<div className=\"editor-post-visibility__password\">\n\t\t\t\t\t\t<VisuallyHidden\n\t\t\t\t\t\t\tas=\"label\"\n\t\t\t\t\t\t\thtmlFor={ `editor-post-visibility__password-input-${ instanceId }` }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Create password' ) }\n\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t<input\n\t\t\t\t\t\t\tclassName=\"editor-post-visibility__password-input\"\n\t\t\t\t\t\t\tid={ `editor-post-visibility__password-input-${ instanceId }` }\n\t\t\t\t\t\t\ttype=\"text\"\n\t\t\t\t\t\t\tonChange={ updatePassword }\n\t\t\t\t\t\t\tvalue={ password }\n\t\t\t\t\t\t\tplaceholder={ __( 'Use a secure password' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</fieldset>\n\t\t\t<ConfirmDialog\n\t\t\t\tisOpen={ showPrivateConfirmDialog }\n\t\t\t\tonConfirm={ confirmPrivate }\n\t\t\t\tonCancel={ handleDialogCancel }\n\t\t\t>\n\t\t\t\t{ __( 'Would you like to privately publish this post now?' ) }\n\t\t\t</ConfirmDialog>\n\t\t</>\n\t);\n}\n\nfunction PostVisibilityChoice( { instanceId, value, label, info, ...props } ) {\n\treturn (\n\t\t<div className=\"editor-post-visibility__choice\">\n\t\t\t<input\n\t\t\t\ttype=\"radio\"\n\t\t\t\tname={ `editor-post-visibility__setting-${ instanceId }` }\n\t\t\t\tvalue={ value }\n\t\t\t\tid={ `editor-post-${ value }-${ instanceId }` }\n\t\t\t\taria-describedby={ `editor-post-${ value }-${ instanceId }-description` }\n\t\t\t\tclassName=\"editor-post-visibility__radio\"\n\t\t\t\t{ ...props }\n\t\t\t/>\n\t\t\t<label\n\t\t\t\thtmlFor={ `editor-post-${ value }-${ instanceId }` }\n\t\t\t\tclassName=\"editor-post-visibility__label\"\n\t\t\t>\n\t\t\t\t{ label }\n\t\t\t</label>\n\t\t\t<p\n\t\t\t\tid={ `editor-post-${ value }-${ instanceId }-description` }\n\t\t\t\tclassName=\"editor-post-visibility__info\"\n\t\t\t>\n\t\t\t\t{ info }\n\t\t\t</p>\n\t\t</div>\n\t);\n}\n"]}
|
|
@@ -1,32 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { find } from 'lodash';
|
|
5
1
|
/**
|
|
6
2
|
* WordPress dependencies
|
|
7
3
|
*/
|
|
8
|
-
|
|
9
|
-
import { withSelect } from '@wordpress/data';
|
|
4
|
+
import { useSelect } from '@wordpress/data';
|
|
10
5
|
/**
|
|
11
6
|
* Internal dependencies
|
|
12
7
|
*/
|
|
13
8
|
|
|
14
9
|
import { visibilityOptions } from './utils';
|
|
15
10
|
import { store as editorStore } from '../../store';
|
|
11
|
+
export default function PostVisibilityLabel() {
|
|
12
|
+
var _visibilityOptions$vi;
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
visibility
|
|
20
|
-
} = _ref;
|
|
21
|
-
|
|
22
|
-
const getVisibilityLabel = () => find(visibilityOptions, {
|
|
23
|
-
value: visibility
|
|
24
|
-
}).label;
|
|
25
|
-
|
|
26
|
-
return getVisibilityLabel(visibility);
|
|
14
|
+
const visibility = useSelect(select => select(editorStore).getEditedPostVisibility());
|
|
15
|
+
return (_visibilityOptions$vi = visibilityOptions[visibility]) === null || _visibilityOptions$vi === void 0 ? void 0 : _visibilityOptions$vi.label;
|
|
27
16
|
}
|
|
28
|
-
|
|
29
|
-
export default withSelect(select => ({
|
|
30
|
-
visibility: select(editorStore).getEditedPostVisibility()
|
|
31
|
-
}))(PostVisibilityLabel);
|
|
32
17
|
//# sourceMappingURL=label.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/editor/src/components/post-visibility/label.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/editor/src/components/post-visibility/label.js"],"names":["useSelect","visibilityOptions","store","editorStore","PostVisibilityLabel","visibility","select","getEditedPostVisibility","label"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,SAASC,iBAAT,QAAkC,SAAlC;AACA,SAASC,KAAK,IAAIC,WAAlB,QAAqC,aAArC;AAEA,eAAe,SAASC,mBAAT,GAA+B;AAAA;;AAC7C,QAAMC,UAAU,GAAGL,SAAS,CAAIM,MAAF,IAC7BA,MAAM,CAAEH,WAAF,CAAN,CAAsBI,uBAAtB,EAD2B,CAA5B;AAGA,kCAAON,iBAAiB,CAAEI,UAAF,CAAxB,0DAAO,sBAAiCG,KAAxC;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { visibilityOptions } from './utils';\nimport { store as editorStore } from '../../store';\n\nexport default function PostVisibilityLabel() {\n\tconst visibility = useSelect( ( select ) =>\n\t\tselect( editorStore ).getEditedPostVisibility()\n\t);\n\treturn visibilityOptions[ visibility ]?.label;\n}\n"]}
|