nwl-components 1.4.1 → 1.5.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.
package/README.md CHANGED
@@ -3,6 +3,93 @@
3
3
  This project is a library of components to be used on the frontend of the Neuroweblab projects.
4
4
  They are similar in style and behaviour to existing projects.
5
5
 
6
+ ## Scope
7
+
8
+ nwl-components holds only **generic** components, which any NAAT app can use and
9
+ customise through props, slots and the `config` object: the project-management pages,
10
+ the project-page shell, and generic building blocks. Nothing tied to one app
11
+ (BrainBox or microdraw) and none of a viewer's own logic belongs here; that stays in
12
+ each app.
13
+
14
+ Exports by group:
15
+
16
+ | Group | Exports |
17
+ |---|---|
18
+ | Pages | `UserPage`, `NewProjectPage`, `SettingsPage`, `ProjectPage` (the project-page shell: header, resizable left/right split, fullscreen; the app fills the slots) |
19
+ | Layout | `Wrapper`, `Header`, `Nav`, `Footer` |
20
+ | Settings | `Settings`, `ProjectInfo`, `Files`, `Collaborators`, `Annotations`, `Access`, `ImportFilesDialog`, `PureFiles`, `PureCollaborators`, `PureAnnotations` |
21
+ | Common widgets | `Button`, `Checkbox`, `Select`, `TextInput`, `TextArea`, `Autocomplete`, `Table`, `SortableTh` and `useSortable` (sortable table columns), `Tabs`, `Tab` |
22
+ | Building blocks | `Editor` (floating/dockable tool window with content and tools slots), `Row`, `Col`, `ButtonsGroup`, `RangeSlider`, `AdjustSettings`, `Chat`, `ScriptConsole`, `TextAnnotations`, `VolumeAnnotations`, `AnnotationCell`, `OntologySelector` (label-set selector) |
23
+
24
+ ### To clean up
25
+
26
+ App-specific content that should become neutral later (no component is deprecated):
27
+
28
+ - the BrainBox stories `src/components/pages/BrainboxProjectPage.stories.js` and
29
+ `src/components/project/BrainboxProject.stories.js`;
30
+ - the story data `TextAnnotations.brainbox.fixtures.json` and
31
+ `TextAnnotations.microdraw.fixtures.json`;
32
+ - the BrainBox settings (site name, logo, URLs, label sets) in `.storybook/preview.js`;
33
+ - `ScriptConsole`: it loads codeflask and consolita from fixed CDN URLs, and its CSS
34
+ targets the global id `#logScript`; both should become configurable;
35
+ - `Chat` renders messages as raw HTML (`v-html`): they must be sanitised before an
36
+ app uses it.
37
+
38
+ ## Sortable tables
39
+
40
+ `useSortable(rows, columns)` keeps a table's sort state; `SortableTh` is a header cell
41
+ that sorts by its column when clicked (or with Enter/Space). Every sortable header always
42
+ shows an icon (a grey up/down "sort" icon when the column is not the sort column, one
43
+ up or down arrow when it is; inline SVG from Tabler Icons, MIT) in a box of fixed size,
44
+ so nothing moves when you click; `aria-sort` is set on the
45
+ `<th>`. First click sorts ascending, a second click reverses, another column sorts
46
+ ascending; missing values (`null`, `undefined`, `''`, not a number/date) are always last.
47
+ The `rows` array is never mutated. Headers written as plain `<th>` look as before.
48
+
49
+ ```js
50
+ import { SortableTh, Table, useSortable } from 'nwl-components';
51
+
52
+ const PageContents = {
53
+ template: '#template',
54
+ setup () {
55
+ const projects = ref([]);
56
+ const sort = useSortable(projects, {
57
+ // column name: { key: row property (or row => value), type: 'string' (default) | 'number' | 'date' }
58
+ Name: { key: 'project' },
59
+ Files: { key: 'numFiles', type: 'number' },
60
+ 'Last modified': { key: 'modified', type: 'date' }
61
+ });
62
+
63
+ return { projects, sort, sortedProjects: sort.sortedRows };
64
+ }
65
+ };
66
+ const app = createApp(PageContents);
67
+ app.component('Table', Table);
68
+ app.component('SortableTh', SortableTh);
69
+ ```
70
+
71
+ ```html
72
+ <script type="text/html" id="template">
73
+ <Table>
74
+ <thead><tr>
75
+ <sortable-th :sort="sort" column="Name">Name</sortable-th>
76
+ <sortable-th :sort="sort" column="Files">Files</sortable-th>
77
+ <sortable-th :sort="sort" column="Last modified">Last modified</sortable-th>
78
+ </tr></thead>
79
+ <tbody>
80
+ <tr v-for="project in sortedProjects">...</tr>
81
+ </tbody>
82
+ </Table>
83
+ </script>
84
+ ```
85
+
86
+ In a template parsed by the browser (written directly in the page, not in a
87
+ `<script type="text/html">`), write `<th is="vue:sortable-th" ...>` instead, so the
88
+ browser keeps it inside the table. `useSortable` also returns `sortBy(column)`,
89
+ `direction(column)` (`'ascending'`, `'descending'` or `'none'`), and the refs
90
+ `sortColumn` and `sortAscending`; a third argument `{ column, ascending }` sets an initial
91
+ sort. Story: `Common/Table` (`npm run storybook`). Since 1.5.0.
92
+
6
93
  ## Single File Components
7
94
 
8
95
  This project makes use of Vue SFCs: _Single File Components_, that have the `.vue` extension.