@wordpress/block-editor 15.10.1-next.v.0 → 15.11.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.
Files changed (81) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-edit/context.cjs +5 -0
  3. package/build/components/block-edit/context.cjs.map +2 -2
  4. package/build/components/block-edit/index.cjs +3 -0
  5. package/build/components/block-edit/index.cjs.map +2 -2
  6. package/build/components/block-inspector/index.cjs +2 -9
  7. package/build/components/block-inspector/index.cjs.map +2 -2
  8. package/build/components/block-list/block.cjs +3 -0
  9. package/build/components/block-list/block.cjs.map +2 -2
  10. package/build/components/button-block-appender/index.cjs +23 -19
  11. package/build/components/button-block-appender/index.cjs.map +2 -2
  12. package/build/components/font-sizes/font-size-picker.cjs +2 -1
  13. package/build/components/font-sizes/font-size-picker.cjs.map +2 -2
  14. package/build/components/inspector-controls/fill.cjs +4 -25
  15. package/build/components/inspector-controls/fill.cjs.map +2 -2
  16. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.cjs +6 -6
  17. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.cjs.map +2 -2
  18. package/build/hooks/block-fields/index.cjs +52 -86
  19. package/build/hooks/block-fields/index.cjs.map +3 -3
  20. package/build/hooks/block-fields/link/index.cjs +2 -11
  21. package/build/hooks/block-fields/link/index.cjs.map +2 -2
  22. package/build/hooks/block-fields/media/index.cjs +9 -14
  23. package/build/hooks/block-fields/media/index.cjs.map +2 -2
  24. package/build/hooks/index.cjs +2 -1
  25. package/build/hooks/index.cjs.map +3 -3
  26. package/build/hooks/list-view.cjs +27 -10
  27. package/build/hooks/list-view.cjs.map +2 -2
  28. package/build/hooks/utils.cjs +3 -2
  29. package/build/hooks/utils.cjs.map +2 -2
  30. package/build/store/selectors.cjs +7 -1
  31. package/build/store/selectors.cjs.map +2 -2
  32. package/build-module/components/block-edit/context.mjs +4 -0
  33. package/build-module/components/block-edit/context.mjs.map +2 -2
  34. package/build-module/components/block-edit/index.mjs +4 -0
  35. package/build-module/components/block-edit/index.mjs.map +2 -2
  36. package/build-module/components/block-inspector/index.mjs +2 -9
  37. package/build-module/components/block-inspector/index.mjs.map +2 -2
  38. package/build-module/components/block-list/block.mjs +3 -0
  39. package/build-module/components/block-list/block.mjs.map +2 -2
  40. package/build-module/components/button-block-appender/index.mjs +23 -19
  41. package/build-module/components/button-block-appender/index.mjs.map +2 -2
  42. package/build-module/components/font-sizes/font-size-picker.mjs +2 -1
  43. package/build-module/components/font-sizes/font-size-picker.mjs.map +2 -2
  44. package/build-module/components/inspector-controls/fill.mjs +6 -22
  45. package/build-module/components/inspector-controls/fill.mjs.map +2 -2
  46. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.mjs +6 -6
  47. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.mjs.map +2 -2
  48. package/build-module/hooks/block-fields/index.mjs +45 -87
  49. package/build-module/hooks/block-fields/index.mjs.map +2 -2
  50. package/build-module/hooks/block-fields/link/index.mjs +2 -11
  51. package/build-module/hooks/block-fields/link/index.mjs.map +2 -2
  52. package/build-module/hooks/block-fields/media/index.mjs +9 -14
  53. package/build-module/hooks/block-fields/media/index.mjs.map +2 -2
  54. package/build-module/hooks/index.mjs +2 -1
  55. package/build-module/hooks/index.mjs.map +2 -2
  56. package/build-module/hooks/list-view.mjs +27 -10
  57. package/build-module/hooks/list-view.mjs.map +2 -2
  58. package/build-module/hooks/utils.mjs +5 -3
  59. package/build-module/hooks/utils.mjs.map +2 -2
  60. package/build-module/store/selectors.mjs +7 -1
  61. package/build-module/store/selectors.mjs.map +2 -2
  62. package/package.json +39 -39
  63. package/src/components/block-edit/context.js +3 -0
  64. package/src/components/block-edit/index.js +6 -0
  65. package/src/components/block-inspector/index.js +2 -6
  66. package/src/components/block-list/block.js +3 -0
  67. package/src/components/block-list/block.native.js +5 -0
  68. package/src/components/block-patterns-list/stories/index.story.jsx +1 -1
  69. package/src/components/button-block-appender/index.js +2 -2
  70. package/src/components/font-sizes/font-size-picker.js +1 -0
  71. package/src/components/inspector-controls/fill.js +10 -20
  72. package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +11 -8
  73. package/src/hooks/block-fields/index.js +66 -111
  74. package/src/hooks/block-fields/link/index.js +2 -14
  75. package/src/hooks/block-fields/media/index.js +9 -21
  76. package/src/hooks/index.js +2 -1
  77. package/src/hooks/list-view.js +40 -10
  78. package/src/hooks/utils.js +4 -0
  79. package/src/store/selectors.js +14 -6
  80. /package/src/components/block-icon/stories/{index.story.js → index.story.ts} +0 -0
  81. /package/src/components/contrast-checker/stories/{index.story.js → index.story.ts} +0 -0
@@ -30,7 +30,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // packages/block-editor/src/components/inspector-controls/fill.js
31
31
  var fill_exports = {};
32
32
  __export(fill_exports, {
33
- PrivateInspectorControlsFill: () => PrivateInspectorControlsFill,
34
33
  default: () => InspectorControlsFill
35
34
  });
36
35
  module.exports = __toCommonJS(fill_exports);
@@ -41,12 +40,11 @@ var import_element = require("@wordpress/element");
41
40
  var import_context = require("../block-edit/context.cjs");
42
41
  var import_groups = __toESM(require("./groups.cjs"));
43
42
  var import_jsx_runtime = require("react/jsx-runtime");
