@webround/editor 0.3.11 → 0.3.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.
@@ -6,6 +6,8 @@ export interface DomNode {
6
6
  tag: string;
7
7
  attrs: Record<string, string>;
8
8
  text: string;
9
+ /** The element's own `id` (what `aria-labelledby` points at), not its `data-wr-id`. */
10
+ htmlId?: string;
9
11
  /** A form field that has a `<label>`: it sits inside one, or one points at it (`for`). */
10
12
  labelled?: true;
11
13
  children: DomNode[];
@@ -23,6 +23,7 @@ export function serializeDom(root) {
23
23
  const labelled = fields.includes(tag) && (el.closest?.('label') != null || (fieldId !== null && pointedAt.has(fieldId)));
24
24
  return {
25
25
  ...(id ? { id } : {}),
26
+ ...(fieldId ? { htmlId: fieldId } : {}),
26
27
  wrType: el.getAttribute('data-wr-type'),
27
28
  tag,
28
29
  attrs,
@@ -44,7 +45,11 @@ function toCheckNode(node) {
44
45
  }
45
46
  /** The tree a rule sees, from what `serializeDom` read (wherever it ran). */
46
47
  export function checkPageFromSerialized(name, nodes) {
47
- return { name, source: 'dom', nodes: nodes.map(toCheckNode) };
48
+ const elementIds = [];
49
+ const collect = (list) => list.forEach(node => { if (node.htmlId)
50
+ elementIds.push(node.htmlId); collect(node.children); });
51
+ collect(nodes);
52
+ return { name, source: 'dom', nodes: nodes.map(toCheckNode), elementIds };
48
53
  }
49
54
  export function checkPageFromDom(name, root) {
50
55
  return checkPageFromSerialized(name, serializeDom(root));
@@ -222,7 +222,8 @@ export const RULES = [
222
222
  if (n.kind !== 'input')
223
223
  continue;
224
224
  const written = Object.values(n.values?.label ?? {}).some(text => text.trim() !== '');
225
- if (!written && !n.attrs['aria-label']?.trim())
225
+ // A drawn page has no JSON: there the label is the `<label>` the field sits in or the one that points at it (`insideLabel`, as `form-label` reads it)
226
+ if (!written && !n.attrs['aria-label']?.trim() && !n.insideLabel)
226
227
  report(n, 'A form field has no label: a placeholder is not one, and the owner reads this name in the email.');
227
228
  }
228
229
  },
@@ -304,7 +305,8 @@ export const RULES = [
304
305
  name: 'aria-reference',
305
306
  severity: 'warning',
306
307
  run(page, report) {
307
- const ids = new Set(everyNode(page).map(n => n.id).filter((id) => !!id));
308
+ // The Wr elements' ids, and (a drawn page) every `id` of the HTML: a plain element can be pointed at too
309
+ const ids = new Set([...everyNode(page).map(n => n.id).filter((id) => !!id), ...(page.elementIds ?? [])]);
308
310
  for (const n of everyNode(page)) {
309
311
  for (const attribute of ['aria-labelledby', 'aria-describedby']) {
310
312
  const value = n.attrs[attribute];
@@ -53,6 +53,8 @@ export interface CheckPage {
53
53
  project?: CheckProject;
54
54
  /** The ids of the form fields some `<label htmlFor>` of the code points at. */
55
55
  labelledIds?: string[];
56
+ /** Every `id` the HTML of the page has (only the DOM producer knows them: in the code a plain element's id can be computed). */
57
+ elementIds?: string[];
56
58
  /** What the page tells search engines (only the code producer knows it: the DOM has no `config`): text by language key, `default` first. */
57
59
  seo?: {
58
60
  title: Record<string, string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webround/editor",
3
- "version": "0.3.11",
3
+ "version": "0.3.13",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -75,7 +75,7 @@
75
75
  "@lexical/selection": "^0.51.0",
76
76
  "@lexical/utils": "^0.51.0",
77
77
  "@monaco-editor/react": "^4.7.0",
78
- "@webround/core": "^0.3.11",
78
+ "@webround/core": "^0.3.13",
79
79
  "highlight.js": "^11.12.0",
80
80
  "hls.js": "^1.5.0",
81
81
  "lexical": "^0.51.0",