From 269cec47d01502fb150d30e4546079022212cdf8 Mon Sep 17 00:00:00 2001 From: Tim Stallmann Date: Tue, 6 Aug 2024 10:27:53 -0400 Subject: [PATCH 1/3] Upgrade prettier to 3.2 --- .prettierrc | 6 ++++-- package-lock.json | 12 ++++++------ package.json | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.prettierrc b/.prettierrc index dc2fb828f..9d000625a 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,3 +1,5 @@ { - "singleQuote": true -} \ No newline at end of file + "singleQuote": true, + "arrowParens": "always", + "trailingComma": "none" +} diff --git a/package-lock.json b/package-lock.json index 92273860d..832445f35 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "less": ">=4.0", "lint-staged": ">=12.3.1", "mocha": ">=2.4.1", - "prettier": "^2.5.1", + "prettier": "~3.2.0", "typescript": "~5.4", "uglify-js": "2.x" } @@ -1418,15 +1418,15 @@ } }, "node_modules/prettier": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", - "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", + "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", "dev": true, "bin": { - "prettier": "bin-prettier.js" + "prettier": "bin/prettier.cjs" }, "engines": { - "node": ">=10.13.0" + "node": ">=14" }, "funding": { "url": "https://github.com/prettier/prettier?sponsor=1" diff --git a/package.json b/package.json index 9023d3693..df7673e98 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "less": ">=4.0", "lint-staged": ">=12.3.1", "mocha": ">=2.4.1", - "prettier": "^2.5.1", + "prettier": "~3.2.0", "typescript": "~5.4", "uglify-js": "2.x" }, From 06a92c93b804776eca879d02c78ca0dc63eff97a Mon Sep 17 00:00:00 2001 From: Tim Stallmann Date: Tue, 6 Aug 2024 10:28:32 -0400 Subject: [PATCH 2/3] Run prettier on all files --- .github/workflows/mathquill-pr-linting.yml | 23 +- .prettierrc | 6 +- CHANGELOG.md | 45 +- README.md | 1 + benchmark/render.html | 9 +- benchmark/select.html | 2 +- benchmark/update.html | 2 +- circle.yml | 467 +++++++------ docs/Api_Methods.md | 63 +- docs/Code_of_Conduct.md | 9 +- docs/Config.md | 17 +- docs/Getting_Started.md | 9 +- quickstart.html | 6 +- script/escape-non-ascii | 10 +- script/mangle-pray | 13 +- script/screenshots.js | 32 +- script/tsc-emit-only | 12 +- src/browser.ts | 2 +- src/commands/math.ts | 2 +- src/commands/math/LatexCommandInput.ts | 4 +- src/commands/math/basicSymbols.ts | 8 +- src/commands/math/commands.ts | 150 ++--- src/commands/text.ts | 8 +- src/css/editable.less | 15 +- src/css/font.less | 29 +- src/css/main.less | 16 +- src/css/math.less | 152 +++-- src/css/mixins/fonts.less | 6 +- src/css/selections.less | 22 +- src/css/textarea.less | 5 +- src/cursor.ts | 2 +- src/publicapi.ts | 10 +- src/services/aria.ts | 2 +- src/services/focusBlur.ts | 4 +- src/services/latex.ts | 6 +- src/services/mouse.ts | 2 +- src/services/saneKeyboardEvents.util.ts | 8 +- src/services/textarea.ts | 4 +- src/tree.ts | 8 +- test/basic.html | 6 +- test/demo.html | 10 +- test/digit-grouping.html | 14 +- test/support/assert.ts | 10 +- test/support/jquery-stub.ts | 2 +- test/support/trigger-event.ts | 4 +- test/tsconfig.public-types-test.json | 40 +- test/undo.html | 6 +- test/unit.html | 18 +- test/unit/SupSub.test.js | 12 +- test/unit/ans.test.js | 2 +- test/unit/autoOperatorNames.test.js | 4 +- test/unit/autoSubscriptAndBreakOut.test.js | 2 +- test/unit/autosubscript.test.js | 2 +- test/unit/charsThatBreakOutOfSupSub.test.js | 2 +- test/unit/css.test.js | 2 +- test/unit/digit-grouping.test.js | 694 ++++++++++---------- test/unit/dom.test.ts | 4 +- test/unit/domFragment.test.ts | 76 +-- test/unit/focusBlur.test.js | 4 +- test/unit/latex.test.js | 48 +- test/unit/publicapi.test.js | 50 +- test/unit/quietEmptyDelimiters.test.js | 4 +- test/unit/resetCursorOnBlur.test.js | 2 +- test/unit/saneKeyboardEvents.test.js | 38 +- test/unit/text.test.js | 4 +- test/unit/typing.test.js | 34 +- test/visual.html | 32 +- tsconfig.json | 46 +- 68 files changed, 1222 insertions(+), 1141 deletions(-) diff --git a/.github/workflows/mathquill-pr-linting.yml b/.github/workflows/mathquill-pr-linting.yml index 2b8b78773..f9ca7029b 100644 --- a/.github/workflows/mathquill-pr-linting.yml +++ b/.github/workflows/mathquill-pr-linting.yml @@ -6,13 +6,12 @@ name: mathquill pr linting on: workflow_dispatch: push: - branches: [ "main" ] + branches: ['main'] pull_request: - branches: [ "main" ] + branches: ['main'] jobs: build: - runs-on: ubuntu-latest timeout-minutes: 30 strategy: @@ -21,12 +20,12 @@ jobs: # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: - - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - run: make - - run: make lint - - run: npx prettier --check '**/*.{ts,js,css,html}' + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: make + - run: make lint + - run: npx prettier --check '**/*.{ts,js,css,html}' diff --git a/.prettierrc b/.prettierrc index 9d000625a..c9894c5a9 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,5 @@ { - "singleQuote": true, - "arrowParens": "always", - "trailingComma": "none" + "singleQuote": true, + "arrowParens": "always", + "trailingComma": "none" } diff --git a/CHANGELOG.md b/CHANGELOG.md index e194cb279..c349bcacc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,25 +3,28 @@ The major change in this interface version is the removal of MathQuill's dependency on JQuery. **breaking changes:** + - `.revert()` now returns an HTML element rather than a JQuery collection - The (undocumented) `substituteKeyboardEvents` configuration option is no longer supported - The (undocumented) `overrideKeystroke` configuration option now receives a native `KeyboardEvent` as its second parameter (it previously received a JQuery event). -- In previous interface versions, `MQ.config()` changed the _global_ default configuration, shared across multiple API instances. On a v3 instance, however, it only affects the default configuration for the particular API instance on which it was called. E.g.: +- In previous interface versions, `MQ.config()` changed the _global_ default configuration, shared across multiple API instances. On a v3 instance, however, it only affects the default configuration for the particular API instance on which it was called. E.g.: + ```javascript // Interface v1 and v2 -var MQ_a = MathQuill.getInterface(2), MQ_b = MathQuill.getInterface(2); +var MQ_a = MathQuill.getInterface(2), + MQ_b = MathQuill.getInterface(2); MQ_a.config(myConfig); MQ_a.MathField(el_a); // configured with myConfig MQ_b.MathField(el_b); // configured with myConfig // Interface v3 -var MQ_c = MathQuill.getInterface(3), MQ_d = MathQuill.getInterface(3); +var MQ_c = MathQuill.getInterface(3), + MQ_d = MathQuill.getInterface(3); MQ_c.config(myConfig); MQ_c.MathField(el_a); // configured with myConfig MQ_d.MathField(el_b); // unaffected by myConfig ``` - ## v0.10.1: Fix `font-size: 0` typing problems and more _2016-03-21_ @@ -37,12 +40,13 @@ see the [v0.9.x → v0.10.0 Migration Guide][].) [v0.9.x → v0.10.0 Migration Guide]: https://github.com/mathquill/mathquill/wiki/v0.9.x-%E2%86%92-v0.10.0-Migration-Guide **new features:** + - (#544, #552, #558, #581) new symbols `\nparallel`, `\measuredangle`, `\odot`, `\parallelogram` (nonstandard), `\nless`, `\ngtr`, `\square` - (#544) new commands `\overleftarrow`, `\overrightarrow` - **bugfixes:** + - (#585) fix typing in Chrome Canary, Enter key in Webkit+Blink - (#582) fix `\degree` symbol to round-trip (rather than exporting `^\circ` which doesn't parse as one symbol) @@ -59,6 +63,7 @@ see the [v0.9.x → v0.10.0 Migration Guide][].) - (#525) fix Tab while there's a selection **build system fixes:** + - (#532) add console output to show URL of local test pages ## v0.10.0: Total API overhaul, new features galore @@ -72,11 +77,12 @@ itself): See the [v0.9.x → v0.10.0 Migration Guide] (https://github.com/mathquill/mathquill/wiki/v0.9.x-%E2%86%92-v0.10.0-Migration-Guide). (If you already use the new global `MathQuill()`-based API from the - `dev` branch, migrating to v0.10.0 should be just [one small change] - (https://github.com/mathquill/mathquill/wiki/%60dev%60-branch-(2014%E2%80%932015)-%E2%86%92-v0.10.0-Migration-Guide) - for you.) +`dev` branch, migrating to v0.10.0 should be just [one small change] +(https://github.com/mathquill/mathquill/wiki/%60dev%60-branch-(2014%E2%80%932015)-%E2%86%92-v0.10.0-Migration-Guide) +for you.) **API-only changes:** + - (#336, #349, #351, #353) config options architecture - (#308) don't auto-MathQuill-ify on jQuery `ready` - (#297) prefix all CSS classes with `mq-` @@ -84,6 +90,7 @@ itself): See the [v0.9.x → v0.10.0 Migration Guide] global `MathQuill()` returns API objects **typist-facing changes:** + - (#506) delete `\caret` and `\underscore` - (#453) incremental backspace: backspacing into a compound command like fraction or exponent goes left into it rather than selecting it @@ -101,6 +108,7 @@ itself): See the [v0.9.x → v0.10.0 Migration Guide] - (#157) stop fractions created by typing `/` at `,`/`;`/`:` **new features:** + - (#468) add WOFF and WOFF2 font formats - (#376, #398) add `autoSubscriptNumerals` option - (#338) config option `sumStartsWithNEquals` @@ -121,10 +129,12 @@ itself): See the [v0.9.x → v0.10.0 Migration Guide] - (#151) `\textcolor{color}{math}` **new build system features:** + - (#377) `OMIT_FONT_FACE=true make` omits `@font-face {...}` - (#319) `make basic` builds stripped-down MathQuill for basic math **bugfixes:** + - (#452) fix blinking blue cursor and autocorrect on iOS - (#448) fix `\ddots` to be downward-rightward not upward-rightward - (#432) fix quadratic-time fragment construction @@ -148,12 +158,14 @@ itself): See the [v0.9.x → v0.10.0 Migration Guide] - (c1fe1ef, 9aef35f) fix up/down in an `\editable{}` in a fraction **docs:** + - (#485) add more metadata to package.json - (#484) fix links in README - (#393) correctly credit co-creator @jneen - (#283) use Mozilla Public License (MPL) instead of LGPL **internal refactors:** + - (#303) remove STIX font files, never used them - (#244) refactor focus/blur out into its own service - (#240) simplify `saneKeyboardEvents()` handlers pattern @@ -172,6 +184,7 @@ _2014-1-22_ URGENT HOTFIX for cursor showing up as an ugly box in Chrome 40 (#371) **bugfixes:** + - (#371) fix cursor showing up as an ugly box in Chrome 40 - (#230) fix selecting previously selected static math can't be copied - (#217) fix no Array::indexOf in IE<9, use RegExp::test @@ -179,10 +192,12 @@ URGENT HOTFIX for cursor showing up as an ugly box in Chrome 40 (#371) - (#211) fix CSS typo causing no italics when there should be **build system changes:** + - (#222 and #228) `make server` auto-rebuilds without restarting server - (#212) use empty target trick in Makefile **docs:** + - (#283) change license from LGPL to Mozilla Public License ## v0.9.3: Fix `NZQRC` appearing double-struck/blackboard bold @@ -190,18 +205,22 @@ URGENT HOTFIX for cursor showing up as an ugly box in Chrome 40 (#371) _2013-11-11_ **new features:** + - (#185) add `\vec` **bugfixes:** + - (#164) displaying `NZQRC` as `\mathbb{NZQRC}` (double-struck) - (#180) can't type >1 spaces in `RootTextBlock`s - (#190) `$` at the end of a `TextBlock` causes errors later - (#152) when "Select All"-ed, `.mathquill('latex')` throws **internal refactors:** + - rename `.end` and `.endChild` both to `.ends` **build system changes:** + - fix `make publish` to work on BSD - (#189) replace Connect with tiny handwritten static server - upgrade to uglifyjs2 @@ -214,9 +233,11 @@ NOTE: The hotfix for typing over selections in Safari 5.1 (#135) from v0.9.1 had a huge bug, fixed as #166. **feature changes:** + - (#156) stop LiveFraction at commas/colons/semicolons **bugfixes:** + - allow angle bracket as a VanillaSymbol (thanks @fpirsch!) - (#166) fix selecting after paste - (#121) editing `\text{...}` created from LaTeX @@ -225,11 +246,13 @@ v0.9.1 had a huge bug, fixed as #166. - stretched parens not being grayed **internal refactors:** + - Massive renaming introducing direction constants `L` and `R`, and directionalized methods - Use a subclass of jQuery with directionalized methods (see `d5597e4`) **build system changes:** + - New site-building system - no more submodules, `npm` only @@ -237,6 +260,6 @@ v0.9.1 had a huge bug, fixed as #166. _2012-12-19_ - * Started the changelog - * Added a `make publish` script - * Hotfix for typing over selections in Safari 5.1 (#135) +- Started the changelog +- Added a `make publish` script +- Hotfix for typing over selections in Safari 5.1 (#135) diff --git a/README.md b/README.md index c5202aa6a..f9308fbc9 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ MathQuill is resuming active development and we're committed to getting things r ## Getting Started MathQuill has a simple interface. This brief example creates a MathQuill element and renders, then reads a given input: + ```javascript var htmlElement = document.getElementById('some_id'); var config = { diff --git a/benchmark/render.html b/benchmark/render.html index e317437dd..c77b425eb 100644 --- a/benchmark/render.html +++ b/benchmark/render.html @@ -1,4 +1,4 @@ - + @@ -133,9 +133,8 @@

