@shadow-js/web 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/README.md +190 -2
- package/dist/dev/attributes.d.ts +90 -0
- package/dist/dev/attributes.js +196 -0
- package/dist/dev/attributes.js.map +1 -0
- package/dist/dev/autofocus.d.ts +32 -0
- package/dist/dev/autofocus.js +45 -0
- package/dist/dev/autofocus.js.map +1 -0
- package/dist/dev/class-style.d.ts +89 -0
- package/dist/dev/class-style.js +197 -0
- package/dist/dev/class-style.js.map +1 -0
- package/dist/dev/component.d.ts +23 -0
- package/dist/dev/component.js +42 -0
- package/dist/dev/component.js.map +1 -0
- package/dist/dev/control-flow/activity.d.ts +58 -0
- package/dist/dev/control-flow/activity.js +136 -0
- package/dist/dev/control-flow/activity.js.map +1 -0
- package/dist/dev/control-flow/branch.js +104 -0
- package/dist/dev/control-flow/branch.js.map +1 -0
- package/dist/dev/control-flow/client-only.d.ts +48 -0
- package/dist/dev/control-flow/client-only.js +50 -0
- package/dist/dev/control-flow/client-only.js.map +1 -0
- package/dist/dev/control-flow/dynamic.d.ts +82 -0
- package/dist/dev/control-flow/dynamic.js +134 -0
- package/dist/dev/control-flow/dynamic.js.map +1 -0
- package/dist/dev/control-flow/error-boundary.d.ts +72 -0
- package/dist/dev/control-flow/error-boundary.js +115 -0
- package/dist/dev/control-flow/error-boundary.js.map +1 -0
- package/dist/dev/control-flow/for.d.ts +80 -0
- package/dist/dev/control-flow/for.js +23 -0
- package/dist/dev/control-flow/for.js.map +1 -0
- package/dist/dev/control-flow/fragment.d.ts +38 -0
- package/dist/dev/control-flow/fragment.js +31 -0
- package/dist/dev/control-flow/fragment.js.map +1 -0
- package/dist/dev/control-flow/hot-link.js +64 -0
- package/dist/dev/control-flow/hot-link.js.map +1 -0
- package/dist/dev/control-flow/index-list.d.ts +48 -0
- package/dist/dev/control-flow/index-list.js +31 -0
- package/dist/dev/control-flow/index-list.js.map +1 -0
- package/dist/dev/control-flow/index.d.ts +15 -0
- package/dist/dev/control-flow/lazy.d.ts +58 -0
- package/dist/dev/control-flow/lazy.js +64 -0
- package/dist/dev/control-flow/lazy.js.map +1 -0
- package/dist/dev/control-flow/no-hydration.d.ts +39 -0
- package/dist/dev/control-flow/no-hydration.js +58 -0
- package/dist/dev/control-flow/no-hydration.js.map +1 -0
- package/dist/dev/control-flow/portal.d.ts +69 -0
- package/dist/dev/control-flow/portal.js +134 -0
- package/dist/dev/control-flow/portal.js.map +1 -0
- package/dist/dev/control-flow/root-errors.d.ts +25 -0
- package/dist/dev/control-flow/root-errors.js +33 -0
- package/dist/dev/control-flow/root-errors.js.map +1 -0
- package/dist/dev/control-flow/show.d.ts +101 -0
- package/dist/dev/control-flow/show.js +18 -0
- package/dist/dev/control-flow/show.js.map +1 -0
- package/dist/dev/control-flow/suspense-list.d.ts +65 -0
- package/dist/dev/control-flow/suspense-list.js +105 -0
- package/dist/dev/control-flow/suspense-list.js.map +1 -0
- package/dist/dev/control-flow/suspense.d.ts +53 -0
- package/dist/dev/control-flow/suspense.js +102 -0
- package/dist/dev/control-flow/suspense.js.map +1 -0
- package/dist/dev/control-flow/switch.d.ts +85 -0
- package/dist/dev/control-flow/switch.js +90 -0
- package/dist/dev/control-flow/switch.js.map +1 -0
- package/dist/dev/derived.d.ts +52 -0
- package/dist/dev/derived.js +34 -0
- package/dist/dev/derived.js.map +1 -0
- package/dist/dev/element.d.ts +40 -0
- package/dist/dev/element.js +105 -0
- package/dist/dev/element.js.map +1 -0
- package/dist/dev/events.d.ts +87 -0
- package/dist/dev/events.js +265 -0
- package/dist/dev/events.js.map +1 -0
- package/dist/dev/extend.d.ts +12 -0
- package/dist/dev/extend.js +12 -0
- package/dist/dev/head/components.d.ts +137 -0
- package/dist/dev/head/components.js +170 -0
- package/dist/dev/head/components.js.map +1 -0
- package/dist/dev/head/registry.js +68 -0
- package/dist/dev/head/registry.js.map +1 -0
- package/dist/dev/head/server-head.d.ts +54 -0
- package/dist/dev/head/server-head.js +76 -0
- package/dist/dev/head/server-head.js.map +1 -0
- package/dist/dev/head/sink.js +96 -0
- package/dist/dev/head/sink.js.map +1 -0
- package/dist/dev/head/use-head.d.ts +35 -0
- package/dist/dev/head/use-head.js +84 -0
- package/dist/dev/head/use-head.js.map +1 -0
- package/dist/dev/head/validate.d.ts +85 -0
- package/dist/dev/head/validate.js +268 -0
- package/dist/dev/head/validate.js.map +1 -0
- package/dist/dev/hmr.d.ts +82 -0
- package/dist/dev/hmr.js +124 -0
- package/dist/dev/hmr.js.map +1 -0
- package/dist/dev/hydration.d.ts +61 -0
- package/dist/dev/hydration.js +120 -0
- package/dist/dev/hydration.js.map +1 -0
- package/dist/dev/index.d.ts +45 -0
- package/dist/dev/index.js +34 -0
- package/dist/dev/insert.d.ts +97 -0
- package/dist/dev/insert.js +357 -0
- package/dist/dev/insert.js.map +1 -0
- package/dist/dev/internal/claim.d.ts +106 -0
- package/dist/dev/internal/claim.js +357 -0
- package/dist/dev/internal/claim.js.map +1 -0
- package/dist/dev/internal/css-units.js +26 -0
- package/dist/dev/internal/css-units.js.map +1 -0
- package/dist/dev/internal/diagnostics.d.ts +30 -0
- package/dist/dev/internal/diagnostics.js +38 -0
- package/dist/dev/internal/diagnostics.js.map +1 -0
- package/dist/dev/internal/early-events.js +76 -0
- package/dist/dev/internal/early-events.js.map +1 -0
- package/dist/dev/internal/hydration-hooks.d.ts +43 -0
- package/dist/dev/internal/hydration-hooks.js +27 -0
- package/dist/dev/internal/hydration-hooks.js.map +1 -0
- package/dist/dev/internal/hydration-scope.d.ts +131 -0
- package/dist/dev/internal/hydration-scope.js +156 -0
- package/dist/dev/internal/hydration-scope.js.map +1 -0
- package/dist/dev/internal/names.d.ts +33 -0
- package/dist/dev/internal/names.js +35 -0
- package/dist/dev/internal/names.js.map +1 -0
- package/dist/dev/internal/portal-context.d.ts +39 -0
- package/dist/dev/internal/portal-context.js +28 -0
- package/dist/dev/internal/portal-context.js.map +1 -0
- package/dist/dev/internal/react-names.js +116 -0
- package/dist/dev/internal/react-names.js.map +1 -0
- package/dist/dev/internal/reconcile.d.ts +40 -0
- package/dist/dev/internal/reconcile.js +122 -0
- package/dist/dev/internal/reconcile.js.map +1 -0
- package/dist/dev/internal/stream-context.d.ts +47 -0
- package/dist/dev/internal/stream-context.js +23 -0
- package/dist/dev/internal/stream-context.js.map +1 -0
- package/dist/dev/jsx/aria.d.ts +72 -0
- package/dist/dev/jsx/component.d.ts +89 -0
- package/dist/dev/jsx/events.d.ts +364 -0
- package/dist/dev/jsx/global.d.ts +211 -0
- package/dist/dev/jsx/html.d.ts +879 -0
- package/dist/dev/jsx/intrinsic.d.ts +59 -0
- package/dist/dev/jsx/mathml.d.ts +186 -0
- package/dist/dev/jsx/svg.d.ts +607 -0
- package/dist/dev/jsx/types.d.ts +176 -0
- package/dist/dev/jsx-dev-runtime.d.ts +10 -0
- package/dist/dev/jsx-dev-runtime.js +0 -0
- package/dist/dev/jsx-runtime.d.ts +94 -0
- package/dist/dev/jsx-runtime.js +0 -0
- package/dist/dev/reactive.d.ts +110 -0
- package/dist/dev/reactive.js +85 -0
- package/dist/dev/reactive.js.map +1 -0
- package/dist/dev/render.d.ts +36 -0
- package/dist/dev/render.js +52 -0
- package/dist/dev/render.js.map +1 -0
- package/dist/dev/resource-hints.d.ts +145 -0
- package/dist/dev/resource-hints.js +200 -0
- package/dist/dev/resource-hints.js.map +1 -0
- package/dist/dev/select-value.d.ts +24 -0
- package/dist/dev/select-value.js +51 -0
- package/dist/dev/select-value.js.map +1 -0
- package/dist/dev/server/attributes.d.ts +33 -0
- package/dist/dev/server/attributes.js +155 -0
- package/dist/dev/server/attributes.js.map +1 -0
- package/dist/dev/server/class-style.d.ts +46 -0
- package/dist/dev/server/class-style.js +173 -0
- package/dist/dev/server/class-style.js.map +1 -0
- package/dist/dev/server/component.d.ts +42 -0
- package/dist/dev/server/component.js +72 -0
- package/dist/dev/server/component.js.map +1 -0
- package/dist/dev/server/derived.d.ts +41 -0
- package/dist/dev/server/derived.js +26 -0
- package/dist/dev/server/derived.js.map +1 -0
- package/dist/dev/server/element.d.ts +89 -0
- package/dist/dev/server/element.js +216 -0
- package/dist/dev/server/element.js.map +1 -0
- package/dist/dev/server/errors.js +26 -0
- package/dist/dev/server/errors.js.map +1 -0
- package/dist/dev/server/escape.d.ts +30 -0
- package/dist/dev/server/escape.js +119 -0
- package/dist/dev/server/escape.js.map +1 -0
- package/dist/dev/server/form-controls.d.ts +50 -0
- package/dist/dev/server/form-controls.js +193 -0
- package/dist/dev/server/form-controls.js.map +1 -0
- package/dist/dev/server/hydration-script.d.ts +65 -0
- package/dist/dev/server/hydration-script.js +59 -0
- package/dist/dev/server/hydration-script.js.map +1 -0
- package/dist/dev/server/index.d.ts +16 -0
- package/dist/dev/server/index.js +16 -0
- package/dist/dev/server/node.d.ts +13 -0
- package/dist/dev/server/node.js +21 -0
- package/dist/dev/server/node.js.map +1 -0
- package/dist/dev/server/portals.d.ts +46 -0
- package/dist/dev/server/portals.js +99 -0
- package/dist/dev/server/portals.js.map +1 -0
- package/dist/dev/server/render.d.ts +129 -0
- package/dist/dev/server/render.js +256 -0
- package/dist/dev/server/render.js.map +1 -0
- package/dist/dev/server/serialize.d.ts +45 -0
- package/dist/dev/server/serialize.js +315 -0
- package/dist/dev/server/serialize.js.map +1 -0
- package/dist/dev/server/stream.d.ts +94 -0
- package/dist/dev/server/stream.js +235 -0
- package/dist/dev/server/stream.js.map +1 -0
- package/dist/dev/server.d.ts +16 -0
- package/dist/dev/server.js +16 -0
- package/dist/dev/spread.d.ts +49 -0
- package/dist/dev/spread.js +296 -0
- package/dist/dev/spread.js.map +1 -0
- package/dist/dev/template.d.ts +26 -0
- package/dist/dev/template.js +120 -0
- package/dist/dev/template.js.map +1 -0
- package/dist/dev/view-transition.d.ts +97 -0
- package/dist/dev/view-transition.js +121 -0
- package/dist/dev/view-transition.js.map +1 -0
- package/dist/prod/attributes.js +2 -0
- package/dist/prod/attributes.js.map +1 -0
- package/dist/prod/autofocus.js +2 -0
- package/dist/prod/autofocus.js.map +1 -0
- package/dist/prod/class-style.js +2 -0
- package/dist/prod/class-style.js.map +1 -0
- package/dist/prod/component.js +2 -0
- package/dist/prod/component.js.map +1 -0
- package/dist/prod/control-flow/activity.js +2 -0
- package/dist/prod/control-flow/activity.js.map +1 -0
- package/dist/prod/control-flow/branch.js +2 -0
- package/dist/prod/control-flow/branch.js.map +1 -0
- package/dist/prod/control-flow/client-only.js +2 -0
- package/dist/prod/control-flow/client-only.js.map +1 -0
- package/dist/prod/control-flow/dynamic.js +2 -0
- package/dist/prod/control-flow/dynamic.js.map +1 -0
- package/dist/prod/control-flow/error-boundary.js +2 -0
- package/dist/prod/control-flow/error-boundary.js.map +1 -0
- package/dist/prod/control-flow/for.js +2 -0
- package/dist/prod/control-flow/for.js.map +1 -0
- package/dist/prod/control-flow/fragment.js +2 -0
- package/dist/prod/control-flow/fragment.js.map +1 -0
- package/dist/prod/control-flow/hot-link.js +2 -0
- package/dist/prod/control-flow/hot-link.js.map +1 -0
- package/dist/prod/control-flow/index-list.js +2 -0
- package/dist/prod/control-flow/index-list.js.map +1 -0
- package/dist/prod/control-flow/lazy.js +2 -0
- package/dist/prod/control-flow/lazy.js.map +1 -0
- package/dist/prod/control-flow/no-hydration.js +2 -0
- package/dist/prod/control-flow/no-hydration.js.map +1 -0
- package/dist/prod/control-flow/portal.js +2 -0
- package/dist/prod/control-flow/portal.js.map +1 -0
- package/dist/prod/control-flow/root-errors.js +2 -0
- package/dist/prod/control-flow/root-errors.js.map +1 -0
- package/dist/prod/control-flow/show.js +2 -0
- package/dist/prod/control-flow/show.js.map +1 -0
- package/dist/prod/control-flow/suspense-list.js +2 -0
- package/dist/prod/control-flow/suspense-list.js.map +1 -0
- package/dist/prod/control-flow/suspense.js +2 -0
- package/dist/prod/control-flow/suspense.js.map +1 -0
- package/dist/prod/control-flow/switch.js +2 -0
- package/dist/prod/control-flow/switch.js.map +1 -0
- package/dist/prod/derived.js +2 -0
- package/dist/prod/derived.js.map +1 -0
- package/dist/prod/element.js +2 -0
- package/dist/prod/element.js.map +1 -0
- package/dist/prod/events.js +2 -0
- package/dist/prod/events.js.map +1 -0
- package/dist/prod/extend.js +1 -0
- package/dist/prod/head/components.js +2 -0
- package/dist/prod/head/components.js.map +1 -0
- package/dist/prod/head/registry.js +2 -0
- package/dist/prod/head/registry.js.map +1 -0
- package/dist/prod/head/server-head.js +2 -0
- package/dist/prod/head/server-head.js.map +1 -0
- package/dist/prod/head/sink.js +2 -0
- package/dist/prod/head/sink.js.map +1 -0
- package/dist/prod/head/use-head.js +2 -0
- package/dist/prod/head/use-head.js.map +1 -0
- package/dist/prod/head/validate.js +2 -0
- package/dist/prod/head/validate.js.map +1 -0
- package/dist/prod/hmr.js +2 -0
- package/dist/prod/hmr.js.map +1 -0
- package/dist/prod/hydration.js +2 -0
- package/dist/prod/hydration.js.map +1 -0
- package/dist/prod/index.js +1 -0
- package/dist/prod/insert.js +2 -0
- package/dist/prod/insert.js.map +1 -0
- package/dist/prod/internal/claim.js +2 -0
- package/dist/prod/internal/claim.js.map +1 -0
- package/dist/prod/internal/css-units.js +2 -0
- package/dist/prod/internal/css-units.js.map +1 -0
- package/dist/prod/internal/diagnostics.js +2 -0
- package/dist/prod/internal/diagnostics.js.map +1 -0
- package/dist/prod/internal/early-events.js +2 -0
- package/dist/prod/internal/early-events.js.map +1 -0
- package/dist/prod/internal/hydration-hooks.js +2 -0
- package/dist/prod/internal/hydration-hooks.js.map +1 -0
- package/dist/prod/internal/hydration-scope.js +2 -0
- package/dist/prod/internal/hydration-scope.js.map +1 -0
- package/dist/prod/internal/names.js +2 -0
- package/dist/prod/internal/names.js.map +1 -0
- package/dist/prod/internal/portal-context.js +2 -0
- package/dist/prod/internal/portal-context.js.map +1 -0
- package/dist/prod/internal/react-names.js +2 -0
- package/dist/prod/internal/react-names.js.map +1 -0
- package/dist/prod/internal/reconcile.js +2 -0
- package/dist/prod/internal/reconcile.js.map +1 -0
- package/dist/prod/internal/stream-context.js +2 -0
- package/dist/prod/internal/stream-context.js.map +1 -0
- package/dist/prod/jsx-dev-runtime.js +0 -0
- package/dist/prod/jsx-runtime.js +0 -0
- package/dist/prod/reactive.js +2 -0
- package/dist/prod/reactive.js.map +1 -0
- package/dist/prod/render.js +2 -0
- package/dist/prod/render.js.map +1 -0
- package/dist/prod/resource-hints.js +2 -0
- package/dist/prod/resource-hints.js.map +1 -0
- package/dist/prod/select-value.js +2 -0
- package/dist/prod/select-value.js.map +1 -0
- package/dist/prod/server/attributes.js +2 -0
- package/dist/prod/server/attributes.js.map +1 -0
- package/dist/prod/server/class-style.js +2 -0
- package/dist/prod/server/class-style.js.map +1 -0
- package/dist/prod/server/component.js +2 -0
- package/dist/prod/server/component.js.map +1 -0
- package/dist/prod/server/derived.js +2 -0
- package/dist/prod/server/derived.js.map +1 -0
- package/dist/prod/server/element.js +2 -0
- package/dist/prod/server/element.js.map +1 -0
- package/dist/prod/server/errors.js +2 -0
- package/dist/prod/server/errors.js.map +1 -0
- package/dist/prod/server/escape.js +2 -0
- package/dist/prod/server/escape.js.map +1 -0
- package/dist/prod/server/form-controls.js +3 -0
- package/dist/prod/server/form-controls.js.map +1 -0
- package/dist/prod/server/hydration-script.js +2 -0
- package/dist/prod/server/hydration-script.js.map +1 -0
- package/dist/prod/server/index.js +1 -0
- package/dist/prod/server/node.js +2 -0
- package/dist/prod/server/node.js.map +1 -0
- package/dist/prod/server/portals.js +2 -0
- package/dist/prod/server/portals.js.map +1 -0
- package/dist/prod/server/render.js +2 -0
- package/dist/prod/server/render.js.map +1 -0
- package/dist/prod/server/serialize.js +2 -0
- package/dist/prod/server/serialize.js.map +1 -0
- package/dist/prod/server/stream.js +2 -0
- package/dist/prod/server/stream.js.map +1 -0
- package/dist/prod/server.js +1 -0
- package/dist/prod/spread.js +2 -0
- package/dist/prod/spread.js.map +1 -0
- package/dist/prod/template.js +2 -0
- package/dist/prod/template.js.map +1 -0
- package/dist/prod/view-transition.js +2 -0
- package/dist/prod/view-transition.js.map +1 -0
- package/dist/server/attributes.js +2 -0
- package/dist/server/attributes.js.map +1 -0
- package/dist/server/autofocus.js +2 -0
- package/dist/server/autofocus.js.map +1 -0
- package/dist/server/class-style.js +2 -0
- package/dist/server/class-style.js.map +1 -0
- package/dist/server/component.js +2 -0
- package/dist/server/component.js.map +1 -0
- package/dist/server/control-flow/activity.js +2 -0
- package/dist/server/control-flow/activity.js.map +1 -0
- package/dist/server/control-flow/branch.js +2 -0
- package/dist/server/control-flow/branch.js.map +1 -0
- package/dist/server/control-flow/client-only.js +2 -0
- package/dist/server/control-flow/client-only.js.map +1 -0
- package/dist/server/control-flow/dynamic.js +2 -0
- package/dist/server/control-flow/dynamic.js.map +1 -0
- package/dist/server/control-flow/error-boundary.js +2 -0
- package/dist/server/control-flow/error-boundary.js.map +1 -0
- package/dist/server/control-flow/for.js +2 -0
- package/dist/server/control-flow/for.js.map +1 -0
- package/dist/server/control-flow/fragment.js +2 -0
- package/dist/server/control-flow/fragment.js.map +1 -0
- package/dist/server/control-flow/index-list.js +2 -0
- package/dist/server/control-flow/index-list.js.map +1 -0
- package/dist/server/control-flow/lazy.js +2 -0
- package/dist/server/control-flow/lazy.js.map +1 -0
- package/dist/server/control-flow/no-hydration.js +2 -0
- package/dist/server/control-flow/no-hydration.js.map +1 -0
- package/dist/server/control-flow/portal.js +2 -0
- package/dist/server/control-flow/portal.js.map +1 -0
- package/dist/server/control-flow/root-errors.js +2 -0
- package/dist/server/control-flow/root-errors.js.map +1 -0
- package/dist/server/control-flow/show.js +2 -0
- package/dist/server/control-flow/show.js.map +1 -0
- package/dist/server/control-flow/suspense-list.js +2 -0
- package/dist/server/control-flow/suspense-list.js.map +1 -0
- package/dist/server/control-flow/suspense.js +2 -0
- package/dist/server/control-flow/suspense.js.map +1 -0
- package/dist/server/control-flow/switch.js +2 -0
- package/dist/server/control-flow/switch.js.map +1 -0
- package/dist/server/derived.js +2 -0
- package/dist/server/derived.js.map +1 -0
- package/dist/server/element.js +2 -0
- package/dist/server/element.js.map +1 -0
- package/dist/server/events.js +2 -0
- package/dist/server/events.js.map +1 -0
- package/dist/server/extend.js +1 -0
- package/dist/server/head/components.js +2 -0
- package/dist/server/head/components.js.map +1 -0
- package/dist/server/head/registry.js +2 -0
- package/dist/server/head/registry.js.map +1 -0
- package/dist/server/head/server-head.js +2 -0
- package/dist/server/head/server-head.js.map +1 -0
- package/dist/server/head/sink.js +2 -0
- package/dist/server/head/sink.js.map +1 -0
- package/dist/server/head/use-head.js +2 -0
- package/dist/server/head/use-head.js.map +1 -0
- package/dist/server/head/validate.js +2 -0
- package/dist/server/head/validate.js.map +1 -0
- package/dist/server/hydration.js +2 -0
- package/dist/server/hydration.js.map +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/insert.js +2 -0
- package/dist/server/insert.js.map +1 -0
- package/dist/server/internal/claim.js +2 -0
- package/dist/server/internal/claim.js.map +1 -0
- package/dist/server/internal/css-units.js +2 -0
- package/dist/server/internal/css-units.js.map +1 -0
- package/dist/server/internal/diagnostics.js +2 -0
- package/dist/server/internal/diagnostics.js.map +1 -0
- package/dist/server/internal/early-events.js +2 -0
- package/dist/server/internal/early-events.js.map +1 -0
- package/dist/server/internal/hydration-hooks.js +2 -0
- package/dist/server/internal/hydration-hooks.js.map +1 -0
- package/dist/server/internal/hydration-scope.js +2 -0
- package/dist/server/internal/hydration-scope.js.map +1 -0
- package/dist/server/internal/names.js +2 -0
- package/dist/server/internal/names.js.map +1 -0
- package/dist/server/internal/portal-context.js +2 -0
- package/dist/server/internal/portal-context.js.map +1 -0
- package/dist/server/internal/react-names.js +2 -0
- package/dist/server/internal/react-names.js.map +1 -0
- package/dist/server/internal/reconcile.js +2 -0
- package/dist/server/internal/reconcile.js.map +1 -0
- package/dist/server/internal/stream-context.js +2 -0
- package/dist/server/internal/stream-context.js.map +1 -0
- package/dist/server/reactive.js +2 -0
- package/dist/server/reactive.js.map +1 -0
- package/dist/server/render.js +2 -0
- package/dist/server/render.js.map +1 -0
- package/dist/server/resource-hints.js +2 -0
- package/dist/server/resource-hints.js.map +1 -0
- package/dist/server/select-value.js +2 -0
- package/dist/server/select-value.js.map +1 -0
- package/dist/server/server/attributes.js +2 -0
- package/dist/server/server/attributes.js.map +1 -0
- package/dist/server/server/class-style.js +2 -0
- package/dist/server/server/class-style.js.map +1 -0
- package/dist/server/server/component.js +2 -0
- package/dist/server/server/component.js.map +1 -0
- package/dist/server/server/derived.js +2 -0
- package/dist/server/server/derived.js.map +1 -0
- package/dist/server/server/element.js +2 -0
- package/dist/server/server/element.js.map +1 -0
- package/dist/server/server/errors.js +2 -0
- package/dist/server/server/errors.js.map +1 -0
- package/dist/server/server/escape.js +2 -0
- package/dist/server/server/escape.js.map +1 -0
- package/dist/server/server/form-controls.js +3 -0
- package/dist/server/server/form-controls.js.map +1 -0
- package/dist/server/server/hydration-script.js +2 -0
- package/dist/server/server/hydration-script.js.map +1 -0
- package/dist/server/server/index.js +1 -0
- package/dist/server/server/node.js +2 -0
- package/dist/server/server/node.js.map +1 -0
- package/dist/server/server/portals.js +2 -0
- package/dist/server/server/portals.js.map +1 -0
- package/dist/server/server/render.js +2 -0
- package/dist/server/server/render.js.map +1 -0
- package/dist/server/server/serialize.js +2 -0
- package/dist/server/server/serialize.js.map +1 -0
- package/dist/server/server/stream.js +2 -0
- package/dist/server/server/stream.js.map +1 -0
- package/dist/server/server.js +1 -0
- package/dist/server/spread.js +2 -0
- package/dist/server/spread.js.map +1 -0
- package/dist/server/template.js +2 -0
- package/dist/server/template.js.map +1 -0
- package/dist/server/view-transition.js +2 -0
- package/dist/server/view-transition.js.map +1 -0
- package/dist/server-dev/attributes.js +196 -0
- package/dist/server-dev/attributes.js.map +1 -0
- package/dist/server-dev/autofocus.js +45 -0
- package/dist/server-dev/autofocus.js.map +1 -0
- package/dist/server-dev/class-style.js +197 -0
- package/dist/server-dev/class-style.js.map +1 -0
- package/dist/server-dev/component.js +42 -0
- package/dist/server-dev/component.js.map +1 -0
- package/dist/server-dev/control-flow/activity.js +41 -0
- package/dist/server-dev/control-flow/activity.js.map +1 -0
- package/dist/server-dev/control-flow/branch.js +104 -0
- package/dist/server-dev/control-flow/branch.js.map +1 -0
- package/dist/server-dev/control-flow/client-only.js +50 -0
- package/dist/server-dev/control-flow/client-only.js.map +1 -0
- package/dist/server-dev/control-flow/dynamic.js +106 -0
- package/dist/server-dev/control-flow/dynamic.js.map +1 -0
- package/dist/server-dev/control-flow/error-boundary.js +115 -0
- package/dist/server-dev/control-flow/error-boundary.js.map +1 -0
- package/dist/server-dev/control-flow/for.js +23 -0
- package/dist/server-dev/control-flow/for.js.map +1 -0
- package/dist/server-dev/control-flow/fragment.js +31 -0
- package/dist/server-dev/control-flow/fragment.js.map +1 -0
- package/dist/server-dev/control-flow/hot-link.js +57 -0
- package/dist/server-dev/control-flow/hot-link.js.map +1 -0
- package/dist/server-dev/control-flow/index-list.js +31 -0
- package/dist/server-dev/control-flow/index-list.js.map +1 -0
- package/dist/server-dev/control-flow/lazy.js +64 -0
- package/dist/server-dev/control-flow/lazy.js.map +1 -0
- package/dist/server-dev/control-flow/no-hydration.js +40 -0
- package/dist/server-dev/control-flow/no-hydration.js.map +1 -0
- package/dist/server-dev/control-flow/portal.js +134 -0
- package/dist/server-dev/control-flow/portal.js.map +1 -0
- package/dist/server-dev/control-flow/root-errors.js +33 -0
- package/dist/server-dev/control-flow/root-errors.js.map +1 -0
- package/dist/server-dev/control-flow/show.js +18 -0
- package/dist/server-dev/control-flow/show.js.map +1 -0
- package/dist/server-dev/control-flow/suspense-list.js +100 -0
- package/dist/server-dev/control-flow/suspense-list.js.map +1 -0
- package/dist/server-dev/control-flow/suspense.js +119 -0
- package/dist/server-dev/control-flow/suspense.js.map +1 -0
- package/dist/server-dev/control-flow/switch.js +90 -0
- package/dist/server-dev/control-flow/switch.js.map +1 -0
- package/dist/server-dev/derived.js +34 -0
- package/dist/server-dev/derived.js.map +1 -0
- package/dist/server-dev/element.js +66 -0
- package/dist/server-dev/element.js.map +1 -0
- package/dist/server-dev/events.js +265 -0
- package/dist/server-dev/events.js.map +1 -0
- package/dist/server-dev/extend.js +12 -0
- package/dist/server-dev/head/components.js +170 -0
- package/dist/server-dev/head/components.js.map +1 -0
- package/dist/server-dev/head/registry.js +68 -0
- package/dist/server-dev/head/registry.js.map +1 -0
- package/dist/server-dev/head/server-head.js +76 -0
- package/dist/server-dev/head/server-head.js.map +1 -0
- package/dist/server-dev/head/sink.js +96 -0
- package/dist/server-dev/head/sink.js.map +1 -0
- package/dist/server-dev/head/use-head.js +84 -0
- package/dist/server-dev/head/use-head.js.map +1 -0
- package/dist/server-dev/head/validate.js +268 -0
- package/dist/server-dev/head/validate.js.map +1 -0
- package/dist/server-dev/hydration.js +120 -0
- package/dist/server-dev/hydration.js.map +1 -0
- package/dist/server-dev/index.js +34 -0
- package/dist/server-dev/insert.js +357 -0
- package/dist/server-dev/insert.js.map +1 -0
- package/dist/server-dev/internal/claim.js +357 -0
- package/dist/server-dev/internal/claim.js.map +1 -0
- package/dist/server-dev/internal/css-units.js +26 -0
- package/dist/server-dev/internal/css-units.js.map +1 -0
- package/dist/server-dev/internal/diagnostics.js +38 -0
- package/dist/server-dev/internal/diagnostics.js.map +1 -0
- package/dist/server-dev/internal/early-events.js +76 -0
- package/dist/server-dev/internal/early-events.js.map +1 -0
- package/dist/server-dev/internal/hydration-hooks.js +27 -0
- package/dist/server-dev/internal/hydration-hooks.js.map +1 -0
- package/dist/server-dev/internal/hydration-scope.js +156 -0
- package/dist/server-dev/internal/hydration-scope.js.map +1 -0
- package/dist/server-dev/internal/names.js +35 -0
- package/dist/server-dev/internal/names.js.map +1 -0
- package/dist/server-dev/internal/portal-context.js +28 -0
- package/dist/server-dev/internal/portal-context.js.map +1 -0
- package/dist/server-dev/internal/react-names.js +116 -0
- package/dist/server-dev/internal/react-names.js.map +1 -0
- package/dist/server-dev/internal/reconcile.js +122 -0
- package/dist/server-dev/internal/reconcile.js.map +1 -0
- package/dist/server-dev/internal/stream-context.js +23 -0
- package/dist/server-dev/internal/stream-context.js.map +1 -0
- package/dist/server-dev/reactive.js +85 -0
- package/dist/server-dev/reactive.js.map +1 -0
- package/dist/server-dev/render.js +52 -0
- package/dist/server-dev/render.js.map +1 -0
- package/dist/server-dev/resource-hints.js +200 -0
- package/dist/server-dev/resource-hints.js.map +1 -0
- package/dist/server-dev/select-value.js +51 -0
- package/dist/server-dev/select-value.js.map +1 -0
- package/dist/server-dev/server/attributes.js +155 -0
- package/dist/server-dev/server/attributes.js.map +1 -0
- package/dist/server-dev/server/class-style.js +173 -0
- package/dist/server-dev/server/class-style.js.map +1 -0
- package/dist/server-dev/server/component.js +72 -0
- package/dist/server-dev/server/component.js.map +1 -0
- package/dist/server-dev/server/derived.js +26 -0
- package/dist/server-dev/server/derived.js.map +1 -0
- package/dist/server-dev/server/element.js +216 -0
- package/dist/server-dev/server/element.js.map +1 -0
- package/dist/server-dev/server/errors.js +26 -0
- package/dist/server-dev/server/errors.js.map +1 -0
- package/dist/server-dev/server/escape.js +119 -0
- package/dist/server-dev/server/escape.js.map +1 -0
- package/dist/server-dev/server/form-controls.js +193 -0
- package/dist/server-dev/server/form-controls.js.map +1 -0
- package/dist/server-dev/server/hydration-script.js +59 -0
- package/dist/server-dev/server/hydration-script.js.map +1 -0
- package/dist/server-dev/server/index.js +16 -0
- package/dist/server-dev/server/node.js +21 -0
- package/dist/server-dev/server/node.js.map +1 -0
- package/dist/server-dev/server/portals.js +99 -0
- package/dist/server-dev/server/portals.js.map +1 -0
- package/dist/server-dev/server/render.js +256 -0
- package/dist/server-dev/server/render.js.map +1 -0
- package/dist/server-dev/server/serialize.js +315 -0
- package/dist/server-dev/server/serialize.js.map +1 -0
- package/dist/server-dev/server/stream.js +235 -0
- package/dist/server-dev/server/stream.js.map +1 -0
- package/dist/server-dev/server.js +16 -0
- package/dist/server-dev/spread.js +296 -0
- package/dist/server-dev/spread.js.map +1 -0
- package/dist/server-dev/template.js +120 -0
- package/dist/server-dev/template.js.map +1 -0
- package/dist/server-dev/view-transition.js +90 -0
- package/dist/server-dev/view-transition.js.map +1 -0
- package/package.json +136 -4
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Accessor } from "@shadow-js/core";
|
|
2
|
+
//#region src/control-flow/suspense.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Props of {@link Suspense}.
|
|
5
|
+
* @since 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
export interface SuspenseProps {
|
|
8
|
+
/**
|
|
9
|
+
* Shown while any resource read inside the boundary is loading for the first time.
|
|
10
|
+
* @default undefined (a pending boundary renders nothing)
|
|
11
|
+
*/
|
|
12
|
+
fallback?: unknown;
|
|
13
|
+
/**
|
|
14
|
+
* The content. Created once, under the boundary, and kept alive while the fallback is visible.
|
|
15
|
+
* @default undefined (renders nothing)
|
|
16
|
+
*/
|
|
17
|
+
children?: unknown;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Shows `fallback` while resources read inside it are loading for the first time. The children
|
|
21
|
+
* are created once and stay alive (with their state) while the fallback is visible; the boundary
|
|
22
|
+
* only switches what is displayed. Nested boundaries each track their own resources.
|
|
23
|
+
*
|
|
24
|
+
* On the server a boundary renders its fallback when its data is not ready (`renderToString`), or
|
|
25
|
+
* streams the content later (`renderToStream`). Content and fallback get their own hydration key
|
|
26
|
+
* space, so what a boundary renders never shifts the keys of its siblings.
|
|
27
|
+
*
|
|
28
|
+
* @param props See {@link SuspenseProps}.
|
|
29
|
+
* @returns An accessor of what the boundary shows: the fallback while a resource is pending, the
|
|
30
|
+
* children otherwise.
|
|
31
|
+
* @example
|
|
32
|
+
* import { useResource } from "@shadow-js/core";
|
|
33
|
+
* import { Suspense } from "@shadow-js/web";
|
|
34
|
+
*
|
|
35
|
+
* function Profile() {
|
|
36
|
+
* const name = useResource(() => Promise.resolve("Ada"));
|
|
37
|
+
* return <p>{name()}</p>;
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* function Page() {
|
|
41
|
+
* return (
|
|
42
|
+
* <Suspense fallback={<p>Loading...</p>}>
|
|
43
|
+
* <Profile />
|
|
44
|
+
* </Suspense>
|
|
45
|
+
* );
|
|
46
|
+
* }
|
|
47
|
+
* @see SuspenseList
|
|
48
|
+
* @see ErrorBoundary
|
|
49
|
+
* @since 1.0.0
|
|
50
|
+
*/
|
|
51
|
+
export declare function Suspense(props: SuspenseProps): Accessor<unknown>;
|
|
52
|
+
//#endregion
|
|
53
|
+
//# sourceMappingURL=suspense.d.ts.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { childScope, nextKey, withScope } from "../internal/hydration-scope.js";
|
|
2
|
+
import { registerInList } from "./suspense-list.js";
|
|
3
|
+
import { SuspenseContext, runWithOwner, useMemo } from "@shadow-js/core";
|
|
4
|
+
import { createOwner, createSignalNode, readSignal, transitionHooks, writeSignal } from "@shadow-js/core/extend";
|
|
5
|
+
//#region src/control-flow/suspense.ts
|
|
6
|
+
/**
|
|
7
|
+
* A counter the resources of one boundary report to (see {@link SuspenseTracker}), and the hold a
|
|
8
|
+
* transition takes on the boundary. A transition that reads pending data while the boundary shows
|
|
9
|
+
* content does not bring the fallback back: its readers keep their previous values, the boundary
|
|
10
|
+
* keeps its content, and the readers run again when the count returns to zero.
|
|
11
|
+
*/
|
|
12
|
+
function createTracker() {
|
|
13
|
+
const pending = createSignalNode(0, Object.is);
|
|
14
|
+
let hold;
|
|
15
|
+
let shown = false;
|
|
16
|
+
const adjust = (by) => {
|
|
17
|
+
writeSignal(pending, pending.value + by, { allowInMemo: true });
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
tracker: {
|
|
21
|
+
increment: () => adjust(1),
|
|
22
|
+
decrement: () => {
|
|
23
|
+
adjust(-1);
|
|
24
|
+
if (pending.value === 0) hold?.release();
|
|
25
|
+
},
|
|
26
|
+
hold: () => {
|
|
27
|
+
if (!shown) return false;
|
|
28
|
+
hold ??= transitionHooks()?.boundaryHold();
|
|
29
|
+
return hold?.engage() === true;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
count: () => readSignal(pending),
|
|
33
|
+
holding: () => hold?.holding() === true,
|
|
34
|
+
revealed: () => {
|
|
35
|
+
shown = true;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Shows `fallback` while resources read inside it are loading for the first time. The children
|
|
41
|
+
* are created once and stay alive (with their state) while the fallback is visible; the boundary
|
|
42
|
+
* only switches what is displayed. Nested boundaries each track their own resources.
|
|
43
|
+
*
|
|
44
|
+
* On the server a boundary renders its fallback when its data is not ready (`renderToString`), or
|
|
45
|
+
* streams the content later (`renderToStream`). Content and fallback get their own hydration key
|
|
46
|
+
* space, so what a boundary renders never shifts the keys of its siblings.
|
|
47
|
+
*
|
|
48
|
+
* @param props See {@link SuspenseProps}.
|
|
49
|
+
* @returns An accessor of what the boundary shows: the fallback while a resource is pending, the
|
|
50
|
+
* children otherwise.
|
|
51
|
+
* @example
|
|
52
|
+
* import { useResource } from "@shadow-js/core";
|
|
53
|
+
* import { Suspense } from "@shadow-js/web";
|
|
54
|
+
*
|
|
55
|
+
* function Profile() {
|
|
56
|
+
* const name = useResource(() => Promise.resolve("Ada"));
|
|
57
|
+
* return <p>{name()}</p>;
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* function Page() {
|
|
61
|
+
* return (
|
|
62
|
+
* <Suspense fallback={<p>Loading...</p>}>
|
|
63
|
+
* <Profile />
|
|
64
|
+
* </Suspense>
|
|
65
|
+
* );
|
|
66
|
+
* }
|
|
67
|
+
* @see SuspenseList
|
|
68
|
+
* @see ErrorBoundary
|
|
69
|
+
* @since 1.0.0
|
|
70
|
+
*/
|
|
71
|
+
function Suspense(props) {
|
|
72
|
+
const key = nextKey();
|
|
73
|
+
const { tracker, count, holding, revealed } = createTracker();
|
|
74
|
+
const slot = registerInList(() => count() === 0);
|
|
75
|
+
const boundary = createOwner();
|
|
76
|
+
boundary.gate = () => count() > 0 || slot !== null && !slot.reveal();
|
|
77
|
+
const content = runWithOwner(boundary, () => withScope(childScope(key), () => SuspenseContext({
|
|
78
|
+
value: tracker,
|
|
79
|
+
get children() {
|
|
80
|
+
return props.children;
|
|
81
|
+
}
|
|
82
|
+
})));
|
|
83
|
+
const fallbackScope = childScope(key === void 0 ? void 0 : `${key}f`);
|
|
84
|
+
return useMemo((previous) => {
|
|
85
|
+
count();
|
|
86
|
+
if (holding() && previous !== void 0) return previous;
|
|
87
|
+
if (slot === null) {
|
|
88
|
+
if (count() > 0) return withScope(fallbackScope, () => props.fallback);
|
|
89
|
+
revealed();
|
|
90
|
+
return content();
|
|
91
|
+
}
|
|
92
|
+
if (count() === 0 && slot.reveal()) {
|
|
93
|
+
revealed();
|
|
94
|
+
return content();
|
|
95
|
+
}
|
|
96
|
+
return slot.showFallback() ? withScope(fallbackScope, () => props.fallback) : null;
|
|
97
|
+
}, { allowWrites: true });
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
export { Suspense };
|
|
101
|
+
|
|
102
|
+
//# sourceMappingURL=suspense.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suspense.js","names":[],"sources":["../../../src/control-flow/suspense.ts"],"sourcesContent":["import {\n type Accessor,\n getOwner,\n runWithOwner,\n SuspenseContext,\n type SuspenseTracker,\n useContext,\n useMemo,\n} from \"@shadow-js/core\";\nimport {\n type BoundaryHold,\n createOwner,\n createSignalNode,\n readSignal,\n transitionHooks,\n writeSignal,\n} from \"@shadow-js/core/extend\";\nimport { childScope, nextKey, StreamContext, withScope } from \"../extend\";\nimport { ssrRaw } from \"../server/element\";\n// biome-ignore lint/suspicious/noShadowRestrictedNames: `escape` is the compiler's SSR helper name.\nimport { escape } from \"../server/escape\";\nimport { registerInList } from \"./suspense-list\";\n\n/**\n * Props of {@link Suspense}.\n * @since 1.0.0\n */\nexport interface SuspenseProps {\n /**\n * Shown while any resource read inside the boundary is loading for the first time.\n * @default undefined (a pending boundary renders nothing)\n */\n fallback?: unknown;\n /**\n * The content. Created once, under the boundary, and kept alive while the fallback is visible.\n * @default undefined (renders nothing)\n */\n children?: unknown;\n}\n\n/** What a boundary tracks: its pending reads, and whether a transition holds its content. */\ninterface Tracking {\n readonly tracker: SuspenseTracker;\n readonly count: () => number;\n /** True while a transition waits for data and the boundary keeps showing its content. */\n readonly holding: () => boolean;\n /** Called when the boundary first shows its content: only then can a transition hold it. */\n readonly revealed: () => void;\n}\n\n/**\n * A counter the resources of one boundary report to (see {@link SuspenseTracker}), and the hold a\n * transition takes on the boundary. A transition that reads pending data while the boundary shows\n * content does not bring the fallback back: its readers keep their previous values, the boundary\n * keeps its content, and the readers run again when the count returns to zero.\n */\nfunction createTracker(): Tracking {\n // Counted with an extension-API cell: a resource may be read (and so hold this boundary) while a\n // memo computes, where a plain write would be rejected.\n const pending = createSignalNode<number>(0, Object.is);\n // The hold a transition takes on this boundary. Only a transition read creates it (core keeps the\n // machinery of holds behind its transition hooks); the boundary's memo reads the count before it\n // reads the hold, so it runs again when the count reaches zero (the release).\n let hold: BoundaryHold | undefined;\n let shown = false;\n const adjust = (by: number): void => {\n writeSignal(pending, pending.value + by, { allowInMemo: true });\n };\n const tracker: SuspenseTracker = {\n increment: () => adjust(1),\n decrement: () => {\n adjust(-1);\n if (pending.value === 0) hold?.release();\n },\n hold: (): boolean => {\n if (!shown) return false;\n hold ??= transitionHooks()?.boundaryHold();\n return hold?.engage() === true;\n },\n };\n return {\n tracker,\n count: () => readSignal(pending),\n holding: () => hold?.holding() === true,\n revealed: () => {\n shown = true;\n },\n };\n}\n\n/**\n * Shows `fallback` while resources read inside it are loading for the first time. The children\n * are created once and stay alive (with their state) while the fallback is visible; the boundary\n * only switches what is displayed. Nested boundaries each track their own resources.\n *\n * On the server a boundary renders its fallback when its data is not ready (`renderToString`), or\n * streams the content later (`renderToStream`). Content and fallback get their own hydration key\n * space, so what a boundary renders never shifts the keys of its siblings.\n *\n * @param props See {@link SuspenseProps}.\n * @returns An accessor of what the boundary shows: the fallback while a resource is pending, the\n * children otherwise.\n * @example\n * import { useResource } from \"@shadow-js/core\";\n * import { Suspense } from \"@shadow-js/web\";\n *\n * function Profile() {\n * const name = useResource(() => Promise.resolve(\"Ada\"));\n * return <p>{name()}</p>;\n * }\n *\n * function Page() {\n * return (\n * <Suspense fallback={<p>Loading...</p>}>\n * <Profile />\n * </Suspense>\n * );\n * }\n * @see SuspenseList\n * @see ErrorBoundary\n * @since 1.0.0\n */\nexport function Suspense(props: SuspenseProps): Accessor<unknown> {\n const key = nextKey();\n const { tracker, count, holding, revealed } = createTracker();\n // The content lives under its own owner, whose gate holds back user effects and `onMount` until\n // the boundary has resolved once. Render effects (DOM bindings) are never held.\n // Inside a <SuspenseList> the boundary also waits for its turn to be revealed.\n const slot = __SERVER__ ? null : registerInList(() => count() === 0);\n const boundary = createOwner();\n boundary.gate = () => count() > 0 || (slot !== null && !slot.reveal());\n const content = runWithOwner(boundary, () =>\n withScope(childScope(key), () =>\n SuspenseContext({\n value: tracker,\n get children() {\n return props.children;\n },\n }),\n ),\n );\n if (__SERVER__) return suspenseOnServer(props, key, count, content as () => unknown);\n const fallbackScope = childScope(key === undefined ? undefined : `${key}f`);\n return useMemo<unknown>(\n (previous) => {\n // Read first: the memo depends on the count even while held, so it runs again when the hold ends.\n count();\n // A transition holds the boundary: the content stays as it was (the same value, so no DOM change).\n if (holding() && previous !== undefined) return previous;\n if (slot === null) {\n if (count() > 0) return withScope(fallbackScope, () => props.fallback);\n revealed();\n return (content as () => unknown)();\n }\n if (count() === 0 && slot.reveal()) {\n revealed();\n return (content as () => unknown)();\n }\n return slot.showFallback() ? withScope(fallbackScope, () => props.fallback) : null;\n },\n { allowWrites: true },\n );\n}\n\n/** Server behavior: ready content, a fallback, or a fallback plus a deferred stream chunk. */\nfunction suspenseOnServer(\n props: SuspenseProps,\n key: string | undefined,\n count: () => number,\n content: () => unknown,\n): Accessor<unknown> {\n const fallbackScope = childScope(key === undefined ? undefined : `${key}f`);\n if (count() === 0) return content;\n const sink = useContext(StreamContext);\n if (sink === null || key === undefined) {\n return () => withScope(fallbackScope, () => props.fallback);\n }\n const owner = getOwner();\n const boundary = {\n id: key,\n rebuild: (): string | null => {\n const next = createTracker();\n const rebuilt = runWithOwner(owner, () =>\n withScope(childScope(key), () =>\n SuspenseContext({\n value: next.tracker,\n get children() {\n return props.children;\n },\n }),\n ),\n );\n if (next.count() > 0) {\n sink.defer(boundary);\n return null;\n }\n return escape((rebuilt as () => unknown)());\n },\n };\n sink.defer(boundary);\n // The markers delimit the region the stream later replaces; hydration strips them.\n return () => [\n ssrRaw(`<!--[b:${key}-->`),\n withScope(fallbackScope, () => props.fallback),\n ssrRaw(\"<!--]-->\"),\n ];\n}\n"],"mappings":";;;;;;;;;;;AAwDA,SAAS,gBAA0B;CAGjC,MAAM,UAAU,iBAAyB,GAAG,OAAO,EAAE;CAIrD,IAAI;CACJ,IAAI,QAAQ;CACZ,MAAM,UAAU,OAAqB;EACnC,YAAY,SAAS,QAAQ,QAAQ,IAAI,EAAE,aAAa,KAAK,CAAC;CAChE;CAaA,OAAO;EACL,SAAA;GAZA,iBAAiB,OAAO,CAAC;GACzB,iBAAiB;IACf,OAAO,EAAE;IACT,IAAI,QAAQ,UAAU,GAAG,MAAM,QAAQ;GACzC;GACA,YAAqB;IACnB,IAAI,CAAC,OAAO,OAAO;IACnB,SAAS,gBAAgB,CAAC,EAAE,aAAa;IACzC,OAAO,MAAM,OAAO,MAAM;GAC5B;EAGM;EACN,aAAa,WAAW,OAAO;EAC/B,eAAe,MAAM,QAAQ,MAAM;EACnC,gBAAgB;GACd,QAAQ;EACV;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,SAAS,OAAyC;CAChE,MAAM,MAAM,QAAQ;CACpB,MAAM,EAAE,SAAS,OAAO,SAAS,aAAa,cAAc;CAI5D,MAAM,OAA2B,qBAAqB,MAAM,MAAM,CAAC;CACnE,MAAM,WAAW,YAAY;CAC7B,SAAS,aAAa,MAAM,IAAI,KAAM,SAAS,QAAQ,CAAC,KAAK,OAAO;CACpE,MAAM,UAAU,aAAa,gBAC3B,UAAU,WAAW,GAAG,SACtB,gBAAgB;EACd,OAAO;EACP,IAAI,WAAW;GACb,OAAO,MAAM;EACf;CACF,CAAC,CACH,CACF;CAEA,MAAM,gBAAgB,WAAW,QAAQ,KAAA,IAAY,KAAA,IAAY,GAAG,IAAI,EAAE;CAC1E,OAAO,SACJ,aAAa;EAEZ,MAAM;EAEN,IAAI,QAAQ,KAAK,aAAa,KAAA,GAAW,OAAO;EAChD,IAAI,SAAS,MAAM;GACjB,IAAI,MAAM,IAAI,GAAG,OAAO,UAAU,qBAAqB,MAAM,QAAQ;GACrE,SAAS;GACT,OAAQ,QAA0B;EACpC;EACA,IAAI,MAAM,MAAM,KAAK,KAAK,OAAO,GAAG;GAClC,SAAS;GACT,OAAQ,QAA0B;EACpC;EACA,OAAO,KAAK,aAAa,IAAI,UAAU,qBAAqB,MAAM,QAAQ,IAAI;CAChF,GACA,EAAE,aAAa,KAAK,CACtB;AACF"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Accessor } from "@shadow-js/core";
|
|
2
|
+
//#region src/control-flow/switch.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Props of {@link Match}. A Match descriptor is the props object itself.
|
|
5
|
+
* @since 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
export interface MatchProps<T> {
|
|
8
|
+
/** The condition. The first Match whose `when` is truthy is shown. */
|
|
9
|
+
readonly when: T | undefined | null | false | 0 | "";
|
|
10
|
+
/**
|
|
11
|
+
* Same meaning as in {@link ShowLooseProps}: `true` rebuilds the branch when the identity of
|
|
12
|
+
* `when` changes.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
readonly keyed?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The branch content: plain content, an accessor, or a callback, as the children of
|
|
18
|
+
* {@link ShowProps}.
|
|
19
|
+
* @default undefined (the selected Match renders nothing)
|
|
20
|
+
*/
|
|
21
|
+
readonly children?: unknown;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Describes one branch of a {@link Switch}. It returns its props unchanged.
|
|
25
|
+
*
|
|
26
|
+
* @param props The condition and the branch content.
|
|
27
|
+
* @returns The same props object, which `Switch` reads.
|
|
28
|
+
* @example
|
|
29
|
+
* import { Match } from "@shadow-js/web";
|
|
30
|
+
*
|
|
31
|
+
* const branch = Match({ when: "ready", children: "Loaded" });
|
|
32
|
+
* console.log(branch.when); // "ready"
|
|
33
|
+
* @see Switch
|
|
34
|
+
* @since 1.0.0
|
|
35
|
+
*/
|
|
36
|
+
export declare function Match<T>(props: MatchProps<T>): MatchProps<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Props of {@link Switch}.
|
|
39
|
+
* @since 1.0.0
|
|
40
|
+
*/
|
|
41
|
+
export interface SwitchProps {
|
|
42
|
+
/**
|
|
43
|
+
* Shown when no Match is truthy. Read lazily.
|
|
44
|
+
* @default undefined (nothing is rendered when no Match is truthy)
|
|
45
|
+
*/
|
|
46
|
+
readonly fallback?: unknown;
|
|
47
|
+
/**
|
|
48
|
+
* One or more {@link Match} descriptors. `null`, `undefined` and booleans are ignored.
|
|
49
|
+
* @default undefined (no branches; the fallback is shown)
|
|
50
|
+
*/
|
|
51
|
+
readonly children?: unknown;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Shows the first {@link Match} whose `when` is truthy, or the fallback when none is.
|
|
55
|
+
* Re-selecting the same branch with the same truthiness (or, when keyed, the same value) does not
|
|
56
|
+
* rebuild it.
|
|
57
|
+
*
|
|
58
|
+
* @param props See {@link SwitchProps}.
|
|
59
|
+
* @returns An accessor of the selected branch's content.
|
|
60
|
+
* @throws TypeError (production message `SHADOW_SWITCH_CHILDREN`) when a child is neither a Match
|
|
61
|
+
* nor `null`, `undefined` or a boolean.
|
|
62
|
+
* @example
|
|
63
|
+
* import { useSignal } from "@shadow-js/core";
|
|
64
|
+
* import { Match, Switch } from "@shadow-js/web";
|
|
65
|
+
*
|
|
66
|
+
* function Status() {
|
|
67
|
+
* const [error] = useSignal<string | null>(null);
|
|
68
|
+
* const [data] = useSignal<string | null>("ready");
|
|
69
|
+
* return (
|
|
70
|
+
* <Switch fallback={<p>Loading...</p>}>
|
|
71
|
+
* <Match when={error()}>
|
|
72
|
+
* <p>Failed</p>
|
|
73
|
+
* </Match>
|
|
74
|
+
* <Match when={data()}>
|
|
75
|
+
* <p>Ready</p>
|
|
76
|
+
* </Match>
|
|
77
|
+
* </Switch>
|
|
78
|
+
* );
|
|
79
|
+
* }
|
|
80
|
+
* @see Show
|
|
81
|
+
* @since 1.0.0
|
|
82
|
+
*/
|
|
83
|
+
export declare function Switch(props: SwitchProps): Accessor<unknown>;
|
|
84
|
+
//#endregion
|
|
85
|
+
//# sourceMappingURL=switch.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createBranches } from "./branch.js";
|
|
2
|
+
import { children } from "@shadow-js/core";
|
|
3
|
+
//#region src/control-flow/switch.ts
|
|
4
|
+
/**
|
|
5
|
+
* Describes one branch of a {@link Switch}. It returns its props unchanged.
|
|
6
|
+
*
|
|
7
|
+
* @param props The condition and the branch content.
|
|
8
|
+
* @returns The same props object, which `Switch` reads.
|
|
9
|
+
* @example
|
|
10
|
+
* import { Match } from "@shadow-js/web";
|
|
11
|
+
*
|
|
12
|
+
* const branch = Match({ when: "ready", children: "Loaded" });
|
|
13
|
+
* console.log(branch.when); // "ready"
|
|
14
|
+
* @see Switch
|
|
15
|
+
* @since 1.0.0
|
|
16
|
+
*/
|
|
17
|
+
function Match(props) {
|
|
18
|
+
return props;
|
|
19
|
+
}
|
|
20
|
+
/** A Match descriptor is any object with a `when` key. Anything else is not a Match. */
|
|
21
|
+
function isMatch(item) {
|
|
22
|
+
return typeof item === "object" && item !== null && "when" in item;
|
|
23
|
+
}
|
|
24
|
+
/** Resolves the children into Match descriptors. Throws for any other kind of child. */
|
|
25
|
+
function matchesOf(resolved) {
|
|
26
|
+
const matches = [];
|
|
27
|
+
for (const item of resolved.toArray()) {
|
|
28
|
+
if (!isMatch(item)) throw new TypeError("ShadowJS Switch: children must be <Match>");
|
|
29
|
+
matches.push(item);
|
|
30
|
+
}
|
|
31
|
+
return matches;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Shows the first {@link Match} whose `when` is truthy, or the fallback when none is.
|
|
35
|
+
* Re-selecting the same branch with the same truthiness (or, when keyed, the same value) does not
|
|
36
|
+
* rebuild it.
|
|
37
|
+
*
|
|
38
|
+
* @param props See {@link SwitchProps}.
|
|
39
|
+
* @returns An accessor of the selected branch's content.
|
|
40
|
+
* @throws TypeError (production message `SHADOW_SWITCH_CHILDREN`) when a child is neither a Match
|
|
41
|
+
* nor `null`, `undefined` or a boolean.
|
|
42
|
+
* @example
|
|
43
|
+
* import { useSignal } from "@shadow-js/core";
|
|
44
|
+
* import { Match, Switch } from "@shadow-js/web";
|
|
45
|
+
*
|
|
46
|
+
* function Status() {
|
|
47
|
+
* const [error] = useSignal<string | null>(null);
|
|
48
|
+
* const [data] = useSignal<string | null>("ready");
|
|
49
|
+
* return (
|
|
50
|
+
* <Switch fallback={<p>Loading...</p>}>
|
|
51
|
+
* <Match when={error()}>
|
|
52
|
+
* <p>Failed</p>
|
|
53
|
+
* </Match>
|
|
54
|
+
* <Match when={data()}>
|
|
55
|
+
* <p>Ready</p>
|
|
56
|
+
* </Match>
|
|
57
|
+
* </Switch>
|
|
58
|
+
* );
|
|
59
|
+
* }
|
|
60
|
+
* @see Show
|
|
61
|
+
* @since 1.0.0
|
|
62
|
+
*/
|
|
63
|
+
function Switch(props) {
|
|
64
|
+
const matches = children(() => props.children);
|
|
65
|
+
matchesOf(matches);
|
|
66
|
+
return createBranches("Switch", () => {
|
|
67
|
+
const list = matchesOf(matches);
|
|
68
|
+
for (const [index, match] of list.entries()) {
|
|
69
|
+
const when = match.when;
|
|
70
|
+
if (when) return {
|
|
71
|
+
index,
|
|
72
|
+
keyed: match.keyed === true,
|
|
73
|
+
when,
|
|
74
|
+
read: () => match.when,
|
|
75
|
+
body: () => match.children
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
index: -1,
|
|
80
|
+
keyed: false,
|
|
81
|
+
when: void 0,
|
|
82
|
+
read: () => void 0,
|
|
83
|
+
body: () => void 0
|
|
84
|
+
};
|
|
85
|
+
}, () => props.fallback);
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { Match, Switch };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=switch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.js","names":["resolveChildren"],"sources":["../../../src/control-flow/switch.ts"],"sourcesContent":["import { type Accessor, type ResolvedChildren, children as resolveChildren } from \"@shadow-js/core\";\nimport { createBranches, FALLBACK } from \"./branch\";\n\n/**\n * Props of {@link Match}. A Match descriptor is the props object itself.\n * @since 1.0.0\n */\nexport interface MatchProps<T> {\n /** The condition. The first Match whose `when` is truthy is shown. */\n readonly when: T | undefined | null | false | 0 | \"\";\n /**\n * Same meaning as in {@link ShowLooseProps}: `true` rebuilds the branch when the identity of\n * `when` changes.\n * @default false\n */\n readonly keyed?: boolean;\n /**\n * The branch content: plain content, an accessor, or a callback, as the children of\n * {@link ShowProps}.\n * @default undefined (the selected Match renders nothing)\n */\n readonly children?: unknown;\n}\n\n/**\n * Describes one branch of a {@link Switch}. It returns its props unchanged.\n *\n * @param props The condition and the branch content.\n * @returns The same props object, which `Switch` reads.\n * @example\n * import { Match } from \"@shadow-js/web\";\n *\n * const branch = Match({ when: \"ready\", children: \"Loaded\" });\n * console.log(branch.when); // \"ready\"\n * @see Switch\n * @since 1.0.0\n */\nexport function Match<T>(props: MatchProps<T>): MatchProps<T> {\n return props;\n}\n\n/**\n * Props of {@link Switch}.\n * @since 1.0.0\n */\nexport interface SwitchProps {\n /**\n * Shown when no Match is truthy. Read lazily.\n * @default undefined (nothing is rendered when no Match is truthy)\n */\n readonly fallback?: unknown;\n /**\n * One or more {@link Match} descriptors. `null`, `undefined` and booleans are ignored.\n * @default undefined (no branches; the fallback is shown)\n */\n readonly children?: unknown;\n}\n\n/** A Match descriptor is any object with a `when` key. Anything else is not a Match. */\nfunction isMatch(item: unknown): item is MatchProps<unknown> {\n return typeof item === \"object\" && item !== null && \"when\" in item;\n}\n\n/** Resolves the children into Match descriptors. Throws for any other kind of child. */\nfunction matchesOf(resolved: ResolvedChildren): MatchProps<unknown>[] {\n const matches: MatchProps<unknown>[] = [];\n for (const item of resolved.toArray()) {\n if (!isMatch(item))\n throw new TypeError(\n __DEV__ ? \"ShadowJS Switch: children must be <Match>\" : \"SHADOW_SWITCH_CHILDREN\",\n );\n matches.push(item);\n }\n return matches;\n}\n\n/**\n * Shows the first {@link Match} whose `when` is truthy, or the fallback when none is.\n * Re-selecting the same branch with the same truthiness (or, when keyed, the same value) does not\n * rebuild it.\n *\n * @param props See {@link SwitchProps}.\n * @returns An accessor of the selected branch's content.\n * @throws TypeError (production message `SHADOW_SWITCH_CHILDREN`) when a child is neither a Match\n * nor `null`, `undefined` or a boolean.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { Match, Switch } from \"@shadow-js/web\";\n *\n * function Status() {\n * const [error] = useSignal<string | null>(null);\n * const [data] = useSignal<string | null>(\"ready\");\n * return (\n * <Switch fallback={<p>Loading...</p>}>\n * <Match when={error()}>\n * <p>Failed</p>\n * </Match>\n * <Match when={data()}>\n * <p>Ready</p>\n * </Match>\n * </Switch>\n * );\n * }\n * @see Show\n * @since 1.0.0\n */\nexport function Switch(props: SwitchProps): Accessor<unknown> {\n const matches = resolveChildren(() => props.children);\n // Validate now, so that a wrong child is reported where the Switch is written.\n matchesOf(matches);\n return createBranches(\n \"Switch\",\n () => {\n const list = matchesOf(matches);\n for (const [index, match] of list.entries()) {\n const when = match.when;\n if (when) {\n return {\n index,\n keyed: match.keyed === true,\n when,\n read: () => match.when,\n body: () => match.children,\n };\n }\n }\n return {\n index: FALLBACK,\n keyed: false,\n when: undefined,\n read: () => undefined,\n body: () => undefined,\n };\n },\n () => props.fallback,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqCA,SAAgB,MAAS,OAAqC;CAC5D,OAAO;AACT;;AAoBA,SAAS,QAAQ,MAA4C;CAC3D,OAAO,OAAO,SAAS,YAAY,SAAS,QAAQ,UAAU;AAChE;;AAGA,SAAS,UAAU,UAAmD;CACpE,MAAM,UAAiC,CAAC;CACxC,KAAK,MAAM,QAAQ,SAAS,QAAQ,GAAG;EACrC,IAAI,CAAC,QAAQ,IAAI,GACf,MAAM,IAAI,UACE,2CACZ;EACF,QAAQ,KAAK,IAAI;CACnB;CACA,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,OAAO,OAAuC;CAC5D,MAAM,UAAUA,eAAsB,MAAM,QAAQ;CAEpD,UAAU,OAAO;CACjB,OAAO,eACL,gBACM;EACJ,MAAM,OAAO,UAAU,OAAO;EAC9B,KAAK,MAAM,CAAC,OAAO,UAAU,KAAK,QAAQ,GAAG;GAC3C,MAAM,OAAO,MAAM;GACnB,IAAI,MACF,OAAO;IACL;IACA,OAAO,MAAM,UAAU;IACvB;IACA,YAAY,MAAM;IAClB,YAAY,MAAM;GACpB;EAEJ;EACA,OAAO;GACL,OAAA;GACA,OAAO;GACP,MAAM,KAAA;GACN,YAAY,KAAA;GACZ,YAAY,KAAA;EACd;CACF,SACM,MAAM,QACd;AACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/derived.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A value the compiler keeps live: the result of `const x = <expression reading signals>` inside a
|
|
4
|
+
* component. Read it as `x.value` or call it as `x()`, so `{double}` and `{double()}` both work in
|
|
5
|
+
* JSX. When the value is itself a function, calling the derived calls that function with the
|
|
6
|
+
* arguments, so a derived function stays callable.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* import { useSignal } from "@shadow-js/core";
|
|
10
|
+
* import { derived } from "@shadow-js/web";
|
|
11
|
+
*
|
|
12
|
+
* function setup() {
|
|
13
|
+
* const [count, setCount] = useSignal(2);
|
|
14
|
+
* const double = derived(() => count() * 2);
|
|
15
|
+
* console.log(double.value); // 4
|
|
16
|
+
* setCount(5);
|
|
17
|
+
* console.log(double()); // 10
|
|
18
|
+
* }
|
|
19
|
+
* @see derived
|
|
20
|
+
* @since 1.0.0
|
|
21
|
+
*/
|
|
22
|
+
export interface Derived<T> {
|
|
23
|
+
/**
|
|
24
|
+
* Returns the current value, tracked. When the value is a function, calls it with `args` and
|
|
25
|
+
* returns its result instead.
|
|
26
|
+
*/
|
|
27
|
+
(...args: unknown[]): unknown;
|
|
28
|
+
/** The current value, tracked: reading it inside an effect or binding subscribes that reader. */
|
|
29
|
+
readonly value: T;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Wraps a computation as a {@link Derived} value that recomputes only when the signals it reads
|
|
33
|
+
* change. The compiler emits it for `const x = <expression reading signals>` inside components; it
|
|
34
|
+
* is not meant to be written by hand.
|
|
35
|
+
*
|
|
36
|
+
* @param compute The computation. Runs in a memo, so it is tracked and cached between reads.
|
|
37
|
+
* @returns A {@link Derived} whose `value` (and call result) follows `compute`.
|
|
38
|
+
* @example
|
|
39
|
+
* import { useSignal } from "@shadow-js/core";
|
|
40
|
+
* import { derived } from "@shadow-js/web";
|
|
41
|
+
*
|
|
42
|
+
* function setup() {
|
|
43
|
+
* const [price] = useSignal(20);
|
|
44
|
+
* const total = derived(() => price() * 3);
|
|
45
|
+
* console.log(total.value); // 60
|
|
46
|
+
* }
|
|
47
|
+
* @see Derived
|
|
48
|
+
* @since 1.0.0
|
|
49
|
+
*/
|
|
50
|
+
export declare function derived<T>(compute: () => T): Derived<T>;
|
|
51
|
+
//#endregion
|
|
52
|
+
//# sourceMappingURL=derived.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useMemo } from "@shadow-js/core";
|
|
2
|
+
//#region src/derived.ts
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a computation as a {@link Derived} value that recomputes only when the signals it reads
|
|
5
|
+
* change. The compiler emits it for `const x = <expression reading signals>` inside components; it
|
|
6
|
+
* is not meant to be written by hand.
|
|
7
|
+
*
|
|
8
|
+
* @param compute The computation. Runs in a memo, so it is tracked and cached between reads.
|
|
9
|
+
* @returns A {@link Derived} whose `value` (and call result) follows `compute`.
|
|
10
|
+
* @example
|
|
11
|
+
* import { useSignal } from "@shadow-js/core";
|
|
12
|
+
* import { derived } from "@shadow-js/web";
|
|
13
|
+
*
|
|
14
|
+
* function setup() {
|
|
15
|
+
* const [price] = useSignal(20);
|
|
16
|
+
* const total = derived(() => price() * 3);
|
|
17
|
+
* console.log(total.value); // 60
|
|
18
|
+
* }
|
|
19
|
+
* @see Derived
|
|
20
|
+
* @since 1.0.0
|
|
21
|
+
*/
|
|
22
|
+
function derived(compute) {
|
|
23
|
+
const memo = useMemo(compute);
|
|
24
|
+
const read = ((...args) => {
|
|
25
|
+
const current = memo();
|
|
26
|
+
return typeof current === "function" ? current(...args) : current;
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(read, "value", { get: memo });
|
|
29
|
+
return read;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { derived };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=derived.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derived.js","names":[],"sources":["../../src/derived.ts"],"sourcesContent":["import { useMemo } from \"@shadow-js/core\";\n\n/**\n * A value the compiler keeps live: the result of `const x = <expression reading signals>` inside a\n * component. Read it as `x.value` or call it as `x()`, so `{double}` and `{double()}` both work in\n * JSX. When the value is itself a function, calling the derived calls that function with the\n * arguments, so a derived function stays callable.\n *\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { derived } from \"@shadow-js/web\";\n *\n * function setup() {\n * const [count, setCount] = useSignal(2);\n * const double = derived(() => count() * 2);\n * console.log(double.value); // 4\n * setCount(5);\n * console.log(double()); // 10\n * }\n * @see derived\n * @since 1.0.0\n */\nexport interface Derived<T> {\n /**\n * Returns the current value, tracked. When the value is a function, calls it with `args` and\n * returns its result instead.\n */\n (...args: unknown[]): unknown;\n /** The current value, tracked: reading it inside an effect or binding subscribes that reader. */\n readonly value: T;\n}\n\n/**\n * Wraps a computation as a {@link Derived} value that recomputes only when the signals it reads\n * change. The compiler emits it for `const x = <expression reading signals>` inside components; it\n * is not meant to be written by hand.\n *\n * @param compute The computation. Runs in a memo, so it is tracked and cached between reads.\n * @returns A {@link Derived} whose `value` (and call result) follows `compute`.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { derived } from \"@shadow-js/web\";\n *\n * function setup() {\n * const [price] = useSignal(20);\n * const total = derived(() => price() * 3);\n * console.log(total.value); // 60\n * }\n * @see Derived\n * @since 1.0.0\n */\nexport function derived<T>(compute: () => T): Derived<T> {\n const memo = useMemo(compute);\n const read = ((...args: unknown[]): unknown => {\n const current = memo();\n return typeof current === \"function\"\n ? (current as (...a: unknown[]) => unknown)(...args)\n : current;\n }) as { (...args: unknown[]): unknown; value: T };\n Object.defineProperty(read, \"value\", { get: memo });\n return read as Derived<T>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmDA,SAAgB,QAAW,SAA8B;CACvD,MAAM,OAAO,QAAQ,OAAO;CAC5B,MAAM,SAAS,GAAG,SAA6B;EAC7C,MAAM,UAAU,KAAK;EACrB,OAAO,OAAO,YAAY,aACrB,QAAyC,GAAG,IAAI,IACjD;CACN;CACA,OAAO,eAAe,MAAM,SAAS,EAAE,KAAK,KAAK,CAAC;CAClD,OAAO;AACT"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region src/element.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates one HTML element from a tag name and a props object, without the generic prop runtime of
|
|
4
|
+
* `spread` and `Dynamic`: for a library that renders one fixed element (a link, a button) and wants
|
|
5
|
+
* to pay only for what it binds. It draws a hydration key, so during `hydrate()` it adopts the
|
|
6
|
+
* server's element and its children; on the server it returns the markup `Dynamic` writes for the tag.
|
|
7
|
+
*
|
|
8
|
+
* Each prop other than `children`, `ref` and `onX` is read in a render effect, so a getter prop
|
|
9
|
+
* updates the element in place. `class` and the other attributes follow {@link setAttribute} (URL
|
|
10
|
+
* attributes that would run script are refused); `style` follows {@link style}. Use `Dynamic` when the
|
|
11
|
+
* tag is not known in advance, or for SVG, `classList`, delegated events or React prop names.
|
|
12
|
+
*
|
|
13
|
+
* @param tag An HTML tag name matching `[a-z][a-z0-9-]*` (any case), such as `"a"`. `script` is
|
|
14
|
+
* refused.
|
|
15
|
+
* @param props The element's props. `onX` keys whose third letter is uppercase are native listeners,
|
|
16
|
+
* read once: the rest of the key lowercased is the event (`onClick` is `click`), and the value is a
|
|
17
|
+
* function (called with the element as `this`) or a `[fn, data]` tuple (called as `fn(data, event)`);
|
|
18
|
+
* handlers run batched and untracked. `ref` is called once with the element. `children` is inserted
|
|
19
|
+
* (a getter keeps it reactive). `class` takes a string; `style` a string or an object.
|
|
20
|
+
* @returns The element on the client; its server markup when rendering on the server.
|
|
21
|
+
* @throws TypeError `SHADOW_ELEMENT_TAG` when `tag` is not an allowed tag name.
|
|
22
|
+
* @example
|
|
23
|
+
* import { useSignal } from "@shadow-js/core";
|
|
24
|
+
* import { element } from "@shadow-js/web";
|
|
25
|
+
*
|
|
26
|
+
* function HomeLink() {
|
|
27
|
+
* const [active] = useSignal(true);
|
|
28
|
+
* return element("a", {
|
|
29
|
+
* href: "/",
|
|
30
|
+
* get "aria-current"() { return active() ? "page" : undefined; },
|
|
31
|
+
* onClick: (event: MouseEvent) => console.log(event.type),
|
|
32
|
+
* children: "Home",
|
|
33
|
+
* });
|
|
34
|
+
* }
|
|
35
|
+
* @see spread
|
|
36
|
+
* @since 1.0.0
|
|
37
|
+
*/
|
|
38
|
+
export declare function element(tag: string, props: object): unknown;
|
|
39
|
+
//#endregion
|
|
40
|
+
//# sourceMappingURL=element.d.ts.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { setAttribute } from "./attributes.js";
|
|
2
|
+
import { style } from "./class-style.js";
|
|
3
|
+
import { nextKey } from "./internal/hydration-scope.js";
|
|
4
|
+
import { checkClaimedTag } from "./internal/claim.js";
|
|
5
|
+
import { claims } from "./internal/hydration-hooks.js";
|
|
6
|
+
import { insert } from "./insert.js";
|
|
7
|
+
import { batch, untrack, useRenderEffect } from "@shadow-js/core";
|
|
8
|
+
//#region src/element.ts
|
|
9
|
+
/**
|
|
10
|
+
* The slim element primitive: one HTML element with attributes, event listeners, `ref` and children,
|
|
11
|
+
* and no generic prop runtime. `Dynamic` and `spread` cover every prop shape; this covers the common
|
|
12
|
+
* ones, so a library that renders one fixed element (a link, a button) pays for what it binds.
|
|
13
|
+
*
|
|
14
|
+
* It keeps the renderer's contracts: the hydration key is drawn when the element is created, so it
|
|
15
|
+
* claims the server's element and adopts its children; on the server it writes the same markup `Dynamic`
|
|
16
|
+
* writes for the tag.
|
|
17
|
+
*/
|
|
18
|
+
/** Tag shape that `Dynamic` accepts. `script` is refused for the same reason. */
|
|
19
|
+
const TAG_PATTERN = /^[a-z][a-z0-9-]*$/i;
|
|
20
|
+
/** `onClick` to `click`, when the key is an event handler name. */
|
|
21
|
+
function eventNameOf(key) {
|
|
22
|
+
return key.length > 2 && key.startsWith("on") && /^[A-Z]/.test(key.charAt(2)) ? key.slice(2).toLowerCase() : void 0;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Binds one listener, read once. A function runs with the element as `this`; a `[fn, data]` tuple
|
|
26
|
+
* receives `data` first. `null`, `undefined` and `false` bind nothing. Handlers run in a batch and
|
|
27
|
+
* untracked, as the event binding of `Dynamic` runs them.
|
|
28
|
+
*/
|
|
29
|
+
function bindListener(el, name, handler) {
|
|
30
|
+
let call;
|
|
31
|
+
if (typeof handler === "function") call = (event) => handler.call(el, event);
|
|
32
|
+
else if (Array.isArray(handler)) {
|
|
33
|
+
const [fn, data] = handler;
|
|
34
|
+
if (typeof fn === "function") call = (event) => fn.call(el, data, event);
|
|
35
|
+
}
|
|
36
|
+
if (call === void 0) return;
|
|
37
|
+
const run = call;
|
|
38
|
+
el.addEventListener(name, (event) => {
|
|
39
|
+
batch(() => untrack(() => run(event)));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates one HTML element from a tag name and a props object, without the generic prop runtime of
|
|
44
|
+
* `spread` and `Dynamic`: for a library that renders one fixed element (a link, a button) and wants
|
|
45
|
+
* to pay only for what it binds. It draws a hydration key, so during `hydrate()` it adopts the
|
|
46
|
+
* server's element and its children; on the server it returns the markup `Dynamic` writes for the tag.
|
|
47
|
+
*
|
|
48
|
+
* Each prop other than `children`, `ref` and `onX` is read in a render effect, so a getter prop
|
|
49
|
+
* updates the element in place. `class` and the other attributes follow {@link setAttribute} (URL
|
|
50
|
+
* attributes that would run script are refused); `style` follows {@link style}. Use `Dynamic` when the
|
|
51
|
+
* tag is not known in advance, or for SVG, `classList`, delegated events or React prop names.
|
|
52
|
+
*
|
|
53
|
+
* @param tag An HTML tag name matching `[a-z][a-z0-9-]*` (any case), such as `"a"`. `script` is
|
|
54
|
+
* refused.
|
|
55
|
+
* @param props The element's props. `onX` keys whose third letter is uppercase are native listeners,
|
|
56
|
+
* read once: the rest of the key lowercased is the event (`onClick` is `click`), and the value is a
|
|
57
|
+
* function (called with the element as `this`) or a `[fn, data]` tuple (called as `fn(data, event)`);
|
|
58
|
+
* handlers run batched and untracked. `ref` is called once with the element. `children` is inserted
|
|
59
|
+
* (a getter keeps it reactive). `class` takes a string; `style` a string or an object.
|
|
60
|
+
* @returns The element on the client; its server markup when rendering on the server.
|
|
61
|
+
* @throws TypeError `SHADOW_ELEMENT_TAG` when `tag` is not an allowed tag name.
|
|
62
|
+
* @example
|
|
63
|
+
* import { useSignal } from "@shadow-js/core";
|
|
64
|
+
* import { element } from "@shadow-js/web";
|
|
65
|
+
*
|
|
66
|
+
* function HomeLink() {
|
|
67
|
+
* const [active] = useSignal(true);
|
|
68
|
+
* return element("a", {
|
|
69
|
+
* href: "/",
|
|
70
|
+
* get "aria-current"() { return active() ? "page" : undefined; },
|
|
71
|
+
* onClick: (event: MouseEvent) => console.log(event.type),
|
|
72
|
+
* children: "Home",
|
|
73
|
+
* });
|
|
74
|
+
* }
|
|
75
|
+
* @see spread
|
|
76
|
+
* @since 1.0.0
|
|
77
|
+
*/
|
|
78
|
+
function element(tag, props) {
|
|
79
|
+
if (!TAG_PATTERN.test(tag) || tag.toLowerCase() === "script") throw new TypeError("ShadowJS element: invalid tag");
|
|
80
|
+
const read = props;
|
|
81
|
+
const claimed = claims.current.claimElement(nextKey());
|
|
82
|
+
if (claimed !== null && true) checkClaimedTag(claimed, tag);
|
|
83
|
+
const el = claimed ?? document.createElement(tag);
|
|
84
|
+
for (const key of Object.keys(props)) {
|
|
85
|
+
if (key === "children" || key === "ref") continue;
|
|
86
|
+
const event = eventNameOf(key);
|
|
87
|
+
if (event !== void 0) bindListener(el, event, read[key]);
|
|
88
|
+
else if (key === "style") {
|
|
89
|
+
let applied;
|
|
90
|
+
useRenderEffect(() => read[key], (value) => {
|
|
91
|
+
applied = style(el, value, applied);
|
|
92
|
+
});
|
|
93
|
+
} else useRenderEffect(() => read[key], (value) => {
|
|
94
|
+
setAttribute(el, key, value);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
const ref = read["ref"];
|
|
98
|
+
if (typeof ref === "function") ref(el);
|
|
99
|
+
insert(el, () => read["children"]);
|
|
100
|
+
return el;
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
export { element };
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.js","names":[],"sources":["../../src/element.ts"],"sourcesContent":["import { batch, untrack, useRenderEffect } from \"@shadow-js/core\";\nimport { setAttribute } from \"./attributes\";\nimport { style } from \"./class-style\";\nimport { insert } from \"./insert\";\nimport { checkClaimedTag } from \"./internal/claim\";\nimport { claims } from \"./internal/hydration-hooks\";\nimport { nextKey } from \"./internal/hydration-scope\";\nimport { ssrElement, ssrRaw } from \"./server/element\";\n\n/**\n * The slim element primitive: one HTML element with attributes, event listeners, `ref` and children,\n * and no generic prop runtime. `Dynamic` and `spread` cover every prop shape; this covers the common\n * ones, so a library that renders one fixed element (a link, a button) pays for what it binds.\n *\n * It keeps the renderer's contracts: the hydration key is drawn when the element is created, so it\n * claims the server's element and adopts its children; on the server it writes the same markup `Dynamic`\n * writes for the tag.\n */\n\n/** Tag shape that `Dynamic` accepts. `script` is refused for the same reason. */\nconst TAG_PATTERN = /^[a-z][a-z0-9-]*$/i;\n\n/** `onClick` to `click`, when the key is an event handler name. */\nfunction eventNameOf(key: string): string | undefined {\n return key.length > 2 && key.startsWith(\"on\") && /^[A-Z]/.test(key.charAt(2))\n ? key.slice(2).toLowerCase()\n : undefined;\n}\n\n/**\n * Binds one listener, read once. A function runs with the element as `this`; a `[fn, data]` tuple\n * receives `data` first. `null`, `undefined` and `false` bind nothing. Handlers run in a batch and\n * untracked, as the event binding of `Dynamic` runs them.\n */\nfunction bindListener(el: Element, name: string, handler: unknown): void {\n let call: ((event: Event) => unknown) | undefined;\n if (typeof handler === \"function\") {\n call = (event: Event): unknown => handler.call(el, event);\n } else if (Array.isArray(handler)) {\n const [fn, data] = handler as [unknown, unknown];\n if (typeof fn === \"function\") call = (event: Event): unknown => fn.call(el, data, event);\n }\n if (call === undefined) return;\n const run = call;\n el.addEventListener(name, (event: Event): void => {\n batch(() => untrack(() => run(event)));\n });\n}\n\n/**\n * Creates one HTML element from a tag name and a props object, without the generic prop runtime of\n * `spread` and `Dynamic`: for a library that renders one fixed element (a link, a button) and wants\n * to pay only for what it binds. It draws a hydration key, so during `hydrate()` it adopts the\n * server's element and its children; on the server it returns the markup `Dynamic` writes for the tag.\n *\n * Each prop other than `children`, `ref` and `onX` is read in a render effect, so a getter prop\n * updates the element in place. `class` and the other attributes follow {@link setAttribute} (URL\n * attributes that would run script are refused); `style` follows {@link style}. Use `Dynamic` when the\n * tag is not known in advance, or for SVG, `classList`, delegated events or React prop names.\n *\n * @param tag An HTML tag name matching `[a-z][a-z0-9-]*` (any case), such as `\"a\"`. `script` is\n * refused.\n * @param props The element's props. `onX` keys whose third letter is uppercase are native listeners,\n * read once: the rest of the key lowercased is the event (`onClick` is `click`), and the value is a\n * function (called with the element as `this`) or a `[fn, data]` tuple (called as `fn(data, event)`);\n * handlers run batched and untracked. `ref` is called once with the element. `children` is inserted\n * (a getter keeps it reactive). `class` takes a string; `style` a string or an object.\n * @returns The element on the client; its server markup when rendering on the server.\n * @throws TypeError `SHADOW_ELEMENT_TAG` when `tag` is not an allowed tag name.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { element } from \"@shadow-js/web\";\n *\n * function HomeLink() {\n * const [active] = useSignal(true);\n * return element(\"a\", {\n * href: \"/\",\n * get \"aria-current\"() { return active() ? \"page\" : undefined; },\n * onClick: (event: MouseEvent) => console.log(event.type),\n * children: \"Home\",\n * });\n * }\n * @see spread\n * @since 1.0.0\n */\nexport function element(tag: string, props: object): unknown {\n if (!TAG_PATTERN.test(tag) || tag.toLowerCase() === \"script\") {\n throw new TypeError(__DEV__ ? \"ShadowJS element: invalid tag\" : \"SHADOW_ELEMENT_TAG\");\n }\n const read = props as Readonly<Record<string, unknown>>;\n if (__SERVER__) {\n // The children are read after the hydration key is drawn, in the order the client claims them.\n return ssrElement(\n tag,\n props,\n () => {\n const children = read[\"children\"];\n return children === undefined\n ? undefined\n : [ssrRaw(\"<!--[-->\"), children, ssrRaw(\"<!--]-->\")];\n },\n true,\n );\n }\n const claimed = claims.current.claimElement(nextKey());\n if (claimed !== null && __DEV__) checkClaimedTag(claimed, tag);\n const el = claimed ?? document.createElement(tag);\n for (const key of Object.keys(props)) {\n if (key === \"children\" || key === \"ref\") continue;\n const event = eventNameOf(key);\n if (event !== undefined) {\n bindListener(el, event, read[key]);\n } else if (key === \"style\") {\n // The last value written, so a property that leaves the style object is removed (as spread does).\n let applied: unknown;\n useRenderEffect(\n () => read[key],\n (value) => {\n applied = style(el as HTMLElement, value, applied);\n },\n );\n } else {\n useRenderEffect(\n () => read[key],\n (value) => {\n setAttribute(el, key, value);\n },\n );\n }\n }\n const ref = read[\"ref\"];\n if (typeof ref === \"function\") ref(el);\n insert(el, () => read[\"children\"]);\n return el;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,MAAM,cAAc;;AAGpB,SAAS,YAAY,KAAiC;CACpD,OAAO,IAAI,SAAS,KAAK,IAAI,WAAW,IAAI,KAAK,SAAS,KAAK,IAAI,OAAO,CAAC,CAAC,IACxE,IAAI,MAAM,CAAC,CAAC,CAAC,YAAY,IACzB,KAAA;AACN;;;;;;AAOA,SAAS,aAAa,IAAa,MAAc,SAAwB;CACvE,IAAI;CACJ,IAAI,OAAO,YAAY,YACrB,QAAQ,UAA0B,QAAQ,KAAK,IAAI,KAAK;MACnD,IAAI,MAAM,QAAQ,OAAO,GAAG;EACjC,MAAM,CAAC,IAAI,QAAQ;EACnB,IAAI,OAAO,OAAO,YAAY,QAAQ,UAA0B,GAAG,KAAK,IAAI,MAAM,KAAK;CACzF;CACA,IAAI,SAAS,KAAA,GAAW;CACxB,MAAM,MAAM;CACZ,GAAG,iBAAiB,OAAO,UAAuB;EAChD,YAAY,cAAc,IAAI,KAAK,CAAC,CAAC;CACvC,CAAC;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,QAAQ,KAAa,OAAwB;CAC3D,IAAI,CAAC,YAAY,KAAK,GAAG,KAAK,IAAI,YAAY,MAAM,UAClD,MAAM,IAAI,UAAoB,+BAAsD;CAEtF,MAAM,OAAO;CAeb,MAAM,UAAU,OAAO,QAAQ,aAAa,QAAQ,CAAC;CACrD,IAAI,YAAY,QAAA,MAAiB,gBAAgB,SAAS,GAAG;CAC7D,MAAM,KAAK,WAAW,SAAS,cAAc,GAAG;CAChD,KAAK,MAAM,OAAO,OAAO,KAAK,KAAK,GAAG;EACpC,IAAI,QAAQ,cAAc,QAAQ,OAAO;EACzC,MAAM,QAAQ,YAAY,GAAG;EAC7B,IAAI,UAAU,KAAA,GACZ,aAAa,IAAI,OAAO,KAAK,IAAI;OAC5B,IAAI,QAAQ,SAAS;GAE1B,IAAI;GACJ,sBACQ,KAAK,OACV,UAAU;IACT,UAAU,MAAM,IAAmB,OAAO,OAAO;GACnD,CACF;EACF,OACE,sBACQ,KAAK,OACV,UAAU;GACT,aAAa,IAAI,KAAK,KAAK;EAC7B,CACF;CAEJ;CACA,MAAM,MAAM,KAAK;CACjB,IAAI,OAAO,QAAQ,YAAY,IAAI,EAAE;CACrC,OAAO,UAAU,KAAK,WAAW;CACjC,OAAO;AACT"}
|