nmdc-runtime 1.3.1__py3-none-any.whl → 2.12.0__py3-none-any.whl
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.
- nmdc_runtime/Dockerfile +177 -0
- nmdc_runtime/api/analytics.py +90 -0
- nmdc_runtime/api/boot/capabilities.py +9 -0
- nmdc_runtime/api/boot/object_types.py +126 -0
- nmdc_runtime/api/boot/triggers.py +84 -0
- nmdc_runtime/api/boot/workflows.py +116 -0
- nmdc_runtime/api/core/auth.py +212 -0
- nmdc_runtime/api/core/idgen.py +200 -0
- nmdc_runtime/api/core/metadata.py +777 -0
- nmdc_runtime/api/core/util.py +114 -0
- nmdc_runtime/api/db/mongo.py +436 -0
- nmdc_runtime/api/db/s3.py +37 -0
- nmdc_runtime/api/endpoints/capabilities.py +25 -0
- nmdc_runtime/api/endpoints/find.py +634 -0
- nmdc_runtime/api/endpoints/jobs.py +206 -0
- nmdc_runtime/api/endpoints/lib/helpers.py +274 -0
- nmdc_runtime/api/endpoints/lib/linked_instances.py +193 -0
- nmdc_runtime/api/endpoints/lib/path_segments.py +165 -0
- nmdc_runtime/api/endpoints/metadata.py +260 -0
- nmdc_runtime/api/endpoints/nmdcschema.py +515 -0
- nmdc_runtime/api/endpoints/object_types.py +38 -0
- nmdc_runtime/api/endpoints/objects.py +277 -0
- nmdc_runtime/api/endpoints/operations.py +78 -0
- nmdc_runtime/api/endpoints/queries.py +701 -0
- nmdc_runtime/api/endpoints/runs.py +98 -0
- nmdc_runtime/api/endpoints/search.py +38 -0
- nmdc_runtime/api/endpoints/sites.py +205 -0
- nmdc_runtime/api/endpoints/triggers.py +25 -0
- nmdc_runtime/api/endpoints/users.py +214 -0
- nmdc_runtime/api/endpoints/util.py +817 -0
- nmdc_runtime/api/endpoints/wf_file_staging.py +307 -0
- nmdc_runtime/api/endpoints/workflows.py +353 -0
- nmdc_runtime/api/entrypoint.sh +7 -0
- nmdc_runtime/api/main.py +495 -0
- nmdc_runtime/api/middleware.py +43 -0
- nmdc_runtime/api/models/capability.py +14 -0
- nmdc_runtime/api/models/id.py +92 -0
- nmdc_runtime/api/models/job.py +57 -0
- nmdc_runtime/api/models/lib/helpers.py +78 -0
- nmdc_runtime/api/models/metadata.py +11 -0
- nmdc_runtime/api/models/nmdc_schema.py +146 -0
- nmdc_runtime/api/models/object.py +180 -0
- nmdc_runtime/api/models/object_type.py +20 -0
- nmdc_runtime/api/models/operation.py +66 -0
- nmdc_runtime/api/models/query.py +246 -0
- nmdc_runtime/api/models/query_continuation.py +111 -0
- nmdc_runtime/api/models/run.py +161 -0
- nmdc_runtime/api/models/site.py +87 -0
- nmdc_runtime/api/models/trigger.py +13 -0
- nmdc_runtime/api/models/user.py +207 -0
- nmdc_runtime/api/models/util.py +260 -0
- nmdc_runtime/api/models/wfe_file_stages.py +122 -0
- nmdc_runtime/api/models/workflow.py +15 -0
- nmdc_runtime/api/openapi.py +178 -0
- nmdc_runtime/api/swagger_ui/assets/EllipsesButton.js +146 -0
- nmdc_runtime/api/swagger_ui/assets/EndpointSearchWidget.js +369 -0
- nmdc_runtime/api/swagger_ui/assets/script.js +252 -0
- nmdc_runtime/api/swagger_ui/assets/style.css +155 -0
- nmdc_runtime/api/swagger_ui/swagger_ui.py +34 -0
- nmdc_runtime/config.py +56 -0
- nmdc_runtime/minter/adapters/repository.py +22 -2
- nmdc_runtime/minter/config.py +30 -4
- nmdc_runtime/minter/domain/model.py +55 -1
- nmdc_runtime/minter/entrypoints/fastapi_app.py +1 -1
- nmdc_runtime/mongo_util.py +89 -0
- nmdc_runtime/site/backup/nmdcdb_mongodump.py +1 -1
- nmdc_runtime/site/backup/nmdcdb_mongoexport.py +1 -3
- nmdc_runtime/site/changesheets/data/OmicsProcessing-to-catted-Biosamples.tsv +1561 -0
- nmdc_runtime/site/changesheets/scripts/missing_neon_soils_ecosystem_data.py +311 -0
- nmdc_runtime/site/changesheets/scripts/neon_soils_add_ncbi_ids.py +210 -0
- nmdc_runtime/site/dagster.yaml +53 -0
- nmdc_runtime/site/entrypoint-daemon.sh +29 -0
- nmdc_runtime/site/entrypoint-dagit-readonly.sh +26 -0
- nmdc_runtime/site/entrypoint-dagit.sh +29 -0
- nmdc_runtime/site/export/ncbi_xml.py +1331 -0
- nmdc_runtime/site/export/ncbi_xml_utils.py +405 -0
- nmdc_runtime/site/export/study_metadata.py +27 -4
- nmdc_runtime/site/graphs.py +294 -45
- nmdc_runtime/site/ops.py +1008 -230
- nmdc_runtime/site/repair/database_updater.py +451 -0
- nmdc_runtime/site/repository.py +368 -133
- nmdc_runtime/site/resources.py +154 -80
- nmdc_runtime/site/translation/gold_translator.py +235 -83
- nmdc_runtime/site/translation/neon_benthic_translator.py +212 -188
- nmdc_runtime/site/translation/neon_soil_translator.py +82 -58
- nmdc_runtime/site/translation/neon_surface_water_translator.py +698 -0
- nmdc_runtime/site/translation/neon_utils.py +24 -7
- nmdc_runtime/site/translation/submission_portal_translator.py +616 -162
- nmdc_runtime/site/translation/translator.py +73 -3
- nmdc_runtime/site/util.py +26 -7
- nmdc_runtime/site/validation/emsl.py +1 -0
- nmdc_runtime/site/validation/gold.py +1 -0
- nmdc_runtime/site/validation/util.py +16 -12
- nmdc_runtime/site/workspace.yaml +13 -0
- nmdc_runtime/static/NMDC_logo.svg +1073 -0
- nmdc_runtime/static/ORCID-iD_icon_vector.svg +4 -0
- nmdc_runtime/static/README.md +5 -0
- nmdc_runtime/static/favicon.ico +0 -0
- nmdc_runtime/util.py +236 -192
- nmdc_runtime-2.12.0.dist-info/METADATA +45 -0
- nmdc_runtime-2.12.0.dist-info/RECORD +131 -0
- {nmdc_runtime-1.3.1.dist-info → nmdc_runtime-2.12.0.dist-info}/WHEEL +1 -2
- {nmdc_runtime-1.3.1.dist-info → nmdc_runtime-2.12.0.dist-info}/entry_points.txt +0 -1
- nmdc_runtime/containers.py +0 -14
- nmdc_runtime/core/db/Database.py +0 -15
- nmdc_runtime/core/exceptions/__init__.py +0 -23
- nmdc_runtime/core/exceptions/base.py +0 -47
- nmdc_runtime/core/exceptions/token.py +0 -13
- nmdc_runtime/domain/users/queriesInterface.py +0 -18
- nmdc_runtime/domain/users/userSchema.py +0 -37
- nmdc_runtime/domain/users/userService.py +0 -14
- nmdc_runtime/infrastructure/database/db.py +0 -3
- nmdc_runtime/infrastructure/database/models/user.py +0 -10
- nmdc_runtime/lib/__init__.py +0 -1
- nmdc_runtime/lib/extract_nmdc_data.py +0 -41
- nmdc_runtime/lib/load_nmdc_data.py +0 -121
- nmdc_runtime/lib/nmdc_dataframes.py +0 -829
- nmdc_runtime/lib/nmdc_etl_class.py +0 -402
- nmdc_runtime/lib/transform_nmdc_data.py +0 -1117
- nmdc_runtime/site/drsobjects/ingest.py +0 -93
- nmdc_runtime/site/drsobjects/registration.py +0 -131
- nmdc_runtime/site/terminusdb/generate.py +0 -198
- nmdc_runtime/site/terminusdb/ingest.py +0 -44
- nmdc_runtime/site/terminusdb/schema.py +0 -1671
- nmdc_runtime/site/translation/emsl.py +0 -42
- nmdc_runtime/site/translation/gold.py +0 -53
- nmdc_runtime/site/translation/jgi.py +0 -31
- nmdc_runtime/site/translation/util.py +0 -132
- nmdc_runtime/site/validation/jgi.py +0 -42
- nmdc_runtime-1.3.1.dist-info/METADATA +0 -181
- nmdc_runtime-1.3.1.dist-info/RECORD +0 -81
- nmdc_runtime-1.3.1.dist-info/top_level.txt +0 -1
- /nmdc_runtime/{client → api}/__init__.py +0 -0
- /nmdc_runtime/{core → api/boot}/__init__.py +0 -0
- /nmdc_runtime/{core/db → api/core}/__init__.py +0 -0
- /nmdc_runtime/{domain → api/db}/__init__.py +0 -0
- /nmdc_runtime/{domain/users → api/endpoints}/__init__.py +0 -0
- /nmdc_runtime/{infrastructure → api/endpoints/lib}/__init__.py +0 -0
- /nmdc_runtime/{infrastructure/database → api/models}/__init__.py +0 -0
- /nmdc_runtime/{infrastructure/database/models → api/models/lib}/__init__.py +0 -0
- /nmdc_runtime/{site/drsobjects/__init__.py → api/models/minter.py} +0 -0
- /nmdc_runtime/site/{terminusdb → repair}/__init__.py +0 -0
- {nmdc_runtime-1.3.1.dist-info → nmdc_runtime-2.12.0.dist-info/licenses}/LICENSE +0 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
r"""
|
|
2
|
+
This module contains the definitions of constants and functions related to
|
|
3
|
+
generating the API's OpenAPI schema (a.k.a. Swagger schema).
|
|
4
|
+
|
|
5
|
+
References:
|
|
6
|
+
- FastAPI Documentation: https://fastapi.tiangolo.com/tutorial/metadata/
|
|
7
|
+
|
|
8
|
+
Notes:
|
|
9
|
+
- The tag descriptions in this file were cut/pasted from `nmdc_runtime/api/main.py`.
|
|
10
|
+
Now that they are in a separate module, we will be able to edit them more easily.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from typing import List, Dict
|
|
14
|
+
from enum import Enum
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class OpenAPITag(str, Enum):
|
|
18
|
+
r"""A tag you can use to group related API endpoints together in an OpenAPI schema."""
|
|
19
|
+
|
|
20
|
+
MINTER = "Persistent identifiers"
|
|
21
|
+
SYSTEM_ADMINISTRATION = "System administration"
|
|
22
|
+
WORKFLOWS = "Workflow management"
|
|
23
|
+
METADATA_ACCESS = "Metadata access"
|
|
24
|
+
USERS = "User accounts"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# Mapping from tag names to their (Markdown-formatted) descriptions.
|
|
28
|
+
tag_descriptions: Dict[str, str] = {}
|
|
29
|
+
|
|
30
|
+
tag_descriptions[
|
|
31
|
+
OpenAPITag.METADATA_ACCESS.value
|
|
32
|
+
] = r"""
|
|
33
|
+
Retrieve and manage metadata.
|
|
34
|
+
|
|
35
|
+
The metadata access endpoints fall into several subcategories:
|
|
36
|
+
|
|
37
|
+
- **Find**: Find a few types of metadata, using a simplified syntax.
|
|
38
|
+
- Each endpoint deals with a predetermined type of metadata; i.e., [studies](https://w3id.org/nmdc/Study/), [biosamples](https://w3id.org/nmdc/Biosample/), [data objects](https://w3id.org/nmdc/DataObject/), [planned processes](https://w3id.org/nmdc/PlannedProcess/), or [workflow executions](https://w3id.org/nmdc/WorkflowExecution/).
|
|
39
|
+
- **NMDC schema**: Examine the [NMDC schema](https://microbiomedata.github.io/nmdc-schema/), itself, and use schema-related terminology to find metadata of any type.
|
|
40
|
+
- **Queries**: Find, update, and delete metadata using [MongoDB commands](https://www.mongodb.com/docs/manual/reference/command/#user-commands).
|
|
41
|
+
- **Changesheets**: Modify metadata by uploading [changesheets](https://docs.microbiomedata.org/runtime/howto-guides/author-changesheets/).
|
|
42
|
+
- **JSON operations**: Insert or update metadata by submitting a JSON document representing a [Database](https://w3id.org/nmdc/Database/).
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
tag_descriptions[
|
|
46
|
+
OpenAPITag.WORKFLOWS.value
|
|
47
|
+
] = r"""
|
|
48
|
+
Manage workflows and their execution.
|
|
49
|
+
|
|
50
|
+
The workflow management endpoints fall into several subcategories:
|
|
51
|
+
|
|
52
|
+
- **Sites**: Register compute sites that can execute workflows, and generate credentials for them.
|
|
53
|
+
- A site corresponds to a physical place that may participate in job execution.
|
|
54
|
+
- A site may register data objects and capabilities with the Runtime. It may claim jobs to execute, and it may update job operations with execution info.
|
|
55
|
+
- A site must be able to service requests for any data objects it has registered.
|
|
56
|
+
- A site may expose a "put object" custom method for authorized users. This method facilitates an operation to upload an object to the site and have the site register that object with the Runtime system.
|
|
57
|
+
- **Workflows**: Manage workflow templates, which serve as blueprints for job execution.
|
|
58
|
+
- A workflow is a template for creating jobs.
|
|
59
|
+
- Workflow jobs are typically created by the system via triggers, which are associations between workflows and data object types.
|
|
60
|
+
- **Capabilities**: Manage the technical requirements that sites must meet to execute specific workflows.
|
|
61
|
+
- A workflow may require a site that executes it to have specific capabilities.
|
|
62
|
+
- These capabilities may go beyond the simple ability to access the data objects registered with the Runtime system.
|
|
63
|
+
- Sites register their capabilities, and sites are only able to claim workflow jobs if those sites have the capabilities required by the workflow.
|
|
64
|
+
- **Object types**: Manage the types of data objects whose creation can trigger job creation and, eventually, workflow execution.
|
|
65
|
+
- A data object type is an annotation that can be applied to data objects.
|
|
66
|
+
- A data object may have one or more types. Those types can be associated with workflows, through triggers.
|
|
67
|
+
- **Triggers**: Define associations between workflows and object types to enable automatic job creation.
|
|
68
|
+
- A [trigger](https://docs.microbiomedata.org/runtime/howto-guides/create-triggers/) is an association between a workflow and a data object type.
|
|
69
|
+
- When a data object is [annotated with a type](https://docs.microbiomedata.org/runtime/nb/queue_and_trigger_data_jobs/#use-case-annotate-a-known-object-with-a-type-that-will-trigger-a-workflow)—which may occur shortly after object registration—the Runtime will check—via trigger associations—whether it is due to create any jobs.
|
|
70
|
+
- **Jobs**: Manage the [claiming](https://docs.microbiomedata.org/runtime/howto-guides/claim-and-run-jobs/) and status of workflow executions.
|
|
71
|
+
- A job is a resource that decouples the configuration of a workflow, from execution of that workflow.
|
|
72
|
+
- Rather than directly creating a workflow operation, the Runtime creates a job that pairs a workflow with its configuration. Then, a site can claim the job—by its ID—and execute the associated workflow without doing additional configuration.
|
|
73
|
+
- A job can have multiple executions. All executions of all jobs of a given workflow, make up that workflow's executions.
|
|
74
|
+
- A site that already has a compatible job execution result can preempt the unnecessary creation of a job by _pre-claiming_ it. This will return like a claim, and now the site can register known data object inputs for the job without the risk of the Runtime creating a claimable job of the pre-claimed type.
|
|
75
|
+
- **Objects**: Manage the Data Repository Service (DRS) objects that are inputs and outputs of workflow executions.
|
|
76
|
+
- A [Data Repository Service (DRS) object](https://ga4gh.github.io/data-repository-service-schemas/preview/release/drs-1.1.0/docs/#_drs_datatypes) represents content necessary for—or content produced by—job execution.
|
|
77
|
+
- An object may be a *blob* (analogous to a file) or a *bundle* (analogous to a folder). Sites register objects, and sites must ensure that these objects are accessible to the "NMDC data broker."
|
|
78
|
+
- An object may be annotated with one or more object types, useful for triggering workflows.
|
|
79
|
+
- **Operations**: Track and monitor the real-time execution status of claimed jobs, including progress updates and error handling.
|
|
80
|
+
- An operation is a resource for tracking the execution of a job.
|
|
81
|
+
- When a job is claimed by a site for execution, an operation resource is created.
|
|
82
|
+
- An operation is like a "promise," in that it should eventually resolve to either a successful result—i.e., an execution resource—or to an error.
|
|
83
|
+
- An operation is parameterized to return a result type, and a metadata type for storing progress information, that are both particular to the job type.
|
|
84
|
+
- Operations may be paused, resumed, and/or cancelled.
|
|
85
|
+
- Operations may expire, i.e. not be stored indefinitely. In this case, it is recommended that execution resources have longer lifetimes/not expire, so that information about successful results of operations are available.
|
|
86
|
+
- **Runs**: _(work in progress)_ Execute simple jobs and report execution events back to the Runtime.
|
|
87
|
+
- Run simple jobs.
|
|
88
|
+
- For off-site job runs, keep the Runtime appraised of run events.
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
tag_descriptions[
|
|
92
|
+
OpenAPITag.USERS.value
|
|
93
|
+
] = r"""
|
|
94
|
+
Create and manage user accounts.
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
tag_descriptions[
|
|
98
|
+
OpenAPITag.MINTER.value
|
|
99
|
+
] = r"""
|
|
100
|
+
Mint and manage persistent identifiers.
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
tag_descriptions[
|
|
104
|
+
OpenAPITag.SYSTEM_ADMINISTRATION.value
|
|
105
|
+
] = r"""
|
|
106
|
+
Retrieve information about the software components that make up the Runtime.
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
# Remove leading and trailing whitespace from each description.
|
|
110
|
+
for name, description in tag_descriptions.items():
|
|
111
|
+
tag_descriptions[name] = description.strip()
|
|
112
|
+
|
|
113
|
+
ordered_tag_descriptors: List[Dict] = [
|
|
114
|
+
{
|
|
115
|
+
"name": OpenAPITag.METADATA_ACCESS.value,
|
|
116
|
+
"description": tag_descriptions[OpenAPITag.METADATA_ACCESS.value],
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"name": OpenAPITag.WORKFLOWS.value,
|
|
120
|
+
"description": tag_descriptions[OpenAPITag.WORKFLOWS.value],
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"name": OpenAPITag.MINTER.value,
|
|
124
|
+
"description": tag_descriptions[OpenAPITag.MINTER.value],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"name": OpenAPITag.USERS.value,
|
|
128
|
+
"description": tag_descriptions[OpenAPITag.USERS.value],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"name": OpenAPITag.SYSTEM_ADMINISTRATION.value,
|
|
132
|
+
"description": tag_descriptions[OpenAPITag.SYSTEM_ADMINISTRATION.value],
|
|
133
|
+
},
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def make_api_description(api_version: str, schema_version: str) -> str:
|
|
138
|
+
r"""
|
|
139
|
+
Returns an API description into which the specified schema version string has been incorporated.
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
api_version (str): The version of this Runtime instance.
|
|
143
|
+
schema_version (str): The version of `nmdc-schema` the Runtime is using.
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
str: The Markdown-formatted API description.
|
|
147
|
+
"""
|
|
148
|
+
result = f"""
|
|
149
|
+
Welcome to the **NMDC Runtime API**, an API you can use to [access metadata](https://docs.microbiomedata.org/howto_guides/api_gui/) residing in the NMDC database.
|
|
150
|
+
|
|
151
|
+
Users having adequate permissions can also use it to generate identifiers, submit metadata,
|
|
152
|
+
and manage workflow executions.
|
|
153
|
+
|
|
154
|
+
##### Quick start
|
|
155
|
+
|
|
156
|
+
The endpoints of the NMDC Runtime API are listed below.
|
|
157
|
+
They are organized into sections, each of which can be opened and closed.
|
|
158
|
+
The endpoints, themselves, can also be opened and closed.
|
|
159
|
+
|
|
160
|
+
Each endpoint—when opened—has a "Try it out" button, which you can press in order to send a request
|
|
161
|
+
to the endpoint directly from this web page. Each endpoint can also be
|
|
162
|
+
[accessed programmatically](https://docs.microbiomedata.org/runtime/nb/api_access_via_python/).
|
|
163
|
+
|
|
164
|
+
Some endpoints have a padlock icon, which means that the endpoint is only accessible to logged-in users.
|
|
165
|
+
You can log in by clicking the "Authorize" button located directly above the list of endpoints.
|
|
166
|
+
|
|
167
|
+
##### Contact us
|
|
168
|
+
|
|
169
|
+
You can [contact us](https://microbiomedata.org/contact/) anytime.
|
|
170
|
+
We continuously refine the API and may be able to streamline your use case.
|
|
171
|
+
|
|
172
|
+
##### Versions
|
|
173
|
+
|
|
174
|
+
[NMDC Runtime](https://docs.microbiomedata.org/runtime/) version: `{api_version}`
|
|
175
|
+
|
|
176
|
+
[NMDC Schema](https://microbiomedata.github.io/nmdc-schema/) version: `{schema_version}`
|
|
177
|
+
""".strip()
|
|
178
|
+
return result
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ellipses button with tooltip, implemented as a Web Component.
|
|
3
|
+
*
|
|
4
|
+
* The tooltip has a slot [1], which can be used to specify the tooltip's text.
|
|
5
|
+
*
|
|
6
|
+
* References:
|
|
7
|
+
* - [1] https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/slot
|
|
8
|
+
*/
|
|
9
|
+
class EllipsesButton extends HTMLElement {
|
|
10
|
+
// List the names of HTML attributes this element will respond to.
|
|
11
|
+
// Reference: https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#responding_to_attribute_changes
|
|
12
|
+
static observedAttributes = ["is-open"];
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
|
|
17
|
+
this.tooltipWrapperEl = null;
|
|
18
|
+
|
|
19
|
+
// Ensure that, within our callback methods, the "this" variable refers to this class instance.
|
|
20
|
+
this.stopEventPropagation = this.stopEventPropagation.bind(this);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
connectedCallback() {
|
|
24
|
+
this.attachShadow({ mode: "open" });
|
|
25
|
+
this.shadowRoot.innerHTML = String.raw`
|
|
26
|
+
<style>
|
|
27
|
+
.container {
|
|
28
|
+
display: inline-flex;
|
|
29
|
+
}
|
|
30
|
+
button {
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
background-color: transparent;
|
|
33
|
+
border: none;
|
|
34
|
+
line-height: 0px;
|
|
35
|
+
border-radius: 9999px; /* circle */
|
|
36
|
+
|
|
37
|
+
transition: background-color 0.2s ease-in-out,
|
|
38
|
+
color 0.2s ease-in-out;
|
|
39
|
+
}
|
|
40
|
+
button:hover {
|
|
41
|
+
color: #1f69c0;
|
|
42
|
+
background-color: #f4f4f4;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.tooltip-wrapper {
|
|
46
|
+
cursor: auto;
|
|
47
|
+
display: inline-flex;
|
|
48
|
+
align-items: center;
|
|
49
|
+
opacity: 0;
|
|
50
|
+
transition: opacity 0.2s ease-in-out;
|
|
51
|
+
}
|
|
52
|
+
button:hover + .tooltip-wrapper {
|
|
53
|
+
opacity: 1;
|
|
54
|
+
}
|
|
55
|
+
.tooltip-arrow {
|
|
56
|
+
margin-right: -4px;
|
|
57
|
+
fill: #f4f4f4;
|
|
58
|
+
}
|
|
59
|
+
.tooltip-box {
|
|
60
|
+
font-family: sans-serif;
|
|
61
|
+
background: #f4f4f4;
|
|
62
|
+
color: #333;
|
|
63
|
+
padding: 4px 8px;
|
|
64
|
+
border-radius: 4px;
|
|
65
|
+
font-size: 11px;
|
|
66
|
+
}
|
|
67
|
+
.hidden {
|
|
68
|
+
display: none;
|
|
69
|
+
}
|
|
70
|
+
</style>
|
|
71
|
+
|
|
72
|
+
<span class="container">
|
|
73
|
+
<button aria-describedby="tooltip" name="toggle-button">
|
|
74
|
+
<!-- Ellipses (row of three dots) -->
|
|
75
|
+
<svg width="12" height="12" viewBox="0 0 12 12" class="ellipses">
|
|
76
|
+
<ellipse cx="2" cy="6" rx="1" ry="1" fill="currentColor" />
|
|
77
|
+
<ellipse cx="6" cy="6" rx="1" ry="1" fill="currentColor" />
|
|
78
|
+
<ellipse cx="10" cy="6" rx="1" ry="1" fill="currentColor" />
|
|
79
|
+
</svg>
|
|
80
|
+
|
|
81
|
+
<!-- X (the symbol for closing) -->
|
|
82
|
+
<svg width="12" height="12" viewBox="0 0 12 12" class="cross hidden">
|
|
83
|
+
<line x1="1" y1="1" x2="11" y2="11" stroke="currentColor" stroke-width="1"/>
|
|
84
|
+
<line x1="11" y1="1" x2="1" y2="11" stroke="currentColor" stroke-width="1"/>
|
|
85
|
+
</svg>
|
|
86
|
+
</button>
|
|
87
|
+
|
|
88
|
+
<!-- Tooltip (rectangle with left-pointing arrowhead) -->
|
|
89
|
+
<div class="tooltip-wrapper">
|
|
90
|
+
<svg class="tooltip-arrow" width="16" height="24" viewBox="0 0 16 24">
|
|
91
|
+
<polygon points="0,12 16,6 16,18" />
|
|
92
|
+
</svg>
|
|
93
|
+
<div class="tooltip-box">
|
|
94
|
+
<slot role="tooltip">...</slot>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
</span>
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
// Prevent click events on the tooltip from bubbling up to higher-level HTML elements.
|
|
101
|
+
this.tooltipWrapperEl = this.shadowRoot.querySelector(".tooltip-wrapper");
|
|
102
|
+
this.tooltipWrapperEl.addEventListener("click", this.stopEventPropagation);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Prevents the specified event from bubbling up to higher-level HTML elements.
|
|
107
|
+
*
|
|
108
|
+
* @param {Event} event The event.
|
|
109
|
+
*/
|
|
110
|
+
stopEventPropagation(event) {
|
|
111
|
+
event.stopPropagation();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Handle a change in the value (or the addition, removal, or replacement) of any HTML attribute
|
|
116
|
+
* whose name is listed in the `observedAttributes` list.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} attributeName Name of the attribute whose value changed
|
|
119
|
+
* @param {string | null} oldValue Value the attribute changed _from_
|
|
120
|
+
* @param {string | null} newValue Value the attribute changed _to_
|
|
121
|
+
*
|
|
122
|
+
* Reference: https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#responding_to_attribute_changes
|
|
123
|
+
*/
|
|
124
|
+
attributeChangedCallback(attributeName, oldValue, newValue) {
|
|
125
|
+
// If the "is-open" attribute changed and its value is "true", show the "X" (Castlevania boomerang) icon.
|
|
126
|
+
// Otherwise, show the "..." (Pac-Man bait) icon.
|
|
127
|
+
if (attributeName === "is-open") {
|
|
128
|
+
const ellipsesEl = this.shadowRoot.querySelector("button .ellipses");
|
|
129
|
+
const crossEl = this.shadowRoot.querySelector("button .cross");
|
|
130
|
+
if (typeof newValue === "string" && newValue.toLowerCase() === "true") {
|
|
131
|
+
ellipsesEl.classList.add("hidden");
|
|
132
|
+
crossEl.classList.remove("hidden");
|
|
133
|
+
} else {
|
|
134
|
+
crossEl.classList.add("hidden");
|
|
135
|
+
ellipsesEl.classList.remove("hidden");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
disconnectedCallback() {
|
|
141
|
+
console.debug("Cleaning up event listener(s)");
|
|
142
|
+
if (this.tooltipWrapperEl !== null) {
|
|
143
|
+
this.tooltipWrapperEl.removeEventListener("click", this.stopEventPropagation);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|