diff --git a/.github/workflows/app.yml b/.github/workflows/app.yml new file mode 100644 index 0000000..5d5eb4a --- /dev/null +++ b/.github/workflows/app.yml @@ -0,0 +1,41 @@ +name: App + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [14.x] + + steps: + - uses: actions/checkout@v2 + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn config get cacheFolder)" + + - uses: actions/cache@v2 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + + - name: yarn install, build, and test + run: | + yarn install + yarn build + yarn test + if: | + steps.yarn-cache.outputs.cache-hit != 'true' + env: + CI: false \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..989e2c5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/README.md b/README.md index 02aac3f..766db2b 100644 --- a/README.md +++ b/README.md @@ -1,70 +1,76 @@ -# Getting Started with Create React App +[![Amplience Dynamic Content](media/header.png)](https://amplience.com/dynamic-content) -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). +![Dynamic Content Shoppable Image Extension](media/screenshot.png) -## Available Scripts +# Dynamic Content Shoppable Image Extension -In the project directory, you can run: +This extension allows users to define Focal Points and interactable Hotspots over an image, in a format similar to what Content Hub provides, but with the data being stored on a content item. -### `yarn start` +If you want to get started after cloning this repo, remember to sync packages with `yarn install`. -Runs the app in the development mode.\ -Open [http://localhost:3000](http://localhost:3000) to view it in the browser. +## Partial for Shoppabble Image Field and Configuration -The page will reload if you make edits.\ -You will also see any lint errors in the console. +The shoppable image extension has a rather complicated structure for the field it writes, so it's recommended that you put the schema in a partial. You can find the full partial definition in `shoppable-image-partial.json` in the base of this repository. -### `yarn test` +To use the schema when imported as a partial, use this snippet: -Launches the test runner in the interactive watch mode.\ -See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. +```json +{ + "shoppableImage": { + "title": "Shoppable Image", + "description": "An image enriched with a focal point and hotspots.", + "allOf": [ + { "$ref": "https://amplience.com/shoppable-image-partial#/definitions/shoppableImage" } + ] + } +} +``` -### `yarn build` +## Register Extension -Builds the app for production to the `build` folder.\ -It correctly bundles React in production mode and optimizes the build for the best performance. +This extension needs to be [registered](https://amplience.com/docs/development/registeringextensions.html) against a Hub with in the Dynamic Content application (Developer -> Extensions), for it to load within that Hub. -The build is minified and the filenames include the hashes.\ -Your app is ready to be deployed! +### Setup -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. +![Setup](media/setup.png) -### `yarn eject` +* Category: Content Field +* Label: Shoppable Image _(this will appear as the tab title in the Dashboard)_ +* Name: shoppable-image _(needs to be unique with the Hub)_ +* URL: [https://shoppable-image.extensions.content.amplience.net](https://shoppable-image.extensions.content.amplience.net) +* Description: Shoppable Image Extension _(can be left blank, if you wish)_ -**Note: this is a one-way operation. Once you `eject`, you can’t go back!** +Note: +You can use our deployed version of this extension (builds from the "production" branch) - -If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. +[https://shoppable-image.extensions.content.amplience.net](https://shoppable-image.extensions.content.amplience.net) -Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. +_As this is an open source project you're welcome to host your own "fork" of this project. You can use any standard static hosting service (Netlify, Amplify, Vercel, etc.) if you wish._ -You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. +#### Permissions -## Learn More +No additional permissions are required. -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). +## Output Data Format & Usage -To learn React, check out the [React documentation](https://reactjs.org/). +The shoppable image extension creates a simple format that you can ingest in your site to use or represent hotspots and the point of interest however you want. -### Code Splitting +For information on the format structure, and how you might use it in your own renderer, see [this documentation.](docs/FORMAT-USAGE.md) -This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) +## Visualization -### Analyzing the Bundle Size +The webapp for the extension can also double as a standalone visualization for the shoppable image field. It will run in visualization mode if you provide `?vse={{vse.domain}}` as a query string parameter, and will read back the field from the `shoppableImage` property of your content item. If you want to provide a different top level property, simply provide it in the query string like `fieldName=exampleImage`. -This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) +The visualization uses the `dc-visualization-sdk` to update its preview as the field is being edited, so you'll be able to try hotspot interaction over your image as you add and move hotspots. -### Making a Progressive Web App +To add the visualization to your content type, just switch to the `Visualizations` tab, and add a visualization with the extension as the url, and the query string `?vse={{vse.domain}}`. -This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) +## Development server -### Advanced Configuration +Run `HTTPS=true yarn run start` for a dev server. Navigate to `https://localhost:3000/`. The app will automatically reload if you change any of the source files. -This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) +If you want to test on DC, you'll need to link an extension to that same localhost url. Keep in mind that you might run into a browser security issue when using SSL, so if you're having any issues visit the extension directly and accept any ssl warnings. -### Deployment +## Build -This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) - -### `yarn build` fails to minify - -This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) +Run `yarn build`. The built extension will then be present in the `build/` directory, and you can upload it to any webserver. \ No newline at end of file diff --git a/amplify.yml b/amplify.yml new file mode 100644 index 0000000..d1a7a2a --- /dev/null +++ b/amplify.yml @@ -0,0 +1,16 @@ +version: 1 +frontend: + phases: + preBuild: + commands: + - nvm install 14 + - nvm use 14 + - yarn install --immutable + - yarn test + build: + commands: + - CI=false yarn build + artifacts: + baseDirectory: build + files: + - '**/*' \ No newline at end of file diff --git a/docs/FORMAT-USAGE.md b/docs/FORMAT-USAGE.md new file mode 100644 index 0000000..6755939 --- /dev/null +++ b/docs/FORMAT-USAGE.md @@ -0,0 +1,207 @@ +# Format & Usage information + +This document will explain what each of the fields in the partial maps to, and how to use them in your own applications. + +## Example + +![Example of an image enriched with the Shoppable Image Extension](../media/format-example.png) + +In the example image above, a few regions of the image have been highlighted with polygon hotspots, there is a point of interest centered on the camera, and there is a hotspot placed on top of a watch. + +Here is the JSON for this Shoppable Image: + +```json +{ + "shoppableImage": { + "image": { + "_meta": { + "schema": "http://bigcontent.io/cms/schema/v1/core#/definitions/image-link" + }, + "id": "b82e697a-0c8d-4270-9241-58ce6b53948c", + "name": "hipster-bag", + "endpoint": "csdemo", + "defaultHost": "cdn.media.amplience.net" + }, + "poi": { + "x": 0.38377001455604076, + "y": 0.7459606986899564, + "w": 0.09999999999999999, + "h": 0.15 + }, + "hotspots":[ + { + "id": "4b70802c-0499-4c6f-aa27-1e4ff0b125cb", + "target": "Watch", + "selector": ".watch", + "points": { + "x": 0.5647743813682679, + "y": 0.8384279475982532 + } + } + ], + "polygons": [ + { + "id": "744a00b9-0b21-47b5-800e-789911e0ad9a", + "target": "Shirt", + "selector": ".Shirt", + "points": [ + { + "x": 0.11062590975254731, + "y": 0.4912663755458515 + }, + { + "x": 0.33624454148471616, + "y": 0.4912663755458515 + }, + { + "x": 0.33624454148471616, + "y": 0.8973799126637555 + }, + { + "x": 0.11062590975254731, + "y": 0.8973799126637555 + } + ] + }, + { + "id": "6264b28f-0db9-4caf-b4d5-900bfb140d1a", + "target": "Fabric", + "selector": ".fabric", + "points": [ + { + "x": 0.4735225618631732, + "y": 0.36899563318777295 + }, + { + "x": 0.5352110625909757, + "y": 0.36899563318777295 + }, + { + "x": 0.5921542940320236, + "y": 0.4127074235807857 + }, + { + "x": 0.6229985443959243, + "y": 0.4934061135371177 + }, + { + "x": 0.6229985443959243, + "y": 0.5808296943231442 + }, + { + "x": 0.5921542940320236, + "y": 0.6615283842794764 + }, + { + "x": 0.5352110625909757, + "y": 0.7052401746724891 + }, + { + "x": 0.4735225618631732, + "y": 0.7052401746724891 + }, + { + "x": 0.41657933042212547, + "y": 0.6615283842794764 + }, + { + "x": 0.38573508005822416, + "y": 0.5808296943231442 + }, + { + "x": 0.38573508005822416, + "y": 0.4934061135371177 + }, + { + "x": 0.41657933042212547, + "y": 0.4127074235807857 + } + ] + }, + { + "id": "5678248d-6ad5-40c7-bb20-a68e9f3f1312", + "target": "Bag", + "selector": ".bag", + "points": [ + { + "x": 0.6506550218340611, + "y": 0.10043668122270744 + }, + { + "x": 0.9068413391557496, + "y": 0.10043668122270744 + }, + { + "x": 0.9068413391557496, + "y": 0.4781659388646288 + }, + { + "x": 0.6506550218340611, + "y": 0.4781659388646288 + } + ] + } + ] + } +} +``` + +The `image` field is a normal amplience media link. You can use the provided information to request the image. Here is an example handlebars template for generating an `` `src` attribute from an `image` object: + +```hbs +https://{{image.defaultHost}}/i/{{image.endpoint}}/{{image.name}} +``` + +The `poi` field represents a point of interest - an anchor point for the image to be centered around when cropping. The point of interest is technically a rectangle; it contains `x` and `y` positions, as well as width `w` and height `h`. The point is considered in the center of the rectangle. + +The `hotspots` field is an array of hotspot objects: +- `id`: GUID for the hotspot. Can be used to uniquely identify the hotspot. +- `target`: Target string. It's up to the user what this means. +- `selector`: Selector string. It's up to the user what this means. +- `points`: An object containing a single point for the hotspot. `x` and `y` contain the x and y postions, respectively. + +The `polygons` field is an array of polygon objects: +- `id`: GUID for the polygon. Can be used to uniquely identify the polygon. +- `target`: Target string. It's up to the user what this means. +- `selector`: Selector string. It's up to the user what this means. +- `points`: An array of points that construct the polygon. The final point is connected to the first point to form a closed loop. + +## Interactive Hotspots over an Image + +To place interactive elements over your image, you need both a container for them, and some code to calculate their placement relative to the scaled image size. The visualization does this by creating a container with the image size which floats on top of the image itself using `position: absolute;`, and hotspots/polygons which are placed by using css transforms with translations calculated by multiplying the normalized positions with the image size. + +Hotspots are easy enough to place by creating a div and styling it yourself, but polygons prove a little more challenging as they can technically create any shape out of their points. The best way to deal with this is to render your polygon within an SVG, and then place that in your container. + +You can generate an SVG Path's `d` attribute using the points of the polygon, which will let you draw the path within an SVG with any styling and interaction of your choice. See [polygon-helper.ts](../src/preview/polygon/polygon-helper.ts) for an example method that does this (`pointsToSVGPath`). + +## Point of Interest + +As the crop rectangle for the image changes dynamically, the visualization requests the full image and then applies the crop using css and javascript. You can do this by making the image a background and then using background position to move the image to follow the point of interest, or you can put the image in an outer container with `overflow: hidden` and your crop size, and use a css transformation to move the image. It's worth noting here that your interactive hotspots rely on the uncropped size of the image, so if hotspots are used, they should also be transformed in the same manner as the image. + +To crop with point of interest and a target aspect, you want to first determine which axis is uncropped. If the w/h ratio of the image is greater than the w/h ratio of the container, then the y-axis will be uncropped, as the wider image will overflow outside of your container in the x-axis. If it is less, the x-axis will be uncropped. You only need to move the image in the axis where it is cropped, so this simplifies calculation a bit. + +Let's say that the y-axis is uncropped, that `imageWidth` and `imageHeight` contain the size of the image, and that `targetWidth` contains the width of the cropping container. You can calculate a crop that avoids moving outside the image as follows: + +```typescript +// The point of interest needs to be converted back from normalized rectangle +// into a centerpoint with pixel coords. +const poiX = (field.poi.x + field.poi.w / 2 - 0.5) * imageWidth; + +// maxDist is the number of pixels of the image that overflow in a single direction. +// This will bound how much the image can be moved in that axis. +const maxDist = (imageWidth - targetWidth) / 2; + +offsetTransform = `translate(${Math.min(maxDist, Math.max(-poiX, -maxDist))}px, 0)`; +``` + +When uncropped on the y-axis, the css for the contained image is `height: 100%; maxWidth: none;`, and it's centered using flex. If uncropped on the other axis, simply swap all X for Y and width for height in the above examples. If using an interactive canvas on top, set its size to that of the image (scaled by its constrained axis) and also have it placed in the middle to float over it. + +If you wish to crop the image statically, you can pass the point of interest directly to DI and have it crop around the point of interest for you. Example parameters: + +`poi=0.2056,0.5014,0.1124,0.15&scaleFit=poi` + +You can add these to any crop that works with Point of Interest, such as an aspect crop. This one sets a width of 141px, and the height is implicitly 141 as well due to the aspect: + +`sm=aspect&aspect=1:1&w=141` + +If you wish to use both point of interest and hotspots at the same time, then you'll still need to know the original size of the image before cropping, as all coordinates are normalized using that size. This might mean applying the crop rectangle to the full image yourself, or requesting the image metadata separately to get its original size. \ No newline at end of file diff --git a/media/format-example.png b/media/format-example.png new file mode 100644 index 0000000..7268aff Binary files /dev/null and b/media/format-example.png differ diff --git a/media/header.png b/media/header.png new file mode 100644 index 0000000..dc252de Binary files /dev/null and b/media/header.png differ diff --git a/media/screenshot.png b/media/screenshot.png new file mode 100644 index 0000000..dc7a232 Binary files /dev/null and b/media/screenshot.png differ diff --git a/media/setup.png b/media/setup.png new file mode 100644 index 0000000..6d8fb4a Binary files /dev/null and b/media/setup.png differ diff --git a/package.json b/package.json index d92533d..264ecd1 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,27 @@ { "name": "dc-extension-shoppable-image", - "version": "0.1.0", + "version": "1.0.0", "private": true, "dependencies": { + "@emotion/react": "^11.5.0", + "@emotion/styled": "^11.3.0", + "@mui/icons-material": "^5.1.0", + "@mui/material": "^5.1.0", "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", "@testing-library/user-event": "^12.1.10", + "@types/jest": "^27.0.2", + "@types/node": "^16.11.7", + "@types/react-dom": "^17.0.11", + "@types/uuid": "^8.3.4", + "clsx": "^1.1.1", + "dc-extensions-sdk": "^2.0.0", + "dc-visualization-sdk": "^1.1.0", "react": "^17.0.2", "react-dom": "^17.0.2", "react-scripts": "4.0.3", + "typescript": "^4.4.4", + "uuid": "^8.3.2", "web-vitals": "^1.0.1" }, "scripts": { @@ -34,5 +47,8 @@ "last 1 firefox version", "last 1 safari version" ] + }, + "devDependencies": { + "@types/react": "^17.0.34" } } diff --git a/shoppable-image-partial.json b/shoppable-image-partial.json new file mode 100644 index 0000000..5696a0c --- /dev/null +++ b/shoppable-image-partial.json @@ -0,0 +1,115 @@ +{ + "shoppableImage": { + "type": "object", + "properties": { + "image": { + "title": "Image", + "description": "The base image that the shoppable image elements are for.", + "allOf": [ + { "$ref": "http://bigcontent.io/cms/schema/v1/core#/definitions/image-link" } + ] + }, + "poi": { + "title": "Focal Point", + "description": "The focal point defined on the image. Coordinates are normalized 0-1 based on image size.", + "type": "object", + "properties": { + "x": { + "type": "number" + }, + "y": { + "type": "number" + }, + "w": { + "type": "number" + }, + "h": { + "type": "number" + } + } + }, + "hotspots": { + "title": "Hotspots", + "description": "Interactable hotspots defined on the image. Coordinates are normalized 0-1 based on image size.", + "type": "array", + "items": { + "type": "object", + "properties": { + "points": { + "title": "Point", + "description": "The location of this hotspot on the image.", + "type": "object", + "properties": { + "x": { + "type": "number" + }, + "y": { + "type": "number" + } + } + }, + "id": { + "title": "ID", + "description": "Unique idendifier for this hotspot.", + "type": "string" + }, + "selector": { + "title": "Selector", + "description": "The selector associated with this hotspot.", + "type": "string" + }, + "target": { + "title": "Target", + "description": "The target associated with this hotspot.", + "type": "string" + } + } + } + }, + "polygons": { + "title": "Polygons", + "description": "Interactable polygonal regions defined on the image. Coordinates are normalized 0-1 based on image size.", + "type": "array", + "items": { + "type": "object", + "properties": { + "points": { + "title": "Polygon Points", + "description": "The points that define this polygon. The polygon edge is drawn between all points in order, and closed at the end by drawing an edge from the last to the first point.", + "type": "array", + "items": { + "type": "object", + "properties": { + "x": { + "type": "number" + }, + "y": { + "type": "number" + } + } + } + }, + "id": { + "title": "ID", + "description": "Unique idendifier for this polygon.", + "type": "string" + }, + "selector": { + "title": "Selector", + "description": "The selector associated with this polygon.", + "type": "string" + }, + "target": { + "title": "Target", + "description": "The target associated with this polygon.", + "type": "string" + } + } + } + } + }, + "ui:extension": { + "name": "shoppable-image" + } + } +} \ No newline at end of file diff --git a/src/App.css b/src/App.css index 74b5e05..b3456d4 100644 --- a/src/App.css +++ b/src/App.css @@ -1,38 +1,8 @@ -.App { - text-align: center; +.amp-app { + overflow: hidden; + min-height: 500px; } -.App-logo { - height: 40vmin; - pointer-events: none; -} - -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } -} - -.App-header { - background-color: #282c34; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); - color: white; -} - -.App-link { - color: #61dafb; -} - -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } +.amp-app-clip { + overflow: hidden; } diff --git a/src/App.js b/src/App.js deleted file mode 100644 index 3784575..0000000 --- a/src/App.js +++ /dev/null @@ -1,25 +0,0 @@ -import logo from './logo.svg'; -import './App.css'; - -function App() { - return ( -
-
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - -
-
- ); -} - -export default App; diff --git a/src/App.test.js b/src/App.test.js index 1f03afe..93107e8 100644 --- a/src/App.test.js +++ b/src/App.test.js @@ -1,8 +1,8 @@ -import { render, screen } from '@testing-library/react'; +import { render } from '@testing-library/react'; import App from './App'; -test('renders learn react link', () => { - render(); - const linkElement = screen.getByText(/learn react/i); - expect(linkElement).toBeInTheDocument(); +test('renders amp-app div', () => { + const { container } = render(); + const mainElement = container.getElementsByClassName('amp-app'); + expect(mainElement).toBeDefined(); }); diff --git a/src/App.tsx b/src/App.tsx new file mode 100644 index 0000000..bafeb5b --- /dev/null +++ b/src/App.tsx @@ -0,0 +1,45 @@ +import "./App.css"; +import { WithEditorContext } from "./core/EditorContext"; +import { PreviewCanvas } from "./preview/preview-canvas/preview-canvas"; +import { EditToolbar } from "./preview/edit-toolbar/edit-toolbar"; +import { WithExtensionContext } from "./core/ExtensionContext"; +import { ThemeProvider } from "@emotion/react"; +import { theme } from "./theme"; +import { MetadataList } from "./metadata/metadata-list/metadata-list"; +import { WithVisualizationContext } from "./visualization/visualization-context"; +import { WithWindowContext } from "./core/WindowContext"; +import { VisContainer } from "./visualization/vis-container/vis-container"; +import { Title } from "./preview/title/title"; + +function App() { + const params = new URL(document.location.href).searchParams; + const vse = params.get("vse"); + const fieldName = params.get("fieldName") || "shoppableImage"; + + return ( +
+ + + {vse != null ? ( + + + + ) : ( + + + + <div className="amp-app-clip"> + <EditToolbar /> + <PreviewCanvas /> + <MetadataList /> + </div> + </WithEditorContext> + </WithExtensionContext> + )} + </WithWindowContext> + </ThemeProvider> + </div> + ); +} + +export default App; diff --git a/src/core/AutoResizer.tsx b/src/core/AutoResizer.tsx new file mode 100644 index 0000000..bd483c5 --- /dev/null +++ b/src/core/AutoResizer.tsx @@ -0,0 +1,30 @@ +import { ContentFieldExtension } from "dc-extensions-sdk"; + +export class AutoResizer { + private active = true; + private lastSize = 0; + private animFrameBound: () => void; + + constructor(private sdk: ContentFieldExtension) { + this.animFrameBound = this.animFrame.bind(this); + + requestAnimationFrame(this.animFrameBound); + } + + animFrame() { + const height = this.sdk.frame.getHeight(); + + if (height !== this.lastSize) { + this.lastSize = height; + this.sdk.frame.setHeight(height); + } + + if (this.active) { + requestAnimationFrame(this.animFrameBound); + } + } + + dispose() { + this.active = false; + } +} diff --git a/src/core/EditorContext.tsx b/src/core/EditorContext.tsx new file mode 100644 index 0000000..e2290ab --- /dev/null +++ b/src/core/EditorContext.tsx @@ -0,0 +1,130 @@ +import React, { useState } from "react"; +import { useExtensionContext } from "./ExtensionContext"; +import { + ShoppableImageHotspot, + ShoppableImagePolygon, +} from "./ShoppableImageData"; + +export enum EditorMode { + Initial, + + EditorPoi, + + EditorGrab, + EditorHotspot, + EditorPolygonRect, + EditorPolygonCircle, + + // These modes don't exist, they trigger actions. + Swap, + Delete, +} + +export enum MetadataSelectionType { + Default, + ResizeX, + ResizeY, + Resize, +} + +export enum MetadataSelectionMode { + Hotspot, + Polygon +} + +export type MetadataSelectionTarget = + | ShoppableImageHotspot + | ShoppableImagePolygon; + +export interface MetadataSelection { + target: MetadataSelectionTarget; + mode: MetadataSelectionMode; + type: MetadataSelectionType; + resizeAnchor?: { x: number; y: number }; + lastPosition?: { x: number; y: number }; + createdUndo?: boolean; +} + +interface EditorState { + mode: EditorMode; + changeMode(mode: EditorMode): void; + selection: MetadataSelection | undefined; + setSelection(selection: MetadataSelection | undefined): void; +} + +const dummySetter = () => { + /* */ +}; + +const defaultEditorState: EditorState = { + mode: EditorMode.Initial, + changeMode: dummySetter, + selection: undefined, + setSelection: dummySetter, +}; + +const EditorContext = React.createContext(defaultEditorState); + +export function WithEditorContext({ children }: { children: React.ReactNode }) { + const [state, setState] = useState(defaultEditorState); + const { field } = useExtensionContext(); + + state.changeMode = (mode: EditorMode) => { + setState({ ...state, mode: mode, selection: undefined }); + }; + + state.setSelection = (selection: MetadataSelection | undefined) => { + if (state.mode === EditorMode.EditorPoi && selection) { + switch (selection.mode) { + case MetadataSelectionMode.Hotspot: + state.mode = EditorMode.EditorHotspot; + break; + case MetadataSelectionMode.Polygon: + state.mode = EditorMode.EditorGrab; + break; + } + } + + setState({ ...state, selection }); + }; + + const validateSelection = () => { + if (state.selection && field) { + if (state.selection.mode === MetadataSelectionMode.Hotspot) { + const index = field.hotspots ? field.hotspots.findIndex(x => x.id === (state.selection as MetadataSelection).target.id) : -1; + + if (index === -1) { + state.setSelection(undefined); + } else if (field.hotspots && field.hotspots[index] !== (state.selection as MetadataSelection).target) { + // Might need to repoint at new object. + state.setSelection({ + ...state.selection, + target: field.hotspots[index] + }); + } + } else if (state.selection.mode === MetadataSelectionMode.Polygon) { + const index = field.polygons ? field.polygons.findIndex(x => x.id === (state.selection as MetadataSelection).target.id) : -1; + + if (index === -1) { + state.setSelection(undefined); + } else if (field.polygons && field.polygons[index] !== (state.selection as MetadataSelection).target) { + // Might need to repoint at new object. + state.setSelection({ + ...state.selection, + target: field.polygons[index] + }); + } + } + } + } + + validateSelection(); + + return ( + <EditorContext.Provider value={state}>{children}</EditorContext.Provider> + ); +} + +export function useEditorContext() { + return React.useContext(EditorContext); +} diff --git a/src/core/ExtensionContext.tsx b/src/core/ExtensionContext.tsx new file mode 100644 index 0000000..75f4ae2 --- /dev/null +++ b/src/core/ExtensionContext.tsx @@ -0,0 +1,109 @@ +import { ContentFieldExtension } from "dc-extensions-sdk"; +import React, { useEffect, useState } from "react"; +import { setFlagsFromString } from "v8"; +import { AutoResizer } from "./AutoResizer"; +import { getSdk } from "./ExtensionSdk"; +import { KeyboardShortcuts } from "./KeyboardShortcuts"; +import { ShoppableImageData } from "./ShoppableImageData"; + +interface ExtensionState { + params?: any; + sdk?: ContentFieldExtension; + field?: ShoppableImageData; + setField?: () => void; + setUndo?: () => void; + undo?: () => void; + redo?: () => void; + clearUndo?: () => void; + undoHistory: ShoppableImageData[]; + redoHistory: ShoppableImageData[]; + sdkConnected: boolean; +} + +const defaultExtensionState: ExtensionState = { + undoHistory: [], + redoHistory: [], + sdkConnected: false +}; + +const ExtensionContext = React.createContext(defaultExtensionState); + +export function WithExtensionContext({ + children, +}: { + children: React.ReactNode; +}) { + const [state, setState] = useState(defaultExtensionState); + + useEffect(() => { + getSdk().then(async (sdk) => { + new AutoResizer(sdk); + + const params: any = { ...sdk.params.installation, ...sdk.params.instance }; + const schema = sdk.field.schema; + const field = await sdk.field.getValue() as ShoppableImageData; + const undoHistory: ShoppableImageData[] = []; + const redoHistory: ShoppableImageData[] = []; + + if (params.title == null && schema.title) { + params.title = schema.title; + } + + const state: ExtensionState = { params, sdk, field, undoHistory, redoHistory, sdkConnected: true }; + + state.setField = () => { + sdk.field.setValue(field); + setState({ ...state }); + } + + state.setUndo = () => { + redoHistory.splice(0, redoHistory.length); + undoHistory.push(JSON.parse(JSON.stringify(field))); + setState({ ...state }); + } + + state.undo = () => { + const undo = undoHistory.pop(); + + if (undo) { + redoHistory.push(JSON.parse(JSON.stringify(field))); + Object.assign(field, undo); + sdk.field.setValue(field); + setState({ ...state }); + } + } + + state.redo = () => { + const redo = redoHistory.pop(); + + if (redo) { + undoHistory.push(JSON.parse(JSON.stringify(field))); + Object.assign(field, redo); + sdk.field.setValue(field); + setState({ ...state }); + } + } + + state.clearUndo = () => { + redoHistory.splice(0, redoHistory.length); + undoHistory.splice(0, undoHistory.length); + } + + KeyboardShortcuts.bindUndoMethods(state.undo, state.redo); + + setState(state); + }).catch((e) => { + console.error(e); + }); + }, []); + + return ( + <ExtensionContext.Provider value={state}> + {children} + </ExtensionContext.Provider> + ); +} + +export function useExtensionContext() { + return React.useContext(ExtensionContext); +} diff --git a/src/core/ExtensionSdk.ts b/src/core/ExtensionSdk.ts new file mode 100644 index 0000000..be60ccb --- /dev/null +++ b/src/core/ExtensionSdk.ts @@ -0,0 +1,10 @@ +import { init, ContentFieldExtension } from 'dc-extensions-sdk'; + +let sdk: Promise<ContentFieldExtension>; + +export async function getSdk(): Promise<ContentFieldExtension> { + if (sdk == null) { + sdk = init(); + } + return await sdk; +} diff --git a/src/core/KeyboardShortcuts.tsx b/src/core/KeyboardShortcuts.tsx new file mode 100644 index 0000000..8171ab0 --- /dev/null +++ b/src/core/KeyboardShortcuts.tsx @@ -0,0 +1,140 @@ +interface KeyboardBinding { + code: string, + needsCtrl?: boolean, + needsShift?: boolean, + action: () => void +} + +export class KeyboardShortcuts { + keyDownBind: (event: KeyboardEvent) => void; + keyUpBind: (event: KeyboardEvent) => void; + ignoreShortcuts = false; + + undoBind?: () => void; + redoBind?: () => void; + deleteBind?: () => void; + + private actions: Map<string, KeyboardBinding[]>; + + constructor() { + this.keyDownBind = this.keyDown.bind(this); + this.keyUpBind = this.keyUp.bind(this); + + const bindings: KeyboardBinding[] = [ + { + code: 'KeyZ', + needsCtrl: true, + needsShift: true, + action: this.redo.bind(this) + }, + { + code: 'KeyZ', + needsCtrl: true, + action: this.undo.bind(this) + }, + { + code: 'KeyY', + needsCtrl: true, + action: this.redo.bind(this) + }, + { + code: 'Backspace', + action: this.delete.bind(this) + }, + { + code: 'Delete', + action: this.delete.bind(this) + } + ]; + + this.actions = new Map(); + + for (const binding of bindings) { + let codeBindings = this.actions.get(binding.code); + + if (codeBindings === undefined) { + codeBindings = []; + + this.actions.set(binding.code, codeBindings); + } + + codeBindings.push(binding); + } + + this.bind(); + } + + bind(): void { + window.addEventListener('keydown', this.keyDownBind); + window.addEventListener('keyup', this.keyUpBind); + } + + unbind(): void { + window.removeEventListener('keydown', this.keyDownBind); + window.removeEventListener('keyup', this.keyUpBind); + } + + undo(): void { + if (this.undoBind) { + this.undoBind(); + } + } + + redo(): void { + if (this.redoBind) { + this.redoBind(); + } + } + + delete(): void { + if (this.deleteBind) { + this.deleteBind(); + } + } + + static globalInstance?: KeyboardShortcuts; + + static getInstance(): KeyboardShortcuts { + if (this.globalInstance == null) { + this.globalInstance = new KeyboardShortcuts(); + } + + return this.globalInstance; + } + + static bindUndoMethods(undo: () => void, redo: () => void) { + const instance = this.getInstance(); + + instance.undoBind = undo; + instance.redoBind = redo; + } + + static bindDeleteMethod(deleteMethod: () => void) { + const instance = this.getInstance(); + + instance.deleteBind = deleteMethod; + } + + keyDown(event: KeyboardEvent) { + if (document.activeElement && document.activeElement.tagName === 'INPUT') { + return; + } + + const matches = this.actions.get(event.code); + + if (matches) { + for (const match of matches) { + if ((!match.needsCtrl || (event.ctrlKey || event.metaKey)) && + (!match.needsShift || event.shiftKey)) { + match.action(); + event.preventDefault(); + return; + } + } + } + } + + keyUp(event: KeyboardEvent) { + + } +} \ No newline at end of file diff --git a/src/core/ShoppableImageData.ts b/src/core/ShoppableImageData.ts new file mode 100644 index 0000000..b709c1d --- /dev/null +++ b/src/core/ShoppableImageData.ts @@ -0,0 +1,34 @@ +import { MediaImageLink } from "dc-extensions-sdk/dist/types/lib/components/MediaLink"; + +export interface ShoppableImagePoi { + x: number; + y: number; + w: number; + h: number; +} + +export interface ShoppableImagePoint { + x: number; + y: number; +} + +export interface ShoppableImageHotspot { + id: string; + selector: string; + points: ShoppableImagePoint; + target: string; +} + +export interface ShoppableImagePolygon { + id: string; + selector: string; + points: ShoppableImagePoint[]; + target: string; +} + +export interface ShoppableImageData { + image: MediaImageLink; + poi?: ShoppableImagePoi; + hotspots?: ShoppableImageHotspot[]; + polygons?: ShoppableImagePolygon[]; +} \ No newline at end of file diff --git a/src/core/WindowContext.tsx b/src/core/WindowContext.tsx new file mode 100644 index 0000000..f142588 --- /dev/null +++ b/src/core/WindowContext.tsx @@ -0,0 +1,30 @@ +import React, { useEffect, useState } from "react"; + +const WindowContext = React.createContext({ w: 0, h: 0 }); + +export function WithWindowContext({ + children, +}: { + children: React.ReactNode; +}) { + const [state, setState] = useState({ w: window.innerWidth, h: window.innerHeight }); + + const resizeWindow = () => { + setState({ w: window.innerWidth, h: window.innerHeight }); + } + + useEffect(() => { + window.addEventListener("resize", resizeWindow); + return () => window.removeEventListener("resize", resizeWindow); + }, []); + + return ( + <WindowContext.Provider value={state}> + {children} + </WindowContext.Provider> + ); +} + +export function useWindowContext() { + return React.useContext(WindowContext); +} diff --git a/src/index.css b/src/index.css index ec2585e..ae3597c 100644 --- a/src/index.css +++ b/src/index.css @@ -5,6 +5,7 @@ body { sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; + overflow: hidden; } code { diff --git a/src/index.js b/src/index.tsx similarity index 100% rename from src/index.js rename to src/index.tsx diff --git a/src/metadata/metadata-list/metadata-list.tsx b/src/metadata/metadata-list/metadata-list.tsx new file mode 100644 index 0000000..c42ee33 --- /dev/null +++ b/src/metadata/metadata-list/metadata-list.tsx @@ -0,0 +1,196 @@ +import Delete from "@mui/icons-material/Delete"; +import { + IconButton, + Table, + TableBody, + TableCell, + TableContainer, + TableRow, + TextField, +} from "@mui/material"; +import { EditorMode, MetadataSelectionMode, MetadataSelectionType, useEditorContext } from "../../core/EditorContext"; +import { useExtensionContext } from "../../core/ExtensionContext"; +import { KeyboardShortcuts } from "../../core/KeyboardShortcuts"; +import { ShoppableImageHotspot, ShoppableImagePolygon } from "../../core/ShoppableImageData"; + +export function MetadataList({ className }: { className?: string }) { + const { field, setField, setUndo } = useExtensionContext(); + const { selection, setSelection, mode } = useEditorContext(); + + const editable = mode !== EditorMode.Initial; + + const updateField = (obj: any, prop: string, value: any) => { + if (setUndo) { + setUndo(); + } + obj[prop] = value; + if (setField) { + setField(); + } + }; + + const deletePoi = () => { + if (field && setField && setUndo && field.poi && field.poi.x != null) { + setUndo(); + field.poi = { } as any; + setField(); + } + } + + const deleteHotspot = (index: number) => { + if (field && field.hotspots && setField && setUndo) { + setUndo(); + field.hotspots.splice(index, 1); + setField(); + setSelection(undefined); + } + } + + const deletePolygon = (index: number) => { + if (field && field.polygons && setField && setUndo) { + setUndo(); + field.polygons.splice(index, 1); + setField(); + setSelection(undefined); + } + } + + KeyboardShortcuts.bindDeleteMethod(() => { + if (field) { + if (selection) { + if (selection.mode === MetadataSelectionMode.Hotspot && field.hotspots) { + deleteHotspot(field.hotspots.indexOf(selection.target as ShoppableImageHotspot)); + } + + if (selection.mode === MetadataSelectionMode.Polygon && field.polygons) { + deletePolygon(field.polygons.indexOf(selection.target as ShoppableImagePolygon)); + } + } else if (mode === EditorMode.EditorPoi) { + deletePoi(); + } + } + }); + + return ( + <TableContainer> + <Table aria-label="Metadata List"> + <TableBody> + {field && field.poi && field.poi.x != null && ( + <TableRow> + <TableCell component="th">Focal Point</TableCell> + <TableCell sx={{ paddingTop: "2px", paddingBottom: "2px" }}> + <div + style={{ width: "100%", height: "100%", display: "flex", alignItems:"center" }} + > + <span style={{flex: '1'}}> + {`"x": ${field.poi.x + field.poi.w / 2}, "y": ${ + field.poi.y + field.poi.h / 2 + }`} + </span> + { + editable && + <IconButton onClick={() => deletePoi()} sx={{ margin: "2px" }}> + <Delete /> + </IconButton> + } + </div> + </TableCell> + </TableRow> + )} + {field && + field.hotspots && + field.hotspots.map((hotspot, index) => ( + <TableRow + key={index} + selected={selection && selection.target === hotspot} + onClick={() => setSelection({ target: hotspot, mode: MetadataSelectionMode.Hotspot, type: MetadataSelectionType.Default })} + > + <TableCell component="th">Hotspot {index + 1}</TableCell> + <TableCell sx={{ paddingTop: "2px", paddingBottom: "2px" }}> + <div + style={{ width: "100%", height: "100%", display: "flex" }} + > + <TextField + label="Target" + size="small" + variant="standard" + sx={{ marginRight: "10px", flex: "1" }} + value={hotspot.target} + disabled={!editable} + onChange={(evt: any) => + updateField(hotspot, "target", evt.target.value) + } + /> + <TextField + label="Selector" + size="small" + variant="standard" + sx={{ marginLeft: "10px", flex: "1" }} + value={hotspot.selector} + disabled={!editable} + onChange={(evt: any) => + updateField(hotspot, "selector", evt.target.value) + } + /> + + { + editable && + <IconButton sx={{ margin: "2px" }} onClick={() => deleteHotspot(index)}> + <Delete /> + </IconButton> + } + </div> + </TableCell> + </TableRow> + ))} + {field && + field.polygons && + field.polygons.map((polygon, index) => ( + <TableRow + key={index} + selected={selection && selection.target === polygon} + onClick={() => setSelection({ target: polygon, mode: MetadataSelectionMode.Polygon, type: MetadataSelectionType.Default })} + > + <TableCell component="th">Polygon {index + 1}</TableCell> + <TableCell sx={{ paddingTop: "2px", paddingBottom: "2px" }}> + <div + style={{ width: "100%", height: "100%", display: "flex" }} + > + <TextField + label="Target" + size="small" + variant="standard" + sx={{ marginRight: "10px", flex: "1" }} + value={polygon.target} + disabled={!editable} + onChange={(evt: any) => + updateField(polygon, "target", evt.target.value) + } + /> + <TextField + label="Selector" + size="small" + variant="standard" + sx={{ marginLeft: "10px", flex: "1" }} + value={polygon.selector} + disabled={!editable} + onChange={(evt: any) => + updateField(polygon, "selector", evt.target.value) + } + /> + + { + editable && + <IconButton sx={{ margin: "2px" }} onClick={() => deletePolygon(index)}> + <Delete /> + </IconButton> + } + </div> + </TableCell> + </TableRow> + ))} + </TableBody> + </Table> + </TableContainer> + ); +} diff --git a/src/preview/edit-toolbar/edit-toolbar.css b/src/preview/edit-toolbar/edit-toolbar.css new file mode 100644 index 0000000..a8fa1ad --- /dev/null +++ b/src/preview/edit-toolbar/edit-toolbar.css @@ -0,0 +1,50 @@ +:root { + --color-lighter-grey: #e5e5e5; +} + +.amp-edit-toolbar { + transition: margin-top 0.5s; + margin-top: 0; + display: flex; + position: relative; + z-index: 1; + background-color: var(--color-lighter-grey); + width: 100%; + height: 42px; +} + +.amp-edit-toolbar button { + margin: 5px; + height: 32px; + line-height: 32px; + flex-shrink: 0; +} + +.amp-root__topbar--hide { + margin-top: -42px !important; +} + +.amp-edit-toolbar__modescroll { + overflow: auto; + overflow-y: hidden; + flex: 1; +} + +.amp-edit-toolbar__modes { + flex: 1; + display: inline-flex; +} + +.amp-edit-toolbar__reset { + min-width: 0 !important; + padding: 6px !important; +} + +.amp-edit-toolbar__modeicon { + margin-left: -3px; + margin-right: 3px; +} + +.amp-edit-toolbar__rot45 { + transform: rotate(45deg); +} \ No newline at end of file diff --git a/src/preview/edit-toolbar/edit-toolbar.tsx b/src/preview/edit-toolbar/edit-toolbar.tsx new file mode 100644 index 0000000..d9edb05 --- /dev/null +++ b/src/preview/edit-toolbar/edit-toolbar.tsx @@ -0,0 +1,159 @@ +import "./edit-toolbar.css"; +import clsx from "clsx"; +import { EditorMode } from "../../core/EditorContext"; +import { useEditorContext } from "../../core/EditorContext"; +import { useExtensionContext } from "../../core/ExtensionContext"; +import Button from "@mui/material/Button"; +import Divider from "@mui/material/Divider"; +import Undo from "@mui/icons-material/Undo"; +import Redo from "@mui/icons-material/Redo"; +import { Menu, MenuItem, Tooltip } from "@mui/material"; +import { + CircleOutlined, + CropSquareSharp, + GpsFixed, + HighlightAlt, + HighlightOff +} from "@mui/icons-material"; +import React from "react"; + +export function EditToolbar({ className }: { className?: string }) { + const { mode, changeMode } = useEditorContext(); + const { undoHistory, undo, redoHistory, redo } = useExtensionContext(); + const [anchorEl, setAnchorEl] = React.useState<Element | null>(null); + const open = anchorEl != null; + + const handleClose = () => { + setAnchorEl(null); + }; + + const getPolygonIcon = () => { + switch (mode) { + case EditorMode.EditorPolygonRect: + return <CropSquareSharp className="amp-edit-toolbar__modeicon" />; + case EditorMode.EditorPolygonCircle: + return <CircleOutlined className="amp-edit-toolbar__modeicon" />; + default: + return <HighlightAlt className="amp-edit-toolbar__modeicon" />; + } + }; + + return ( + <div + className={clsx("amp-edit-toolbar", className, { + "amp-root__topbar--hide": mode === EditorMode.Initial, + })} + > + <div className="amp-edit-toolbar__modescroll"> + <div className="amp-edit-toolbar__modes"> + <Tooltip title="Click to reposition the Focal Point."> + <Button + variant="contained" + color={mode === EditorMode.EditorPoi ? "primary" : "secondary"} + onClick={() => changeMode(EditorMode.EditorPoi)} + disableElevation + > + <GpsFixed className="amp-edit-toolbar__modeicon" /> + Focal Point + </Button> + </Tooltip> + + <Tooltip title="Click to place a new Hotspot, or drag an existing one."> + <Button + variant="contained" + color={ + mode === EditorMode.EditorHotspot ? "primary" : "secondary" + } + onClick={() => changeMode(EditorMode.EditorHotspot)} + disableElevation + > + <HighlightOff className="amp-edit-toolbar__modeicon amp-edit-toolbar__rot45" /> + Hotspots + </Button> + </Tooltip> + + <Tooltip title="Click to place a new Polygon Hotspot, or drag an existing one."> + <Button + variant="contained" + color={ + mode === EditorMode.EditorGrab || + mode === EditorMode.EditorPolygonCircle || + mode === EditorMode.EditorPolygonRect + ? "primary" + : "secondary" + } + onClick={(evt) => { + changeMode(EditorMode.EditorGrab); + setAnchorEl(evt.currentTarget); + }} + disableElevation + > + {getPolygonIcon()} + Polygon Hotspot + </Button> + </Tooltip> + <Menu anchorEl={anchorEl} open={open} onClose={handleClose}> + <MenuItem + onClick={() => { + changeMode(EditorMode.EditorPolygonRect); + handleClose(); + }} + > + Rectangular Hotspot + </MenuItem> + <MenuItem + onClick={() => { + changeMode(EditorMode.EditorPolygonCircle); + handleClose(); + }} + > + Circular Hotspot + </MenuItem> + </Menu> + + <Divider orientation="vertical" variant="middle" flexItem /> + + <Button + variant="contained" + color="secondary" + className="amp-edit-toolbar__reset" + disableElevation + disabled={undoHistory.length === 0} + onClick={() => { + if (undo) { + undo(); + } + }} + > + <Undo /> + </Button> + + <Button + variant="contained" + color="secondary" + className="amp-edit-toolbar__reset" + disableElevation + disabled={redoHistory.length === 0} + onClick={() => { + if (redo) { + redo(); + } + }} + > + <Redo /> + </Button> + </div> + </div> + <div className="amp-edit-toolbar__right"> + <Button + variant="contained" + color="primary" + onClick={() => changeMode(EditorMode.Initial)} + disableElevation + > + Done + </Button> + </div> + </div> + ); +} diff --git a/src/preview/mode-buttons/mode-buttons.css b/src/preview/mode-buttons/mode-buttons.css new file mode 100644 index 0000000..b8d9439 --- /dev/null +++ b/src/preview/mode-buttons/mode-buttons.css @@ -0,0 +1,29 @@ +.amp-mode-buttons { + width: 100%; + height: 100%; + display: flex; + + flex-direction: row; + justify-content: center; + align-items: center; + + background-color: rgba(41,51,63,.8); + transition: all .3s; + opacity: 0; + + position: absolute; + z-index: 101; +} + +.amp-mode-buttons button { + margin: 10px; +} + +.amp-mode-buttons:hover { + opacity: 1; +} + +.amp-mode-buttons__hide { + opacity: 0; + pointer-events: none; +} diff --git a/src/preview/mode-buttons/mode-buttons.tsx b/src/preview/mode-buttons/mode-buttons.tsx new file mode 100644 index 0000000..14898fa --- /dev/null +++ b/src/preview/mode-buttons/mode-buttons.tsx @@ -0,0 +1,81 @@ +import Fab from "@mui/material/Fab"; +import AddIcon from "@mui/icons-material/Add"; +import EditIcon from "@mui/icons-material/Edit"; +import SwapHorizIcon from "@mui/icons-material/SwapHoriz"; +import DeleteIcon from "@mui/icons-material/Delete"; +import "./mode-buttons.css"; +import Tooltip from "@mui/material/Tooltip"; +import { useExtensionContext } from "../../core/ExtensionContext"; +import { EditorMode, useEditorContext } from "../../core/EditorContext"; + +export function ModeButtons() { + const { sdk, field, setField, clearUndo } = useExtensionContext(); + const { mode, changeMode } = useEditorContext(); + + const showButtons = mode === EditorMode.Initial; + const hasImage = field && field.image.id; + + const modeButton = async (mode: EditorMode): Promise<void> => { + if (sdk && field && setField && clearUndo) { + switch (mode) { + case EditorMode.Swap: + field.image = await sdk.mediaLink.getImage(); + + field.poi = {} as any; + field.hotspots = []; + field.polygons = []; + + clearUndo(); + setField(); + changeMode(EditorMode.EditorPoi); + break; + case EditorMode.Delete: + field.image = { _empty: true } as any; + field.poi = {} as any; + field.hotspots = []; + field.polygons = []; + clearUndo(); + setField(); + break; + default: + changeMode(mode); + break; + } + } + }; + + if (!showButtons) { + return <></>; + } + + return ( + <div className="amp-mode-buttons"> + {hasImage && ( + <> + <Tooltip title="Edit image & focal point"> + <Fab onClick={() => modeButton(EditorMode.EditorPoi)}> + <EditIcon /> + </Fab> + </Tooltip> + <Tooltip title="Replace"> + <Fab onClick={() => modeButton(EditorMode.Swap)}> + <SwapHorizIcon /> + </Fab> + </Tooltip> + <Tooltip title="Remove"> + <Fab onClick={() => modeButton(EditorMode.Delete)}> + <DeleteIcon /> + </Fab> + </Tooltip> + </> + )} + {!hasImage && ( + <Tooltip title="Set image"> + <Fab onClick={() => modeButton(EditorMode.Swap)}> + <AddIcon /> + </Fab> + </Tooltip> + )} + </div> + ); +} diff --git a/src/preview/polygon/polygon-helper.ts b/src/preview/polygon/polygon-helper.ts new file mode 100644 index 0000000..74e6025 --- /dev/null +++ b/src/preview/polygon/polygon-helper.ts @@ -0,0 +1,45 @@ +import { ShoppableImagePoint } from "../../core/ShoppableImageData"; + +export class PolygonHelper { + static box( + x: number, + y: number, + w: number, + h: number + ): ShoppableImagePoint[] { + return [ + { x, y }, + { x: x + w, y }, + { x: x + w, y: y + h }, + { x, y: y + h }, + ]; + } + + static circle( + x: number, + y: number, + xr: number, + yr: number + ): ShoppableImagePoint[] { + const circleEdgeDist = 0.37; + const circleCornerDist = 0.13; + + return [ + { x: x + circleEdgeDist * xr, y: y }, + { x: x + (1 - circleEdgeDist) * xr, y: y }, + { x: x + (1 - circleCornerDist) * xr, y: y + circleCornerDist * yr }, + { x: x + xr, y: y + circleEdgeDist * yr }, + { x: x + xr, y: y + (1 - circleEdgeDist) * yr }, + { + x: x + (1 - circleCornerDist) * xr, + y: y + (1 - circleCornerDist) * yr, + }, + { x: x + (1 - circleEdgeDist) * xr, y: y + yr }, + { x: x + circleEdgeDist * xr, y: y + yr }, + { x: x + circleCornerDist * xr, y: y + (1 - circleCornerDist) * yr }, + { x: x, y: y + (1 - circleEdgeDist) * yr }, + { x: x, y: y + circleEdgeDist * yr }, + { x: x + circleCornerDist * xr, y: y + circleCornerDist * yr }, + ]; + } +} diff --git a/src/preview/polygon/polygon.tsx b/src/preview/polygon/polygon.tsx new file mode 100644 index 0000000..9eca57b --- /dev/null +++ b/src/preview/polygon/polygon.tsx @@ -0,0 +1,103 @@ +import React, { SVGProps } from "react"; +import { ShoppableImagePoint } from "../../core/ShoppableImageData"; + +export interface PolygonBounds { + x: number; + y: number; + w: number; + h: number; +} + +export interface SVGPath { + bounds: PolygonBounds; + path: string; +} + +export const pointsToSVGPath = (points: ShoppableImagePoint[]): SVGPath => { + let path = ""; + + const bounds = { + x: Infinity, + y: Infinity, + w: -Infinity, + h: -Infinity, + }; + + for (let point of points) { + if (point.x < bounds.x) bounds.x = point.x; + if (point.y < bounds.y) bounds.y = point.y; + if (point.x > bounds.w) bounds.w = point.x; + if (point.y > bounds.h) bounds.h = point.y; + } + + bounds.w -= bounds.x; + bounds.h -= bounds.y; + + for (let i = 0; i < points.length; i++) { + const point = points[i]; + + const x = point.x - bounds.x; + const y = point.y - bounds.y; + + if (i === 0) { + path += `M ${x} ${y}`; + } else { + path += ` L ${x} ${y}`; + } + } + + path += " Z"; + + return { + bounds, + path, + }; +}; + +export function Polygon({ + polygon, + className, + size, + polyRef, + svgProps, +}: { + polygon: SVGPath; + size: { x: number; y: number }; + className?: string; + polyRef?: React.ForwardedRef<SVGSVGElement>; + svgProps?: SVGProps<unknown>; +}) { + return ( + <svg + viewBox={`0 0 ${polygon.bounds.w} ${polygon.bounds.h}`} + className={className} + preserveAspectRatio="none" + style={{ + width: polygon.bounds.w * size.x, + height: polygon.bounds.h * size.y, + left: polygon.bounds.x * size.x, + top: polygon.bounds.y * size.y, + + strokeWidth: 1.5 / size.x + "px", + strokeDasharray: 5 / size.x + "px", + }} + {...svgProps} + ref={polyRef} + > + <path d={polygon.path}></path> + </svg> + ); +} + +interface PolygonProps { + polygon: SVGPath; + size: { x: number; y: number }; + className?: string; +} + +export const PolygonForwardRef = React.forwardRef< + SVGSVGElement, + SVGProps<unknown> & PolygonProps +>((props, ref) => { + return <Polygon {...props} svgProps={props} polyRef={ref} />; +}); diff --git a/src/preview/preview-canvas/mouse-state.ts b/src/preview/preview-canvas/mouse-state.ts new file mode 100644 index 0000000..9563b66 --- /dev/null +++ b/src/preview/preview-canvas/mouse-state.ts @@ -0,0 +1,11 @@ +export class MouseState { + isMouseDown = false; + + mouseDown() { + this.isMouseDown = true; + } + + mouseUp() { + this.isMouseDown = false; + } +} diff --git a/src/preview/preview-canvas/preview-canvas.css b/src/preview/preview-canvas/preview-canvas.css new file mode 100644 index 0000000..5e57ff0 --- /dev/null +++ b/src/preview/preview-canvas/preview-canvas.css @@ -0,0 +1,96 @@ +.amp-preview-canvas { + height: 458px; + display: flex; + justify-content: center; + align-items: center; + overflow: hidden; + position: relative; +} + +.amp-preview-canvas__image { + max-width: 100%; + max-height: 100%; + opacity: 1; + transition: opacity 0.33s; + position: absolute; +} + +.amp-preview-canvas__image--hide { + opacity: 0; +} + +.amp-preview-canvas__interactive { + position: absolute; +} + +.amp-preview-canvas__focalpoint { + position: absolute; + border: 1px dashed rgba(255, 255, 255, 0.75);; + background-color: rgba(0, 41, 131, 0.33); + transition: opacity 0.33s; + display: flex; + justify-content: center; + align-items: center; +} + +.amp-preview-canvas__focalcircle { + border: 1px solid white; + background-color: black; + + opacity: 0.33; + width: 40%; + height: 40%; + + border-radius: 50%; +} + +.amp-preview-canvas__focalpoint--inactive { + opacity: 0.33; +} + +.amp-preview-canvas__hotspot { + position: absolute; + border: 1px solid white; + background-color: rgba(0, 41, 131, 0.33); + transition: background-color 0.33s, opacity 0.33s; + + width: 40px; + height: 40px; + + margin: -20px; + + border-radius: 50%; +} + +.amp-preview-canvas__hotspotplus { + width: 40px; + height: 40px; + fill: white; +} + +.amp-preview-canvas__hotspot--inactive { + opacity: 0.33; +} + +.amp-preview-canvas__hotspot--selected { + background-color: rgba(0, 153, 255, 0.33); + z-index: 1; +} + +.amp-preview-canvas__polygon { + position: absolute; + stroke: white; + stroke-dasharray: 2; + fill: rgba(0, 41, 131, 0.33); + transition: fill 0.33s, opacity 0.33s; +} + +.amp-preview-canvas__polygon--inactive { + opacity: 0.33; +} + +.amp-preview-canvas__polygon--selected { + fill: rgba(0, 153, 255, 0.33); + outline: 1px solid #039be5; + z-index: 1; +} \ No newline at end of file diff --git a/src/preview/preview-canvas/preview-canvas.tsx b/src/preview/preview-canvas/preview-canvas.tsx new file mode 100644 index 0000000..54ed91f --- /dev/null +++ b/src/preview/preview-canvas/preview-canvas.tsx @@ -0,0 +1,709 @@ +import "./preview-canvas.css"; +import clsx from "clsx"; +import { useEffect, useState } from "react"; +import { useExtensionContext } from "../../core/ExtensionContext"; +import { ModeButtons } from "../mode-buttons/mode-buttons"; +import { CircularProgress } from "@mui/material"; +import React from "react"; +import { + ShoppableImageHotspot, + ShoppableImagePoi, + ShoppableImagePoint, + ShoppableImagePolygon, +} from "../../core/ShoppableImageData"; +import { MouseState } from "./mouse-state"; +import { + EditorMode, + MetadataSelectionMode, + MetadataSelectionTarget, + MetadataSelectionType, + useEditorContext, +} from "../../core/EditorContext"; +import { pointsToSVGPath, Polygon, SVGPath } from "../polygon/polygon"; +import { PolygonHelper } from "../polygon/polygon-helper"; +import { useWindowContext } from "../../core/WindowContext"; +import { v4 as uuidv4 } from "uuid"; + +export function PreviewCanvas() { + const { mode, selection, setSelection } = useEditorContext(); + const { sdk, field, setField, setUndo } = useExtensionContext(); + const windowSize = useWindowContext(); + const [loaded, setLoaded] = useState(false); + const [cursor, setCursor] = useState("default"); + const [imageSize, setImageSize] = useState({ w: -1, h: -1 }); + const [grabOffset, setGrabOffset] = useState({ x: 0, y: 0 }); + const [mouseState] = useState(new MouseState()); + + const imageRef = React.createRef<HTMLImageElement>(); + const canvasRef = React.createRef<HTMLDivElement>(); + + const targetHeight = 458; + const targetWidth = windowSize.w; + const targetAspect = targetWidth / targetHeight; + + let polygons: SVGPath[] = []; + + const imageLoaded = () => { + setLoaded(true); + if (imageRef.current) { + setImageSize({ w: imageRef.current.width, h: imageRef.current.height }); + } + }; + + let imageStyle: any = {}; + let canvas: JSX.Element | undefined; + if (loaded) { + const widthBounded = imageSize.w / imageSize.h > targetAspect; + + const canvasHeight = widthBounded + ? (imageSize.h / imageSize.w) * targetWidth + : targetHeight; + const canvasWidth = widthBounded + ? targetWidth + : (imageSize.w / imageSize.h) * targetHeight; + + imageStyle = widthBounded ? { minWidth: "100%" } : { minHeight: "100%" }; + + const unitScale = widthBounded ? targetHeight / targetWidth : 1; + + const aspect = { + x: unitScale * (widthBounded ? 1 : canvasHeight / canvasWidth), + y: unitScale * (widthBounded ? canvasWidth / canvasHeight : 1), + }; + + const size = { x: canvasWidth, y: canvasHeight }; + + if (field && field.polygons) { + polygons = field.polygons.map((polygon) => + pointsToSVGPath(polygon.points) + ); + } + + const scaleSize = (poi: ShoppableImagePoi): any => { + return { + transform: `translate(${poi.x * canvasWidth}px, ${ + poi.y * canvasHeight + }px)`, + width: poi.w * canvasWidth + "px", + height: poi.h * canvasHeight + "px", + }; + }; + + const scaleHotspot = (hotspot: ShoppableImageHotspot): any => { + return { + transform: `translate(${hotspot.points.x * canvasWidth}px, ${ + hotspot.points.y * canvasHeight + }px)`, + }; + }; + + const getPageOffset = (elem: HTMLElement): { x: number; y: number } => { + const rect = elem.getBoundingClientRect(); + + return { + x: rect.x, + y: rect.y + }; + }; + + const boundPoi = (poi: ShoppableImagePoi): ShoppableImagePoi => { + if (poi.x < 0) poi.x = 0; + if (poi.y < 0) poi.y = 0; + if (poi.x + poi.w > 1) poi.x = 1 - poi.w; + if (poi.y + poi.h > 1) poi.y = 1 - poi.h; + + return poi; + }; + + const isHotPolyMode = (): boolean => { + return ( + mode === EditorMode.EditorPolygonRect || + mode === EditorMode.EditorPolygonCircle || + mode === EditorMode.EditorHotspot || + mode === EditorMode.EditorGrab + ); + }; + + type ResizeAnchor = { x: number; y: number }; + + interface ClickedPolygonResult { + polygon?: ShoppableImagePolygon | undefined; + type: MetadataSelectionType; + anchor?: ResizeAnchor; + bestDistanceSquared: number; + } + + const getClickedPolygon = (x: number, y: number): ClickedPolygonResult => { + // Step 1: Find the polygon with the lowest distance. + // This is used to select polygons when the mouse overlaps multiple. + + let bestIndex = -1; + let bestDistanceSquared = Infinity; + let bestType = MetadataSelectionType.Default; + let anchor: ResizeAnchor | undefined; + + const resizeMarginX = 0.01 * aspect.x; + const resizeMarginY = 0.01 * aspect.y; + + let index = 0; + if (field && field.polygons) { + for (const polygon of polygons) { + // First, does the polygon overlap the mouse? + const bounds = polygon.bounds; + const startX = bounds.x - resizeMarginX; + const startY = bounds.y - resizeMarginY; + const endX = bounds.x + bounds.w + resizeMarginX; + const endY = bounds.y + bounds.h + resizeMarginY; + if (x >= startX && y >= startY && x <= endX && y <= endY) { + let type = MetadataSelectionType.Default; + + // 1 indicates positive resize, 0 negative. + let resizeX: number | undefined; + let resizeY: number | undefined; + + if (x > bounds.x + bounds.w - resizeMarginX) { + resizeX = 1; + } else if (x < bounds.x + resizeMarginX) { + resizeX = 0; + } + + if (y > bounds.y + bounds.h - resizeMarginY) { + resizeY = 1; + } else if (y < bounds.y + resizeMarginY) { + resizeY = 0; + } + + if (resizeX !== undefined) { + type = + resizeY !== undefined + ? MetadataSelectionType.Resize + : MetadataSelectionType.ResizeX; + + // 0 indicates anchor at x,y. 1 indicates anchor at width,height. + anchor = { x: 1 - resizeX, y: 1 - (resizeY || 0) }; + } else if (resizeY !== undefined) { + type = MetadataSelectionType.ResizeY; + + anchor = { x: 0, y: 1 - resizeY }; + } + + const center = { + x: bounds.x + bounds.w / 2, + y: bounds.y + bounds.h / 2, + }; + + const dV = [ + Math.abs(x - center.x) / aspect.x, + Math.abs(y - center.y) / aspect.y, + ]; + + const distSquared = + selection && selection.target === field.polygons[index] + ? 0 + : dV[0] * dV[0] + dV[1] * dV[1]; + + if (distSquared < bestDistanceSquared) { + bestIndex = index; + bestDistanceSquared = distSquared; + bestType = type; + } + } + + index++; + } + } + + if (field && field.polygons && bestIndex != null) { + return { + polygon: field.polygons[bestIndex], + type: bestType, + anchor, + bestDistanceSquared, + }; + } else { + return { + polygon: undefined, + type: MetadataSelectionType.Default, + anchor, + bestDistanceSquared, + }; + } + }; + + const getClickedHotspot = ( + x: number, + y: number, + bestDistanceSquared = Infinity + ): ShoppableImageHotspot | undefined => { + // Step 1: Find the hotspot with the lowest distance. + + let bestHotspot: ShoppableImageHotspot | undefined; + + if (field && field.hotspots) { + for (const hotspot of field.hotspots) { + const point = hotspot.points; + + const dV = [ + Math.abs(x - point.x) / aspect.x, + Math.abs(y - point.y) / aspect.y, + ]; + const distSquared = dV[0] * dV[0] + dV[1] * dV[1]; + + if (distSquared < bestDistanceSquared) { + bestHotspot = hotspot; + bestDistanceSquared = distSquared; + } + } + } + + if (bestHotspot !== undefined) { + // Step 2: Must be clicking near a hotspot to grab it. + const hotspotGrabSizeSquared = 0.05 * 0.05; + if (bestDistanceSquared > hotspotGrabSizeSquared) { + bestHotspot = undefined; + } + } + return bestHotspot; + }; + + const onDrag = (evt: React.MouseEvent<HTMLDivElement, MouseEvent>) => { + if (canvasRef.current && field && setField) { + const offset = getPageOffset(canvasRef.current); + const x = (evt.pageX - offset.x) / canvasWidth; + const y = (evt.pageY - offset.y) / canvasHeight; + + const markUndo = (condition: boolean | undefined) => { + if (condition && selection && setUndo && !selection.createdUndo) { + setUndo(); + selection.createdUndo = true; + } + }; + + switch (mode) { + case EditorMode.EditorPoi: + const width = 0.15 * aspect.x; + const height = 0.15 * aspect.y; + + const poi = boundPoi({ + x: x - width / 2, + y: y - height / 2, + w: width, + h: height, + }); + + field.poi = poi; + break; + + case EditorMode.EditorGrab: + case EditorMode.EditorHotspot: + case EditorMode.EditorPolygonRect: + case EditorMode.EditorPolygonCircle: + if (selection) { + switch (selection.mode) { + case MetadataSelectionMode.Hotspot: + const points = { + x: x + grabOffset.x, + y: y + grabOffset.y, + }; + + const oldPoints = (selection.target as ShoppableImageHotspot) + .points; + + markUndo( + oldPoints.x !== points.x || oldPoints.y !== points.y + ); + + (selection.target as ShoppableImageHotspot).points = points; + break; + case MetadataSelectionMode.Polygon: + if (field.polygons) { + const polygon = selection.target as ShoppableImagePolygon; + const polyIndex = field.polygons.indexOf(polygon); + const cPoly = polygons[polyIndex]; + + if (selection.lastPosition) { + const offset = { + x: x - selection.lastPosition.x, + y: y - selection.lastPosition.y, + }; + + if (selection.type === MetadataSelectionType.Default) { + markUndo(offset.x !== 0 || offset.y !== 0); + + polygon.points = polygon.points.map((point) => { + return { + x: point.x + offset.x, + y: point.y + offset.y, + }; + }); + } else { + const resizeBoth = + selection.type === MetadataSelectionType.Resize; + const resizeX = + resizeBoth || + selection.type === MetadataSelectionType.ResizeX; + const resizeY = + resizeBoth || + selection.type === MetadataSelectionType.ResizeY; + + const minWidth = 0.05 * aspect.x; + const minHeight = 0.05 * aspect.y; + + const anchor = selection.resizeAnchor; + + const anchorEdgeX = + cPoly.bounds.x + (anchor?.x || 0) * cPoly.bounds.w; + const anchorEdgeY = + cPoly.bounds.y + (anchor?.y || 0) * cPoly.bounds.h; + + // The distance from mouse is flipped with the anchor at bottom right. + const mulX = ((anchor?.x || 0) - 0.5) * -2; + const mulY = ((anchor?.y || 0) - 0.5) * -2; + + const newWidth = Math.max( + minWidth, + resizeX ? (x - anchorEdgeX) * mulX : cPoly.bounds.w + ); + + const newHeight = Math.max( + minHeight, + resizeY ? (y - anchorEdgeY) * mulY : cPoly.bounds.h + ); + + const ratioX = newWidth / cPoly.bounds.w; + const ratioY = newHeight / cPoly.bounds.h; + + let offset: { x: number; y: number }; + if (selection.resizeAnchor) { + offset = { + x: + (cPoly.bounds.w - newWidth) * + selection.resizeAnchor.x, + y: + (cPoly.bounds.h - newHeight) * + selection.resizeAnchor.y, + }; + } else { + offset = { x: 0, y: 0 }; + } + + markUndo(ratioX !== 1 || ratioY !== 1); + + polygon.points = polygon.points.map((point) => { + return { + x: + (point.x - cPoly.bounds.x) * ratioX + + cPoly.bounds.x + + offset.x, + y: + (point.y - cPoly.bounds.y) * ratioY + + cPoly.bounds.y + + offset.y, + }; + }); + } + } + + selection.lastPosition = { x, y }; + } + break; + } + } + break; + } + + setField(); + } + }; + + const getMouseType = ( + type: MetadataSelectionType, + anchor?: ResizeAnchor + ): string => { + switch (type) { + case MetadataSelectionType.Default: + return "grab"; + case MetadataSelectionType.ResizeX: + return "ew-resize"; + case MetadataSelectionType.ResizeY: + return "ns-resize"; + case MetadataSelectionType.Resize: + return anchor && anchor.x !== anchor.y + ? "nesw-resize" + : "nwse-resize"; + } + return "default"; + }; + + const mouseMove = (evt: React.MouseEvent<HTMLDivElement, MouseEvent>) => { + let targetMouse = "default"; + + if (mouseState.isMouseDown) { + if (selection && selection.target) { + if (selection.type === MetadataSelectionType.Default) { + targetMouse = "grabbing"; + } else { + targetMouse = getMouseType(selection.type, selection.resizeAnchor); + } + } + + onDrag(evt); + } else if (canvasRef.current) { + const offset = getPageOffset(canvasRef.current); + const x = (evt.pageX - offset.x) / canvasWidth; + const y = (evt.pageY - offset.y) / canvasHeight; + + if (isHotPolyMode()) { + const { polygon, type, anchor, bestDistanceSquared } = + getClickedPolygon(x, y); + const hover = getClickedHotspot(x, y, bestDistanceSquared); + + if (hover) { + targetMouse = "grab"; + } else if (polygon) { + targetMouse = getMouseType(type, anchor); + } else if (mode !== EditorMode.EditorGrab) { + targetMouse = "copy"; + } + } + } + + if (cursor !== targetMouse) { + setCursor(targetMouse); + } + }; + + const mouseDown = (evt: React.MouseEvent<HTMLDivElement, MouseEvent>) => { + mouseState.mouseDown(); + if (canvasRef.current && field) { + const offset = getPageOffset(canvasRef.current); + const x = (evt.pageX - offset.x) / canvasWidth; + const y = (evt.pageY - offset.y) / canvasHeight; + + switch (mode) { + case EditorMode.EditorPoi: + // POI does not need selection. + if (setUndo) setUndo(); + onDrag(evt); + break; + + case EditorMode.EditorGrab: + case EditorMode.EditorHotspot: + case EditorMode.EditorPolygonCircle: + case EditorMode.EditorPolygonRect: + if (!field.polygons) { + field.polygons = []; + } + + if (!field.hotspots) { + field.hotspots = []; + } + + let target: MetadataSelectionTarget; + let selectionMode: MetadataSelectionMode; + + let { polygon, type, anchor, bestDistanceSquared } = + getClickedPolygon(x, y); + + let moveHotspot = getClickedHotspot(x, y, bestDistanceSquared); + + let isNew = false; + + if (moveHotspot) { + selectionMode = MetadataSelectionMode.Hotspot; + target = moveHotspot; + } else if (polygon) { + selectionMode = MetadataSelectionMode.Polygon; + target = polygon; + } else { + isNew = true; + + // Didn't click a hostpot or a polygon. + // Depeding on mode, create a new one. + + if (mode === EditorMode.EditorHotspot) { + moveHotspot = { + id: uuidv4(), + target: "target", + selector: ".selector", + points: { + x, + y, + }, + }; + + if (setUndo) setUndo(); + field.hotspots.push(moveHotspot); + + selectionMode = MetadataSelectionMode.Hotspot; + target = moveHotspot; + } else { + let points: ShoppableImagePoint[]; + if (mode === EditorMode.EditorPolygonRect) { + points = PolygonHelper.box( + x, + y, + 0.1 * aspect.x, + 0.1 * aspect.y + ); + } else { + points = PolygonHelper.circle( + x, + y, + 0.1 * aspect.x, + 0.1 * aspect.y + ); + } + + polygon = { + id: uuidv4(), + target: "target", + selector: ".selector", + points: points, + }; + + if (setUndo) setUndo(); + field.polygons.push(polygon); + + type = MetadataSelectionType.Resize; + + selectionMode = MetadataSelectionMode.Polygon; + target = polygon; + } + } + + if (selectionMode === MetadataSelectionMode.Hotspot) { + setGrabOffset({ + x: (target as ShoppableImageHotspot).points.x - x, + y: (target as ShoppableImageHotspot).points.y - y, + }); + } else { + setGrabOffset({ + x: x, + y: y, + }); + } + + setSelection({ + target, + mode: selectionMode, + type: type, + lastPosition: { x, y }, + resizeAnchor: anchor, + createdUndo: isNew, + }); + break; + } + } + }; + + const mouseUp = (evt: React.MouseEvent<HTMLDivElement, MouseEvent>) => { + mouseState.mouseUp(); + mouseMove(evt); + }; + + canvas = ( + <div + className="amp-preview-canvas__interactive" + style={{ + width: canvasWidth + "px", + height: canvasHeight + "px", + cursor, + }} + ref={canvasRef} + onMouseMove={mouseMove} + onMouseDown={mouseDown} + onMouseUp={mouseUp} + > + {field && field.poi && field.poi.x != null && ( + <div + className={clsx("amp-preview-canvas__focalpoint", { + "amp-preview-canvas__focalpoint--inactive": + mode !== EditorMode.EditorPoi, + })} + style={scaleSize(field.poi)} + > + <div className="amp-preview-canvas__focalcircle"></div> + </div> + )} + + {field && + field.hotspots && + field.hotspots.map((hotspot, index) => ( + <div + key={hotspot.id} + className={clsx("amp-preview-canvas__hotspot", { + "amp-preview-canvas__hotspot--selected": + selection && selection.target === hotspot, + "amp-preview-canvas__hotspot--inactive": !isHotPolyMode(), + })} + style={scaleHotspot(hotspot)} + > + <svg + viewBox="0 0 20 20" + className={clsx("amp-preview-canvas__hotspotplus")} + > + <rect x="9.15" y="3.5" width="1.7" height="13"></rect> + <rect y="9.15" x="3.5" width="13" height="1.7"></rect> + </svg> + </div> + ))} + + {field && + field.polygons && + polygons.map((polygon, index) => ( + <Polygon + key={field.polygons![index].id} + size={size} + className={clsx("amp-preview-canvas__polygon", { + "amp-preview-canvas__polygon--selected": + selection && + selection.target === + (field.polygons as ShoppableImagePolygon[])[index], + "amp-preview-canvas__polygon--inactive": !isHotPolyMode(), + })} + polygon={polygon} + ></Polygon> + ))} + </div> + ); + } + + let image: JSX.Element | undefined; + let src = "invalid"; + if (field && field.image.id) { + const imageHost = sdk?.stagingEnvironment || field.image.defaultHost; + src = `https://${imageHost}/i/${field.image.endpoint}/${encodeURIComponent( + field.image.name + )}`; + + image = ( + <img + src={src} + ref={imageRef} + alt="" + crossOrigin="anonymous" + className={clsx("amp-preview-canvas__image", { + "amp-preview-canvas__image--hide": !loaded, + })} + style={imageStyle} + onLoad={() => { + imageLoaded(); + }} + /> + ); + } + + useEffect(() => { + setLoaded(false); + }, [src]); + + return ( + <div className="amp-preview-canvas"> + {image || false} + {image && !loaded && <CircularProgress />} + {canvas || false} + <ModeButtons /> + </div> + ); +} diff --git a/src/preview/title/title.css b/src/preview/title/title.css new file mode 100644 index 0000000..64b6d67 --- /dev/null +++ b/src/preview/title/title.css @@ -0,0 +1,5 @@ +.amp-title { + color: #666; + font-size: 13px; + margin: 5px 0; +} diff --git a/src/preview/title/title.tsx b/src/preview/title/title.tsx new file mode 100644 index 0000000..b446aad --- /dev/null +++ b/src/preview/title/title.tsx @@ -0,0 +1,13 @@ +import "./title.css"; +import { useExtensionContext } from "../../core/ExtensionContext"; + +export function Title() { + const { params } = useExtensionContext(); + const title = params?.title; + + return title != null ? ( + <div className="amp-title">{title}</div> + ) : ( + <></> + ); +} diff --git a/src/react-app-env.d.ts b/src/react-app-env.d.ts new file mode 100644 index 0000000..6431bc5 --- /dev/null +++ b/src/react-app-env.d.ts @@ -0,0 +1 @@ +/// <reference types="react-scripts" /> diff --git a/src/theme.ts b/src/theme.ts new file mode 100644 index 0000000..321bb7d --- /dev/null +++ b/src/theme.ts @@ -0,0 +1,41 @@ +import { createTheme } from "@mui/material/styles"; + +const primaryBlue = "#039be5"; + +export const theme = createTheme({ + palette: { + primary: { + main: primaryBlue, + contrastText: "#ffffff", + }, + secondary: { + main: "#ffffff", + }, + error: { + main: "#ff3366", + }, + contrastThreshold: 3, + }, + components: { + MuiButton: { + defaultProps: { + disableElevation: true + }, + styleOverrides: { + root: { + textTransform: 'none' + } + } + }, + MuiFab: { + styleOverrides: { + root: { + color: 'white', + '&:hover': { + backgroundColor: primaryBlue + } + } + } + }, + }, +}); diff --git a/src/visualization/vis-container/vis-container.css b/src/visualization/vis-container/vis-container.css new file mode 100644 index 0000000..a3d91a4 --- /dev/null +++ b/src/visualization/vis-container/vis-container.css @@ -0,0 +1,11 @@ +.amp-vis-container-toolbar { + display: flex; + justify-content: flex-end; + background-color: var(--color-lighter-grey); + width: 100%; + height: 42px; +} + +.amp-vis-container-toolbar__group { + flex-direction: row !important; +} \ No newline at end of file diff --git a/src/visualization/vis-container/vis-container.tsx b/src/visualization/vis-container/vis-container.tsx new file mode 100644 index 0000000..ebaee1e --- /dev/null +++ b/src/visualization/vis-container/vis-container.tsx @@ -0,0 +1,37 @@ +import "./vis-container.css"; +import { Checkbox, FormControlLabel, FormGroup } from "@mui/material"; +import { useState } from "react"; +import { VisPage } from "../vis-page/vis-page"; + +export function VisContainer({ vse }: { vse: string }) { + const [hotspotHide, setHotspotHide] = useState(false); + const [scaleToFit, setScaleToFit] = useState(false); + + return ( + <> + <div className="amp-vis-container-toolbar"> + <FormGroup className="amp-vis-container-toolbar__group"> + <FormControlLabel + control={ + <Checkbox + checked={hotspotHide} + onChange={(evt) => setHotspotHide(evt.target.checked)} + /> + } + label="Hide Hotspots" + /> + <FormControlLabel + control={ + <Checkbox + checked={scaleToFit} + onChange={(evt) => setScaleToFit(evt.target.checked)} + /> + } + label="Scale to Fit" + /> + </FormGroup> + </div> + <VisPage hotspotHide={hotspotHide} scaleToFit={scaleToFit} vse={vse} /> + </> + ); +} diff --git a/src/visualization/vis-page/vis-page.css b/src/visualization/vis-page/vis-page.css new file mode 100644 index 0000000..26ccc98 --- /dev/null +++ b/src/visualization/vis-page/vis-page.css @@ -0,0 +1,91 @@ +.amp-vis-page { + width: 100%; + display: flex; + justify-content: center; + align-items: center; + overflow: hidden; + position: relative; +} + +.amp-vis-page__image { + max-width: 100%; + max-height: 100%; + opacity: 1; + transition: opacity 0.33s; + position: absolute; +} + +.amp-vis-page__image--hide { + opacity: 0; +} + +.amp-vis-page__interactive { + position: absolute; +} + +.amp-vis-page__focalpoint { + position: absolute; + border: 1px dashed rgba(255, 255, 255, 0.75);; + background-color: rgba(0, 0, 0, 0.25); + transition: opacity 0.33s; + display: flex; + justify-content: center; + align-items: center; +} + +.amp-vis-page__focalcircle { + border: 1px solid white; + background-color: black; + + opacity: 0.33; + width: 40%; + height: 40%; + + border-radius: 50%; +} + +.amp-vis-page__focalpoint--hidden { + opacity: 0; +} + +.amp-vis-page__hotspot { + position: absolute; + border: 1px solid white; + background-color: rgba(0, 41, 131, 0.33); + transition: background-color 0.33s, opacity 0.33s; + + width: 40px; + height: 40px; + + margin: -20px; + + border-radius: 50%; +} + +.amp-vis-page__hotspotplus { + width: 40px; + height: 40px; + fill: white; +} + +.amp-vis-page__hotspot--hidden { + opacity: 0; +} + +.amp-vis-page__polygon { + position: absolute; + stroke: white; + stroke-dasharray: 2; + fill: rgba(0, 41, 131, 0.33); + transition: fill 0.33s, opacity 0.33s; +} + +.amp-vis-page__polygon--hidden { + opacity: 0; +} + +.amp-vis-page__polygon--selected { + fill: rgba(0, 153, 255, 0.33); + outline: 1px solid #039be5; + z-index: 1; +} \ No newline at end of file diff --git a/src/visualization/vis-page/vis-page.tsx b/src/visualization/vis-page/vis-page.tsx new file mode 100644 index 0000000..26a4526 --- /dev/null +++ b/src/visualization/vis-page/vis-page.tsx @@ -0,0 +1,225 @@ +import "./vis-page.css"; +import { CircularProgress, Tooltip } from "@mui/material"; +import clsx from "clsx"; +import React from "react"; +import { useEffect, useState } from "react"; +import { + ShoppableImageHotspot, + ShoppableImagePoi, + ShoppableImagePolygon, +} from "../../core/ShoppableImageData"; +import { + pointsToSVGPath, + PolygonForwardRef, + SVGPath, +} from "../../preview/polygon/polygon"; +import { useVisualizationContext } from "../visualization-context"; +import { useWindowContext } from "../../core/WindowContext"; + +export function VisPage({ vse, hotspotHide, scaleToFit }: { vse: string, hotspotHide: boolean, scaleToFit: boolean }) { + const { field } = useVisualizationContext(); + const windowSize = useWindowContext(); + const [loaded, setLoaded] = useState(false); + const [imageSize, setImageSize] = useState({ w: -1, h: -1 }); + const toolbarHeight = 42; + + const targetWidth = windowSize.w; + const targetHeight = windowSize.h - toolbarHeight; + + const imageRef = React.createRef<HTMLImageElement>(); + const canvasRef = React.createRef<HTMLDivElement>(); + + const targetAspect = targetWidth / targetHeight; + + let polygons: SVGPath[] = []; + + const imageLoaded = () => { + setLoaded(true); + if (imageRef.current) { + setImageSize({ w: imageRef.current.width, h: imageRef.current.height }); + } + }; + + const hotspotTitle = (hotspot: ShoppableImageHotspot | ShoppableImagePolygon) => { + return `Target: ${hotspot.target} | Selector: ${hotspot.selector}`; + }; + + if (field && field.polygons) { + polygons = field.polygons.map((polygon) => pointsToSVGPath(polygon.points)); + } + + let imageStyle: any = {}; + let canvas: JSX.Element | undefined; + const hidden = hotspotHide; + + if (field && loaded) { + const widthBounded = imageSize.w / imageSize.h > targetAspect; + + let canvasHeight: number, canvasWidth: number; + + let offsetTransform = ''; + + if (scaleToFit) { + // Scale image to canvas. Focal point is not used. + canvasHeight = widthBounded + ? (imageSize.h / imageSize.w) * targetWidth + : targetHeight; + canvasWidth = widthBounded + ? targetWidth + : (imageSize.w / imageSize.h) * targetHeight; + + imageStyle = widthBounded ? { minWidth: "100%" } : { minHeight: "100%" }; + } else { + // Fill image to canvas, centering on focal point. If the width is the bounding dimension, let it overflow, and vice versa. + canvasHeight = widthBounded + ? targetHeight + : (imageSize.h / imageSize.w) * targetWidth; + canvasWidth = widthBounded + ? (imageSize.w / imageSize.h) * targetHeight + : targetWidth; + + // Determine a position offset based on the focal point, if present. + if (field.poi) { + const poiX = (field.poi.x + field.poi.w / 2 - 0.5) * canvasWidth; + const poiY = (field.poi.y + field.poi.h / 2 - 0.5) * canvasHeight; + + if (widthBounded) { + // Width overflow, center on x. + const maxDist = (canvasWidth - targetWidth) / 2; + + offsetTransform = `translate(${Math.min(maxDist, Math.max(-poiX, -maxDist))}px, 0)`; + } else { + // Height overflow, center on y. + const maxDist = (canvasHeight - targetHeight) / 2; + + offsetTransform = `translate(0, ${Math.min(maxDist, Math.max(-poiY, -maxDist))}px)`; + } + } + + imageStyle = widthBounded ? { height: "100%", maxWidth: "none" } : { width: "100%", maxHeight: "none" }; + } + + imageStyle.transform = offsetTransform; + + const size = { x: canvasWidth, y: canvasHeight }; + + const scaleSize = (poi: ShoppableImagePoi): any => { + return { + transform: `translate(${poi.x * canvasWidth}px, ${ + poi.y * canvasHeight + }px)`, + width: poi.w * canvasWidth + "px", + height: poi.h * canvasHeight + "px", + }; + }; + + const scaleHotspot = (hotspot: ShoppableImageHotspot): any => { + return { + transform: `translate(${hotspot.points.x * canvasWidth}px, ${ + hotspot.points.y * canvasHeight + }px)`, + }; + }; + + canvas = ( + <div + className="amp-vis-page__interactive" + style={{ + width: canvasWidth + "px", + height: canvasHeight + "px", + transform: offsetTransform + }} + ref={canvasRef} + > + {field && field.poi && field.poi.x != null && ( + <div + className={clsx("amp-vis-page__focalpoint", { + "amp-vis-page__focalpoint--hidden": hidden, + })} + style={scaleSize(field.poi)} + > + <div className="amp-vis-page__focalcircle"></div> + </div> + )} + + {field && + field.polygons && + polygons.map((polygon, index) => ( + <Tooltip + key={index} + title={hotspotTitle( + (field.polygons as ShoppableImagePolygon[])[index] + )} + followCursor + > + <PolygonForwardRef + size={size} + className={clsx("amp-vis-page__polygon", { + "amp-vis-page__polygon--hidden": hidden, + })} + polygon={polygon} + ></PolygonForwardRef> + </Tooltip> + ))} + + {field && + field.hotspots && + field.hotspots.map((hotspot, index) => ( + <Tooltip key={index} title={hotspotTitle(hotspot)} followCursor> + <div + className={clsx("amp-vis-page__hotspot", { + "amp-vis-page__hotspot--hidden": hidden, + })} + style={scaleHotspot(hotspot)} + > + <svg + viewBox="0 0 20 20" + className={clsx("amp-vis-page__hotspotplus")} + > + <rect x="9.15" y="3.5" width="1.7" height="13"></rect> + <rect y="9.15" x="3.5" width="13" height="1.7"></rect> + </svg> + </div> + </Tooltip> + ))} + </div> + ); + } + + let image: JSX.Element | undefined; + let src = "invalid"; + if (field && field.image.id) { + const imageHost = vse || field.image.defaultHost; + src = `https://${imageHost}/i/${field.image.endpoint}/${encodeURIComponent( + field.image.name + )}`; + + image = ( + <img + src={src} + ref={imageRef} + alt="" + crossOrigin="anonymous" + className={clsx("amp-vis-page__image", { + "amp-vis-page__image--hide": !loaded, + })} + style={imageStyle} + onLoad={() => { + imageLoaded(); + }} + /> + ); + } + + useEffect(() => { + setLoaded(false); + }, [src]); + + return ( + <div className="amp-vis-page" style={{ height: targetHeight }}> + {image || false} + {image && !loaded && <CircularProgress />} + {canvas || false} + </div> + ); +} diff --git a/src/visualization/visualization-context.tsx b/src/visualization/visualization-context.tsx new file mode 100644 index 0000000..d1c3156 --- /dev/null +++ b/src/visualization/visualization-context.tsx @@ -0,0 +1,51 @@ +import React, { useEffect, useState } from "react"; +import { ShoppableImageData } from "../core/ShoppableImageData"; +import { init } from 'dc-visualization-sdk'; + +interface VisualizationState { + field?: ShoppableImageData; +} + +const defaultVisualizationState: VisualizationState = { +}; + +const VisualizationContext = React.createContext(defaultVisualizationState); + +export function WithVisualizationContext({ + fieldName, + children, +}: { + fieldName: string; + children: React.ReactNode; +}) { + const [state, setState] = useState(defaultVisualizationState); + + useEffect(() => { + init().then(async (sdk) => { + const state: VisualizationState = { + field: (await sdk.form.get({ + format: 'linked', + depth: 'all' + })).content[fieldName] + }; + + sdk.form.changed((model) => { + setState({ ...state, field: model.content[fieldName] as ShoppableImageData }); + }); + + setState({ ...state }); + }).catch((e) => { + console.error(e); + }); + }, [fieldName]); + + return ( + <VisualizationContext.Provider value={state}> + {children} + </VisualizationContext.Provider> + ); +} + +export function useVisualizationContext() { + return React.useContext(VisualizationContext); +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..a273b0c --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx" + }, + "include": [ + "src" + ] +} diff --git a/yarn.lock b/yarn.lock index 13cc812..69be2ec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1098,7 +1098,7 @@ dependencies: regenerator-runtime "^0.13.4" -"@babel/runtime@^7.12.5", "@babel/runtime@^7.9.2": +"@babel/runtime@^7.12.5", "@babel/runtime@^7.13.10", "@babel/runtime@^7.16.0", "@babel/runtime@^7.8.7", "@babel/runtime@^7.9.2": version "7.16.3" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.16.3.tgz#b86f0db02a04187a3c17caa77de69840165d42d5" integrity sha512-WBwekcqacdY2e9AF/Q7WLFUWmdJGJTkbjqTjoMDgXkVZ3ZRUvOPsLb5KdwISoQVsbP+DQzVZW4Zhci0DvpbNTQ== @@ -1161,6 +1161,107 @@ resolved "https://registry.yarnpkg.com/@csstools/normalize.css/-/normalize.css-10.1.0.tgz#f0950bba18819512d42f7197e56c518aa491cf18" integrity sha512-ij4wRiunFfaJxjB0BdrYHIH8FxBJpOwNPhhAcunlmPdXudL1WQV1qoP9un6JsEBAgQH+7UXyyjh0g7jTxXK6tg== +"@emotion/babel-plugin@^11.3.0": + version "11.3.0" + resolved "https://registry.yarnpkg.com/@emotion/babel-plugin/-/babel-plugin-11.3.0.tgz#3a16850ba04d8d9651f07f3fb674b3436a4fb9d7" + integrity sha512-UZKwBV2rADuhRp+ZOGgNWg2eYgbzKzQXfQPtJbu/PLy8onurxlNCLvxMQEvlr1/GudguPI5IU9qIY1+2z1M5bA== + dependencies: + "@babel/helper-module-imports" "^7.12.13" + "@babel/plugin-syntax-jsx" "^7.12.13" + "@babel/runtime" "^7.13.10" + "@emotion/hash" "^0.8.0" + "@emotion/memoize" "^0.7.5" + "@emotion/serialize" "^1.0.2" + babel-plugin-macros "^2.6.1" + convert-source-map "^1.5.0" + escape-string-regexp "^4.0.0" + find-root "^1.1.0" + source-map "^0.5.7" + stylis "^4.0.3" + +"@emotion/cache@^11.5.0": + version "11.5.0" + resolved "https://registry.yarnpkg.com/@emotion/cache/-/cache-11.5.0.tgz#a5eb78cbef8163939ee345e3ddf0af217b845e62" + integrity sha512-mAZ5QRpLriBtaj/k2qyrXwck6yeoz1V5lMt/jfj6igWU35yYlNKs2LziXVgvH81gnJZ+9QQNGelSsnuoAy6uIw== + dependencies: + "@emotion/memoize" "^0.7.4" + "@emotion/sheet" "^1.0.3" + "@emotion/utils" "^1.0.0" + "@emotion/weak-memoize" "^0.2.5" + stylis "^4.0.10" + +"@emotion/hash@^0.8.0": + version "0.8.0" + resolved "https://registry.yarnpkg.com/@emotion/hash/-/hash-0.8.0.tgz#bbbff68978fefdbe68ccb533bc8cbe1d1afb5413" + integrity sha512-kBJtf7PH6aWwZ6fka3zQ0p6SBYzx4fl1LoZXE2RrnYST9Xljm7WfKJrU4g/Xr3Beg72MLrp1AWNUmuYJTL7Cow== + +"@emotion/is-prop-valid@^1.1.0": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@emotion/is-prop-valid/-/is-prop-valid-1.1.0.tgz#29ef6be1e946fb4739f9707def860f316f668cde" + integrity sha512-9RkilvXAufQHsSsjQ3PIzSns+pxuX4EW8EbGeSPjZMHuMx6z/MOzb9LpqNieQX4F3mre3NWS2+X3JNRHTQztUQ== + dependencies: + "@emotion/memoize" "^0.7.4" + +"@emotion/memoize@^0.7.4", "@emotion/memoize@^0.7.5": + version "0.7.5" + resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.7.5.tgz#2c40f81449a4e554e9fc6396910ed4843ec2be50" + integrity sha512-igX9a37DR2ZPGYtV6suZ6whr8pTFtyHL3K/oLUotxpSVO2ASaprmAe2Dkq7tBo7CRY7MMDrAa9nuQP9/YG8FxQ== + +"@emotion/react@^11.5.0": + version "11.5.0" + resolved "https://registry.yarnpkg.com/@emotion/react/-/react-11.5.0.tgz#19b5771bbfbda5e8517e948a2d9064810f0022bd" + integrity sha512-MYq/bzp3rYbee4EMBORCn4duPQfgpiEB5XzrZEBnUZAL80Qdfr7CEv/T80jwaTl/dnZmt9SnTa8NkTrwFNpLlw== + dependencies: + "@babel/runtime" "^7.13.10" + "@emotion/cache" "^11.5.0" + "@emotion/serialize" "^1.0.2" + "@emotion/sheet" "^1.0.3" + "@emotion/utils" "^1.0.0" + "@emotion/weak-memoize" "^0.2.5" + hoist-non-react-statics "^3.3.1" + +"@emotion/serialize@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@emotion/serialize/-/serialize-1.0.2.tgz#77cb21a0571c9f68eb66087754a65fa97bfcd965" + integrity sha512-95MgNJ9+/ajxU7QIAruiOAdYNjxZX7G2mhgrtDWswA21VviYIRP1R5QilZ/bDY42xiKsaktP4egJb3QdYQZi1A== + dependencies: + "@emotion/hash" "^0.8.0" + "@emotion/memoize" "^0.7.4" + "@emotion/unitless" "^0.7.5" + "@emotion/utils" "^1.0.0" + csstype "^3.0.2" + +"@emotion/sheet@^1.0.3": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@emotion/sheet/-/sheet-1.0.3.tgz#00c326cd7985c5ccb8fe2c1b592886579dcfab8f" + integrity sha512-YoX5GyQ4db7LpbmXHMuc8kebtBGP6nZfRC5Z13OKJMixBEwdZrJ914D6yJv/P+ZH/YY3F5s89NYX2hlZAf3SRQ== + +"@emotion/styled@^11.3.0": + version "11.3.0" + resolved "https://registry.yarnpkg.com/@emotion/styled/-/styled-11.3.0.tgz#d63ee00537dfb6ff612e31b0e915c5cf9925a207" + integrity sha512-fUoLcN3BfMiLlRhJ8CuPUMEyKkLEoM+n+UyAbnqGEsCd5IzKQ7VQFLtzpJOaCD2/VR2+1hXQTnSZXVJeiTNltA== + dependencies: + "@babel/runtime" "^7.13.10" + "@emotion/babel-plugin" "^11.3.0" + "@emotion/is-prop-valid" "^1.1.0" + "@emotion/serialize" "^1.0.2" + "@emotion/utils" "^1.0.0" + +"@emotion/unitless@^0.7.5": + version "0.7.5" + resolved "https://registry.yarnpkg.com/@emotion/unitless/-/unitless-0.7.5.tgz#77211291c1900a700b8a78cfafda3160d76949ed" + integrity sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg== + +"@emotion/utils@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@emotion/utils/-/utils-1.0.0.tgz#abe06a83160b10570816c913990245813a2fd6af" + integrity sha512-mQC2b3XLDs6QCW+pDQDiyO/EdGZYOygE8s5N5rrzjSI4M3IejPE/JPndCBwRT9z982aqQNi6beWs1UeayrQxxA== + +"@emotion/weak-memoize@^0.2.5": + version "0.2.5" + resolved "https://registry.yarnpkg.com/@emotion/weak-memoize/-/weak-memoize-0.2.5.tgz#8eed982e2ee6f7f4e44c253e12962980791efd46" + integrity sha512-6U71C2Wp7r5XtFtQzYrW5iKFT67OixrSxjI4MptCHzdSVlgabczzqLe0ZSgnub/5Kp4hSbpDB1tMytZY9pwxxA== + "@eslint/eslintrc@^0.3.0": version "0.3.0" resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.3.0.tgz#d736d6963d7003b6514e6324bec9c602ac340318" @@ -1407,6 +1508,92 @@ "@types/yargs" "^16.0.0" chalk "^4.0.0" +"@mui/core@5.0.0-alpha.54": + version "5.0.0-alpha.54" + resolved "https://registry.yarnpkg.com/@mui/core/-/core-5.0.0-alpha.54.tgz#2c04163552ac536e2026778cc7f7435ce004ba1b" + integrity sha512-8TxdHqDdSb6wjhsnpE5n7qtkFKDG3PUSlVY0gR3VcdsHXscUY13l3VbMQW1brI4D/R9zx5VYmxIHWaHFgw4RtA== + dependencies: + "@babel/runtime" "^7.16.0" + "@emotion/is-prop-valid" "^1.1.0" + "@mui/utils" "^5.1.0" + "@popperjs/core" "^2.4.4" + clsx "^1.1.1" + prop-types "^15.7.2" + react-is "^17.0.2" + +"@mui/icons-material@^5.1.0": + version "5.1.0" + resolved "https://registry.yarnpkg.com/@mui/icons-material/-/icons-material-5.1.0.tgz#f733c9505422398b9b56ec9ed04e53db5985e5e0" + integrity sha512-GD2cNZ2XTqoxX6DMUg+tos1fDUVg6kXWxwo9UuBiRIhK8N+B7CG7vjRDf28LLmewcqIjxqy+T2SEVqDLy1FOYQ== + dependencies: + "@babel/runtime" "^7.16.0" + +"@mui/material@^5.1.0": + version "5.1.0" + resolved "https://registry.yarnpkg.com/@mui/material/-/material-5.1.0.tgz#43382d51957b82bb0d102f1c3c1947246ecbc29c" + integrity sha512-K76v7zRhpJToInSI8sRcEmTwpVFBZ223VIusjZRKXN8JzX+PuErG7skfa1yUuhc3f4VEqcYYUw0LvI+DJJ05eg== + dependencies: + "@babel/runtime" "^7.16.0" + "@mui/core" "5.0.0-alpha.54" + "@mui/system" "^5.1.0" + "@mui/types" "^7.1.0" + "@mui/utils" "^5.1.0" + "@types/react-transition-group" "^4.4.4" + clsx "^1.1.1" + csstype "^3.0.9" + hoist-non-react-statics "^3.3.2" + prop-types "^15.7.2" + react-is "^17.0.2" + react-transition-group "^4.4.2" + +"@mui/private-theming@^5.1.0": + version "5.1.0" + resolved "https://registry.yarnpkg.com/@mui/private-theming/-/private-theming-5.1.0.tgz#44d6a8b75d76c6067b7996993c23b985a457788d" + integrity sha512-RWzpvwZTNoCUlWFtf7uMDY4QkNL6pI3V2Ac4MZeVzJr3DLluQrt0JjUdsy8CVS7HCTp1YGiyZsJ7H8PfR9jIOw== + dependencies: + "@babel/runtime" "^7.16.0" + "@mui/utils" "^5.1.0" + prop-types "^15.7.2" + +"@mui/styled-engine@^5.1.0": + version "5.1.0" + resolved "https://registry.yarnpkg.com/@mui/styled-engine/-/styled-engine-5.1.0.tgz#9f25606505c94e7364bdc9e5d5520cbac1daef2a" + integrity sha512-Z27hexqYL21z+iVat47n1E/Tj4r83JK6hXaOFj2rYMYz0lJQ6YGLF+c2B3NNJoglL76Vo0w4yKC63FsO+015kw== + dependencies: + "@babel/runtime" "^7.16.0" + "@emotion/cache" "^11.5.0" + prop-types "^15.7.2" + +"@mui/system@^5.1.0": + version "5.1.0" + resolved "https://registry.yarnpkg.com/@mui/system/-/system-5.1.0.tgz#7fef622486fa17755e4352f16fbae0d7a72150a3" + integrity sha512-1h+YDnPGfTWZkf7lgeNV+vw6altxXGLclXLdxs9GPzEMNYXX7xveUjmndYpO1p/yx7GNG2gLWWkFZ1TYCeo4+Q== + dependencies: + "@babel/runtime" "^7.16.0" + "@mui/private-theming" "^5.1.0" + "@mui/styled-engine" "^5.1.0" + "@mui/types" "^7.1.0" + "@mui/utils" "^5.1.0" + clsx "^1.1.1" + csstype "^3.0.9" + prop-types "^15.7.2" + +"@mui/types@^7.1.0": + version "7.1.0" + resolved "https://registry.yarnpkg.com/@mui/types/-/types-7.1.0.tgz#5ed928c5a41cfbf9a4be82ea3bbdc47bcc9610d5" + integrity sha512-Hh7ALdq/GjfIwLvqH3XftuY3bcKhupktTm+S6qRIDGOtPtRuq2L21VWzOK4p7kblirK0XgGVH5BLwa6u8z/6QQ== + +"@mui/utils@^5.1.0": + version "5.1.0" + resolved "https://registry.yarnpkg.com/@mui/utils/-/utils-5.1.0.tgz#876951933b77828925ad9502a16070497664aae6" + integrity sha512-TbAa3DZBGE6xjrVsQ6e0Iw0jwgGZqPg/48aZJJWXJJjU8NU5OhBRutYhrk/kbdDRmsIArHNdpJayBSi7yETYvg== + dependencies: + "@babel/runtime" "^7.16.0" + "@types/prop-types" "^15.7.4" + "@types/react-is" "^16.7.1 || ^17.0.0" + prop-types "^15.7.2" + react-is "^17.0.2" + "@nodelib/fs.scandir@2.1.4": version "2.1.4" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.4.tgz#d4b3549a5db5de2683e0c1071ab4f140904bbf69" @@ -1448,6 +1635,11 @@ schema-utils "^2.6.5" source-map "^0.7.3" +"@popperjs/core@^2.4.4": + version "2.10.2" + resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.10.2.tgz#0798c03351f0dea1a5a4cabddf26a55a7cbee590" + integrity sha512-IXf3XA7+XyN7CP9gGh/XB0UxVMlvARGEgGXLubFICsUMGz6Q+DU+i4gGlpOxTjKvXjkJDJC8YdqdKkDj9qZHEQ== + "@rollup/plugin-node-resolve@^7.1.1": version "7.1.3" resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-7.1.3.tgz#80de384edfbd7bfc9101164910f86078151a3eca" @@ -1745,7 +1937,7 @@ dependencies: "@types/istanbul-lib-report" "*" -"@types/jest@*": +"@types/jest@*", "@types/jest@^27.0.2": version "27.0.2" resolved "https://registry.yarnpkg.com/@types/jest/-/jest-27.0.2.tgz#ac383c4d4aaddd29bbf2b916d8d105c304a5fcd7" integrity sha512-4dRxkS/AFX0c5XW6IPMNOydLn2tEhNhJV7DnYK+0bjoJZ+QTmfucBlihX7aoEsh/ocYtkLC73UbnBXBXIxsULA== @@ -1773,6 +1965,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.31.tgz#72286bd33d137aa0d152d47ec7c1762563d34055" integrity sha512-vFHy/ezP5qI0rFgJ7aQnjDXwAMrG0KqqIH7tQG5PPv3BWBayOPIQNBjVc/P6hhdZfMx51REc6tfDNXHUio893g== +"@types/node@^16.11.7": + version "16.11.7" + resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.7.tgz#36820945061326978c42a01e56b61cd223dfdc42" + integrity sha512-QB5D2sqfSjCmTuWcBWyJ+/44bcjO7VbjSbOE0ucoVbAsSNQc4Lt6QkgkVXkTDwkL4z/beecZNDvVX15D4P8Jbw== + "@types/normalize-package-data@^2.4.0": version "2.4.0" resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e" @@ -1788,11 +1985,46 @@ resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.2.1.tgz#374e31645d58cb18a07b3ecd8e9dede4deb2cccd" integrity sha512-DxZZbyMAM9GWEzXL+BMZROWz9oo6A9EilwwOMET2UVu2uZTqMWS5S69KVtuVKaRjCUpcrOXRalet86/OpG4kqw== +"@types/prop-types@*", "@types/prop-types@^15.7.4": + version "15.7.4" + resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.4.tgz#fcf7205c25dff795ee79af1e30da2c9790808f11" + integrity sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ== + "@types/q@^1.5.1": version "1.5.4" resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.4.tgz#15925414e0ad2cd765bfef58842f7e26a7accb24" integrity sha512-1HcDas8SEj4z1Wc696tH56G8OlRaH/sqZOynNNB+HF0WOeXPaxTtbYzJY2oEfiUxjSKjhCKr+MvR7dCHcEelug== +"@types/react-dom@^17.0.11": + version "17.0.11" + resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.11.tgz#e1eadc3c5e86bdb5f7684e00274ae228e7bcc466" + integrity sha512-f96K3k+24RaLGVu/Y2Ng3e1EbZ8/cVJvypZWd7cy0ofCBaf2lcM46xNhycMZ2xGwbBjRql7hOlZ+e2WlJ5MH3Q== + dependencies: + "@types/react" "*" + +"@types/react-is@^16.7.1 || ^17.0.0": + version "17.0.3" + resolved "https://registry.yarnpkg.com/@types/react-is/-/react-is-17.0.3.tgz#2d855ba575f2fc8d17ef9861f084acc4b90a137a" + integrity sha512-aBTIWg1emtu95bLTLx0cpkxwGW3ueZv71nE2YFBpL8k/z5czEW8yYpOo8Dp+UUAFAtKwNaOsh/ioSeQnWlZcfw== + dependencies: + "@types/react" "*" + +"@types/react-transition-group@^4.4.4": + version "4.4.4" + resolved "https://registry.yarnpkg.com/@types/react-transition-group/-/react-transition-group-4.4.4.tgz#acd4cceaa2be6b757db61ed7b432e103242d163e" + integrity sha512-7gAPz7anVK5xzbeQW9wFBDg7G++aPLAFY0QaSMOou9rJZpbuI58WAuJrgu+qR92l61grlnCUe7AFX8KGahAgug== + dependencies: + "@types/react" "*" + +"@types/react@*", "@types/react@^17.0.34": + version "17.0.34" + resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.34.tgz#797b66d359b692e3f19991b6b07e4b0c706c0102" + integrity sha512-46FEGrMjc2+8XhHXILr+3+/sTe3OfzSPU9YGKILLrUYbQ1CLQC9Daqo1KzENGXAWwrFwiY0l4ZbF20gRvgpWTg== + dependencies: + "@types/prop-types" "*" + "@types/scheduler" "*" + csstype "^3.0.2" + "@types/resolve@0.0.8": version "0.0.8" resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-0.0.8.tgz#f26074d238e02659e323ce1a13d041eee280e194" @@ -1800,6 +2032,11 @@ dependencies: "@types/node" "*" +"@types/scheduler@*": + version "0.16.2" + resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39" + integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew== + "@types/source-list-map@*": version "0.1.2" resolved "https://registry.yarnpkg.com/@types/source-list-map/-/source-list-map-0.1.2.tgz#0078836063ffaf17412349bba364087e0ac02ec9" @@ -1829,6 +2066,11 @@ dependencies: source-map "^0.6.1" +"@types/uuid@^8.3.4": + version "8.3.4" + resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.4.tgz#bd86a43617df0594787d38b735f55c805becf1bc" + integrity sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw== + "@types/webpack-sources@*": version "2.1.0" resolved "https://registry.yarnpkg.com/@types/webpack-sources/-/webpack-sources-2.1.0.tgz#8882b0bd62d1e0ce62f183d0d01b72e6e82e8c10" @@ -2599,7 +2841,7 @@ babel-plugin-jest-hoist@^26.6.2: "@types/babel__core" "^7.0.0" "@types/babel__traverse" "^7.0.6" -babel-plugin-macros@2.8.0: +babel-plugin-macros@2.8.0, babel-plugin-macros@^2.6.1: version "2.8.0" resolved "https://registry.yarnpkg.com/babel-plugin-macros/-/babel-plugin-macros-2.8.0.tgz#0f958a7cc6556b1e65344465d99111a1e5e10138" integrity sha512-SEP5kJpfGYqYKpBrj5XU3ahw5p5GOHJ0U5ssOSQ/WBVdwkD2Dzlce95exQTs3jOVWPPKLBN2rlEWkCK7dSmLvg== @@ -3273,6 +3515,11 @@ cliui@^6.0.0: strip-ansi "^6.0.0" wrap-ansi "^6.2.0" +clsx@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/clsx/-/clsx-1.1.1.tgz#98b3134f9abbdf23b2663491ace13c5c03a73188" + integrity sha512-6/bPho624p3S2pMyvP5kKBPXnI3ufHLObBFCfgx+LkeR5lg2XYy2hqZqUf45ypD8COn2bhgGJSUE+l5dhNBieA== + co@^4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184" @@ -3468,6 +3715,13 @@ convert-source-map@^0.3.3: resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-0.3.5.tgz#f1d802950af7dd2631a1febe0596550c86ab3190" integrity sha1-8dgClQr33SYxof6+BZZVDIarMZA= +convert-source-map@^1.5.0: + version "1.8.0" + resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.8.0.tgz#f3373c32d21b4d780dd8004514684fb791ca4369" + integrity sha512-+OQdjP49zViI/6i7nIJpA8rAl4sV/JdPfU9nZs3VqOwGIgizICvuN2ru6fMd+4llL0tar18UYJXfZ/TWtmhUjA== + dependencies: + safe-buffer "~5.1.1" + cookie-signature@1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c" @@ -3848,6 +4102,11 @@ cssstyle@^2.2.0: dependencies: cssom "~0.3.6" +csstype@^3.0.2, csstype@^3.0.9: + version "3.0.9" + resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.9.tgz#6410af31b26bd0520933d02cbc64fce9ce3fbf0b" + integrity sha512-rpw6JPxK6Rfg1zLOYCSwle2GFOOsnjmDYDaBwEcwoOg4qlsIVCN789VkBZDJAGi4T07gI4YSutR43t9Zz4Lzuw== + cyclist@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9" @@ -3882,6 +4141,21 @@ data-urls@^2.0.0: whatwg-mimetype "^2.3.0" whatwg-url "^8.0.0" +dc-extensions-sdk@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/dc-extensions-sdk/-/dc-extensions-sdk-2.0.0.tgz#7e94e0acbe37bb84ad505e8d2c8e139be6925267" + integrity sha512-/D3xvfRPejyQFVLyy+WalZjRsPAczj82VIA71gasuiCQAdvCP0VViUvMKyFSKQMSy8rrrMRhgafS0ULzV5AGQg== + dependencies: + message-event-channel "^1.1.0" + +dc-visualization-sdk@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/dc-visualization-sdk/-/dc-visualization-sdk-1.1.0.tgz#a377763cfee70a20287845fe1919e4b896e8a666" + integrity sha512-w3c/kWIAdphwUROoOh0/TzjWEpHi30IMW2XzgF59NAm+xQo7UMZvwYBf0eyiuFV4NfGdZOY3fMyJd82p+xT1yQ== + dependencies: + message-event-channel "^1.1.0" + object-hash "^2.1.1" + debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.9: version "2.6.9" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" @@ -4116,6 +4390,14 @@ dom-converter@^0.2: dependencies: utila "~0.4" +dom-helpers@^5.0.1: + version "5.2.1" + resolved "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-5.2.1.tgz#d9400536b2bf8225ad98fe052e029451ac40e902" + integrity sha512-nRCa7CK3VTrM2NmGkIy4cbK7IZlgBE/PYMn55rrXefr5xXDP0LdtfPnblFDoVdcAfslJ7or6iqAUnx0CCGIWQA== + dependencies: + "@babel/runtime" "^7.8.7" + csstype "^3.0.2" + dom-serializer@0: version "0.2.2" resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.2.2.tgz#1afb81f533717175d478655debc5e332d9f9bb51" @@ -4418,6 +4700,11 @@ escape-string-regexp@^1.0.5: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= +escape-string-regexp@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" + integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== + escodegen@^1.14.1: version "1.14.3" resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.14.3.tgz#4e7b81fba61581dc97582ed78cab7f0e8d63f503" @@ -4979,6 +5266,11 @@ find-cache-dir@^3.3.1: make-dir "^3.0.2" pkg-dir "^4.1.0" +find-root@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/find-root/-/find-root-1.1.0.tgz#abcfc8ba76f708c42a97b3d685b7e9450bfb9ce4" + integrity sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng== + find-up@4.1.0, find-up@^4.0.0, find-up@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19" @@ -5437,6 +5729,13 @@ hmac-drbg@^1.0.1: minimalistic-assert "^1.0.0" minimalistic-crypto-utils "^1.0.1" +hoist-non-react-statics@^3.3.1, hoist-non-react-statics@^3.3.2: + version "3.3.2" + resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45" + integrity sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw== + dependencies: + react-is "^16.7.0" + hoopy@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/hoopy/-/hoopy-0.1.4.tgz#609207d661100033a9a9402ad3dea677381c1b1d" @@ -7097,6 +7396,13 @@ merge2@^1.3.0: resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae" integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg== +message-event-channel@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/message-event-channel/-/message-event-channel-1.1.0.tgz#8ff5798228432efd692f9f8fd3f749f35185c367" + integrity sha512-/6tBIQr8xmGiTkQZbLwiIxdsG21VcykYryk08cEdJdphEPYYCwi9ur/jSDfbQ6fY1urqo8TDZQ7dr7xJOrCqqw== + dependencies: + url-polyfill "^1.1.7" + methods@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee" @@ -7543,6 +7849,11 @@ object-copy@^0.1.0: define-property "^0.2.5" kind-of "^3.0.3" +object-hash@^2.1.1: + version "2.2.0" + resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-2.2.0.tgz#5ad518581eefc443bd763472b8ff2e9c2c0d54a5" + integrity sha512-gScRMn0bS5fH+IuwyIFgnh9zBdo4DV+6GhygmWM9HyNJSgS0hScp1f5vjtm7oIIOiT9trXrShAkLFSc2IqKNgw== + object-inspect@^1.8.0, object-inspect@^1.9.0: version "1.9.0" resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.9.0.tgz#c90521d74e1127b67266ded3394ad6116986533a" @@ -8798,7 +9109,7 @@ prompts@2.4.0, prompts@^2.0.1: kleur "^3.0.3" sisteransi "^1.0.5" -prop-types@^15.7.2: +prop-types@^15.6.2, prop-types@^15.7.2: version "15.7.2" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5" integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ== @@ -9018,7 +9329,7 @@ react-error-overlay@^6.0.9: resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.9.tgz#3c743010c9359608c375ecd6bc76f35d93995b0a" integrity sha512-nQTTcUu+ATDbrSD1BZHr5kgSD4oF8OFjxun8uAaL8RwPBacGBNPf/yAuVVdx17N8XNzRDMrZ9XcKZHCjPW+9ew== -react-is@^16.8.1: +react-is@^16.7.0, react-is@^16.8.1: version "16.13.1" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ== @@ -9028,6 +9339,11 @@ react-is@^17.0.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.1.tgz#5b3531bd76a645a4c9fb6e693ed36419e3301339" integrity sha512-NAnt2iGDXohE5LI7uBnLnqvLQMtzhkiAOLXTmv+qnF9Ky7xAPcX8Up/xWIhxvLVGJvuLiNc4xQLtuqDRzb4fSA== +react-is@^17.0.2: + version "17.0.2" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" + integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== + react-refresh@^0.8.3: version "0.8.3" resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.8.3.tgz#721d4657672d400c5e3c75d063c4a85fb2d5d68f" @@ -9099,6 +9415,16 @@ react-scripts@4.0.3: optionalDependencies: fsevents "^2.1.3" +react-transition-group@^4.4.2: + version "4.4.2" + resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-4.4.2.tgz#8b59a56f09ced7b55cbd53c36768b922890d5470" + integrity sha512-/RNYfRAMlZwDSr6z4zNKV6xu53/e2BuaBbGhbyYIXTrmgu/bGHzmqOs7mJSJBHy9Ud+ApHx3QjrkKSp1pxvlFg== + dependencies: + "@babel/runtime" "^7.5.5" + dom-helpers "^5.0.1" + loose-envify "^1.4.0" + prop-types "^15.6.2" + react@^17.0.2: version "17.0.2" resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037" @@ -9955,7 +10281,7 @@ source-map@0.6.1, source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0, sourc resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== -source-map@^0.5.0, source-map@^0.5.6: +source-map@^0.5.0, source-map@^0.5.6, source-map@^0.5.7: version "0.5.7" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w= @@ -10293,6 +10619,11 @@ stylehacks@^4.0.0: postcss "^7.0.0" postcss-selector-parser "^3.0.0" +stylis@^4.0.10, stylis@^4.0.3: + version "4.0.10" + resolved "https://registry.yarnpkg.com/stylis/-/stylis-4.0.10.tgz#446512d1097197ab3f02fb3c258358c3f7a14240" + integrity sha512-m3k+dk7QeJw660eIKRRn3xPF6uuvHs/FFzjX3HQ5ove0qYsiygoAhwn5a3IYKaZPo5LrYD0rfVmtv1gNY1uYwg== + supports-color@^5.3.0: version "5.5.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f" @@ -10691,6 +11022,11 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= +typescript@^4.4.4: + version "4.4.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c" + integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA== + unicode-canonical-property-names-ecmascript@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818" @@ -10817,6 +11153,11 @@ url-parse@^1.4.3, url-parse@^1.4.7: querystringify "^2.1.1" requires-port "^1.0.0" +url-polyfill@^1.1.7: + version "1.1.12" + resolved "https://registry.yarnpkg.com/url-polyfill/-/url-polyfill-1.1.12.tgz#6cdaa17f6b022841b3aec0bf8dbd87ac0cd33331" + integrity sha512-mYFmBHCapZjtcNHW0MDq9967t+z4Dmg5CJ0KqysK3+ZbyoNOWQHksGCTWwDhxGXllkWlOc10Xfko6v4a3ucM6A== + url@^0.11.0: version "0.11.0" resolved "https://registry.yarnpkg.com/url/-/url-0.11.0.tgz#3838e97cfc60521eb73c525a8e55bfdd9e2e28f1" @@ -10882,7 +11223,7 @@ uuid@^3.3.2, uuid@^3.4.0: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== -uuid@^8.3.0: +uuid@^8.3.0, uuid@^8.3.2: version "8.3.2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==