44
- function PrivateInspectorControlsFill({
43
+ function InspectorControlsFill({
45
44
  children,
46
45
  group = "default",
47
46
  __experimentalGroup,
48
- resetAllFilter,
49
- forceDisplayControls
47
+ resetAllFilter
50
48
  }) {
51
49
  if (__experimentalGroup) {
52
50
  (0, import_deprecated.default)(
@@ -65,7 +63,8 @@ function PrivateInspectorControlsFill({
65
63
  (0, import_warning.default)(`Unknown InspectorControls group "${group}" provided.`);
66
64
  return null;
67
65
  }
68
- if (!forceDisplayControls && !context[import_context.mayDisplayControlsKey]) {
66
+ const shouldDisplayForPatternEditing = context[import_context.mayDisplayPatternEditingControlsKey] && (group === "list" || group === "content");
67
+ if (!context[import_context.mayDisplayControlsKey] && !shouldDisplayForPatternEditing) {
69
68
  return null;
70
69
  }
71
70
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalStyleProvider, { document, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Fill, { children: (fillProps) => {
@@ -79,22 +78,6 @@ function PrivateInspectorControlsFill({
79
78
  );
80
79
  } }) });
81
80
  }
82
- function InspectorControlsFill({
83
- children,
84
- group = "default",
85
- __experimentalGroup,
86
- resetAllFilter
87
- }) {
88
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
89
- PrivateInspectorControlsFill,
90
- {
91
- group,
92
- __experimentalGroup,
93
- resetAllFilter,
94
- children
95
- }
96
- );
97
- }
98
81
  function RegisterResetAll({ resetAllFilter, children }) {
99
82
  const { registerResetAllFilter, deregisterResetAllFilter } = (0, import_element.useContext)(import_components.__experimentalToolsPanelContext);
100
83
  (0, import_element.useEffect)(() => {
@@ -115,8 +98,4 @@ function ToolsPanelInspectorControl({ children, resetAllFilter, fillProps }) {
115
98
  innerMarkup
116
99
  );
117
100
  }
118
- // Annotate the CommonJS export names for ESM import in node:
119
- 0 && (module.exports = {
120
- PrivateInspectorControlsFill
121
- });
122
101
  //# sourceMappingURL=fill.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/inspector-controls/fill.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalStyleProvider as StyleProvider,\n\t__experimentalToolsPanelContext as ToolsPanelContext,\n} from '@wordpress/components';\nimport warning from '@wordpress/warning';\nimport deprecated from '@wordpress/deprecated';\nimport { useEffect, useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseBlockEditContext,\n\tmayDisplayControlsKey,\n} from '../block-edit/context';\nimport groups from './groups';\n\nexport function PrivateInspectorControlsFill( {\n\tchildren,\n\tgroup = 'default',\n\t__experimentalGroup,\n\tresetAllFilter,\n\tforceDisplayControls,\n} ) {\n\tif ( __experimentalGroup ) {\n\t\tdeprecated(\n\t\t\t'`__experimentalGroup` property in `InspectorControlsFill`',\n\t\t\t{\n\t\t\t\tsince: '6.2',\n\t\t\t\tversion: '6.4',\n\t\t\t\talternative: '`group`',\n\t\t\t}\n\t\t);\n\t\tgroup = __experimentalGroup;\n\t}\n\n\tconst context = useBlockEditContext();\n\tconst Fill = groups[ group ]?.Fill;\n\tif ( ! Fill ) {\n\t\twarning( `Unknown InspectorControls group \"${ group }\" provided.` );\n\t\treturn null;\n\t}\n\tif ( ! forceDisplayControls && ! context[ mayDisplayControlsKey ] ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<StyleProvider document={ document }>\n\t\t\t<Fill>\n\t\t\t\t{ ( fillProps ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ToolsPanelInspectorControl\n\t\t\t\t\t\t\tfillProps={ fillProps }\n\t\t\t\t\t\t\tchildren={ children }\n\t\t\t\t\t\t\tresetAllFilter={ resetAllFilter }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t</Fill>\n\t\t</StyleProvider>\n\t);\n}\n\nexport default function InspectorControlsFill( {\n\tchildren,\n\tgroup = 'default',\n\t__experimentalGroup,\n\tresetAllFilter,\n} ) {\n\treturn (\n\t\t<PrivateInspectorControlsFill\n\t\t\tgroup={ group }\n\t\t\t__experimentalGroup={ __experimentalGroup }\n\t\t\tresetAllFilter={ resetAllFilter }\n\t\t>\n\t\t\t{ children }\n\t\t</PrivateInspectorControlsFill>\n\t);\n}\n\nfunction RegisterResetAll( { resetAllFilter, children } ) {\n\tconst { registerResetAllFilter, deregisterResetAllFilter } =\n\t\tuseContext( ToolsPanelContext );\n\tuseEffect( () => {\n\t\tif (\n\t\t\tresetAllFilter &&\n\t\t\tregisterResetAllFilter &&\n\t\t\tderegisterResetAllFilter\n\t\t) {\n\t\t\tregisterResetAllFilter( resetAllFilter );\n\t\t\treturn () => {\n\t\t\t\tderegisterResetAllFilter( resetAllFilter );\n\t\t\t};\n\t\t}\n\t}, [ resetAllFilter, registerResetAllFilter, deregisterResetAllFilter ] );\n\treturn children;\n}\n\nfunction ToolsPanelInspectorControl( { children, resetAllFilter, fillProps } ) {\n\t// `fillProps.forwardedContext` is an array of context provider entries, provided by slot,\n\t// that should wrap the fill markup.\n\tconst { forwardedContext = [] } = fillProps;\n\n\t// Children passed to InspectorControlsFill will not have\n\t// access to any React Context whose Provider is part of\n\t// the InspectorControlsSlot tree. So we re-create the\n\t// Provider in this subtree.\n\tconst innerMarkup = (\n\t\t<RegisterResetAll resetAllFilter={ resetAllFilter }>\n\t\t\t{ children }\n\t\t</RegisterResetAll>\n\t);\n\treturn forwardedContext.reduce(\n\t\t( inner, [ Provider, props ] ) => (\n\t\t\t<Provider { ...props }>{ inner }</Provider>\n\t\t),\n\t\tinnerMarkup\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAGO;AACP,qBAAoB;AACpB,wBAAuB;AACvB,qBAAsC;AAKtC,qBAGO;AACP,oBAAmB;AAoCb;AAlCC,SAAS,6BAA8B;AAAA,EAC7C;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,MAAK,qBAAsB;AAC1B,0BAAAA;AAAA,MACC;AAAA,MACA;AAAA,QACC,OAAO;AAAA,QACP,SAAS;AAAA,QACT,aAAa;AAAA,MACd;AAAA,IACD;AACA,YAAQ;AAAA,EACT;AAEA,QAAM,cAAU,oCAAoB;AACpC,QAAM,OAAO,cAAAC,QAAQ,KAAM,GAAG;AAC9B,MAAK,CAAE,MAAO;AACb,uBAAAC,SAAS,oCAAqC,KAAM,aAAc;AAClE,WAAO;AAAA,EACR;AACA,MAAK,CAAE,wBAAwB,CAAE,QAAS,oCAAsB,GAAI;AACnE,WAAO;AAAA,EACR;AAEA,SACC,4CAAC,kBAAAC,6BAAA,EAAc,UACd,sDAAC,QACE,WAAE,cAAe;AAClB,WACC;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACD;AAAA,EAEF,GACD,GACD;AAEF;AAEe,SAAR,sBAAwC;AAAA,EAC9C;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA;AACD,GAAI;AACH,SACC;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MAEE;AAAA;AAAA,EACH;AAEF;AAEA,SAAS,iBAAkB,EAAE,gBAAgB,SAAS,GAAI;AACzD,QAAM,EAAE,wBAAwB,yBAAyB,QACxD,2BAAY,kBAAAC,+BAAkB;AAC/B,gCAAW,MAAM;AAChB,QACC,kBACA,0BACA,0BACC;AACD,6BAAwB,cAAe;AACvC,aAAO,MAAM;AACZ,iCAA0B,cAAe;AAAA,MAC1C;AAAA,IACD;AAAA,EACD,GAAG,CAAE,gBAAgB,wBAAwB,wBAAyB,CAAE;AACxE,SAAO;AACR;AAEA,SAAS,2BAA4B,EAAE,UAAU,gBAAgB,UAAU,GAAI;AAG9E,QAAM,EAAE,mBAAmB,CAAC,EAAE,IAAI;AAMlC,QAAM,cACL,4CAAC,oBAAiB,gBACf,UACH;AAED,SAAO,iBAAiB;AAAA,IACvB,CAAE,OAAO,CAAE,UAAU,KAAM,MAC1B,4CAAC,YAAW,GAAG,OAAU,iBAAO;AAAA,IAEjC;AAAA,EACD;AACD;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalStyleProvider as StyleProvider,\n\t__experimentalToolsPanelContext as ToolsPanelContext,\n} from '@wordpress/components';\nimport warning from '@wordpress/warning';\nimport deprecated from '@wordpress/deprecated';\nimport { useEffect, useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseBlockEditContext,\n\tmayDisplayControlsKey,\n\tmayDisplayPatternEditingControlsKey,\n} from '../block-edit/context';\nimport groups from './groups';\n\nexport default function InspectorControlsFill( {\n\tchildren,\n\tgroup = 'default',\n\t__experimentalGroup,\n\tresetAllFilter,\n} ) {\n\tif ( __experimentalGroup ) {\n\t\tdeprecated(\n\t\t\t'`__experimentalGroup` property in `InspectorControlsFill`',\n\t\t\t{\n\t\t\t\tsince: '6.2',\n\t\t\t\tversion: '6.4',\n\t\t\t\talternative: '`group`',\n\t\t\t}\n\t\t);\n\t\tgroup = __experimentalGroup;\n\t}\n\n\tconst context = useBlockEditContext();\n\tconst Fill = groups[ group ]?.Fill;\n\tif ( ! Fill ) {\n\t\twarning( `Unknown InspectorControls group \"${ group }\" provided.` );\n\t\treturn null;\n\t}\n\tconst shouldDisplayForPatternEditing =\n\t\tcontext[ mayDisplayPatternEditingControlsKey ] &&\n\t\t( group === 'list' || group === 'content' );\n\n\tif (\n\t\t! context[ mayDisplayControlsKey ] &&\n\t\t! shouldDisplayForPatternEditing\n\t) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<StyleProvider document={ document }>\n\t\t\t<Fill>\n\t\t\t\t{ ( fillProps ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ToolsPanelInspectorControl\n\t\t\t\t\t\t\tfillProps={ fillProps }\n\t\t\t\t\t\t\tchildren={ children }\n\t\t\t\t\t\t\tresetAllFilter={ resetAllFilter }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t</Fill>\n\t\t</StyleProvider>\n\t);\n}\n\nfunction RegisterResetAll( { resetAllFilter, children } ) {\n\tconst { registerResetAllFilter, deregisterResetAllFilter } =\n\t\tuseContext( ToolsPanelContext );\n\tuseEffect( () => {\n\t\tif (\n\t\t\tresetAllFilter &&\n\t\t\tregisterResetAllFilter &&\n\t\t\tderegisterResetAllFilter\n\t\t) {\n\t\t\tregisterResetAllFilter( resetAllFilter );\n\t\t\treturn () => {\n\t\t\t\tderegisterResetAllFilter( resetAllFilter );\n\t\t\t};\n\t\t}\n\t}, [ resetAllFilter, registerResetAllFilter, deregisterResetAllFilter ] );\n\treturn children;\n}\n\nfunction ToolsPanelInspectorControl( { children, resetAllFilter, fillProps } ) {\n\t// `fillProps.forwardedContext` is an array of context provider entries, provided by slot,\n\t// that should wrap the fill markup.\n\tconst { forwardedContext = [] } = fillProps;\n\n\t// Children passed to InspectorControlsFill will not have\n\t// access to any React Context whose Provider is part of\n\t// the InspectorControlsSlot tree. So we re-create the\n\t// Provider in this subtree.\n\tconst innerMarkup = (\n\t\t<RegisterResetAll resetAllFilter={ resetAllFilter }>\n\t\t\t{ children }\n\t\t</RegisterResetAll>\n\t);\n\treturn forwardedContext.reduce(\n\t\t( inner, [ Provider, props ] ) => (\n\t\t\t<Provider { ...props }>{ inner }</Provider>\n\t\t),\n\t\tinnerMarkup\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAGO;AACP,qBAAoB;AACpB,wBAAuB;AACvB,qBAAsC;AAKtC,qBAIO;AACP,oBAAmB;AA0Cb;AAxCS,SAAR,sBAAwC;AAAA,EAC9C;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA;AACD,GAAI;AACH,MAAK,qBAAsB;AAC1B,0BAAAA;AAAA,MACC;AAAA,MACA;AAAA,QACC,OAAO;AAAA,QACP,SAAS;AAAA,QACT,aAAa;AAAA,MACd;AAAA,IACD;AACA,YAAQ;AAAA,EACT;AAEA,QAAM,cAAU,oCAAoB;AACpC,QAAM,OAAO,cAAAC,QAAQ,KAAM,GAAG;AAC9B,MAAK,CAAE,MAAO;AACb,uBAAAC,SAAS,oCAAqC,KAAM,aAAc;AAClE,WAAO;AAAA,EACR;AACA,QAAM,iCACL,QAAS,kDAAoC,MAC3C,UAAU,UAAU,UAAU;AAEjC,MACC,CAAE,QAAS,oCAAsB,KACjC,CAAE,gCACD;AACD,WAAO;AAAA,EACR;AAEA,SACC,4CAAC,kBAAAC,6BAAA,EAAc,UACd,sDAAC,QACE,WAAE,cAAe;AAClB,WACC;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACD;AAAA,EAEF,GACD,GACD;AAEF;AAEA,SAAS,iBAAkB,EAAE,gBAAgB,SAAS,GAAI;AACzD,QAAM,EAAE,wBAAwB,yBAAyB,QACxD,2BAAY,kBAAAC,+BAAkB;AAC/B,gCAAW,MAAM;AAChB,QACC,kBACA,0BACA,0BACC;AACD,6BAAwB,cAAe;AACvC,aAAO,MAAM;AACZ,iCAA0B,cAAe;AAAA,MAC1C;AAAA,IACD;AAAA,EACD,GAAG,CAAE,gBAAgB,wBAAwB,wBAAyB,CAAE;AACxE,SAAO;AACR;AAEA,SAAS,2BAA4B,EAAE,UAAU,gBAAgB,UAAU,GAAI;AAG9E,QAAM,EAAE,mBAAmB,CAAC,EAAE,IAAI;AAMlC,QAAM,cACL,4CAAC,oBAAiB,gBACf,UACH;AAED,SAAO,iBAAiB;AAAA,IACvB,CAAE,OAAO,CAAE,UAAU,KAAM,MAC1B,4CAAC,YAAW,GAAG,OAAU,iBAAO;AAAA,IAEjC;AAAA,EACD;AACD;",
6
6
  "names": ["deprecated", "groups", "warning", "StyleProvider", "ToolsPanelContext"]
7
7
  }
@@ -86,16 +86,16 @@ function useInspectorControlsTabs(blockName, contentClientIds, isSectionBlock, h
86
86
  ...(0, import_components.__experimentalUseSlotFills)(positionGroup.name) || [],
87
87
  ...hasListFills && hasStyleFills > 1 ? advancedFills : []
88
88
  ];
89
- const hasContentTab = hasContentFills || !!(contentClientIds && contentClientIds.length > 0);
90
- const hasListTab = hasListFills && !isSectionBlock;
91
- if (hasListTab) {
92
- tabs.push(import_utils.TAB_LIST_VIEW);
93
- }
89
+ const shouldShowBlockFields = window?.__experimentalContentOnlyInspectorFields;
90
+ const hasContentTab = hasContentFills || !shouldShowBlockFields && contentClientIds?.length;
94
91
  if (hasContentTab) {
95
92
  tabs.push(import_utils.TAB_CONTENT);
96
93
  }
94
+ if (hasListFills) {
95
+ tabs.push(import_utils.TAB_LIST_VIEW);
96
+ }
97
97
  if ((settingsFills.length || // Advanded fills who up in settings tab if available or they blend into the default tab, if there's only one tab.
98
- advancedFills.length && (hasContentTab || hasListTab)) && !isSectionBlock) {
98
+ advancedFills.length && (hasContentTab || hasListFills)) && !isSectionBlock) {
99
99
  tabs.push(import_utils.TAB_SETTINGS);
100
100
  }
101
101
  if (hasBlockStyles || hasStyleFills) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/inspector-controls-tabs/use-inspector-controls-tabs.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __experimentalUseSlotFills as useSlotFills } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport InspectorControlsGroups from '../inspector-controls/groups';\nimport { InspectorAdvancedControls } from '../inspector-controls';\nimport { TAB_LIST_VIEW, TAB_SETTINGS, TAB_STYLES, TAB_CONTENT } from './utils';\nimport { store as blockEditorStore } from '../../store';\n\nconst EMPTY_ARRAY = [];\n\nfunction getShowTabs( blockName, tabSettings = {} ) {\n\t// Block specific setting takes precedence over generic default.\n\tif ( tabSettings[ blockName ] !== undefined ) {\n\t\treturn tabSettings[ blockName ];\n\t}\n\n\t// Use generic default if set over the Gutenberg experiment option.\n\tif ( tabSettings.default !== undefined ) {\n\t\treturn tabSettings.default;\n\t}\n\n\treturn true;\n}\n\nexport default function useInspectorControlsTabs(\n\tblockName,\n\tcontentClientIds,\n\tisSectionBlock,\n\thasBlockStyles\n) {\n\tconst tabs = [];\n\tconst {\n\t\tbindings: bindingsGroup,\n\t\tborder: borderGroup,\n\t\tcolor: colorGroup,\n\t\tcontent: contentGroup,\n\t\tdefault: defaultGroup,\n\t\tdimensions: dimensionsGroup,\n\t\tlist: listGroup,\n\t\tposition: positionGroup,\n\t\tstyles: stylesGroup,\n\t\ttypography: typographyGroup,\n\t\teffects: effectsGroup,\n\t} = InspectorControlsGroups;\n\n\t// List View Tab: If there are any fills for the list group add that tab.\n\tconst listFills = useSlotFills( listGroup.name );\n\tconst hasListFills = !! listFills && listFills.length;\n\n\t// Content Tab: If there are any fills for the content group add that tab.\n\tconst contentFills = useSlotFills( contentGroup.name );\n\tconst hasContentFills = !! contentFills && contentFills.length;\n\n\t// Styles Tab: Add this tab if there are any fills for block supports\n\t// e.g. border, color, spacing, typography, etc.\n\tconst styleFills = [\n\t\t...( useSlotFills( borderGroup.name ) || [] ),\n\t\t...( useSlotFills( colorGroup.name ) || [] ),\n\t\t...( useSlotFills( dimensionsGroup.name ) || [] ),\n\t\t...( useSlotFills( stylesGroup.name ) || [] ),\n\t\t...( useSlotFills( typographyGroup.name ) || [] ),\n\t\t...( useSlotFills( effectsGroup.name ) || [] ),\n\t];\n\tconst hasStyleFills = styleFills.length;\n\n\t// Settings Tab: If we don't have multiple tabs to display\n\t// (i.e. both list view and styles), check only the default and position\n\t// InspectorControls slots. If we have multiple tabs, we'll need to check\n\t// the advanced controls slot as well to ensure they are rendered.\n\tconst advancedFills = [\n\t\t...( useSlotFills( InspectorAdvancedControls.slotName ) || [] ),\n\t\t...( useSlotFills( bindingsGroup.name ) || [] ),\n\t];\n\n\tconst settingsFills = [\n\t\t...( useSlotFills( defaultGroup.name ) || [] ),\n\t\t...( useSlotFills( positionGroup.name ) || [] ),\n\t\t...( hasListFills && hasStyleFills > 1 ? advancedFills : [] ),\n\t];\n\n\tconst hasContentTab =\n\t\thasContentFills ||\n\t\t!! ( contentClientIds && contentClientIds.length > 0 );\n\n\tconst hasListTab = hasListFills && ! isSectionBlock;\n\n\t// Add the tabs in the order that they will default to if available.\n\t// List View > Content > Settings > Styles.\n\tif ( hasListTab ) {\n\t\ttabs.push( TAB_LIST_VIEW );\n\t}\n\n\tif ( hasContentTab ) {\n\t\ttabs.push( TAB_CONTENT );\n\t}\n\n\tif (\n\t\t( settingsFills.length ||\n\t\t\t// Advanded fills who up in settings tab if available or they blend into the default tab, if there's only one tab.\n\t\t\t( advancedFills.length && ( hasContentTab || hasListTab ) ) ) &&\n\t\t! isSectionBlock\n\t) {\n\t\ttabs.push( TAB_SETTINGS );\n\t}\n\n\tif ( hasBlockStyles || hasStyleFills ) {\n\t\ttabs.push( TAB_STYLES );\n\t}\n\n\tconst tabSettings = useSelect( ( select ) => {\n\t\treturn select( blockEditorStore ).getSettings().blockInspectorTabs;\n\t}, [] );\n\n\tconst showTabs = getShowTabs( blockName, tabSettings );\n\treturn showTabs ? tabs : EMPTY_ARRAY;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAA2D;AAC3D,kBAA0B;AAK1B,oBAAoC;AACpC,gCAA0C;AAC1C,mBAAqE;AACrE,mBAA0C;AAE1C,IAAM,cAAc,CAAC;AAErB,SAAS,YAAa,WAAW,cAAc,CAAC,GAAI;AAEnD,MAAK,YAAa,SAAU,MAAM,QAAY;AAC7C,WAAO,YAAa,SAAU;AAAA,EAC/B;AAGA,MAAK,YAAY,YAAY,QAAY;AACxC,WAAO,YAAY;AAAA,EACpB;AAEA,SAAO;AACR;AAEe,SAAR,yBACN,WACA,kBACA,gBACA,gBACC;AACD,QAAM,OAAO,CAAC;AACd,QAAM;AAAA,IACL,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,MAAM;AAAA,IACN,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,SAAS;AAAA,EACV,IAAI,cAAAA;AAGJ,QAAM,gBAAY,kBAAAC,4BAAc,UAAU,IAAK;AAC/C,QAAM,eAAe,CAAC,CAAE,aAAa,UAAU;AAG/C,QAAM,mBAAe,kBAAAA,4BAAc,aAAa,IAAK;AACrD,QAAM,kBAAkB,CAAC,CAAE,gBAAgB,aAAa;AAIxD,QAAM,aAAa;AAAA,IAClB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CAAC,CAAE;AAEN,QAAM,WAAW,YAAa,WAAW,WAAY;AACrD,SAAO,WAAW,OAAO;AAC1B;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __experimentalUseSlotFills as useSlotFills } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport InspectorControlsGroups from '../inspector-controls/groups';\nimport { InspectorAdvancedControls } from '../inspector-controls';\nimport { TAB_LIST_VIEW, TAB_SETTINGS, TAB_STYLES, TAB_CONTENT } from './utils';\nimport { store as blockEditorStore } from '../../store';\n\nconst EMPTY_ARRAY = [];\n\nfunction getShowTabs( blockName, tabSettings = {} ) {\n\t// Block specific setting takes precedence over generic default.\n\tif ( tabSettings[ blockName ] !== undefined ) {\n\t\treturn tabSettings[ blockName ];\n\t}\n\n\t// Use generic default if set over the Gutenberg experiment option.\n\tif ( tabSettings.default !== undefined ) {\n\t\treturn tabSettings.default;\n\t}\n\n\treturn true;\n}\n\nexport default function useInspectorControlsTabs(\n\tblockName,\n\tcontentClientIds,\n\tisSectionBlock,\n\thasBlockStyles\n) {\n\tconst tabs = [];\n\tconst {\n\t\tbindings: bindingsGroup,\n\t\tborder: borderGroup,\n\t\tcolor: colorGroup,\n\t\tcontent: contentGroup,\n\t\tdefault: defaultGroup,\n\t\tdimensions: dimensionsGroup,\n\t\tlist: listGroup,\n\t\tposition: positionGroup,\n\t\tstyles: stylesGroup,\n\t\ttypography: typographyGroup,\n\t\teffects: effectsGroup,\n\t} = InspectorControlsGroups;\n\n\t// List View Tab: If there are any fills for the list group add that tab.\n\tconst listFills = useSlotFills( listGroup.name );\n\tconst hasListFills = !! listFills && listFills.length;\n\n\t// Content Tab: If there are any fills for the content group add that tab.\n\tconst contentFills = useSlotFills( contentGroup.name );\n\tconst hasContentFills = !! contentFills && contentFills.length;\n\n\t// Styles Tab: Add this tab if there are any fills for block supports\n\t// e.g. border, color, spacing, typography, etc.\n\tconst styleFills = [\n\t\t...( useSlotFills( borderGroup.name ) || [] ),\n\t\t...( useSlotFills( colorGroup.name ) || [] ),\n\t\t...( useSlotFills( dimensionsGroup.name ) || [] ),\n\t\t...( useSlotFills( stylesGroup.name ) || [] ),\n\t\t...( useSlotFills( typographyGroup.name ) || [] ),\n\t\t...( useSlotFills( effectsGroup.name ) || [] ),\n\t];\n\tconst hasStyleFills = styleFills.length;\n\n\t// Settings Tab: If we don't have multiple tabs to display\n\t// (i.e. both list view and styles), check only the default and position\n\t// InspectorControls slots. If we have multiple tabs, we'll need to check\n\t// the advanced controls slot as well to ensure they are rendered.\n\tconst advancedFills = [\n\t\t...( useSlotFills( InspectorAdvancedControls.slotName ) || [] ),\n\t\t...( useSlotFills( bindingsGroup.name ) || [] ),\n\t];\n\n\tconst settingsFills = [\n\t\t...( useSlotFills( defaultGroup.name ) || [] ),\n\t\t...( useSlotFills( positionGroup.name ) || [] ),\n\t\t...( hasListFills && hasStyleFills > 1 ? advancedFills : [] ),\n\t];\n\n\t// When the block fields experiment is active, only rely on `hasContentFills`\n\t// to determine whether the content tab to be shown. The tab purely uses slot\n\t// fills in this situation.\n\tconst shouldShowBlockFields =\n\t\twindow?.__experimentalContentOnlyInspectorFields;\n\tconst hasContentTab =\n\t\thasContentFills ||\n\t\t( ! shouldShowBlockFields && contentClientIds?.length );\n\n\tif ( hasContentTab ) {\n\t\ttabs.push( TAB_CONTENT );\n\t}\n\n\t// Add the tabs in the order that they will default to if available.\n\t// List View > Content > Settings > Styles.\n\tif ( hasListFills ) {\n\t\ttabs.push( TAB_LIST_VIEW );\n\t}\n\n\tif (\n\t\t( settingsFills.length ||\n\t\t\t// Advanded fills who up in settings tab if available or they blend into the default tab, if there's only one tab.\n\t\t\t( advancedFills.length && ( hasContentTab || hasListFills ) ) ) &&\n\t\t! isSectionBlock\n\t) {\n\t\ttabs.push( TAB_SETTINGS );\n\t}\n\n\tif ( hasBlockStyles || hasStyleFills ) {\n\t\ttabs.push( TAB_STYLES );\n\t}\n\n\tconst tabSettings = useSelect( ( select ) => {\n\t\treturn select( blockEditorStore ).getSettings().blockInspectorTabs;\n\t}, [] );\n\n\tconst showTabs = getShowTabs( blockName, tabSettings );\n\treturn showTabs ? tabs : EMPTY_ARRAY;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAA2D;AAC3D,kBAA0B;AAK1B,oBAAoC;AACpC,gCAA0C;AAC1C,mBAAqE;AACrE,mBAA0C;AAE1C,IAAM,cAAc,CAAC;AAErB,SAAS,YAAa,WAAW,cAAc,CAAC,GAAI;AAEnD,MAAK,YAAa,SAAU,MAAM,QAAY;AAC7C,WAAO,YAAa,SAAU;AAAA,EAC/B;AAGA,MAAK,YAAY,YAAY,QAAY;AACxC,WAAO,YAAY;AAAA,EACpB;AAEA,SAAO;AACR;AAEe,SAAR,yBACN,WACA,kBACA,gBACA,gBACC;AACD,QAAM,OAAO,CAAC;AACd,QAAM;AAAA,IACL,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,MAAM;AAAA,IACN,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,SAAS;AAAA,EACV,IAAI,cAAAA;AAGJ,QAAM,gBAAY,kBAAAC,4BAAc,UAAU,IAAK;AAC/C,QAAM,eAAe,CAAC,CAAE,aAAa,UAAU;AAG/C,QAAM,mBAAe,kBAAAA,4BAAc,aAAa,IAAK;AACrD,QAAM,kBAAkB,CAAC,CAAE,gBAAgB,aAAa;AAIxD,QAAM,aAAa;AAAA,IAClB,OAAK,kBAAAA,4BAAc,YAAY,IAAK,KAAK,CAAC;AAAA,IAC1C,OAAK,kBAAAA,4BAAc,WAAW,IAAK,KAAK,CAAC;AAAA,IACzC,OAAK,kBAAAA,4BAAc,gBAAgB,IAAK,KAAK,CAAC;AAAA,IAC9C,OAAK,kBAAAA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object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
8
12
  var __copyProps = (to, from, except, desc) => {
9
13
  if (from && typeof from === "object" || typeof from === "function") {
10
14
  for (let key of __getOwnPropNames(from))
@@ -21,36 +25,35 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
29
 
25
30
  // packages/block-editor/src/hooks/block-fields/index.js
26
- var import_hooks = require("@wordpress/hooks");
31
+ var block_fields_exports = {};
32
+ __export(block_fields_exports, {
33
+ BlockFieldsPanel: () => BlockFieldsPanel,
34
+ default: () => block_fields_default
35
+ });
36
+ module.exports = __toCommonJS(block_fields_exports);
27
37
  var import_blocks = require("@wordpress/blocks");
28
38
  var import_components = require("@wordpress/components");
29
- var import_compose = require("@wordpress/compose");
39
+ var import_data = require("@wordpress/data");
30
40
  var import_dataviews = require("@wordpress/dataviews");
31
41
  var import_element = require("@wordpress/element");
32
42
  var import_i18n = require("@wordpress/i18n");
43
+ var import_store = require("../../store/index.cjs");
33
44
  var import_lock_unlock = require("../../lock-unlock.cjs");
34
45
  var import_block_icon = __toESM(require("../../components/block-icon/index.cjs"));
35
46
  var import_use_block_display_title = __toESM(require("../../components/block-title/use-block-display-title.cjs"));
36
47
  var import_use_block_display_information = __toESM(require("../../components/use-block-display-information/index.cjs"));
37
48
  var import_fields_dropdown_menu = __toESM(require("./fields-dropdown-menu.cjs"));
38
49
  var import_private_block_context = require("../../components/block-list/private-block-context.cjs");
39
- var import_fill = require("../../components/inspector-controls/fill.cjs");
50
+ var import_fill = __toESM(require("../../components/inspector-controls/fill.cjs"));
40
51
  var import_rich_text = __toESM(require("./rich-text/index.cjs"));
41
52
  var import_media = __toESM(require("./media/index.cjs"));
42
53
  var import_link = __toESM(require("./link/index.cjs"));
43
54
  var import_jsx_runtime = require("react/jsx-runtime");
44
55
  var { fieldsKey, formKey } = (0, import_lock_unlock.unlock)(import_blocks.privateApis);
45
- var CONTROLS = {
46
- richtext: import_rich_text.default,
47
- media: import_media.default,
48
- link: import_link.default
49
- };
50
- function createConfiguredControl(ControlComponent, type, config) {
51
- if (!ControlComponent) {
52
- throw new Error(`Control type "${type}" not found`);
53
- }
56
+ function createConfiguredControl(ControlComponent, config = {}) {
54
57
  return function ConfiguredControl(props) {
55
58
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ControlComponent, { ...props, config });
56
59
  };
@@ -58,7 +61,6 @@ function createConfiguredControl(ControlComponent, type, config) {
58
61
  function BlockFields({
59
62
  clientId,
60
63
  blockType,
61
- attributes,
62
64
  setAttributes,
63
65
  isCollapsed = false
64
66
  }) {
@@ -68,6 +70,10 @@ function BlockFields({
68
70
  });
69
71
  const blockInformation = (0, import_use_block_display_information.default)(clientId);
70
72
  const blockTypeFields = blockType?.[fieldsKey];
73
+ const attributes = (0, import_data.useSelect)(
74
+ (select) => select(import_store.store).getBlockAttributes(clientId),
75
+ [clientId]
76
+ );
71
77
  const computedForm = (0, import_element.useMemo)(() => {
72
78
  if (!isCollapsed) {
73
79
  return blockType?.[formKey];
@@ -84,41 +90,18 @@ function BlockFields({
84
90
  }
85
91
  return blockTypeFields.map((fieldDef) => {
86
92
  const field = {
87
- id: fieldDef.id,
88
- label: fieldDef.label,
89
- type: fieldDef.type
90
- // Use the field's type; DataForm will use built-in or custom Edit
93
+ ...fieldDef
91
94
  };
92
- if (fieldDef.mapping) {
93
- field.getValue = ({ item }) => {
94
- const mappedValue = {};
95
- Object.entries(fieldDef.mapping).forEach(
96
- ([key, attrKey]) => {
97
- mappedValue[key] = item[attrKey];
98
- }
99
- );
100
- return mappedValue;
101
- };
102
- field.setValue = ({ value }) => {
103
- const attributeUpdates = {};
104
- Object.entries(fieldDef.mapping).forEach(
105
- ([key, attrKey]) => {
106
- attributeUpdates[attrKey] = value[key];
107
- }
108
- );
109
- return attributeUpdates;
110
- };
111
- }
112
- const ControlComponent = CONTROLS[fieldDef.type];
113
- if (ControlComponent) {
114
- field.Edit = createConfiguredControl(
115
- ControlComponent,
116
- fieldDef.type,
117
- {
118
- clientId,
119
- fieldDef
120
- }
121
- );
95
+ if ("string" === typeof fieldDef.Edit && fieldDef.Edit === "rich-text") {
96
+ field.Edit = createConfiguredControl(import_rich_text.default, {
97
+ clientId
98
+ });
99
+ } else if ("string" === typeof fieldDef.Edit && fieldDef.Edit === "link") {
100
+ field.Edit = createConfiguredControl(import_link.default);
101
+ } else if ("object" === typeof fieldDef.Edit && fieldDef.Edit.control === "media") {
102
+ field.Edit = createConfiguredControl(import_media.default, {
103
+ ...fieldDef.Edit
104
+ });
122
105
  }
123
106
  return field;
124
107
  });
@@ -173,45 +156,28 @@ function BlockFields({
173
156
  )
174
157
  ] });
175
158
  }
176
- var withBlockFields = (0, import_compose.createHigherOrderComponent)(
177
- (BlockEdit) => (props) => {
178
- const {
159
+ function hasBlockFieldsSupport(blockName) {
160
+ return !!(window?.__experimentalContentOnlyInspectorFields && (0, import_blocks.getBlockType)(blockName)?.[fieldsKey]);
161
+ }
162
+ function BlockFieldsPanel(props) {
163
+ const { blockType, isSelectionWithinCurrentSection } = (0, import_element.useContext)(import_private_block_context.PrivateBlockContext);
164
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fill.default, { group: "content", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
165
+ BlockFields,
166
+ {
167
+ ...props,
179
168
  blockType,
180
- isSelectionWithinCurrentSection,
181
- isSectionBlock,
182
- blockEditingMode,
183
- isSelected
184
- } = (0, import_element.useContext)(import_private_block_context.PrivateBlockContext);
185
- const shouldShowBlockFields = window?.__experimentalContentOnlyInspectorFields;
186
- const blockTypeFields = blockType?.[fieldsKey];
187
- if (!shouldShowBlockFields || !blockTypeFields?.length) {
188
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BlockEdit, { ...props }, "edit");
169
+ isCollapsed: isSelectionWithinCurrentSection
189
170
  }
190
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
191
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BlockEdit, { ...props }, "edit"),
192
- // Display the controls of all inner blocks for section/pattern editing.
193
- isSelectionWithinCurrentSection && (isSectionBlock || blockEditingMode === "contentOnly") && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
194
- import_fill.PrivateInspectorControlsFill,
195
- {
196
- group: "content",
197
- forceDisplayControls: true,
198
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
199
- BlockFields,
200
- {
201
- ...props,
202
- blockType,
203
- isCollapsed: true
204
- }
205
- )
206
- }
207
- ),
208
- !isSelectionWithinCurrentSection && isSelected && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_fill.PrivateInspectorControlsFill, { group: "content", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BlockFields, { ...props, blockType }) })
209
- ] });
210
- }
211
- );
212
- (0, import_hooks.addFilter)(
213
- "editor.BlockEdit",
214
- "core/content-only-controls/block-fields",
215
- withBlockFields
216
- );
171
+ ) });
172
+ }
173
+ var block_fields_default = {
174
+ edit: BlockFieldsPanel,
175
+ hasSupport: hasBlockFieldsSupport,
176
+ attributeKeys: [],
177
+ supportsPatternEditing: true
178
+ };
179
+ // Annotate the CommonJS export names for ESM import in node:
180
+ 0 && (module.exports = {
181
+ BlockFieldsPanel
182
+ });
217
183
  //# sourceMappingURL=index.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/block-fields/index.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\nimport {\n\t__experimentalHStack as HStack,\n\t__experimentalTruncate as Truncate,\n} from '@wordpress/components';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { DataForm } from '@wordpress/dataviews';\nimport { useContext, useState, useMemo } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport BlockIcon from '../../components/block-icon';\nimport useBlockDisplayTitle from '../../components/block-title/use-block-display-title';\nimport useBlockDisplayInformation from '../../components/use-block-display-information';\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\nimport FieldsDropdownMenu from './fields-dropdown-menu';\nimport { PrivateBlockContext } from '../../components/block-list/private-block-context';\nimport { PrivateInspectorControlsFill } from '../../components/inspector-controls/fill';\n\n// controls\nimport RichText from './rich-text';\nimport Media from './media';\nimport Link from './link';\n\nconst CONTROLS = {\n\trichtext: RichText,\n\tmedia: Media,\n\tlink: Link,\n};\n\n/**\n * Creates a configured control component that wraps a custom control\n * and passes configuration as props.\n *\n * @param {Component} ControlComponent The React component for the control.\n * @param {string} type The type of control.\n * @param {Object} config The control configuration passed as a prop.\n *\n * @return {Function} A wrapped control component\n */\nfunction createConfiguredControl( ControlComponent, type, config ) {\n\tif ( ! ControlComponent ) {\n\t\tthrow new Error( `Control type \"${ type }\" not found` );\n\t}\n\n\treturn function ConfiguredControl( props ) {\n\t\treturn <ControlComponent { ...props } config={ config } />;\n\t};\n}\n\n/**\n * Component that renders a DataForm for a single block's attributes\n * @param {Object} props\n * @param {string} props.clientId The clientId of the block.\n * @param {Object} props.blockType The blockType definition.\n * @param {Object} props.attributes The block's attribute values.\n * @param {Function} props.setAttributes Action to set the block's attributes.\n * @param {boolean} props.isCollapsed Whether the DataForm is rendered as 'collapsed' with only the first field\n * displayed by default. When collapsed a dropdown is displayed to allow\n * displaying additional fields. The block's title is displayed as the title.\n * The collapsed mode is often used when multiple BlockForms are shown together.\n */\nfunction BlockFields( {\n\tclientId,\n\tblockType,\n\tattributes,\n\tsetAttributes,\n\tisCollapsed = false,\n} ) {\n\tconst blockTitle = useBlockDisplayTitle( {\n\t\tclientId,\n\t\tcontext: 'list-view',\n\t} );\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\n\tconst blockTypeFields = blockType?.[ fieldsKey ];\n\n\tconst computedForm = useMemo( () => {\n\t\tif ( ! isCollapsed ) {\n\t\t\treturn blockType?.[ formKey ];\n\t\t}\n\n\t\t// For a collapsed form only show the first field by default.\n\t\treturn {\n\t\t\t...blockType?.[ formKey ],\n\t\t\tfields: [ blockType?.[ formKey ]?.fields?.[ 0 ] ],\n\t\t};\n\t}, [ blockType, isCollapsed ] );\n\n\tconst [ form, setForm ] = useState( computedForm );\n\n\t// Build DataForm fields with proper structure\n\tconst dataFormFields = useMemo( () => {\n\t\tif ( ! blockTypeFields?.length ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn blockTypeFields.map( ( fieldDef ) => {\n\t\t\tconst field = {\n\t\t\t\tid: fieldDef.id,\n\t\t\t\tlabel: fieldDef.label,\n\t\t\t\ttype: fieldDef.type, // Use the field's type; DataForm will use built-in or custom Edit\n\t\t\t};\n\n\t\t\t// If the field defines a `mapping`, then custom `getValue` and `setValue`\n\t\t\t// implementations are provided.\n\t\t\t// These functions map from the inconsistent attribute keys found on blocks\n\t\t\t// to consistent keys that the field can use internally (and back again).\n\t\t\t// When `mapping` isn't provided, we can use the field API's default\n\t\t\t// implementation of these functions.\n\t\t\tif ( fieldDef.mapping ) {\n\t\t\t\tfield.getValue = ( { item } ) => {\n\t\t\t\t\t// Extract mapped properties from the block attributes\n\t\t\t\t\tconst mappedValue = {};\n\t\t\t\t\tObject.entries( fieldDef.mapping ).forEach(\n\t\t\t\t\t\t( [ key, attrKey ] ) => {\n\t\t\t\t\t\t\tmappedValue[ key ] = item[ attrKey ];\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t\treturn mappedValue;\n\t\t\t\t};\n\t\t\t\tfield.setValue = ( { value } ) => {\n\t\t\t\t\tconst attributeUpdates = {};\n\t\t\t\t\tObject.entries( fieldDef.mapping ).forEach(\n\t\t\t\t\t\t( [ key, attrKey ] ) => {\n\t\t\t\t\t\t\tattributeUpdates[ attrKey ] = value[ key ];\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t\treturn attributeUpdates;\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Only add custom Edit component if one exists for this type\n\t\t\tconst ControlComponent = CONTROLS[ fieldDef.type ];\n\t\t\tif ( ControlComponent ) {\n\t\t\t\t// Use EditConfig pattern: Edit is an object with control type and config props\n\t\t\t\tfield.Edit = createConfiguredControl(\n\t\t\t\t\tControlComponent,\n\t\t\t\t\tfieldDef.type,\n\t\t\t\t\t{\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\tfieldDef,\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn field;\n\t\t} );\n\t}, [ blockTypeFields, clientId ] );\n\n\tif ( ! blockTypeFields?.length ) {\n\t\t// TODO - we might still want to show a placeholder for blocks with no fields.\n\t\t// for example, a way to select the block.\n\t\treturn null;\n\t}\n\n\tconst handleToggleField = ( fieldId ) => {\n\t\tsetForm( ( prev ) => {\n\t\t\tif ( prev.fields?.includes( fieldId ) ) {\n\t\t\t\treturn {\n\t\t\t\t\t...prev,\n\t\t\t\t\tfields: prev.fields.filter( ( id ) => id !== fieldId ),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...prev,\n\t\t\t\tfields: [ ...( prev.fields || [] ), fieldId ],\n\t\t\t};\n\t\t} );\n\t};\n\n\treturn (\n\t\t<div className=\"block-editor-block-fields__container\">\n\t\t\t<div className=\"block-editor-block-fields__header\">\n\t\t\t\t<HStack spacing={ 1 }>\n\t\t\t\t\t{ isCollapsed && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\tclassName=\"block-editor-block-fields__header-icon\"\n\t\t\t\t\t\t\t\ticon={ blockInformation?.icon }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<h2 className=\"block-editor-block-fields__header-title\">\n\t\t\t\t\t\t\t\t<Truncate numberOfLines={ 1 }>\n\t\t\t\t\t\t\t\t\t{ blockTitle }\n\t\t\t\t\t\t\t\t</Truncate>\n\t\t\t\t\t\t\t</h2>\n\t\t\t\t\t\t\t<FieldsDropdownMenu\n\t\t\t\t\t\t\t\tfields={ dataFormFields }\n\t\t\t\t\t\t\t\tvisibleFields={ form.fields }\n\t\t\t\t\t\t\t\tonToggleField={ handleToggleField }\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{ ! isCollapsed && (\n\t\t\t\t\t\t<h2 className=\"block-editor-block-fields__header-title\">\n\t\t\t\t\t\t\t{ __( 'Content' ) }\n\t\t\t\t\t\t</h2>\n\t\t\t\t\t) }\n\t\t\t\t</HStack>\n\t\t\t</div>\n\t\t\t<DataForm\n\t\t\t\tdata={ attributes }\n\t\t\t\tfields={ dataFormFields }\n\t\t\t\tform={ form }\n\t\t\t\tonChange={ setAttributes }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nconst withBlockFields = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst {\n\t\t\tblockType,\n\t\t\tisSelectionWithinCurrentSection,\n\t\t\tisSectionBlock,\n\t\t\tblockEditingMode,\n\t\t\tisSelected,\n\t\t} = useContext( PrivateBlockContext );\n\n\t\tconst shouldShowBlockFields =\n\t\t\twindow?.__experimentalContentOnlyInspectorFields;\n\t\tconst blockTypeFields = blockType?.[ fieldsKey ];\n\n\t\tif ( ! shouldShowBlockFields || ! blockTypeFields?.length ) {\n\t\t\treturn <BlockEdit key=\"edit\" { ...props } />;\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t\t{\n\t\t\t\t\t// Display the controls of all inner blocks for section/pattern editing.\n\t\t\t\t\tisSelectionWithinCurrentSection &&\n\t\t\t\t\t\t( isSectionBlock ||\n\t\t\t\t\t\t\tblockEditingMode === 'contentOnly' ) && (\n\t\t\t\t\t\t\t<PrivateInspectorControlsFill\n\t\t\t\t\t\t\t\tgroup=\"content\"\n\t\t\t\t\t\t\t\tforceDisplayControls\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<BlockFields\n\t\t\t\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\t\t\t\tblockType={ blockType }\n\t\t\t\t\t\t\t\t\tisCollapsed\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</PrivateInspectorControlsFill>\n\t\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\t{ ! isSelectionWithinCurrentSection && isSelected && (\n\t\t\t\t\t<PrivateInspectorControlsFill group=\"content\">\n\t\t\t\t\t\t<BlockFields { ...props } blockType={ blockType } />\n\t\t\t\t\t</PrivateInspectorControlsFill>\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/content-only-controls/block-fields',\n\twithBlockFields\n);\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAGA,mBAA0B;AAC1B,oBAAiD;AACjD,wBAGO;AACP,qBAA2C;AAC3C,uBAAyB;AACzB,qBAA8C;AAC9C,kBAAmB;AAKnB,yBAAuB;AACvB,wBAAsB;AACtB,qCAAiC;AACjC,2CAAuC;AAEvC,kCAA+B;AAC/B,mCAAoC;AACpC,kBAA6C;AAG7C,uBAAqB;AACrB,mBAAkB;AAClB,kBAAiB;AAwBR;AAhCT,IAAM,EAAE,WAAW,QAAQ,QAAI,2BAAQ,cAAAA,WAAkB;AAUzD,IAAM,WAAW;AAAA,EAChB,UAAU,iBAAAC;AAAA,EACV,OAAO,aAAAC;AAAA,EACP,MAAM,YAAAC;AAC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S,eAAgB,GACvB,sBACH,GACD;AAAA,QACA;AAAA,UAAC,4BAAAC;AAAA,UAAA;AAAA,YACA,QAAS;AAAA,YACT,eAAgB,KAAK;AAAA,YACrB,eAAgB;AAAA;AAAA,QACjB;AAAA,SACD;AAAA,MAEC,CAAE,eACH,4CAAC,QAAG,WAAU,2CACX,8BAAI,SAAU,GACjB;AAAA,OAEF,GACD;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,MAAO;AAAA,QACP,QAAS;AAAA,QACT;AAAA,QACA,UAAW;AAAA;AAAA,IACZ;AAAA,KACD;AAEF;AAEA,IAAM,sBAAkB;AAAA,EACvB,CAAE,cAAe,CAAE,UAAW;AAC7B,UAAM;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD,QAAI,2BAAY,gDAAoB;AAEpC,UAAM,wBACL,QAAQ;AACT,UAAM,kBAAkB,YAAa,SAAU;AAE/C,QAAK,CAAE,yBAAyB,CAAE,iBAAiB,QAAS;AAC3D,aAAO,4CAAC,aAAuB,GAAG,SAAZ,MAAoB;AAAA,IAC3C;AAEA,WACC,4EACC;AAAA,kDAAC,aAAuB,GAAG,SAAZ,MAAoB;AAAA;AAAA,MAGlC,oCACG,kBACD,qBAAqB,kBACrB;AAAA,QAAC;AAAA;AAAA,UACA,OAAM;AAAA,UACN,sBAAoB;AAAA,UAEpB;AAAA,YAAC;AAAA;AAAA,cACE,GAAG;AAAA,cACL;AAAA,cACA,aAAW;AAAA;AAAA,UACZ;AAAA;AAAA,MACD;AAAA,MAGD,CAAE,mCAAmC,cACtC,4CAAC,4CAA6B,OAAM,WACnC,sDAAC,eAAc,GAAG,OAAQ,WAAwB,GACnD;AAAA,OAEF;AAAA,EAEF;AACD;AAAA,IAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;",
6
- "names": ["blocksPrivateApis", "RichText", "Media", "Link", "useBlockDisplayTitle", "useBlockDisplayInformation", "HStack", "BlockIcon", "Truncate", "FieldsDropdownMenu"]
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as blocksPrivateApis,\n\tgetBlockType,\n} from '@wordpress/blocks';\nimport {\n\t__experimentalHStack as HStack,\n\t__experimentalTruncate as Truncate,\n} from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { DataForm } from '@wordpress/dataviews';\nimport { useContext, useState, useMemo } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\nimport BlockIcon from '../../components/block-icon';\nimport useBlockDisplayTitle from '../../components/block-title/use-block-display-title';\nimport useBlockDisplayInformation from '../../components/use-block-display-information';\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\nimport FieldsDropdownMenu from './fields-dropdown-menu';\nimport { PrivateBlockContext } from '../../components/block-list/private-block-context';\nimport InspectorControls from '../../components/inspector-controls/fill';\n\n// controls\nimport RichText from './rich-text';\nimport Media from './media';\nimport Link from './link';\n\n/**\n * Creates a configured control component that wraps a custom control\n * and passes configuration as props.\n *\n * @param {Component} ControlComponent The React component for the control.\n * @param {Object} config The control configuration passed as a prop.\n *\n * @return {Function} A wrapped control component\n */\nfunction createConfiguredControl( ControlComponent, config = {} ) {\n\treturn function ConfiguredControl( props ) {\n\t\treturn <ControlComponent { ...props } config={ config } />;\n\t};\n}\n\n/**\n * Component that renders a DataForm for a single block's attributes\n * @param {Object} props\n * @param {string} props.clientId The clientId of the block.\n * @param {Object} props.blockType The blockType definition.\n * @param {Function} props.setAttributes Action to set the block's attributes.\n * @param {boolean} props.isCollapsed Whether the DataForm is rendered as 'collapsed' with only the first field\n * displayed by default. When collapsed a dropdown is displayed to allow\n * displaying additional fields. The block's title is displayed as the title.\n * The collapsed mode is often used when multiple BlockForms are shown together.\n */\nfunction BlockFields( {\n\tclientId,\n\tblockType,\n\tsetAttributes,\n\tisCollapsed = false,\n} ) {\n\tconst blockTitle = useBlockDisplayTitle( {\n\t\tclientId,\n\t\tcontext: 'list-view',\n\t} );\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\n\tconst blockTypeFields = blockType?.[ fieldsKey ];\n\n\tconst attributes = useSelect(\n\t\t( select ) => select( blockEditorStore ).getBlockAttributes( clientId ),\n\t\t[ clientId ]\n\t);\n\n\tconst computedForm = useMemo( () => {\n\t\tif ( ! isCollapsed ) {\n\t\t\treturn blockType?.[ formKey ];\n\t\t}\n\n\t\t// For a collapsed form only show the first field by default.\n\t\treturn {\n\t\t\t...blockType?.[ formKey ],\n\t\t\tfields: [ blockType?.[ formKey ]?.fields?.[ 0 ] ],\n\t\t};\n\t}, [ blockType, isCollapsed ] );\n\n\tconst [ form, setForm ] = useState( computedForm );\n\n\t// Build DataForm fields with proper structure\n\tconst dataFormFields = useMemo( () => {\n\t\tif ( ! blockTypeFields?.length ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn blockTypeFields.map( ( fieldDef ) => {\n\t\t\tconst field = {\n\t\t\t\t...fieldDef,\n\t\t\t};\n\n\t\t\t// These should be custom Edit components, not replaced here.\n\t\t\t//\n\t\t\t// - rich-text control: it needs clientId\n\t\t\t// - link control: does not need anything extra\n\t\t\t// - media control: needs the Edit config\n\t\t\tif (\n\t\t\t\t'string' === typeof fieldDef.Edit &&\n\t\t\t\tfieldDef.Edit === 'rich-text'\n\t\t\t) {\n\t\t\t\tfield.Edit = createConfiguredControl( RichText, {\n\t\t\t\t\tclientId,\n\t\t\t\t} );\n\t\t\t} else if (\n\t\t\t\t'string' === typeof fieldDef.Edit &&\n\t\t\t\tfieldDef.Edit === 'link'\n\t\t\t) {\n\t\t\t\tfield.Edit = createConfiguredControl( Link );\n\t\t\t} else if (\n\t\t\t\t'object' === typeof fieldDef.Edit &&\n\t\t\t\tfieldDef.Edit.control === 'media'\n\t\t\t) {\n\t\t\t\tfield.Edit = createConfiguredControl( Media, {\n\t\t\t\t\t...fieldDef.Edit,\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\treturn field;\n\t\t} );\n\t}, [ blockTypeFields, clientId ] );\n\n\tif ( ! blockTypeFields?.length ) {\n\t\t// TODO - we might still want to show a placeholder for blocks with no fields.\n\t\t// for example, a way to select the block.\n\t\treturn null;\n\t}\n\n\tconst handleToggleField = ( fieldId ) => {\n\t\tsetForm( ( prev ) => {\n\t\t\tif ( prev.fields?.includes( fieldId ) ) {\n\t\t\t\treturn {\n\t\t\t\t\t...prev,\n\t\t\t\t\tfields: prev.fields.filter( ( id ) => id !== fieldId ),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...prev,\n\t\t\t\tfields: [ ...( prev.fields || [] ), fieldId ],\n\t\t\t};\n\t\t} );\n\t};\n\n\treturn (\n\t\t<div className=\"block-editor-block-fields__container\">\n\t\t\t<div className=\"block-editor-block-fields__header\">\n\t\t\t\t<HStack spacing={ 1 }>\n\t\t\t\t\t{ isCollapsed && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\tclassName=\"block-editor-block-fields__header-icon\"\n\t\t\t\t\t\t\t\ticon={ blockInformation?.icon }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<h2 className=\"block-editor-block-fields__header-title\">\n\t\t\t\t\t\t\t\t<Truncate numberOfLines={ 1 }>\n\t\t\t\t\t\t\t\t\t{ blockTitle }\n\t\t\t\t\t\t\t\t</Truncate>\n\t\t\t\t\t\t\t</h2>\n\t\t\t\t\t\t\t<FieldsDropdownMenu\n\t\t\t\t\t\t\t\tfields={ dataFormFields }\n\t\t\t\t\t\t\t\tvisibleFields={ form.fields }\n\t\t\t\t\t\t\t\tonToggleField={ handleToggleField }\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{ ! isCollapsed && (\n\t\t\t\t\t\t<h2 className=\"block-editor-block-fields__header-title\">\n\t\t\t\t\t\t\t{ __( 'Content' ) }\n\t\t\t\t\t\t</h2>\n\t\t\t\t\t) }\n\t\t\t\t</HStack>\n\t\t\t</div>\n\t\t\t<DataForm\n\t\t\t\tdata={ attributes }\n\t\t\t\tfields={ dataFormFields }\n\t\t\t\tform={ form }\n\t\t\t\tonChange={ setAttributes }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nfunction hasBlockFieldsSupport( blockName ) {\n\treturn !! (\n\t\twindow?.__experimentalContentOnlyInspectorFields &&\n\t\tgetBlockType( blockName )?.[ fieldsKey ]\n\t);\n}\n\nexport function BlockFieldsPanel( props ) {\n\tconst { blockType, isSelectionWithinCurrentSection } =\n\t\tuseContext( PrivateBlockContext );\n\n\treturn (\n\t\t<InspectorControls group=\"content\">\n\t\t\t<BlockFields\n\t\t\t\t{ ...props }\n\t\t\t\tblockType={ blockType }\n\t\t\t\tisCollapsed={ isSelectionWithinCurrentSection }\n\t\t\t/>\n\t\t</InspectorControls>\n\t);\n}\n\n/**\n * Export block support definition.\n */\nexport default {\n\tedit: BlockFieldsPanel,\n\thasSupport: hasBlockFieldsSupport,\n\tattributeKeys: [],\n\tsupportsPatternEditing: true,\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAGO;AACP,wBAGO;AACP,kBAA0B;AAC1B,uBAAyB;AACzB,qBAA8C;AAC9C,kBAAmB;AAKnB,mBAA0C;AAC1C,yBAAuB;AACvB,wBAAsB;AACtB,qCAAiC;AACjC,2CAAuC;AAEvC,kCAA+B;AAC/B,mCAAoC;AACpC,kBAA8B;AAG9B,uBAAqB;AACrB,mBAAkB;AAClB,kBAAiB;AAaR;AArBT,IAAM,EAAE,WAAW,QAAQ,QAAI,2BAAQ,cAAAA,WAAkB;AAmBzD,SAAS,wBAAyB,kBAAkB,SAAS,CAAC,GAAI;AACjE,SAAO,SAAS,kBAAmB,OAAQ;AAC1C,WAAO,4CAAC,oBAAmB,GAAG,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U,IAAK,SAAU;AAEzC;AAEO,SAAS,iBAAkB,OAAQ;AACzC,QAAM,EAAE,WAAW,gCAAgC,QAClD,2BAAY,gDAAoB;AAEjC,SACC,4CAAC,YAAAC,SAAA,EAAkB,OAAM,WACxB;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACL;AAAA,MACA,aAAc;AAAA;AAAA,EACf,GACD;AAEF;AAKA,IAAO,uBAAQ;AAAA,EACd,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,eAAe,CAAC;AAAA,EAChB,wBAAwB;AACzB;",
6
+ "names": ["blocksPrivateApis", "useBlockDisplayTitle", "useBlockDisplayInformation", "blockEditorStore", "RichText", "Link", "Media", "HStack", "BlockIcon", "Truncate", "FieldsDropdownMenu", "InspectorControls"]
7
7
  }
