@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,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The longest anchor a tree may name.
|
|
3
|
+
*
|
|
4
|
+
* A bound rather than a judgement about slugs: this is markup a model writes
|
|
5
|
+
* into the document, and every other place a proposal writes a string has one.
|
|
6
|
+
* Nothing legible reaches it — the longest anchor in this repository's own
|
|
7
|
+
* writing is a third of it.
|
|
8
|
+
*/
|
|
9
|
+
export const ANCHOR_MAX_LENGTH = 64;
|
|
10
|
+
/**
|
|
11
|
+
* Lowercase words of letters and digits, joined by single hyphens.
|
|
12
|
+
*
|
|
13
|
+
* Deliberately narrower than what an `id` attribute permits, which since HTML5
|
|
14
|
+
* is very nearly anything. The grammar is not about what the document accepts;
|
|
15
|
+
* it is about what survives the round trip from the tree, through a URL a person
|
|
16
|
+
* copies out of an address bar, and back to the element. Three things it
|
|
17
|
+
* excludes, each of which parses as an `id` and then fails to be found:
|
|
18
|
+
*
|
|
19
|
+
* **Capitals.** Fragment matching is case-sensitive, so a tree that anchors
|
|
20
|
+
* `Pricing` and links to `#pricing` scrolls nowhere, silently, and the two
|
|
21
|
+
* strings look identical in a diff read quickly.
|
|
22
|
+
*
|
|
23
|
+
* **Spaces and everything else that must be encoded.** `#see it happen` reaches
|
|
24
|
+
* the browser as `#see%20it%20happen` and matches an element whose id contains a
|
|
25
|
+
* space, so it half works — until something in the chain normalises one spelling
|
|
26
|
+
* and not the other.
|
|
27
|
+
*
|
|
28
|
+
* **Leading, trailing and doubled hyphens.** Not wrong, exactly, and the only
|
|
29
|
+
* way they occur is a slug generated from a heading with punctuation in it, where
|
|
30
|
+
* they are the visible residue of a bug somewhere upstream.
|
|
31
|
+
*/
|
|
32
|
+
const ANCHOR_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
33
|
+
export const createAnchorLedger = () => {
|
|
34
|
+
const held = new Map();
|
|
35
|
+
return {
|
|
36
|
+
claim: (anchor, nodeId) => {
|
|
37
|
+
const holder = held.get(anchor);
|
|
38
|
+
if (holder !== undefined)
|
|
39
|
+
return holder;
|
|
40
|
+
held.set(anchor, nodeId);
|
|
41
|
+
return undefined;
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* The whole check, as a function of a declared value and what is already taken.
|
|
47
|
+
*
|
|
48
|
+
* Total, like every other reading of something a model wrote: a number where a
|
|
49
|
+
* slug goes, a slug with a space in it, or a slug another node already holds all
|
|
50
|
+
* come back as a reading rather than as a thrown error. A page is not lost
|
|
51
|
+
* because a proposal named a bad anchor; it renders with one band that cannot be
|
|
52
|
+
* linked to, and says so.
|
|
53
|
+
*
|
|
54
|
+
* Claiming happens here rather than in the caller so that the check and the
|
|
55
|
+
* record of it cannot come apart — there is no order of operations in which a
|
|
56
|
+
* node is told it is anchored and the ledger does not know.
|
|
57
|
+
*/
|
|
58
|
+
export const resolveAnchor = (declared, nodeId, ledger) => {
|
|
59
|
+
if (typeof declared !== "string") {
|
|
60
|
+
return {
|
|
61
|
+
status: "unusable",
|
|
62
|
+
detail: declared === undefined ? "no value was given" : `got ${typeof declared}`,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (declared.length === 0)
|
|
66
|
+
return { status: "unusable", detail: "it is empty" };
|
|
67
|
+
if (declared.length > ANCHOR_MAX_LENGTH) {
|
|
68
|
+
return {
|
|
69
|
+
status: "unusable",
|
|
70
|
+
detail: `it is ${declared.length} characters and the most an anchor may be is ${ANCHOR_MAX_LENGTH}`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (!ANCHOR_PATTERN.test(declared)) {
|
|
74
|
+
return {
|
|
75
|
+
status: "unusable",
|
|
76
|
+
detail: `"${declared}" is not lowercase letters, digits and single hyphens`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const holder = ledger.claim(declared, nodeId);
|
|
80
|
+
if (holder !== undefined)
|
|
81
|
+
return { status: "claimed", anchor: declared, holder };
|
|
82
|
+
return { status: "anchored", attributes: { id: declared } };
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=anchor.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type ChangeEvent } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* The third control that runs on the client, and the first that hands a value
|
|
4
|
+
* back to the primitive that placed it.
|
|
5
|
+
*
|
|
6
|
+
* `copy` acts on the node's own text, which is in the tree. `disclose` acts on a
|
|
7
|
+
* region of the render, and says so by stamping a boolean on its own button that
|
|
8
|
+
* the primitive's stylesheet selects on. Neither gives the primitive a *number*,
|
|
9
|
+
* and a wipe divider is a number: the thing it drives is a `clip-path`, and no
|
|
10
|
+
* attribute selector can be written that means "at 37 per cent".
|
|
11
|
+
*
|
|
12
|
+
* So this control publishes its value as a **CSS custom property** rather than
|
|
13
|
+
* an attribute, and that choice carries a consequence the other two do not have.
|
|
14
|
+
* `var()` resolves by inheritance — downwards — while `data-loom-disclosed` is
|
|
15
|
+
* read sideways by an ordinary sibling selector. A property this control set on
|
|
16
|
+
* its own element would therefore be readable by nothing, because the region it
|
|
17
|
+
* exists to drive is its sibling, not its child. See
|
|
18
|
+
* [0096](../../decisions/0096-a-behaviour-publishes-a-value-on-the-element-the-primitive-placed-it-in.md)
|
|
19
|
+
* for why the property goes on the **parent** instead, and what that costs.
|
|
20
|
+
*
|
|
21
|
+
* **It renders nothing until it knows scripting runs**, for the reason the other
|
|
22
|
+
* two give, and here the fallback is the whole point rather than a consolation.
|
|
23
|
+
* A primitive reads the value as `var(--loom-adjust, 50)` with its own declared
|
|
24
|
+
* position as the fallback, so a page served with scripting off shows the still
|
|
25
|
+
* comparison at the position the tree asked for — which is what most pages using
|
|
26
|
+
* this actually are. Nothing is hidden behind a control that never arrives.
|
|
27
|
+
*
|
|
28
|
+
* **A range input rather than a hand-built handle.** Dragging, arrow keys, Home
|
|
29
|
+
* and End, the announced role and the announced value are all a browser's to get
|
|
30
|
+
* right, and a `role="slider"` div reimplements every one of them worse. The
|
|
31
|
+
* pure-CSS routes were weighed and rejected before this seam existed — a range
|
|
32
|
+
* input cannot drive a clip *in CSS alone*, which is true and is exactly the gap
|
|
33
|
+
* a behaviour fills: the value is read here, in a component, and written where
|
|
34
|
+
* a stylesheet can reach it.
|
|
35
|
+
*/
|
|
36
|
+
export type AdjustControlProps = {
|
|
37
|
+
/**
|
|
38
|
+
* The control's name, in the language this deployment serves. A slider with no
|
|
39
|
+
* accessible name is announced as a bare "slider", which is the failure the
|
|
40
|
+
* text seam exists to prevent — so the seam drops the control rather than
|
|
41
|
+
* render it nameless, and this never receives a blank.
|
|
42
|
+
*/
|
|
43
|
+
readonly label: string;
|
|
44
|
+
};
|
|
45
|
+
export declare const AdjustControl: ({ label }: AdjustControlProps) => import("react").DetailedReactHTMLElement<{
|
|
46
|
+
ref: import("react").RefObject<HTMLInputElement | null>;
|
|
47
|
+
type: string;
|
|
48
|
+
className: string;
|
|
49
|
+
min: number;
|
|
50
|
+
max: number;
|
|
51
|
+
value: number;
|
|
52
|
+
"aria-label": string;
|
|
53
|
+
onChange: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
54
|
+
style: {
|
|
55
|
+
readonly accentColor: "var(--loom-accent, currentColor)";
|
|
56
|
+
readonly display: string;
|
|
57
|
+
readonly cursor: "grab";
|
|
58
|
+
readonly margin: 0;
|
|
59
|
+
readonly verticalAlign: "middle";
|
|
60
|
+
};
|
|
61
|
+
}, HTMLInputElement> | null;
|
|
62
|
+
//# sourceMappingURL=behaviour-adjust.d.ts.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createElement, useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { ADJUST_MAXIMUM, ADJUST_MINIMUM, ADJUST_PROPERTY, ADJUST_RESTING } from "./behaviour.js";
|
|
4
|
+
import { controlClass, controlDisplay } from "./control.js";
|
|
5
|
+
/**
|
|
6
|
+
* `var()` with a fallback rather than the `tokens.ts` helpers, for the reason
|
|
7
|
+
* both other controls give: those live in `src/primitives/`, which the render
|
|
8
|
+
* seam must not depend on, and a control that only looks right on a themed page
|
|
9
|
+
* renders invisible in a preview pane that mounts no theme.
|
|
10
|
+
*
|
|
11
|
+
* `accentColor` is the one line that matters. It is the only way to theme a
|
|
12
|
+
* range input's thumb and track without replacing the whole control with
|
|
13
|
+
* pseudo-element rules per engine — which would be the hand-built handle this
|
|
14
|
+
* deliberately is not.
|
|
15
|
+
*
|
|
16
|
+
* `display` is set here rather than left to the browser, which is the one line
|
|
17
|
+
* that is not about appearance. The other two controls set it inline and so
|
|
18
|
+
* cannot be hidden by a rule; making this one the exception would mean the
|
|
19
|
+
* property that hides a control hides two of three. `inline-block` is what a
|
|
20
|
+
* range input is displayed as anyway, so writing it down changes no page.
|
|
21
|
+
*/
|
|
22
|
+
const INPUT_STYLE = {
|
|
23
|
+
accentColor: "var(--loom-accent, currentColor)",
|
|
24
|
+
display: controlDisplay("adjust", "inline-block"),
|
|
25
|
+
cursor: "grab",
|
|
26
|
+
margin: 0,
|
|
27
|
+
verticalAlign: "middle",
|
|
28
|
+
};
|
|
29
|
+
export const AdjustControl = ({ label }) => {
|
|
30
|
+
const [usable, setUsable] = useState(false);
|
|
31
|
+
const [value, setValue] = useState(ADJUST_RESTING);
|
|
32
|
+
const input = useRef(null);
|
|
33
|
+
/**
|
|
34
|
+
* Deliberately an effect rather than a render-time check, for the reason the
|
|
35
|
+
* other two controls give: anything read while rendering would make the
|
|
36
|
+
* server's markup and the browser's first render disagree, and React resolves
|
|
37
|
+
* that by keeping the server's — so the control would be missing exactly where
|
|
38
|
+
* it works. That the effect ran is the whole of the capability check.
|
|
39
|
+
*/
|
|
40
|
+
useEffect(() => setUsable(true), []);
|
|
41
|
+
/**
|
|
42
|
+
* `usable` is a dependency and not a redundant one: the first run happens
|
|
43
|
+
* while the control is still rendering nothing, so the ref is empty and there
|
|
44
|
+
* is no parent to write to. The write has to happen again once there is.
|
|
45
|
+
*
|
|
46
|
+
* The cleanup removes the property rather than leaving the last value behind.
|
|
47
|
+
* A primitive that unmounts its control — a media query that stops offering
|
|
48
|
+
* the comparison, a node the tree no longer holds — should fall back to its
|
|
49
|
+
* own declared position, and a stale custom property on an element the runtime
|
|
50
|
+
* does not own would quietly outlive the thing that set it.
|
|
51
|
+
*/
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const parent = input.current?.parentElement;
|
|
54
|
+
if (!parent)
|
|
55
|
+
return undefined;
|
|
56
|
+
parent.style.setProperty(ADJUST_PROPERTY, String(value));
|
|
57
|
+
return () => {
|
|
58
|
+
parent.style.removeProperty(ADJUST_PROPERTY);
|
|
59
|
+
};
|
|
60
|
+
}, [value, usable]);
|
|
61
|
+
const change = useCallback((event) => {
|
|
62
|
+
setValue(Number(event.target.value));
|
|
63
|
+
}, []);
|
|
64
|
+
if (!usable)
|
|
65
|
+
return null;
|
|
66
|
+
return createElement("input", {
|
|
67
|
+
ref: input,
|
|
68
|
+
type: "range",
|
|
69
|
+
className: controlClass("adjust"),
|
|
70
|
+
min: ADJUST_MINIMUM,
|
|
71
|
+
max: ADJUST_MAXIMUM,
|
|
72
|
+
value,
|
|
73
|
+
"aria-label": label,
|
|
74
|
+
onChange: change,
|
|
75
|
+
style: INPUT_STYLE,
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=behaviour-adjust.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one control in the runtime that runs on the client.
|
|
3
|
+
*
|
|
4
|
+
* Everything else Loom renders is a projection of the tree and nothing more
|
|
5
|
+
* ([0008](../../decisions/0008-the-renderer-is-a-total-pure-projection.md)). A
|
|
6
|
+
* copy button cannot be: writing to the clipboard is a click handler, and a
|
|
7
|
+
* click handler is not expressible in JSON, which is what a primitive's props
|
|
8
|
+
* are ([0009](../../decisions/0009-primitives-receive-props-in-a-bag.md)).
|
|
9
|
+
* So it lives here, behind `"use client"`, and a primitive receives it already
|
|
10
|
+
* built — see `behaviour.ts` for why that is the shape rather than a prop, a
|
|
11
|
+
* host-installed script, or a primitive of its own.
|
|
12
|
+
*
|
|
13
|
+
* **It renders nothing until it knows it will work.** The server render and the
|
|
14
|
+
* first client render are both empty, and the button appears from an effect
|
|
15
|
+
* once `navigator.clipboard.writeText` is actually there. That costs a paint
|
|
16
|
+
* and buys the property the finding this closes insisted on: a button that
|
|
17
|
+
* looks like it copies and does not is worse for a visitor than no button, and
|
|
18
|
+
* an insecure origin, an old browser and a page served with scripting off are
|
|
19
|
+
* three ordinary ways to get one. Nothing here guesses; it asks.
|
|
20
|
+
*
|
|
21
|
+
* The two labels arrive as props because they are the primitive's declared
|
|
22
|
+
* strings, resolved through the text seam like every other string a component
|
|
23
|
+
* owns (0063). There is no English in this file.
|
|
24
|
+
*/
|
|
25
|
+
export type CopyControlProps = {
|
|
26
|
+
/** What goes on the clipboard: the text of the node the behaviour belongs to. */
|
|
27
|
+
readonly value: string;
|
|
28
|
+
/** The control's name, in the language this deployment serves. */
|
|
29
|
+
readonly label: string;
|
|
30
|
+
/** What it says for a moment after a successful write. */
|
|
31
|
+
readonly copiedLabel: string;
|
|
32
|
+
};
|
|
33
|
+
export declare const CopyControl: ({ value, label, copiedLabel }: CopyControlProps) => import("react").DetailedReactHTMLElement<{
|
|
34
|
+
type: string;
|
|
35
|
+
className: string;
|
|
36
|
+
onClick: () => void;
|
|
37
|
+
style: {
|
|
38
|
+
readonly display: string;
|
|
39
|
+
readonly alignItems: "center";
|
|
40
|
+
readonly gap: "var(--loom-spacing-1, 4px)";
|
|
41
|
+
readonly paddingBlock: "var(--loom-spacing-1, 4px)";
|
|
42
|
+
readonly paddingInline: "var(--loom-spacing-2, 8px)";
|
|
43
|
+
readonly fontFamily: "inherit";
|
|
44
|
+
readonly fontSize: "var(--loom-scale-1, 0.75rem)";
|
|
45
|
+
readonly lineHeight: 1.2;
|
|
46
|
+
readonly color: "var(--loom-fg-muted, currentColor)";
|
|
47
|
+
readonly background: "var(--loom-bg-surface, transparent)";
|
|
48
|
+
readonly border: "1px solid var(--loom-border-subtle, currentColor)";
|
|
49
|
+
readonly borderRadius: "var(--loom-radius-sm, 4px)";
|
|
50
|
+
readonly cursor: "pointer";
|
|
51
|
+
};
|
|
52
|
+
}, HTMLElement> | null;
|
|
53
|
+
//# sourceMappingURL=behaviour-copy.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createElement, useCallback, useEffect, useState } from "react";
|
|
3
|
+
import { controlClass, controlDisplay } from "./control.js";
|
|
4
|
+
/**
|
|
5
|
+
* How long the control shows its confirmation. Long enough to read, short
|
|
6
|
+
* enough that a reader who copies twice sees the second one happen.
|
|
7
|
+
*/
|
|
8
|
+
const CONFIRMATION_MS = 2000;
|
|
9
|
+
/**
|
|
10
|
+
* `var()` with a fallback, rather than the `tokens.ts` helpers, for two reasons
|
|
11
|
+
* that point the same way: those live in `src/primitives/`, which the render
|
|
12
|
+
* seam must not depend on, and a control that only looks right on a themed page
|
|
13
|
+
* would render invisible in a preview pane that mounts no theme. The variables
|
|
14
|
+
* themselves are this package's own — `theme/apply.ts` emits every one of them.
|
|
15
|
+
*
|
|
16
|
+
* `display` is the one line a primitive can take back, because it is the one a
|
|
17
|
+
* primitive has to: an inline declaration beats the rule a stylesheet would aim
|
|
18
|
+
* at the control's class, and whether a button belongs at this width is not
|
|
19
|
+
* something the runtime knows. See `controlDisplay` for the two names that
|
|
20
|
+
* override it.
|
|
21
|
+
*/
|
|
22
|
+
const BUTTON_STYLE = {
|
|
23
|
+
display: controlDisplay("copy", "inline-flex"),
|
|
24
|
+
alignItems: "center",
|
|
25
|
+
gap: "var(--loom-spacing-1, 4px)",
|
|
26
|
+
paddingBlock: "var(--loom-spacing-1, 4px)",
|
|
27
|
+
paddingInline: "var(--loom-spacing-2, 8px)",
|
|
28
|
+
fontFamily: "inherit",
|
|
29
|
+
fontSize: "var(--loom-scale-1, 0.75rem)",
|
|
30
|
+
lineHeight: 1.2,
|
|
31
|
+
color: "var(--loom-fg-muted, currentColor)",
|
|
32
|
+
background: "var(--loom-bg-surface, transparent)",
|
|
33
|
+
border: "1px solid var(--loom-border-subtle, currentColor)",
|
|
34
|
+
borderRadius: "var(--loom-radius-sm, 4px)",
|
|
35
|
+
cursor: "pointer",
|
|
36
|
+
};
|
|
37
|
+
export const CopyControl = ({ value, label, copiedLabel }) => {
|
|
38
|
+
const [state, setState] = useState("unusable");
|
|
39
|
+
/**
|
|
40
|
+
* Deliberately an effect rather than a render-time check. Reading
|
|
41
|
+
* `navigator` while rendering would make the server's markup and the
|
|
42
|
+
* browser's first render disagree, which React resolves by keeping the
|
|
43
|
+
* server's — so the button would be missing exactly where it works.
|
|
44
|
+
*/
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (typeof navigator !== "undefined" && typeof navigator.clipboard?.writeText === "function") {
|
|
47
|
+
setState("idle");
|
|
48
|
+
}
|
|
49
|
+
}, []);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (state !== "copied")
|
|
52
|
+
return undefined;
|
|
53
|
+
const timer = setTimeout(() => setState("idle"), CONFIRMATION_MS);
|
|
54
|
+
return () => clearTimeout(timer);
|
|
55
|
+
}, [state]);
|
|
56
|
+
const copy = useCallback(() => {
|
|
57
|
+
void navigator.clipboard.writeText(value).then(() => setState("copied"),
|
|
58
|
+
/**
|
|
59
|
+
* A refused clipboard — a permission the reader denied, a document that
|
|
60
|
+
* lost focus — leaves the control saying what it says. Announcing a copy
|
|
61
|
+
* that did not happen is the failure this whole control is arranged to
|
|
62
|
+
* avoid, and there is no second sentence here to say it with.
|
|
63
|
+
*/
|
|
64
|
+
() => setState("idle"));
|
|
65
|
+
}, [value]);
|
|
66
|
+
if (state === "unusable")
|
|
67
|
+
return null;
|
|
68
|
+
return createElement("button", {
|
|
69
|
+
type: "button",
|
|
70
|
+
className: controlClass("copy"),
|
|
71
|
+
onClick: copy,
|
|
72
|
+
style: BUTTON_STYLE,
|
|
73
|
+
}, createElement("span", { "aria-live": "polite" }, state === "copied" ? copiedLabel : label));
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=behaviour-copy.js.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A button that opens and closes the region beside it.
|
|
3
|
+
*
|
|
4
|
+
* The second control in the runtime that runs on the client, and it exists for
|
|
5
|
+
* the same reason as the first: a disclosure is a behaviour, a behaviour is a
|
|
6
|
+
* function, and a primitive's props are JSON
|
|
7
|
+
* ([0009](../../decisions/0009-primitives-receive-props-in-a-bag.md)).
|
|
8
|
+
* See `behaviour.ts` for why that makes it the runtime's to build rather than
|
|
9
|
+
* the primitive's, and 0091 for why the *region* is nonetheless the primitive's
|
|
10
|
+
* to hide.
|
|
11
|
+
*
|
|
12
|
+
* **It owns one element and no more.** The control does not wrap the region,
|
|
13
|
+
* does not reach for it with a ref, and is not told where it is. It stamps its
|
|
14
|
+
* own state on its own button as `data-loom-disclosed`, and the primitive's
|
|
15
|
+
* stylesheet decides what that means for the layout it owns — an ordinary
|
|
16
|
+
* sibling or `:has()` selector, in whatever media query the primitive wants the
|
|
17
|
+
* collapsing to apply to. That keeps the two halves at arm's length: the
|
|
18
|
+
* runtime knows nothing about navigation bars, and `loom.nav` gets to keep the
|
|
19
|
+
* box model it already has instead of taking a wrapper it did not ask for,
|
|
20
|
+
* which is the same objection 0086 raised against reading the DOM for the copy
|
|
21
|
+
* text.
|
|
22
|
+
*
|
|
23
|
+
* **One name, not two.** The button is called the same thing open and closed,
|
|
24
|
+
* and `aria-expanded` carries the state — the disclosure pattern as the ARIA
|
|
25
|
+
* practices state it. A control that renames itself "Close" when it opens says
|
|
26
|
+
* the state twice and says it differently to a screen reader than to an eye,
|
|
27
|
+
* which is why `copy` takes two strings for its momentary confirmation and this
|
|
28
|
+
* takes one for its name.
|
|
29
|
+
*
|
|
30
|
+
* **It renders nothing until it knows it will work**, exactly as the copy
|
|
31
|
+
* control does, and here the stakes are higher rather than lower. The capability
|
|
32
|
+
* it needs is that scripting runs at all, which the effect below is the proof
|
|
33
|
+
* of. Ship the button in the server's markup instead and a page served with
|
|
34
|
+
* scripting off gets a dead button, with — because the stylesheet keys off the
|
|
35
|
+
* closed state — every link in the menu hidden behind it and no way to reach
|
|
36
|
+
* one. Rendering late inverts that failure into a safe one: no button means no
|
|
37
|
+
* attribute, no attribute means no rule matches, and the region is simply
|
|
38
|
+
* visible the way it was before any of this existed.
|
|
39
|
+
*
|
|
40
|
+
* The cost is a paint. On a phone the region is briefly open and then collapses
|
|
41
|
+
* once hydration lands, which is visible and is the honest price of not being
|
|
42
|
+
* able to hide something before knowing it can be got back. A primitive that
|
|
43
|
+
* minds can transition the collapse; nothing here guesses.
|
|
44
|
+
*/
|
|
45
|
+
export type DiscloseControlProps = {
|
|
46
|
+
/**
|
|
47
|
+
* The control's name, in the language this deployment serves. Constant across
|
|
48
|
+
* both states — see above.
|
|
49
|
+
*/
|
|
50
|
+
readonly label: string;
|
|
51
|
+
};
|
|
52
|
+
export declare const DiscloseControl: ({ label }: DiscloseControlProps) => import("react").DetailedReactHTMLElement<{
|
|
53
|
+
type: string;
|
|
54
|
+
className: string;
|
|
55
|
+
onClick: () => void;
|
|
56
|
+
"aria-expanded": boolean;
|
|
57
|
+
"data-loom-disclosed": string;
|
|
58
|
+
style: {
|
|
59
|
+
readonly display: string;
|
|
60
|
+
readonly alignItems: "center";
|
|
61
|
+
readonly gap: "var(--loom-spacing-2, 8px)";
|
|
62
|
+
readonly paddingBlock: "var(--loom-spacing-1, 4px)";
|
|
63
|
+
readonly paddingInline: "var(--loom-spacing-2, 8px)";
|
|
64
|
+
readonly fontFamily: "inherit";
|
|
65
|
+
readonly fontSize: "var(--loom-scale-1, 0.75rem)";
|
|
66
|
+
readonly lineHeight: 1.2;
|
|
67
|
+
readonly color: "var(--loom-fg-muted, currentColor)";
|
|
68
|
+
readonly background: "var(--loom-bg-surface, transparent)";
|
|
69
|
+
readonly border: "1px solid var(--loom-border-subtle, currentColor)";
|
|
70
|
+
readonly borderRadius: "var(--loom-radius-sm, 4px)";
|
|
71
|
+
readonly cursor: "pointer";
|
|
72
|
+
};
|
|
73
|
+
}, HTMLElement> | null;
|
|
74
|
+
//# sourceMappingURL=behaviour-disclose.d.ts.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createElement, useCallback, useEffect, useState } from "react";
|
|
3
|
+
import { DISCLOSED_ATTRIBUTE } from "./behaviour.js";
|
|
4
|
+
import { controlClass, controlDisplay } from "./control.js";
|
|
5
|
+
const GLYPH_BAR = {
|
|
6
|
+
display: "block",
|
|
7
|
+
width: "0.875em",
|
|
8
|
+
height: "1.5px",
|
|
9
|
+
background: "currentColor",
|
|
10
|
+
borderRadius: "1px",
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* `var()` with a fallback rather than the `tokens.ts` helpers, for the reason
|
|
14
|
+
* the copy control gives: those live in `src/primitives/`, which the render seam
|
|
15
|
+
* must not depend on, and a control that only looks right on a themed page
|
|
16
|
+
* renders invisible in a preview pane that mounts no theme.
|
|
17
|
+
*
|
|
18
|
+
* `display` is the exception a primitive may take back, and this is the control
|
|
19
|
+
* that needed it first: a menu button belongs on a phone and not on a laptop,
|
|
20
|
+
* which is a rule about the button rather than about the region beside it. See
|
|
21
|
+
* `controlDisplay` for the two names that override it, and for the sharp edge —
|
|
22
|
+
* a hidden button still carries its state, so the rule keyed on that state has
|
|
23
|
+
* to be lifted in the same query.
|
|
24
|
+
*/
|
|
25
|
+
const BUTTON_STYLE = {
|
|
26
|
+
display: controlDisplay("disclose", "inline-flex"),
|
|
27
|
+
alignItems: "center",
|
|
28
|
+
gap: "var(--loom-spacing-2, 8px)",
|
|
29
|
+
paddingBlock: "var(--loom-spacing-1, 4px)",
|
|
30
|
+
paddingInline: "var(--loom-spacing-2, 8px)",
|
|
31
|
+
fontFamily: "inherit",
|
|
32
|
+
fontSize: "var(--loom-scale-1, 0.75rem)",
|
|
33
|
+
lineHeight: 1.2,
|
|
34
|
+
color: "var(--loom-fg-muted, currentColor)",
|
|
35
|
+
background: "var(--loom-bg-surface, transparent)",
|
|
36
|
+
border: "1px solid var(--loom-border-subtle, currentColor)",
|
|
37
|
+
borderRadius: "var(--loom-radius-sm, 4px)",
|
|
38
|
+
cursor: "pointer",
|
|
39
|
+
};
|
|
40
|
+
const GLYPH_STYLE = {
|
|
41
|
+
display: "inline-flex",
|
|
42
|
+
flexDirection: "column",
|
|
43
|
+
justifyContent: "center",
|
|
44
|
+
gap: "3px",
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Two bars rather than three. It reads as a menu at this size, and the third
|
|
48
|
+
* bar is the one that turns a glyph into a logo at small sizes. `aria-hidden`
|
|
49
|
+
* because the button already has a name and a screen reader announcing "image"
|
|
50
|
+
* beside it is noise.
|
|
51
|
+
*/
|
|
52
|
+
const glyph = () => createElement("span", { "aria-hidden": true, style: GLYPH_STYLE }, createElement("span", { key: "a", style: GLYPH_BAR }), createElement("span", { key: "b", style: GLYPH_BAR }));
|
|
53
|
+
export const DiscloseControl = ({ label }) => {
|
|
54
|
+
const [usable, setUsable] = useState(false);
|
|
55
|
+
const [open, setOpen] = useState(false);
|
|
56
|
+
/**
|
|
57
|
+
* Deliberately an effect rather than a render-time check, for the reason the
|
|
58
|
+
* copy control gives: anything read while rendering would make the server's
|
|
59
|
+
* markup and the browser's first render disagree, and React resolves that by
|
|
60
|
+
* keeping the server's — so the control would be missing exactly where it
|
|
61
|
+
* works. That the effect ran is the whole of the capability check; there is
|
|
62
|
+
* no second thing to ask for.
|
|
63
|
+
*/
|
|
64
|
+
useEffect(() => setUsable(true), []);
|
|
65
|
+
const toggle = useCallback(() => setOpen((was) => !was), []);
|
|
66
|
+
if (!usable)
|
|
67
|
+
return null;
|
|
68
|
+
return createElement("button", {
|
|
69
|
+
type: "button",
|
|
70
|
+
className: controlClass("disclose"),
|
|
71
|
+
onClick: toggle,
|
|
72
|
+
"aria-expanded": open,
|
|
73
|
+
[DISCLOSED_ATTRIBUTE]: open ? "true" : "false",
|
|
74
|
+
style: BUTTON_STYLE,
|
|
75
|
+
}, glyph(), createElement("span", { key: "label" }, label));
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=behaviour-disclose.js.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { type MouseEvent } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* The fourth and fifth controls that run on the client, and the first pair that
|
|
4
|
+
* has to agree about anything.
|
|
5
|
+
*
|
|
6
|
+
* `copy`, `disclose` and `adjust` are each one control answering to nobody. A
|
|
7
|
+
* presentation is two: the trigger that opens a region and the cross inside it
|
|
8
|
+
* that closes it. `presented.ts` carries why that could not be a shared store
|
|
9
|
+
* and is a bubbling event instead, and why the state is published on the
|
|
10
|
+
* element the primitive placed the trigger in rather than on the trigger.
|
|
11
|
+
*
|
|
12
|
+
* **What this is not.** It is not a dialog. The runtime opens and closes a
|
|
13
|
+
* boolean and says so in the markup; whether the region that boolean governs is
|
|
14
|
+
* a centred panel over a scrim, a menu under a button or a frame filling the
|
|
15
|
+
* viewport is the primitive's, along with every pixel of it. That is 0092's
|
|
16
|
+
* split, unchanged — the control owns its button and the primitive owns the
|
|
17
|
+
* region — extended to the case where the region needs a second button.
|
|
18
|
+
*
|
|
19
|
+
* **What a primitive still has to do, and the runtime cannot.** A modal traps
|
|
20
|
+
* focus, marks the rest of the page inert, and stops the document behind it
|
|
21
|
+
* scrolling. None of that is here, and none of it is a behaviour: they are
|
|
22
|
+
* facts about the region and the page around it, which is the half the primitive
|
|
23
|
+
* owns. A primitive that presents a *modal* region has to arrange them and this
|
|
24
|
+
* seam neither helps nor hinders it.
|
|
25
|
+
*/
|
|
26
|
+
export type PresentControlProps = {
|
|
27
|
+
/**
|
|
28
|
+
* The trigger's name, in the language this deployment serves. Constant across
|
|
29
|
+
* both states, for the reason the disclosure control gives: `aria-expanded`
|
|
30
|
+
* carries the state and a control that renames itself says it twice.
|
|
31
|
+
*/
|
|
32
|
+
readonly label: string;
|
|
33
|
+
};
|
|
34
|
+
export type DismissControlProps = {
|
|
35
|
+
/**
|
|
36
|
+
* The close control's name. Unlike every other control in the vocabulary this
|
|
37
|
+
* one is **not rendered as text** — see {@link DismissControl}.
|
|
38
|
+
*/
|
|
39
|
+
readonly label: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The trigger. It opens the region, publishes whether the region is showing, and
|
|
43
|
+
* closes it again on any of the three things that close an overlay.
|
|
44
|
+
*
|
|
45
|
+
* **It renders nothing until it knows scripting runs**, for the reason all three
|
|
46
|
+
* earlier controls give, and the consequence here is the one that decides which
|
|
47
|
+
* way a primitive must write its rule. No button means no attribute, no
|
|
48
|
+
* attribute means no rule matches, and the region is simply *there* — so a
|
|
49
|
+
* primitive hides its region with `[data-loom-presented="false"] .region` and
|
|
50
|
+
* never reveals it with the `"true"` form. Written the other way, a page served
|
|
51
|
+
* without scripting has a panel nothing can open and nothing to say why.
|
|
52
|
+
*
|
|
53
|
+
* **Escape and a press outside close it; a press inside does not.** "Outside" is
|
|
54
|
+
* measured against the element this control was placed in, which is the same
|
|
55
|
+
* element the state is published on and therefore the same box the primitive
|
|
56
|
+
* laid the region out inside. The one case that needs stating is a region drawn
|
|
57
|
+
* over the whole viewport: its scrim is inside that element too, so a press on
|
|
58
|
+
* it is an inside press and will not dismiss. A primitive doing that places a
|
|
59
|
+
* `dismiss` control, which is what it is for.
|
|
60
|
+
*/
|
|
61
|
+
export declare const PresentControl: ({ label }: PresentControlProps) => import("react").DetailedReactHTMLElement<{
|
|
62
|
+
type: string;
|
|
63
|
+
ref: import("react").RefObject<HTMLButtonElement | null>;
|
|
64
|
+
className: string;
|
|
65
|
+
onClick: () => void;
|
|
66
|
+
"aria-expanded": boolean;
|
|
67
|
+
style: {
|
|
68
|
+
readonly display: string;
|
|
69
|
+
readonly alignItems: "center";
|
|
70
|
+
readonly gap: "var(--loom-spacing-2, 8px)";
|
|
71
|
+
readonly paddingBlock: "var(--loom-spacing-1, 4px)";
|
|
72
|
+
readonly paddingInline: "var(--loom-spacing-3, 12px)";
|
|
73
|
+
readonly fontFamily: "inherit";
|
|
74
|
+
readonly fontSize: "var(--loom-scale-1, 0.75rem)";
|
|
75
|
+
readonly lineHeight: 1.2;
|
|
76
|
+
readonly color: "var(--loom-fg-default, currentColor)";
|
|
77
|
+
readonly background: "var(--loom-bg-surface, transparent)";
|
|
78
|
+
readonly border: "1px solid var(--loom-border-subtle, currentColor)";
|
|
79
|
+
readonly borderRadius: "var(--loom-radius-sm, 4px)";
|
|
80
|
+
readonly cursor: "pointer";
|
|
81
|
+
};
|
|
82
|
+
}, HTMLButtonElement> | null;
|
|
83
|
+
/**
|
|
84
|
+
* The cross inside the region.
|
|
85
|
+
*
|
|
86
|
+
* **The only control in the vocabulary whose name is not rendered as text.** A
|
|
87
|
+
* close affordance on an overlay is a glyph everywhere a reader has ever met
|
|
88
|
+
* one, and a panel with the word "Close" spelled out beside the cross is a panel
|
|
89
|
+
* nobody designed. The text seam's guarantee is untouched and is the reason this
|
|
90
|
+
* is safe rather than a shortcut: the name is still declared by the primitive,
|
|
91
|
+
* still translated by the deployment's dictionary, still refused at registration
|
|
92
|
+
* if it is blank — it arrives as `aria-label` instead of as a child, so a screen
|
|
93
|
+
* reader is told what the button is and an eye is shown the cross.
|
|
94
|
+
*
|
|
95
|
+
* **It carries no state and reads none.** It does not know whether the region
|
|
96
|
+
* around it is open, because it does not have to: a closed region is hidden by
|
|
97
|
+
* the primitive's own rule and a button inside a `display: none` subtree cannot
|
|
98
|
+
* be pressed. So this dispatches and stops, and the trigger above it decides
|
|
99
|
+
* what that means.
|
|
100
|
+
*/
|
|
101
|
+
export declare const DismissControl: ({ label }: DismissControlProps) => import("react").DetailedReactHTMLElement<{
|
|
102
|
+
type: string;
|
|
103
|
+
className: string;
|
|
104
|
+
onClick: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
105
|
+
"aria-label": string;
|
|
106
|
+
style: {
|
|
107
|
+
readonly display: string;
|
|
108
|
+
readonly alignItems: "center";
|
|
109
|
+
readonly justifyContent: "center";
|
|
110
|
+
readonly inlineSize: "1.75em";
|
|
111
|
+
readonly blockSize: "1.75em";
|
|
112
|
+
readonly padding: 0;
|
|
113
|
+
readonly fontFamily: "inherit";
|
|
114
|
+
readonly fontSize: "var(--loom-scale-2, 0.875rem)";
|
|
115
|
+
readonly lineHeight: 1;
|
|
116
|
+
readonly color: "var(--loom-fg-muted, currentColor)";
|
|
117
|
+
readonly background: "transparent";
|
|
118
|
+
readonly border: "1px solid transparent";
|
|
119
|
+
readonly borderRadius: "var(--loom-radius-full, 999px)";
|
|
120
|
+
readonly cursor: "pointer";
|
|
121
|
+
};
|
|
122
|
+
}, HTMLElement> | null;
|
|
123
|
+
//# sourceMappingURL=behaviour-present.d.ts.map
|