@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,18 @@
|
|
|
1
|
+
import { createBranches } from "./branch.js";
|
|
2
|
+
//#region src/control-flow/show.ts
|
|
3
|
+
function Show(props) {
|
|
4
|
+
return createBranches("Show", () => {
|
|
5
|
+
const when = props.when;
|
|
6
|
+
return {
|
|
7
|
+
index: when ? 0 : -1,
|
|
8
|
+
keyed: props.keyed === true,
|
|
9
|
+
when,
|
|
10
|
+
read: () => props.when,
|
|
11
|
+
body: () => props.children
|
|
12
|
+
};
|
|
13
|
+
}, () => props.fallback);
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { Show };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=show.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"show.js","names":[],"sources":["../../../src/control-flow/show.ts"],"sourcesContent":["import type { Accessor } from \"@shadow-js/core\";\nimport type { JsxChild } from \"../jsx/types\";\nimport { createBranches, FALLBACK } from \"./branch\";\n\n/** What `when` accepts: the value, or any falsy stand-in (`0` and `\"\"` count as falsy). */\ntype ShowCondition<T> = T | undefined | null | false | 0 | \"\";\n\n/** Props shared by both forms of {@link Show}. */\ninterface ShowBaseProps<T> {\n /** The condition. The children are shown while it is truthy. */\n readonly when: ShowCondition<T>;\n /**\n * Shown while `when` is falsy. Read lazily, only when it is needed.\n * @default undefined (a falsy `when` renders nothing)\n */\n readonly fallback?: unknown;\n}\n\n/**\n * Keyed form: the children are rebuilt whenever the identity of `when` changes and a callback\n * child receives the value itself.\n * @since 1.0.0\n */\nexport interface ShowKeyedProps<T> extends ShowBaseProps<T> {\n /** Must be `true` in this form: a change of the identity of `when` rebuilds the children. */\n readonly keyed: true;\n /**\n * Plain content, an accessor, or a callback `(item) => content` called untracked in the branch.\n * @default undefined (a truthy `when` renders nothing)\n */\n readonly children?: JsxChild | (() => unknown) | ((item: NonNullable<T>) => unknown);\n}\n\n/**\n * Default form: the branch is rebuilt only when the truthiness of `when` changes. A callback child\n * receives an accessor of the latest truthy value; reading it after `when` became falsy throws a\n * TypeError, except while the branch is being torn down.\n * @since 1.0.0\n */\nexport interface ShowAccessorProps<T> extends ShowBaseProps<T> {\n /**\n * Absent or `false` in this form: the children are rebuilt only when the truthiness of `when`\n * changes.\n * @default false\n */\n readonly keyed?: false;\n /**\n * Plain content, an accessor, or a callback `(item) => content` called untracked in the branch.\n * @default undefined (a truthy `when` renders nothing)\n */\n readonly children?: JsxChild | (() => unknown) | ((item: Accessor<NonNullable<T>>) => unknown);\n}\n\n/**\n * Props of {@link Show}.\n * @since 1.0.0\n */\nexport type ShowProps<T> = ShowKeyedProps<T> | ShowAccessorProps<T>;\n\n/**\n * The same props with untyped `children`, for code that forwards children it does not know the\n * shape of (a wrapper component's own `props.children`).\n * @since 1.0.0\n */\nexport interface ShowLooseProps<T> extends ShowBaseProps<T> {\n /**\n * Same meaning as in {@link ShowKeyedProps}: `true` rebuilds the children when the identity of\n * `when` changes.\n * @default false\n */\n readonly keyed?: boolean;\n /**\n * Plain content, an accessor, or a callback, as in {@link ShowProps}.\n * @default undefined (a truthy `when` renders nothing)\n */\n readonly children?: unknown;\n}\n\n/**\n * Shows `children` while `when` is truthy, and `fallback` otherwise. The branch is rebuilt only\n * when the truthiness of `when` changes (or, with `keyed`, when its identity changes).\n *\n * `when` follows JavaScript truthiness: `0`, `\"\"`, `null`, `undefined` and `false` show the\n * fallback. While `fallback` is not given, a falsy `when` renders nothing.\n *\n * @param props See {@link ShowProps}.\n * @returns An accessor of the current branch's content. The DOM runtime's `insert` consumes it.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { Show } from \"@shadow-js/web\";\n *\n * function Greeting() {\n * const [user] = useSignal<{ name: string } | null>(null);\n * return (\n * <Show when={user()} fallback={<p>Sign in</p>}>\n * {(u) => <p>Hello {u().name}</p>}\n * </Show>\n * );\n * }\n * @see Switch\n * @see ErrorBoundary\n * @since 1.0.0\n */\nexport function Show<T>(props: ShowProps<T>): Accessor<unknown>;\nexport function Show<T>(props: ShowLooseProps<T>): Accessor<unknown>;\nexport function Show<T>(props: ShowLooseProps<T>): Accessor<unknown> {\n return createBranches(\n \"Show\",\n () => {\n const when = props.when;\n return {\n index: when ? 0 : FALLBACK,\n keyed: props.keyed === true,\n when,\n read: () => props.when,\n body: () => props.children,\n };\n },\n () => props.fallback,\n );\n}\n"],"mappings":";;AAyGA,SAAgB,KAAQ,OAA6C;CACnE,OAAO,eACL,cACM;EACJ,MAAM,OAAO,MAAM;EACnB,OAAO;GACL,OAAO,OAAO,IAAA;GACd,OAAO,MAAM,UAAU;GACvB;GACA,YAAY,MAAM;GAClB,YAAY,MAAM;EACpB;CACF,SACM,MAAM,QACd;AACF"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createContext, onCleanup } from "@shadow-js/core";
|
|
2
|
+
import { createSignalNode, readSignal, writeSignal } from "@shadow-js/core/extend";
|
|
3
|
+
//#region src/control-flow/suspense-list.ts
|
|
4
|
+
/** The enclosing list, or null. @internal */
|
|
5
|
+
const SuspenseListContext = /* @__PURE__ */ createContext(null, { name: "SuspenseList" });
|
|
6
|
+
/**
|
|
7
|
+
* Coordinates the `<Suspense>` boundaries below it so a page of independent loads reveals in a
|
|
8
|
+
* calm order instead of popping in at random.
|
|
9
|
+
*
|
|
10
|
+
* @param props See {@link SuspenseListProps}.
|
|
11
|
+
* @returns An accessor of the children, rendered with the list's coordination in context.
|
|
12
|
+
* @example
|
|
13
|
+
* import { Suspense, SuspenseList } from "@shadow-js/web";
|
|
14
|
+
*
|
|
15
|
+
* function Skeleton() {
|
|
16
|
+
* return <p>Loading...</p>;
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* function Profile() {
|
|
20
|
+
* return <p>Profile</p>;
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* function Feed() {
|
|
24
|
+
* return <p>Feed</p>;
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* function Page() {
|
|
28
|
+
* return (
|
|
29
|
+
* <SuspenseList revealOrder="forwards" tail="collapsed">
|
|
30
|
+
* <Suspense fallback={<Skeleton />}>
|
|
31
|
+
* <Profile />
|
|
32
|
+
* </Suspense>
|
|
33
|
+
* <Suspense fallback={<Skeleton />}>
|
|
34
|
+
* <Feed />
|
|
35
|
+
* </Suspense>
|
|
36
|
+
* </SuspenseList>
|
|
37
|
+
* );
|
|
38
|
+
* }
|
|
39
|
+
* @see Suspense
|
|
40
|
+
* @since 1.0.0
|
|
41
|
+
*/
|
|
42
|
+
function SuspenseList(props) {
|
|
43
|
+
const changes = createSignalNode(0, false);
|
|
44
|
+
const slots = [];
|
|
45
|
+
const touch = () => {
|
|
46
|
+
writeSignal(changes, 0, { allowInMemo: true });
|
|
47
|
+
};
|
|
48
|
+
return SuspenseListContext({
|
|
49
|
+
value: { register(ready) {
|
|
50
|
+
const entry = { ready };
|
|
51
|
+
slots.push(entry);
|
|
52
|
+
touch();
|
|
53
|
+
onCleanup(() => {
|
|
54
|
+
const index = slots.indexOf(entry);
|
|
55
|
+
if (index !== -1) slots.splice(index, 1);
|
|
56
|
+
touch();
|
|
57
|
+
});
|
|
58
|
+
const position = () => {
|
|
59
|
+
readSignal(changes);
|
|
60
|
+
return slots.indexOf(entry);
|
|
61
|
+
};
|
|
62
|
+
const reveal = () => {
|
|
63
|
+
const index = position();
|
|
64
|
+
if (index === -1) return false;
|
|
65
|
+
switch (props.revealOrder) {
|
|
66
|
+
case "together": return slots.every((slot) => slot.ready());
|
|
67
|
+
case "forwards": return slots.slice(0, index + 1).every((slot) => slot.ready());
|
|
68
|
+
case "backwards": return slots.slice(index).every((slot) => slot.ready());
|
|
69
|
+
default: return ready();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const showFallback = () => {
|
|
73
|
+
if (reveal()) return false;
|
|
74
|
+
const order = props.revealOrder;
|
|
75
|
+
if (!(order === "forwards" || order === "backwards")) return true;
|
|
76
|
+
if (props.tail === "hidden") return false;
|
|
77
|
+
if (props.tail !== "collapsed") return true;
|
|
78
|
+
const index = position();
|
|
79
|
+
const ordered = order === "backwards" ? [...slots].reverse() : slots;
|
|
80
|
+
const wanted = order === "backwards" ? slots.length - 1 - index : index;
|
|
81
|
+
for (let i = 0; i < ordered.length; i += 1) {
|
|
82
|
+
const candidate = ordered[i];
|
|
83
|
+
if (candidate !== void 0 && !candidate.ready()) return i === wanted;
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
reveal,
|
|
89
|
+
showFallback
|
|
90
|
+
};
|
|
91
|
+
} },
|
|
92
|
+
get children() {
|
|
93
|
+
return props.children;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
export { SuspenseList, SuspenseListContext };
|
|
99
|
+
|
|
100
|
+
//# sourceMappingURL=suspense-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suspense-list.js","names":[],"sources":["../../../src/control-flow/suspense-list.ts"],"sourcesContent":["import { type Accessor, type Context, createContext, onCleanup, useContext } from \"@shadow-js/core\";\nimport { createSignalNode, readSignal, writeSignal } from \"@shadow-js/core/extend\";\n\n/** What a `<Suspense>` inside a list learns about its place: when to show content and a fallback. @internal */\nexport interface SuspenseListSlot {\n /** True when this boundary may show its content now (it is ready and the order allows it). */\n reveal(): boolean;\n /** True when this boundary should show its fallback while it waits. */\n showFallback(): boolean;\n}\n\n/** Provided by `<SuspenseList>` to the boundaries below it. @internal */\nexport interface SuspenseListState {\n /** Registers a boundary, in creation order; `ready` reports that its own data has loaded. */\n register(ready: () => boolean): SuspenseListSlot;\n}\n\n/** The enclosing list, or null. @internal */\nexport const SuspenseListContext: Context<SuspenseListState | null> =\n /* @__PURE__ */ createContext<SuspenseListState | null>(null, { name: \"SuspenseList\" });\n\n/**\n * Props of {@link SuspenseList}.\n * @since 1.0.0\n */\nexport interface SuspenseListProps {\n /**\n * `\"forwards\"`: boundaries reveal in order, each after the ones before it. `\"backwards\"`: the\n * same from the last one. `\"together\"`: all at once, when the last one is ready. Without it each\n * boundary reveals on its own. Read reactively.\n * @default undefined (each boundary reveals as soon as its own data is ready)\n */\n readonly revealOrder?: \"forwards\" | \"backwards\" | \"together\" | undefined;\n /**\n * What the boundaries that are still waiting show: `\"collapsed\"` only the next fallback in\n * order, `\"hidden\"` none. Applies to `forwards` and `backwards`; the default shows every fallback.\n * @default undefined (every waiting boundary shows its fallback)\n */\n readonly tail?: \"collapsed\" | \"hidden\" | undefined;\n /**\n * The content, with the `<Suspense>` boundaries to coordinate anywhere below it.\n * @default undefined (renders nothing)\n */\n readonly children?: unknown;\n}\n\n/**\n * Coordinates the `<Suspense>` boundaries below it so a page of independent loads reveals in a\n * calm order instead of popping in at random.\n *\n * @param props See {@link SuspenseListProps}.\n * @returns An accessor of the children, rendered with the list's coordination in context.\n * @example\n * import { Suspense, SuspenseList } from \"@shadow-js/web\";\n *\n * function Skeleton() {\n * return <p>Loading...</p>;\n * }\n *\n * function Profile() {\n * return <p>Profile</p>;\n * }\n *\n * function Feed() {\n * return <p>Feed</p>;\n * }\n *\n * function Page() {\n * return (\n * <SuspenseList revealOrder=\"forwards\" tail=\"collapsed\">\n * <Suspense fallback={<Skeleton />}>\n * <Profile />\n * </Suspense>\n * <Suspense fallback={<Skeleton />}>\n * <Feed />\n * </Suspense>\n * </SuspenseList>\n * );\n * }\n * @see Suspense\n * @since 1.0.0\n */\nexport function SuspenseList(props: SuspenseListProps): Accessor<unknown> {\n // The set of boundaries changes as they are created and disposed; `changes` tells readers.\n const changes = createSignalNode<number>(0, false);\n const slots: Array<{ readonly ready: () => boolean }> = [];\n const touch = (): void => {\n writeSignal(changes, 0, { allowInMemo: true });\n };\n\n const state: SuspenseListState = {\n register(ready) {\n const entry = { ready };\n slots.push(entry);\n touch();\n onCleanup(() => {\n const index = slots.indexOf(entry);\n if (index !== -1) slots.splice(index, 1);\n touch();\n });\n const position = (): number => {\n readSignal(changes);\n return slots.indexOf(entry);\n };\n const reveal = (): boolean => {\n const index = position();\n if (index === -1) return false;\n switch (props.revealOrder) {\n case \"together\":\n return slots.every((slot) => slot.ready());\n case \"forwards\":\n return slots.slice(0, index + 1).every((slot) => slot.ready());\n case \"backwards\":\n return slots.slice(index).every((slot) => slot.ready());\n default:\n return ready();\n }\n };\n const showFallback = (): boolean => {\n if (reveal()) return false;\n const order = props.revealOrder;\n const sequential = order === \"forwards\" || order === \"backwards\";\n if (!sequential) return true;\n if (props.tail === \"hidden\") return false;\n if (props.tail !== \"collapsed\") return true;\n // Only the next boundary in order that is not revealed yet shows its fallback.\n const index = position();\n const ordered = order === \"backwards\" ? [...slots].reverse() : slots;\n const wanted = order === \"backwards\" ? slots.length - 1 - index : index;\n for (let i = 0; i < ordered.length; i += 1) {\n const candidate = ordered[i];\n if (candidate !== undefined && !candidate.ready()) return i === wanted;\n }\n return false;\n };\n return { reveal, showFallback };\n },\n };\n\n return SuspenseListContext({\n value: state,\n get children() {\n return props.children;\n },\n }) as Accessor<unknown>;\n}\n\n/** The slot of the nearest list for a boundary created now, or null outside a list. @internal */\nexport function registerInList(ready: () => boolean): SuspenseListSlot | null {\n const list = useContext(SuspenseListContext);\n return list === null ? null : list.register(ready);\n}\n"],"mappings":";;;;AAkBA,MAAa,sBACK,8BAAwC,MAAM,EAAE,MAAM,eAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DxF,SAAgB,aAAa,OAA6C;CAExE,MAAM,UAAU,iBAAyB,GAAG,KAAK;CACjD,MAAM,QAAkD,CAAC;CACzD,MAAM,cAAoB;EACxB,YAAY,SAAS,GAAG,EAAE,aAAa,KAAK,CAAC;CAC/C;CAmDA,OAAO,oBAAoB;EACzB,OAAO,EAjDP,SAAS,OAAO;GACd,MAAM,QAAQ,EAAE,MAAM;GACtB,MAAM,KAAK,KAAK;GAChB,MAAM;GACN,gBAAgB;IACd,MAAM,QAAQ,MAAM,QAAQ,KAAK;IACjC,IAAI,UAAU,IAAI,MAAM,OAAO,OAAO,CAAC;IACvC,MAAM;GACR,CAAC;GACD,MAAM,iBAAyB;IAC7B,WAAW,OAAO;IAClB,OAAO,MAAM,QAAQ,KAAK;GAC5B;GACA,MAAM,eAAwB;IAC5B,MAAM,QAAQ,SAAS;IACvB,IAAI,UAAU,IAAI,OAAO;IACzB,QAAQ,MAAM,aAAd;KACE,KAAK,YACH,OAAO,MAAM,OAAO,SAAS,KAAK,MAAM,CAAC;KAC3C,KAAK,YACH,OAAO,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,OAAO,SAAS,KAAK,MAAM,CAAC;KAC/D,KAAK,aACH,OAAO,MAAM,MAAM,KAAK,CAAC,CAAC,OAAO,SAAS,KAAK,MAAM,CAAC;KACxD,SACE,OAAO,MAAM;IACjB;GACF;GACA,MAAM,qBAA8B;IAClC,IAAI,OAAO,GAAG,OAAO;IACrB,MAAM,QAAQ,MAAM;IAEpB,IAAI,EADe,UAAU,cAAc,UAAU,cACpC,OAAO;IACxB,IAAI,MAAM,SAAS,UAAU,OAAO;IACpC,IAAI,MAAM,SAAS,aAAa,OAAO;IAEvC,MAAM,QAAQ,SAAS;IACvB,MAAM,UAAU,UAAU,cAAc,CAAC,GAAG,KAAK,CAAC,CAAC,QAAQ,IAAI;IAC/D,MAAM,SAAS,UAAU,cAAc,MAAM,SAAS,IAAI,QAAQ;IAClE,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK,GAAG;KAC1C,MAAM,YAAY,QAAQ;KAC1B,IAAI,cAAc,KAAA,KAAa,CAAC,UAAU,MAAM,GAAG,OAAO,MAAM;IAClE;IACA,OAAO;GACT;GACA,OAAO;IAAE;IAAQ;GAAa;EAChC,EAIW;EACX,IAAI,WAAW;GACb,OAAO,MAAM;EACf;CACF,CAAC;AACH"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { childScope, nextKey, withScope } from "../internal/hydration-scope.js";
|
|
2
|
+
import { escape } from "../server/escape.js";
|
|
3
|
+
import { ssrRaw } from "../server/element.js";
|
|
4
|
+
import { StreamContext } from "../internal/stream-context.js";
|
|
5
|
+
import { SuspenseContext, getOwner, runWithOwner, useContext } from "@shadow-js/core";
|
|
6
|
+
import { createOwner, createSignalNode, readSignal, transitionHooks, writeSignal } from "@shadow-js/core/extend";
|
|
7
|
+
//#region src/control-flow/suspense.ts
|
|
8
|
+
/**
|
|
9
|
+
* A counter the resources of one boundary report to (see {@link SuspenseTracker}), and the hold a
|
|
10
|
+
* transition takes on the boundary. A transition that reads pending data while the boundary shows
|
|
11
|
+
* content does not bring the fallback back: its readers keep their previous values, the boundary
|
|
12
|
+
* keeps its content, and the readers run again when the count returns to zero.
|
|
13
|
+
*/
|
|
14
|
+
function createTracker() {
|
|
15
|
+
const pending = createSignalNode(0, Object.is);
|
|
16
|
+
let hold;
|
|
17
|
+
let shown = false;
|
|
18
|
+
const adjust = (by) => {
|
|
19
|
+
writeSignal(pending, pending.value + by, { allowInMemo: true });
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
tracker: {
|
|
23
|
+
increment: () => adjust(1),
|
|
24
|
+
decrement: () => {
|
|
25
|
+
adjust(-1);
|
|
26
|
+
if (pending.value === 0) hold?.release();
|
|
27
|
+
},
|
|
28
|
+
hold: () => {
|
|
29
|
+
if (!shown) return false;
|
|
30
|
+
hold ??= transitionHooks()?.boundaryHold();
|
|
31
|
+
return hold?.engage() === true;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
count: () => readSignal(pending),
|
|
35
|
+
holding: () => hold?.holding() === true,
|
|
36
|
+
revealed: () => {
|
|
37
|
+
shown = true;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Shows `fallback` while resources read inside it are loading for the first time. The children
|
|
43
|
+
* are created once and stay alive (with their state) while the fallback is visible; the boundary
|
|
44
|
+
* only switches what is displayed. Nested boundaries each track their own resources.
|
|
45
|
+
*
|
|
46
|
+
* On the server a boundary renders its fallback when its data is not ready (`renderToString`), or
|
|
47
|
+
* streams the content later (`renderToStream`). Content and fallback get their own hydration key
|
|
48
|
+
* space, so what a boundary renders never shifts the keys of its siblings.
|
|
49
|
+
*
|
|
50
|
+
* @param props See {@link SuspenseProps}.
|
|
51
|
+
* @returns An accessor of what the boundary shows: the fallback while a resource is pending, the
|
|
52
|
+
* children otherwise.
|
|
53
|
+
* @example
|
|
54
|
+
* import { useResource } from "@shadow-js/core";
|
|
55
|
+
* import { Suspense } from "@shadow-js/web";
|
|
56
|
+
*
|
|
57
|
+
* function Profile() {
|
|
58
|
+
* const name = useResource(() => Promise.resolve("Ada"));
|
|
59
|
+
* return <p>{name()}</p>;
|
|
60
|
+
* }
|
|
61
|
+
*
|
|
62
|
+
* function Page() {
|
|
63
|
+
* return (
|
|
64
|
+
* <Suspense fallback={<p>Loading...</p>}>
|
|
65
|
+
* <Profile />
|
|
66
|
+
* </Suspense>
|
|
67
|
+
* );
|
|
68
|
+
* }
|
|
69
|
+
* @see SuspenseList
|
|
70
|
+
* @see ErrorBoundary
|
|
71
|
+
* @since 1.0.0
|
|
72
|
+
*/
|
|
73
|
+
function Suspense(props) {
|
|
74
|
+
const key = nextKey();
|
|
75
|
+
const { tracker, count, holding, revealed } = createTracker();
|
|
76
|
+
const boundary = createOwner();
|
|
77
|
+
boundary.gate = () => count() > 0 || false;
|
|
78
|
+
return suspenseOnServer(props, key, count, runWithOwner(boundary, () => withScope(childScope(key), () => SuspenseContext({
|
|
79
|
+
value: tracker,
|
|
80
|
+
get children() {
|
|
81
|
+
return props.children;
|
|
82
|
+
}
|
|
83
|
+
}))));
|
|
84
|
+
}
|
|
85
|
+
/** Server behavior: ready content, a fallback, or a fallback plus a deferred stream chunk. */
|
|
86
|
+
function suspenseOnServer(props, key, count, content) {
|
|
87
|
+
const fallbackScope = childScope(key === void 0 ? void 0 : `${key}f`);
|
|
88
|
+
if (count() === 0) return content;
|
|
89
|
+
const sink = useContext(StreamContext);
|
|
90
|
+
if (sink === null || key === void 0) return () => withScope(fallbackScope, () => props.fallback);
|
|
91
|
+
const owner = getOwner();
|
|
92
|
+
const boundary = {
|
|
93
|
+
id: key,
|
|
94
|
+
rebuild: () => {
|
|
95
|
+
const next = createTracker();
|
|
96
|
+
const rebuilt = runWithOwner(owner, () => withScope(childScope(key), () => SuspenseContext({
|
|
97
|
+
value: next.tracker,
|
|
98
|
+
get children() {
|
|
99
|
+
return props.children;
|
|
100
|
+
}
|
|
101
|
+
})));
|
|
102
|
+
if (next.count() > 0) {
|
|
103
|
+
sink.defer(boundary);
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
return escape(rebuilt());
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
sink.defer(boundary);
|
|
110
|
+
return () => [
|
|
111
|
+
ssrRaw(`<!--[b:${key}-->`),
|
|
112
|
+
withScope(fallbackScope, () => props.fallback),
|
|
113
|
+
ssrRaw("<!--]-->")
|
|
114
|
+
];
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
export { Suspense };
|
|
118
|
+
|
|
119
|
+
//# 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;CAK5D,MAAM,WAAW,YAAY;CAC7B,SAAS,aAAa,MAAM,IAAI,KAAM;CAWtB,OAAO,iBAAiB,OAAO,KAAK,OAVpC,aAAa,gBAC3B,UAAU,WAAW,GAAG,SACtB,gBAAgB;EACd,OAAO;EACP,IAAI,WAAW;GACb,OAAO,MAAM;EACf;CACF,CAAC,CACH,CAE+D,CAAkB;AAqBrF;;AAGA,SAAS,iBACP,OACA,KACA,OACA,SACmB;CACnB,MAAM,gBAAgB,WAAW,QAAQ,KAAA,IAAY,KAAA,IAAY,GAAG,IAAI,EAAE;CAC1E,IAAI,MAAM,MAAM,GAAG,OAAO;CAC1B,MAAM,OAAO,WAAW,aAAa;CACrC,IAAI,SAAS,QAAQ,QAAQ,KAAA,GAC3B,aAAa,UAAU,qBAAqB,MAAM,QAAQ;CAE5D,MAAM,QAAQ,SAAS;CACvB,MAAM,WAAW;EACf,IAAI;EACJ,eAA8B;GAC5B,MAAM,OAAO,cAAc;GAC3B,MAAM,UAAU,aAAa,aAC3B,UAAU,WAAW,GAAG,SACtB,gBAAgB;IACd,OAAO,KAAK;IACZ,IAAI,WAAW;KACb,OAAO,MAAM;IACf;GACF,CAAC,CACH,CACF;GACA,IAAI,KAAK,MAAM,IAAI,GAAG;IACpB,KAAK,MAAM,QAAQ;IACnB,OAAO;GACT;GACA,OAAO,OAAQ,QAA0B,CAAC;EAC5C;CACF;CACA,KAAK,MAAM,QAAQ;CAEnB,aAAa;EACX,OAAO,UAAU,IAAI,IAAI;EACzB,UAAU,qBAAqB,MAAM,QAAQ;EAC7C,OAAO,UAAU;CACnB;AACF"}
|
|
@@ -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,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,66 @@
|
|
|
1
|
+
import { ssrElement, ssrRaw } from "./server/element.js";
|
|
2
|
+
import "@shadow-js/core";
|
|
3
|
+
//#region src/element.ts
|
|
4
|
+
/**
|
|
5
|
+
* The slim element primitive: one HTML element with attributes, event listeners, `ref` and children,
|
|
6
|
+
* and no generic prop runtime. `Dynamic` and `spread` cover every prop shape; this covers the common
|
|
7
|
+
* ones, so a library that renders one fixed element (a link, a button) pays for what it binds.
|
|
8
|
+
*
|
|
9
|
+
* It keeps the renderer's contracts: the hydration key is drawn when the element is created, so it
|
|
10
|
+
* claims the server's element and adopts its children; on the server it writes the same markup `Dynamic`
|
|
11
|
+
* writes for the tag.
|
|
12
|
+
*/
|
|
13
|
+
/** Tag shape that `Dynamic` accepts. `script` is refused for the same reason. */
|
|
14
|
+
const TAG_PATTERN = /^[a-z][a-z0-9-]*$/i;
|
|
15
|
+
/**
|
|
16
|
+
* Creates one HTML element from a tag name and a props object, without the generic prop runtime of
|
|
17
|
+
* `spread` and `Dynamic`: for a library that renders one fixed element (a link, a button) and wants
|
|
18
|
+
* to pay only for what it binds. It draws a hydration key, so during `hydrate()` it adopts the
|
|
19
|
+
* server's element and its children; on the server it returns the markup `Dynamic` writes for the tag.
|
|
20
|
+
*
|
|
21
|
+
* Each prop other than `children`, `ref` and `onX` is read in a render effect, so a getter prop
|
|
22
|
+
* updates the element in place. `class` and the other attributes follow {@link setAttribute} (URL
|
|
23
|
+
* attributes that would run script are refused); `style` follows {@link style}. Use `Dynamic` when the
|
|
24
|
+
* tag is not known in advance, or for SVG, `classList`, delegated events or React prop names.
|
|
25
|
+
*
|
|
26
|
+
* @param tag An HTML tag name matching `[a-z][a-z0-9-]*` (any case), such as `"a"`. `script` is
|
|
27
|
+
* refused.
|
|
28
|
+
* @param props The element's props. `onX` keys whose third letter is uppercase are native listeners,
|
|
29
|
+
* read once: the rest of the key lowercased is the event (`onClick` is `click`), and the value is a
|
|
30
|
+
* function (called with the element as `this`) or a `[fn, data]` tuple (called as `fn(data, event)`);
|
|
31
|
+
* handlers run batched and untracked. `ref` is called once with the element. `children` is inserted
|
|
32
|
+
* (a getter keeps it reactive). `class` takes a string; `style` a string or an object.
|
|
33
|
+
* @returns The element on the client; its server markup when rendering on the server.
|
|
34
|
+
* @throws TypeError `SHADOW_ELEMENT_TAG` when `tag` is not an allowed tag name.
|
|
35
|
+
* @example
|
|
36
|
+
* import { useSignal } from "@shadow-js/core";
|
|
37
|
+
* import { element } from "@shadow-js/web";
|
|
38
|
+
*
|
|
39
|
+
* function HomeLink() {
|
|
40
|
+
* const [active] = useSignal(true);
|
|
41
|
+
* return element("a", {
|
|
42
|
+
* href: "/",
|
|
43
|
+
* get "aria-current"() { return active() ? "page" : undefined; },
|
|
44
|
+
* onClick: (event: MouseEvent) => console.log(event.type),
|
|
45
|
+
* children: "Home",
|
|
46
|
+
* });
|
|
47
|
+
* }
|
|
48
|
+
* @see spread
|
|
49
|
+
* @since 1.0.0
|
|
50
|
+
*/
|
|
51
|
+
function element(tag, props) {
|
|
52
|
+
if (!TAG_PATTERN.test(tag) || tag.toLowerCase() === "script") throw new TypeError("ShadowJS element: invalid tag");
|
|
53
|
+
const read = props;
|
|
54
|
+
return ssrElement(tag, props, () => {
|
|
55
|
+
const children = read["children"];
|
|
56
|
+
return children === void 0 ? void 0 : [
|
|
57
|
+
ssrRaw("<!--[-->"),
|
|
58
|
+
children,
|
|
59
|
+
ssrRaw("<!--]-->")
|
|
60
|
+
];
|
|
61
|
+
}, true);
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { element };
|
|
65
|
+
|
|
66
|
+
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEpB,SAAgB,QAAQ,KAAa,OAAwB;CAC3D,IAAI,CAAC,YAAY,KAAK,GAAG,KAAK,IAAI,YAAY,MAAM,UAClD,MAAM,IAAI,UAAoB,+BAAsD;CAEtF,MAAM,OAAO;CAGX,OAAO,WACL,KACA,aACM;EACJ,MAAM,WAAW,KAAK;EACtB,OAAO,aAAa,KAAA,IAChB,KAAA,IACA;GAAC,OAAO,UAAU;GAAG;GAAU,OAAO,UAAU;EAAC;CACvD,GACA,IACF;AAgCJ"}
|