@@ -75,12 +75,11 @@ function getUpdatedLinkAttributes({
75
75
  rel: updatedRel || void 0
76
76
  };
77
77
  }
78
- function Link({ data, field, onChange, config = {} }) {
78
+ function Link({ data, field, onChange }) {
79
79
  const [isLinkControlOpen, setIsLinkControlOpen] = (0, import_element.useState)(false);
80
80
  const { popoverProps } = (0, import_use_inspector_popover_placement.useInspectorPopoverPlacement)({
81
81
  isControl: true
82
82
  });
83
- const { fieldDef } = config;
84
83
  const value = field.getValue({ item: data });
85
84
  const url = value?.url;
86
85
  const rel = value?.rel || "";
@@ -152,18 +151,10 @@ function Link({ data, field, onChange, config = {} }) {
152
151
  );
153
152
  },
154
153
  onRemove: () => {
155
- const removeValue = {};
156
- if (fieldDef?.mapping) {
157
- Object.keys(fieldDef.mapping).forEach(
158
- (key) => {
159
- removeValue[key] = void 0;
160
- }
161
- );
162
- }
163
154
  onChange(
164
155
  field.setValue({
165
156
  item: data,
166
- value: removeValue
157
+ value: {}
167
158
  })
168
159
  );
169
160
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/hooks/block-fields/link/index.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tIcon,\n\t__experimentalGrid as Grid,\n\tPopover,\n} from '@wordpress/components';\nimport { useMemo, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { link } from '@wordpress/icons';\nimport { prependHTTP } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport LinkControl from '../../../components/link-control';\nimport { useInspectorPopoverPlacement } from '../use-inspector-popover-placement';\n\nexport const NEW_TAB_REL = 'noreferrer noopener';\nexport const NEW_TAB_TARGET = '_blank';\nexport const NOFOLLOW_REL = 'nofollow';\n\n/**\n * Updates the link attributes.\n *\n * @param {Object} attributes The current block attributes.\n * @param {string} attributes.rel The current link rel attribute.\n * @param {string} attributes.url The current link url.\n * @param {boolean} attributes.opensInNewTab Whether the link should open in a new window.\n * @param {boolean} attributes.nofollow Whether the link should be marked as nofollow.\n */\nexport function getUpdatedLinkAttributes( {\n\trel = '',\n\turl = '',\n\topensInNewTab,\n\tnofollow,\n} ) {\n\tlet newLinkTarget;\n\t// Since `rel` is editable attribute, we need to check for existing values and proceed accordingly.\n\tlet updatedRel = rel;\n\n\tif ( opensInNewTab ) {\n\t\tnewLinkTarget = NEW_TAB_TARGET;\n\t\tupdatedRel = updatedRel?.includes( NEW_TAB_REL )\n\t\t\t? updatedRel\n\t\t\t: updatedRel + ` ${ NEW_TAB_REL }`;\n\t} else {\n\t\tconst relRegex = new RegExp( `\\\\b${ NEW_TAB_REL }\\\\s*`, 'g' );\n\t\tupdatedRel = updatedRel?.replace( relRegex, '' ).trim();\n\t}\n\n\tif ( nofollow ) {\n\t\tupdatedRel = updatedRel?.includes( NOFOLLOW_REL )\n\t\t\t? updatedRel\n\t\t\t: ( updatedRel + ` ${ NOFOLLOW_REL }` ).trim();\n\t} else {\n\t\tconst relRegex = new RegExp( `\\\\b${ NOFOLLOW_REL }\\\\s*`, 'g' );\n\t\tupdatedRel = updatedRel?.replace( relRegex, '' ).trim();\n\t}\n\n\treturn {\n\t\turl: prependHTTP( url ),\n\t\tlinkTarget: newLinkTarget,\n\t\trel: updatedRel || undefined,\n\t};\n}\n\nexport default function Link( { data, field, onChange, config = {} } ) {\n\tconst [ isLinkControlOpen, setIsLinkControlOpen ] = useState( false );\n\tconst { popoverProps } = useInspectorPopoverPlacement( {\n\t\tisControl: true,\n\t} );\n\tconst { fieldDef } = config;\n\tconst value = field.getValue( { item: data } );\n\tconst url = value?.url;\n\tconst rel = value?.rel || '';\n\tconst target = value?.linkTarget;\n\n\tconst opensInNewTab = target === NEW_TAB_TARGET;\n\tconst nofollow = rel === NOFOLLOW_REL;\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/51256.\n\tconst linkValue = useMemo(\n\t\t() => ( { url, opensInNewTab, nofollow } ),\n\t\t[ url, opensInNewTab, nofollow ]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tclassName=\"block-editor-content-only-controls__link\"\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tsetIsLinkControlOpen( true );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<Grid\n\t\t\t\t\trowGap={ 0 }\n\t\t\t\t\tcolumnGap={ 8 }\n\t\t\t\t\ttemplateColumns=\"24px 1fr\"\n\t\t\t\t\tclassName=\"block-editor-content-only-controls__link-row\"\n\t\t\t\t>\n\t\t\t\t\t{ url && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<Icon icon={ link } size={ 24 } />\n\t\t\t\t\t\t\t<span className=\"block-editor-content-only-controls__link-title\">\n\t\t\t\t\t\t\t\t{ url }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t\t{ ! url && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\ticon={ link }\n\t\t\t\t\t\t\t\tsize={ 24 }\n\t\t\t\t\t\t\t\tstyle={ { opacity: 0.3 } }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<span className=\"block-editor-content-only-controls__link-title\">\n\t\t\t\t\t\t\t\t{ __( 'Link' ) }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</Grid>\n\t\t\t</Button>\n\t\t\t{ isLinkControlOpen && (\n\t\t\t\t<Popover\n\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\tsetIsLinkControlOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\t{ ...( popoverProps ?? {} ) }\n\t\t\t\t>\n\t\t\t\t\t<LinkControl\n\t\t\t\t\t\tvalue={ linkValue }\n\t\t\t\t\t\tonChange={ ( newValues ) => {\n\t\t\t\t\t\t\tconst updatedAttrs = getUpdatedLinkAttributes( {\n\t\t\t\t\t\t\t\trel,\n\t\t\t\t\t\t\t\t...newValues,\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\tonChange(\n\t\t\t\t\t\t\t\tfield.setValue( {\n\t\t\t\t\t\t\t\t\titem: data,\n\t\t\t\t\t\t\t\t\tvalue: updatedAttrs,\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\tonRemove={ () => {\n\t\t\t\t\t\t\t// Remove all link-related properties based on what's in the mapping\n\t\t\t\t\t\t\tconst removeValue = {};\n\n\t\t\t\t\t\t\tif ( fieldDef?.mapping ) {\n\t\t\t\t\t\t\t\tObject.keys( fieldDef.mapping ).forEach(\n\t\t\t\t\t\t\t\t\t( key ) => {\n\t\t\t\t\t\t\t\t\t\tremoveValue[ key ] = undefined;\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\n\t\t\t\t\t\t\tonChange(\n\t\t\t\t\t\t\t\tfield.setValue( {\n\t\t\t\t\t\t\t\t\titem: data,\n\t\t\t\t\t\t\t\t\tvalue: removeValue,\n\t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M,eAAe,yBAA0B;AAAA,gBAC9C;AAAA,gBACA,GAAG;AAAA,cACJ,CAAE;AAEF;AAAA,gBACC,MAAM,SAAU;AAAA,kBACf,MAAM;AAAA,kBACN,OAAO;AAAA,gBACR,CAAE;AAAA,cACH;AAAA,YACD;AAAA,YACA,UAAW,MAAM;AAEhB,oBAAM,cAAc,CAAC;AAErB,kBAAK,UAAU,SAAU;AACxB,uBAAO,KAAM,SAAS,OAAQ,EAAE;AAAA,kBAC/B,CAAE,QAAS;AACV,gCAAa,GAAI,IAAI;AAAA,kBACtB;AAAA,gBACD;AAAA,cACD;AAEA;AAAA,gBACC,MAAM,SAAU;AAAA,kBACf,MAAM;AAAA,kBACN,OAAO;AAAA,gBACR,CAAE;AAAA,cACH;AAAA,YACD;AAAA;AAAA,QACD;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tIcon,\n\t__experimentalGrid as Grid,\n\tPopover,\n} from '@wordpress/components';\nimport { useMemo, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { link } from '@wordpress/icons';\nimport { prependHTTP } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport LinkControl from '../../../components/link-control';\nimport { useInspectorPopoverPlacement } from '../use-inspector-popover-placement';\n\nexport const NEW_TAB_REL = 'noreferrer noopener';\nexport const NEW_TAB_TARGET = '_blank';\nexport const NOFOLLOW_REL = 'nofollow';\n\n/**\n * Updates the link attributes.\n *\n * @param {Object} attributes The current block attributes.\n * @param {string} attributes.rel The current link rel attribute.\n * @param {string} attributes.url The current link url.\n * @param {boolean} attributes.opensInNewTab Whether the link should open in a new window.\n * @param {boolean} attributes.nofollow Whether the link should be marked as nofollow.\n */\nexport function getUpdatedLinkAttributes( {\n\trel = '',\n\turl = '',\n\topensInNewTab,\n\tnofollow,\n} ) {\n\tlet newLinkTarget;\n\t// Since `rel` is editable attribute, we need to check for existing values and proceed accordingly.\n\tlet updatedRel = rel;\n\n\tif ( opensInNewTab ) {\n\t\tnewLinkTarget = NEW_TAB_TARGET;\n\t\tupdatedRel = updatedRel?.includes( NEW_TAB_REL )\n\t\t\t? updatedRel\n\t\t\t: updatedRel + ` ${ NEW_TAB_REL }`;\n\t} else {\n\t\tconst relRegex = new RegExp( `\\\\b${ NEW_TAB_REL }\\\\s*`, 'g' );\n\t\tupdatedRel = updatedRel?.replace( relRegex, '' ).trim();\n\t}\n\n\tif ( nofollow ) {\n\t\tupdatedRel = updatedRel?.includes( NOFOLLOW_REL )\n\t\t\t? updatedRel\n\t\t\t: ( updatedRel + ` ${ NOFOLLOW_REL }` ).trim();\n\t} else {\n\t\tconst relRegex = new RegExp( `\\\\b${ NOFOLLOW_REL }\\\\s*`, 'g' );\n\t\tupdatedRel = updatedRel?.replace( relRegex, '' ).trim();\n\t}\n\n\treturn {\n\t\turl: prependHTTP( url ),\n\t\tlinkTarget: newLinkTarget,\n\t\trel: updatedRel || undefined,\n\t};\n}\n\nexport default function Link( { data, field, onChange } ) {\n\tconst [ isLinkControlOpen, setIsLinkControlOpen ] = useState( false );\n\tconst { popoverProps } = useInspectorPopoverPlacement( {\n\t\tisControl: true,\n\t} );\n\tconst value = field.getValue( { item: data } );\n\tconst url = value?.url;\n\tconst rel = value?.rel || '';\n\tconst target = value?.linkTarget;\n\n\tconst opensInNewTab = target === NEW_TAB_TARGET;\n\tconst nofollow = rel === NOFOLLOW_REL;\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/51256.\n\tconst linkValue = useMemo(\n\t\t() => ( { url, opensInNewTab, nofollow } ),\n\t\t[ url, opensInNewTab, nofollow ]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tclassName=\"block-editor-content-only-controls__link\"\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tsetIsLinkControlOpen( true );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<Grid\n\t\t\t\t\trowGap={ 0 }\n\t\t\t\t\tcolumnGap={ 8 }\n\t\t\t\t\ttemplateColumns=\"24px 1fr\"\n\t\t\t\t\tclassName=\"block-editor-content-only-controls__link-row\"\n\t\t\t\t>\n\t\t\t\t\t{ url && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<Icon icon={ link } size={ 24 } />\n\t\t\t\t\t\t\t<span className=\"block-editor-content-only-controls__link-title\">\n\t\t\t\t\t\t\t\t{ url }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t\t{ ! url && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\ticon={ link }\n\t\t\t\t\t\t\t\tsize={ 24 }\n\t\t\t\t\t\t\t\tstyle={ { opacity: 0.3 } }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<span className=\"block-editor-content-only-controls__link-title\">\n\t\t\t\t\t\t\t\t{ __( 'Link' ) }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</Grid>\n\t\t\t</Button>\n\t\t\t{ isLinkControlOpen && (\n\t\t\t\t<Popover\n\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\tsetIsLinkControlOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\t{ ...( popoverProps ?? {} ) }\n\t\t\t\t>\n\t\t\t\t\t<LinkControl\n\t\t\t\t\t\tvalue={ linkValue }\n\t\t\t\t\t\tonChange={ ( newValues ) => {\n\t\t\t\t\t\t\tconst updatedAttrs = getUpdatedLinkAttributes( {\n\t\t\t\t\t\t\t\trel,\n\t\t\t\t\t\t\t\t...newValues,\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\tonChange(\n\t\t\t\t\t\t\t\tfield.setValue( {\n\t\t\t\t\t\t\t\t\titem: data,\n\t\t\t\t\t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AA,QACA,SAAU,MAAM;AACf,+BAAsB,KAAM;AAAA,QAC7B;AAAA,QACE,GAAK,gBAAgB,CAAC;AAAA,QAExB;AAAA,UAAC,oBAAAC;AAAA,UAAA;AAAA,YACA,OAAQ;AAAA,YACR,UAAW,CAAE,cAAe;AAC3B,oBAAM,eAAe,yBAA0B;AAAA,gBAC9C;AAAA,gBACA,GAAG;AAAA,cACJ,CAAE;AAEF;AAAA,gBACC,MAAM,SAAU;AAAA,kBACf,MAAM;AAAA,kBACN,OAAO;AAAA,gBACR,CAAE;AAAA,cACH;AAAA,YACD;AAAA,YACA,UAAW,MAAM;AAChB;AAAA,gBACC,MAAM,SAAU;AAAA,kBACf,MAAM;AAAA,kBACN,OAAO,CAAC;AAAA,gBACT,CAAE;AAAA,cACH;AAAA,YACD;AAAA;AAAA,QACD;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;",
6
6
  "names": ["Grid", "LinkControl"]
7
7
  }
@@ -44,8 +44,7 @@ var import_private_keys = require("../../../store/private-keys.cjs");
44
44
  var import_store = require("../../../store/index.cjs");
45
45
  var import_jsx_runtime = require("react/jsx-runtime");
46
46
  function MediaThumbnail({ data, field, attachment, config }) {
47
- const { fieldDef } = config;
48
- const { allowedTypes = [], multiple = false } = fieldDef.args || {};
47
+ const { allowedTypes = [], multiple = false } = config || {};
49
48
  if (multiple) {
50
49
  return "todo multiple";
51
50
  }
@@ -87,9 +86,11 @@ function Media({ data, field, onChange, config = {} }) {
87
86
  isControl: true
88
87
  });
89
88
  const value = field.getValue({ item: data });
90
- const { fieldDef } = config;
91
- const { allowedTypes = [], multiple = false } = fieldDef.args || {};
92
- const hasFeaturedImageSupport = fieldDef?.mapping && "featuredImage" in fieldDef.mapping;
89
+ const {
90
+ allowedTypes = [],
91
+ multiple = false,
92
+ useFeaturedImage = false
93
+ } = config;
93
94
  const id = value?.id;
94
95
  const url = value?.url;
95
96
  const attachment = (0, import_data.useSelect)(
@@ -131,20 +132,14 @@ function Media({ data, field, onChange, config = {} }) {
131
132
  multiple,
132
133
  popoverProps,
133
134
  onReset: () => {
134
- const resetValue = {};
135
- if (fieldDef?.mapping) {
136
- Object.keys(fieldDef.mapping).forEach((key) => {
137
- resetValue[key] = void 0;
138
- });
139
- }
140
135
  onChange(
141
136
  field.setValue({
142
137
  item: data,
143
- value: resetValue
138
+ value: {}
144
139
  })
145
140
  );
146
141
  },
147
- ...hasFeaturedImageSupport && {
142
+ ...useFeaturedImage && {
148
143
  useFeaturedImage: !!value?.featuredImage,
149
144
  onToggleFeaturedImage: () => {
150
145
  onChange(
@@ -163,7 +158,7 @@ function Media({ data, field, onChange, config = {} }) {
163
158
  ...selectedMedia,
164
159
  mediaType: selectedMedia.media_type
165
160
  };
166
- if (hasFeaturedImageSupport) {
161
+ if (useFeaturedImage) {
167
162
  newValue.featuredImage = false;
168
163
  }
169
164
  onChange(