@wordpress/block-editor 16.2.0 → 17.0.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 +39 -0
- package/build/components/block-inspector/index.cjs +9 -6
- package/build/components/block-inspector/index.cjs.map +2 -2
- package/build/components/block-keyboard-shortcuts/index.cjs +201 -0
- package/build/components/block-keyboard-shortcuts/index.cjs.map +7 -0
- package/build/components/block-list/block.cjs +10 -3
- package/build/components/block-list/block.cjs.map +2 -2
- package/build/components/block-list/index.cjs +6 -1
- package/build/components/block-list/index.cjs.map +2 -2
- package/build/components/block-list/use-block-props/use-focus-first-element.cjs +4 -0
- package/build/components/block-list/use-block-props/use-focus-first-element.cjs.map +2 -2
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.cjs +6 -7
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.cjs.map +2 -2
- package/build/components/block-parent-selector/index.cjs +98 -29
- package/build/components/block-parent-selector/index.cjs.map +3 -3
- package/build/components/block-popover/inbetween.cjs +2 -2
- package/build/components/block-popover/inbetween.cjs.map +2 -2
- package/build/components/block-preview/index.cjs +0 -4
- package/build/components/block-preview/index.cjs.map +2 -2
- package/build/components/block-styles/index.cjs +77 -33
- package/build/components/block-styles/index.cjs.map +3 -3
- package/build/components/block-visibility/constants.cjs.map +2 -2
- package/build/components/child-layout-control/index.cjs.map +2 -2
- package/build/components/colors/with-colors.cjs +55 -71
- package/build/components/colors/with-colors.cjs.map +2 -2
- package/build/components/dimensions-tool/aspect-ratio-tool.cjs +4 -2
- package/build/components/dimensions-tool/aspect-ratio-tool.cjs.map +2 -2
- package/build/components/dimensions-tool/index.cjs +18 -16
- package/build/components/dimensions-tool/index.cjs.map +2 -2
- package/build/components/dimensions-tool/utils.cjs +61 -0
- package/build/components/dimensions-tool/utils.cjs.map +7 -0
- package/build/components/duotone-control/index.cjs +2 -0
- package/build/components/duotone-control/index.cjs.map +2 -2
- package/build/components/global-styles/advanced-panel.cjs.map +3 -3
- package/build/components/global-styles/border-panel.cjs +2 -5
- package/build/components/global-styles/border-panel.cjs.map +2 -2
- package/build/components/global-styles/color-panel.cjs +14 -2
- package/build/components/global-styles/color-panel.cjs.map +2 -2
- package/build/components/global-styles/dimensions-panel.cjs +9 -5
- package/build/components/global-styles/dimensions-panel.cjs.map +2 -2
- package/build/components/global-styles/filters-panel.cjs +12 -8
- package/build/components/global-styles/filters-panel.cjs.map +2 -2
- package/build/components/global-styles/shadow-panel-components.cjs +16 -11
- package/build/components/global-styles/shadow-panel-components.cjs.map +2 -2
- package/build/components/global-styles/utils.cjs +9 -0
- package/build/components/global-styles/utils.cjs.map +2 -2
- package/build/components/inner-blocks/index.cjs +5 -3
- package/build/components/inner-blocks/index.cjs.map +2 -2
- package/build/components/inserter/block-patterns-explorer/index.cjs +39 -22
- package/build/components/inserter/block-patterns-explorer/index.cjs.map +2 -2
- package/build/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.cjs +21 -55
- package/build/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.cjs.map +2 -2
- package/build/components/inserter/block-patterns-explorer/pattern-list.cjs +19 -44
- package/build/components/inserter/block-patterns-explorer/pattern-list.cjs.map +3 -3
- package/build/components/inserter/hooks/use-insertion-point.cjs +4 -4
- package/build/components/inserter/hooks/use-insertion-point.cjs.map +2 -2
- package/build/components/inserter/menu.cjs +18 -7
- package/build/components/inserter/menu.cjs.map +2 -2
- package/build/components/inserter/quick-inserter.cjs +30 -27
- package/build/components/inserter/quick-inserter.cjs.map +2 -2
- package/build/components/inspector-controls-tabs/styles-tab.cjs +1 -1
- package/build/components/inspector-controls-tabs/styles-tab.cjs.map +2 -2
- package/build/components/list-view/index.cjs +31 -5
- package/build/components/list-view/index.cjs.map +3 -3
- package/build/components/list-view/utils.cjs +13 -1
- package/build/components/list-view/utils.cjs.map +2 -2
- package/build/components/media-placeholder/index.cjs +1 -1
- package/build/components/media-placeholder/index.cjs.map +3 -3
- package/build/components/provider/index.cjs +5 -1
- package/build/components/provider/index.cjs.map +3 -3
- package/build/components/publish-date-time-picker/index.cjs +3 -2
- package/build/components/publish-date-time-picker/index.cjs.map +2 -2
- package/build/components/rich-text/event-listeners/enter.cjs +46 -39
- package/build/components/rich-text/event-listeners/enter.cjs.map +2 -2
- package/build/components/rich-text/index.cjs +7 -5
- package/build/components/rich-text/index.cjs.map +2 -2
- package/build/components/rich-text/multiline.cjs +105 -70
- package/build/components/rich-text/multiline.cjs.map +3 -3
- package/build/components/url-input/index.cjs.map +2 -2
- package/build/components/writing-flow/use-input.cjs +65 -13
- package/build/components/writing-flow/use-input.cjs.map +3 -3
- package/build/hooks/border.cjs +25 -3
- package/build/hooks/border.cjs.map +2 -2
- package/build/hooks/dimensions.cjs +9 -2
- package/build/hooks/dimensions.cjs.map +2 -2
- package/build/hooks/duotone.cjs +4 -3
- package/build/hooks/duotone.cjs.map +2 -2
- package/build/hooks/gap.cjs +8 -2
- package/build/hooks/gap.cjs.map +2 -2
- package/build/hooks/layout-child.cjs +35 -13
- package/build/hooks/layout-child.cjs.map +2 -2
- package/build/hooks/layout.cjs +23 -1
- package/build/hooks/layout.cjs.map +2 -2
- package/build/hooks/states.cjs +7 -4
- package/build/hooks/states.cjs.map +2 -2
- package/build/layouts/constrained.cjs +8 -1
- package/build/layouts/constrained.cjs.map +2 -2
- package/build/layouts/flex.cjs +9 -0
- package/build/layouts/flex.cjs.map +2 -2
- package/build/layouts/flow.cjs +4 -1
- package/build/layouts/flow.cjs.map +2 -2
- package/build/layouts/grid.cjs +5 -1
- package/build/layouts/grid.cjs.map +2 -2
- package/build/private-apis.cjs +3 -1
- package/build/private-apis.cjs.map +2 -2
- package/build/store/actions.cjs +1 -1
- package/build/store/actions.cjs.map +2 -2
- package/build-module/components/block-inspector/index.mjs +9 -6
- package/build-module/components/block-inspector/index.mjs.map +2 -2
- package/build-module/components/block-keyboard-shortcuts/index.mjs +173 -0
- package/build-module/components/block-keyboard-shortcuts/index.mjs.map +7 -0
- package/build-module/components/block-list/block.mjs +10 -3
- package/build-module/components/block-list/block.mjs.map +2 -2
- package/build-module/components/block-list/index.mjs +6 -1
- package/build-module/components/block-list/index.mjs.map +2 -2
- package/build-module/components/block-list/use-block-props/use-focus-first-element.mjs +4 -0
- package/build-module/components/block-list/use-block-props/use-focus-first-element.mjs.map +2 -2
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.mjs +6 -7
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.mjs.map +2 -2
- package/build-module/components/block-parent-selector/index.mjs +101 -32
- package/build-module/components/block-parent-selector/index.mjs.map +2 -2
- package/build-module/components/block-popover/inbetween.mjs +2 -2
- package/build-module/components/block-popover/inbetween.mjs.map +2 -2
- package/build-module/components/block-preview/index.mjs +0 -4
- package/build-module/components/block-preview/index.mjs.map +2 -2
- package/build-module/components/block-styles/index.mjs +79 -35
- package/build-module/components/block-styles/index.mjs.map +2 -2
- package/build-module/components/block-visibility/constants.mjs.map +2 -2
- package/build-module/components/child-layout-control/index.mjs +5 -5
- package/build-module/components/child-layout-control/index.mjs.map +1 -1
- package/build-module/components/colors/with-colors.mjs +56 -72
- package/build-module/components/colors/with-colors.mjs.map +2 -2
- package/build-module/components/dimensions-tool/aspect-ratio-tool.mjs +4 -2
- package/build-module/components/dimensions-tool/aspect-ratio-tool.mjs.map +2 -2
- package/build-module/components/dimensions-tool/index.mjs +19 -17
- package/build-module/components/dimensions-tool/index.mjs.map +2 -2
- package/build-module/components/dimensions-tool/utils.mjs +35 -0
- package/build-module/components/dimensions-tool/utils.mjs.map +7 -0
- package/build-module/components/duotone-control/index.mjs +2 -0
- package/build-module/components/duotone-control/index.mjs.map +2 -2
- package/build-module/components/global-styles/advanced-panel.mjs +5 -2
- package/build-module/components/global-styles/advanced-panel.mjs.map +2 -2
- package/build-module/components/global-styles/border-panel.mjs +2 -5
- package/build-module/components/global-styles/border-panel.mjs.map +2 -2
- package/build-module/components/global-styles/color-panel.mjs +14 -2
- package/build-module/components/global-styles/color-panel.mjs.map +2 -2
- package/build-module/components/global-styles/dimensions-panel.mjs +9 -5
- package/build-module/components/global-styles/dimensions-panel.mjs.map +2 -2
- package/build-module/components/global-styles/filters-panel.mjs +16 -9
- package/build-module/components/global-styles/filters-panel.mjs.map +2 -2
- package/build-module/components/global-styles/shadow-panel-components.mjs +16 -11
- package/build-module/components/global-styles/shadow-panel-components.mjs.map +2 -2
- package/build-module/components/global-styles/utils.mjs +8 -0
- package/build-module/components/global-styles/utils.mjs.map +2 -2
- package/build-module/components/inner-blocks/index.mjs +5 -3
- package/build-module/components/inner-blocks/index.mjs.map +2 -2
- package/build-module/components/inserter/block-patterns-explorer/index.mjs +39 -22
- package/build-module/components/inserter/block-patterns-explorer/index.mjs.map +2 -2
- package/build-module/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.mjs +22 -56
- package/build-module/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.mjs.map +2 -2
- package/build-module/components/inserter/block-patterns-explorer/pattern-list.mjs +20 -45
- package/build-module/components/inserter/block-patterns-explorer/pattern-list.mjs.map +2 -2
- package/build-module/components/inserter/hooks/use-insertion-point.mjs +4 -4
- package/build-module/components/inserter/hooks/use-insertion-point.mjs.map +2 -2
- package/build-module/components/inserter/menu.mjs +19 -8
- package/build-module/components/inserter/menu.mjs.map +2 -2
- package/build-module/components/inserter/quick-inserter.mjs +30 -27
- package/build-module/components/inserter/quick-inserter.mjs.map +2 -2
- package/build-module/components/inspector-controls-tabs/styles-tab.mjs +1 -1
- package/build-module/components/inspector-controls-tabs/styles-tab.mjs.map +2 -2
- package/build-module/components/list-view/index.mjs +32 -5
- package/build-module/components/list-view/index.mjs.map +3 -3
- package/build-module/components/list-view/utils.mjs +13 -1
- package/build-module/components/list-view/utils.mjs.map +2 -2
- package/build-module/components/media-placeholder/index.mjs +3 -3
- package/build-module/components/media-placeholder/index.mjs.map +2 -2
- package/build-module/components/provider/index.mjs +6 -2
- package/build-module/components/provider/index.mjs.map +2 -2
- package/build-module/components/publish-date-time-picker/index.mjs +3 -2
- package/build-module/components/publish-date-time-picker/index.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/enter.mjs +46 -39
- package/build-module/components/rich-text/event-listeners/enter.mjs.map +2 -2
- package/build-module/components/rich-text/index.mjs +7 -5
- package/build-module/components/rich-text/index.mjs.map +2 -2
- package/build-module/components/rich-text/multiline.mjs +112 -72
- package/build-module/components/rich-text/multiline.mjs.map +2 -2
- package/build-module/components/url-input/index.mjs +2 -2
- package/build-module/components/url-input/index.mjs.map +1 -1
- package/build-module/components/writing-flow/use-input.mjs +66 -14
- package/build-module/components/writing-flow/use-input.mjs.map +3 -3
- package/build-module/hooks/border.mjs +26 -8
- package/build-module/hooks/border.mjs.map +2 -2
- package/build-module/hooks/dimensions.mjs +9 -2
- package/build-module/hooks/dimensions.mjs.map +2 -2
- package/build-module/hooks/duotone.mjs +8 -4
- package/build-module/hooks/duotone.mjs.map +2 -2
- package/build-module/hooks/gap.mjs +6 -1
- package/build-module/hooks/gap.mjs.map +2 -2
- package/build-module/hooks/layout-child.mjs +36 -13
- package/build-module/hooks/layout-child.mjs.map +2 -2
- package/build-module/hooks/layout.mjs +22 -1
- package/build-module/hooks/layout.mjs.map +2 -2
- package/build-module/hooks/states.mjs +8 -5
- package/build-module/hooks/states.mjs.map +2 -2
- package/build-module/layouts/constrained.mjs +8 -1
- package/build-module/layouts/constrained.mjs.map +2 -2
- package/build-module/layouts/flex.mjs +9 -0
- package/build-module/layouts/flex.mjs.map +2 -2
- package/build-module/layouts/flow.mjs +4 -1
- package/build-module/layouts/flow.mjs.map +2 -2
- package/build-module/layouts/grid.mjs +5 -1
- package/build-module/layouts/grid.mjs.map +2 -2
- package/build-module/private-apis.mjs +3 -1
- package/build-module/private-apis.mjs.map +2 -2
- package/build-module/store/actions.mjs +1 -1
- package/build-module/store/actions.mjs.map +2 -2
- package/build-style/style-rtl.css +108 -71
- package/build-style/style.css +108 -71
- package/build-types/components/block-visibility/constants.d.ts +4 -3
- package/build-types/components/block-visibility/constants.d.ts.map +1 -1
- package/package.json +43 -43
- package/src/components/background-image-control/README.md +122 -0
- package/src/components/block-edit-visually-button/README.md +39 -0
- package/src/components/block-editing-mode/README.md +72 -0
- package/src/components/block-inspector/index.js +6 -6
- package/src/components/block-keyboard-shortcuts/index.js +256 -0
- package/src/components/block-list/block.js +7 -0
- package/src/components/block-list/index.js +7 -1
- package/src/components/block-list/use-block-props/use-focus-first-element.js +5 -0
- package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +6 -8
- package/src/components/block-parent-selector/index.js +111 -30
- package/src/components/block-popover/README.md +10 -3
- package/src/components/block-popover/inbetween.js +8 -2
- package/src/components/block-popover/stories/index.story.jsx +143 -0
- package/src/components/block-preview/index.js +0 -2
- package/src/components/block-styles/index.js +95 -43
- package/src/components/block-styles/style.scss +5 -34
- package/src/components/block-tools/style.scss +94 -0
- package/src/components/block-visibility/constants.ts +4 -3
- package/src/components/child-layout-control/index.js +5 -5
- package/src/components/color-palette/test/__snapshots__/control.js.snap +3 -29
- package/src/components/colors/test/with-colors.js +6 -7
- package/src/components/colors/with-colors.js +79 -105
- package/src/components/dimensions-tool/aspect-ratio-tool.js +16 -4
- package/src/components/dimensions-tool/index.js +34 -22
- package/src/components/dimensions-tool/test/index.js +166 -2
- package/src/components/dimensions-tool/test/utils.js +51 -0
- package/src/components/dimensions-tool/utils.js +67 -0
- package/src/components/duotone-control/index.js +2 -0
- package/src/components/duotone-control/test/index.js +100 -0
- package/src/components/global-styles/advanced-panel.js +5 -2
- package/src/components/global-styles/border-panel.js +11 -9
- package/src/components/global-styles/color-panel.js +13 -1
- package/src/components/global-styles/dimensions-panel.js +17 -5
- package/src/components/global-styles/filters-panel.js +24 -10
- package/src/components/global-styles/shadow-panel-components.js +38 -11
- package/src/components/global-styles/test/border-panel.js +230 -0
- package/src/components/global-styles/test/color-panel.js +24 -0
- package/src/components/global-styles/test/dimensions-panel.js +98 -7
- package/src/components/global-styles/test/filters-panel.js +84 -0
- package/src/components/global-styles/test/utils.js +30 -0
- package/src/components/global-styles/utils.js +23 -0
- package/src/components/inner-blocks/index.js +11 -2
- package/src/components/inner-blocks/stories/index.story.jsx +246 -0
- package/src/components/inserter/block-patterns-explorer/index.js +24 -11
- package/src/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js +18 -56
- package/src/components/inserter/block-patterns-explorer/pattern-list.js +22 -47
- package/src/components/inserter/hooks/use-insertion-point.js +9 -4
- package/src/components/inserter/menu.js +23 -10
- package/src/components/inserter/quick-inserter.js +15 -13
- package/src/components/inserter/style.scss +44 -62
- package/src/components/inspector-controls-tabs/README.md +92 -0
- package/src/components/inspector-controls-tabs/styles-tab.js +1 -1
- package/src/components/link-control/test/index.js +5 -0
- package/src/components/list-view/index.js +50 -7
- package/src/components/list-view/utils.js +16 -1
- package/src/components/media-placeholder/index.js +9 -4
- package/src/components/plain-text/stories/index.story.jsx +3 -0
- package/src/components/provider/index.js +7 -1
- package/src/components/publish-date-time-picker/README.md +10 -0
- package/src/components/publish-date-time-picker/index.js +17 -14
- package/src/components/rich-text/event-listeners/enter.js +58 -45
- package/src/components/rich-text/index.js +9 -4
- package/src/components/rich-text/multiline.js +126 -86
- package/src/components/url-input/index.js +2 -2
- package/src/components/url-input/test/fixtures/validated-input-control-deprecation.js +27 -0
- package/src/components/url-input/test/index.js +5 -0
- package/src/components/url-popover/README.md +7 -0
- package/src/components/url-popover/stories/index.story.jsx +133 -47
- package/src/components/writing-flow/use-input.js +105 -15
- package/src/hooks/border.js +27 -8
- package/src/hooks/dimensions.js +8 -1
- package/src/hooks/duotone.js +23 -7
- package/src/hooks/gap.js +16 -0
- package/src/hooks/layout-child.js +41 -9
- package/src/hooks/layout.js +117 -71
- package/src/hooks/states.js +8 -5
- package/src/hooks/test/gap.js +31 -1
- package/src/hooks/test/layout-child.js +60 -1
- package/src/hooks/test/layout.js +27 -0
- package/src/layouts/constrained.js +9 -1
- package/src/layouts/flex.js +15 -0
- package/src/layouts/flow.js +4 -1
- package/src/layouts/grid.js +9 -1
- package/src/layouts/test/constrained.js +26 -0
- package/src/layouts/test/flow.js +26 -0
- package/src/layouts/test/grid.js +46 -0
- package/src/private-apis.js +2 -0
- package/src/store/actions.js +14 -1
- package/build/components/floating-toolbar/nav-up-icon.cjs +0 -52
- package/build/components/floating-toolbar/nav-up-icon.cjs.map +0 -7
- package/build/components/gradients/with-gradient.cjs +0 -36
- package/build/components/gradients/with-gradient.cjs.map +0 -7
- package/build/components/inserter-button/sparkles.cjs +0 -36
- package/build/components/inserter-button/sparkles.cjs.map +0 -7
- package/build-module/components/floating-toolbar/nav-up-icon.mjs +0 -31
- package/build-module/components/floating-toolbar/nav-up-icon.mjs.map +0 -7
- package/build-module/components/gradients/with-gradient.mjs +0 -11
- package/build-module/components/gradients/with-gradient.mjs.map +0 -7
- package/build-module/components/inserter-button/sparkles.mjs +0 -15
- package/build-module/components/inserter-button/sparkles.mjs.map +0 -7
- package/build-style/default-editor-styles-rtl.css +0 -68
- package/build-style/default-editor-styles.css +0 -68
- package/src/components/floating-toolbar/nav-up-icon.js +0 -22
- package/src/components/gradients/with-gradient.js +0 -9
- package/src/components/inserter-button/README.md +0 -62
- package/src/components/inserter-button/sparkles.js +0 -12
- package/src/default-editor-styles.scss +0 -25
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/rich-text/index.js"],
|
|
4
|
-
"sourcesContent": ["import clsx from 'clsx';\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\nimport {\n\tuseRef,\n\tuseState,\n\tuseCallback,\n\tuseEffect,\n\tuseMemo,\n\tforwardRef,\n\tuseContext,\n} from '@wordpress/element';\nimport { useDispatch, useRegistry, useSelect } from '@wordpress/data';\nimport { useMergeRefs, useInstanceId } from '@wordpress/compose';\nimport { privateApis as richTextPrivateApis } from '@wordpress/rich-text';\nimport { Popover } from '@wordpress/components';\nimport { getBlockBindingsSource } from '@wordpress/blocks';\nimport deprecated from '@wordpress/deprecated';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useBlockEditorAutocompleteProps } from '../autocomplete';\nimport { useBlockEditContext } from '../block-edit';\nimport {\n\tblockBindingsKey,\n\tblockEditingModeKey,\n\tisPreviewModeKey,\n} from '../block-edit/context';\nimport FormatToolbarContainer from './format-toolbar-container';\nimport { store as blockEditorStore } from '../../store';\nimport { useMarkPersistent } from './use-mark-persistent';\nimport { useEventListeners } from './event-listeners';\nimport FormatEdit from './format-edit';\nimport { getAllowedFormats } from './utils';\nimport { Content, valueToHTMLString } from './content';\nimport { withDeprecations } from './with-deprecations';\nimport BlockContext from '../block-context';\nimport { unlock } from '../../lock-unlock';\n\n// `RichTextShortcut` and `RichTextInputEvent` now live in\n// `@wordpress/rich-text` so they share the shortcut and input-event contexts\n// with standalone rich text fields. Re-exported below for back-compat (e.g.\n// `@wordpress/format-library` imports them from `@wordpress/block-editor`).\nconst {\n\tuseRichText,\n\tKeyboardShortcutContext,\n\tInputEventContext,\n\tRichTextShortcut,\n\tRichTextInputEvent,\n} = unlock( richTextPrivateApis );\n\nconst instanceIdKey = Symbol( 'instanceId' );\n\nexport function RichTextWrapper(\n\t{\n\t\tchildren,\n\t\ttagName = 'div',\n\t\tvalue: adjustedValue = '',\n\t\tonChange: adjustedOnChange,\n\t\tisSelected: originalIsSelected,\n\t\tmultiline,\n\t\tinlineToolbar,\n\t\twrapperClassName,\n\t\tautocompleters,\n\t\tonReplace,\n\t\tplaceholder,\n\t\tallowedFormats,\n\t\twithoutInteractiveFormatting,\n\t\tonRemove,\n\t\tonMerge,\n\t\tonSplit,\n\t\t__unstableOnSplitAtEnd: onSplitAtEnd,\n\t\t__unstableOnSplitAtDoubleLineEnd: onSplitAtDoubleLineEnd,\n\t\tidentifier,\n\t\tpreserveWhiteSpace,\n\t\t__unstablePastePlainText: pastePlainText,\n\t\t__unstableEmbedURLOnPaste,\n\t\t__unstableDisableFormats: disableFormats,\n\t\tdisableLineBreaks,\n\t\t__unstableAllowPrefixTransformations,\n\t\treadOnly,\n\t\t...props\n\t},\n\tforwardedRef\n) {\n\tif ( onSplit ) {\n\t\tdeprecated( 'wp.blockEditor.RichText onSplit prop', {\n\t\t\tsince: '6.4',\n\t\t\talternative: 'block.json support key: \"splitting\"',\n\t\t} );\n\t}\n\n\tconst instanceId = useInstanceId( RichTextWrapper );\n\tconst anchorRef = useRef();\n\tconst [ anchorElement, setAnchorElement ] = useState( null );\n\tconst context = useBlockEditContext();\n\tconst { clientId, isSelected: isBlockSelected, name: blockName } = context;\n\tconst blockBindings = context[ blockBindingsKey ];\n\tconst hasDefaultEditingMode = context[ blockEditingModeKey ] === 'default';\n\tconst blockContext = useContext( BlockContext );\n\tconst registry = useRegistry();\n\tconst selector = ( select ) => {\n\t\t// Avoid subscribing to the block editor store if the block is not\n\t\t// selected.\n\t\tif ( ! isBlockSelected ) {\n\t\t\treturn { isSelected: false };\n\t\t}\n\n\t\tconst { getSelectionStart, getSelectionEnd } =\n\t\t\tselect( blockEditorStore );\n\t\tconst selectionStart = getSelectionStart();\n\t\tconst selectionEnd = getSelectionEnd();\n\n\t\tlet isSelected;\n\n\t\tif ( originalIsSelected === undefined ) {\n\t\t\tisSelected =\n\t\t\t\tselectionStart.clientId === clientId &&\n\t\t\t\tselectionEnd.clientId === clientId &&\n\t\t\t\t( identifier\n\t\t\t\t\t? selectionStart.attributeKey === identifier\n\t\t\t\t\t: selectionStart[ instanceIdKey ] === instanceId );\n\t\t} else if ( originalIsSelected ) {\n\t\t\tisSelected = selectionStart.clientId === clientId;\n\t\t}\n\n\t\treturn {\n\t\t\tselectionStart: isSelected ? selectionStart.offset : undefined,\n\t\t\tselectionEnd: isSelected ? selectionEnd.offset : undefined,\n\t\t\tisSelected,\n\t\t};\n\t};\n\tconst { selectionStart, selectionEnd, isSelected } = useSelect( selector, [\n\t\tclientId,\n\t\tidentifier,\n\t\tinstanceId,\n\t\toriginalIsSelected,\n\t\tisBlockSelected,\n\t] );\n\n\tconst { disableBoundBlock, bindingsPlaceholder, bindingsLabel } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! blockBindings?.[ identifier ] ) {\n\t\t\t\treturn {};\n\t\t\t}\n\n\t\t\tconst { __experimentalBlockBindingsSupportedAttributes } =\n\t\t\t\tselect( blockEditorStore ).getSettings();\n\n\t\t\tconst bindableAttributes =\n\t\t\t\t__experimentalBlockBindingsSupportedAttributes?.[ blockName ];\n\n\t\t\tif ( ! bindableAttributes ) {\n\t\t\t\treturn {};\n\t\t\t}\n\n\t\t\tconst relatedBinding = blockBindings[ identifier ];\n\t\t\tconst blockBindingsSource = getBlockBindingsSource(\n\t\t\t\trelatedBinding.source\n\t\t\t);\n\t\t\tconst blockBindingsContext = {};\n\t\t\tif ( blockBindingsSource?.usesContext?.length ) {\n\t\t\t\tfor ( const key of blockBindingsSource.usesContext ) {\n\t\t\t\t\tblockBindingsContext[ key ] = blockContext[ key ];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst _disableBoundBlock =\n\t\t\t\t! blockBindingsSource?.canUserEditValue?.( {\n\t\t\t\t\tselect,\n\t\t\t\t\tcontext: blockBindingsContext,\n\t\t\t\t\targs: relatedBinding.args,\n\t\t\t\t} );\n\n\t\t\t// Don't modify placeholders if value is not empty.\n\t\t\tif ( adjustedValue.length > 0 ) {\n\t\t\t\treturn {\n\t\t\t\t\tdisableBoundBlock: _disableBoundBlock,\n\t\t\t\t\t// Null values will make them fall back to the default behavior.\n\t\t\t\t\tbindingsPlaceholder: null,\n\t\t\t\t\tbindingsLabel: null,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { getBlockAttributes } = select( blockEditorStore );\n\t\t\tconst blockAttributes = getBlockAttributes( clientId );\n\t\t\tlet clientSideFieldLabel = null;\n\t\t\tif ( blockBindingsSource?.getFieldsList ) {\n\t\t\t\tconst fieldsItems = blockBindingsSource.getFieldsList( {\n\t\t\t\t\tselect,\n\t\t\t\t\tcontext: blockBindingsContext,\n\t\t\t\t} );\n\t\t\t\tclientSideFieldLabel = fieldsItems?.find( ( item ) =>\n\t\t\t\t\tfastDeepEqual( item.args, relatedBinding?.args )\n\t\t\t\t)?.label;\n\t\t\t}\n\n\t\t\tconst bindingKey =\n\t\t\t\tclientSideFieldLabel ?? blockBindingsSource?.label;\n\n\t\t\tconst _bindingsPlaceholder = _disableBoundBlock\n\t\t\t\t? bindingKey\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: %s: connected field label or source label */\n\t\t\t\t\t\t__( 'Add %s' ),\n\t\t\t\t\t\tbindingKey\n\t\t\t\t );\n\t\t\tconst _bindingsLabel = _disableBoundBlock\n\t\t\t\t? relatedBinding?.args?.key || blockBindingsSource?.label\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: %s: source label or key */\n\t\t\t\t\t\t__( 'Empty %s; start writing to edit its value' ),\n\t\t\t\t\t\trelatedBinding?.args?.key || blockBindingsSource?.label\n\t\t\t\t );\n\n\t\t\treturn {\n\t\t\t\tdisableBoundBlock: _disableBoundBlock,\n\t\t\t\tbindingsPlaceholder:\n\t\t\t\t\tblockAttributes?.placeholder || _bindingsPlaceholder,\n\t\t\t\tbindingsLabel: _bindingsLabel,\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tblockBindings,\n\t\t\tidentifier,\n\t\t\tblockName,\n\t\t\tadjustedValue,\n\t\t\tclientId,\n\t\t\tblockContext,\n\t\t]\n\t);\n\tconst isInsidePatternOverrides = !! blockContext?.[ 'pattern/overrides' ];\n\tconst hasOverrideEnabled =\n\t\tblockBindings?.__default?.source === 'core/pattern-overrides';\n\n\tconst shouldDisableForPattern =\n\t\tisInsidePatternOverrides && ! hasOverrideEnabled;\n\n\tconst shouldDisableEditing =\n\t\treadOnly || disableBoundBlock || shouldDisableForPattern;\n\n\t// Whether the wrapper is the editing host, which depends on the selected\n\t// block, not necessarily this one. Only the selected, default-mode block\n\t// can be it, so others skip the subscription entirely.\n\tconst isEditingHost = useSelect(\n\t\t( select ) => {\n\t\t\tif (\n\t\t\t\tshouldDisableEditing ||\n\t\t\t\t! hasDefaultEditingMode ||\n\t\t\t\t! isBlockSelected\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst { getSelectedBlockClientId, canHostEditableRoot } = unlock(\n\t\t\t\tselect( blockEditorStore )\n\t\t\t);\n\t\t\treturn canHostEditableRoot( getSelectedBlockClientId() );\n\t\t},\n\t\t[ shouldDisableEditing, hasDefaultEditingMode, isBlockSelected ]\n\t);\n\n\tconst { getSelectionStart, getSelectionEnd, getBlockRootClientId } =\n\t\tuseSelect( blockEditorStore );\n\tconst { selectionChange } = useDispatch( blockEditorStore );\n\tconst adjustedAllowedFormats = getAllowedFormats( {\n\t\tallowedFormats,\n\t\tdisableFormats,\n\t} );\n\tconst hasFormats =\n\t\t! adjustedAllowedFormats || adjustedAllowedFormats.length > 0;\n\n\tconst onSelectionChange = useCallback(\n\t\t( start, end ) => {\n\t\t\tconst selection = {};\n\t\t\tconst unset = start === undefined && end === undefined;\n\n\t\t\tconst baseSelection = {\n\t\t\t\tclientId,\n\t\t\t\t[ identifier ? 'attributeKey' : instanceIdKey ]: identifier\n\t\t\t\t\t? identifier\n\t\t\t\t\t: instanceId,\n\t\t\t};\n\n\t\t\tif ( typeof start === 'number' || unset ) {\n\t\t\t\t// If we are only setting the start (or the end below), which\n\t\t\t\t// means a partial selection, and we're not updating a selection\n\t\t\t\t// with the same client ID, abort. This means the selected block\n\t\t\t\t// is a parent block.\n\t\t\t\tif (\n\t\t\t\t\tend === undefined &&\n\t\t\t\t\tgetBlockRootClientId( clientId ) !==\n\t\t\t\t\t\tgetBlockRootClientId( getSelectionEnd().clientId )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tselection.start = {\n\t\t\t\t\t...baseSelection,\n\t\t\t\t\toffset: start,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif ( typeof end === 'number' || unset ) {\n\t\t\t\tif (\n\t\t\t\t\tstart === undefined &&\n\t\t\t\t\tgetBlockRootClientId( clientId ) !==\n\t\t\t\t\t\tgetBlockRootClientId( getSelectionStart().clientId )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tselection.end = {\n\t\t\t\t\t...baseSelection,\n\t\t\t\t\toffset: end,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tselectionChange( selection );\n\t\t},\n\t\t[\n\t\t\tclientId,\n\t\t\tgetBlockRootClientId,\n\t\t\tgetSelectionEnd,\n\t\t\tgetSelectionStart,\n\t\t\tidentifier,\n\t\t\tinstanceId,\n\t\t\tselectionChange,\n\t\t]\n\t);\n\n\tconst {\n\t\tvalue,\n\t\tgetValue,\n\t\tonChange,\n\t\tref: richTextRef,\n\t\tformatTypes,\n\t} = useRichText( {\n\t\tvalue: adjustedValue,\n\t\tonChange: adjustedOnChange,\n\t\tselectionStart,\n\t\tselectionEnd,\n\t\tonSelectionChange,\n\t\tplaceholder: bindingsPlaceholder || placeholder,\n\t\t__unstableIsSelected: isSelected,\n\t\t__unstableDisableFormats: disableFormats,\n\t\tpreserveWhiteSpace,\n\t\t__unstableDependencies: [ tagName ],\n\t\tallowedFormats: adjustedAllowedFormats,\n\t\twithoutInteractiveFormatting,\n\t\t__unstableFormatTypeHandlerContext: useMemo(\n\t\t\t() => ( {\n\t\t\t\trichTextIdentifier: identifier,\n\t\t\t\tblockClientId: clientId,\n\t\t\t} ),\n\t\t\t[ identifier, clientId ]\n\t\t),\n\t} );\n\tconst autocompleteProps = useBlockEditorAutocompleteProps( {\n\t\tonReplace,\n\t\tcompleters: autocompleters,\n\t\trecord: value,\n\t\tonChange,\n\t} );\n\n\t// While a focused editing host owns the selection (the block supports\n\t// `editableRoot`), ARIA attributes describing the autocomplete state must\n\t// be mirrored onto the host: assistive technology resolves them relative\n\t// to the focused element.\n\tconst {\n\t\t'aria-autocomplete': ariaAutocomplete,\n\t\t'aria-haspopup': ariaHasPopup,\n\t\t'aria-controls': ariaControls,\n\t\t'aria-owns': ariaOwns,\n\t\t'aria-activedescendant': ariaActiveDescendant,\n\t} = autocompleteProps;\n\tuseEffect( () => {\n\t\tif ( ! isSelected ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst host = anchorRef.current?.parentElement?.closest(\n\t\t\t'[contenteditable=\"true\"]'\n\t\t);\n\n\t\tif ( ! host ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst attributes = {\n\t\t\t'aria-autocomplete': ariaAutocomplete,\n\t\t\t'aria-haspopup': ariaHasPopup,\n\t\t\t'aria-controls': ariaControls,\n\t\t\t'aria-owns': ariaOwns,\n\t\t\t'aria-activedescendant': ariaActiveDescendant,\n\t\t};\n\n\t\tfor ( const [ key, value_ ] of Object.entries( attributes ) ) {\n\t\t\tif ( value_ === undefined ) {\n\t\t\t\thost.removeAttribute( key );\n\t\t\t} else {\n\t\t\t\thost.setAttribute( key, value_ );\n\t\t\t}\n\t\t}\n\n\t\treturn () => {\n\t\t\tfor ( const key of Object.keys( attributes ) ) {\n\t\t\t\thost.removeAttribute( key );\n\t\t\t}\n\t\t};\n\t}, [\n\t\tisSelected,\n\t\tariaAutocomplete,\n\t\tariaHasPopup,\n\t\tariaControls,\n\t\tariaOwns,\n\t\tariaActiveDescendant,\n\t] );\n\n\tuseMarkPersistent( { html: adjustedValue, value } );\n\n\tconst keyboardShortcuts = useRef( new Set() );\n\tconst inputEvents = useRef( new Set() );\n\n\tfunction onFocus() {\n\t\tanchorRef.current?.focus();\n\t}\n\n\t// Setting tabIndex to 0 is unnecessary, the element is already focusable\n\t// because it's contentEditable. This also fixes a Safari bug where it's\n\t// not possible to Shift+Click multi select blocks when Shift Clicking\n\t// into an element with tabIndex because Safari will focus the element.\n\t// However, Safari will correctly ignore nested contentEditable elements.\n\t// While the writing flow wrapper is contentEditable (the selected block\n\t// supports `editableRoot`), nested editable elements are no longer\n\t// focusable areas on their own, so an explicit tabIndex restores their\n\t// focusability.\n\tlet tabIndex = props.tabIndex;\n\tif ( isEditingHost ) {\n\t\ttabIndex = props.tabIndex ?? 0;\n\t} else if ( ! shouldDisableEditing && props.tabIndex === 0 ) {\n\t\ttabIndex = null;\n\t}\n\n\tconst TagName = tagName;\n\treturn (\n\t\t<>\n\t\t\t{ isSelected && (\n\t\t\t\t<KeyboardShortcutContext.Provider value={ keyboardShortcuts }>\n\t\t\t\t\t<InputEventContext.Provider value={ inputEvents }>\n\t\t\t\t\t\t<Popover.__unstableSlotNameProvider value=\"__unstable-block-tools-after\">\n\t\t\t\t\t\t\t{ children &&\n\t\t\t\t\t\t\t\tchildren( { value, onChange, onFocus } ) }\n\n\t\t\t\t\t\t\t<FormatEdit\n\t\t\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\t\tonFocus={ onFocus }\n\t\t\t\t\t\t\t\tformatTypes={ formatTypes }\n\t\t\t\t\t\t\t\tforwardedRef={ anchorRef }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</Popover.__unstableSlotNameProvider>\n\t\t\t\t\t</InputEventContext.Provider>\n\t\t\t\t</KeyboardShortcutContext.Provider>\n\t\t\t) }\n\t\t\t{ isSelected && hasFormats && (\n\t\t\t\t<FormatToolbarContainer\n\t\t\t\t\tinline={ inlineToolbar }\n\t\t\t\t\teditableContentElement={ anchorElement }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<TagName\n\t\t\t\t// Overridable props.\n\t\t\t\trole=\"textbox\"\n\t\t\t\taria-multiline={ ! disableLineBreaks }\n\t\t\t\taria-readonly={ shouldDisableEditing }\n\t\t\t\t{ ...props }\n\t\t\t\t// Unset draggable (coming from block props) for contentEditable\n\t\t\t\t// elements because it will interfere with multi block selection\n\t\t\t\t// when the contentEditable and draggable elements are the same\n\t\t\t\t// element.\n\t\t\t\tdraggable={ undefined }\n\t\t\t\taria-label={\n\t\t\t\t\tbindingsLabel || props[ 'aria-label' ] || placeholder\n\t\t\t\t}\n\t\t\t\t{ ...autocompleteProps }\n\t\t\t\tref={ useMergeRefs( [\n\t\t\t\t\t// Rich text ref must be first because its focus listener\n\t\t\t\t\t// must be set up before any other ref calls .focus() on\n\t\t\t\t\t// mount.\n\t\t\t\t\trichTextRef,\n\t\t\t\t\tforwardedRef,\n\t\t\t\t\tautocompleteProps.ref,\n\t\t\t\t\tprops.ref,\n\t\t\t\t\tuseEventListeners( {\n\t\t\t\t\t\tregistry,\n\t\t\t\t\t\tgetValue,\n\t\t\t\t\t\tonChange,\n\t\t\t\t\t\t__unstableAllowPrefixTransformations,\n\t\t\t\t\t\tformatTypes,\n\t\t\t\t\t\tonReplace,\n\t\t\t\t\t\tselectionChange,\n\t\t\t\t\t\tisSelected,\n\t\t\t\t\t\tdisableFormats,\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\ttagName,\n\t\t\t\t\t\tonSplit,\n\t\t\t\t\t\t__unstableEmbedURLOnPaste,\n\t\t\t\t\t\tpastePlainText,\n\t\t\t\t\t\tonMerge,\n\t\t\t\t\t\tonRemove,\n\t\t\t\t\t\tdisableLineBreaks,\n\t\t\t\t\t\tonSplitAtEnd,\n\t\t\t\t\t\tonSplitAtDoubleLineEnd,\n\t\t\t\t\t\tkeyboardShortcuts,\n\t\t\t\t\t\tinputEvents,\n\t\t\t\t\t} ),\n\t\t\t\t\tanchorRef,\n\t\t\t\t\tsetAnchorElement,\n\t\t\t\t] ) }\n\t\t\t\tcontentEditable={ ! shouldDisableEditing }\n\t\t\t\tsuppressContentEditableWarning\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'block-editor-rich-text__editable',\n\t\t\t\t\tprops.className,\n\t\t\t\t\t'rich-text'\n\t\t\t\t) }\n\t\t\t\ttabIndex={ tabIndex }\n\t\t\t\tdata-wp-block-attribute-key={ identifier }\n\t\t\t/>\n\t\t</>\n\t);\n}\n\n// This is the private API for the RichText component.\n// It allows access to all props, not just the public ones.\nexport const PrivateRichText = withDeprecations(\n\tforwardRef( RichTextWrapper )\n);\n\nPrivateRichText.Content = Content;\nPrivateRichText.isEmpty = ( value ) => {\n\treturn ! value || value.length === 0;\n};\n\n// This is the public API for the RichText component.\n// We wrap the PrivateRichText component to hide some props from the public API.\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/rich-text/README.md\n */\nconst PublicForwardedRichTextContainer = forwardRef( ( props, ref ) => {\n\tconst context = useBlockEditContext();\n\tconst isPreviewMode = context[ isPreviewModeKey ];\n\n\tif ( isPreviewMode ) {\n\t\t// Remove all non-content props.\n\t\tconst {\n\t\t\tchildren,\n\t\t\ttagName: Tag = 'div',\n\t\t\tvalue,\n\t\t\tonChange,\n\t\t\tisSelected,\n\t\t\tmultiline,\n\t\t\tinlineToolbar,\n\t\t\twrapperClassName,\n\t\t\tautocompleters,\n\t\t\tonReplace,\n\t\t\tplaceholder,\n\t\t\tallowedFormats,\n\t\t\twithoutInteractiveFormatting,\n\t\t\tonRemove,\n\t\t\tonMerge,\n\t\t\tonSplit,\n\t\t\t__unstableOnSplitAtEnd,\n\t\t\t__unstableOnSplitAtDoubleLineEnd,\n\t\t\tidentifier,\n\t\t\tpreserveWhiteSpace,\n\t\t\t__unstablePastePlainText,\n\t\t\t__unstableEmbedURLOnPaste,\n\t\t\t__unstableDisableFormats,\n\t\t\tdisableLineBreaks,\n\t\t\t__unstableAllowPrefixTransformations,\n\t\t\treadOnly,\n\t\t\t...contentProps\n\t\t} = props;\n\t\treturn (\n\t\t\t<Tag\n\t\t\t\tref={ ref }\n\t\t\t\t{ ...contentProps }\n\t\t\t\tdangerouslySetInnerHTML={ {\n\t\t\t\t\t__html: valueToHTMLString( value, multiline ) || '<br>',\n\t\t\t\t} }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn <PrivateRichText ref={ ref } { ...props } readOnly={ false } />;\n} );\n\nPublicForwardedRichTextContainer.Content = Content;\nPublicForwardedRichTextContainer.isEmpty = ( value ) => {\n\treturn ! value || value.length === 0;\n};\n\nexport default PublicForwardedRichTextContainer;\nexport { RichTextShortcut };\nexport { RichTextToolbarButton } from './toolbar-button';\nexport { RichTextInputEvent as __unstableRichTextInputEvent };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AACjB,iBAA0B;AAC1B,qBAQO;AACP,kBAAoD;AACpD,qBAA4C;AAC5C,uBAAmD;AACnD,wBAAwB;AACxB,oBAAuC;AACvC,wBAAuB;AACvB,kBAA4B;AAC5B,0BAAgD;AAChD,wBAAoC;AACpC,qBAIO;AACP,sCAAmC;AACnC,mBAA0C;AAC1C,iCAAkC;AAClC,6BAAkC;AAClC,yBAAuB;AACvB,mBAAkC;AAClC,qBAA2C;AAC3C,+BAAiC;AACjC,2BAAyB;AACzB,yBAAuB;
|
|
4
|
+
"sourcesContent": ["import clsx from 'clsx';\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\nimport {\n\tuseRef,\n\tuseState,\n\tuseCallback,\n\tuseEffect,\n\tuseMemo,\n\tforwardRef,\n\tuseContext,\n} from '@wordpress/element';\nimport { useDispatch, useRegistry, useSelect } from '@wordpress/data';\nimport { useMergeRefs, useInstanceId } from '@wordpress/compose';\nimport { privateApis as richTextPrivateApis } from '@wordpress/rich-text';\nimport { Popover } from '@wordpress/components';\nimport { getBlockBindingsSource } from '@wordpress/blocks';\nimport deprecated from '@wordpress/deprecated';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useBlockEditorAutocompleteProps } from '../autocomplete';\nimport { useBlockEditContext } from '../block-edit';\nimport {\n\tblockBindingsKey,\n\tblockEditingModeKey,\n\tisPreviewModeKey,\n} from '../block-edit/context';\nimport FormatToolbarContainer from './format-toolbar-container';\nimport { store as blockEditorStore } from '../../store';\nimport { useMarkPersistent } from './use-mark-persistent';\nimport { useEventListeners } from './event-listeners';\nimport FormatEdit from './format-edit';\nimport { getAllowedFormats } from './utils';\nimport { Content, valueToHTMLString } from './content';\nimport { withDeprecations } from './with-deprecations';\nimport BlockContext from '../block-context';\nimport { unlock } from '../../lock-unlock';\nimport { PrivateBlockContext } from '../block-list/private-block-context';\n\n// `RichTextShortcut` and `RichTextInputEvent` now live in\n// `@wordpress/rich-text` so they share the shortcut and input-event contexts\n// with standalone rich text fields. Re-exported below for back-compat (e.g.\n// `@wordpress/format-library` imports them from `@wordpress/block-editor`).\nconst {\n\tuseRichText,\n\tKeyboardShortcutContext,\n\tInputEventContext,\n\tRichTextShortcut,\n\tRichTextInputEvent,\n} = unlock( richTextPrivateApis );\n\nconst instanceIdKey = Symbol( 'instanceId' );\n\nfunction RichTextWrapper(\n\t{\n\t\tchildren,\n\t\ttagName = 'div',\n\t\tvalue: adjustedValue = '',\n\t\tonChange: adjustedOnChange,\n\t\tisSelected: originalIsSelected,\n\t\tmultiline,\n\t\tinlineToolbar,\n\t\twrapperClassName,\n\t\tautocompleters,\n\t\tonReplace,\n\t\tplaceholder,\n\t\tallowedFormats,\n\t\twithoutInteractiveFormatting,\n\t\tonRemove,\n\t\tonMerge,\n\t\tonSplit,\n\t\t__unstableOnSplitAtEnd: onSplitAtEnd,\n\t\t__unstableOnSplitAtDoubleLineEnd: onSplitAtDoubleLineEnd,\n\t\tidentifier,\n\t\tpreserveWhiteSpace,\n\t\t__unstablePastePlainText: pastePlainText,\n\t\t__unstableEmbedURLOnPaste,\n\t\t__unstableDisableFormats: disableFormats,\n\t\tdisableLineBreaks,\n\t\t__unstableAllowPrefixTransformations,\n\t\treadOnly,\n\t\t...props\n\t},\n\tforwardedRef\n) {\n\tif ( onSplit ) {\n\t\tdeprecated( 'wp.blockEditor.RichText onSplit prop', {\n\t\t\tsince: '6.4',\n\t\t\talternative: 'block.json support key: \"splitting\"',\n\t\t} );\n\t}\n\n\tconst { supportsSplitting } = useContext( PrivateBlockContext );\n\tconst instanceId = useInstanceId( RichTextWrapper );\n\tconst anchorRef = useRef();\n\tconst [ anchorElement, setAnchorElement ] = useState( null );\n\tconst context = useBlockEditContext();\n\tconst { clientId, isSelected: isBlockSelected, name: blockName } = context;\n\tconst blockBindings = context[ blockBindingsKey ];\n\tconst hasDefaultEditingMode = context[ blockEditingModeKey ] === 'default';\n\tconst blockContext = useContext( BlockContext );\n\tconst registry = useRegistry();\n\tconst selector = ( select ) => {\n\t\t// Avoid subscribing to the block editor store if the block is not\n\t\t// selected.\n\t\tif ( ! isBlockSelected ) {\n\t\t\treturn { isSelected: false };\n\t\t}\n\n\t\tconst { getSelectionStart, getSelectionEnd } =\n\t\t\tselect( blockEditorStore );\n\t\tconst selectionStart = getSelectionStart();\n\t\tconst selectionEnd = getSelectionEnd();\n\n\t\tlet isSelected;\n\n\t\tif ( originalIsSelected === undefined ) {\n\t\t\tisSelected =\n\t\t\t\tselectionStart.clientId === clientId &&\n\t\t\t\tselectionEnd.clientId === clientId &&\n\t\t\t\t( identifier\n\t\t\t\t\t? selectionStart.attributeKey === identifier\n\t\t\t\t\t: selectionStart[ instanceIdKey ] === instanceId );\n\t\t} else if ( originalIsSelected ) {\n\t\t\tisSelected = selectionStart.clientId === clientId;\n\t\t}\n\n\t\treturn {\n\t\t\tselectionStart: isSelected ? selectionStart.offset : undefined,\n\t\t\tselectionEnd: isSelected ? selectionEnd.offset : undefined,\n\t\t\tisSelected,\n\t\t};\n\t};\n\tconst { selectionStart, selectionEnd, isSelected } = useSelect( selector, [\n\t\tclientId,\n\t\tidentifier,\n\t\tinstanceId,\n\t\toriginalIsSelected,\n\t\tisBlockSelected,\n\t] );\n\n\tconst { disableBoundBlock, bindingsPlaceholder, bindingsLabel } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! blockBindings?.[ identifier ] ) {\n\t\t\t\treturn {};\n\t\t\t}\n\n\t\t\tconst { __experimentalBlockBindingsSupportedAttributes } =\n\t\t\t\tselect( blockEditorStore ).getSettings();\n\n\t\t\tconst bindableAttributes =\n\t\t\t\t__experimentalBlockBindingsSupportedAttributes?.[ blockName ];\n\n\t\t\tif ( ! bindableAttributes ) {\n\t\t\t\treturn {};\n\t\t\t}\n\n\t\t\tconst relatedBinding = blockBindings[ identifier ];\n\t\t\tconst blockBindingsSource = getBlockBindingsSource(\n\t\t\t\trelatedBinding.source\n\t\t\t);\n\t\t\tconst blockBindingsContext = {};\n\t\t\tif ( blockBindingsSource?.usesContext?.length ) {\n\t\t\t\tfor ( const key of blockBindingsSource.usesContext ) {\n\t\t\t\t\tblockBindingsContext[ key ] = blockContext[ key ];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst _disableBoundBlock =\n\t\t\t\t! blockBindingsSource?.canUserEditValue?.( {\n\t\t\t\t\tselect,\n\t\t\t\t\tcontext: blockBindingsContext,\n\t\t\t\t\targs: relatedBinding.args,\n\t\t\t\t} );\n\n\t\t\t// Don't modify placeholders if value is not empty.\n\t\t\tif ( adjustedValue.length > 0 ) {\n\t\t\t\treturn {\n\t\t\t\t\tdisableBoundBlock: _disableBoundBlock,\n\t\t\t\t\t// Null values will make them fall back to the default behavior.\n\t\t\t\t\tbindingsPlaceholder: null,\n\t\t\t\t\tbindingsLabel: null,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst { getBlockAttributes } = select( blockEditorStore );\n\t\t\tconst blockAttributes = getBlockAttributes( clientId );\n\t\t\tlet clientSideFieldLabel = null;\n\t\t\tif ( blockBindingsSource?.getFieldsList ) {\n\t\t\t\tconst fieldsItems = blockBindingsSource.getFieldsList( {\n\t\t\t\t\tselect,\n\t\t\t\t\tcontext: blockBindingsContext,\n\t\t\t\t} );\n\t\t\t\tclientSideFieldLabel = fieldsItems?.find( ( item ) =>\n\t\t\t\t\tfastDeepEqual( item.args, relatedBinding?.args )\n\t\t\t\t)?.label;\n\t\t\t}\n\n\t\t\tconst bindingKey =\n\t\t\t\tclientSideFieldLabel ?? blockBindingsSource?.label;\n\n\t\t\tconst _bindingsPlaceholder = _disableBoundBlock\n\t\t\t\t? bindingKey\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: %s: connected field label or source label */\n\t\t\t\t\t\t__( 'Add %s' ),\n\t\t\t\t\t\tbindingKey\n\t\t\t\t );\n\t\t\tconst _bindingsLabel = _disableBoundBlock\n\t\t\t\t? relatedBinding?.args?.key || blockBindingsSource?.label\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: %s: source label or key */\n\t\t\t\t\t\t__( 'Empty %s; start writing to edit its value' ),\n\t\t\t\t\t\trelatedBinding?.args?.key || blockBindingsSource?.label\n\t\t\t\t );\n\n\t\t\treturn {\n\t\t\t\tdisableBoundBlock: _disableBoundBlock,\n\t\t\t\tbindingsPlaceholder:\n\t\t\t\t\tblockAttributes?.placeholder || _bindingsPlaceholder,\n\t\t\t\tbindingsLabel: _bindingsLabel,\n\t\t\t};\n\t\t},\n\t\t[\n\t\t\tblockBindings,\n\t\t\tidentifier,\n\t\t\tblockName,\n\t\t\tadjustedValue,\n\t\t\tclientId,\n\t\t\tblockContext,\n\t\t]\n\t);\n\tconst isInsidePatternOverrides = !! blockContext?.[ 'pattern/overrides' ];\n\tconst hasOverrideEnabled =\n\t\tblockBindings?.__default?.source === 'core/pattern-overrides';\n\n\tconst shouldDisableForPattern =\n\t\tisInsidePatternOverrides && ! hasOverrideEnabled;\n\n\tconst shouldDisableEditing =\n\t\treadOnly || disableBoundBlock || shouldDisableForPattern;\n\n\t// Whether the wrapper is the editing host, which depends on the selected\n\t// block, not necessarily this one. Only the selected, default-mode block\n\t// can be it, so others skip the subscription entirely.\n\tconst isEditingHost = useSelect(\n\t\t( select ) => {\n\t\t\tif (\n\t\t\t\tshouldDisableEditing ||\n\t\t\t\t! hasDefaultEditingMode ||\n\t\t\t\t! isBlockSelected\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst { getSelectedBlockClientId, canHostEditableRoot } = unlock(\n\t\t\t\tselect( blockEditorStore )\n\t\t\t);\n\t\t\treturn canHostEditableRoot( getSelectedBlockClientId() );\n\t\t},\n\t\t[ shouldDisableEditing, hasDefaultEditingMode, isBlockSelected ]\n\t);\n\n\tconst { getSelectionStart, getSelectionEnd, getBlockRootClientId } =\n\t\tuseSelect( blockEditorStore );\n\tconst { selectionChange } = useDispatch( blockEditorStore );\n\tconst adjustedAllowedFormats = getAllowedFormats( {\n\t\tallowedFormats,\n\t\tdisableFormats,\n\t} );\n\tconst hasFormats =\n\t\t! adjustedAllowedFormats || adjustedAllowedFormats.length > 0;\n\n\tconst onSelectionChange = useCallback(\n\t\t( start, end ) => {\n\t\t\tconst selection = {};\n\t\t\tconst unset = start === undefined && end === undefined;\n\n\t\t\tconst baseSelection = {\n\t\t\t\tclientId,\n\t\t\t\t[ identifier ? 'attributeKey' : instanceIdKey ]: identifier\n\t\t\t\t\t? identifier\n\t\t\t\t\t: instanceId,\n\t\t\t};\n\n\t\t\tif ( typeof start === 'number' || unset ) {\n\t\t\t\t// If we are only setting the start (or the end below), which\n\t\t\t\t// means a partial selection, and we're not updating a selection\n\t\t\t\t// with the same client ID, abort. This means the selected block\n\t\t\t\t// is a parent block.\n\t\t\t\tif (\n\t\t\t\t\tend === undefined &&\n\t\t\t\t\tgetBlockRootClientId( clientId ) !==\n\t\t\t\t\t\tgetBlockRootClientId( getSelectionEnd().clientId )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tselection.start = {\n\t\t\t\t\t...baseSelection,\n\t\t\t\t\toffset: start,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif ( typeof end === 'number' || unset ) {\n\t\t\t\tif (\n\t\t\t\t\tstart === undefined &&\n\t\t\t\t\tgetBlockRootClientId( clientId ) !==\n\t\t\t\t\t\tgetBlockRootClientId( getSelectionStart().clientId )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tselection.end = {\n\t\t\t\t\t...baseSelection,\n\t\t\t\t\toffset: end,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tselectionChange( selection );\n\t\t},\n\t\t[\n\t\t\tclientId,\n\t\t\tgetBlockRootClientId,\n\t\t\tgetSelectionEnd,\n\t\t\tgetSelectionStart,\n\t\t\tidentifier,\n\t\t\tinstanceId,\n\t\t\tselectionChange,\n\t\t]\n\t);\n\n\tconst {\n\t\tvalue,\n\t\tgetValue,\n\t\tonChange,\n\t\tref: richTextRef,\n\t\tformatTypes,\n\t} = useRichText( {\n\t\tvalue: adjustedValue,\n\t\tonChange: adjustedOnChange,\n\t\tselectionStart,\n\t\tselectionEnd,\n\t\tonSelectionChange,\n\t\tplaceholder: bindingsPlaceholder || placeholder,\n\t\t__unstableIsSelected: isSelected,\n\t\t__unstableDisableFormats: disableFormats,\n\t\tpreserveWhiteSpace,\n\t\t__unstableDependencies: [ tagName ],\n\t\tallowedFormats: adjustedAllowedFormats,\n\t\twithoutInteractiveFormatting,\n\t\t__unstableFormatTypeHandlerContext: useMemo(\n\t\t\t() => ( {\n\t\t\t\trichTextIdentifier: identifier,\n\t\t\t\tblockClientId: clientId,\n\t\t\t} ),\n\t\t\t[ identifier, clientId ]\n\t\t),\n\t} );\n\tconst autocompleteProps = useBlockEditorAutocompleteProps( {\n\t\tonReplace,\n\t\tcompleters: autocompleters,\n\t\trecord: value,\n\t\tonChange,\n\t} );\n\n\t// While a focused editing host owns the selection (the block supports\n\t// `editableRoot`), ARIA attributes describing the autocomplete state must\n\t// be mirrored onto the host: assistive technology resolves them relative\n\t// to the focused element.\n\tconst {\n\t\t'aria-autocomplete': ariaAutocomplete,\n\t\t'aria-haspopup': ariaHasPopup,\n\t\t'aria-controls': ariaControls,\n\t\t'aria-owns': ariaOwns,\n\t\t'aria-activedescendant': ariaActiveDescendant,\n\t} = autocompleteProps;\n\tuseEffect( () => {\n\t\tif ( ! isSelected ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst host = anchorRef.current?.parentElement?.closest(\n\t\t\t'[contenteditable=\"true\"]'\n\t\t);\n\n\t\tif ( ! host ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst attributes = {\n\t\t\t'aria-autocomplete': ariaAutocomplete,\n\t\t\t'aria-haspopup': ariaHasPopup,\n\t\t\t'aria-controls': ariaControls,\n\t\t\t'aria-owns': ariaOwns,\n\t\t\t'aria-activedescendant': ariaActiveDescendant,\n\t\t};\n\n\t\tfor ( const [ key, value_ ] of Object.entries( attributes ) ) {\n\t\t\tif ( value_ === undefined ) {\n\t\t\t\thost.removeAttribute( key );\n\t\t\t} else {\n\t\t\t\thost.setAttribute( key, value_ );\n\t\t\t}\n\t\t}\n\n\t\treturn () => {\n\t\t\tfor ( const key of Object.keys( attributes ) ) {\n\t\t\t\thost.removeAttribute( key );\n\t\t\t}\n\t\t};\n\t}, [\n\t\tisSelected,\n\t\tariaAutocomplete,\n\t\tariaHasPopup,\n\t\tariaControls,\n\t\tariaOwns,\n\t\tariaActiveDescendant,\n\t] );\n\n\tuseMarkPersistent( { html: adjustedValue, value } );\n\n\tconst keyboardShortcuts = useRef( new Set() );\n\tconst inputEvents = useRef( new Set() );\n\n\tfunction onFocus() {\n\t\tanchorRef.current?.focus();\n\t}\n\n\t// Setting tabIndex to 0 is unnecessary, the element is already focusable\n\t// because it's contentEditable. This also fixes a Safari bug where it's\n\t// not possible to Shift+Click multi select blocks when Shift Clicking\n\t// into an element with tabIndex because Safari will focus the element.\n\t// However, Safari will correctly ignore nested contentEditable elements.\n\t// While the writing flow wrapper is contentEditable (the selected block\n\t// supports `editableRoot`), nested editable elements are no longer\n\t// focusable areas on their own, so an explicit tabIndex restores their\n\t// focusability.\n\tlet tabIndex = props.tabIndex;\n\tif ( isEditingHost ) {\n\t\ttabIndex = props.tabIndex ?? 0;\n\t} else if ( ! shouldDisableEditing && props.tabIndex === 0 ) {\n\t\ttabIndex = null;\n\t}\n\n\tconst TagName = tagName;\n\treturn (\n\t\t<>\n\t\t\t{ isSelected && (\n\t\t\t\t<KeyboardShortcutContext.Provider value={ keyboardShortcuts }>\n\t\t\t\t\t<InputEventContext.Provider value={ inputEvents }>\n\t\t\t\t\t\t<Popover.__unstableSlotNameProvider value=\"__unstable-block-tools-after\">\n\t\t\t\t\t\t\t{ children &&\n\t\t\t\t\t\t\t\tchildren( { value, onChange, onFocus } ) }\n\n\t\t\t\t\t\t\t<FormatEdit\n\t\t\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\t\tonFocus={ onFocus }\n\t\t\t\t\t\t\t\tformatTypes={ formatTypes }\n\t\t\t\t\t\t\t\tforwardedRef={ anchorRef }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</Popover.__unstableSlotNameProvider>\n\t\t\t\t\t</InputEventContext.Provider>\n\t\t\t\t</KeyboardShortcutContext.Provider>\n\t\t\t) }\n\t\t\t{ isSelected && hasFormats && (\n\t\t\t\t<FormatToolbarContainer\n\t\t\t\t\tinline={ inlineToolbar }\n\t\t\t\t\teditableContentElement={ anchorElement }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<TagName\n\t\t\t\t// Overridable props.\n\t\t\t\trole=\"textbox\"\n\t\t\t\taria-multiline={ ! disableLineBreaks }\n\t\t\t\taria-readonly={ shouldDisableEditing }\n\t\t\t\t{ ...props }\n\t\t\t\t// Unset draggable (coming from block props) for contentEditable\n\t\t\t\t// elements because it will interfere with multi block selection\n\t\t\t\t// when the contentEditable and draggable elements are the same\n\t\t\t\t// element.\n\t\t\t\tdraggable={ undefined }\n\t\t\t\taria-label={\n\t\t\t\t\tbindingsLabel || props[ 'aria-label' ] || placeholder\n\t\t\t\t}\n\t\t\t\t{ ...autocompleteProps }\n\t\t\t\tref={ useMergeRefs( [\n\t\t\t\t\t// Rich text ref must be first because its focus listener\n\t\t\t\t\t// must be set up before any other ref calls .focus() on\n\t\t\t\t\t// mount.\n\t\t\t\t\trichTextRef,\n\t\t\t\t\tforwardedRef,\n\t\t\t\t\tautocompleteProps.ref,\n\t\t\t\t\tprops.ref,\n\t\t\t\t\tuseEventListeners( {\n\t\t\t\t\t\tregistry,\n\t\t\t\t\t\tgetValue,\n\t\t\t\t\t\tonChange,\n\t\t\t\t\t\t__unstableAllowPrefixTransformations,\n\t\t\t\t\t\tformatTypes,\n\t\t\t\t\t\tonReplace,\n\t\t\t\t\t\tselectionChange,\n\t\t\t\t\t\tisSelected,\n\t\t\t\t\t\tdisableFormats,\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\ttagName,\n\t\t\t\t\t\tonSplit,\n\t\t\t\t\t\t__unstableEmbedURLOnPaste,\n\t\t\t\t\t\tpastePlainText,\n\t\t\t\t\t\tonMerge,\n\t\t\t\t\t\tonRemove,\n\t\t\t\t\t\tdisableLineBreaks,\n\t\t\t\t\t\tonSplitAtEnd,\n\t\t\t\t\t\tonSplitAtDoubleLineEnd,\n\t\t\t\t\t\tkeyboardShortcuts,\n\t\t\t\t\t\tinputEvents,\n\t\t\t\t\t\tsupportsSplitting,\n\t\t\t\t\t} ),\n\t\t\t\t\tanchorRef,\n\t\t\t\t\tsetAnchorElement,\n\t\t\t\t] ) }\n\t\t\t\tcontentEditable={ ! shouldDisableEditing }\n\t\t\t\tsuppressContentEditableWarning\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'block-editor-rich-text__editable',\n\t\t\t\t\tprops.className,\n\t\t\t\t\t'rich-text'\n\t\t\t\t) }\n\t\t\t\ttabIndex={ tabIndex }\n\t\t\t\tdata-wp-block-attribute-key={ identifier }\n\t\t\t/>\n\t\t</>\n\t);\n}\n\nconst ForwardedRichTextWrapper = forwardRef( RichTextWrapper );\n\nexport { ForwardedRichTextWrapper as RichTextWrapper };\n\n// This is the private API for the RichText component.\n// It allows access to all props, not just the public ones.\nexport const PrivateRichText = withDeprecations( ForwardedRichTextWrapper );\n\nPrivateRichText.Content = Content;\nPrivateRichText.isEmpty = ( value ) => {\n\treturn ! value || value.length === 0;\n};\n\n// This is the public API for the RichText component.\n// We wrap the PrivateRichText component to hide some props from the public API.\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/rich-text/README.md\n */\nconst PublicForwardedRichTextContainer = forwardRef( ( props, ref ) => {\n\tconst context = useBlockEditContext();\n\tconst isPreviewMode = context[ isPreviewModeKey ];\n\n\tif ( isPreviewMode ) {\n\t\t// Remove all non-content props.\n\t\tconst {\n\t\t\tchildren,\n\t\t\ttagName: Tag = 'div',\n\t\t\tvalue,\n\t\t\tonChange,\n\t\t\tisSelected,\n\t\t\tmultiline,\n\t\t\tinlineToolbar,\n\t\t\twrapperClassName,\n\t\t\tautocompleters,\n\t\t\tonReplace,\n\t\t\tplaceholder,\n\t\t\tallowedFormats,\n\t\t\twithoutInteractiveFormatting,\n\t\t\tonRemove,\n\t\t\tonMerge,\n\t\t\tonSplit,\n\t\t\t__unstableOnSplitAtEnd,\n\t\t\t__unstableOnSplitAtDoubleLineEnd,\n\t\t\tidentifier,\n\t\t\tpreserveWhiteSpace,\n\t\t\t__unstablePastePlainText,\n\t\t\t__unstableEmbedURLOnPaste,\n\t\t\t__unstableDisableFormats,\n\t\t\tdisableLineBreaks,\n\t\t\t__unstableAllowPrefixTransformations,\n\t\t\treadOnly,\n\t\t\t...contentProps\n\t\t} = props;\n\t\treturn (\n\t\t\t<Tag\n\t\t\t\tref={ ref }\n\t\t\t\t{ ...contentProps }\n\t\t\t\tdangerouslySetInnerHTML={ {\n\t\t\t\t\t__html: valueToHTMLString( value, multiline ) || '<br>',\n\t\t\t\t} }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn <PrivateRichText ref={ ref } { ...props } readOnly={ false } />;\n} );\n\nPublicForwardedRichTextContainer.Content = Content;\nPublicForwardedRichTextContainer.isEmpty = ( value ) => {\n\treturn ! value || value.length === 0;\n};\n\nexport default PublicForwardedRichTextContainer;\nexport { RichTextShortcut };\nexport { RichTextToolbarButton } from './toolbar-button';\nexport { RichTextInputEvent as __unstableRichTextInputEvent };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;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AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACJ,IAAI;AACJ,WACC;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACE,GAAG;AAAA,QACL,yBAA0B;AAAA,UACzB,YAAQ,kCAAmB,OAAO,SAAU,KAAK;AAAA,QAClD;AAAA;AAAA,IACD;AAAA,EAEF;AAEA,SAAO,4CAAC,mBAAgB,KAAc,GAAG,OAAQ,UAAW,OAAQ;AACrE,CAAE;AAEF,iCAAiC,UAAU;AAC3C,iCAAiC,UAAU,CAAE,UAAW;AACvD,SAAO,CAAE,SAAS,MAAM,WAAW;AACpC;AAEA,IAAO,oBAAQ;",
|
|
6
6
|
"names": ["richTextPrivateApis", "deprecated", "BlockContext", "getSelectionStart", "getSelectionEnd", "blockEditorStore", "selectionStart", "selectionEnd", "isSelected", "fastDeepEqual", "FormatEdit", "FormatToolbarContainer", "clsx"]
|
|
7
7
|
}
|
|
@@ -38,11 +38,110 @@ var import_deprecated = __toESM(require("@wordpress/deprecated"));
|
|
|
38
38
|
var import_data = require("@wordpress/data");
|
|
39
39
|
var import_keycodes = require("@wordpress/keycodes");
|
|
40
40
|
var import_rich_text = require("@wordpress/rich-text");
|
|
41
|
+
var import_compose = require("@wordpress/compose");
|
|
41
42
|
var import__ = require("./index.cjs");
|
|
42
43
|
var import_store = require("../../store/index.cjs");
|
|
43
44
|
var import_block_edit = require("../block-edit/index.cjs");
|
|
44
45
|
var import_utils = require("./utils.cjs");
|
|
46
|
+
var import_lock_unlock = require("../../lock-unlock.cjs");
|
|
45
47
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
48
|
+
var { subscribeOwnedListener } = (0, import_lock_unlock.unlock)(import_rich_text.privateApis);
|
|
49
|
+
function useEnterRef(props) {
|
|
50
|
+
const { getSelectionStart, getSelectionEnd } = (0, import_data.useSelect)(import_store.store);
|
|
51
|
+
const { selectionChange } = (0, import_data.useDispatch)(import_store.store);
|
|
52
|
+
return (0, import_compose.useRefEffect)((element) => {
|
|
53
|
+
function onKeyDown(event) {
|
|
54
|
+
if (event.keyCode !== import_keycodes.ENTER) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
const { value, values, onChange, index, identifier, clientId } = props.current;
|
|
59
|
+
const { offset: start } = getSelectionStart();
|
|
60
|
+
const { offset: end } = getSelectionEnd();
|
|
61
|
+
if (typeof start !== "number" || typeof end !== "number") {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const richTextValue = (0, import_rich_text.create)({ html: value });
|
|
65
|
+
richTextValue.start = start;
|
|
66
|
+
richTextValue.end = end;
|
|
67
|
+
const array = (0, import_rich_text.split)(richTextValue).map(
|
|
68
|
+
(v) => (0, import_rich_text.toHTMLString)({ value: v })
|
|
69
|
+
);
|
|
70
|
+
const newValues = values.slice();
|
|
71
|
+
newValues.splice(index, 1, ...array);
|
|
72
|
+
onChange(newValues);
|
|
73
|
+
selectionChange(clientId, `${identifier}-${index + 1}`, 0, 0);
|
|
74
|
+
}
|
|
75
|
+
return subscribeOwnedListener(element, "keydown", onKeyDown, true);
|
|
76
|
+
}, []);
|
|
77
|
+
}
|
|
78
|
+
function Line(lineProps) {
|
|
79
|
+
const {
|
|
80
|
+
value,
|
|
81
|
+
values,
|
|
82
|
+
onChange,
|
|
83
|
+
index,
|
|
84
|
+
identifier,
|
|
85
|
+
multilineTagName,
|
|
86
|
+
...props
|
|
87
|
+
} = lineProps;
|
|
88
|
+
const { clientId } = (0, import_block_edit.useBlockEditContext)();
|
|
89
|
+
const { selectionChange } = (0, import_data.useDispatch)(import_store.store);
|
|
90
|
+
const latestRef = (0, import_element.useRef)();
|
|
91
|
+
(0, import_element.useInsertionEffect)(() => {
|
|
92
|
+
latestRef.current = { ...lineProps, clientId };
|
|
93
|
+
});
|
|
94
|
+
const ref = useEnterRef(latestRef);
|
|
95
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
96
|
+
import__.RichTextWrapper,
|
|
97
|
+
{
|
|
98
|
+
identifier: `${identifier}-${index}`,
|
|
99
|
+
tagName: multilineTagName,
|
|
100
|
+
value,
|
|
101
|
+
onChange: (newValue) => {
|
|
102
|
+
const newValues = values.slice();
|
|
103
|
+
newValues[index] = newValue;
|
|
104
|
+
onChange(newValues);
|
|
105
|
+
},
|
|
106
|
+
isSelected: void 0,
|
|
107
|
+
ref,
|
|
108
|
+
onMerge: (forward) => {
|
|
109
|
+
const newValues = values.slice();
|
|
110
|
+
let offset = 0;
|
|
111
|
+
if (forward) {
|
|
112
|
+
if (!newValues[index + 1]) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
newValues.splice(
|
|
116
|
+
index,
|
|
117
|
+
2,
|
|
118
|
+
newValues[index] + newValues[index + 1]
|
|
119
|
+
);
|
|
120
|
+
offset = newValues[index].length - 1;
|
|
121
|
+
} else {
|
|
122
|
+
if (!newValues[index - 1]) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
newValues.splice(
|
|
126
|
+
index - 1,
|
|
127
|
+
2,
|
|
128
|
+
newValues[index - 1] + newValues[index]
|
|
129
|
+
);
|
|
130
|
+
offset = newValues[index - 1].length - 1;
|
|
131
|
+
}
|
|
132
|
+
onChange(newValues);
|
|
133
|
+
selectionChange(
|
|
134
|
+
clientId,
|
|
135
|
+
`${identifier}-${index - (forward ? 0 : 1)}`,
|
|
136
|
+
offset,
|
|
137
|
+
offset
|
|
138
|
+
);
|
|
139
|
+
},
|
|
140
|
+
...props
|
|
141
|
+
},
|
|
142
|
+
index
|
|
143
|
+
);
|
|
144
|
+
}
|
|
46
145
|
function RichTextMultiline({
|
|
47
146
|
children,
|
|
48
147
|
identifier,
|
|
@@ -58,9 +157,6 @@ function RichTextMultiline({
|
|
|
58
157
|
alternative: "nested blocks (InnerBlocks)",
|
|
59
158
|
link: "https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/nested-blocks-inner-blocks/"
|
|
60
159
|
});
|
|
61
|
-
const { clientId } = (0, import_block_edit.useBlockEditContext)();
|
|
62
|
-
const { getSelectionStart, getSelectionEnd } = (0, import_data.useSelect)(import_store.store);
|
|
63
|
-
const { selectionChange } = (0, import_data.useDispatch)(import_store.store);
|
|
64
160
|
const multilineTagName = (0, import_utils.getMultilineTag)(multiline);
|
|
65
161
|
value = value || `<${multilineTagName}></${multilineTagName}>`;
|
|
66
162
|
const padded = `</${multilineTagName}>${value}<${multilineTagName}>`;
|
|
@@ -78,75 +174,14 @@ function RichTextMultiline({
|
|
|
78
174
|
}
|
|
79
175
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TagName, { ref: forwardedRef, children: values.map((_value, index) => {
|
|
80
176
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
81
|
-
|
|
177
|
+
Line,
|
|
82
178
|
{
|
|
83
|
-
|
|
84
|
-
tagName: multilineTagName,
|
|
179
|
+
values,
|
|
85
180
|
value: _value,
|
|
86
|
-
onChange:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
},
|
|
91
|
-
isSelected: void 0,
|
|
92
|
-
onKeyDown: (event) => {
|
|
93
|
-
if (event.keyCode !== import_keycodes.ENTER) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
event.preventDefault();
|
|
97
|
-
const { offset: start } = getSelectionStart();
|
|
98
|
-
const { offset: end } = getSelectionEnd();
|
|
99
|
-
if (typeof start !== "number" || typeof end !== "number") {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
const richTextValue = (0, import_rich_text.create)({ html: _value });
|
|
103
|
-
richTextValue.start = start;
|
|
104
|
-
richTextValue.end = end;
|
|
105
|
-
const array = (0, import_rich_text.split)(richTextValue).map(
|
|
106
|
-
(v) => (0, import_rich_text.toHTMLString)({ value: v })
|
|
107
|
-
);
|
|
108
|
-
const newValues = values.slice();
|
|
109
|
-
newValues.splice(index, 1, ...array);
|
|
110
|
-
_onChange(newValues);
|
|
111
|
-
selectionChange(
|
|
112
|
-
clientId,
|
|
113
|
-
`${identifier}-${index + 1}`,
|
|
114
|
-
0,
|
|
115
|
-
0
|
|
116
|
-
);
|
|
117
|
-
},
|
|
118
|
-
onMerge: (forward) => {
|
|
119
|
-
const newValues = values.slice();
|
|
120
|
-
let offset = 0;
|
|
121
|
-
if (forward) {
|
|
122
|
-
if (!newValues[index + 1]) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
newValues.splice(
|
|
126
|
-
index,
|
|
127
|
-
2,
|
|
128
|
-
newValues[index] + newValues[index + 1]
|
|
129
|
-
);
|
|
130
|
-
offset = newValues[index].length - 1;
|
|
131
|
-
} else {
|
|
132
|
-
if (!newValues[index - 1]) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
newValues.splice(
|
|
136
|
-
index - 1,
|
|
137
|
-
2,
|
|
138
|
-
newValues[index - 1] + newValues[index]
|
|
139
|
-
);
|
|
140
|
-
offset = newValues[index - 1].length - 1;
|
|
141
|
-
}
|
|
142
|
-
_onChange(newValues);
|
|
143
|
-
selectionChange(
|
|
144
|
-
clientId,
|
|
145
|
-
`${identifier}-${index - (forward ? 0 : 1)}`,
|
|
146
|
-
offset,
|
|
147
|
-
offset
|
|
148
|
-
);
|
|
149
|
-
},
|
|
181
|
+
onChange: _onChange,
|
|
182
|
+
index,
|
|
183
|
+
identifier,
|
|
184
|
+
multilineTagName,
|
|
150
185
|
...props
|
|
151
186
|
},
|
|
152
187
|
index
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/rich-text/multiline.js"],
|
|
4
|
-
"sourcesContent": ["import { forwardRef } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { ENTER } from '@wordpress/keycodes';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import { forwardRef, useInsertionEffect, useRef } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { ENTER } from '@wordpress/keycodes';\nimport {\n\tcreate,\n\tsplit,\n\ttoHTMLString,\n\tprivateApis as richTextPrivateApis,\n} from '@wordpress/rich-text';\nimport { useRefEffect } from '@wordpress/compose';\nimport { RichTextWrapper } from './';\nimport { store as blockEditorStore } from '../../store';\nimport { useBlockEditContext } from '../block-edit';\nimport { getMultilineTag } from './utils';\nimport { unlock } from '../../lock-unlock';\n\nconst { subscribeOwnedListener } = unlock( richTextPrivateApis );\n\nfunction useEnterRef( props ) {\n\tconst { getSelectionStart, getSelectionEnd } =\n\t\tuseSelect( blockEditorStore );\n\tconst { selectionChange } = useDispatch( blockEditorStore );\n\treturn useRefEffect( ( element ) => {\n\t\tfunction onKeyDown( event ) {\n\t\t\tif ( event.keyCode !== ENTER ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\n\t\t\tconst { value, values, onChange, index, identifier, clientId } =\n\t\t\t\tprops.current;\n\t\t\tconst { offset: start } = getSelectionStart();\n\t\t\tconst { offset: end } = getSelectionEnd();\n\n\t\t\t// Cannot split if there is no selection.\n\t\t\tif ( typeof start !== 'number' || typeof end !== 'number' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst richTextValue = create( { html: value } );\n\t\t\trichTextValue.start = start;\n\t\t\trichTextValue.end = end;\n\n\t\t\tconst array = split( richTextValue ).map( ( v ) =>\n\t\t\t\ttoHTMLString( { value: v } )\n\t\t\t);\n\n\t\t\tconst newValues = values.slice();\n\t\t\tnewValues.splice( index, 1, ...array );\n\t\t\tonChange( newValues );\n\t\t\tselectionChange( clientId, `${ identifier }-${ index + 1 }`, 0, 0 );\n\t\t}\n\t\t// Capture phase so this runs before the generic rich text enter\n\t\t// listener, which skips events that already had their default\n\t\t// prevented.\n\t\treturn subscribeOwnedListener( element, 'keydown', onKeyDown, true );\n\t}, [] );\n}\n\nfunction Line( lineProps ) {\n\tconst {\n\t\tvalue,\n\t\tvalues,\n\t\tonChange,\n\t\tindex,\n\t\tidentifier,\n\t\tmultilineTagName,\n\t\t...props\n\t} = lineProps;\n\tconst { clientId } = useBlockEditContext();\n\tconst { selectionChange } = useDispatch( blockEditorStore );\n\tconst latestRef = useRef();\n\tuseInsertionEffect( () => {\n\t\tlatestRef.current = { ...lineProps, clientId };\n\t} );\n\tconst ref = useEnterRef( latestRef );\n\treturn (\n\t\t<RichTextWrapper\n\t\t\tkey={ index }\n\t\t\tidentifier={ `${ identifier }-${ index }` }\n\t\t\ttagName={ multilineTagName }\n\t\t\tvalue={ value }\n\t\t\tonChange={ ( newValue ) => {\n\t\t\t\tconst newValues = values.slice();\n\t\t\t\tnewValues[ index ] = newValue;\n\t\t\t\tonChange( newValues );\n\t\t\t} }\n\t\t\tisSelected={ undefined }\n\t\t\tref={ ref }\n\t\t\tonMerge={ ( forward ) => {\n\t\t\t\tconst newValues = values.slice();\n\t\t\t\tlet offset = 0;\n\t\t\t\tif ( forward ) {\n\t\t\t\t\tif ( ! newValues[ index + 1 ] ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tnewValues.splice(\n\t\t\t\t\t\tindex,\n\t\t\t\t\t\t2,\n\t\t\t\t\t\tnewValues[ index ] + newValues[ index + 1 ]\n\t\t\t\t\t);\n\t\t\t\t\toffset = newValues[ index ].length - 1;\n\t\t\t\t} else {\n\t\t\t\t\tif ( ! newValues[ index - 1 ] ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tnewValues.splice(\n\t\t\t\t\t\tindex - 1,\n\t\t\t\t\t\t2,\n\t\t\t\t\t\tnewValues[ index - 1 ] + newValues[ index ]\n\t\t\t\t\t);\n\t\t\t\t\toffset = newValues[ index - 1 ].length - 1;\n\t\t\t\t}\n\t\t\t\tonChange( newValues );\n\t\t\t\tselectionChange(\n\t\t\t\t\tclientId,\n\t\t\t\t\t`${ identifier }-${ index - ( forward ? 0 : 1 ) }`,\n\t\t\t\t\toffset,\n\t\t\t\t\toffset\n\t\t\t\t);\n\t\t\t} }\n\t\t\t{ ...props }\n\t\t/>\n\t);\n}\n\nfunction RichTextMultiline(\n\t{\n\t\tchildren,\n\t\tidentifier,\n\t\ttagName: TagName = 'div',\n\t\tvalue = '',\n\t\tonChange,\n\t\tmultiline,\n\t\t...props\n\t},\n\tforwardedRef\n) {\n\tdeprecated( 'wp.blockEditor.RichText multiline prop', {\n\t\tsince: '6.1',\n\t\tversion: '6.3',\n\t\talternative: 'nested blocks (InnerBlocks)',\n\t\tlink: 'https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/nested-blocks-inner-blocks/',\n\t} );\n\n\tconst multilineTagName = getMultilineTag( multiline );\n\tvalue = value || `<${ multilineTagName }></${ multilineTagName }>`;\n\tconst padded = `</${ multilineTagName }>${ value }<${ multilineTagName }>`;\n\tconst values = padded.split(\n\t\t`</${ multilineTagName }><${ multilineTagName }>`\n\t);\n\n\tvalues.shift();\n\tvalues.pop();\n\n\tfunction _onChange( newValues ) {\n\t\tonChange(\n\t\t\t`<${ multilineTagName }>${ newValues.join(\n\t\t\t\t`</${ multilineTagName }><${ multilineTagName }>`\n\t\t\t) }</${ multilineTagName }>`\n\t\t);\n\t}\n\n\treturn (\n\t\t<TagName ref={ forwardedRef }>\n\t\t\t{ values.map( ( _value, index ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<Line\n\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\tvalues={ values }\n\t\t\t\t\t\tvalue={ _value }\n\t\t\t\t\t\tonChange={ _onChange }\n\t\t\t\t\t\tindex={ index }\n\t\t\t\t\t\tidentifier={ identifier }\n\t\t\t\t\t\tmultilineTagName={ multilineTagName }\n\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</TagName>\n\t);\n}\n\nexport default forwardRef( RichTextMultiline );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAuD;AACvD,wBAAuB;AACvB,kBAAuC;AACvC,sBAAsB;AACtB,uBAKO;AACP,qBAA6B;AAC7B,eAAgC;AAChC,mBAA0C;AAC1C,wBAAoC;AACpC,mBAAgC;AAChC,yBAAuB;AAgErB;AA9DF,IAAM,EAAE,uBAAuB,QAAI,2BAAQ,iBAAAA,WAAoB;AAE/D,SAAS,YAAa,OAAQ;AAC7B,QAAM,EAAE,mBAAmB,gBAAgB,QAC1C,uBAAW,aAAAC,KAAiB;AAC7B,QAAM,EAAE,gBAAgB,QAAI,yBAAa,aAAAA,KAAiB;AAC1D,aAAO,6BAAc,CAAE,YAAa;AACnC,aAAS,UAAW,OAAQ;AAC3B,UAAK,MAAM,YAAY,uBAAQ;AAC9B;AAAA,MACD;AAEA,YAAM,eAAe;AAErB,YAAM,EAAE,OAAO,QAAQ,UAAU,OAAO,YAAY,SAAS,IAC5D,MAAM;AACP,YAAM,EAAE,QAAQ,MAAM,IAAI,kBAAkB;AAC5C,YAAM,EAAE,QAAQ,IAAI,IAAI,gBAAgB;AAGxC,UAAK,OAAO,UAAU,YAAY,OAAO,QAAQ,UAAW;AAC3D;AAAA,MACD;AAEA,YAAM,oBAAgB,yBAAQ,EAAE,MAAM,MAAM,CAAE;AAC9C,oBAAc,QAAQ;AACtB,oBAAc,MAAM;AAEpB,YAAM,YAAQ,wBAAO,aAAc,EAAE;AAA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AAAA,QACX;AAAA,QACA;AAAA,QACA;AAAA,QACE,GAAG;AAAA;AAAA,MAPC;AAAA,IAQP;AAAA,EAEF,CAAE,GACH;AAEF;AAEA,IAAO,wBAAQ,2BAAY,iBAAkB;",
|
|
6
|
+
"names": ["richTextPrivateApis", "blockEditorStore", "deprecated"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/url-input/index.js"],
|
|
4
|
-
"sourcesContent": ["import clsx from 'clsx';\nimport { speak } from '@wordpress/a11y';\nimport { __, sprintf, _n } from '@wordpress/i18n';\nimport { useEffect, useRef, useState } from '@wordpress/element';\nimport { UP, DOWN, ENTER, TAB } from '@wordpress/keycodes';\nimport {\n\tBaseControl,\n\tButton,\n\t__experimentalInputControl as InputControl,\n\tSpinner,\n\tPopover,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { useDebounce, useEvent, useInstanceId } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { isURL } from '@wordpress/url';\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { ValidatedInputControl } = unlock( componentsPrivateApis );\n\nconst noop = () => {};\n\n/**\n * Whether the argument is a function.\n *\n * @param {*} maybeFunc The argument to check.\n * @return {boolean} True if the argument is a function, false otherwise.\n */\nfunction isFunction( maybeFunc ) {\n\treturn typeof maybeFunc === 'function';\n}\n\n/**\n * Text field for entering a URL, with an autocomplete list of matching posts,\n * pages and other link suggestions.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/url-input/README.md\n *\n * @param {Object} props Component props.\n */\nexport default function URLInput( props ) {\n\tconst {\n\t\t__experimentalFetchLinkSuggestions: fetchLinkSuggestionsProp,\n\t\t__experimentalHandleURLSuggestions: handleURLSuggestions,\n\t\t__experimentalRenderControl: renderControl,\n\t\t__experimentalRenderSuggestions: renderSuggestions,\n\t\t__experimentalShowInitialSuggestions: showInitialSuggestions = false,\n\t\tautocompleteRef,\n\t\tclassName,\n\t\tcustomValidity,\n\t\tdisableSuggestions,\n\t\tdisabled = false,\n\t\thelp = null,\n\t\thideLabelFromVision = false,\n\t\tinputRef,\n\t\tisFullWidth,\n\t\tlabel = null,\n\t\tmarkWhenOptional,\n\t\tonChange,\n\t\tonKeyDown,\n\t\tonSubmit,\n\t\tplaceholder = __( 'Paste URL or type to search' ),\n\t\trequired = true,\n\t\tsuffix,\n\t\tvalue = '',\n\t} = props;\n\n\tconst instanceId = useInstanceId( URLInput );\n\tconst { getSettings } = useSelect( blockEditorStore );\n\tconst debouncedSpeak = useDebounce( speak, 500 );\n\n\tconst [ suggestions, setSuggestions ] = useState( [] );\n\tconst [ suggestionsValue, setSuggestionsValue ] = useState( null );\n\tconst [ selectedSuggestion, setSelectedSuggestion ] = useState( null );\n\tconst [ isSuggestionsListOpen, setIsSuggestionsListOpen ] =\n\t\tuseState( false );\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst [ isComposing, setIsComposing ] = useState( false );\n\n\tconst fallbackInputRef = useRef();\n\tconst suggestionNodesRef = useRef( [] );\n\t// A fetch Promise can't be aborted. It's mimicked by holding on to the\n\t// pending request so that responses of superseded requests can be ignored.\n\tconst suggestionsRequestRef = useRef( null );\n\n\tconst controlInputRef = inputRef ?? fallbackInputRef;\n\n\tconst inputId = `url-input-control-${ instanceId }`;\n\tconst suggestionsListboxId = `block-editor-url-input-suggestions-${ instanceId }`;\n\tconst suggestionOptionIdPrefix = `block-editor-url-input-suggestion-${ instanceId }`;\n\n\t// The suggestions are hidden rather than discarded, so that returning focus\n\t// to a field that already has results doesn't trigger a new search.\n\tconst showSuggestions =\n\t\tisSuggestionsListOpen &&\n\t\tdisableSuggestions !== true &&\n\t\t( showInitialSuggestions || !! value.length );\n\n\tconst updateSuggestions = useEvent( ( searchValue = '' ) => {\n\t\tconst fetchLinkSuggestions = isFunction( fetchLinkSuggestionsProp )\n\t\t\t? fetchLinkSuggestionsProp\n\t\t\t: getSettings().__experimentalFetchLinkSuggestions;\n\n\t\tif ( ! fetchLinkSuggestions ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Initial suggestions may only show if there is no value\n\t\t// (note: this includes whitespace).\n\t\tconst isInitialSuggestions = ! searchValue?.length;\n\n\t\t// Trim only now we've determined whether or not it originally had a \"length\"\n\t\t// (even if that value was all whitespace).\n\t\tconst search = searchValue.trim();\n\n\t\t// Allow a suggestions request if:\n\t\t// - there are at least 2 characters in the search input (except manual searches where\n\t\t// search input length is not required to trigger a fetch)\n\t\t// - this is a direct entry (eg: a URL)\n\t\tif (\n\t\t\t! isInitialSuggestions &&\n\t\t\t( search.length < 2 ||\n\t\t\t\t( ! handleURLSuggestions && isURL( search ) ) )\n\t\t) {\n\t\t\tsuggestionsRequestRef.current?.cancel?.();\n\t\t\tsuggestionsRequestRef.current = null;\n\n\t\t\tsetSuggestions( [] );\n\t\t\tsetIsSuggestionsListOpen( false );\n\t\t\tsetSuggestionsValue( search );\n\t\t\tsetSelectedSuggestion( null );\n\t\t\tsetIsLoading( false );\n\n\t\t\treturn;\n\t\t}\n\n\t\tsetSelectedSuggestion( null );\n\t\tsetIsLoading( true );\n\n\t\tconst request = fetchLinkSuggestions( search, {\n\t\t\tisInitialSuggestions,\n\t\t} );\n\t\tsuggestionsRequestRef.current = request;\n\n\t\trequest\n\t\t\t.then( ( nextSuggestions ) => {\n\t\t\t\tif ( suggestionsRequestRef.current !== request ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetSuggestions( nextSuggestions );\n\t\t\t\tsetSuggestionsValue( search );\n\t\t\t\tsetIsLoading( false );\n\t\t\t\tsetIsSuggestionsListOpen( !! nextSuggestions.length );\n\n\t\t\t\tif ( nextSuggestions.length ) {\n\t\t\t\t\tdebouncedSpeak(\n\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t/* translators: %d: number of results. */\n\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t'%d result found, use up and down arrow keys to navigate.',\n\t\t\t\t\t\t\t\t'%d results found, use up and down arrow keys to navigate.',\n\t\t\t\t\t\t\t\tnextSuggestions.length\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tnextSuggestions.length\n\t\t\t\t\t\t),\n\t\t\t\t\t\t'assertive'\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tdebouncedSpeak( __( 'No results.' ), 'assertive' );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( () => {\n\t\t\t\tif ( suggestionsRequestRef.current !== request ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetIsLoading( false );\n\t\t\t} )\n\t\t\t.finally( () => {\n\t\t\t\tif ( suggestionsRequestRef.current === request ) {\n\t\t\t\t\tsuggestionsRequestRef.current = null;\n\t\t\t\t}\n\t\t\t} );\n\t} );\n\n\tconst debouncedUpdateSuggestions = useDebounce( updateSuggestions, 200 );\n\n\t// Keep the suggestions in sync with the value being searched for. An empty\n\t// value requests the initial suggestions, when those are enabled.\n\t// Composition state is a dependency, so the composed value is picked up\n\t// whether the browser reports it before or after `compositionend`.\n\tuseEffect( () => {\n\t\tif (\n\t\t\t! disableSuggestions &&\n\t\t\t! isComposing &&\n\t\t\t( value.length || showInitialSuggestions )\n\t\t) {\n\t\t\tdebouncedUpdateSuggestions( value );\n\t\t}\n\t}, [\n\t\tvalue,\n\t\tisComposing,\n\t\tdisableSuggestions,\n\t\tshowInitialSuggestions,\n\t\tdebouncedUpdateSuggestions,\n\t] );\n\n\t// Persist the hidden state, so that the list can't reappear with stale\n\t// results once the value or the props allow suggestions again.\n\tuseEffect( () => {\n\t\tif ( ! showSuggestions ) {\n\t\t\tsetIsSuggestionsListOpen( false );\n\t\t}\n\t}, [ showSuggestions ] );\n\n\tuseEffect( () => {\n\t\tif ( showSuggestions && selectedSuggestion !== null ) {\n\t\t\tsuggestionNodesRef.current[ selectedSuggestion ]?.scrollIntoView( {\n\t\t\t\tbehavior: 'instant',\n\t\t\t\tblock: 'nearest',\n\t\t\t\tinline: 'nearest',\n\t\t\t} );\n\t\t}\n\t}, [ showSuggestions, selectedSuggestion ] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tsuggestionsRequestRef.current?.cancel?.();\n\t\t\tsuggestionsRequestRef.current = null;\n\t\t};\n\t}, [] );\n\n\tfunction selectLink( suggestion ) {\n\t\tonChange( suggestion.url, suggestion );\n\t\tsetSelectedSuggestion( null );\n\t\tsetIsSuggestionsListOpen( false );\n\t}\n\n\tfunction handleSuggestionClick( suggestion ) {\n\t\tselectLink( suggestion );\n\t\t// Move focus to the input field when a link suggestion is clicked.\n\t\tcontrolInputRef.current.focus();\n\t}\n\n\tfunction handleChange( newValue ) {\n\t\t// `InputControl` passes an `{ event }` object as its second argument,\n\t\t// which callers would mistake for a selected suggestion.\n\t\tonChange( newValue );\n\t}\n\n\tfunction handleCompositionStart() {\n\t\tsetIsComposing( true );\n\t\t// Cancel any debounced suggestions update scheduled before the\n\t\t// composition started so no request fires while composing.\n\t\tdebouncedUpdateSuggestions.cancel();\n\t}\n\n\tfunction handleCompositionEnd() {\n\t\tsetIsComposing( false );\n\t}\n\n\tfunction handleFocus() {\n\t\t// When opening the link editor, if there's a value present, we want to load the suggestions pane with the results for this input search value\n\t\t// Don't re-run the suggestions on focus if there are already suggestions present (prevents searching again when tabbing between the input and buttons)\n\t\t// or there is already a request in progress.\n\t\tif (\n\t\t\tvalue &&\n\t\t\t! disableSuggestions &&\n\t\t\t! suggestions.length &&\n\t\t\tsuggestionsRequestRef.current === null\n\t\t) {\n\t\t\tdebouncedUpdateSuggestions( value );\n\t\t}\n\t}\n\n\tfunction handleKeyDown( event ) {\n\t\tonKeyDown?.( event );\n\n\t\t// Unless the list can consume them, the keys must reach the editor for\n\t\t// block navigation, so they mustn't be prevented.\n\t\tif ( ! showSuggestions || ! suggestions.length || isLoading ) {\n\t\t\t// Holding Shift extends the selection, which the browser handles.\n\t\t\tif (\n\t\t\t\t! event.shiftKey &&\n\t\t\t\t( event.keyCode === UP || event.keyCode === DOWN )\n\t\t\t) {\n\t\t\t\t// Firefox on Windows leaves the caret in place, trapping focus,\n\t\t\t\t// since the editor only navigates away from an edge.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/issues/5693#issuecomment-436684747\n\t\t\t\tconst caret =\n\t\t\t\t\tevent.keyCode === UP ? 0 : event.target.value.length;\n\n\t\t\t\t// UP moves the caret to the start of the text, DOWN to the end.\n\t\t\t\t// Once it is already there, with nothing selected, the key is\n\t\t\t\t// left to the editor to navigate out of the field.\n\t\t\t\tif (\n\t\t\t\t\tevent.target.selectionStart !== caret ||\n\t\t\t\t\tevent.target.selectionEnd !== caret\n\t\t\t\t) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tevent.target.setSelectionRange( caret, caret );\n\t\t\t\t}\n\t\t\t} else if ( event.keyCode === ENTER && onSubmit ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tonSubmit( null, event );\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst suggestion = suggestions[ selectedSuggestion ] ?? null;\n\n\t\tswitch ( event.keyCode ) {\n\t\t\tcase UP:\n\t\t\tcase DOWN: {\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\tconst offset = event.keyCode === UP ? -1 : 1;\n\t\t\t\t// An unselected list is entered from the end nearest the key,\n\t\t\t\t// and the ends wrap into each other.\n\t\t\t\tconst from = selectedSuggestion ?? ( offset === -1 ? 0 : -1 );\n\n\t\t\t\tsetSelectedSuggestion(\n\t\t\t\t\t( from + offset + suggestions.length ) % suggestions.length\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase TAB: {\n\t\t\t\tif ( suggestion ) {\n\t\t\t\t\tselectLink( suggestion );\n\t\t\t\t\tspeak( __( 'Link selected.' ) );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase ENTER: {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif ( suggestion ) {\n\t\t\t\t\tselectLink( suggestion );\n\t\t\t\t}\n\n\t\t\t\tonSubmit?.( suggestion, event );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst controlProps = {\n\t\tid: inputId, // Passes attribute to label for the for attribute\n\t\tlabel,\n\t\tclassName: clsx( 'block-editor-url-input', className, {\n\t\t\t'is-full-width': isFullWidth,\n\t\t} ),\n\t\thideLabelFromVision,\n\t};\n\n\tconst inputProps = {\n\t\tid: inputId,\n\t\tvalue,\n\t\trequired,\n\t\ttype: 'text',\n\t\tname: inputId,\n\t\tautoComplete: 'off',\n\t\tonChange: disabled ? noop : handleChange,\n\t\tonCompositionStart: disabled ? noop : handleCompositionStart,\n\t\tonCompositionEnd: disabled ? noop : handleCompositionEnd,\n\t\tonFocus: disabled ? noop : handleFocus,\n\t\tonKeyDown: disabled ? noop : handleKeyDown,\n\t\tplaceholder,\n\t\trole: 'combobox',\n\t\t'aria-label': label ? undefined : __( 'URL' ), // Ensure input always has an accessible label\n\t\t'aria-expanded': showSuggestions,\n\t\t'aria-autocomplete': 'list',\n\t\t'aria-owns': suggestionsListboxId,\n\t\t'aria-activedescendant':\n\t\t\tselectedSuggestion !== null\n\t\t\t\t? `${ suggestionOptionIdPrefix }-${ selectedSuggestion }`\n\t\t\t\t: undefined,\n\t\tref: controlInputRef,\n\t\tdisabled,\n\t\tsuffix,\n\t\thelp,\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<Control\n\t\t\t\tcontrolProps={ controlProps }\n\t\t\t\tinputProps={ inputProps }\n\t\t\t\tisLoading={ isLoading }\n\t\t\t\tcustomValidity={ customValidity }\n\t\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\t\trenderControl={ renderControl }\n\t\t\t/>\n\t\t\t{ showSuggestions && suggestions.length > 0 && (\n\t\t\t\t<Suggestions\n\t\t\t\t\tautocompleteRef={ autocompleteRef }\n\t\t\t\t\tclassName={ className }\n\t\t\t\t\thandleSuggestionClick={ handleSuggestionClick }\n\t\t\t\t\tisLoading={ isLoading }\n\t\t\t\t\trenderSuggestions={ renderSuggestions }\n\t\t\t\t\tselectedSuggestion={ selectedSuggestion }\n\t\t\t\t\tsuggestionNodesRef={ suggestionNodesRef }\n\t\t\t\t\tsuggestionOptionIdPrefix={ suggestionOptionIdPrefix }\n\t\t\t\t\tsuggestions={ suggestions }\n\t\t\t\t\tsuggestionsListboxId={ suggestionsListboxId }\n\t\t\t\t\tsuggestionsValue={ suggestionsValue }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction Control( {\n\tcontrolProps,\n\tinputProps,\n\tisLoading,\n\tcustomValidity,\n\tmarkWhenOptional,\n\trenderControl,\n} ) {\n\t// Once a validity has been reported, keep using the validated control, so\n\t// that clearing the validity doesn't remount (and blur) the input.\n\tconst [ isValidated, setIsValidated ] = useState(\n\t\tcustomValidity !== undefined\n\t);\n\n\tif ( customValidity !== undefined && ! isValidated ) {\n\t\tsetIsValidated( true );\n\t}\n\n\tif ( renderControl ) {\n\t\treturn renderControl( controlProps, inputProps, isLoading );\n\t}\n\n\tconst MaybeValidatedInputControl = isValidated\n\t\t? ValidatedInputControl\n\t\t: InputControl;\n\n\treturn (\n\t\t<BaseControl { ...controlProps }>\n\t\t\t<MaybeValidatedInputControl\n\t\t\t\t{ ...inputProps }\n\t\t\t\t{ ...( isValidated && {\n\t\t\t\t\tcustomValidity,\n\t\t\t\t\t// Suppress the \"(Required)\" indicator in the label.\n\t\t\t\t\t// The field is still required for validation, but the indicator\n\t\t\t\t\t// can be hidden when markWhenOptional is set to true.\n\t\t\t\t\t...( markWhenOptional !== undefined && {\n\t\t\t\t\t\tmarkWhenOptional,\n\t\t\t\t\t} ),\n\t\t\t\t} ) }\n\t\t\t/>\n\t\t\t{ isLoading && <Spinner /> }\n\t\t</BaseControl>\n\t);\n}\n\nfunction Suggestions( {\n\tautocompleteRef,\n\tclassName,\n\thandleSuggestionClick,\n\tisLoading,\n\trenderSuggestions,\n\tselectedSuggestion,\n\tsuggestionNodesRef,\n\tsuggestionOptionIdPrefix,\n\tsuggestions,\n\tsuggestionsListboxId,\n\tsuggestionsValue,\n} ) {\n\tconst suggestionsListProps = {\n\t\tid: suggestionsListboxId,\n\t\tref: autocompleteRef,\n\t\trole: 'listbox',\n\t};\n\n\tconst buildSuggestionItemProps = ( suggestion, index ) => {\n\t\treturn {\n\t\t\trole: 'option',\n\t\t\ttabIndex: '-1',\n\t\t\tid: `${ suggestionOptionIdPrefix }-${ index }`,\n\t\t\tref: ( node ) => {\n\t\t\t\tsuggestionNodesRef.current[ index ] = node;\n\t\t\t},\n\t\t\t'aria-selected': index === selectedSuggestion ? true : undefined,\n\t\t};\n\t};\n\n\tif ( isFunction( renderSuggestions ) ) {\n\t\treturn renderSuggestions( {\n\t\t\tsuggestions,\n\t\t\tselectedSuggestion,\n\t\t\tsuggestionsListProps,\n\t\t\tbuildSuggestionItemProps,\n\t\t\tisLoading,\n\t\t\thandleSuggestionClick,\n\t\t\tisInitialSuggestions: ! suggestionsValue?.length,\n\t\t\tcurrentInputValue: suggestionsValue,\n\t\t} );\n\t}\n\n\treturn (\n\t\t<Popover placement=\"bottom\" focusOnMount={ false }>\n\t\t\t<div\n\t\t\t\t{ ...suggestionsListProps }\n\t\t\t\tclassName={ clsx( 'block-editor-url-input__suggestions', {\n\t\t\t\t\t[ `${ className }__suggestions` ]: className,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t{ suggestions.map( ( suggestion, index ) => (\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t{ ...buildSuggestionItemProps( suggestion, index ) }\n\t\t\t\t\t\tkey={ suggestion.id }\n\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t'block-editor-url-input__suggestion',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t'is-selected': index === selectedSuggestion,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tonClick={ () => handleSuggestionClick( suggestion ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ suggestion.title }\n\t\t\t\t\t</Button>\n\t\t\t\t) ) }\n\t\t\t</div>\n\t\t</Popover>\n\t);\n}\n"],
|
|
4
|
+
"sourcesContent": ["import clsx from 'clsx';\nimport { speak } from '@wordpress/a11y';\nimport { __, sprintf, _n } from '@wordpress/i18n';\nimport { useEffect, useRef, useState } from '@wordpress/element';\nimport { UP, DOWN, ENTER, TAB } from '@wordpress/keycodes';\nimport {\n\tBaseControl,\n\tButton,\n\t__experimentalInputControl as WCInputControl,\n\tSpinner,\n\tPopover,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { useDebounce, useEvent, useInstanceId } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { isURL } from '@wordpress/url';\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { ValidatedInputControl } = unlock( componentsPrivateApis );\n\nconst noop = () => {};\n\n/**\n * Whether the argument is a function.\n *\n * @param {*} maybeFunc The argument to check.\n * @return {boolean} True if the argument is a function, false otherwise.\n */\nfunction isFunction( maybeFunc ) {\n\treturn typeof maybeFunc === 'function';\n}\n\n/**\n * Text field for entering a URL, with an autocomplete list of matching posts,\n * pages and other link suggestions.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/url-input/README.md\n *\n * @param {Object} props Component props.\n */\nexport default function URLInput( props ) {\n\tconst {\n\t\t__experimentalFetchLinkSuggestions: fetchLinkSuggestionsProp,\n\t\t__experimentalHandleURLSuggestions: handleURLSuggestions,\n\t\t__experimentalRenderControl: renderControl,\n\t\t__experimentalRenderSuggestions: renderSuggestions,\n\t\t__experimentalShowInitialSuggestions: showInitialSuggestions = false,\n\t\tautocompleteRef,\n\t\tclassName,\n\t\tcustomValidity,\n\t\tdisableSuggestions,\n\t\tdisabled = false,\n\t\thelp = null,\n\t\thideLabelFromVision = false,\n\t\tinputRef,\n\t\tisFullWidth,\n\t\tlabel = null,\n\t\tmarkWhenOptional,\n\t\tonChange,\n\t\tonKeyDown,\n\t\tonSubmit,\n\t\tplaceholder = __( 'Paste URL or type to search' ),\n\t\trequired = true,\n\t\tsuffix,\n\t\tvalue = '',\n\t} = props;\n\n\tconst instanceId = useInstanceId( URLInput );\n\tconst { getSettings } = useSelect( blockEditorStore );\n\tconst debouncedSpeak = useDebounce( speak, 500 );\n\n\tconst [ suggestions, setSuggestions ] = useState( [] );\n\tconst [ suggestionsValue, setSuggestionsValue ] = useState( null );\n\tconst [ selectedSuggestion, setSelectedSuggestion ] = useState( null );\n\tconst [ isSuggestionsListOpen, setIsSuggestionsListOpen ] =\n\t\tuseState( false );\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst [ isComposing, setIsComposing ] = useState( false );\n\n\tconst fallbackInputRef = useRef();\n\tconst suggestionNodesRef = useRef( [] );\n\t// A fetch Promise can't be aborted. It's mimicked by holding on to the\n\t// pending request so that responses of superseded requests can be ignored.\n\tconst suggestionsRequestRef = useRef( null );\n\n\tconst controlInputRef = inputRef ?? fallbackInputRef;\n\n\tconst inputId = `url-input-control-${ instanceId }`;\n\tconst suggestionsListboxId = `block-editor-url-input-suggestions-${ instanceId }`;\n\tconst suggestionOptionIdPrefix = `block-editor-url-input-suggestion-${ instanceId }`;\n\n\t// The suggestions are hidden rather than discarded, so that returning focus\n\t// to a field that already has results doesn't trigger a new search.\n\tconst showSuggestions =\n\t\tisSuggestionsListOpen &&\n\t\tdisableSuggestions !== true &&\n\t\t( showInitialSuggestions || !! value.length );\n\n\tconst updateSuggestions = useEvent( ( searchValue = '' ) => {\n\t\tconst fetchLinkSuggestions = isFunction( fetchLinkSuggestionsProp )\n\t\t\t? fetchLinkSuggestionsProp\n\t\t\t: getSettings().__experimentalFetchLinkSuggestions;\n\n\t\tif ( ! fetchLinkSuggestions ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Initial suggestions may only show if there is no value\n\t\t// (note: this includes whitespace).\n\t\tconst isInitialSuggestions = ! searchValue?.length;\n\n\t\t// Trim only now we've determined whether or not it originally had a \"length\"\n\t\t// (even if that value was all whitespace).\n\t\tconst search = searchValue.trim();\n\n\t\t// Allow a suggestions request if:\n\t\t// - there are at least 2 characters in the search input (except manual searches where\n\t\t// search input length is not required to trigger a fetch)\n\t\t// - this is a direct entry (eg: a URL)\n\t\tif (\n\t\t\t! isInitialSuggestions &&\n\t\t\t( search.length < 2 ||\n\t\t\t\t( ! handleURLSuggestions && isURL( search ) ) )\n\t\t) {\n\t\t\tsuggestionsRequestRef.current?.cancel?.();\n\t\t\tsuggestionsRequestRef.current = null;\n\n\t\t\tsetSuggestions( [] );\n\t\t\tsetIsSuggestionsListOpen( false );\n\t\t\tsetSuggestionsValue( search );\n\t\t\tsetSelectedSuggestion( null );\n\t\t\tsetIsLoading( false );\n\n\t\t\treturn;\n\t\t}\n\n\t\tsetSelectedSuggestion( null );\n\t\tsetIsLoading( true );\n\n\t\tconst request = fetchLinkSuggestions( search, {\n\t\t\tisInitialSuggestions,\n\t\t} );\n\t\tsuggestionsRequestRef.current = request;\n\n\t\trequest\n\t\t\t.then( ( nextSuggestions ) => {\n\t\t\t\tif ( suggestionsRequestRef.current !== request ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetSuggestions( nextSuggestions );\n\t\t\t\tsetSuggestionsValue( search );\n\t\t\t\tsetIsLoading( false );\n\t\t\t\tsetIsSuggestionsListOpen( !! nextSuggestions.length );\n\n\t\t\t\tif ( nextSuggestions.length ) {\n\t\t\t\t\tdebouncedSpeak(\n\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t/* translators: %d: number of results. */\n\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t'%d result found, use up and down arrow keys to navigate.',\n\t\t\t\t\t\t\t\t'%d results found, use up and down arrow keys to navigate.',\n\t\t\t\t\t\t\t\tnextSuggestions.length\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tnextSuggestions.length\n\t\t\t\t\t\t),\n\t\t\t\t\t\t'assertive'\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tdebouncedSpeak( __( 'No results.' ), 'assertive' );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( () => {\n\t\t\t\tif ( suggestionsRequestRef.current !== request ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetIsLoading( false );\n\t\t\t} )\n\t\t\t.finally( () => {\n\t\t\t\tif ( suggestionsRequestRef.current === request ) {\n\t\t\t\t\tsuggestionsRequestRef.current = null;\n\t\t\t\t}\n\t\t\t} );\n\t} );\n\n\tconst debouncedUpdateSuggestions = useDebounce( updateSuggestions, 200 );\n\n\t// Keep the suggestions in sync with the value being searched for. An empty\n\t// value requests the initial suggestions, when those are enabled.\n\t// Composition state is a dependency, so the composed value is picked up\n\t// whether the browser reports it before or after `compositionend`.\n\tuseEffect( () => {\n\t\tif (\n\t\t\t! disableSuggestions &&\n\t\t\t! isComposing &&\n\t\t\t( value.length || showInitialSuggestions )\n\t\t) {\n\t\t\tdebouncedUpdateSuggestions( value );\n\t\t}\n\t}, [\n\t\tvalue,\n\t\tisComposing,\n\t\tdisableSuggestions,\n\t\tshowInitialSuggestions,\n\t\tdebouncedUpdateSuggestions,\n\t] );\n\n\t// Persist the hidden state, so that the list can't reappear with stale\n\t// results once the value or the props allow suggestions again.\n\tuseEffect( () => {\n\t\tif ( ! showSuggestions ) {\n\t\t\tsetIsSuggestionsListOpen( false );\n\t\t}\n\t}, [ showSuggestions ] );\n\n\tuseEffect( () => {\n\t\tif ( showSuggestions && selectedSuggestion !== null ) {\n\t\t\tsuggestionNodesRef.current[ selectedSuggestion ]?.scrollIntoView( {\n\t\t\t\tbehavior: 'instant',\n\t\t\t\tblock: 'nearest',\n\t\t\t\tinline: 'nearest',\n\t\t\t} );\n\t\t}\n\t}, [ showSuggestions, selectedSuggestion ] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tsuggestionsRequestRef.current?.cancel?.();\n\t\t\tsuggestionsRequestRef.current = null;\n\t\t};\n\t}, [] );\n\n\tfunction selectLink( suggestion ) {\n\t\tonChange( suggestion.url, suggestion );\n\t\tsetSelectedSuggestion( null );\n\t\tsetIsSuggestionsListOpen( false );\n\t}\n\n\tfunction handleSuggestionClick( suggestion ) {\n\t\tselectLink( suggestion );\n\t\t// Move focus to the input field when a link suggestion is clicked.\n\t\tcontrolInputRef.current.focus();\n\t}\n\n\tfunction handleChange( newValue ) {\n\t\t// `InputControl` passes an `{ event }` object as its second argument,\n\t\t// which callers would mistake for a selected suggestion.\n\t\tonChange( newValue );\n\t}\n\n\tfunction handleCompositionStart() {\n\t\tsetIsComposing( true );\n\t\t// Cancel any debounced suggestions update scheduled before the\n\t\t// composition started so no request fires while composing.\n\t\tdebouncedUpdateSuggestions.cancel();\n\t}\n\n\tfunction handleCompositionEnd() {\n\t\tsetIsComposing( false );\n\t}\n\n\tfunction handleFocus() {\n\t\t// When opening the link editor, if there's a value present, we want to load the suggestions pane with the results for this input search value\n\t\t// Don't re-run the suggestions on focus if there are already suggestions present (prevents searching again when tabbing between the input and buttons)\n\t\t// or there is already a request in progress.\n\t\tif (\n\t\t\tvalue &&\n\t\t\t! disableSuggestions &&\n\t\t\t! suggestions.length &&\n\t\t\tsuggestionsRequestRef.current === null\n\t\t) {\n\t\t\tdebouncedUpdateSuggestions( value );\n\t\t}\n\t}\n\n\tfunction handleKeyDown( event ) {\n\t\tonKeyDown?.( event );\n\n\t\t// Unless the list can consume them, the keys must reach the editor for\n\t\t// block navigation, so they mustn't be prevented.\n\t\tif ( ! showSuggestions || ! suggestions.length || isLoading ) {\n\t\t\t// Holding Shift extends the selection, which the browser handles.\n\t\t\tif (\n\t\t\t\t! event.shiftKey &&\n\t\t\t\t( event.keyCode === UP || event.keyCode === DOWN )\n\t\t\t) {\n\t\t\t\t// Firefox on Windows leaves the caret in place, trapping focus,\n\t\t\t\t// since the editor only navigates away from an edge.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/issues/5693#issuecomment-436684747\n\t\t\t\tconst caret =\n\t\t\t\t\tevent.keyCode === UP ? 0 : event.target.value.length;\n\n\t\t\t\t// UP moves the caret to the start of the text, DOWN to the end.\n\t\t\t\t// Once it is already there, with nothing selected, the key is\n\t\t\t\t// left to the editor to navigate out of the field.\n\t\t\t\tif (\n\t\t\t\t\tevent.target.selectionStart !== caret ||\n\t\t\t\t\tevent.target.selectionEnd !== caret\n\t\t\t\t) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tevent.target.setSelectionRange( caret, caret );\n\t\t\t\t}\n\t\t\t} else if ( event.keyCode === ENTER && onSubmit ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tonSubmit( null, event );\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst suggestion = suggestions[ selectedSuggestion ] ?? null;\n\n\t\tswitch ( event.keyCode ) {\n\t\t\tcase UP:\n\t\t\tcase DOWN: {\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\tconst offset = event.keyCode === UP ? -1 : 1;\n\t\t\t\t// An unselected list is entered from the end nearest the key,\n\t\t\t\t// and the ends wrap into each other.\n\t\t\t\tconst from = selectedSuggestion ?? ( offset === -1 ? 0 : -1 );\n\n\t\t\t\tsetSelectedSuggestion(\n\t\t\t\t\t( from + offset + suggestions.length ) % suggestions.length\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase TAB: {\n\t\t\t\tif ( suggestion ) {\n\t\t\t\t\tselectLink( suggestion );\n\t\t\t\t\tspeak( __( 'Link selected.' ) );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase ENTER: {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif ( suggestion ) {\n\t\t\t\t\tselectLink( suggestion );\n\t\t\t\t}\n\n\t\t\t\tonSubmit?.( suggestion, event );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst controlProps = {\n\t\tid: inputId, // Passes attribute to label for the for attribute\n\t\tlabel,\n\t\tclassName: clsx( 'block-editor-url-input', className, {\n\t\t\t'is-full-width': isFullWidth,\n\t\t} ),\n\t\thideLabelFromVision,\n\t};\n\n\tconst inputProps = {\n\t\tid: inputId,\n\t\tvalue,\n\t\trequired,\n\t\ttype: 'text',\n\t\tname: inputId,\n\t\tautoComplete: 'off',\n\t\tonChange: disabled ? noop : handleChange,\n\t\tonCompositionStart: disabled ? noop : handleCompositionStart,\n\t\tonCompositionEnd: disabled ? noop : handleCompositionEnd,\n\t\tonFocus: disabled ? noop : handleFocus,\n\t\tonKeyDown: disabled ? noop : handleKeyDown,\n\t\tplaceholder,\n\t\trole: 'combobox',\n\t\t'aria-label': label ? undefined : __( 'URL' ), // Ensure input always has an accessible label\n\t\t'aria-expanded': showSuggestions,\n\t\t'aria-autocomplete': 'list',\n\t\t'aria-owns': suggestionsListboxId,\n\t\t'aria-activedescendant':\n\t\t\tselectedSuggestion !== null\n\t\t\t\t? `${ suggestionOptionIdPrefix }-${ selectedSuggestion }`\n\t\t\t\t: undefined,\n\t\tref: controlInputRef,\n\t\tdisabled,\n\t\tsuffix,\n\t\thelp,\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<Control\n\t\t\t\tcontrolProps={ controlProps }\n\t\t\t\tinputProps={ inputProps }\n\t\t\t\tisLoading={ isLoading }\n\t\t\t\tcustomValidity={ customValidity }\n\t\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\t\trenderControl={ renderControl }\n\t\t\t/>\n\t\t\t{ showSuggestions && suggestions.length > 0 && (\n\t\t\t\t<Suggestions\n\t\t\t\t\tautocompleteRef={ autocompleteRef }\n\t\t\t\t\tclassName={ className }\n\t\t\t\t\thandleSuggestionClick={ handleSuggestionClick }\n\t\t\t\t\tisLoading={ isLoading }\n\t\t\t\t\trenderSuggestions={ renderSuggestions }\n\t\t\t\t\tselectedSuggestion={ selectedSuggestion }\n\t\t\t\t\tsuggestionNodesRef={ suggestionNodesRef }\n\t\t\t\t\tsuggestionOptionIdPrefix={ suggestionOptionIdPrefix }\n\t\t\t\t\tsuggestions={ suggestions }\n\t\t\t\t\tsuggestionsListboxId={ suggestionsListboxId }\n\t\t\t\t\tsuggestionsValue={ suggestionsValue }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction Control( {\n\tcontrolProps,\n\tinputProps,\n\tisLoading,\n\tcustomValidity,\n\tmarkWhenOptional,\n\trenderControl,\n} ) {\n\t// Once a validity has been reported, keep using the validated control, so\n\t// that clearing the validity doesn't remount (and blur) the input.\n\tconst [ isValidated, setIsValidated ] = useState(\n\t\tcustomValidity !== undefined\n\t);\n\n\tif ( customValidity !== undefined && ! isValidated ) {\n\t\tsetIsValidated( true );\n\t}\n\n\tif ( renderControl ) {\n\t\treturn renderControl( controlProps, inputProps, isLoading );\n\t}\n\n\tconst MaybeValidatedInputControl = isValidated\n\t\t? ValidatedInputControl\n\t\t: WCInputControl;\n\n\treturn (\n\t\t<BaseControl { ...controlProps }>\n\t\t\t<MaybeValidatedInputControl\n\t\t\t\t{ ...inputProps }\n\t\t\t\t{ ...( isValidated && {\n\t\t\t\t\tcustomValidity,\n\t\t\t\t\t// Suppress the \"(Required)\" indicator in the label.\n\t\t\t\t\t// The field is still required for validation, but the indicator\n\t\t\t\t\t// can be hidden when markWhenOptional is set to true.\n\t\t\t\t\t...( markWhenOptional !== undefined && {\n\t\t\t\t\t\tmarkWhenOptional,\n\t\t\t\t\t} ),\n\t\t\t\t} ) }\n\t\t\t/>\n\t\t\t{ isLoading && <Spinner /> }\n\t\t</BaseControl>\n\t);\n}\n\nfunction Suggestions( {\n\tautocompleteRef,\n\tclassName,\n\thandleSuggestionClick,\n\tisLoading,\n\trenderSuggestions,\n\tselectedSuggestion,\n\tsuggestionNodesRef,\n\tsuggestionOptionIdPrefix,\n\tsuggestions,\n\tsuggestionsListboxId,\n\tsuggestionsValue,\n} ) {\n\tconst suggestionsListProps = {\n\t\tid: suggestionsListboxId,\n\t\tref: autocompleteRef,\n\t\trole: 'listbox',\n\t};\n\n\tconst buildSuggestionItemProps = ( suggestion, index ) => {\n\t\treturn {\n\t\t\trole: 'option',\n\t\t\ttabIndex: '-1',\n\t\t\tid: `${ suggestionOptionIdPrefix }-${ index }`,\n\t\t\tref: ( node ) => {\n\t\t\t\tsuggestionNodesRef.current[ index ] = node;\n\t\t\t},\n\t\t\t'aria-selected': index === selectedSuggestion ? true : undefined,\n\t\t};\n\t};\n\n\tif ( isFunction( renderSuggestions ) ) {\n\t\treturn renderSuggestions( {\n\t\t\tsuggestions,\n\t\t\tselectedSuggestion,\n\t\t\tsuggestionsListProps,\n\t\t\tbuildSuggestionItemProps,\n\t\t\tisLoading,\n\t\t\thandleSuggestionClick,\n\t\t\tisInitialSuggestions: ! suggestionsValue?.length,\n\t\t\tcurrentInputValue: suggestionsValue,\n\t\t} );\n\t}\n\n\treturn (\n\t\t<Popover placement=\"bottom\" focusOnMount={ false }>\n\t\t\t<div\n\t\t\t\t{ ...suggestionsListProps }\n\t\t\t\tclassName={ clsx( 'block-editor-url-input__suggestions', {\n\t\t\t\t\t[ `${ className }__suggestions` ]: className,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t{ suggestions.map( ( suggestion, index ) => (\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t{ ...buildSuggestionItemProps( suggestion, index ) }\n\t\t\t\t\t\tkey={ suggestion.id }\n\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t'block-editor-url-input__suggestion',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t'is-selected': index === selectedSuggestion,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tonClick={ () => handleSuggestionClick( suggestion ) }\n\t\t\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B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,sBAAsB,CAAE,kBAAkB;AAAA,MAC1C,mBAAmB;AAAA,IACpB,CAAE;AAAA,EACH;AAEA,SACC,4CAAC,6BAAQ,WAAU,UAAS,cAAe,OAC1C;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACL,eAAY,YAAAD,SAAM,uCAAuC;AAAA,QACxD,CAAE,GAAI,SAAU,eAAgB,GAAG;AAAA,MACpC,CAAE;AAAA,MAEA,sBAAY,IAAK,CAAE,YAAY,UAChC;AAAA,QAAC;AAAA;AAAA,UACA,uBAAqB;AAAA,UACnB,GAAG,yBAA0B,YAAY,KAAM;AAAA,UACjD,KAAM,WAAW;AAAA,UACjB,eAAY,YAAAA;AAAA,YACX;AAAA,YACA;AAAA,cACC,eAAe,UAAU;AAAA,YAC1B;AAAA,UACD;AAAA,UACA,SAAU,MAAM,sBAAuB,UAAW;AAAA;AAAA,QAEhD,WAAW;AAAA,MACd,CACC;AAAA;AAAA,EACH,GACD;AAEF;",
|
|
6
|
-
"names": ["componentsPrivateApis", "blockEditorStore", "clsx", "
|
|
6
|
+
"names": ["componentsPrivateApis", "blockEditorStore", "clsx", "WCInputControl"]
|
|
7
7
|
}
|
|
@@ -42,7 +42,11 @@ function useInput() {
|
|
|
42
42
|
getBlockRootClientId,
|
|
43
43
|
getSelectionStart,
|
|
44
44
|
getSelectionEnd,
|
|
45
|
-
getBlockAttributes
|
|
45
|
+
getBlockAttributes,
|
|
46
|
+
getNextBlockClientId,
|
|
47
|
+
getBlockOrder,
|
|
48
|
+
getBlockEditingMode,
|
|
49
|
+
getBlockListSettings
|
|
46
50
|
} = (0, import_data.useSelect)(import_store.store);
|
|
47
51
|
const {
|
|
48
52
|
replaceBlocks,
|
|
@@ -50,7 +54,10 @@ function useInput() {
|
|
|
50
54
|
removeBlocks,
|
|
51
55
|
__unstableDeleteSelection,
|
|
52
56
|
__unstableExpandSelection,
|
|
53
|
-
__unstableMarkAutomaticChange
|
|
57
|
+
__unstableMarkAutomaticChange,
|
|
58
|
+
insertAfterBlock,
|
|
59
|
+
insertBlock,
|
|
60
|
+
selectBlock
|
|
54
61
|
} = (0, import_data.useDispatch)(import_store.store);
|
|
55
62
|
return (0, import_compose.useRefEffect)((node) => {
|
|
56
63
|
function onBeforeInput(event) {
|
|
@@ -72,7 +79,7 @@ function useInput() {
|
|
|
72
79
|
}
|
|
73
80
|
if (!hasMultiSelection()) {
|
|
74
81
|
if (event.keyCode === import_keycodes.ENTER) {
|
|
75
|
-
if (event.shiftKey
|
|
82
|
+
if (event.shiftKey) {
|
|
76
83
|
return;
|
|
77
84
|
}
|
|
78
85
|
const clientId = getSelectedBlockClientId();
|
|
@@ -103,18 +110,63 @@ function useInput() {
|
|
|
103
110
|
return;
|
|
104
111
|
}
|
|
105
112
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (canInsertBlockType(
|
|
113
|
+
const rootClientId = getBlockRootClientId(clientId);
|
|
114
|
+
const { activeElement } = event.target.ownerDocument;
|
|
115
|
+
if (!__unstableIsFullySelected() && (canInsertBlockType(
|
|
110
116
|
(0, import_blocks.getDefaultBlockName)(),
|
|
111
|
-
|
|
112
|
-
) || canInsertBlockType(
|
|
113
|
-
blockName,
|
|
114
|
-
getBlockRootClientId(clientId)
|
|
115
|
-
)) {
|
|
116
|
-
__unstableSplitSelection();
|
|
117
|
+
rootClientId
|
|
118
|
+
) || canInsertBlockType(blockName, rootClientId)) && ((0, import_blocks.hasBlockSupport)(blockName, "splitting", false) || event.__deprecatedOnSplit)) {
|
|
117
119
|
event.preventDefault();
|
|
120
|
+
__unstableSplitSelection();
|
|
121
|
+
} else if (
|
|
122
|
+
// Handle Enter only on the block wrapper itself or
|
|
123
|
+
// an editable element within the block, which may be
|
|
124
|
+
// nested within the wrapper (e.g. Site Title). Other
|
|
125
|
+
// focusable elements (an embed's URL field, an
|
|
126
|
+
// appender button) keep their native Enter behavior.
|
|
127
|
+
(activeElement.getAttribute("data-block") === clientId || activeElement.isContentEditable) && (0, import_dom.getBlockClientId)(activeElement) === clientId
|
|
128
|
+
) {
|
|
129
|
+
const { defaultBlock: directInsertBlock } = rootClientId && getBlockListSettings(rootClientId) || {};
|
|
130
|
+
if (canInsertBlockType(
|
|
131
|
+
directInsertBlock?.name ?? (0, import_blocks.getDefaultBlockName)(),
|
|
132
|
+
rootClientId
|
|
133
|
+
)) {
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
insertAfterBlock(clientId);
|
|
136
|
+
} else {
|
|
137
|
+
let getNextClientId2 = function(id) {
|
|
138
|
+
let nextClientId2 = null;
|
|
139
|
+
while (typeof id === "string" && !(nextClientId2 = getNextBlockClientId(id))) {
|
|
140
|
+
id = getBlockRootClientId(id);
|
|
141
|
+
}
|
|
142
|
+
return nextClientId2;
|
|
143
|
+
};
|
|
144
|
+
var getNextClientId = getNextClientId2;
|
|
145
|
+
if (!getBlockOrder(clientId).length) {
|
|
146
|
+
const { defaultBlock } = getBlockListSettings(clientId) ?? {};
|
|
147
|
+
const name = defaultBlock?.name ?? (0, import_blocks.getDefaultBlockName)();
|
|
148
|
+
if (canInsertBlockType(name, clientId)) {
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
insertBlock(
|
|
151
|
+
(0, import_blocks.createBlock)(
|
|
152
|
+
name,
|
|
153
|
+
defaultBlock?.attributes
|
|
154
|
+
),
|
|
155
|
+
0,
|
|
156
|
+
clientId
|
|
157
|
+
);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
let nextClientId = getBlockOrder(clientId)[0] ?? getNextClientId2(clientId);
|
|
162
|
+
while (nextClientId && getBlockEditingMode(nextClientId) === "disabled") {
|
|
163
|
+
nextClientId = getNextClientId2(nextClientId);
|
|
164
|
+
}
|
|
165
|
+
if (nextClientId) {
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
selectBlock(nextClientId, true);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
118
170
|
}
|
|
119
171
|
}
|
|
120
172
|
return;
|