@wordpress/block-library 9.33.5 → 9.33.7

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.
Files changed (56) hide show
  1. package/build/heading/index.js +3 -1
  2. package/build/heading/index.js.map +3 -3
  3. package/build/heading/variations.js +53 -0
  4. package/build/heading/variations.js.map +7 -0
  5. package/build/navigation-link/edit.js +25 -10
  6. package/build/navigation-link/edit.js.map +2 -2
  7. package/build/navigation-link/link-ui/index.js +8 -3
  8. package/build/navigation-link/link-ui/index.js.map +2 -2
  9. package/build/navigation-link/shared/controls.js +76 -21
  10. package/build/navigation-link/shared/controls.js.map +2 -2
  11. package/build/navigation-link/shared/use-entity-binding.js +31 -2
  12. package/build/navigation-link/shared/use-entity-binding.js.map +3 -3
  13. package/build/paragraph/index.js +3 -1
  14. package/build/paragraph/index.js.map +3 -3
  15. package/build/paragraph/variations.js +55 -0
  16. package/build/paragraph/variations.js.map +7 -0
  17. package/build-module/heading/index.js +3 -1
  18. package/build-module/heading/index.js.map +2 -2
  19. package/build-module/heading/variations.js +33 -0
  20. package/build-module/heading/variations.js.map +7 -0
  21. package/build-module/navigation-link/edit.js +25 -10
  22. package/build-module/navigation-link/edit.js.map +2 -2
  23. package/build-module/navigation-link/link-ui/index.js +8 -3
  24. package/build-module/navigation-link/link-ui/index.js.map +2 -2
  25. package/build-module/navigation-link/shared/controls.js +77 -22
  26. package/build-module/navigation-link/shared/controls.js.map +2 -2
  27. package/build-module/navigation-link/shared/use-entity-binding.js +35 -3
  28. package/build-module/navigation-link/shared/use-entity-binding.js.map +2 -2
  29. package/build-module/paragraph/index.js +3 -1
  30. package/build-module/paragraph/index.js.map +2 -2
  31. package/build-module/paragraph/variations.js +35 -0
  32. package/build-module/paragraph/variations.js.map +7 -0
  33. package/build-style/accordion-heading/style-rtl.css +19 -3
  34. package/build-style/accordion-heading/style.css +19 -3
  35. package/build-style/accordion-panel/style-rtl.css +4 -1
  36. package/build-style/accordion-panel/style.css +4 -1
  37. package/build-style/editor-rtl.css +7 -0
  38. package/build-style/editor.css +7 -0
  39. package/build-style/navigation-link/editor-rtl.css +7 -0
  40. package/build-style/navigation-link/editor.css +7 -0
  41. package/build-style/style-rtl.css +23 -4
  42. package/build-style/style.css +23 -4
  43. package/package.json +11 -11
  44. package/src/accordion-heading/style.scss +40 -7
  45. package/src/accordion-panel/style.scss +6 -1
  46. package/src/heading/index.js +2 -0
  47. package/src/heading/variations.js +37 -0
  48. package/src/navigation-link/edit.js +44 -13
  49. package/src/navigation-link/editor.scss +7 -0
  50. package/src/navigation-link/link-ui/index.js +9 -8
  51. package/src/navigation-link/shared/controls.js +123 -25
  52. package/src/navigation-link/shared/test/controls.js +19 -9
  53. package/src/navigation-link/shared/test/use-entity-binding.js +14 -1
  54. package/src/navigation-link/shared/use-entity-binding.js +57 -9
  55. package/src/paragraph/index.js +2 -0
  56. package/src/paragraph/variations.js +39 -0
@@ -42,6 +42,7 @@ var import_edit = __toESM(require("./edit"));
42
42
  var import_block = __toESM(require("./block.json"));
43
43
  var import_save = __toESM(require("./save"));
44
44
  var import_transforms = __toESM(require("./transforms"));
45
+ var import_variations = __toESM(require("./variations"));
45
46
  const { name } = import_block.default;
46
47
  const settings = {
47
48
  icon: import_icons.heading,
@@ -80,7 +81,8 @@ const settings = {
80
81
  };
81
82
  },
82
83
  edit: import_edit.default,
83
- save: import_save.default
84
+ save: import_save.default,
85
+ variations: import_variations.default
84
86
  };
85
87
  const init = () => (0, import_init_block.default)({ name, metadata: import_block.default, settings });
86
88
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/heading/index.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { heading as icon } from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tcontent: __( 'Code is Poetry' ),\n\t\t\tlevel: 2,\n\t\t\ttextAlign: 'center',\n\t\t},\n\t},\n\t__experimentalLabel( attributes, { context } ) {\n\t\tconst { content, level } = attributes;\n\n\t\tconst customName = attributes?.metadata?.name;\n\t\tconst hasContent = content?.trim().length > 0;\n\n\t\t// In the list view, use the block's content as the label.\n\t\t// If the content is empty, fall back to the default label.\n\t\tif ( context === 'list-view' && ( customName || hasContent ) ) {\n\t\t\treturn customName || content;\n\t\t}\n\n\t\tif ( context === 'accessibility' ) {\n\t\t\treturn ! hasContent\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t/* translators: accessibility text. %s: heading level. */\n\t\t\t\t\t\t__( 'Level %s. Empty.' ),\n\t\t\t\t\t\tlevel\n\t\t\t\t )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: accessibility text. 1: heading level. 2: heading content. */\n\t\t\t\t\t\t__( 'Level %1$s. %2$s' ),\n\t\t\t\t\t\tlevel,\n\t\t\t\t\t\tcontent\n\t\t\t\t );\n\t\t}\n\t},\n\ttransforms,\n\tdeprecated,\n\tmerge( attributes, attributesToMerge ) {\n\t\treturn {\n\t\t\tcontent:\n\t\t\t\t( attributes.content || '' ) +\n\t\t\t\t( attributesToMerge.content || '' ),\n\t\t};\n\t},\n\tedit,\n\tsave,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,+BAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAGA,mBAAgC;AAChC,kBAA4B;AAK5B,wBAAsB;AACtB,wBAAuB;AACvB,kBAAiB;AACjB,mBAAqB;AACrB,kBAAiB;AACjB,wBAAuB;AAEvB,MAAM,EAAE,KAAK,IAAI,aAAAA;AAIV,MAAM,WAAW;AAAA,EACvB,mBAAAC;AAAA,EACA,SAAS;AAAA,IACR,YAAY;AAAA,MACX,aAAS,gBAAI,gBAAiB;AAAA,MAC9B,OAAO;AAAA,MACP,WAAW;AAAA,IACZ;AAAA,EACD;AAAA,EACA,oBAAqB,YAAY,EAAE,QAAQ,GAAI;AAC9C,UAAM,EAAE,SAAS,MAAM,IAAI;AAE3B,UAAM,aAAa,YAAY,UAAU;AACzC,UAAM,aAAa,SAAS,KAAK,EAAE,SAAS;AAI5C,QAAK,YAAY,gBAAiB,cAAc,aAAe;AAC9D,aAAO,cAAc;AAAA,IACtB;AAEA,QAAK,YAAY,iBAAkB;AAClC,aAAO,CAAE,iBACN;AAAA;AAAA,YAEA,gBAAI,kBAAmB;AAAA,QACvB;AAAA,MACA,QACA;AAAA;AAAA,YAEA,gBAAI,kBAAmB;AAAA,QACvB;AAAA,QACA;AAAA,MACA;AAAA,IACJ;AAAA,EACD;AAAA,EACA,8BAAAC;AAAA,EACA,8BAAAC;AAAA,EACA,MAAO,YAAY,mBAAoB;AACtC,WAAO;AAAA,MACN,UACG,WAAW,WAAW,OACtB,kBAAkB,WAAW;AAAA,IACjC;AAAA,EACD;AAAA,EACA,kBAAAC;AAAA,EACA,kBAAAC;AACD;AAEO,MAAM,OAAO,UAAM,kBAAAC,SAAW,EAAE,MAAM,uBAAAN,SAAU,SAAS,CAAE;",
6
- "names": ["metadata", "icon", "transforms", "deprecated", "edit", "save", "initBlock"]
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { heading as icon } from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport variations from './variations';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tcontent: __( 'Code is Poetry' ),\n\t\t\tlevel: 2,\n\t\t\ttextAlign: 'center',\n\t\t},\n\t},\n\t__experimentalLabel( attributes, { context } ) {\n\t\tconst { content, level } = attributes;\n\n\t\tconst customName = attributes?.metadata?.name;\n\t\tconst hasContent = content?.trim().length > 0;\n\n\t\t// In the list view, use the block's content as the label.\n\t\t// If the content is empty, fall back to the default label.\n\t\tif ( context === 'list-view' && ( customName || hasContent ) ) {\n\t\t\treturn customName || content;\n\t\t}\n\n\t\tif ( context === 'accessibility' ) {\n\t\t\treturn ! hasContent\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t/* translators: accessibility text. %s: heading level. */\n\t\t\t\t\t\t__( 'Level %s. Empty.' ),\n\t\t\t\t\t\tlevel\n\t\t\t\t )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: accessibility text. 1: heading level. 2: heading content. */\n\t\t\t\t\t\t__( 'Level %1$s. %2$s' ),\n\t\t\t\t\t\tlevel,\n\t\t\t\t\t\tcontent\n\t\t\t\t );\n\t\t}\n\t},\n\ttransforms,\n\tdeprecated,\n\tmerge( attributes, attributesToMerge ) {\n\t\treturn {\n\t\t\tcontent:\n\t\t\t\t( attributes.content || '' ) +\n\t\t\t\t( attributesToMerge.content || '' ),\n\t\t};\n\t},\n\tedit,\n\tsave,\n\tvariations,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,+BAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAGA,mBAAgC;AAChC,kBAA4B;AAK5B,wBAAsB;AACtB,wBAAuB;AACvB,kBAAiB;AACjB,mBAAqB;AACrB,kBAAiB;AACjB,wBAAuB;AACvB,wBAAuB;AAEvB,MAAM,EAAE,KAAK,IAAI,aAAAA;AAIV,MAAM,WAAW;AAAA,EACvB,mBAAAC;AAAA,EACA,SAAS;AAAA,IACR,YAAY;AAAA,MACX,aAAS,gBAAI,gBAAiB;AAAA,MAC9B,OAAO;AAAA,MACP,WAAW;AAAA,IACZ;AAAA,EACD;AAAA,EACA,oBAAqB,YAAY,EAAE,QAAQ,GAAI;AAC9C,UAAM,EAAE,SAAS,MAAM,IAAI;AAE3B,UAAM,aAAa,YAAY,UAAU;AACzC,UAAM,aAAa,SAAS,KAAK,EAAE,SAAS;AAI5C,QAAK,YAAY,gBAAiB,cAAc,aAAe;AAC9D,aAAO,cAAc;AAAA,IACtB;AAEA,QAAK,YAAY,iBAAkB;AAClC,aAAO,CAAE,iBACN;AAAA;AAAA,YAEA,gBAAI,kBAAmB;AAAA,QACvB;AAAA,MACA,QACA;AAAA;AAAA,YAEA,gBAAI,kBAAmB;AAAA,QACvB;AAAA,QACA;AAAA,MACA;AAAA,IACJ;AAAA,EACD;AAAA,EACA,8BAAAC;AAAA,EACA,8BAAAC;AAAA,EACA,MAAO,YAAY,mBAAoB;AACtC,WAAO;AAAA,MACN,UACG,WAAW,WAAW,OACtB,kBAAkB,WAAW;AAAA,IACjC;AAAA,EACD;AAAA,EACA,kBAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,8BAAAC;AACD;AAEO,MAAM,OAAO,UAAM,kBAAAC,SAAW,EAAE,MAAM,uBAAAP,SAAU,SAAS,CAAE;",
6
+ "names": ["metadata", "icon", "transforms", "deprecated", "edit", "save", "variations", "initBlock"]
7
7
  }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var variations_exports = {};
