|
| 1 | +import { service } from '@ember/service'; |
| 2 | +import Component from '@glimmer/component'; |
| 3 | +import join from 'ember-composable-helpers/helpers/join'; |
| 4 | +import mapBy from 'ember-composable-helpers/helpers/map-by'; |
| 5 | +import svgJar from 'ember-svg-jar/helpers/svg-jar'; |
| 6 | +import { LinkTo } from '@ember/routing'; |
| 7 | +import { array, concat } from '@ember/helper'; |
| 8 | +import githubLink from 'ember-api-docs/helpers/github-link'; |
| 9 | +import and from 'ember-truth-helpers/helpers/and'; |
| 10 | +import eq from 'ember-api-docs/helpers/eq'; |
| 11 | +import ImportExample from 'ember-api-docs/components/import-example'; |
| 12 | +import MarkdownToHtml from 'ember-cli-showdown/components/markdown-to-html'; |
| 13 | + |
| 14 | +export default class ClassFieldDescription extends Component { |
| 15 | + <template> |
| 16 | + {{! template-lint-disable no-invalid-interactive }} |
| 17 | + <section class="class-field-description {{@type}}"> |
| 18 | + <h3 id="{{@field.name}}" class="class-field-description--header"> |
| 19 | + <span class="signature"> |
| 20 | + <span class="{{@type}}-name"> |
| 21 | + {{@field.name}} |
| 22 | + </span> |
| 23 | + {{#if @field.params}}(<span class="args">{{join |
| 24 | + ", " |
| 25 | + (mapBy "name" @field.params) |
| 26 | + }}</span>){{/if}} |
| 27 | + {{#if @field.return}} |
| 28 | + : |
| 29 | + <span class="return-type">{{@field.return.type}}</span> |
| 30 | + {{/if}} |
| 31 | + </span> |
| 32 | + {{#if @field.access}} |
| 33 | + <span class="access">{{@field.access}}</span> |
| 34 | + {{/if}} |
| 35 | + {{#if @field.deprecated}} |
| 36 | + <span class="access">deprecated</span> |
| 37 | + {{/if}} |
| 38 | + <a |
| 39 | + class="class-field-description--link" |
| 40 | + href="#{{@field.name}}" |
| 41 | + aria-label="Jump to {{@field.name}}" |
| 42 | + > |
| 43 | + {{svgJar "link" width="20px" height="20px" aria-hidden="true"}} |
| 44 | + </a> |
| 45 | + </h3> |
| 46 | + {{#if @model.module}} |
| 47 | + <div class="attributes"> |
| 48 | + <div class="attribute"> |
| 49 | + <span class="attribute-label">Module:</span> |
| 50 | + <span class="attribute-value"><LinkTo |
| 51 | + @route="project-version.modules.module" |
| 52 | + @models={{array |
| 53 | + @model.projectVersion.compactVersion |
| 54 | + @model.module |
| 55 | + }} |
| 56 | + >{{@model.module}}</LinkTo></span> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + {{/if}} |
| 60 | + <p class="github-link" data-test-file={{@field.file}}> |
| 61 | + {{#if @field.inherited}} |
| 62 | + Inherited from |
| 63 | + <a |
| 64 | + href="{{githubLink |
| 65 | + @model.project.id |
| 66 | + @model.projectVersion.version |
| 67 | + @field.file |
| 68 | + @field.line |
| 69 | + }}" |
| 70 | + target="_blank" |
| 71 | + rel="noopener noreferrer" |
| 72 | + > |
| 73 | + {{@field.inheritedFrom}} |
| 74 | + {{@field.file}}:{{@field.line}} |
| 75 | + </a> |
| 76 | + {{else}} |
| 77 | + Defined in |
| 78 | + <a |
| 79 | + href="{{githubLink |
| 80 | + @model.project.id |
| 81 | + @model.projectVersion.version |
| 82 | + @field.file |
| 83 | + @field.line |
| 84 | + }}" |
| 85 | + target="_blank" |
| 86 | + rel="noopener noreferrer" |
| 87 | + > |
| 88 | + {{@field.file}}:{{@field.line}} |
| 89 | + </a> |
| 90 | + {{/if}} |
| 91 | + </p> |
| 92 | + {{#if @field.since}} |
| 93 | + <p class="field-since"> |
| 94 | + Available since v{{@field.since}} |
| 95 | + </p> |
| 96 | + {{/if}} |
| 97 | + {{#if |
| 98 | + (and |
| 99 | + (eq @field.static 1) |
| 100 | + (eq @field.itemtype "method") |
| 101 | + this.hasImportExample |
| 102 | + ) |
| 103 | + }} |
| 104 | + <ImportExample |
| 105 | + @item={{concat "{ " @field.name " }"}} |
| 106 | + @package={{@field.class}} |
| 107 | + /> |
| 108 | + {{/if}} |
| 109 | + <dl class="parameters"> |
| 110 | + {{#each @field.params as |param|}} |
| 111 | + <div class="parameter"> |
| 112 | + <dt>{{param.name}}</dt> |
| 113 | + <dd class="parameter-type">{{param.type}}</dd> |
| 114 | + <dd><MarkdownToHtml @markdown={{param.description}} /></dd> |
| 115 | + {{#if param.props}} |
| 116 | + <dl class="parameters"> |
| 117 | + {{#each param.props as |prop|}} |
| 118 | + <div class="prop"> |
| 119 | + <dt>{{prop.name}}</dt> |
| 120 | + <dd class="parameter-type">{{prop.type}}</dd> |
| 121 | + <dd><MarkdownToHtml @markdown={{prop.description}} /></dd> |
| 122 | + </div> |
| 123 | + {{/each}} |
| 124 | + </dl> |
| 125 | + {{/if}} |
| 126 | + </div> |
| 127 | + {{/each}} |
| 128 | + {{#if @field.return}} |
| 129 | + <div class="return"> |
| 130 | + <dt>returns</dt> |
| 131 | + <dd class="return-type">{{@field.return.type}}</dd> |
| 132 | + <dd><MarkdownToHtml @markdown={{@field.return.description}} /></dd> |
| 133 | + </div> |
| 134 | + {{/if}} |
| 135 | + </dl> |
| 136 | + <MarkdownToHtml @markdown={{@field.description}} /> |
| 137 | + </section> |
| 138 | + </template> |
| 139 | + @service |
| 140 | + legacyModuleMappings; |
| 141 | + |
| 142 | + get hasImportExample() { |
| 143 | + return this.legacyModuleMappings.hasFunctionMapping( |
| 144 | + this.args.field.name, |
| 145 | + this.args.field.class, |
| 146 | + ); |
| 147 | + } |
| 148 | +} |
0 commit comments