@itrocks/handbook 0.0.11 → 0.0.13

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.
@@ -11,6 +11,7 @@ A package is a published `@itrocks/*` module; `HasPlugins` and `Plugin<T>` refer
11
11
  - Request, route, action, response or workflow: [actions and routes](requests-actions-and-routes.md).
12
12
  - Conversion or view metadata: [transformations and views](transformations-and-views.md).
13
13
  - Template, include, fragment or target: [HTML templates](html-templates-and-targets.md).
14
+ - Business view, object form or structured modal: [structured views](../../framework-usage/structured-views.md).
14
15
  - DOM activation, navigation or browser plugin: [browser components](browser-components.md).
15
16
  - Selector, UI state, stylesheet or asset: [SCSS and assets](scss-and-assets.md).
16
17
  - Storage, relations, schema or database adapter: [persistence](persistence-and-schema.md).
@@ -4,7 +4,9 @@ Register independent DOM enhancements by selector with `build()`; use `HasPlugin
4
4
  extensions around a stable host API.
5
5
 
6
6
  `build()` handles matching elements in `document.body` and later insertions; it can also register prioritised listeners.
7
- Put registrations in an explicit browser build module imported by the browser entry or a template dependency.
7
+ Put template-specific registrations in an explicit browser build module declared in the owning template's head.
8
+ Follow [HTML templates and asset loading](html-templates-and-targets.md#fragments-and-assets);
9
+ reserve browser-entry imports for shared infrastructure or necessary host context detection.
8
10
  Use semantic selectors and guard repeated activation when components do not already do so.
9
11
  Load heavy or optional behaviour inside the callback. Browser subpath imports use explicit `.js` extensions.
10
12
  Keep structure in HTML, behaviour in TypeScript and visual state in SCSS, sharing documented classes and attributes.
@@ -3,6 +3,22 @@
3
3
  Render valid standalone HTML and identify the fragment for asynchronous navigation.
4
4
  The action prepares a small named data context and owns business decisions.
5
5
 
6
+ For the structure of new object views, lists, forms and structured modal content, follow
7
+ [structured business views](../../framework-usage/structured-views.md).
8
+
9
+ ## Authoring and validation
10
+
11
+ Author page and fragment markup in HTML templates. Server actions prepare data; browser code enhances the rendered DOM.
12
+ Do not assemble view markup in TypeScript strings or construct entire views with DOM creation calls.
13
+
14
+ The rendered standalone document and the DOM after fragment insertion must pass the
15
+ [W3C Nu HTML Checker](https://validator.w3.org/nu/). Validate rendered output, with template expressions resolved,
16
+ including conditional branches and representative dynamic values. Check source templates for valid HTML structure too.
17
+ Use standard HTML and permitted ARIA attributes; application-specific metadata belongs in `data-*` attributes.
18
+ Do not invent bare attributes or rely on the browser silently repairing invalid nesting.
19
+ Context-dependent composite fragments can be enclosed in a `<template>` outside `BEGIN`/`END` to keep their standalone
20
+ document valid without inserting that wrapper into the live DOM.
21
+
6
22
  ## Expressions
7
23
 
8
24
  - `{property.path}` reads a path; a non-class function is called on its owner.
@@ -28,6 +44,14 @@ Keep language, title and required assets in the full document. Client navigation
28
44
  head styles/scripts without duplicating URLs. Includes retain asset dependencies; relative links become application
29
45
  paths, with `node_modules/@itrocks` served as `/@itrocks/...` and other dependencies as `/lib/...`.
30
46
 
47
+ Declare template-specific CSS with `<link rel="stylesheet">` and JavaScript with `<script type="module" src="...">`
48
+ in that template's `<head>`, outside `BEGIN`/`END` when appropriate. These fragment markers do not prevent the framework
49
+ from processing the head: `xtarget` loads the declared assets when the HTML is first used and avoids duplicates.
50
+ Prefer these declarations over application-wide imports or script-driven asset loading.
51
+ Keep only shared application infrastructure and necessary context detection in the application entry.
52
+ When no HTML template owns an optional integration, load it at the relevant context and document why it is needed.
53
+ Framework adapters belong to the framework; importing a reusable package must not implicitly bind it to the framework.
54
+
31
55
  Match block delimiters exactly. Keep selectors, attributes and action names consistent with browser and SCSS contracts.
32
56
  Verify direct navigation and fragment insertion.
33
57
 
@@ -6,6 +6,9 @@ then the owning package's README for the feature being used.
6
6
  Read only the conventions needed by the task:
7
7
 
8
8
  - Application source: [coding conventions](coding-conventions.md).
9
+ - New business views, object forms and structured modal content: [structured business views](structured-views.md).
10
+ - HTML syntax, fragments and front-end assets:
11
+ [templates and targets](../framework-changes/architecture/html-templates-and-targets.md).
9
12
  - Markdown: [documentation conventions](../framework-changes/documentation/markdown.md).
10
13
  - Framework extension or integration: select the relevant [architecture
11
14
  guide](../framework-changes/architecture/README.md).
@@ -17,6 +17,7 @@ proportionate to the task; choose the KISS (Keep It Simple And Stupid) solution
17
17
  Prefer less code when correctness and readability are equivalent.
18
18
  - Apply SOLID through clear responsibilities, existing extension points, substitutable contracts, focused interfaces
19
19
  and appropriate dependency boundaries. Each separation must serve the current behaviour and simplify maintenance.
20
+ - When a condition encloses the rest of a loop body, prefer an inverted `continue` guard to another indentation level.
20
21
 
21
22
  When fixing a bug, reconsider the model before adding another condition or special case. For example, column drag
22
23
  placement can remember the hovered column and react to changes of column and movement direction, instead of repeatedly
@@ -29,13 +30,48 @@ inferring placement from position thresholds.
29
30
  such as YAML.
30
31
  - Omit semicolons; use single quotes and template literals for interpolation or multiline text.
31
32
  - Space postfix operators: `index ++`, `index --`.
32
- - Align `from`, `=`, `:` and values in adjacent related lines where the limit allows.
33
+ - Align `from`, `=`, `:`, `??` and values in adjacent related lines where the limit allows. Include mixed `const`/`let`
34
+ declarations, assignments and constructor parameters in the same alignment group; keep a space before each operator.
35
+ - Declare one variable per statement. Separate preparation, object configuration and the final call or return with
36
+ blank lines when they form distinct steps.
33
37
  - Put `{` on the next line for classes, interfaces, functions, methods and constructors.
34
38
  - Keep `{` on the control line for conditions, loops, `switch`, `try`, `catch` and `finally`.
35
39
  - Put `else`, `catch` and `finally` on a new line after the preceding `}`.
36
- - Braces may be omitted for a single-line control body; multiline bodies require them.
40
+ - Use braces and a separate body line for conditional returns. Otherwise prefer braces; very short flow guards such
41
+ as `if (condition) continue` may remain on one line.
42
+ - For empty constructors, keep `{}` on the closing parameter line, including after a multiline parameter list.
37
43
  - Leave a blank line after a non-empty class opening brace and before its closing brace.
38
44
 
45
+ ## Wrapped expressions
46
+
47
+ The 120-column limit is a maximum, not a target. Break dense expressions earlier when their structure is clearer.
48
+
49
+ - For multiline control conditions, put `if (` on its own line, indent the condition once, and align `) {` with `if`.
50
+ Put leading `&&` and `||` on continuation lines at the same condition indentation.
51
+ - Prefer a direct ternary return when choosing between two values. Keep only simple ternaries on one line; otherwise
52
+ put `?` and `:` on separate lines, one level below the return or assignment. Parenthesise concatenation branches.
53
+ - For a ternary chain, align successive conditions and their results instead of increasing indentation for each case.
54
+ - In multiline array and object literals, put one entry per line, including spreads and shorthand properties.
55
+ Break nested calls at argument boundaries and close each enclosing call at its corresponding indentation level.
56
+
57
+ ```ts
58
+ if (
59
+ !path || !path.startsWith('/') || path.startsWith('//')
60
+ || (new URL(path, origin).pathname !== path)
61
+ ) {
62
+ return ''
63
+ }
64
+
65
+ return (!prefix || path.startsWith(prefix + '/'))
66
+ ? path
67
+ : (prefix + path)
68
+
69
+ result =
70
+ isFunction(value) ? value(options) :
71
+ isType(value) ? new value(options) :
72
+ value
73
+ ```
74
+
39
75
  ## Signatures
40
76
 
41
77
  Choose the first layout below that fits 120 columns. Apply the same parameter and return-type breaks to methods,
@@ -71,7 +107,8 @@ function calculate(
71
107
 
72
108
  Sort homogeneous sequences alphabetically by stable name wherever order has no semantic significance.
73
109
  This includes configuration, documentation, object/array entries, declarations, members, imports, exports,
74
- parameters and test cases. Separate coherent kinds where useful, then sort within each group.
110
+ parameters and test cases. Preserve existing responsibility groups, placing new members in their matching group,
111
+ then sort within each group. Use short sentence-case section comments, preserving acronym capitals such as HTML and URL.
75
112
  Preserve required initialisation, side effects, fallback, precedence, lifecycle, overload, protocol and runtime order;
76
113
  comment non-obvious constraints.
77
114
 
@@ -0,0 +1,150 @@
1
+ # Structured business views
2
+
3
+ Use an `<article>` for a structured view of business objects or an action on them, wherever it appears:
4
+ in `main`, a modal, a form or another view. Keep the same header, content and optional footer structure.
5
+ Notifications, navigation, inline references and other compact supporting elements may use smaller markup.
6
+
7
+ The standard edit view uses `<form>` as its article-equivalent root, with exactly the same structure.
8
+ Use this form root when the whole view is one submission; use articles for structured views within a larger form.
9
+ Never nest forms. A list uses an article containing its search/selection form.
10
+
11
+ Follow [templates and targets](../framework-changes/architecture/html-templates-and-targets.md) for expressions,
12
+ translation, URLs, fragment syntax, assets and HTML validation.
13
+
14
+ ## Structure and identity
15
+
16
+ - Put the view directly inside its destination. In `main`, use `main > article` or `main > form`;
17
+ an extra wrapper prevents the standard panel layout from matching.
18
+ - Put `<header>` first, containing `<h2>` and, when needed, `<ul class="general actions">`.
19
+ Keep the heading even when the application hides it: the framework uses top-level headings for the breadcrumb.
20
+ Keep the document `<title>` consistent with it.
21
+ - Use one direct child for the content: a property list, table container, form or wrapper around several sections.
22
+ An optional direct `<footer>` follows it. Do not put several content siblings beside the header/footer:
23
+ `article.css` assigns them all to the same grid area, causing overlap.
24
+ - Put `data-action`, `data-class` and `data-route` on the article or equivalent form root.
25
+ They identify the view's operation, business class and addressed business route, respectively.
26
+ `data-class` is the reflected class name, not its display label. `data-route` excludes the action suffix;
27
+ use the object's route for an object view and the type's route for a collection.
28
+ Add `data-id="{?id}"` for an identified object; omit it for a new object or collection.
29
+ - Keep action names consistent with routes, CSS and action definitions. Use additional `data-*` attributes only
30
+ when the owning component consumes them.
31
+
32
+ `ux-core/css/article.css` supplies the header/content/footer grid and content scrolling for `main > article` and
33
+ `main > form`. Its grid selectors do not match modal or nested views. Preserve the structure there and use the
34
+ owning component's layout; provide scoped CSS if it needs equivalent sizing or scrolling.
35
+ Do not insert another `<main>` into a modal to obtain those styles.
36
+
37
+ ## Properties, actions and forms
38
+
39
+ The action passes the business object or a small named view model to `htmlTemplateResponse`.
40
+ For an object context, use `{%name}`, `{@route}` and `<!--%orderedProperties-->`.
41
+ For a view model, enter its object block before using object reflection; collections use their explicit type/columns.
42
+ `{.actions}` and `{.action}` access the enclosing action context from the root object;
43
+ each loop changes the current context. Keep business decisions in the action.
44
+
45
+ - Object properties: `<ul class="object properties">`, with one `<li data-property="{name}">` per property.
46
+ For display, use `<label>{@display}</label>{outputMandatoryContainer}`.
47
+ For editing, use `{edit}`, which supplies the field markup and labels through the configured transformers.
48
+ For selected fields, use reflected properties such as `{%property.name.edit}` rather than rebuilding widgets.
49
+ - Actions: one `<li class="{action}">{{template}}</li>` per configured action in `ul.general.actions`.
50
+ Reuse action templates, captions, destinations and icon styles. Put selection actions in `ul.selection.actions`
51
+ within the selection form, normally in its footer. Buttons that do not submit must have `type="button"`.
52
+ - Forms: declare `action="app://(...)"`, `method="post"` for a mutation, and the response `target`.
53
+ Use `target="main"` for a view response and `target="#notifications:prepend"` for notification feedback.
54
+ A submit control may override these with `formaction` and `formtarget`.
55
+ Follow standard edit forms with `autocomplete="off"` and conditional `enctype="multipart/form-data"`
56
+ when file properties are present. Add `data-allow-new` only when related-object creation is intended.
57
+ - Lists: preserve the standard search/selection form, `table.objects`, column/filter metadata, feed include and
58
+ selection controls when using the list components. Start from `list/src/list.html` and `feed.html`;
59
+ copying just the visible table loses their browser contracts.
60
+
61
+ ## Template for main
62
+
63
+ This object-view example is located at `app/customer/output.html`; adjust asset paths to the template's location.
64
+ Declare the styles the view uses, including `app.css`, `article.css`, action-bar styles and property/action styles.
65
+ Declare any view-specific browser build module in the head, as described in
66
+ [browser components](../framework-changes/architecture/browser-components.md).
67
+
68
+ ```html
69
+ <!DOCTYPE html>
70
+ <html lang="en">
71
+ <head>
72
+ <meta charset="utf-8">
73
+ <link href="../../node_modules/@itrocks/ux-core/css/app.css" rel="stylesheet">
74
+ <link href="../../node_modules/@itrocks/ux-core/css/article.css" rel="stylesheet">
75
+ <link href="../../node_modules/@itrocks/action-bar/action.css" rel="stylesheet">
76
+ <link href="../../node_modules/@itrocks/output/css/output.css" rel="stylesheet">
77
+ <title>{@output.ucFirst}</title>
78
+ </head>
79
+ <body>
80
+ <main>
81
+ <!--BEGIN-->
82
+ <!--#main-->
83
+ <article data-action="output" data-class="{%name}" data-id="{?id}" data-route="{@route}">
84
+ <header>
85
+ <h2>{@output.ucFirst}</h2>
86
+ <ul class="general actions">
87
+ <li class="close"><a href="app://(@typeRoute)/list" target="main">Close</a></li>
88
+ <!--.actions-->
89
+ <li class="{action}">{{template}}</li>
90
+ <!--end-->
91
+ </ul>
92
+ </header>
93
+ <ul class="object properties">
94
+ <!--%orderedProperties-->
95
+ <li data-property="{name}"><label>{@display}</label>{outputMandatoryContainer}</li>
96
+ <!--end-->
97
+ </ul>
98
+ </article>
99
+ <!--#end-->
100
+ <!--END-->
101
+ </main>
102
+ </body>
103
+ </html>
104
+ ```
105
+
106
+ Keep the document shell and `<main>` outside `BEGIN`/`END`: only the article enters the existing destination.
107
+ The application container owns navigation, breadcrumb, notifications, base URL and import map.
108
+ Use `<!--#main-->` for a response explicitly destined for `main`, as in the standard CRUD views.
109
+ For a view reusable in a modal or another target, omit that target block and its `<!--#end-->`:
110
+ the caller's `target` then chooses the destination. Keep `BEGIN`/`END` around the view in either case.
111
+ A notification response targets `#notifications:prepend` and contains notification items, not another business article.
112
+
113
+ ## Edit variant
114
+
115
+ Keep the preceding document/fragment shell, link `edit/css/edit.css` and `save/css/action.css` as well,
116
+ and replace the article with this form. Set the document title to `{.action.ucFirst} {@output}`.
117
+ This follows the standard edit/new contract; the save response supplies notification feedback.
118
+
119
+ ```html
120
+ <form action="app://(@route)/save" autocomplete="off" method="post" target="#notifications:prepend"
121
+ data-action="edit" data-class="{%name}" data-id="{?id}" data-route="{@route}"
122
+ data-if="{%hasFileProperty}" enctype="multipart/form-data" data-end>
123
+ <header>
124
+ <h2>{.action.ucFirst} {@output}</h2>
125
+ <ul class="general actions">
126
+ <li class="close"><a href="app://(@route)" target="main">Close</a></li>
127
+ <li class="save"><input type="submit" value="Save"></li>
128
+ <!--id?-->
129
+ <!--.actions-->
130
+ <li class="{action}">{{template}}</li>
131
+ <!--end-->
132
+ <!--end-->
133
+ </ul>
134
+ </header>
135
+ <ul class="object properties">
136
+ <!--%orderedProperties-->
137
+ <li data-property="{name}">{edit}</li>
138
+ <!--end-->
139
+ </ul>
140
+ </form>
141
+ ```
142
+
143
+ Check resolved HTML and the inserted DOM using the
144
+ [validation rules](../framework-changes/architecture/html-templates-and-targets.md#authoring-and-validation).
145
+ Verify direct navigation and partial insertion, heading/breadcrumb, content scrolling, action destinations,
146
+ form submission and first-use asset loading. Check the actual modal/nested context when applicable.
147
+
148
+ Reference implementations, relative to `node_modules/@itrocks/`: `output/src/output.html`, `edit/src/edit.html`,
149
+ `list/src/list.html`, `list/src/feed.html`, `save/src/save.html`, `home/src/container.html`,
150
+ `ux-core/css/article.css` and `action/cjs/action.html`.
package/package.json CHANGED
@@ -25,5 +25,5 @@
25
25
  "type": "git",
26
26
  "url": "git+https://github.com/itrocks-ts/handbook.git"
27
27
  },
28
- "version": "0.0.11"
28
+ "version": "0.0.13"
29
29
  }