Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Storybook using JSX with UV demos #720

Open
wants to merge 2 commits into
base: webpack
Choose a base branch
from

Conversation

stephenwf
Copy link
Contributor

Support for Storybook using the HTML preset and JSX-DOM for rendering the HTML using JSX.

  • Requires dist folder to exist, so you need to run npm build first
  • Can be started using npm run storybook
  • Will watch for changes in the UV, so can be used to develop it
  • HTML file for pulling in extra resources
  • Mounts the contents of ./dist so you can access configs and resources in that folder – before we switch that over the webpack too.
  • Added "Knobs" add-on and hooked it up to the UV demo to switch out the Manifest and Canvas. Could be useful for building simple configuration editing examples.
  • Added JSX support to TS configuration, along with JSX-DOM. When you construct a JSX element, the return value is a HTMLElement that can be immediately attached. (not React)
  • Stories can be found in ./stories/ and can pull in files, classes from ../src relative to that folder.
  • JS files that change may not be picked up when, such as jQuery plugins or lib folder. You'll have to restart to see these changes.

Mostly a baseline, I wanted to get the minimum configuration in, plenty more could be added for theming, add-ons and showcasing various other UI elements in isolation.

Screenshot 2020-04-05 at 12 18 38

@edsilv edsilv requested a review from demiankatz April 14, 2020 12:31
Copy link
Contributor

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great based on the screen shot, but I wasn't able to get it to work on my end. I checked out the code, ran npm install ; npm run-script build ; npm run storybook and it pops up in my browser, but the page never fully loads. I get the storybook framework, but the left sidebar just stays forever in a blinking loading state.

I'm not familiar with this tool, so maybe I'm just missing something, but it's not clear to me how the changes in this pull request would expose everything shown in the screen shot. For example, how do you specify which knobs to expose through the interface? This leads me to wonder if my problem has to do with a missing file that hasn't been committed, or something like that.

I also had a couple of small questions and comments which are separated out below. Of these, I think the most significant is the include vs. require thing; I'm just not sure why that change is necessary, and if nothing else, the associated comment should be made more detailed. :-)

@@ -14,7 +14,8 @@ import { Helper, loadManifest, IManifoldOptions } from "@iiif/manifold";
import { Annotation, AnnotationBody, Canvas, Sequence } from "manifesto.js";
import { BaseComponent, IBaseComponentOptions } from "@iiif/base-component";
import { URLDataProvider } from "./URLDataProvider";
import "./lib/";
// Has to be require.
require("./lib/");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this the case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was related to a bug when accessing globals like $?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever the reason, I think it would be a good idea to understand what is going on. My understanding of include vs. require suggests that the differences between them are minimal (the biggest difference is that require can accept dynamic inputs, while include cannot -- which makes include better for tree-shaking because it is predictable). If using include instead of require on a static input is causing a change in behavior, that's probably a side effect of some step in the compilation process related to Typescript and/or Webpack, and perhaps there's a different/better solution, or there are other implications.

Anyway, I imagine there's a very good chance that @stephenwf has already thought this all through, but if that's the case, I'd just like to see more of that thinking captured in the comment so we don't have to re-investigate in the future when we come back around and wonder why exactly we need a require here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In short, the problem was the loading order. There's nothing in ./lib/ that includes jQuery or jQuery views as a dependency. A more involved fix for this would be to move more into the webpack build, like jQuery and the plugins so that Webpack can ensure the correct loading order etc.

In terms of output, the only difference in the bundle is the removal of a hint left by Webpack for minification:

- /* harmony import */ var _lib___WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./lib/ */ "./src/lib/index.js");
+ __webpack_require__(/*! ./lib/ */ "./src/lib/index.js");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Maybe the comment could be changed to something like Must be require instead of include to support jQuery; TODO: eliminate jQuery or explicitly include it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ill do that 👍

@@ -0,0 +1,2 @@
<script src="https://unpkg.com/[email protected]/dist/ResizeObserver.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would sure be nice to figure out a way to not have to put this everywhere that bundle.js is loaded! (But that's a problem for another day...)

rotation?: number,
xywh?: string,
embedded?: boolean,
locales?: any, //??
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this ?? comment indicate that further work/discussion is needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, as far as I can tell, there are no types for the locale config in the UV.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edsilv, any thoughts on this? Hopefully we can either adjust the type (if necessary/possible) or remove the comment (if no further action is needed).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think typing it shouldn't be a problem

@stephenwf
Copy link
Contributor Author

@demiankatz I was having some problems with the files being gitignored! Looks like the storybook config isn't there. Let me change that now 👍

Comment on lines +1 to +20
module.exports = {
stories: ['../stories/**/*.stories.tsx'],
addons: ['@storybook/addon-knobs/register'],
webpackFinal: async config => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
use: [
{
loader: require.resolve('ts-loader'),
},
// Optional
{
loader: require.resolve('react-docgen-typescript-loader'),
},
],
});
config.resolve.extensions.push('.ts', '.tsx');
return config;
},
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@demiankatz Here's the missing file, you should be able to run it locally now. Sorry about that, problems with the .gitignore for main.js files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's progress, but it's still not quite working for me. Now, if I run grunt build and npm run storybook, I see the full storybook interface with the two examples you provided and the appropriate knobs, but the UV itself doesn't load. The pane where it should be is white and empty. I'm seeing a 404 error in my console for the file http://localhost:6006/uv/lib/uv-openseadragon-extension.en-GB.config.json.

I haven't tried deleting everything and starting fresh with a clean npm install. If you think that's worth a shot, let me know and I'll do it... but since it's a time-consuming process, I first wanted to check and see if the missing JSON file was an obvious indication of a different problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth, on the working Netlify demo you shared, the config.json file is coming from the URL https://uv-storybook.netlify.com/uv-assets/config/uv-openseadragon-extension.en-GB.config.json. Not sure why the path is so significantly different in my local environment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, can you try: grunt build --dist and then npm run storybook ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same result. I have a ./dist directory which is being served up by Storybook through port 6006... but something is still trying to request http://localhost:6006/uv/lib/uv-openseadragon-extension.en-GB.config.json and there's no ./dist/uv directory in my instance, so I get a 404.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's weird. runs fine with npm start

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edsilv, did you mean grunt build --dist? I tried running npm build --dist and just got an error message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm run build --dist

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edsilv, I don't get an error when I do that, but I don't think the --dist flag carries through when you wrap npm around the command.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I think npm run build:dist is the way to do it through npm as currently configured. But that works for me too. Perhaps the virtex error you're seeing has to do with an artifact in your local system? Did you try from a clean checkout?

@edsilv edsilv added this to the UV v4.0.4 milestone Jul 20, 2022
@demiankatz demiankatz removed this from the UV v4.1.0 milestone Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: To be assessed
Development

Successfully merging this pull request may close these issues.

3 participants