@estiva-app/ui 0.78.0 → 0.79.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/dist/linked.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * widgets look nothing up, and keep nothing but what a reader does to them.
7
7
  *
8
8
  * The shape follows the prototype Miky approved (Widgets 2, 15 Oct; why:
9
- * https://github.com/estiva-app/estiva-docs/blob/main/decisions/where-a-link-sits-and-which-file-gets-the-card.md).
9
+ * https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-link-on-words-counts-toward-the-card.md).
10
10
  */
11
11
  import type { ThingKind } from './KindIcon';
12
12
  /** What a link stands for, by its icon. `page` draws a page of text. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/ui",
3
- "version": "0.78.0",
3
+ "version": "0.79.0",
4
4
  "description": "Estiva's design tokens (the contract) and a small set of primitives (a convenience) for every Estiva app.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/registry.json CHANGED
@@ -4,8 +4,8 @@
4
4
  "kind": "package",
5
5
  "repo": "estiva-ui",
6
6
  "package": "@estiva-app/ui",
7
- "packageVersion": "0.78.0",
8
- "exports": 203,
7
+ "packageVersion": "0.79.0",
8
+ "exports": 204,
9
9
  "typeExports": 197,
10
10
  "files": null
11
11
  },
@@ -8702,6 +8702,25 @@
8702
8702
  "bg-error-muted signal:bg-bg-inset signal:border signal:border-border-default signal:shadow-md leaf:bg-bg-inset leaf:border leaf:border-border-default leaf:shadow-md"
8703
8703
  ]
8704
8704
  },
8705
+ {
8706
+ "name": "toggleTableHeaderRow",
8707
+ "repo": "estiva-ui",
8708
+ "kind": "helper",
8709
+ "importPath": "@estiva-app/ui/editor",
8710
+ "sourceFile": "src/EditorTableControls.tsx",
8711
+ "purpose": "The table's first row becomes its header row, or an ordinary row again: whichever cell of the table `cell` is.",
8712
+ "purposeFrom": "comment",
8713
+ "props": [],
8714
+ "variants": [],
8715
+ "ownsBehaviours": [],
8716
+ "status": "stable",
8717
+ "migrationStage": null,
8718
+ "docsId": "primitives-editortablecontrols--docs",
8719
+ "storyId": "primitives-editortablecontrols--default",
8720
+ "docPage": null,
8721
+ "app": null,
8722
+ "looks": []
8723
+ },
8705
8724
  {
8706
8725
  "name": "Toolbar",
8707
8726
  "repo": "estiva-ui",
package/src/CardUnder.tsx CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The one card added under a piece of text, and the ✕ that removes it (why:
3
- * https://github.com/estiva-app/estiva-docs/blob/main/decisions/where-a-link-sits-and-which-file-gets-the-card.md).
3
+ * https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-link-on-words-counts-toward-the-card.md).
4
4
  *
5
5
  * Under a box being written in, the ✕ always shows. Under text already sent
6
6
  * (`revealOnHover`) it shows when the pointer is over the card or the ✕ has
@@ -10,14 +10,19 @@ row and on its column, and a ➕ bar under the table and right of it.
10
10
 
11
11
  <Canvas of={EditorTableControlsStories.Default} />
12
12
 
13
+ <Canvas of={EditorTableControlsStories.NoHeaderRow} />
14
+
13
15
  ## When
14
16
 
15
17
  - **An editor whose documents hold tables** — with TableKit
16
18
  (`@tiptap/extension-table`) in its extensions. Point at a cell: the row's
17
19
  handle sits on the table's left edge, the column's on its top edge; each
18
20
  opens Insert (above and below, or left and right), Delete, and Delete
19
- table. A header row offers nothing above it, and deleting it makes the next
20
- row the header, so a table always opens with its header. From the last row, a ➕ under the table adds a row after it; from the
21
+ table. The first row's menu opens with Header row, ticked while the first
22
+ row is the table's header; choosing it turns the header row off (the first
23
+ row becomes an ordinary row) or on again. A header row offers nothing above
24
+ it, and deleting it makes the next row the header. With the header off, the
25
+ first row takes Insert above and deleting it promotes nothing. From the last row, a ➕ under the table adds a row after it; from the
21
26
  last column, a ➕ right of the table adds a column after it.
22
27
  - **Not editable**: nothing is drawn.
23
28
 
@@ -36,10 +36,18 @@ const DOCUMENT = {
36
36
  ],
37
37
  }
38
38
 
39
- function Editing({ editable }: { editable: boolean }) {
39
+ const NO_HEADER = {
40
+ type: 'doc',
41
+ content: [
42
+ { type: 'paragraph', content: [{ type: 'text', text: 'The first row’s handle turns the header row back on.' }] },
43
+ { type: 'table', content: [row('tableCell', 'Item one', 'Value', 'Value'), row('tableCell', 'Item two', 'Value', 'Value')] },
44
+ ],
45
+ }
46
+
47
+ function Editing({ editable, content = DOCUMENT }: { editable: boolean; content?: object }) {
40
48
  const editor = useEditor({
41
49
  extensions: [StarterKit.configure({ dropcursor: blockDropCursor }), TableKit.configure({ table: { resizable: false } }), BlockId],
42
- content: DOCUMENT,
50
+ content,
43
51
  editable,
44
52
  editorProps: { attributes: { class: richTextClassName('default', 'outline-none'), 'aria-label': 'Text' } },
45
53
  })
@@ -52,11 +60,16 @@ function Editing({ editable }: { editable: boolean }) {
52
60
  )
53
61
  }
54
62
 
55
- /** Point at a cell; press a handle for Insert and Delete, or a ➕ bar to add a row or a column at the end. */
63
+ /** Point at a cell; press a handle for Insert and Delete, or a ➕ bar to add a row or a column at the end. The first row's handle also has Header row, ticked while it is on. */
56
64
  export const Default: Story = {
57
65
  render: () => <Editing editable />,
58
66
  }
