@haklex/rich-litexml 0.3.4 → 0.4.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/dist/index.mjs CHANGED
@@ -128,6 +128,8 @@ function registerBuiltinReaders(registry) {
128
128
  var idAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
129
129
  var makePollIdSuffix = customAlphabet(idAlphabet, 10);
130
130
  var makeOptionIdSuffix = customAlphabet(idAlphabet, 6);
131
+ var makeChatParticipantId = customAlphabet(idAlphabet, 6);
132
+ var makeChatMessageId = customAlphabet(idAlphabet, 8);
131
133
  function extractBlockId(el) {
132
134
  const id = el.getAttribute("id");
133
135
  return id ? { $: { blockId: id } } : {};
@@ -407,6 +409,40 @@ function registerCustomReaders(registry) {
407
409
  version: 1
408
410
  };
409
411
  });
412
+ registry.registerReader("chat", (el) => {
413
+ const variant = el.getAttribute("variant") === "user-user" ? "user-user" : "user-agent";
414
+ const participants = [];
415
+ const messages = [];
416
+ for (const child of el.children) {
417
+ const tag = child.tagName.toLowerCase();
418
+ if (tag === "participants") for (const p of child.children) {
419
+ if (p.tagName.toLowerCase() !== "participant") continue;
420
+ const kind = p.getAttribute("kind") === "agent" ? "agent" : "user";
421
+ participants.push({
422
+ id: p.getAttribute("id") || `p_${makeChatParticipantId()}`,
423
+ kind,
424
+ name: p.getAttribute("name") || void 0,
425
+ avatar: p.getAttribute("avatar") || void 0
426
+ });
427
+ }
428
+ else if (tag === "messages") for (const m of child.children) {
429
+ if (m.tagName.toLowerCase() !== "message") continue;
430
+ messages.push({
431
+ id: m.getAttribute("id") || `m_${makeChatMessageId()}`,
432
+ participantId: m.getAttribute("participant") ?? "",
433
+ content: m.textContent ?? ""
434
+ });
435
+ }
436
+ }
437
+ return {
438
+ type: "chat",
439
+ ...extractBlockId(el),
440
+ variant,
441
+ participants,
442
+ messages,
443
+ version: 1
444
+ };
445
+ });
410
446
  registry.registerReader("poll", (el) => {
411
447
  let question = "";
412
448
  const options = [];
@@ -843,6 +879,41 @@ function registerCustomWriters(registry) {
843
879
  children: files
844
880
  };
845
881
  });
882
+ registry.registerWriter("chat", (node) => {
883
+ const n = node;
884
+ const participantsEl = {
885
+ tag: "participants",
886
+ children: (n.participants ?? []).map((p) => ({
887
+ tag: "participant",
888
+ attrs: optAttr({
889
+ id: p.id,
890
+ kind: p.kind,
891
+ name: p.name,
892
+ avatar: p.avatar
893
+ }),
894
+ children: []
895
+ }))
896
+ };
897
+ const messagesEl = {
898
+ tag: "messages",
899
+ children: (n.messages ?? []).map((m) => ({
900
+ tag: "message",
901
+ attrs: optAttr({
902
+ id: m.id,
903
+ participant: m.participantId
904
+ }),
905
+ children: [m.content ?? ""]
906
+ }))
907
+ };
908
+ return {
909
+ tag: "chat",
910
+ attrs: optAttr({
911
+ ...blockId(n),
912
+ variant: n.variant
913
+ }),
914
+ children: [participantsEl, messagesEl]
915
+ };
916
+ });
846
917
  registry.registerWriter("poll", (node) => {
847
918
  const n = node;
848
919
  const optionElements = (n.options ?? []).map((option) => ({
@@ -1 +1 @@
1
- {"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../src/readers/custom.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAiCnD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAgarE"}
1
+ {"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../src/readers/custom.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAmCnD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CA2crE"}
@@ -1 +1 @@
1
- {"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../src/writers/custom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAenD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CA+RrE"}
1
+ {"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../src/writers/custom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAenD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CA6TrE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haklex/rich-litexml",
3
- "version": "0.3.4",
3
+ "version": "0.4.1",
4
4
  "description": "Bidirectional Lexical SerializedNode <-> XML conversion with plugin registry",
5
5
  "repository": {
6
6
  "type": "git",