• Settings
    • Locale
    • Change the locale of the datepicker, schedule and client side validation messages.

      Language
      English
      English
      English
      French
      German
      German
      German
      Italian
      Korean
      Spanish
      Catalan
      Dutch
      Portuguese
      Portuguese
      Arabic
      Arabic
      Bulgarian
      Bangla
      Bosnian
      Czech
      Greek
      Estonian
      Persian
      Finnish
      Danish
      Hindi
      Indonesian
      Icelandic
      Croatian
      Japanese
      Hungarian
      Hebrew
      Georgian
      Central Kurdish
      Khmer
      Kyrgyz
      Kazakh
      Lithuanian
      Latvian
      Malay
      Norwegian
      Polish
      Romanian
      Russian
      Slovak
      Slovenian
      Serbian
      Serbian
      Swedish
      Thai
      Turkish
      Ukrainian
      Uzbek
      Vietnamese
      Chinese
      Chinese
  • Resources

MonacoEditor Diff Extender

The extender attribute of the diff editor works like the one of the code editor, see its documentation for the extender object.

MonacoDiffEditor Tag Documentation

Inline Monaco diff editor.

NameTypeRequiredDefaultDescription
id String false generated Unique identifier of the component in a namingContainer.
rendered Boolean false generated Unique identifier of the component in a namingContainer.
binding UIComponent false generated An EL expression referring to a server side UIComponent instance in a backing bean.
extender String false Extender script: JavaScript expression that evaluates to an extender instance.
overflowWidgetsDomNode String false Search expression for overflow widgets DOM node.

MonacoDiffEditorFramed Tag Documentation

Framed Monaco diff editor (iframe).

NameTypeRequiredDefaultDescription
id String false generated Unique identifier of the component in a namingContainer.
rendered Boolean false generated Unique identifier of the component in a namingContainer.
binding UIComponent false generated An EL expression referring to a server side UIComponent instance in a backing bean.
extender String false URL to an extender script loaded into the iframe.
iframeUrlParams Object false Additional URL params added to the iframe URL.

MonacoEditorFramed Tag Documentation

Framed Monaco code editor (iframe).

NameTypeRequiredDefaultDescription
id String false generated Unique identifier of the component in a namingContainer.
rendered Boolean false generated Unique identifier of the component in a namingContainer.
binding UIComponent false generated An EL expression referring to a server side UIComponent instance in a backing bean.
extender String false URL to an extender script loaded into the iframe.
iframeUrlParams Object false Additional URL params added to the iframe URL. Either a Map<String, String> or a String with a JavaScript expression that evaluates to an object representing such a map.
Tag Documentation Widget Source Basic Localization Events Theme Extender Diff Diff Localization Diff Events Diff Theme Diff Extender
Extender (diff editor)

Set the extender attribute to run custom JavaScript with callbacks for the lifecycle of the Monaco editor, e.g. to change the options before the editor is created or to add TypeScript declaration files. The inline editor takes a JavaScript expression that evaluates to the extender object; the framed editor takes the URL of a JavaScript file that writes the extender to window.MonacoEnvironment.Extender and runs in the iframe, without access to jQuery or PrimeFaces. The default example loads the jQuery declaration files for autocomplete. Pick an example, edit the extender or the CSS and press Run.

Additional type declarations (JQuery)This example illustrates how you can add custom type declaration files to the editor. It loads the type declarations files for JQuery -- try hovering over the JQuery functions in the editor to the right or try typing some code to see the autocomplete feature in action.

To do so, you should add the beforeCreate to your extender object. Use the third parameter wasLibLoaded to check whether the Monaco editor library was reloaded -- if not, there's no need to add declarations files again.

Then you can add the required type declaration files via monaco.typescript.javascriptDefaults.addExtraLib (if you are editing a JavaScript file) or monaco.typescript.typescriptDefaults.addExtraLib (if you are editing a TypeScript file). See the Monaco editor API DOC for more info on that function.

Finally, you may wonder from where you should load the declaration files. You could add the declaration inline into the extender script, which may be a viable option for small declaration files. For larger files, it is recommended you load the declaration file from a network resource. Note that the beforeCreate hook of the extender may return a Promise. If it does, the Monaco editor widget will wait until that Promise resolves and only create the editor once it does.

See also https://github.com/DefinitelyTyped/DefinitelyTyped, the repository for high quality TypeScript type definitions for many popular JavaScript libraries.
Run
Link to this extender example

Usage