59
67
 
68
+ /** A table with its header row off: the first row is an ordinary row, and its handle's Header row is not ticked. */
69
+ export const NoHeaderRow: Story = {
70
+ render: () => <Editing editable content={NO_HEADER} />,
71
+ }
72
+
60
73
  /** An editor that is not editable: no controls. */
61
74
  export const NotEditable: Story = {
62
75
  render: () => <Editing editable={false} />,
@@ -13,7 +13,7 @@ import { Editor } from '@tiptap/core'
13
13
  import StarterKit from '@tiptap/starter-kit'
14
14
  import { TableKit } from '@tiptap/extension-table'
15
15
  import { BlockId } from './BlockNodes'
16
- import { EditorTableControls, appendTableColumn, appendTableRow, deleteTableColumn, deleteTableRow } from './EditorTableControls'
16
+ import { EditorTableControls, appendTableColumn, appendTableRow, deleteTableColumn, deleteTableRow, toggleTableHeaderRow } from './EditorTableControls'
17
17
 
18
18
  type Json = { type: string; attrs?: Record<string, unknown>; content?: Json[]; text?: string }
19
19
 
@@ -230,12 +230,50 @@ describe('EditorTableControls', () => {
230
230
  const user = await mount(e)
231
231
  await act(async () => user.hover(screen.getByText('B')))
232
232
  await press(user, screen.getByRole('button', { name: 'Row menu' }))
233
- expect(screen.getAllByRole('menuitem').map((r) => r.textContent)).toEqual(['Insert below', 'Delete', 'Delete table'])
233
+ expect(screen.getAllByRole('menuitem').map((r) => r.textContent)).toEqual(['Header row', 'Insert below', 'Delete', 'Delete table'])
234
234
  await user.click(screen.getByRole('menuitem', { name: 'Delete' }))
235
235
  await frame()
236
236
  expect(shape(e)).toEqual(['#a1|#b1|#c1', 'a2|b2|c2'])
237
237
  })
238
238
 
239
+ it('the first row’s menu turns the header row off and on; off, the first row is an ordinary row', async () => {
240
+ const e = editor()
241
+ const user = await mount(e)
242
+ await act(async () => user.hover(screen.getByText('B')))
243
+ await press(user, screen.getByRole('button', { name: 'Row menu' }))
244
+ await user.click(screen.getByRole('menuitem', { name: 'Header row' }))
245
+ await frame()
246
+ expect(shape(e)).toEqual(['A|B|C', 'a1|b1|c1', 'a2|b2|c2'])
247
+
248
+ // Off: the first row takes a row above it, and deleting it promotes nothing.
249
+ await act(async () => user.hover(screen.getByText('B')))
250
+ await press(user, screen.getByRole('button', { name: 'Row menu' }))
251
+ expect(screen.getAllByRole('menuitem').map((r) => r.textContent)).toEqual(['Header row', 'Insert above', 'Insert below', 'Delete', 'Delete table'])
252
+ await user.click(screen.getByRole('menuitem', { name: 'Header row' }))
253
+ await frame()
254
+ expect(shape(e)).toEqual(['#A|#B|#C', 'a1|b1|c1', 'a2|b2|c2'])
255
+
256
+ await act(async () => user.hover(screen.getByText('B')))
257
+ await press(user, screen.getByRole('button', { name: 'Row menu' }))
258
+ await user.click(screen.getByRole('menuitem', { name: 'Header row' }))
259
+ await frame()
260
+ await act(async () => user.hover(screen.getByText('B')))
261
+ await press(user, screen.getByRole('button', { name: 'Row menu' }))
262
+ await user.click(screen.getByRole('menuitem', { name: 'Delete' }))
263
+ await frame()
264
+ expect(shape(e)).toEqual(['a1|b1|c1', 'a2|b2|c2'])
265
+ })
266
+
267
+ it('switches the header row from any cell of the table, and only on the first row’s menu', async () => {
268
+ const e = editor()
269
+ const user = await mount(e)
270
+ await act(async () => user.hover(screen.getByText('b2')))
271
+ await press(user, screen.getByRole('button', { name: 'Row menu' }))
272
+ expect(screen.queryByRole('menuitem', { name: 'Header row' })).toBeNull()
273
+ expect(toggleTableHeaderRow(e, cellOf('b2'))).toBe(true)
274
+ expect(shape(e)).toEqual(['A|B|C', 'a1|b1|c1', 'a2|b2|c2'])
275
+ })
276
+
239
277
  it('takes the controls away when the document changes without an update — someone else’s edit loaded', async () => {
240
278
  const e = editor()
241
279
  const user = await mount(e)
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useRef, useState, type MouseEvent, type ReactNo
2
2
  import type { Editor } from '@tiptap/core'
3
3
  import { TextSelection, type Command } from '@tiptap/pm/state'
4
4
  import { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, deleteColumn, deleteRow, deleteTable, toggleHeader } from '@tiptap/pm/tables'
5
- import { IconColumnInsertLeft, IconColumnInsertRight, IconGripHorizontal, IconGripVertical, IconPlus, IconRowInsertBottom, IconRowInsertTop, IconTrash } from '@tabler/icons-react'
5
+ import { IconCheck, IconColumnInsertLeft, IconColumnInsertRight, IconGripHorizontal, IconGripVertical, IconPlus, IconRowInsertBottom, IconRowInsertTop, IconTableRow, IconTrash } from '@tabler/icons-react'
6
6
  import { cn } from './cn'
7
7
  import { IconButton } from './IconButton'
8
8
  import { FLOATING_SURFACE_CLASSES } from './looks'
@@ -67,6 +67,15 @@ export function deleteTableRow(editor: Editor, cell: HTMLTableCellElement): bool
67
67
  return inCell(editor, cell, header ? (state, dispatch, view) => deleteRow(state, dispatch) && (!view || toggleHeader('row')(view.state, view.dispatch)) : deleteRow)
68
68
  }
69
69
 
70
+ /**
71
+ * The table's first row becomes its header row, or an ordinary row again:
72
+ * whichever cell of the table `cell` is. A table with no header row has no
73
+ * text spelling, so the agent keeps it as written (SPEC §13.3, "No spelling").
74
+ */
75
+ export function toggleTableHeaderRow(editor: Editor, cell: HTMLTableCellElement): boolean {
76
+ return inCell(editor, cell, toggleHeader('row'))
77
+ }
78
+
70
79
  /** The same for a column: the last one deletes the table. */
71
80
  export function deleteTableColumn(editor: Editor, cell: HTMLTableCellElement): boolean {
72
81
  const row = cell.closest('tr')
@@ -114,7 +123,9 @@ const HANDLE_BOX = cn(FLOATING_SURFACE_CLASSES, 'shadow-none')
114
123
  /**
115
124
  * A table's own controls in an editor, as in Notion: point at a cell and a
116
125
  * handle sits on its row's left edge and on its column's top edge; press one
117
- * for Insert above and below (left and right), Delete, and Delete table. On
126
+ * for Insert above and below (left and right), Delete, and Delete table. The
127
+ * first row's menu also turns the header row on and off (Header row, ticked
128
+ * while it is on); with it off, the first row is an ordinary row. On
118
129
  * the last row a ➕ bar under the table adds a row, and on the last column one
119
130
  * right of it adds a column. Tab in
120
131
  * the last cell adds a row too — that is TableKit's own.
@@ -202,6 +213,18 @@ export function EditorTableControls({ editor, children, className }: EditorTable
202
213
  </IconButton>
203
214
  }
204
215
  >
216
+ {/* The header row is switched where it lives: on the first row's menu, ticked while that row is the header. */}
217
+ {shown.row.rowIndex === 0 && (
218
+ <>
219
+ <MenuItem
220
+ label="Header row"
221
+ leading={<IconTableRow {...ICON} />}
222
+ trailing={isHeaderRow(shown.row) ? <IconCheck {...ICON} aria-hidden /> : undefined}
223
+ onClick={run(() => toggleTableHeaderRow(editor, shown.cell))}
224
+ />
225
+ <MenuSeparator />
226
+ </>
227
+ )}
205
228
  {/* Nothing goes above a header row: it is the table's first row, and a header anywhere else is no header (RichText, the agent's text). */}
206
229
  {!isHeaderRow(shown.row) && <MenuItem label="Insert above" leading={<IconRowInsertTop {...ICON} />} onClick={run(() => inCell(editor, shown.cell, addRowBefore))} />}
207
230
  <MenuItem label="Insert below" leading={<IconRowInsertBottom {...ICON} />} onClick={run(() => inCell(editor, shown.cell, addRowAfter))} />
package/src/editor.ts CHANGED
@@ -53,7 +53,7 @@ export {
53
53
  type ListKind,
54
54
  type QuoteKind,
55
55
  } from './EditorBlockHandle'
56
- export { EditorTableControls, appendTableRow, appendTableColumn, deleteTableRow, deleteTableColumn, type EditorTableControlsProps } from './EditorTableControls'
56
+ export { EditorTableControls, appendTableRow, appendTableColumn, deleteTableRow, deleteTableColumn, toggleTableHeaderRow, type EditorTableControlsProps } from './EditorTableControls'
57
57
  export {
58
58
  PersonMention,
59
59
  UrgentPersonMention,
package/src/linked.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * widgets look nothing up, and keep nothing but what a reader does to them.
7
7
  *
8
8
  * The shape follows the prototype Miky approved (Widgets 2, 15 Oct; why:
9
- * https://github.com/estiva-app/estiva-docs/blob/main/decisions/where-a-link-sits-and-which-file-gets-the-card.md).
9
+ * https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-link-on-words-counts-toward-the-card.md).
10
10
  */
11
11
  import type { ThingKind } from './KindIcon'
12
12
 
@@ -48,20 +48,20 @@ describe('the registry builds', () => {
48
48
  expect(registry.entries.map((one) => one.name).sort()).toEqual(values.map((one) => one.name).sort())
49
49
  })
50
50
 
51
- it('counts 203 names over 95 files: 138 components, 62 helpers and 3 hooks (EntryShell, the screen while nobody is signed in, moved from Peek (AUT-3), on 17 October; CommentBox with commentBoxRows, and ReactionRow with AddReactionButton and whoReacted, the shared comment box and reaction row (COMM-2), on 17 October; the link widgets — LinkChip, LinkRow, LinkCard, CardUnder, PartCard, LinkPreview and their parts, with useCanHover, chosenOf, loadingShapeOf and unavailableMemory — from the Widgets 2 prototype, on 16 October; InlineText, a title or the line under it edited where it stands (SUM-4), on 16 October; ComposeBox with ComposeKeys and its classes, CommentHighlights with its five helpers, and keepSelection and releaseSelection, from the Leaf prototype (LEAF-4), on 16 October;NavTree, NavTreeSection, the composer triggers and UnreadDot joined on 2 October; BlockHandle and EditorBlockHandle (RIC-18) on 2 October, moveBlock and blockDropCursor, the drop in the gutter, on 5 October, MembersPill and MembersDialog, moved from Peek (SHI-31), on 6 October, ShowMore on 7 October, AppProvider on 8 October, and KindIcon, thingKindOf and PastedImages with its two helpers, moved from Peek, on 8 October; CodeBlockColours, the coloured code block of the editor, on 9 October; Checklist, Callout, isChecklistTick and calloutLook (RIC-19) on 13 October; EditorTableControls and its four actions (RIC-21) on 13 October; ReferenceCards, useReferenceCards and its three helpers, the card a chip in a document asks for, on 14 October; LinkChips and its two helpers, a URL in a document read as its chip, on 14 October; ReferenceMenu, ReferenceMenuView and three helpers, the menu of a chip while writing, on 14 October; PastedMarkdown, markdown pasted as the blocks it spells (LEAF-10), on 15 October; turnIntoRows, turnListInto and turnQuoteInto, the block menu’s Turn into for a list and a quote (LEAF-11), on 15 October)', () => {
51
+ it('counts 204 names over 95 files: 138 components, 63 helpers and 3 hooks (toggleTableHeaderRow, a table’s header row on and off (LEAF-12), on 19 October;EntryShell, the screen while nobody is signed in, moved from Peek (AUT-3), on 17 October; CommentBox with commentBoxRows, and ReactionRow with AddReactionButton and whoReacted, the shared comment box and reaction row (COMM-2), on 17 October; the link widgets — LinkChip, LinkRow, LinkCard, CardUnder, PartCard, LinkPreview and their parts, with useCanHover, chosenOf, loadingShapeOf and unavailableMemory — from the Widgets 2 prototype, on 16 October; InlineText, a title or the line under it edited where it stands (SUM-4), on 16 October; ComposeBox with ComposeKeys and its classes, CommentHighlights with its five helpers, and keepSelection and releaseSelection, from the Leaf prototype (LEAF-4), on 16 October;NavTree, NavTreeSection, the composer triggers and UnreadDot joined on 2 October; BlockHandle and EditorBlockHandle (RIC-18) on 2 October, moveBlock and blockDropCursor, the drop in the gutter, on 5 October, MembersPill and MembersDialog, moved from Peek (SHI-31), on 6 October, ShowMore on 7 October, AppProvider on 8 October, and KindIcon, thingKindOf and PastedImages with its two helpers, moved from Peek, on 8 October; CodeBlockColours, the coloured code block of the editor, on 9 October; Checklist, Callout, isChecklistTick and calloutLook (RIC-19) on 13 October; EditorTableControls and its four actions (RIC-21) on 13 October; ReferenceCards, useReferenceCards and its three helpers, the card a chip in a document asks for, on 14 October; LinkChips and its two helpers, a URL in a document read as its chip, on 14 October; ReferenceMenu, ReferenceMenuView and three helpers, the menu of a chip while writing, on 14 October; PastedMarkdown, markdown pasted as the blocks it spells (LEAF-10), on 15 October; turnIntoRows, turnListInto and turnQuoteInto, the block menu’s Turn into for a list and a quote (LEAF-11), on 15 October)', () => {
52
52
  // The reconciliation GATES.md §24 explains. If this changes, that changes.
53
53
  // The `EDITOR_EXTENSIONS` count as components by their names; they are
54
54
  // editor extensions, documented on SelectionToolbar's, BlockNodes' and
55
55
  // ComposerTriggers' pages.
56
56
  const kinds = registry.entries.reduce<Record<string, number>>((all, one) => ({ ...all, [one.kind]: (all[one.kind] ?? 0) + 1 }), {})
57
- expect(kinds).toEqual({ component: 138, helper: 62, hook: 3 })
57
+ expect(kinds).toEqual({ component: 138, helper: 63, hook: 3 })
58
58
  expect(new Set(registry.entries.map((one) => one.sourceFile)).size).toBe(95)
59
59
  })
60
60
 
61
61
  it('gives every entry a purpose, from its own page or from the comment above it', () => {
62
62
  expect(registry.entries.filter((one) => one.purpose.trim() === '')).toEqual([])
63
63
  expect(registry.entries.filter((one) => one.purposeFrom === 'page').length).toBe(89)
64
- expect(registry.entries.filter((one) => one.purposeFrom === 'comment').length).toBe(114)
64
+ expect(registry.entries.filter((one) => one.purposeFrom === 'comment').length).toBe(115)
65
65
  })
66
66
 
67
67
  it('takes a name with a page of its own from the page, and a name without one from the code', () => {