@prestack/thread-ui 0.0.1 → 0.0.2
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/dist/ui/animations/anm_appear.ts +13 -0
- package/dist/ui/animations/anm_blur_in.ts +19 -0
- package/dist/ui/animations/anm_blur_out.ts +18 -0
- package/dist/ui/animations/anm_dismiss.ts +18 -0
- package/dist/ui/animations/anm_drop.ts +19 -0
- package/dist/ui/animations/anm_fall.ts +18 -0
- package/dist/ui/animations/anm_flash.ts +18 -0
- package/dist/ui/animations/anm_glow.ts +16 -0
- package/dist/ui/animations/anm_lift.ts +16 -0
- package/dist/ui/animations/anm_nudge.ts +16 -0
- package/dist/ui/animations/anm_pop_in.ts +23 -0
- package/dist/ui/animations/anm_pop_out.ts +22 -0
- package/dist/ui/animations/anm_press.ts +12 -0
- package/dist/ui/animations/anm_pulse.ts +13 -0
- package/dist/ui/animations/anm_rise.ts +19 -0
- package/dist/ui/animations/anm_shake.ts +13 -0
- package/dist/ui/animations/anm_slide_in_left.ts +19 -0
- package/dist/ui/animations/anm_slide_in_right.ts +19 -0
- package/dist/ui/animations/anm_slide_out_left.ts +18 -0
- package/dist/ui/animations/anm_slide_out_right.ts +18 -0
- package/dist/ui/animations/anm_spin.ts +12 -0
- package/dist/ui/animations/anm_swell.ts +16 -0
- package/dist/ui/animations/anm_wobble.ts +24 -0
- package/dist/ui/animations/anm_zoom_in.ts +19 -0
- package/dist/ui/animations/anm_zoom_out.ts +18 -0
- package/dist/ui/animations.ts +317 -0
- package/dist/ui/attach.js +13 -4
- package/dist/ui/attach.ts +613 -0
- package/dist/ui/charts.tsx +74 -0
- package/dist/ui/checked.d.ts +2 -2
- package/dist/ui/checked.ts +32 -0
- package/dist/ui/collector.ts +140 -0
- package/dist/ui/compositions.d.ts +10 -1
- package/dist/ui/compositions.js +262 -23
- package/dist/ui/compositions.ts +640 -0
- package/dist/ui/consent.ts +55 -0
- package/dist/ui/content.tsx +39 -0
- package/dist/ui/contrast.ts +27 -0
- package/dist/ui/controls.tsx +30 -0
- package/dist/ui/disclosure.tsx +22 -0
- package/dist/ui/dismiss-layer.ts +87 -0
- package/dist/ui/door.ts +140 -0
- package/dist/ui/drag.ts +316 -0
- package/dist/ui/elements/accordion.js +2 -2
- package/dist/ui/elements/accordion.tsx +47 -0
- package/dist/ui/elements/accordion.works.ts +66 -0
- package/dist/ui/elements/aspect-ratio.js +1 -1
- package/dist/ui/elements/aspect-ratio.tsx +30 -0
- package/dist/ui/elements/aspect-ratio.works.ts +5 -0
- package/dist/ui/elements/avatar.js +1 -1
- package/dist/ui/elements/avatar.tsx +33 -0
- package/dist/ui/elements/avatar.works.ts +16 -0
- package/dist/ui/elements/badge.js +1 -1
- package/dist/ui/elements/badge.tsx +32 -0
- package/dist/ui/elements/badge.works.ts +9 -0
- package/dist/ui/elements/bars.js +2 -2
- package/dist/ui/elements/bars.tsx +49 -0
- package/dist/ui/elements/bars.works.ts +29 -0
- package/dist/ui/elements/box.js +3 -2
- package/dist/ui/elements/box.tsx +35 -0
- package/dist/ui/elements/breadcrumb.js +2 -2
- package/dist/ui/elements/breadcrumb.tsx +37 -0
- package/dist/ui/elements/breadcrumb.works.ts +24 -0
- package/dist/ui/elements/button.js +1 -1
- package/dist/ui/elements/button.tsx +45 -0
- package/dist/ui/elements/button.works.tsx +52 -0
- package/dist/ui/elements/column.js +1 -1
- package/dist/ui/elements/column.tsx +28 -0
- package/dist/ui/elements/consent.js +2 -2
- package/dist/ui/elements/consent.tsx +70 -0
- package/dist/ui/elements/consent.works.tsx +132 -0
- package/dist/ui/elements/donut.js +2 -2
- package/dist/ui/elements/donut.tsx +44 -0
- package/dist/ui/elements/donut.works.ts +42 -0
- package/dist/ui/elements/each.js +1 -1
- package/dist/ui/elements/each.tsx +33 -0
- package/dist/ui/elements/each.works.tsx +82 -0
- package/dist/ui/elements/empty.js +1 -1
- package/dist/ui/elements/empty.tsx +32 -0
- package/dist/ui/elements/field.js +1 -1
- package/dist/ui/elements/field.tsx +44 -0
- package/dist/ui/elements/field.works.ts +65 -0
- package/dist/ui/elements/funnel.js +2 -2
- package/dist/ui/elements/funnel.tsx +49 -0
- package/dist/ui/elements/funnel.works.ts +37 -0
- package/dist/ui/elements/gauge.js +1 -1
- package/dist/ui/elements/gauge.tsx +39 -0
- package/dist/ui/elements/gauge.works.ts +42 -0
- package/dist/ui/elements/glyph.js +1 -1
- package/dist/ui/elements/glyph.tsx +29 -0
- package/dist/ui/elements/glyph.works.tsx +42 -0
- package/dist/ui/elements/grid.js +1 -1
- package/dist/ui/elements/grid.tsx +28 -0
- package/dist/ui/elements/heatmap.js +2 -2
- package/dist/ui/elements/heatmap.tsx +47 -0
- package/dist/ui/elements/heatmap.works.ts +24 -0
- package/dist/ui/elements/hit-box.js +1 -1
- package/dist/ui/elements/hit-box.tsx +46 -0
- package/dist/ui/elements/hit-box.works.tsx +576 -0
- package/dist/ui/elements/image.js +1 -1
- package/dist/ui/elements/image.tsx +28 -0
- package/dist/ui/elements/line-chart.js +2 -2
- package/dist/ui/elements/line-chart.tsx +44 -0
- package/dist/ui/elements/line-chart.works.ts +41 -0
- package/dist/ui/elements/link.js +1 -1
- package/dist/ui/elements/link.tsx +37 -0
- package/dist/ui/elements/link.works.ts +25 -0
- package/dist/ui/elements/media.js +1 -1
- package/dist/ui/elements/media.tsx +56 -0
- package/dist/ui/elements/menu.js +2 -2
- package/dist/ui/elements/menu.tsx +50 -0
- package/dist/ui/elements/menu.works.tsx +153 -0
- package/dist/ui/elements/money.js +1 -1
- package/dist/ui/elements/money.tsx +28 -0
- package/dist/ui/elements/money.works.ts +9 -0
- package/dist/ui/elements/pagination.js +2 -2
- package/dist/ui/elements/pagination.tsx +38 -0
- package/dist/ui/elements/pagination.works.ts +20 -0
- package/dist/ui/elements/progress.js +1 -1
- package/dist/ui/elements/progress.tsx +33 -0
- package/dist/ui/elements/progress.works.ts +8 -0
- package/dist/ui/elements/radio-group.js +2 -2
- package/dist/ui/elements/radio-group.tsx +49 -0
- package/dist/ui/elements/radio-group.works.ts +33 -0
- package/dist/ui/elements/row.js +1 -1
- package/dist/ui/elements/row.tsx +28 -0
- package/dist/ui/elements/scatter.js +1 -1
- package/dist/ui/elements/scatter.tsx +41 -0
- package/dist/ui/elements/scatter.works.ts +38 -0
- package/dist/ui/elements/select.js +2 -2
- package/dist/ui/elements/select.tsx +42 -0
- package/dist/ui/elements/select.works.ts +5 -0
- package/dist/ui/elements/separator.js +1 -1
- package/dist/ui/elements/separator.tsx +30 -0
- package/dist/ui/elements/skeleton.js +1 -1
- package/dist/ui/elements/skeleton.tsx +30 -0
- package/dist/ui/elements/slider.js +1 -1
- package/dist/ui/elements/slider.tsx +33 -0
- package/dist/ui/elements/slider.works.ts +5 -0
- package/dist/ui/elements/sparkline.js +1 -1
- package/dist/ui/elements/sparkline.tsx +36 -0
- package/dist/ui/elements/sparkline.works.ts +32 -0
- package/dist/ui/elements/spinner.js +1 -1
- package/dist/ui/elements/spinner.tsx +32 -0
- package/dist/ui/elements/stack.js +1 -1
- package/dist/ui/elements/stack.tsx +28 -0
- package/dist/ui/elements/stat.js +1 -1
- package/dist/ui/elements/stat.tsx +35 -0
- package/dist/ui/elements/stat.works.ts +14 -0
- package/dist/ui/elements/surface.js +1 -1
- package/dist/ui/elements/surface.tsx +35 -0
- package/dist/ui/elements/surface.works.ts +9 -0
- package/dist/ui/elements/table.js +2 -2
- package/dist/ui/elements/table.tsx +61 -0
- package/dist/ui/elements/table.works.ts +30 -0
- package/dist/ui/elements/tabs.js +2 -2
- package/dist/ui/elements/tabs.tsx +47 -0
- package/dist/ui/elements/tabs.works.ts +84 -0
- package/dist/ui/elements/text.js +1 -1
- package/dist/ui/elements/text.tsx +32 -0
- package/dist/ui/elements/textarea.js +1 -1
- package/dist/ui/elements/textarea.tsx +37 -0
- package/dist/ui/elements/textarea.works.ts +5 -0
- package/dist/ui/elements/time.js +1 -1
- package/dist/ui/elements/time.tsx +34 -0
- package/dist/ui/elements/time.works.ts +25 -0
- package/dist/ui/elements/toggle.js +1 -1
- package/dist/ui/elements/toggle.tsx +33 -0
- package/dist/ui/elements/toggle.works.ts +5 -0
- package/dist/ui/elements/tooltip.js +1 -1
- package/dist/ui/elements/tooltip.tsx +39 -0
- package/dist/ui/elements/tooltip.works.ts +77 -0
- package/dist/ui/elements/value.js +1 -1
- package/dist/ui/elements/value.tsx +30 -0
- package/dist/ui/elements/value.works.ts +9 -0
- package/dist/ui/elements.ts +127 -0
- package/dist/ui/focus-scope.ts +121 -0
- package/dist/ui/fonts.ts +355 -0
- package/dist/ui/generators/dev.ts +79 -0
- package/dist/ui/generators/elements.d.ts +1 -11
- package/dist/ui/generators/elements.js +43 -13
- package/dist/ui/generators/elements.ts +794 -0
- package/dist/ui/generators/i18n.ts +301 -0
- package/dist/ui/generators/icons.ts +214 -0
- package/dist/ui/generators/react.js +10 -3
- package/dist/ui/generators/react.ts +268 -0
- package/dist/ui/generators/routes.d.ts +1 -0
- package/dist/ui/generators/routes.js +89 -69
- package/dist/ui/generators/routes.ts +739 -0
- package/dist/ui/generators/show.ts +259 -0
- package/dist/ui/generators/styles.js +1 -1
- package/dist/ui/generators/styles.ts +670 -0
- package/dist/ui/generators/variants.ts +205 -0
- package/dist/ui/i18n/catalogs/en.ts +191 -0
- package/dist/ui/i18n/format.ts +221 -0
- package/dist/ui/i18n/locales.ts +33 -0
- package/dist/ui/i18n/parse.ts +315 -0
- package/dist/ui/i18n/translator.ts +31 -0
- package/dist/ui/i18n/types.ts +96 -0
- package/dist/ui/icons.ts +331 -0
- package/dist/ui/islands/map.ts +58 -0
- package/dist/ui/localizations.ts +75 -0
- package/dist/ui/makers/message.ts +292 -0
- package/dist/ui/material.ts +236 -0
- package/dist/ui/materials/mat_bordered.ts +13 -0
- package/dist/ui/materials/mat_ceramic.ts +13 -0
- package/dist/ui/materials/mat_clay.ts +13 -0
- package/dist/ui/materials/mat_elevated.ts +24 -0
- package/dist/ui/materials/mat_flat.ts +34 -0
- package/dist/ui/materials/mat_glass.ts +20 -0
- package/dist/ui/materials/mat_lit.ts +13 -0
- package/dist/ui/materials/mat_moulded.ts +11 -0
- package/dist/ui/materials.ts +206 -0
- package/dist/ui/modes.ts +44 -0
- package/dist/ui/navigation.tsx +32 -0
- package/dist/ui/positioning.ts +90 -0
- package/dist/ui/presented.tsx +119 -0
- package/dist/ui/provider.d.ts +2 -0
- package/dist/ui/provider.js +7 -1
- package/dist/ui/provider.tsx +182 -0
- package/dist/ui/render-loop.ts +133 -0
- package/dist/ui/roving-focus.ts +161 -0
- package/dist/ui/screens.js +17 -8
- package/dist/ui/screens.ts +142 -0
- package/dist/ui/scroll-lock.ts +28 -0
- package/dist/ui/series.ts +97 -0
- package/dist/ui/signals.ts +386 -0
- package/dist/ui/styleguide.ts +231 -0
- package/dist/ui/styleguides.ts +374 -0
- package/dist/ui/themes.ts +22 -0
- package/dist/ui/token.js +1 -1
- package/dist/ui/token.ts +78 -0
- package/dist/ui/tokens/shadow.ts +25 -0
- package/dist/ui/tokens.ts +235 -0
- package/dist/ui/validators.ts +232 -0
- package/dist/ui/variant.d.ts +1 -0
- package/dist/ui/variant.js +3 -0
- package/dist/ui/variant.ts +352 -0
- package/dist/ui/variants/var_avatar-round.ts +14 -0
- package/dist/ui/variants/var_bubble-me.ts +14 -0
- package/dist/ui/variants/var_bubble-them.ts +13 -0
- package/dist/ui/variants/var_button-border.ts +76 -0
- package/dist/ui/variants/var_button-cta.ts +76 -0
- package/dist/ui/variants/var_button-destructive-ghost.ts +72 -0
- package/dist/ui/variants/var_button-destructive.ts +76 -0
- package/dist/ui/variants/var_button-fill.ts +76 -0
- package/dist/ui/variants/var_button-ghost.ts +72 -0
- package/dist/ui/variants/var_button-glass.ts +55 -0
- package/dist/ui/variants/var_button-normal.ts +76 -0
- package/dist/ui/variants/var_button-quiet.ts +74 -0
- package/dist/ui/variants/var_card.ts +17 -0
- package/dist/ui/variants/var_chip.ts +13 -0
- package/dist/ui/variants/var_choice.ts +15 -0
- package/dist/ui/variants/var_framed.ts +10 -0
- package/dist/ui/variants/var_glyph-plain.ts +11 -0
- package/dist/ui/variants/var_input.ts +43 -0
- package/dist/ui/variants/var_link-inline.ts +29 -0
- package/dist/ui/variants/var_list-row.ts +34 -0
- package/dist/ui/variants/var_rule.ts +10 -0
- package/dist/ui/variants/var_skeleton-block.ts +12 -0
- package/dist/ui/variants/var_spinner-turning.ts +12 -0
- package/dist/ui/variants/var_stat-tile.ts +13 -0
- package/dist/ui/variants/var_tab-bar.ts +15 -0
- package/dist/ui/variants/var_tap-target.ts +25 -0
- package/dist/ui/variants.ts +64 -0
- package/dist/ui/wrappers.d.ts +4 -1
- package/dist/ui/wrappers.js +60 -20
- package/dist/ui/wrappers.tsx +426 -0
- package/package.json +8 -2
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { basename, dirname, join, relative } from 'node:path'
|
|
3
|
+
import { argv, stdout } from 'node:process'
|
|
4
|
+
import { pathToFileURL } from 'node:url'
|
|
5
|
+
|
|
6
|
+
import { wrapped } from '@prestack/thread/core/asking'
|
|
7
|
+
import { exit, invoked } from '@prestack/thread/core/invoked'
|
|
8
|
+
import type { Threaded } from '@prestack/thread/core/thread'
|
|
9
|
+
import { named as packageOf } from '@prestack/thread/core/scope'
|
|
10
|
+
import type { Tree } from '@prestack/thread/core/tree'
|
|
11
|
+
import { findTree, inTree } from '@prestack/thread/core/tree'
|
|
12
|
+
|
|
13
|
+
import { compiled } from './generators/react.ts'
|
|
14
|
+
|
|
15
|
+
export const TEACHES: readonly string[] = [
|
|
16
|
+
' what the body may reach, and how a premium state is written:',
|
|
17
|
+
'',
|
|
18
|
+
' `useUi()` is the door. It carries `actor` — who is asking, with the roles read from',
|
|
19
|
+
' the row that declared itself the caller — and `translate`, `clock` and `dispatch`. Name',
|
|
20
|
+
' it in the body and the import is written for you.',
|
|
21
|
+
'',
|
|
22
|
+
' A premium look is not decided at the call site. A grant already says who may run an',
|
|
23
|
+
' operation, in words your own entity declares, and a signal that names that operation',
|
|
24
|
+
' holds for exactly the callers the grant refuses. The rule is written once, on the',
|
|
25
|
+
' grant, and every screen follows it:',
|
|
26
|
+
'',
|
|
27
|
+
' <FeatureBox.paywalled>',
|
|
28
|
+
' <Text k=\'feature.title\' />',
|
|
29
|
+
' </FeatureBox.paywalled>',
|
|
30
|
+
'',
|
|
31
|
+
' Read it in three parts, and each is its own command:',
|
|
32
|
+
'',
|
|
33
|
+
' `locked` is a signal the ELEMENT declares it raises — `thread create element` with',
|
|
34
|
+
' `raises: locked`. A signal this app declares cannot be raised on an element that',
|
|
35
|
+
' never said it raises one, so `Box` will not take it. Nothing passes it here: it is',
|
|
36
|
+
' set for you wherever the gate refuses the operation the signal names.',
|
|
37
|
+
' `.paywalled` is a variant worn as the TAG, never passed as a prop, and it is what',
|
|
38
|
+
' carries the look — `thread create variant` with a `state: locked` and what it sets.',
|
|
39
|
+
' Declare that state on a MATERIAL instead and every variant made of it locks the same',
|
|
40
|
+
' way, which is how one overlay dresses a whole app from one row.',
|
|
41
|
+
' The rule itself is `thread grant`, and the words in it are options on the value your',
|
|
42
|
+
' entity names as saying what a caller may do — `thread create entity`.',
|
|
43
|
+
'',
|
|
44
|
+
' THE MEMBER IS THE VARIANT\'S WHOLE ID, CAMELCASED — never the part after the element',
|
|
45
|
+
' name. A variant `button-fill` is worn `<Button.buttonFill>`, and `<Button.fill>` is not',
|
|
46
|
+
' a thing. `.paywalled` above reads short only because that variant is itself named',
|
|
47
|
+
' `paywalled`; most carry the element in their id and wear all of it.',
|
|
48
|
+
'',
|
|
49
|
+
' how a control reaches an operation:',
|
|
50
|
+
'',
|
|
51
|
+
' Wiring is imperative. There is no `run=`, `operation=` or `dispatch=` prop on any',
|
|
52
|
+
' element, and the compiler is what will tell you so. A control calls dispatch in its own',
|
|
53
|
+
' handler:',
|
|
54
|
+
'',
|
|
55
|
+
' <Button.buttonFill label=\'common.save\'',
|
|
56
|
+
' onPress={() => useUi().dispatch?.(\'wf_save\')} />',
|
|
57
|
+
'',
|
|
58
|
+
' `dispatch` is optional on the hook, so `?.` is required — without it the compiler says',
|
|
59
|
+
' "Cannot invoke an object which is possibly \'undefined\'". The name is the operation\'s own',
|
|
60
|
+
' id from `thread create operation`, and one this app never declared is refused before it',
|
|
61
|
+
' runs. An operation whose `to:` named nobody is refused however the button looks — and',
|
|
62
|
+
' `to:` takes roles off an entity, which is a noun that arrives with `thread attach',
|
|
63
|
+
` ${packageOf('data')}\`.`,
|
|
64
|
+
'',
|
|
65
|
+
' Nothing here decides access. The gate still refuses the operation behind the lock',
|
|
66
|
+
' whatever the screen shows, so a screen that got this wrong shows the wrong thing and',
|
|
67
|
+
' still cannot do the wrong thing.',
|
|
68
|
+
'',
|
|
69
|
+
' how a press moves to another screen:',
|
|
70
|
+
'',
|
|
71
|
+
' Name the screen. `navigateTo` takes the screen\'s export name — its id in PascalCase, so',
|
|
72
|
+
' `order-detail` is reached as `navigateTo="OrderDetail"`:',
|
|
73
|
+
'',
|
|
74
|
+
' <Button.buttonNormal label=\'home.orders\' navigateTo="Orders" />',
|
|
75
|
+
'',
|
|
76
|
+
' That is the whole of it. `thread routes` reads every `navigateTo` the screens and their',
|
|
77
|
+
' compositions hold and writes the map — from which screen, through which button, to which',
|
|
78
|
+
' screen — and the pages. A page is reached by its route, and a sheet, popover, overlay or',
|
|
79
|
+
' toast opens where somebody already is, so the press is written the same way for both.',
|
|
80
|
+
' A name no screen has and a destination not written out as a name are each refused there.',
|
|
81
|
+
' Never an `href` and never',
|
|
82
|
+
' a router: a move the map cannot see is a screen the map reads as unreachable.',
|
|
83
|
+
'',
|
|
84
|
+
' how a screen shows data:',
|
|
85
|
+
'',
|
|
86
|
+
' A screen NAMES the reads it binds, and never fetches. `views` takes the ids of declared',
|
|
87
|
+
' views, the framework runs each one, and `useView` hands back what came out:',
|
|
88
|
+
'',
|
|
89
|
+
' export const Orders = screen(\'orders\', { as: \'page\', views: [\'vw_orders\'] }, () => (',
|
|
90
|
+
' <Each rows={useView<readonly Row[]>(\'vw_orders\') ?? []} by="id">',
|
|
91
|
+
' {(row) => <Text k="orders.line" with={{ name: row.name }} />}',
|
|
92
|
+
' </Each>',
|
|
93
|
+
' ))',
|
|
94
|
+
'',
|
|
95
|
+
' `useView` comes through the same door as `useUi`, and it refuses a name the screen did not',
|
|
96
|
+
' bind. `thread routes` refuses a view this app declares no operation for, and writes what each',
|
|
97
|
+
' screen shows into the map. A fetch of your own, or a hook you wrote, is how a screen ends up',
|
|
98
|
+
' showing something nothing declared, and there is no second way in.',
|
|
99
|
+
]
|
|
100
|
+
|
|
101
|
+
export const REACHES = /\buseUi\s*\(/
|
|
102
|
+
|
|
103
|
+
const here = 'thread/ui/compositions.ts'
|
|
104
|
+
|
|
105
|
+
const said = [
|
|
106
|
+
{
|
|
107
|
+
on: '2026-08-25',
|
|
108
|
+
said: 'Compositions is basically a mix of elements+variants, arranged with arrangement elements, with ways to invoke functions (navigateTo, dispatch).',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
on: '2026-08-25',
|
|
112
|
+
said: 'The compositions.ts just says what the thing is, and describes it. Then the file itself, seeded, is a cmp_ file, where we build the actual UI from. And the UI file is plain react, just with our system.',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
on: '2026-08-25',
|
|
116
|
+
said: 'Variants themselves declare what elements they relate to, in their declarations. Then the composition says button.primary and if that matches the combination of variant and element it is acceptable. And make sure the composition can only dispatch existing operations.',
|
|
117
|
+
},
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
export const declares: readonly Threaded[] = []
|
|
121
|
+
|
|
122
|
+
export const COMPOSITIONS: Threaded & { readonly files: string } = {
|
|
123
|
+
id: 'composition',
|
|
124
|
+
at: here,
|
|
125
|
+
files: 'compositions/cmp_*.tsx',
|
|
126
|
+
describes:
|
|
127
|
+
'A React component made through this system: elements wearing variants, arranged, and able to reach a declared operation. Each row names a file prefixed `cmp_`, and that file is plain React a person writes, because the arrangement, the conditions and the content are theirs. A call site states only what is left over: what a thing does comes from its element, and how it looks and which states it answers to come from its variant, so `Button.primary` is legal only where a variant `primary` says it is worn by `Button`. Text in it is a message key, a look is a variant, and a value names a style guide row, never a raw one. The framework ships none, because what an app is made of is the app’s, and this row says what a composition is, never what is inside it.',
|
|
128
|
+
version: 1,
|
|
129
|
+
cites: said,
|
|
130
|
+
declares,
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const PASCAL = (id: string): string =>
|
|
134
|
+
id
|
|
135
|
+
.split('-')
|
|
136
|
+
.map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`)
|
|
137
|
+
.join('')
|
|
138
|
+
|
|
139
|
+
export function nameOf(at: string): string {
|
|
140
|
+
const file = at.split('\\').join('/').split('/').at(-1) ?? at
|
|
141
|
+
return PASCAL(file.replace(/^cmp_/, '').replace(/\.[^.]+$/, ''))
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
type Listed = {
|
|
145
|
+
readonly id: string
|
|
146
|
+
readonly at?: string
|
|
147
|
+
readonly describes?: string
|
|
148
|
+
readonly wears?: readonly string[]
|
|
149
|
+
readonly arranges?: boolean
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function sheetOf(tree: Tree, file: string, ...named: readonly string[]): Promise<readonly Listed[]> {
|
|
153
|
+
try {
|
|
154
|
+
const held = (await import(pathToFileURL(inTree(tree, file)).href)) as Readonly<
|
|
155
|
+
Record<string, { readonly declares?: readonly Listed[] } | undefined>
|
|
156
|
+
>
|
|
157
|
+
for (const one of named) {
|
|
158
|
+
const found = held[one]?.declares
|
|
159
|
+
if (found !== undefined) return found
|
|
160
|
+
}
|
|
161
|
+
return []
|
|
162
|
+
} catch {
|
|
163
|
+
return []
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const camelOf = (id: string): string => id.replace(/-([a-z0-9])/g, (_, one: string) => one.toUpperCase())
|
|
168
|
+
|
|
169
|
+
const sentence = (one: Listed, pad: string): readonly string[] =>
|
|
170
|
+
String(one.describes ?? '').trim() === '' ? [] : wrapped(String(one.describes), pad)
|
|
171
|
+
|
|
172
|
+
async function listed(tree: Tree, making: 'composition' | 'screen'): Promise<readonly string[]> {
|
|
173
|
+
const [elements, variants, compositions, screens] = await Promise.all([
|
|
174
|
+
sheetOf(tree, `elements.${'ts'}`, 'ELEMENT', 'ELEMENTS'),
|
|
175
|
+
sheetOf(tree, `variants.${'ts'}`, 'VARIANT', 'VARIANTS'),
|
|
176
|
+
sheetOf(tree, `compositions.${'ts'}`, 'COMPOSITION', 'COMPOSITIONS'),
|
|
177
|
+
making === 'screen' ? sheetOf(tree, `screens.${'ts'}`, 'SCREEN', 'SCREENS') : Promise.resolve([]),
|
|
178
|
+
])
|
|
179
|
+
|
|
180
|
+
const worn = new Map<string, string[]>()
|
|
181
|
+
for (const one of variants) {
|
|
182
|
+
for (const each of one.wears ?? []) {
|
|
183
|
+
const key = PASCAL(each)
|
|
184
|
+
const already = worn.get(key) ?? []
|
|
185
|
+
if (!already.includes(one.id)) worn.set(key, [...already, one.id])
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const writes = (one: Listed): string => {
|
|
190
|
+
const name = PASCAL(one.id)
|
|
191
|
+
const members = (worn.get(name) ?? []).sort().map((each) => `<${name}.${camelOf(each)}>`)
|
|
192
|
+
if (members.length === 0) return `<${name}>`
|
|
193
|
+
return one.arranges === true ? `<${name}>, or ${members.join(' ')}` : members.join(' ')
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const section = (title: string, rows: readonly Listed[], write: (one: Listed) => string): readonly string[] =>
|
|
197
|
+
rows.length === 0
|
|
198
|
+
? [` ${title}: none yet.`, '']
|
|
199
|
+
: [
|
|
200
|
+
` ${title} (${String(rows.length)}):`,
|
|
201
|
+
...rows.flatMap((one) => [` ${write(one)}`, ...sentence(one, ' ')]),
|
|
202
|
+
'',
|
|
203
|
+
]
|
|
204
|
+
|
|
205
|
+
return [
|
|
206
|
+
'',
|
|
207
|
+
...(making === 'screen'
|
|
208
|
+
? section('SCREENS that exist, and the name a press reaches each one by', screens, (one) => `${one.id} — navigateTo="${PASCAL(one.id)}"`)
|
|
209
|
+
: []),
|
|
210
|
+
...section('COMPOSITIONS you can place', compositions, (one) =>
|
|
211
|
+
`<${typeof one.at === 'string' && one.at !== '' ? nameOf(one.at) : PASCAL(one.id)}>`,
|
|
212
|
+
),
|
|
213
|
+
...section('ELEMENTS, written as the tags they can actually be typed as', elements, writes),
|
|
214
|
+
...(variants.length === 0
|
|
215
|
+
? [' VARIANTS: none yet.', '']
|
|
216
|
+
: [
|
|
217
|
+
` VARIANTS (${String(variants.length)}), under the elements that accept them:`,
|
|
218
|
+
...[...worn.keys()].sort().map((name) =>
|
|
219
|
+
` ${name} — ${(worn.get(name) ?? []).sort().map(camelOf).join(', ')}`,
|
|
220
|
+
),
|
|
221
|
+
...(() => {
|
|
222
|
+
const nobody = variants.filter((one) => (one.wears ?? []).length === 0).map((one) => one.id)
|
|
223
|
+
return nobody.length === 0
|
|
224
|
+
? []
|
|
225
|
+
: [` worn by nothing, so writable nowhere: ${nobody.sort().join(', ')}`]
|
|
226
|
+
})(),
|
|
227
|
+
'',
|
|
228
|
+
]),
|
|
229
|
+
' Materials, style guide values, fonts and animations are chosen inside a VARIANT, never inside',
|
|
230
|
+
' a body — `npx thread create variant` prints every one of them at the moment one is needed.',
|
|
231
|
+
'',
|
|
232
|
+
|
|
233
|
+
' Every element and the tags it is written as: `npx thread create element`. Every variant and',
|
|
234
|
+
' the tag it is worn as: `npx thread create variant`. Then open the one nearest to what you are',
|
|
235
|
+
' about to build with `npx thread read <id>` — it already answers how a body is arranged, how a',
|
|
236
|
+
' variant is worn and how a control reaches an operation, and a file cannot be wrong in the way',
|
|
237
|
+
' a remembered example can.',
|
|
238
|
+
'',
|
|
239
|
+
]
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export const catalogue = async (): Promise<readonly string[]> => listed(findTree(), 'composition')
|
|
243
|
+
|
|
244
|
+
export const screening = async (): Promise<readonly string[]> => listed(findTree(), 'screen')
|
|
245
|
+
|
|
246
|
+
const TAG = /<([A-Z][A-Za-z0-9]*)/g
|
|
247
|
+
|
|
248
|
+
export function composed(
|
|
249
|
+
body: string,
|
|
250
|
+
rows: readonly { readonly id: string; readonly at?: string }[],
|
|
251
|
+
from: 'screens' | 'compositions',
|
|
252
|
+
except?: string,
|
|
253
|
+
): readonly string[] {
|
|
254
|
+
const named = new Map<string, string>()
|
|
255
|
+
for (const row of rows) {
|
|
256
|
+
const at = row.at
|
|
257
|
+
if (typeof at !== 'string' || at === '' || at === except) continue
|
|
258
|
+
named.set(PASCAL(row.id), at)
|
|
259
|
+
}
|
|
260
|
+
const found = new Set<string>()
|
|
261
|
+
for (const [, tag] of body.matchAll(TAG)) if (tag !== undefined && named.has(tag)) found.add(tag)
|
|
262
|
+
return [...found].sort().map((one) => {
|
|
263
|
+
const at = named.get(one) ?? ''
|
|
264
|
+
const file = (at.split('\\').join('/').split('/').at(-1) ?? at).replace(/\.[^.]+$/, '')
|
|
265
|
+
return `import { ${one} } from '${from === 'screens' ? '../compositions' : '.'}/${file}.tsx'`
|
|
266
|
+
})
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const IMPORTS = /^import\s[\s\S]*?from\s*['"]([^'"]+)['"]/gm
|
|
270
|
+
|
|
271
|
+
const FRAMEWORK = 'thread/'
|
|
272
|
+
|
|
273
|
+
export const HOME = `${packageOf('ui')}/${here.slice(FRAMEWORK.length).split('/').slice(0, -1).join('/')}`
|
|
274
|
+
|
|
275
|
+
export const DOORS: ReadonlySet<string> = new Set(['react', `${HOME}/wrappers`, `${HOME}/drag`])
|
|
276
|
+
|
|
277
|
+
const SHIPPED = new RegExp(`^${HOME}/elements/([a-z0-9-]+)$`)
|
|
278
|
+
|
|
279
|
+
const slashed = (path: string): string => path.split('\\').join('/')
|
|
280
|
+
|
|
281
|
+
export function reaching(
|
|
282
|
+
at: string,
|
|
283
|
+
text: string,
|
|
284
|
+
elements: ReadonlySet<string>,
|
|
285
|
+
declared: ReadonlySet<string>,
|
|
286
|
+
): readonly string[] {
|
|
287
|
+
const here = slashed(at).split('/').slice(0, -1).join('/')
|
|
288
|
+
const found = new Set<string>()
|
|
289
|
+
for (const one of text.matchAll(IMPORTS)) {
|
|
290
|
+
const from = one[1]
|
|
291
|
+
if (from === undefined || DOORS.has(from)) continue
|
|
292
|
+
const shipped = SHIPPED.exec(from)?.[1]
|
|
293
|
+
if (shipped !== undefined && elements.has(shipped)) continue
|
|
294
|
+
if (from.startsWith('.') && declared.has(slashed(join(here, from)))) continue
|
|
295
|
+
found.add(from)
|
|
296
|
+
}
|
|
297
|
+
return [...found].sort()
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const CLAUSE = /^import\s+(?!type\s)([\s\S]*?)\s*from\s*['"][^'"]+['"]/gm
|
|
301
|
+
|
|
302
|
+
const WORD = /(?:^|[,{]|\s)(?:[A-Za-z_$][\w$]*\s+as\s+)?([A-Za-z_$][\w$]*)/g
|
|
303
|
+
|
|
304
|
+
const NOT_A_NAME = new Set(['type', 'as', 'from', 'import'])
|
|
305
|
+
|
|
306
|
+
const KEPT = 'a composition keeps no state of its own. State belongs to the element that raises the signal, in the works file beside it'
|
|
307
|
+
|
|
308
|
+
const RUNS = 'nothing here runs on its own. A read is bound by the screen in its own views list, and a press is answered by dispatch'
|
|
309
|
+
|
|
310
|
+
const REFUSED: Readonly<Record<string, string>> = {
|
|
311
|
+
useState: KEPT,
|
|
312
|
+
useReducer: KEPT,
|
|
313
|
+
useSyncExternalStore: KEPT,
|
|
314
|
+
useEffect: RUNS,
|
|
315
|
+
useLayoutEffect: RUNS,
|
|
316
|
+
element: 'only the compiler writes an element, and a file that calls it turns off the checks that keep this one declared',
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export const COMPILED = 'app/_generated/compiled'
|
|
320
|
+
|
|
321
|
+
export function compiledAt(at: string): string {
|
|
322
|
+
return `${COMPILED}/${slashed(at)}`
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const ENDINGS = ['.tsx', '.ts'] as const
|
|
326
|
+
|
|
327
|
+
function beside(root: string, where: string, said: string): string | undefined {
|
|
328
|
+
if (!said.startsWith(`${HOME}/`)) return undefined
|
|
329
|
+
const tail = said.slice(HOME.length + 1)
|
|
330
|
+
for (const ending of ENDINGS) {
|
|
331
|
+
const at = `${COMPILED}/ui/${tail}${ending}`
|
|
332
|
+
if (!existsSync(join(root, at))) continue
|
|
333
|
+
const out = slashed(relative(dirname(where), at))
|
|
334
|
+
return out.startsWith('.') ? out : `./${out}`
|
|
335
|
+
}
|
|
336
|
+
return undefined
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const NAMED_IMPORT = /(['"])(@[^'"]+)\1/g
|
|
340
|
+
|
|
341
|
+
export function settled(
|
|
342
|
+
root: string,
|
|
343
|
+
rows: readonly Threaded[],
|
|
344
|
+
checking: boolean,
|
|
345
|
+
by: string,
|
|
346
|
+
kept: Set<string>,
|
|
347
|
+
): readonly string[] {
|
|
348
|
+
const said: string[] = []
|
|
349
|
+
for (const row of rows) {
|
|
350
|
+
const file = join(root, row.at)
|
|
351
|
+
if (!existsSync(file)) continue
|
|
352
|
+
const held = compiled(readFileSync(file, 'utf8'), row.at)
|
|
353
|
+
if (held.because !== undefined) {
|
|
354
|
+
said.push(held.because)
|
|
355
|
+
continue
|
|
356
|
+
}
|
|
357
|
+
const where = compiledAt(row.at)
|
|
358
|
+
kept.add(where)
|
|
359
|
+
const text = (held.text ?? '').replace(NAMED_IMPORT, (whole: string, quote: string, said: string) => {
|
|
360
|
+
const found = beside(root, where, said)
|
|
361
|
+
return found === undefined ? whole : `${quote}${found}${quote}`
|
|
362
|
+
})
|
|
363
|
+
const at = join(root, where)
|
|
364
|
+
if (!checking) {
|
|
365
|
+
mkdirSync(dirname(at), { recursive: true })
|
|
366
|
+
writeFileSync(at, text, 'utf8')
|
|
367
|
+
continue
|
|
368
|
+
}
|
|
369
|
+
if (existsSync(at) && readFileSync(at, 'utf8') === text) continue
|
|
370
|
+
said.push(
|
|
371
|
+
`${where} is not what the compiler writes from ${row.at}. A compiled file that differs from its ` +
|
|
372
|
+
`source is a hand edit wearing a generated name. Run \`${by}\` and commit what it writes.`,
|
|
373
|
+
)
|
|
374
|
+
}
|
|
375
|
+
return said
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const ORG = packageOf('ui').split('/')[0] ?? ''
|
|
379
|
+
|
|
380
|
+
const REACHED = /^(?:import|export)\s+(type\s+)?(?:(?:[^\n]|\n(?=[ \t}]))*?\s)?from\s*['"]([^'"]+)['"]/gm
|
|
381
|
+
|
|
382
|
+
export const RUNTIME: readonly string[] = ['wrappers.tsx', 'drag.ts', 'provider.tsx', 'islands/map.ts']
|
|
383
|
+
|
|
384
|
+
const NODE = /^node:/
|
|
385
|
+
|
|
386
|
+
function installs(root: string): ReadonlySet<string> {
|
|
387
|
+
try {
|
|
388
|
+
const held = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as {
|
|
389
|
+
readonly dependencies?: Readonly<Record<string, string>>
|
|
390
|
+
readonly devDependencies?: Readonly<Record<string, string>>
|
|
391
|
+
}
|
|
392
|
+
return new Set([...Object.keys(held.dependencies ?? {}), ...Object.keys(held.devDependencies ?? {})])
|
|
393
|
+
} catch {
|
|
394
|
+
return new Set()
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function packaging(said: string): string {
|
|
399
|
+
return said.startsWith('@') ? said.split('/').slice(0, 2).join('/') : (said.split('/')[0] ?? said)
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export function emitting(
|
|
403
|
+
root: string,
|
|
404
|
+
entries: readonly string[],
|
|
405
|
+
checking: boolean,
|
|
406
|
+
kept: Set<string>,
|
|
407
|
+
): readonly string[] {
|
|
408
|
+
const has = installs(root)
|
|
409
|
+
const from = join(root, 'node_modules', packageOf('ui'), 'dist', 'ui')
|
|
410
|
+
const said: string[] = []
|
|
411
|
+
if (!existsSync(from)) {
|
|
412
|
+
return [
|
|
413
|
+
`this app declares an interface and ${packageOf('ui')} is not installed, so there is nothing to emit it from. ` +
|
|
414
|
+
`Install it and run \`thread attach ${packageOf('ui')}\` again.`,
|
|
415
|
+
]
|
|
416
|
+
}
|
|
417
|
+
const seen = new Set<string>()
|
|
418
|
+
const walk = (at: string): void => {
|
|
419
|
+
if (seen.has(at)) return
|
|
420
|
+
seen.add(at)
|
|
421
|
+
const file = join(from, at)
|
|
422
|
+
if (!existsSync(file)) {
|
|
423
|
+
said.push(
|
|
424
|
+
`${at} is part of the interface this app emits, and the installed ${packageOf('ui')} does not hold it. ` +
|
|
425
|
+
'Upgrade the framework packages and run this again.',
|
|
426
|
+
)
|
|
427
|
+
return
|
|
428
|
+
}
|
|
429
|
+
const text = readFileSync(file, 'utf8')
|
|
430
|
+
const where = `${COMPILED}/ui/${at}`
|
|
431
|
+
kept.add(where)
|
|
432
|
+
const to = join(root, where)
|
|
433
|
+
if (checking) {
|
|
434
|
+
if (!existsSync(to) || readFileSync(to, 'utf8') !== text) {
|
|
435
|
+
said.push(
|
|
436
|
+
`${where} is not what this app emits from ${packageOf('ui')}. An emitted file that differs from ` +
|
|
437
|
+
'its source is a hand edit wearing a generated name. Run `thread compositions` and commit what it writes.',
|
|
438
|
+
)
|
|
439
|
+
}
|
|
440
|
+
} else {
|
|
441
|
+
mkdirSync(dirname(to), { recursive: true })
|
|
442
|
+
writeFileSync(to, text, 'utf8')
|
|
443
|
+
}
|
|
444
|
+
for (const one of text.matchAll(REACHED)) {
|
|
445
|
+
const named = one[2] ?? ''
|
|
446
|
+
if (named.startsWith('.')) {
|
|
447
|
+
const next = slashed(join(dirname(at), named))
|
|
448
|
+
if (next.startsWith('..')) {
|
|
449
|
+
said.push(`${at} reaches \`${named}\`, which is outside the interface this app emits.`)
|
|
450
|
+
continue
|
|
451
|
+
}
|
|
452
|
+
walk(next)
|
|
453
|
+
continue
|
|
454
|
+
}
|
|
455
|
+
if (one[1] !== undefined) continue
|
|
456
|
+
if (!named.startsWith(`${ORG}/`)) {
|
|
457
|
+
const held = packaging(named)
|
|
458
|
+
if (NODE.test(named) || has.has(held)) continue
|
|
459
|
+
said.push(
|
|
460
|
+
`${at} reaches ${held}, and this app installs nothing by that name. An emitted interface brings ` +
|
|
461
|
+
`what it reaches with it, so ${held} has to arrive when ` +
|
|
462
|
+
`thread attach ${packageOf('ui')} runs.`,
|
|
463
|
+
)
|
|
464
|
+
continue
|
|
465
|
+
}
|
|
466
|
+
said.push(
|
|
467
|
+
`${at} reaches \`${named}\`, so emitting it would leave this app importing the framework while it runs. ` +
|
|
468
|
+
'It reaches what is emitted beside it, or nothing of this framework at all.',
|
|
469
|
+
)
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
for (const one of entries) walk(one)
|
|
473
|
+
return said
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
export function stale(root: string, kept: ReadonlySet<string>, checking: boolean): readonly string[] {
|
|
477
|
+
const said: string[] = []
|
|
478
|
+
const walk = (at: string): void => {
|
|
479
|
+
const where = join(root, at)
|
|
480
|
+
if (!existsSync(where)) return
|
|
481
|
+
for (const each of readdirSync(where, { withFileTypes: true })) {
|
|
482
|
+
const path = `${at}/${each.name}`
|
|
483
|
+
if (each.isDirectory()) {
|
|
484
|
+
walk(path)
|
|
485
|
+
continue
|
|
486
|
+
}
|
|
487
|
+
if (kept.has(path)) continue
|
|
488
|
+
if (checking) {
|
|
489
|
+
said.push(
|
|
490
|
+
`${path} sits under ${COMPILED} and nothing declares what it was written from any more. ` +
|
|
491
|
+
'Run `thread compositions` and it goes.',
|
|
492
|
+
)
|
|
493
|
+
continue
|
|
494
|
+
}
|
|
495
|
+
rmSync(join(root, path), { force: true })
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
walk(COMPILED)
|
|
499
|
+
return said
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
export function handing(at: string, text: string): readonly string[] {
|
|
503
|
+
const found: string[] = []
|
|
504
|
+
for (const one of text.matchAll(CLAUSE)) {
|
|
505
|
+
for (const name of (one[1] ?? '').matchAll(WORD)) {
|
|
506
|
+
const held = name[1]
|
|
507
|
+
if (held === undefined || NOT_A_NAME.has(held)) continue
|
|
508
|
+
const why = REFUSED[held]
|
|
509
|
+
if (why === undefined) continue
|
|
510
|
+
found.push(`${at} imports \`${held}\`, and ${why}.`)
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
if (/\bfetch\s*\(/.test(text)) {
|
|
514
|
+
found.push(
|
|
515
|
+
`${at} calls \`fetch\`, and nothing here reaches the network by hand. A screen names the reads it ` +
|
|
516
|
+
'binds in its own views list, and the framework runs each one.',
|
|
517
|
+
)
|
|
518
|
+
}
|
|
519
|
+
return found
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
export async function undeclared(
|
|
523
|
+
tree: Tree,
|
|
524
|
+
rows: readonly Threaded[],
|
|
525
|
+
): Promise<readonly string[]> {
|
|
526
|
+
const elements = new Set<string>()
|
|
527
|
+
const declared = new Set<string>()
|
|
528
|
+
|
|
529
|
+
for (const [file, exported] of [
|
|
530
|
+
['elements.ts', 'ELEMENT'],
|
|
531
|
+
['compositions.ts', 'COMPOSITION'],
|
|
532
|
+
['screens.ts', 'SCREEN'],
|
|
533
|
+
] as const) {
|
|
534
|
+
const where = inTree(tree, file)
|
|
535
|
+
if (!existsSync(where)) continue
|
|
536
|
+
const sheet = (await import(pathToFileURL(where).href)) as Readonly<
|
|
537
|
+
Record<string, { readonly declares?: readonly Threaded[] } | undefined>
|
|
538
|
+
>
|
|
539
|
+
for (const row of sheet[exported]?.declares ?? []) {
|
|
540
|
+
if (exported === 'ELEMENT') elements.add(row.id)
|
|
541
|
+
if (row.at !== '') declared.add(slashed(row.at))
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const found: string[] = []
|
|
546
|
+
for (const row of rows) {
|
|
547
|
+
const file = join(tree.at, row.at)
|
|
548
|
+
if (!existsSync(file)) continue
|
|
549
|
+
const text = readFileSync(file, 'utf8')
|
|
550
|
+
found.push(...handing(row.at, text))
|
|
551
|
+
for (const one of reaching(row.at, text, elements, declared)) {
|
|
552
|
+
found.push(
|
|
553
|
+
`${row.at} imports \`${one}\`, which this app declares nothing by. A composition reaches ` +
|
|
554
|
+
'declared elements, other declared compositions, and the door — everything else is a thing ' +
|
|
555
|
+
'nothing wrote down. Declare it, or take it out and write the body through `thread create`.',
|
|
556
|
+
)
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
return found
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function starter(row: Threaded): string {
|
|
563
|
+
const name = nameOf(row.at)
|
|
564
|
+
return `'use client'
|
|
565
|
+
|
|
566
|
+
import { Box } from '${HOME}/elements/box'
|
|
567
|
+
import { composition } from '${HOME}/wrappers'
|
|
568
|
+
|
|
569
|
+
export const ${name} = composition('${name}', () => <Box.card />)
|
|
570
|
+
`
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
export function seeds(rows: readonly Threaded[], held: (at: string) => boolean): readonly { readonly path: string; readonly content: string }[] {
|
|
574
|
+
return rows.filter((row) => !held(row.at)).map((row) => ({ path: row.at, content: starter(row) }))
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
async function run(): Promise<number> {
|
|
578
|
+
const tree = findTree()
|
|
579
|
+
const at = inTree(tree, 'compositions.ts')
|
|
580
|
+
if (!existsSync(at)) {
|
|
581
|
+
stdout.write(`thread: this tree has no ${tree.name}/${basename(at)}, so it declares no composition and there is nothing to seed or check.\n`)
|
|
582
|
+
return 0
|
|
583
|
+
}
|
|
584
|
+
const held = (await import(pathToFileURL(at).href)) as { COMPOSITION?: { readonly declares?: readonly Threaded[] } }
|
|
585
|
+
|
|
586
|
+
if (held.COMPOSITION === undefined) {
|
|
587
|
+
stdout.write(`thread: ${tree.name}/compositions.ts exports no \`COMPOSITION\`, so nothing declares a composition here.\n`)
|
|
588
|
+
return 1
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
const rows = held.COMPOSITION.declares ?? []
|
|
592
|
+
const checking = argv.includes('--check')
|
|
593
|
+
const made = seeds(rows, (where) => existsSync(join(tree.at, where)))
|
|
594
|
+
|
|
595
|
+
const unseeded = made[0]
|
|
596
|
+
if (checking && unseeded !== undefined) {
|
|
597
|
+
stdout.write(
|
|
598
|
+
`thread: ${unseeded.path} is declared and the file is not there yet. A row names a file, and ` +
|
|
599
|
+
'`--check` never writes one — run `thread compositions` and commit what it seeds.\n',
|
|
600
|
+
)
|
|
601
|
+
return 1
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
if (!checking) {
|
|
605
|
+
for (const one of made) {
|
|
606
|
+
mkdirSync(dirname(join(tree.at, one.path)), { recursive: true })
|
|
607
|
+
writeFileSync(join(tree.at, one.path), one.content, 'utf8')
|
|
608
|
+
stdout.write(`thread: seeded ${one.path}\n`)
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
const parts = await sheetOf(tree, 'elements.ts', 'ELEMENT', 'ELEMENTS')
|
|
613
|
+
const shipped = `node_modules/${packageOf('ui')}/dist/ui/`
|
|
614
|
+
const entries = [
|
|
615
|
+
...RUNTIME,
|
|
616
|
+
...parts.flatMap((one) =>
|
|
617
|
+
(one.at ?? '').startsWith(shipped) ? [(one.at ?? '').slice(shipped.length).replace(/\.js$/, '.tsx')] : [],
|
|
618
|
+
),
|
|
619
|
+
]
|
|
620
|
+
const kept = new Set<string>()
|
|
621
|
+
for (const one of await sheetOf(tree, 'screens.ts', 'SCREEN', 'SCREENS')) {
|
|
622
|
+
if (one.at !== undefined && one.at !== '') kept.add(compiledAt(one.at))
|
|
623
|
+
}
|
|
624
|
+
const found = [
|
|
625
|
+
...(await undeclared(tree, rows)),
|
|
626
|
+
...emitting(tree.at, entries, checking, kept),
|
|
627
|
+
...settled(tree.at, rows, checking, 'thread compositions', kept),
|
|
628
|
+
]
|
|
629
|
+
const loose = [...found, ...(found.length === 0 ? stale(tree.at, kept, checking) : [])]
|
|
630
|
+
for (const one of loose) stdout.write(`thread: ${one}\n`)
|
|
631
|
+
|
|
632
|
+
stdout.write(
|
|
633
|
+
`thread: ${String(rows.length)} composition(s) declared, ${String(made.length)} seeded, ` +
|
|
634
|
+
`${String(rows.length - made.length)} already written, ` +
|
|
635
|
+
`${loose.length === 0 ? 'none reaching anything undeclared' : `${String(loose.length)} reaching something undeclared`}\n`,
|
|
636
|
+
)
|
|
637
|
+
return loose.length === 0 ? 0 : 1
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
if (invoked(import.meta.url)) exit(await run())
|