@jam-overture/loom 0.1.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/LICENSE +21 -0
- package/README.md +743 -0
- package/dist/catalogue.d.ts +70 -0
- package/dist/catalogue.js +88 -0
- package/dist/cli/args.d.ts +17 -0
- package/dist/cli/args.js +83 -0
- package/dist/cli/filesystem.d.ts +15 -0
- package/dist/cli/filesystem.js +31 -0
- package/dist/cli/index.d.ts +12 -0
- package/dist/cli/index.js +12 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.js +30 -0
- package/dist/cli/namespace.d.ts +40 -0
- package/dist/cli/namespace.js +40 -0
- package/dist/cli/plan.d.ts +84 -0
- package/dist/cli/plan.js +113 -0
- package/dist/cli/run.d.ts +17 -0
- package/dist/cli/run.js +75 -0
- package/dist/cli/templates.d.ts +43 -0
- package/dist/cli/templates.js +134 -0
- package/dist/closed-set.d.ts +34 -0
- package/dist/closed-set.js +34 -0
- package/dist/data/adapter.d.ts +123 -0
- package/dist/data/adapter.js +91 -0
- package/dist/data/binding.d.ts +48 -0
- package/dist/data/binding.js +39 -0
- package/dist/data/catalogue.d.ts +26 -0
- package/dist/data/catalogue.js +6 -0
- package/dist/data/index.d.ts +14 -0
- package/dist/data/index.js +14 -0
- package/dist/data/plan.d.ts +58 -0
- package/dist/data/plan.js +0 -0
- package/dist/data/resolution.d.ts +91 -0
- package/dist/data/resolution.js +96 -0
- package/dist/data/resolve.d.ts +46 -0
- package/dist/data/resolve.js +37 -0
- package/dist/data/source.d.ts +40 -0
- package/dist/data/source.js +45 -0
- package/dist/deadline.d.ts +57 -0
- package/dist/deadline.js +78 -0
- package/dist/frame/catalogue.d.ts +24 -0
- package/dist/frame/catalogue.js +5 -0
- package/dist/frame/index.d.ts +12 -0
- package/dist/frame/index.js +12 -0
- package/dist/frame/origin.d.ts +87 -0
- package/dist/frame/origin.js +114 -0
- package/dist/frame/resolution.d.ts +85 -0
- package/dist/frame/resolution.js +79 -0
- package/dist/grammar.d.ts +26 -0
- package/dist/grammar.js +28 -0
- package/dist/ids.d.ts +57 -0
- package/dist/ids.js +104 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +26 -0
- package/dist/interactivity.d.ts +50 -0
- package/dist/interactivity.js +22 -0
- package/dist/interpretation/anthropic.d.ts +22 -0
- package/dist/interpretation/anthropic.js +76 -0
- package/dist/interpretation/client.d.ts +83 -0
- package/dist/interpretation/client.js +2 -0
- package/dist/interpretation/draft.d.ts +234 -0
- package/dist/interpretation/draft.js +84 -0
- package/dist/interpretation/index.d.ts +15 -0
- package/dist/interpretation/index.js +15 -0
- package/dist/interpretation/interpreter.d.ts +62 -0
- package/dist/interpretation/interpreter.js +151 -0
- package/dist/interpretation/materialize.d.ts +42 -0
- package/dist/interpretation/materialize.js +107 -0
- package/dist/interpretation/prompt.d.ts +229 -0
- package/dist/interpretation/prompt.js +285 -0
- package/dist/interpretation/render.d.ts +76 -0
- package/dist/interpretation/render.js +272 -0
- package/dist/interpretation/schema.d.ts +49 -0
- package/dist/interpretation/schema.js +131 -0
- package/dist/json.d.ts +35 -0
- package/dist/json.js +11 -0
- package/dist/paging.d.ts +60 -0
- package/dist/paging.js +49 -0
- package/dist/primitive-type.d.ts +32 -0
- package/dist/primitive-type.js +39 -0
- package/dist/render/addressing.d.ts +59 -0
- package/dist/render/addressing.js +60 -0
- package/dist/render/anchor.d.ts +105 -0
- package/dist/render/anchor.js +84 -0
- package/dist/render/behaviour-adjust.d.ts +62 -0
- package/dist/render/behaviour-adjust.js +78 -0
- package/dist/render/behaviour-copy.d.ts +53 -0
- package/dist/render/behaviour-copy.js +75 -0
- package/dist/render/behaviour-disclose.d.ts +74 -0
- package/dist/render/behaviour-disclose.js +77 -0
- package/dist/render/behaviour-present.d.ts +123 -0
- package/dist/render/behaviour-present.js +173 -0
- package/dist/render/behaviour.d.ts +243 -0
- package/dist/render/behaviour.js +284 -0
- package/dist/render/control.d.ts +81 -0
- package/dist/render/control.js +80 -0
- package/dist/render/decorative.d.ts +62 -0
- package/dist/render/decorative.js +2 -0
- package/dist/render/diagnostics.d.ts +260 -0
- package/dist/render/diagnostics.js +61 -0
- package/dist/render/disclosed.d.ts +37 -0
- package/dist/render/disclosed.js +37 -0
- package/dist/render/editable.d.ts +34 -0
- package/dist/render/editable.js +35 -0
- package/dist/render/frame.d.ts +42 -0
- package/dist/render/frame.js +31 -0
- package/dist/render/index.d.ts +35 -0
- package/dist/render/index.js +35 -0
- package/dist/render/inline-variables.d.ts +77 -0
- package/dist/render/inline-variables.js +220 -0
- package/dist/render/presented.d.ts +82 -0
- package/dist/render/presented.js +82 -0
- package/dist/render/primitive.d.ts +228 -0
- package/dist/render/primitive.js +36 -0
- package/dist/render/props.d.ts +48 -0
- package/dist/render/props.js +2 -0
- package/dist/render/reads.d.ts +73 -0
- package/dist/render/reads.js +45 -0
- package/dist/render/render.d.ts +164 -0
- package/dist/render/render.js +571 -0
- package/dist/render/request.d.ts +111 -0
- package/dist/render/request.js +60 -0
- package/dist/render/text.d.ts +91 -0
- package/dist/render/text.js +44 -0
- package/dist/render/theme.d.ts +61 -0
- package/dist/render/theme.js +52 -0
- package/dist/reserved-props.d.ts +35 -0
- package/dist/reserved-props.js +45 -0
- package/dist/result.d.ts +27 -0
- package/dist/result.js +30 -0
- package/dist/role.d.ts +71 -0
- package/dist/role.js +22 -0
- package/dist/runtime/analysis.d.ts +149 -0
- package/dist/runtime/analysis.js +187 -0
- package/dist/runtime/assessment.d.ts +35 -0
- package/dist/runtime/assessment.js +13 -0
- package/dist/runtime/disposition.d.ts +102 -0
- package/dist/runtime/disposition.js +59 -0
- package/dist/runtime/events.d.ts +187 -0
- package/dist/runtime/events.js +7 -0
- package/dist/runtime/gate.d.ts +43 -0
- package/dist/runtime/gate.js +169 -0
- package/dist/runtime/index.d.ts +27 -0
- package/dist/runtime/index.js +27 -0
- package/dist/runtime/intent.d.ts +60 -0
- package/dist/runtime/intent.js +36 -0
- package/dist/runtime/interpreter.d.ts +117 -0
- package/dist/runtime/interpreter.js +46 -0
- package/dist/runtime/inverse-interpreter.d.ts +90 -0
- package/dist/runtime/inverse-interpreter.js +56 -0
- package/dist/runtime/inverse.d.ts +87 -0
- package/dist/runtime/inverse.js +48 -0
- package/dist/runtime/narration.d.ts +24 -0
- package/dist/runtime/narration.js +36 -0
- package/dist/runtime/nesting.d.ts +31 -0
- package/dist/runtime/nesting.js +46 -0
- package/dist/runtime/pipeline.d.ts +124 -0
- package/dist/runtime/pipeline.js +178 -0
- package/dist/runtime/policy-fingerprint.d.ts +29 -0
- package/dist/runtime/policy-fingerprint.js +119 -0
- package/dist/runtime/policy-source.d.ts +42 -0
- package/dist/runtime/policy-source.js +8 -0
- package/dist/runtime/policy.d.ts +156 -0
- package/dist/runtime/policy.js +107 -0
- package/dist/runtime/proposal.d.ts +423 -0
- package/dist/runtime/proposal.js +109 -0
- package/dist/runtime/redirection.d.ts +53 -0
- package/dist/runtime/redirection.js +38 -0
- package/dist/runtime/repointing.d.ts +71 -0
- package/dist/runtime/repointing.js +0 -0
- package/dist/runtime/reversibility.d.ts +36 -0
- package/dist/runtime/reversibility.js +39 -0
- package/dist/runtime/stake-level.d.ts +33 -0
- package/dist/runtime/stake-level.js +58 -0
- package/dist/runtime/stakes.d.ts +47 -0
- package/dist/runtime/stakes.js +305 -0
- package/dist/runtime/vocabulary.d.ts +122 -0
- package/dist/runtime/vocabulary.js +87 -0
- package/dist/sdk/audit.d.ts +195 -0
- package/dist/sdk/audit.js +128 -0
- package/dist/sdk/catalogue.d.ts +37 -0
- package/dist/sdk/catalogue.js +16 -0
- package/dist/sdk/conformance.d.ts +342 -0
- package/dist/sdk/conformance.js +494 -0
- package/dist/sdk/copy.d.ts +105 -0
- package/dist/sdk/copy.js +90 -0
- package/dist/sdk/definition.d.ts +242 -0
- package/dist/sdk/definition.js +64 -0
- package/dist/sdk/index.d.ts +19 -0
- package/dist/sdk/index.js +19 -0
- package/dist/sdk/interactivity.d.ts +29 -0
- package/dist/sdk/interactivity.js +34 -0
- package/dist/sdk/pairings.d.ts +124 -0
- package/dist/sdk/pairings.js +81 -0
- package/dist/sdk/registry.d.ts +162 -0
- package/dist/sdk/registry.js +329 -0
- package/dist/sdk/selection.d.ts +46 -0
- package/dist/sdk/selection.js +24 -0
- package/dist/sdk/text.d.ts +100 -0
- package/dist/sdk/text.js +105 -0
- package/dist/sdk/vocabulary.d.ts +39 -0
- package/dist/sdk/vocabulary.js +36 -0
- package/dist/signals/broadcast.d.ts +134 -0
- package/dist/signals/broadcast.js +451 -0
- package/dist/signals/collect.d.ts +184 -0
- package/dist/signals/collect.js +196 -0
- package/dist/signals/deliver.d.ts +64 -0
- package/dist/signals/deliver.js +85 -0
- package/dist/signals/fold.d.ts +112 -0
- package/dist/signals/fold.js +76 -0
- package/dist/signals/index.d.ts +31 -0
- package/dist/signals/index.js +31 -0
- package/dist/signals/ingest.d.ts +51 -0
- package/dist/signals/ingest.js +70 -0
- package/dist/signals/intake.d.ts +149 -0
- package/dist/signals/intake.js +154 -0
- package/dist/signals/journal.d.ts +94 -0
- package/dist/signals/journal.js +11 -0
- package/dist/signals/kinds.d.ts +22 -0
- package/dist/signals/kinds.js +22 -0
- package/dist/signals/ledger.d.ts +46 -0
- package/dist/signals/ledger.js +81 -0
- package/dist/signals/memory.d.ts +17 -0
- package/dist/signals/memory.js +99 -0
- package/dist/signals/migrate.d.ts +27 -0
- package/dist/signals/migrate.js +78 -0
- package/dist/signals/postgres.d.ts +7 -0
- package/dist/signals/postgres.js +295 -0
- package/dist/signals/rollup.d.ts +142 -0
- package/dist/signals/rollup.js +0 -0
- package/dist/signals/schema.d.ts +534 -0
- package/dist/signals/schema.js +92 -0
- package/dist/signals/signal.d.ts +381 -0
- package/dist/signals/signal.js +150 -0
- package/dist/signals/tally.d.ts +70 -0
- package/dist/signals/tally.js +2 -0
- package/dist/signals/view.d.ts +51 -0
- package/dist/signals/view.js +54 -0
- package/dist/store/attribution.d.ts +125 -0
- package/dist/store/attribution.js +116 -0
- package/dist/store/database.d.ts +14 -0
- package/dist/store/database.js +2 -0
- package/dist/store/driver.d.ts +29 -0
- package/dist/store/driver.js +39 -0
- package/dist/store/errors.d.ts +56 -0
- package/dist/store/errors.js +37 -0
- package/dist/store/index.d.ts +16 -0
- package/dist/store/index.js +16 -0
- package/dist/store/memory.d.ts +3 -0
- package/dist/store/memory.js +115 -0
- package/dist/store/migrate.d.ts +54 -0
- package/dist/store/migrate.js +122 -0
- package/dist/store/postgres-holds.d.ts +4 -0
- package/dist/store/postgres-holds.js +192 -0
- package/dist/store/postgres.d.ts +8 -0
- package/dist/store/postgres.js +262 -0
- package/dist/store/replay.d.ts +94 -0
- package/dist/store/replay.js +82 -0
- package/dist/store/revert.d.ts +116 -0
- package/dist/store/revert.js +243 -0
- package/dist/store/schema.d.ts +371 -0
- package/dist/store/schema.js +78 -0
- package/dist/store/source.d.ts +23 -0
- package/dist/store/source.js +37 -0
- package/dist/store/store.d.ts +231 -0
- package/dist/store/store.js +52 -0
- package/dist/store/undone.d.ts +18 -0
- package/dist/store/undone.js +89 -0
- package/dist/submit/catalogue.d.ts +20 -0
- package/dist/submit/catalogue.js +5 -0
- package/dist/submit/declaration.d.ts +39 -0
- package/dist/submit/declaration.js +30 -0
- package/dist/submit/endpoint.d.ts +131 -0
- package/dist/submit/endpoint.js +160 -0
- package/dist/submit/index.d.ts +13 -0
- package/dist/submit/index.js +13 -0
- package/dist/submit/plan.d.ts +49 -0
- package/dist/submit/plan.js +47 -0
- package/dist/submit/resolution.d.ts +61 -0
- package/dist/submit/resolution.js +64 -0
- package/dist/submit/resolve.d.ts +45 -0
- package/dist/submit/resolve.js +36 -0
- package/dist/telemetry/calibration.d.ts +132 -0
- package/dist/telemetry/calibration.js +151 -0
- package/dist/telemetry/episode.d.ts +140 -0
- package/dist/telemetry/episode.js +272 -0
- package/dist/telemetry/event.d.ts +2310 -0
- package/dist/telemetry/event.js +405 -0
- package/dist/telemetry/index.d.ts +15 -0
- package/dist/telemetry/index.js +15 -0
- package/dist/telemetry/journal.d.ts +116 -0
- package/dist/telemetry/journal.js +11 -0
- package/dist/telemetry/memory.d.ts +24 -0
- package/dist/telemetry/memory.js +75 -0
- package/dist/telemetry/migrate.d.ts +26 -0
- package/dist/telemetry/migrate.js +40 -0
- package/dist/telemetry/postgres.d.ts +6 -0
- package/dist/telemetry/postgres.js +139 -0
- package/dist/telemetry/retention.d.ts +131 -0
- package/dist/telemetry/retention.js +217 -0
- package/dist/telemetry/schema.d.ts +113 -0
- package/dist/telemetry/schema.js +33 -0
- package/dist/telemetry/sink.d.ts +42 -0
- package/dist/telemetry/sink.js +61 -0
- package/dist/testing/contracts.d.ts +34 -0
- package/dist/testing/contracts.js +34 -0
- package/dist/testing/definitions.d.ts +15 -0
- package/dist/testing/definitions.js +48 -0
- package/dist/testing/doubles.d.ts +94 -0
- package/dist/testing/doubles.js +141 -0
- package/dist/testing/episode-harness.d.ts +49 -0
- package/dist/testing/episode-harness.js +65 -0
- package/dist/testing/filesystem.d.ts +17 -0
- package/dist/testing/filesystem.js +17 -0
- package/dist/testing/fixtures.d.ts +57 -0
- package/dist/testing/fixtures.js +84 -0
- package/dist/testing/hold-contract.d.ts +19 -0
- package/dist/testing/hold-contract.js +374 -0
- package/dist/testing/index.d.ts +41 -0
- package/dist/testing/index.js +41 -0
- package/dist/testing/journal-contract.d.ts +17 -0
- package/dist/testing/journal-contract.js +353 -0
- package/dist/testing/model-replies.d.ts +34 -0
- package/dist/testing/model-replies.js +101 -0
- package/dist/testing/primitives.d.ts +7 -0
- package/dist/testing/primitives.js +29 -0
- package/dist/testing/reader-signal-contract.d.ts +38 -0
- package/dist/testing/reader-signal-contract.js +318 -0
- package/dist/testing/row-security.d.ts +17 -0
- package/dist/testing/row-security.js +21 -0
- package/dist/testing/store-contract.d.ts +25 -0
- package/dist/testing/store-contract.js +500 -0
- package/dist/theme/apply.d.ts +17 -0
- package/dist/theme/apply.js +60 -0
- package/dist/theme/contrast.d.ts +197 -0
- package/dist/theme/contrast.js +259 -0
- package/dist/theme/derive.d.ts +77 -0
- package/dist/theme/derive.js +167 -0
- package/dist/theme/faces.d.ts +73 -0
- package/dist/theme/faces.js +119 -0
- package/dist/theme/font-packs.d.ts +25 -0
- package/dist/theme/font-packs.js +257 -0
- package/dist/theme/index.d.ts +20 -0
- package/dist/theme/index.js +20 -0
- package/dist/theme/lab.d.ts +30 -0
- package/dist/theme/lab.js +46 -0
- package/dist/theme/library.d.ts +114 -0
- package/dist/theme/library.js +300 -0
- package/dist/theme/measure.d.ts +144 -0
- package/dist/theme/measure.js +145 -0
- package/dist/theme/palettes.d.ts +64 -0
- package/dist/theme/palettes.js +497 -0
- package/dist/theme/registry.d.ts +59 -0
- package/dist/theme/registry.js +60 -0
- package/dist/theme/separation.d.ts +177 -0
- package/dist/theme/separation.js +203 -0
- package/dist/theme/style-presets.d.ts +60 -0
- package/dist/theme/style-presets.js +124 -0
- package/dist/theme/theme.d.ts +253 -0
- package/dist/theme/theme.js +171 -0
- package/dist/tree/apply.d.ts +16 -0
- package/dist/tree/apply.js +104 -0
- package/dist/tree/builders.d.ts +19 -0
- package/dist/tree/builders.js +20 -0
- package/dist/tree/compare.d.ts +68 -0
- package/dist/tree/compare.js +75 -0
- package/dist/tree/configuration.d.ts +25 -0
- package/dist/tree/configuration.js +108 -0
- package/dist/tree/delta.d.ts +288 -0
- package/dist/tree/delta.js +88 -0
- package/dist/tree/errors.d.ts +69 -0
- package/dist/tree/errors.js +34 -0
- package/dist/tree/identity.d.ts +117 -0
- package/dist/tree/identity.js +145 -0
- package/dist/tree/index.d.ts +21 -0
- package/dist/tree/index.js +21 -0
- package/dist/tree/inverse.d.ts +24 -0
- package/dist/tree/inverse.js +112 -0
- package/dist/tree/mutation.d.ts +18 -0
- package/dist/tree/mutation.js +49 -0
- package/dist/tree/naming.d.ts +4 -0
- package/dist/tree/naming.js +35 -0
- package/dist/tree/navigation.d.ts +38 -0
- package/dist/tree/navigation.js +83 -0
- package/dist/tree/node.d.ts +103 -0
- package/dist/tree/node.js +46 -0
- package/dist/tree/outline.d.ts +28 -0
- package/dist/tree/outline.js +10 -0
- package/dist/tree/tree.d.ts +83 -0
- package/dist/tree/tree.js +62 -0
- package/dist/write/commit.d.ts +124 -0
- package/dist/write/commit.js +234 -0
- package/dist/write/held.d.ts +674 -0
- package/dist/write/held.js +185 -0
- package/dist/write/index.d.ts +11 -0
- package/dist/write/index.js +11 -0
- package/dist/write/liveness.d.ts +132 -0
- package/dist/write/liveness.js +91 -0
- package/dist/write/revert.d.ts +79 -0
- package/dist/write/revert.js +134 -0
- package/package.json +160 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createElement, useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { controlClass, controlDisplay } from "./control.js";
|
|
4
|
+
import { DISMISS_EVENT, PRESENTED_ATTRIBUTE } from "./presented.js";
|
|
5
|
+
/**
|
|
6
|
+
* `var()` with a fallback rather than the `tokens.ts` helpers, for the reason
|
|
7
|
+
* every control in this directory gives: those live in `src/primitives/`, which
|
|
8
|
+
* the render seam must not depend on, and a control that only looks right under
|
|
9
|
+
* a mounted theme renders invisible in a preview pane that mounts none.
|
|
10
|
+
*/
|
|
11
|
+
const TRIGGER_STYLE = {
|
|
12
|
+
display: controlDisplay("present", "inline-flex"),
|
|
13
|
+
alignItems: "center",
|
|
14
|
+
gap: "var(--loom-spacing-2, 8px)",
|
|
15
|
+
paddingBlock: "var(--loom-spacing-1, 4px)",
|
|
16
|
+
paddingInline: "var(--loom-spacing-3, 12px)",
|
|
17
|
+
fontFamily: "inherit",
|
|
18
|
+
fontSize: "var(--loom-scale-1, 0.75rem)",
|
|
19
|
+
lineHeight: 1.2,
|
|
20
|
+
color: "var(--loom-fg-default, currentColor)",
|
|
21
|
+
background: "var(--loom-bg-surface, transparent)",
|
|
22
|
+
border: "1px solid var(--loom-border-subtle, currentColor)",
|
|
23
|
+
borderRadius: "var(--loom-radius-sm, 4px)",
|
|
24
|
+
cursor: "pointer",
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Square, and sized in `em` so it tracks whatever the region sets around it. The
|
|
28
|
+
* glyph is a multiplication sign rather than a lowercase x, which is the
|
|
29
|
+
* character that is actually a cross at every weight.
|
|
30
|
+
*/
|
|
31
|
+
const CLOSE_STYLE = {
|
|
32
|
+
display: controlDisplay("dismiss", "inline-flex"),
|
|
33
|
+
alignItems: "center",
|
|
34
|
+
justifyContent: "center",
|
|
35
|
+
inlineSize: "1.75em",
|
|
36
|
+
blockSize: "1.75em",
|
|
37
|
+
padding: 0,
|
|
38
|
+
fontFamily: "inherit",
|
|
39
|
+
fontSize: "var(--loom-scale-2, 0.875rem)",
|
|
40
|
+
lineHeight: 1,
|
|
41
|
+
color: "var(--loom-fg-muted, currentColor)",
|
|
42
|
+
background: "transparent",
|
|
43
|
+
border: "1px solid transparent",
|
|
44
|
+
borderRadius: "var(--loom-radius-full, 999px)",
|
|
45
|
+
cursor: "pointer",
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The trigger. It opens the region, publishes whether the region is showing, and
|
|
49
|
+
* closes it again on any of the three things that close an overlay.
|
|
50
|
+
*
|
|
51
|
+
* **It renders nothing until it knows scripting runs**, for the reason all three
|
|
52
|
+
* earlier controls give, and the consequence here is the one that decides which
|
|
53
|
+
* way a primitive must write its rule. No button means no attribute, no
|
|
54
|
+
* attribute means no rule matches, and the region is simply *there* — so a
|
|
55
|
+
* primitive hides its region with `[data-loom-presented="false"] .region` and
|
|
56
|
+
* never reveals it with the `"true"` form. Written the other way, a page served
|
|
57
|
+
* without scripting has a panel nothing can open and nothing to say why.
|
|
58
|
+
*
|
|
59
|
+
* **Escape and a press outside close it; a press inside does not.** "Outside" is
|
|
60
|
+
* measured against the element this control was placed in, which is the same
|
|
61
|
+
* element the state is published on and therefore the same box the primitive
|
|
62
|
+
* laid the region out inside. The one case that needs stating is a region drawn
|
|
63
|
+
* over the whole viewport: its scrim is inside that element too, so a press on
|
|
64
|
+
* it is an inside press and will not dismiss. A primitive doing that places a
|
|
65
|
+
* `dismiss` control, which is what it is for.
|
|
66
|
+
*/
|
|
67
|
+
export const PresentControl = ({ label }) => {
|
|
68
|
+
const [usable, setUsable] = useState(false);
|
|
69
|
+
const [open, setOpen] = useState(false);
|
|
70
|
+
const trigger = useRef(null);
|
|
71
|
+
/**
|
|
72
|
+
* Deliberately an effect rather than a render-time check, for the reason the
|
|
73
|
+
* copy control gives: anything read while rendering would make the server's
|
|
74
|
+
* markup and the browser's first render disagree, and React resolves that by
|
|
75
|
+
* keeping the server's — so the control would be missing exactly where it
|
|
76
|
+
* works.
|
|
77
|
+
*/
|
|
78
|
+
useEffect(() => setUsable(true), []);
|
|
79
|
+
const toggle = useCallback(() => setOpen((was) => !was), []);
|
|
80
|
+
/**
|
|
81
|
+
* The published state, on the parent. `adjust` writes a custom property on the
|
|
82
|
+
* same element for a different reason — inheritance runs downwards — and this
|
|
83
|
+
* writes an attribute there because a descendant selector does too.
|
|
84
|
+
*
|
|
85
|
+
* The parent is read from the ref rather than held, so the cleanup removes the
|
|
86
|
+
* attribute from the element it was written to even when the button has
|
|
87
|
+
* already gone.
|
|
88
|
+
*/
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
const parent = trigger.current?.parentElement;
|
|
91
|
+
if (!parent)
|
|
92
|
+
return;
|
|
93
|
+
parent.setAttribute(PRESENTED_ATTRIBUTE, open ? "true" : "false");
|
|
94
|
+
return () => parent.removeAttribute(PRESENTED_ATTRIBUTE);
|
|
95
|
+
}, [open, usable]);
|
|
96
|
+
/**
|
|
97
|
+
* The three ways out, attached only while the region is showing. A dismiss
|
|
98
|
+
* event that arrives while it is closed is a control the primitive rendered
|
|
99
|
+
* inside a hidden region, which cannot be pressed — so there is nothing to
|
|
100
|
+
* hear and nothing listening costs nothing.
|
|
101
|
+
*/
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (!open)
|
|
104
|
+
return;
|
|
105
|
+
const parent = trigger.current?.parentElement;
|
|
106
|
+
if (!parent)
|
|
107
|
+
return;
|
|
108
|
+
const close = () => setOpen(false);
|
|
109
|
+
const onKeyDown = (event) => {
|
|
110
|
+
if (event.key === "Escape")
|
|
111
|
+
close();
|
|
112
|
+
};
|
|
113
|
+
const onPointerDown = (event) => {
|
|
114
|
+
const target = event.target;
|
|
115
|
+
if (target instanceof Node && parent.contains(target))
|
|
116
|
+
return;
|
|
117
|
+
close();
|
|
118
|
+
};
|
|
119
|
+
document.addEventListener("keydown", onKeyDown);
|
|
120
|
+
document.addEventListener("pointerdown", onPointerDown);
|
|
121
|
+
parent.addEventListener(DISMISS_EVENT, close);
|
|
122
|
+
return () => {
|
|
123
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
124
|
+
document.removeEventListener("pointerdown", onPointerDown);
|
|
125
|
+
parent.removeEventListener(DISMISS_EVENT, close);
|
|
126
|
+
};
|
|
127
|
+
}, [open]);
|
|
128
|
+
if (!usable)
|
|
129
|
+
return null;
|
|
130
|
+
return createElement("button", {
|
|
131
|
+
type: "button",
|
|
132
|
+
ref: trigger,
|
|
133
|
+
className: controlClass("present"),
|
|
134
|
+
onClick: toggle,
|
|
135
|
+
"aria-expanded": open,
|
|
136
|
+
style: TRIGGER_STYLE,
|
|
137
|
+
}, label);
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* The cross inside the region.
|
|
141
|
+
*
|
|
142
|
+
* **The only control in the vocabulary whose name is not rendered as text.** A
|
|
143
|
+
* close affordance on an overlay is a glyph everywhere a reader has ever met
|
|
144
|
+
* one, and a panel with the word "Close" spelled out beside the cross is a panel
|
|
145
|
+
* nobody designed. The text seam's guarantee is untouched and is the reason this
|
|
146
|
+
* is safe rather than a shortcut: the name is still declared by the primitive,
|
|
147
|
+
* still translated by the deployment's dictionary, still refused at registration
|
|
148
|
+
* if it is blank — it arrives as `aria-label` instead of as a child, so a screen
|
|
149
|
+
* reader is told what the button is and an eye is shown the cross.
|
|
150
|
+
*
|
|
151
|
+
* **It carries no state and reads none.** It does not know whether the region
|
|
152
|
+
* around it is open, because it does not have to: a closed region is hidden by
|
|
153
|
+
* the primitive's own rule and a button inside a `display: none` subtree cannot
|
|
154
|
+
* be pressed. So this dispatches and stops, and the trigger above it decides
|
|
155
|
+
* what that means.
|
|
156
|
+
*/
|
|
157
|
+
export const DismissControl = ({ label }) => {
|
|
158
|
+
const [usable, setUsable] = useState(false);
|
|
159
|
+
useEffect(() => setUsable(true), []);
|
|
160
|
+
const dismiss = useCallback((event) => {
|
|
161
|
+
event.currentTarget.dispatchEvent(new CustomEvent(DISMISS_EVENT, { bubbles: true }));
|
|
162
|
+
}, []);
|
|
163
|
+
if (!usable)
|
|
164
|
+
return null;
|
|
165
|
+
return createElement("button", {
|
|
166
|
+
type: "button",
|
|
167
|
+
className: controlClass("dismiss"),
|
|
168
|
+
onClick: dismiss,
|
|
169
|
+
"aria-label": label,
|
|
170
|
+
style: CLOSE_STYLE,
|
|
171
|
+
}, createElement("span", { "aria-hidden": true }, "×"));
|
|
172
|
+
};
|
|
173
|
+
//# sourceMappingURL=behaviour-present.js.map
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { PrimitiveType } from "../primitive-type.js";
|
|
3
|
+
import type { PrimitiveText } from "./text.js";
|
|
4
|
+
export { DISCLOSED_ATTRIBUTE } from "./disclosed.js";
|
|
5
|
+
export { DISMISS_EVENT, PRESENTED_ATTRIBUTE } from "./presented.js";
|
|
6
|
+
/**
|
|
7
|
+
* The behaviour seam: the things a primitive *does* that its props cannot carry.
|
|
8
|
+
*
|
|
9
|
+
* It is the fourth gap of the shape §4e, §4f and §4g each answered. Data is a
|
|
10
|
+
* question props cannot ask; text is a string props must not hold; a submission
|
|
11
|
+
* is an address props may not name. A **behaviour** is an interaction props
|
|
12
|
+
* cannot express at all — a click handler is a function, and a primitive's
|
|
13
|
+
* props are JSON.
|
|
14
|
+
*
|
|
15
|
+
* The case that forced it is the copy button on a code panel: every reference
|
|
16
|
+
* site a developer reads has one, and `loom.code` could not have one, because
|
|
17
|
+
* there was nowhere for a behaviour to come from. `interactive` was the closest
|
|
18
|
+
* thing and it is not that — it *describes* a target so the Gate can refuse a
|
|
19
|
+
* bad nesting, and describing one does not create one.
|
|
20
|
+
*
|
|
21
|
+
* **A behaviour is a control the framework builds and a primitive places.** Not
|
|
22
|
+
* a prop, not a script a host remembers to install, not a client boundary each
|
|
23
|
+
* primitive opens for itself:
|
|
24
|
+
*
|
|
25
|
+
* - **Not a prop**, for 0055's reason. A prop is written by a model and weighed
|
|
26
|
+
* by the Gate as a small reversible change, and "this button now copies
|
|
27
|
+
* something else" is not that. Nothing in the tree names a behaviour; the
|
|
28
|
+
* registered component does, and a human approved that component once.
|
|
29
|
+
* - **Not a host-installed script**, for 0055's other reason. A primitive that
|
|
30
|
+
* works only where somebody remembered to link something fails silently, in
|
|
31
|
+
* someone else's deployment, with nothing in the render to say why.
|
|
32
|
+
* - **Not a client boundary per primitive.** That is the shape this could have
|
|
33
|
+
* taken and the reason it does not is the closed set. The things a Loom page
|
|
34
|
+
* may *do* are as much a bounded vocabulary as the primitives it may name and
|
|
35
|
+
* the schemes a URL may use (0053); a library where any component may open a
|
|
36
|
+
* boundary has no such list, and nothing to check against it.
|
|
37
|
+
*
|
|
38
|
+
* So the vocabulary is here, one entry per behaviour, and `src/primitives/`
|
|
39
|
+
* declares from it and never implements. Three things follow, and each one is a
|
|
40
|
+
* check the registry can make at registration rather than a bug someone finds
|
|
41
|
+
* on a page:
|
|
42
|
+
*
|
|
43
|
+
* - A control needs an **accessible name**, so a behaviour names the text keys
|
|
44
|
+
* the primitive must declare — and they resolve through the ordinary text
|
|
45
|
+
* seam, so a German deployment translates the copy button with the dictionary
|
|
46
|
+
* it already has.
|
|
47
|
+
* - A control **is a target**, so a primitive that takes one must say it is
|
|
48
|
+
* `interactive` — otherwise the Gate would let a code panel with a copy
|
|
49
|
+
* button sit inside a linked card, which is a button inside an anchor and one
|
|
50
|
+
* of the two silently stops working.
|
|
51
|
+
* - A behaviour the primitive **never places** is a control that never appears,
|
|
52
|
+
* which is what the conformance probe reports the same way it reports a
|
|
53
|
+
* declared slot nobody rendered.
|
|
54
|
+
*
|
|
55
|
+
* What a control acts on comes from the **tree**, not from the DOM. The copy
|
|
56
|
+
* button copies the text of the node it belongs to, read off the same tree the
|
|
57
|
+
* page was projected from — so it is right before the browser has laid anything
|
|
58
|
+
* out, needs no ref into markup the primitive owns, and copies what the page
|
|
59
|
+
* *says* rather than whatever text happened to render beside it.
|
|
60
|
+
*
|
|
61
|
+
* Two members later that is still true of what a control *reads*, and the
|
|
62
|
+
* vocabulary has grown a second axis it says nothing about: what a control hands
|
|
63
|
+
* *back*. `copy` hands back nothing. `disclose` hands back a boolean, on its own
|
|
64
|
+
* element, which a sibling selector reaches. `adjust` hands back a number, on the
|
|
65
|
+
* element the primitive placed it in, because inheritance is the only way a
|
|
66
|
+
* stylesheet can compute with one. Each is the smallest thing that reaches the
|
|
67
|
+
* layout it has to reach, and
|
|
68
|
+
* [0096](../../decisions/0096-a-behaviour-publishes-a-value-on-the-element-the-primitive-placed-it-in.md)
|
|
69
|
+
* records why the third could not be the second.
|
|
70
|
+
*
|
|
71
|
+
* `present` and `dismiss` are the fourth and fifth, and they are the first
|
|
72
|
+
* *pair*: a third axis, which is whether a control is answerable to another one.
|
|
73
|
+
* Every member before them is complete on its own, and an overlay is the case
|
|
74
|
+
* where that stops being possible — a dialog is closed by a cross inside the
|
|
75
|
+
* panel as well as by the trigger that opened it, and a click handler is a
|
|
76
|
+
* function whichever button it is on. So `dismiss` is meaningless without
|
|
77
|
+
* `present`, which is a fourth thing the registry checks at registration, and
|
|
78
|
+
* the two agree through the DOM rather than through the seam. `presented.ts`
|
|
79
|
+
* carries why, and [0176](../../decisions/0176-a-control-may-be-answerable-to-another-control-and-they-agree-through-the-dom.md)
|
|
80
|
+
* records what was rejected.
|
|
81
|
+
*
|
|
82
|
+
* What a control hands back is not the same question as what a primitive may say
|
|
83
|
+
* about it, and the second one lives in `control.ts`: the class every control
|
|
84
|
+
* carries, and the custom property that decides whether it is displayed. Both
|
|
85
|
+
* exist because a control's presentation is an inline style, which a rule cannot
|
|
86
|
+
* beat.
|
|
87
|
+
*/
|
|
88
|
+
export declare const BEHAVIOUR_NAMES: readonly ["copy", "disclose", "adjust", "present", "dismiss"];
|
|
89
|
+
export type BehaviourName = (typeof BEHAVIOUR_NAMES)[number];
|
|
90
|
+
/**
|
|
91
|
+
* The custom property an adjust control publishes its value on: a plain number
|
|
92
|
+
* between {@link ADJUST_MINIMUM} and {@link ADJUST_MAXIMUM}, no unit.
|
|
93
|
+
*
|
|
94
|
+
* **This is the whole of the contract between the runtime and a primitive that
|
|
95
|
+
* takes `adjust`**, and it is a custom property rather than an attribute for the
|
|
96
|
+
* one reason an attribute cannot be made to work: what this hands back is a
|
|
97
|
+
* number a stylesheet has to *compute with*, and there is no portable way to
|
|
98
|
+
* read an attribute's value into a length. `attr()` outside `content` is not
|
|
99
|
+
* something a library may rely on today.
|
|
100
|
+
*
|
|
101
|
+
* A property is read with `var()`, which resolves by **inheritance**, and that
|
|
102
|
+
* is what makes this behaviour differ from `disclose` in a way worth stating
|
|
103
|
+
* rather than glossing. `data-loom-disclosed` is read *sideways*, by an ordinary
|
|
104
|
+
* sibling selector, so the control stamping it on its own button reaches the
|
|
105
|
+
* region beside it. Inheritance runs downwards only, so a property set on the
|
|
106
|
+
* control's own element would be readable by nothing at all — least of all the
|
|
107
|
+
* sibling region the control exists to drive.
|
|
108
|
+
*
|
|
109
|
+
* So the control writes this property on **the element the primitive placed it
|
|
110
|
+
* in**, its parent, and the primitive reads it from anywhere in that subtree.
|
|
111
|
+
* The unit is left off deliberately, so one value serves every use:
|
|
112
|
+
*
|
|
113
|
+
* ```css
|
|
114
|
+
* .after { clip-path: inset(0 calc(100% - var(--loom-adjust, 50) * 1%) 0 0) }
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* **The fallback is not optional and not decoration.** The property is absent
|
|
118
|
+
* until the control has mounted and proved scripting runs, and absent again the
|
|
119
|
+
* moment it unmounts — so the second argument to `var()` is what a page served
|
|
120
|
+
* with scripting off renders, and it should be the position the primitive's own
|
|
121
|
+
* props declared. That is what keeps the still version of a comparison the thing
|
|
122
|
+
* that ships, rather than a blank waiting on a control that may never arrive.
|
|
123
|
+
*
|
|
124
|
+
* See [0096](../../decisions/0096-a-behaviour-publishes-a-value-on-the-element-the-primitive-placed-it-in.md).
|
|
125
|
+
*/
|
|
126
|
+
export declare const ADJUST_PROPERTY = "--loom-adjust";
|
|
127
|
+
/** The bottom of an adjust control's range. */
|
|
128
|
+
export declare const ADJUST_MINIMUM = 0;
|
|
129
|
+
/**
|
|
130
|
+
* The top of an adjust control's range.
|
|
131
|
+
*
|
|
132
|
+
* A percentage rather than a unit interval, because every use so far multiplies
|
|
133
|
+
* by `1%` and a stylesheet author reading `var(--loom-adjust)` should see the
|
|
134
|
+
* number they would have typed. Fixed rather than declarable for the reason the
|
|
135
|
+
* seam gives about props: what a control ranges over is not a model's to write.
|
|
136
|
+
*/
|
|
137
|
+
export declare const ADJUST_MAXIMUM = 100;
|
|
138
|
+
/**
|
|
139
|
+
* Where the control sits before anybody moves it.
|
|
140
|
+
*
|
|
141
|
+
* The midpoint, and it is the control's rather than the primitive's on purpose.
|
|
142
|
+
* `build` receives the node's text and its content, not its props, so there is
|
|
143
|
+
* nothing here that could read a declared position — and nothing that needs to:
|
|
144
|
+
* the primitive supplies its own position as the `var()` fallback, which covers
|
|
145
|
+
* the case that actually matters, the page where the control never mounts. Once
|
|
146
|
+
* a reader has a slider in front of them, where it started is theirs to change.
|
|
147
|
+
*/
|
|
148
|
+
export declare const ADJUST_RESTING = 50;
|
|
149
|
+
type Behaviour = {
|
|
150
|
+
/** One line, for the reference. A behaviour is never shown to a model. */
|
|
151
|
+
readonly description: string;
|
|
152
|
+
/**
|
|
153
|
+
* The text keys the primitive must declare for this control to have a name.
|
|
154
|
+
* Checked at registration, so a control with no accessible name is not
|
|
155
|
+
* reachable by leaving something out.
|
|
156
|
+
*/
|
|
157
|
+
readonly text: readonly string[];
|
|
158
|
+
/**
|
|
159
|
+
* Whether it puts something on the page the reader aims at. Everything so far
|
|
160
|
+
* does; the field exists because the check it drives — that the primitive
|
|
161
|
+
* declares itself `interactive` — would be wrong to apply to a behaviour that
|
|
162
|
+
* renders nothing, and the first of those is a question of when, not if.
|
|
163
|
+
*/
|
|
164
|
+
readonly rendersControl: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Another member of the vocabulary this one does nothing without.
|
|
167
|
+
*
|
|
168
|
+
* `undefined` for every behaviour that is complete on its own, which is four
|
|
169
|
+
* of the five. It exists for `dismiss`, whose control asks the nearest
|
|
170
|
+
* presentation above it to close: declared without `present`, it renders a
|
|
171
|
+
* button that dispatches an event nothing is listening for, on a region
|
|
172
|
+
* nothing opens. That is a dead control rather than a wrong one, so it is
|
|
173
|
+
* refused at registration rather than reported by the audit — the same
|
|
174
|
+
* judgement the seam already makes about a control with no accessible name.
|
|
175
|
+
*/
|
|
176
|
+
readonly requires?: BehaviourName;
|
|
177
|
+
readonly build: (content: string, text: PrimitiveText<string>) => ReactNode;
|
|
178
|
+
};
|
|
179
|
+
export declare const BEHAVIOURS: Readonly<Record<BehaviourName, Behaviour>>;
|
|
180
|
+
export declare const isBehaviourName: (value: string) => value is BehaviourName;
|
|
181
|
+
/**
|
|
182
|
+
* The controls a primitive receives, by declared behaviour name — already built
|
|
183
|
+
* and ready to place, the way `loom.slots` hands over rendered regions.
|
|
184
|
+
*
|
|
185
|
+
* A node rather than a component on purpose. There is nothing left for the
|
|
186
|
+
* primitive to configure: the text came from its own declarations and the
|
|
187
|
+
* content came from the tree, so a component here would be a component with no
|
|
188
|
+
* props anybody could get right or wrong. Placing it is the whole of the
|
|
189
|
+
* primitive's part, and where it goes is the whole of its discretion.
|
|
190
|
+
*
|
|
191
|
+
* `TName` is the union of names the primitive declared, so reading a behaviour
|
|
192
|
+
* it did not ask for does not compile — the same bargain `loom.text` makes.
|
|
193
|
+
*/
|
|
194
|
+
export type PrimitiveBehaviours<TName extends BehaviourName = never> = Readonly<Record<TName, ReactNode>>;
|
|
195
|
+
/**
|
|
196
|
+
* The map handed to a primitive that declared none. Null-prototype for the
|
|
197
|
+
* reason `NO_TEXT` gives: `constructor` is not a behaviour name today, and a
|
|
198
|
+
* lookup that answered with a function off `Object.prototype` if it ever were
|
|
199
|
+
* is not a thing anyone should have to debug from a rendered page.
|
|
200
|
+
*/
|
|
201
|
+
export declare const NO_BEHAVIOURS: PrimitiveBehaviours<BehaviourName>;
|
|
202
|
+
/**
|
|
203
|
+
* The renderer's whole dependency on the seam: which behaviours a type declared.
|
|
204
|
+
*
|
|
205
|
+
* A separate interface for the reason `TextResolver` is one, with the opposite
|
|
206
|
+
* conclusion about wiring: there is nothing for a host to supply here, because
|
|
207
|
+
* a behaviour's implementation is this package's and its strings arrive through
|
|
208
|
+
* the text seam. So a registry built by §4's SDK answers this, and a resolver
|
|
209
|
+
* that is not one has no declarations to lose.
|
|
210
|
+
*/
|
|
211
|
+
export interface BehaviourResolver {
|
|
212
|
+
readonly behavioursFor: (type: PrimitiveType) => readonly BehaviourName[];
|
|
213
|
+
}
|
|
214
|
+
export declare const isBehaviourResolver: (value: object) => value is BehaviourResolver;
|
|
215
|
+
/** A declared behaviour whose control could not be given a name. */
|
|
216
|
+
export type UnnamedBehaviour = {
|
|
217
|
+
readonly behaviour: BehaviourName;
|
|
218
|
+
readonly key: string;
|
|
219
|
+
};
|
|
220
|
+
export type ResolvedBehaviours = {
|
|
221
|
+
readonly behaviours: PrimitiveBehaviours<BehaviourName>;
|
|
222
|
+
/**
|
|
223
|
+
* Behaviours left out because a key resolved to nothing. The registry refuses
|
|
224
|
+
* a primitive that declares neither, so the way here is a host dictionary
|
|
225
|
+
* that answers a declared key with a blank — which `overlayText` has no
|
|
226
|
+
* business second-guessing and this has no business rendering.
|
|
227
|
+
*/
|
|
228
|
+
readonly unnamed: readonly UnnamedBehaviour[];
|
|
229
|
+
};
|
|
230
|
+
export declare const NO_RESOLVED_BEHAVIOURS: ResolvedBehaviours;
|
|
231
|
+
/**
|
|
232
|
+
* Builds the controls for one node.
|
|
233
|
+
*
|
|
234
|
+
* A behaviour whose text is missing or blank is **dropped rather than rendered
|
|
235
|
+
* nameless**. That is the same judgement the text seam makes about a control
|
|
236
|
+
* with no accessible name, taken one step further because there is a whole
|
|
237
|
+
* control to leave out here rather than a string to fall back on: a copy button
|
|
238
|
+
* a screen reader announces as "button" is worse than a page with no copy
|
|
239
|
+
* button, in exactly the way the finding that asked for this said a fake one
|
|
240
|
+
* would be.
|
|
241
|
+
*/
|
|
242
|
+
export declare const resolveBehaviours: (names: readonly BehaviourName[], content: string, text: PrimitiveText<string>) => ResolvedBehaviours;
|
|
243
|
+
//# sourceMappingURL=behaviour.d.ts.map
|