<style>
    .monacoEditorBox {
        border: 1px solid var(--p-content-border-color);
        min-width: 0;
    }
    .monacoExtenderBox {
        border: 1px solid var(--p-primary-color);
        min-width: 0;
    }
    .monacoEditorError {
        border: 1px solid var(--p-red-500, #cc3333);
        height: 500px;
        overflow: auto;
    }
    .monacoEditorError pre {
        word-break: break-all;
        white-space: break-spaces;
    }
    .monacoEditorMessage.p-message {
        width: 100%;
        padding: 1em;
        margin: 1em;
    }
</style>
<h:outputScript library="js" name="monacoColorScheme.js"/>

<div class="card">
    <h5>Extender (diff editor)</h5>
    <p>
        Set the <code>extender</code> attribute to run custom JavaScript with callbacks for the lifecycle of the Monaco editor, e.g. to change the options before the editor is created or to add TypeScript declaration files. The inline editor takes a JavaScript expression that evaluates to the extender object; the framed editor takes the URL of a JavaScript file that writes the extender to <code>window.MonacoEnvironment.Extender</code> and runs in the iframe, without access to jQuery or PrimeFaces. The default example loads the jQuery declaration files for autocomplete. Pick an example, edit the extender or the CSS and press <i>Run</i>.
    </p>
    <h:form id="formExtenderDiff">


        <p:staticMessage id="extenderInfo" severity="info" styleClass="monacoEditorMessage" escape="false"
          summary="#{monacoEditorController.extenderName}" detail="#{monacoEditorController.extenderInfo}" />

        <h:panelGrid columns="4">
          <!-- Apply the selected extender -->
          <p:commandLink id="applyExtender" partialSubmit="true" styleClass="p-button p-button-text-icon-right"
            actionListener="#{monacoEditorController.onMonacoExtenderRun}"
            process="@this,extenderTabs:monacoExtender,extenderTabs:monacoCss,monacoEditorWrapper" update="customExtenderInline,monacoEditorWrapper">
            <span class="p-button-icon-right p-c pi pi-play" style="color:white"></span>
            <span class="p-button-text p-c" style="color:white">Run</span>
          </p:commandLink>

          <!-- Select extender example -->
          <p:outputLabel for="extenderExample" value="Extender example: " />
          <p:selectOneMenu id="extenderExample" value="#{monacoEditorController.extenderExample}">
              <f:selectItems value="#{monacoEditorController.extenderExamplesDiff}" />
              <p:ajax
                process="extenderInfo,extenderTabs:monacoExtender,extenderTabs:monacoCss,monacoEditorWrapper"
                listener="#{monacoEditorController.onExtenderExampleChange}"
                update="customExtenderInline,extenderInfo,extenderLink,extenderTabs:monacoExtender,extenderTabs:monacoCss,monacoEditorWrapper" />
          </p:selectOneMenu>

          <p:link id="extenderLink" href="?example=#{monacoEditorController.extenderExample}"
            target="_blank"
            value="Link to this extender example"/>
        </h:panelGrid>

        <div style="display:flex">
          <!-- Monaco editor for editing the extender -->
          <p:tabView id="extenderTabs" style="flex:1">
              <p:tab id="extenderCode" title="Extender">
                  <h:panelGroup id="monacoExtenderWrapper" layout="block" styleClass="monacoExtenderBox">
                      <pe:monacoEditorFramed id="monacoExtender" widgetVar="monacoExtender"
                          oninitialized="monacoFollowScheme.call(this)"
                          value="#{monacoEditorController.valueExtender}" scheme="file"
                          extender="#{resource['js/monacoExtender.js']}"
                          iframeUrlParams="{extender: 'monaco', language: 'javascript', tsCheck: true, moreDeclarationUrls: ['#{of:escapeJS(resource['primefaces-extensions:monacoeditor/primefaces-monaco-global.d.ts'])}', '#{of:escapeJS(resource['primefaces-extensions:monacoeditor/primefaces-monaco-module.d.ts'])}'], moreDeclarationNames: ['file:///src/primefaces-monaco-global.d.ts', 'file:///src/primefaces-monaco-module.d.ts']}"
                          language="#{monacoEditorController.languageExtender}"
                          editorOptions="#{monacoEditorController.editorOptionsExtender}"
                          width="100%" height="500px" autoResize="true"/>
                  </h:panelGroup>
              </p:tab>
              <p:tab id="customCss" title="Custom CSS">
                  <h:panelGroup id="monacoCssWrapper" layout="block" styleClass="monacoExtenderBox">
                      <pe:monacoEditorFramed id="monacoCss" widgetVar="monacoCss"
                          oninitialized="monacoFollowScheme.call(this)"
                          value="#{monacoEditorController.valueCss}" scheme="file"
                          extender="#{resource['js/monacoExtender.js']}"
                          iframeUrlParams="{extender: 'default'}"
                          language="css"
                          editorOptions="#{monacoEditorController.editorOptionsCss}"
                          width="100%" height="500px" autoResize="true"/>
                  </h:panelGroup>
              </p:tab>
          </p:tabView>

          <!-- Actual editor with the extender applied -->
          <!-- window.createShowcaseExtender wraps the createExtender function -->
          <!-- defined in the editor above to catch and display errors. -->
          <h:panelGroup id="monacoEditorWrapper" layout="block" style="flex:1" styleClass="monacoEditorBox">
              <pe:monacoDiffEditor id="monacoEditor" widgetVar="monacoEditor"
                  oninitialized="monacoFollowScheme.call(this)"
                  rendered="#{empty monacoEditorController.extenderError}"
                  value="#{monacoEditorController.valueDiff}"
                  extender="window.createShowcaseExtender()"
                  language="#{monacoEditorController.language}"
                  editorOptions="#{monacoEditorController.editorOptionsDiff}"
                  width="100%" height="500px" autoResize="true" />
              <h:panelGroup layout="block"
                rendered="#{not empty monacoEditorController.extenderError}" styleClass="monacoEditorError">
                <strong>Could not load custom Monaco editor extender, error was:</strong>
                <pre>#{monacoEditorController.extenderError}</pre>
              </h:panelGroup>
          </h:panelGroup>
        </div>
    </h:form>
</div>