@wordpress/block-editor 9.5.0 → 9.6.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 +2 -0
- package/build/components/block-lock/modal.js +2 -2
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build/components/block-mover/mover-description.js +95 -32
- package/build/components/block-mover/mover-description.js.map +1 -1
- package/build/components/block-settings-menu-controls/index.js +1 -1
- package/build/components/block-settings-menu-controls/index.js.map +1 -1
- package/build/components/block-styles/preview.native.js +1 -3
- package/build/components/block-styles/preview.native.js.map +1 -1
- package/build/components/block-tools/block-selection-button.js +1 -7
- package/build/components/block-tools/block-selection-button.js.map +1 -1
- package/build/components/block-tools/index.js +4 -1
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-types-list/index.native.js +65 -23
- package/build/components/block-types-list/index.native.js.map +1 -1
- package/build/components/colors-gradients/control.js +1 -0
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/colors-gradients/dropdown.js +5 -2
- package/build/components/colors-gradients/dropdown.js.map +1 -1
- package/build/components/image-editor/cropper.js +4 -3
- package/build/components/image-editor/cropper.js.map +1 -1
- package/build/components/image-editor/index.js +3 -1
- package/build/components/image-editor/index.js.map +1 -1
- package/build/components/inserter/block-types-tab.native.js +30 -16
- package/build/components/inserter/block-types-tab.native.js.map +1 -1
- package/build/components/inserter/preview-panel.js +8 -8
- package/build/components/inserter/preview-panel.js.map +1 -1
- package/build/components/inserter/reusable-blocks-tab.native.js +5 -1
- package/build/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build/components/inserter/search-results.native.js +5 -2
- package/build/components/inserter/search-results.native.js.map +1 -1
- package/build/components/inserter/utils.native.js +21 -0
- package/build/components/inserter/utils.native.js.map +1 -1
- package/build/components/inserter-list-item/index.js +5 -1
- package/build/components/inserter-list-item/index.js.map +1 -1
- package/build/components/list-view/branch.js +1 -7
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/observe-typing/index.js +22 -8
- package/build/components/observe-typing/index.js.map +1 -1
- package/build/components/rich-text/format-toolbar-container.js +61 -12
- package/build/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build/components/rich-text/index.js +2 -1
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/use-format-types.js +36 -16
- package/build/components/rich-text/use-format-types.js.map +1 -1
- package/build/components/writing-flow/use-tab-nav.js +1 -1
- package/build/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build/hooks/layout.js +14 -2
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/style.js +41 -31
- package/build/hooks/style.js.map +1 -1
- package/build/layouts/flow.js +26 -3
- package/build/layouts/flow.js.map +1 -1
- package/build-module/components/block-lock/modal.js +2 -2
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js +2 -2
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build-module/components/block-mover/mover-description.js +97 -33
- package/build-module/components/block-mover/mover-description.js.map +1 -1
- package/build-module/components/block-settings-menu-controls/index.js +2 -2
- package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
- package/build-module/components/block-styles/preview.native.js +2 -3
- package/build-module/components/block-styles/preview.native.js.map +1 -1
- package/build-module/components/block-tools/block-selection-button.js +1 -7
- package/build-module/components/block-tools/block-selection-button.js.map +1 -1
- package/build-module/components/block-tools/index.js +4 -1
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-types-list/index.native.js +67 -25
- package/build-module/components/block-types-list/index.native.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +1 -0
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/colors-gradients/dropdown.js +6 -3
- package/build-module/components/colors-gradients/dropdown.js.map +1 -1
- package/build-module/components/image-editor/cropper.js +4 -3
- package/build-module/components/image-editor/cropper.js.map +1 -1
- package/build-module/components/image-editor/index.js +3 -1
- package/build-module/components/image-editor/index.js.map +1 -1
- package/build-module/components/inserter/block-types-tab.native.js +31 -15
- package/build-module/components/inserter/block-types-tab.native.js.map +1 -1
- package/build-module/components/inserter/preview-panel.js +9 -9
- package/build-module/components/inserter/preview-panel.js.map +1 -1
- package/build-module/components/inserter/reusable-blocks-tab.native.js +6 -2
- package/build-module/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build-module/components/inserter/search-results.native.js +6 -3
- package/build-module/components/inserter/search-results.native.js.map +1 -1
- package/build-module/components/inserter/utils.native.js +19 -0
- package/build-module/components/inserter/utils.native.js.map +1 -1
- package/build-module/components/inserter-list-item/index.js +4 -1
- package/build-module/components/inserter-list-item/index.js.map +1 -1
- package/build-module/components/list-view/branch.js +1 -6
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/observe-typing/index.js +22 -8
- package/build-module/components/observe-typing/index.js.map +1 -1
- package/build-module/components/rich-text/format-toolbar-container.js +58 -12
- package/build-module/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build-module/components/rich-text/index.js +2 -1
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/use-format-types.js +37 -18
- package/build-module/components/rich-text/use-format-types.js.map +1 -1
- package/build-module/components/writing-flow/use-tab-nav.js +1 -1
- package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build-module/hooks/layout.js +14 -2
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/style.js +44 -35
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/layouts/flow.js +25 -3
- package/build-module/layouts/flow.js.map +1 -1
- package/build-style/style-rtl.css +2 -2
- package/build-style/style.css +2 -2
- package/package.json +28 -28
- package/src/components/block-lock/modal.js +5 -5
- package/src/components/block-mobile-toolbar/block-actions-menu.native.js +3 -3
- package/src/components/block-mover/mover-description.js +131 -48
- package/src/components/block-mover/test/mover-description.js +55 -3
- package/src/components/block-settings-menu-controls/index.js +2 -2
- package/src/components/block-styles/preview.native.js +2 -2
- package/src/components/block-tools/block-selection-button.js +0 -5
- package/src/components/block-tools/index.js +4 -1
- package/src/components/block-types-list/index.native.js +76 -24
- package/src/components/block-types-list/style.native.scss +18 -0
- package/src/components/color-palette/test/__snapshots__/control.js.snap +0 -4
- package/src/components/colors/test/__snapshots__/with-colors.js.snap +1 -1
- package/src/components/colors/test/with-colors.js +1 -1
- package/src/components/colors-gradients/control.js +1 -0
- package/src/components/colors-gradients/dropdown.js +8 -2
- package/src/components/colors-gradients/style.scss +7 -8
- package/src/components/image-editor/cropper.js +9 -3
- package/src/components/image-editor/index.js +2 -0
- package/src/components/inserter/block-types-tab.native.js +42 -21
- package/src/components/inserter/preview-panel.js +6 -14
- package/src/components/inserter/reusable-blocks-tab.native.js +4 -2
- package/src/components/inserter/search-results.native.js +4 -2
- package/src/components/inserter/test/block-types-tab.native.js +2 -0
- package/src/components/inserter/test/utils.native.js +37 -0
- package/src/components/inserter/utils.native.js +11 -0
- package/src/components/inserter-list-item/index.js +4 -1
- package/src/components/list-view/branch.js +1 -6
- package/src/components/observe-typing/index.js +17 -14
- package/src/components/rich-text/format-toolbar-container.js +63 -14
- package/src/components/rich-text/index.js +1 -0
- package/src/components/rich-text/use-format-types.js +38 -17
- package/src/components/writing-flow/use-tab-nav.js +1 -1
- package/src/hooks/layout.js +14 -3
- package/src/hooks/style.js +46 -39
- package/src/layouts/flow.js +23 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/block-types-tab.native.js"],"names":["BlockTypesTab","onSelect","rootClientId","listProps","clipboardBlock","blockTypes","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/block-types-tab.native.js"],"names":["getBlockNamespace","item","name","split","BlockTypesTab","onSelect","rootClientId","listProps","rawBlockTypes","collections","clipboardBlock","filteredBlockTypes","blockTypes","items","trackBlockTypeSelected","handleSelect","collectionSections","result","Object","keys","forEach","namespace","data","filter","length","push","key","metadata","icon","title","sections"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAZA;AACA;AACA;;AAGA;AACA;AACA;AAOA,MAAMA,iBAAiB,GAAKC,IAAF,IAAYA,IAAI,CAACC,IAAL,CAAUC,KAAV,CAAiB,GAAjB,EAAwB,CAAxB,CAAtC;;AAEA,SAASC,aAAT,OAAgE;AAAA,MAAxC;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,YAAZ;AAA0BC,IAAAA;AAA1B,GAAwC;AAC/D,QAAM,CAAEC,aAAF,GAAmBC,WAAnB,IAAmC,iCACxCH,YADwC,EAExCD,QAFwC,CAAzC;AAIA,QAAMK,cAAc,GAAG,gCAAmBJ,YAAnB,CAAvB;AACA,QAAMK,kBAAkB,GAAG,gCAAqBH,aAArB,CAA3B;AACA,QAAMI,UAAU,GAAGF,cAAc,GAC9B,CAAEA,cAAF,EAAkB,GAAGC,kBAArB,CAD8B,GAE9BA,kBAFH;AAGA,QAAM;AAAEE,IAAAA,KAAF;AAASC,IAAAA;AAAT,MACL,sCAAyBF,UAAzB,CADD;;AAGA,QAAMG,YAAY,GAAG,YAAe;AACnCD,IAAAA,sBAAsB,CAAE,YAAF,CAAtB;AACAT,IAAAA,QAAQ,CAAE,YAAF,CAAR;AACA,GAHD;;AAKA,QAAMW,kBAAkB,GAAG,sBAAS,MAAM;AACzC,UAAMC,MAAM,GAAG,EAAf;AACAC,IAAAA,MAAM,CAACC,IAAP,CAAaV,WAAb,EAA2BW,OAA3B,CAAsCC,SAAF,IAAiB;AACpD,YAAMC,IAAI,GAAGT,KAAK,CAACU,MAAN,CACVtB,IAAF,IAAYD,iBAAiB,CAAEC,IAAF,CAAjB,KAA8BoB,SAD9B,CAAb;;AAGA,UAAKC,IAAI,CAACE,MAAL,GAAc,CAAnB,EAAuB;AACtBP,QAAAA,MAAM,CAACQ,IAAP,CACC,kCAAuB;AACtBC,UAAAA,GAAG,EAAG,cAAcL,SAAW,EADT;AAEtBM,UAAAA,QAAQ,EAAE;AACTC,YAAAA,IAAI,EAAEnB,WAAW,CAAEY,SAAF,CAAX,CAAyBO,IADtB;AAETC,YAAAA,KAAK,EAAEpB,WAAW,CAAEY,SAAF,CAAX,CAAyBQ;AAFvB,WAFY;AAMtBhB,UAAAA,KAAK,EAAES;AANe,SAAvB,CADD;AAUA;AACD,KAhBD;AAkBA,WAAOL,MAAP;AACA,GArB0B,EAqBxB,CAAEJ,KAAF,EAASJ,WAAT,CArBwB,CAA3B;AAuBA,QAAMqB,QAAQ,GAAG,CAChB,kCAAuB;AAAEJ,IAAAA,GAAG,EAAE,SAAP;AAAkBb,IAAAA;AAAlB,GAAvB,CADgB,EAEhB,GAAGG,kBAFa,CAAjB;AAKA,SACC,4BAAC,uBAAD;AACC,IAAA,IAAI,EAAC,QADN;AAEC,IAAA,QAAQ,EAAGc,QAFZ;AAGC,IAAA,QAAQ,EAAGf,YAHZ;AAIC,IAAA,SAAS,EAAGR;AAJb,IADD;AAQA;;eAEcH,a","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport BlockTypesList from '../block-types-list';\nimport useClipboardBlock from './hooks/use-clipboard-block';\nimport useBlockTypeImpressions from './hooks/use-block-type-impressions';\nimport { createInserterSection, filterInserterItems } from './utils';\nimport useBlockTypesState from './hooks/use-block-types-state';\n\nconst getBlockNamespace = ( item ) => item.name.split( '/' )[ 0 ];\n\nfunction BlockTypesTab( { onSelect, rootClientId, listProps } ) {\n\tconst [ rawBlockTypes, , collections ] = useBlockTypesState(\n\t\trootClientId,\n\t\tonSelect\n\t);\n\tconst clipboardBlock = useClipboardBlock( rootClientId );\n\tconst filteredBlockTypes = filterInserterItems( rawBlockTypes );\n\tconst blockTypes = clipboardBlock\n\t\t? [ clipboardBlock, ...filteredBlockTypes ]\n\t\t: filteredBlockTypes;\n\tconst { items, trackBlockTypeSelected } =\n\t\tuseBlockTypeImpressions( blockTypes );\n\n\tconst handleSelect = ( ...args ) => {\n\t\ttrackBlockTypeSelected( ...args );\n\t\tonSelect( ...args );\n\t};\n\n\tconst collectionSections = useMemo( () => {\n\t\tconst result = [];\n\t\tObject.keys( collections ).forEach( ( namespace ) => {\n\t\t\tconst data = items.filter(\n\t\t\t\t( item ) => getBlockNamespace( item ) === namespace\n\t\t\t);\n\t\t\tif ( data.length > 0 ) {\n\t\t\t\tresult.push(\n\t\t\t\t\tcreateInserterSection( {\n\t\t\t\t\t\tkey: `collection-${ namespace }`,\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\ticon: collections[ namespace ].icon,\n\t\t\t\t\t\t\ttitle: collections[ namespace ].title,\n\t\t\t\t\t\t},\n\t\t\t\t\t\titems: data,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t}\n\t\t} );\n\n\t\treturn result;\n\t}, [ items, collections ] );\n\n\tconst sections = [\n\t\tcreateInserterSection( { key: 'default', items } ),\n\t\t...collectionSections,\n\t];\n\n\treturn (\n\t\t<BlockTypesList\n\t\t\tname=\"Blocks\"\n\t\t\tsections={ sections }\n\t\t\tonSelect={ handleSelect }\n\t\t\tlistProps={ listProps }\n\t\t/>\n\t);\n}\n\nexport default BlockTypesTab;\n"]}
|
|
@@ -25,7 +25,7 @@ var _blockPreview = _interopRequireDefault(require("../block-preview"));
|
|
|
25
25
|
* Internal dependencies
|
|
26
26
|
*/
|
|
27
27
|
function InserterPreviewPanel(_ref) {
|
|
28
|
-
var
|
|
28
|
+
var _example$viewportWidt;
|
|
29
29
|
|
|
30
30
|
let {
|
|
31
31
|
item
|
|
@@ -35,24 +35,24 @@ function InserterPreviewPanel(_ref) {
|
|
|
35
35
|
title,
|
|
36
36
|
icon,
|
|
37
37
|
description,
|
|
38
|
-
initialAttributes
|
|
38
|
+
initialAttributes,
|
|
39
|
+
example
|
|
39
40
|
} = item;
|
|
40
|
-
const hoveredItemBlockType = (0, _blocks.getBlockType)(name);
|
|
41
41
|
const isReusable = (0, _blocks.isReusableBlock)(item);
|
|
42
42
|
return (0, _element.createElement)("div", {
|
|
43
43
|
className: "block-editor-inserter__preview-container"
|
|
44
44
|
}, (0, _element.createElement)("div", {
|
|
45
45
|
className: "block-editor-inserter__preview"
|
|
46
|
-
}, isReusable ||
|
|
46
|
+
}, isReusable || example ? (0, _element.createElement)("div", {
|
|
47
47
|
className: "block-editor-inserter__preview-content"
|
|
48
48
|
}, (0, _element.createElement)(_blockPreview.default, {
|
|
49
49
|
__experimentalPadding: 16,
|
|
50
|
-
viewportWidth: (
|
|
51
|
-
blocks:
|
|
52
|
-
attributes: { ...
|
|
50
|
+
viewportWidth: (_example$viewportWidt = example === null || example === void 0 ? void 0 : example.viewportWidth) !== null && _example$viewportWidt !== void 0 ? _example$viewportWidt : 500,
|
|
51
|
+
blocks: example ? (0, _blocks.getBlockFromExample)(item.name, {
|
|
52
|
+
attributes: { ...example.attributes,
|
|
53
53
|
...initialAttributes
|
|
54
54
|
},
|
|
55
|
-
innerBlocks:
|
|
55
|
+
innerBlocks: example.innerBlocks
|
|
56
56
|
}) : (0, _blocks.createBlock)(name, initialAttributes)
|
|
57
57
|
})) : (0, _element.createElement)("div", {
|
|
58
58
|
className: "block-editor-inserter__preview-content-missing"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/preview-panel.js"],"names":["InserterPreviewPanel","item","name","title","icon","description","initialAttributes","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/preview-panel.js"],"names":["InserterPreviewPanel","item","name","title","icon","description","initialAttributes","example","isReusable","viewportWidth","attributes","innerBlocks"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AAKA;;AACA;;AAdA;AACA;AACA;;AAQA;AACA;AACA;AAIA,SAASA,oBAAT,OAA0C;AAAA;;AAAA,MAAX;AAAEC,IAAAA;AAAF,GAAW;AACzC,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,KAAR;AAAeC,IAAAA,IAAf;AAAqBC,IAAAA,WAArB;AAAkCC,IAAAA,iBAAlC;AAAqDC,IAAAA;AAArD,MAAiEN,IAAvE;AACA,QAAMO,UAAU,GAAG,6BAAiBP,IAAjB,CAAnB;AACA,SACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACGO,UAAU,IAAID,OAAd,GACD;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,4BAAC,qBAAD;AACC,IAAA,qBAAqB,EAAG,EADzB;AAEC,IAAA,aAAa,2BAAGA,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEE,aAAZ,yEAA6B,GAF3C;AAGC,IAAA,MAAM,EACLF,OAAO,GACJ,iCAAqBN,IAAI,CAACC,IAA1B,EAAgC;AAChCQ,MAAAA,UAAU,EAAE,EACX,GAAGH,OAAO,CAACG,UADA;AAEX,WAAGJ;AAFQ,OADoB;AAKhCK,MAAAA,WAAW,EAAEJ,OAAO,CAACI;AALW,KAAhC,CADI,GAQJ,yBAAaT,IAAb,EAAmBI,iBAAnB;AAZL,IADD,CADC,GAmBD;AAAK,IAAA,SAAS,EAAC;AAAf,KACG,cAAI,uBAAJ,CADH,CApBF,CADD,EA0BG,CAAEE,UAAF,IACD,4BAAC,kBAAD;AACC,IAAA,KAAK,EAAGL,KADT;AAEC,IAAA,IAAI,EAAGC,IAFR;AAGC,IAAA,WAAW,EAAGC;AAHf,IA3BF,CADD;AAoCA;;eAEcL,oB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tisReusableBlock,\n\tcreateBlock,\n\tgetBlockFromExample,\n} from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport BlockCard from '../block-card';\nimport BlockPreview from '../block-preview';\n\nfunction InserterPreviewPanel( { item } ) {\n\tconst { name, title, icon, description, initialAttributes, example } = item;\n\tconst isReusable = isReusableBlock( item );\n\treturn (\n\t\t<div className=\"block-editor-inserter__preview-container\">\n\t\t\t<div className=\"block-editor-inserter__preview\">\n\t\t\t\t{ isReusable || example ? (\n\t\t\t\t\t<div className=\"block-editor-inserter__preview-content\">\n\t\t\t\t\t\t<BlockPreview\n\t\t\t\t\t\t\t__experimentalPadding={ 16 }\n\t\t\t\t\t\t\tviewportWidth={ example?.viewportWidth ?? 500 }\n\t\t\t\t\t\t\tblocks={\n\t\t\t\t\t\t\t\texample\n\t\t\t\t\t\t\t\t\t? getBlockFromExample( item.name, {\n\t\t\t\t\t\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\t\t\t\t\t\t...example.attributes,\n\t\t\t\t\t\t\t\t\t\t\t\t...initialAttributes,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\tinnerBlocks: example.innerBlocks,\n\t\t\t\t\t\t\t\t\t } )\n\t\t\t\t\t\t\t\t\t: createBlock( name, initialAttributes )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t) : (\n\t\t\t\t\t<div className=\"block-editor-inserter__preview-content-missing\">\n\t\t\t\t\t\t{ __( 'No Preview Available.' ) }\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t{ ! isReusable && (\n\t\t\t\t<BlockCard\n\t\t\t\t\ttitle={ title }\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tdescription={ description }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nexport default InserterPreviewPanel;\n"]}
|
|
@@ -43,9 +43,13 @@ function ReusableBlocksTab(_ref) {
|
|
|
43
43
|
})
|
|
44
44
|
};
|
|
45
45
|
}, [rootClientId]);
|
|
46
|
+
const sections = [(0, _utils.createInserterSection)({
|
|
47
|
+
key: 'reuseable',
|
|
48
|
+
items
|
|
49
|
+
})];
|
|
46
50
|
return (0, _element.createElement)(_blockTypesList.default, {
|
|
47
51
|
name: "ReusableBlocks",
|
|
48
|
-
|
|
52
|
+
sections: sections,
|
|
49
53
|
onSelect: onSelect,
|
|
50
54
|
listProps: listProps
|
|
51
55
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/reusable-blocks-tab.native.js"],"names":["ReusableBlocksTab","onSelect","rootClientId","listProps","items","select","getInserterItems","blockEditorStore","allItems","onlyReusable"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AAVA;AACA;AACA;;AAGA;AACA;AACA;AAKA,SAASA,iBAAT,OAAoE;AAAA,MAAxC;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,YAAZ;AAA0BC,IAAAA;AAA1B,GAAwC;AACnE,QAAM;AAAEC,IAAAA;AAAF,MAAY,qBACfC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA;AAAF,QAAuBD,MAAM,CAAEE,YAAF,CAAnC;AACA,UAAMC,QAAQ,GAAGF,gBAAgB,CAAEJ,YAAF,CAAjC;AAEA,WAAO;AACNE,MAAAA,KAAK,EAAE,gCAAqBI,QAArB,EAA+B;AAAEC,QAAAA,YAAY,EAAE;AAAhB,OAA/B;AADD,KAAP;AAGA,GARgB,EASjB,CAAEP,YAAF,CATiB,CAAlB;AAYA,SACC,4BAAC,uBAAD;AACC,IAAA,IAAI,EAAC,gBADN;AAEC,IAAA,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/reusable-blocks-tab.native.js"],"names":["ReusableBlocksTab","onSelect","rootClientId","listProps","items","select","getInserterItems","blockEditorStore","allItems","onlyReusable","sections","key"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AAVA;AACA;AACA;;AAGA;AACA;AACA;AAKA,SAASA,iBAAT,OAAoE;AAAA,MAAxC;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,YAAZ;AAA0BC,IAAAA;AAA1B,GAAwC;AACnE,QAAM;AAAEC,IAAAA;AAAF,MAAY,qBACfC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA;AAAF,QAAuBD,MAAM,CAAEE,YAAF,CAAnC;AACA,UAAMC,QAAQ,GAAGF,gBAAgB,CAAEJ,YAAF,CAAjC;AAEA,WAAO;AACNE,MAAAA,KAAK,EAAE,gCAAqBI,QAArB,EAA+B;AAAEC,QAAAA,YAAY,EAAE;AAAhB,OAA/B;AADD,KAAP;AAGA,GARgB,EASjB,CAAEP,YAAF,CATiB,CAAlB;AAYA,QAAMQ,QAAQ,GAAG,CAAE,kCAAuB;AAAEC,IAAAA,GAAG,EAAE,WAAP;AAAoBP,IAAAA;AAApB,GAAvB,CAAF,CAAjB;AAEA,SACC,4BAAC,uBAAD;AACC,IAAA,IAAI,EAAC,gBADN;AAEC,IAAA,QAAQ,EAAGM,QAFZ;AAGC,IAAA,QAAQ,EAAGT,QAHZ;AAIC,IAAA,SAAS,EAAGE;AAJb,IADD;AAQA;;eAEcH,iB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport BlockTypesList from '../block-types-list';\nimport { store as blockEditorStore } from '../../store';\nimport { createInserterSection, filterInserterItems } from './utils';\n\nfunction ReusableBlocksTab( { onSelect, rootClientId, listProps } ) {\n\tconst { items } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getInserterItems } = select( blockEditorStore );\n\t\t\tconst allItems = getInserterItems( rootClientId );\n\n\t\t\treturn {\n\t\t\t\titems: filterInserterItems( allItems, { onlyReusable: true } ),\n\t\t\t};\n\t\t},\n\t\t[ rootClientId ]\n\t);\n\n\tconst sections = [ createInserterSection( { key: 'reuseable', items } ) ];\n\n\treturn (\n\t\t<BlockTypesList\n\t\t\tname=\"ReusableBlocks\"\n\t\t\tsections={ sections }\n\t\t\tonSelect={ onSelect }\n\t\t\tlistProps={ listProps }\n\t\t/>\n\t);\n}\n\nexport default ReusableBlocksTab;\n"]}
|
|
@@ -67,9 +67,12 @@ function InserterSearchResults(_ref) {
|
|
|
67
67
|
return (0, _element.createElement)(_blockTypesList.default, {
|
|
68
68
|
name: "Blocks",
|
|
69
69
|
initialNumToRender: isFullScreen ? 10 : 3,
|
|
70
|
-
|
|
70
|
+
sections: [(0, _utils.createInserterSection)({
|
|
71
|
+
key: 'search',
|
|
72
|
+
items
|
|
73
|
+
})],
|
|
71
74
|
onSelect: handleSelect,
|
|
72
|
-
listProps
|
|
75
|
+
listProps: listProps
|
|
73
76
|
});
|
|
74
77
|
}
|
|
75
78
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/search-results.native.js"],"names":["InserterSearchResults","filterValue","onSelect","listProps","rootClientId","isFullScreen","blockTypes","select","allItems","blockEditorStore","getInserterItems","availableItems","allowReusable","filteredItems","items","trackBlockTypeSelected","length","handleSelect"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAbA;AACA;AACA;;AAGA;AACA;AACA;AAQA,SAASA,qBAAT,OAMI;AAAA,MAN4B;AAC/BC,IAAAA,WAD+B;AAE/BC,IAAAA,QAF+B;AAG/BC,IAAAA,SAH+B;AAI/BC,IAAAA,YAJ+B;AAK/BC,IAAAA;AAL+B,GAM5B;AACH,QAAM;AAAEC,IAAAA;AAAF,MAAiB,qBACpBC,MAAF,IAAc;AACb,UAAMC,QAAQ,GACbD,MAAM,CAAEE,YAAF,CAAN,CAA2BC,gBAA3B,CAA6CN,YAA7C,CADD;AAGA,UAAMO,cAAc,GAAG,gCAAqBH,QAArB,EAA+B;AACrDI,MAAAA,aAAa,EAAE;AADsC,KAA/B,CAAvB;AAGA,UAAMC,aAAa,GAAG,8BAAaF,cAAb,EAA6BV,WAA7B,CAAtB;AAEA,WAAO;AAAEK,MAAAA,UAAU,EAAEO;AAAd,KAAP;AACA,GAXqB,EAYtB,CAAET,YAAF,EAAgBH,WAAhB,CAZsB,CAAvB;AAeA,QAAM;AAAEa,IAAAA,KAAF;AAASC,IAAAA;AAAT,MACL,sCAAyBT,UAAzB,CADD;;AAGA,MAAK,CAAEQ,KAAF,IAAW,CAAAA,KAAK,SAAL,IAAAA,KAAK,WAAL,YAAAA,KAAK,CAAEE,MAAP,MAAkB,CAAlC,EAAsC;AACrC,WAAO,4BAAC,kBAAD,OAAP;AACA;;AAED,QAAMC,YAAY,GAAG,YAAe;AACnCF,IAAAA,sBAAsB,CAAE,YAAF,CAAtB;AACAb,IAAAA,QAAQ,CAAE,YAAF,CAAR;AACA,GAHD;;AAKA,SACC,4BAAC,uBAAD;AACC,IAAA,IAAI,EAAC,QADN;AAEC,IAAA,kBAAkB,EAAGG,YAAY,GAAG,EAAH,GAAQ,CAF1C;
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/search-results.native.js"],"names":["InserterSearchResults","filterValue","onSelect","listProps","rootClientId","isFullScreen","blockTypes","select","allItems","blockEditorStore","getInserterItems","availableItems","allowReusable","filteredItems","items","trackBlockTypeSelected","length","handleSelect","key"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAbA;AACA;AACA;;AAGA;AACA;AACA;AAQA,SAASA,qBAAT,OAMI;AAAA,MAN4B;AAC/BC,IAAAA,WAD+B;AAE/BC,IAAAA,QAF+B;AAG/BC,IAAAA,SAH+B;AAI/BC,IAAAA,YAJ+B;AAK/BC,IAAAA;AAL+B,GAM5B;AACH,QAAM;AAAEC,IAAAA;AAAF,MAAiB,qBACpBC,MAAF,IAAc;AACb,UAAMC,QAAQ,GACbD,MAAM,CAAEE,YAAF,CAAN,CAA2BC,gBAA3B,CAA6CN,YAA7C,CADD;AAGA,UAAMO,cAAc,GAAG,gCAAqBH,QAArB,EAA+B;AACrDI,MAAAA,aAAa,EAAE;AADsC,KAA/B,CAAvB;AAGA,UAAMC,aAAa,GAAG,8BAAaF,cAAb,EAA6BV,WAA7B,CAAtB;AAEA,WAAO;AAAEK,MAAAA,UAAU,EAAEO;AAAd,KAAP;AACA,GAXqB,EAYtB,CAAET,YAAF,EAAgBH,WAAhB,CAZsB,CAAvB;AAeA,QAAM;AAAEa,IAAAA,KAAF;AAASC,IAAAA;AAAT,MACL,sCAAyBT,UAAzB,CADD;;AAGA,MAAK,CAAEQ,KAAF,IAAW,CAAAA,KAAK,SAAL,IAAAA,KAAK,WAAL,YAAAA,KAAK,CAAEE,MAAP,MAAkB,CAAlC,EAAsC;AACrC,WAAO,4BAAC,kBAAD,OAAP;AACA;;AAED,QAAMC,YAAY,GAAG,YAAe;AACnCF,IAAAA,sBAAsB,CAAE,YAAF,CAAtB;AACAb,IAAAA,QAAQ,CAAE,YAAF,CAAR;AACA,GAHD;;AAKA,SACC,4BAAC,uBAAD;AACC,IAAA,IAAI,EAAC,QADN;AAEC,IAAA,kBAAkB,EAAGG,YAAY,GAAG,EAAH,GAAQ,CAF1C;AAGC,IAAA,QAAQ,EAAG,CAAE,kCAAuB;AAAEa,MAAAA,GAAG,EAAE,QAAP;AAAiBJ,MAAAA;AAAjB,KAAvB,CAAF,CAHZ;AAIC,IAAA,QAAQ,EAAGG,YAJZ;AAKC,IAAA,SAAS,EAAGd;AALb,IADD;AASA;;eAEcH,qB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { searchItems } from './search-items';\nimport BlockTypesList from '../block-types-list';\nimport InserterNoResults from './no-results';\nimport { store as blockEditorStore } from '../../store';\nimport useBlockTypeImpressions from './hooks/use-block-type-impressions';\nimport { createInserterSection, filterInserterItems } from './utils';\n\nfunction InserterSearchResults( {\n\tfilterValue,\n\tonSelect,\n\tlistProps,\n\trootClientId,\n\tisFullScreen,\n} ) {\n\tconst { blockTypes } = useSelect(\n\t\t( select ) => {\n\t\t\tconst allItems =\n\t\t\t\tselect( blockEditorStore ).getInserterItems( rootClientId );\n\n\t\t\tconst availableItems = filterInserterItems( allItems, {\n\t\t\t\tallowReusable: true,\n\t\t\t} );\n\t\t\tconst filteredItems = searchItems( availableItems, filterValue );\n\n\t\t\treturn { blockTypes: filteredItems };\n\t\t},\n\t\t[ rootClientId, filterValue ]\n\t);\n\n\tconst { items, trackBlockTypeSelected } =\n\t\tuseBlockTypeImpressions( blockTypes );\n\n\tif ( ! items || items?.length === 0 ) {\n\t\treturn <InserterNoResults />;\n\t}\n\n\tconst handleSelect = ( ...args ) => {\n\t\ttrackBlockTypeSelected( ...args );\n\t\tonSelect( ...args );\n\t};\n\n\treturn (\n\t\t<BlockTypesList\n\t\t\tname=\"Blocks\"\n\t\t\tinitialNumToRender={ isFullScreen ? 10 : 3 }\n\t\t\tsections={ [ createInserterSection( { key: 'search', items } ) ] }\n\t\t\tonSelect={ handleSelect }\n\t\t\tlistProps={ listProps }\n\t\t/>\n\t);\n}\n\nexport default InserterSearchResults;\n"]}
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.blockAllowed = blockAllowed;
|
|
7
|
+
exports.createInserterSection = createInserterSection;
|
|
7
8
|
exports.filterInserterItems = filterInserterItems;
|
|
8
9
|
const REUSABLE_BLOCKS_CATEGORY = 'reusable';
|
|
9
10
|
const ALLOWED_EMBED_VARIATIONS = ['core/embed', 'core/embed/youtube', 'core/embed/twitter', 'core/embed/wordpress', 'core/embed/instagram', 'core/embed/vimeo'];
|
|
@@ -43,4 +44,24 @@ function filterInserterItems(items) {
|
|
|
43
44
|
allowReusable
|
|
44
45
|
}));
|
|
45
46
|
}
|
|
47
|
+
|
|
48
|
+
function createInserterSection(_ref2) {
|
|
49
|
+
let {
|
|
50
|
+
key,
|
|
51
|
+
metadata = {},
|
|
52
|
+
items
|
|
53
|
+
} = _ref2;
|
|
54
|
+
|
|
55
|
+
if (!key) {
|
|
56
|
+
throw new Error('A unique key for the section must be provided.');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
metadata,
|
|
61
|
+
data: [{
|
|
62
|
+
key,
|
|
63
|
+
list: items
|
|
64
|
+
}]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
46
67
|
//# sourceMappingURL=utils.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/utils.native.js"],"names":["REUSABLE_BLOCKS_CATEGORY","ALLOWED_EMBED_VARIATIONS","blockAllowed","block","onlyReusable","allowReusable","id","category","isReusable","includes","filterInserterItems","items","filter"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter/utils.native.js"],"names":["REUSABLE_BLOCKS_CATEGORY","ALLOWED_EMBED_VARIATIONS","blockAllowed","block","onlyReusable","allowReusable","id","category","isReusable","includes","filterInserterItems","items","filter","createInserterSection","key","metadata","Error","data","list"],"mappings":";;;;;;;;AAAA,MAAMA,wBAAwB,GAAG,UAAjC;AACA,MAAMC,wBAAwB,GAAG,CAChC,YADgC,EAEhC,oBAFgC,EAGhC,oBAHgC,EAIhC,sBAJgC,EAKhC,sBALgC,EAMhC,kBANgC,CAAjC;;AASO,SAASC,YAAT,CAAuBC,KAAvB,QAAgE;AAAA,MAAlC;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,GAAkC;AACtE,QAAM;AAAEC,IAAAA,EAAF;AAAMC,IAAAA;AAAN,MAAmBJ,KAAzB;AACA,QAAMK,UAAU,GAAGD,QAAQ,KAAKP,wBAAhC;;AAEA,MAAKI,YAAL,EAAoB;AACnB,WAAOI,UAAP;AACA;;AAED,MAAKA,UAAL,EAAkB;AACjB,WAAOH,aAAP;AACA,GAVqE,CAWtE;AACA;AACA;;;AACA,SAAOE,QAAQ,KAAK,OAAb,IAAwBN,wBAAwB,CAACQ,QAAzB,CAAmCH,EAAnC,CAA/B;AACA;;AAEM,SAASI,mBAAT,CACNC,KADM,EAGL;AAAA,MADD;AAAEP,IAAAA,YAAY,GAAG,KAAjB;AAAwBC,IAAAA,aAAa,GAAG;AAAxC,GACC,uEADiD,EACjD;AACD,SAAOM,KAAK,CAACC,MAAN,CAAgBT,KAAF,IACpBD,YAAY,CAAEC,KAAF,EAAS;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,GAAT,CADN,CAAP;AAGA;;AAEM,SAASQ,qBAAT,QAAgE;AAAA,MAAhC;AAAEC,IAAAA,GAAF;AAAOC,IAAAA,QAAQ,GAAG,EAAlB;AAAsBJ,IAAAA;AAAtB,GAAgC;;AACtE,MAAK,CAAEG,GAAP,EAAa;AACZ,UAAM,IAAIE,KAAJ,CAAW,gDAAX,CAAN;AACA;;AAED,SAAO;AACND,IAAAA,QADM;AAENE,IAAAA,IAAI,EAAE,CAAE;AAAEH,MAAAA,GAAF;AAAOI,MAAAA,IAAI,EAAEP;AAAb,KAAF;AAFA,GAAP;AAIA","sourcesContent":["const REUSABLE_BLOCKS_CATEGORY = 'reusable';\nconst ALLOWED_EMBED_VARIATIONS = [\n\t'core/embed',\n\t'core/embed/youtube',\n\t'core/embed/twitter',\n\t'core/embed/wordpress',\n\t'core/embed/instagram',\n\t'core/embed/vimeo',\n];\n\nexport function blockAllowed( block, { onlyReusable, allowReusable } ) {\n\tconst { id, category } = block;\n\tconst isReusable = category === REUSABLE_BLOCKS_CATEGORY;\n\n\tif ( onlyReusable ) {\n\t\treturn isReusable;\n\t}\n\n\tif ( isReusable ) {\n\t\treturn allowReusable;\n\t}\n\t// We don't want to show all possible embed variations\n\t// as different blocks in the inserter. We'll only show a\n\t// few popular ones.\n\treturn category !== 'embed' || ALLOWED_EMBED_VARIATIONS.includes( id );\n}\n\nexport function filterInserterItems(\n\titems,\n\t{ onlyReusable = false, allowReusable = false } = {}\n) {\n\treturn items.filter( ( block ) =>\n\t\tblockAllowed( block, { onlyReusable, allowReusable } )\n\t);\n}\n\nexport function createInserterSection( { key, metadata = {}, items } ) {\n\tif ( ! key ) {\n\t\tthrow new Error( 'A unique key for the section must be provided.' );\n\t}\n\n\treturn {\n\t\tmetadata,\n\t\tdata: [ { key, list: items } ],\n\t};\n}\n"]}
|
|
@@ -15,6 +15,8 @@ var _classnames = _interopRequireDefault(require("classnames"));
|
|
|
15
15
|
|
|
16
16
|
var _blocks = require("@wordpress/blocks");
|
|
17
17
|
|
|
18
|
+
var _components = require("@wordpress/components");
|
|
19
|
+
|
|
18
20
|
var _keycodes = require("@wordpress/keycodes");
|
|
19
21
|
|
|
20
22
|
var _blockIcon = _interopRequireDefault(require("../block-icon"));
|
|
@@ -141,7 +143,9 @@ function InserterListItem(_ref) {
|
|
|
141
143
|
showColors: true
|
|
142
144
|
})), (0, _element.createElement)("span", {
|
|
143
145
|
className: "block-editor-block-types-list__item-title"
|
|
144
|
-
},
|
|
146
|
+
}, (0, _element.createElement)(_components.__experimentalTruncate, {
|
|
147
|
+
numberOfLines: 3
|
|
148
|
+
}, item.title))));
|
|
145
149
|
});
|
|
146
150
|
}
|
|
147
151
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter-list-item/index.js"],"names":["isAppleOS","_window","window","platform","navigator","indexOf","includes","InserterListItem","className","isFirst","item","onSelect","onHover","isDraggable","props","isDragging","itemIconStyle","icon","backgroundColor","background","color","foreground","blocks","name","initialAttributes","innerBlocks","disabled","draggable","onDragStart","onDragEnd","event","current","isDisabled","preventDefault","metaKey","ctrlKey","keyCode","ENTER","title"],"mappings":";;;;;;;;;AAQA;;;;AALA;;AAMA;;AAIA;;AAKA;;AACA;;AACA;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/inserter-list-item/index.js"],"names":["isAppleOS","_window","window","platform","navigator","indexOf","includes","InserterListItem","className","isFirst","item","onSelect","onHover","isDraggable","props","isDragging","itemIconStyle","icon","backgroundColor","background","color","foreground","blocks","name","initialAttributes","innerBlocks","disabled","draggable","onDragStart","onDragEnd","event","current","isDisabled","preventDefault","metaKey","ctrlKey","keyC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CAAR;AAIAvB,UAAAA,OAAO,CAAE,IAAF,CAAP;AACA;AACD,OAzBF;AA0BC,MAAA,OAAO,EAAG,MAAM;AACf,YAAKG,UAAU,CAACgB,OAAhB,EAA0B;AACzB;AACA;;AACDnB,QAAAA,OAAO,CAAEF,IAAF,CAAP;AACA,OA/BF;AAgCC,MAAA,YAAY,EAAG,MAAM;AACpB,YAAKK,UAAU,CAACgB,OAAhB,EAA0B;AACzB;AACA;;AACDnB,QAAAA,OAAO,CAAEF,IAAF,CAAP;AACA,OArCF;AAsCC,MAAA,YAAY,EAAG,MAAME,OAAO,CAAE,IAAF,CAtC7B;AAuCC,MAAA,MAAM,EAAG,MAAMA,OAAO,CAAE,IAAF;AAvCvB,OAwCME,KAxCN,GA0CC;AACC,MAAA,SAAS,EAAC,0CADX;AAEC,MAAA,KAAK,EAAGE;AAFT,OAIC,4BAAC,kBAAD;AAAW,MAAA,IAAI,EAAGN,IAAI,CAACO,IAAvB;AAA8B,MAAA,UAAU;AAAxC,MAJD,CA1CD,EAgDC;AAAM,MAAA,SAAS,EAAC;AAAhB,OACC,4BAAC,kCAAD;AAAU,MAAA,aAAa,EAAG;AAA1B,OACGP,IAAI,CAAC4B,KADR,CADD,CAhDD,CAjBD,CADC;AAAA,GALH,CADD;AAkFA;;eAEc,mBAAM/B,gBAAN,C","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, useRef, memo } from '@wordpress/element';\nimport {\n\tcreateBlock,\n\tcreateBlocksFromInnerBlocksTemplate,\n} from '@wordpress/blocks';\nimport { __experimentalTruncate as Truncate } from '@wordpress/components';\nimport { ENTER } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport BlockIcon from '../block-icon';\nimport { InserterListboxItem } from '../inserter-listbox';\nimport InserterDraggableBlocks from '../inserter-draggable-blocks';\n\n/**\n * Return true if platform is MacOS.\n *\n * @param {Object} _window window object by default; used for DI testing.\n *\n * @return {boolean} True if MacOS; false otherwise.\n */\nfunction isAppleOS( _window = window ) {\n\tconst { platform } = _window.navigator;\n\n\treturn (\n\t\tplatform.indexOf( 'Mac' ) !== -1 ||\n\t\t[ 'iPad', 'iPhone' ].includes( platform )\n\t);\n}\n\nfunction InserterListItem( {\n\tclassName,\n\tisFirst,\n\titem,\n\tonSelect,\n\tonHover,\n\tisDraggable,\n\t...props\n} ) {\n\tconst isDragging = useRef( false );\n\tconst itemIconStyle = item.icon\n\t\t? {\n\t\t\t\tbackgroundColor: item.icon.background,\n\t\t\t\tcolor: item.icon.foreground,\n\t\t }\n\t\t: {};\n\tconst blocks = useMemo( () => {\n\t\treturn [\n\t\t\tcreateBlock(\n\t\t\t\titem.name,\n\t\t\t\titem.initialAttributes,\n\t\t\t\tcreateBlocksFromInnerBlocksTemplate( item.innerBlocks )\n\t\t\t),\n\t\t];\n\t}, [ item.name, item.initialAttributes, item.initialAttributes ] );\n\n\treturn (\n\t\t<InserterDraggableBlocks\n\t\t\tisEnabled={ isDraggable && ! item.disabled }\n\t\t\tblocks={ blocks }\n\t\t\ticon={ item.icon }\n\t\t>\n\t\t\t{ ( { draggable, onDragStart, onDragEnd } ) => (\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"block-editor-block-types-list__list-item\"\n\t\t\t\t\tdraggable={ draggable }\n\t\t\t\t\tonDragStart={ ( event ) => {\n\t\t\t\t\t\tisDragging.current = true;\n\t\t\t\t\t\tif ( onDragStart ) {\n\t\t\t\t\t\t\tonHover( null );\n\t\t\t\t\t\t\tonDragStart( event );\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t\tonDragEnd={ ( event ) => {\n\t\t\t\t\t\tisDragging.current = false;\n\t\t\t\t\t\tif ( onDragEnd ) {\n\t\t\t\t\t\t\tonDragEnd( event );\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<InserterListboxItem\n\t\t\t\t\t\tisFirst={ isFirst }\n\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t'block-editor-block-types-list__item',\n\t\t\t\t\t\t\tclassName\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tdisabled={ item.isDisabled }\n\t\t\t\t\t\tonClick={ ( event ) => {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tonSelect(\n\t\t\t\t\t\t\t\titem,\n\t\t\t\t\t\t\t\tisAppleOS() ? event.metaKey : event.ctrlKey\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tonHover( null );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\t\t\t\tconst { keyCode } = event;\n\t\t\t\t\t\t\tif ( keyCode === ENTER ) {\n\t\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\t\tonSelect(\n\t\t\t\t\t\t\t\t\titem,\n\t\t\t\t\t\t\t\t\tisAppleOS() ? event.metaKey : event.ctrlKey\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tonHover( null );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonFocus={ () => {\n\t\t\t\t\t\t\tif ( isDragging.current ) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonHover( item );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonMouseEnter={ () => {\n\t\t\t\t\t\t\tif ( isDragging.current ) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonHover( item );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonMouseLeave={ () => onHover( null ) }\n\t\t\t\t\t\tonBlur={ () => onHover( null ) }\n\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tclassName=\"block-editor-block-types-list__item-icon\"\n\t\t\t\t\t\t\tstyle={ itemIconStyle }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<BlockIcon icon={ item.icon } showColors />\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<span className=\"block-editor-block-types-list__item-title\">\n\t\t\t\t\t\t\t<Truncate numberOfLines={ 3 }>\n\t\t\t\t\t\t\t\t{ item.title }\n\t\t\t\t\t\t\t</Truncate>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</InserterListboxItem>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</InserterDraggableBlocks>\n\t);\n}\n\nexport default memo( InserterListItem );\n"]}
|
|
@@ -9,8 +9,6 @@ exports.default = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _element = require("@wordpress/element");
|
|
11
11
|
|
|
12
|
-
var _lodash = require("lodash");
|
|
13
|
-
|
|
14
12
|
var _data = require("@wordpress/data");
|
|
15
13
|
|
|
16
14
|
var _block = _interopRequireDefault(require("./block"));
|
|
@@ -19,10 +17,6 @@ var _context = require("./context");
|
|
|
19
17
|
|
|
20
18
|
var _utils = require("./utils");
|
|
21
19
|
|
|
22
|
-
/**
|
|
23
|
-
* External dependencies
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
20
|
/**
|
|
27
21
|
* WordPress dependencies
|
|
28
22
|
*/
|
|
@@ -97,7 +91,7 @@ function ListViewBranch(props) {
|
|
|
97
91
|
expandedState,
|
|
98
92
|
draggedClientIds
|
|
99
93
|
} = (0, _context.useListViewContext)();
|
|
100
|
-
const filteredBlocks =
|
|
94
|
+
const filteredBlocks = blocks.filter(Boolean);
|
|
101
95
|
const blockCount = filteredBlocks.length;
|
|
102
96
|
let nextPosition = listPosition;
|
|
103
97
|
return (0, _element.createElement)(_element.Fragment, null, filteredBlocks.map((block, index) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/list-view/branch.js"],"names":["countBlocks","block","expandedState","draggedClientIds","isExpandedByDefault","isDragged","includes","clientId","isExpanded","innerBlocks","reduce","countReducer","count","length","ListViewBranch","props","blocks","selectBlock","showBlockMovers","selectedClientIds","level","path","isBranchSelected","listPosition","fixedListWindow","filteredBlocks","blockCount","nextPosition","map","index","itemInView","blockInView","position","updatedPath","hasNestedBlocks","shouldExpand","undefined","showBlock","isSelected","isSelectedBranch","defaultProps"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/list-view/branch.js"],"names":["countBlocks","block","expandedState","draggedClientIds","isExpandedByDefault","isDragged","includes","clientId","isExpanded","innerBlocks","reduce","countReducer","count","length","ListViewBranch","props","blocks","selectBlock","showBlockMovers","selectedClientIds","level","path","isBranchSelected","listPosition","fixedListWindow","filteredBlocks","filter","Boolean","blockCount","nextPosition","map","index","itemInView","blockInView","position","updatedPath","hasNestedBlocks","shouldExpand","undefined","showBlock","isSelected","isSelectedBranch","defaultProps"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AACA;;AAXA;AACA;AACA;;AAIA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,WAAT,CACCC,KADD,EAECC,aAFD,EAGCC,gBAHD,EAICC,mBAJD,EAKE;AAAA;;AACD,QAAMC,SAAS,GAAGF,gBAAH,aAAGA,gBAAH,uBAAGA,gBAAgB,CAAEG,QAAlB,CAA4BL,KAAK,CAACM,QAAlC,CAAlB;;AACA,MAAKF,SAAL,EAAiB;AAChB,WAAO,CAAP;AACA;;AACD,QAAMG,UAAU,4BAAGN,aAAa,CAAED,KAAK,CAACM,QAAR,CAAhB,yEAAsCH,mBAAtD;;AAEA,MAAKI,UAAL,EAAkB;AACjB,WACC,IACAP,KAAK,CAACQ,WAAN,CAAkBC,MAAlB,CACCC,YAAY,CACXT,aADW,EAEXC,gBAFW,EAGXC,mBAHW,CADb,EAMC,CAND,CAFD;AAWA;;AACD,SAAO,CAAP;AACA;;AACD,MAAMO,YAAY,GACjB,CAAET,aAAF,EAAiBC,gBAAjB,EAA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GpC,SALb;AAMC,MAAA,KAAK,EAAGe,KANT;AAOC,MAAA,QAAQ,EAAGc,QAPZ;AAQC,MAAA,QAAQ,EAAGN,UARZ;AASC,MAAA,iBAAiB,EAAGA,UATrB;AAUC,MAAA,eAAe,EAAGV,eAVnB;AAWC,MAAA,IAAI,EAAGiB,WAXR;AAYC,MAAA,UAAU,EAAGE,YAZd;AAaC,MAAA,YAAY,EAAGR,YAbhB;AAcC,MAAA,iBAAiB,EAAGV;AAdrB,MAFF,EAmBG,CAAEoB,SAAF,IACD,wCACC;AAAI,MAAA,SAAS,EAAC;AAAd,MADD,CApBF,EAwBGH,eAAe,IAAIC,YAAnB,IAAmC,CAAEhC,SAArC,IACD,4BAAC,cAAD;AACC,MAAA,MAAM,EAAGI,WADV;AAEC,MAAA,WAAW,EAAGQ,WAFf;AAGC,MAAA,eAAe,EAAGC,eAHnB;AAIC,MAAA,KAAK,EAAGE,KAAK,GAAG,CAJjB;AAKC,MAAA,IAAI,EAAGe,WALR;AAMC,MAAA,YAAY,EAAGN,YAAY,GAAG,CAN/B;AAOC,MAAA,eAAe,EAAGL,eAPnB;AAQC,MAAA,gBAAgB,EAAGiB,gBARpB;AASC,MAAA,iBAAiB,EAAGtB,iBATrB;AAUC,MAAA,UAAU,EAAGX;AAVd,MAzBF,CADD;AAyCA,GA/EC,CADH,CADD;AAoFA;;AAEDM,cAAc,CAAC4B,YAAf,GAA8B;AAC7BzB,EAAAA,WAAW,EAAE,MAAM,CAAE;AADQ,CAA9B;;eAIe,mBAAMH,cAAN,C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { memo } from '@wordpress/element';\nimport { AsyncModeProvider } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport ListViewBlock from './block';\nimport { useListViewContext } from './context';\nimport { isClientIdSelected } from './utils';\n\n/**\n * Given a block, returns the total number of blocks in that subtree. This is used to help determine\n * the list position of a block.\n *\n * When a block is collapsed, we do not count their children as part of that total. In the current drag\n * implementation dragged blocks and their children are not counted.\n *\n * @param {Object} block block tree\n * @param {Object} expandedState state that notes which branches are collapsed\n * @param {Array} draggedClientIds a list of dragged client ids\n * @param {boolean} isExpandedByDefault flag to determine the default fallback expanded state.\n * @return {number} block count\n */\nfunction countBlocks(\n\tblock,\n\texpandedState,\n\tdraggedClientIds,\n\tisExpandedByDefault\n) {\n\tconst isDragged = draggedClientIds?.includes( block.clientId );\n\tif ( isDragged ) {\n\t\treturn 0;\n\t}\n\tconst isExpanded = expandedState[ block.clientId ] ?? isExpandedByDefault;\n\n\tif ( isExpanded ) {\n\t\treturn (\n\t\t\t1 +\n\t\t\tblock.innerBlocks.reduce(\n\t\t\t\tcountReducer(\n\t\t\t\t\texpandedState,\n\t\t\t\t\tdraggedClientIds,\n\t\t\t\t\tisExpandedByDefault\n\t\t\t\t),\n\t\t\t\t0\n\t\t\t)\n\t\t);\n\t}\n\treturn 1;\n}\nconst countReducer =\n\t( expandedState, draggedClientIds, isExpandedByDefault ) =>\n\t( count, block ) => {\n\t\tconst isDragged = draggedClientIds?.includes( block.clientId );\n\t\tif ( isDragged ) {\n\t\t\treturn count;\n\t\t}\n\t\tconst isExpanded =\n\t\t\texpandedState[ block.clientId ] ?? isExpandedByDefault;\n\t\tif ( isExpanded && block.innerBlocks.length > 0 ) {\n\t\t\treturn (\n\t\t\t\tcount +\n\t\t\t\tcountBlocks(\n\t\t\t\t\tblock,\n\t\t\t\t\texpandedState,\n\t\t\t\t\tdraggedClientIds,\n\t\t\t\t\tisExpandedByDefault\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t\treturn count + 1;\n\t};\n\nfunction ListViewBranch( props ) {\n\tconst {\n\t\tblocks,\n\t\tselectBlock,\n\t\tshowBlockMovers,\n\t\tselectedClientIds,\n\t\tlevel = 1,\n\t\tpath = '',\n\t\tisBranchSelected = false,\n\t\tlistPosition = 0,\n\t\tfixedListWindow,\n\t\tisExpanded,\n\t} = props;\n\n\tconst { expandedState, draggedClientIds } = useListViewContext();\n\n\tconst filteredBlocks = blocks.filter( Boolean );\n\tconst blockCount = filteredBlocks.length;\n\tlet nextPosition = listPosition;\n\n\treturn (\n\t\t<>\n\t\t\t{ filteredBlocks.map( ( block, index ) => {\n\t\t\t\tconst { clientId, innerBlocks } = block;\n\n\t\t\t\tif ( index > 0 ) {\n\t\t\t\t\tnextPosition += countBlocks(\n\t\t\t\t\t\tfilteredBlocks[ index - 1 ],\n\t\t\t\t\t\texpandedState,\n\t\t\t\t\t\tdraggedClientIds,\n\t\t\t\t\t\tisExpanded\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst { itemInView } = fixedListWindow;\n\t\t\t\tconst blockInView = itemInView( nextPosition );\n\n\t\t\t\tconst position = index + 1;\n\t\t\t\tconst updatedPath =\n\t\t\t\t\tpath.length > 0\n\t\t\t\t\t\t? `${ path }_${ position }`\n\t\t\t\t\t\t: `${ position }`;\n\t\t\t\tconst hasNestedBlocks = !! innerBlocks?.length;\n\n\t\t\t\tconst shouldExpand = hasNestedBlocks\n\t\t\t\t\t? expandedState[ clientId ] ?? isExpanded\n\t\t\t\t\t: undefined;\n\n\t\t\t\tconst isDragged = !! draggedClientIds?.includes( clientId );\n\n\t\t\t\tconst showBlock = isDragged || blockInView;\n\n\t\t\t\t// Make updates to the selected or dragged blocks synchronous,\n\t\t\t\t// but asynchronous for any other block.\n\t\t\t\tconst isSelected = isClientIdSelected(\n\t\t\t\t\tclientId,\n\t\t\t\t\tselectedClientIds\n\t\t\t\t);\n\t\t\t\tconst isSelectedBranch =\n\t\t\t\t\tisBranchSelected || ( isSelected && hasNestedBlocks );\n\t\t\t\treturn (\n\t\t\t\t\t<AsyncModeProvider key={ clientId } value={ ! isSelected }>\n\t\t\t\t\t\t{ showBlock && (\n\t\t\t\t\t\t\t<ListViewBlock\n\t\t\t\t\t\t\t\tblock={ block }\n\t\t\t\t\t\t\t\tselectBlock={ selectBlock }\n\t\t\t\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\t\t\t\tisBranchSelected={ isSelectedBranch }\n\t\t\t\t\t\t\t\tisDragged={ isDragged }\n\t\t\t\t\t\t\t\tlevel={ level }\n\t\t\t\t\t\t\t\tposition={ position }\n\t\t\t\t\t\t\t\trowCount={ blockCount }\n\t\t\t\t\t\t\t\tsiblingBlockCount={ blockCount }\n\t\t\t\t\t\t\t\tshowBlockMovers={ showBlockMovers }\n\t\t\t\t\t\t\t\tpath={ updatedPath }\n\t\t\t\t\t\t\t\tisExpanded={ shouldExpand }\n\t\t\t\t\t\t\t\tlistPosition={ nextPosition }\n\t\t\t\t\t\t\t\tselectedClientIds={ selectedClientIds }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ ! showBlock && (\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<td className=\"block-editor-list-view-placeholder\" />\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ hasNestedBlocks && shouldExpand && ! isDragged && (\n\t\t\t\t\t\t\t<ListViewBranch\n\t\t\t\t\t\t\t\tblocks={ innerBlocks }\n\t\t\t\t\t\t\t\tselectBlock={ selectBlock }\n\t\t\t\t\t\t\t\tshowBlockMovers={ showBlockMovers }\n\t\t\t\t\t\t\t\tlevel={ level + 1 }\n\t\t\t\t\t\t\t\tpath={ updatedPath }\n\t\t\t\t\t\t\t\tlistPosition={ nextPosition + 1 }\n\t\t\t\t\t\t\t\tfixedListWindow={ fixedListWindow }\n\t\t\t\t\t\t\t\tisBranchSelected={ isSelectedBranch }\n\t\t\t\t\t\t\t\tselectedClientIds={ selectedClientIds }\n\t\t\t\t\t\t\t\tisExpanded={ isExpanded }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</AsyncModeProvider>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</>\n\t);\n}\n\nListViewBranch.defaultProps = {\n\tselectBlock: () => {},\n};\n\nexport default memo( ListViewBranch );\n"]}
|
|
@@ -108,7 +108,19 @@ function useMouseMoveTypingReset() {
|
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
function useTypingObserver() {
|
|
111
|
-
const
|
|
111
|
+
const {
|
|
112
|
+
isTyping,
|
|
113
|
+
hasInlineToolbar
|
|
114
|
+
} = (0, _data.useSelect)(select => {
|
|
115
|
+
const {
|
|
116
|
+
isTyping: _isTyping,
|
|
117
|
+
getSettings
|
|
118
|
+
} = select(_store.store);
|
|
119
|
+
return {
|
|
120
|
+
isTyping: _isTyping(),
|
|
121
|
+
hasInlineToolbar: getSettings().hasInlineToolbar
|
|
122
|
+
};
|
|
123
|
+
}, []);
|
|
112
124
|
const {
|
|
113
125
|
startTyping,
|
|
114
126
|
stopTyping
|
|
@@ -120,7 +132,8 @@ function useTypingObserver() {
|
|
|
120
132
|
} = node;
|
|
121
133
|
const {
|
|
122
134
|
defaultView
|
|
123
|
-
} = ownerDocument;
|
|
135
|
+
} = ownerDocument;
|
|
136
|
+
const selection = defaultView.getSelection(); // Listeners to stop typing should only be added when typing.
|
|
124
137
|
// Listeners to start typing should only be added when not typing.
|
|
125
138
|
|
|
126
139
|
if (isTyping) {
|
|
@@ -170,17 +183,18 @@ function useTypingObserver() {
|
|
|
170
183
|
|
|
171
184
|
|
|
172
185
|
function stopTypingOnSelectionUncollapse() {
|
|
173
|
-
|
|
174
|
-
const isCollapsed = selection.rangeCount > 0 && selection.getRangeAt(0).collapsed;
|
|
175
|
-
|
|
176
|
-
if (!isCollapsed) {
|
|
186
|
+
if (!selection.isCollapsed) {
|
|
177
187
|
stopTyping();
|
|
178
188
|
}
|
|
179
189
|
}
|
|
180
190
|
|
|
181
191
|
node.addEventListener('focus', stopTypingOnNonTextField);
|
|
182
192
|
node.addEventListener('keydown', stopTypingOnEscapeKey);
|
|
183
|
-
|
|
193
|
+
|
|
194
|
+
if (!hasInlineToolbar) {
|
|
195
|
+
ownerDocument.addEventListener('selectionchange', stopTypingOnSelectionUncollapse);
|
|
196
|
+
}
|
|
197
|
+
|
|
184
198
|
return () => {
|
|
185
199
|
defaultView.clearTimeout(timerId);
|
|
186
200
|
node.removeEventListener('focus', stopTypingOnNonTextField);
|
|
@@ -225,7 +239,7 @@ function useTypingObserver() {
|
|
|
225
239
|
node.removeEventListener('keypress', startTypingInTextField);
|
|
226
240
|
node.removeEventListener('keydown', startTypingInTextField);
|
|
227
241
|
};
|
|
228
|
-
}, [isTyping, startTyping, stopTyping]);
|
|
242
|
+
}, [isTyping, hasInlineToolbar, startTyping, stopTyping]);
|
|
229
243
|
return (0, _compose.useMergeRefs)([ref1, ref2]);
|
|
230
244
|
}
|
|
231
245
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/observe-typing/index.js"],"names":["KEY_DOWN_ELIGIBLE_KEY_CODES","Set","UP","RIGHT","DOWN","LEFT","ENTER","BACKSPACE","isKeyDownEligibleForStartTyping","event","keyCode","shiftKey","has","useMouseMoveTypingReset","isTyping","select","blockEditorStore","stopTyping","node","ownerDocument","lastClientX","lastClientY","stopTypingOnMouseMove","clientX","clientY","addEventListener","removeEventListener","useTypingObserver","startTyping","ref1","ref2","defaultView","timerId","stopTypingOnNonTextField","target","setTimeout","stopTypingOnEscapeKey","ESCAPE","TAB","stopTypingOnSelectionUncollapse","selection","getSelection","isCollapsed","rangeCount","getRangeAt","collapsed","clearTimeout","startTypingInTextField","type","contains","ObserveTyping","children"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAcA;;AApBA;AACA;AACA;;AAeA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA,MAAMA,2BAA2B,GAAG,IAAIC,GAAJ,CAAS,CAC5CC,YAD4C,EAE5CC,eAF4C,EAG5CC,cAH4C,EAI5CC,cAJ4C,EAK5CC,eAL4C,EAM5CC,mBAN4C,CAAT,CAApC;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,+BAAT,CAA0CC,KAA1C,EAAkD;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CAAd,CAAP;AACA;;AAED,SAASoB,aAAT,OAAuC;AAAA,MAAf;AAAEC,IAAAA;AAAF,GAAe;AACtC,SAAO;AAAK,IAAA,GAAG,EAAGxB,iBAAiB;AAA5B,KAAmCwB,QAAnC,CAAP;AACA;AAED;AACA;AACA;;;eACeD,a","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRefEffect, useMergeRefs } from '@wordpress/compose';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { isTextField } from '@wordpress/dom';\nimport {\n\tUP,\n\tRIGHT,\n\tDOWN,\n\tLEFT,\n\tENTER,\n\tBACKSPACE,\n\tESCAPE,\n\tTAB,\n} from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Set of key codes upon which typing is to be initiated on a keydown event.\n *\n * @type {Set<number>}\n */\nconst KEY_DOWN_ELIGIBLE_KEY_CODES = new Set( [\n\tUP,\n\tRIGHT,\n\tDOWN,\n\tLEFT,\n\tENTER,\n\tBACKSPACE,\n] );\n\n/**\n * Returns true if a given keydown event can be inferred as intent to start\n * typing, or false otherwise. A keydown is considered eligible if it is a\n * text navigation without shift active.\n *\n * @param {KeyboardEvent} event Keydown event to test.\n *\n * @return {boolean} Whether event is eligible to start typing.\n */\nfunction isKeyDownEligibleForStartTyping( event ) {\n\tconst { keyCode, shiftKey } = event;\n\treturn ! shiftKey && KEY_DOWN_ELIGIBLE_KEY_CODES.has( keyCode );\n}\n\n/**\n * Removes the `isTyping` flag when the mouse moves in the document of the given\n * element.\n */\nexport function useMouseMoveTypingReset() {\n\tconst isTyping = useSelect(\n\t\t( select ) => select( blockEditorStore ).isTyping(),\n\t\t[]\n\t);\n\tconst { stopTyping } = useDispatch( blockEditorStore );\n\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tif ( ! isTyping ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { ownerDocument } = node;\n\t\t\tlet lastClientX;\n\t\t\tlet lastClientY;\n\n\t\t\t/**\n\t\t\t * On mouse move, unset typing flag if user has moved cursor.\n\t\t\t *\n\t\t\t * @param {MouseEvent} event Mousemove event.\n\t\t\t */\n\t\t\tfunction stopTypingOnMouseMove( event ) {\n\t\t\t\tconst { clientX, clientY } = event;\n\n\t\t\t\t// We need to check that the mouse really moved because Safari\n\t\t\t\t// triggers mousemove events when shift or ctrl are pressed.\n\t\t\t\tif (\n\t\t\t\t\tlastClientX &&\n\t\t\t\t\tlastClientY &&\n\t\t\t\t\t( lastClientX !== clientX || lastClientY !== clientY )\n\t\t\t\t) {\n\t\t\t\t\tstopTyping();\n\t\t\t\t}\n\n\t\t\t\tlastClientX = clientX;\n\t\t\t\tlastClientY = clientY;\n\t\t\t}\n\n\t\t\townerDocument.addEventListener(\n\t\t\t\t'mousemove',\n\t\t\t\tstopTypingOnMouseMove\n\t\t\t);\n\n\t\t\treturn () => {\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'mousemove',\n\t\t\t\t\tstopTypingOnMouseMove\n\t\t\t\t);\n\t\t\t};\n\t\t},\n\t\t[ isTyping, stopTyping ]\n\t);\n}\n\n/**\n * Sets and removes the `isTyping` flag based on user actions:\n *\n * - Sets the flag if the user types within the given element.\n * - Removes the flag when the user selects some text, focusses a non-text\n * field, presses ESC or TAB, or moves the mouse in the document.\n */\nexport function useTypingObserver() {\n\tconst isTyping = useSelect( ( select ) =>\n\t\tselect( blockEditorStore ).isTyping()\n\t);\n\tconst { startTyping, stopTyping } = useDispatch( blockEditorStore );\n\n\tconst ref1 = useMouseMoveTypingReset();\n\tconst ref2 = useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\t// Listeners to stop typing should only be added when typing.\n\t\t\t// Listeners to start typing should only be added when not typing.\n\t\t\tif ( isTyping ) {\n\t\t\t\tlet timerId;\n\n\t\t\t\t/**\n\t\t\t\t * Stops typing when focus transitions to a non-text field element.\n\t\t\t\t *\n\t\t\t\t * @param {FocusEvent} event Focus event.\n\t\t\t\t */\n\t\t\t\tfunction stopTypingOnNonTextField( event ) {\n\t\t\t\t\tconst { target } = event;\n\n\t\t\t\t\t// Since focus to a non-text field via arrow key will trigger\n\t\t\t\t\t// before the keydown event, wait until after current stack\n\t\t\t\t\t// before evaluating whether typing is to be stopped. Otherwise,\n\t\t\t\t\t// typing will re-start.\n\t\t\t\t\ttimerId = defaultView.setTimeout( () => {\n\t\t\t\t\t\tif ( ! isTextField( target ) ) {\n\t\t\t\t\t\t\tstopTyping();\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\t/**\n\t\t\t\t * Unsets typing flag if user presses Escape while typing flag is\n\t\t\t\t * active.\n\t\t\t\t *\n\t\t\t\t * @param {KeyboardEvent} event Keypress or keydown event to\n\t\t\t\t * interpret.\n\t\t\t\t */\n\t\t\t\tfunction stopTypingOnEscapeKey( event ) {\n\t\t\t\t\tconst { keyCode } = event;\n\n\t\t\t\t\tif ( keyCode === ESCAPE || keyCode === TAB ) {\n\t\t\t\t\t\tstopTyping();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t/**\n\t\t\t\t * On selection change, unset typing flag if user has made an\n\t\t\t\t * uncollapsed (shift) selection.\n\t\t\t\t */\n\t\t\t\tfunction stopTypingOnSelectionUncollapse() {\n\t\t\t\t\tconst selection = defaultView.getSelection();\n\t\t\t\t\tconst isCollapsed =\n\t\t\t\t\t\tselection.rangeCount > 0 &&\n\t\t\t\t\t\tselection.getRangeAt( 0 ).collapsed;\n\n\t\t\t\t\tif ( ! isCollapsed ) {\n\t\t\t\t\t\tstopTyping();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tnode.addEventListener( 'focus', stopTypingOnNonTextField );\n\t\t\t\tnode.addEventListener( 'keydown', stopTypingOnEscapeKey );\n\t\t\t\townerDocument.addEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tstopTypingOnSelectionUncollapse\n\t\t\t\t);\n\n\t\t\t\treturn () => {\n\t\t\t\t\tdefaultView.clearTimeout( timerId );\n\t\t\t\t\tnode.removeEventListener(\n\t\t\t\t\t\t'focus',\n\t\t\t\t\t\tstopTypingOnNonTextField\n\t\t\t\t\t);\n\t\t\t\t\tnode.removeEventListener(\n\t\t\t\t\t\t'keydown',\n\t\t\t\t\t\tstopTypingOnEscapeKey\n\t\t\t\t\t);\n\t\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t\t'selectionchange',\n\t\t\t\t\t\tstopTypingOnSelectionUncollapse\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Handles a keypress or keydown event to infer intention to start\n\t\t\t * typing.\n\t\t\t *\n\t\t\t * @param {KeyboardEvent} event Keypress or keydown event to interpret.\n\t\t\t */\n\t\t\tfunction startTypingInTextField( event ) {\n\t\t\t\tconst { type, target } = event;\n\n\t\t\t\t// Abort early if already typing, or key press is incurred outside a\n\t\t\t\t// text field (e.g. arrow-ing through toolbar buttons).\n\t\t\t\t// Ignore typing if outside the current DOM container\n\t\t\t\tif ( ! isTextField( target ) || ! node.contains( target ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Special-case keydown because certain keys do not emit a keypress\n\t\t\t\t// event. Conversely avoid keydown as the canonical event since\n\t\t\t\t// there are many keydown which are explicitly not targeted for\n\t\t\t\t// typing.\n\t\t\t\tif (\n\t\t\t\t\ttype === 'keydown' &&\n\t\t\t\t\t! isKeyDownEligibleForStartTyping( event )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tstartTyping();\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'keypress', startTypingInTextField );\n\t\t\tnode.addEventListener( 'keydown', startTypingInTextField );\n\n\t\t\treturn () => {\n\t\t\t\tnode.removeEventListener( 'keypress', startTypingInTextField );\n\t\t\t\tnode.removeEventListener( 'keydown', startTypingInTextField );\n\t\t\t};\n\t\t},\n\t\t[ isTyping, startTyping, stopTyping ]\n\t);\n\n\treturn useMergeRefs( [ ref1, ref2 ] );\n}\n\nfunction ObserveTyping( { children } ) {\n\treturn <div ref={ useTypingObserver() }>{ children }</div>;\n}\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/observe-typing/README.md\n */\nexport default ObserveTyping;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/observe-typing/index.js"],"names":["KEY_DOWN_ELIGIBLE_KEY_CODES","Set","UP","RIGHT","DOWN","LEFT","ENTER","BACKSPACE","isKeyDownEligibleForStartTyping","event","keyCode","shiftKey","has","useMouseMoveTypingReset","isTyping","select","blockEditorStore","stopTyping","node","ownerDocument","lastClientX","lastClientY","stopTypingOnMouseMove","clientX","clientY","addEventListener","removeEventListener","useTypingObserver","hasInlineToolbar","_isTyping","getSettings","startTyping","ref1","ref2","defaultView","selection","getSelection","timerId","stopTypingOnNonTextField","target","setTimeout","stopTypingOnEscapeKey","ESCAPE","TAB","stopTypingOnSelectionUncollapse","isCollapsed","clearTimeout","startTypingInTextField","type","contains","ObserveTyping","children"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAcA;;AApBA;AACA;AACA;;AAeA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA,MAAMA,2BAA2B,GAAG,IAAIC,GAAJ,CAAS,CAC5CC,YAD4C,EAE5CC,eAF4C,EAG5CC,cAH4C,EAI5CC,cAJ4C,EAK5CC,eAL4C,EAM5CC,mBAN4C,CAAT,CAApC;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,+BAAT,CAA0CC,KAA1C,EAAkD;AACjD,QAAM;AAAEC,IAAAA,OAAF;AAAWC,IAAAA;AAAX,MAAwBF,KAA9B;AACA,SAAO,CAAEE,QAAF,IAAcX,2BAA2B,CAACY,GAA5B,CAAiCF,OAAjC,CAArB;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SAAO,2BAAc,CAAEe,IAAF,EAAQC,IAAR,CAAd,CAAP;AACA;;AAED,SAASiB,aAAT,OAAuC;AAAA,MAAf;AAAEC,IAAAA;AAAF,GAAe;AACtC,SAAO;AAAK,IAAA,GAAG,EAAGxB,iBAAiB;AAA5B,KAAmCwB,QAAnC,CAAP;AACA;AAED;AACA;AACA;;;eACeD,a","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRefEffect, useMergeRefs } from '@wordpress/compose';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { isTextField } from '@wordpress/dom';\nimport {\n\tUP,\n\tRIGHT,\n\tDOWN,\n\tLEFT,\n\tENTER,\n\tBACKSPACE,\n\tESCAPE,\n\tTAB,\n} from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Set of key codes upon which typing is to be initiated on a keydown event.\n *\n * @type {Set<number>}\n */\nconst KEY_DOWN_ELIGIBLE_KEY_CODES = new Set( [\n\tUP,\n\tRIGHT,\n\tDOWN,\n\tLEFT,\n\tENTER,\n\tBACKSPACE,\n] );\n\n/**\n * Returns true if a given keydown event can be inferred as intent to start\n * typing, or false otherwise. A keydown is considered eligible if it is a\n * text navigation without shift active.\n *\n * @param {KeyboardEvent} event Keydown event to test.\n *\n * @return {boolean} Whether event is eligible to start typing.\n */\nfunction isKeyDownEligibleForStartTyping( event ) {\n\tconst { keyCode, shiftKey } = event;\n\treturn ! shiftKey && KEY_DOWN_ELIGIBLE_KEY_CODES.has( keyCode );\n}\n\n/**\n * Removes the `isTyping` flag when the mouse moves in the document of the given\n * element.\n */\nexport function useMouseMoveTypingReset() {\n\tconst isTyping = useSelect(\n\t\t( select ) => select( blockEditorStore ).isTyping(),\n\t\t[]\n\t);\n\tconst { stopTyping } = useDispatch( blockEditorStore );\n\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tif ( ! isTyping ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { ownerDocument } = node;\n\t\t\tlet lastClientX;\n\t\t\tlet lastClientY;\n\n\t\t\t/**\n\t\t\t * On mouse move, unset typing flag if user has moved cursor.\n\t\t\t *\n\t\t\t * @param {MouseEvent} event Mousemove event.\n\t\t\t */\n\t\t\tfunction stopTypingOnMouseMove( event ) {\n\t\t\t\tconst { clientX, clientY } = event;\n\n\t\t\t\t// We need to check that the mouse really moved because Safari\n\t\t\t\t// triggers mousemove events when shift or ctrl are pressed.\n\t\t\t\tif (\n\t\t\t\t\tlastClientX &&\n\t\t\t\t\tlastClientY &&\n\t\t\t\t\t( lastClientX !== clientX || lastClientY !== clientY )\n\t\t\t\t) {\n\t\t\t\t\tstopTyping();\n\t\t\t\t}\n\n\t\t\t\tlastClientX = clientX;\n\t\t\t\tlastClientY = clientY;\n\t\t\t}\n\n\t\t\townerDocument.addEventListener(\n\t\t\t\t'mousemove',\n\t\t\t\tstopTypingOnMouseMove\n\t\t\t);\n\n\t\t\treturn () => {\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'mousemove',\n\t\t\t\t\tstopTypingOnMouseMove\n\t\t\t\t);\n\t\t\t};\n\t\t},\n\t\t[ isTyping, stopTyping ]\n\t);\n}\n\n/**\n * Sets and removes the `isTyping` flag based on user actions:\n *\n * - Sets the flag if the user types within the given element.\n * - Removes the flag when the user selects some text, focusses a non-text\n * field, presses ESC or TAB, or moves the mouse in the document.\n */\nexport function useTypingObserver() {\n\tconst { isTyping, hasInlineToolbar } = useSelect( ( select ) => {\n\t\tconst { isTyping: _isTyping, getSettings } = select( blockEditorStore );\n\t\treturn {\n\t\t\tisTyping: _isTyping(),\n\t\t\thasInlineToolbar: getSettings().hasInlineToolbar,\n\t\t};\n\t}, [] );\n\tconst { startTyping, stopTyping } = useDispatch( blockEditorStore );\n\n\tconst ref1 = useMouseMoveTypingReset();\n\tconst ref2 = useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\t\t\tconst selection = defaultView.getSelection();\n\n\t\t\t// Listeners to stop typing should only be added when typing.\n\t\t\t// Listeners to start typing should only be added when not typing.\n\t\t\tif ( isTyping ) {\n\t\t\t\tlet timerId;\n\n\t\t\t\t/**\n\t\t\t\t * Stops typing when focus transitions to a non-text field element.\n\t\t\t\t *\n\t\t\t\t * @param {FocusEvent} event Focus event.\n\t\t\t\t */\n\t\t\t\tfunction stopTypingOnNonTextField( event ) {\n\t\t\t\t\tconst { target } = event;\n\n\t\t\t\t\t// Since focus to a non-text field via arrow key will trigger\n\t\t\t\t\t// before the keydown event, wait until after current stack\n\t\t\t\t\t// before evaluating whether typing is to be stopped. Otherwise,\n\t\t\t\t\t// typing will re-start.\n\t\t\t\t\ttimerId = defaultView.setTimeout( () => {\n\t\t\t\t\t\tif ( ! isTextField( target ) ) {\n\t\t\t\t\t\t\tstopTyping();\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\t/**\n\t\t\t\t * Unsets typing flag if user presses Escape while typing flag is\n\t\t\t\t * active.\n\t\t\t\t *\n\t\t\t\t * @param {KeyboardEvent} event Keypress or keydown event to\n\t\t\t\t * interpret.\n\t\t\t\t */\n\t\t\t\tfunction stopTypingOnEscapeKey( event ) {\n\t\t\t\t\tconst { keyCode } = event;\n\n\t\t\t\t\tif ( keyCode === ESCAPE || keyCode === TAB ) {\n\t\t\t\t\t\tstopTyping();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t/**\n\t\t\t\t * On selection change, unset typing flag if user has made an\n\t\t\t\t * uncollapsed (shift) selection.\n\t\t\t\t */\n\t\t\t\tfunction stopTypingOnSelectionUncollapse() {\n\t\t\t\t\tif ( ! selection.isCollapsed ) {\n\t\t\t\t\t\tstopTyping();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tnode.addEventListener( 'focus', stopTypingOnNonTextField );\n\t\t\t\tnode.addEventListener( 'keydown', stopTypingOnEscapeKey );\n\n\t\t\t\tif ( ! hasInlineToolbar ) {\n\t\t\t\t\townerDocument.addEventListener(\n\t\t\t\t\t\t'selectionchange',\n\t\t\t\t\t\tstopTypingOnSelectionUncollapse\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn () => {\n\t\t\t\t\tdefaultView.clearTimeout( timerId );\n\t\t\t\t\tnode.removeEventListener(\n\t\t\t\t\t\t'focus',\n\t\t\t\t\t\tstopTypingOnNonTextField\n\t\t\t\t\t);\n\t\t\t\t\tnode.removeEventListener(\n\t\t\t\t\t\t'keydown',\n\t\t\t\t\t\tstopTypingOnEscapeKey\n\t\t\t\t\t);\n\t\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t\t'selectionchange',\n\t\t\t\t\t\tstopTypingOnSelectionUncollapse\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Handles a keypress or keydown event to infer intention to start\n\t\t\t * typing.\n\t\t\t *\n\t\t\t * @param {KeyboardEvent} event Keypress or keydown event to interpret.\n\t\t\t */\n\t\t\tfunction startTypingInTextField( event ) {\n\t\t\t\tconst { type, target } = event;\n\n\t\t\t\t// Abort early if already typing, or key press is incurred outside a\n\t\t\t\t// text field (e.g. arrow-ing through toolbar buttons).\n\t\t\t\t// Ignore typing if outside the current DOM container\n\t\t\t\tif ( ! isTextField( target ) || ! node.contains( target ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Special-case keydown because certain keys do not emit a keypress\n\t\t\t\t// event. Conversely avoid keydown as the canonical event since\n\t\t\t\t// there are many keydown which are explicitly not targeted for\n\t\t\t\t// typing.\n\t\t\t\tif (\n\t\t\t\t\ttype === 'keydown' &&\n\t\t\t\t\t! isKeyDownEligibleForStartTyping( event )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tstartTyping();\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'keypress', startTypingInTextField );\n\t\t\tnode.addEventListener( 'keydown', startTypingInTextField );\n\n\t\t\treturn () => {\n\t\t\t\tnode.removeEventListener( 'keypress', startTypingInTextField );\n\t\t\t\tnode.removeEventListener( 'keydown', startTypingInTextField );\n\t\t\t};\n\t\t},\n\t\t[ isTyping, hasInlineToolbar, startTyping, stopTyping ]\n\t);\n\n\treturn useMergeRefs( [ ref1, ref2 ] );\n}\n\nfunction ObserveTyping( { children } ) {\n\treturn <div ref={ useTypingObserver() }>{ children }</div>;\n}\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/observe-typing/README.md\n */\nexport default ObserveTyping;\n"]}
|
|
@@ -11,10 +11,16 @@ var _element = require("@wordpress/element");
|
|
|
11
11
|
|
|
12
12
|
var _components = require("@wordpress/components");
|
|
13
13
|
|
|
14
|
+
var _data = require("@wordpress/data");
|
|
15
|
+
|
|
16
|
+
var _richText = require("@wordpress/rich-text");
|
|
17
|
+
|
|
14
18
|
var _blockControls = _interopRequireDefault(require("../block-controls"));
|
|
15
19
|
|
|
16
20
|
var _formatToolbar = _interopRequireDefault(require("./format-toolbar"));
|
|
17
21
|
|
|
22
|
+
var _store = require("../../store");
|
|
23
|
+
|
|
18
24
|
/**
|
|
19
25
|
* WordPress dependencies
|
|
20
26
|
*/
|
|
@@ -22,23 +28,66 @@ var _formatToolbar = _interopRequireDefault(require("./format-toolbar"));
|
|
|
22
28
|
/**
|
|
23
29
|
* Internal dependencies
|
|
24
30
|
*/
|
|
25
|
-
|
|
31
|
+
function InlineSelectionToolbar(_ref) {
|
|
26
32
|
let {
|
|
27
|
-
|
|
28
|
-
anchorRef
|
|
33
|
+
value,
|
|
34
|
+
anchorRef,
|
|
35
|
+
activeFormats
|
|
29
36
|
} = _ref;
|
|
37
|
+
const lastFormat = activeFormats[activeFormats.length - 1];
|
|
38
|
+
const lastFormatType = lastFormat === null || lastFormat === void 0 ? void 0 : lastFormat.type;
|
|
39
|
+
const settings = (0, _data.useSelect)(select => select(_richText.store).getFormatType(lastFormatType), [lastFormatType]);
|
|
40
|
+
const selectionRef = (0, _richText.useAnchorRef)({
|
|
41
|
+
ref: anchorRef,
|
|
42
|
+
value,
|
|
43
|
+
settings
|
|
44
|
+
});
|
|
45
|
+
return (0, _element.createElement)(InlineToolbar, {
|
|
46
|
+
anchorRef: selectionRef
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function InlineToolbar(_ref2) {
|
|
51
|
+
let {
|
|
52
|
+
anchorRef
|
|
53
|
+
} = _ref2;
|
|
54
|
+
return (0, _element.createElement)(_components.Popover, {
|
|
55
|
+
position: "top center",
|
|
56
|
+
focusOnMount: false,
|
|
57
|
+
anchorRef: anchorRef,
|
|
58
|
+
className: "block-editor-rich-text__inline-format-toolbar",
|
|
59
|
+
__unstableSlotName: "block-toolbar"
|
|
60
|
+
}, (0, _element.createElement)("div", {
|
|
61
|
+
className: "block-editor-rich-text__inline-format-toolbar-group"
|
|
62
|
+
}, (0, _element.createElement)(_components.ToolbarGroup, null, (0, _element.createElement)(_formatToolbar.default, null))));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const FormatToolbarContainer = _ref3 => {
|
|
66
|
+
let {
|
|
67
|
+
inline,
|
|
68
|
+
anchorRef,
|
|
69
|
+
value
|
|
70
|
+
} = _ref3;
|
|
71
|
+
const hasInlineToolbar = (0, _data.useSelect)(select => select(_store.store).getSettings().hasInlineToolbar, []);
|
|
30
72
|
|
|
31
73
|
if (inline) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
74
|
+
return (0, _element.createElement)(InlineToolbar, {
|
|
75
|
+
anchorRef: anchorRef
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (hasInlineToolbar) {
|
|
80
|
+
const activeFormats = (0, _richText.getActiveFormats)(value);
|
|
81
|
+
|
|
82
|
+
if ((0, _richText.isCollapsed)(value) && !activeFormats.length) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return (0, _element.createElement)(InlineSelectionToolbar, {
|
|
36
87
|
anchorRef: anchorRef,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
className: "block-editor-rich-text__inline-format-toolbar-group"
|
|
41
|
-
}, (0, _element.createElement)(_components.ToolbarGroup, null, (0, _element.createElement)(_formatToolbar.default, null))));
|
|
88
|
+
value: value,
|
|
89
|
+
activeFormats: activeFormats
|
|
90
|
+
});
|
|
42
91
|
} // Render regular toolbar.
|
|
43
92
|
|
|
44
93
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/format-toolbar-container.js"],"names":["FormatToolbarContainer","inline","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/format-toolbar-container.js"],"names":["InlineSelectionToolbar","value","anchorRef","activeFormats","lastFormat","length","lastFormatType","type","settings","select","richTextStore","getFormatType","selectionRef","ref","InlineToolbar","FormatToolbarContainer","inline","hasInlineToolbar","blockEditorStore","getSettings"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AAUA;;AACA;;AACA;;AAjBA;AACA;AACA;;AAUA;AACA;AACA;AAKA,SAASA,sBAAT,OAAuE;AAAA,MAAtC;AAAEC,IAAAA,KAAF;AAASC,IAAAA,SAAT;AAAoBC,IAAAA;AAApB,GAAsC;AACtE,QAAMC,UAAU,GAAGD,aAAa,CAAEA,aAAa,CAACE,MAAd,GAAuB,CAAzB,CAAhC;AACA,QAAMC,cAAc,GAAGF,UAAH,aAAGA,UAAH,uBAAGA,UAAU,CAAEG,IAAnC;AACA,QAAMC,QAAQ,GAAG,qBACdC,MAAF,IAAcA,MAAM,CAAEC,eAAF,CAAN,CAAwBC,aAAxB,CAAuCL,cAAvC,CADE,EAEhB,CAAEA,cAAF,CAFgB,CAAjB;AAIA,QAAMM,YAAY,GAAG,4BAAc;AAClCC,IAAAA,GAAG,EAAEX,SAD6B;AAElCD,I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ourcesContent":["/**\n * WordPress dependencies\n */\nimport { Popover, ToolbarGroup } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tisCollapsed,\n\tgetActiveFormats,\n\tuseAnchorRef,\n\tstore as richTextStore,\n} from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport BlockControls from '../block-controls';\nimport FormatToolbar from './format-toolbar';\nimport { store as blockEditorStore } from '../../store';\n\nfunction InlineSelectionToolbar( { value, anchorRef, activeFormats } ) {\n\tconst lastFormat = activeFormats[ activeFormats.length - 1 ];\n\tconst lastFormatType = lastFormat?.type;\n\tconst settings = useSelect(\n\t\t( select ) => select( richTextStore ).getFormatType( lastFormatType ),\n\t\t[ lastFormatType ]\n\t);\n\tconst selectionRef = useAnchorRef( {\n\t\tref: anchorRef,\n\t\tvalue,\n\t\tsettings,\n\t} );\n\n\treturn <InlineToolbar anchorRef={ selectionRef } />;\n}\n\nfunction InlineToolbar( { anchorRef } ) {\n\treturn (\n\t\t<Popover\n\t\t\tposition=\"top center\"\n\t\t\tfocusOnMount={ false }\n\t\t\tanchorRef={ anchorRef }\n\t\t\tclassName=\"block-editor-rich-text__inline-format-toolbar\"\n\t\t\t__unstableSlotName=\"block-toolbar\"\n\t\t>\n\t\t\t<div className=\"block-editor-rich-text__inline-format-toolbar-group\">\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t<FormatToolbar />\n\t\t\t\t</ToolbarGroup>\n\t\t\t</div>\n\t\t</Popover>\n\t);\n}\n\nconst FormatToolbarContainer = ( { inline, anchorRef, value } ) => {\n\tconst hasInlineToolbar = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings().hasInlineToolbar,\n\t\t[]\n\t);\n\n\tif ( inline ) {\n\t\treturn <InlineToolbar anchorRef={ anchorRef } />;\n\t}\n\n\tif ( hasInlineToolbar ) {\n\t\tconst activeFormats = getActiveFormats( value );\n\n\t\tif ( isCollapsed( value ) && ! activeFormats.length ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn (\n\t\t\t<InlineSelectionToolbar\n\t\t\t\tanchorRef={ anchorRef }\n\t\t\t\tvalue={ value }\n\t\t\t\tactiveFormats={ activeFormats }\n\t\t\t/>\n\t\t);\n\t}\n\n\t// Render regular toolbar.\n\treturn (\n\t\t<BlockControls group=\"inline\">\n\t\t\t<FormatToolbar />\n\t\t</BlockControls>\n\t);\n};\n\nexport default FormatToolbarContainer;\n"]}
|
|
@@ -360,7 +360,8 @@ function RichTextWrapper(_ref, forwardedRef) {
|
|
|
360
360
|
forwardedRef: anchorRef
|
|
361
361
|
})))), isSelected && hasFormats && (0, _element.createElement)(_formatToolbarContainer.default, {
|
|
362
362
|
inline: inlineToolbar,
|
|
363
|
-
anchorRef: anchorRef
|
|
363
|
+
anchorRef: anchorRef,
|
|
364
|
+
value: value
|
|
364
365
|
}), (0, _element.createElement)(TagName // Overridable props.
|
|
365
366
|
, (0, _extends2.default)({
|
|
366
367
|
role: "textbox",
|