@shadow-js/web 0.0.0-stage → 1.0.1
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 +18 -0
- package/LICENSE +21 -0
- package/README.md +190 -2
- package/dist/dev/attributes.d.ts +88 -0
- package/dist/dev/attributes.js +195 -0
- package/dist/dev/attributes.js.map +1 -0
- package/dist/dev/autofocus.d.ts +30 -0
- package/dist/dev/autofocus.js +44 -0
- package/dist/dev/autofocus.js.map +1 -0
- package/dist/dev/class-style.d.ts +87 -0
- package/dist/dev/class-style.js +196 -0
- package/dist/dev/class-style.js.map +1 -0
- package/dist/dev/component.d.ts +21 -0
- package/dist/dev/component.js +41 -0
- package/dist/dev/component.js.map +1 -0
- package/dist/dev/control-flow/activity.d.ts +56 -0
- package/dist/dev/control-flow/activity.js +135 -0
- package/dist/dev/control-flow/activity.js.map +1 -0
- package/dist/dev/control-flow/branch.js +103 -0
- package/dist/dev/control-flow/branch.js.map +1 -0
- package/dist/dev/control-flow/client-only.d.ts +46 -0
- package/dist/dev/control-flow/client-only.js +49 -0
- package/dist/dev/control-flow/client-only.js.map +1 -0
- package/dist/dev/control-flow/dynamic.d.ts +80 -0
- package/dist/dev/control-flow/dynamic.js +133 -0
- package/dist/dev/control-flow/dynamic.js.map +1 -0
- package/dist/dev/control-flow/error-boundary.d.ts +70 -0
- package/dist/dev/control-flow/error-boundary.js +114 -0
- package/dist/dev/control-flow/error-boundary.js.map +1 -0
- package/dist/dev/control-flow/for.d.ts +78 -0
- package/dist/dev/control-flow/for.js +22 -0
- package/dist/dev/control-flow/for.js.map +1 -0
- package/dist/dev/control-flow/fragment.d.ts +36 -0
- package/dist/dev/control-flow/fragment.js +30 -0
- package/dist/dev/control-flow/fragment.js.map +1 -0
- package/dist/dev/control-flow/hot-link.js +63 -0
- package/dist/dev/control-flow/hot-link.js.map +1 -0
- package/dist/dev/control-flow/index-list.d.ts +46 -0
- package/dist/dev/control-flow/index-list.js +30 -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 +56 -0
- package/dist/dev/control-flow/lazy.js +63 -0
- package/dist/dev/control-flow/lazy.js.map +1 -0
- package/dist/dev/control-flow/no-hydration.d.ts +37 -0
- package/dist/dev/control-flow/no-hydration.js +57 -0
- package/dist/dev/control-flow/no-hydration.js.map +1 -0
- package/dist/dev/control-flow/portal.d.ts +67 -0
- package/dist/dev/control-flow/portal.js +133 -0
- package/dist/dev/control-flow/portal.js.map +1 -0
- package/dist/dev/control-flow/root-errors.d.ts +23 -0
- package/dist/dev/control-flow/root-errors.js +32 -0
- package/dist/dev/control-flow/root-errors.js.map +1 -0
- package/dist/dev/control-flow/show.d.ts +99 -0
- package/dist/dev/control-flow/show.js +17 -0
- package/dist/dev/control-flow/show.js.map +1 -0
- package/dist/dev/control-flow/suspense-list.d.ts +63 -0
- package/dist/dev/control-flow/suspense-list.js +104 -0
- package/dist/dev/control-flow/suspense-list.js.map +1 -0
- package/dist/dev/control-flow/suspense.d.ts +51 -0
- package/dist/dev/control-flow/suspense.js +101 -0
- package/dist/dev/control-flow/suspense.js.map +1 -0
- package/dist/dev/control-flow/switch.d.ts +83 -0
- package/dist/dev/control-flow/switch.js +89 -0
- package/dist/dev/control-flow/switch.js.map +1 -0
- package/dist/dev/derived.d.ts +50 -0
- package/dist/dev/derived.js +33 -0
- package/dist/dev/derived.js.map +1 -0
- package/dist/dev/element.d.ts +38 -0
- package/dist/dev/element.js +104 -0
- package/dist/dev/element.js.map +1 -0
- package/dist/dev/events.d.ts +85 -0
- package/dist/dev/events.js +264 -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 +135 -0
- package/dist/dev/head/components.js +169 -0
- package/dist/dev/head/components.js.map +1 -0
- package/dist/dev/head/registry.js +67 -0
- package/dist/dev/head/registry.js.map +1 -0
- package/dist/dev/head/server-head.d.ts +52 -0
- package/dist/dev/head/server-head.js +75 -0
- package/dist/dev/head/server-head.js.map +1 -0
- package/dist/dev/head/sink.js +95 -0
- package/dist/dev/head/sink.js.map +1 -0
- package/dist/dev/head/use-head.d.ts +33 -0
- package/dist/dev/head/use-head.js +83 -0
- package/dist/dev/head/use-head.js.map +1 -0
- package/dist/dev/head/validate.d.ts +83 -0
- package/dist/dev/head/validate.js +267 -0
- package/dist/dev/head/validate.js.map +1 -0
- package/dist/dev/hmr.d.ts +80 -0
- package/dist/dev/hmr.js +123 -0
- package/dist/dev/hmr.js.map +1 -0
- package/dist/dev/hydration.d.ts +59 -0
- package/dist/dev/hydration.js +119 -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 +95 -0
- package/dist/dev/insert.js +356 -0
- package/dist/dev/insert.js.map +1 -0
- package/dist/dev/internal/claim.d.ts +104 -0
- package/dist/dev/internal/claim.js +356 -0
- package/dist/dev/internal/claim.js.map +1 -0
- package/dist/dev/internal/css-units.js +25 -0
- package/dist/dev/internal/css-units.js.map +1 -0
- package/dist/dev/internal/diagnostics.d.ts +28 -0
- package/dist/dev/internal/diagnostics.js +37 -0
- package/dist/dev/internal/diagnostics.js.map +1 -0
- package/dist/dev/internal/early-events.js +75 -0
- package/dist/dev/internal/early-events.js.map +1 -0
- package/dist/dev/internal/hydration-hooks.d.ts +41 -0
- package/dist/dev/internal/hydration-hooks.js +26 -0
- package/dist/dev/internal/hydration-hooks.js.map +1 -0
- package/dist/dev/internal/hydration-scope.d.ts +129 -0
- package/dist/dev/internal/hydration-scope.js +155 -0
- package/dist/dev/internal/hydration-scope.js.map +1 -0
- package/dist/dev/internal/names.d.ts +31 -0
- package/dist/dev/internal/names.js +34 -0
- package/dist/dev/internal/names.js.map +1 -0
- package/dist/dev/internal/portal-context.d.ts +37 -0
- package/dist/dev/internal/portal-context.js +27 -0
- package/dist/dev/internal/portal-context.js.map +1 -0
- package/dist/dev/internal/react-names.js +115 -0
- package/dist/dev/internal/react-names.js.map +1 -0
- package/dist/dev/internal/reconcile.d.ts +38 -0
- package/dist/dev/internal/reconcile.js +121 -0
- package/dist/dev/internal/reconcile.js.map +1 -0
- package/dist/dev/internal/stream-context.d.ts +45 -0
- package/dist/dev/internal/stream-context.js +22 -0
- package/dist/dev/internal/stream-context.js.map +1 -0
- package/dist/dev/jsx/aria.d.ts +70 -0
- package/dist/dev/jsx/component.d.ts +87 -0
- package/dist/dev/jsx/events.d.ts +362 -0
- package/dist/dev/jsx/global.d.ts +209 -0
- package/dist/dev/jsx/html.d.ts +877 -0
- package/dist/dev/jsx/intrinsic.d.ts +57 -0
- package/dist/dev/jsx/mathml.d.ts +184 -0
- package/dist/dev/jsx/svg.d.ts +605 -0
- package/dist/dev/jsx/types.d.ts +174 -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 +92 -0
- package/dist/dev/jsx-runtime.js +0 -0
- package/dist/dev/reactive.d.ts +108 -0
- package/dist/dev/reactive.js +84 -0
- package/dist/dev/reactive.js.map +1 -0
- package/dist/dev/render.d.ts +34 -0
- package/dist/dev/render.js +51 -0
- package/dist/dev/render.js.map +1 -0
- package/dist/dev/resource-hints.d.ts +143 -0
- package/dist/dev/resource-hints.js +199 -0
- package/dist/dev/resource-hints.js.map +1 -0
- package/dist/dev/select-value.d.ts +22 -0
- package/dist/dev/select-value.js +50 -0
- package/dist/dev/select-value.js.map +1 -0
- package/dist/dev/server/attributes.d.ts +31 -0
- package/dist/dev/server/attributes.js +154 -0
- package/dist/dev/server/attributes.js.map +1 -0
- package/dist/dev/server/class-style.d.ts +44 -0
- package/dist/dev/server/class-style.js +172 -0
- package/dist/dev/server/class-style.js.map +1 -0
- package/dist/dev/server/component.d.ts +40 -0
- package/dist/dev/server/component.js +71 -0
- package/dist/dev/server/component.js.map +1 -0
- package/dist/dev/server/derived.d.ts +39 -0
- package/dist/dev/server/derived.js +25 -0
- package/dist/dev/server/derived.js.map +1 -0
- package/dist/dev/server/element.d.ts +87 -0
- package/dist/dev/server/element.js +215 -0
- package/dist/dev/server/element.js.map +1 -0
- package/dist/dev/server/errors.js +25 -0
- package/dist/dev/server/errors.js.map +1 -0
- package/dist/dev/server/escape.d.ts +28 -0
- package/dist/dev/server/escape.js +118 -0
- package/dist/dev/server/escape.js.map +1 -0
- package/dist/dev/server/form-controls.d.ts +48 -0
- package/dist/dev/server/form-controls.js +192 -0
- package/dist/dev/server/form-controls.js.map +1 -0
- package/dist/dev/server/hydration-script.d.ts +63 -0
- package/dist/dev/server/hydration-script.js +58 -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 +11 -0
- package/dist/dev/server/node.js +20 -0
- package/dist/dev/server/node.js.map +1 -0
- package/dist/dev/server/portals.d.ts +44 -0
- package/dist/dev/server/portals.js +98 -0
- package/dist/dev/server/portals.js.map +1 -0
- package/dist/dev/server/render.d.ts +127 -0
- package/dist/dev/server/render.js +255 -0
- package/dist/dev/server/render.js.map +1 -0
- package/dist/dev/server/serialize.d.ts +43 -0
- package/dist/dev/server/serialize.js +314 -0
- package/dist/dev/server/serialize.js.map +1 -0
- package/dist/dev/server/stream.d.ts +92 -0
- package/dist/dev/server/stream.js +234 -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 +47 -0
- package/dist/dev/spread.js +295 -0
- package/dist/dev/spread.js.map +1 -0
- package/dist/dev/template.d.ts +24 -0
- package/dist/dev/template.js +119 -0
- package/dist/dev/template.js.map +1 -0
- package/dist/dev/view-transition.d.ts +95 -0
- package/dist/dev/view-transition.js +120 -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 +195 -0
- package/dist/server-dev/attributes.js.map +1 -0
- package/dist/server-dev/autofocus.js +44 -0
- package/dist/server-dev/autofocus.js.map +1 -0
- package/dist/server-dev/class-style.js +196 -0
- package/dist/server-dev/class-style.js.map +1 -0
- package/dist/server-dev/component.js +41 -0
- package/dist/server-dev/component.js.map +1 -0
- package/dist/server-dev/control-flow/activity.js +40 -0
- package/dist/server-dev/control-flow/activity.js.map +1 -0
- package/dist/server-dev/control-flow/branch.js +103 -0
- package/dist/server-dev/control-flow/branch.js.map +1 -0
- package/dist/server-dev/control-flow/client-only.js +49 -0
- package/dist/server-dev/control-flow/client-only.js.map +1 -0
- package/dist/server-dev/control-flow/dynamic.js +105 -0
- package/dist/server-dev/control-flow/dynamic.js.map +1 -0
- package/dist/server-dev/control-flow/error-boundary.js +114 -0
- package/dist/server-dev/control-flow/error-boundary.js.map +1 -0
- package/dist/server-dev/control-flow/for.js +22 -0
- package/dist/server-dev/control-flow/for.js.map +1 -0
- package/dist/server-dev/control-flow/fragment.js +30 -0
- package/dist/server-dev/control-flow/fragment.js.map +1 -0
- package/dist/server-dev/control-flow/hot-link.js +56 -0
- package/dist/server-dev/control-flow/hot-link.js.map +1 -0
- package/dist/server-dev/control-flow/index-list.js +30 -0
- package/dist/server-dev/control-flow/index-list.js.map +1 -0
- package/dist/server-dev/control-flow/lazy.js +63 -0
- package/dist/server-dev/control-flow/lazy.js.map +1 -0
- package/dist/server-dev/control-flow/no-hydration.js +39 -0
- package/dist/server-dev/control-flow/no-hydration.js.map +1 -0
- package/dist/server-dev/control-flow/portal.js +133 -0
- package/dist/server-dev/control-flow/portal.js.map +1 -0
- package/dist/server-dev/control-flow/root-errors.js +32 -0
- package/dist/server-dev/control-flow/root-errors.js.map +1 -0
- package/dist/server-dev/control-flow/show.js +17 -0
- package/dist/server-dev/control-flow/show.js.map +1 -0
- package/dist/server-dev/control-flow/suspense-list.js +99 -0
- package/dist/server-dev/control-flow/suspense-list.js.map +1 -0
- package/dist/server-dev/control-flow/suspense.js +118 -0
- package/dist/server-dev/control-flow/suspense.js.map +1 -0
- package/dist/server-dev/control-flow/switch.js +89 -0
- package/dist/server-dev/control-flow/switch.js.map +1 -0
- package/dist/server-dev/derived.js +33 -0
- package/dist/server-dev/derived.js.map +1 -0
- package/dist/server-dev/element.js +65 -0
- package/dist/server-dev/element.js.map +1 -0
- package/dist/server-dev/events.js +264 -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 +169 -0
- package/dist/server-dev/head/components.js.map +1 -0
- package/dist/server-dev/head/registry.js +67 -0
- package/dist/server-dev/head/registry.js.map +1 -0
- package/dist/server-dev/head/server-head.js +75 -0
- package/dist/server-dev/head/server-head.js.map +1 -0
- package/dist/server-dev/head/sink.js +95 -0
- package/dist/server-dev/head/sink.js.map +1 -0
- package/dist/server-dev/head/use-head.js +83 -0
- package/dist/server-dev/head/use-head.js.map +1 -0
- package/dist/server-dev/head/validate.js +267 -0
- package/dist/server-dev/head/validate.js.map +1 -0
- package/dist/server-dev/hydration.js +119 -0
- package/dist/server-dev/hydration.js.map +1 -0
- package/dist/server-dev/index.js +34 -0
- package/dist/server-dev/insert.js +356 -0
- package/dist/server-dev/insert.js.map +1 -0
- package/dist/server-dev/internal/claim.js +356 -0
- package/dist/server-dev/internal/claim.js.map +1 -0
- package/dist/server-dev/internal/css-units.js +25 -0
- package/dist/server-dev/internal/css-units.js.map +1 -0
- package/dist/server-dev/internal/diagnostics.js +37 -0
- package/dist/server-dev/internal/diagnostics.js.map +1 -0
- package/dist/server-dev/internal/early-events.js +75 -0
- package/dist/server-dev/internal/early-events.js.map +1 -0
- package/dist/server-dev/internal/hydration-hooks.js +26 -0
- package/dist/server-dev/internal/hydration-hooks.js.map +1 -0
- package/dist/server-dev/internal/hydration-scope.js +155 -0
- package/dist/server-dev/internal/hydration-scope.js.map +1 -0
- package/dist/server-dev/internal/names.js +34 -0
- package/dist/server-dev/internal/names.js.map +1 -0
- package/dist/server-dev/internal/portal-context.js +27 -0
- package/dist/server-dev/internal/portal-context.js.map +1 -0
- package/dist/server-dev/internal/react-names.js +115 -0
- package/dist/server-dev/internal/react-names.js.map +1 -0
- package/dist/server-dev/internal/reconcile.js +121 -0
- package/dist/server-dev/internal/reconcile.js.map +1 -0
- package/dist/server-dev/internal/stream-context.js +22 -0
- package/dist/server-dev/internal/stream-context.js.map +1 -0
- package/dist/server-dev/reactive.js +84 -0
- package/dist/server-dev/reactive.js.map +1 -0
- package/dist/server-dev/render.js +51 -0
- package/dist/server-dev/render.js.map +1 -0
- package/dist/server-dev/resource-hints.js +199 -0
- package/dist/server-dev/resource-hints.js.map +1 -0
- package/dist/server-dev/select-value.js +50 -0
- package/dist/server-dev/select-value.js.map +1 -0
- package/dist/server-dev/server/attributes.js +154 -0
- package/dist/server-dev/server/attributes.js.map +1 -0
- package/dist/server-dev/server/class-style.js +172 -0
- package/dist/server-dev/server/class-style.js.map +1 -0
- package/dist/server-dev/server/component.js +71 -0
- package/dist/server-dev/server/component.js.map +1 -0
- package/dist/server-dev/server/derived.js +25 -0
- package/dist/server-dev/server/derived.js.map +1 -0
- package/dist/server-dev/server/element.js +215 -0
- package/dist/server-dev/server/element.js.map +1 -0
- package/dist/server-dev/server/errors.js +25 -0
- package/dist/server-dev/server/errors.js.map +1 -0
- package/dist/server-dev/server/escape.js +118 -0
- package/dist/server-dev/server/escape.js.map +1 -0
- package/dist/server-dev/server/form-controls.js +192 -0
- package/dist/server-dev/server/form-controls.js.map +1 -0
- package/dist/server-dev/server/hydration-script.js +58 -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 +20 -0
- package/dist/server-dev/server/node.js.map +1 -0
- package/dist/server-dev/server/portals.js +98 -0
- package/dist/server-dev/server/portals.js.map +1 -0
- package/dist/server-dev/server/render.js +255 -0
- package/dist/server-dev/server/render.js.map +1 -0
- package/dist/server-dev/server/serialize.js +314 -0
- package/dist/server-dev/server/serialize.js.map +1 -0
- package/dist/server-dev/server/stream.js +234 -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 +295 -0
- package/dist/server-dev/spread.js.map +1 -0
- package/dist/server-dev/template.js +119 -0
- package/dist/server-dev/template.js.map +1 -0
- package/dist/server-dev/view-transition.js +89 -0
- package/dist/server-dev/view-transition.js.map +1 -0
- package/package.json +136 -4
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { currentScope, withScope } from "../internal/hydration-scope.js";
|
|
2
|
+
import { attachHotModules, createHotLink } from "./hot-link.js";
|
|
3
|
+
import { rootErrorsOf } from "./root-errors.js";
|
|
4
|
+
import { catchError, createRoot, getOwner, onCleanup, untrack, useMemo, useSignal } from "@shadow-js/core";
|
|
5
|
+
import { createSignalNode, handleError, readSignal, writeSignal } from "@shadow-js/core/extend";
|
|
6
|
+
// src/control-flow/error-boundary.ts
|
|
7
|
+
function ErrorBoundary(props) {
|
|
8
|
+
const failureCell = createSignalNode(void 0, Object.is);
|
|
9
|
+
/** Where an error of this boundary's own fallback goes: the boundary that encloses it. */
|
|
10
|
+
const parentOwner = getOwner();
|
|
11
|
+
const roots = rootErrorsOf(parentOwner);
|
|
12
|
+
/** The hydration scope at creation (a copy of its counts), or null outside a hydration or server render. */
|
|
13
|
+
const live = currentScope();
|
|
14
|
+
const origin = live === null ? null : {
|
|
15
|
+
id: live.id,
|
|
16
|
+
count: live.count,
|
|
17
|
+
resources: live.resources
|
|
18
|
+
};
|
|
19
|
+
const failure = () => readSignal(failureCell);
|
|
20
|
+
const setFailure = (next) => {
|
|
21
|
+
writeSignal(failureCell, next, { allowInMemo: true });
|
|
22
|
+
};
|
|
23
|
+
/** Bumped by reset(): forces a rebuild even when no failure was recorded. */
|
|
24
|
+
const [version, setVersion] = useSignal(0, { equals: false });
|
|
25
|
+
/** False once the boundary's owner is disposed. */
|
|
26
|
+
let alive = true;
|
|
27
|
+
/** True while the body memo is building or tearing down children; errors are captured then. */
|
|
28
|
+
let busy = false;
|
|
29
|
+
/** An error captured while busy, consumed by the next body computation. */
|
|
30
|
+
let pending;
|
|
31
|
+
const reset = () => {
|
|
32
|
+
if (!alive) return;
|
|
33
|
+
setFailure(void 0);
|
|
34
|
+
setVersion((count) => count + 1);
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Dev only: the modules the children were built from. While the fallback is shown, a hot update of one of
|
|
38
|
+
* them resets the boundary, so the edit that fixes the error shows the children without a retry.
|
|
39
|
+
*/
|
|
40
|
+
const hot = createHotLink(() => {
|
|
41
|
+
reset();
|
|
42
|
+
});
|
|
43
|
+
const report = (error) => {
|
|
44
|
+
if (!alive) return;
|
|
45
|
+
roots?.onCaughtError?.(error);
|
|
46
|
+
if (busy) {
|
|
47
|
+
if (pending === void 0) pending = { error };
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
setFailure({ error });
|
|
51
|
+
};
|
|
52
|
+
/** Returns the captured error and clears it. A function, so TypeScript does not narrow the variable. */
|
|
53
|
+
const takePending = () => {
|
|
54
|
+
const captured = pending;
|
|
55
|
+
pending = void 0;
|
|
56
|
+
return captured;
|
|
57
|
+
};
|
|
58
|
+
const fallbackFor = (error) => {
|
|
59
|
+
const fallback = props.fallback;
|
|
60
|
+
if (typeof fallback !== "function") return fallback;
|
|
61
|
+
try {
|
|
62
|
+
return untrack(() => fallback(error, reset));
|
|
63
|
+
} catch (thrown) {
|
|
64
|
+
handleError(thrown, parentOwner);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
/** Builds the children or the fallback, as the current failure state says. */
|
|
69
|
+
const build = () => {
|
|
70
|
+
busy = true;
|
|
71
|
+
try {
|
|
72
|
+
version();
|
|
73
|
+
const current = failure() ?? takePending();
|
|
74
|
+
if (current !== void 0) {
|
|
75
|
+
hot?.arm();
|
|
76
|
+
return fallbackFor(current.error);
|
|
77
|
+
}
|
|
78
|
+
hot?.modules.clear();
|
|
79
|
+
const scope = createRoot((dispose) => {
|
|
80
|
+
if (hot !== void 0) attachHotModules(hot.modules);
|
|
81
|
+
return {
|
|
82
|
+
dispose,
|
|
83
|
+
value: catchError(() => untrack(() => props.children), report)
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
const creation = takePending();
|
|
87
|
+
if (creation !== void 0) {
|
|
88
|
+
scope.dispose();
|
|
89
|
+
hot?.arm();
|
|
90
|
+
return fallbackFor(creation.error);
|
|
91
|
+
}
|
|
92
|
+
hot?.disarm();
|
|
93
|
+
return scope.value;
|
|
94
|
+
} finally {
|
|
95
|
+
createRoot(() => {
|
|
96
|
+
onCleanup(() => {
|
|
97
|
+
busy = true;
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
busy = false;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const body = useMemo(() => origin === null ? build() : withScope({ ...origin }, build), { allowWrites: true });
|
|
104
|
+
createRoot(() => {
|
|
105
|
+
onCleanup(() => {
|
|
106
|
+
alive = false;
|
|
107
|
+
hot?.disarm();
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
return body;
|
|
111
|
+
}
|
|
112
|
+
export { ErrorBoundary };
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=error-boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-boundary.js","names":[],"sources":["../../../src/control-flow/error-boundary.ts"],"sourcesContent":["import {\n type Accessor,\n catchError,\n createRoot,\n getOwner,\n onCleanup,\n untrack,\n useMemo,\n useSignal,\n} from \"@shadow-js/core\";\nimport { createSignalNode, handleError, readSignal, writeSignal } from \"@shadow-js/core/extend\";\nimport { currentScope, type HydrationScope, withScope } from \"../extend\";\nimport type { JsxChild } from \"../jsx/types\";\nimport { attachHotModules, createHotLink, type HotLink } from \"./hot-link\";\nimport { rootErrorsOf } from \"./root-errors\";\n\n/**\n * Props of {@link ErrorBoundary}.\n * @since 1.0.0\n */\nexport interface ErrorBoundaryProps {\n /**\n * Shown after an error. A function is called untracked as `(error, reset)`; any other value is\n * shown as is.\n */\n readonly fallback: JsxChild | ((error: unknown, reset: () => void) => unknown);\n /**\n * The protected content, read untracked when the children are built.\n * @default undefined (nothing is protected; the boundary renders nothing)\n */\n readonly children?: JsxChild | (() => unknown);\n}\n\n/**\n * {@link ErrorBoundaryProps} with untyped members, for code that forwards a fallback or children it\n * does not know the shape of.\n * @since 1.0.0\n */\nexport interface ErrorBoundaryLooseProps {\n /** Shown after an error; the same contract as {@link ErrorBoundaryProps.fallback}. */\n readonly fallback: unknown;\n /**\n * The protected content; the same contract as {@link ErrorBoundaryProps.children}.\n * @default undefined (nothing is protected; the boundary renders nothing)\n */\n readonly children?: unknown;\n}\n\n/** A caught error, wrapped so that any thrown value (including `undefined`) is representable. */\ninterface Failure {\n readonly error: unknown;\n}\n\n/**\n * Renders `children`. If they throw while being created, or any effect, memo or cleanup inside\n * them throws later, the children are disposed and `fallback` is rendered instead. A function\n * fallback receives the error and a `reset` that rebuilds the children from scratch.\n *\n * Errors raised while the boundary is building or tearing down its children are captured and\n * never write a signal, because writing inside a memo is an error. Late errors write the failure\n * signal, which re-runs the boundary. After the boundary is disposed, late errors are dropped.\n * Errors thrown by the fallback are not caught by this boundary; they reach the parent.\n *\n * @param props See {@link ErrorBoundaryProps}.\n * @returns An accessor of the current content (children or fallback).\n * @throws Nothing itself. An error from the children is shown through `fallback`, and an error\n * thrown by a function `fallback` goes to the enclosing boundary or the root's error handler.\n * @example\n * import { ErrorBoundary } from \"@shadow-js/web\";\n *\n * function Dashboard() {\n * return <p>Dashboard</p>;\n * }\n *\n * function Page() {\n * return (\n * <ErrorBoundary\n * fallback={(error, reset) => (\n * <button onClick={reset}>Retry after: {String(error)}</button>\n * )}\n * >\n * <Dashboard />\n * </ErrorBoundary>\n * );\n * }\n * @see Suspense\n * @since 1.0.0\n */\nexport function ErrorBoundary(props: ErrorBoundaryProps): Accessor<unknown>;\nexport function ErrorBoundary(props: ErrorBoundaryLooseProps): Accessor<unknown>;\nexport function ErrorBoundary(props: ErrorBoundaryLooseProps): Accessor<unknown> {\n // An extension-API cell: a failure is boundary state, written from places a plain write refuses\n // (a sibling boundary's fallback throwing while its memo computes).\n const failureCell = createSignalNode<Failure | undefined>(undefined, Object.is);\n /** Where an error of this boundary's own fallback goes: the boundary that encloses it. */\n const parentOwner = getOwner();\n // The root's reporters (render/hydrate options): an error this boundary takes is reported to them.\n const roots = rootErrorsOf(parentOwner);\n /** The hydration scope at creation (a copy of its counts), or null outside a hydration or server render. */\n const live = currentScope();\n const origin: HydrationScope | null =\n live === null ? null : { id: live.id, count: live.count, resources: live.resources };\n const failure = (): Failure | undefined => readSignal(failureCell);\n const setFailure = (next: Failure | undefined): void => {\n writeSignal(failureCell, next, { allowInMemo: true });\n };\n /** Bumped by reset(): forces a rebuild even when no failure was recorded. */\n const [version, setVersion] = useSignal(0, { equals: false });\n /** False once the boundary's owner is disposed. */\n let alive = true;\n /** True while the body memo is building or tearing down children; errors are captured then. */\n let busy = false;\n /** An error captured while busy, consumed by the next body computation. */\n let pending: Failure | undefined;\n\n const reset = (): void => {\n if (!alive) return;\n setFailure(undefined);\n setVersion((count) => count + 1);\n };\n\n /**\n * Dev only: the modules the children were built from. While the fallback is shown, a hot update of one of\n * them resets the boundary, so the edit that fixes the error shows the children without a retry.\n */\n const hot: HotLink | undefined = __DEV__\n ? createHotLink(() => {\n reset();\n })\n : undefined;\n\n const report = (error: unknown): void => {\n if (!alive) return;\n roots?.onCaughtError?.(error);\n if (busy) {\n if (pending === undefined) pending = { error };\n return;\n }\n setFailure({ error });\n };\n\n /** Returns the captured error and clears it. A function, so TypeScript does not narrow the variable. */\n const takePending = (): Failure | undefined => {\n const captured = pending;\n pending = undefined;\n return captured;\n };\n\n const fallbackFor = (error: unknown): unknown => {\n const fallback = props.fallback;\n if (typeof fallback !== \"function\") return fallback;\n try {\n return untrack(() =>\n (fallback as (error: unknown, reset: () => void) => unknown)(error, reset),\n );\n } catch (thrown) {\n // A failing fallback is not this boundary's business: hand it to the enclosing boundary now.\n // Left to the memo it would only surface when a consumer outside that boundary reads it.\n handleError(thrown, parentOwner);\n return undefined;\n }\n };\n\n /** Builds the children or the fallback, as the current failure state says. */\n const build = (): unknown => {\n busy = true;\n try {\n version();\n const current = failure() ?? takePending();\n if (current !== undefined) {\n hot?.arm();\n return fallbackFor(current.error);\n }\n\n hot?.modules.clear();\n const scope = createRoot((dispose) => {\n if (hot !== undefined) attachHotModules(hot.modules);\n return {\n dispose,\n value: catchError(() => untrack(() => props.children), report),\n };\n });\n const creation = takePending();\n if (creation !== undefined) {\n scope.dispose();\n hot?.arm();\n return fallbackFor(creation.error);\n }\n hot?.disarm();\n return scope.value;\n } finally {\n // Newest child of the body memo: its cleanup marks the teardown before any child cleanup runs.\n createRoot(() => {\n onCleanup(() => {\n busy = true;\n });\n });\n busy = false;\n }\n // Children and the fallback are built here; their setup may write signals.\n };\n // Every build starts from the hydration scope the boundary was created in (a copy, so the count\n // is the same each time). A rebuild during a hydration pass then numbers its templates as the\n // first build did, so it claims the server's elements instead of missing keys.\n const body = useMemo<unknown>(\n () => (origin === null ? build() : withScope({ ...origin }, build)),\n { allowWrites: true },\n );\n\n // Created after the body memo, so it is the newest child of the owner and is disposed first.\n createRoot(() => {\n onCleanup(() => {\n alive = false;\n hot?.disarm();\n });\n });\n return body;\n}\n"],"mappings":";;;;;;AA0FA,SAAgB,cAAc,OAAmD;CAG/E,MAAM,cAAc,iBAAsC,KAAA,GAAW,OAAO,EAAE;;CAE9E,MAAM,cAAc,SAAS;CAE7B,MAAM,QAAQ,aAAa,WAAW;;CAEtC,MAAM,OAAO,aAAa;CAC1B,MAAM,SACJ,SAAS,OAAO,OAAO;EAAE,IAAI,KAAK;EAAI,OAAO,KAAK;EAAO,WAAW,KAAK;CAAU;CACrF,MAAM,gBAAqC,WAAW,WAAW;CACjE,MAAM,cAAc,SAAoC;EACtD,YAAY,aAAa,MAAM,EAAE,aAAa,KAAK,CAAC;CACtD;;CAEA,MAAM,CAAC,SAAS,cAAc,UAAU,GAAG,EAAE,QAAQ,MAAM,CAAC;;CAE5D,IAAI,QAAQ;;CAEZ,IAAI,OAAO;;CAEX,IAAI;CAEJ,MAAM,cAAoB;EACxB,IAAI,CAAC,OAAO;EACZ,WAAW,KAAA,CAAS;EACpB,YAAY,UAAU,QAAQ,CAAC;CACjC;;;;;CAMA,MAAM,MACF,oBAAoB;EAClB,MAAM;CACR,CAAC;CAGL,MAAM,UAAU,UAAyB;EACvC,IAAI,CAAC,OAAO;EACZ,OAAO,gBAAgB,KAAK;EAC5B,IAAI,MAAM;GACR,IAAI,YAAY,KAAA,GAAW,UAAU,EAAE,MAAM;GAC7C;EACF;EACA,WAAW,EAAE,MAAM,CAAC;CACtB;;CAGA,MAAM,oBAAyC;EAC7C,MAAM,WAAW;EACjB,UAAU,KAAA;EACV,OAAO;CACT;CAEA,MAAM,eAAe,UAA4B;EAC/C,MAAM,WAAW,MAAM;EACvB,IAAI,OAAO,aAAa,YAAY,OAAO;EAC3C,IAAI;GACF,OAAO,cACJ,SAA4D,OAAO,KAAK,CAC3E;EACF,SAAS,QAAQ;GAGf,YAAY,QAAQ,WAAW;GAC/B;EACF;CACF;;CAGA,MAAM,cAAuB;EAC3B,OAAO;EACP,IAAI;GACF,QAAQ;GACR,MAAM,UAAU,QAAQ,KAAK,YAAY;GACzC,IAAI,YAAY,KAAA,GAAW;IACzB,KAAK,IAAI;IACT,OAAO,YAAY,QAAQ,KAAK;GAClC;GAEA,KAAK,QAAQ,MAAM;GACnB,MAAM,QAAQ,YAAY,YAAY;IACpC,IAAI,QAAQ,KAAA,GAAW,iBAAiB,IAAI,OAAO;IACnD,OAAO;KACL;KACA,OAAO,iBAAiB,cAAc,MAAM,QAAQ,GAAG,MAAM;IAC/D;GACF,CAAC;GACD,MAAM,WAAW,YAAY;GAC7B,IAAI,aAAa,KAAA,GAAW;IAC1B,MAAM,QAAQ;IACd,KAAK,IAAI;IACT,OAAO,YAAY,SAAS,KAAK;GACnC;GACA,KAAK,OAAO;GACZ,OAAO,MAAM;EACf,UAAU;GAER,iBAAiB;IACf,gBAAgB;KACd,OAAO;IACT,CAAC;GACH,CAAC;GACD,OAAO;EACT;CAEF;CAIA,MAAM,OAAO,cACJ,WAAW,OAAO,MAAM,IAAI,UAAU,EAAE,GAAG,OAAO,GAAG,KAAK,GACjE,EAAE,aAAa,KAAK,CACtB;CAGA,iBAAiB;EACf,gBAAgB;GACd,QAAQ;GACR,KAAK,OAAO;EACd,CAAC;CACH,CAAC;CACD,OAAO;AACT"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { mapArray, untrack } from "@shadow-js/core";
|
|
2
|
+
// src/control-flow/for.ts
|
|
3
|
+
/**
|
|
4
|
+
* Calls the row callback. `props.children` is read untracked, once per row.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
function renderRow(props, item, index) {
|
|
8
|
+
return untrack(() => props.children)(item, index);
|
|
9
|
+
}
|
|
10
|
+
function For(props) {
|
|
11
|
+
const list = () => props.each;
|
|
12
|
+
const fallback = () => props.fallback;
|
|
13
|
+
const keyOf = props.key;
|
|
14
|
+
if (keyOf === void 0) return mapArray(list, (item, index) => renderRow(props, item, index), { fallback });
|
|
15
|
+
return mapArray(list, (item, index) => renderRow(props, item, index), {
|
|
16
|
+
key: keyOf,
|
|
17
|
+
fallback
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export { For };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=for.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"for.js","names":[],"sources":["../../../src/control-flow/for.ts"],"sourcesContent":["import { type Accessor, mapArray, untrack } from \"@shadow-js/core\";\n\n/**\n * Props of {@link For} without `key`: rows are matched by item reference.\n * @since 1.0.0\n */\nexport interface ForUnkeyedProps<T> {\n /**\n * The list to render. `null`, `undefined` and `false` count as an empty list. Read lazily, inside\n * the list memo, so it is tracked.\n */\n readonly each: readonly T[] | null | undefined | false;\n /**\n * Shown while the list is empty. Read lazily.\n * @default undefined (an empty list renders nothing)\n */\n readonly fallback?: unknown;\n /**\n * Absent in this form: rows are matched by item reference. Pass `key` to match by key.\n * No default: omit it for reference matching.\n */\n readonly key?: undefined;\n /** Called once per row, untracked. The callback receives the item value. */\n readonly children: (item: T, index: () => number) => unknown;\n}\n\n/**\n * Props of {@link For} with `key`: rows are matched by `key(item)`.\n * @since 1.0.0\n */\nexport interface ForKeyedProps<T> {\n /**\n * The list to render. `null`, `undefined` and `false` count as an empty list. Read lazily, inside\n * the list memo, so it is tracked.\n */\n readonly each: readonly T[] | null | undefined | false;\n /**\n * Shown while the list is empty. Read lazily.\n * @default undefined (an empty list renders nothing)\n */\n readonly fallback?: unknown;\n /** Identifies each item. A new object under the same key updates the row's `item()`. */\n readonly key: (item: T) => unknown;\n /** Called once per row, untracked. The callback receives an accessor of the item. */\n readonly children: (item: () => T, index: () => number) => unknown;\n}\n\n/**\n * Props of {@link For}.\n * @since 1.0.0\n */\nexport type ForProps<T> = ForUnkeyedProps<T> | ForKeyedProps<T>;\n\n/**\n * Calls the row callback. `props.children` is read untracked, once per row.\n * @internal\n */\nfunction renderRow(props: { readonly children: unknown }, item: unknown, index: () => number) {\n const render = untrack(() => props.children) as (item: unknown, index: () => number) => unknown;\n return render(item, index);\n}\n\n/**\n * Renders one row per item. Rows whose key survives an update keep their DOM and state; only\n * changed items create or dispose rows. The list is read lazily, inside the list memo.\n *\n * Whether rows are keyed is decided when `For` is created: it reads `key` once. When the list\n * is empty and `fallback` is not given, the result is `[undefined]`, which renders nothing.\n *\n * @param props See {@link ForUnkeyedProps} and {@link ForKeyedProps}.\n * @returns An accessor of the row values, in input order.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { For } from \"@shadow-js/web\";\n *\n * function TodoList() {\n * const [todos] = useSignal([{ id: 1, title: \"Write docs\" }]);\n * return (\n * <ul>\n * <For each={todos()} key={(todo) => todo.id} fallback={<li>Nothing to do</li>}>\n * {(todo) => <li>{todo().title}</li>}\n * </For>\n * </ul>\n * );\n * }\n * @see Index\n * @since 1.0.0\n */\nexport function For<T>(props: ForKeyedProps<T>): Accessor<unknown[]>;\nexport function For<T>(props: ForUnkeyedProps<T>): Accessor<unknown[]>;\nexport function For<T>(props: ForProps<T>): Accessor<unknown[]> {\n const list = (): readonly T[] | null | undefined | false => props.each;\n const fallback = (): unknown => props.fallback;\n const keyOf = props.key;\n if (keyOf === undefined) {\n return mapArray(list, (item: T, index: () => number) => renderRow(props, item, index), {\n fallback,\n });\n }\n return mapArray(list, (item: () => T, index: () => number) => renderRow(props, item, index), {\n key: keyOf,\n fallback,\n });\n}\n"],"mappings":";;;;;;AAyDA,SAAS,UAAU,OAAuC,MAAe,OAAqB;CAE5F,OADe,cAAc,MAAM,QACvB,CAAC,CAAC,MAAM,KAAK;AAC3B;AA8BA,SAAgB,IAAO,OAAyC;CAC9D,MAAM,aAAsD,MAAM;CAClE,MAAM,iBAA0B,MAAM;CACtC,MAAM,QAAQ,MAAM;CACpB,IAAI,UAAU,KAAA,GACZ,OAAO,SAAS,OAAO,MAAS,UAAwB,UAAU,OAAO,MAAM,KAAK,GAAG,EACrF,SACF,CAAC;CAEH,OAAO,SAAS,OAAO,MAAe,UAAwB,UAAU,OAAO,MAAM,KAAK,GAAG;EAC3F,KAAK;EACL;CACF,CAAC;AACH"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/control-flow/fragment.ts
|
|
2
|
+
/**
|
|
3
|
+
* A no-op wrapper: returns `props.children` untouched, so the children are created by the caller's
|
|
4
|
+
* getter exactly as if no wrapper existed. Use it to group several children under one element.
|
|
5
|
+
*
|
|
6
|
+
* @param props The children to group.
|
|
7
|
+
* @returns `props.children`, unchanged.
|
|
8
|
+
* @example
|
|
9
|
+
* import { Fragment } from "@shadow-js/web";
|
|
10
|
+
*
|
|
11
|
+
* function Header() {
|
|
12
|
+
* return <h1>Title</h1>;
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* function Page() {
|
|
16
|
+
* return (
|
|
17
|
+
* <Fragment>
|
|
18
|
+
* <Header />
|
|
19
|
+
* <p>Body</p>
|
|
20
|
+
* </Fragment>
|
|
21
|
+
* );
|
|
22
|
+
* }
|
|
23
|
+
* @since 1.0.0
|
|
24
|
+
*/
|
|
25
|
+
function Fragment(props) {
|
|
26
|
+
return props.children;
|
|
27
|
+
}
|
|
28
|
+
export { Fragment };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=fragment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fragment.js","names":[],"sources":["../../../src/control-flow/fragment.ts"],"sourcesContent":["/**\n * Props of {@link Fragment}.\n * @since 1.0.0\n */\nexport interface FragmentProps {\n /**\n * The children to group.\n * @default undefined (the Fragment renders nothing)\n */\n readonly children?: unknown;\n}\n\n/**\n * A no-op wrapper: returns `props.children` untouched, so the children are created by the caller's\n * getter exactly as if no wrapper existed. Use it to group several children under one element.\n *\n * @param props The children to group.\n * @returns `props.children`, unchanged.\n * @example\n * import { Fragment } from \"@shadow-js/web\";\n *\n * function Header() {\n * return <h1>Title</h1>;\n * }\n *\n * function Page() {\n * return (\n * <Fragment>\n * <Header />\n * <p>Body</p>\n * </Fragment>\n * );\n * }\n * @since 1.0.0\n */\nexport function Fragment(props: FragmentProps): unknown {\n return props.children;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,SAAS,OAA+B;CACtD,OAAO,MAAM;AACf"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getOwner } from "@shadow-js/core";
|
|
2
|
+
// src/control-flow/hot-link.ts
|
|
3
|
+
/**
|
|
4
|
+
* The hot-update link between an error boundary and the modules its children were built from. Dev
|
|
5
|
+
* only: the callers reach this code behind `__DEV__`, so production bundles never include it.
|
|
6
|
+
*
|
|
7
|
+
* A boundary that shows its fallback listens to those modules. When one of them is hot-replaced (the
|
|
8
|
+
* edit is usually the fix), the boundary resets and builds its children again, so the user does not
|
|
9
|
+
* have to press retry. The same module set is kept while the children are built: each component instance
|
|
10
|
+
* adds its module to it when it is created (`hotModulesOf` in the proxy of `component()`).
|
|
11
|
+
*/
|
|
12
|
+
/** The key the module set is stored under in the owner context of a boundary's children. */
|
|
13
|
+
const HOT_MODULES = /* @__PURE__ */ Symbol("HotModules");
|
|
14
|
+
/**
|
|
15
|
+
* Makes `modules` the set of the root that is being created (called inside its `createRoot`): every
|
|
16
|
+
* component created below that root adds its module to it.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
function attachHotModules(modules) {
|
|
20
|
+
const root = getOwner();
|
|
21
|
+
if (root === null) return;
|
|
22
|
+
const map = Object.create(root.context);
|
|
23
|
+
map[HOT_MODULES] = modules;
|
|
24
|
+
root.context = map;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates the link of a boundary. `onUpdate` runs after a hot update of a module the boundary listens to,
|
|
28
|
+
* once the update is applied.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
function createHotLink(onUpdate) {
|
|
32
|
+
const modules = /* @__PURE__ */ new Set();
|
|
33
|
+
let armed = [];
|
|
34
|
+
const listener = () => {
|
|
35
|
+
onUpdate();
|
|
36
|
+
};
|
|
37
|
+
const disarm = () => {
|
|
38
|
+
for (const registry of armed) registry.listeners.delete(listener);
|
|
39
|
+
armed = [];
|
|
40
|
+
};
|
|
41
|
+
const arm = () => {
|
|
42
|
+
disarm();
|
|
43
|
+
for (const registry of modules) {
|
|
44
|
+
registry.listeners.add(listener);
|
|
45
|
+
armed.push(registry);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
modules,
|
|
50
|
+
arm,
|
|
51
|
+
disarm
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export { attachHotModules, createHotLink };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=hot-link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hot-link.js","names":[],"sources":["../../../src/control-flow/hot-link.ts"],"sourcesContent":["import { getOwner, type Owner } from \"@shadow-js/core\";\nimport type { ModuleRegistry } from \"../hmr\";\n\n/**\n * The hot-update link between an error boundary and the modules its children were built from. Dev\n * only: the callers reach this code behind `__DEV__`, so production bundles never include it.\n *\n * A boundary that shows its fallback listens to those modules. When one of them is hot-replaced (the\n * edit is usually the fix), the boundary resets and builds its children again, so the user does not\n * have to press retry. The same module set is kept while the children are built: each component instance\n * adds its module to it when it is created (`hotModulesOf` in the proxy of `component()`).\n */\n\n/** The key the module set is stored under in the owner context of a boundary's children. */\nconst HOT_MODULES: symbol = /* @__PURE__ */ Symbol(\"HotModules\");\n\n/**\n * Makes `modules` the set of the root that is being created (called inside its `createRoot`): every\n * component created below that root adds its module to it.\n * @internal\n */\nexport function attachHotModules(modules: Set<ModuleRegistry>): void {\n const root = getOwner();\n if (root === null) return;\n const map = Object.create(root.context) as Record<symbol, unknown>;\n map[HOT_MODULES] = modules;\n root.context = map;\n}\n\n/**\n * The module set of the nearest boundary above `owner`, or undefined when there is none.\n * @internal\n */\nexport function hotModulesOf(owner: Owner | null): Set<ModuleRegistry> | undefined {\n return owner?.context?.[HOT_MODULES] as Set<ModuleRegistry> | undefined;\n}\n\n/**\n * The link of one boundary: the modules its children were last built from, and the listener armed on\n * them while the boundary shows its fallback.\n * @internal\n */\nexport interface HotLink {\n /** The modules of the last children build. Cleared by the boundary before each build. */\n readonly modules: Set<ModuleRegistry>;\n /** Listens to every module in `modules`: a hot update of one of them calls the boundary's `onUpdate`. */\n arm(): void;\n /** Stops listening (the children built, or the boundary was disposed). */\n disarm(): void;\n}\n\n/**\n * Creates the link of a boundary. `onUpdate` runs after a hot update of a module the boundary listens to,\n * once the update is applied.\n * @internal\n */\nexport function createHotLink(onUpdate: () => void): HotLink {\n const modules = new Set<ModuleRegistry>();\n let armed: ModuleRegistry[] = [];\n const listener = (): void => {\n onUpdate();\n };\n const disarm = (): void => {\n for (const registry of armed) registry.listeners.delete(listener);\n armed = [];\n };\n const arm = (): void => {\n disarm();\n for (const registry of modules) {\n registry.listeners.add(listener);\n armed.push(registry);\n }\n };\n return { modules, arm, disarm };\n}\n"],"mappings":";;;;;;;;;;;;AAcA,MAAM,cAAsC,uBAAO,YAAY;;;;;;AAO/D,SAAgB,iBAAiB,SAAoC;CACnE,MAAM,OAAO,SAAS;CACtB,IAAI,SAAS,MAAM;CACnB,MAAM,MAAM,OAAO,OAAO,KAAK,OAAO;CACtC,IAAI,eAAe;CACnB,KAAK,UAAU;AACjB;;;;;;AA6BA,SAAgB,cAAc,UAA+B;CAC3D,MAAM,0BAAU,IAAI,IAAoB;CACxC,IAAI,QAA0B,CAAC;CAC/B,MAAM,iBAAuB;EAC3B,SAAS;CACX;CACA,MAAM,eAAqB;EACzB,KAAK,MAAM,YAAY,OAAO,SAAS,UAAU,OAAO,QAAQ;EAChE,QAAQ,CAAC;CACX;CACA,MAAM,YAAkB;EACtB,OAAO;EACP,KAAK,MAAM,YAAY,SAAS;GAC9B,SAAS,UAAU,IAAI,QAAQ;GAC/B,MAAM,KAAK,QAAQ;EACrB;CACF;CACA,OAAO;EAAE;EAAS;EAAK;CAAO;AAChC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { indexArray, untrack } from "@shadow-js/core";
|
|
2
|
+
// src/control-flow/index-list.ts
|
|
3
|
+
/**
|
|
4
|
+
* Renders one row per position. Rows are created and removed only when the length changes; the
|
|
5
|
+
* row at position `i` stays, and its item accessor follows the value at `i`. Use it for
|
|
6
|
+
* primitive lists where identity does not matter.
|
|
7
|
+
*
|
|
8
|
+
* @param props See {@link IndexProps}.
|
|
9
|
+
* @returns An accessor of the row values, in input order.
|
|
10
|
+
* @example
|
|
11
|
+
* import { useSignal } from "@shadow-js/core";
|
|
12
|
+
* import { Index } from "@shadow-js/web";
|
|
13
|
+
*
|
|
14
|
+
* function Cells() {
|
|
15
|
+
* const [values] = useSignal([10, 20, 30]);
|
|
16
|
+
* return (
|
|
17
|
+
* <ul>
|
|
18
|
+
* <Index each={values()}>{(value, index) => <li>{`${index}: ${value()}`}</li>}</Index>
|
|
19
|
+
* </ul>
|
|
20
|
+
* );
|
|
21
|
+
* }
|
|
22
|
+
* @see For
|
|
23
|
+
* @since 1.0.0
|
|
24
|
+
*/
|
|
25
|
+
function Index(props) {
|
|
26
|
+
return indexArray(() => props.each, (item, index) => untrack(() => props.children)(item, index), { fallback: () => props.fallback });
|
|
27
|
+
}
|
|
28
|
+
export { Index };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=index-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-list.js","names":[],"sources":["../../../src/control-flow/index-list.ts"],"sourcesContent":["import { type Accessor, indexArray, untrack } from \"@shadow-js/core\";\n\n/**\n * Props of {@link Index}.\n * @since 1.0.0\n */\nexport interface IndexProps<T> {\n /**\n * The list to render. `null`, `undefined` and `false` count as an empty list. Read lazily, so it\n * is tracked.\n */\n readonly each: readonly T[] | null | undefined | false;\n /**\n * Shown while the list is empty. Read lazily.\n * @default undefined (an empty list renders nothing)\n */\n readonly fallback?: unknown;\n /**\n * Called once per position, untracked. The item is an accessor that follows the value at this\n * position; the index is a plain number, because a position never changes.\n */\n readonly children: (item: () => T, index: number) => unknown;\n}\n\n/**\n * Renders one row per position. Rows are created and removed only when the length changes; the\n * row at position `i` stays, and its item accessor follows the value at `i`. Use it for\n * primitive lists where identity does not matter.\n *\n * @param props See {@link IndexProps}.\n * @returns An accessor of the row values, in input order.\n * @example\n * import { useSignal } from \"@shadow-js/core\";\n * import { Index } from \"@shadow-js/web\";\n *\n * function Cells() {\n * const [values] = useSignal([10, 20, 30]);\n * return (\n * <ul>\n * <Index each={values()}>{(value, index) => <li>{`${index}: ${value()}`}</li>}</Index>\n * </ul>\n * );\n * }\n * @see For\n * @since 1.0.0\n */\nexport function Index<T>(props: IndexProps<T>): Accessor<unknown[]> {\n return indexArray(\n () => props.each,\n (item: () => T, index: number) => untrack(() => props.children)(item, index),\n { fallback: () => props.fallback },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8CA,SAAgB,MAAS,OAA2C;CAClE,OAAO,iBACC,MAAM,OACX,MAAe,UAAkB,cAAc,MAAM,QAAQ,CAAC,CAAC,MAAM,KAAK,GAC3E,EAAE,gBAAgB,MAAM,SAAS,CACnC;AACF"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { untrack, useMemo, useResource } from "@shadow-js/core";
|
|
2
|
+
// src/control-flow/lazy.ts
|
|
3
|
+
/**
|
|
4
|
+
* Defines a component whose code is loaded on first render. While loading, the nearest
|
|
5
|
+
* `<Suspense>` shows its fallback; a failed load throws to the nearest `<ErrorBoundary>` and the
|
|
6
|
+
* next render retries.
|
|
7
|
+
*
|
|
8
|
+
* @param loader Returns a promise of a module whose `default` export is the component, such as
|
|
9
|
+
* `() => import("./chart")`. Called at most once while its load succeeds.
|
|
10
|
+
* @returns A {@link LazyComponent}.
|
|
11
|
+
* @throws Nothing synchronously. A rejected load surfaces as an error when the component's output
|
|
12
|
+
* is read, so the nearest `<ErrorBoundary>` takes it; `preload()` rejects with the same error.
|
|
13
|
+
* @example
|
|
14
|
+
* import { lazy, Suspense } from "@shadow-js/web";
|
|
15
|
+
*
|
|
16
|
+
* function Chart(props: { title: string }) {
|
|
17
|
+
* return <h2>{props.title}</h2>;
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // In an app the loader is `() => import("./chart")`.
|
|
21
|
+
* const LazyChart = lazy(() => Promise.resolve({ default: Chart }));
|
|
22
|
+
*
|
|
23
|
+
* function Page() {
|
|
24
|
+
* return (
|
|
25
|
+
* <Suspense fallback={<p>Loading...</p>}>
|
|
26
|
+
* <LazyChart title="Sales" />
|
|
27
|
+
* </Suspense>
|
|
28
|
+
* );
|
|
29
|
+
* }
|
|
30
|
+
* @see Suspense
|
|
31
|
+
* @see ErrorBoundary
|
|
32
|
+
* @since 1.0.0
|
|
33
|
+
*/
|
|
34
|
+
function lazy(loader) {
|
|
35
|
+
let pending;
|
|
36
|
+
let loaded;
|
|
37
|
+
const load = () => {
|
|
38
|
+
if (pending === void 0) pending = loader().then((module) => {
|
|
39
|
+
loaded = module.default;
|
|
40
|
+
return module.default;
|
|
41
|
+
}, (error) => {
|
|
42
|
+
pending = void 0;
|
|
43
|
+
throw error;
|
|
44
|
+
});
|
|
45
|
+
return pending;
|
|
46
|
+
};
|
|
47
|
+
const Lazy = ((props) => {
|
|
48
|
+
if (loaded !== void 0) {
|
|
49
|
+
const component = loaded;
|
|
50
|
+
return useMemo(() => untrack(() => component(props)), { allowWrites: true });
|
|
51
|
+
}
|
|
52
|
+
const resource = useResource(() => load());
|
|
53
|
+
return useMemo(() => {
|
|
54
|
+
const component = resource();
|
|
55
|
+
return component === void 0 ? void 0 : untrack(() => component(props));
|
|
56
|
+
}, { allowWrites: true });
|
|
57
|
+
});
|
|
58
|
+
Lazy.preload = load;
|
|
59
|
+
return Lazy;
|
|
60
|
+
}
|
|
61
|
+
export { lazy };
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=lazy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy.js","names":[],"sources":["../../../src/control-flow/lazy.ts"],"sourcesContent":["import { type Accessor, untrack, useMemo, useResource } from \"@shadow-js/core\";\n\ntype ComponentFunction<P> = (props: P) => unknown;\n\n/**\n * A component made by {@link lazy}: call it (or write it in JSX) like any component, and use\n * `preload` to start the load early.\n * @since 1.0.0\n */\nexport interface LazyComponent<P> {\n /**\n * Renders the loaded component with `props`. While the code is loading the result is empty and the\n * nearest `<Suspense>` shows its fallback; without a boundary nothing is rendered until the load\n * resolves.\n */\n (props: P): Accessor<unknown>;\n /**\n * Starts loading without rendering and resolves to the component. Calls share one load, so the\n * loader runs once. A failed load is not cached: the next call or render loads again.\n */\n preload(): Promise<ComponentFunction<P>>;\n}\n\n/**\n * Defines a component whose code is loaded on first render. While loading, the nearest\n * `<Suspense>` shows its fallback; a failed load throws to the nearest `<ErrorBoundary>` and the\n * next render retries.\n *\n * @param loader Returns a promise of a module whose `default` export is the component, such as\n * `() => import(\"./chart\")`. Called at most once while its load succeeds.\n * @returns A {@link LazyComponent}.\n * @throws Nothing synchronously. A rejected load surfaces as an error when the component's output\n * is read, so the nearest `<ErrorBoundary>` takes it; `preload()` rejects with the same error.\n * @example\n * import { lazy, Suspense } from \"@shadow-js/web\";\n *\n * function Chart(props: { title: string }) {\n * return <h2>{props.title}</h2>;\n * }\n *\n * // In an app the loader is `() => import(\"./chart\")`.\n * const LazyChart = lazy(() => Promise.resolve({ default: Chart }));\n *\n * function Page() {\n * return (\n * <Suspense fallback={<p>Loading...</p>}>\n * <LazyChart title=\"Sales\" />\n * </Suspense>\n * );\n * }\n * @see Suspense\n * @see ErrorBoundary\n * @since 1.0.0\n */\nexport function lazy<P>(\n loader: () => Promise<{ default: ComponentFunction<P> }>,\n): LazyComponent<P> {\n let pending: Promise<ComponentFunction<P>> | undefined;\n let loaded: ComponentFunction<P> | undefined;\n\n const load = (): Promise<ComponentFunction<P>> => {\n if (pending === undefined) {\n pending = loader().then(\n (module) => {\n loaded = module.default;\n return module.default;\n },\n (error: unknown) => {\n pending = undefined;\n throw error;\n },\n );\n }\n return pending;\n };\n\n const Lazy = ((props: P): Accessor<unknown> => {\n if (loaded !== undefined) {\n const component = loaded;\n return useMemo(() => untrack(() => component(props)), { allowWrites: true });\n }\n const resource = useResource(() => load());\n return useMemo(\n () => {\n const component = resource();\n return component === undefined ? undefined : untrack(() => component(props));\n },\n { allowWrites: true },\n );\n }) as LazyComponent<P>;\n Lazy.preload = load;\n return Lazy;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,KACd,QACkB;CAClB,IAAI;CACJ,IAAI;CAEJ,MAAM,aAA4C;EAChD,IAAI,YAAY,KAAA,GACd,UAAU,OAAO,CAAC,CAAC,MAChB,WAAW;GACV,SAAS,OAAO;GAChB,OAAO,OAAO;EAChB,IACC,UAAmB;GAClB,UAAU,KAAA;GACV,MAAM;EACR,CACF;EAEF,OAAO;CACT;CAEA,MAAM,SAAS,UAAgC;EAC7C,IAAI,WAAW,KAAA,GAAW;GACxB,MAAM,YAAY;GAClB,OAAO,cAAc,cAAc,UAAU,KAAK,CAAC,GAAG,EAAE,aAAa,KAAK,CAAC;EAC7E;EACA,MAAM,WAAW,kBAAkB,KAAK,CAAC;EACzC,OAAO,cACC;GACJ,MAAM,YAAY,SAAS;GAC3B,OAAO,cAAc,KAAA,IAAY,KAAA,IAAY,cAAc,UAAU,KAAK,CAAC;EAC7E,GACA,EAAE,aAAa,KAAK,CACtB;CACF;CACA,KAAK,UAAU;CACf,OAAO;AACT"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { nextKey, withScope } from "../internal/hydration-scope.js";
|
|
2
|
+
import { ssrRaw } from "../server/element.js";
|
|
3
|
+
// src/control-flow/no-hydration.ts
|
|
4
|
+
/**
|
|
5
|
+
* Content the browser never hydrates: the server renders it without hydration keys, and while the
|
|
6
|
+
* page hydrates the browser leaves that markup exactly as it is (no code runs for it, no event
|
|
7
|
+
* handlers or reactivity are attached). Use it for static, heavy markup such as rendered
|
|
8
|
+
* documentation or a long article. Rendered by the browser alone (a client-side navigation), its
|
|
9
|
+
* children render normally.
|
|
10
|
+
*
|
|
11
|
+
* @param props See {@link NoHydrationProps}.
|
|
12
|
+
* @returns An accessor of the content: the children, or the server's own nodes while the browser hydrates.
|
|
13
|
+
* @example
|
|
14
|
+
* import { NoHydration } from "@shadow-js/web";
|
|
15
|
+
*
|
|
16
|
+
* function Docs(props: { html: string }) {
|
|
17
|
+
* return (
|
|
18
|
+
* <NoHydration>
|
|
19
|
+
* <article innerHTML={props.html} />
|
|
20
|
+
* </NoHydration>
|
|
21
|
+
* );
|
|
22
|
+
* }
|
|
23
|
+
* @see ClientOnly
|
|
24
|
+
* @since 1.0.0
|
|
25
|
+
*/
|
|
26
|
+
function NoHydration(props) {
|
|
27
|
+
const key = nextKey();
|
|
28
|
+
{
|
|
29
|
+
const built = withScope(null, () => props.children);
|
|
30
|
+
return () => [
|
|
31
|
+
ssrRaw(`<!--nh:${key ?? ""}-->`),
|
|
32
|
+
built,
|
|
33
|
+
ssrRaw("<!--/nh-->")
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export { NoHydration };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=no-hydration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-hydration.js","names":[],"sources":["../../../src/control-flow/no-hydration.ts"],"sourcesContent":["import type { Accessor } from \"@shadow-js/core\";\nimport { claims, nextKey, withScope } from \"../extend\";\nimport { ssrRaw } from \"../server/element\";\n\n/** The nodes between `<!--nh:KEY-->` and its `<!--/nh-->` in the lifted regions, or undefined when the server sent none. */\nfunction findStatic(\n key: string | undefined,\n regions: readonly (readonly Node[])[] | undefined,\n): Node[] | undefined {\n if (key === undefined || regions === undefined) return undefined;\n for (const region of regions) {\n const open = region.findIndex(\n (node) => node.nodeType === 8 && (node as Comment).data === `nh:${key}`,\n );\n if (open === -1) continue;\n const nodes: Node[] = [];\n let depth = 1;\n for (let i = open + 1; i < region.length; i += 1) {\n const node = region[i] as Node;\n if (node.nodeType === 8) {\n const data = (node as Comment).data;\n if (data.startsWith(\"nh:\")) depth += 1;\n else if (data === \"/nh\" && --depth === 0) break;\n }\n nodes.push(node);\n }\n return nodes;\n }\n return undefined;\n}\n\n/**\n * Props of {@link NoHydration}.\n * @since 1.0.0\n */\nexport interface NoHydrationProps {\n /**\n * The static content. Rendered by the server without hydration keys and left untouched by the\n * browser's hydration pass.\n * @default undefined (renders nothing)\n */\n readonly children?: unknown;\n}\n\n/**\n * Content the browser never hydrates: the server renders it without hydration keys, and while the\n * page hydrates the browser leaves that markup exactly as it is (no code runs for it, no event\n * handlers or reactivity are attached). Use it for static, heavy markup such as rendered\n * documentation or a long article. Rendered by the browser alone (a client-side navigation), its\n * children render normally.\n *\n * @param props See {@link NoHydrationProps}.\n * @returns An accessor of the content: the children, or the server's own nodes while the browser hydrates.\n * @example\n * import { NoHydration } from \"@shadow-js/web\";\n *\n * function Docs(props: { html: string }) {\n * return (\n * <NoHydration>\n * <article innerHTML={props.html} />\n * </NoHydration>\n * );\n * }\n * @see ClientOnly\n * @since 1.0.0\n */\nexport function NoHydration(props: NoHydrationProps): Accessor<unknown> {\n // The component has its own scope, so this key does not move the keys of its siblings.\n const key = nextKey();\n if (__SERVER__) {\n // No scope for the content: the keys of what is rendered inside are not handed out.\n const built = withScope(null, () => props.children);\n return () => [ssrRaw(`<!--nh:${key ?? \"\"}-->`), built, ssrRaw(\"<!--/nh-->\")];\n }\n if (claims.current.isClaiming()) {\n // Hydrating: the server's nodes between the markers are handed to the region as they are.\n const kept = findStatic(key, claims.current.liftedRegions());\n if (kept !== undefined) return () => kept;\n // No markers from the server (the root of the container): render on the client, claiming nothing.\n return () => claims.current.withoutClaiming(() => props.children);\n }\n return () => props.children;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,SAAgB,YAAY,OAA4C;CAEtE,MAAM,MAAM,QAAQ;CACJ;EAEd,MAAM,QAAQ,UAAU,YAAY,MAAM,QAAQ;EAClD,aAAa;GAAC,OAAO,UAAU,OAAO,GAAG,IAAI;GAAG;GAAO,OAAO,YAAY;EAAC;CAC7E;AASF"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { childScope, nextKey, withScope } from "../internal/hydration-scope.js";
|
|
2
|
+
import { claims } from "../internal/hydration-hooks.js";
|
|
3
|
+
import { bindRegion, createRegion, removeRegion } from "../insert.js";
|
|
4
|
+
import { PortalContext } from "../internal/portal-context.js";
|
|
5
|
+
import { renderServerPortal } from "../server/portals.js";
|
|
6
|
+
import { createRoot, isServer, onCleanup, useContext, useRenderEffect } from "@shadow-js/core";
|
|
7
|
+
// src/control-flow/portal.ts
|
|
8
|
+
/** Appends `node` to `target`, moving it in place when the target supports `moveBefore`. */
|
|
9
|
+
function appendMoved(target, node) {
|
|
10
|
+
if (typeof target.moveBefore === "function") target.moveBefore(node, null);
|
|
11
|
+
else target.appendChild(node);
|
|
12
|
+
}
|
|
13
|
+
/** The shadow root of an element, attached once when the element has none. */
|
|
14
|
+
function shadowRootOf(host) {
|
|
15
|
+
return host.shadowRoot ?? host.attachShadow({ mode: "open" });
|
|
16
|
+
}
|
|
17
|
+
/** The mount target of a `mount` prop: the default body, the element, or the function's result. */
|
|
18
|
+
function resolveMount(mount) {
|
|
19
|
+
if (mount === void 0) return document.body;
|
|
20
|
+
return (typeof mount === "function" ? mount() : mount) ?? null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Renders `children` into another part of the document, without a wrapper: the content nodes are
|
|
24
|
+
* inserted directly into the mount element (or its shadow root). Nothing is left at the call site.
|
|
25
|
+
* Disposing the owner removes exactly the nodes the portal inserted; nodes that were already in the
|
|
26
|
+
* mount stay. A reactive `mount` moves the content, and static nodes keep their identity while they
|
|
27
|
+
* move.
|
|
28
|
+
*
|
|
29
|
+
* On the server the content is rendered into the render's `portals` collector (see
|
|
30
|
+
* `createServerPortals`), and the document emits it at the end of `<body>`. When the browser hydrates
|
|
31
|
+
* the portal it adopts that markup instead of creating it again, moving it into the mount if the mount
|
|
32
|
+
* is not `body`. A portal with `useShadow` is not server-rendered; the browser creates it.
|
|
33
|
+
*
|
|
34
|
+
* Events follow the DOM tree. Delegated handlers inside the content fire when the mount is in the
|
|
35
|
+
* document, because the document listener sees the event bubble past the mount. Handlers on
|
|
36
|
+
* elements that wrap the call site do not fire.
|
|
37
|
+
*
|
|
38
|
+
* @param props See {@link PortalProps}.
|
|
39
|
+
* @returns Always null: the portal renders nothing in place.
|
|
40
|
+
* @example
|
|
41
|
+
* import { Portal } from "@shadow-js/web";
|
|
42
|
+
*
|
|
43
|
+
* function Modal() {
|
|
44
|
+
* return <div role="dialog">Hello</div>;
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* function App() {
|
|
48
|
+
* return (
|
|
49
|
+
* <Portal mount={document.getElementById("modal-root")}>
|
|
50
|
+
* <Modal />
|
|
51
|
+
* </Portal>
|
|
52
|
+
* );
|
|
53
|
+
* }
|
|
54
|
+
* @see Dynamic
|
|
55
|
+
* @since 1.0.0
|
|
56
|
+
*/
|
|
57
|
+
function Portal(props) {
|
|
58
|
+
const key = nextKey();
|
|
59
|
+
const sink = useContext(PortalContext);
|
|
60
|
+
if (isServer || sink !== null) {
|
|
61
|
+
if (props.useShadow !== true) renderServerPortal(key, () => props.children, sink);
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
let mounted;
|
|
65
|
+
let warned = false;
|
|
66
|
+
let adopted = claims.current.claimPortal(key);
|
|
67
|
+
/** Stops the content's effects, then removes its nodes. Safe to call when nothing is mounted. */
|
|
68
|
+
const unmount = () => {
|
|
69
|
+
const current = mounted;
|
|
70
|
+
if (current === void 0) return;
|
|
71
|
+
mounted = void 0;
|
|
72
|
+
current.stopEffects();
|
|
73
|
+
removeRegion(current.region);
|
|
74
|
+
};
|
|
75
|
+
/** Creates the content region in `host`, adopting the nodes that are already there. */
|
|
76
|
+
const mountInto = (host, initial, mode) => {
|
|
77
|
+
const region = createRegion(host, null, initial);
|
|
78
|
+
return {
|
|
79
|
+
host,
|
|
80
|
+
region,
|
|
81
|
+
stopEffects: createRoot((dispose) => {
|
|
82
|
+
const bind = () => {
|
|
83
|
+
bindRegion(region, () => props.children);
|
|
84
|
+
};
|
|
85
|
+
if (mode === "plain") bind();
|
|
86
|
+
else if (mode === "claimed") withScope(childScope(key), bind);
|
|
87
|
+
else claims.current.withoutClaiming(() => withScope(childScope(key), bind));
|
|
88
|
+
return dispose;
|
|
89
|
+
})
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
/** Moves the content to `target`. The nodes move first, then the children are bound again. */
|
|
93
|
+
const moveTo = (target) => {
|
|
94
|
+
const previous = mounted;
|
|
95
|
+
if (previous === void 0) {
|
|
96
|
+
const initial = adopted ?? [];
|
|
97
|
+
let mode = "plain";
|
|
98
|
+
if (adopted !== void 0) mode = "claimed";
|
|
99
|
+
else if (key !== void 0 && claims.current.isClaiming()) mode = "unclaimed";
|
|
100
|
+
adopted = void 0;
|
|
101
|
+
for (const node of initial) if (node.parentNode !== target) appendMoved(target, node);
|
|
102
|
+
mounted = mountInto(target, initial, mode);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const nodes = previous.region.nodes.filter((node) => node.parentNode === previous.host);
|
|
106
|
+
previous.stopEffects();
|
|
107
|
+
for (const node of nodes) appendMoved(target, node);
|
|
108
|
+
mounted = mountInto(target, nodes, "plain");
|
|
109
|
+
};
|
|
110
|
+
useRenderEffect(() => {
|
|
111
|
+
return {
|
|
112
|
+
host: resolveMount(props.mount),
|
|
113
|
+
shadow: props.useShadow === true
|
|
114
|
+
};
|
|
115
|
+
}, ({ host, shadow }) => {
|
|
116
|
+
if (host === null) {
|
|
117
|
+
unmount();
|
|
118
|
+
if (!warned) {
|
|
119
|
+
warned = true;
|
|
120
|
+
console.warn("[shadow PORTAL_TARGET_MISSING] Portal has no mount element; nothing is rendered.");
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const target = shadow ? shadowRootOf(host) : host;
|
|
125
|
+
if (mounted !== void 0 && mounted.host === target) return;
|
|
126
|
+
moveTo(target);
|
|
127
|
+
});
|
|
128
|
+
onCleanup(unmount);
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
export { Portal };
|
|
132
|
+
|
|
133
|
+
//# sourceMappingURL=portal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal.js","names":[],"sources":["../../../src/control-flow/portal.ts"],"sourcesContent":["import { createRoot, isServer, onCleanup, useContext, useRenderEffect } from \"@shadow-js/core\";\nimport {\n bindRegion,\n childScope,\n claims,\n createRegion,\n nextKey,\n PortalContext,\n type Region,\n removeRegion,\n withScope,\n} from \"../extend\";\nimport { renderServerPortal } from \"../server/portals\";\n\n/**\n * Props of {@link Portal}.\n * @since 1.0.0\n */\nexport interface PortalProps {\n /**\n * The element that receives the content, or a function returning it (read reactively). A null\n * target, or a function that returns null or undefined, renders nothing and warns once in\n * development (`PORTAL_TARGET_MISSING`).\n * @default document.body (when the prop is omitted)\n */\n readonly mount?: Element | null | (() => Element | null | undefined);\n /**\n * Put the content in a shadow root of the mount, created once and reused. A portal with a shadow\n * root is not server-rendered; the browser creates it.\n * @default false\n */\n readonly useShadow?: boolean;\n /**\n * Reserved for namespace handling. Nodes are inserted as they were created, so the flag does not\n * change the output yet.\n * @default false\n */\n readonly isSVG?: boolean;\n /**\n * The content: a node, text, an array, or an accessor returning them.\n * @default undefined (nothing is rendered)\n */\n readonly children?: unknown;\n}\n\n/** What the portal holds while content is mounted: where it is, its region, and its effects. */\ninterface Mounted {\n readonly host: Node;\n readonly region: Region;\n /** Stops the content's effects. The nodes stay where they are. */\n readonly stopEffects: () => void;\n}\n\n/**\n * How the content of a mount is built. `claimed`: the server markup is adopted (the templates claim\n * it). `unclaimed`: hydrating, but the server sent nothing for this portal, so it is built fresh.\n */\ntype MountMode = \"plain\" | \"claimed\" | \"unclaimed\";\n\n/** A node that can be moved in place (`Element.prototype.moveBefore`, where implemented). */\ninterface MovableNode extends Node {\n moveBefore(node: Node, child: Node | null): void;\n}\n\n/** Appends `node` to `target`, moving it in place when the target supports `moveBefore`. */\nfunction appendMoved(target: Node, node: Node): void {\n if (typeof (target as Partial<MovableNode>).moveBefore === \"function\") {\n (target as MovableNode).moveBefore(node, null);\n } else {\n target.appendChild(node);\n }\n}\n\n/** The shadow root of an element, attached once when the element has none. */\nfunction shadowRootOf(host: Element): ShadowRoot {\n return host.shadowRoot ?? host.attachShadow({ mode: \"open\" });\n}\n\n/** The mount target of a `mount` prop: the default body, the element, or the function's result. */\nfunction resolveMount(mount: PortalProps[\"mount\"]): Element | null {\n if (mount === undefined) return document.body;\n const value = typeof mount === \"function\" ? mount() : mount;\n return value ?? null;\n}\n\n/**\n * Renders `children` into another part of the document, without a wrapper: the content nodes are\n * inserted directly into the mount element (or its shadow root). Nothing is left at the call site.\n * Disposing the owner removes exactly the nodes the portal inserted; nodes that were already in the\n * mount stay. A reactive `mount` moves the content, and static nodes keep their identity while they\n * move.\n *\n * On the server the content is rendered into the render's `portals` collector (see\n * `createServerPortals`), and the document emits it at the end of `<body>`. When the browser hydrates\n * the portal it adopts that markup instead of creating it again, moving it into the mount if the mount\n * is not `body`. A portal with `useShadow` is not server-rendered; the browser creates it.\n *\n * Events follow the DOM tree. Delegated handlers inside the content fire when the mount is in the\n * document, because the document listener sees the event bubble past the mount. Handlers on\n * elements that wrap the call site do not fire.\n *\n * @param props See {@link PortalProps}.\n * @returns Always null: the portal renders nothing in place.\n * @example\n * import { Portal } from \"@shadow-js/web\";\n *\n * function Modal() {\n * return <div role=\"dialog\">Hello</div>;\n * }\n *\n * function App() {\n * return (\n * <Portal mount={document.getElementById(\"modal-root\")}>\n * <Modal />\n * </Portal>\n * );\n * }\n * @see Dynamic\n * @since 1.0.0\n */\nexport function Portal(props: PortalProps): null {\n // The key of this portal's server block, taken at the call site on the server and in the browser\n // alike. The content renders in a scope of its own (`childScope`), so the keys of the siblings do\n // not depend on whether the content rendered.\n const key = nextKey();\n // A server render provides the portal collector (`renderToString` and friends), so it is recognized\n // by the collector as well as by the build's `isServer` flag: the same server code runs in both.\n const sink = useContext(PortalContext);\n if (isServer || sink !== null) {\n if (props.useShadow !== true) renderServerPortal(key, () => props.children, sink);\n return null;\n }\n let mounted: Mounted | undefined;\n let warned = false;\n // The server block of this portal, taken out of the markers while hydrating; used by the first mount.\n let adopted: Node[] | undefined = claims.current.claimPortal(key);\n\n /** Stops the content's effects, then removes its nodes. Safe to call when nothing is mounted. */\n const unmount = (): void => {\n const current = mounted;\n if (current === undefined) return;\n mounted = undefined;\n current.stopEffects();\n removeRegion(current.region);\n };\n\n /** Creates the content region in `host`, adopting the nodes that are already there. */\n const mountInto = (host: Node, initial: Node[], mode: MountMode): Mounted => {\n const region = createRegion(host, null, initial);\n const stopEffects = createRoot((dispose) => {\n const bind = (): void => {\n bindRegion(region, () => props.children);\n };\n if (mode === \"plain\") bind();\n else if (mode === \"claimed\") withScope(childScope(key), bind);\n else claims.current.withoutClaiming(() => withScope(childScope(key), bind));\n return dispose;\n });\n return { host, region, stopEffects };\n };\n\n /** Moves the content to `target`. The nodes move first, then the children are bound again. */\n const moveTo = (target: Node): void => {\n const previous = mounted;\n if (previous === undefined) {\n const initial = adopted ?? [];\n let mode: MountMode = \"plain\";\n if (adopted !== undefined) mode = \"claimed\";\n else if (key !== undefined && claims.current.isClaiming()) mode = \"unclaimed\";\n adopted = undefined;\n for (const node of initial) {\n if (node.parentNode !== target) appendMoved(target, node);\n }\n mounted = mountInto(target, initial, mode);\n return;\n }\n const nodes = previous.region.nodes.filter((node) => node.parentNode === previous.host);\n previous.stopEffects();\n for (const node of nodes) appendMoved(target, node);\n mounted = mountInto(target, nodes, \"plain\");\n };\n\n useRenderEffect(\n () => {\n const host = resolveMount(props.mount);\n const shadow = props.useShadow === true;\n return { host, shadow };\n },\n ({ host, shadow }) => {\n if (host === null) {\n unmount();\n if (__DEV__ && !warned) {\n warned = true;\n console.warn(\n \"[shadow PORTAL_TARGET_MISSING] Portal has no mount element; nothing is rendered.\",\n );\n }\n return;\n }\n const target: Node = shadow ? shadowRootOf(host) : host;\n if (mounted !== undefined && mounted.host === target) return;\n moveTo(target);\n },\n );\n onCleanup(unmount);\n return null;\n}\n"],"mappings":";;;;;;;;AAiEA,SAAS,YAAY,QAAc,MAAkB;CACnD,IAAI,OAAQ,OAAgC,eAAe,YACzD,OAAwB,WAAW,MAAM,IAAI;MAE7C,OAAO,YAAY,IAAI;AAE3B;;AAGA,SAAS,aAAa,MAA2B;CAC/C,OAAO,KAAK,cAAc,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAC9D;;AAGA,SAAS,aAAa,OAA6C;CACjE,IAAI,UAAU,KAAA,GAAW,OAAO,SAAS;CAEzC,QADc,OAAO,UAAU,aAAa,MAAM,IAAI,UACtC;AAClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,OAAO,OAA0B;CAI/C,MAAM,MAAM,QAAQ;CAGpB,MAAM,OAAO,WAAW,aAAa;CACrC,IAAI,YAAY,SAAS,MAAM;EAC7B,IAAI,MAAM,cAAc,MAAM,mBAAmB,WAAW,MAAM,UAAU,IAAI;EAChF,OAAO;CACT;CACA,IAAI;CACJ,IAAI,SAAS;CAEb,IAAI,UAA8B,OAAO,QAAQ,YAAY,GAAG;;CAGhE,MAAM,gBAAsB;EAC1B,MAAM,UAAU;EAChB,IAAI,YAAY,KAAA,GAAW;EAC3B,UAAU,KAAA;EACV,QAAQ,YAAY;EACpB,aAAa,QAAQ,MAAM;CAC7B;;CAGA,MAAM,aAAa,MAAY,SAAiB,SAA6B;EAC3E,MAAM,SAAS,aAAa,MAAM,MAAM,OAAO;EAU/C,OAAO;GAAE;GAAM;GAAQ,aATH,YAAY,YAAY;IAC1C,MAAM,aAAmB;KACvB,WAAW,cAAc,MAAM,QAAQ;IACzC;IACA,IAAI,SAAS,SAAS,KAAK;SACtB,IAAI,SAAS,WAAW,UAAU,WAAW,GAAG,GAAG,IAAI;SACvD,OAAO,QAAQ,sBAAsB,UAAU,WAAW,GAAG,GAAG,IAAI,CAAC;IAC1E,OAAO;GACT,CACiC;EAAE;CACrC;;CAGA,MAAM,UAAU,WAAuB;EACrC,MAAM,WAAW;EACjB,IAAI,aAAa,KAAA,GAAW;GAC1B,MAAM,UAAU,WAAW,CAAC;GAC5B,IAAI,OAAkB;GACtB,IAAI,YAAY,KAAA,GAAW,OAAO;QAC7B,IAAI,QAAQ,KAAA,KAAa,OAAO,QAAQ,WAAW,GAAG,OAAO;GAClE,UAAU,KAAA;GACV,KAAK,MAAM,QAAQ,SACjB,IAAI,KAAK,eAAe,QAAQ,YAAY,QAAQ,IAAI;GAE1D,UAAU,UAAU,QAAQ,SAAS,IAAI;GACzC;EACF;EACA,MAAM,QAAQ,SAAS,OAAO,MAAM,QAAQ,SAAS,KAAK,eAAe,SAAS,IAAI;EACtF,SAAS,YAAY;EACrB,KAAK,MAAM,QAAQ,OAAO,YAAY,QAAQ,IAAI;EAClD,UAAU,UAAU,QAAQ,OAAO,OAAO;CAC5C;CAEA,sBACQ;EAGJ,OAAO;GAAE,MAFI,aAAa,MAAM,KAEpB;GAAG,QADA,MAAM,cAAc;EACb;CACxB,IACC,EAAE,MAAM,aAAa;EACpB,IAAI,SAAS,MAAM;GACjB,QAAQ;GACR,IAAe,CAAC,QAAQ;IACtB,SAAS;IACT,QAAQ,KACN,kFACF;GACF;GACA;EACF;EACA,MAAM,SAAe,SAAS,aAAa,IAAI,IAAI;EACnD,IAAI,YAAY,KAAA,KAAa,QAAQ,SAAS,QAAQ;EACtD,OAAO,MAAM;CACf,CACF;CACA,UAAU,OAAO;CACjB,OAAO;AACT"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getOwner } from "@shadow-js/core";
|
|
2
|
+
// src/control-flow/root-errors.ts
|
|
3
|
+
/**
|
|
4
|
+
* The key the reporters are stored under in an owner's context map. A symbol the context map inherits
|
|
5
|
+
* (as a Provider's value is inherited), so every node below the root sees it, detached roots included.
|
|
6
|
+
* A plain value rather than a context: a context would bring its Provider into every bundle.
|
|
7
|
+
*/
|
|
8
|
+
const ROOT_ERRORS = /* @__PURE__ */ Symbol("RootErrors");
|
|
9
|
+
/**
|
|
10
|
+
* Attaches the options to the root that is being created (called inside its `createRoot`). The reporters
|
|
11
|
+
* go into the root's context map, and an `onUncaughtError` becomes the root's error handler (a fresh root
|
|
12
|
+
* has none, so it is the only one).
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
function attachRootErrors(options) {
|
|
16
|
+
const root = getOwner();
|
|
17
|
+
if (root === null) return;
|
|
18
|
+
const map = Object.create(root.context);
|
|
19
|
+
map[ROOT_ERRORS] = options;
|
|
20
|
+
root.context = map;
|
|
21
|
+
if (options.onUncaughtError !== void 0) root.errorHandlers = [options.onUncaughtError];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The reporters of the nearest root above `owner`, or undefined when no root was given options.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
function rootErrorsOf(owner) {
|
|
28
|
+
return owner?.context?.[ROOT_ERRORS];
|
|
29
|
+
}
|
|
30
|
+
export { attachRootErrors, rootErrorsOf };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=root-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"root-errors.js","names":[],"sources":["../../../src/control-flow/root-errors.ts"],"sourcesContent":["import { getOwner, type Owner } from \"@shadow-js/core\";\n\n/**\n * The error reporters a root was rendered or hydrated with (see `RenderOptions` and `HydrateOptions`).\n * @since 1.0.0\n */\nexport interface RootErrorOptions {\n /**\n * Receives an error that no error boundary took. The root then does not rethrow it.\n * @default undefined (no reporter; an error no boundary takes follows the default handling)\n */\n readonly onUncaughtError?: (error: unknown) => void;\n /**\n * Receives an error an `ErrorBoundary` caught (its fallback is shown).\n * @default undefined (no reporter)\n */\n readonly onCaughtError?: (error: unknown) => void;\n /**\n * Receives a hydration mismatch that was repaired on the client. Only `hydrate` reports these.\n * @default undefined (no reporter)\n */\n readonly onRecoverableError?: (error: unknown) => void;\n}\n\n/**\n * The key the reporters are stored under in an owner's context map. A symbol the context map inherits\n * (as a Provider's value is inherited), so every node below the root sees it, detached roots included.\n * A plain value rather than a context: a context would bring its Provider into every bundle.\n */\nconst ROOT_ERRORS: symbol = /* @__PURE__ */ Symbol(\"RootErrors\");\n\n/**\n * Attaches the options to the root that is being created (called inside its `createRoot`). The reporters\n * go into the root's context map, and an `onUncaughtError` becomes the root's error handler (a fresh root\n * has none, so it is the only one).\n * @internal\n */\nexport function attachRootErrors(options: RootErrorOptions): void {\n const root = getOwner();\n if (root === null) return;\n const map = Object.create(root.context) as Record<symbol, unknown>;\n map[ROOT_ERRORS] = options;\n root.context = map;\n if (options.onUncaughtError !== undefined) root.errorHandlers = [options.onUncaughtError];\n}\n\n/**\n * The reporters of the nearest root above `owner`, or undefined when no root was given options.\n * @internal\n */\nexport function rootErrorsOf(owner: Owner | null): RootErrorOptions | undefined {\n return owner?.context?.[ROOT_ERRORS] as RootErrorOptions | undefined;\n}\n"],"mappings":";;;;;;;AA6BA,MAAM,cAAsC,uBAAO,YAAY;;;;;;;AAQ/D,SAAgB,iBAAiB,SAAiC;CAChE,MAAM,OAAO,SAAS;CACtB,IAAI,SAAS,MAAM;CACnB,MAAM,MAAM,OAAO,OAAO,KAAK,OAAO;CACtC,IAAI,eAAe;CACnB,KAAK,UAAU;CACf,IAAI,QAAQ,oBAAoB,KAAA,GAAW,KAAK,gBAAgB,CAAC,QAAQ,eAAe;AAC1F;;;;;AAMA,SAAgB,aAAa,OAAmD;CAC9E,OAAO,OAAO,UAAU;AAC1B"}
|