@quitecustard/payload 0.2.1 → 0.2.2

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
@@ -34,6 +34,8 @@ shows on hover — this page is the map, not the reference.
34
34
  - `published-where` — the published clause, stated once so a bypassing read and the access rule
35
35
  cannot drift apart
36
36
  - `collection-versions` — `draftVersions(maxPerDoc?)`: the autosave + schedulePublish shape
37
+ - `lexical-plain-text` — `lexicalPlainText` / `lexicalNodeText`: a rich text value as plain text,
38
+ one block per line, for search indexes and excerpts
37
39
 
38
40
  ### `access/`
39
41
 
@@ -89,6 +91,9 @@ Postgres only, and the only folder needing the `@payloadcms/drizzle` + `drizzle-
89
91
  - `after-response` — defer non-critical work past the response, falling back to inline outside a request
90
92
  - `run-queued-jobs` — drains the Payload job queue, which nothing else does
91
93
  - `unique-slug`, `unique-username` — collision-free values, each candidate checked exactly
94
+ - `accent-colour-hook` — `accentColourHook({field, source, extract})`: an afterChange hook that
95
+ keeps a colour field in step with the document's picture, deferred past the response. The decode
96
+ is the caller's `extract`.
92
97
 
93
98
  `src/internal/` holds implementation detail and is not importable: `"./internal/*": null` sits ahead
94
99
  of the wildcard in `exports`.
@@ -163,7 +168,8 @@ replacing it, so registering both on one table is safe.
163
168
  directly. What they can't run on is SQLite or Mongo: the raw SQL uses `pg_constraint`,
164
169
  `timestamptz` and data-modifying CTEs. No module outside `db/` imports drizzle at all, so the
165
170
  other five folders work on any adapter.
166
- - `fields/seo-tab` assumes `@payloadcms/plugin-seo`, and `operations/after-response` assumes `next`.
167
- Those two are the only modules touching either peer.
171
+ - `fields/seo-tab` assumes `@payloadcms/plugin-seo`, and `operations/after-response` assumes `next`,
172
+ as does `operations/accent-colour-hook`, which defers through it. Those are the only modules
173
+ touching either peer.
168
174
 
169
175
  MIT licensed. Source: [custard-kit](https://github.com/QuiteCustard/custard-kit).
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The plain text of one serialised Lexical node and everything beneath it.
3
+ *
4
+ * Blocks come out one per line, a table row as its cells joined by `" | "`, a list item with a
5
+ * leading `"- "`, and a line break as `"\n"`. Formatting, link targets and block or upload nodes
6
+ * (which carry no `children`) contribute nothing. Reads the node structurally, so it takes whatever
7
+ * a rich text field hands back and returns `''` for anything that is not a node.
8
+ */
9
+ export declare const lexicalNodeText: (node: unknown) => string;
10
+ /**
11
+ * The plain text of a rich text field's value (the editor state, `{ root }`), for search indexes,
12
+ * excerpts and anywhere else markup cannot go. An empty or missing value reads as `''`.
13
+ *
14
+ * ```ts
15
+ * lexicalPlainText(post.content) // "First paragraph\n- a list item\nName | Value"
16
+ * ```
17
+ *
18
+ * See `lexicalNodeText` for how each node type is written out.
19
+ */
20
+ export declare const lexicalPlainText: (value: unknown) => string;
@@ -0,0 +1,44 @@
1
+ import { isRecord } from '@quitecustard/core/utils/is-record';
2
+ const childrenOf = (node) => Array.isArray(node.children) ? node.children : [];
3
+ // Containers whose children are blocks of their own. Every other node (paragraph, heading, link,
4
+ // table cell) holds inline content and reads as one run.
5
+ const blockContainers = new Set(['root', 'list', 'table']);
6
+ const joinFilled = (parts, separator) => parts
7
+ .map((part) => part.trim())
8
+ .filter(Boolean)
9
+ .join(separator);
10
+ /**
11
+ * The plain text of one serialised Lexical node and everything beneath it.
12
+ *
13
+ * Blocks come out one per line, a table row as its cells joined by `" | "`, a list item with a
14
+ * leading `"- "`, and a line break as `"\n"`. Formatting, link targets and block or upload nodes
15
+ * (which carry no `children`) contribute nothing. Reads the node structurally, so it takes whatever
16
+ * a rich text field hands back and returns `''` for anything that is not a node.
17
+ */
18
+ export const lexicalNodeText = (node) => {
19
+ if (!isRecord(node))
20
+ return '';
21
+ if (node.type === 'linebreak')
22
+ return '\n';
23
+ if (typeof node.text === 'string')
24
+ return node.text;
25
+ const parts = childrenOf(node).map(lexicalNodeText);
26
+ if (node.type === 'tablerow')
27
+ return joinFilled(parts, ' | ');
28
+ if (node.type === 'listitem')
29
+ return `- ${parts.join('').trim()}`;
30
+ if (typeof node.type === 'string' && blockContainers.has(node.type))
31
+ return joinFilled(parts, '\n');
32
+ return parts.join('');
33
+ };
34
+ /**
35
+ * The plain text of a rich text field's value (the editor state, `{ root }`), for search indexes,
36
+ * excerpts and anywhere else markup cannot go. An empty or missing value reads as `''`.
37
+ *
38
+ * ```ts
39
+ * lexicalPlainText(post.content) // "First paragraph\n- a list item\nName | Value"
40
+ * ```
41
+ *
42
+ * See `lexicalNodeText` for how each node type is written out.
43
+ */
44
+ export const lexicalPlainText = (value) => isRecord(value) ? lexicalNodeText(value.root) : '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quitecustard/payload",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Payload v3 helpers: relation narrowing, transactions, autosave-vs-unpublish detection, sync locks, unique slugs and usernames",
5
5
  "keywords": [
6
6
  "payload",