Site color

Choose your site’s color palette.

Saved on this device.

RegorApp

RegorAppIndependent app

Mount an independent browser app from a TypeScript file colocated with its MDX page.

Browser entry points

A focused browser app

Complete and undo tasks, change the goal, add a note, and pause changes. The status and native progress bar update together. Reset restores this app’s initial state.

RegorApp in contextCOMPOSITION

An app mount, a module, and fresh reactive state. Change the controls and inspect the complete source.

<RegorApp id="regor-app-demo" data-review-counter="Release review" src="./playground.ts"/>
import {
  defineButtonComponents,
  defineFlexComponents,
  defineFormComponents,
  defineFormInputField,
  definePanelComponents,
} from '@purestack/ts-components'
import {
  batch,
  type ComputedRef,
  computed,
  createApp,
  defineComponent,
  html,
  type Ref,
  ref,
} from 'regor'

export interface ReviewCounter {
  prefix: string
  title: string
  completed: Ref<number>
  goal: Ref<string>
  note: Ref<string>
  locked: Ref<boolean>
  target: ComputedRef<number>
  complete: () => void
  undo: () => void
  reset: () => void
}

const reviewTemplate = html`<Panel variant="surface" tone="neutral" bodyClass="p-3">
  <Flex direction="column" align="stretch">
    <div>
      <p class="text-eyebrow m-0">INDEPENDENT BROWSER APP</p>
      <h3 class="fs-h4 my-2">{{ title }}</h3>
    </div>
    <FormStatus
      :tone="completed >= target ? 'success' : 'info'"
      aria-live="polite"
      >{{ completed }} of {{ target }} tasks complete ·
      {{ completed >= target ? 'Ready for review' : 'Work in progress' }}</FormStatus>
    <progress
      class="w-full"
      :value="completed"
      :max="target"
      :aria-label="title + ': ' + completed + ' of ' + target + ' complete'"
    ></progress>
    <FormInputField
      :id="prefix + '-goal'"
      label="Review goal"
      type="number"
      min="1"
      max="12"
      :model="goal"
      :disabled="locked"/>
    <FormInputField
      :id="prefix + '-note'"
      label="Review note"
      placeholder="Add context for this review"
      :model="note"
      :disabled="locked"/>
    <p class="m-0">{{ note || 'No review note yet.' }}</p>
    <FormCheck
      :id="prefix + '-locked'"
      label="Pause changes"
      :checked="locked"/>
    <Flex wrap="true" class="gap-2">
      <Btn
        tone="accent"
        @click="complete"
        :disabled="locked || completed >= target"
        >Complete a task</Btn>
      <Btn variant="outline" @click="undo" :disabled="locked || completed === 0"
        >Undo task</Btn>
      <Btn tone="neutral" variant="subtleBtn" @click="reset">Reset review</Btn>
    </Flex>
  </Flex>
</Panel>`

// One module may serve several mounts. Each createApp call owns fresh refs.
for (const mount of document.querySelectorAll<HTMLElement>(
  'app[data-review-counter]',
)) {
  createApp(
    {
      components: {
        ReviewCounter: defineComponent<ReviewCounter>(reviewTemplate, {
          context: () => {
            const completed = ref(0)
            const goal = ref('5')
            const note = ref('')
            const locked = ref(false)
            const target = computed(() =>
              Math.max(1, Math.min(12, Math.floor(Number(goal()) || 5))),
            )
            return {
              prefix: mount.id,
              title: mount.dataset.reviewCounter || 'Release review',
              completed,
              goal,
              note,
              locked,
              target,
              complete: () => {
                if (!locked() && completed() < target())
                  completed(completed() + 1)
              },
              undo: () => {
                if (!locked() && completed() > 0) completed(completed() - 1)
              },
              reset: () =>
                batch(() => {
                  completed(0)
                  goal('5')
                  note('')
                  locked(false)
                }),
            }
          },
        }),
        ...defineFlexComponents(),
        ...definePanelComponents(),
        ...defineButtonComponents(),
        ...defineFormComponents(),
        ...defineFormInputField(),
      },
    },
    { element: mount, template: html`<ReviewCounter/>` },
  )
}

Two apps, independent state

Both mounts load the same module URL. Browser modules execute once per URL; the entry point explicitly creates an app for every matching mount. Each call gets fresh refs and unique field IDs. Completing a task in one review leaves the other unchanged.

Design review and content reviewCOMPOSITION

Change either goal or note, pause one app, and reset it. The neighboring app keeps its own state.

<Grid columns="1" columnsMd="2">
  <RegorApp id="regor-app-design" data-review-counter="Design review" src="./playground.ts"/>
  <RegorApp id="regor-app-content" data-review-counter="Content review" src="./playground.ts"/>
</Grid>

Explicit source ownership

Bind an explicit sourceRelPath to change the source directory used to resolve src. The colon binding overrides the source owner automatically attached by MDX compilation. Here the owner is the real PageScript guide, and its sibling-relative src resolves back to this guide’s playground. The emitted bundle is shared with the other mounts.

A mount with a different source ownerCOMPOSITION

The app is still mounted on this page. sourceRelPath affects build-time path resolution, not DOM selection.

<RegorApp
  id="regor-app-owned"
  data-review-counter="Shared source review"
  src="../regor-app/playground.ts"
  :sourceRelPath="'components/runtime/page-script/page-script.mdx'"
/>

From MDX to reactive UI

Four pieces with clear ownershipCOMPOSITION
1 · Sourceplayground.ts beside the guide

The SSG resolves the relative path, records the entry point, and emits its browser bundle.

2 · MountOne unique app ID

id and data-review-counter are native attributes on the app element. Each field ID derives from the mount ID.

3 · RegistrationOnly the component families used here

Buttons, flex, panels, form fields, and statuses are explicitly registered in the browser app.

4 · ContextFresh refs and computed values

Task count, goal, note, and pause state belong to one mount. Progress and feedback derive from them.

RegorApp creates the mount and includes the module. Your entry point registers components and calls createApp.

Feature map

Feature Visible example
src The focused app loads a colocated TypeScript entry point.
sourceRelPath Shared source review resolves src relative to another real MDX owner.
Native id and data attributes Every mount has its own ID and review label; the entry reads those attributes.
Browser registration The full source registers each component family used by the template.
Independent state Design and content reviews update and reset independently.
Reactive values and events Edit the goal and note, complete or undo a task, and pause changes.
Derived presentation Status, progress, disabled buttons, and the note reflect the current refs.

RegorApp has no tone, variant, or variantMode props and no server-rendered content slot. Appearance belongs to the components inside the mounted app. It creates a browser app rather than hydrating a server-rendered Regor component tree.

Behavior and accessibility

RegorApp renders an app mount element and a module entry script. Give the mount a unique native id and use the matching selector in createApp. Source resolution is automatic; sourceRelPath is only an override. Register the component families and SVG icons your browser app uses.

API reference

RegorApp contract

src and sourceRelPath are component props. id is a native attribute on the app mount. The TypeScript entry point calls createApp explicitly.

src

string
Default
required

Browser entry point. A relative path resolves from the current MDX page. SSG records and bundles local scripts.

sourceRelPath

string
Default
detected from the current page

Optional source-resolution override. Omit it for ordinary colocated MDX and TypeScript files.

Composition

No content slot. RegorApp uses PageScript internally. Available in SSG’s standard component registration; browser code imports createApp, defineComponent and html from Regor.