marko 5.23.0 → 5.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. package/dist/runtime/components/entry/index-browser.js +2 -6
  2. package/dist/runtime/components/registry/index-browser.js +444 -20
  3. package/dist/runtime/components/registry/index.js +1 -1
  4. package/dist/runtime/components/renderer.js +6 -5
  5. package/dist/runtime/components/update-manager.js +7 -7
  6. package/dist/runtime/components/util/index-browser.js +4 -4
  7. package/dist/runtime/components/util/index.js +2 -2
  8. package/dist/runtime/createOut.js +1 -1
  9. package/dist/runtime/dom-insert.js +4 -4
  10. package/dist/runtime/helpers/_change-case.js +2 -2
  11. package/dist/runtime/helpers/dynamic-tag.js +4 -4
  12. package/dist/runtime/helpers/repeatable.js +12 -0
  13. package/dist/runtime/helpers/self-iterator.js +3 -0
  14. package/dist/runtime/helpers/style-value.js +1 -1
  15. package/dist/runtime/html/AsyncStream.js +14 -14
  16. package/dist/runtime/html/BufferedWriter.js +2 -2
  17. package/dist/runtime/html/create-readable/index-browser.js +1 -1
  18. package/dist/runtime/html/create-readable/index.js +9 -9
  19. package/dist/runtime/html/helpers/_dynamic-attr.js +2 -2
  20. package/dist/runtime/html/helpers/attr.js +3 -3
  21. package/dist/runtime/html/helpers/data-marko.js +1 -1
  22. package/dist/runtime/html/helpers/escape-quotes.js +1 -1
  23. package/dist/runtime/html/helpers/escape-xml.js +1 -1
  24. package/dist/runtime/html/index.js +2 -2
  25. package/dist/runtime/renderable.js +5 -5
  26. package/dist/runtime/setImmediate/index-browser.js +1 -1
  27. package/dist/runtime/setImmediate/index-worker.js +2 -2
  28. package/dist/runtime/setImmediate/index.js +2 -2
  29. package/dist/runtime/vdom/AsyncVDOMBuilder.js +74 -74
  30. package/dist/runtime/vdom/VComponent.js +3 -3
  31. package/dist/runtime/vdom/VDocumentFragment.js +7 -7
  32. package/dist/runtime/vdom/VElement.js +44 -44
  33. package/dist/runtime/vdom/VFragment.js +5 -5
  34. package/dist/runtime/vdom/VNode.js +32 -32
  35. package/dist/runtime/vdom/VText.js +8 -8
  36. package/dist/runtime/vdom/helpers/v-element.js +1 -1
  37. package/dist/runtime/vdom/helpers/v-text.js +1 -1
  38. package/dist/runtime/vdom/hot-reload.js +4 -4
  39. package/dist/runtime/vdom/index.js +2 -2
  40. package/dist/runtime/vdom/morphdom/fragment.js +4 -4
  41. package/dist/runtime/vdom/morphdom/helpers.js +4 -4
  42. package/dist/runtime/vdom/morphdom/index.js +36 -36
  43. package/dist/runtime/vdom/morphdom/specialElHandlers.js +6 -6
  44. package/dist/runtime/vdom/preserve-attrs.js +1 -1
  45. package/dist/runtime/vdom/vdom.js +14 -14
  46. package/docs/body-content.md +37 -18
  47. package/docs/class-components.md +1 -1
  48. package/docs/express.md +2 -2
  49. package/docs/fastify.md +1 -1
  50. package/docs/rendering.md +14 -4
  51. package/docs/typescript.md +13 -13
  52. package/index.d.ts +4 -2
  53. package/package.json +3 -3
  54. package/src/runtime/components/entry/index-browser.js +2 -6
  55. package/src/runtime/components/registry/index-browser.js +451 -27
  56. package/src/runtime/components/renderer.js +2 -1
  57. package/src/runtime/helpers/repeatable.js +12 -0
  58. package/src/runtime/helpers/self-iterator.js +3 -0
  59. package/dist/runtime/components/init-components/index-browser.js +0 -453
  60. package/dist/runtime/components/init-components/index.js +0 -2
  61. package/dist/runtime/components/init-components/package.json +0 -11
  62. package/src/runtime/components/init-components/index-browser.js +0 -453
  63. package/src/runtime/components/init-components/index.js +0 -1
  64. package/src/runtime/components/init-components/package.json +0 -11
