@bigmistqke/workpad 0.0.0-stage → 0.18.1

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.
Files changed (277) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +781 -2
  3. package/bin/workpad.ts +1526 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
  5. package/dist/bin/workpad.js +1202 -0
  6. package/dist/client/runtime.js +1194 -0
  7. package/dist/define.js +27 -0
  8. package/dist/plugins/alert/README.md +18 -0
  9. package/dist/plugins/alert/index.js +40 -0
  10. package/dist/plugins/alert/public/style.css +40 -0
  11. package/dist/plugins/ansi/README.md +36 -0
  12. package/dist/plugins/ansi/index.js +63 -0
  13. package/dist/plugins/ansi/public/style.css +28 -0
  14. package/dist/plugins/badge/README.md +32 -0
  15. package/dist/plugins/badge/index.js +28 -0
  16. package/dist/plugins/badge/public/style.css +30 -0
  17. package/dist/plugins/chat/README.md +81 -0
  18. package/dist/plugins/chat/index.js +96 -0
  19. package/dist/plugins/chat/public/client.js +3 -0
  20. package/dist/plugins/chat/public/style.css +143 -0
  21. package/dist/plugins/claude/README.md +116 -0
  22. package/dist/plugins/claude/channel.js +130 -0
  23. package/dist/plugins/claude/doctor.js +316 -0
  24. package/dist/plugins/claude/index.js +199 -0
  25. package/dist/plugins/claude/session.js +68 -0
  26. package/dist/plugins/code/README.md +54 -0
  27. package/dist/plugins/code/diff.js +75 -0
  28. package/dist/plugins/code/index.js +105 -0
  29. package/dist/plugins/code/public/client.js +1 -0
  30. package/dist/plugins/code/public/style.css +99 -0
  31. package/dist/plugins/comments/README.md +30 -0
  32. package/dist/plugins/comments/index.js +39 -0
  33. package/dist/plugins/comments/public/client.js +24 -0
  34. package/dist/plugins/comments/public/style.css +224 -0
  35. package/dist/plugins/details/README.md +24 -0
  36. package/dist/plugins/details/index.js +28 -0
  37. package/dist/plugins/details/public/style.css +7 -0
  38. package/dist/plugins/draft/README.md +14 -0
  39. package/dist/plugins/draft/index.js +27 -0
  40. package/dist/plugins/draft/public/style.css +21 -0
  41. package/dist/plugins/forge/README.md +22 -0
  42. package/dist/plugins/forge/index.js +83 -0
  43. package/dist/plugins/form/README.md +126 -0
  44. package/dist/plugins/form/index.js +179 -0
  45. package/dist/plugins/form/public/style.css +172 -0
  46. package/dist/plugins/grid/README.md +45 -0
  47. package/dist/plugins/grid/index.js +35 -0
  48. package/dist/plugins/grid/public/style.css +98 -0
  49. package/dist/plugins/iframe/README.md +18 -0
  50. package/dist/plugins/iframe/index.js +49 -0
  51. package/dist/plugins/iframe/public/style.css +28 -0
  52. package/dist/plugins/index.js +44 -0
  53. package/dist/plugins/lightbox/README.md +24 -0
  54. package/dist/plugins/lightbox/index.js +20 -0
  55. package/dist/plugins/lightbox/public/client.js +4 -0
  56. package/dist/plugins/lightbox/public/style.css +66 -0
  57. package/dist/plugins/mermaid/README.md +21 -0
  58. package/dist/plugins/mermaid/index.js +42 -0
  59. package/dist/plugins/mermaid/public/style.css +21 -0
  60. package/dist/plugins/opencode/README.md +48 -0
  61. package/dist/plugins/opencode/channel.js +92 -0
  62. package/dist/plugins/opencode/index.js +64 -0
  63. package/dist/plugins/opencode/shim.js +150 -0
  64. package/dist/plugins/quiet/README.md +26 -0
  65. package/dist/plugins/quiet/index.js +23 -0
  66. package/dist/plugins/tabs/README.md +44 -0
  67. package/dist/plugins/tabs/index.js +75 -0
  68. package/dist/plugins/tabs/public/client.js +1 -0
  69. package/dist/plugins/tabs/public/style.css +98 -0
  70. package/dist/plugins/terminal/README.md +63 -0
  71. package/dist/plugins/terminal/host.js +338 -0
  72. package/dist/plugins/terminal/index.js +170 -0
  73. package/dist/plugins/terminal/modes.js +32 -0
  74. package/dist/plugins/terminal/public/client.js +41 -0
  75. package/dist/plugins/terminal/public/style.css +511 -0
  76. package/dist/plugins/terminal/server.js +256 -0
  77. package/dist/plugins/terminal/sizes.js +58 -0
  78. package/dist/plugins/timeline/README.md +48 -0
  79. package/dist/plugins/timeline/index.js +83 -0
  80. package/dist/plugins/timeline/public/style.css +138 -0
  81. package/dist/plugins/toc/README.md +40 -0
  82. package/dist/plugins/toc/index.js +29 -0
  83. package/dist/plugins/toc/public/client.js +1 -0
  84. package/dist/plugins/toc/public/style.css +117 -0
  85. package/dist/plugins/window/README.md +51 -0
  86. package/dist/plugins/window/index.js +91 -0
  87. package/dist/solid/index.js +41 -0
  88. package/dist/src/agents.js +81 -0
  89. package/dist/src/anchors.js +52 -0
  90. package/dist/src/api.js +282 -0
  91. package/dist/src/archive.js +49 -0
  92. package/dist/src/auth.js +67 -0
  93. package/dist/src/build.js +159 -0
  94. package/dist/src/client/page/base.css +1762 -0
  95. package/dist/src/client/page/main.js +2121 -0
  96. package/dist/src/config.js +76 -0
  97. package/dist/src/document.js +93 -0
  98. package/dist/src/entries.js +264 -0
  99. package/dist/src/events.js +322 -0
  100. package/dist/src/files.js +47 -0
  101. package/dist/src/formstate.js +65 -0
  102. package/dist/src/help.js +213 -0
  103. package/dist/src/html.js +34 -0
  104. package/dist/src/hub.js +348 -0
  105. package/dist/src/icons.js +6 -0
  106. package/dist/src/listen.js +132 -0
  107. package/dist/src/listeners.js +64 -0
  108. package/dist/src/load.js +81 -0
  109. package/dist/src/loader.js +179 -0
  110. package/dist/src/migrate.js +314 -0
  111. package/dist/src/package.js +52 -0
  112. package/dist/src/pages/blocks.js +67 -0
  113. package/dist/src/pages/board.js +59 -0
  114. package/dist/src/pages/index.js +27 -0
  115. package/dist/src/pages/markdown.js +863 -0
  116. package/dist/src/pages/render.js +761 -0
  117. package/dist/src/pages/window.js +29 -0
  118. package/dist/src/plugins.js +283 -0
  119. package/dist/src/public.js +24 -0
  120. package/dist/src/rename.js +130 -0
  121. package/dist/src/running.js +146 -0
  122. package/dist/src/serve.js +188 -0
  123. package/dist/src/server.js +1105 -0
  124. package/dist/src/site.js +179 -0
  125. package/dist/src/state.js +155 -0
  126. package/dist/src/status.js +323 -0
  127. package/dist/src/thread.js +68 -0
  128. package/dist/src/watchdog.js +38 -0
  129. package/dist/src/ws.js +128 -0
  130. package/package.json +154 -4
  131. package/plugins/README.md +304 -0
  132. package/plugins/alert/README.md +18 -0
  133. package/plugins/alert/index.ts +50 -0
  134. package/plugins/alert/public/style.css +40 -0
  135. package/plugins/ansi/README.md +36 -0
  136. package/plugins/ansi/index.ts +95 -0
  137. package/plugins/ansi/public/style.css +28 -0
  138. package/plugins/badge/README.md +32 -0
  139. package/plugins/badge/index.ts +36 -0
  140. package/plugins/badge/public/style.css +30 -0
  141. package/plugins/chat/README.md +81 -0
  142. package/plugins/chat/autosize.ts +139 -0
  143. package/plugins/chat/client.tsx +187 -0
  144. package/plugins/chat/index.ts +146 -0
  145. package/plugins/chat/public/style.css +143 -0
  146. package/plugins/claude/README.md +116 -0
  147. package/plugins/claude/channel.ts +136 -0
  148. package/plugins/claude/doctor.ts +274 -0
  149. package/plugins/claude/index.ts +248 -0
  150. package/plugins/claude/session.ts +70 -0
  151. package/plugins/code/README.md +54 -0
  152. package/plugins/code/client.ts +73 -0
  153. package/plugins/code/diff.ts +96 -0
  154. package/plugins/code/index.ts +136 -0
  155. package/plugins/code/public/style.css +99 -0
  156. package/plugins/comments/README.md +30 -0
  157. package/plugins/comments/client.ts +723 -0
  158. package/plugins/comments/index.ts +48 -0
  159. package/plugins/comments/public/style.css +224 -0
  160. package/plugins/details/README.md +24 -0
  161. package/plugins/details/index.ts +30 -0
  162. package/plugins/details/public/style.css +7 -0
  163. package/plugins/draft/README.md +14 -0
  164. package/plugins/draft/index.ts +23 -0
  165. package/plugins/draft/public/style.css +21 -0
  166. package/plugins/forge/README.md +22 -0
  167. package/plugins/forge/index.ts +84 -0
  168. package/plugins/form/README.md +126 -0
  169. package/plugins/form/index.ts +199 -0
  170. package/plugins/form/public/style.css +172 -0
  171. package/plugins/grid/README.md +45 -0
  172. package/plugins/grid/index.ts +41 -0
  173. package/plugins/grid/public/style.css +98 -0
  174. package/plugins/iframe/README.md +18 -0
  175. package/plugins/iframe/index.ts +53 -0
  176. package/plugins/iframe/public/style.css +28 -0
  177. package/plugins/index.ts +49 -0
  178. package/plugins/lightbox/README.md +24 -0
  179. package/plugins/lightbox/client.ts +109 -0
  180. package/plugins/lightbox/index.ts +25 -0
  181. package/plugins/lightbox/public/style.css +66 -0
  182. package/plugins/mermaid/README.md +21 -0
  183. package/plugins/mermaid/index.ts +46 -0
  184. package/plugins/mermaid/public/style.css +21 -0
  185. package/plugins/opencode/README.md +48 -0
  186. package/plugins/opencode/channel.ts +112 -0
  187. package/plugins/opencode/index.ts +91 -0
  188. package/plugins/opencode/shim.ts +166 -0
  189. package/plugins/quiet/README.md +26 -0
  190. package/plugins/quiet/index.ts +28 -0
  191. package/plugins/tabs/README.md +44 -0
  192. package/plugins/tabs/client.ts +96 -0
  193. package/plugins/tabs/index.ts +103 -0
  194. package/plugins/tabs/public/style.css +98 -0
  195. package/plugins/terminal/README.md +63 -0
  196. package/plugins/terminal/client.ts +391 -0
  197. package/plugins/terminal/host.ts +434 -0
  198. package/plugins/terminal/index.ts +199 -0
  199. package/plugins/terminal/modes.ts +30 -0
  200. package/plugins/terminal/public/style.css +225 -0
  201. package/plugins/terminal/server.ts +266 -0
  202. package/plugins/terminal/sizes.ts +72 -0
  203. package/plugins/timeline/README.md +48 -0
  204. package/plugins/timeline/index.ts +82 -0
  205. package/plugins/timeline/public/style.css +138 -0
  206. package/plugins/toc/README.md +40 -0
  207. package/plugins/toc/client.ts +236 -0
  208. package/plugins/toc/index.ts +55 -0
  209. package/plugins/toc/public/style.css +117 -0
  210. package/plugins/window/README.md +51 -0
  211. package/plugins/window/index.ts +92 -0
  212. package/skills/workpad/SKILL.md +592 -0
  213. package/solid/index.tsx +80 -0
  214. package/src/agents.ts +134 -0
  215. package/src/anchors.ts +85 -0
  216. package/src/api.ts +444 -0
  217. package/src/archive.ts +75 -0
  218. package/src/auth.ts +99 -0
  219. package/src/build.ts +213 -0
  220. package/src/client/base.ts +19 -0
  221. package/src/client/forms.ts +420 -0
  222. package/src/client/markdown.ts +147 -0
  223. package/src/client/page/base.css +1762 -0
  224. package/src/client/page/board.ts +166 -0
  225. package/src/client/page/elsewhere.ts +153 -0
  226. package/src/client/page/fresh.ts +343 -0
  227. package/src/client/page/heading-link.ts +32 -0
  228. package/src/client/page/live.ts +134 -0
  229. package/src/client/page/main.ts +398 -0
  230. package/src/client/page/orphans.ts +64 -0
  231. package/src/client/page/place.ts +260 -0
  232. package/src/client/page/sort.ts +49 -0
  233. package/src/client/page/sticky.ts +58 -0
  234. package/src/client/page/theme.ts +36 -0
  235. package/src/client/page/view.ts +9 -0
  236. package/src/client/page/waiting.ts +278 -0
  237. package/src/client/page/window.ts +40 -0
  238. package/src/client/reactive.ts +19 -0
  239. package/src/client/read.ts +111 -0
  240. package/src/client/runtime.ts +499 -0
  241. package/src/client/scroll.ts +90 -0
  242. package/src/client/toast.ts +99 -0
  243. package/src/config.ts +111 -0
  244. package/src/define.ts +997 -0
  245. package/src/document.ts +191 -0
  246. package/src/entries.ts +352 -0
  247. package/src/events.ts +463 -0
  248. package/src/files.ts +74 -0
  249. package/src/formstate.ts +72 -0
  250. package/src/help.ts +240 -0
  251. package/src/html.ts +44 -0
  252. package/src/hub.ts +435 -0
  253. package/src/icons.ts +18 -0
  254. package/src/listen.ts +171 -0
  255. package/src/listeners.ts +89 -0
  256. package/src/load.ts +113 -0
  257. package/src/loader.ts +227 -0
  258. package/src/migrate.ts +352 -0
  259. package/src/package.ts +62 -0
  260. package/src/pages/blocks.ts +106 -0
  261. package/src/pages/board.ts +89 -0
  262. package/src/pages/index.ts +79 -0
  263. package/src/pages/markdown.ts +976 -0
  264. package/src/pages/render.ts +845 -0
  265. package/src/pages/window.ts +69 -0
  266. package/src/plugins.ts +319 -0
  267. package/src/public.ts +39 -0
  268. package/src/rename.ts +147 -0
  269. package/src/running.ts +171 -0
  270. package/src/serve.ts +221 -0
  271. package/src/server.ts +1385 -0
  272. package/src/site.ts +170 -0
  273. package/src/state.ts +327 -0
  274. package/src/status.ts +466 -0
  275. package/src/thread.ts +98 -0
  276. package/src/watchdog.ts +53 -0
  277. package/src/ws.ts +155 -0
