foldkit-ssr 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +693 -61
- package/dist/{client-XnpTQZHw.d.ts → client-BEHlUHBv.d.ts} +10 -7
- package/dist/client-BEHlUHBv.d.ts.map +1 -0
- package/dist/client.d.ts +6 -5
- package/dist/client.js +66 -18
- package/dist/client.js.map +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/context.js.map +1 -1
- package/dist/diagnostics.d.ts +2 -2
- package/dist/diagnostics.js +14 -1
- package/dist/diagnostics.js.map +1 -1
- package/dist/handoff.d.ts +23 -0
- package/dist/handoff.d.ts.map +1 -0
- package/dist/handoff.js +15 -0
- package/dist/handoff.js.map +1 -0
- package/dist/index.d.ts +108 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +386 -51
- package/dist/index.js.map +1 -1
- package/dist/keep.d.ts +5 -1
- package/dist/keep.d.ts.map +1 -1
- package/dist/keep.js +55 -11
- package/dist/keep.js.map +1 -1
- package/dist/{listen-DaUPRKVR.d.ts → listen-7HzKBhqU.d.ts} +11 -2
- package/dist/{listen-DaUPRKVR.d.ts.map → listen-7HzKBhqU.d.ts.map} +1 -1
- package/dist/listen.d.ts +2 -2
- package/dist/listen.js +17 -7
- package/dist/listen.js.map +1 -1
- package/dist/loader.d.ts +13 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +156 -0
- package/dist/loader.js.map +1 -0
- package/dist/marks-CX15BwOw.d.ts +39 -0
- package/dist/marks-CX15BwOw.d.ts.map +1 -0
- package/dist/marks.d.ts +2 -0
- package/dist/marks.js +41 -0
- package/dist/marks.js.map +1 -0
- package/dist/pageCache-DO0pOgnc.d.ts +80 -0
- package/dist/pageCache-DO0pOgnc.d.ts.map +1 -0
- package/dist/pageCache.d.ts +2 -0
- package/dist/pageCache.js +112 -0
- package/dist/pageCache.js.map +1 -0
- package/dist/{requestContext-D9nsbGSJ.d.ts → requestContext-DmwmQeci.d.ts} +12 -2
- package/dist/requestContext-DmwmQeci.d.ts.map +1 -0
- package/dist/requestContext.d.ts +2 -2
- package/dist/requestContext.js +30 -13
- package/dist/requestContext.js.map +1 -1
- package/dist/{resumable-BPN_qQHU.d.ts → resumable-BV9_OKxr.d.ts} +7 -10
- package/dist/resumable-BV9_OKxr.d.ts.map +1 -0
- package/dist/resumable.d.ts +2 -1
- package/dist/resumable.js +16 -19
- package/dist/resumable.js.map +1 -1
- package/dist/runtimeChunk.d.ts +13 -0
- package/dist/runtimeChunk.d.ts.map +1 -0
- package/dist/runtimeChunk.js +36 -0
- package/dist/runtimeChunk.js.map +1 -0
- package/dist/runtimeUrl.d.ts +10 -0
- package/dist/runtimeUrl.d.ts.map +1 -0
- package/dist/runtimeUrl.js +13 -0
- package/dist/runtimeUrl.js.map +1 -0
- package/dist/{shared-DbupL3vO.d.ts → shared-mQ8CXr-r.d.ts} +69 -22
- package/dist/shared-mQ8CXr-r.d.ts.map +1 -0
- package/dist/shared.d.ts +3 -2
- package/dist/shared.js +40 -18
- package/dist/shared.js.map +1 -1
- package/dist/vite.d.ts +3 -2
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +2 -1
- package/dist/vite.js.map +1 -1
- package/package.json +11 -6
- package/dist/client-XnpTQZHw.d.ts.map +0 -1
- package/dist/requestContext-D9nsbGSJ.d.ts.map +0 -1
- package/dist/resumable-BPN_qQHU.d.ts.map +0 -1
- package/dist/shared-DbupL3vO.d.ts.map +0 -1
package/dist/resumable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resumable.js","names":[],"sources":["../src/resumable.ts"],"sourcesContent":["/**\n * The resumable builder: the application's `h`, whose event attributes say, in\n * the server's markup, which Message each element causes.\n *\n * A Foldkit handler is a Message value (`h.OnClick(Message.Liked({ id }))`), so\n * for most events that is already data. The events that carry a value\n * (`OnInput`, `OnChange`, `OnKeyDown`, `OnKeyUp`) take a closure only to put\n * the value into a Message field; this builder also takes the Message's own\n * constructor there, a Message with a hole, and fills the hole the same way.\n *\n * During the server's renders each binding gets an ordinal, recorded in render\n * order, and its element a `data-foldkit-plus-on-<event>` attribute naming it.\n * In the browser the builder marks nothing: it is the application's `h`, with\n * the hole forms turned into the closures Foldkit expects.\n */\nimport { Schema, SchemaAST } from 'effect'\nimport type { Attribute, ChildAttribute, HtmlBuilder, KeyboardModifiers } from 'foldkit/html'\nimport { current, type Binding } from './context.js'\n\n/** The attribute prefix of an element's binding marker. */\nexport const BINDING_ATTRIBUTE = 'data-foldkit-plus-on-'\n\n/**\n * The DOM event each of Foldkit's event attributes listens to, read from\n * Foldkit's own attribute table (0.163). `OnCustomEvent` names its event in\n * its payload, and `OnMount` and `OnUnmount` listen to none.\n */\nexport const EVENT_OF: Readonly<Record<string, string>> = {\n OnClick: 'click',\n OnDoubleClick: 'dblclick',\n OnMouseDown: 'mousedown',\n OnMouseUp: 'mouseup',\n OnMouseEnter: 'mouseenter',\n OnMouseLeave: 'mouseleave',\n OnMouseOver: 'mouseover',\n OnMouseOut: 'mouseout',\n OnMouseMove: 'mousemove',\n OnPointerMove: 'pointermove',\n OnPointerLeave: 'pointerleave',\n OnPointerDown: 'pointerdown',\n OnPointerUp: 'pointerup',\n OnKeyDown: 'keydown',\n OnKeyDownPreventDefault: 'keydown',\n OnKeyDownSelf: 'keydown',\n OnKeyDownSelfPreventDefault: 'keydown',\n OnKeyDownFocus: 'keydown',\n OnKeyUp: 'keyup',\n OnKeyUpPreventDefault: 'keyup',\n OnKeyPress: 'keypress',\n OnFocus: 'focus',\n OnBlur: 'blur',\n OnFocusEnter: 'focusin',\n OnFocusLeave: 'focusout',\n OnInput: 'input',\n OnChange: 'change',\n OnBeforeInput: 'beforeinput',\n OnBeforeInputPreventDefault: 'beforeinput',\n OnFileChange: 'change',\n OnSubmit: 'submit',\n OnReset: 'reset',\n OnScroll: 'scroll',\n OnWheel: 'wheel',\n OnCopy: 'copy',\n OnCut: 'cut',\n OnPaste: 'paste',\n OnPastePreventDefault: 'paste',\n OnCopyText: 'copy',\n OnCutText: 'cut',\n OnCancel: 'cancel',\n OnCancelPreventDefault: 'cancel',\n OnToggle: 'toggle',\n OnContextMenu: 'contextmenu',\n OnDragStart: 'dragstart',\n OnDrag: 'drag',\n OnDragEnd: 'dragend',\n OnDragEnter: 'dragenter',\n OnDragLeave: 'dragleave',\n OnDragOver: 'dragover',\n OnDrop: 'drop',\n OnDropFiles: 'drop',\n OnTouchStart: 'touchstart',\n OnTouchEnd: 'touchend',\n OnTouchMove: 'touchmove',\n OnTouchCancel: 'touchcancel',\n OnAnimationStart: 'animationstart',\n OnAnimationEnd: 'animationend',\n OnAnimationIteration: 'animationiteration',\n OnTransitionEnd: 'transitionend',\n OnLoad: 'load',\n OnError: 'error',\n OnPlay: 'play',\n OnPause: 'pause',\n OnEnded: 'ended',\n OnTimeUpdate: 'timeupdate',\n OnVolumeChange: 'volumechange',\n OnSelect: 'select',\n}\n\n/**\n * The attributes whose binding the page can describe: a Message value, or one\n * of the hole forms this builder records. Any other handler still runs on the\n * live page, so its event is marked `*`: the page does something there it\n * cannot name, and a dispatcher that ran only the named bindings would do less.\n */\nconst MARKABLE: ReadonlySet<string> = new Set([\n 'OnClick',\n 'OnDoubleClick',\n 'OnMouseDown',\n 'OnMouseUp',\n 'OnMouseEnter',\n 'OnMouseLeave',\n 'OnMouseOver',\n 'OnMouseOut',\n 'OnMouseMove',\n 'OnFocus',\n 'OnBlur',\n 'OnSubmit',\n 'OnReset',\n 'OnInput',\n 'OnChange',\n 'OnKeyDown',\n 'OnKeyUp',\n])\n\n/** The token in a marker for a handler the page cannot describe. */\nexport const UNNAMED_HANDLER = '*'\n\n/** The posted field that carries a form's encoded Message, for the server fallback. */\nexport const FALLBACK_FIELD = 'foldkit-plus-message'\n\n/** The posted field that says how many placement wrappers the form's fields sit under. */\nexport const FALLBACK_DEPTH_FIELD = 'foldkit-plus-depth'\n\n/**\n * The attribute on a field whose typing before boot is kept (`KeepTyped`),\n * naming the binding whose Message replays it.\n */\nexport const KEEP_ATTRIBUTE = 'data-foldkit-plus-keep'\n\n/** The value of a `KeepTyped` marker no resumable element took, while the server renders. */\nexport const UNPLACED_KEEP = '?'\n\n/**\n * The `input` types whose value is not something typed, so `KeepTyped` has\n * nothing to keep on them.\n */\nconst UNTYPED_INPUTS: ReadonlySet<string> = new Set([\n 'checkbox',\n 'radio',\n 'file',\n 'hidden',\n 'button',\n 'submit',\n 'reset',\n 'image',\n])\n\n/** The attribute on a placement's root naming its slot, while the server renders. */\nexport const SLOT_ATTRIBUTE = 'data-foldkit-plus-slot'\n\ndeclare const invalid: unique symbol\n\n/** A compile-time failure that names its cause. */\nexport interface Invalid<Message extends string> {\n readonly [invalid]: Message\n}\n\ntype IsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never\n\n/** A Message constructor from `defineMessageUnion`: a tagged Schema that can be called. */\ntype AnyMemberSchema = Schema.Top & { readonly fields: Schema.Struct.Fields }\n\n/** The Message a member makes. */\ntype Made<M> = M extends { readonly Type: infer T } ? T : never\n\n/** The fields a member's event may be given fixed: all but `_tag`. */\ntype Fixable<M> = Partial<Omit<Made<M>, '_tag'>>\n\n/** The fields of a member the event fills: those neither `_tag` nor fixed. */\ntype Rest<M, Fixed> = Omit<Made<M>, '_tag' | keyof Fixed>\n\ntype ProducesMessage<M, Message> = [Made<M>] extends [Message]\n ? unknown\n : Invalid<\"the member is not one of this view's Messages\">\n\ntype TextHoleCheck<M, Fixed> = [keyof Rest<M, Fixed>] extends [never]\n ? Invalid<'the member has no field left for the event to fill'>\n : true extends IsUnion<keyof Rest<M, Fixed>>\n ? Invalid<'the member leaves more than one field for the event to fill: fix the others'>\n : Rest<M, Fixed>[keyof Rest<M, Fixed>] extends string\n ? string extends Rest<M, Fixed>[keyof Rest<M, Fixed>]\n ? unknown\n : Invalid<'the field the event fills must be a string'>\n : Invalid<'the field the event fills must be a string'>\n\ntype KeyHoleCheck<M, Fixed> = [keyof Rest<M, Fixed>] extends ['key' | 'modifiers']\n ? ['key' | 'modifiers'] extends [keyof Rest<M, Fixed>]\n ? unknown\n : Invalid<'the member must leave exactly key and modifiers for the event to fill'>\n : Invalid<'the member must leave exactly key and modifiers for the event to fill'>\n\n/**\n * Foldkit's attribute of one tag, as its own builder returns it, so an\n * element that refuses some attributes (a `textarea`, `InnerHTML`) takes it.\n */\ntype Tagged<Message, Tag extends string> = Extract<Attribute<Message>, { readonly _tag: Tag }>\n\n/** `OnInput` and `OnChange`: a closure, or a member whose one string field the event fills. */\nexport interface TextHole<Message, Tag extends string> {\n (toMessage: (value: string) => Message): Tagged<Message, Tag>\n <M extends AnyMemberSchema, const Fixed extends Fixable<M> = {}>(\n member: M & ProducesMessage<M, Message> & TextHoleCheck<M, Fixed>,\n fixed?: Fixed,\n ): Tagged<Message, Tag>\n}\n\n/** `OnKeyDown` and `OnKeyUp`: a closure, or a member whose `key` and `modifiers` the event fills. */\nexport interface KeyHole<Message, Tag extends string> {\n (toMessage: (key: string, modifiers: KeyboardModifiers) => Message): Tagged<Message, Tag>\n <M extends AnyMemberSchema, const Fixed extends Fixable<M> = {}>(\n member: M & ProducesMessage<M, Message> & KeyHoleCheck<M, Fixed>,\n fixed?: Fixed,\n ): Tagged<Message, Tag>\n}\n\n/**\n * A builder a view is given: Foldkit's `HtmlBuilder`, or a Surface renderer's,\n * which leaves out Foldkit's phantom key. Its Message is what `OnClick` takes.\n */\nexport type AnyBuilder = {\n readonly OnClick: (message: never, ...rest: ReadonlyArray<never>) => unknown\n}\n\n/** The Message a builder's handlers make. */\nexport type MessageOf<Builder> = Builder extends {\n readonly OnClick: (message: infer Message, ...rest: ReadonlyArray<never>) => unknown\n}\n ? Message\n : never\n\n/**\n * The resumable builder for a view whose Messages are `Message`: its elements\n * and attributes, and the hole forms of the four value events. One shape\n * whether it wraps a view's `HtmlBuilder` or a Surface renderer's builder, so a\n * helper typed with it takes either. It keeps Foldkit's phantom Message key,\n * so a placement's view accepts it as the parent's builder.\n */\nexport type ResumableBuilder<Message> = Omit<\n HtmlBuilder<Message>,\n 'OnInput' | 'OnChange' | 'OnKeyDown' | 'OnKeyUp'\n> & {\n readonly OnInput: TextHole<Message, 'OnInput'>\n readonly OnChange: TextHole<Message, 'OnChange'>\n readonly OnKeyDown: KeyHole<Message, 'OnKeyDown'>\n readonly OnKeyUp: KeyHole<Message, 'OnKeyUp'>\n /**\n * Keeps what is typed into this field before the runtime starts: the\n * browser replays it as the field's `OnInput` Message (else its\n * `OnChange`), given in the hole form, and keeps the caret. The field must\n * be an `input` that takes text, a `textarea` or a `select`.\n */\n readonly KeepTyped: () => Tagged<Message, 'Attribute'>\n}\n\ntype AnyMember = ((value: Record<string, unknown>) => unknown) & {\n readonly fields: Readonly<Record<string, unknown>>\n}\n\nconst isMember = (value: unknown): value is AnyMember =>\n typeof value === 'function' && typeof (value as { fields?: unknown }).fields === 'object'\n\nconst tagOf = (member: AnyMember): string => {\n const tag = member.fields._tag\n return Schema.isSchema(tag) && SchemaAST.isLiteral(tag.ast) && typeof tag.ast.literal === 'string'\n ? tag.ast.literal\n : 'the member'\n}\n\n/**\n * The fields a member leaves for the event to fill, given what is fixed. Only\n * `fixed`'s own keys fix a field: `in` finds `constructor` on every object.\n */\nconst holeOf = (member: AnyMember, fixed: object): ReadonlyArray<string> =>\n Object.keys(member.fields).filter(field => field !== '_tag' && !Object.hasOwn(fixed, field))\n\nconst NO_MODIFIERS: KeyboardModifiers = {\n shiftKey: false,\n ctrlKey: false,\n altKey: false,\n metaKey: false,\n}\n\n/** Each hole-form attribute, with its Message filled by a placeholder and the fields the event fills. */\nconst holes = new WeakMap<\n object,\n { readonly template: unknown; readonly hole: ReadonlyArray<string> }\n>()\n\n/** What an element is given: Foldkit's attributes, and a Submodel's wrapped ones, which carry no tag. */\ntype Item = Attribute<unknown> | ChildAttribute\n\nconst isAttribute = (item: Item): item is Attribute<unknown> => '_tag' in item\n\nconst builders = new WeakMap<object, unknown>()\n\n/** Each attribute `KeepTyped` made: a request to the element it is given, never written as it is. */\nconst keeps = new WeakSet<object>()\n\n/** A hole form's placeholder Message, or `undefined` when its field's checks refuse one. */\nconst placeholder = (make: () => unknown): unknown => {\n try {\n return make()\n } catch {\n return undefined\n }\n}\n\n/**\n * The resumable builder for a view's `h`. Use it in place of `h`; it has the\n * same elements and attributes, and the hole forms of the four value events.\n */\nexport const builder = <Builder extends AnyBuilder>(\n h: Builder,\n): ResumableBuilder<MessageOf<Builder>> => {\n const cached = builders.get(h)\n if (cached !== undefined) return cached as ResumableBuilder<MessageOf<Builder>>\n const source = h as unknown as Record<string, unknown>\n const attribute = source.Attribute as (name: string, value: string) => unknown\n\n /** The attributes with a marker for each binding, while the server renders. */\n const mark = (tag: string, given: ReadonlyArray<Item>): ReadonlyArray<unknown> => {\n const kept = given.some(item => keeps.has(item))\n const attributes = kept ? given.filter(item => !keeps.has(item)) : given\n const now = current()\n if (now?.mode !== 'collect' && now?.mode !== 'replay') return attributes\n const id = attributes.find(\n (item): item is Extract<Attribute<unknown>, { readonly _tag: 'Id' }> =>\n isAttribute(item) && item._tag === 'Id',\n )\n const element = id === undefined ? tag : `${tag}#${id.value}`\n // Foldkit chains every handler of an event, in the order the attributes\n // come, so a marker lists every binding of its event in that order.\n const tokens = new Map<string, Array<string>>()\n // The ordinal of the element's hole-form `OnInput` and `OnChange`, which `KeepTyped` replays.\n const typed = new Map<string, number>()\n for (const item of attributes) {\n if (!isAttribute(item)) continue\n const event = item._tag === 'OnCustomEvent' ? item.name : EVENT_OF[item._tag]\n if (event === undefined) continue\n // Recorded for the refusal; the render does not survive it.\n if (now.mode === 'collect' && now.region !== undefined) {\n now.inStatic.push({ region: now.region, element, event })\n }\n const recorded = holes.get(item)\n const nested = now.depth === 0 ? {} : { depth: now.depth }\n const binding: Binding | undefined = !MARKABLE.has(item._tag)\n ? undefined\n : 'message' in item\n ? {\n attribute: item._tag,\n event,\n element,\n message: now.wrap(item.message),\n ...('options' in item && item.options !== undefined ? { options: item.options } : {}),\n }\n : recorded === undefined\n ? undefined\n : {\n attribute: item._tag,\n event,\n element,\n message: now.wrap(recorded.template),\n hole: recorded.hole,\n ...nested,\n }\n const list = tokens.get(event) ?? []\n tokens.set(event, list)\n if (binding === undefined) {\n // One entry per element and event, however many handlers it chains.\n if (now.mode === 'collect' && !list.includes(UNNAMED_HANDLER)) {\n now.unnamed.push({ element, event })\n }\n list.push(UNNAMED_HANDLER)\n } else {\n if (binding.hole !== undefined && !typed.has(binding.attribute)) {\n typed.set(binding.attribute, now.bindings.length)\n }\n list.push(String(now.bindings.length))\n now.bindings.push(binding)\n }\n }\n const markers = [...tokens].map(([event, list]) =>\n attribute(`${BINDING_ATTRIBUTE}${event}`, list.join(' ')),\n )\n if (kept) {\n const ordinal = typed.get('OnInput') ?? typed.get('OnChange')\n const type = attributes.find(\n (item): item is Extract<Attribute<unknown>, { readonly _tag: 'Type' }> =>\n isAttribute(item) && item._tag === 'Type',\n )?.value\n const field =\n tag === 'textarea' ||\n tag === 'select' ||\n (tag === 'input' && (type === undefined || !UNTYPED_INPUTS.has(type.toLowerCase())))\n if (!field) {\n if (now.mode === 'collect') {\n now.unkeepable.push(\n `KeepTyped on ${type === undefined ? element : `${element} of type ${type}`}, which holds no typed value: keep an input that takes text, a textarea or a select`,\n )\n }\n } else if (ordinal === undefined) {\n if (now.mode === 'collect') {\n now.unkeepable.push(\n `KeepTyped on ${element}, which has no OnInput or OnChange given a Message member, so nothing names the Message its typing replays as`,\n )\n }\n } else markers.push(attribute(KEEP_ATTRIBUTE, String(ordinal)))\n }\n return markers.length === 0 ? attributes : [...attributes, ...markers]\n }\n\n /**\n * A form whose `OnSubmit` names a Message, while the server renders for a\n * plan with a fallback, also posts that Message: `method=\"post\"` to its own\n * URL, and a hidden input carrying the Message encoded. Posted fields named\n * as the Message's own fields override them, so a typed title reaches\n * `update` as it would through the page. A form given its own `Method` is\n * the view's, left as drawn: a search is a GET of the address the URL\n * mirror reads, and posts no Message.\n */\n const fallback = (\n tag: string,\n attributes: ReadonlyArray<Item>,\n children: unknown,\n ): { readonly attributes: ReadonlyArray<Item>; readonly children: unknown } => {\n const now = current()\n if (\n tag !== 'form' ||\n now?.mode === undefined ||\n now.mode === 'resume' ||\n now.fallback === undefined\n ) {\n return { attributes, children }\n }\n const submit = attributes.find(\n (item): item is Extract<Attribute<unknown>, { readonly _tag: 'OnSubmit' }> =>\n isAttribute(item) && item._tag === 'OnSubmit',\n )\n const method = attributes.some(item => isAttribute(item) && item._tag === 'Method')\n if (submit === undefined || method || !Array.isArray(children)) return { attributes, children }\n const encoded = now.fallback(now.wrap(submit.message))\n if (encoded === undefined) return { attributes, children }\n const make = (name: string) => source[name] as (value: string) => Attribute<unknown>\n const input = source.input as (attributes: ReadonlyArray<unknown>) => unknown\n const hidden = (name: string, value: string) =>\n input([make('Type')('hidden'), make('Name')(name), make('Value')(value)])\n return {\n attributes: [...attributes, make('Method')('post')],\n children: [\n ...children,\n hidden(FALLBACK_FIELD, encoded),\n ...(now.depth === 0 ? [] : [hidden(FALLBACK_DEPTH_FIELD, String(now.depth))]),\n ],\n }\n }\n\n const textHole =\n (name: string) =>\n (given: unknown, fixed: Record<string, unknown> = {}): unknown => {\n const make = source[name] as (toMessage: (value: string) => unknown) => object\n if (!isMember(given)) return make(given as (value: string) => unknown)\n const hole = holeOf(given, fixed)\n if (hole.length !== 1) {\n throw new Error(\n `Resume.builder: ${name}(${tagOf(given)}) leaves ${hole.length === 0 ? 'no field' : hole.join(', ')} for the event to fill; it must leave one string field`,\n )\n }\n const [field] = hole as [string]\n const made = make(value => given({ ...fixed, [field]: value }))\n const template = placeholder(() => given({ ...fixed, [field]: '' }))\n // A field whose checks refuse the empty placeholder cannot be written\n // into the page as data; left unrecorded, the handler is marked as one\n // the page cannot name, and the live page answers it.\n if (template !== undefined) holes.set(made, { template, hole })\n return made\n }\n\n const keyHole =\n (name: string) =>\n (given: unknown, fixed: Record<string, unknown> = {}): unknown => {\n const make = source[name] as (\n toMessage: (key: string, modifiers: KeyboardModifiers) => unknown,\n ) => object\n if (!isMember(given)) {\n return make(given as (key: string, modifiers: KeyboardModifiers) => unknown)\n }\n const hole = holeOf(given, fixed)\n if (hole.length !== 2 || !hole.includes('key') || !hole.includes('modifiers')) {\n throw new Error(\n `Resume.builder: ${name}(${tagOf(given)}) leaves ${hole.join(', ') || 'no field'} for the event to fill; it must leave exactly key and modifiers`,\n )\n }\n const made = make((key, modifiers) => given({ ...fixed, key, modifiers }))\n const template = placeholder(() => given({ ...fixed, key: '', modifiers: NO_MODIFIERS }))\n if (template !== undefined) holes.set(made, { template, hole })\n return made\n }\n\n /**\n * `h.submodel` with the child's root stamped with its slot, while the\n * server renders: a boundary a tool can find, which the browser takes off\n * as the page boots, with the markers.\n */\n const submodel = (config: {\n readonly slotId: string\n readonly view: unknown\n readonly toParentMessage: (message: unknown) => unknown\n }): unknown => {\n const original = source.submodel as (config: unknown) => unknown\n const now = current()\n if (now?.mode !== 'collect' && now?.mode !== 'replay') return original(config)\n const view = config.view as (...args: ReadonlyArray<unknown>) => unknown\n const stamped = (...args: ReadonlyArray<unknown>) => {\n // A binding inside dispatches the parent's Message, as Foldkit's own\n // handlers do, so it is recorded lifted through this placement.\n const outer = { wrap: now.wrap, depth: now.depth }\n now.wrap = message => outer.wrap(config.toParentMessage(message))\n now.depth = outer.depth + 1\n let out: { data?: { attrs?: Record<string, unknown> } } | null\n try {\n out = view(...args) as typeof out\n } finally {\n now.wrap = outer.wrap\n now.depth = outer.depth\n }\n if (out !== null && typeof out === 'object' && out.data !== undefined) {\n out.data.attrs = { ...out.data.attrs, [SLOT_ATTRIBUTE]: config.slotId }\n }\n return out\n }\n // The view carries Foldkit's Submodel brand as an own property; keep it.\n return original({ ...config, view: Object.assign(stamped, view) })\n }\n\n const wrapped: Record<string, unknown> = {}\n for (const [name, value] of Object.entries(source)) {\n if (name === 'submodel') wrapped[name] = submodel\n else if (name === 'OnInput' || name === 'OnChange') wrapped[name] = textHole(name)\n else if (name === 'OnKeyDown' || name === 'OnKeyUp') wrapped[name] = keyHole(name)\n else if (name === 'keyed') {\n const keyed = value as (tag: string) => (key: PropertyKey, ...rest: Array<unknown>) => unknown\n wrapped[name] =\n (tag: string) =>\n (key: PropertyKey, attributes: ReadonlyArray<Item> = [], ...rest: Array<unknown>) => {\n const posted = fallback(tag, attributes, rest[0])\n return keyed(tag)(key, mark(tag, posted.attributes), posted.children, ...rest.slice(1))\n }\n } else if (/^[a-z]/.test(name) && typeof value === 'function') {\n const element = value as (\n attributes: ReadonlyArray<unknown>,\n ...rest: Array<unknown>\n ) => unknown\n wrapped[name] = (attributes: ReadonlyArray<Item>, ...rest: Array<unknown>) => {\n const posted = fallback(name, attributes, rest[0])\n return element(mark(name, posted.attributes), posted.children, ...rest.slice(1))\n }\n } else wrapped[name] = value\n }\n wrapped.KeepTyped = () => {\n // Written so during the server's first render: an element this builder\n // builds takes it out, so one left in the markup is on an element `h`\n // built, which nothing marks, and is refused there, naming the element.\n const made = attribute(KEEP_ATTRIBUTE, current()?.mode === 'collect' ? UNPLACED_KEEP : '')\n keeps.add(made as object)\n return made\n }\n builders.set(h, wrapped)\n return wrapped as unknown as ResumableBuilder<MessageOf<Builder>>\n}\n\n/**\n * A view or renderer written against the resumable builder, as one that takes\n * the builder it is given: `Surface.rootView(Page, params, Resume.view(render))`,\n * `SurfaceView.define`, or an application's own view.\n */\nexport const view =\n <Model, Builder extends AnyBuilder, Out>(\n render: (model: Model, rh: ResumableBuilder<MessageOf<Builder>>) => Out,\n ) =>\n (model: Model, h: Builder): Out =>\n render(model, builder(h))\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,MAAa,oBAAoB;;;;;;AAOjC,MAAa,WAA6C;CACxD,SAAS;CACT,eAAe;CACf,aAAa;CACb,WAAW;CACX,cAAc;CACd,cAAc;CACd,aAAa;CACb,YAAY;CACZ,aAAa;CACb,eAAe;CACf,gBAAgB;CAChB,eAAe;CACf,aAAa;CACb,WAAW;CACX,yBAAy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Q,IAAI;MAC5E,IAAI,SAAS,SAAS;EACzB,MAAM,QAAQ;EACd,QAAQ,SACL,SACA,KAAkB,aAAkC,CAAC,GAAG,GAAG,SAAyB;GACnF,MAAM,SAAS,SAAS,KAAK,YAAY,KAAK,EAAE;GAChD,OAAO,MAAM,GAAG,CAAC,CAAC,KAAK,KAAK,KAAK,OAAO,UAAU,GAAG,OAAO,UAAU,GAAG,KAAK,MAAM,CAAC,CAAC;EACxF;CACJ,OAAO,IAAI,SAAS,KAAK,IAAI,KAAK,OAAO,UAAU,YAAY;EAC7D,MAAM,UAAU;EAIhB,QAAQ,SAAS,YAAiC,GAAG,SAAyB;GAC5E,MAAM,SAAS,SAAS,MAAM,YAAY,KAAK,EAAE;GACjD,OAAO,QAAQ,KAAK,MAAM,OAAO,UAAU,GAAG,OAAO,UAAU,GAAG,KAAK,MAAM,CAAC,CAAC;EACjF;CACF,OAAO,QAAQ,QAAQ;CAEzB,QAAQ,kBAAkB;EAIxB,MAAM,OAAO,UAAU,gBAAgB,QAAQ,CAAC,EAAE,SAAS,YAAA,MAA4B,EAAE;EACzF,MAAM,IAAI,IAAc;EACxB,OAAO;CACT;CACA,SAAS,IAAI,GAAG,OAAO;CACvB,OAAO;AACT;;;;;;AAOA,MAAa,QAET,YAED,OAAc,MACb,OAAO,OAAO,QAAQ,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"resumable.js","names":[],"sources":["../src/resumable.ts"],"sourcesContent":["/**\n * The resumable builder: the application's `h`, whose event attributes say, in\n * the server's markup, which Message each element causes.\n *\n * A Foldkit handler is a Message value (`h.OnClick(Message.Liked({ id }))`), so\n * for most events that is already data. The events that carry a value\n * (`OnInput`, `OnChange`, `OnKeyDown`, `OnKeyUp`) take a closure only to put\n * the value into a Message field; this builder also takes the Message's own\n * constructor there, a Message with a hole, and fills the hole the same way.\n *\n * During the server's renders each binding gets an ordinal, recorded in render\n * order, and its element a `data-foldkit-plus-on-<event>` attribute naming it.\n * In the browser the builder marks nothing: it is the application's `h`, with\n * the hole forms turned into the closures Foldkit expects.\n */\nimport { Match, Schema, SchemaAST } from 'effect'\nimport type { Attribute, ChildAttribute, HtmlBuilder, KeyboardModifiers } from 'foldkit/html'\nimport { current, type Binding } from './context.js'\nimport { BINDING_ATTRIBUTE, KEEP_ATTRIBUTE } from './marks.js'\n\nexport { BINDING_ATTRIBUTE, KEEP_ATTRIBUTE } from './marks.js'\n\n/**\n * The DOM event each of Foldkit's event attributes listens to, read from\n * Foldkit's own attribute table (0.163). `OnCustomEvent` names its event in\n * its payload, and `OnMount` and `OnUnmount` listen to none.\n */\nexport const EVENT_OF: Readonly<Record<string, string>> = {\n OnClick: 'click',\n OnDoubleClick: 'dblclick',\n OnMouseDown: 'mousedown',\n OnMouseUp: 'mouseup',\n OnMouseEnter: 'mouseenter',\n OnMouseLeave: 'mouseleave',\n OnMouseOver: 'mouseover',\n OnMouseOut: 'mouseout',\n OnMouseMove: 'mousemove',\n OnPointerMove: 'pointermove',\n OnPointerLeave: 'pointerleave',\n OnPointerDown: 'pointerdown',\n OnPointerUp: 'pointerup',\n OnKeyDown: 'keydown',\n OnKeyDownPreventDefault: 'keydown',\n OnKeyDownSelf: 'keydown',\n OnKeyDownSelfPreventDefault: 'keydown',\n OnKeyDownFocus: 'keydown',\n OnKeyUp: 'keyup',\n OnKeyUpPreventDefault: 'keyup',\n OnKeyPress: 'keypress',\n OnFocus: 'focus',\n OnBlur: 'blur',\n OnFocusEnter: 'focusin',\n OnFocusLeave: 'focusout',\n OnInput: 'input',\n OnChange: 'change',\n OnBeforeInput: 'beforeinput',\n OnBeforeInputPreventDefault: 'beforeinput',\n OnFileChange: 'change',\n OnSubmit: 'submit',\n OnReset: 'reset',\n OnScroll: 'scroll',\n OnWheel: 'wheel',\n OnCopy: 'copy',\n OnCut: 'cut',\n OnPaste: 'paste',\n OnPastePreventDefault: 'paste',\n OnCopyText: 'copy',\n OnCutText: 'cut',\n OnCancel: 'cancel',\n OnCancelPreventDefault: 'cancel',\n OnToggle: 'toggle',\n OnContextMenu: 'contextmenu',\n OnDragStart: 'dragstart',\n OnDrag: 'drag',\n OnDragEnd: 'dragend',\n OnDragEnter: 'dragenter',\n OnDragLeave: 'dragleave',\n OnDragOver: 'dragover',\n OnDrop: 'drop',\n OnDropFiles: 'drop',\n OnTouchStart: 'touchstart',\n OnTouchEnd: 'touchend',\n OnTouchMove: 'touchmove',\n OnTouchCancel: 'touchcancel',\n OnAnimationStart: 'animationstart',\n OnAnimationEnd: 'animationend',\n OnAnimationIteration: 'animationiteration',\n OnTransitionEnd: 'transitionend',\n OnLoad: 'load',\n OnError: 'error',\n OnPlay: 'play',\n OnPause: 'pause',\n OnEnded: 'ended',\n OnTimeUpdate: 'timeupdate',\n OnVolumeChange: 'volumechange',\n OnSelect: 'select',\n}\n\n/**\n * The attributes whose binding the page can describe: a Message value, or one\n * of the hole forms this builder records. Any other handler still runs on the\n * live page, so its event is marked `*`: the page does something there it\n * cannot name, and a dispatcher that ran only the named bindings would do less.\n */\nconst MARKABLE: ReadonlySet<string> = new Set([\n 'OnClick',\n 'OnDoubleClick',\n 'OnMouseDown',\n 'OnMouseUp',\n 'OnMouseEnter',\n 'OnMouseLeave',\n 'OnMouseOver',\n 'OnMouseOut',\n 'OnMouseMove',\n 'OnFocus',\n 'OnBlur',\n 'OnSubmit',\n 'OnReset',\n 'OnInput',\n 'OnChange',\n 'OnKeyDown',\n 'OnKeyUp',\n])\n\n/** The token in a marker for a handler the page cannot describe. */\nexport const UNNAMED_HANDLER = '*'\n\n/** The posted field that carries a form's encoded Message, for the server fallback. */\nexport const FALLBACK_FIELD = 'foldkit-plus-message'\n\n/** The posted field that says how many placement wrappers the form's fields sit under. */\nexport const FALLBACK_DEPTH_FIELD = 'foldkit-plus-depth'\n\n/** The value of a `KeepTyped` marker no resumable element took, while the server renders. */\nexport const UNPLACED_KEEP = '?'\n\n/**\n * The `input` types that hold nothing a person types or ticks, so\n * `KeepTyped` has nothing to keep on them.\n */\nconst UNTYPED_INPUTS: ReadonlySet<string> = new Set([\n 'file',\n 'hidden',\n 'button',\n 'submit',\n 'reset',\n 'image',\n])\n\n/** The attribute on a placement's root naming its slot, while the server renders. */\nexport const SLOT_ATTRIBUTE = 'data-foldkit-plus-slot'\n\ndeclare const invalid: unique symbol\n\n/** A compile-time failure that names its cause. */\nexport interface Invalid<Message extends string> {\n readonly [invalid]: Message\n}\n\ntype IsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never\n\n/** A Message constructor from `defineMessageUnion`: a tagged Schema that can be called. */\ntype AnyMemberSchema = Schema.Top & { readonly fields: Schema.Struct.Fields }\n\n/** The Message a member makes. */\ntype Made<M> = M extends { readonly Type: infer T } ? T : never\n\n/** The fields a member's event may be given fixed: all but `_tag`. */\ntype Fixable<M> = Partial<Omit<Made<M>, '_tag'>>\n\n/** The fields of a member the event fills: those neither `_tag` nor fixed. */\ntype Rest<M, Fixed> = Omit<Made<M>, '_tag' | keyof Fixed>\n\ntype ProducesMessage<M, Message> = [Made<M>] extends [Message]\n ? unknown\n : Invalid<\"the member is not one of this view's Messages\">\n\ntype TextHoleCheck<M, Fixed> = [keyof Rest<M, Fixed>] extends [never]\n ? Invalid<'the member has no field left for the event to fill'>\n : true extends IsUnion<keyof Rest<M, Fixed>>\n ? Invalid<'the member leaves more than one field for the event to fill: fix the others'>\n : Rest<M, Fixed>[keyof Rest<M, Fixed>] extends string\n ? string extends Rest<M, Fixed>[keyof Rest<M, Fixed>]\n ? unknown\n : Invalid<'the field the event fills must be a string'>\n : Invalid<'the field the event fills must be a string'>\n\ntype KeyHoleCheck<M, Fixed> = [keyof Rest<M, Fixed>] extends ['key' | 'modifiers']\n ? ['key' | 'modifiers'] extends [keyof Rest<M, Fixed>]\n ? unknown\n : Invalid<'the member must leave exactly key and modifiers for the event to fill'>\n : Invalid<'the member must leave exactly key and modifiers for the event to fill'>\n\n/**\n * Foldkit's attribute of one tag, as its own builder returns it, so an\n * element that refuses some attributes (a `textarea`, `InnerHTML`) takes it.\n */\ntype Tagged<Message, Tag extends string> = Extract<Attribute<Message>, { readonly _tag: Tag }>\n\n/** `OnInput` and `OnChange`: a closure, or a member whose one string field the event fills. */\nexport interface TextHole<Message, Tag extends string> {\n (toMessage: (value: string) => Message): Tagged<Message, Tag>\n <M extends AnyMemberSchema, const Fixed extends Fixable<M> = {}>(\n member: M & ProducesMessage<M, Message> & TextHoleCheck<M, Fixed>,\n fixed?: Fixed,\n ): Tagged<Message, Tag>\n}\n\n/** `OnKeyDown` and `OnKeyUp`: a closure, or a member whose `key` and `modifiers` the event fills. */\nexport interface KeyHole<Message, Tag extends string> {\n (toMessage: (key: string, modifiers: KeyboardModifiers) => Message): Tagged<Message, Tag>\n <M extends AnyMemberSchema, const Fixed extends Fixable<M> = {}>(\n member: M & ProducesMessage<M, Message> & KeyHoleCheck<M, Fixed>,\n fixed?: Fixed,\n ): Tagged<Message, Tag>\n}\n\n/**\n * A builder a view is given: Foldkit's `HtmlBuilder`, or a Surface renderer's,\n * which leaves out Foldkit's phantom key. Its Message is what `OnClick` takes.\n */\nexport type AnyBuilder = {\n readonly OnClick: (message: never, ...rest: ReadonlyArray<never>) => unknown\n}\n\n/** The Message a builder's handlers make. */\nexport type MessageOf<Builder> = Builder extends {\n readonly OnClick: (message: infer Message, ...rest: ReadonlyArray<never>) => unknown\n}\n ? Message\n : never\n\n/**\n * The resumable builder for a view whose Messages are `Message`: its elements\n * and attributes, and the hole forms of the four value events. One shape\n * whether it wraps a view's `HtmlBuilder` or a Surface renderer's builder, so a\n * helper typed with it takes either. It keeps Foldkit's phantom Message key,\n * so a placement's view accepts it as the parent's builder.\n */\nexport type ResumableBuilder<Message> = Omit<\n HtmlBuilder<Message>,\n 'OnInput' | 'OnChange' | 'OnKeyDown' | 'OnKeyUp'\n> & {\n readonly OnInput: TextHole<Message, 'OnInput'>\n readonly OnChange: TextHole<Message, 'OnChange'>\n readonly OnKeyDown: KeyHole<Message, 'OnKeyDown'>\n readonly OnKeyUp: KeyHole<Message, 'OnKeyUp'>\n /**\n * Keeps what is typed into this field before the runtime starts: the\n * browser replays it as the field's `OnInput` Message (else its\n * `OnChange`), given in the hole form, and keeps the caret. The field must\n * be an `input` that takes text, a `textarea` or a `select`; or a\n * checkbox or radio, whose ticking replays its `OnChange` (else `OnInput`,\n * else `OnClick`) Message, in either form. On a plan whose `start` is not\n * `'now'`, a field with such a binding and no `KeepTyped` is refused\n * (`UnkeptField`).\n */\n readonly KeepTyped: () => Tagged<Message, 'Attribute'>\n}\n\ntype AnyMember = ((value: Record<string, unknown>) => unknown) & {\n readonly fields: Readonly<Record<string, unknown>>\n}\n\nconst isMember = (value: unknown): value is AnyMember =>\n typeof value === 'function' && typeof (value as { fields?: unknown }).fields === 'object'\n\nconst tagOf = (member: AnyMember): string => {\n const tag = member.fields._tag\n return Schema.isSchema(tag) && SchemaAST.isLiteral(tag.ast) && typeof tag.ast.literal === 'string'\n ? tag.ast.literal\n : 'the member'\n}\n\n/**\n * The fields a member leaves for the event to fill, given what is fixed. Only\n * `fixed`'s own keys fix a field: `in` finds `constructor` on every object.\n */\nconst holeOf = (member: AnyMember, fixed: object): ReadonlyArray<string> =>\n Object.keys(member.fields).filter(field => field !== '_tag' && !Object.hasOwn(fixed, field))\n\nconst NO_MODIFIERS: KeyboardModifiers = {\n shiftKey: false,\n ctrlKey: false,\n altKey: false,\n metaKey: false,\n}\n\n/** Each hole-form attribute, with its Message filled by a placeholder and the fields the event fills. */\nconst holes = new WeakMap<\n object,\n { readonly template: unknown; readonly hole: ReadonlyArray<string> }\n>()\n\n/** What an element is given: Foldkit's attributes, and a Submodel's wrapped ones, which carry no tag. */\ntype Item = Attribute<unknown> | ChildAttribute\n\nconst isAttribute = (item: Item): item is Attribute<unknown> => '_tag' in item\n\n// Built once: a matcher made in `mark` would be rebuilt for every attribute of every element.\nconst eventOf = Match.type<Attribute<unknown>>().pipe(\n Match.tag('OnCustomEvent', custom => custom.name),\n Match.orElse((other): string | undefined => EVENT_OF[other._tag]),\n)\n\nconst builders = new WeakMap<object, unknown>()\n\n/** Each attribute `KeepTyped` made: a request to the element it is given, never written as it is. */\nconst keeps = new WeakSet<object>()\n\n/** A hole form's placeholder Message, or `undefined` when its field's checks refuse one. */\nconst placeholder = (make: () => unknown): unknown => {\n try {\n return make()\n } catch {\n return undefined\n }\n}\n\n/**\n * The resumable builder for a view's `h`. Use it in place of `h`; it has the\n * same elements and attributes, and the hole forms of the four value events.\n */\nexport const builder = <Builder extends AnyBuilder>(\n h: Builder,\n): ResumableBuilder<MessageOf<Builder>> => {\n const cached = builders.get(h)\n if (cached !== undefined) return cached as ResumableBuilder<MessageOf<Builder>>\n const source = h as unknown as Record<string, unknown>\n const attribute = source.Attribute as (name: string, value: string) => unknown\n\n /** The attributes with a marker for each binding, while the server renders. */\n const mark = (tag: string, given: ReadonlyArray<Item>): ReadonlyArray<unknown> => {\n const kept = given.some(item => keeps.has(item))\n const attributes = kept ? given.filter(item => !keeps.has(item)) : given\n const now = current()\n if (now?.mode !== 'collect' && now?.mode !== 'replay') return attributes\n const id = attributes.find(\n (item): item is Extract<Attribute<unknown>, { readonly _tag: 'Id' }> =>\n isAttribute(item) && item._tag === 'Id',\n )\n const element = id === undefined ? tag : `${tag}#${id.value}`\n // Foldkit chains every handler of an event, in the order the attributes\n // come, so a marker lists every binding of its event in that order.\n const tokens = new Map<string, Array<string>>()\n // The ordinal of the element's hole-form `OnInput` and `OnChange`, which\n // `KeepTyped` replays for a typed value, and of each attribute's first\n // binding: a checkbox or radio replays its `OnChange`, `OnInput` or\n // `OnClick` in either form, since what it holds is `checked`, which no\n // hole carries.\n const typed = new Map<string, number>()\n const named = new Map<string, number>()\n for (const item of attributes) {\n if (!isAttribute(item)) continue\n const event = eventOf(item)\n if (event === undefined) continue\n // Recorded for the refusal; the render does not survive it.\n if (now.mode === 'collect' && now.region !== undefined) {\n now.inStatic.push({ region: now.region, element, event })\n }\n const recorded = holes.get(item)\n const nested = now.depth === 0 ? {} : { depth: now.depth }\n const binding: Binding | undefined = !MARKABLE.has(item._tag)\n ? undefined\n : 'message' in item\n ? {\n attribute: item._tag,\n event,\n element,\n message: now.wrap(item.message),\n ...('options' in item && item.options !== undefined ? { options: item.options } : {}),\n }\n : recorded === undefined\n ? undefined\n : {\n attribute: item._tag,\n event,\n element,\n message: now.wrap(recorded.template),\n hole: recorded.hole,\n ...nested,\n }\n const list = tokens.get(event) ?? []\n tokens.set(event, list)\n if (binding === undefined) {\n // One entry per element and event, however many handlers it chains.\n if (now.mode === 'collect' && !list.includes(UNNAMED_HANDLER)) {\n now.unnamed.push({ element, event })\n }\n list.push(UNNAMED_HANDLER)\n } else {\n if (binding.hole !== undefined && !typed.has(binding.attribute)) {\n typed.set(binding.attribute, now.bindings.length)\n }\n if (!named.has(binding.attribute)) named.set(binding.attribute, now.bindings.length)\n list.push(String(now.bindings.length))\n now.bindings.push(binding)\n }\n }\n const markers = [...tokens].map(([event, list]) =>\n attribute(`${BINDING_ATTRIBUTE}${event}`, list.join(' ')),\n )\n const type = attributes\n .find(\n (item): item is Extract<Attribute<unknown>, { readonly _tag: 'Type' }> =>\n isAttribute(item) && item._tag === 'Type',\n )\n ?.value.toLowerCase()\n const checkable = tag === 'input' && (type === 'checkbox' || type === 'radio')\n const field =\n tag === 'textarea' ||\n tag === 'select' ||\n (tag === 'input' && (type === undefined || !UNTYPED_INPUTS.has(type)))\n const ordinal = checkable\n ? (named.get('OnChange') ?? named.get('OnInput') ?? named.get('OnClick'))\n : (typed.get('OnInput') ?? typed.get('OnChange'))\n if (kept) {\n if (!field) {\n if (now.mode === 'collect') {\n now.unkeepable.push(\n `KeepTyped on ${type === undefined ? element : `${element} of type ${type}`}, which holds nothing typed or ticked: keep an input that takes text, a checkbox, a radio, a textarea or a select`,\n )\n }\n } else if (ordinal === undefined) {\n if (now.mode === 'collect') {\n now.unkeepable.push(\n `KeepTyped on ${element}, which has no ${checkable ? 'OnChange, OnInput or OnClick naming a Message' : 'OnInput or OnChange given a Message member'}, so nothing names the Message its typing replays as`,\n )\n }\n } else markers.push(attribute(KEEP_ATTRIBUTE, String(ordinal)))\n } else if (field && ordinal !== undefined && now.mode === 'collect') {\n // Refused by the server for a plan that does not start now: what is\n // typed before such a page boots would be lost at its first render.\n now.unkept.push(element)\n }\n return markers.length === 0 ? attributes : [...attributes, ...markers]\n }\n\n /**\n * A form whose `OnSubmit` names a Message, while the server renders for a\n * plan with a fallback, also posts that Message: `method=\"post\"` to its own\n * URL, and a hidden input carrying the Message encoded. Posted fields named\n * as the Message's own fields override them, so a typed title reaches\n * `update` as it would through the page. A form given its own `Method` is\n * the view's, left as drawn: a search is a GET of the address the URL\n * mirror reads, and posts no Message.\n */\n const fallback = (\n tag: string,\n attributes: ReadonlyArray<Item>,\n children: unknown,\n ): { readonly attributes: ReadonlyArray<Item>; readonly children: unknown } => {\n const now = current()\n if (\n tag !== 'form' ||\n now?.mode === undefined ||\n now.mode === 'resume' ||\n now.fallback === undefined\n ) {\n return { attributes, children }\n }\n const submit = attributes.find(\n (item): item is Extract<Attribute<unknown>, { readonly _tag: 'OnSubmit' }> =>\n isAttribute(item) && item._tag === 'OnSubmit',\n )\n const method = attributes.some(item => isAttribute(item) && item._tag === 'Method')\n if (submit === undefined || method || !Array.isArray(children)) return { attributes, children }\n const encoded = now.fallback(now.wrap(submit.message))\n if (encoded === undefined) return { attributes, children }\n const make = (name: string) => source[name] as (value: string) => Attribute<unknown>\n const input = source.input as (attributes: ReadonlyArray<unknown>) => unknown\n const hidden = (name: string, value: string) =>\n input([make('Type')('hidden'), make('Name')(name), make('Value')(value)])\n return {\n attributes: [...attributes, make('Method')('post')],\n children: [\n ...children,\n hidden(FALLBACK_FIELD, encoded),\n ...(now.depth === 0 ? [] : [hidden(FALLBACK_DEPTH_FIELD, String(now.depth))]),\n ],\n }\n }\n\n const textHole =\n (name: string) =>\n (given: unknown, fixed: Record<string, unknown> = {}): unknown => {\n const make = source[name] as (toMessage: (value: string) => unknown) => object\n if (!isMember(given)) return make(given as (value: string) => unknown)\n const hole = holeOf(given, fixed)\n if (hole.length !== 1) {\n throw new Error(\n `Resume.builder: ${name}(${tagOf(given)}) leaves ${hole.length === 0 ? 'no field' : hole.join(', ')} for the event to fill; it must leave one string field`,\n )\n }\n const [field] = hole as [string]\n const made = make(value => given({ ...fixed, [field]: value }))\n const template = placeholder(() => given({ ...fixed, [field]: '' }))\n // A field whose checks refuse the empty placeholder cannot be written\n // into the page as data; left unrecorded, the handler is marked as one\n // the page cannot name, and the live page answers it.\n if (template !== undefined) holes.set(made, { template, hole })\n return made\n }\n\n const keyHole =\n (name: string) =>\n (given: unknown, fixed: Record<string, unknown> = {}): unknown => {\n const make = source[name] as (\n toMessage: (key: string, modifiers: KeyboardModifiers) => unknown,\n ) => object\n if (!isMember(given)) {\n return make(given as (key: string, modifiers: KeyboardModifiers) => unknown)\n }\n const hole = holeOf(given, fixed)\n if (hole.length !== 2 || !hole.includes('key') || !hole.includes('modifiers')) {\n throw new Error(\n `Resume.builder: ${name}(${tagOf(given)}) leaves ${hole.join(', ') || 'no field'} for the event to fill; it must leave exactly key and modifiers`,\n )\n }\n const made = make((key, modifiers) => given({ ...fixed, key, modifiers }))\n const template = placeholder(() => given({ ...fixed, key: '', modifiers: NO_MODIFIERS }))\n if (template !== undefined) holes.set(made, { template, hole })\n return made\n }\n\n /**\n * `h.submodel` with the child's root stamped with its slot, while the\n * server renders: a boundary a tool can find, which the browser takes off\n * as the page boots, with the markers.\n */\n const submodel = (config: {\n readonly slotId: string\n readonly view: unknown\n readonly toParentMessage: (message: unknown) => unknown\n }): unknown => {\n const original = source.submodel as (config: unknown) => unknown\n const now = current()\n if (now?.mode !== 'collect' && now?.mode !== 'replay') return original(config)\n const view = config.view as (...args: ReadonlyArray<unknown>) => unknown\n const stamped = (...args: ReadonlyArray<unknown>) => {\n // A binding inside dispatches the parent's Message, as Foldkit's own\n // handlers do, so it is recorded lifted through this placement.\n const outer = { wrap: now.wrap, depth: now.depth }\n now.wrap = message => outer.wrap(config.toParentMessage(message))\n now.depth = outer.depth + 1\n let out: { data?: { attrs?: Record<string, unknown> } } | null\n try {\n out = view(...args) as typeof out\n } finally {\n now.wrap = outer.wrap\n now.depth = outer.depth\n }\n if (out !== null && typeof out === 'object' && out.data !== undefined) {\n out.data.attrs = { ...out.data.attrs, [SLOT_ATTRIBUTE]: config.slotId }\n }\n return out\n }\n // The view carries Foldkit's Submodel brand as an own property; keep it.\n return original({ ...config, view: Object.assign(stamped, view) })\n }\n\n const wrapped: Record<string, unknown> = {}\n for (const [name, value] of Object.entries(source)) {\n if (name === 'submodel') wrapped[name] = submodel\n else if (name === 'OnInput' || name === 'OnChange') wrapped[name] = textHole(name)\n else if (name === 'OnKeyDown' || name === 'OnKeyUp') wrapped[name] = keyHole(name)\n else if (name === 'keyed') {\n const keyed = value as (tag: string) => (key: PropertyKey, ...rest: Array<unknown>) => unknown\n wrapped[name] =\n (tag: string) =>\n (key: PropertyKey, attributes: ReadonlyArray<Item> = [], ...rest: Array<unknown>) => {\n const posted = fallback(tag, attributes, rest[0])\n return keyed(tag)(key, mark(tag, posted.attributes), posted.children, ...rest.slice(1))\n }\n } else if (/^[a-z]/.test(name) && typeof value === 'function') {\n const element = value as (\n attributes: ReadonlyArray<unknown>,\n ...rest: Array<unknown>\n ) => unknown\n wrapped[name] = (attributes: ReadonlyArray<Item>, ...rest: Array<unknown>) => {\n const posted = fallback(name, attributes, rest[0])\n return element(mark(name, posted.attributes), posted.children, ...rest.slice(1))\n }\n } else wrapped[name] = value\n }\n wrapped.KeepTyped = () => {\n // Written so during the server's first render: an element this builder\n // builds takes it out, so one left in the markup is on an element `h`\n // built, which nothing marks, and is refused there, naming the element.\n const made = attribute(KEEP_ATTRIBUTE, current()?.mode === 'collect' ? UNPLACED_KEEP : '')\n keeps.add(made as object)\n return made\n }\n builders.set(h, wrapped)\n return wrapped as unknown as ResumableBuilder<MessageOf<Builder>>\n}\n\n/**\n * A view or renderer written against the resumable builder, as one that takes\n * the builder it is given: `Surface.rootView(Page, params, Resume.view(render))`,\n * `SurfaceView.define`, or an application's own view.\n */\nexport const view =\n <Model, Builder extends AnyBuilder, Out>(\n render: (model: Model, rh: ResumableBuilder<MessageOf<Builder>>) => Out,\n ) =>\n (model: Model, h: Builder): Out =>\n render(model, builder(h))\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,WAA6C;CACxD,SAAS;CACT,eAAe;CACf,aAAa;CACb,WAAW;CACX,cAAc;CACd,cAAc;CACd,aAAa;CACb,YAAY;CACZ,aAAa;CACb,eAAe;CACf,gBAAgB;CAChB,eAAe;CACf,aAAa;CACb,WAAW;CACX,yBAAyB;CACzB,eAAe;CACf,6BAA6B;CAC7B,gBAAgB;CAChB,SAAS;CACT,uBAAuB;CACvB,YAAY;CACZ,SAAS;CACT,QAAQ;CACR,cAAc;CACd,cAAc;CACd,SAAS;CACT,UAAU;CACV,eAAe;CACf,6BAA6B;CAC7B,cAAc;CACd,UAAU;CACV,SAAS;CACT,UAAU;CACV,SAAS;CACT,QAAQ;CACR,OAAO;CACP,SAAS;CACT,uBAAuB;CACvB,YAAY;CACZ,WAAW;CACX,UAAU;CACV,wBAAwB;CACxB,UAAU;CACV,eAAe;CACf,aAAa;CACb,QAAQ;CACR,WAAW;CACX,aAAa;CACb,aAAa;CACb,YAAY;CACZ,QAAQ;CACR,aAAa;CACb,cAAc;CACd,YAAY;CACZ,aAAa;CACb,eAAe;CACf,kBAAkB;CAClB,gBAAgB;CAChB,sBAAsB;CACtB,iBAAiB;CACjB,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,SAAS;CACT,SAAS;CACT,cAAc;CACd,gBAAgB;CAChB,UAAU;AACZ;;;;;;;AAQA,MAAM,2BAAgC,IAAI,IAAI;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,MAAa,kBAAkB;;AAG/B,MAAa,iBAAiB;;AAG9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AQ,SAAS,YAAiC,GAAG,SAAyB;GAC5E,MAAM,SAAS,SAAS,MAAM,YAAY,KAAK,EAAE;GACjD,OAAO,QAAQ,KAAK,MAAM,OAAO,UAAU,GAAG,OAAO,UAAU,GAAG,KAAK,MAAM,CAAC,CAAC;EACjF;CACF,OAAO,QAAQ,QAAQ;CAEzB,QAAQ,kBAAkB;EAIxB,MAAM,OAAO,UAAU,gBAAgB,QAAQ,CAAC,EAAE,SAAS,YAAA,MAA4B,EAAE;EACzF,MAAM,IAAI,IAAc;EACxB,OAAO;CACT;CACA,SAAS,IAAI,GAAG,OAAO;CACvB,OAAO;AACT;;;;;;AAOA,MAAa,QAET,YAED,OAAc,MACb,OAAO,OAAO,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
/**
|
|
3
|
+
* Emits `entry`, the module the loader's `runtime` imports, as a chunk of
|
|
4
|
+
* the client build, and writes that chunk's address into the loader. The
|
|
5
|
+
* chunk is the one the dynamic import loads: the bundler gives one module
|
|
6
|
+
* one chunk. A development server and a server build leave the loader
|
|
7
|
+
* without an address, and it fetches the chunk as it runs it.
|
|
8
|
+
*/
|
|
9
|
+
export declare const runtimeChunk: (options: {
|
|
10
|
+
/** The runtime's module, root-relative (`/src/client/entry.ts`), as the loader imports it. */
|
|
11
|
+
readonly entry: string;
|
|
12
|
+
}) => Plugin;
|
|
13
|
+
//# sourceMappingURL=runtimeChunk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeChunk.d.ts","names":[],"sources":["../src/runtimeChunk.ts"],"mappings":";;;;;;;;qBAkBa,eAAY;;WAEd;MACP"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/runtimeChunk.ts
|
|
2
|
+
/** `runtimeUrl`'s placeholder, as `runtimeUrl.ts` gives it, in either quote. */
|
|
3
|
+
const PLACEHOLDER = /(\bruntimeUrl(?:\s*:\s*string)?\s*=\s*)(['"])foldkit-ssr:runtime-url\2/;
|
|
4
|
+
/**
|
|
5
|
+
* Emits `entry`, the module the loader's `runtime` imports, as a chunk of
|
|
6
|
+
* the client build, and writes that chunk's address into the loader. The
|
|
7
|
+
* chunk is the one the dynamic import loads: the bundler gives one module
|
|
8
|
+
* one chunk. A development server and a server build leave the loader
|
|
9
|
+
* without an address, and it fetches the chunk as it runs it.
|
|
10
|
+
*/
|
|
11
|
+
const runtimeChunk = (options) => {
|
|
12
|
+
let reference;
|
|
13
|
+
return {
|
|
14
|
+
name: "foldkit-ssr:runtime-chunk",
|
|
15
|
+
apply: "build",
|
|
16
|
+
applyToEnvironment: (environment) => environment.name === "client",
|
|
17
|
+
async buildStart() {
|
|
18
|
+
const resolved = await this.resolve(options.entry);
|
|
19
|
+
if (resolved === null) throw new Error(`foldkit-ssr: runtimeChunk cannot resolve its entry ${options.entry}`);
|
|
20
|
+
reference = this.emitFile({
|
|
21
|
+
type: "chunk",
|
|
22
|
+
id: resolved.id
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
transform(code) {
|
|
26
|
+
if (reference === void 0 || !PLACEHOLDER.test(code)) return null;
|
|
27
|
+
return {
|
|
28
|
+
code: code.replace(PLACEHOLDER, `$1import.meta.ROLLUP_FILE_URL_${reference}`),
|
|
29
|
+
map: null
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export { runtimeChunk };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=runtimeChunk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeChunk.js","names":[],"sources":["../src/runtimeChunk.ts"],"sourcesContent":["/**\n * `runtimeChunk`, from `foldkit-ssr/vite`: tells `foldkit-ssr/loader` where a\n * client build put the runtime's chunk, so the loader can fetch it without\n * running it. Kept apart from the static site's plugin, which imports the\n * server renderer, so a config can import this one by path.\n */\nimport type { Plugin } from 'vite'\n\n/** `runtimeUrl`'s placeholder, as `runtimeUrl.ts` gives it, in either quote. */\nconst PLACEHOLDER = /(\\bruntimeUrl(?:\\s*:\\s*string)?\\s*=\\s*)(['\"])foldkit-ssr:runtime-url\\2/\n\n/**\n * Emits `entry`, the module the loader's `runtime` imports, as a chunk of\n * the client build, and writes that chunk's address into the loader. The\n * chunk is the one the dynamic import loads: the bundler gives one module\n * one chunk. A development server and a server build leave the loader\n * without an address, and it fetches the chunk as it runs it.\n */\nexport const runtimeChunk = (options: {\n /** The runtime's module, root-relative (`/src/client/entry.ts`), as the loader imports it. */\n readonly entry: string\n}): Plugin => {\n let reference: string | undefined\n return {\n name: 'foldkit-ssr:runtime-chunk',\n apply: 'build',\n applyToEnvironment: environment => environment.name === 'client',\n async buildStart() {\n const resolved = await this.resolve(options.entry)\n if (resolved === null) {\n throw new Error(`foldkit-ssr: runtimeChunk cannot resolve its entry ${options.entry}`)\n }\n reference = this.emitFile({ type: 'chunk', id: resolved.id })\n },\n transform(code) {\n if (reference === undefined || !PLACEHOLDER.test(code)) return null\n return {\n code: code.replace(PLACEHOLDER, `$1import.meta.ROLLUP_FILE_URL_${reference}`),\n map: null,\n }\n },\n }\n}\n"],"mappings":";;AASA,MAAM,cAAc;;;;;;;;AASpB,MAAa,gBAAgB,YAGf;CACZ,IAAI;CACJ,OAAO;EACL,MAAM;EACN,OAAO;EACP,qBAAoB,gBAAe,YAAY,SAAS;EACxD,MAAM,aAAa;GACjB,MAAM,WAAW,MAAM,KAAK,QAAQ,QAAQ,KAAK;GACjD,IAAI,aAAa,MACf,MAAM,IAAI,MAAM,sDAAsD,QAAQ,OAAO;GAEvF,YAAY,KAAK,SAAS;IAAE,MAAM;IAAS,IAAI,SAAS;GAAG,CAAC;EAC9D;EACA,UAAU,MAAM;GACd,IAAI,cAAc,KAAA,KAAa,CAAC,YAAY,KAAK,IAAI,GAAG,OAAO;GAC/D,OAAO;IACL,MAAM,KAAK,QAAQ,aAAa,iCAAiC,WAAW;IAC5E,KAAK;GACP;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The runtime chunk's built address, for `foldkit-ssr/loader` to fetch
|
|
3
|
+
* without running it. `runtimeChunk` from `foldkit-ssr/vite` replaces the
|
|
4
|
+
* string `runtimeUrl` is given in a client build with the address the
|
|
5
|
+
* bundler gives the chunk; anywhere else it stays `UNBUILT`, and the loader
|
|
6
|
+
* fetches nothing early. Imports nothing, as the loader must not.
|
|
7
|
+
*/
|
|
8
|
+
export declare const UNBUILT = "foldkit-ssr:runtime-url";
|
|
9
|
+
export declare const runtimeUrl: string;
|
|
10
|
+
//# sourceMappingURL=runtimeUrl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeUrl.d.ts","names":[],"sources":["../src/runtimeUrl.ts"],"mappings":";;;;;;;qBAOa;qBAEA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/runtimeUrl.ts
|
|
2
|
+
/**
|
|
3
|
+
* The runtime chunk's built address, for `foldkit-ssr/loader` to fetch
|
|
4
|
+
* without running it. `runtimeChunk` from `foldkit-ssr/vite` replaces the
|
|
5
|
+
* string `runtimeUrl` is given in a client build with the address the
|
|
6
|
+
* bundler gives the chunk; anywhere else it stays `UNBUILT`, and the loader
|
|
7
|
+
* fetches nothing early. Imports nothing, as the loader must not.
|
|
8
|
+
*/
|
|
9
|
+
const UNBUILT = "foldkit-ssr:runtime-url";
|
|
10
|
+
const runtimeUrl = "foldkit-ssr:runtime-url";
|
|
11
|
+
export { UNBUILT, runtimeUrl };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=runtimeUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeUrl.js","names":[],"sources":["../src/runtimeUrl.ts"],"sourcesContent":["/**\n * The runtime chunk's built address, for `foldkit-ssr/loader` to fetch\n * without running it. `runtimeChunk` from `foldkit-ssr/vite` replaces the\n * string `runtimeUrl` is given in a client build with the address the\n * bundler gives the chunk; anywhere else it stays `UNBUILT`, and the loader\n * fetches nothing early. Imports nothing, as the loader must not.\n */\nexport const UNBUILT = 'foldkit-ssr:runtime-url'\n\nexport const runtimeUrl: string = 'foldkit-ssr:runtime-url'\n"],"mappings":";;;;;;;;AAOA,MAAa,UAAU;AAEvB,MAAa,aAAqB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as DecodedBinding } from "./listen-
|
|
1
|
+
import { n as DecodedBinding } from "./listen-7HzKBhqU.js";
|
|
2
2
|
import { Cause, Effect, Layer, Option, Result, Schema, Stream } from "effect";
|
|
3
|
-
import { ActiveSurface, Diagnostic, Metadata, ModelPlace, ReportDiagnostic, SurfaceSource, WritableProjection } from "foldkit-surface";
|
|
4
|
-
import { Html, HtmlBuilder } from "foldkit/html";
|
|
3
|
+
import { ActiveSurface, Diagnostic, Metadata, ModelPlace, ModelRef, ReportDiagnostic, SurfaceSource, WritableProjection } from "foldkit-surface";
|
|
4
|
+
import { Attribute, ChildAttribute, Html, HtmlBuilder } from "foldkit/html";
|
|
5
5
|
import { Runtime } from "foldkit";
|
|
6
6
|
import { Ports } from "foldkit/port";
|
|
7
7
|
/** A served page the browser contained instead of resuming: it stays in view, inert, and no runtime starts. */
|
|
@@ -36,8 +36,28 @@ interface HandlerUnnamed extends Diagnostic {
|
|
|
36
36
|
readonly element: string;
|
|
37
37
|
readonly event: string;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* A kept page drawn otherwise for the request it served (`SSR.entry`'s
|
|
41
|
+
* `cache.check`): the render read something of the request, or anything
|
|
42
|
+
* else that differs between requests, that the cache could not see. The
|
|
43
|
+
* request was given the page drawn again.
|
|
44
|
+
*/
|
|
45
|
+
interface CachedPageDiffers extends Diagnostic {
|
|
46
|
+
readonly _tag: 'CachedPageDiffers';
|
|
47
|
+
readonly url: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A served page whose head markup (a plan's `meta`) was still in its body:
|
|
51
|
+
* the host's document renderer is not wrapped in `SSR.headed`, so link
|
|
52
|
+
* previews and crawlers, which read the served head, never saw it.
|
|
53
|
+
* `SSR.hydrate` removed it; the head gets it once the page runs.
|
|
54
|
+
*/
|
|
55
|
+
interface HeadNotMoved extends Diagnostic {
|
|
56
|
+
readonly _tag: 'HeadNotMoved';
|
|
57
|
+
}
|
|
39
58
|
/** Every diagnostic SSR reports. */
|
|
40
|
-
type SsrDiagnostic = PageContained | StaticRegionMissing | BundleUnloaded | PageFailed | HandlerUnnamed;
|
|
59
|
+
type SsrDiagnostic = PageContained | StaticRegionMissing | BundleUnloaded | PageFailed | HandlerUnnamed | CachedPageDiffers | HeadNotMoved;
|
|
60
|
+
declare const headNotMoved: HeadNotMoved;
|
|
41
61
|
declare const pageContained: (reason: PageContained['reason'], detail: string) => PageContained;
|
|
42
62
|
declare const noBuildId: PageContained;
|
|
43
63
|
/** The page's stamped build id, if it has one, is not the client's `client`. */
|
|
@@ -48,6 +68,7 @@ declare const pageFailed: (url: string, cause: Cause.Cause<unknown>) => PageFail
|
|
|
48
68
|
declare const handlerUnnamed: (plan: string, element: string, event: string) => HandlerUnnamed;
|
|
49
69
|
/** `effect` reporting to `report` when one is given, else to the reporter in its context. */
|
|
50
70
|
declare const reportingTo: (report: ReportDiagnostic | undefined) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
71
|
+
declare const cachedPageDiffers: (url: string) => CachedPageDiffers;
|
|
51
72
|
type Region = ReadonlyArray<Html | string>;
|
|
52
73
|
/** An element whose handler for `event` is a function, which the page cannot describe. */
|
|
53
74
|
interface UnnamedHandler {
|
|
@@ -95,6 +116,8 @@ type RenderContext = {
|
|
|
95
116
|
readonly unnamed: Array<UnnamedHandler>;
|
|
96
117
|
/** Why each `KeepTyped` field met cannot be replayed, one line each. */
|
|
97
118
|
readonly unkeepable: Array<string>;
|
|
119
|
+
/** Each field with a binding that names its typing and no `KeepTyped`. */
|
|
120
|
+
readonly unkept: Array<string>;
|
|
98
121
|
} | {
|
|
99
122
|
readonly mode: 'replay';
|
|
100
123
|
readonly regions: ReadonlyMap<string, Region>;
|
|
@@ -116,18 +139,6 @@ declare const within: <A>(next: RenderContext, run: () => A) => A;
|
|
|
116
139
|
declare const withContext: <Config extends {
|
|
117
140
|
readonly view: (model: any, h: any) => unknown;
|
|
118
141
|
}>(config: Config, next: RenderContext) => Config;
|
|
119
|
-
/**
|
|
120
|
-
* The attribute Foldkit's server stamps on an application's root, as
|
|
121
|
-
* `foldkit/experimental/server` exports it. Written out here so a page can
|
|
122
|
-
* find its root without that module; a test pins the two together.
|
|
123
|
-
*/
|
|
124
|
-
declare const FOLDKIT_APP_ATTRIBUTE = "data-foldkit-app";
|
|
125
|
-
/**
|
|
126
|
-
* The attribute on the stamped root that carries a page's resume envelope.
|
|
127
|
-
* Foldkit pairs its own handoff the same way: the build id rides on the root
|
|
128
|
-
* beside the app stamp, and the client reads it before adopting anything.
|
|
129
|
-
*/
|
|
130
|
-
declare const RESUME_ATTRIBUTE = "data-foldkit-plus-resume";
|
|
131
142
|
/** The envelope format this package writes and reads. */
|
|
132
143
|
declare const PROTOCOL = 1;
|
|
133
144
|
/**
|
|
@@ -136,6 +147,14 @@ declare const PROTOCOL = 1;
|
|
|
136
147
|
* follows it into the head before adopting the page.
|
|
137
148
|
*/
|
|
138
149
|
declare const STYLES_MARKER = "foldkit-plus-styles";
|
|
150
|
+
/**
|
|
151
|
+
* The comments a dynamically served page's head markup (a plan's `meta`)
|
|
152
|
+
* sits between in the stamped root, until the host's `SSR.headed` moves it
|
|
153
|
+
* before `</head>`. Left in the body, `SSR.hydrate` removes it and reports
|
|
154
|
+
* `HeadNotMoved`.
|
|
155
|
+
*/
|
|
156
|
+
declare const HEAD_MARKER = "foldkit-plus-head";
|
|
157
|
+
declare const HEAD_END_MARKER = "/foldkit-plus-head";
|
|
139
158
|
/**
|
|
140
159
|
* JSON for a script element: `<` is escaped so `</script>` in the data ends
|
|
141
160
|
* nothing. U+2028 and U+2029 are escaped too: they are fine in JSON and break a
|
|
@@ -143,10 +162,11 @@ declare const STYLES_MARKER = "foldkit-plus-styles";
|
|
|
143
162
|
*/
|
|
144
163
|
declare const serializeJsonScript: (value: unknown) => string;
|
|
145
164
|
/**
|
|
146
|
-
* The envelope JSON as the stamped root carries it
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
165
|
+
* The envelope JSON as the stamped root carries it, in single quotes so the
|
|
166
|
+
* JSON's own double quotes need no escape. `&` and `'` are escaped, so no
|
|
167
|
+
* string in the Model can break out of the value; `getAttribute` resolves the
|
|
168
|
+
* entities back to exactly the JSON. `serializeJsonScript` has already escaped
|
|
169
|
+
* `<` and the line separators.
|
|
150
170
|
*/
|
|
151
171
|
declare const attributeOf: (json: string) => string;
|
|
152
172
|
/**
|
|
@@ -198,6 +218,15 @@ type PlanSurface<Model> = ActiveSurface<Model> | SurfaceSource<Model>;
|
|
|
198
218
|
declare const projectionsOf: <Model>(source: PlanSurface<Model>, model: Model) => ReadonlyArray<{
|
|
199
219
|
readonly metadata: Metadata;
|
|
200
220
|
}>;
|
|
221
|
+
/**
|
|
222
|
+
* A Model path the browser can read again for itself, such as one a URL or
|
|
223
|
+
* cookie mirror owns, and how to copy the server's value for the coverage
|
|
224
|
+
* check. The envelope leaves the path out.
|
|
225
|
+
*/
|
|
226
|
+
interface RestoredPlace<Model> {
|
|
227
|
+
readonly path: ReadonlyArray<string>;
|
|
228
|
+
readonly copy: (target: Model, source: Model) => Model;
|
|
229
|
+
}
|
|
201
230
|
/**
|
|
202
231
|
* Which part of the Model the browser owns, and what it starts from.
|
|
203
232
|
*
|
|
@@ -213,6 +242,13 @@ interface ResumePlan<Model, Fields extends Schema.Struct.Fields, Commands = unkn
|
|
|
213
242
|
readonly boot?: ((model: Model) => Commands) | undefined;
|
|
214
243
|
/** Model paths allowed to start from the baseline, as each place's focus gives them. */
|
|
215
244
|
readonly local: ReadonlyArray<ReadonlyArray<string>>;
|
|
245
|
+
/**
|
|
246
|
+
* Model paths the browser reads again before the first render, such as the
|
|
247
|
+
* fields a URL or cookie mirror owns. The envelope leaves them out.
|
|
248
|
+
*/
|
|
249
|
+
readonly restored: ReadonlyArray<RestoredPlace<Model>>;
|
|
250
|
+
/** The browser's own values for `restored`, read before the first render; never run on the server. */
|
|
251
|
+
readonly restore?: ((model: Model) => Model) | undefined;
|
|
216
252
|
/** The Surfaces the browser may activate, which the plan must cover. */
|
|
217
253
|
readonly surfaces: ReadonlyArray<PlanSurface<Model>>;
|
|
218
254
|
/** State another package owns, each captured and restored by that package. */
|
|
@@ -303,6 +339,8 @@ declare const plan: <Model, Fields extends Schema.Struct.Fields, Commands = unkn
|
|
|
303
339
|
readonly baseline?: Model | undefined;
|
|
304
340
|
readonly boot?: ((model: Model) => Commands) | undefined;
|
|
305
341
|
readonly local?: ReadonlyArray<ModelPlace<NoInfer<Model>>> | undefined;
|
|
342
|
+
readonly restored?: ReadonlyArray<ModelRef<NoInfer<Model>, any>> | undefined;
|
|
343
|
+
readonly restore?: ((model: Model) => Model) | undefined;
|
|
306
344
|
readonly surfaces?: ReadonlyArray<PlanSurface<Model>> | undefined;
|
|
307
345
|
readonly parts?: ReadonlyArray<ResumePart<Model>> | undefined;
|
|
308
346
|
readonly start?: Start | undefined;
|
|
@@ -366,6 +404,15 @@ declare const STATIC_ATTRIBUTE = "data-foldkit-plus-static";
|
|
|
366
404
|
* belongs in a Surface, not here.
|
|
367
405
|
*/
|
|
368
406
|
declare const staticRegion: (id: string, render: (ih: HtmlBuilder<never>) => Region) => Html;
|
|
407
|
+
/**
|
|
408
|
+
* A bundle of attributes, such as a Slot's, typed as binding no Message, for a
|
|
409
|
+
* static region's `ih` or any builder. A Slot's attributes are typed with the
|
|
410
|
+
* page's Message whatever its Mixins add, so the type cannot tell a Style from
|
|
411
|
+
* a handler; this checks when it is called instead, and throws on any handler
|
|
412
|
+
* (an `On…` attribute) or a Submodel's attribute, neither of which a static
|
|
413
|
+
* region could run.
|
|
414
|
+
*/
|
|
415
|
+
declare const unbound: <Message>(attributes: ReadonlyArray<Attribute<Message> | ChildAttribute>) => ReadonlyArray<Attribute<never>>;
|
|
369
416
|
/**
|
|
370
417
|
* Whether the view call in progress is the server rendering a page, rather than the browser: true
|
|
371
418
|
* through both of `render`'s passes, false while the browser resumes and outside any render. For a
|
|
@@ -486,5 +533,5 @@ declare const bindingsAndEvents: <Model, Fields extends Schema.Struct.Fields>(pl
|
|
|
486
533
|
readonly bindings: ReadonlyArray<DecodedBinding>;
|
|
487
534
|
readonly events: ReadonlyArray<string> | undefined;
|
|
488
535
|
}, ResumeRefused>;
|
|
489
|
-
export {
|
|
490
|
-
//# sourceMappingURL=shared-
|
|
536
|
+
export { bundleUnloaded as $, resume as A, RenderContext as B, metaEntry as C, plan as D, pathKey as E, staticRegion as F, BundleUnloaded as G, current as H, tagOf as I, HeadNotMoved as J, CachedPageDiffers as K, unbound as L, serializeJsonScript as M, serving as N, projectionsOf as O, startingFrom as P, StaticRegionMissing as Q, Binding as R, codecOf as S, modelFrom as T, withContext as U, UnnamedHandler as V, within as W, PageFailed as X, PageContained as Y, SsrDiagnostic as Z, allowedTags as _, Meta as a, pageContained as at, bindings as b, RestoredPlace as c, staticRegionMissing as ct, ResumePlan as d, cachedPageDiffers as et, ResumeRefused as f, Start as g, STYLES_MARKER as h, META_ATTRIBUTE as i, otherBuild as it, routeOf as j, refuse as k, ResumableConfig as l, STATIC_ATTRIBUTE as m, HEAD_MARKER as n, headNotMoved as nt, PROTOCOL as o, pageFailed as ot, RouteMatch as p, HandlerUnnamed as q, Loadable as r, noBuildId as rt, PlanSurface as s, reportingTo as st, HEAD_END_MARKER as t, handlerUnnamed as tt, ResumePart as u, arrival as v, metaMarkup as w, bindingsAndEvents as x, attributeOf as y, Region as z };
|
|
537
|
+
//# sourceMappingURL=shared-mQ8CXr-r.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-mQ8CXr-r.d.ts","names":[],"sources":["../src/diagnostics.ts","../src/context.ts","../src/shared.ts"],"mappings":";;;;;;;UAaiB,sBAAsB;WAC5B;;;;;WAKA,qCAAqC;;;UAI/B,4BAA4B;WAClC;WACA;;;UAIM,uBAAuB;WAC7B;WACA;;;UAIM,mBAAmB;WACzB;WACA;WACA,OAAO,MAAM;;;UAIP,uBAAuB;WAC7B;WACA;WACA;WACA;;;;;;;;UASM,0BAA0B;WAChC;WACA;;;;;;;;UASM,qBAAqB;WAC3B;;;KAIC,gBACR,gBACA,sBACA,iBACA,aACA,iBACA,oBACA;cAES,cAAc;cAQd,gBAAa,QAAY,yBAAuB,mBAAmB;cAQnE,WAAW;;cAMX,aAAU,QAAY,OAAO,gBAAc,mBAAmB;cAS9D,sBAAmB,mBAAqB;cAQxC,iBAAc,mBAAqB;cAQnC,aAAU,aAAe,OAAS,MAAM,mBAAiB;cASzD,iBAAc,cAAgB,iBAAiB,kBAAkB;;cAWjE,cAAW,QACb,kCACR,GAAG,GAAG,GAAC,QAAU,OAAO,OAAO,GAAG,GAAG,OAAK,OAAO,OAAO,GAAG,GAAG;cAGpD,oBAAiB,gBAAkB;KCtIpC,SAAS,cAAc;;UAGlB;WACN;WACA;;;;;;;;;UAUM;;WAEN;WACA;WACA;WACA;WACA,OAAO;;WAEP;WACA;;KAGC;WAEG;WACA,SAAS,YAAY;WACrB,YAAY;WACZ,UAAU,MAAM;;WAEhB,YAAY;;EAErB,OAAO;;EAEP;;EAEA;;WAES,UAAU;aACR;aACA;aACA;;;WAGF,SAAS,MAAM;;WAEf,YAAY;;WAEZ,QAAQ;;WAGR;WACA,SAAS,oBAAoB;WAC7B,UAAU,MAAM;WAChB,YAAY;EACrB,OAAO;EACP;;WAGS;WACA,WAAW;;WAEX,UAAU;WACV,SAAS,YAAY;;;cAMvB,eAAc;cAWd,SAAU,GAAC,MAAQ,eAAa,WAAa,MAAI;;cAejD,cAAe;WAA0B,OAAO,YAAY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,OAAO;;WAC9D,OAAO,OAAO,OAAO;WACrB,WAAW;WACX;WACA,gBAAgB,SAAS;WACzB,mBAAmB,SAAS;;WAE5B,YAAY,MAAM;;;;;;WAMlB,OAAO,cAAc;;;UAIf;WACN;WACA,YAAY;WACZ;;;cAcE,eAAgB,OAAK,QACxB,gBAAgB,QAAM;WACZ,OAAO;WAAgB,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAnCnB,OAAA,OAAA,OAAA;EACb,WAAA;EAEK,gBAAA,SAAS;EACN,mBAAA,SAAS;EAEhB,YAAA,MAAM;EAMX,OAAA,cAAc;;aAuBL,OAAA;aAA2B,WAAA;;;;cAIzC,UAAO;;;;;;;;;cAaP,WAAY,OAAO,eAAe,OAAO,OAAO,QAAM,MAC3D,WAAW,OAAO,SAAO,MACzB,YAAU,MACV,SAAO,OACN,UACN,OAAO,OAAO,cAAc,iBAAiB;;;;;cASnC,oBAAqB,OAAO,eAAe,OAAO,OAAO,QAAM,MACpE,WAAW,OAAO,SAAO,MACzB,YAAU,MACV,SAAO,OACN,UACN,OAAO;WAEG,UAAU,cAAc;WACxB,QAAQ;GAEnB"}
|
package/dist/shared.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { i as RESUME_ATTRIBUTE, n as FOLDKIT_APP_ATTRIBUTE } from "./marks-CX15BwOw.js";
|
|
2
|
+
import { A as resume, C as metaEntry, D as plan, E as pathKey, F as staticRegion, I as tagOf, L as unbound, M as serializeJsonScript, N as serving, O as projectionsOf, P as startingFrom, S as codecOf, T as modelFrom, _ as allowedTags, a as Meta, b as bindings, c as RestoredPlace, d as ResumePlan, f as ResumeRefused, g as Start, h as STYLES_MARKER, i as META_ATTRIBUTE, j as routeOf, k as refuse, l as ResumableConfig, m as STATIC_ATTRIBUTE, n as HEAD_MARKER, o as PROTOCOL, p as RouteMatch, r as Loadable, s as PlanSurface, t as HEAD_END_MARKER, u as ResumePart, v as arrival, w as metaMarkup, x as bindingsAndEvents, y as attributeOf } from "./shared-mQ8CXr-r.js";
|
|
3
|
+
export { FOLDKIT_APP_ATTRIBUTE, HEAD_END_MARKER, HEAD_MARKER, Loadable, META_ATTRIBUTE, Meta, PROTOCOL, PlanSurface, RESUME_ATTRIBUTE, RestoredPlace, ResumableConfig, ResumePart, ResumePlan, ResumeRefused, RouteMatch, STATIC_ATTRIBUTE, STYLES_MARKER, Start, allowedTags, arrival, attributeOf, bindings, bindingsAndEvents, codecOf, metaEntry, metaMarkup, modelFrom, pathKey, plan, projectionsOf, refuse, resume, routeOf, serializeJsonScript, serving, startingFrom, staticRegion, tagOf, unbound };
|
package/dist/shared.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { current } from "./context.js";
|
|
2
2
|
import { staticRegionMissing } from "./diagnostics.js";
|
|
3
|
+
import { FOLDKIT_APP_ATTRIBUTE, RESUME_ATTRIBUTE } from "./marks.js";
|
|
3
4
|
import { decodeBindings, readBindings } from "./listen.js";
|
|
4
5
|
import { Effect, Option, Result, Schema, Stream } from "effect";
|
|
5
6
|
import { ModelRef } from "foldkit-surface";
|
|
@@ -11,18 +12,6 @@ import { fromString } from "foldkit/url";
|
|
|
11
12
|
* browser reads it, static regions, and the page's bindings. Nothing here
|
|
12
13
|
* imports Foldkit's server renderer, so `client.ts` can carry all of it.
|
|
13
14
|
*/
|
|
14
|
-
/**
|
|
15
|
-
* The attribute Foldkit's server stamps on an application's root, as
|
|
16
|
-
* `foldkit/experimental/server` exports it. Written out here so a page can
|
|
17
|
-
* find its root without that module; a test pins the two together.
|
|
18
|
-
*/
|
|
19
|
-
const FOLDKIT_APP_ATTRIBUTE = "data-foldkit-app";
|
|
20
|
-
/**
|
|
21
|
-
* The attribute on the stamped root that carries a page's resume envelope.
|
|
22
|
-
* Foldkit pairs its own handoff the same way: the build id rides on the root
|
|
23
|
-
* beside the app stamp, and the client reads it before adopting anything.
|
|
24
|
-
*/
|
|
25
|
-
const RESUME_ATTRIBUTE = "data-foldkit-plus-resume";
|
|
26
15
|
/** The envelope format this package writes and reads. */
|
|
27
16
|
const PROTOCOL = 1;
|
|
28
17
|
/**
|
|
@@ -31,6 +20,14 @@ const PROTOCOL = 1;
|
|
|
31
20
|
* follows it into the head before adopting the page.
|
|
32
21
|
*/
|
|
33
22
|
const STYLES_MARKER = "foldkit-plus-styles";
|
|
23
|
+
/**
|
|
24
|
+
* The comments a dynamically served page's head markup (a plan's `meta`)
|
|
25
|
+
* sits between in the stamped root, until the host's `SSR.headed` moves it
|
|
26
|
+
* before `</head>`. Left in the body, `SSR.hydrate` removes it and reports
|
|
27
|
+
* `HeadNotMoved`.
|
|
28
|
+
*/
|
|
29
|
+
const HEAD_MARKER = "foldkit-plus-head";
|
|
30
|
+
const HEAD_END_MARKER = "/foldkit-plus-head";
|
|
34
31
|
const LINE_SEPARATOR = String.fromCharCode(8232);
|
|
35
32
|
const PARAGRAPH_SEPARATOR = String.fromCharCode(8233);
|
|
36
33
|
/**
|
|
@@ -40,12 +37,13 @@ const PARAGRAPH_SEPARATOR = String.fromCharCode(8233);
|
|
|
40
37
|
*/
|
|
41
38
|
const serializeJsonScript = (value) => JSON.stringify(value).replaceAll("<", "\\u003c").replaceAll(LINE_SEPARATOR, "\\u2028").replaceAll(PARAGRAPH_SEPARATOR, "\\u2029");
|
|
42
39
|
/**
|
|
43
|
-
* The envelope JSON as the stamped root carries it
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
40
|
+
* The envelope JSON as the stamped root carries it, in single quotes so the
|
|
41
|
+
* JSON's own double quotes need no escape. `&` and `'` are escaped, so no
|
|
42
|
+
* string in the Model can break out of the value; `getAttribute` resolves the
|
|
43
|
+
* entities back to exactly the JSON. `serializeJsonScript` has already escaped
|
|
44
|
+
* `<` and the line separators.
|
|
47
45
|
*/
|
|
48
|
-
const attributeOf = (json) => ` ${RESUME_ATTRIBUTE}=
|
|
46
|
+
const attributeOf = (json) => ` ${RESUME_ATTRIBUTE}='${json.replaceAll("&", "&").replaceAll("'", "'")}'`;
|
|
49
47
|
/** Marks each head element a plan's `meta` wrote, so the browser can replace them. */
|
|
50
48
|
const META_ATTRIBUTE = "data-foldkit-meta";
|
|
51
49
|
const attributeText = (text) => text.replaceAll("&", "&").replaceAll("\"", """).replaceAll("<", "<").replaceAll(">", ">");
|
|
@@ -144,12 +142,23 @@ const plan = (application, config) => {
|
|
|
144
142
|
return from === void 0 ? [surface] : [surface, from];
|
|
145
143
|
}).find((surface) => application.owner !== void 0 && surface.owner !== application.owner);
|
|
146
144
|
if (foreign !== void 0) throw new Error(`SSR.plan: the Surface "${foreign.name}" belongs to another application than plan "${config.id}"`);
|
|
145
|
+
const restored = (config.restored ?? []).map((place) => {
|
|
146
|
+
const focus = ModelRef.focus(place);
|
|
147
|
+
return {
|
|
148
|
+
path: focus.dependency,
|
|
149
|
+
copy: (target, source) => focus.set(target, focus.get(source))
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
const sent = restored.find(({ path }) => config.state.dependencies.some((outer) => outer.length > 0 && outer.length <= path.length && outer.every((key, index) => path[index] === key)));
|
|
153
|
+
if (sent !== void 0) throw new Error(`SSR.plan: "${sent.path.join(".")}" is restored by the browser, so the state must not send it`);
|
|
147
154
|
return {
|
|
148
155
|
id: config.id,
|
|
149
156
|
state: config.state,
|
|
150
157
|
baseline: config.baseline ?? application.initial,
|
|
151
158
|
...config.boot === void 0 ? {} : { boot: config.boot },
|
|
152
159
|
local: (config.local ?? []).map((place) => ModelRef.focus(place).dependency),
|
|
160
|
+
restored,
|
|
161
|
+
...config.restore === void 0 ? {} : { restore: config.restore },
|
|
153
162
|
surfaces,
|
|
154
163
|
parts,
|
|
155
164
|
...application.Message === void 0 ? {} : { Message: application.Message },
|
|
@@ -285,6 +294,19 @@ const staticRegion = (id, render) => {
|
|
|
285
294
|
}
|
|
286
295
|
};
|
|
287
296
|
/**
|
|
297
|
+
* A bundle of attributes, such as a Slot's, typed as binding no Message, for a
|
|
298
|
+
* static region's `ih` or any builder. A Slot's attributes are typed with the
|
|
299
|
+
* page's Message whatever its Mixins add, so the type cannot tell a Style from
|
|
300
|
+
* a handler; this checks when it is called instead, and throws on any handler
|
|
301
|
+
* (an `On…` attribute) or a Submodel's attribute, neither of which a static
|
|
302
|
+
* region could run.
|
|
303
|
+
*/
|
|
304
|
+
const unbound = (attributes) => attributes.map((attribute) => {
|
|
305
|
+
if (!("_tag" in attribute)) throw new Error("SSR.unbound was given a Submodel's attribute, which dispatches a Message");
|
|
306
|
+
if (attribute._tag.startsWith("On")) throw new Error(`SSR.unbound was given ${attribute._tag}, which binds a Message`);
|
|
307
|
+
return attribute;
|
|
308
|
+
});
|
|
309
|
+
/**
|
|
288
310
|
* Whether the view call in progress is the server rendering a page, rather than the browser: true
|
|
289
311
|
* through both of `render`'s passes, false while the browser resumes and outside any render. For a
|
|
290
312
|
* view that sends markup it will adopt in the browser rather than draw there, such as
|
|
@@ -342,6 +364,6 @@ const bindingsAndEvents = (plan, page, root, model) => {
|
|
|
342
364
|
events: events.success
|
|
343
365
|
});
|
|
344
366
|
};
|
|
345
|
-
export { FOLDKIT_APP_ATTRIBUTE, META_ATTRIBUTE, PROTOCOL, RESUME_ATTRIBUTE, ResumeRefused, STATIC_ATTRIBUTE, STYLES_MARKER, allowedTags, arrival, attributeOf, bindings, bindingsAndEvents, codecOf, metaEntry, metaMarkup, modelFrom, pathKey, plan, projectionsOf, refuse, resume, routeOf, serializeJsonScript, serving, startingFrom, staticRegion, tagOf };
|
|
367
|
+
export { FOLDKIT_APP_ATTRIBUTE, HEAD_END_MARKER, HEAD_MARKER, META_ATTRIBUTE, PROTOCOL, RESUME_ATTRIBUTE, ResumeRefused, STATIC_ATTRIBUTE, STYLES_MARKER, allowedTags, arrival, attributeOf, bindings, bindingsAndEvents, codecOf, metaEntry, metaMarkup, modelFrom, pathKey, plan, projectionsOf, refuse, resume, routeOf, serializeJsonScript, serving, startingFrom, staticRegion, tagOf, unbound };
|
|
346
368
|
|
|
347
369
|
//# sourceMappingURL=shared.js.map
|