package/docs/express.md CHANGED
@@ -29,7 +29,7 @@ Express’s builtin view engine may be asynchronous, but it doesn’t support st
29
29
 
30
30
  [The `@marko/express` package](https://www.npmjs.com/package/@marko/express) adds a `res.marko()` method to [Express’s response object](https://expressjs.com/en/api.html#res). This method works like [`res.render()`](https://expressjs.com/en/api.html#res.render), but without the restrictions of Express’s view engine, letting you take full advantage of Marko’s streaming and modular template organization.
31
31
 
32
- > **ProTip**: By using `res.marko()`, properties from [`app.locals`](https://expressjs.com/en/api.html#app.locals) and [`res.locals`](https://expressjs.com/en/api.html#res.locals) are automatically [available on `out.global`](https://markojs.com/docs/rendering/#global-data).
32
+ > **ProTip**: By using `res.marko()`, properties from [`app.locals`](https://expressjs.com/en/api.html#app.locals) and [`res.locals`](https://expressjs.com/en/api.html#res.locals) are automatically [available on `$global`](https://markojs.com/docs/rendering/#global-data).
33
33
 
34
34
  ```js
35
35
  import express from "express";
@@ -50,7 +50,7 @@ app.get("/", function (req, res) {
50
50
  app.listen(8080);
51
51
  ```
52
52
 
53
- > **Note**: Older versions of `@marko/express` used to also attach Express’s `app`, `req`, and `res` objects onto `out.global`. This meant uncontrolled network data could cause new and exciting surprises in your app code. Nowadays we recommend explicitly accessing the specific pieces of the HTTP exchange you’re interested in, like this:
53
+ > **Note**: Older versions of `@marko/express` used to also attach Express’s `app`, `req`, and `res` objects onto `$global`. This meant uncontrolled network data could cause new and exciting surprises in your app code. Nowadays we recommend explicitly accessing the specific pieces of the HTTP exchange you’re interested in, like this:
54
54
  >
55
55
  > ```js
56
56
  > app.get("/", function (req, res) {
package/docs/fastify.md CHANGED
@@ -21,7 +21,7 @@ npm install marko @marko/fastify fastify --save
21
21
 
22
22
  The [`@marko/fastify`](https://github.com/marko-js/fastify/) adds a `reply.marko` decorator to the `reply` object. This function allows us to pass in a Marko template and supports Marko's streaming and modular approach to templates.
23
23
 
24
- By using `reply.marko` you'll automatically have access to `app.locals`, and `reply.locals` from within your Marko template and custom tags. These values are added to `out.global`.
24
+ By using `reply.marko` you'll automatically have access to `app.locals`, and `reply.locals` from within your Marko template and custom tags. These values are added to `$global`.
25
25
 
26
26
  ```javascript
27
27
  import fastify from "fastify";
package/docs/rendering.md CHANGED
@@ -209,7 +209,7 @@ This method is available on the server, but not available by default in the brow
209
209
 
210
210
  ## Global data
211
211
 
212
- If you need to make data available to all rendered views, use the `$global` property on the input data object. This property will be removed from `input` and merged into the `out.global` property.
212
+ If you need to make data available to all rendered views, use the `$global` property on the input data object. This property will be removed from `input` and provided to the template through a variable called `$global`. It is also made available on the `out.global` property.
213
213
 
214
214
  Global values persist across renders.
215
215
 
@@ -221,11 +221,21 @@ View.render({
221
221
  });
222
222
  ```
223
223
 
224
+ Within the template you can access `$global` similar to accessing `input`.
225
+
226
+ ```marko
227
+ <div>
228
+ You are on ${$global.flags.includes("mobile") ? "mobile" : "desktop"}
229
+ </div>
230
+ ```
231
+
232
+ > **Note:** `$global` is not available within [`static`](./syntax.md#static-javascript) parts of the template. In order to reference `$global` within the component class you must use `out.global` from one of the lifecycle methods that provide it.
233
+
224
234
  > **Warning:** Use `$global` with caution; it is visible in any component.
225
235
 
226
236
  ### Sending global data to browsers
227
237
 
228
- ⚠️ To prevent accidentally exposing sensitive data, by default **no keys** in `out.global` are sent to browsers. To serialize data to the frontend, name the desired properties in `$global.serializedGlobals`.
238
+ ⚠️ To prevent accidentally exposing sensitive data, by default **no keys** in `$global` are sent to browsers. To serialize data to the frontend, name the desired properties in `$global.serializedGlobals`.
229
239
 
230
240
  Values must be serializable by [the `warp10` module](https://www.npmjs.com/package/warp10).
231
241
 
@@ -238,8 +248,8 @@ app.get("/", (req, res) => {
238
248
  Page.render(
239
249
  {
240
250
  $global: {
241
- isIos: /iPad|iPhone/.test(ua), // Serialized and available on the server and browser as `out.global.isIos`
242
- isAndroid: /Android/.test(ua), // Serialized and available on the server and browser as `out.global.isAndroid`
251
+ isIos: /iPad|iPhone/.test(ua), // Serialized and available on the server and browser as `$global.isIos`
252
+ isAndroid: /Android/.test(ua), // Serialized and available on the server and browser as `$global.isAndroid`
243
253
  req, // Only available server-side and not serialized, because it’s not in `serializedGlobals`
244
254
 
245
255
  serializedGlobals: {
@@ -18,7 +18,7 @@ There are two (non-exclusive) ways to add TypeScript to a Marko project:
18
18
  📦 package.json
19
19
  <mark><img src="./icons/ts.svg" width=16> tsconfig.json</mark>
20
20
  </pre>
21
- - **If you’re [publishing packages of Marko tags](https://markojs.com/docs/custom-tags/#publishing-tags-to-npm)**, add the following to [your `marko.json`](https://markojs.com/docs/marko-json/):
21
+ - **If you’re [publishing packages of Marko tags](https://markojs.com/docs/custom-tags/#publishing-tags-to-npm)**, add the following to [your `marko.json`](./marko-json.md):
22
22
  ```json
23
23
  "script-lang": "ts"
24
24
  ```
@@ -28,7 +28,7 @@ There are two (non-exclusive) ways to add TypeScript to a Marko project:
28
28
 
29
29
  ## Typing a tag's `input`
30
30
 
31
- A `.marko` file will use any exported `Input` type for [that file’s `input` object](https://markojs.com/docs/class-components/#input).
31
+ A `.marko` file will use any exported `Input` type for [that file’s `input` object](./class-components.md#input).
32
32
 
33
33
  This can be `export type Input` or `export interface Input`.
34
34
 
@@ -66,7 +66,7 @@ export interface Input extends PriceInput {
66
66
 
67
67
  ### Generic `Input`s
68
68
 
69
- [Generic Types and Type Parameters](https://www.typescriptlang.org/docs/handbook/2/generics.html) on `Input` are recognized throughout the entire `.marko` template (excluding [static statements](https://markojs.com/docs/syntax/#static-javascript)).
69
+ [Generic Types and Type Parameters](https://www.typescriptlang.org/docs/handbook/2/generics.html) on `Input` are recognized throughout the entire `.marko` template (excluding [static statements](./syntax.md#static-javascript)).
70
70
 
71
71
  For example, if you set up a component like this:
72
72
 
@@ -114,19 +114,19 @@ Marko exposes [type definitions](https://github.com/marko-js/marko/blob/main/pac
114
114
  - **`Marko.TemplateInput<Input>`**
115
115
  - The object accepted by the render methods of a template. It includes the template's `Input` as well as `$global` values.
116
116
  - **`Marko.Body<Params, Return>`**
117
- - The type of the [body content](https://markojs.com/docs/body-content/) of a tag (`renderBody`)
117
+ - The type of the [body content](./body-content.md) of a tag (`renderBody`)
118
118
  - **`Marko.Component<Input, State>`**
119
- - The base class for a [class component](https://markojs.com/docs/class-components/)
119
+ - The base class for a [class component](./class-components.md)
120
120
  - **`Marko.Renderable`**
121
- - Values accepted by the [`<${dynamic}/>` tag](https://markojs.com/docs/syntax/#dynamic-tagname)
121
+ - Values accepted by the [`<${dynamic}/>` tag](./syntax.md#dynamic-tagname)
122
122
  - `string | Marko.Template | Marko.Body | { renderBody: Marko.Body}`
123
123
  - **`Marko.Out`**
124
124
  - The render context with methods like `write`, `beginAsync`, etc.
125
125
  - `ReturnType<template.render>`
126
126
  - **`Marko.Global`**
127
- - The type of the object on `out.global` that can be passed to a template's render methods as the `$global` property
127
+ - The type of the object in `$global` and `out.global` that can be passed to a template's render methods as the `$global` property.
128
128
  - **`Marko.RenderResult`**
129
- - The [result](https://markojs.com/docs/rendering/#renderresult) of rendering a Marko template
129
+ - The [result](./rendering.md#renderresult) of rendering a Marko template
130
130
  - `ReturnType<template.renderSync>`
131
131
  - `Awaited<ReturnType<template.render>>`
132
132
  - **`Marko.Emitter`**
@@ -137,10 +137,10 @@ Marko exposes [type definitions](https://github.com/marko-js/marko/blob/main/pac
137
137
  - Helpers to extract the input and return types for the specified `keyof Marko.NativeTag`
138
138
  - **`Marko.BodyParameters<Body>`** and **`Marko.BodyReturnType<Body>`**
139
139
  - Helpers to extract the parameters and return types from the specified `Marko.Body`
140
- - **`Marko.Repeated<T>`** and **`Marko.Repeatable<T>`**
141
- - Used to represent types for attributes tags which can have one or many instances
142
- - `Marko.Repeated<T>`: `[T, T, ...T[]]` (array with at least two items)
143
- - `Marko.Repeatable<T>`: `T | Marko.Repeated<T>`
140
+ - **`Marko.AttrTag<T>`** and **`Marko.RepeatableAttrTag<T>`**
141
+ - Used to represent types for [attributes tags](./body-content.md#named-body-content)
142
+ - `Marko.AttrTag<T>`: A single attribute tag
143
+ - `Marko.RepeatableAttrTag<T>`: One or more attribute tags
144
144
 
145
145
  ### Typing `renderBody`
146
146
 
@@ -221,7 +221,7 @@ $ const { color, renderBody, ...restOfInput } = input;
221
221
 
222
222
  ## TypeScript Syntax in `.marko`
223
223
 
224
- Any [JavaScript expression in Marko](https://markojs.com/docs/syntax/#inline-javascript) can also be written as a TypeScript expression.
224
+ Any [JavaScript expression in Marko](./syntax.md#inline-javascript) can also be written as a TypeScript expression.
225
225
 
226
226
  ### Tag Type Parameters
227
227
 
package/index.d.ts CHANGED
@@ -311,8 +311,8 @@ declare namespace Marko {
311
311
  removeAllListeners(eventName?: PropertyKey): this;
312
312
  }
313
313
 
314
- export type Repeated<T> = [T, T, ...T[]];
315
- export type Repeatable<T> = T | Repeated<T>;
314
+ export type AttrTag<T> = T & Iterable<AttrTag<T>>;
315
+ export type RepeatableAttrTag<T> = Repeatable<AttrTag<T>>;
316
316
 
317
317
  export interface NativeTags {
318
318
  [name: string]: {
@@ -326,3 +326,5 @@ declare namespace Marko {
326
326
  export type NativeTagReturn<Name extends keyof NativeTags> =
327
327
  NativeTags[Name]["return"];
328
328
  }
329
+
330
+ type Repeatable<T> = T | [T, T, ...T[]];
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "5.23.0",
3
+ "version": "5.25.0",
4
4
  "license": "MIT",
5
5
  "description": "UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.",
6
6
  "dependencies": {
7
- "@marko/compiler": "^5.25.0",
8
- "@marko/translator-default": "^5.23.0",
7
+ "@marko/compiler": "^5.27.0",
8
+ "@marko/translator-default": "^5.25.0",
9
9
  "app-module-path": "^2.2.0",
10
10
  "argly": "^1.2.0",
11
11
  "browser-refresh-client": "1.1.4",
@@ -1,11 +1,7 @@
1
- var initComponents = require("../init-components");
2
- require("../ComponentsContext").___initClientRendered =
3
- initComponents.___initClientRendered;
1
+ var registry = require("../registry");
4
2
 
5
3
  exports.getComponentForEl = require("../util").___getComponentForEl;
6
- exports.init = window.$initComponents = initComponents.___initServerRendered;
7
-
8
- var registry = require("../registry");
4
+ exports.init = registry.___initServerRendered;
9
5
  exports.register = function (id, component) {
10
6
  registry.r(id, function () {
11
7
  return component;