Coder Social home page Coder Social logo

plone / mockup Goto Github PK

View Code? Open in Web Editor NEW
46.0 160.0 92.0 136.69 MB

A collection of client side patterns for faster and easier web development

Home Page: http://plone.github.io/mockup/

License: BSD 3-Clause "New" or "Revised" License

HTML 0.02% JavaScript 95.76% Shell 0.01% Makefile 0.17% SCSS 3.65% Liquid 0.38%
javascript patternslib ui-components hacktoberfest

mockup's Introduction

Plone Mockup

Mockup is the JavaScript stack of the Plone Classic UI.

Usage

There are several options to integrate Mockup.

  1. It comes pre-installed with Plone 6 Classic UI.

  2. You can install and compile a bundle. See Development Section below.

  3. You can download a .zip from Mockup's releases page on GitHub.

  4. You can use a precompiled bundle from a CDN, like:

    <script src="https://unpkg.com/@plone/mockup@latest/dist/bundle.min.js"></script>

    or:

    <script src="https://cdn.jsdelivr.net/npm/@plone/mockup@latest/dist/bundle.min.js"></script>

Install

  • Have a current version of Node.js installed.

  • To install, run: make install.

  • To run the demo server, do: make serve.

    This starts up the webpack build process in watch mode. Any JavaScript changes are immediately compiled. For some changes - like for adding new packages via yarn add and then using it you might need to restart. The command also spins up a development server for our 11ty based documentation and demo pages. If you don't need the docs running, you can run yarn start:webpack or npm run start:webpack instead, so that only the webpack devserver is running.

  • Go to http://localhost:8000: On this port our demo and documentation pages are served.

Mockup overview

Mockup is a JavaScript UI library which provides widgets, apps, and functionality for the Plone Classic UI frontend. It is based on Patternslib, and provides its functionality through patterns. Patterns are initialized and activated when a triggering CSS selector is found in the DOM tree. For example, the related items widget is initialized on a form input field with the CSS class pat-relateditems. The configuration is done via data attributes. For the related items pattern, it's an attribute called data-pat-relateditems. The data structure of the configuration can be a JSON string or CSS declaration as key-value pairs, with the key and value separated by a colon (:), and the pairs separated by a semicolon (;). Defining a JSON structure is more flexible though.

Here are two examples.

pat-relateditems configuration as JSON structure:

<input
    type="text"
    class="pat-relateditems"
    data-pat-relateditems='{
        "selectableTypes": ["Document"],
        "vocabularyUrl": "relateditems-test.json"
    }'
/>

pat-relateditems configuration as CSS declarations:

<input
    type="text"
    class="pat-relateditems"
    data-pat-relateditems="
        selectableTypes: Document;
        vocabularyUrl: relateditems-test.json;
    "
/>

Because of historic reasons, the Mockup pattern attributes are written in "camelCase", for example vocabularyUrl. But to resemble the CSS syntax, new patterns should instead separate each word with a dash, for example vocabulary-url.

Mockup Patterns

Deprecated patterns:

Development

You can directly develop with the 11ty based documentation / demo server by running make serve.

