@haklex/rich-ext-chat 0.4.1 → 0.6.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/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # @haklex/rich-ext-chat
2
+
3
+ Static chat-snapshot blocks for assistant / conversation transcripts. Renders multi-participant message lists with variant-aware bubble styling.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @haklex/rich-ext-chat
9
+ ```
10
+
11
+ ## Peer Dependencies
12
+
13
+ | Package | Version |
14
+ | --------- | --------- |
15
+ | `lexical` | `^0.44.0` |
16
+ | `react` | `>= 19` |
17
+
18
+ ## Usage
19
+
20
+ ### Register nodes
21
+
22
+ Edit (read + write):
23
+
24
+ ```ts
25
+ import { chatEditNodes } from '@haklex/rich-ext-chat/edit';
26
+
27
+ const editorConfig = { nodes: [...chatEditNodes] };
28
+ ```
29
+
30
+ Static / read-only:
31
+
32
+ ```ts
33
+ import { chatNodes } from '@haklex/rich-ext-chat/node';
34
+
35
+ const staticConfig = { nodes: [...chatNodes] };
36
+ ```
37
+
38
+ ### Use renderers
39
+
40
+ ```tsx
41
+ import { ChatEditRenderer } from '@haklex/rich-ext-chat/edit';
42
+ import { ChatRenderer } from '@haklex/rich-ext-chat/renderer';
43
+ ```
44
+
45
+ ### Tree-shake the default renderer
46
+
47
+ ```ts
48
+ import { CHAT_NODE_KEY, chatNodes } from '@haklex/rich-ext-chat/node';
49
+ import type { RichRendererModule } from '@haklex/rich-compose';
50
+
51
+ const lightModule: RichRendererModule = {
52
+ name: 'chat',
53
+ nodes: chatNodes,
54
+ renderers: { [CHAT_NODE_KEY]: MyLightChat },
55
+ };
56
+ ```
57
+
58
+ ### Import styles
59
+
60
+ ```ts
61
+ import '@haklex/rich-ext-chat/style.css';
62
+ ```
63
+
64
+ ## Exports
65
+
66
+ ### Nodes
67
+
68
+ - `ChatNode` -- static (read-only) node
69
+ - `ChatEditNode` -- edit node
70
+ - `$createChatNode()` / `$isChatNode()` -- Lexical helpers
71
+ - `chatNodes` -- array of static nodes for config registration
72
+ - `chatEditNodes` -- array of edit nodes for config registration
73
+
74
+ ### Renderers
75
+
76
+ - `ChatRenderer` -- static renderer
77
+ - `ChatEditRenderer` -- edit renderer with participant management
78
+
79
+ ### Slot Key
80
+
81
+ - `CHAT_NODE_KEY` -- `'Chat'` constant for `RendererConfig` slot lookup
82
+
83
+ ### Types
84
+
85
+ - `ChatMessage`, `ChatParticipant`, `ChatParticipantKind`, `ChatVariant`
86
+ - `ChatRendererProps` (also flowed into `RendererConfig.Chat` via module augmentation)
87
+ - `SerializedChatNode`
88
+
89
+ ## Sub-path Exports
90
+
91
+ | Path | Description |
92
+ | --------------------------------- | --------------------------------------------------------- |
93
+ | `@haklex/rich-ext-chat` | Full exports (node + renderer + edit) |
94
+ | `@haklex/rich-ext-chat/node` | Lightweight node + slot key + types — no default renderer |
95
+ | `@haklex/rich-ext-chat/renderer` | Default `ChatRenderer` (heavy) |
96
+ | `@haklex/rich-ext-chat/edit` | Edit-mode node + `ChatEditRenderer` |
97
+ | `@haklex/rich-ext-chat/static` | Convenience: node + renderer (SSR bundle) |
98
+ | `@haklex/rich-ext-chat/style.css` | Stylesheet |
99
+
100
+ ## Part of Haklex
101
+
102
+ This package is part of the [Haklex](../../README.md) rich editor ecosystem.
103
+
104
+ ## License
105
+
106
+ MIT
@@ -0,0 +1,163 @@
1
+ import { DecoratorNode } from "lexical";
2
+ import { customAlphabet } from "nanoid";
3
+ import { createRendererDecoration } from "@haklex/rich-editor/renderers";
4
+ //#region src/utils.ts
5
+ var idAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
6
+ var makeParticipantId = customAlphabet(idAlphabet, 6);
7
+ var makeMessageId = customAlphabet(idAlphabet, 8);
8
+ function createParticipantId() {
9
+ return `p_${makeParticipantId()}`;
10
+ }
11
+ function createMessageId() {
12
+ return `m_${makeMessageId()}`;
13
+ }
14
+ function createDefaultParticipants(variant) {
15
+ if (variant === "user-agent") return [{
16
+ id: createParticipantId(),
17
+ kind: "user"
18
+ }, {
19
+ id: createParticipantId(),
20
+ kind: "agent"
21
+ }];
22
+ return [{
23
+ id: createParticipantId(),
24
+ kind: "user"
25
+ }, {
26
+ id: createParticipantId(),
27
+ kind: "user"
28
+ }];
29
+ }
30
+ //#endregion
31
+ //#region src/slot.ts
32
+ /**
33
+ * RendererConfig slot key for `@haklex/rich-ext-chat`.
34
+ *
35
+ * Override modules should reference this constant instead of the bare string
36
+ * literal so renames stay searchable across the workspace.
37
+ */
38
+ var CHAT_NODE_KEY = "Chat";
39
+ //#endregion
40
+ //#region \0@oxc-project+runtime@0.127.0/helpers/typeof.js
41
+ function _typeof(o) {
42
+ "@babel/helpers - typeof";
43
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
44
+ return typeof o;
45
+ } : function(o) {
46
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
47
+ }, _typeof(o);
48
+ }
49
+ //#endregion
50
+ //#region \0@oxc-project+runtime@0.127.0/helpers/toPrimitive.js
51
+ function toPrimitive(t, r) {
52
+ if ("object" != _typeof(t) || !t) return t;
53
+ var e = t[Symbol.toPrimitive];
54
+ if (void 0 !== e) {
55
+ var i = e.call(t, r || "default");
56
+ if ("object" != _typeof(i)) return i;
57
+ throw new TypeError("@@toPrimitive must return a primitive value.");
58
+ }
59
+ return ("string" === r ? String : Number)(t);
60
+ }
61
+ //#endregion
62
+ //#region \0@oxc-project+runtime@0.127.0/helpers/toPropertyKey.js
63
+ function toPropertyKey(t) {
64
+ var i = toPrimitive(t, "string");
65
+ return "symbol" == _typeof(i) ? i : i + "";
66
+ }
67
+ //#endregion
68
+ //#region \0@oxc-project+runtime@0.127.0/helpers/defineProperty.js
69
+ function _defineProperty(e, r, t) {
70
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
71
+ value: t,
72
+ enumerable: !0,
73
+ configurable: !0,
74
+ writable: !0
75
+ }) : e[r] = t, e;
76
+ }
77
+ //#endregion
78
+ //#region src/nodes/ChatNode.ts
79
+ var ChatNode = class ChatNode extends DecoratorNode {
80
+ static getType() {
81
+ return "chat";
82
+ }
83
+ static clone(node) {
84
+ return new ChatNode({
85
+ variant: node.__variant,
86
+ participants: node.__participants,
87
+ messages: node.__messages
88
+ }, node.__key);
89
+ }
90
+ constructor(payload, key) {
91
+ super(key);
92
+ _defineProperty(this, "__variant", void 0);
93
+ _defineProperty(this, "__participants", void 0);
94
+ _defineProperty(this, "__messages", void 0);
95
+ this.__variant = payload.variant;
96
+ this.__participants = payload.participants && payload.participants.length > 0 ? payload.participants : createDefaultParticipants(payload.variant);
97
+ this.__messages = payload.messages ?? [];
98
+ }
99
+ createDOM(_config) {
100
+ const div = document.createElement("div");
101
+ div.className = "rich-chat-wrapper";
102
+ return div;
103
+ }
104
+ updateDOM() {
105
+ return false;
106
+ }
107
+ isInline() {
108
+ return false;
109
+ }
110
+ getVariant() {
111
+ return this.getLatest().__variant;
112
+ }
113
+ setVariant(variant) {
114
+ const writable = this.getWritable();
115
+ writable.__variant = variant;
116
+ }
117
+ getParticipants() {
118
+ return this.getLatest().__participants;
119
+ }
120
+ setParticipants(participants) {
121
+ const writable = this.getWritable();
122
+ writable.__participants = participants;
123
+ }
124
+ getMessages() {
125
+ return this.getLatest().__messages;
126
+ }
127
+ setMessages(messages) {
128
+ const writable = this.getWritable();
129
+ writable.__messages = messages;
130
+ }
131
+ static importJSON(serializedNode) {
132
+ return new ChatNode({
133
+ variant: serializedNode.variant,
134
+ participants: serializedNode.participants,
135
+ messages: serializedNode.messages
136
+ });
137
+ }
138
+ exportJSON() {
139
+ return {
140
+ ...super.exportJSON(),
141
+ type: "chat",
142
+ variant: this.__variant,
143
+ participants: this.__participants,
144
+ messages: this.__messages,
145
+ version: 1
146
+ };
147
+ }
148
+ decorate(_editor, _config) {
149
+ return createRendererDecoration(CHAT_NODE_KEY, void 0, {
150
+ variant: this.__variant,
151
+ participants: this.__participants,
152
+ messages: this.__messages
153
+ });
154
+ }
155
+ };
156
+ function $createChatNode(payload) {
157
+ return new ChatNode(payload);
158
+ }
159
+ function $isChatNode(node) {
160
+ return node instanceof ChatNode;
161
+ }
162
+ //#endregion
163
+ export { CHAT_NODE_KEY as a, _defineProperty as i, $isChatNode as n, createMessageId as o, ChatNode as r, $createChatNode as t };
@@ -1,9 +1,6 @@
1
- import { DecoratorNode } from "lexical";
2
- import { customAlphabet } from "nanoid";
3
1
  import { jsx, jsxs } from "react/jsx-runtime";
4
2
  import { code } from "@streamdown/code";
5
3
  import { Streamdown } from "streamdown";
6
- import { createRendererDecoration } from "@haklex/rich-editor/renderers";
7
4
  //#region src/styles.css.ts
8
5
  var container = "_7z1aq60";
9
6
  var row = "_7z1aq61";
@@ -68,33 +65,6 @@ var button = "_7z1aq61b";
68
65
  var buttonPrimary = "_7z1aq61c";
69
66
  var buttonGhost = "_7z1aq61d";
70
67
  //#endregion
71
- //#region src/utils.ts
72
- var idAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
73
- var makeParticipantId = customAlphabet(idAlphabet, 6);
74
- var makeMessageId = customAlphabet(idAlphabet, 8);
75
- function createParticipantId() {
76
- return `p_${makeParticipantId()}`;
77
- }
78
- function createMessageId() {
79
- return `m_${makeMessageId()}`;
80
- }
81
- function createDefaultParticipants(variant) {
82
- if (variant === "user-agent") return [{
83
- id: createParticipantId(),
84
- kind: "user"
85
- }, {
86
- id: createParticipantId(),
87
- kind: "agent"
88
- }];
89
- return [{
90
- id: createParticipantId(),
91
- kind: "user"
92
- }, {
93
- id: createParticipantId(),
94
- kind: "user"
95
- }];
96
- }
97
- //#endregion
98
68
  //#region src/ChatRenderer.tsx
99
69
  var streamdownPlugins = { code };
100
70
  var UNKNOWN = {
@@ -215,127 +185,4 @@ var ChatRenderer = ({ variant, participants, messages }) => {
215
185
  });
216
186
  };
217
187
  //#endregion
218
- //#region \0@oxc-project+runtime@0.127.0/helpers/typeof.js
219
- function _typeof(o) {
220
- "@babel/helpers - typeof";
221
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
222
- return typeof o;
223
- } : function(o) {
224
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
225
- }, _typeof(o);
226
- }
227
- //#endregion
228
- //#region \0@oxc-project+runtime@0.127.0/helpers/toPrimitive.js
229
- function toPrimitive(t, r) {
230
- if ("object" != _typeof(t) || !t) return t;
231
- var e = t[Symbol.toPrimitive];
232
- if (void 0 !== e) {
233
- var i = e.call(t, r || "default");
234
- if ("object" != _typeof(i)) return i;
235
- throw new TypeError("@@toPrimitive must return a primitive value.");
236
- }
237
- return ("string" === r ? String : Number)(t);
238
- }
239
- //#endregion
240
- //#region \0@oxc-project+runtime@0.127.0/helpers/toPropertyKey.js
241
- function toPropertyKey(t) {
242
- var i = toPrimitive(t, "string");
243
- return "symbol" == _typeof(i) ? i : i + "";
244
- }
245
- //#endregion
246
- //#region \0@oxc-project+runtime@0.127.0/helpers/defineProperty.js
247
- function _defineProperty(e, r, t) {
248
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
249
- value: t,
250
- enumerable: !0,
251
- configurable: !0,
252
- writable: !0
253
- }) : e[r] = t, e;
254
- }
255
- //#endregion
256
- //#region src/nodes/ChatNode.ts
257
- var ChatNode = class ChatNode extends DecoratorNode {
258
- static getType() {
259
- return "chat";
260
- }
261
- static clone(node) {
262
- return new ChatNode({
263
- variant: node.__variant,
264
- participants: node.__participants,
265
- messages: node.__messages
266
- }, node.__key);
267
- }
268
- constructor(payload, key) {
269
- super(key);
270
- _defineProperty(this, "__variant", void 0);
271
- _defineProperty(this, "__participants", void 0);
272
- _defineProperty(this, "__messages", void 0);
273
- this.__variant = payload.variant;
274
- this.__participants = payload.participants && payload.participants.length > 0 ? payload.participants : createDefaultParticipants(payload.variant);
275
- this.__messages = payload.messages ?? [];
276
- }
277
- createDOM(_config) {
278
- const div = document.createElement("div");
279
- div.className = "rich-chat-wrapper";
280
- return div;
281
- }
282
- updateDOM() {
283
- return false;
284
- }
285
- isInline() {
286
- return false;
287
- }
288
- getVariant() {
289
- return this.getLatest().__variant;
290
- }
291
- setVariant(variant) {
292
- const writable = this.getWritable();
293
- writable.__variant = variant;
294
- }
295
- getParticipants() {
296
- return this.getLatest().__participants;
297
- }
298
- setParticipants(participants) {
299
- const writable = this.getWritable();
300
- writable.__participants = participants;
301
- }
302
- getMessages() {
303
- return this.getLatest().__messages;
304
- }
305
- setMessages(messages) {
306
- const writable = this.getWritable();
307
- writable.__messages = messages;
308
- }
309
- static importJSON(serializedNode) {
310
- return new ChatNode({
311
- variant: serializedNode.variant,
312
- participants: serializedNode.participants,
313
- messages: serializedNode.messages
314
- });
315
- }
316
- exportJSON() {
317
- return {
318
- ...super.exportJSON(),
319
- type: "chat",
320
- variant: this.__variant,
321
- participants: this.__participants,
322
- messages: this.__messages,
323
- version: 1
324
- };
325
- }
326
- decorate(_editor, _config) {
327
- return createRendererDecoration("Chat", ChatRenderer, {
328
- variant: this.__variant,
329
- participants: this.__participants,
330
- messages: this.__messages
331
- });
332
- }
333
- };
334
- function $createChatNode(payload) {
335
- return new ChatNode(payload);
336
- }
337
- function $isChatNode(node) {
338
- return node instanceof ChatNode;
339
- }
340
- //#endregion
341
- export { participantPillUser as A, modalFooter as C, participantInput as D, participantCard as E, variantPill as F, variantPillActive as I, variantPillHint as L, rail as M, sectionLabel as N, participantLabel as O, semanticClassNames as P, variantPillName as R, modalBody as S, pane as T, messageCard as _, ChatRenderer as a, messageTextarea as b, addMessageButton as c, buttonPrimary as d, editContainer as f, messageActions as g, editorDialogPopup as h, _defineProperty as i, participantRow as j, participantPill as k, button as l, editOverlay as m, $isChatNode as n, createMessageId as o, editLabel as p, ChatNode as r, addMessage as s, $createChatNode as t, buttonGhost as u, messageHead as v, modalHeader as w, modal as x, messageSelect as y, variantStack as z };
188
+ export { variantPill as A, participantLabel as C, rail as D, participantRow as E, variantPillHint as M, variantPillName as N, sectionLabel as O, variantStack as P, participantInput as S, participantPillUser as T, modalBody as _, buttonGhost as a, pane as b, editLabel as c, messageActions as d, messageCard as f, modal as g, messageTextarea as h, button as i, variantPillActive as j, semanticClassNames as k, editOverlay as l, messageSelect as m, addMessage as n, buttonPrimary as o, messageHead as p, addMessageButton as r, editContainer as s, ChatRenderer as t, editorDialogPopup as u, modalFooter as v, participantPill as w, participantCard as x, modalHeader as y };
@@ -0,0 +1,9 @@
1
+ import { ComponentType } from 'react';
2
+ import { ChatRendererProps } from './types';
3
+ declare module '@haklex/rich-editor' {
4
+ interface RendererConfig {
5
+ Chat?: ComponentType<ChatRendererProps>;
6
+ }
7
+ }
8
+ export {};
9
+ //# sourceMappingURL=augment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"augment.d.ts","sourceRoot":"","sources":["../src/augment.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAU,cAAc;QACtB,IAAI,CAAC,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;KACzC;CACF;AAED,OAAO,EAAE,CAAC"}