@@ -0,0 +1,199 @@
1
+ // :::form{name=…} — a named form whose body is ordinary markdown, with inputs written inline anywhere in
2
+ // it: `:radio[This **week**]{name=when}`, `:checkbox[…]`, `:text[…]`, `:button[Send]` and so on. See
3
+ // README.md.
4
+ //
5
+ // Everything here renders on the server as plain HTML: a `<form name>` the core looks after (it
6
+ // sends a submit as an event, keeps drafts, puts the last answer back and marks where the form
7
+ // stands, which the page shows). The chat under the form is the chat plugin's.
8
+ import fs from 'node:fs'
9
+ import { definePlugin, type Plugin } from '@bigmistqke/workpad'
10
+ import { anchorTaken, html, raw, type Block, type DirectiveContext } from '@bigmistqke/workpad'
11
+ import { chatThread } from '../chat/index.ts'
12
+ import { isQuestionName } from '../../src/status.ts'
13
+ import { builtinPublic } from '../../src/package.ts'
14
+
15
+ const style = 'style.css'
16
+
17
+ const CHOICES = new Set(['radio', 'checkbox', 'select', 'hidden'])
18
+
19
+ interface Node {
20
+ type: string
21
+ name?: string
22
+ attributes?: Record<string, string>
23
+ children?: Node[]
24
+ }
25
+
26
+ /** The inputs written inside a form's markdown (forms inside it excluded: forms don't nest). */
27
+ function inputsOf(nodes: Node[]) {
28
+ const found: { name: string; attrs: Record<string, string> }[] = []
29
+ const walk = (node: Node) => {
30
+ if ((node.type === 'textDirective' || node.type === 'leafDirective') && node.name)
31
+ found.push({ name: node.name, attrs: node.attributes ?? {} })
32
+ if (node.type === 'containerDirective' && node.name === 'form') return
33
+ for (const child of node.children ?? []) walk(child)
34
+ }
35
+ nodes.forEach(walk)
36
+ return found
37
+ }
38
+
39
+ /**
40
+ * Marks the list items that start with an option and say more under it (`data-wp-explained`): rows
41
+ * to pick with an explanation are spaced apart, plain ones sit close. The explanation is text in the
42
+ * item, which a stylesheet can't tell from nothing, so the markdown is looked at instead.
43
+ */
44
+ function markExplained(nodes: Node[]) {
45
+ const walk = (node: Node & { value?: string; data?: { hProperties?: Record<string, unknown> } }) => {
46
+ if (node.type === 'containerDirective' && node.name === 'form') return
47
+ if (node.type === 'listItem') {
48
+ const [first, ...rest] = node.children ?? []
49
+ const lead = first?.type === 'paragraph' ? (first.children ?? []) : []
50
+ const option = lead[0]?.type === 'textDirective' && (lead[0].name === 'radio' || lead[0].name === 'checkbox')
51
+ const more =
52
+ rest.length > 0 || lead.slice(1).some(n => n.type !== 'text' || !!(n as { value?: string }).value?.trim())
53
+ if (option && more) node.data = { ...node.data, hProperties: { ...node.data?.hProperties, dataWpExplained: '' } }
54
+ }
55
+ for (const child of node.children ?? []) walk(child)
56
+ }
57
+ nodes.forEach(walk)
58
+ }
59
+
60
+ const recommendedTag = html`<span class="wp-form-recommended">recommended</span>`
61
+
62
+ const form: Block = {
63
+ style,
64
+ async html(ctx) {
65
+ const c = ctx as DirectiveContext
66
+ const written = c.attrs.name || c.attrs.id || ''
67
+ // a colon marks the events of workpad or a plugin (`chat:message`), never an answer
68
+ if (written && !isQuestionName(written))
69
+ throw new Error(
70
+ `form name "${written}" has a colon: those names are reserved for events of workpad and plugins`,
71
+ )
72
+ // a slash marks a form in a chat message: named in its chat, `<chat>/<name>` (or its number there)
73
+ if (written.includes('/'))
74
+ throw new Error(`form name "${written}" has a slash: those names are a chat message's forms, \`<chat>/<name>\``)
75
+ const name = c.chat ? `${c.chat.name}/${written || c.chat.next()}` : written || 'form'
76
+ const inputs = inputsOf(c.children as Node[])
77
+ markExplained(c.children as Node[])
78
+ const choices = [...new Set(inputs.filter(i => CHOICES.has(i.name) && i.attrs.name).map(i => i.attrs.name))]
79
+ const hasButton = inputs.some(i => i.name === 'button')
80
+ // the first button is the form's primary one; the markup is the button block's own
81
+ const body = (await c.toHtml(c.children)).replace(
82
+ '<button name="action"',
83
+ '<button class="wp-primary" name="action"',
84
+ )
85
+ // #form:<name> goes to it, #chat:<name> to its chat (src/anchors.ts)
86
+ const id = c.anchor('form', name)
87
+ // the form's chat: talk about the question, named after the form (see ../chat); one in a chat
88
+ // message has the chat it is in, and `chat=false` has none (a button that only starts something)
89
+ const thread =
90
+ c.chat || c.attrs.chat === 'false' ? '' : await chatThread(c, name, { choices, anchor: c.anchor('chat', name) })
91
+ // its label is its title (a grid's card, when the form is an item of one); a badge ending it at
92
+ // its right (data-wp-title, base.css)
93
+ const title = c.label && html`<div class="wp-form-title" data-wp-title>${raw(c.label)}</div>`
94
+ return html`${!id ? anchorTaken('form', name) : ''}
95
+ <form name="${name}" class="wp-form" ${id ? html` id="${id}"` : ''}>
96
+ ${title}${raw(body)}${!hasButton && html`<p><button class="wp-primary">Send</button></p>`}${raw(thread)}
97
+ </form>`
98
+ },
99
+ }
100
+
101
+ /** The label of an inline input as HTML, else its fallback. */
102
+ const labelOf = (c: DirectiveContext, fallback = '') => (c.label ? raw(c.label) : fallback)
103
+
104
+ /**
105
+ * :radio[label]{name=… value=… recommended checked} and :checkbox[…]{…}. With `other`, an answer not on
106
+ * the list: the option has a text box, typing in it picks the option, and it sends what was typed
107
+ * (the core's forms.ts, `data-wp-other`).
108
+ */
109
+ const option =
110
+ (type: 'radio' | 'checkbox'): Block['html'] =>
111
+ ctx => {
112
+ const c = ctx as DirectiveContext
113
+ if ('other' in c.attrs) {
114
+ const placeholder = c.attrs.placeholder ?? 'something else'
115
+ return html`<label class="wp-form-option wp-form-other"
116
+ ><input type="${type}" name="${c.attrs.name}" value="" data-wp-other /><span class="wp-form-option-label"
117
+ >${labelOf(c, 'Other')}</span
118
+ ><input
119
+ type="text"
120
+ class="wp-form-other-text"
121
+ data-wp-other-text
122
+ placeholder="${placeholder}"
123
+ aria-label="${c.labelText ?? 'Other'}"
124
+ /></label>`
125
+ }
126
+ const value = c.attrs.value ?? c.labelText ?? ''
127
+ return html`<label class="wp-form-option"
128
+ ><input type="${type}" name="${c.attrs.name}" value="${value}" ${'checked' in c.attrs && raw(' checked')} /><span
129
+ class="wp-form-option-label"
130
+ >${labelOf(c, value)}</span
131
+ >${'recommended' in c.attrs && recommendedTag}</label
132
+ >`
133
+ }
134
+
135
+ /** :text[label]{name=… placeholder=…}, and number, date, range */
136
+ const field =
137
+ (type: string): Block['html'] =>
138
+ ctx => {
139
+ const c = ctx as DirectiveContext
140
+ const extra = ['placeholder', 'min', 'max', 'step', 'value']
141
+ .filter(k => k in c.attrs)
142
+ .map(k => html` ${raw(k)}="${c.attrs[k]}"`)
143
+ return html`<label class="wp-form-field"
144
+ ><span class="wp-form-label">${labelOf(c)}</span><input type="${type}" name="${c.attrs.name}" ${extra}
145
+ /></label>`
146
+ }
147
+
148
+ const input = (name: string, render: Block['html']): [string, Block] => [name, { html: render, style }]
149
+
150
+ const inputs: [string, Block][] = [
151
+ input('radio', option('radio')),
152
+ input('checkbox', option('checkbox')),
153
+ input('text', field('text')),
154
+ input('number', field('number')),
155
+ input('date', field('date')),
156
+ input('range', field('range')),
157
+ input('textarea', ctx => {
158
+ const c = ctx as DirectiveContext
159
+ return html`<label class="wp-form-field"
160
+ ><span class="wp-form-label">${labelOf(c)}</span
161
+ ><textarea name="${c.attrs.name}" rows="3" placeholder="${c.attrs.placeholder ?? ''}">
162
+ ${c.attrs.value ?? ''}</textarea>
163
+ </label>`
164
+ }),
165
+ input('select', ctx => {
166
+ const c = ctx as DirectiveContext
167
+ const options = (c.attrs.options ?? '')
168
+ .split(',')
169
+ .map(s => s.trim())
170
+ .filter(Boolean)
171
+ return html`<label class="wp-form-field"
172
+ ><span class="wp-form-label">${labelOf(c)}</span
173
+ ><select name="${c.attrs.name}">
174
+ ${options.map(o => html`<option${o === c.attrs.value && raw(' selected')}>${o}</option>`)}
175
+ </select></label
176
+ >`
177
+ }),
178
+ input('hidden', ctx => {
179
+ const c = ctx as DirectiveContext
180
+ return html`<input type="hidden" name="${c.attrs.name}" value="${c.attrs.value ?? ''}" />`
181
+ }),
182
+ input('button', ctx => {
183
+ const c = ctx as DirectiveContext
184
+ const value = c.labelText ?? 'Send'
185
+ return html`<button name="action" value="${value}">${labelOf(c, 'Send')}</button>`
186
+ }),
187
+ ]
188
+
189
+ export default function formPlugin(): Plugin {
190
+ return definePlugin({
191
+ name: 'form',
192
+ public: builtinPublic('form'),
193
+ blocks: {
194
+ form: { ...form, menu: { group: 'ask', summary: 'questions: radios, checkboxes, text, buttons; one form per decision' } },
195
+ ...Object.fromEntries(inputs),
196
+ },
197
+ docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
198
+ })
199
+ }
@@ -0,0 +1,172 @@
1
+ /* a form reads as a set-off part of the article: hairline rules above and below, no box */
2
+ .wp-form {
3
+ /* a block; ringed (open, waiting, sending, failed), plus the ring's distance (base.css) */
4
+ margin: var(--gap-block) 0;
5
+ padding: 1.6em 0 1.7em;
6
+ border-top: var(--hairline) solid var(--border);
7
+ border-bottom: var(--hairline) solid var(--border);
8
+ display: grid;
9
+ /* one column, as wide as the form: wide content (a code block) scrolls inside it, not past it */
10
+ grid-template-columns: minmax(0, 1fr);
11
+ gap: var(--space-2xl);
12
+ /* taller than its content (a card a grid's row stretches): the content packs at the top, the
13
+ room is left below it, instead of spread between its parts */
14
+ align-content: start;
15
+ }
16
+ .wp-form-pending {
17
+ min-height: 72px;
18
+ }
19
+ /* the form's body is markdown: its first and last blocks sit flush with the rules */
20
+ .wp-form > :first-child {
21
+ margin-top: 0;
22
+ }
23
+ .wp-form > :last-child {
24
+ margin-bottom: 0;
25
+ }
26
+ .wp-form > :is(p, ul, ol, table, .wp-grid, div) {
27
+ margin-top: 0;
28
+ margin-bottom: 0;
29
+ }
30
+ /* its label, `:::form[Title]`: its title, as a heading of the page's third level (base.css) */
31
+ .wp-form-title {
32
+ font-family: var(--serif);
33
+ font-weight: 500;
34
+ font-size: calc(var(--text-size) * 1.4);
35
+ line-height: 1.2;
36
+ letter-spacing: -0.01em;
37
+ margin: 0;
38
+ }
39
+ /* the question: a first paragraph all in bold, as the form's docs write it, reads as its title */
40
+ .wp-form > p:first-child:has(> strong:only-child) {
41
+ font-size: 1.3em;
42
+ line-height: 1.3;
43
+ }
44
+
45
+ /* an inline option, :radio[…] or :checkbox[…]: the input and its label read as one */
46
+ .wp-form-option {
47
+ display: inline-flex;
48
+ gap: var(--space-md);
49
+ align-items: baseline;
50
+ cursor: pointer;
51
+ }
52
+ .wp-form-option + .wp-form-option {
53
+ margin-left: var(--space-2xl);
54
+ }
55
+ .wp-form-option input {
56
+ margin: 0;
57
+ translate: 0 0.1em;
58
+ }
59
+ .wp-form-option-label {
60
+ font-weight: var(--weight-strong);
61
+ }
62
+ /* an answer not on the list: a text box in the option's line (`other`) */
63
+ .wp-form-other {
64
+ align-items: center;
65
+ }
66
+ .wp-form-other .wp-form-other-text {
67
+ translate: none;
68
+ font: inherit;
69
+ padding: var(--space-2xs) var(--space-md);
70
+ min-width: 12em;
71
+ border: var(--hairline) solid var(--border);
72
+ border-radius: var(--radius-sm);
73
+ background: var(--bg);
74
+ color: var(--text);
75
+ }
76
+ .wp-form-recommended {
77
+ font: 500 var(--ui-tiny)/var(--ui-line-height) var(--sans);
78
+ color: var(--muted);
79
+ letter-spacing: var(--caps-spacing);
80
+ text-transform: uppercase;
81
+ margin-left: var(--space-lg);
82
+ }
83
+
84
+ /* a list item that starts with an option is a row to pick: no bullet, the picked one tinted, and
85
+ the rest of the item reads as what the option means */
86
+ .wp-form li:has(> p:first-child > .wp-form-option:first-child),
87
+ .wp-form li:has(> .wp-form-option:first-child) {
88
+ list-style: none;
89
+ margin-left: -1.2em;
90
+ /* --wp-hang: how far an explained row's text hangs in (below) */
91
+ padding: var(--space-2xs) var(--space-lg) var(--space-2xs) calc(var(--space-lg) + var(--wp-hang, 0px));
92
+ border-radius: var(--radius-sm);
93
+ }
94
+ /* rows to pick sit close: their padding (the room for the tint) is the space between them */
95
+ .wp-form :where(li:has(> p:first-child > .wp-form-option:first-child)) + li,
96
+ .wp-form :where(li:has(> .wp-form-option:first-child)) + li {
97
+ margin-top: 0;
98
+ }
99
+ /* a row with an explanation under its option (marked by the form block) stands apart from the
100
+ next, and what it says hangs under the option's label, past the radio or checkbox, so the
101
+ option and its explanation read as one */
102
+ .wp-form li[data-wp-explained] + li,
103
+ .wp-form li + li[data-wp-explained] {
104
+ /* as far as a heading is from what it heads: each option is a small section of its own */
105
+ margin-top: var(--gap-heading);
106
+ }
107
+ .wp-form li[data-wp-explained] {
108
+ --wp-hang: calc(12px + var(--space-md));
109
+ }
110
+ .wp-form li[data-wp-explained] > .wp-form-option:first-child,
111
+ .wp-form li[data-wp-explained] > p:first-child > .wp-form-option:first-child {
112
+ margin-left: calc(0px - var(--wp-hang));
113
+ margin-bottom: var(--gap-attach);
114
+ }
115
+ .wp-form li:has(> p:first-child > .wp-form-option:first-child):hover,
116
+ .wp-form li:has(> .wp-form-option:first-child):hover {
117
+ background: var(--tint);
118
+ }
119
+ .wp-form li:has(> p:first-child > .wp-form-option:first-child input:checked),
120
+ .wp-form li:has(> .wp-form-option:first-child input:checked) {
121
+ background: color-mix(in srgb, var(--accent) var(--tint-faint), transparent);
122
+ }
123
+ .wp-form li > p:first-child {
124
+ margin-bottom: 0.2em;
125
+ }
126
+ .wp-form li > p:first-child > .wp-form-option:first-child,
127
+ .wp-form li > .wp-form-option:first-child {
128
+ display: flex;
129
+ margin-bottom: 0.15em;
130
+ }
131
+
132
+ /* fields: the label above the input */
133
+ .wp-form-field {
134
+ display: flex;
135
+ flex-direction: column;
136
+ gap: var(--space-xs);
137
+ margin: 0;
138
+ min-width: 0;
139
+ }
140
+ .wp-form-field :is(input:not([type='range']), textarea, select) {
141
+ width: 100%;
142
+ }
143
+ .wp-form-field textarea {
144
+ resize: vertical;
145
+ }
146
+ /* a field's label reads like an option's: the text's face and size, in bold */
147
+ .wp-form-label {
148
+ font-weight: var(--weight-strong);
149
+ line-height: var(--ui-line-height);
150
+ }
151
+ /* fields one after another (on lines of one paragraph): apart, each label with its own input */
152
+ .wp-form-field + .wp-form-field {
153
+ margin-top: var(--gap-prose);
154
+ }
155
+ .wp-form-label:empty {
156
+ display: none;
157
+ }
158
+
159
+ /* buttons: the first one of a form is its primary one */
160
+ .wp-form button[name='action'] + button[name='action'] {
161
+ margin-left: var(--space-md);
162
+ }
163
+ .wp-form button.wp-primary {
164
+ background: var(--accent);
165
+ color: var(--accent-text);
166
+ border-color: var(--accent);
167
+ }
168
+ .wp-card .wp-form {
169
+ padding: 0;
170
+ border: 0;
171
+ margin: 0.6em 0 0;
172
+ }
@@ -0,0 +1,45 @@
1
+ Cards in a responsive grid, one per item: an `:::item[Title]` container,
2
+ titled by its label (without one, an untitled card). The card's body is any
3
+ markdown, other blocks and headings of any level included. The grid takes
4
+ one colon more than its items: `::::grid` around `:::item`.
5
+
6
+ A label that ends in a badge (`:::item[Parser :badge[done]]`) shows it at
7
+ the card's right edge.
8
+
9
+ A `:::form` or a `:::details` directly in the grid is a card as it is, not
10
+ wrapped in a card of its own: `:::form[Docs]{name=docs}` is the card,
11
+ titled `Docs`, with the question in it. Write it without an `:::item`
12
+ around it.
13
+
14
+ Attributes: `cols` (target column count on a wide screen, default 3),
15
+ `narrow`.
16
+
17
+ ```markdown
18
+ ::::grid{cols=3}
19
+ :::item[Parser :badge[done]]
20
+ remark + remark-directive.
21
+ :::
22
+
23
+ :::item[Islands :badge[active]]
24
+ Solid components mounted per block.
25
+ :::
26
+
27
+ :::form[Docs :badge[todo]]{name=docs chat=false}
28
+ Start on them? :button[Start it]
29
+ :::
30
+ ::::
31
+ ```
32
+
33
+ ::::grid{cols=3}
34
+ :::item[Parser :badge[done]]
35
+ remark + remark-directive.
36
+ :::
37
+
38
+ :::item[Islands :badge[active]]
39
+ Solid components mounted per block.
40
+ :::
41
+
42
+ :::form[Docs :badge[todo]]{name=docs chat=false}
43
+ Start on them? :button[Start it]
44
+ :::
45
+ ::::
@@ -0,0 +1,41 @@
1
+ import fs from 'node:fs'
2
+ import { definePlugin, type Plugin } from '@bigmistqke/workpad'
3
+ // Static block: no component, so no JavaScript on the page.
4
+ import { html, raw, type DirectiveContext } from '@bigmistqke/workpad'
5
+ import { builtinPublic } from '../../src/package.ts'
6
+
7
+ /**
8
+ * A card per item (DirectiveContext.items): an `:::item[Title]`, titled by its label. A form or a
9
+ * details that is an item is the card itself, never in a card of its own (style.css).
10
+ */
11
+ export async function render(ctx: DirectiveContext) {
12
+ const items = await ctx.items()
13
+ const cols = Number(ctx.attrs.cols)
14
+ const style = cols ? html` style="--wp-grid-cols:${cols}"` : null
15
+ // an item's title and html are HTML already
16
+ const cards = items.map(s =>
17
+ s.block
18
+ ? raw(s.html)
19
+ : html`<article class="wp-card">
20
+ ${s.title && html`<header><h3>${raw(s.title)}</h3></header>`}
21
+ <div class="wp-card-body">${raw(s.html)}</div>
22
+ </article>`,
23
+ )
24
+ return html`<div class="wp-grid${'narrow' in ctx.attrs ? '' : ' wp-wide'}" ${style}>${cards}</div>`
25
+ }
26
+
27
+ export default function grid(): Plugin {
28
+ return definePlugin({
29
+ name: 'grid',
30
+ public: builtinPublic('grid'),
31
+ blocks: {
32
+ grid: {
33
+ menu: { group: 'arrange', summary: 'side by side: options compared, cards' },
34
+ attrs: ['cols', 'narrow'],
35
+ html: render,
36
+ style: 'style.css',
37
+ },
38
+ },
39
+ docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
40
+ })
41
+ }
@@ -0,0 +1,98 @@
1
+ .wp-grid {
2
+ display: grid;
3
+ gap: var(--space-3xl);
4
+ margin: var(--gap-block) 0;
5
+ /* columns for the room it has: in the article, as wide as a wide block is there (narrower beside
6
+ a docked table of contents, --wp-aside), in a container its width (--wp-room, see base.css's
7
+ containers); as many as asked for, the gaps between them taken off, while each is at least 200px */
8
+ --wp-grid-room: var(--wp-room, min(var(--wide, 1040px), 100vw - 32px - var(--wp-aside, 0px)));
9
+ grid-template-columns: repeat(
10
+ auto-fill,
11
+ minmax(
12
+ min(
13
+ 100%,
14
+ max(
15
+ 200px,
16
+ (var(--wp-grid-room) - (var(--wp-grid-cols, 3) - 1) * var(--space-3xl)) / var(--wp-grid-cols, 3) - 1px
17
+ )
18
+ ),
19
+ 1fr
20
+ )
21
+ );
22
+ }
23
+ .wp-grid:not(.wp-wide) {
24
+ grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
25
+ }
26
+
27
+ .wp-card {
28
+ background: var(--surface);
29
+ border: var(--hairline) solid var(--border);
30
+ border-radius: var(--radius);
31
+ padding: var(--space-2xl) var(--space-2xl) var(--space-2xl);
32
+ min-width: 0;
33
+ }
34
+ .wp-card > header {
35
+ margin-bottom: var(--gap-attach);
36
+ }
37
+ .wp-card h3 {
38
+ margin: 0;
39
+ font-size: 1.02rem;
40
+ }
41
+ .wp-card-body {
42
+ font-size: var(--ui-text);
43
+ line-height: 1.6;
44
+ }
45
+ .wp-card-body > :first-child {
46
+ margin-top: 0;
47
+ }
48
+ .wp-card-body > :last-child {
49
+ margin-bottom: 0;
50
+ }
51
+
52
+
53
+ /* a form or a details that is an item is the card itself, never a frame in a frame: framed as a
54
+ card. A form's ring (base.css) is its border, not around it: no room for one in the gaps; its
55
+ states keep the card's padding and place */
56
+ .wp-grid > :is(form.wp-form, details.wp-details) {
57
+ background: var(--surface);
58
+ border: var(--hairline) solid var(--border);
59
+ border-radius: var(--radius);
60
+ padding: var(--space-2xl);
61
+ margin: 0;
62
+ min-width: 0;
63
+ --wp-ring-at: 0px;
64
+ }
65
+ .wp-grid > form.wp-form:is([data-wp-open], [data-wp-pending], [data-wp-received], [data-wp-state], [data-wp-folded]) {
66
+ border-color: var(--border);
67
+ padding: var(--space-2xl);
68
+ margin: 0;
69
+ }
70
+ .wp-grid > form.wp-form::before {
71
+ border-radius: var(--radius);
72
+ }
73
+ .wp-grid > form.wp-form > .wp-form-title {
74
+ font-size: 1.02rem;
75
+ }
76
+ .wp-grid > details.wp-details > summary {
77
+ padding: 0;
78
+ }
79
+ .wp-grid > details.wp-details[open] > summary {
80
+ margin-bottom: var(--gap-attach);
81
+ }
82
+ .wp-grid > details.wp-details > :not(summary) {
83
+ margin-left: 0;
84
+ }
85
+ .wp-grid > details.wp-details[open] > :last-child {
86
+ margin-bottom: 0;
87
+ }
88
+ /* an answered form as a card: its title first, as an unanswered card has it, the answer line under */
89
+ .wp-grid > form.wp-form[data-wp-folded] > .wp-form-title {
90
+ order: -1;
91
+ }
92
+ .wp-grid > form.wp-form[data-wp-folded] > .wp-folded {
93
+ margin-top: var(--space-sm);
94
+ }
95
+ .wp-grid > form.wp-form[data-wp-folded] .wp-folded-choice {
96
+ font: var(--ui-small)/var(--ui-line-height) var(--sans);
97
+ color: var(--muted);
98
+ }
@@ -0,0 +1,18 @@
1
+ Another page inside this one: a running app (a dev server), a deployed
2
+ site, or an HTML file next to the pages. Drag the frame's bottom edge to
3
+ make it taller. With `compose=window`, it is in a window: a header with its label
4
+ (or, without one, its address), a button that opens it on its own, and one
5
+ that fills the browser window with it (the same button, or Esc, puts it
6
+ back).
7
+
8
+ Attributes: `src` (required: an http(s) URL, or a path such as `demo.html`
9
+ for `.workpad/pages/demo.html`), `height` (a number of pixels or a CSS
10
+ length, default 480), `compose=window`, `wide` (wider than the text column).
11
+
12
+ ```markdown
13
+ ::iframe[The app as it runs now]{src="http://localhost:5173" height=600 compose=window wide}
14
+ ```
15
+
16
+ A site that forbids being framed (most large ones do, with
17
+ `X-Frame-Options` or `frame-ancestors`) shows as a blank or refused frame;
18
+ link to it instead.
@@ -0,0 +1,53 @@
1
+ // Another page inside this one: a URL (a dev server, a deployed site) or an HTML file next to the
2
+ // pages (`demo.html` in .workpad/pages/ is served as it is), in a frame that can be made taller
3
+ // by dragging its bottom edge. With `compose=window`, in a window (src/pages/window.ts): a header with its
4
+ // label, open on its own, fill the browser window.
5
+ import fs from 'node:fs'
6
+ import { builtinPublic } from '../../src/package.ts'
7
+ import { definePlugin, type Plugin } from '@bigmistqke/workpad'
8
+ import { html, type DirectiveContext } from '@bigmistqke/workpad'
9
+
10
+ /** http(s), protocol-relative, or a path on this server; never `javascript:` or `data:`. */
11
+ export const safeSrc = (src: string) => /^(https?:)?\/\//i.test(src) || !/^[a-z][a-z0-9+.-]*:/i.test(src)
12
+
13
+ /** A height in px (a bare number) or a CSS length; else the default. */
14
+ export function height(value: string | undefined): string {
15
+ if (value && /^\d+(\.\d+)?$/.test(value)) return `${value}px`
16
+ if (value && /^\d+(\.\d+)?(px|em|rem|vh|svh|dvh)$/.test(value)) return value
17
+ return '480px'
18
+ }
19
+
20
+ export async function render(ctx: DirectiveContext) {
21
+ const src = (ctx.attrs.src ?? '').trim()
22
+ if (!src) return html`<pre class="wp-error">iframe: needs a src, like ::iframe{src="http://localhost:5173"}</pre>`
23
+ if (!safeSrc(src))
24
+ return html`<pre class="wp-error">iframe: src must be an http(s) URL or a path, not ${src.split(':')[0]}:</pre>`
25
+ const title = ctx.labelText ?? ctx.attrs.title ?? src
26
+ // the frame, which the reader can drag taller
27
+ return html`<div class="wp-iframe-frame" style="height: ${height(ctx.attrs.height)}">
28
+ <iframe src="${ctx.fileUrl(src)}" title="${title}" loading="lazy" referrerpolicy="no-referrer"></iframe>
29
+ </div>`
30
+ }
31
+
32
+ /** What it shows on its own, for the ↗ of a window around it: its address. */
33
+ export function open(ctx: DirectiveContext) {
34
+ const src = (ctx.attrs.src ?? '').trim()
35
+ return src && safeSrc(src) ? ctx.fileUrl(src) : null
36
+ }
37
+
38
+ export default function iframe(): Plugin {
39
+ return definePlugin({
40
+ name: 'iframe',
41
+ public: builtinPublic('iframe'),
42
+ blocks: {
43
+ iframe: {
44
+ menu: { group: 'show', summary: 'another page, live: the running app' },
45
+ attrs: ['src', 'height', 'title', 'wide'],
46
+ html: render,
47
+ open,
48
+ style: 'style.css',
49
+ },
50
+ },
51
+ docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
52
+ })
53
+ }
@@ -0,0 +1,28 @@
1
+ /* the iframe in its window (the window's look is the page's): a frame its bottom edge drags taller */
2
+ .wp-iframe-frame {
3
+ resize: vertical;
4
+ overflow: hidden;
5
+ min-height: 120px;
6
+ background: #fff;
7
+ }
8
+ .wp-iframe-frame iframe {
9
+ display: block;
10
+ width: 100%;
11
+ height: 100%;
12
+ border: 0;
13
+ }
14
+ /* in a window (`::iframe{src window}`): the frame is its body, edge to edge; filling the browser
15
+ window, as tall as it is */
16
+ .wp-window-body:has(> .wp-iframe-frame:only-child) {
17
+ padding: 0;
18
+ overflow: hidden;
19
+ }
20
+ .wp-window[data-wp-maximized] .wp-window-body:has(> .wp-iframe-frame:only-child) {
21
+ display: flex;
22
+ flex-direction: column;
23
+ }
24
+ .wp-window[data-wp-maximized] .wp-iframe-frame {
25
+ flex: 1;
26
+ height: auto !important;
27
+ resize: none;
28
+ }