All MQ render times:

div.querySelector('.mq-result').innerText = `MQ: ${mqDuration.toFixed( 2 )} ms`; - div.querySelector( - '.html-result' - ).innerText = `HTML: ${htmlDuration.toFixed(2)} ms`; + div.querySelector('.html-result').innerText = + `HTML: ${htmlDuration.toFixed(2)} ms`; } function printResults() { @@ -156,7 +155,7 @@

All MQ render times:

[(a, b) => `${a}^{${b}}`, 2], [(a, b) => `${a}_{${b}}`, 2], [(...args) => `\\left[${args.join(',')}\\right]`, -1], - [(a) => `\\left(${a}\\right)`, 1], + [(a) => `\\left(${a}\\right)`, 1] ]; let [fn, arity] = diff --git a/benchmark/select.html b/benchmark/select.html index 0df40455f..ca3293eb8 100644 --- a/benchmark/select.html +++ b/benchmark/select.html @@ -1,4 +1,4 @@ - + diff --git a/benchmark/update.html b/benchmark/update.html index 17a17e8e1..7178a7d2b 100644 --- a/benchmark/update.html +++ b/benchmark/update.html @@ -1,4 +1,4 @@ - + diff --git a/circle.yml b/circle.yml index e9b4a8f06..b9cd1fd78 100644 --- a/circle.yml +++ b/circle.yml @@ -27,7 +27,6 @@ # # - boom testing boom - # this file is based on https://github.com/circleci/sauce-connect/blob/a65e41c91e02550ce56c75740a422bebc4acbf6f/circle.yml # via https://circleci.com/docs/browser-testing-with-sauce-labs/ # @@ -54,262 +53,262 @@ jobs: # To see the list of pre-built images that CircleCI provides for most common languages see # https://circleci.com/docs/2.0/circleci-images/ docker: - - image: circleci/node:lts-browsers + - image: circleci/node:lts-browsers steps: - # Machine Setup - # If you break your build into multiple jobs with workflows, you will probably want to do the parts of this that are relevant in each - # The following `checkout` command checks out your code to your working directory. In 1.0 we did this implicitly. In 2.0 you can choose where in the course of a job your code should be checked out. - - checkout - # Prepare for artifact and test results collection equivalent to how it was done on 1.0. - # In many cases you can simplify this from what is generated here. - # 'See docs on artifact collection here https://circleci.com/docs/2.0/artifacts/' - - run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS - # Dependencies - # This would typically go in either a build or a build-and-test job when using workflows - # Restore the dependency cache - - restore_cache: - keys: - # This branch if available - - v1-dep-{{ .Branch }}- - # Default branch if not - - v1-dep-master- - # Any branch if there are none on the default branch - this should be unnecessary if you have your default branch configured correctly - - v1-dep- - # This is based on your 1.0 configuration file or project settings - - run: - command: |- - # SauceConnect: download if not cached, and launch with retry - test $SAUCE_USERNAME && test $SAUCE_ACCESS_KEY || { - echo 'Sauce Labs credentials required. Sign up here: https://saucelabs.com/opensauce/' - exit 1 - } + # Machine Setup + # If you break your build into multiple jobs with workflows, you will probably want to do the parts of this that are relevant in each + # The following `checkout` command checks out your code to your working directory. In 1.0 we did this implicitly. In 2.0 you can choose where in the course of a job your code should be checked out. + - checkout + # Prepare for artifact and test results collection equivalent to how it was done on 1.0. + # In many cases you can simplify this from what is generated here. + # 'See docs on artifact collection here https://circleci.com/docs/2.0/artifacts/' + - run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS + # Dependencies + # This would typically go in either a build or a build-and-test job when using workflows + # Restore the dependency cache + - restore_cache: + keys: + # This branch if available + - v1-dep-{{ .Branch }}- + # Default branch if not + - v1-dep-master- + # Any branch if there are none on the default branch - this should be unnecessary if you have your default branch configured correctly + - v1-dep- + # This is based on your 1.0 configuration file or project settings + - run: + command: |- + # SauceConnect: download if not cached, and launch with retry + test $SAUCE_USERNAME && test $SAUCE_ACCESS_KEY || { + echo 'Sauce Labs credentials required. Sign up here: https://saucelabs.com/opensauce/' + exit 1 + } - mkdir -p ~/sauce-connect - cd ~/sauce-connect - - if [ -x sc-*-linux/bin/sc ]; then - echo Using cached sc-*-linux/bin/sc - else - time wget https://saucelabs.com/downloads/sc-4.7.1-linux.tar.gz - time tar -xzf sc-4.7.1-linux.tar.gz - fi + mkdir -p ~/sauce-connect + cd ~/sauce-connect - time sc-*-linux/bin/sc --user $SAUCE_USERNAME --api-key $SAUCE_ACCESS_KEY \ - --readyfile ~/sauce_is_ready - test -e ~/sauce_was_ready && exit + if [ -x sc-*-linux/bin/sc ]; then + echo Using cached sc-*-linux/bin/sc + else + time wget https://saucelabs.com/downloads/sc-4.7.1-linux.tar.gz + time tar -xzf sc-4.7.1-linux.tar.gz + fi - echo 'Sauce Connect failed, try redownloading (https://git.io/vSxsJ)' - rm -rf * - time wget https://saucelabs.com/downloads/sc-4.7.1-linux.tar.gz - time tar -xzf sc-4.7.1-linux.tar.gz + time sc-*-linux/bin/sc --user $SAUCE_USERNAME --api-key $SAUCE_ACCESS_KEY \ + --readyfile ~/sauce_is_ready + test -e ~/sauce_was_ready && exit - time sc-*-linux/bin/sc --user $SAUCE_USERNAME --api-key $SAUCE_ACCESS_KEY \ - --readyfile ~/sauce_is_ready - test -e ~/sauce_was_ready && exit + echo 'Sauce Connect failed, try redownloading (https://git.io/vSxsJ)' + rm -rf * + time wget https://saucelabs.com/downloads/sc-4.7.1-linux.tar.gz + time tar -xzf sc-4.7.1-linux.tar.gz - echo 'ERROR: Exited twice without creating readyfile' \ - | tee /dev/stderr > ~/sauce_is_ready - exit 1 - background: true - # The following line was run implicitly in your 1.0 builds based on what CircleCI inferred about the structure of your project. In 2.0 you need to be explicit about which commands should be run. In some cases you can discard inferred commands if they are not relevant to your project. - - run: if [ -z "${NODE_ENV:-}" ]; then export NODE_ENV=test; fi - - run: export PATH="~/mathquill/mathquill/node_modules/.bin:$PATH" - - run: npm install - # Save dependency cache - - save_cache: - key: v1-dep-{{ .Branch }}-{{ epoch }} - paths: - # This is a broad list of cache paths to include many possible development environments - # You can probably delete some of these entries - - vendor/bundle - - ~/virtualenvs - - ~/.m2 - - ~/.ivy2 - - ~/.bundle - - ~/.go_workspace - - ~/.gradle - - ~/.cache/bower - # These cache paths were specified in the 1.0 config - - ~/sauce-connect - - ./node_modules - # Test - # This would typically be a build job when using workflows, possibly combined with build - # This is based on your 1.0 configuration file or project settings - - run: |- - # Generate link to Many-Worlds build and add to GitHub Commit Status - curl -i -X POST https://api.github.com/repos/mathquill/mathquill/statuses/$CIRCLE_SHA1 \ - -u MathQuillBot:$GITHUB_STATUS_API_KEY \ - -d '{ - "context": "ci/many-worlds", - "state": "success", - "description": "Try the tests on the Many-Worlds build of this commit:", - "target_url": "http://many-worlds.glitch.me/mathquill/mathquill/commit/'$CIRCLE_SHA1'/test/" - }' - # Safari on Sauce can only connect to port 3000, 4000, 7000, or 8000. Edge needs port 7000 or 8000. - # https://david263a.wordpress.com/2015/04/18/fixing-safari-cant-connect-to-localhost-issue-when-using-sauce-labs-connect-tunnel/ - # https://support.saucelabs.com/customer/portal/questions/14368823-requests-to-localhost-on-microsoft-edge-are-failing-over-sauce-connect - - run: - command: PORT=8000 make server - background: true - # Wait for tunnel to be ready (`make server` is much faster, no need to wait for it) - - run: while [ ! -e ~/sauce_is_ready ]; do sleep 1; done; touch ~/sauce_was_ready; test -z "$(<~/sauce_is_ready)" - # This is based on your 1.0 configuration file or project settings - - run: - command: |- - # Screenshots: capture in the background while running unit tests - mkdir -p $CIRCLE_TEST_REPORTS/mocha + time sc-*-linux/bin/sc --user $SAUCE_USERNAME --api-key $SAUCE_ACCESS_KEY \ + --readyfile ~/sauce_is_ready + test -e ~/sauce_was_ready && exit - # CircleCI expects test results to be reported in an JUnit/xUnit-style XML file: - # https://circleci.com/docs/test-metadata/#a-namemochajsamocha-for-nodejs - # Our unit tests are in a browser, so they can't write to a file, and Sauce - # apparently truncates custom data in their test result reports, so instead we - # POST to this trivial Node server on localhost:9000 that writes the body of - # any POST request to $CIRCLE_TEST_REPORTS/junit/test-results.xml - node -e ' - require("http").createServer(function(req, res) { - res.setHeader("Access-Control-Allow-Origin", "*"); - req.pipe(process.stdout); - req.on("end", res.end.bind(res)); - }) - .listen(9000); - console.error("listening on http://0.0.0.0:9000/"); - ' 2>&1 >$CIRCLE_TEST_REPORTS/junit/test-results.xml | { - # ^ note: `2>&1` must precede `>$CIRCLE_TEST_REPORTS/...` because - # shell redirect is like assignment; if it came after, then both - # stdout and stderr would be written to `xunit.xml` and nothing - # would be piped into here + echo 'ERROR: Exited twice without creating readyfile' \ + | tee /dev/stderr > ~/sauce_is_ready + exit 1 + background: true + # The following line was run implicitly in your 1.0 builds based on what CircleCI inferred about the structure of your project. In 2.0 you need to be explicit about which commands should be run. In some cases you can discard inferred commands if they are not relevant to your project. + - run: if [ -z "${NODE_ENV:-}" ]; then export NODE_ENV=test; fi + - run: export PATH="~/mathquill/mathquill/node_modules/.bin:$PATH" + - run: npm install + # Save dependency cache + - save_cache: + key: v1-dep-{{ .Branch }}-{{ epoch }} + paths: + # This is a broad list of cache paths to include many possible development environments + # You can probably delete some of these entries + - vendor/bundle + - ~/virtualenvs + - ~/.m2 + - ~/.ivy2 + - ~/.bundle + - ~/.go_workspace + - ~/.gradle + - ~/.cache/bower + # These cache paths were specified in the 1.0 config + - ~/sauce-connect + - ./node_modules + # Test + # This would typically be a build job when using workflows, possibly combined with build + # This is based on your 1.0 configuration file or project settings + - run: |- + # Generate link to Many-Worlds build and add to GitHub Commit Status + curl -i -X POST https://api.github.com/repos/mathquill/mathquill/statuses/$CIRCLE_SHA1 \ + -u MathQuillBot:$GITHUB_STATUS_API_KEY \ + -d '{ + "context": "ci/many-worlds", + "state": "success", + "description": "Try the tests on the Many-Worlds build of this commit:", + "target_url": "http://many-worlds.glitch.me/mathquill/mathquill/commit/'$CIRCLE_SHA1'/test/" + }' + # Safari on Sauce can only connect to port 3000, 4000, 7000, or 8000. Edge needs port 7000 or 8000. + # https://david263a.wordpress.com/2015/04/18/fixing-safari-cant-connect-to-localhost-issue-when-using-sauce-labs-connect-tunnel/ + # https://support.saucelabs.com/customer/portal/questions/14368823-requests-to-localhost-on-microsoft-edge-are-failing-over-sauce-connect + - run: + command: PORT=8000 make server + background: true + # Wait for tunnel to be ready (`make server` is much faster, no need to wait for it) + - run: while [ ! -e ~/sauce_is_ready ]; do sleep 1; done; touch ~/sauce_was_ready; test -z "$(<~/sauce_is_ready)" + # This is based on your 1.0 configuration file or project settings + - run: + command: |- + # Screenshots: capture in the background while running unit tests + mkdir -p $CIRCLE_TEST_REPORTS/mocha - head -1 # wait for "listening on ..." to be logged + # CircleCI expects test results to be reported in an JUnit/xUnit-style XML file: + # https://circleci.com/docs/test-metadata/#a-namemochajsamocha-for-nodejs + # Our unit tests are in a browser, so they can't write to a file, and Sauce + # apparently truncates custom data in their test result reports, so instead we + # POST to this trivial Node server on localhost:9000 that writes the body of + # any POST request to $CIRCLE_TEST_REPORTS/junit/test-results.xml + node -e ' + require("http").createServer(function(req, res) { + res.setHeader("Access-Control-Allow-Origin", "*"); + req.pipe(process.stdout); + req.on("end", res.end.bind(res)); + }) + .listen(9000); + console.error("listening on http://0.0.0.0:9000/"); + ' 2>&1 >$CIRCLE_TEST_REPORTS/junit/test-results.xml | { + # ^ note: `2>&1` must precede `>$CIRCLE_TEST_REPORTS/...` because + # shell redirect is like assignment; if it came after, then both + # stdout and stderr would be written to `xunit.xml` and nothing + # would be piped into here - # https://circleci.com/docs/environment-variables/ - build_name="CircleCI build #$CIRCLE_BUILD_NUM" - if [ $CIRCLE_PR_NUMBER ]; then - build_name="$build_name: PR #$CIRCLE_PR_NUMBER" - [ "$CIRCLE_BRANCH" ] && build_name="$build_name ($CIRCLE_BRANCH)" - else - build_name="$build_name: $CIRCLE_BRANCH" - fi - build_name="$build_name @ ${CIRCLE_SHA1:0:7}" - export MQ_CI_BUILD_NAME="$build_name" + head -1 # wait for "listening on ..." to be logged - time { test -d node_modules/wd || npm install wd; } - time node script/screenshots.js http://localhost:8000/test/visual.html \ - && touch ~/screenshots_are_ready || echo EXIT STATUS $? | tee /dev/stderr > ~/screenshots_are_ready: - } - background: true - - run: |- - # Unit tests in the browser + # https://circleci.com/docs/environment-variables/ + build_name="CircleCI build #$CIRCLE_BUILD_NUM" + if [ $CIRCLE_PR_NUMBER ]; then + build_name="$build_name: PR #$CIRCLE_PR_NUMBER" + [ "$CIRCLE_BRANCH" ] && build_name="$build_name ($CIRCLE_BRANCH)" + else + build_name="$build_name: $CIRCLE_BRANCH" + fi + build_name="$build_name @ ${CIRCLE_SHA1:0:7}" + export MQ_CI_BUILD_NAME="$build_name" - echo '1. Launch tests' - echo + time { test -d node_modules/wd || npm install wd; } + time node script/screenshots.js http://localhost:8000/test/visual.html \ + && touch ~/screenshots_are_ready || echo EXIT STATUS $? | tee /dev/stderr > ~/screenshots_are_ready: + } + background: true + - run: |- + # Unit tests in the browser - # https://circleci.com/docs/environment-variables/ - build_name="CircleCI build #$CIRCLE_BUILD_NUM" - if [ $CIRCLE_PR_NUMBER ]; then - build_name="$build_name: PR #$CIRCLE_PR_NUMBER" - [ "$CIRCLE_BRANCH" ] && build_name="$build_name ($CIRCLE_BRANCH)" - else - build_name="$build_name: $CIRCLE_BRANCH" - fi - build_name="$build_name @ ${CIRCLE_SHA1:0:7}" + echo '1. Launch tests' + echo - # "build" and "customData" parameters from: - # https://wiki.saucelabs.com/display/DOCS/Test+Configuration+Options#TestConfigurationOptions-TestAnnotation - set -o pipefail - curl -i -X POST https://saucelabs.com/rest/v1/$SAUCE_USERNAME/js-tests \ - -u $SAUCE_USERNAME:$SAUCE_ACCESS_KEY \ - -H 'Content-Type: application/json' \ - -d '{ - "name": "Unit tests, Mocha", - "build": "'"$build_name"'", - "customData": {"build_url": "'"$CIRCLE_BUILD_URL"'"}, - "framework": "mocha", - "url": "http://localhost:8000/test/unit.html?post_xunit_to=http://localhost:9000", - "platforms": [["", "Chrome", ""]] - }' \ - | tee /dev/stderr | tail -1 > js-tests.json + # https://circleci.com/docs/environment-variables/ + build_name="CircleCI build #$CIRCLE_BUILD_NUM" + if [ $CIRCLE_PR_NUMBER ]; then + build_name="$build_name: PR #$CIRCLE_PR_NUMBER" + [ "$CIRCLE_BRANCH" ] && build_name="$build_name ($CIRCLE_BRANCH)" + else + build_name="$build_name: $CIRCLE_BRANCH" + fi + build_name="$build_name @ ${CIRCLE_SHA1:0:7}" - echo '2. Wait for tests to finish:' - echo - # > Make the request multiple times as the tests run until the response - # > contains `completed: true` to the get the final results. - # https://wiki.saucelabs.com/display/DOCS/JavaScript+Unit+Testing+Methods - while true # Bash has no do...while >:( - do - sleep 5 - curl -i -X POST https://saucelabs.com/rest/v1/$SAUCE_USERNAME/js-tests/status \ + # "build" and "customData" parameters from: + # https://wiki.saucelabs.com/display/DOCS/Test+Configuration+Options#TestConfigurationOptions-TestAnnotation + set -o pipefail + curl -i -X POST https://saucelabs.com/rest/v1/$SAUCE_USERNAME/js-tests \ -u $SAUCE_USERNAME:$SAUCE_ACCESS_KEY \ -H 'Content-Type: application/json' \ - -d @js-tests.json \ - | tee /dev/stderr | tail -1 > status.json + -d '{ + "name": "Unit tests, Mocha", + "build": "'"$build_name"'", + "customData": {"build_url": "'"$CIRCLE_BUILD_URL"'"}, + "framework": "mocha", + "url": "http://localhost:8000/test/unit.html?post_xunit_to=http://localhost:9000", + "platforms": [["", "Chrome", ""]] + }' \ + | tee /dev/stderr | tail -1 > js-tests.json - # deliberately do `... != false` rather than `... == true` - # because unexpected values should break rather than infinite loop - [ "$(jq .completed Make the request multiple times as the tests run until the response + # > contains `completed: true` to the get the final results. + # https://wiki.saucelabs.com/display/DOCS/JavaScript+Unit+Testing+Methods + while true # Bash has no do...while >:( + do + sleep 5 + curl -i -X POST https://saucelabs.com/rest/v1/$SAUCE_USERNAME/js-tests/status \ + -u $SAUCE_USERNAME:$SAUCE_ACCESS_KEY \ + -H 'Content-Type: application/json' \ + -d @js-tests.json \ + | tee /dev/stderr | tail -1 > status.json - echo '3. Exit with non-zero status code if any unit tests failed' - exit "$(jq '.["js tests"][0].result.failures' ``` This lets different copies of MathQuill each power their own math fields, but using different copies on the same DOM element won't work. `.noConflict()` is primarily intended to help you reduce globals. - - # Constructors ## MQ.StaticMath(html_element) @@ -43,11 +41,15 @@ If the given element is already an editable math field, this will return a new e `\MathQuillMathField` can be used to embed editable math fields inside static math, like: ```html -\sqrt{ \MathQuillMathField{x}^2 + \MathQuillMathField{y}^2 } +\sqrt{ \MathQuillMathField{x}^2 + \MathQuillMathField{y}^2 } ``` @@ -60,8 +62,8 @@ HTML element of a static math or math field, returns an API object for it (if not, `null`): ```js -MQ(mathFieldSpan) instanceof MQ.MathField // => true -MQ(otherSpan) // => null +MQ(mathFieldSpan) instanceof MQ.MathField; // => true +MQ(otherSpan); // => null ``` ## MQ.config(config) @@ -71,7 +73,8 @@ Updates the default [configuration options](Config.md) for this instance of the If there are multiple instances of the MathQuill API, `MQ.config()` only affects the math MathQuill objects created by `MQ`. E.g.: ```javascript -var MQ1 = MathQuill.getInterface(3), MQ2 = MathQuill.getInterface(3); +var MQ1 = MathQuill.getInterface(3), + MQ2 = MathQuill.getInterface(3); MQ1.config(myConfig); MQ1.MathField(a); // configured with myConfig @@ -80,46 +83,46 @@ MQ1.MathField(b); MQ2.MathField(c); // unaffected by myConfig ``` - # Comparing MathFields ## Checking Type + ```js var staticMath = MQ.StaticMath(staticMathSpan); -mathField instanceof MQ.StaticMath // => true -mathField instanceof MQ // => true -mathField instanceof MathQuill // => true +mathField instanceof MQ.StaticMath; // => true +mathField instanceof MQ; // => true +mathField instanceof MathQuill; // => true var mathField = MQ.MathField(mathFieldSpan); -mathField instanceof MQ.MathField // => true -mathField instanceof MQ.EditableField // => true -mathField instanceof MQ // => true -mathField instanceof MathQuill // => true +mathField instanceof MQ.MathField; // => true +mathField instanceof MQ.EditableField; // => true +mathField instanceof MQ; // => true +mathField instanceof MathQuill; // => true ``` ## Comparing IDs + API objects for the same MathQuill instance have the same `.id`, which will always be a unique truthy primitive value that can be used as an object key (like an ad hoc [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) or [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)): ```js -MQ(mathFieldSpan).id === mathField.id // => true +MQ(mathFieldSpan).id === mathField.id; // => true var setOfMathFields = {}; setOfMathFields[mathField.id] = mathField; -MQ(mathFieldSpan).id in setOfMathFields // => true -staticMath.id in setOfMathFields // => false +MQ(mathFieldSpan).id in setOfMathFields; // => true +staticMath.id in setOfMathFields; // => false ``` ## Data Object + Similarly, API objects for the same MathQuill instance share a `.data` object (which can be used like an ad hoc [`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) or [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)): ```js -MQ(mathFieldSpan).data === mathField.data // => true +MQ(mathFieldSpan).data === mathField.data; // => true mathField.data.foo = 'bar'; -MQ(mathFieldSpan).data.foo // => 'bar' +MQ(mathFieldSpan).data.foo; // => 'bar' ``` - - # MathQuill base methods The following are methods that every MathQuill object has. These are the only methods that static math instances have and a subset of the methods that editable fields have. @@ -127,11 +130,13 @@ The following are methods that every MathQuill object has. These are the only me ## .revert() Any element that has been turned into a MathQuill instance can be reverted: + ```html some HTML ``` + ```js mathfield.revert().innerHTML; // => 'some HTML' ``` @@ -163,6 +168,7 @@ This will render the argument as LaTeX in the MathQuill instance. Returns the current cursor position / selection within the latex. If the cursor is before the plus this method would return: + ```js { latex: 'a+b', @@ -269,6 +275,7 @@ Changes the [configuration](Config.md) of just this math field. ## .dropEmbedded(pageX, pageY, options) **[ᴇxᴘᴇʀɪᴍᴇɴᴛᴀʟ](#note-on-experimental-features)** Insert a custom embedded element at the given coordinates, where `options` is an object like: + ```js { htmlString: '', diff --git a/docs/Code_of_Conduct.md b/docs/Code_of_Conduct.md index 7d01333ce..bf5754c27 100644 --- a/docs/Code_of_Conduct.md +++ b/docs/Code_of_Conduct.md @@ -5,14 +5,15 @@ The MathQuill project and its supporting communication channels, including GitHub, the MathQuill Slack, and the #mathquill IRC channel, are dedicated to providing a harassment-free experience for everyone, regardless of gender, gender identity and expression, sexual orientation, disability, physical appearance, age, body size, race, or religion. We do not tolerate harassment of participants in any form. Sexual language and imagery is not appropriate without discussion and pre-approval from a moderator. Participants violating these rules may be sanctioned or expelled from the group at the discretion of [@laughinghan], [@stufflebear], or another moderator. ### Additional Details + Harassment includes offensive verbal comments related to gender, gender identity and expression, sexual orientation, disability, physical appearance, age, body size, race, religion, sexual images in public spaces, deliberate intimidation, stalking, following, harassing photography or recording, sustained disruption of discussion, inappropriate contact, and unwelcome sexual attention. Disclosure of another person’s contact information including legal name or residence without their permission is also unacceptable behavior. - + Participants asked to stop any harassing or inappropriate behavior are expected to comply immediately. - + If a participant engages in harassing behavior, [@laughinghan], [@stufflebear], or another moderator may take any action they deem appropriate, including warning the offender or permanent expulsion from the channel. - + If you are being harassed, notice that someone else is being harassed, or have any other concerns, please contact us at or any moderator you feel most comfortable with as soon as possible. They will address the issue as soon as they are able to. - + ### Attribution CoC adopted from http://pastebin.com/UV8snBsV, which was adapted from http://tinyurl.com/lhc-c-of-c, which was further adapted from a private channel CoC written by @juliepagano. diff --git a/docs/Config.md b/docs/Config.md index dea197a23..4bceb13ec 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -1,6 +1,7 @@ # Setting Configuration The configuration options object is of the following form: + ```js { spaceBehavesLikeTab: true, @@ -28,8 +29,6 @@ You can configure an editable math field by passing an options argument as the s Defaults may be set with [`MQ.config(global_config)`](Api_Methods.md#mqconfigconfig). - - # Configuration Options ## spacesBehavesLikeTab @@ -118,13 +117,14 @@ Nested content in latex rendered during initialization or pasted into mathquill You can also specify a speech-friendly representation of the operator name by supplying the operator name, a `|` and its speech alternative (separate multiple words with a `-`). For example, `'sin|sine cos|cosine tan|tangent sinh|hyperbolic-sine'`. ## substituteTextarea + `substituteTextarea` is a function that creates a focusable DOM element that is called when setting up a math field. Overwriting this may be useful for hacks like suppressing built-in virtual keyboards. It defaults to `