20
+ __export(variations_exports, {
21
+ default: () => variations_default
22
+ });
23
+ module.exports = __toCommonJS(variations_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ var import_i18n = require("@wordpress/i18n");
26
+ var import_primitives = require("@wordpress/primitives");
27
+ var import_icons = require("@wordpress/icons");
28
+ const variations = [
29
+ {
30
+ name: "heading",
31
+ title: (0, import_i18n.__)("Heading"),
32
+ description: (0, import_i18n.__)(
33
+ "Introduce new sections and organize content to help visitors (and search engines) understand the structure of your content."
34
+ ),
35
+ isDefault: true,
36
+ scope: ["inserter", "transform"],
37
+ attributes: { fitText: void 0 },
38
+ icon: import_icons.heading
39
+ },
40
+ // There is a hardcoded workaround in packages/block-editor/src/store/selectors.js
41
+ // to make Stretchy variations appear as the last of their sections in the inserter.
42
+ {
43
+ name: "stretchy-heading",
44
+ title: (0, import_i18n.__)("Stretchy Heading"),
45
+ description: (0, import_i18n.__)("Heading that resizes to fit its container."),
46
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.Path, { d: "m3 18.6 6-4.7 6 4.7V5H3v13.6Zm16.2-9.8v1.5h2.2L17.7 14l1.1 1.1 3.7-3.7v2.2H24V8.8h-4.8Z" }) }),
47
+ attributes: { fitText: true },
48
+ scope: ["inserter", "transform"],
49
+ isActive: (blockAttributes) => blockAttributes.fitText === true
50
+ }
51
+ ];
52
+ var variations_default = variations;
53
+ //# sourceMappingURL=variations.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/heading/variations.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Path, SVG } from '@wordpress/primitives';\nimport { heading } from '@wordpress/icons';\n\nconst variations = [\n\t{\n\t\tname: 'heading',\n\t\ttitle: __( 'Heading' ),\n\t\tdescription: __(\n\t\t\t'Introduce new sections and organize content to help visitors (and search engines) understand the structure of your content.'\n\t\t),\n\t\tisDefault: true,\n\t\tscope: [ 'inserter', 'transform' ],\n\t\tattributes: { fitText: undefined },\n\t\ticon: heading,\n\t},\n\t// There is a hardcoded workaround in packages/block-editor/src/store/selectors.js\n\t// to make Stretchy variations appear as the last of their sections in the inserter.\n\t{\n\t\tname: 'stretchy-heading',\n\t\ttitle: __( 'Stretchy Heading' ),\n\t\tdescription: __( 'Heading that resizes to fit its container.' ),\n\t\ticon: (\n\t\t\t<SVG xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">\n\t\t\t\t<Path d=\"m3 18.6 6-4.7 6 4.7V5H3v13.6Zm16.2-9.8v1.5h2.2L17.7 14l1.1 1.1 3.7-3.7v2.2H24V8.8h-4.8Z\" />\n\t\t\t</SVG>\n\t\t),\n\t\tattributes: { fitText: true },\n\t\tscope: [ 'inserter', 'transform' ],\n\t\tisActive: ( blockAttributes ) => blockAttributes.fitText === true,\n\t},\n];\n\nexport default variations;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BI;AAxBJ,kBAAmB;AACnB,wBAA0B;AAC1B,mBAAwB;AAExB,MAAM,aAAa;AAAA,EAClB;AAAA,IACC,MAAM;AAAA,IACN,WAAO,gBAAI,SAAU;AAAA,IACrB,iBAAa;AAAA,MACZ;AAAA,IACD;AAAA,IACA,WAAW;AAAA,IACX,OAAO,CAAE,YAAY,WAAY;AAAA,IACjC,YAAY,EAAE,SAAS,OAAU;AAAA,IACjC,MAAM;AAAA,EACP;AAAA;AAAA;AAAA,EAGA;AAAA,IACC,MAAM;AAAA,IACN,WAAO,gBAAI,kBAAmB;AAAA,IAC9B,iBAAa,gBAAI,4CAA6C;AAAA,IAC9D,MACC,4CAAC,yBAAI,OAAM,8BAA6B,SAAQ,aAC/C,sDAAC,0BAAK,GAAE,2FAA0F,GACnG;AAAA,IAED,YAAY,EAAE,SAAS,KAAK;AAAA,IAC5B,OAAO,CAAE,YAAY,WAAY;AAAA,IACjC,UAAU,CAAE,oBAAqB,gBAAgB,YAAY;AAAA,EAC9D;AACD;AAEA,IAAO,qBAAQ;",
6
+ "names": []
7
+ }
@@ -84,20 +84,30 @@ const useIsInvalidLink = (kind, type, id, enabled) => {
84
84
  const isPostType = kind === "post-type" || type === "post" || type === "page";
85
85
  const hasId = Number.isInteger(id);
86
86
  const blockEditingMode = (0, import_block_editor.useBlockEditingMode)();
87
- const postStatus = (0, import_data.useSelect)(
87
+ const { postStatus, isDeleted } = (0, import_data.useSelect)(
88
88
  (select) => {
89
89
  if (!isPostType) {
90
- return null;
90
+ return { postStatus: null, isDeleted: false };
91
91
  }
92
92
  if (blockEditingMode === "disabled" || !enabled) {
93
- return null;
93
+ return { postStatus: null, isDeleted: false };
94
94
  }
95
- const { getEntityRecord } = select(import_core_data.store);
96
- return getEntityRecord("postType", type, id)?.status;
95
+ const { getEntityRecord, hasFinishedResolution } = select(import_core_data.store);
96
+ const entityRecord = getEntityRecord("postType", type, id);
97
+ const hasResolved = hasFinishedResolution("getEntityRecord", [
98
+ "postType",
99
+ type,
100
+ id
101
+ ]);
102
+ const deleted = hasResolved && entityRecord === void 0;
103
+ return {
104
+ postStatus: entityRecord?.status,
105
+ isDeleted: deleted
106
+ };
97
107
  },
98
108
  [isPostType, blockEditingMode, enabled, type, id]
99
109
  );
100
- const isInvalid = isPostType && hasId && postStatus && "trash" === postStatus;
110
+ const isInvalid = isPostType && hasId && (isDeleted || postStatus && "trash" === postStatus);
101
111
  const isDraft = "draft" === postStatus;
102
112
  return [isInvalid, isDraft];
103
113
  };
@@ -189,7 +199,12 @@ function NavigationLinkEdit({
189
199
  [clientId, maxNestingLevel]
190
200
  );
191
201
  const { getBlocks } = (0, import_data.useSelect)(import_block_editor.store);
192
- const { clearBinding, createBinding } = (0, import_shared.useEntityBinding)({
202
+ const {
203
+ clearBinding,
204
+ createBinding,
205
+ hasUrlBinding,
206
+ isBoundEntityAvailable
207
+ } = (0, import_shared.useEntityBinding)({
193
208
  clientId,
194
209
  attributes
195
210
  });
@@ -296,13 +311,13 @@ function NavigationLinkEdit({
296
311
  renderAppender: false
297
312
  }
298
313
  );
299
- if (!url || isInvalid || isDraft) {
314
+ if (!url || isInvalid || isDraft || hasUrlBinding && !isBoundEntityAvailable) {
300
315
  blockProps.onClick = () => {
301
316
  setIsLinkOpen(true);
302
317
  };
303
318
  }
304
319
  const classes = (0, import_clsx.default)("wp-block-navigation-item__content", {
305
- "wp-block-navigation-link__placeholder": !url || isInvalid || isDraft
320
+ "wp-block-navigation-link__placeholder": !url || isInvalid || isDraft || hasUrlBinding && !isBoundEntityAvailable
306
321
  });
307
322
  const missingText = getMissingText(type);
308
323
  const placeholderText = `(${isInvalid ? (0, import_i18n.__)("Invalid") : (0, import_i18n.__)("Draft")})`;
@@ -398,7 +413,7 @@ function NavigationLinkEdit({
398
413
  link: attributes,
399
414
  onClose: () => {
400
415
  setIsLinkOpen(false);
401
- if (!url) {
416
+ if (!url && !hasUrlBinding) {
402
417
  onReplace([]);
403
418
  } else if (isNewLink.current) {
404
419
  selectBlock(clientId);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/navigation-link/edit.js"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { displayShortcut, isKeyboardEvent } from '@wordpress/keycodes';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tRichText,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\tgetColorClassName,\n\tuseInnerBlocksProps,\n\tuseBlockEditingMode,\n} from '@wordpress/block-editor';\nimport { isURL, prependHTTP } from '@wordpress/url';\nimport { useState, useEffect, useRef, useCallback } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { link as linkIcon, addSubmenu } from '@wordpress/icons';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useMergeRefs, usePrevious } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getColors } from '../navigation/edit/utils';\nimport { Controls, LinkUI, updateAttributes, useEntityBinding } from './shared';\n\nconst DEFAULT_BLOCK = { name: 'core/navigation-link' };\nconst NESTING_BLOCK_NAMES = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n];\n\n/**\n * A React hook to determine if it's dragging within the target element.\n *\n * @typedef {import('@wordpress/element').RefObject} RefObject\n *\n * @param {RefObject<HTMLElement>} elementRef The target elementRef object.\n *\n * @return {boolean} Is dragging within the target element.\n */\nconst useIsDraggingWithin = ( elementRef ) => {\n\tconst [ isDraggingWithin, setIsDraggingWithin ] = useState( false );\n\n\tuseEffect( () => {\n\t\tconst { ownerDocument } = elementRef.current;\n\n\t\tfunction handleDragStart( event ) {\n\t\t\t// Check the first time when the dragging starts.\n\t\t\thandleDragEnter( event );\n\t\t}\n\n\t\t// Set to false whenever the user cancel the drag event by either releasing the mouse or press Escape.\n\t\tfunction handleDragEnd() {\n\t\t\tsetIsDraggingWithin( false );\n\t\t}\n\n\t\tfunction handleDragEnter( event ) {\n\t\t\t// Check if the current target is inside the item element.\n\t\t\tif ( elementRef.current.contains( event.target ) ) {\n\t\t\t\tsetIsDraggingWithin( true );\n\t\t\t} else {\n\t\t\t\tsetIsDraggingWithin( false );\n\t\t\t}\n\t\t}\n\n\t\t// Bind these events to the document to catch all drag events.\n\t\t// Ideally, we can also use `event.relatedTarget`, but sadly that\n\t\t// doesn't work in Safari.\n\t\townerDocument.addEventListener( 'dragstart', handleDragStart );\n\t\townerDocument.addEventListener( 'dragend', handleDragEnd );\n\t\townerDocument.addEventListener( 'dragenter', handleDragEnter );\n\n\t\treturn () => {\n\t\t\townerDocument.removeEventListener( 'dragstart', handleDragStart );\n\t\t\townerDocument.removeEventListener( 'dragend', handleDragEnd );\n\t\t\townerDocument.removeEventListener( 'dragenter', handleDragEnter );\n\t\t};\n\t}, [ elementRef ] );\n\n\treturn isDraggingWithin;\n};\n\nconst useIsInvalidLink = ( kind, type, id, enabled ) => {\n\tconst isPostType =\n\t\tkind === 'post-type' || type === 'post' || type === 'page';\n\tconst hasId = Number.isInteger( id );\n\tconst blockEditingMode = useBlockEditingMode();\n\n\tconst postStatus = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! isPostType ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\t// Fetching the posts status is an \"expensive\" operation. Especially for sites with large navigations.\n\t\t\t// When the block is rendered in a template or other disabled contexts we can skip this check in order\n\t\t\t// to avoid all these additional requests that don't really add any value in that mode.\n\t\t\tif ( blockEditingMode === 'disabled' || ! enabled ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst { getEntityRecord } = select( coreStore );\n\t\t\treturn getEntityRecord( 'postType', type, id )?.status;\n\t\t},\n\t\t[ isPostType, blockEditingMode, enabled, type, id ]\n\t);\n\n\t// Check Navigation Link validity if:\n\t// 1. Link is 'post-type'.\n\t// 2. It has an id.\n\t// 3. It's neither null, nor undefined, as valid items might be either of those while loading.\n\t// If those conditions are met, check if\n\t// 1. The post status is published.\n\t// 2. The Navigation Link item has no label.\n\t// If either of those is true, invalidate.\n\tconst isInvalid =\n\t\tisPostType && hasId && postStatus && 'trash' === postStatus;\n\tconst isDraft = 'draft' === postStatus;\n\n\treturn [ isInvalid, isDraft ];\n};\n\nfunction getMissingText( type ) {\n\tlet missingText = '';\n\n\tswitch ( type ) {\n\t\tcase 'post':\n\t\t\t/* translators: label for missing post in navigation link block */\n\t\t\tmissingText = __( 'Select post' );\n\t\t\tbreak;\n\t\tcase 'page':\n\t\t\t/* translators: label for missing page in navigation link block */\n\t\t\tmissingText = __( 'Select page' );\n\t\t\tbreak;\n\t\tcase 'category':\n\t\t\t/* translators: label for missing category in navigation link block */\n\t\t\tmissingText = __( 'Select category' );\n\t\t\tbreak;\n\t\tcase 'tag':\n\t\t\t/* translators: label for missing tag in navigation link block */\n\t\t\tmissingText = __( 'Select tag' );\n\t\t\tbreak;\n\t\tdefault:\n\t\t\t/* translators: label for missing values in navigation link block */\n\t\t\tmissingText = __( 'Add link' );\n\t}\n\n\treturn missingText;\n}\n\nexport default function NavigationLinkEdit( {\n\tattributes,\n\tisSelected,\n\tsetAttributes,\n\tinsertBlocksAfter,\n\tmergeBlocks,\n\tonReplace,\n\tcontext,\n\tclientId,\n} ) {\n\tconst { id, label, type, url, description, kind, metadata } = attributes;\n\tconst { maxNestingLevel } = context;\n\n\tconst {\n\t\treplaceBlock,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\tselectBlock,\n\t} = useDispatch( blockEditorStore );\n\t// Have the link editing ui open on mount when lacking a url and selected.\n\tconst [ isLinkOpen, setIsLinkOpen ] = useState( isSelected && ! url );\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\tconst listItemRef = useRef( null );\n\tconst isDraggingWithin = useIsDraggingWithin( listItemRef );\n\tconst itemLabelPlaceholder = __( 'Add label\u2026' );\n\tconst ref = useRef();\n\tconst linkUIref = useRef();\n\tconst prevUrl = usePrevious( url );\n\tconst isNewLink = useRef( ! url );\n\n\tconst {\n\t\tisAtMaxNesting,\n\t\tisTopLevelLink,\n\t\tisParentOfSelectedBlock,\n\t\thasChildren,\n\t\tvalidateLinkStatus,\n\t\tparentBlockClientId,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockCount,\n\t\t\t\tgetBlockName,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\thasSelectedInnerBlock,\n\t\t\t\tgetBlockParentsByBlockName,\n\t\t\t\tgetSelectedBlockClientId,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\t\t\tconst parentBlockName = getBlockName( rootClientId );\n\t\t\tconst isTopLevel = parentBlockName === 'core/navigation';\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\t\t\tconst rootNavigationClientId = isTopLevel\n\t\t\t\t? rootClientId\n\t\t\t\t: getBlockParentsByBlockName(\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t'core/navigation'\n\t\t\t\t )[ 0 ];\n\n\t\t\t// Get the immediate parent - if it's a submenu, use it; otherwise use the navigation block\n\t\t\tconst parentBlockId =\n\t\t\t\tparentBlockName === 'core/navigation-submenu'\n\t\t\t\t\t? rootClientId\n\t\t\t\t\t: rootNavigationClientId;\n\n\t\t\t// Enable when the root Navigation block is selected or any of its inner blocks.\n\t\t\tconst enableLinkStatusValidation =\n\t\t\t\tselectedBlockClientId === rootNavigationClientId ||\n\t\t\t\thasSelectedInnerBlock( rootNavigationClientId, true );\n\n\t\t\treturn {\n\t\t\t\tisAtMaxNesting:\n\t\t\t\t\tgetBlockParentsByBlockName( clientId, NESTING_BLOCK_NAMES )\n\t\t\t\t\t\t.length >= maxNestingLevel,\n\t\t\t\tisTopLevelLink: isTopLevel,\n\t\t\t\tisParentOfSelectedBlock: hasSelectedInnerBlock(\n\t\t\t\t\tclientId,\n\t\t\t\t\ttrue\n\t\t\t\t),\n\t\t\t\thasChildren: !! getBlockCount( clientId ),\n\t\t\t\tvalidateLinkStatus: enableLinkStatusValidation,\n\t\t\t\tparentBlockClientId: parentBlockId,\n\t\t\t};\n\t\t},\n\t\t[ clientId, maxNestingLevel ]\n\t);\n\tconst { getBlocks } = useSelect( blockEditorStore );\n\n\t// URL binding logic\n\tconst { clearBinding, createBinding } = useEntityBinding( {\n\t\tclientId,\n\t\tattributes,\n\t} );\n\n\tconst [ isInvalid, isDraft ] = useIsInvalidLink(\n\t\tkind,\n\t\ttype,\n\t\tid,\n\t\tvalidateLinkStatus\n\t);\n\n\t/**\n\t * Transform to submenu block.\n\t */\n\tconst transformToSubmenu = useCallback( () => {\n\t\tlet innerBlocks = getBlocks( clientId );\n\t\tif ( innerBlocks.length === 0 ) {\n\t\t\tinnerBlocks = [ createBlock( 'core/navigation-link' ) ];\n\t\t\tselectBlock( innerBlocks[ 0 ].clientId );\n\t\t}\n\t\tconst newSubmenu = createBlock(\n\t\t\t'core/navigation-submenu',\n\t\t\tattributes,\n\t\t\tinnerBlocks\n\t\t);\n\t\treplaceBlock( clientId, newSubmenu );\n\t}, [ getBlocks, clientId, selectBlock, replaceBlock, attributes ] );\n\n\t// On mount, if this is a new link without a URL and it's selected,\n\t// select the parent block (submenu or navigation) instead to keep the appender visible.\n\t// This helps us return focus to the appender if the user closes the link ui without creating a link.\n\t// If we leave focus on this block, then when we close the link without creating a link, focus will\n\t// be lost during the new block selection process.\n\tuseEffect( () => {\n\t\tif ( isNewLink.current && isSelected && ! url ) {\n\t\t\tselectBlock( parentBlockClientId );\n\t\t}\n\t}, [] ); // eslint-disable-line react-hooks/exhaustive-deps\n\n\tuseEffect( () => {\n\t\t// If block has inner blocks, transform to Submenu.\n\t\tif ( hasChildren ) {\n\t\t\t// This side-effect should not create an undo level as those should\n\t\t\t// only be created via user interactions.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\ttransformToSubmenu();\n\t\t}\n\t}, [\n\t\thasChildren,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\ttransformToSubmenu,\n\t] );\n\n\t// If the LinkControl popover is open and the URL has changed, close the LinkControl and focus the label text.\n\tuseEffect( () => {\n\t\t// We only want to do this when the URL has gone from nothing to a new URL AND the label looks like a URL\n\t\tif (\n\t\t\t! prevUrl &&\n\t\t\turl &&\n\t\t\tisLinkOpen &&\n\t\t\tisURL( prependHTTP( label ) ) &&\n\t\t\t/^.+\\.[a-z]+/.test( label )\n\t\t) {\n\t\t\t// Focus and select the label text.\n\t\t\tselectLabelText();\n\t\t}\n\t}, [ prevUrl, url, isLinkOpen, label ] );\n\n\t/**\n\t * Focus the Link label text and select it.\n\t */\n\tfunction selectLabelText() {\n\t\tref.current.focus();\n\t\tconst { ownerDocument } = ref.current;\n\t\tconst { defaultView } = ownerDocument;\n\t\tconst selection = defaultView.getSelection();\n\t\tconst range = ownerDocument.createRange();\n\t\t// Get the range of the current ref contents so we can add this range to the selection.\n\t\trange.selectNodeContents( ref.current );\n\t\tselection.removeAllRanges();\n\t\tselection.addRange( range );\n\t}\n\n\t/**\n\t * Removes the current link if set.\n\t */\n\tfunction removeLink() {\n\t\t// Reset all attributes that comprise the link.\n\t\t// It is critical that all attributes are reset\n\t\t// to their default values otherwise this may\n\t\t// in advertently trigger side effects because\n\t\t// the values will have \"changed\".\n\t\tsetAttributes( {\n\t\t\turl: undefined,\n\t\t\tlabel: undefined,\n\t\t\tid: undefined,\n\t\t\tkind: undefined,\n\t\t\ttype: undefined,\n\t\t\topensInNewTab: false,\n\t\t} );\n\n\t\t// Close the link editing UI.\n\t\tsetIsLinkOpen( false );\n\t}\n\n\tconst {\n\t\ttextColor,\n\t\tcustomTextColor,\n\t\tbackgroundColor,\n\t\tcustomBackgroundColor,\n\t} = getColors( context, ! isTopLevelLink );\n\n\tfunction onKeyDown( event ) {\n\t\tif ( isKeyboardEvent.primary( event, 'k' ) ) {\n\t\t\t// Required to prevent the command center from opening,\n\t\t\t// as it shares the CMD+K shortcut.\n\t\t\t// See https://github.com/WordPress/gutenberg/pull/59845.\n\t\t\tevent.preventDefault();\n\t\t\t// If this link is a child of a parent submenu item, the parent submenu item event will also open, closing this popover\n\t\t\tevent.stopPropagation();\n\t\t\tsetIsLinkOpen( true );\n\t\t}\n\t}\n\n\tconst blockProps = useBlockProps( {\n\t\tref: useMergeRefs( [ setPopoverAnchor, listItemRef ] ),\n\t\tclassName: clsx( 'wp-block-navigation-item', {\n\t\t\t'is-editing': isSelected || isParentOfSelectedBlock,\n\t\t\t'is-dragging-within': isDraggingWithin,\n\t\t\t'has-link': !! url,\n\t\t\t'has-child': hasChildren,\n\t\t\t'has-text-color': !! textColor || !! customTextColor,\n\t\t\t[ getColorClassName( 'color', textColor ) ]: !! textColor,\n\t\t\t'has-background': !! backgroundColor || customBackgroundColor,\n\t\t\t[ getColorClassName( 'background-color', backgroundColor ) ]:\n\t\t\t\t!! backgroundColor,\n\t\t} ),\n\t\tstyle: {\n\t\t\tcolor: ! textColor && customTextColor,\n\t\t\tbackgroundColor: ! backgroundColor && customBackgroundColor,\n\t\t},\n\t\tonKeyDown,\n\t} );\n\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{\n\t\t\t...blockProps,\n\t\t\tclassName: 'remove-outline', // Remove the outline from the inner blocks container.\n\t\t},\n\t\t{\n\t\t\tdefaultBlock: DEFAULT_BLOCK,\n\t\t\tdirectInsert: true,\n\t\t\trenderAppender: false,\n\t\t}\n\t);\n\n\tif ( ! url || isInvalid || isDraft ) {\n\t\tblockProps.onClick = () => {\n\t\t\tsetIsLinkOpen( true );\n\t\t};\n\t}\n\n\tconst classes = clsx( 'wp-block-navigation-item__content', {\n\t\t'wp-block-navigation-link__placeholder': ! url || isInvalid || isDraft,\n\t} );\n\n\tconst missingText = getMissingText( type );\n\t/* translators: Whether the navigation link is Invalid or a Draft. */\n\tconst placeholderText = `(${\n\t\tisInvalid ? __( 'Invalid' ) : __( 'Draft' )\n\t})`;\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\tshortcut={ displayShortcut.primary( 'k' ) }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tsetIsLinkOpen( true );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t{ ! isAtMaxNesting && (\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\tname=\"submenu\"\n\t\t\t\t\t\t\ticon={ addSubmenu }\n\t\t\t\t\t\t\ttitle={ __( 'Add submenu' ) }\n\t\t\t\t\t\t\tonClick={ transformToSubmenu }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls>\n\t\t\t\t<Controls\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ /* eslint-disable jsx-a11y/anchor-is-valid */ }\n\t\t\t\t<a className={ classes }>\n\t\t\t\t\t{ /* eslint-enable */ }\n\t\t\t\t\t{ ! url && ! metadata?.bindings?.url ? (\n\t\t\t\t\t\t<div className=\"wp-block-navigation-link__placeholder-text\">\n\t\t\t\t\t\t\t<span>{ missingText }</span>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t{ ! isInvalid && ! isDraft && (\n\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\t\t\t\t\tidentifier=\"label\"\n\t\t\t\t\t\t\t\t\t\tclassName=\"wp-block-navigation-item__label\"\n\t\t\t\t\t\t\t\t\t\tvalue={ label }\n\t\t\t\t\t\t\t\t\t\tonChange={ ( labelValue ) =>\n\t\t\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\t\t\tlabel: labelValue,\n\t\t\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\t\t\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\t\t\t\t\t\t__unstableOnSplitAtEnd={ () =>\n\t\t\t\t\t\t\t\t\t\t\tinsertBlocksAfter(\n\t\t\t\t\t\t\t\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t\t\t\t\t\t\t\t'core/navigation-link'\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\taria-label={ __(\n\t\t\t\t\t\t\t\t\t\t\t'Navigation link text'\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tplaceholder={ itemLabelPlaceholder }\n\t\t\t\t\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t{ description && (\n\t\t\t\t\t\t\t\t\t\t<span className=\"wp-block-navigation-item__description\">\n\t\t\t\t\t\t\t\t\t\t\t{ description }\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ ( isInvalid || isDraft ) && (\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t\t'wp-block-navigation-link__placeholder-text',\n\t\t\t\t\t\t\t\t\t\t'wp-block-navigation-link__label',\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t'is-invalid': isInvalid,\n\t\t\t\t\t\t\t\t\t\t\t'is-draft': isDraft,\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t// Some attributes are stored in an escaped form. It's a legacy issue.\n\t\t\t\t\t\t\t\t\t\t\t// Ideally they would be stored in a raw, unescaped form.\n\t\t\t\t\t\t\t\t\t\t\t// Unescape is used here to \"recover\" the escaped characters\n\t\t\t\t\t\t\t\t\t\t\t// so they display without encoding.\n\t\t\t\t\t\t\t\t\t\t\t// See `updateAttributes` for more details.\n\t\t\t\t\t\t\t\t\t\t\t`${ decodeEntities( label ) } ${\n\t\t\t\t\t\t\t\t\t\t\t\tisInvalid || isDraft\n\t\t\t\t\t\t\t\t\t\t\t\t\t? placeholderText\n\t\t\t\t\t\t\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t\t\t\t\t\t}`.trim()\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t\t{ isLinkOpen && (\n\t\t\t\t\t\t<LinkUI\n\t\t\t\t\t\t\tref={ linkUIref }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tlink={ attributes }\n\t\t\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\t\t\tsetIsLinkOpen( false );\n\t\t\t\t\t\t\t\t// If there is no link then remove the auto-inserted block.\n\t\t\t\t\t\t\t\t// This avoids empty blocks which can provided a poor UX.\n\t\t\t\t\t\t\t\tif ( ! url ) {\n\t\t\t\t\t\t\t\t\tonReplace( [] );\n\t\t\t\t\t\t\t\t} else if ( isNewLink.current ) {\n\t\t\t\t\t\t\t\t\t// If we just created a new link, select it\n\t\t\t\t\t\t\t\t\tselectBlock( clientId );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tanchor={ popoverAnchor }\n\t\t\t\t\t\t\tonRemove={ removeLink }\n\t\t\t\t\t\t\tonChange={ ( updatedValue ) => {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\tisEntityLink,\n\t\t\t\t\t\t\t\t\tattributes: updatedAttributes,\n\t\t\t\t\t\t\t\t} = updateAttributes(\n\t\t\t\t\t\t\t\t\tupdatedValue,\n\t\t\t\t\t\t\t\t\tsetAttributes,\n\t\t\t\t\t\t\t\t\tattributes\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t// Handle URL binding based on the final computed state\n\t\t\t\t\t\t\t\t// Only create bindings for entity links (posts, pages, taxonomies)\n\t\t\t\t\t\t\t\t// Never create bindings for custom links (manual URLs)\n\t\t\t\t\t\t\t\tif ( isEntityLink ) {\n\t\t\t\t\t\t\t\t\tcreateBinding( updatedAttributes );\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tclearBinding( updatedAttributes );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</a>\n\t\t\t\t<div { ...innerBlocksProps } />\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0aI;AAvaJ,kBAAiB;AAKjB,oBAA4B;AAC5B,kBAAuC;AACvC,wBAA4C;AAC5C,sBAAiD;AACjD,kBAAmB;AACnB,0BASO;AACP,iBAAmC;AACnC,qBAAyD;AACzD,2BAA+B;AAC/B,mBAA6C;AAC7C,uBAAmC;AACnC,qBAA0C;AAK1C,mBAA0B;AAC1B,oBAAqE;AAErE,MAAM,gBAAgB,EAAE,MAAM,uBAAuB;AACrD,MAAM,sBAAsB;AAAA,EAC3B;AAAA,EACA;AACD;AAWA,MAAM,sBAAsB,CAAE,eAAgB;AAC7C,QAAM,CAAE,kBAAkB,mBAAoB,QAAI,yBAAU,KAAM;AAElE,gCAAW,MAAM;AAChB,UAAM,EAAE,cAAc,IAAI,WAAW;AAErC,aAAS,gBAAiB,OAAQ;AA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AAU;AAE/B,4BAAa,QAAS;AAAA,cACvB;AAAA,YACD;AAAA,YACA,QAAS;AAAA,YACT,UAAW;AAAA,YACX,UAAW,CAAE,iBAAkB;AAC9B,oBAAM;AAAA,gBACL;AAAA,gBACA,YAAY;AAAA,cACb,QAAI;AAAA,gBACH;AAAA,gBACA;AAAA,gBACA;AAAA,cACD;AAKA,kBAAK,cAAe;AACnB,8BAAe,iBAAkB;AAAA,cAClC,OAAO;AACN,6BAAc,iBAAkB;AAAA,cACjC;AAAA,YACD;AAAA;AAAA,QACD;AAAA,SAEF;AAAA,MACA,4CAAC,SAAM,GAAG,kBAAmB;AAAA,OAC9B;AAAA,KACD;AAEF;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { displayShortcut, isKeyboardEvent } from '@wordpress/keycodes';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tRichText,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\tgetColorClassName,\n\tuseInnerBlocksProps,\n\tuseBlockEditingMode,\n} from '@wordpress/block-editor';\nimport { isURL, prependHTTP } from '@wordpress/url';\nimport { useState, useEffect, useRef, useCallback } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { link as linkIcon, addSubmenu } from '@wordpress/icons';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useMergeRefs, usePrevious } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getColors } from '../navigation/edit/utils';\nimport { Controls, LinkUI, updateAttributes, useEntityBinding } from './shared';\n\nconst DEFAULT_BLOCK = { name: 'core/navigation-link' };\nconst NESTING_BLOCK_NAMES = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n];\n\n/**\n * A React hook to determine if it's dragging within the target element.\n *\n * @typedef {import('@wordpress/element').RefObject} RefObject\n *\n * @param {RefObject<HTMLElement>} elementRef The target elementRef object.\n *\n * @return {boolean} Is dragging within the target element.\n */\nconst useIsDraggingWithin = ( elementRef ) => {\n\tconst [ isDraggingWithin, setIsDraggingWithin ] = useState( false );\n\n\tuseEffect( () => {\n\t\tconst { ownerDocument } = elementRef.current;\n\n\t\tfunction handleDragStart( event ) {\n\t\t\t// Check the first time when the dragging starts.\n\t\t\thandleDragEnter( event );\n\t\t}\n\n\t\t// Set to false whenever the user cancel the drag event by either releasing the mouse or press Escape.\n\t\tfunction handleDragEnd() {\n\t\t\tsetIsDraggingWithin( false );\n\t\t}\n\n\t\tfunction handleDragEnter( event ) {\n\t\t\t// Check if the current target is inside the item element.\n\t\t\tif ( elementRef.current.contains( event.target ) ) {\n\t\t\t\tsetIsDraggingWithin( true );\n\t\t\t} else {\n\t\t\t\tsetIsDraggingWithin( false );\n\t\t\t}\n\t\t}\n\n\t\t// Bind these events to the document to catch all drag events.\n\t\t// Ideally, we can also use `event.relatedTarget`, but sadly that\n\t\t// doesn't work in Safari.\n\t\townerDocument.addEventListener( 'dragstart', handleDragStart );\n\t\townerDocument.addEventListener( 'dragend', handleDragEnd );\n\t\townerDocument.addEventListener( 'dragenter', handleDragEnter );\n\n\t\treturn () => {\n\t\t\townerDocument.removeEventListener( 'dragstart', handleDragStart );\n\t\t\townerDocument.removeEventListener( 'dragend', handleDragEnd );\n\t\t\townerDocument.removeEventListener( 'dragenter', handleDragEnter );\n\t\t};\n\t}, [ elementRef ] );\n\n\treturn isDraggingWithin;\n};\n\nconst useIsInvalidLink = ( kind, type, id, enabled ) => {\n\tconst isPostType =\n\t\tkind === 'post-type' || type === 'post' || type === 'page';\n\tconst hasId = Number.isInteger( id );\n\tconst blockEditingMode = useBlockEditingMode();\n\n\tconst { postStatus, isDeleted } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! isPostType ) {\n\t\t\t\treturn { postStatus: null, isDeleted: false };\n\t\t\t}\n\n\t\t\t// Fetching the posts status is an \"expensive\" operation. Especially for sites with large navigations.\n\t\t\t// When the block is rendered in a template or other disabled contexts we can skip this check in order\n\t\t\t// to avoid all these additional requests that don't really add any value in that mode.\n\t\t\tif ( blockEditingMode === 'disabled' || ! enabled ) {\n\t\t\t\treturn { postStatus: null, isDeleted: false };\n\t\t\t}\n\n\t\t\tconst { getEntityRecord, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst entityRecord = getEntityRecord( 'postType', type, id );\n\t\t\tconst hasResolved = hasFinishedResolution( 'getEntityRecord', [\n\t\t\t\t'postType',\n\t\t\t\ttype,\n\t\t\t\tid,\n\t\t\t] );\n\n\t\t\t// If resolution has finished and entityRecord is undefined, the entity was deleted.\n\t\t\tconst deleted = hasResolved && entityRecord === undefined;\n\n\t\t\treturn {\n\t\t\t\tpostStatus: entityRecord?.status,\n\t\t\t\tisDeleted: deleted,\n\t\t\t};\n\t\t},\n\t\t[ isPostType, blockEditingMode, enabled, type, id ]\n\t);\n\n\t// Check Navigation Link validity if:\n\t// 1. Link is 'post-type'.\n\t// 2. It has an id.\n\t// 3. It's neither null, nor undefined, as valid items might be either of those while loading.\n\t// If those conditions are met, check if\n\t// 1. The post status is trash (trashed).\n\t// 2. The entity doesn't exist (deleted).\n\t// If either of those is true, invalidate.\n\tconst isInvalid =\n\t\tisPostType &&\n\t\thasId &&\n\t\t( isDeleted || ( postStatus && 'trash' === postStatus ) );\n\tconst isDraft = 'draft' === postStatus;\n\n\treturn [ isInvalid, isDraft ];\n};\n\nfunction getMissingText( type ) {\n\tlet missingText = '';\n\n\tswitch ( type ) {\n\t\tcase 'post':\n\t\t\t/* translators: label for missing post in navigation link block */\n\t\t\tmissingText = __( 'Select post' );\n\t\t\tbreak;\n\t\tcase 'page':\n\t\t\t/* translators: label for missing page in navigation link block */\n\t\t\tmissingText = __( 'Select page' );\n\t\t\tbreak;\n\t\tcase 'category':\n\t\t\t/* translators: label for missing category in navigation link block */\n\t\t\tmissingText = __( 'Select category' );\n\t\t\tbreak;\n\t\tcase 'tag':\n\t\t\t/* translators: label for missing tag in navigation link block */\n\t\t\tmissingText = __( 'Select tag' );\n\t\t\tbreak;\n\t\tdefault:\n\t\t\t/* translators: label for missing values in navigation link block */\n\t\t\tmissingText = __( 'Add link' );\n\t}\n\n\treturn missingText;\n}\n\nexport default function NavigationLinkEdit( {\n\tattributes,\n\tisSelected,\n\tsetAttributes,\n\tinsertBlocksAfter,\n\tmergeBlocks,\n\tonReplace,\n\tcontext,\n\tclientId,\n} ) {\n\tconst { id, label, type, url, description, kind, metadata } = attributes;\n\tconst { maxNestingLevel } = context;\n\n\tconst {\n\t\treplaceBlock,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\tselectBlock,\n\t} = useDispatch( blockEditorStore );\n\t// Have the link editing ui open on mount when lacking a url and selected.\n\tconst [ isLinkOpen, setIsLinkOpen ] = useState( isSelected && ! url );\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\tconst listItemRef = useRef( null );\n\tconst isDraggingWithin = useIsDraggingWithin( listItemRef );\n\tconst itemLabelPlaceholder = __( 'Add label\u2026' );\n\tconst ref = useRef();\n\tconst linkUIref = useRef();\n\tconst prevUrl = usePrevious( url );\n\tconst isNewLink = useRef( ! url );\n\n\tconst {\n\t\tisAtMaxNesting,\n\t\tisTopLevelLink,\n\t\tisParentOfSelectedBlock,\n\t\thasChildren,\n\t\tvalidateLinkStatus,\n\t\tparentBlockClientId,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockCount,\n\t\t\t\tgetBlockName,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\thasSelectedInnerBlock,\n\t\t\t\tgetBlockParentsByBlockName,\n\t\t\t\tgetSelectedBlockClientId,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\t\t\tconst parentBlockName = getBlockName( rootClientId );\n\t\t\tconst isTopLevel = parentBlockName === 'core/navigation';\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\t\t\tconst rootNavigationClientId = isTopLevel\n\t\t\t\t? rootClientId\n\t\t\t\t: getBlockParentsByBlockName(\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t'core/navigation'\n\t\t\t\t )[ 0 ];\n\n\t\t\t// Get the immediate parent - if it's a submenu, use it; otherwise use the navigation block\n\t\t\tconst parentBlockId =\n\t\t\t\tparentBlockName === 'core/navigation-submenu'\n\t\t\t\t\t? rootClientId\n\t\t\t\t\t: rootNavigationClientId;\n\n\t\t\t// Enable when the root Navigation block is selected or any of its inner blocks.\n\t\t\tconst enableLinkStatusValidation =\n\t\t\t\tselectedBlockClientId === rootNavigationClientId ||\n\t\t\t\thasSelectedInnerBlock( rootNavigationClientId, true );\n\n\t\t\treturn {\n\t\t\t\tisAtMaxNesting:\n\t\t\t\t\tgetBlockParentsByBlockName( clientId, NESTING_BLOCK_NAMES )\n\t\t\t\t\t\t.length >= maxNestingLevel,\n\t\t\t\tisTopLevelLink: isTopLevel,\n\t\t\t\tisParentOfSelectedBlock: hasSelectedInnerBlock(\n\t\t\t\t\tclientId,\n\t\t\t\t\ttrue\n\t\t\t\t),\n\t\t\t\thasChildren: !! getBlockCount( clientId ),\n\t\t\t\tvalidateLinkStatus: enableLinkStatusValidation,\n\t\t\t\tparentBlockClientId: parentBlockId,\n\t\t\t};\n\t\t},\n\t\t[ clientId, maxNestingLevel ]\n\t);\n\tconst { getBlocks } = useSelect( blockEditorStore );\n\n\t// URL binding logic\n\tconst {\n\t\tclearBinding,\n\t\tcreateBinding,\n\t\thasUrlBinding,\n\t\tisBoundEntityAvailable,\n\t} = useEntityBinding( {\n\t\tclientId,\n\t\tattributes,\n\t} );\n\n\tconst [ isInvalid, isDraft ] = useIsInvalidLink(\n\t\tkind,\n\t\ttype,\n\t\tid,\n\t\tvalidateLinkStatus\n\t);\n\n\t/**\n\t * Transform to submenu block.\n\t */\n\tconst transformToSubmenu = useCallback( () => {\n\t\tlet innerBlocks = getBlocks( clientId );\n\t\tif ( innerBlocks.length === 0 ) {\n\t\t\tinnerBlocks = [ createBlock( 'core/navigation-link' ) ];\n\t\t\tselectBlock( innerBlocks[ 0 ].clientId );\n\t\t}\n\t\tconst newSubmenu = createBlock(\n\t\t\t'core/navigation-submenu',\n\t\t\tattributes,\n\t\t\tinnerBlocks\n\t\t);\n\t\treplaceBlock( clientId, newSubmenu );\n\t}, [ getBlocks, clientId, selectBlock, replaceBlock, attributes ] );\n\n\t// On mount, if this is a new link without a URL and it's selected,\n\t// select the parent block (submenu or navigation) instead to keep the appender visible.\n\t// This helps us return focus to the appender if the user closes the link ui without creating a link.\n\t// If we leave focus on this block, then when we close the link without creating a link, focus will\n\t// be lost during the new block selection process.\n\tuseEffect( () => {\n\t\tif ( isNewLink.current && isSelected && ! url ) {\n\t\t\tselectBlock( parentBlockClientId );\n\t\t}\n\t}, [] ); // eslint-disable-line react-hooks/exhaustive-deps\n\n\tuseEffect( () => {\n\t\t// If block has inner blocks, transform to Submenu.\n\t\tif ( hasChildren ) {\n\t\t\t// This side-effect should not create an undo level as those should\n\t\t\t// only be created via user interactions.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\ttransformToSubmenu();\n\t\t}\n\t}, [\n\t\thasChildren,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\ttransformToSubmenu,\n\t] );\n\n\t// If the LinkControl popover is open and the URL has changed, close the LinkControl and focus the label text.\n\tuseEffect( () => {\n\t\t// We only want to do this when the URL has gone from nothing to a new URL AND the label looks like a URL\n\t\tif (\n\t\t\t! prevUrl &&\n\t\t\turl &&\n\t\t\tisLinkOpen &&\n\t\t\tisURL( prependHTTP( label ) ) &&\n\t\t\t/^.+\\.[a-z]+/.test( label )\n\t\t) {\n\t\t\t// Focus and select the label text.\n\t\t\tselectLabelText();\n\t\t}\n\t}, [ prevUrl, url, isLinkOpen, label ] );\n\n\t/**\n\t * Focus the Link label text and select it.\n\t */\n\tfunction selectLabelText() {\n\t\tref.current.focus();\n\t\tconst { ownerDocument } = ref.current;\n\t\tconst { defaultView } = ownerDocument;\n\t\tconst selection = defaultView.getSelection();\n\t\tconst range = ownerDocument.createRange();\n\t\t// Get the range of the current ref contents so we can add this range to the selection.\n\t\trange.selectNodeContents( ref.current );\n\t\tselection.removeAllRanges();\n\t\tselection.addRange( range );\n\t}\n\n\t/**\n\t * Removes the current link if set.\n\t */\n\tfunction removeLink() {\n\t\t// Reset all attributes that comprise the link.\n\t\t// It is critical that all attributes are reset\n\t\t// to their default values otherwise this may\n\t\t// in advertently trigger side effects because\n\t\t// the values will have \"changed\".\n\t\tsetAttributes( {\n\t\t\turl: undefined,\n\t\t\tlabel: undefined,\n\t\t\tid: undefined,\n\t\t\tkind: undefined,\n\t\t\ttype: undefined,\n\t\t\topensInNewTab: false,\n\t\t} );\n\n\t\t// Close the link editing UI.\n\t\tsetIsLinkOpen( false );\n\t}\n\n\tconst {\n\t\ttextColor,\n\t\tcustomTextColor,\n\t\tbackgroundColor,\n\t\tcustomBackgroundColor,\n\t} = getColors( context, ! isTopLevelLink );\n\n\tfunction onKeyDown( event ) {\n\t\tif ( isKeyboardEvent.primary( event, 'k' ) ) {\n\t\t\t// Required to prevent the command center from opening,\n\t\t\t// as it shares the CMD+K shortcut.\n\t\t\t// See https://github.com/WordPress/gutenberg/pull/59845.\n\t\t\tevent.preventDefault();\n\t\t\t// If this link is a child of a parent submenu item, the parent submenu item event will also open, closing this popover\n\t\t\tevent.stopPropagation();\n\t\t\tsetIsLinkOpen( true );\n\t\t}\n\t}\n\n\tconst blockProps = useBlockProps( {\n\t\tref: useMergeRefs( [ setPopoverAnchor, listItemRef ] ),\n\t\tclassName: clsx( 'wp-block-navigation-item', {\n\t\t\t'is-editing': isSelected || isParentOfSelectedBlock,\n\t\t\t'is-dragging-within': isDraggingWithin,\n\t\t\t'has-link': !! url,\n\t\t\t'has-child': hasChildren,\n\t\t\t'has-text-color': !! textColor || !! customTextColor,\n\t\t\t[ getColorClassName( 'color', textColor ) ]: !! textColor,\n\t\t\t'has-background': !! backgroundColor || customBackgroundColor,\n\t\t\t[ getColorClassName( 'background-color', backgroundColor ) ]:\n\t\t\t\t!! backgroundColor,\n\t\t} ),\n\t\tstyle: {\n\t\t\tcolor: ! textColor && customTextColor,\n\t\t\tbackgroundColor: ! backgroundColor && customBackgroundColor,\n\t\t},\n\t\tonKeyDown,\n\t} );\n\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{\n\t\t\t...blockProps,\n\t\t\tclassName: 'remove-outline', // Remove the outline from the inner blocks container.\n\t\t},\n\t\t{\n\t\t\tdefaultBlock: DEFAULT_BLOCK,\n\t\t\tdirectInsert: true,\n\t\t\trenderAppender: false,\n\t\t}\n\t);\n\n\tif (\n\t\t! url ||\n\t\tisInvalid ||\n\t\tisDraft ||\n\t\t( hasUrlBinding && ! isBoundEntityAvailable )\n\t) {\n\t\tblockProps.onClick = () => {\n\t\t\tsetIsLinkOpen( true );\n\t\t};\n\t}\n\n\tconst classes = clsx( 'wp-block-navigation-item__content', {\n\t\t'wp-block-navigation-link__placeholder':\n\t\t\t! url ||\n\t\t\tisInvalid ||\n\t\t\tisDraft ||\n\t\t\t( hasUrlBinding && ! isBoundEntityAvailable ),\n\t} );\n\n\tconst missingText = getMissingText( type );\n\t/* translators: Whether the navigation link is Invalid or a Draft. */\n\tconst placeholderText = `(${\n\t\tisInvalid ? __( 'Invalid' ) : __( 'Draft' )\n\t})`;\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\tshortcut={ displayShortcut.primary( 'k' ) }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tsetIsLinkOpen( true );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t{ ! isAtMaxNesting && (\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\tname=\"submenu\"\n\t\t\t\t\t\t\ticon={ addSubmenu }\n\t\t\t\t\t\t\ttitle={ __( 'Add submenu' ) }\n\t\t\t\t\t\t\tonClick={ transformToSubmenu }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls>\n\t\t\t\t<Controls\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ /* eslint-disable jsx-a11y/anchor-is-valid */ }\n\t\t\t\t<a className={ classes }>\n\t\t\t\t\t{ /* eslint-enable */ }\n\t\t\t\t\t{ ! url && ! metadata?.bindings?.url ? (\n\t\t\t\t\t\t<div className=\"wp-block-navigation-link__placeholder-text\">\n\t\t\t\t\t\t\t<span>{ missingText }</span>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t{ ! isInvalid && ! isDraft && (\n\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\t\t\t\t\tidentifier=\"label\"\n\t\t\t\t\t\t\t\t\t\tclassName=\"wp-block-navigation-item__label\"\n\t\t\t\t\t\t\t\t\t\tvalue={ label }\n\t\t\t\t\t\t\t\t\t\tonChange={ ( labelValue ) =>\n\t\t\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\t\t\tlabel: labelValue,\n\t\t\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\t\t\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\t\t\t\t\t\t__unstableOnSplitAtEnd={ () =>\n\t\t\t\t\t\t\t\t\t\t\tinsertBlocksAfter(\n\t\t\t\t\t\t\t\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t\t\t\t\t\t\t\t'core/navigation-link'\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\taria-label={ __(\n\t\t\t\t\t\t\t\t\t\t\t'Navigation link text'\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tplaceholder={ itemLabelPlaceholder }\n\t\t\t\t\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t{ description && (\n\t\t\t\t\t\t\t\t\t\t<span className=\"wp-block-navigation-item__description\">\n\t\t\t\t\t\t\t\t\t\t\t{ description }\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ ( isInvalid || isDraft ) && (\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t\t'wp-block-navigation-link__placeholder-text',\n\t\t\t\t\t\t\t\t\t\t'wp-block-navigation-link__label',\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t'is-invalid': isInvalid,\n\t\t\t\t\t\t\t\t\t\t\t'is-draft': isDraft,\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t// Some attributes are stored in an escaped form. It's a legacy issue.\n\t\t\t\t\t\t\t\t\t\t\t// Ideally they would be stored in a raw, unescaped form.\n\t\t\t\t\t\t\t\t\t\t\t// Unescape is used here to \"recover\" the escaped characters\n\t\t\t\t\t\t\t\t\t\t\t// so they display without encoding.\n\t\t\t\t\t\t\t\t\t\t\t// See `updateAttributes` for more details.\n\t\t\t\t\t\t\t\t\t\t\t`${ decodeEntities( label ) } ${\n\t\t\t\t\t\t\t\t\t\t\t\tisInvalid || isDraft\n\t\t\t\t\t\t\t\t\t\t\t\t\t? placeholderText\n\t\t\t\t\t\t\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\t\t\t\t\t\t}`.trim()\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t\t{ isLinkOpen && (\n\t\t\t\t\t\t<LinkUI\n\t\t\t\t\t\t\tref={ linkUIref }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tlink={ attributes }\n\t\t\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\t\t\tsetIsLinkOpen( false );\n\t\t\t\t\t\t\t\t// If there is no link and no binding, remove the auto-inserted block.\n\t\t\t\t\t\t\t\t// This avoids empty blocks which can provided a poor UX.\n\t\t\t\t\t\t\t\t// Don't remove if binding exists (even if entity is unavailable) so user can fix it.\n\t\t\t\t\t\t\t\tif ( ! url && ! hasUrlBinding ) {\n\t\t\t\t\t\t\t\t\tonReplace( [] );\n\t\t\t\t\t\t\t\t} else if ( isNewLink.current ) {\n\t\t\t\t\t\t\t\t\t// If we just created a new link, select it\n\t\t\t\t\t\t\t\t\tselectBlock( clientId );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tanchor={ popoverAnchor }\n\t\t\t\t\t\t\tonRemove={ removeLink }\n\t\t\t\t\t\t\tonChange={ ( updatedValue ) => {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\tisEntityLink,\n\t\t\t\t\t\t\t\t\tattributes: updatedAttributes,\n\t\t\t\t\t\t\t\t} = updateAttributes(\n\t\t\t\t\t\t\t\t\tupdatedValue,\n\t\t\t\t\t\t\t\t\tsetAttributes,\n\t\t\t\t\t\t\t\t\tattributes\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t// Handle URL binding based on the final computed state\n\t\t\t\t\t\t\t\t// Only create bindings for entity links (posts, pages, taxonomies)\n\t\t\t\t\t\t\t\t// Never create bindings for custom links (manual URLs)\n\t\t\t\t\t\t\t\tif ( isEntityLink ) {\n\t\t\t\t\t\t\t\t\tcreateBinding( updatedAttributes );\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tclearBinding( updatedAttributes );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</a>\n\t\t\t\t<div { ...innerBlocksProps } />\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwcI;AArcJ,kBAAiB;AAKjB,oBAA4B;AAC5B,kBAAuC;AACvC,wBAA4C;AAC5C,sBAAiD;AACjD,kBAAmB;AACnB,0BASO;AACP,iBAAmC;AACnC,qBAAyD;AACzD,2BAA+B;AAC/B,mBAA6C;AAC7C,uBAAmC;AACnC,qBAA0C;AAK1C,mBAA0B;AAC1B,oBAAqE;AAErE,MAAM,gBAAgB,EAAE,MAAM,uBAAuB;AACrD,MAAM,sBAAsB;AAAA,EAC3B;AAAA,EACA;AACD;AAWA,MAAM,sBAAsB,CAAE,eAAgB;AAC7C,QAAM,CAAE,kBAAkB,mBAAoB,QAAI,yBAAU,K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AA,gBACA;AAAA,kBACC,cAAc;AAAA,kBACd,YAAY;AAAA,gBACb;AAAA,cACD;AAAA,cAEA,sDAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAOC,iBAAI,qCAAgB,KAAM,CAAE,IAC3B,aAAa,UACV,kBACA,EACJ,GAAG,KAAK;AAAA,eAEV;AAAA;AAAA,UACD;AAAA,WAEF;AAAA,QAEC,cACD;AAAA,UAAC;AAAA;AAAA,YACA,KAAM;AAAA,YACN;AAAA,YACA,MAAO;AAAA,YACP,SAAU,MAAM;AACf,4BAAe,KAAM;AAIrB,kBAAK,CAAE,OAAO,CAAE,eAAgB;AAC/B,0BAAW,CAAC,CAAE;AAAA,cACf,WAAY,UAAU,SAAU;AAE/B,4BAAa,QAAS;AAAA,cACvB;AAAA,YACD;AAAA,YACA,QAAS;AAAA,YACT,UAAW;AAAA,YACX,UAAW,CAAE,iBAAkB;AAC9B,oBAAM;AAAA,gBACL;AAAA,gBACA,YAAY;AAAA,cACb,QAAI;AAAA,gBACH;AAAA,gBACA;AAAA,gBACA;AAAA,cACD;AAKA,kBAAK,cAAe;AACnB,8BAAe,iBAAkB;AAAA,cAClC,OAAO;AACN,6BAAc,iBAAkB;AAAA,cACjC;AAAA,YACD;AAAA;AAAA,QACD;AAAA,SAEF;AAAA,MACA,4CAAC,SAAM,GAAG,kBAAmB;AAAA,OAC9B;AAAA,KACD;AAEF;",
6
6
  "names": ["coreStore", "blockEditorStore", "clsx", "linkIcon"]
7
7
  }
@@ -44,6 +44,7 @@ var import_icons = require("@wordpress/icons");
44
44
  var import_compose = require("@wordpress/compose");
45
45
  var import_page_creator = require("./page-creator");
46
46
  var import_block_inserter = __toESM(require("./block-inserter"));
47
+ var import_use_entity_binding = require("../shared/use-entity-binding");
47
48
  function getSuggestionsQuery(type, kind) {
48
49
  switch (type) {
49
50
  case "post":
@@ -74,7 +75,8 @@ function getSuggestionsQuery(type, kind) {
74
75
  }
75
76
  }
76
77
  function UnforwardedLinkUI(props, ref) {
77
- const { label, url, opensInNewTab, type, kind, id, metadata } = props.link;
78
+ const { label, url, opensInNewTab, type, kind, id } = props.link;
79
+ const { clientId } = props;
78
80
  const postType = type || "page";
79
81
  const [addingBlock, setAddingBlock] = (0, import_element.useState)(false);
80
82
  const [addingPage, setAddingPage] = (0, import_element.useState)(false);
@@ -84,7 +86,10 @@ function UnforwardedLinkUI(props, ref) {
84
86
  kind: "postType",
85
87
  name: postType
86
88
  });
87
- const hasUrlBinding = (metadata?.bindings?.url?.source === "core/post-data" || metadata?.bindings?.url?.source === "core/term-data") && !!id;
89
+ const { isBoundEntityAvailable } = (0, import_use_entity_binding.useEntityBinding)({
90
+ clientId,
91
+ attributes: props.link
92
+ });
88
93
  const link = (0, import_element.useMemo)(
89
94
  () => ({
90
95
  url,
@@ -145,7 +150,7 @@ function UnforwardedLinkUI(props, ref) {
145
150
  onChange: props.onChange,
146
151
  onRemove: props.onRemove,
147
152
  onCancel: props.onCancel,
148
- handleEntities: hasUrlBinding,
153
+ handleEntities: isBoundEntityAvailable,
149
154
  renderControlBottom: () => {
150
155
  if (link?.url?.length) {
151
156
  return null;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/navigation-link/link-ui/index.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport {\n\tPopover,\n\tButton,\n\tVisuallyHidden,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { LinkControl, useBlockEditingMode } from '@wordpress/block-editor';\nimport {\n\tuseMemo,\n\tuseState,\n\tuseRef,\n\tuseEffect,\n\tforwardRef,\n} from '@wordpress/element';\nimport { useResourcePermissions } from '@wordpress/core-data';\nimport { plus } from '@wordpress/icons';\nimport { useInstanceId } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { LinkUIPageCreator } from './page-creator';\nimport LinkUIBlockInserter from './block-inserter';\n\n/**\n * Given the Link block's type attribute, return the query params to give to\n * /wp/v2/search.\n *\n * @param {string} type Link block's type attribute.\n * @param {string} kind Link block's entity of kind (post-type|taxonomy)\n * @return {{ type?: string, subtype?: string }} Search query params.\n */\nexport function getSuggestionsQuery( type, kind ) {\n\tswitch ( type ) {\n\t\tcase 'post':\n\t\tcase 'page':\n\t\t\treturn { type: 'post', subtype: type };\n\t\tcase 'category':\n\t\t\treturn { type: 'term', subtype: 'category' };\n\t\tcase 'tag':\n\t\t\treturn { type: 'term', subtype: 'post_tag' };\n\t\tcase 'post_format':\n\t\t\treturn { type: 'post-format' };\n\t\tdefault:\n\t\t\tif ( kind === 'taxonomy' ) {\n\t\t\t\treturn { type: 'term', subtype: type };\n\t\t\t}\n\t\t\tif ( kind === 'post-type' ) {\n\t\t\t\treturn { type: 'post', subtype: type };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t// for custom link which has no type\n\t\t\t\t// always show pages as initial suggestions\n\t\t\t\tinitialSuggestionsSearchOptions: {\n\t\t\t\t\ttype: 'post',\n\t\t\t\t\tsubtype: 'page',\n\t\t\t\t\tperPage: 20,\n\t\t\t\t},\n\t\t\t};\n\t}\n}\n\nfunction UnforwardedLinkUI( props, ref ) {\n\tconst { label, url, opensInNewTab, type, kind, id, metadata } = props.link;\n\tconst postType = type || 'page';\n\n\tconst [ addingBlock, setAddingBlock ] = useState( false );\n\tconst [ addingPage, setAddingPage ] = useState( false );\n\tconst [ focusAddBlockButton, setFocusAddBlockButton ] = useState( false );\n\tconst [ focusAddPageButton, setFocusAddPageButton ] = useState( false );\n\tconst permissions = useResourcePermissions( {\n\t\tkind: 'postType',\n\t\tname: postType,\n\t} );\n\n\t// Check if there's a URL binding with the new binding sources\n\t// Only enable handleEntities when there's actually a binding present\n\tconst hasUrlBinding =\n\t\t( metadata?.bindings?.url?.source === 'core/post-data' ||\n\t\t\tmetadata?.bindings?.url?.source === 'core/term-data' ) &&\n\t\t!! id;\n\n\t// Memoize link value to avoid overriding the LinkControl's internal state.\n\t// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/50976#issuecomment-1568226407.\n\tconst link = useMemo(\n\t\t() => ( {\n\t\t\turl,\n\t\t\topensInNewTab,\n\t\t\ttitle: label && stripHTML( label ),\n\t\t\tkind,\n\t\t\ttype,\n\t\t\tid,\n\t\t} ),\n\t\t[ label, opensInNewTab, url, kind, type, id ]\n\t);\n\n\tconst handlePageCreated = ( pageLink ) => {\n\t\t// Set the new page as the current link\n\t\tprops.onChange( pageLink );\n\t\t// Return to main Link UI\n\t\tsetAddingPage( false );\n\t};\n\n\tconst dialogTitleId = useInstanceId(\n\t\tLinkUI,\n\t\t'link-ui-link-control__title'\n\t);\n\tconst dialogDescriptionId = useInstanceId(\n\t\tLinkUI,\n\t\t'link-ui-link-control__description'\n\t);\n\n\tconst blockEditingMode = useBlockEditingMode();\n\n\treturn (\n\t\t<Popover\n\t\t\tref={ ref }\n\t\t\tplacement=\"bottom\"\n\t\t\tonClose={ props.onClose }\n\t\t\tanchor={ props.anchor }\n\t\t\tshift\n\t\t>\n\t\t\t{ ! addingBlock && ! addingPage && (\n\t\t\t\t<div\n\t\t\t\t\trole=\"dialog\"\n\t\t\t\t\taria-labelledby={ dialogTitleId }\n\t\t\t\t\taria-describedby={ dialogDescriptionId }\n\t\t\t\t>\n\t\t\t\t\t<VisuallyHidden>\n\t\t\t\t\t\t<h2 id={ dialogTitleId }>{ __( 'Add link' ) }</h2>\n\n\t\t\t\t\t\t<p id={ dialogDescriptionId }>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'Search for and add a link to your Navigation.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</p>\n\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t<LinkControl\n\t\t\t\t\t\thasTextControl\n\t\t\t\t\t\thasRichPreviews\n\t\t\t\t\t\tvalue={ link }\n\t\t\t\t\t\tshowInitialSuggestions\n\t\t\t\t\t\twithCreateSuggestion={ false }\n\t\t\t\t\t\tnoDirectEntry={ !! type }\n\t\t\t\t\t\tnoURLSuggestion={ !! type }\n\t\t\t\t\t\tsuggestionsQuery={ getSuggestionsQuery( type, kind ) }\n\t\t\t\t\t\tonChange={ props.onChange }\n\t\t\t\t\t\tonRemove={ props.onRemove }\n\t\t\t\t\t\tonCancel={ props.onCancel }\n\t\t\t\t\t\thandleEntities={ hasUrlBinding }\n\t\t\t\t\t\trenderControlBottom={ () => {\n\t\t\t\t\t\t\t// Don't show the tools when there is submitted link (preview state).\n\t\t\t\t\t\t\tif ( link?.url?.length ) {\n\t\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<LinkUITools\n\t\t\t\t\t\t\t\t\tfocusAddBlockButton={ focusAddBlockButton }\n\t\t\t\t\t\t\t\t\tfocusAddPageButton={ focusAddPageButton }\n\t\t\t\t\t\t\t\t\tsetAddingBlock={ () => {\n\t\t\t\t\t\t\t\t\t\tsetAddingBlock( true );\n\t\t\t\t\t\t\t\t\t\tsetFocusAddBlockButton( false );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tsetAddingPage={ () => {\n\t\t\t\t\t\t\t\t\t\tsetAddingPage( true );\n\t\t\t\t\t\t\t\t\t\tsetFocusAddPageButton( false );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tcanAddPage={\n\t\t\t\t\t\t\t\t\t\tpermissions?.canCreate &&\n\t\t\t\t\t\t\t\t\t\ttype === 'page'\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tcanAddBlock={\n\t\t\t\t\t\t\t\t\t\tblockEditingMode === 'default'\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ addingBlock && (\n\t\t\t\t<LinkUIBlockInserter\n\t\t\t\t\tclientId={ props.clientId }\n\t\t\t\t\tonBack={ () => {\n\t\t\t\t\t\tsetAddingBlock( false );\n\t\t\t\t\t\tsetFocusAddBlockButton( true );\n\t\t\t\t\t\tsetFocusAddPageButton( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonBlockInsert={ props?.onBlockInsert }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t{ addingPage && (\n\t\t\t\t<LinkUIPageCreator\n\t\t\t\t\tpostType={ postType }\n\t\t\t\t\tonBack={ () => {\n\t\t\t\t\t\tsetAddingPage( false );\n\t\t\t\t\t\tsetFocusAddPageButton( true );\n\t\t\t\t\t\tsetFocusAddBlockButton( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonPageCreated={ handlePageCreated }\n\t\t\t\t\tinitialTitle={ link?.url || '' }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</Popover>\n\t);\n}\n\nexport const LinkUI = forwardRef( UnforwardedLinkUI );\n\nconst LinkUITools = ( {\n\tsetAddingBlock,\n\tsetAddingPage,\n\tfocusAddBlockButton,\n\tfocusAddPageButton,\n\tcanAddPage,\n\tcanAddBlock,\n} ) => {\n\tconst blockInserterAriaRole = 'listbox';\n\tconst addBlockButtonRef = useRef();\n\tconst addPageButtonRef = useRef();\n\n\t// Focus the add block button when the popover is opened.\n\tuseEffect( () => {\n\t\tif ( focusAddBlockButton ) {\n\t\t\taddBlockButtonRef.current?.focus();\n\t\t}\n\t}, [ focusAddBlockButton ] );\n\n\t// Focus the add page button when the popover is opened.\n\tuseEffect( () => {\n\t\tif ( focusAddPageButton ) {\n\t\t\taddPageButtonRef.current?.focus();\n\t\t}\n\t}, [ focusAddPageButton ] );\n\n\t// Don't render anything if neither button should be shown\n\tif ( ! canAddPage && ! canAddBlock ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<VStack spacing={ 0 } className=\"link-ui-tools\">\n\t\t\t{ canAddPage && (\n\t\t\t\t<Button\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tref={ addPageButtonRef }\n\t\t\t\t\ticon={ plus }\n\t\t\t\t\tonClick={ ( e ) => {\n\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\tsetAddingPage( true );\n\t\t\t\t\t} }\n\t\t\t\t\taria-haspopup={ blockInserterAriaRole }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Create page' ) }\n\t\t\t\t</Button>\n\t\t\t) }\n\t\t\t{ canAddBlock && (\n\t\t\t\t<Button\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tref={ addBlockButtonRef }\n\t\t\t\t\ticon={ plus }\n\t\t\t\t\tonClick={ ( e ) => {\n\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\tsetAddingBlock( true );\n\t\t\t\t\t} }\n\t\t\t\t\taria-haspopup={ blockInserterAriaRole }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Add block' ) }\n\t\t\t\t</Button>\n\t\t\t) }\n\t\t</VStack>\n\t);\n};\n\nexport default LinkUITools;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqIK;AAlIL,iBAAiD;AACjD,wBAKO;AACP,kBAAmB;AACnB,0BAAiD;AACjD,qBAMO;AACP,uBAAuC;AACvC,mBAAqB;AACrB,qBAA8B;AAK9B,0BAAkC;AAClC,4BAAgC;AAUzB,SAAS,oBAAqB,MAAM,MAAO;AACjD,UAAS,MAAO;AAAA,IACf,KAAK;AAAA,IACL,KAAK;AACJ,aAAO,EAAE,MAAM,QAAQ,SAAS,KAAK;AAAA,IACtC,KAAK;AACJ,aAAO,EAAE,MAAM,QAAQ,SAAS,WAAW;AAAA,IAC5C,KAAK;AACJ,aAAO,EAAE,MAAM,QAAQ,SAAS,WAAW;AAAA,IAC5C,KAAK;AACJ,aAAO,EAAE,MAAM,cAAc;AAAA,IAC9B;AACC,UAAK,SAAS,YAAa;A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B;AAAA,QACrB,KAAM;AAAA,QACN,MAAO;AAAA,QACP,SAAU,CAAE,MAAO;AAClB,YAAE,eAAe;AACjB,yBAAgB,IAAK;AAAA,QACtB;AAAA,QACA,iBAAgB;AAAA,QAEd,8BAAI,WAAY;AAAA;AAAA,IACnB;AAAA,KAEF;AAEF;AAEA,IAAO,kBAAQ;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport {\n\tPopover,\n\tButton,\n\tVisuallyHidden,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { LinkControl, useBlockEditingMode } from '@wordpress/block-editor';\nimport {\n\tuseMemo,\n\tuseState,\n\tuseRef,\n\tuseEffect,\n\tforwardRef,\n} from '@wordpress/element';\nimport { useResourcePermissions } from '@wordpress/core-data';\nimport { plus } from '@wordpress/icons';\nimport { useInstanceId } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { LinkUIPageCreator } from './page-creator';\nimport LinkUIBlockInserter from './block-inserter';\nimport { useEntityBinding } from '../shared/use-entity-binding';\n\n/**\n * Given the Link block's type attribute, return the query params to give to\n * /wp/v2/search.\n *\n * @param {string} type Link block's type attribute.\n * @param {string} kind Link block's entity of kind (post-type|taxonomy)\n * @return {{ type?: string, subtype?: string }} Search query params.\n */\nexport function getSuggestionsQuery( type, kind ) {\n\tswitch ( type ) {\n\t\tcase 'post':\n\t\tcase 'page':\n\t\t\treturn { type: 'post', subtype: type };\n\t\tcase 'category':\n\t\t\treturn { type: 'term', subtype: 'category' };\n\t\tcase 'tag':\n\t\t\treturn { type: 'term', subtype: 'post_tag' };\n\t\tcase 'post_format':\n\t\t\treturn { type: 'post-format' };\n\t\tdefault:\n\t\t\tif ( kind === 'taxonomy' ) {\n\t\t\t\treturn { type: 'term', subtype: type };\n\t\t\t}\n\t\t\tif ( kind === 'post-type' ) {\n\t\t\t\treturn { type: 'post', subtype: type };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t// for custom link which has no type\n\t\t\t\t// always show pages as initial suggestions\n\t\t\t\tinitialSuggestionsSearchOptions: {\n\t\t\t\t\ttype: 'post',\n\t\t\t\t\tsubtype: 'page',\n\t\t\t\t\tperPage: 20,\n\t\t\t\t},\n\t\t\t};\n\t}\n}\n\nfunction UnforwardedLinkUI( props, ref ) {\n\tconst { label, url, opensInNewTab, type, kind, id } = props.link;\n\tconst { clientId } = props;\n\tconst postType = type || 'page';\n\n\tconst [ addingBlock, setAddingBlock ] = useState( false );\n\tconst [ addingPage, setAddingPage ] = useState( false );\n\tconst [ focusAddBlockButton, setFocusAddBlockButton ] = useState( false );\n\tconst [ focusAddPageButton, setFocusAddPageButton ] = useState( false );\n\tconst permissions = useResourcePermissions( {\n\t\tkind: 'postType',\n\t\tname: postType,\n\t} );\n\n\t// Use the entity binding hook to get binding status\n\tconst { isBoundEntityAvailable } = useEntityBinding( {\n\t\tclientId,\n\t\tattributes: props.link,\n\t} );\n\n\t// Memoize link value to avoid overriding the LinkControl's internal state.\n\t// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/50976#issuecomment-1568226407.\n\tconst link = useMemo(\n\t\t() => ( {\n\t\t\turl,\n\t\t\topensInNewTab,\n\t\t\ttitle: label && stripHTML( label ),\n\t\t\tkind,\n\t\t\ttype,\n\t\t\tid,\n\t\t} ),\n\t\t[ label, opensInNewTab, url, kind, type, id ]\n\t);\n\n\tconst handlePageCreated = ( pageLink ) => {\n\t\t// Set the new page as the current link\n\t\tprops.onChange( pageLink );\n\t\t// Return to main Link UI\n\t\tsetAddingPage( false );\n\t};\n\n\tconst dialogTitleId = useInstanceId(\n\t\tLinkUI,\n\t\t'link-ui-link-control__title'\n\t);\n\tconst dialogDescriptionId = useInstanceId(\n\t\tLinkUI,\n\t\t'link-ui-link-control__description'\n\t);\n\n\tconst blockEditingMode = useBlockEditingMode();\n\n\treturn (\n\t\t<Popover\n\t\t\tref={ ref }\n\t\t\tplacement=\"bottom\"\n\t\t\tonClose={ props.onClose }\n\t\t\tanchor={ props.anchor }\n\t\t\tshift\n\t\t>\n\t\t\t{ ! addingBlock && ! addingPage && (\n\t\t\t\t<div\n\t\t\t\t\trole=\"dialog\"\n\t\t\t\t\taria-labelledby={ dialogTitleId }\n\t\t\t\t\taria-describedby={ dialogDescriptionId }\n\t\t\t\t>\n\t\t\t\t\t<VisuallyHidden>\n\t\t\t\t\t\t<h2 id={ dialogTitleId }>{ __( 'Add link' ) }</h2>\n\n\t\t\t\t\t\t<p id={ dialogDescriptionId }>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'Search for and add a link to your Navigation.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</p>\n\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t<LinkControl\n\t\t\t\t\t\thasTextControl\n\t\t\t\t\t\thasRichPreviews\n\t\t\t\t\t\tvalue={ link }\n\t\t\t\t\t\tshowInitialSuggestions\n\t\t\t\t\t\twithCreateSuggestion={ false }\n\t\t\t\t\t\tnoDirectEntry={ !! type }\n\t\t\t\t\t\tnoURLSuggestion={ !! type }\n\t\t\t\t\t\tsuggestionsQuery={ getSuggestionsQuery( type, kind ) }\n\t\t\t\t\t\tonChange={ props.onChange }\n\t\t\t\t\t\tonRemove={ props.onRemove }\n\t\t\t\t\t\tonCancel={ props.onCancel }\n\t\t\t\t\t\thandleEntities={ isBoundEntityAvailable }\n\t\t\t\t\t\trenderControlBottom={ () => {\n\t\t\t\t\t\t\t// Don't show the tools when there is submitted link (preview state).\n\t\t\t\t\t\t\tif ( link?.url?.length ) {\n\t\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<LinkUITools\n\t\t\t\t\t\t\t\t\tfocusAddBlockButton={ focusAddBlockButton }\n\t\t\t\t\t\t\t\t\tfocusAddPageButton={ focusAddPageButton }\n\t\t\t\t\t\t\t\t\tsetAddingBlock={ () => {\n\t\t\t\t\t\t\t\t\t\tsetAddingBlock( true );\n\t\t\t\t\t\t\t\t\t\tsetFocusAddBlockButton( false );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tsetAddingPage={ () => {\n\t\t\t\t\t\t\t\t\t\tsetAddingPage( true );\n\t\t\t\t\t\t\t\t\t\tsetFocusAddPageButton( false );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tcanAddPage={\n\t\t\t\t\t\t\t\t\t\tpermissions?.canCreate &&\n\t\t\t\t\t\t\t\t\t\ttype === 'page'\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tcanAddBlock={\n\t\t\t\t\t\t\t\t\t\tblockEditingMode === 'default'\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ addingBlock && (\n\t\t\t\t<LinkUIBlockInserter\n\t\t\t\t\tclientId={ props.clientId }\n\t\t\t\t\tonBack={ () => {\n\t\t\t\t\t\tsetAddingBlock( false );\n\t\t\t\t\t\tsetFocusAddBlockButton( true );\n\t\t\t\t\t\tsetFocusAddPageButton( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonBlockInsert={ props?.onBlockInsert }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t{ addingPage && (\n\t\t\t\t<LinkUIPageCreator\n\t\t\t\t\tpostType={ postType }\n\t\t\t\t\tonBack={ () => {\n\t\t\t\t\t\tsetAddingPage( false );\n\t\t\t\t\t\tsetFocusAddPageButton( true );\n\t\t\t\t\t\tsetFocusAddBlockButton( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonPageCreated={ handlePageCreated }\n\t\t\t\t\tinitialTitle={ link?.url || '' }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</Popover>\n\t);\n}\n\nexport const LinkUI = forwardRef( UnforwardedLinkUI );\n\nconst LinkUITools = ( {\n\tsetAddingBlock,\n\tsetAddingPage,\n\tfocusAddBlockButton,\n\tfocusAddPageButton,\n\tcanAddPage,\n\tcanAddBlock,\n} ) => {\n\tconst blockInserterAriaRole = 'listbox';\n\tconst addBlockButtonRef = useRef();\n\tconst addPageButtonRef = useRef();\n\n\t// Focus the add block button when the popover is opened.\n\tuseEffect( () => {\n\t\tif ( focusAddBlockButton ) {\n\t\t\taddBlockButtonRef.current?.focus();\n\t\t}\n\t}, [ focusAddBlockButton ] );\n\n\t// Focus the add page button when the popover is opened.\n\tuseEffect( () => {\n\t\tif ( focusAddPageButton ) {\n\t\t\taddPageButtonRef.current?.focus();\n\t\t}\n\t}, [ focusAddPageButton ] );\n\n\t// Don't render anything if neither button should be shown\n\tif ( ! canAddPage && ! canAddBlock ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<VStack spacing={ 0 } className=\"link-ui-tools\">\n\t\t\t{ canAddPage && (\n\t\t\t\t<Button\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tref={ addPageButtonRef }\n\t\t\t\t\ticon={ plus }\n\t\t\t\t\tonClick={ ( e ) => {\n\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\tsetAddingPage( true );\n\t\t\t\t\t} }\n\t\t\t\t\taria-haspopup={ blockInserterAriaRole }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Create page' ) }\n\t\t\t\t</Button>\n\t\t\t) }\n\t\t\t{ canAddBlock && (\n\t\t\t\t<Button\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tref={ addBlockButtonRef }\n\t\t\t\t\ticon={ plus }\n\t\t\t\t\tonClick={ ( e ) => {\n\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\tsetAddingBlock( true );\n\t\t\t\t\t} }\n\t\t\t\t\taria-haspopup={ blockInserterAriaRole }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Add block' ) }\n\t\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AM,wBAAoB,uBAAO;AACjC,QAAM,uBAAmB,uBAAO;AAGhC,gCAAW,MAAM;AAChB,QAAK,qBAAsB;AAC1B,wBAAkB,SAAS,MAAM;AAAA,IAClC;AAAA,EACD,GAAG,CAAE,mBAAoB,CAAE;AAG3B,gCAAW,MAAM;AAChB,QAAK,oBAAqB;AACzB,uBAAiB,SAAS,MAAM;AAAA,IACjC;AAAA,EACD,GAAG,CAAE,kBAAmB,CAAE;AAG1B,MAAK,CAAE,cAAc,CAAE,aAAc;AACpC,WAAO;AAAA,EACR;AAEA,SACC,6CAAC,kBAAAC,sBAAA,EAAO,SAAU,GAAI,WAAU,iBAC7B;AAAA,kBACD;AAAA,MAAC;AAAA;AAAA,QACA,uBAAqB;AAAA,QACrB,KAAM;AAAA,QACN,MAAO;AAAA,QACP,SAAU,CAAE,MAAO;AAClB,YAAE,eAAe;AACjB,wBAAe,IAAK;AAAA,QACrB;AAAA,QACA,iBAAgB;AAAA,QAEd,8BAAI,aAAc;AAAA;AAAA,IACrB;AAAA,IAEC,eACD;AAAA,MAAC;AAAA;AAAA,QACA,uBAAqB;AAAA,QACrB,KAAM;AAAA,QACN,MAAO;AAAA,QACP,SAAU,CAAE,MAAO;AAClB,YAAE,eAAe;AACjB,yBAAgB,IAAK;AAAA,QACtB;AAAA,QACA,iBAAgB;AAAA,QAEd,8BAAI,WAAY;AAAA;AAAA,IACnB;AAAA,KAEF;AAEF;AAEA,IAAO,kBAAQ;",
6
6
  "names": ["stripHTML", "LinkUIBlockInserter", "VStack"]
7
7
  }
@@ -61,17 +61,34 @@ function Controls({ attributes, setAttributes, clientId }) {
61
61
  const { label, url, description, rel, opensInNewTab } = attributes;
62
62
  const lastURLRef = (0, import_element.useRef)(url);
63
63
  const dropdownMenuProps = (0, import_hooks.useToolsPanelDropdownMenuProps)();
64
+ const urlInputRef = (0, import_element.useRef)();
65
+ const shouldFocusURLInputRef = (0, import_element.useRef)(false);
64
66
  const inputId = (0, import_compose.useInstanceId)(Controls, "link-input");
65
67
  const helpTextId = `${inputId}__help`;
66
- const { hasUrlBinding, clearBinding } = (0, import_use_entity_binding.useEntityBinding)({
68
+ const [inputValue, setInputValue] = (0, import_element.useState)(url);
69
+ (0, import_element.useEffect)(() => {
70
+ setInputValue(url);
71
+ lastURLRef.current = url;
72
+ }, [url]);
73
+ const { hasUrlBinding, isBoundEntityAvailable, clearBinding } = (0, import_use_entity_binding.useEntityBinding)({
67
74
  clientId,
68
75
  attributes
69
76
  });
70
77
  const { updateBlockAttributes } = (0, import_data.useDispatch)(import_block_editor.store);
71
- const editBoundLink = () => {
78
+ const unsyncBoundLink = () => {
72
79
  clearBinding();
73
- updateBlockAttributes(clientId, { url: "", id: void 0 });
80
+ updateBlockAttributes(clientId, {
81
+ url: lastURLRef.current,
82
+ // set the lastURLRef as the new editable value so we avoid bugs from empty link states
83
+ id: void 0
84
+ });
74
85
  };
86
+ (0, import_element.useEffect)(() => {
87
+ if (!hasUrlBinding && shouldFocusURLInputRef.current) {
88
+ urlInputRef.current?.select();
89
+ }
90
+ shouldFocusURLInputRef.current = false;
91
+ }, [hasUrlBinding]);
75
92
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
76
93
  import_components.__experimentalToolsPanel,
77
94
  {
@@ -119,39 +136,54 @@ function Controls({ attributes, setAttributes, clientId }) {
119
136
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
120
137
  import_components.__experimentalInputControl,
121
138
  {
139
+ ref: urlInputRef,
122
140
  __nextHasNoMarginBottom: true,
123
141
  __next40pxDefaultSize: true,
124
142
  id: inputId,
125
143
  label: (0, import_i18n.__)("Link"),
126
- value: url ? (0, import_url.safeDecodeURI)(url) : "",
127
- onChange: (urlValue) => {
128
- if (hasUrlBinding) {
129
- return;
144
+ value: (() => {
145
+ if (hasUrlBinding && !isBoundEntityAvailable) {
146
+ return "";
130
147
  }
131
- setAttributes({
132
- url: encodeURI((0, import_url.safeDecodeURI)(urlValue))
133
- });
134
- },
148
+ return inputValue ? (0, import_url.safeDecodeURI)(inputValue) : "";
149
+ })(),
135
150
  autoComplete: "off",
136
151
  type: "url",
137
152
  disabled: hasUrlBinding,
153
+ "aria-invalid": hasUrlBinding && !isBoundEntityAvailable ? "true" : void 0,
154
+ "aria-describedby": helpTextId,
155
+ className: hasUrlBinding && !isBoundEntityAvailable ? "navigation-link-control__input-with-error-suffix" : void 0,
156
+ onChange: (newValue) => {
157
+ if (isBoundEntityAvailable) {
158
+ return;
159
+ }
160
+ setInputValue(newValue);
161
+ },
138
162
  onFocus: () => {
139
- if (hasUrlBinding) {
163
+ if (isBoundEntityAvailable) {
140
164
  return;
141
165
  }
142
166
  lastURLRef.current = url;
143
167
  },
144
168
  onBlur: () => {
145
- if (hasUrlBinding) {
169
+ if (isBoundEntityAvailable) {
146
170
  return;
147
171
  }
148
- (0, import_update_attributes.updateAttributes)(
149
- { url: !url ? lastURLRef.current : url },
150
- setAttributes,
151
- { ...attributes, url: lastURLRef.current }
152
- );
172
+ const finalValue = !inputValue ? lastURLRef.current : inputValue;
173
+ setInputValue(finalValue);
174
+ (0, import_update_attributes.updateAttributes)({ url: finalValue }, setAttributes, {
175
+ ...attributes,
176
+ url: lastURLRef.current
177
+ });
153
178
  },
154
- help: hasUrlBinding && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
179
+ help: hasUrlBinding && !isBoundEntityAvailable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
180
+ MissingEntityHelpText,
181
+ {
182
+ id: helpTextId,
183
+ type: attributes.type,
184
+ kind: attributes.kind
185
+ }
186
+ ) : isBoundEntityAvailable && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
155
187
  BindingHelpText,
156
188
  {
157
189
  type: attributes.type,
@@ -162,11 +194,15 @@ function Controls({ attributes, setAttributes, clientId }) {
162
194
  import_components.Button,
163
195
  {
164
196
  icon: import_icons.linkOff,
165
- onClick: editBoundLink,
197
+ onClick: () => {
198
+ unsyncBoundLink();
199
+ shouldFocusURLInputRef.current = true;
200
+ },
166
201
  "aria-describedby": helpTextId,
167
202
  showTooltip: true,
168
203
  label: (0, import_i18n.__)("Unsync and edit"),
169
- __next40pxDefaultSize: true
204
+ __next40pxDefaultSize: true,
205
+ className: hasUrlBinding && !isBoundEntityAvailable ? "navigation-link-control__error-suffix-button" : void 0
170
206
  }
171
207
  )
172
208
  }
@@ -251,6 +287,25 @@ function BindingHelpText({ type, kind }) {
251
287
  entityType
252
288
  );
253
289
  }
290
+ function MissingEntityHelpText({ id, type, kind }) {
291
+ const entityType = getEntityTypeName(type, kind);
292
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
293
+ "span",
294
+ {
295
+ id,
296
+ className: "navigation-link-control__error-text",
297
+ role: "alert",
298
+ "aria-live": "polite",
299
+ children: (0, import_i18n.sprintf)(
300
+ /* translators: %s is the entity type (e.g., "page", "post", "category") */
301
+ (0, import_i18n.__)(
302
+ "Synced %s is missing. Please update or remove this link."
303
+ ),
304
+ entityType
305
+ )
306
+ }
307
+ );
308
+ }
254
309
  // Annotate the CommonJS export names for ESM import in node:
255
310
  0 && (module.exports = {
256
311
  Controls