If you want to develop in Plone, you have two options:

  1. Run make watch-plone. You need buildout to have plone.staticresources checked out next to Mockup. Mockup will compile it's bundle directly into the ++plone++static directory of plone.staticresources and update it when you change something in Mockup.

  2. Run npx yarn start:webpack, go to the resource registry ( http://localhost:8080/Plone/@@resourceregistry-controlpanel ) and add the URL http://localhost:8000/bundle.min.js to the JavaScript input field of the plone bundle instead of the other URL ++plone++static/bundle-plone/bundle.min.js.

For more commands inspect Makefile and the script part of the package.json.

Running tests

Run make check to run all tests including eslint checks.

To run individual tests, run:

  • jest: Run all tests
  • jest src/pat/PATH-TO-PATTERN: Run a specific test suite
  • jest src/pat/PATH-TO-PATTERN -t "Test name": Run a specific test matching "Test name" from a specific test suite.
  • jest --watch: Run the interactive test runner.

Debugging tests

The tests are based on jsdom - a library mocking DOM and HTML standards in JavaScript. No real browsers are involved, which make the tests run really fast.

Still, you can connect to the Chrome debugging interface via:

node --inspect-brk node_modules/.bin/jest --runInBand ./src/pat/PATH-TO-PATTERN``

Connect in chrome via (You need to click "continue" or "Resume script execution" in the inspector once to proceed):

chrome://inspect

You can pass Jest any parameter it accepts, like -t TESTPATTERN::

node --inspect-brk node_modules/.bin/jest --runInBand ./src/pat/PATH-TO-PATTERN -t test.name

You can put some debugger; statements to the code to break the execution and investigate.

Developing external Packages

If you want to work on ony external package like Patternslib or any external Mockup pattern you can do so by linking those packages into the node_modules folder via yarn link.

  1. Check out the external package you want to develop on.

  2. Make sure you have installed the dependencies in the development package (e.g. by running yarn install). (TODO: verify that!)

  3. Run yarn link in the external development package to register it with yarn.

  4. Run yarn link "PACKAGE-NAME" in mockup to create the node_modules symlink.

After developing you might want to run yarn unlink "PACKAGE-NAME" to unlink the development package.

For more information see:

Please note:: Make sure to unlink and reinstall development pacakges before building a production bundle. In doubt, remove the node_modules directory and re-install.

Bundle build analyzation

https://survivejs.com/webpack/optimizing/build-analysis/ https://formidable.com/blog/2018/finding-webpack-duplicates-with-inspectpack-plugin/

Build the stats.json file:

npx yarn build:stats

Check dependency tree and why which package was included: https://www.npmjs.com/package/whybundled

npx whybundled stats.json

Visualize dependency tree and analyze bundle size: https://www.npmjs.com/package/webpack-bundle-analyzer

npx webpack-bundle-analyzer stats.json

i18n message extraction

To update the translation file, the following needs to be done:

  1. Extract the messages from this package:
npx yarn run i18n

Or just npm run i18n...

  1. Copy the widgets.pot file to plone.app.locales

Assuming you are doing this from a buildout.coredev environment in the mockup folder:

cp widgets.pot ../plone.app.locales/plone/app/locales/locales/
  1. Run i18ndude to update the po files
cd ../plone.app.locales/plone/app/locales/locales
i18ndude sync --pot widgets.pot */LC_MESSAGES/widgets.po

i18n message handling in Plone

To test a translation, for example French:

  • Edit the po file src/plone.app.locales/plone/app/locales/locales/fr/LC_MESSAGES/widgets.po.

  • Restart your instance to rebuild the mo file from the po file.

  • Purge your localStorage and refresh the page to trigger a new download of the translations.

The translations are handled by src/core/i18n.js. This translation helper that calls the @@plonejsi18n view defined in plone.app.content to generate a JSON of the translations from the mo file. The @@plonejsi18n view is called one time for a given domain and language and the result is cached in localStorage for 24 hours. The only way to test the new translations is to restart the instance to update the mo file from the po file, and then to purge the localStorage to trigger a new download of the translations.

Style guide

  • Tab: 4 spaces for everything, except for HTML and XML files which must use 2 spaces, and the Makefile which must use tabs. This rule is defined in the .editorconfig file.

Commit style guide

We automatically generate the changelog from the commit messages following the Conventional Commits specification. Changelog generation is done by the conventional changelog plugin for release-it. This is enforced via a pre-commit hook managed by husky.

And this is how you use it:

We have 4 different types of changelog entries:

  • Breaking Changes (type: breaking),
  • Features (type: feat),
  • Bug Fixes (type: fix),
  • Maintenance (type: maint).

We can group commits in the changelog via a scope or grouping. Let's follow a convention and use these groupings, but the grouping is optional and any other group name can be used.

  • "Dependencies" for upgrading package.json dependencies.
  • "Docs" for documentation.
  • "Build" for everything related to the release workflow, Webpack and building bundles.
  • "Cleanup" for cleaning up or reformatting code.
  • "pat PATTERNNAME" for changes to individual patterns in src/pat.
  • "core MODULENAME" for changes to core modules in src/core.

A commit message with a changelog grouping must be structured like so: TYPE(GROUP): MESSAGE. Without grouping: TYPE: MESSAGE

If the commit message doesn't follow this convention, then it won't be included in the changelog. To bypass the pre-commit hook, use the git -n switch. Example: git commit yarn.lock -m "yarn install." -n.

If you are working on a component like the structure pattern (pat-structure), use pat structure as a group.

Examples:

Add a feature to the structure pattern:

git commit src/pat/structure -m "feat(pat structure): Add feature to cook some coffee"

Cleanup task:

git commit -am "maint(Cleanup): Remove whitespace from documentation."

or without a grouping:

git commit -am "maint: Remove unnecessary file from root directory."

Note

Please keep commits on the yarn.lock file or any other auto-generated code seperate.

Just commit them seperately with git commit yarn.lock -m "yarn install" -n.

Keeping them seperate reduces the effort when merging or rebasing branches where a merge conflict can easily happen. In such cases you can just withdraw your changes on the yarn.lock file, or remove those commits and reinstall with yarn install at the end of a successful merge or rebase.


mockup's People

Contributors

agitator avatar b4oshany avatar bloodbare avatar claytron avatar datakurre avatar davidblewett avatar davilima6 avatar davisagli avatar deiferni avatar dextermilo avatar djay avatar ebrehault avatar erral avatar esteele avatar frapell avatar garbas avatar jcbrand avatar jean avatar jensens avatar mauritsvanrees avatar metatoaster avatar mrtango avatar obct537 avatar petschki avatar sunew avatar thet avatar thokas avatar vangheem avatar veritazx avatar vincentfretin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mockup's Issues

No feedback on delete if an error occurs.

If you delete a content item and it is locked by another person a ResourceLockedError is raised. The user should be informed about this but is not if using p.a.toolbar.

Steps to reproduce:

  1. Create some content C
  2. Edit content C in browser A
  3. Try to delete content C in browser B

management of portlets in p.a.toolbar is not done

  • look up portlet managers for that page/context
  • display portlet managers inside a drop down for toolbar
  • then, display portlets in overlay modal in order
  • reorder portlets
  • add new portlets, edit, hide, delete
  • all portlets in plone 5 will be done in z3c.form *

It's not possible to properly open a form in a modal without using Javascript

Doing something like

<a href="my-form" class="pat-modal">My Form</a>

Opens the form in a modal window, but submit buttons won't do anything.

After reading the modal.js code, it seems that the 'actions' array needs to be specifically set, and there is no way of doing this from the template

Adding something like

data-pat-modal="templateOptions-actions: {'.some-class': { onSuccess: callBack }}"

to the template, ends up with a string ( "{'.some-class': { onSuccess: callBack }}" ) in the action, instead of an Object.

This is going to need to be fixed so gh-32 can be closed

Add a note on bundles in documentation

If you have a custom theme and add p.a.toolbar according to the rules found in the README.rst the toolbar will not show up. You have to add the "tinymce", "widgets" and "toolbar_init" entries to the bundles registry. This should be documented somewhere.

Bugs in select2 3.4.0

There are a couple of bugs in the release of select2 we have:

  • The documentation for 3.4.0 says there is a "search" method, select2.js does not contain it.
  • There is a bug where if a minimumInputLength is set and options.multiple is true, the widget throws an error this.showSearch is undefined.

Both of these appear to be fixed in select2 master. Unfortunately, these make the livesearch pattern difficult to test.

default configuration of patterns via data attributes on body

Implamentation

  1. list all records in plone.app.registry starting with pattern.
  2. for each record/pattrn (pattern.=) create data-pat-="" attribute on body element where is dictionary and then converted into string using json.dumps
  3. for each record/pattern check for adapter (request, context, record) so it is possible to customize options based on request and/or context (not used in plone's core but very useful for addons to customize)
  4. use plone.transformationchain and post process html to append data attributed to the body

because how patterns work this options will be picked by patterns used across

Bonus

we might also consider passing other data as body data attributes (portalurl, roles, groups, ...).

Suggestion for documentation layout

I actually liked having the pattern examples in a single file with anchor navigation. What about adding a sticky navigation sidebar for the various patterns like bootstrap's docs (http://twitter.github.io/bootstrap)? This would allow for better ease of use to browse patterns, and would prevent us from having so many files in the repo.

Thoughts?

accessible focus handling for overlays

  • add anchor element around title of all overlays
  • add anchor element around buttons/links which activate all overlays
  • when overlay without a form is activated, set focus to the overlay title anchor
  • when overlay close link or overlay form cancel button are clicked, set focus to the originating button's anchor
  • when close link loses focus, set focus to the overlay title anchor

browser support

Right now it seems to only work on Firefox. Broken in IE(obviously) and Chrome(which is surprising).

error building mockup

I tried to checkout and build mockup using make bootstrap followed by make. It ended with this output:

cat build/widgets.css > build/toolbar.css
./node_modules/.bin/lessc less/toolbar.less >> build/toolbar.css    
FileError: 'pattern.tinymce.less' wasn't found in /Users/davisagli/Plone/zinstance/src/mockup/less/widgets.less on line 12, column 1:
11 @import "pattern.livesearch.less";
12 @import "pattern.tinymce.less";
13 

make: *** [build/toolbar.css] Error 1

What's wrong?

Personal-tools should come last in the DOM of the toolbar

currently the personal-tools, although displayed (for visual user) to the right, is the first item in the DOM. For screenreader users, that means the first thing they will hear, every time they want to edit something, is their own name. This is redundant (they know who they are...) and annoying, and breaks a fluent workflow.

Suggestion for documentation layout

I actually liked having the pattern examples in a single file with anchor navigation. What about adding a sticky navigation sidebar for the various patterns like bootstrap's docs (http://twitter.github.io/bootstrap)? This would allow for better ease of use to browse patterns, and would prevent us from having so many files in the repo.

Thoughts?

accessible dom order for enhanced widgets

When overriding HTML controls with javascript widgets,

  • add a link class="hiddenStructure" saying "Skip repeated visual control"
  • add the added javascript elements
  • add the link anchor after the added javascript elements

For the example of a autocomplete replacing a text field, a screen reader user should see the non-enhanced text field first in the DOM order, with a link to skip past the added functionality. This DOM order provides ease of use for assistive technology users because screen readers have well-established means of rendering and operating standard form controls.

Modals & Expose should have consistent close buttons for a11y reasons

Some modals and popups have a "close" button, others don't. Even on those that have it, the button is on the top left (for sighted users), before the first form element (for screenreader users), meaning they would have to go 'back', but there is no indication this is what they should do..

Clues like visual darkening (Expose) don't work for screenreader users, so they also don't see the notion they should 'click somewhere on the dark area' to get out of the modal.

Ideally, a close button should be placed at the end of the DOM for the modal. If there is alreay one on the topleft, this can probably be classed 'hiddenStructure' so no duplicate buttons appear for sighted users.

rethink UI of sitesetup and start with rewrite

First step is to bring the control panel into a modal and make links open in a new tab/same tab
Second step is to integrate all the sections into a single modal instead of opening new tabs
Third step might be to actually restructure the UI of finding and selecting items on the control panel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.