Commit graph

310 commits

Author SHA1 Message Date
Yorhel
c9f185c6c9 Shrinking 2024-10-01 13:21:35 +02:00
kfule
b5857a7cd0
m.domFor(): workaround for unintentional mangling. Fix #2842 (#2981) 2024-10-01 08:04:42 +10:00
kfule
0b8dd459dd Always keep key in vnode.attrs if it exists
Because vnode.attrs is never null by commit f9e5163
2024-09-25 19:24:55 -07:00
kfule
a644d9f7ad Remove code when vnode.attrs is null
Because vnode.attrs is never null by commit f9e5163
2024-09-25 19:24:55 -07:00
Kory Nunn
8e7ef427e0
Remove dependance on global window and document (#2897)
* Remove dependance on global window and document

* Use any available document, prioritising parent.ownerDocument

* Fix mockDom for DocumentFragment, revert to better ownerDocument implementation

* Simplify activeElement usage
2024-09-23 04:54:03 -07:00
Keita Furui
6c1c5cf106
hyperscript: handles shared empty attrs, fixes #2821 2024-09-23 04:49:54 -07:00
Pierre-Yves Gérardy
c1fc1de772
Bypass css text (#2811)
* [DOM mocks] enable setting element.style

* Use the style setter directly
2023-01-17 15:04:19 +01:00
Barney
da76ed9054 Bundler can't parse multiple exports per module 2022-07-02 15:01:56 -07:00
Pierre-Yves
8cb7988096 Add tests for the hooks for a delayed removal in a fragment, address other review concerns 2022-06-21 17:02:05 +02:00
Barney
9af9ea66a2 Simplify domFor logic 2022-06-21 17:02:05 +02:00
Barney
62b6308295 camelCase file references dom-for -> domFor 2022-06-21 17:02:05 +02:00
Pierre-Yves
665578060e Address review comments, linter and build concerns 2022-06-21 17:02:05 +02:00
Pierre-Yves
3fd82e6359 implement m.domFor() and use it internally to move and remove nodes. Fix #2780 2022-06-21 17:02:05 +02:00
Pierre-Yves Gérardy
efdb563fa5
Remove a stale comment
This hasn't been true since v2.0
2022-06-01 09:37:11 +02:00
Stephan Hoyer
e9a365c150 Kick promise polyfill 2022-05-30 08:38:13 +02:00
Stephan Hoyer
9906e23118 Fix naming 2022-03-02 07:35:35 +01:00
Stephan Hoyer
885b3f9442 Consistent naming of Mithril.js 2022-02-19 12:06:39 +01:00
Barney Carroll
f9e51636d8 vnode.attrs is never null 2022-02-12 12:19:35 +01:00
Barney Carroll
e4c6621ba8 Updating textarea subtree should not be expected to override user input 2022-02-12 12:19:35 +01:00
Barney Carroll
d021271be8 Non-mutating m.fragment/m.trust references 2022-02-12 12:19:35 +01:00
Barney Carroll
a3983c9655 Remove redundant child normalisation 2022-02-12 12:19:35 +01:00
Barney Carroll
0f9274f873 Fix lint errors 2022-02-12 12:19:35 +01:00
Barney Carroll
9999fbe2a4 Text is always represented as text vnodes, never as vnode.text 2022-02-12 12:19:35 +01:00
Barney Carroll
31d2ed4be8 Tests use hyperscript instead of manually constructing nodes 2022-02-12 12:19:35 +01:00
Stephan Hoyer
b97fd59381 Warn about reusing mutated attrs object - fixes #2719 2022-02-09 20:37:02 +01:00
Stephan Hoyer
ab4b21dacc Make sure title attrs are removed properly - fixes #2676 2022-01-26 09:57:41 +01:00
Barney Carroll
ade77f37c9
Remove unreachable keyed node logic, fixes #2597 (#2673) 2021-04-18 18:14:21 +01:00
Isiah Meadows
9f0dc2ab46
Runtime-deprecate ospec, change change-log to changelog, fix a few assorted bugs (#2578) 2020-09-29 13:27:07 -07:00
ZeikJT
cf7a841c4c
Remove extra isLifecycleMethod call from removeAttr (#2594) 2020-05-17 00:50:16 -07:00
Tim Gates
11e8e861fc
docs: Fix simple typo, subsequece -> subsequence (#2582)
There is a small typo in mithril.js, render/render.js.

Should read `subsequence` rather than `subsequece`.
2020-04-08 12:07:28 -07:00
Isiah Meadows
d4551f49f5
Add streams to releases again, include minified bundle, drop in… (#2539)
* Minify stream, add stream stuff to releases again

* Kill off a lot of tech debt, drop internal utilities from npm

1. Kill `module/`, internalize `bundler/`, privatize `test-utils/`

We've been telling people to move elsewhere from these for a while, and
it's about time we just pull the plug here and finally remove them.

- We officially removed the bundler from the public API in v2.0, and
  that was the only one of these that was ever publicly documented.
  Usage should be low enough by now it shouldn't break anyone- I'm not
  seeing bundler bugs being reported anymore, either.
- The `module/` utility was so narrow and caveat-filled that I'm not
  sure anyone really used it (even us core Mithril devs never really
  used it), and we only had it documented in the repo folder it lived
  in. I think only one bug was ever filed, and it's because it somehow
  ended up completely non-functional without any of us realizing it.
- The test utilities were meant to be internal from day 1, but people
  started using it despite us core developers constantly telling people
  to look elsewhere and even the docs recommending specific alternatives
  without mention of our internal mocks. (Now if people would RTFM,
  that'd be nice...)

2. Add dedicated HTML test files to verify ospec and the promise
   polyfill, and ensure the promise tests are in pure ES5.

These are made specially for those and should be much easier to just run
now.

3. Fix the benchmark script to use the real DOM in browsers and to not
   require as many dependencies to create. Also, tweak them to be much
   more effective and precise on what's being tested.

Previously, it was rendering to the HTML file itself, while now it's
rendering to the `body`. This means in browsers, it's triggering layout
and everything, benchmarking how well Mithril optimizes for style and
layout recalcs, too. It also puts some pressure on the hyperscript
parser attribute application, so that can be noticed as well.

* Update dependencies
2019-10-03 04:58:14 -04:00
Isiah Meadows
34f4363357
Add m.censor, adjust m.route.Link to use it (#2538)
Also, restructure a few things for better code reuse.
2019-09-30 18:44:39 -04:00
Isiah Meadows
b98ab29efd
Make errors and their messages more accurate and helpful (#2536)
Also, I normalized them to all be sentences for consistency, and I moved
the reentrancy check from `m.mount` to `m.render` to be a little more
helpful. The router change during mounting is inconsequential and only
to avoid the new modified error, and the change to the update loop is to
send the original error if an error occurred while initializing the
default route. (This is all around more useful anyways.)

And while I was at it, I fixed an obscure bug with sync redraws.
2019-09-30 16:08:04 -04:00
Isiah Meadows
30ad45caa1
Unbreak m.trust (#2516)
* Actually return the check from `maybeSetContentEditable`

Lots of code paths relied on it being a boolean. When I created the
abstraction, I apparently forgot to make sure it returned the result.

* Don't forget to copy instance state over

* Update changelog [skip ci]

* Fix changelog issue [skip ci]
2019-08-17 14:38:10 -04:00
Isiah Meadows
39fa2b32c2
Fix #1881 + related ospec bug (#2492)
* Fix #1881 + related ospec bug

* Test duplicate resolves, update changelog
2019-07-26 18:19:40 -04:00
Isiah Meadows
4cbcaf2936
Fix link + docs (#2476)
* Fix a copy/paste fail

Also, fix some incorrect tests.

* Clarify how routes are diffed, improve key + route resolver docs

- Add some missing links to route resolvers and single-child keyed
  fragments, clarify usage around them.
- Drive-by: remove a redundant sentence that itself was missing a
  period.

* Actually test for propagation and preventDefault

Previously, the mocks were both junk and inaccurate. No wonder my tests
were silently failing - they were wrong and not obviously wrong.
2019-07-16 16:03:24 -04:00
Isiah Meadows
582bda56dc
Partially recast the router API to be a lot more intuitive. (#2469)
* Recast the router API to be a lot more intuitive.

Fixes #2387
Fixes #2072
Fixes quite a few issues reported on Gitter.

For `m.route.Link`:

- More intuitive
- More accessible
- More ergonomic
- It can be disabled
- It can be cancelled
- It can be changed
- Oh, and you can use it isomorphically.

For `m.route.prefix`

- You can *read* it.
- You can write to it, of course.
- It's literally just setting a property.

For the router itself (and the rest of Mithril):

- You can now `require("mithril")` and all its submodules without a DOM
  at all. There is a catch: you can't instantiate any routes, you can't
  mount anything, and you can't invoke `m.render` in any capacity. You
  can only use `m.route.Link`, `m.route.prefix`, hyperscript stuff, and
  `mithril/stream`, and you can use `m.request` with `background: true`
  if you use a global XHR polyfill. (You can't use `m.request` without
  `background: true` except with a DOM to redraw with.) The goal here is
  to try to get out of the way for simple testing and to defer the
  inevitable `TypeError`s for the relevant DOM methods to runtime.

  The factory requires no arguments, and in terms of globals, you can
  just figure out based on what errors are thrown what globals to
  define. Their values don't matter - they just need to be set to
  *something*, even if it's just `null` or `undefined`, before Mithril
  executes.

Had to make quite a few other changes throughout the docs and tests to
update them accordingly. Oh, and that massive router overhaul enabled me
to do all this.

Also, slip in a few drive-by fixes to the mocks so they're a little
easier to work with and can accept more URLs. This was required for a
few of the tests.

* Update changelog + numbers, add forgotten bundle option

* Add PR numbers to changelog [skip ci]

* Allow continuing to the next match by returning `false`.

* Update numbers again
2019-07-12 15:29:37 -04:00
Isiah Meadows
1f4b2cf49a
Deservicify core (#2458)
* De-servicify router (mostly)

Still uses the redraw service, but it no longer has an intermediate
service of its own.

Also, did a *lot* of test deduplication in this. About 30-40% of the
router service tests were already tested on the main router API instance
itself.

Bundle size decreased from 9560 to 9548 bytes min+gzip.

* Merge `m.mount` + `m.redraw`, update router

Simplifies the router and redraw mechanism, and makes it much easier to
keep predictable.

Bundle size down to 9433 bytes min+gzip, docs updated accordingly.

* Make `mithril/render` just return the `m.render` function directly.

* Deservicify `m.render`, revise `m.route`

- You now have to use `mithril/render/render` directly if you want an
  implicit redraw function. (This will likely be going away in v3.)
- Revise `m.route` to only `key` components

* Add `redraw` to `m.render`, deservicify requests

* Test error logging

* Update docs + changelog [skip ci]
2019-07-07 18:28:43 -04:00
Isiah Meadows
db277217f8
Move fragment type check to normalizer (#2462)
Should result in more informative stack traces.

Fixes #2461
2019-07-07 17:16:56 -04:00
Isiah Meadows
6c562d2b9b
Fix keys, normalize holes (#2452)
* Fix #2434

* Treat holes as unkeyed, normalize boolean/null/undefined

This brings a lot better consistency with that API, even though it's
slightly breaking. (I had to update a bunch of tests to correspond with
it.)

* Fill in PR number [skip ci]
2019-07-03 17:05:44 -04:00
Isiah Meadows
ddc8adbbd3
Fix #2424 (#2450)
* Fix #2424

* Add PR ref
2019-07-03 14:41:37 -04:00
Isiah Meadows
9e9b89d900
Fix #2067 (#2447)
* Fix #2067

* Add PR number [skip ci]
2019-07-03 04:53:45 -04:00
Vasil Rimar
39c20bdb34 Handle [ fragment selector. Fixes #2349 (#2352)
* Handle `[` fragment selector. Fix #2349

* Update tests

* Simplify hyperscript function
2019-01-07 04:56:09 -05:00
Isiah Meadows
966e78bcab
Allow variadic arguments to m.fragment (#2328)
* Implement support for variadic arguments to `m.fragment`

While I was at it, I refactored the common logic out of `hyperscript`.

* Add a missed change from #2326

* Update docs + changelog [skip ci]

* Explain rationale for `hyperscriptVnode`'s calling convention

This way, it doesn't get erroneously "cleaned up" into something worse,
and so it's clearer how it'd be potentially optimized once ES5 support
is dropped.
2018-12-05 23:57:42 -05:00
Isiah Meadows
8134c51a48
Fix style updates to avoid unnecessary allocation (#2312)
* Fix style updates to avoid unnecessary allocation

- Drive-by: properly censor `cssFloat` -> css `float:` to match DOM
  behavior

* Document `style` syntax + custom property support. [skip ci]

* Add a missing test

* Add a few more descriptive comments.

* Update changelog [skip ci]
2018-12-03 14:31:08 -05:00
Isiah Meadows
462fb659d7
Fix event handler this value, simplify redraw handling (#2320)
Shaves 10 bytes off the bundle from smaller name + reduced indirection
2018-12-03 06:35:27 -05:00
Isiah Meadows
4a641092dc
Officially drop IE9-10 support, pull out our hacks (#2296)
- I also fixed a bunch of related comments
- I had to polyfill `requestAnimationFrame` for Node
- Drive-by: run `eslint . --fix`
- Drive-by: update transpiling info in CONTRIBUTING.md
- Drive-by: we aren't the only ones going semicolon-free
2018-11-27 18:04:15 -05:00
Isiah Meadows
a8473e63c9
Reverse hook order for all but onbeforeupdate (#2297)
- Drive-by: `onbeforeupdate` prevents subtree redraw if *either* hook
  returns `false`, not *both*.
2018-11-27 18:02:48 -05:00
Rasmus Porsager
7c299ab48c Allow css vars with uppercase characters (#2311)
* Allow css vars with uppercase characters

* Remove charAt

* Extract dash lowercase lambda

* Extract match uppercase regex

* Set key and value correctly in updateStyle

* Fix domMock style to work like the browser
2018-11-26 09:40:08 -05:00
Barney Carroll
4c5968a526 Fix #2192 (#2308)
* Fix #2192

* Fix mock style property definitions

* Re-instate camelCased style property key declaration support

* Fix removeProperty, eslint fix

* Stringify style keys: fix perf tests

* Fix weird uncaught mixed whitespace

* Fix weird uncaught mixed whitespace
2018-11-26 05:49:16 -05:00